aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig4
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/Kconfig38
-rw-r--r--drivers/acpi/Makefile5
-rw-r--r--drivers/acpi/asus_acpi.c4
-rw-r--r--drivers/acpi/bus.c8
-rw-r--r--drivers/acpi/button.c245
-rw-r--r--drivers/acpi/container.c2
-rw-r--r--drivers/acpi/dispatcher/dsfield.c58
-rw-r--r--drivers/acpi/dispatcher/dsinit.c28
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c11
-rw-r--r--drivers/acpi/dispatcher/dsmthdat.c195
-rw-r--r--drivers/acpi/dispatcher/dsobject.c79
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c105
-rw-r--r--drivers/acpi/dispatcher/dsutils.c41
-rw-r--r--drivers/acpi/dispatcher/dswexec.c57
-rw-r--r--drivers/acpi/dispatcher/dswload.c118
-rw-r--r--drivers/acpi/dispatcher/dswscope.c31
-rw-r--r--drivers/acpi/dispatcher/dswstate.c458
-rw-r--r--drivers/acpi/ec.c409
-rw-r--r--drivers/acpi/events/evevent.c33
-rw-r--r--drivers/acpi/events/evgpe.c39
-rw-r--r--drivers/acpi/events/evgpeblk.c63
-rw-r--r--drivers/acpi/events/evmisc.c97
-rw-r--r--drivers/acpi/events/evregion.c35
-rw-r--r--drivers/acpi/events/evrgnini.c14
-rw-r--r--drivers/acpi/events/evsci.c12
-rw-r--r--drivers/acpi/events/evxface.c19
-rw-r--r--drivers/acpi/events/evxfevnt.c25
-rw-r--r--drivers/acpi/executer/exconfig.c31
-rw-r--r--drivers/acpi/executer/exconvrt.c44
-rw-r--r--drivers/acpi/executer/excreate.c50
-rw-r--r--drivers/acpi/executer/exdump.c105
-rw-r--r--drivers/acpi/executer/exfield.c25
-rw-r--r--drivers/acpi/executer/exfldio.c133
-rw-r--r--drivers/acpi/executer/exmisc.c7
-rw-r--r--drivers/acpi/executer/exmutex.c45
-rw-r--r--drivers/acpi/executer/exnames.c70
-rw-r--r--drivers/acpi/executer/exoparg1.c94
-rw-r--r--drivers/acpi/executer/exoparg2.c69
-rw-r--r--drivers/acpi/executer/exoparg3.c25
-rw-r--r--drivers/acpi/executer/exoparg6.c26
-rw-r--r--drivers/acpi/executer/exprep.c104
-rw-r--r--drivers/acpi/executer/exregion.c34
-rw-r--r--drivers/acpi/executer/exresnte.c24
-rw-r--r--drivers/acpi/executer/exresolv.c63
-rw-r--r--drivers/acpi/executer/exresop.c80
-rw-r--r--drivers/acpi/executer/exstore.c260
-rw-r--r--drivers/acpi/executer/exstoren.c20
-rw-r--r--drivers/acpi/executer/exstorob.c9
-rw-r--r--drivers/acpi/executer/exsystem.c48
-rw-r--r--drivers/acpi/executer/exutils.c37
-rw-r--r--drivers/acpi/glue.c360
-rw-r--r--drivers/acpi/hardware/hwacpi.c19
-rw-r--r--drivers/acpi/hardware/hwgpe.c31
-rw-r--r--drivers/acpi/hardware/hwregs.c114
-rw-r--r--drivers/acpi/hardware/hwsleep.c101
-rw-r--r--drivers/acpi/hardware/hwtimer.c4
-rw-r--r--drivers/acpi/hotkey.c1019
-rw-r--r--drivers/acpi/ibm_acpi.c8
-rw-r--r--drivers/acpi/namespace/nsaccess.c5
-rw-r--r--drivers/acpi/namespace/nsalloc.c121
-rw-r--r--drivers/acpi/namespace/nsdump.c109
-rw-r--r--drivers/acpi/namespace/nsdumpdv.c18
-rw-r--r--drivers/acpi/namespace/nseval.c70
-rw-r--r--drivers/acpi/namespace/nsinit.c28
-rw-r--r--drivers/acpi/namespace/nsload.c28
-rw-r--r--drivers/acpi/namespace/nsnames.c12
-rw-r--r--drivers/acpi/namespace/nsobject.c14
-rw-r--r--drivers/acpi/namespace/nssearch.c29
-rw-r--r--drivers/acpi/namespace/nsutils.c167
-rw-r--r--drivers/acpi/namespace/nswalk.c2
-rw-r--r--drivers/acpi/namespace/nsxfeval.c16
-rw-r--r--drivers/acpi/namespace/nsxfname.c8
-rw-r--r--drivers/acpi/namespace/nsxfobj.c4
-rw-r--r--drivers/acpi/osl.c12
-rw-r--r--drivers/acpi/parser/psargs.c55
-rw-r--r--drivers/acpi/parser/psopcode.c298
-rw-r--r--drivers/acpi/parser/psparse.c144
-rw-r--r--drivers/acpi/parser/psscope.c45
-rw-r--r--drivers/acpi/parser/pstree.c159
-rw-r--r--drivers/acpi/parser/psutils.c15
-rw-r--r--drivers/acpi/parser/pswalk.c11
-rw-r--r--drivers/acpi/parser/psxface.c21
-rw-r--r--drivers/acpi/pci_bind.c27
-rw-r--r--drivers/acpi/pci_irq.c2
-rw-r--r--drivers/acpi/pci_link.c43
-rw-r--r--drivers/acpi/pci_root.c24
-rw-r--r--drivers/acpi/processor_core.c39
-rw-r--r--drivers/acpi/processor_idle.c138
-rw-r--r--drivers/acpi/processor_perflib.c33
-rw-r--r--drivers/acpi/resources/rsaddr.c480
-rw-r--r--drivers/acpi/resources/rscalc.c144
-rw-r--r--drivers/acpi/resources/rscreate.c45
-rw-r--r--drivers/acpi/resources/rsdump.c402
-rw-r--r--drivers/acpi/resources/rsio.c197
-rw-r--r--drivers/acpi/resources/rsirq.c167
-rw-r--r--drivers/acpi/resources/rslist.c68
-rw-r--r--drivers/acpi/resources/rsmemory.c236
-rw-r--r--drivers/acpi/resources/rsmisc.c160
-rw-r--r--drivers/acpi/resources/rsutils.c53
-rw-r--r--drivers/acpi/resources/rsxface.c43
-rw-r--r--drivers/acpi/scan.c138
-rw-r--r--drivers/acpi/sleep/main.c74
-rw-r--r--drivers/acpi/sleep/poweroff.c81
-rw-r--r--drivers/acpi/sleep/proc.c9
-rw-r--r--drivers/acpi/tables/tbconvrt.c105
-rw-r--r--drivers/acpi/tables/tbget.c63
-rw-r--r--drivers/acpi/tables/tbgetall.c45
-rw-r--r--drivers/acpi/tables/tbinstal.c31
-rw-r--r--drivers/acpi/tables/tbrsdt.c19
-rw-r--r--drivers/acpi/tables/tbutils.c97
-rw-r--r--drivers/acpi/tables/tbxface.c39
-rw-r--r--drivers/acpi/tables/tbxfroot.c123
-rw-r--r--drivers/acpi/toshiba_acpi.c8
-rw-r--r--drivers/acpi/utilities/utalloc.c84
-rw-r--r--drivers/acpi/utilities/utcopy.c126
-rw-r--r--drivers/acpi/utilities/utdebug.c106
-rw-r--r--drivers/acpi/utilities/utdelete.c63
-rw-r--r--drivers/acpi/utilities/uteval.c36
-rw-r--r--drivers/acpi/utilities/utglobal.c133
-rw-r--r--drivers/acpi/utilities/utinit.c36
-rw-r--r--drivers/acpi/utilities/utmath.c2
-rw-r--r--drivers/acpi/utilities/utmisc.c187
-rw-r--r--drivers/acpi/utilities/utobject.c68
-rw-r--r--drivers/acpi/utilities/utxface.c61
-rw-r--r--drivers/acpi/video.c15
-rw-r--r--drivers/atm/ambassador.c4
-rw-r--r--drivers/atm/firestream.c6
-rw-r--r--drivers/atm/he.c1
-rw-r--r--drivers/atm/idt77252.c3
-rw-r--r--drivers/atm/zatm.c107
-rw-r--r--drivers/atm/zatm.h1
-rw-r--r--drivers/base/base.h1
-rw-r--r--drivers/base/bus.c117
-rw-r--r--drivers/base/core.c2
-rw-r--r--drivers/base/dd.c2
-rw-r--r--drivers/base/driver.c35
-rw-r--r--drivers/base/firmware_class.c13
-rw-r--r--drivers/base/sys.c1
-rw-r--r--drivers/block/as-iosched.c5
-rw-r--r--drivers/block/cciss.c18
-rw-r--r--drivers/block/cfq-iosched.c2081
-rw-r--r--drivers/block/deadline-iosched.c3
-rw-r--r--drivers/block/elevator.c9
-rw-r--r--drivers/block/ll_rw_blk.c206
-rw-r--r--drivers/block/swim3.c10
-rw-r--r--drivers/block/sx8.c7
-rw-r--r--drivers/bluetooth/bluecard_cs.c16
-rw-r--r--drivers/bluetooth/bt3c_cs.c14
-rw-r--r--drivers/bluetooth/btuart_cs.c14
-rw-r--r--drivers/bluetooth/dtl1_cs.c15
-rw-r--r--drivers/bluetooth/hci_vhci.c2
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/agp/amd64-agp.c9
-rw-r--r--drivers/char/drm/Kconfig9
-rw-r--r--drivers/char/drm/Makefile10
-rw-r--r--drivers/char/drm/ati_pcigart.c2
-rw-r--r--drivers/char/drm/drm.h2
-rw-r--r--drivers/char/drm/drmP.h35
-rw-r--r--drivers/char/drm/drm_auth.c4
-rw-r--r--drivers/char/drm/drm_bufs.c37
-rw-r--r--drivers/char/drm/drm_context.c10
-rw-r--r--drivers/char/drm/drm_drv.c9
-rw-r--r--drivers/char/drm/drm_fops.c14
-rw-r--r--drivers/char/drm/drm_ioc32.c1069
-rw-r--r--drivers/char/drm/drm_irq.c2
-rw-r--r--drivers/char/drm/drm_lock.c12
-rw-r--r--drivers/char/drm/drm_memory.c13
-rw-r--r--drivers/char/drm/drm_pciids.h7
-rw-r--r--drivers/char/drm/drm_proc.c2
-rw-r--r--drivers/char/drm/drm_stub.c92
-rw-r--r--drivers/char/drm/drm_vm.c10
-rw-r--r--drivers/char/drm/i810_dma.c24
-rw-r--r--drivers/char/drm/i810_drv.h1
-rw-r--r--drivers/char/drm/i830_dma.c20
-rw-r--r--drivers/char/drm/i830_drv.c2
-rw-r--r--drivers/char/drm/i830_drv.h2
-rw-r--r--drivers/char/drm/i830_irq.c5
-rw-r--r--drivers/char/drm/i915_dma.c84
-rw-r--r--drivers/char/drm/i915_drm.h27
-rw-r--r--drivers/char/drm/i915_drv.c30
-rw-r--r--drivers/char/drm/i915_drv.h38
-rw-r--r--drivers/char/drm/i915_ioc32.c221
-rw-r--r--drivers/char/drm/i915_irq.c28
-rw-r--r--drivers/char/drm/i915_mem.c24
-rw-r--r--drivers/char/drm/mga_drv.c3
-rw-r--r--drivers/char/drm/mga_drv.h2
-rw-r--r--drivers/char/drm/mga_ioc32.c167
-rw-r--r--drivers/char/drm/r128_drv.c3
-rw-r--r--drivers/char/drm/r128_drv.h3
-rw-r--r--drivers/char/drm/r128_ioc32.c219
-rw-r--r--drivers/char/drm/r128_state.c2
-rw-r--r--drivers/char/drm/radeon_drv.c3
-rw-r--r--drivers/char/drm/radeon_drv.h3
-rw-r--r--drivers/char/drm/radeon_ioc32.c395
-rw-r--r--drivers/char/drm/radeon_irq.c27
-rw-r--r--drivers/char/drm/via_3d_reg.h1651
-rw-r--r--drivers/char/drm/via_dma.c741
-rw-r--r--drivers/char/drm/via_drm.h243
-rw-r--r--drivers/char/drm/via_drv.c126
-rw-r--r--drivers/char/drm/via_drv.h118
-rw-r--r--drivers/char/drm/via_ds.c280
-rw-r--r--drivers/char/drm/via_ds.h104
-rw-r--r--drivers/char/drm/via_irq.c339
-rw-r--r--drivers/char/drm/via_map.c110
-rw-r--r--drivers/char/drm/via_mm.c358
-rw-r--r--drivers/char/drm/via_mm.h40
-rw-r--r--drivers/char/drm/via_verifier.c1061
-rw-r--r--drivers/char/drm/via_verifier.h61
-rw-r--r--drivers/char/drm/via_video.c97
-rw-r--r--drivers/char/hvc_console.c429
-rw-r--r--drivers/char/hvc_vio.c152
-rw-r--r--drivers/char/hvsi.c8
-rw-r--r--drivers/char/hw_random.c2
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c4
-rw-r--r--drivers/char/misc.c3
-rw-r--r--drivers/char/moxa.c2
-rw-r--r--drivers/char/n_tty.c33
-rw-r--r--drivers/char/pcmcia/synclink_cs.c16
-rw-r--r--drivers/char/random.c2
-rw-r--r--drivers/char/rio/rio_linux.c4
-rw-r--r--drivers/char/rocket.c3
-rw-r--r--drivers/char/rtc.c16
-rw-r--r--drivers/char/sysrq.c2
-rw-r--r--drivers/char/tb0219.c19
-rw-r--r--drivers/char/tipar.c2
-rw-r--r--drivers/char/tpm/tpm.c2
-rw-r--r--drivers/char/tty_ioctl.c4
-rw-r--r--drivers/char/vt.c2
-rw-r--r--drivers/char/vt_ioctl.c5
-rw-r--r--drivers/char/watchdog/i8xx_tco.c2
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c2
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/cpufreq/cpufreq.c4
-rw-r--r--drivers/crypto/padlock-aes.c153
-rw-r--r--drivers/crypto/padlock.h22
-rw-r--r--drivers/firmware/pcdp.c24
-rw-r--r--drivers/firmware/pcdp.h35
-rw-r--r--drivers/hwmon/Kconfig420
-rw-r--r--drivers/hwmon/Makefile44
-rw-r--r--drivers/hwmon/adm1021.c (renamed from drivers/i2c/chips/adm1021.c)0
-rw-r--r--drivers/hwmon/adm1025.c (renamed from drivers/i2c/chips/adm1025.c)0
-rw-r--r--drivers/hwmon/adm1026.c (renamed from drivers/i2c/chips/adm1026.c)0
-rw-r--r--drivers/hwmon/adm1031.c (renamed from drivers/i2c/chips/adm1031.c)0
-rw-r--r--drivers/hwmon/adm9240.c (renamed from drivers/i2c/chips/adm9240.c)0
-rw-r--r--drivers/hwmon/asb100.c (renamed from drivers/i2c/chips/asb100.c)0
-rw-r--r--drivers/hwmon/atxp1.c (renamed from drivers/i2c/chips/atxp1.c)2
-rw-r--r--drivers/hwmon/ds1621.c (renamed from drivers/i2c/chips/ds1621.c)0
-rw-r--r--drivers/hwmon/fscher.c (renamed from drivers/i2c/chips/fscher.c)0
-rw-r--r--drivers/hwmon/fscpos.c (renamed from drivers/i2c/chips/fscpos.c)0
-rw-r--r--drivers/hwmon/gl518sm.c (renamed from drivers/i2c/chips/gl518sm.c)0
-rw-r--r--drivers/hwmon/gl520sm.c (renamed from drivers/i2c/chips/gl520sm.c)0
-rw-r--r--drivers/hwmon/it87.c (renamed from drivers/i2c/chips/it87.c)0
-rw-r--r--drivers/hwmon/lm63.c (renamed from drivers/i2c/chips/lm63.c)0
-rw-r--r--drivers/hwmon/lm75.c (renamed from drivers/i2c/chips/lm75.c)0
-rw-r--r--drivers/hwmon/lm75.h (renamed from drivers/i2c/chips/lm75.h)0
-rw-r--r--drivers/hwmon/lm77.c (renamed from drivers/i2c/chips/lm77.c)0
-rw-r--r--drivers/hwmon/lm78.c (renamed from drivers/i2c/chips/lm78.c)0
-rw-r--r--drivers/hwmon/lm80.c (renamed from drivers/i2c/chips/lm80.c)0
-rw-r--r--drivers/hwmon/lm83.c (renamed from drivers/i2c/chips/lm83.c)0
-rw-r--r--drivers/hwmon/lm85.c (renamed from drivers/i2c/chips/lm85.c)0
-rw-r--r--drivers/hwmon/lm87.c (renamed from drivers/i2c/chips/lm87.c)0
-rw-r--r--drivers/hwmon/lm90.c (renamed from drivers/i2c/chips/lm90.c)0
-rw-r--r--drivers/hwmon/lm92.c (renamed from drivers/i2c/chips/lm92.c)0
-rw-r--r--drivers/hwmon/max1619.c (renamed from drivers/i2c/chips/max1619.c)0
-rw-r--r--drivers/hwmon/pc87360.c (renamed from drivers/i2c/chips/pc87360.c)0
-rw-r--r--drivers/hwmon/sis5595.c (renamed from drivers/i2c/chips/sis5595.c)0
-rw-r--r--drivers/hwmon/smsc47b397.c (renamed from drivers/i2c/chips/smsc47b397.c)0
-rw-r--r--drivers/hwmon/smsc47m1.c (renamed from drivers/i2c/chips/smsc47m1.c)0
-rw-r--r--drivers/hwmon/via686a.c (renamed from drivers/i2c/chips/via686a.c)12
-rw-r--r--drivers/hwmon/w83627ehf.c (renamed from drivers/i2c/chips/w83627ehf.c)0
-rw-r--r--drivers/hwmon/w83627hf.c (renamed from drivers/i2c/chips/w83627hf.c)0
-rw-r--r--drivers/hwmon/w83781d.c (renamed from drivers/i2c/chips/w83781d.c)0
-rw-r--r--drivers/hwmon/w83l785ts.c (renamed from drivers/i2c/chips/w83l785ts.c)0
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c8
-rw-r--r--drivers/i2c/busses/i2c-i801.c4
-rw-r--r--drivers/i2c/busses/i2c-keywest.c7
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/chips/Kconfig413
-rw-r--r--drivers/i2c/chips/Makefile38
-rw-r--r--drivers/i2c/chips/eeprom.c3
-rw-r--r--drivers/i2c/chips/m41t00.c2
-rw-r--r--drivers/i2c/chips/max6875.c6
-rw-r--r--drivers/i2c/chips/tps65010.c59
-rw-r--r--drivers/i2c/i2c-core.c17
-rw-r--r--drivers/ide/Kconfig6
-rw-r--r--drivers/ide/Makefile1
-rw-r--r--drivers/ide/ide-cd.c4
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-dma.c1
-rw-r--r--drivers/ide/ide-iops.c3
-rw-r--r--drivers/ide/ide-lib.c13
-rw-r--r--drivers/ide/legacy/hd.c4
-rw-r--r--drivers/ide/legacy/ide-cs.c42
-rw-r--r--drivers/ide/pci/Makefile1
-rw-r--r--drivers/ide/pci/alim15x3.c10
-rw-r--r--drivers/ide/pci/amd74xx.c7
-rw-r--r--drivers/ide/pci/cs5530.c4
-rw-r--r--drivers/ide/pci/cy82c693.c8
-rw-r--r--drivers/ide/pci/generic.c73
-rw-r--r--drivers/ide/pci/hpt366.c470
-rw-r--r--drivers/ide/pci/it8172.c4
-rw-r--r--drivers/ide/pci/it821x.c812
-rw-r--r--drivers/ide/pci/ns87415.c2
-rw-r--r--drivers/ide/pci/opti621.c2
-rw-r--r--drivers/ide/pci/sc1200.c2
-rw-r--r--drivers/ide/pci/serverworks.c10
-rw-r--r--drivers/ide/pci/sl82c105.c6
-rw-r--r--drivers/ide/pci/slc90e66.c2
-rw-r--r--drivers/ide/pci/triflex.c2
-rw-r--r--drivers/ide/pci/via82cxxx.c4
-rw-r--r--drivers/ide/ppc/pmac.c20
-rw-r--r--drivers/ide/setup-pci.c2
-rw-r--r--drivers/ieee1394/Kconfig12
-rw-r--r--drivers/ieee1394/csr.c3
-rw-r--r--drivers/ieee1394/csr1212.c37
-rw-r--r--drivers/ieee1394/dma.c2
-rw-r--r--drivers/ieee1394/eth1394.c6
-rw-r--r--drivers/ieee1394/ieee1394_core.c35
-rw-r--r--drivers/ieee1394/ieee1394_core.h4
-rw-r--r--drivers/ieee1394/iso.c27
-rw-r--r--drivers/ieee1394/iso.h13
-rw-r--r--drivers/ieee1394/nodemgr.c2
-rw-r--r--drivers/ieee1394/ohci1394.c53
-rw-r--r--drivers/ieee1394/pcilynx.c4
-rw-r--r--drivers/ieee1394/raw1394.c7
-rw-r--r--drivers/ieee1394/sbp2.c135
-rw-r--r--drivers/infiniband/Kconfig10
-rw-r--r--drivers/infiniband/core/Makefile5
-rw-r--r--drivers/infiniband/core/packer.c4
-rw-r--r--drivers/infiniband/core/sa_query.c18
-rw-r--r--drivers/infiniband/core/uverbs.h132
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c1006
-rw-r--r--drivers/infiniband/core/uverbs_main.c698
-rw-r--r--drivers/infiniband/core/uverbs_mem.c221
-rw-r--r--drivers/infiniband/core/verbs.c32
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c531
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.h48
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c177
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h18
-rw-r--r--drivers/infiniband/hw/mthca/mthca_doorbell.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c58
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c34
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mcg.c63
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c151
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.h14
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c367
-rw-r--r--drivers/infiniband/hw/mthca/mthca_pd.c24
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c334
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h30
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c344
-rw-r--r--drivers/infiniband/hw/mthca/mthca_user.h81
-rw-r--r--drivers/infiniband/include/ib_user_verbs.h389
-rw-r--r--drivers/infiniband/include/ib_verbs.h124
-rw-r--r--drivers/input/evdev.c407
-rw-r--r--drivers/input/gameport/Kconfig14
-rw-r--r--drivers/input/gameport/Makefile2
-rw-r--r--drivers/input/gameport/cs461x.c322
-rw-r--r--drivers/input/gameport/gameport.c34
-rw-r--r--drivers/input/gameport/ns558.c12
-rw-r--r--drivers/input/gameport/vortex.c186
-rw-r--r--drivers/input/input.c37
-rw-r--r--drivers/input/joydev.c116
-rw-r--r--drivers/input/joystick/a3d.c2
-rw-r--r--drivers/input/joystick/adi.c4
-rw-r--r--drivers/input/joystick/amijoy.c29
-rw-r--r--drivers/input/joystick/analog.c4
-rw-r--r--drivers/input/joystick/db9.c17
-rw-r--r--drivers/input/joystick/gamecon.c29
-rw-r--r--drivers/input/joystick/gf2k.c2
-rw-r--r--drivers/input/joystick/grip_mp.c2
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c1
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c1
-rw-r--r--drivers/input/joystick/spaceball.c4
-rw-r--r--drivers/input/joystick/spaceorb.c2
-rw-r--r--drivers/input/joystick/tmdc.c2
-rw-r--r--drivers/input/joystick/turbografx.c35
-rw-r--r--drivers/input/keyboard/atkbd.c6
-rw-r--r--drivers/input/keyboard/corgikbd.c6
-rw-r--r--drivers/input/keyboard/lkkbd.c8
-rw-r--r--drivers/input/keyboard/locomokbd.c28
-rw-r--r--drivers/input/keyboard/maple_keyb.c22
-rw-r--r--drivers/input/misc/uinput.c6
-rw-r--r--drivers/input/mouse/Makefile2
-rw-r--r--drivers/input/mouse/alps.c52
-rw-r--r--drivers/input/mouse/amimouse.c8
-rw-r--r--drivers/input/mouse/inport.c38
-rw-r--r--drivers/input/mouse/lifebook.c134
-rw-r--r--drivers/input/mouse/lifebook.h17
-rw-r--r--drivers/input/mouse/logibm.c17
-rw-r--r--drivers/input/mouse/maplemouse.c75
-rw-r--r--drivers/input/mouse/pc110pad.c21
-rw-r--r--drivers/input/mouse/psmouse-base.c351
-rw-r--r--drivers/input/mouse/psmouse.h4
-rw-r--r--drivers/input/mouse/rpcmouse.c2
-rw-r--r--drivers/input/mouse/vsxxxaa.c4
-rw-r--r--drivers/input/mousedev.c8
-rw-r--r--drivers/input/serio/libps2.c136
-rw-r--r--drivers/input/serio/serio.c89
-rw-r--r--drivers/input/touchscreen/elo.c2
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c180
-rw-r--r--drivers/input/touchscreen/mk712.c21
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c16
-rw-r--r--drivers/isdn/hardware/eicon/dadapter.c2
-rw-r--r--drivers/isdn/hisax/avma1_cs.c15
-rw-r--r--drivers/isdn/hisax/elsa_cs.c15
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c8
-rw-r--r--drivers/isdn/hisax/isdnl1.c3
-rw-r--r--drivers/isdn/hisax/isdnl2.c17
-rw-r--r--drivers/isdn/hisax/isdnl3.c2
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c20
-rw-r--r--drivers/isdn/hisax/teles_cs.c14
-rw-r--r--drivers/isdn/hysdn/hycapi.c20
-rw-r--r--drivers/isdn/hysdn/hysdn_boot.c4
-rw-r--r--drivers/isdn/hysdn/hysdn_defs.h12
-rw-r--r--drivers/isdn/hysdn/hysdn_init.c2
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c4
-rw-r--r--drivers/isdn/i4l/isdn_tty.c4
-rw-r--r--drivers/isdn/icn/icn.c4
-rw-r--r--drivers/macintosh/Kconfig42
-rw-r--r--drivers/macintosh/Makefile5
-rw-r--r--drivers/macintosh/adb.c10
-rw-r--r--drivers/macintosh/macio_asic.c78
-rw-r--r--drivers/macintosh/macio_sysfs.c50
-rw-r--r--drivers/macintosh/macserial.c3036
-rw-r--r--drivers/macintosh/macserial.h461
-rw-r--r--drivers/macintosh/mediabay.c7
-rw-r--r--drivers/macintosh/therm_pm72.c9
-rw-r--r--drivers/macintosh/therm_windtunnel.c6
-rw-r--r--drivers/macintosh/via-pmu.c78
-rw-r--r--drivers/md/bitmap.c9
-rw-r--r--drivers/md/dm-mpath.c68
-rw-r--r--drivers/md/dm-raid1.c1
-rw-r--r--drivers/md/dm-snap.c6
-rw-r--r--drivers/md/dm-table.c1
-rw-r--r--drivers/md/dm.c27
-rw-r--r--drivers/md/md.c1
-rw-r--r--drivers/md/raid0.c8
-rw-r--r--drivers/md/raid1.c37
-rw-r--r--drivers/media/common/ir-common.c255
-rw-r--r--drivers/media/common/saa7146_core.c13
-rw-r--r--drivers/media/dvb/Kconfig4
-rw-r--r--drivers/media/dvb/Makefile2
-rw-r--r--drivers/media/dvb/b2c2/Kconfig14
-rw-r--r--drivers/media/dvb/b2c2/Makefile2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-common.h6
-rw-r--r--drivers/media/dvb/b2c2/flexcop-dma.c165
-rw-r--r--drivers/media/dvb/b2c2/flexcop-hw-filter.c12
-rw-r--r--drivers/media/dvb/b2c2/flexcop-misc.c12
-rw-r--r--drivers/media/dvb/b2c2/flexcop-pci.c122
-rw-r--r--drivers/media/dvb/b2c2/flexcop-reg.h548
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.c2
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c34
-rw-r--r--drivers/media/dvb/b2c2/flexcop.h1
-rw-r--r--drivers/media/dvb/b2c2/flexcop_ibi_value_be.h458
-rw-r--r--drivers/media/dvb/b2c2/flexcop_ibi_value_le.h458
-rw-r--r--drivers/media/dvb/b2c2/skystar2.c2644
-rw-r--r--drivers/media/dvb/bt8xx/dst.c233
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c349
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h3
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c4
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c19
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c44
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h22
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig34
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c10
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c295
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.h30
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c62
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c73
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u-fe.c76
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c96
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.h42
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-common.h4
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h10
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c10
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c14
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-urb.c182
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h26
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c2
-rw-r--r--drivers/media/dvb/dvb-usb/umt-010.c2
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c49
-rw-r--r--drivers/media/dvb/frontends/Kconfig13
-rw-r--r--drivers/media/dvb/frontends/Makefile2
-rw-r--r--drivers/media/dvb/frontends/cx22702.c29
-rw-r--r--drivers/media/dvb/frontends/cx22702.h5
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c85
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h6
-rw-r--r--drivers/media/dvb/frontends/l64781.c9
-rw-r--r--drivers/media/dvb/frontends/lgdt3302.c599
-rw-r--r--drivers/media/dvb/frontends/lgdt3302.h49
-rw-r--r--drivers/media/dvb/frontends/lgdt3302_priv.h72
-rw-r--r--drivers/media/dvb/frontends/s5h1420.c800
-rw-r--r--drivers/media/dvb/frontends/s5h1420.h41
-rw-r--r--drivers/media/dvb/frontends/stv0297.c8
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c235
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h31
-rw-r--r--drivers/media/dvb/frontends/tda80xx.c1
-rw-r--r--drivers/media/dvb/pluto2/Kconfig16
-rw-r--r--drivers/media/dvb/pluto2/Makefile3
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c809
-rw-r--r--drivers/media/dvb/ttpci/Kconfig9
-rw-r--r--drivers/media/dvb/ttpci/av7110.c251
-rw-r--r--drivers/media/dvb/ttpci/av7110.h7
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c220
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.h4
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c395
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.h12
-rw-r--r--drivers/media/dvb/ttpci/av7110_ipack.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c12
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c21
-rw-r--r--drivers/media/dvb/ttpci/budget.c99
-rw-r--r--drivers/media/dvb/ttusb-budget/Kconfig1
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c52
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c11
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusbdecfe.c14
-rw-r--r--drivers/media/video/Kconfig14
-rw-r--r--drivers/media/video/Makefile3
-rw-r--r--drivers/media/video/bt832.c12
-rw-r--r--drivers/media/video/bttv-cards.c110
-rw-r--r--drivers/media/video/bttv-driver.c90
-rw-r--r--drivers/media/video/bttv-i2c.c26
-rw-r--r--drivers/media/video/bttv-risc.c9
-rw-r--r--drivers/media/video/bttvp.h5
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c5
-rw-r--r--drivers/media/video/cx88/cx88-cards.c71
-rw-r--r--drivers/media/video/cx88/cx88-core.c59
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c95
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c32
-rw-r--r--drivers/media/video/cx88/cx88-input.c384
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c33
-rw-r--r--drivers/media/video/cx88/cx88-reg.h11
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c76
-rw-r--r--drivers/media/video/cx88/cx88-video.c363
-rw-r--r--drivers/media/video/cx88/cx88.h24
-rw-r--r--drivers/media/video/ir-kbd-i2c.c51
-rw-r--r--drivers/media/video/msp3400.c25
-rw-r--r--drivers/media/video/mt20xx.c22
-rw-r--r--drivers/media/video/mxb.c7
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c2096
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c74
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c423
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c45
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c48
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c19
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c121
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c12
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c54
-rw-r--r--drivers/media/video/saa7134/saa7134.h21
-rw-r--r--drivers/media/video/tda7432.c13
-rw-r--r--drivers/media/video/tda8290.c23
-rw-r--r--drivers/media/video/tda9875.c13
-rw-r--r--drivers/media/video/tda9887.c16
-rw-r--r--drivers/media/video/tea5767.c342
-rw-r--r--drivers/media/video/tuner-3036.c2
-rw-r--r--drivers/media/video/tuner-core.c743
-rw-r--r--drivers/media/video/tuner-simple.c101
-rw-r--r--drivers/media/video/tvaudio.c5
-rw-r--r--drivers/media/video/tveeprom.c9
-rw-r--r--drivers/message/fusion/mptbase.c14
-rw-r--r--drivers/message/fusion/mptfc.c4
-rw-r--r--drivers/message/fusion/mptscsih.c10
-rw-r--r--drivers/message/fusion/mptscsih.h4
-rw-r--r--drivers/message/fusion/mptspi.c4
-rw-r--r--drivers/message/i2o/config-osm.c2
-rw-r--r--drivers/misc/Kconfig5
-rw-r--r--drivers/mmc/mmci.c9
-rw-r--r--drivers/mmc/wbsd.c80
-rw-r--r--drivers/mmc/wbsd.h9
-rw-r--r--drivers/mtd/afs.c16
-rw-r--r--drivers/mtd/chips/Kconfig29
-rw-r--r--drivers/mtd/chips/amd_flash.c14
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c580
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c497
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c5
-rw-r--r--drivers/mtd/chips/fwh_lock.h6
-rw-r--r--drivers/mtd/chips/gen_probe.c4
-rw-r--r--drivers/mtd/chips/jedec_probe.c28
-rw-r--r--drivers/mtd/cmdlinepart.c8
-rw-r--r--drivers/mtd/devices/block2mtd.c20
-rw-r--r--drivers/mtd/devices/ms02-nv.c8
-rw-r--r--drivers/mtd/devices/mtdram.c265
-rw-r--r--drivers/mtd/devices/phram.c34
-rw-r--r--drivers/mtd/devices/slram.c23
-rw-r--r--drivers/mtd/ftl.c5
-rw-r--r--drivers/mtd/maps/Kconfig127
-rw-r--r--drivers/mtd/maps/Makefile11
-rw-r--r--drivers/mtd/maps/alchemy-flash.c192
-rw-r--r--drivers/mtd/maps/amd76xrom.c4
-rw-r--r--drivers/mtd/maps/bast-flash.c13
-rw-r--r--drivers/mtd/maps/db1550-flash.c187
-rw-r--r--drivers/mtd/maps/db1x00-flash.c226
-rw-r--r--drivers/mtd/maps/elan-104nc.c228
-rw-r--r--drivers/mtd/maps/ichxrom.c6
-rw-r--r--drivers/mtd/maps/ixp2000.c7
-rw-r--r--drivers/mtd/maps/mainstone-flash.c178
-rw-r--r--drivers/mtd/maps/map_funcs.c11
-rw-r--r--drivers/mtd/maps/omap_nor.c179
-rw-r--r--drivers/mtd/maps/pb1550-flash.c203
-rw-r--r--drivers/mtd/maps/pb1xxx-flash.c178
-rw-r--r--drivers/mtd/maps/pci.c4
-rw-r--r--drivers/mtd/maps/pcmciamtd.c36
-rw-r--r--drivers/mtd/maps/plat-ram.c278
-rw-r--r--drivers/mtd/maps/scb2_flash.c4
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c33
-rw-r--r--drivers/mtd/mtdchar.c176
-rw-r--r--drivers/mtd/mtdcore.c6
-rw-r--r--drivers/mtd/mtdpart.c28
-rw-r--r--drivers/mtd/nand/Kconfig21
-rw-r--r--drivers/mtd/nand/Makefile2
-rw-r--r--drivers/mtd/nand/diskonchip.c96
-rw-r--r--drivers/mtd/nand/nand_base.c317
-rw-r--r--drivers/mtd/nand/nand_bbt.c112
-rw-r--r--drivers/mtd/nand/nand_ids.c18
-rw-r--r--drivers/mtd/nand/nandsim.c41
-rw-r--r--drivers/mtd/nand/rtc_from4.c140
-rw-r--r--drivers/mtd/nand/s3c2410.c297
-rw-r--r--[-rwxr-xr-x]drivers/mtd/nand/sharpsl.c4
-rw-r--r--drivers/mtd/nand/tx4925ndfmc.c416
-rw-r--r--drivers/mtd/nand/tx4938ndfmc.c406
-rw-r--r--drivers/net/3c503.c16
-rw-r--r--drivers/net/3c505.c6
-rw-r--r--drivers/net/3c509.c1
-rw-r--r--drivers/net/3c515.c16
-rw-r--r--drivers/net/3c523.c19
-rw-r--r--drivers/net/3c59x.c6
-rw-r--r--drivers/net/8139cp.c25
-rw-r--r--drivers/net/82596.c14
-rw-r--r--drivers/net/Kconfig29
-rw-r--r--drivers/net/ac3200.c19
-rw-r--r--drivers/net/acenic.c5
-rwxr-xr-xdrivers/net/amd8111e.c8
-rw-r--r--drivers/net/appletalk/Kconfig27
-rw-r--r--drivers/net/arm/etherh.c16
-rw-r--r--drivers/net/at1700.c4
-rw-r--r--drivers/net/b44.c6
-rw-r--r--drivers/net/bmac.c7
-rw-r--r--drivers/net/bonding/bond_3ad.c3
-rw-r--r--drivers/net/bonding/bond_main.c390
-rw-r--r--drivers/net/bonding/bonding.h12
-rw-r--r--drivers/net/cs89x0.c59
-rw-r--r--drivers/net/cs89x0.h2
-rw-r--r--drivers/net/defxx.c88
-rw-r--r--drivers/net/dl2k.c8
-rw-r--r--drivers/net/dm9000.c4
-rw-r--r--drivers/net/e100.c37
-rw-r--r--drivers/net/e1000/e1000.h4
-rw-r--r--drivers/net/e1000/e1000_ethtool.c131
-rw-r--r--drivers/net/e1000/e1000_hw.c23
-rw-r--r--drivers/net/e1000/e1000_hw.h1
-rw-r--r--drivers/net/e1000/e1000_main.c111
-rw-r--r--drivers/net/e2100.c15
-rw-r--r--drivers/net/eepro.c21
-rw-r--r--drivers/net/eepro100.c8
-rw-r--r--drivers/net/eexpress.c12
-rw-r--r--drivers/net/epic100.c6
-rw-r--r--drivers/net/eql.c16
-rw-r--r--drivers/net/es3210.c16
-rw-r--r--drivers/net/eth16i.c20
-rw-r--r--drivers/net/ewrk3.c12
-rw-r--r--drivers/net/fealnx.c11
-rw-r--r--drivers/net/forcedeth.c53
-rw-r--r--drivers/net/gianfar.c652
-rw-r--r--drivers/net/gianfar.h363
-rw-r--r--drivers/net/gianfar_ethtool.c277
-rw-r--r--drivers/net/gianfar_phy.c2
-rw-r--r--drivers/net/hamachi.c12
-rw-r--r--drivers/net/hamradio/scc.c5
-rw-r--r--drivers/net/hp-plus.c15
-rw-r--r--drivers/net/hp.c17
-rw-r--r--drivers/net/hp100.c44
-rw-r--r--drivers/net/isa-skeleton.c20
-rw-r--r--drivers/net/ixgb/ixgb_main.c5
-rw-r--r--drivers/net/lance.c17
-rw-r--r--drivers/net/lasi_82596.c8
-rw-r--r--drivers/net/lne390.c19
-rw-r--r--drivers/net/mace.c6
-rw-r--r--drivers/net/myri_code.h1283
-rw-r--r--drivers/net/myri_sbus.c2
-rw-r--r--drivers/net/natsemi.c4
-rw-r--r--drivers/net/ne-h8300.c19
-rw-r--r--drivers/net/ne.c18
-rw-r--r--drivers/net/ne2.c19
-rw-r--r--drivers/net/ne2k-pci.c3
-rw-r--r--drivers/net/ns83820.c5
-rw-r--r--drivers/net/pcmcia/3c574_cs.c15
-rw-r--r--drivers/net/pcmcia/3c589_cs.c19
-rw-r--r--drivers/net/pcmcia/axnet_cs.c36
-rw-r--r--drivers/net/pcmcia/com20020_cs.c14
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c37
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c18
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c15
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c220
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c329
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c35
-rw-r--r--drivers/net/pcnet32.c8
-rw-r--r--drivers/net/plip.c2
-rw-r--r--drivers/net/ppp_async.c2
-rw-r--r--drivers/net/ppp_generic.c12
-rw-r--r--drivers/net/ppp_synctty.c2
-rw-r--r--drivers/net/r8169.c4
-rw-r--r--drivers/net/s2io.c15
-rw-r--r--drivers/net/sb1000.c14
-rw-r--r--drivers/net/sb1250-mac.c4
-rw-r--r--drivers/net/shaper.c42
-rw-r--r--drivers/net/sis900.c11
-rw-r--r--drivers/net/sk98lin/skge.c5
-rw-r--r--drivers/net/skfp/Makefile4
-rw-r--r--drivers/net/skfp/drvfbi.c222
-rw-r--r--drivers/net/skfp/ess.c4
-rw-r--r--drivers/net/skfp/fplustm.c70
-rw-r--r--drivers/net/skfp/h/cmtdef.h7
-rw-r--r--drivers/net/skfp/h/hwmtm.h25
-rw-r--r--drivers/net/skfp/h/osdef1st.h2
-rw-r--r--drivers/net/skfp/hwmtm.c34
-rw-r--r--drivers/net/skfp/lnkstat.c204
-rw-r--r--drivers/net/skfp/pcmplc.c7
-rw-r--r--drivers/net/skfp/pmf.c11
-rw-r--r--drivers/net/skfp/skfddi.c1
-rw-r--r--drivers/net/skfp/smt.c48
-rw-r--r--drivers/net/skfp/smtdef.c5
-rw-r--r--drivers/net/skfp/smtparse.c467
-rw-r--r--drivers/net/skge.c1714
-rw-r--r--drivers/net/skge.h587
-rw-r--r--drivers/net/slip.c7
-rw-r--r--drivers/net/smc-mca.c60
-rw-r--r--drivers/net/smc-mca.h61
-rw-r--r--drivers/net/smc-ultra.c15
-rw-r--r--drivers/net/smc91x.c45
-rw-r--r--drivers/net/smc91x.h13
-rw-r--r--drivers/net/starfire.c6
-rw-r--r--drivers/net/sundance.c6
-rw-r--r--drivers/net/sungem.c9
-rw-r--r--drivers/net/sungem_phy.c69
-rw-r--r--drivers/net/sungem_phy.h3
-rw-r--r--drivers/net/tg3.c69
-rw-r--r--drivers/net/tg3.h10
-rw-r--r--drivers/net/tlan.c3
-rw-r--r--drivers/net/tokenring/3c359.c3
-rw-r--r--drivers/net/tokenring/3c359_microcode.h2
-rw-r--r--drivers/net/tokenring/abyss.c11
-rw-r--r--drivers/net/tokenring/ibmtr.c28
-rw-r--r--drivers/net/tokenring/lanstreamer.c9
-rw-r--r--drivers/net/tokenring/madgemc.c14
-rw-r--r--drivers/net/tokenring/proteon.c11
-rw-r--r--drivers/net/tokenring/skisa.c11
-rw-r--r--drivers/net/tokenring/smctr.c2
-rw-r--r--drivers/net/tokenring/smctr_firmware.h2
-rw-r--r--drivers/net/tokenring/tms380tr.c13
-rw-r--r--drivers/net/tokenring/tmspci.c11
-rw-r--r--drivers/net/tulip/de2104x.c6
-rw-r--r--drivers/net/tulip/dmfe.c23
-rw-r--r--drivers/net/tulip/eeprom.c16
-rw-r--r--drivers/net/tulip/interrupt.c10
-rw-r--r--drivers/net/tulip/media.c3
-rw-r--r--drivers/net/tulip/tulip_core.c50
-rw-r--r--drivers/net/tulip/winbond-840.c9
-rw-r--r--drivers/net/tulip/xircom_tulip_cb.c4
-rw-r--r--drivers/net/tun.c2
-rw-r--r--drivers/net/typhoon.c10
-rw-r--r--drivers/net/via-rhine.c26
-rw-r--r--drivers/net/via-velocity.c6
-rw-r--r--drivers/net/wan/farsync.c4
-rw-r--r--drivers/net/wan/hdlc_cisco.c5
-rw-r--r--drivers/net/wan/hdlc_ppp.c3
-rw-r--r--drivers/net/wan/hdlc_raw.c3
-rw-r--r--drivers/net/wan/sdla_fr.c7
-rw-r--r--drivers/net/wan/sdla_ft1.c3
-rw-r--r--drivers/net/wan/sdla_ppp.c3
-rw-r--r--drivers/net/wan/sdla_x25.c3
-rw-r--r--drivers/net/wan/wanpipe_multppp.c9
-rw-r--r--drivers/net/wan/wanxl.c5
-rw-r--r--drivers/net/wd.c18
-rw-r--r--drivers/net/wireless/airo.c16
-rw-r--r--drivers/net/wireless/airo_cs.c17
-rw-r--r--drivers/net/wireless/airport.c8
-rw-r--r--drivers/net/wireless/arlan-main.c26
-rw-r--r--drivers/net/wireless/atmel_cs.c39
-rw-r--r--drivers/net/wireless/netwave_cs.c14
-rw-r--r--drivers/net/wireless/orinoco.c2465
-rw-r--r--drivers/net/wireless/orinoco.h30
-rw-r--r--drivers/net/wireless/orinoco_cs.c58
-rw-r--r--drivers/net/wireless/prism54/isl_38xx.c6
-rw-r--r--drivers/net/wireless/ray_cs.c14
-rw-r--r--drivers/net/wireless/wavelan_cs.c17
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h1
-rw-r--r--drivers/net/wireless/wl3501_cs.c26
-rw-r--r--drivers/net/yellowfin.c8
-rw-r--r--drivers/parisc/dino.c1
-rw-r--r--drivers/parisc/lba_pci.c2
-rw-r--r--drivers/parport/parport_cs.c16
-rw-r--r--drivers/parport/parport_pc.c2
-rw-r--r--drivers/pci/Makefile1
-rw-r--r--drivers/pci/bus.c11
-rw-r--r--drivers/pci/hotplug.c2
-rw-r--r--drivers/pci/hotplug/Kconfig5
-rw-r--r--drivers/pci/hotplug/Makefile5
-rw-r--r--drivers/pci/hotplug/acpiphp.h47
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c9
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c882
-rw-r--r--drivers/pci/hotplug/acpiphp_pci.c449
-rw-r--r--drivers/pci/hotplug/acpiphp_res.c700
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c5
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c611
-rw-r--r--drivers/pci/msi.c88
-rw-r--r--drivers/pci/msi.h9
-rw-r--r--drivers/pci/pci-acpi.c110
-rw-r--r--drivers/pci/pci-driver.c198
-rw-r--r--drivers/pci/pci-sysfs.c26
-rw-r--r--drivers/pci/pci.c28
-rw-r--r--drivers/pci/pci.h4
-rw-r--r--drivers/pci/pcie/portdrv.h5
-rw-r--r--drivers/pci/pcie/portdrv_core.c14
-rw-r--r--drivers/pci/pcie/portdrv_pci.c79
-rw-r--r--drivers/pci/probe.c53
-rw-r--r--drivers/pci/proc.c14
-rw-r--r--drivers/pci/quirks.c1
-rw-r--r--drivers/pci/remove.c14
-rw-r--r--drivers/pci/search.c1
-rw-r--r--drivers/pci/setup-bus.c8
-rw-r--r--drivers/pcmcia/Kconfig50
-rw-r--r--drivers/pcmcia/Makefile3
-rw-r--r--drivers/pcmcia/au1000_generic.h1
-rw-r--r--drivers/pcmcia/au1000_pb1x00.c1
-rw-r--r--drivers/pcmcia/au1000_xxs1500.c1
-rw-r--r--drivers/pcmcia/cardbus.c1
-rw-r--r--drivers/pcmcia/cistpl.c28
-rw-r--r--drivers/pcmcia/cs.c1180
-rw-r--r--drivers/pcmcia/cs_internal.h29
-rw-r--r--drivers/pcmcia/ds.c1350
-rw-r--r--drivers/pcmcia/ds_internal.h21
-rw-r--r--drivers/pcmcia/hd64465_ss.c1
-rw-r--r--drivers/pcmcia/i82365.c18
-rw-r--r--drivers/pcmcia/m32r_cfc.c1
-rw-r--r--drivers/pcmcia/m32r_pcc.c1
-rw-r--r--drivers/pcmcia/pcmcia_compat.c82
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c759
-rw-r--r--drivers/pcmcia/pcmcia_resource.c943
-rw-r--r--drivers/pcmcia/rsrc_mgr.c11
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c170
-rw-r--r--drivers/pcmcia/sa1100_generic.c1
-rw-r--r--drivers/pcmcia/soc_common.h1
-rw-r--r--drivers/pcmcia/socket_sysfs.c167
-rw-r--r--drivers/pcmcia/tcic.c1
-rw-r--r--drivers/pcmcia/ti113x.h4
-rw-r--r--drivers/pcmcia/yenta_socket.c176
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c15
-rw-r--r--drivers/pnp/pnpbios/rsparser.c2
-rw-r--r--drivers/pnp/resource.c2
-rw-r--r--drivers/s390/net/claw.c4
-rw-r--r--drivers/s390/net/ctctty.c6
-rw-r--r--drivers/s390/net/qeth_main.c2
-rw-r--r--drivers/sbus/char/Kconfig14
-rw-r--r--drivers/sbus/char/aurora.c6
-rw-r--r--drivers/sbus/char/bbc_envctrl.c3
-rw-r--r--drivers/sbus/char/bpp.c20
-rw-r--r--drivers/sbus/char/envctrl.c10
-rw-r--r--drivers/sbus/char/vfc_i2c.c8
-rw-r--r--drivers/scsi/3w-9xxx.c8
-rw-r--r--drivers/scsi/3w-xxxx.c8
-rw-r--r--drivers/scsi/aacraid/commctrl.c2
-rw-r--r--drivers/scsi/ahci.c22
-rw-r--r--drivers/scsi/ipr.c10
-rw-r--r--drivers/scsi/libata-core.c6
-rw-r--r--drivers/scsi/libata-scsi.c16
-rw-r--r--drivers/scsi/mac53c94.c7
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/mesh.c8
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c18
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c17
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c30
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c26
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c14
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/serial/68328serial.c17
-rw-r--r--drivers/serial/8250.c61
-rw-r--r--drivers/serial/8250_accent.c47
-rw-r--r--drivers/serial/8250_boca.c61
-rw-r--r--drivers/serial/8250_fourport.c53
-rw-r--r--drivers/serial/8250_hub6.c58
-rw-r--r--drivers/serial/8250_mca.c64
-rw-r--r--drivers/serial/8250_pci.c51
-rw-r--r--drivers/serial/Kconfig84
-rw-r--r--drivers/serial/Makefile6
-rw-r--r--drivers/serial/au1x00_uart.c3
-rw-r--r--drivers/serial/bast_sio.c80
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c32
-rw-r--r--drivers/serial/crisv10.c2
-rw-r--r--drivers/serial/icom.c1
-rw-r--r--drivers/serial/ip22zilog.c13
-rw-r--r--drivers/serial/jsm/jsm.h1
-rw-r--r--drivers/serial/mpsc.c3
-rw-r--r--drivers/serial/pmac_zilog.c13
-rw-r--r--drivers/serial/pxa.c3
-rw-r--r--drivers/serial/s3c2410.c5
-rw-r--r--drivers/serial/serial_core.c42
-rw-r--r--drivers/serial/serial_cs.c113
-rw-r--r--drivers/serial/serial_txx9.c3
-rw-r--r--drivers/serial/sunsab.c7
-rw-r--r--drivers/serial/sunsu.c3
-rw-r--r--drivers/serial/sunzilog.c13
-rw-r--r--drivers/telephony/ixj_pcmcia.c14
-rw-r--r--drivers/usb/Makefile4
-rw-r--r--drivers/usb/atm/Kconfig50
-rw-r--r--drivers/usb/atm/Makefile7
-rw-r--r--drivers/usb/atm/cxacru.c878
-rw-r--r--drivers/usb/atm/speedtch.c1112
-rw-r--r--drivers/usb/atm/usb_atm.c1188
-rw-r--r--drivers/usb/atm/usb_atm.h176
-rw-r--r--drivers/usb/atm/usbatm.c1230
-rw-r--r--drivers/usb/atm/usbatm.h184
-rw-r--r--drivers/usb/atm/xusbatm.c196
-rw-r--r--drivers/usb/class/cdc-acm.c240
-rw-r--r--drivers/usb/class/cdc-acm.h25
-rw-r--r--drivers/usb/class/usblp.c3
-rw-r--r--drivers/usb/core/buffer.c2
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/hcd-pci.c1
-rw-r--r--drivers/usb/core/hcd.c281
-rw-r--r--drivers/usb/core/hcd.h27
-rw-r--r--drivers/usb/core/hub.c59
-rw-r--r--drivers/usb/core/hub.h11
-rw-r--r--drivers/usb/core/message.c2
-rw-r--r--drivers/usb/core/sysfs.c2
-rw-r--r--drivers/usb/core/urb.c4
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/gadget/Kconfig11
-rw-r--r--drivers/usb/gadget/dummy_hcd.c754
-rw-r--r--drivers/usb/gadget/ether.c371
-rw-r--r--drivers/usb/gadget/file_storage.c61
-rw-r--r--drivers/usb/gadget/goku_udc.c34
-rw-r--r--drivers/usb/gadget/inode.c12
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c6
-rw-r--r--drivers/usb/gadget/ndis.h14
-rw-r--r--drivers/usb/gadget/net2280.c59
-rw-r--r--drivers/usb/gadget/omap_udc.c310
-rw-r--r--drivers/usb/gadget/omap_udc.h4
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c49
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h10
-rw-r--r--drivers/usb/gadget/rndis.c515
-rw-r--r--drivers/usb/gadget/rndis.h95
-rw-r--r--drivers/usb/gadget/serial.c36
-rw-r--r--drivers/usb/gadget/zero.c14
-rw-r--r--drivers/usb/host/Kconfig13
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/ehci-dbg.c59
-rw-r--r--drivers/usb/host/ehci-hcd.c60
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/ehci-q.c4
-rw-r--r--drivers/usb/host/ehci-sched.c36
-rw-r--r--drivers/usb/host/hc_crisv10.c10
-rw-r--r--drivers/usb/host/isp116x-hcd.c1871
-rw-r--r--drivers/usb/host/isp116x.h583
-rw-r--r--drivers/usb/host/ohci-hcd.c60
-rw-r--r--drivers/usb/host/ohci-hub.c3
-rw-r--r--drivers/usb/host/ohci-mem.c5
-rw-r--r--drivers/usb/host/ohci-omap.c57
-rw-r--r--drivers/usb/host/ohci-pci.c13
-rw-r--r--drivers/usb/host/ohci.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c20
-rw-r--r--drivers/usb/host/sl811_cs.c28
-rw-r--r--drivers/usb/host/uhci-debug.c32
-rw-r--r--drivers/usb/host/uhci-hcd.c773
-rw-r--r--drivers/usb/host/uhci-hcd.h59
-rw-r--r--drivers/usb/host/uhci-hub.c83
-rw-r--r--drivers/usb/host/uhci-q.c60
-rw-r--r--drivers/usb/input/Kconfig37
-rw-r--r--drivers/usb/input/Makefile3
-rw-r--r--drivers/usb/input/acecad.c285
-rw-r--r--drivers/usb/input/aiptek.c32
-rw-r--r--drivers/usb/input/ati_remote.c248
-rw-r--r--drivers/usb/input/hid-core.c50
-rw-r--r--drivers/usb/input/hid-debug.h16
-rw-r--r--drivers/usb/input/hid-input.c16
-rw-r--r--drivers/usb/input/hid-lgff.c18
-rw-r--r--drivers/usb/input/hid.h18
-rw-r--r--drivers/usb/input/hiddev.c56
-rw-r--r--drivers/usb/input/itmtouch.c268
-rw-r--r--drivers/usb/input/kbtab.c17
-rw-r--r--drivers/usb/input/keyspan_remote.c633
-rw-r--r--drivers/usb/input/mtouchusb.c410
-rw-r--r--drivers/usb/input/powermate.c30
-rw-r--r--drivers/usb/input/touchkitusb.c11
-rw-r--r--drivers/usb/input/usbkbd.c29
-rw-r--r--drivers/usb/input/usbmouse.c31
-rw-r--r--drivers/usb/input/wacom.c398
-rw-r--r--drivers/usb/input/xpad.c75
-rw-r--r--drivers/usb/media/Makefile2
-rw-r--r--drivers/usb/media/sn9c102.h2
-rw-r--r--drivers/usb/media/sn9c102_core.c2
-rw-r--r--drivers/usb/media/sn9c102_ov7630.c394
-rw-r--r--drivers/usb/media/sn9c102_sensor.h16
-rw-r--r--drivers/usb/media/sn9c102_tas5110c1b.c21
-rw-r--r--drivers/usb/media/sn9c102_tas5130d1b.c27
-rw-r--r--drivers/usb/media/stv680.c8
-rw-r--r--drivers/usb/media/stv680.h5
-rw-r--r--drivers/usb/misc/Kconfig10
-rw-r--r--drivers/usb/misc/Makefile1
-rw-r--r--drivers/usb/misc/idmouse.c149
-rw-r--r--drivers/usb/misc/ldusb.c794
-rw-r--r--drivers/usb/misc/usbtest.c60
-rw-r--r--drivers/usb/mon/mon_text.c48
-rw-r--r--drivers/usb/net/kaweth.c4
-rw-r--r--drivers/usb/net/pegasus.c2
-rw-r--r--drivers/usb/net/pegasus.h2
-rw-r--r--drivers/usb/net/rtl8150.c2
-rw-r--r--drivers/usb/net/usbnet.c8
-rw-r--r--drivers/usb/net/zd1201.c41
-rw-r--r--drivers/usb/net/zd1201.h1
-rw-r--r--drivers/usb/serial/cyberjack.c19
-rw-r--r--drivers/usb/serial/ftdi_sio.c756
-rw-r--r--drivers/usb/serial/generic.c24
-rw-r--r--drivers/usb/serial/ipaq.c5
-rw-r--r--drivers/usb/serial/ipw.c14
-rw-r--r--drivers/usb/serial/ir-usb.c16
-rw-r--r--drivers/usb/serial/keyspan_pda.c19
-rw-r--r--drivers/usb/serial/omninet.c17
-rw-r--r--drivers/usb/serial/option.c228
-rw-r--r--drivers/usb/serial/safe_serial.c13
-rw-r--r--drivers/usb/serial/usb-serial.c1
-rw-r--r--drivers/usb/serial/usb-serial.h3
-rw-r--r--drivers/usb/storage/scsiglue.c54
-rw-r--r--drivers/usb/storage/scsiglue.h1
-rw-r--r--drivers/usb/storage/transport.c116
-rw-r--r--drivers/usb/storage/transport.h1
-rw-r--r--drivers/usb/storage/unusual_devs.h2
-rw-r--r--drivers/video/aty/aty128fb.c14
-rw-r--r--drivers/video/chipsfb.c176
-rw-r--r--drivers/video/console/fbcon.c8
-rw-r--r--drivers/video/fbsysfs.c2
-rw-r--r--drivers/video/imxfb.c14
-rw-r--r--drivers/video/imxfb.h1
-rw-r--r--drivers/video/logo/Kconfig5
-rw-r--r--drivers/video/logo/Makefile1
-rw-r--r--drivers/video/logo/logo.c5
-rw-r--r--drivers/video/logo/logo_m32r_clut224.ppm1292
-rw-r--r--drivers/video/platinumfb.c6
-rw-r--r--drivers/video/s1d13xxxfb.c10
-rw-r--r--drivers/video/savage/savagefb_driver.c2
-rw-r--r--drivers/w1/w1.c5
-rw-r--r--drivers/w1/w1_int.c2
1049 files changed, 60545 insertions, 38603 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index aed4a9b97c14..cecab0acc3fe 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -28,7 +28,7 @@ source "drivers/message/i2o/Kconfig"
28 28
29source "drivers/macintosh/Kconfig" 29source "drivers/macintosh/Kconfig"
30 30
31source "net/Kconfig" 31source "drivers/net/Kconfig"
32 32
33source "drivers/isdn/Kconfig" 33source "drivers/isdn/Kconfig"
34 34
@@ -44,6 +44,8 @@ source "drivers/i2c/Kconfig"
44 44
45source "drivers/w1/Kconfig" 45source "drivers/w1/Kconfig"
46 46
47source "drivers/hwmon/Kconfig"
48
47source "drivers/misc/Kconfig" 49source "drivers/misc/Kconfig"
48 50
49source "drivers/media/Kconfig" 51source "drivers/media/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 3167be54fedd..126a851d5653 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_INPUT) += input/
52obj-$(CONFIG_I2O) += message/ 52obj-$(CONFIG_I2O) += message/
53obj-$(CONFIG_I2C) += i2c/ 53obj-$(CONFIG_I2C) += i2c/
54obj-$(CONFIG_W1) += w1/ 54obj-$(CONFIG_W1) += w1/
55obj-$(CONFIG_HWMON) += hwmon/
55obj-$(CONFIG_PHONE) += telephony/ 56obj-$(CONFIG_PHONE) += telephony/
56obj-$(CONFIG_MD) += md/ 57obj-$(CONFIG_MD) += md/
57obj-$(CONFIG_BT) += bluetooth/ 58obj-$(CONFIG_BT) += bluetooth/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 86c52520ed34..986410e7b483 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "ACPI (Advanced Configuration and Power Interface) Support" 5menu "ACPI (Advanced Configuration and Power Interface) Support"
6 depends on PM
6 depends on !X86_VISWS 7 depends on !X86_VISWS
7 depends on !IA64_HP_SIM 8 depends on !IA64_HP_SIM
8 depends on IA64 || X86 9 depends on IA64 || X86
@@ -48,7 +49,6 @@ config ACPI_BOOT
48 49
49config ACPI_INTERPRETER 50config ACPI_INTERPRETER
50 bool 51 bool
51 depends on !IA64_SGI_SN
52 default y 52 default y
53 53
54if ACPI_INTERPRETER 54if ACPI_INTERPRETER
@@ -79,6 +79,14 @@ config ACPI_SLEEP_PROC_FS
79 depends on ACPI_SLEEP && PROC_FS 79 depends on ACPI_SLEEP && PROC_FS
80 default y 80 default y
81 81
82config ACPI_SLEEP_PROC_SLEEP
83 bool "/proc/acpi/sleep (deprecated)"
84 depends on ACPI_SLEEP_PROC_FS
85 default n
86 ---help---
87 Create /proc/acpi/sleep
88 Deprecated by /sys/power/state
89
82config ACPI_AC 90config ACPI_AC
83 tristate "AC Adapter" 91 tristate "AC Adapter"
84 depends on X86 92 depends on X86
@@ -99,7 +107,6 @@ config ACPI_BATTERY
99 107
100config ACPI_BUTTON 108config ACPI_BUTTON
101 tristate "Button" 109 tristate "Button"
102 depends on !IA64_SGI_SN
103 default m 110 default m
104 help 111 help
105 This driver registers for events based on buttons, such as the 112 This driver registers for events based on buttons, such as the
@@ -111,7 +118,6 @@ config ACPI_BUTTON
111config ACPI_VIDEO 118config ACPI_VIDEO
112 tristate "Video" 119 tristate "Video"
113 depends on EXPERIMENTAL 120 depends on EXPERIMENTAL
114 depends on !IA64_SGI_SN
115 default m 121 default m
116 help 122 help
117 This driver implement the ACPI Extensions For Display Adapters 123 This driver implement the ACPI Extensions For Display Adapters
@@ -122,9 +128,17 @@ config ACPI_VIDEO
122 Note that this is an ref. implementation only. It may or may not work 128 Note that this is an ref. implementation only. It may or may not work
123 for your integrated video device. 129 for your integrated video device.
124 130
131config ACPI_HOTKEY
132 tristate "Generic Hotkey"
133 depends on ACPI_INTERPRETER
134 depends on EXPERIMENTAL
135 depends on !IA64_SGI_SN
136 default m
137 help
138 ACPI generic hotkey
139
125config ACPI_FAN 140config ACPI_FAN
126 tristate "Fan" 141 tristate "Fan"
127 depends on !IA64_SGI_SN
128 default m 142 default m
129 help 143 help
130 This driver adds support for ACPI fan devices, allowing user-mode 144 This driver adds support for ACPI fan devices, allowing user-mode
@@ -132,7 +146,6 @@ config ACPI_FAN
132 146
133config ACPI_PROCESSOR 147config ACPI_PROCESSOR
134 tristate "Processor" 148 tristate "Processor"
135 depends on !IA64_SGI_SN
136 default m 149 default m
137 help 150 help
138 This driver installs ACPI as the idle handler for Linux, and uses 151 This driver installs ACPI as the idle handler for Linux, and uses
@@ -142,7 +155,6 @@ config ACPI_PROCESSOR
142config ACPI_HOTPLUG_CPU 155config ACPI_HOTPLUG_CPU
143 bool "Processor Hotplug (EXPERIMENTAL)" 156 bool "Processor Hotplug (EXPERIMENTAL)"
144 depends on ACPI_PROCESSOR && HOTPLUG_CPU && EXPERIMENTAL 157 depends on ACPI_PROCESSOR && HOTPLUG_CPU && EXPERIMENTAL
145 depends on !IA64_SGI_SN
146 select ACPI_CONTAINER 158 select ACPI_CONTAINER
147 default n 159 default n
148 ---help--- 160 ---help---
@@ -262,7 +274,6 @@ config ACPI_BLACKLIST_YEAR
262 274
263config ACPI_DEBUG 275config ACPI_DEBUG
264 bool "Debug Statements" 276 bool "Debug Statements"
265 depends on !IA64_SGI_SN
266 default n 277 default n
267 help 278 help
268 The ACPI driver can optionally report errors with a great deal 279 The ACPI driver can optionally report errors with a great deal
@@ -271,7 +282,6 @@ config ACPI_DEBUG
271 282
272config ACPI_BUS 283config ACPI_BUS
273 bool 284 bool
274 depends on !IA64_SGI_SN
275 default y 285 default y
276 286
277config ACPI_EC 287config ACPI_EC
@@ -285,17 +295,14 @@ config ACPI_EC
285 295
286config ACPI_POWER 296config ACPI_POWER
287 bool 297 bool
288 depends on !IA64_SGI_SN
289 default y 298 default y
290 299
291config ACPI_PCI 300config ACPI_PCI
292 bool 301 bool
293 depends on !IA64_SGI_SN
294 default PCI 302 default PCI
295 303
296config ACPI_SYSTEM 304config ACPI_SYSTEM
297 bool 305 bool
298 depends on !IA64_SGI_SN
299 default y 306 default y
300 help 307 help
301 This driver will enable your system to shut down using ACPI, and 308 This driver will enable your system to shut down using ACPI, and
@@ -327,8 +334,13 @@ config ACPI_CONTAINER
327 depends on EXPERIMENTAL 334 depends on EXPERIMENTAL
328 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO) 335 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO)
329 ---help--- 336 ---help---
330 This is the ACPI generic container driver which supports 337 This allows _physical_ insertion and removal of CPUs and memory.
331 ACPI0004, PNP0A05 and PNP0A06 devices 338 This can be useful, for example, on NUMA machines that support
339 ACPI based physical hotplug of nodes, or non-NUMA machines that
340 support physical cpu/memory hot-plug.
341
342 If one selects "m", this driver can be loaded with
343 "modprobe acpi_container".
332 344
333config ACPI_HOTPLUG_MEMORY 345config ACPI_HOTPLUG_MEMORY
334 tristate "Memory Hotplug" 346 tristate "Memory Hotplug"
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 65c92e20566d..ad67e8f61e6c 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -36,13 +36,14 @@ processor-objs += processor_perflib.o
36endif 36endif
37 37
38obj-$(CONFIG_ACPI_BUS) += sleep/ 38obj-$(CONFIG_ACPI_BUS) += sleep/
39obj-$(CONFIG_ACPI_BUS) += bus.o 39obj-$(CONFIG_ACPI_BUS) += bus.o glue.o
40obj-$(CONFIG_ACPI_AC) += ac.o 40obj-$(CONFIG_ACPI_AC) += ac.o
41obj-$(CONFIG_ACPI_BATTERY) += battery.o 41obj-$(CONFIG_ACPI_BATTERY) += battery.o
42obj-$(CONFIG_ACPI_BUTTON) += button.o 42obj-$(CONFIG_ACPI_BUTTON) += button.o
43obj-$(CONFIG_ACPI_EC) += ec.o 43obj-$(CONFIG_ACPI_EC) += ec.o
44obj-$(CONFIG_ACPI_FAN) += fan.o 44obj-$(CONFIG_ACPI_FAN) += fan.o
45obj-$(CONFIG_ACPI_VIDEO) += video.o 45obj-$(CONFIG_ACPI_VIDEO) += video.o
46obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
46obj-$(CONFIG_ACPI_PCI) += pci_root.o pci_link.o pci_irq.o pci_bind.o 47obj-$(CONFIG_ACPI_PCI) += pci_root.o pci_link.o pci_irq.o pci_bind.o
47obj-$(CONFIG_ACPI_POWER) += power.o 48obj-$(CONFIG_ACPI_POWER) += power.o
48obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 49obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index a75cb565caeb..a560b1e2da77 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -1204,6 +1204,10 @@ static int __init asus_acpi_init(void)
1204 if (acpi_disabled) 1204 if (acpi_disabled)
1205 return -ENODEV; 1205 return -ENODEV;
1206 1206
1207 if (!acpi_specific_hotkey_enabled){
1208 printk(KERN_ERR "Using generic hotkey driver\n");
1209 return -ENODEV;
1210 }
1207 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); 1211 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1208 if (!asus_proc_dir) { 1212 if (!asus_proc_dir) {
1209 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); 1213 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 4edff1738579..d77c2307883c 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -212,6 +212,12 @@ acpi_bus_set_power (
212 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device is not power manageable\n")); 212 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device is not power manageable\n"));
213 return_VALUE(-ENODEV); 213 return_VALUE(-ENODEV);
214 } 214 }
215 /*
216 * Get device's current power state if it's unknown
217 * This means device power state isn't initialized or previous setting failed
218 */
219 if (device->power.state == ACPI_STATE_UNKNOWN)
220 acpi_bus_get_power(device->handle, &device->power.state);
215 if (state == device->power.state) { 221 if (state == device->power.state) {
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state)); 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state));
217 return_VALUE(0); 223 return_VALUE(0);
@@ -231,7 +237,7 @@ acpi_bus_set_power (
231 * On transitions to a high-powered state we first apply power (via 237 * On transitions to a high-powered state we first apply power (via
232 * power resources) then evalute _PSx. Conversly for transitions to 238 * power resources) then evalute _PSx. Conversly for transitions to
233 * a lower-powered state. 239 * a lower-powered state.
234 */ 240 */
235 if (state < device->power.state) { 241 if (state < device->power.state) {
236 if (device->power.flags.power_resources) { 242 if (device->power.flags.power_resources) {
237 result = acpi_power_transition(device, state); 243 result = acpi_power_transition(device, state);
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index ec4430e3053f..0f45d45f05a0 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -26,9 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_bus.h> 29#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 30#include <acpi/acpi_drivers.h>
34 31
@@ -36,9 +33,6 @@
36#define ACPI_BUTTON_COMPONENT 0x00080000 33#define ACPI_BUTTON_COMPONENT 0x00080000
37#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver" 34#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
38#define ACPI_BUTTON_CLASS "button" 35#define ACPI_BUTTON_CLASS "button"
39#define ACPI_BUTTON_FILE_INFO "info"
40#define ACPI_BUTTON_FILE_STATE "state"
41#define ACPI_BUTTON_TYPE_UNKNOWN 0x00
42#define ACPI_BUTTON_NOTIFY_STATUS 0x80 36#define ACPI_BUTTON_NOTIFY_STATUS 0x80
43 37
44#define ACPI_BUTTON_SUBCLASS_POWER "power" 38#define ACPI_BUTTON_SUBCLASS_POWER "power"
@@ -70,8 +64,6 @@ MODULE_LICENSE("GPL");
70 64
71static int acpi_button_add (struct acpi_device *device); 65static int acpi_button_add (struct acpi_device *device);
72static int acpi_button_remove (struct acpi_device *device, int type); 66static int acpi_button_remove (struct acpi_device *device, int type);
73static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
74static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
75 67
76static struct acpi_driver acpi_button_driver = { 68static struct acpi_driver acpi_button_driver = {
77 .name = ACPI_BUTTON_DRIVER_NAME, 69 .name = ACPI_BUTTON_DRIVER_NAME,
@@ -90,187 +82,6 @@ struct acpi_button {
90 unsigned long pushed; 82 unsigned long pushed;
91}; 83};
92 84
93static struct file_operations acpi_button_info_fops = {
94 .open = acpi_button_info_open_fs,
95 .read = seq_read,
96 .llseek = seq_lseek,
97 .release = single_release,
98};
99
100static struct file_operations acpi_button_state_fops = {
101 .open = acpi_button_state_open_fs,
102 .read = seq_read,
103 .llseek = seq_lseek,
104 .release = single_release,
105};
106/* --------------------------------------------------------------------------
107 FS Interface (/proc)
108 -------------------------------------------------------------------------- */
109
110static struct proc_dir_entry *acpi_button_dir;
111
112static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
113{
114 struct acpi_button *button = (struct acpi_button *) seq->private;
115
116 ACPI_FUNCTION_TRACE("acpi_button_info_seq_show");
117
118 if (!button || !button->device)
119 return_VALUE(0);
120
121 seq_printf(seq, "type: %s\n",
122 acpi_device_name(button->device));
123
124 return_VALUE(0);
125}
126
127static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
128{
129 return single_open(file, acpi_button_info_seq_show, PDE(inode)->data);
130}
131
132static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
133{
134 struct acpi_button *button = (struct acpi_button *) seq->private;
135 acpi_status status;
136 unsigned long state;
137
138 ACPI_FUNCTION_TRACE("acpi_button_state_seq_show");
139
140 if (!button || !button->device)
141 return_VALUE(0);
142
143 status = acpi_evaluate_integer(button->handle,"_LID",NULL,&state);
144 if (ACPI_FAILURE(status)) {
145 seq_printf(seq, "state: unsupported\n");
146 }
147 else{
148 seq_printf(seq, "state: %s\n", (state ? "open" : "closed"));
149 }
150
151 return_VALUE(0);
152}
153
154static int acpi_button_state_open_fs(struct inode *inode, struct file *file)
155{
156 return single_open(file, acpi_button_state_seq_show, PDE(inode)->data);
157}
158
159static int
160acpi_button_add_fs (
161 struct acpi_device *device)
162{
163 struct proc_dir_entry *entry = NULL;
164 struct acpi_button *button = NULL;
165
166 ACPI_FUNCTION_TRACE("acpi_button_add_fs");
167
168 if (!device || !acpi_driver_data(device))
169 return_VALUE(-EINVAL);
170
171 button = acpi_driver_data(device);
172
173 switch (button->type) {
174 case ACPI_BUTTON_TYPE_POWER:
175 case ACPI_BUTTON_TYPE_POWERF:
176 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER,
177 acpi_button_dir);
178 break;
179 case ACPI_BUTTON_TYPE_SLEEP:
180 case ACPI_BUTTON_TYPE_SLEEPF:
181 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP,
182 acpi_button_dir);
183 break;
184 case ACPI_BUTTON_TYPE_LID:
185 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID,
186 acpi_button_dir);
187 break;
188 }
189
190 if (!entry)
191 return_VALUE(-ENODEV);
192 entry->owner = THIS_MODULE;
193
194 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
195 if (!acpi_device_dir(device))
196 return_VALUE(-ENODEV);
197 acpi_device_dir(device)->owner = THIS_MODULE;
198
199 /* 'info' [R] */
200 entry = create_proc_entry(ACPI_BUTTON_FILE_INFO,
201 S_IRUGO, acpi_device_dir(device));
202 if (!entry)
203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
204 "Unable to create '%s' fs entry\n",
205 ACPI_BUTTON_FILE_INFO));
206 else {
207 entry->proc_fops = &acpi_button_info_fops;
208 entry->data = acpi_driver_data(device);
209 entry->owner = THIS_MODULE;
210 }
211
212 /* show lid state [R] */
213 if (button->type == ACPI_BUTTON_TYPE_LID) {
214 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE,
215 S_IRUGO, acpi_device_dir(device));
216 if (!entry)
217 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
218 "Unable to create '%s' fs entry\n",
219 ACPI_BUTTON_FILE_INFO));
220 else {
221 entry->proc_fops = &acpi_button_state_fops;
222 entry->data = acpi_driver_data(device);
223 entry->owner = THIS_MODULE;
224 }
225 }
226
227 return_VALUE(0);
228}
229
230
231static int
232acpi_button_remove_fs (
233 struct acpi_device *device)
234{
235 struct acpi_button *button = NULL;
236
237 ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
238
239 button = acpi_driver_data(device);
240 if (acpi_device_dir(device)) {
241 if (button->type == ACPI_BUTTON_TYPE_LID)
242 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
243 acpi_device_dir(device));
244 remove_proc_entry(ACPI_BUTTON_FILE_INFO,
245 acpi_device_dir(device));
246
247 remove_proc_entry(acpi_device_bid(device),
248 acpi_device_dir(device)->parent);
249
250
251 switch (button->type) {
252 case ACPI_BUTTON_TYPE_POWER:
253 case ACPI_BUTTON_TYPE_POWERF:
254 remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER,
255 acpi_button_dir);
256 break;
257 case ACPI_BUTTON_TYPE_SLEEP:
258 case ACPI_BUTTON_TYPE_SLEEPF:
259 remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP,
260 acpi_button_dir);
261 break;
262 case ACPI_BUTTON_TYPE_LID:
263 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID,
264 acpi_button_dir);
265 break;
266 }
267 acpi_device_dir(device) = NULL;
268 }
269
270 return_VALUE(0);
271}
272
273
274/* -------------------------------------------------------------------------- 85/* --------------------------------------------------------------------------
275 Driver Interface 86 Driver Interface
276 -------------------------------------------------------------------------- */ 87 -------------------------------------------------------------------------- */
@@ -310,8 +121,7 @@ acpi_button_notify_fixed (
310 121
311 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed"); 122 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
312 123
313 if (!button) 124 BUG_ON(!button);
314 return_ACPI_STATUS(AE_BAD_PARAMETER);
315 125
316 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 126 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
317 127
@@ -327,10 +137,6 @@ acpi_button_add (
327 acpi_status status = AE_OK; 137 acpi_status status = AE_OK;
328 struct acpi_button *button = NULL; 138 struct acpi_button *button = NULL;
329 139
330 static struct acpi_device *power_button;
331 static struct acpi_device *sleep_button;
332 static struct acpi_device *lid_button;
333
334 ACPI_FUNCTION_TRACE("acpi_button_add"); 140 ACPI_FUNCTION_TRACE("acpi_button_add");
335 141
336 if (!device) 142 if (!device)
@@ -391,42 +197,6 @@ acpi_button_add (
391 goto end; 197 goto end;
392 } 198 }
393 199
394 /*
395 * Ensure only one button of each type is used.
396 */
397 switch (button->type) {
398 case ACPI_BUTTON_TYPE_POWER:
399 case ACPI_BUTTON_TYPE_POWERF:
400 if (!power_button)
401 power_button = device;
402 else {
403 kfree(button);
404 return_VALUE(-ENODEV);
405 }
406 break;
407 case ACPI_BUTTON_TYPE_SLEEP:
408 case ACPI_BUTTON_TYPE_SLEEPF:
409 if (!sleep_button)
410 sleep_button = device;
411 else {
412 kfree(button);
413 return_VALUE(-ENODEV);
414 }
415 break;
416 case ACPI_BUTTON_TYPE_LID:
417 if (!lid_button)
418 lid_button = device;
419 else {
420 kfree(button);
421 return_VALUE(-ENODEV);
422 }
423 break;
424 }
425
426 result = acpi_button_add_fs(device);
427 if (result)
428 goto end;
429
430 switch (button->type) { 200 switch (button->type) {
431 case ACPI_BUTTON_TYPE_POWERF: 201 case ACPI_BUTTON_TYPE_POWERF:
432 status = acpi_install_fixed_event_handler ( 202 status = acpi_install_fixed_event_handler (
@@ -470,7 +240,6 @@ acpi_button_add (
470 240
471end: 241end:
472 if (result) { 242 if (result) {
473 acpi_button_remove_fs(device);
474 kfree(button); 243 kfree(button);
475 } 244 }
476 245
@@ -511,8 +280,6 @@ acpi_button_remove (struct acpi_device *device, int type)
511 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 280 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
512 "Error removing notify handler\n")); 281 "Error removing notify handler\n"));
513 282
514 acpi_button_remove_fs(device);
515
516 kfree(button); 283 kfree(button);
517 284
518 return_VALUE(0); 285 return_VALUE(0);
@@ -526,21 +293,14 @@ acpi_button_init (void)
526 293
527 ACPI_FUNCTION_TRACE("acpi_button_init"); 294 ACPI_FUNCTION_TRACE("acpi_button_init");
528 295
529 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
530 if (!acpi_button_dir)
531 return_VALUE(-ENODEV);
532 acpi_button_dir->owner = THIS_MODULE;
533
534 result = acpi_bus_register_driver(&acpi_button_driver); 296 result = acpi_bus_register_driver(&acpi_button_driver);
535 if (result < 0) { 297 if (result < 0) {
536 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
537 return_VALUE(-ENODEV); 298 return_VALUE(-ENODEV);
538 } 299 }
539 300
540 return_VALUE(0); 301 return_VALUE(0);
541} 302}
542 303
543
544static void __exit 304static void __exit
545acpi_button_exit (void) 305acpi_button_exit (void)
546{ 306{
@@ -548,11 +308,8 @@ acpi_button_exit (void)
548 308
549 acpi_bus_unregister_driver(&acpi_button_driver); 309 acpi_bus_unregister_driver(&acpi_button_driver);
550 310
551 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
552
553 return_VOID; 311 return_VOID;
554} 312}
555 313
556
557module_init(acpi_button_init); 314module_init(acpi_button_init);
558module_exit(acpi_button_exit); 315module_exit(acpi_button_exit);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 5a0adbf8bc04..97013ddfa202 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -153,7 +153,7 @@ container_device_add(struct acpi_device **device, acpi_handle handle)
153 return_VALUE(-ENODEV); 153 return_VALUE(-ENODEV);
154 } 154 }
155 155
156 result = acpi_bus_scan(*device); 156 result = acpi_bus_start(*device);
157 157
158 return_VALUE(result); 158 return_VALUE(result);
159} 159}
diff --git a/drivers/acpi/dispatcher/dsfield.c b/drivers/acpi/dispatcher/dsfield.c
index 2779211be756..84193983d6ba 100644
--- a/drivers/acpi/dispatcher/dsfield.c
+++ b/drivers/acpi/dispatcher/dsfield.c
@@ -53,13 +53,20 @@
53#define _COMPONENT ACPI_DISPATCHER 53#define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dsfield") 54 ACPI_MODULE_NAME ("dsfield")
55 55
56/* Local prototypes */
57
58static acpi_status
59acpi_ds_get_field_names (
60 struct acpi_create_field_info *info,
61 struct acpi_walk_state *walk_state,
62 union acpi_parse_object *arg);
63
56 64
57/******************************************************************************* 65/*******************************************************************************
58 * 66 *
59 * FUNCTION: acpi_ds_create_buffer_field 67 * FUNCTION: acpi_ds_create_buffer_field
60 * 68 *
61 * PARAMETERS: Opcode - The opcode to be executed 69 * PARAMETERS: Op - Current parse op (create_xXField)
62 * Operands - List of operands for the opcode
63 * walk_state - Current state 70 * walk_state - Current state
64 * 71 *
65 * RETURN: Status 72 * RETURN: Status
@@ -70,7 +77,7 @@
70 * create_word_field_op, 77 * create_word_field_op,
71 * create_dword_field_op, 78 * create_dword_field_op,
72 * create_qword_field_op, 79 * create_qword_field_op,
73 * create_field_op (all of which define fields in buffers) 80 * create_field_op (all of which define a field in a buffer)
74 * 81 *
75 ******************************************************************************/ 82 ******************************************************************************/
76 83
@@ -119,7 +126,8 @@ acpi_ds_create_buffer_field (
119 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE; 126 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
120 } 127 }
121 else { 128 else {
122 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND; 129 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
130 ACPI_NS_ERROR_IF_FOUND;
123 } 131 }
124 132
125 /* 133 /*
@@ -134,16 +142,16 @@ acpi_ds_create_buffer_field (
134 } 142 }
135 } 143 }
136 144
137 /* We could put the returned object (Node) on the object stack for later, but 145 /* We could put the returned object (Node) on the object stack for later,
138 * for now, we will put it in the "op" object that the parser uses, so we 146 * but for now, we will put it in the "op" object that the parser uses,
139 * can get it again at the end of this scope 147 * so we can get it again at the end of this scope
140 */ 148 */
141 op->common.node = node; 149 op->common.node = node;
142 150
143 /* 151 /*
144 * If there is no object attached to the node, this node was just created and 152 * If there is no object attached to the node, this node was just created
145 * we need to create the field object. Otherwise, this was a lookup of an 153 * and we need to create the field object. Otherwise, this was a lookup
146 * existing node and we don't want to create the field object again. 154 * of an existing node and we don't want to create the field object again.
147 */ 155 */
148 obj_desc = acpi_ns_get_attached_object (node); 156 obj_desc = acpi_ns_get_attached_object (node);
149 if (obj_desc) { 157 if (obj_desc) {
@@ -205,7 +213,7 @@ cleanup:
205 * 213 *
206 ******************************************************************************/ 214 ******************************************************************************/
207 215
208acpi_status 216static acpi_status
209acpi_ds_get_field_names ( 217acpi_ds_get_field_names (
210 struct acpi_create_field_info *info, 218 struct acpi_create_field_info *info,
211 struct acpi_walk_state *walk_state, 219 struct acpi_walk_state *walk_state,
@@ -238,7 +246,8 @@ acpi_ds_get_field_names (
238 + (acpi_integer) arg->common.value.size; 246 + (acpi_integer) arg->common.value.size;
239 247
240 if (position > ACPI_UINT32_MAX) { 248 if (position > ACPI_UINT32_MAX) {
241 ACPI_REPORT_ERROR (("Bit offset within field too large (> 0xFFFFFFFF)\n")); 249 ACPI_REPORT_ERROR ((
250 "Bit offset within field too large (> 0xFFFFFFFF)\n"));
242 return_ACPI_STATUS (AE_SUPPORT); 251 return_ACPI_STATUS (AE_SUPPORT);
243 } 252 }
244 253
@@ -250,12 +259,15 @@ acpi_ds_get_field_names (
250 259
251 /* 260 /*
252 * Get a new access_type and access_attribute -- to be used for all 261 * Get a new access_type and access_attribute -- to be used for all
253 * field units that follow, until field end or another access_as keyword. 262 * field units that follow, until field end or another access_as
263 * keyword.
254 * 264 *
255 * In field_flags, preserve the flag bits other than the ACCESS_TYPE bits 265 * In field_flags, preserve the flag bits other than the
266 * ACCESS_TYPE bits
256 */ 267 */
257 info->field_flags = (u8) ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) | 268 info->field_flags = (u8)
258 ((u8) ((u32) arg->common.value.integer >> 8))); 269 ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
270 ((u8) ((u32) arg->common.value.integer >> 8)));
259 271
260 info->attribute = (u8) (arg->common.value.integer); 272 info->attribute = (u8) (arg->common.value.integer);
261 break; 273 break;
@@ -267,7 +279,8 @@ acpi_ds_get_field_names (
267 279
268 status = acpi_ns_lookup (walk_state->scope_info, 280 status = acpi_ns_lookup (walk_state->scope_info,
269 (char *) &arg->named.name, 281 (char *) &arg->named.name,
270 info->field_type, ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE, 282 info->field_type, ACPI_IMODE_EXECUTE,
283 ACPI_NS_DONT_OPEN_SCOPE,
271 walk_state, &info->field_node); 284 walk_state, &info->field_node);
272 if (ACPI_FAILURE (status)) { 285 if (ACPI_FAILURE (status)) {
273 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status); 286 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
@@ -295,8 +308,9 @@ acpi_ds_get_field_names (
295 + (acpi_integer) arg->common.value.size; 308 + (acpi_integer) arg->common.value.size;
296 309
297 if (position > ACPI_UINT32_MAX) { 310 if (position > ACPI_UINT32_MAX) {
298 ACPI_REPORT_ERROR (("Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n", 311 ACPI_REPORT_ERROR ((
299 (char *) &info->field_node->name)); 312 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n",
313 (char *) &info->field_node->name));
300 return_ACPI_STATUS (AE_SUPPORT); 314 return_ACPI_STATUS (AE_SUPPORT);
301 } 315 }
302 316
@@ -306,7 +320,8 @@ acpi_ds_get_field_names (
306 320
307 default: 321 default:
308 322
309 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid opcode in field list: %X\n", 323 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
324 "Invalid opcode in field list: %X\n",
310 arg->common.aml_opcode)); 325 arg->common.aml_opcode));
311 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 326 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
312 } 327 }
@@ -435,7 +450,8 @@ acpi_ds_init_field_objects (
435 status = acpi_ns_lookup (walk_state->scope_info, 450 status = acpi_ns_lookup (walk_state->scope_info,
436 (char *) &arg->named.name, 451 (char *) &arg->named.name,
437 type, ACPI_IMODE_LOAD_PASS1, 452 type, ACPI_IMODE_LOAD_PASS1,
438 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, 453 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
454 ACPI_NS_ERROR_IF_FOUND,
439 walk_state, &node); 455 walk_state, &node);
440 if (ACPI_FAILURE (status)) { 456 if (ACPI_FAILURE (status)) {
441 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status); 457 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index b4d264dbbf67..d7790db50178 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -49,12 +49,21 @@
49#define _COMPONENT ACPI_DISPATCHER 49#define _COMPONENT ACPI_DISPATCHER
50 ACPI_MODULE_NAME ("dsinit") 50 ACPI_MODULE_NAME ("dsinit")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ds_init_one_object (
56 acpi_handle obj_handle,
57 u32 level,
58 void *context,
59 void **return_value);
60
52 61
53/******************************************************************************* 62/*******************************************************************************
54 * 63 *
55 * FUNCTION: acpi_ds_init_one_object 64 * FUNCTION: acpi_ds_init_one_object
56 * 65 *
57 * PARAMETERS: obj_handle - Node 66 * PARAMETERS: obj_handle - Node for the object
58 * Level - Current nesting level 67 * Level - Current nesting level
59 * Context - Points to a init info struct 68 * Context - Points to a init info struct
60 * return_value - Not used 69 * return_value - Not used
@@ -70,7 +79,7 @@
70 * 79 *
71 ******************************************************************************/ 80 ******************************************************************************/
72 81
73acpi_status 82static acpi_status
74acpi_ds_init_one_object ( 83acpi_ds_init_one_object (
75 acpi_handle obj_handle, 84 acpi_handle obj_handle,
76 u32 level, 85 u32 level,
@@ -105,7 +114,8 @@ acpi_ds_init_one_object (
105 114
106 status = acpi_ds_initialize_region (obj_handle); 115 status = acpi_ds_initialize_region (obj_handle);
107 if (ACPI_FAILURE (status)) { 116 if (ACPI_FAILURE (status)) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region %p [%4.4s] - Init failure, %s\n", 117 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
118 "Region %p [%4.4s] - Init failure, %s\n",
109 obj_handle, acpi_ut_get_node_name (obj_handle), 119 obj_handle, acpi_ut_get_node_name (obj_handle),
110 acpi_format_exception (status))); 120 acpi_format_exception (status)));
111 } 121 }
@@ -118,8 +128,10 @@ acpi_ds_init_one_object (
118 128
119 info->method_count++; 129 info->method_count++;
120 130
121 /* Print a dot for each method unless we are going to print the entire pathname */ 131 /*
122 132 * Print a dot for each method unless we are going to print
133 * the entire pathname
134 */
123 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { 135 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
124 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, ".")); 136 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
125 } 137 }
@@ -140,7 +152,8 @@ acpi_ds_init_one_object (
140 */ 152 */
141 status = acpi_ds_parse_method (obj_handle); 153 status = acpi_ds_parse_method (obj_handle);
142 if (ACPI_FAILURE (status)) { 154 if (ACPI_FAILURE (status)) {
143 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Method %p [%4.4s] - parse failure, %s\n", 155 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
156 "Method %p [%4.4s] - parse failure, %s\n",
144 obj_handle, acpi_ut_get_node_name (obj_handle), 157 obj_handle, acpi_ut_get_node_name (obj_handle),
145 acpi_format_exception (status))); 158 acpi_format_exception (status)));
146 159
@@ -154,7 +167,8 @@ acpi_ds_init_one_object (
154 * for every execution since there isn't much overhead 167 * for every execution since there isn't much overhead
155 */ 168 */
156 acpi_ns_delete_namespace_subtree (obj_handle); 169 acpi_ns_delete_namespace_subtree (obj_handle);
157 acpi_ns_delete_namespace_by_owner (((struct acpi_namespace_node *) obj_handle)->object->method.owning_id); 170 acpi_ns_delete_namespace_by_owner (
171 ((struct acpi_namespace_node *) obj_handle)->object->method.owning_id);
158 break; 172 break;
159 173
160 174
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 9f0456cb9bb5..9fc3f4c033eb 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -153,12 +153,11 @@ acpi_ds_parse_method (
153 /* 153 /*
154 * Parse the method, first pass 154 * Parse the method, first pass
155 * 155 *
156 * The first pass load is where newly declared named objects are 156 * The first pass load is where newly declared named objects are added into
157 * added into the namespace. Actual evaluation of 157 * the namespace. Actual evaluation of the named objects (what would be
158 * the named objects (what would be called a "second 158 * called a "second pass") happens during the actual execution of the
159 * pass") happens during the actual execution of the 159 * method so that operands to the named objects can take on dynamic
160 * method so that operands to the named objects can 160 * run-time values.
161 * take on dynamic run-time values.
162 */ 161 */
163 status = acpi_ps_parse_aml (walk_state); 162 status = acpi_ps_parse_aml (walk_state);
164 if (ACPI_FAILURE (status)) { 163 if (ACPI_FAILURE (status)) {
diff --git a/drivers/acpi/dispatcher/dsmthdat.c b/drivers/acpi/dispatcher/dsmthdat.c
index f31d095f9833..f7998306f756 100644
--- a/drivers/acpi/dispatcher/dsmthdat.c
+++ b/drivers/acpi/dispatcher/dsmthdat.c
@@ -52,6 +52,29 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME ("dsmthdat") 53 ACPI_MODULE_NAME ("dsmthdat")
54 54
55/* Local prototypes */
56
57static void
58acpi_ds_method_data_delete_value (
59 u16 opcode,
60 u32 index,
61 struct acpi_walk_state *walk_state);
62
63static acpi_status
64acpi_ds_method_data_set_value (
65 u16 opcode,
66 u32 index,
67 union acpi_operand_object *object,
68 struct acpi_walk_state *walk_state);
69
70#ifdef ACPI_OBSOLETE_FUNCTIONS
71acpi_object_type
72acpi_ds_method_data_get_type (
73 u16 opcode,
74 u32 index,
75 struct acpi_walk_state *walk_state);
76#endif
77
55 78
56/******************************************************************************* 79/*******************************************************************************
57 * 80 *
@@ -62,8 +85,8 @@
62 * RETURN: Status 85 * RETURN: Status
63 * 86 *
64 * DESCRIPTION: Initialize the data structures that hold the method's arguments 87 * DESCRIPTION: Initialize the data structures that hold the method's arguments
65 * and locals. The data struct is an array of NTEs for each. 88 * and locals. The data struct is an array of namespace nodes for
66 * This allows ref_of and de_ref_of to work properly for these 89 * each - this allows ref_of and de_ref_of to work properly for these
67 * special data types. 90 * special data types.
68 * 91 *
69 * NOTES: walk_state fields are initialized to zero by the 92 * NOTES: walk_state fields are initialized to zero by the
@@ -92,7 +115,8 @@ acpi_ds_method_data_init (
92 walk_state->arguments[i].name.integer |= (i << 24); 115 walk_state->arguments[i].name.integer |= (i << 24);
93 walk_state->arguments[i].descriptor = ACPI_DESC_TYPE_NAMED; 116 walk_state->arguments[i].descriptor = ACPI_DESC_TYPE_NAMED;
94 walk_state->arguments[i].type = ACPI_TYPE_ANY; 117 walk_state->arguments[i].type = ACPI_TYPE_ANY;
95 walk_state->arguments[i].flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 118 walk_state->arguments[i].flags = ANOBJ_END_OF_PEER_LIST |
119 ANOBJ_METHOD_ARG;
96 } 120 }
97 121
98 /* Init the method locals */ 122 /* Init the method locals */
@@ -104,7 +128,8 @@ acpi_ds_method_data_init (
104 walk_state->local_variables[i].name.integer |= (i << 24); 128 walk_state->local_variables[i].name.integer |= (i << 24);
105 walk_state->local_variables[i].descriptor = ACPI_DESC_TYPE_NAMED; 129 walk_state->local_variables[i].descriptor = ACPI_DESC_TYPE_NAMED;
106 walk_state->local_variables[i].type = ACPI_TYPE_ANY; 130 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
107 walk_state->local_variables[i].flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 131 walk_state->local_variables[i].flags = ANOBJ_END_OF_PEER_LIST |
132 ANOBJ_METHOD_LOCAL;
108 } 133 }
109 134
110 return_VOID; 135 return_VOID;
@@ -198,15 +223,18 @@ acpi_ds_method_data_init_args (
198 return_ACPI_STATUS (AE_OK); 223 return_ACPI_STATUS (AE_OK);
199 } 224 }
200 225
201 /* Copy passed parameters into the new method stack frame */ 226 /* Copy passed parameters into the new method stack frame */
202 227
203 while ((index < ACPI_METHOD_NUM_ARGS) && (index < max_param_count) && params[index]) { 228 while ((index < ACPI_METHOD_NUM_ARGS) &&
229 (index < max_param_count) &&
230 params[index]) {
204 /* 231 /*
205 * A valid parameter. 232 * A valid parameter.
206 * Store the argument in the method/walk descriptor. 233 * Store the argument in the method/walk descriptor.
207 * Do not copy the arg in order to implement call by reference 234 * Do not copy the arg in order to implement call by reference
208 */ 235 */
209 status = acpi_ds_method_data_set_value (AML_ARG_OP, index, params[index], walk_state); 236 status = acpi_ds_method_data_set_value (AML_ARG_OP, index,
237 params[index], walk_state);
210 if (ACPI_FAILURE (status)) { 238 if (ACPI_FAILURE (status)) {
211 return_ACPI_STATUS (status); 239 return_ACPI_STATUS (status);
212 } 240 }
@@ -224,11 +252,13 @@ acpi_ds_method_data_init_args (
224 * FUNCTION: acpi_ds_method_data_get_node 252 * FUNCTION: acpi_ds_method_data_get_node
225 * 253 *
226 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 254 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
227 * Index - which local_var or argument whose type 255 * Index - Which Local or Arg whose type to get
228 * to get
229 * walk_state - Current walk state object 256 * walk_state - Current walk state object
257 * Node - Where the node is returned.
230 * 258 *
231 * RETURN: Get the Node associated with a local or arg. 259 * RETURN: Status and node
260 *
261 * DESCRIPTION: Get the Node associated with a local or arg.
232 * 262 *
233 ******************************************************************************/ 263 ******************************************************************************/
234 264
@@ -249,7 +279,8 @@ acpi_ds_method_data_get_node (
249 case AML_LOCAL_OP: 279 case AML_LOCAL_OP:
250 280
251 if (index > ACPI_METHOD_MAX_LOCAL) { 281 if (index > ACPI_METHOD_MAX_LOCAL) {
252 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n", 282 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
283 "Local index %d is invalid (max %d)\n",
253 index, ACPI_METHOD_MAX_LOCAL)); 284 index, ACPI_METHOD_MAX_LOCAL));
254 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 285 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
255 } 286 }
@@ -262,7 +293,8 @@ acpi_ds_method_data_get_node (
262 case AML_ARG_OP: 293 case AML_ARG_OP:
263 294
264 if (index > ACPI_METHOD_MAX_ARG) { 295 if (index > ACPI_METHOD_MAX_ARG) {
265 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n", 296 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
297 "Arg index %d is invalid (max %d)\n",
266 index, ACPI_METHOD_MAX_ARG)); 298 index, ACPI_METHOD_MAX_ARG));
267 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 299 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
268 } 300 }
@@ -286,7 +318,7 @@ acpi_ds_method_data_get_node (
286 * FUNCTION: acpi_ds_method_data_set_value 318 * FUNCTION: acpi_ds_method_data_set_value
287 * 319 *
288 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 320 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
289 * Index - which local_var or argument to get 321 * Index - Which Local or Arg to get
290 * Object - Object to be inserted into the stack entry 322 * Object - Object to be inserted into the stack entry
291 * walk_state - Current walk state object 323 * walk_state - Current walk state object
292 * 324 *
@@ -297,7 +329,7 @@ acpi_ds_method_data_get_node (
297 * 329 *
298 ******************************************************************************/ 330 ******************************************************************************/
299 331
300acpi_status 332static acpi_status
301acpi_ds_method_data_set_value ( 333acpi_ds_method_data_set_value (
302 u16 opcode, 334 u16 opcode,
303 u32 index, 335 u32 index,
@@ -340,68 +372,16 @@ acpi_ds_method_data_set_value (
340 372
341/******************************************************************************* 373/*******************************************************************************
342 * 374 *
343 * FUNCTION: acpi_ds_method_data_get_type
344 *
345 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
346 * Index - which local_var or argument whose type
347 * to get
348 * walk_state - Current walk state object
349 *
350 * RETURN: Data type of current value of the selected Arg or Local
351 *
352 ******************************************************************************/
353#ifdef ACPI_FUTURE_USAGE
354acpi_object_type
355acpi_ds_method_data_get_type (
356 u16 opcode,
357 u32 index,
358 struct acpi_walk_state *walk_state)
359{
360 acpi_status status;
361 struct acpi_namespace_node *node;
362 union acpi_operand_object *object;
363
364
365 ACPI_FUNCTION_TRACE ("ds_method_data_get_type");
366
367
368 /* Get the namespace node for the arg/local */
369
370 status = acpi_ds_method_data_get_node (opcode, index, walk_state, &node);
371 if (ACPI_FAILURE (status)) {
372 return_VALUE ((ACPI_TYPE_NOT_FOUND));
373 }
374
375 /* Get the object */
376
377 object = acpi_ns_get_attached_object (node);
378 if (!object) {
379 /* Uninitialized local/arg, return TYPE_ANY */
380
381 return_VALUE (ACPI_TYPE_ANY);
382 }
383
384 /* Get the object type */
385
386 return_VALUE (ACPI_GET_OBJECT_TYPE (object));
387}
388#endif /* ACPI_FUTURE_USAGE */
389
390
391/*******************************************************************************
392 *
393 * FUNCTION: acpi_ds_method_data_get_value 375 * FUNCTION: acpi_ds_method_data_get_value
394 * 376 *
395 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 377 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
396 * Index - which local_var or argument to get 378 * Index - which local_var or argument to get
397 * walk_state - Current walk state object 379 * walk_state - Current walk state object
398 * *dest_desc - Ptr to Descriptor into which selected Arg 380 * dest_desc - Where Arg or Local value is returned
399 * or Local value should be copied
400 * 381 *
401 * RETURN: Status 382 * RETURN: Status
402 * 383 *
403 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame 384 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
404 * at the current top of the method stack.
405 * Used only in acpi_ex_resolve_to_value(). 385 * Used only in acpi_ex_resolve_to_value().
406 * 386 *
407 ******************************************************************************/ 387 ******************************************************************************/
@@ -467,14 +447,16 @@ acpi_ds_method_data_get_value (
467 else switch (opcode) { 447 else switch (opcode) {
468 case AML_ARG_OP: 448 case AML_ARG_OP:
469 449
470 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n", 450 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
451 "Uninitialized Arg[%d] at node %p\n",
471 index, node)); 452 index, node));
472 453
473 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 454 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
474 455
475 case AML_LOCAL_OP: 456 case AML_LOCAL_OP:
476 457
477 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n", 458 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
459 "Uninitialized Local[%d] at node %p\n",
478 index, node)); 460 index, node));
479 461
480 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 462 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
@@ -506,12 +488,12 @@ acpi_ds_method_data_get_value (
506 * 488 *
507 * RETURN: None 489 * RETURN: None
508 * 490 *
509 * DESCRIPTION: Delete the entry at Opcode:Index on the method stack. Inserts 491 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
510 * a null into the stack slot after the object is deleted. 492 * a null into the stack slot after the object is deleted.
511 * 493 *
512 ******************************************************************************/ 494 ******************************************************************************/
513 495
514void 496static void
515acpi_ds_method_data_delete_value ( 497acpi_ds_method_data_delete_value (
516 u16 opcode, 498 u16 opcode,
517 u32 index, 499 u32 index,
@@ -562,7 +544,7 @@ acpi_ds_method_data_delete_value (
562 * FUNCTION: acpi_ds_store_object_to_local 544 * FUNCTION: acpi_ds_store_object_to_local
563 * 545 *
564 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 546 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
565 * Index - which local_var or argument to set 547 * Index - Which Local or Arg to set
566 * obj_desc - Value to be stored 548 * obj_desc - Value to be stored
567 * walk_state - Current walk state 549 * walk_state - Current walk state
568 * 550 *
@@ -651,19 +633,20 @@ acpi_ds_store_object_to_local (
651 */ 633 */
652 if (opcode == AML_ARG_OP) { 634 if (opcode == AML_ARG_OP) {
653 /* 635 /*
654 * Make sure that the object is the correct type. This may be overkill, but 636 * Make sure that the object is the correct type. This may be
655 * it is here because references were NS nodes in the past. Now they are 637 * overkill, butit is here because references were NS nodes in
656 * operand objects of type Reference. 638 * the past. Now they are operand objects of type Reference.
657 */ 639 */
658 if (ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) != ACPI_DESC_TYPE_OPERAND) { 640 if (ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) != ACPI_DESC_TYPE_OPERAND) {
659 ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: [%s]\n", 641 ACPI_REPORT_ERROR ((
660 acpi_ut_get_descriptor_name (current_obj_desc))); 642 "Invalid descriptor type while storing to method arg: [%s]\n",
643 acpi_ut_get_descriptor_name (current_obj_desc)));
661 return_ACPI_STATUS (AE_AML_INTERNAL); 644 return_ACPI_STATUS (AE_AML_INTERNAL);
662 } 645 }
663 646
664 /* 647 /*
665 * If we have a valid reference object that came from ref_of(), do the 648 * If we have a valid reference object that came from ref_of(),
666 * indirect store 649 * do the indirect store
667 */ 650 */
668 if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && 651 if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
669 (current_obj_desc->reference.opcode == AML_REF_OF_OP)) { 652 (current_obj_desc->reference.opcode == AML_REF_OF_OP)) {
@@ -713,3 +696,55 @@ acpi_ds_store_object_to_local (
713} 696}
714 697
715 698
699#ifdef ACPI_OBSOLETE_FUNCTIONS
700/*******************************************************************************
701 *
702 * FUNCTION: acpi_ds_method_data_get_type
703 *
704 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
705 * Index - Which Local or Arg whose type to get
706 * walk_state - Current walk state object
707 *
708 * RETURN: Data type of current value of the selected Arg or Local
709 *
710 * DESCRIPTION: Get the type of the object stored in the Local or Arg
711 *
712 ******************************************************************************/
713
714acpi_object_type
715acpi_ds_method_data_get_type (
716 u16 opcode,
717 u32 index,
718 struct acpi_walk_state *walk_state)
719{
720 acpi_status status;
721 struct acpi_namespace_node *node;
722 union acpi_operand_object *object;
723
724
725 ACPI_FUNCTION_TRACE ("ds_method_data_get_type");
726
727
728 /* Get the namespace node for the arg/local */
729
730 status = acpi_ds_method_data_get_node (opcode, index, walk_state, &node);
731 if (ACPI_FAILURE (status)) {
732 return_VALUE ((ACPI_TYPE_NOT_FOUND));
733 }
734
735 /* Get the object */
736
737 object = acpi_ns_get_attached_object (node);
738 if (!object) {
739 /* Uninitialized local/arg, return TYPE_ANY */
740
741 return_VALUE (ACPI_TYPE_ANY);
742 }
743
744 /* Get the object type */
745
746 return_VALUE (ACPI_GET_OBJECT_TYPE (object));
747}
748#endif
749
750
diff --git a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
index eb8af4785bcb..bfbae4e4c667 100644
--- a/drivers/acpi/dispatcher/dsobject.c
+++ b/drivers/acpi/dispatcher/dsobject.c
@@ -52,9 +52,15 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME ("dsobject") 53 ACPI_MODULE_NAME ("dsobject")
54 54
55static acpi_status
56acpi_ds_build_internal_object (
57 struct acpi_walk_state *walk_state,
58 union acpi_parse_object *op,
59 union acpi_operand_object **obj_desc_ptr);
60
55 61
56#ifndef ACPI_NO_METHOD_EXECUTION 62#ifndef ACPI_NO_METHOD_EXECUTION
57/***************************************************************************** 63/*******************************************************************************
58 * 64 *
59 * FUNCTION: acpi_ds_build_internal_object 65 * FUNCTION: acpi_ds_build_internal_object
60 * 66 *
@@ -67,9 +73,9 @@
67 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object 73 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
68 * Simple objects are any objects other than a package object! 74 * Simple objects are any objects other than a package object!
69 * 75 *
70 ****************************************************************************/ 76 ******************************************************************************/
71 77
72acpi_status 78static acpi_status
73acpi_ds_build_internal_object ( 79acpi_ds_build_internal_object (
74 struct acpi_walk_state *walk_state, 80 struct acpi_walk_state *walk_state,
75 union acpi_parse_object *op, 81 union acpi_parse_object *op,
@@ -90,9 +96,11 @@ acpi_ds_build_internal_object (
90 * Otherwise, go ahead and look it up now 96 * Otherwise, go ahead and look it up now
91 */ 97 */
92 if (!op->common.node) { 98 if (!op->common.node) {
93 status = acpi_ns_lookup (walk_state->scope_info, op->common.value.string, 99 status = acpi_ns_lookup (walk_state->scope_info,
100 op->common.value.string,
94 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 101 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
95 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, 102 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
103 NULL,
96 (struct acpi_namespace_node **) &(op->common.node)); 104 (struct acpi_namespace_node **) &(op->common.node));
97 105
98 if (ACPI_FAILURE (status)) { 106 if (ACPI_FAILURE (status)) {
@@ -104,12 +112,14 @@ acpi_ds_build_internal_object (
104 112
105 /* Create and init the internal ACPI object */ 113 /* Create and init the internal ACPI object */
106 114
107 obj_desc = acpi_ut_create_internal_object ((acpi_ps_get_opcode_info (op->common.aml_opcode))->object_type); 115 obj_desc = acpi_ut_create_internal_object (
116 (acpi_ps_get_opcode_info (op->common.aml_opcode))->object_type);
108 if (!obj_desc) { 117 if (!obj_desc) {
109 return_ACPI_STATUS (AE_NO_MEMORY); 118 return_ACPI_STATUS (AE_NO_MEMORY);
110 } 119 }
111 120
112 status = acpi_ds_init_object_from_op (walk_state, op, op->common.aml_opcode, &obj_desc); 121 status = acpi_ds_init_object_from_op (walk_state, op, op->common.aml_opcode,
122 &obj_desc);
113 if (ACPI_FAILURE (status)) { 123 if (ACPI_FAILURE (status)) {
114 acpi_ut_remove_reference (obj_desc); 124 acpi_ut_remove_reference (obj_desc);
115 return_ACPI_STATUS (status); 125 return_ACPI_STATUS (status);
@@ -120,7 +130,7 @@ acpi_ds_build_internal_object (
120} 130}
121 131
122 132
123/***************************************************************************** 133/*******************************************************************************
124 * 134 *
125 * FUNCTION: acpi_ds_build_internal_buffer_obj 135 * FUNCTION: acpi_ds_build_internal_buffer_obj
126 * 136 *
@@ -134,7 +144,7 @@ acpi_ds_build_internal_object (
134 * DESCRIPTION: Translate a parser Op package object to the equivalent 144 * DESCRIPTION: Translate a parser Op package object to the equivalent
135 * namespace object 145 * namespace object
136 * 146 *
137 ****************************************************************************/ 147 ******************************************************************************/
138 148
139acpi_status 149acpi_status
140acpi_ds_build_internal_buffer_obj ( 150acpi_ds_build_internal_buffer_obj (
@@ -229,7 +239,7 @@ acpi_ds_build_internal_buffer_obj (
229} 239}
230 240
231 241
232/***************************************************************************** 242/*******************************************************************************
233 * 243 *
234 * FUNCTION: acpi_ds_build_internal_package_obj 244 * FUNCTION: acpi_ds_build_internal_package_obj
235 * 245 *
@@ -243,7 +253,7 @@ acpi_ds_build_internal_buffer_obj (
243 * DESCRIPTION: Translate a parser Op package object to the equivalent 253 * DESCRIPTION: Translate a parser Op package object to the equivalent
244 * namespace object 254 * namespace object
245 * 255 *
246 ****************************************************************************/ 256 ******************************************************************************/
247 257
248acpi_status 258acpi_status
249acpi_ds_build_internal_package_obj ( 259acpi_ds_build_internal_package_obj (
@@ -331,11 +341,12 @@ acpi_ds_build_internal_package_obj (
331 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { 341 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
332 /* Object (package or buffer) is already built */ 342 /* Object (package or buffer) is already built */
333 343
334 obj_desc->package.elements[i] = ACPI_CAST_PTR (union acpi_operand_object, arg->common.node); 344 obj_desc->package.elements[i] =
345 ACPI_CAST_PTR (union acpi_operand_object, arg->common.node);
335 } 346 }
336 else { 347 else {
337 status = acpi_ds_build_internal_object (walk_state, arg, 348 status = acpi_ds_build_internal_object (walk_state, arg,
338 &obj_desc->package.elements[i]); 349 &obj_desc->package.elements[i]);
339 } 350 }
340 351
341 i++; 352 i++;
@@ -348,7 +359,7 @@ acpi_ds_build_internal_package_obj (
348} 359}
349 360
350 361
351/***************************************************************************** 362/*******************************************************************************
352 * 363 *
353 * FUNCTION: acpi_ds_create_node 364 * FUNCTION: acpi_ds_create_node
354 * 365 *
@@ -360,7 +371,7 @@ acpi_ds_build_internal_package_obj (
360 * 371 *
361 * DESCRIPTION: Create the object to be associated with a namespace node 372 * DESCRIPTION: Create the object to be associated with a namespace node
362 * 373 *
363 ****************************************************************************/ 374 ******************************************************************************/
364 375
365acpi_status 376acpi_status
366acpi_ds_create_node ( 377acpi_ds_create_node (
@@ -392,7 +403,8 @@ acpi_ds_create_node (
392 403
393 /* Build an internal object for the argument(s) */ 404 /* Build an internal object for the argument(s) */
394 405
395 status = acpi_ds_build_internal_object (walk_state, op->common.value.arg, &obj_desc); 406 status = acpi_ds_build_internal_object (walk_state, op->common.value.arg,
407 &obj_desc);
396 if (ACPI_FAILURE (status)) { 408 if (ACPI_FAILURE (status)) {
397 return_ACPI_STATUS (status); 409 return_ACPI_STATUS (status);
398 } 410 }
@@ -414,7 +426,7 @@ acpi_ds_create_node (
414#endif /* ACPI_NO_METHOD_EXECUTION */ 426#endif /* ACPI_NO_METHOD_EXECUTION */
415 427
416 428
417/***************************************************************************** 429/*******************************************************************************
418 * 430 *
419 * FUNCTION: acpi_ds_init_object_from_op 431 * FUNCTION: acpi_ds_init_object_from_op
420 * 432 *
@@ -429,7 +441,7 @@ acpi_ds_create_node (
429 * associated arguments. The namespace object is a more compact 441 * associated arguments. The namespace object is a more compact
430 * representation of the Op and its arguments. 442 * representation of the Op and its arguments.
431 * 443 *
432 ****************************************************************************/ 444 ******************************************************************************/
433 445
434acpi_status 446acpi_status
435acpi_ds_init_object_from_op ( 447acpi_ds_init_object_from_op (
@@ -462,7 +474,8 @@ acpi_ds_init_object_from_op (
462 /* 474 /*
463 * Defer evaluation of Buffer term_arg operand 475 * Defer evaluation of Buffer term_arg operand
464 */ 476 */
465 obj_desc->buffer.node = (struct acpi_namespace_node *) walk_state->operands[0]; 477 obj_desc->buffer.node = (struct acpi_namespace_node *)
478 walk_state->operands[0];
466 obj_desc->buffer.aml_start = op->named.data; 479 obj_desc->buffer.aml_start = op->named.data;
467 obj_desc->buffer.aml_length = op->named.length; 480 obj_desc->buffer.aml_length = op->named.length;
468 break; 481 break;
@@ -473,7 +486,8 @@ acpi_ds_init_object_from_op (
473 /* 486 /*
474 * Defer evaluation of Package term_arg operand 487 * Defer evaluation of Package term_arg operand
475 */ 488 */
476 obj_desc->package.node = (struct acpi_namespace_node *) walk_state->operands[0]; 489 obj_desc->package.node = (struct acpi_namespace_node *)
490 walk_state->operands[0];
477 obj_desc->package.aml_start = op->named.data; 491 obj_desc->package.aml_start = op->named.data;
478 obj_desc->package.aml_length = op->named.length; 492 obj_desc->package.aml_length = op->named.length;
479 break; 493 break;
@@ -486,9 +500,10 @@ acpi_ds_init_object_from_op (
486 /* 500 /*
487 * Resolve AML Constants here - AND ONLY HERE! 501 * Resolve AML Constants here - AND ONLY HERE!
488 * All constants are integers. 502 * All constants are integers.
489 * We mark the integer with a flag that indicates that it started life 503 * We mark the integer with a flag that indicates that it started
490 * as a constant -- so that stores to constants will perform as expected (noop). 504 * life as a constant -- so that stores to constants will perform
491 * (zero_op is used as a placeholder for optional target operands.) 505 * as expected (noop). zero_op is used as a placeholder for optional
506 * target operands.
492 */ 507 */
493 obj_desc->common.flags = AOPOBJ_AML_CONSTANT; 508 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
494 509
@@ -521,7 +536,8 @@ acpi_ds_init_object_from_op (
521 536
522 default: 537 default:
523 538
524 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown constant opcode %X\n", opcode)); 539 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
540 "Unknown constant opcode %X\n", opcode));
525 status = AE_AML_OPERAND_TYPE; 541 status = AE_AML_OPERAND_TYPE;
526 break; 542 break;
527 } 543 }
@@ -535,7 +551,8 @@ acpi_ds_init_object_from_op (
535 551
536 552
537 default: 553 default:
538 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n", op_info->type)); 554 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n",
555 op_info->type));
539 status = AE_AML_OPERAND_TYPE; 556 status = AE_AML_OPERAND_TYPE;
540 break; 557 break;
541 } 558 }
@@ -570,8 +587,10 @@ acpi_ds_init_object_from_op (
570 obj_desc->reference.offset = opcode - AML_LOCAL_OP; 587 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
571 588
572#ifndef ACPI_NO_METHOD_EXECUTION 589#ifndef ACPI_NO_METHOD_EXECUTION
573 status = acpi_ds_method_data_get_node (AML_LOCAL_OP, obj_desc->reference.offset, 590 status = acpi_ds_method_data_get_node (AML_LOCAL_OP,
574 walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object); 591 obj_desc->reference.offset,
592 walk_state,
593 (struct acpi_namespace_node **) &obj_desc->reference.object);
575#endif 594#endif
576 break; 595 break;
577 596
@@ -584,8 +603,10 @@ acpi_ds_init_object_from_op (
584 obj_desc->reference.offset = opcode - AML_ARG_OP; 603 obj_desc->reference.offset = opcode - AML_ARG_OP;
585 604
586#ifndef ACPI_NO_METHOD_EXECUTION 605#ifndef ACPI_NO_METHOD_EXECUTION
587 status = acpi_ds_method_data_get_node (AML_ARG_OP, obj_desc->reference.offset, 606 status = acpi_ds_method_data_get_node (AML_ARG_OP,
588 walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object); 607 obj_desc->reference.offset,
608 walk_state,
609 (struct acpi_namespace_node **) &obj_desc->reference.object);
589#endif 610#endif
590 break; 611 break;
591 612
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index 5c987a0e7b75..ba13bca28bee 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -54,12 +54,31 @@
54#define _COMPONENT ACPI_DISPATCHER 54#define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME ("dsopcode") 55 ACPI_MODULE_NAME ("dsopcode")
56 56
57/* Local prototypes */
57 58
58/***************************************************************************** 59static acpi_status
60acpi_ds_execute_arguments (
61 struct acpi_namespace_node *node,
62 struct acpi_namespace_node *scope_node,
63 u32 aml_length,
64 u8 *aml_start);
65
66static acpi_status
67acpi_ds_init_buffer_field (
68 u16 aml_opcode,
69 union acpi_operand_object *obj_desc,
70 union acpi_operand_object *buffer_desc,
71 union acpi_operand_object *offset_desc,
72 union acpi_operand_object *length_desc,
73 union acpi_operand_object *result_desc);
74
75
76/*******************************************************************************
59 * 77 *
60 * FUNCTION: acpi_ds_execute_arguments 78 * FUNCTION: acpi_ds_execute_arguments
61 * 79 *
62 * PARAMETERS: Node - Parent NS node 80 * PARAMETERS: Node - Object NS node
81 * scope_node - Parent NS node
63 * aml_length - Length of executable AML 82 * aml_length - Length of executable AML
64 * aml_start - Pointer to the AML 83 * aml_start - Pointer to the AML
65 * 84 *
@@ -67,9 +86,9 @@
67 * 86 *
68 * DESCRIPTION: Late (deferred) execution of region or field arguments 87 * DESCRIPTION: Late (deferred) execution of region or field arguments
69 * 88 *
70 ****************************************************************************/ 89 ******************************************************************************/
71 90
72acpi_status 91static acpi_status
73acpi_ds_execute_arguments ( 92acpi_ds_execute_arguments (
74 struct acpi_namespace_node *node, 93 struct acpi_namespace_node *node,
75 struct acpi_namespace_node *scope_node, 94 struct acpi_namespace_node *scope_node,
@@ -162,7 +181,7 @@ acpi_ds_execute_arguments (
162} 181}
163 182
164 183
165/***************************************************************************** 184/*******************************************************************************
166 * 185 *
167 * FUNCTION: acpi_ds_get_buffer_field_arguments 186 * FUNCTION: acpi_ds_get_buffer_field_arguments
168 * 187 *
@@ -173,7 +192,7 @@ acpi_ds_execute_arguments (
173 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late 192 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
174 * evaluation of these field attributes. 193 * evaluation of these field attributes.
175 * 194 *
176 ****************************************************************************/ 195 ******************************************************************************/
177 196
178acpi_status 197acpi_status
179acpi_ds_get_buffer_field_arguments ( 198acpi_ds_get_buffer_field_arguments (
@@ -208,7 +227,7 @@ acpi_ds_get_buffer_field_arguments (
208} 227}
209 228
210 229
211/***************************************************************************** 230/*******************************************************************************
212 * 231 *
213 * FUNCTION: acpi_ds_get_buffer_arguments 232 * FUNCTION: acpi_ds_get_buffer_arguments
214 * 233 *
@@ -219,7 +238,7 @@ acpi_ds_get_buffer_field_arguments (
219 * DESCRIPTION: Get Buffer length and initializer byte list. This implements 238 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
220 * the late evaluation of these attributes. 239 * the late evaluation of these attributes.
221 * 240 *
222 ****************************************************************************/ 241 ******************************************************************************/
223 242
224acpi_status 243acpi_status
225acpi_ds_get_buffer_arguments ( 244acpi_ds_get_buffer_arguments (
@@ -255,7 +274,7 @@ acpi_ds_get_buffer_arguments (
255} 274}
256 275
257 276
258/***************************************************************************** 277/*******************************************************************************
259 * 278 *
260 * FUNCTION: acpi_ds_get_package_arguments 279 * FUNCTION: acpi_ds_get_package_arguments
261 * 280 *
@@ -266,7 +285,7 @@ acpi_ds_get_buffer_arguments (
266 * DESCRIPTION: Get Package length and initializer byte list. This implements 285 * DESCRIPTION: Get Package length and initializer byte list. This implements
267 * the late evaluation of these attributes. 286 * the late evaluation of these attributes.
268 * 287 *
269 ****************************************************************************/ 288 ******************************************************************************/
270 289
271acpi_status 290acpi_status
272acpi_ds_get_package_arguments ( 291acpi_ds_get_package_arguments (
@@ -353,17 +372,17 @@ acpi_ds_get_region_arguments (
353} 372}
354 373
355 374
356/***************************************************************************** 375/*******************************************************************************
357 * 376 *
358 * FUNCTION: acpi_ds_initialize_region 377 * FUNCTION: acpi_ds_initialize_region
359 * 378 *
360 * PARAMETERS: Op - A valid region Op object 379 * PARAMETERS: obj_handle - Region namespace node
361 * 380 *
362 * RETURN: Status 381 * RETURN: Status
363 * 382 *
364 * DESCRIPTION: Front end to ev_initialize_region 383 * DESCRIPTION: Front end to ev_initialize_region
365 * 384 *
366 ****************************************************************************/ 385 ******************************************************************************/
367 386
368acpi_status 387acpi_status
369acpi_ds_initialize_region ( 388acpi_ds_initialize_region (
@@ -382,7 +401,7 @@ acpi_ds_initialize_region (
382} 401}
383 402
384 403
385/***************************************************************************** 404/*******************************************************************************
386 * 405 *
387 * FUNCTION: acpi_ds_init_buffer_field 406 * FUNCTION: acpi_ds_init_buffer_field
388 * 407 *
@@ -390,16 +409,16 @@ acpi_ds_initialize_region (
390 * obj_desc - buffer_field object 409 * obj_desc - buffer_field object
391 * buffer_desc - Host Buffer 410 * buffer_desc - Host Buffer
392 * offset_desc - Offset into buffer 411 * offset_desc - Offset into buffer
393 * Length - Length of field (CREATE_FIELD_OP only) 412 * length_desc - Length of field (CREATE_FIELD_OP only)
394 * Result - Where to store the result 413 * result_desc - Where to store the result
395 * 414 *
396 * RETURN: Status 415 * RETURN: Status
397 * 416 *
398 * DESCRIPTION: Perform actual initialization of a buffer field 417 * DESCRIPTION: Perform actual initialization of a buffer field
399 * 418 *
400 ****************************************************************************/ 419 ******************************************************************************/
401 420
402acpi_status 421static acpi_status
403acpi_ds_init_buffer_field ( 422acpi_ds_init_buffer_field (
404 u16 aml_opcode, 423 u16 aml_opcode,
405 union acpi_operand_object *obj_desc, 424 union acpi_operand_object *obj_desc,
@@ -435,8 +454,10 @@ acpi_ds_init_buffer_field (
435 * after resolution in acpi_ex_resolve_operands(). 454 * after resolution in acpi_ex_resolve_operands().
436 */ 455 */
437 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) { 456 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
438 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n", 457 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
439 acpi_ps_get_opcode_name (aml_opcode), acpi_ut_get_descriptor_name (result_desc))); 458 "(%s) destination not a NS Node [%s]\n",
459 acpi_ps_get_opcode_name (aml_opcode),
460 acpi_ut_get_descriptor_name (result_desc)));
440 461
441 status = AE_AML_OPERAND_TYPE; 462 status = AE_AML_OPERAND_TYPE;
442 goto cleanup; 463 goto cleanup;
@@ -452,9 +473,18 @@ acpi_ds_init_buffer_field (
452 473
453 /* Offset is in bits, count is in bits */ 474 /* Offset is in bits, count is in bits */
454 475
476 field_flags = AML_FIELD_ACCESS_BYTE;
455 bit_offset = offset; 477 bit_offset = offset;
456 bit_count = (u32) length_desc->integer.value; 478 bit_count = (u32) length_desc->integer.value;
457 field_flags = AML_FIELD_ACCESS_BYTE; 479
480 /* Must have a valid (>0) bit count */
481
482 if (bit_count == 0) {
483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Attempt to create_field of length 0\n"));
485 status = AE_AML_OPERAND_VALUE;
486 goto cleanup;
487 }
458 break; 488 break;
459 489
460 case AML_CREATE_BIT_FIELD_OP: 490 case AML_CREATE_BIT_FIELD_OP:
@@ -527,7 +557,8 @@ acpi_ds_init_buffer_field (
527 557
528 /* 558 /*
529 * Initialize areas of the field object that are common to all fields 559 * Initialize areas of the field object that are common to all fields
530 * For field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE) 560 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
561 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
531 */ 562 */
532 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0, 563 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
533 bit_offset, bit_count); 564 bit_offset, bit_count);
@@ -539,8 +570,8 @@ acpi_ds_init_buffer_field (
539 570
540 /* Reference count for buffer_desc inherits obj_desc count */ 571 /* Reference count for buffer_desc inherits obj_desc count */
541 572
542 buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count + 573 buffer_desc->common.reference_count = (u16)
543 obj_desc->common.reference_count); 574 (buffer_desc->common.reference_count + obj_desc->common.reference_count);
544 575
545 576
546cleanup: 577cleanup:
@@ -569,7 +600,7 @@ cleanup:
569} 600}
570 601
571 602
572/***************************************************************************** 603/*******************************************************************************
573 * 604 *
574 * FUNCTION: acpi_ds_eval_buffer_field_operands 605 * FUNCTION: acpi_ds_eval_buffer_field_operands
575 * 606 *
@@ -581,7 +612,7 @@ cleanup:
581 * DESCRIPTION: Get buffer_field Buffer and Index 612 * DESCRIPTION: Get buffer_field Buffer and Index
582 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk 613 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
583 * 614 *
584 ****************************************************************************/ 615 ******************************************************************************/
585 616
586acpi_status 617acpi_status
587acpi_ds_eval_buffer_field_operands ( 618acpi_ds_eval_buffer_field_operands (
@@ -656,7 +687,7 @@ acpi_ds_eval_buffer_field_operands (
656} 687}
657 688
658 689
659/***************************************************************************** 690/*******************************************************************************
660 * 691 *
661 * FUNCTION: acpi_ds_eval_region_operands 692 * FUNCTION: acpi_ds_eval_region_operands
662 * 693 *
@@ -668,7 +699,7 @@ acpi_ds_eval_buffer_field_operands (
668 * DESCRIPTION: Get region address and length 699 * DESCRIPTION: Get region address and length
669 * Called from acpi_ds_exec_end_op during op_region parse tree walk 700 * Called from acpi_ds_exec_end_op during op_region parse tree walk
670 * 701 *
671 ****************************************************************************/ 702 ******************************************************************************/
672 703
673acpi_status 704acpi_status
674acpi_ds_eval_region_operands ( 705acpi_ds_eval_region_operands (
@@ -686,7 +717,8 @@ acpi_ds_eval_region_operands (
686 717
687 718
688 /* 719 /*
689 * This is where we evaluate the address and length fields of the op_region declaration 720 * This is where we evaluate the address and length fields of the
721 * op_region declaration
690 */ 722 */
691 node = op->common.node; 723 node = op->common.node;
692 724
@@ -707,7 +739,8 @@ acpi_ds_eval_region_operands (
707 739
708 /* Resolve the length and address operands to numbers */ 740 /* Resolve the length and address operands to numbers */
709 741
710 status = acpi_ex_resolve_operands (op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state); 742 status = acpi_ex_resolve_operands (op->common.aml_opcode,
743 ACPI_WALK_OPERANDS, walk_state);
711 if (ACPI_FAILURE (status)) { 744 if (ACPI_FAILURE (status)) {
712 return_ACPI_STATUS (status); 745 return_ACPI_STATUS (status);
713 } 746 }
@@ -736,7 +769,8 @@ acpi_ds_eval_region_operands (
736 */ 769 */
737 operand_desc = walk_state->operands[walk_state->num_operands - 2]; 770 operand_desc = walk_state->operands[walk_state->num_operands - 2];
738 771
739 obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value; 772 obj_desc->region.address = (acpi_physical_address)
773 operand_desc->integer.value;
740 acpi_ut_remove_reference (operand_desc); 774 acpi_ut_remove_reference (operand_desc);
741 775
742 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n", 776 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
@@ -752,7 +786,7 @@ acpi_ds_eval_region_operands (
752} 786}
753 787
754 788
755/***************************************************************************** 789/*******************************************************************************
756 * 790 *
757 * FUNCTION: acpi_ds_eval_data_object_operands 791 * FUNCTION: acpi_ds_eval_data_object_operands
758 * 792 *
@@ -765,7 +799,7 @@ acpi_ds_eval_region_operands (
765 * DESCRIPTION: Get the operands and complete the following data object types: 799 * DESCRIPTION: Get the operands and complete the following data object types:
766 * Buffer, Package. 800 * Buffer, Package.
767 * 801 *
768 ****************************************************************************/ 802 ******************************************************************************/
769 803
770acpi_status 804acpi_status
771acpi_ds_eval_data_object_operands ( 805acpi_ds_eval_data_object_operands (
@@ -830,7 +864,7 @@ acpi_ds_eval_data_object_operands (
830 864
831 if (ACPI_SUCCESS (status)) { 865 if (ACPI_SUCCESS (status)) {
832 /* 866 /*
833 * Return the object in the walk_state, unless the parent is a package -- 867 * Return the object in the walk_state, unless the parent is a package -
834 * in this case, the return object will be stored in the parse tree 868 * in this case, the return object will be stored in the parse tree
835 * for the package. 869 * for the package.
836 */ 870 */
@@ -988,7 +1022,8 @@ acpi_ds_exec_end_control_op (
988 status = AE_CTRL_PENDING; 1022 status = AE_CTRL_PENDING;
989 } 1023 }
990 1024
991 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", op)); 1025 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1026 "[WHILE_OP] termination! Op=%p\n",op));
992 1027
993 /* Pop this control state and free it */ 1028 /* Pop this control state and free it */
994 1029
diff --git a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
index 462c5d83e747..9613349ac31d 100644
--- a/drivers/acpi/dispatcher/dsutils.c
+++ b/drivers/acpi/dispatcher/dsutils.c
@@ -100,7 +100,6 @@ acpi_ds_clear_implicit_return (
100 100
101 101
102#ifndef ACPI_NO_METHOD_EXECUTION 102#ifndef ACPI_NO_METHOD_EXECUTION
103
104/******************************************************************************* 103/*******************************************************************************
105 * 104 *
106 * FUNCTION: acpi_ds_do_implicit_return 105 * FUNCTION: acpi_ds_do_implicit_return
@@ -205,7 +204,7 @@ acpi_ds_is_result_used (
205 * NOTE: this is optional because the ASL language does not actually 204 * NOTE: this is optional because the ASL language does not actually
206 * support this behavior. 205 * support this behavior.
207 */ 206 */
208 acpi_ds_do_implicit_return (walk_state->result_obj, walk_state, TRUE); 207 (void) acpi_ds_do_implicit_return (walk_state->result_obj, walk_state, TRUE);
209 208
210 /* 209 /*
211 * Now determine if the parent will use the result 210 * Now determine if the parent will use the result
@@ -219,8 +218,9 @@ acpi_ds_is_result_used (
219 (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) { 218 (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) {
220 /* No parent, the return value cannot possibly be used */ 219 /* No parent, the return value cannot possibly be used */
221 220
222 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "At Method level, result of [%s] not used\n", 221 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
223 acpi_ps_get_opcode_name (op->common.aml_opcode))); 222 "At Method level, result of [%s] not used\n",
223 acpi_ps_get_opcode_name (op->common.aml_opcode)));
224 return_VALUE (FALSE); 224 return_VALUE (FALSE);
225 } 225 }
226 226
@@ -228,7 +228,8 @@ acpi_ds_is_result_used (
228 228
229 parent_info = acpi_ps_get_opcode_info (op->common.parent->common.aml_opcode); 229 parent_info = acpi_ps_get_opcode_info (op->common.parent->common.aml_opcode);
230 if (parent_info->class == AML_CLASS_UNKNOWN) { 230 if (parent_info->class == AML_CLASS_UNKNOWN) {
231 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%p\n", op)); 231 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
232 "Unknown parent opcode. Op=%p\n", op));
232 return_VALUE (FALSE); 233 return_VALUE (FALSE);
233 } 234 }
234 235
@@ -309,17 +310,19 @@ acpi_ds_is_result_used (
309 310
310 311
311result_used: 312result_used:
312 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] used by Parent [%s] Op=%p\n", 313 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
313 acpi_ps_get_opcode_name (op->common.aml_opcode), 314 "Result of [%s] used by Parent [%s] Op=%p\n",
314 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op)); 315 acpi_ps_get_opcode_name (op->common.aml_opcode),
316 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op));
315 317
316 return_VALUE (TRUE); 318 return_VALUE (TRUE);
317 319
318 320
319result_not_used: 321result_not_used:
320 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] not used by Parent [%s] Op=%p\n", 322 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
321 acpi_ps_get_opcode_name (op->common.aml_opcode), 323 "Result of [%s] not used by Parent [%s] Op=%p\n",
322 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op)); 324 acpi_ps_get_opcode_name (op->common.aml_opcode),
325 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op));
323 326
324 return_VALUE (FALSE); 327 return_VALUE (FALSE);
325} 328}
@@ -522,7 +525,8 @@ acpi_ds_create_operand (
522 if ((walk_state->deferred_node) && 525 if ((walk_state->deferred_node) &&
523 (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD) && 526 (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD) &&
524 (arg_index != 0)) { 527 (arg_index != 0)) {
525 obj_desc = ACPI_CAST_PTR (union acpi_operand_object, walk_state->deferred_node); 528 obj_desc = ACPI_CAST_PTR (
529 union acpi_operand_object, walk_state->deferred_node);
526 status = AE_OK; 530 status = AE_OK;
527 } 531 }
528 else /* All other opcodes */ { 532 else /* All other opcodes */ {
@@ -565,7 +569,8 @@ acpi_ds_create_operand (
565 * indicate this to the interpreter, set the 569 * indicate this to the interpreter, set the
566 * object to the root 570 * object to the root
567 */ 571 */
568 obj_desc = ACPI_CAST_PTR (union acpi_operand_object, acpi_gbl_root_node); 572 obj_desc = ACPI_CAST_PTR (
573 union acpi_operand_object, acpi_gbl_root_node);
569 status = AE_OK; 574 status = AE_OK;
570 } 575 }
571 else { 576 else {
@@ -612,7 +617,8 @@ acpi_ds_create_operand (
612 */ 617 */
613 opcode = AML_ZERO_OP; /* Has no arguments! */ 618 opcode = AML_ZERO_OP; /* Has no arguments! */
614 619
615 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", arg)); 620 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
621 "Null namepath: Arg=%p\n", arg));
616 } 622 }
617 else { 623 else {
618 opcode = arg->common.aml_opcode; 624 opcode = arg->common.aml_opcode;
@@ -642,7 +648,8 @@ acpi_ds_create_operand (
642 * Only error is underflow, and this indicates 648 * Only error is underflow, and this indicates
643 * a missing or null operand! 649 * a missing or null operand!
644 */ 650 */
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n", 651 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
652 "Missing or null operand, %s\n",
646 acpi_format_exception (status))); 653 acpi_format_exception (status)));
647 return_ACPI_STATUS (status); 654 return_ACPI_STATUS (status);
648 } 655 }
@@ -657,8 +664,8 @@ acpi_ds_create_operand (
657 664
658 /* Initialize the new object */ 665 /* Initialize the new object */
659 666
660 status = acpi_ds_init_object_from_op (walk_state, arg, 667 status = acpi_ds_init_object_from_op (
661 opcode, &obj_desc); 668 walk_state, arg, opcode, &obj_desc);
662 if (ACPI_FAILURE (status)) { 669 if (ACPI_FAILURE (status)) {
663 acpi_ut_delete_object_desc (obj_desc); 670 acpi_ut_delete_object_desc (obj_desc);
664 return_ACPI_STATUS (status); 671 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index 2071a0d2bbbb..10f71318e23b 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -73,11 +73,13 @@ static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch [] = {
73 acpi_ex_opcode_3A_1T_1R, 73 acpi_ex_opcode_3A_1T_1R,
74 acpi_ex_opcode_6A_0T_1R}; 74 acpi_ex_opcode_6A_0T_1R};
75 75
76
76/***************************************************************************** 77/*****************************************************************************
77 * 78 *
78 * FUNCTION: acpi_ds_get_predicate_value 79 * FUNCTION: acpi_ds_get_predicate_value
79 * 80 *
80 * PARAMETERS: walk_state - Current state of the parse tree walk 81 * PARAMETERS: walk_state - Current state of the parse tree walk
82 * result_obj - if non-zero, pop result from result stack
81 * 83 *
82 * RETURN: Status 84 * RETURN: Status
83 * 85 *
@@ -124,7 +126,8 @@ acpi_ds_get_predicate_value (
124 } 126 }
125 127
126 if (!obj_desc) { 128 if (!obj_desc) {
127 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n", 129 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
130 "No predicate obj_desc=%p State=%p\n",
128 obj_desc, walk_state)); 131 obj_desc, walk_state));
129 132
130 return_ACPI_STATUS (AE_AML_NO_OPERAND); 133 return_ACPI_STATUS (AE_AML_NO_OPERAND);
@@ -197,7 +200,7 @@ cleanup:
197 * FUNCTION: acpi_ds_exec_begin_op 200 * FUNCTION: acpi_ds_exec_begin_op
198 * 201 *
199 * PARAMETERS: walk_state - Current state of the parse tree walk 202 * PARAMETERS: walk_state - Current state of the parse tree walk
200 * out_op - Return op if a new one is created 203 * out_op - Where to return op if a new one is created
201 * 204 *
202 * RETURN: Status 205 * RETURN: Status
203 * 206 *
@@ -233,7 +236,8 @@ acpi_ds_exec_begin_op (
233 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 236 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
234 237
235 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) { 238 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) {
236 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", 239 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
240 "(%s) Popping scope for Op %p\n",
237 acpi_ut_get_type_name (walk_state->op_info->object_type), op)); 241 acpi_ut_get_type_name (walk_state->op_info->object_type), op));
238 242
239 status = acpi_ds_scope_stack_pop (walk_state); 243 status = acpi_ds_scope_stack_pop (walk_state);
@@ -297,11 +301,10 @@ acpi_ds_exec_begin_op (
297 301
298 if (walk_state->walk_type == ACPI_WALK_METHOD) { 302 if (walk_state->walk_type == ACPI_WALK_METHOD) {
299 /* 303 /*
300 * Found a named object declaration during method 304 * Found a named object declaration during method execution;
301 * execution; we must enter this object into the 305 * we must enter this object into the namespace. The created
302 * namespace. The created object is temporary and 306 * object is temporary and will be deleted upon completion of
303 * will be deleted upon completion of the execution 307 * the execution of this method.
304 * of this method.
305 */ 308 */
306 status = acpi_ds_load2_begin_op (walk_state, NULL); 309 status = acpi_ds_load2_begin_op (walk_state, NULL);
307 } 310 }
@@ -338,8 +341,6 @@ acpi_ds_exec_begin_op (
338 * FUNCTION: acpi_ds_exec_end_op 341 * FUNCTION: acpi_ds_exec_end_op
339 * 342 *
340 * PARAMETERS: walk_state - Current state of the parse tree walk 343 * PARAMETERS: walk_state - Current state of the parse tree walk
341 * Op - Op that has been just been completed in the
342 * walk; Arguments have now been evaluated.
343 * 344 *
344 * RETURN: Status 345 * RETURN: Status
345 * 346 *
@@ -389,7 +390,7 @@ acpi_ds_exec_end_op (
389 /* Decode the Opcode Class */ 390 /* Decode the Opcode Class */
390 391
391 switch (op_class) { 392 switch (op_class) {
392 case AML_CLASS_ARGUMENT: /* constants, literals, etc. -- do nothing */ 393 case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */
393 break; 394 break;
394 395
395 396
@@ -417,12 +418,12 @@ acpi_ds_exec_end_op (
417 /* Resolve all operands */ 418 /* Resolve all operands */
418 419
419 status = acpi_ex_resolve_operands (walk_state->opcode, 420 status = acpi_ex_resolve_operands (walk_state->opcode,
420 &(walk_state->operands [walk_state->num_operands -1]), 421 &(walk_state->operands [walk_state->num_operands -1]),
421 walk_state); 422 walk_state);
422 if (ACPI_SUCCESS (status)) { 423 if (ACPI_SUCCESS (status)) {
423 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, 424 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
424 acpi_ps_get_opcode_name (walk_state->opcode), 425 acpi_ps_get_opcode_name (walk_state->opcode),
425 walk_state->num_operands, "after ex_resolve_operands"); 426 walk_state->num_operands, "after ex_resolve_operands");
426 } 427 }
427 } 428 }
428 429
@@ -506,7 +507,8 @@ acpi_ds_exec_end_op (
506 if ((op->asl.parent) && 507 if ((op->asl.parent) &&
507 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) || 508 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) ||
508 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) { 509 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) {
509 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method Reference in a Package, Op=%p\n", op)); 510 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
511 "Method Reference in a Package, Op=%p\n", op));
510 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object; 512 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object;
511 acpi_ut_add_reference (op->asl.value.arg->asl.node->object); 513 acpi_ut_add_reference (op->asl.value.arg->asl.node->object);
512 return_ACPI_STATUS (AE_OK); 514 return_ACPI_STATUS (AE_OK);
@@ -583,13 +585,15 @@ acpi_ds_exec_end_op (
583 case AML_NAME_OP: 585 case AML_NAME_OP:
584 586
585 /* 587 /*
586 * Put the Node on the object stack (Contains the ACPI Name of 588 * Put the Node on the object stack (Contains the ACPI Name
587 * this object) 589 * of this object)
588 */ 590 */
589 walk_state->operands[0] = (void *) op->common.parent->common.node; 591 walk_state->operands[0] = (void *) op->common.parent->common.node;
590 walk_state->num_operands = 1; 592 walk_state->num_operands = 1;
591 593
592 status = acpi_ds_create_node (walk_state, op->common.parent->common.node, op->common.parent); 594 status = acpi_ds_create_node (walk_state,
595 op->common.parent->common.node,
596 op->common.parent);
593 if (ACPI_FAILURE (status)) { 597 if (ACPI_FAILURE (status)) {
594 break; 598 break;
595 } 599 }
@@ -600,7 +604,7 @@ acpi_ds_exec_end_op (
600 case AML_INT_EVAL_SUBTREE_OP: 604 case AML_INT_EVAL_SUBTREE_OP:
601 605
602 status = acpi_ds_eval_data_object_operands (walk_state, op, 606 status = acpi_ds_eval_data_object_operands (walk_state, op,
603 acpi_ns_get_attached_object (op->common.parent->common.node)); 607 acpi_ns_get_attached_object (op->common.parent->common.node));
604 break; 608 break;
605 609
606 default: 610 default:
@@ -609,7 +613,7 @@ acpi_ds_exec_end_op (
609 break; 613 break;
610 } 614 }
611 615
612 /* Done with this result state (Now that operand stack is built) */ 616 /* Done with result state (Now that operand stack is built) */
613 617
614 status = acpi_ds_result_stack_pop (walk_state); 618 status = acpi_ds_result_stack_pop (walk_state);
615 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
@@ -620,8 +624,7 @@ acpi_ds_exec_end_op (
620 * If a result object was returned from above, push it on the 624 * If a result object was returned from above, push it on the
621 * current result stack 625 * current result stack
622 */ 626 */
623 if (ACPI_SUCCESS (status) && 627 if (walk_state->result_obj) {
624 walk_state->result_obj) {
625 status = acpi_ds_result_push (walk_state->result_obj, walk_state); 628 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
626 } 629 }
627 break; 630 break;
@@ -654,7 +657,8 @@ acpi_ds_exec_end_op (
654 657
655 case AML_TYPE_UNDEFINED: 658 case AML_TYPE_UNDEFINED:
656 659
657 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Undefined opcode type Op=%p\n", op)); 660 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
661 "Undefined opcode type Op=%p\n", op));
658 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 662 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
659 663
660 664
@@ -709,13 +713,14 @@ cleanup:
709 status = acpi_gbl_exception_handler (status, 713 status = acpi_gbl_exception_handler (status,
710 walk_state->method_node->name.integer, walk_state->opcode, 714 walk_state->method_node->name.integer, walk_state->opcode,
711 walk_state->aml_offset, NULL); 715 walk_state->aml_offset, NULL);
712 acpi_ex_enter_interpreter (); 716 (void) acpi_ex_enter_interpreter ();
713 } 717 }
714 718
715 if (walk_state->result_obj) { 719 if (walk_state->result_obj) {
716 /* Break to debugger to display result */ 720 /* Break to debugger to display result */
717 721
718 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj, walk_state)); 722 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj,
723 walk_state));
719 724
720 /* 725 /*
721 * Delete the result op if and only if: 726 * Delete the result op if and only if:
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index 06d758679588..1ac197ccfc80 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -79,20 +79,23 @@ acpi_ds_init_callbacks (
79 79
80 switch (pass_number) { 80 switch (pass_number) {
81 case 1: 81 case 1:
82 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 82 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
83 ACPI_PARSE_DELETE_TREE;
83 walk_state->descending_callback = acpi_ds_load1_begin_op; 84 walk_state->descending_callback = acpi_ds_load1_begin_op;
84 walk_state->ascending_callback = acpi_ds_load1_end_op; 85 walk_state->ascending_callback = acpi_ds_load1_end_op;
85 break; 86 break;
86 87
87 case 2: 88 case 2:
88 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 89 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
90 ACPI_PARSE_DELETE_TREE;
89 walk_state->descending_callback = acpi_ds_load2_begin_op; 91 walk_state->descending_callback = acpi_ds_load2_begin_op;
90 walk_state->ascending_callback = acpi_ds_load2_end_op; 92 walk_state->ascending_callback = acpi_ds_load2_end_op;
91 break; 93 break;
92 94
93 case 3: 95 case 3:
94#ifndef ACPI_NO_METHOD_EXECUTION 96#ifndef ACPI_NO_METHOD_EXECUTION
95 walk_state->parse_flags |= ACPI_PARSE_EXECUTE | ACPI_PARSE_DELETE_TREE; 97 walk_state->parse_flags |= ACPI_PARSE_EXECUTE |
98 ACPI_PARSE_DELETE_TREE;
96 walk_state->descending_callback = acpi_ds_exec_begin_op; 99 walk_state->descending_callback = acpi_ds_exec_begin_op;
97 walk_state->ascending_callback = acpi_ds_exec_end_op; 100 walk_state->ascending_callback = acpi_ds_exec_end_op;
98#endif 101#endif
@@ -111,8 +114,7 @@ acpi_ds_init_callbacks (
111 * FUNCTION: acpi_ds_load1_begin_op 114 * FUNCTION: acpi_ds_load1_begin_op
112 * 115 *
113 * PARAMETERS: walk_state - Current state of the parse tree walk 116 * PARAMETERS: walk_state - Current state of the parse tree walk
114 * Op - Op that has been just been reached in the 117 * out_op - Where to return op if a new one is created
115 * walk; Arguments have not been evaluated yet.
116 * 118 *
117 * RETURN: Status 119 * RETURN: Status
118 * 120 *
@@ -146,7 +148,8 @@ acpi_ds_load1_begin_op (
146#if 0 148#if 0
147 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) || 149 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
148 (walk_state->op_info->class == AML_CLASS_CONTROL)) { 150 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
149 acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n", walk_state->op_info->name); 151 acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n",
152 walk_state->op_info->name);
150 *out_op = op; 153 *out_op = op;
151 return (AE_CTRL_SKIP); 154 return (AE_CTRL_SKIP);
152 } 155 }
@@ -191,7 +194,8 @@ acpi_ds_load1_begin_op (
191 */ 194 */
192 acpi_dm_add_to_external_list (path); 195 acpi_dm_add_to_external_list (path);
193 status = acpi_ns_lookup (walk_state->scope_info, path, object_type, 196 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
194 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 197 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
198 walk_state, &(node));
195 } 199 }
196#endif 200#endif
197 if (ACPI_FAILURE (status)) { 201 if (ACPI_FAILURE (status)) {
@@ -224,10 +228,12 @@ acpi_ds_load1_begin_op (
224 * Name (DEB, 0) 228 * Name (DEB, 0)
225 * Scope (DEB) { ... } 229 * Scope (DEB) { ... }
226 * 230 *
227 * Note: silently change the type here. On the second pass, we will report a warning 231 * Note: silently change the type here. On the second pass, we will report
232 * a warning
228 */ 233 */
229 234
230 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 235 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
236 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
231 path, acpi_ut_get_type_name (node->type))); 237 path, acpi_ut_get_type_name (node->type)));
232 238
233 node->type = ACPI_TYPE_ANY; 239 node->type = ACPI_TYPE_ANY;
@@ -238,7 +244,8 @@ acpi_ds_load1_begin_op (
238 244
239 /* All other types are an error */ 245 /* All other types are an error */
240 246
241 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n", 247 ACPI_REPORT_ERROR ((
248 "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
242 acpi_ut_get_type_name (node->type), path)); 249 acpi_ut_get_type_name (node->type), path));
243 250
244 return (AE_AML_OPERAND_TYPE); 251 return (AE_AML_OPERAND_TYPE);
@@ -249,7 +256,8 @@ acpi_ds_load1_begin_op (
249 default: 256 default:
250 257
251 /* 258 /*
252 * For all other named opcodes, we will enter the name into the namespace. 259 * For all other named opcodes, we will enter the name into
260 * the namespace.
253 * 261 *
254 * Setup the search flags. 262 * Setup the search flags.
255 * Since we are entering a name into the namespace, we do not want to 263 * Since we are entering a name into the namespace, we do not want to
@@ -279,14 +287,16 @@ acpi_ds_load1_begin_op (
279 acpi_ut_get_type_name (object_type))); 287 acpi_ut_get_type_name (object_type)));
280 } 288 }
281 else { 289 else {
282 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n", 290 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
291 "[%s] Both Find or Create allowed\n",
283 acpi_ut_get_type_name (object_type))); 292 acpi_ut_get_type_name (object_type)));
284 } 293 }
285 294
286 /* 295 /*
287 * Enter the named type into the internal namespace. We enter the name 296 * Enter the named type into the internal namespace. We enter the name
288 * as we go downward in the parse tree. Any necessary subobjects that involve 297 * as we go downward in the parse tree. Any necessary subobjects that
289 * arguments to the opcode must be created as we go back up the parse tree later. 298 * involve arguments to the opcode must be created as we go back up the
299 * parse tree later.
290 */ 300 */
291 status = acpi_ns_lookup (walk_state->scope_info, path, object_type, 301 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
292 ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node)); 302 ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node));
@@ -335,8 +345,6 @@ acpi_ds_load1_begin_op (
335 * FUNCTION: acpi_ds_load1_end_op 345 * FUNCTION: acpi_ds_load1_end_op
336 * 346 *
337 * PARAMETERS: walk_state - Current state of the parse tree walk 347 * PARAMETERS: walk_state - Current state of the parse tree walk
338 * Op - Op that has been just been completed in the
339 * walk; Arguments have now been evaluated.
340 * 348 *
341 * RETURN: Status 349 * RETURN: Status
342 * 350 *
@@ -383,7 +391,9 @@ acpi_ds_load1_end_op (
383 391
384 if (op->common.aml_opcode == AML_REGION_OP) { 392 if (op->common.aml_opcode == AML_REGION_OP) {
385 status = acpi_ex_create_region (op->named.data, op->named.length, 393 status = acpi_ex_create_region (op->named.data, op->named.length,
386 (acpi_adr_space_type) ((op->common.value.arg)->common.value.integer), walk_state); 394 (acpi_adr_space_type)
395 ((op->common.value.arg)->common.value.integer),
396 walk_state);
387 if (ACPI_FAILURE (status)) { 397 if (ACPI_FAILURE (status)) {
388 return (status); 398 return (status);
389 } 399 }
@@ -394,7 +404,8 @@ acpi_ds_load1_end_op (
394 /* For Name opcode, get the object type from the argument */ 404 /* For Name opcode, get the object type from the argument */
395 405
396 if (op->common.value.arg) { 406 if (op->common.value.arg) {
397 object_type = (acpi_ps_get_opcode_info ((op->common.value.arg)->common.aml_opcode))->object_type; 407 object_type = (acpi_ps_get_opcode_info (
408 (op->common.value.arg)->common.aml_opcode))->object_type;
398 op->common.node->type = (u8) object_type; 409 op->common.node->type = (u8) object_type;
399 } 410 }
400 } 411 }
@@ -448,8 +459,7 @@ acpi_ds_load1_end_op (
448 * FUNCTION: acpi_ds_load2_begin_op 459 * FUNCTION: acpi_ds_load2_begin_op
449 * 460 *
450 * PARAMETERS: walk_state - Current state of the parse tree walk 461 * PARAMETERS: walk_state - Current state of the parse tree walk
451 * Op - Op that has been just been reached in the 462 * out_op - Wher to return op if a new one is created
452 * walk; Arguments have not been evaluated yet.
453 * 463 *
454 * RETURN: Status 464 * RETURN: Status
455 * 465 *
@@ -478,14 +488,20 @@ acpi_ds_load2_begin_op (
478 if (op) { 488 if (op) {
479 /* We only care about Namespace opcodes here */ 489 /* We only care about Namespace opcodes here */
480 490
481 if ((!(walk_state->op_info->flags & AML_NSOPCODE) && (walk_state->opcode != AML_INT_NAMEPATH_OP)) || 491 if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
492 (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
482 (!(walk_state->op_info->flags & AML_NAMED))) { 493 (!(walk_state->op_info->flags & AML_NAMED))) {
494 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
495 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
496 ACPI_REPORT_WARNING ((
497 "Encountered executable code at module level, [%s]\n",
498 acpi_ps_get_opcode_name (walk_state->opcode)));
499 }
483 return_ACPI_STATUS (AE_OK); 500 return_ACPI_STATUS (AE_OK);
484 } 501 }
485 502
486 /* 503 /* Get the name we are going to enter or lookup in the namespace */
487 * Get the name we are going to enter or lookup in the namespace 504
488 */
489 if (walk_state->opcode == AML_INT_NAMEPATH_OP) { 505 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
490 /* For Namepath op, get the path string */ 506 /* For Namepath op, get the path string */
491 507
@@ -528,21 +544,25 @@ acpi_ds_load2_begin_op (
528 case AML_INT_NAMEPATH_OP: 544 case AML_INT_NAMEPATH_OP:
529 545
530 /* 546 /*
531 * The name_path is an object reference to an existing object. Don't enter the 547 * The name_path is an object reference to an existing object.
532 * name into the namespace, but look it up for use later 548 * Don't enter the name into the namespace, but look it up
549 * for use later.
533 */ 550 */
534 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 551 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
535 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 552 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
553 walk_state, &(node));
536 break; 554 break;
537 555
538 case AML_SCOPE_OP: 556 case AML_SCOPE_OP:
539 557
540 /* 558 /*
541 * The Path is an object reference to an existing object. Don't enter the 559 * The Path is an object reference to an existing object.
542 * name into the namespace, but look it up for use later 560 * Don't enter the name into the namespace, but look it up
561 * for use later.
543 */ 562 */
544 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 563 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
545 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 564 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
565 walk_state, &(node));
546 if (ACPI_FAILURE (status)) { 566 if (ACPI_FAILURE (status)) {
547#ifdef _ACPI_ASL_COMPILER 567#ifdef _ACPI_ASL_COMPILER
548 if (status == AE_NOT_FOUND) { 568 if (status == AE_NOT_FOUND) {
@@ -582,7 +602,8 @@ acpi_ds_load2_begin_op (
582 * Scope (DEB) { ... } 602 * Scope (DEB) { ... }
583 */ 603 */
584 604
585 ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 605 ACPI_REPORT_WARNING ((
606 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
586 buffer_ptr, acpi_ut_get_type_name (node->type))); 607 buffer_ptr, acpi_ut_get_type_name (node->type)));
587 608
588 node->type = ACPI_TYPE_ANY; 609 node->type = ACPI_TYPE_ANY;
@@ -593,7 +614,8 @@ acpi_ds_load2_begin_op (
593 614
594 /* All other types are an error */ 615 /* All other types are an error */
595 616
596 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n", 617 ACPI_REPORT_ERROR ((
618 "Invalid type (%s) for target of Scope operator [%4.4s]\n",
597 acpi_ut_get_type_name (node->type), buffer_ptr)); 619 acpi_ut_get_type_name (node->type), buffer_ptr));
598 620
599 return (AE_AML_OPERAND_TYPE); 621 return (AE_AML_OPERAND_TYPE);
@@ -621,8 +643,9 @@ acpi_ds_load2_begin_op (
621 643
622 /* 644 /*
623 * Enter the named type into the internal namespace. We enter the name 645 * Enter the named type into the internal namespace. We enter the name
624 * as we go downward in the parse tree. Any necessary subobjects that involve 646 * as we go downward in the parse tree. Any necessary subobjects that
625 * arguments to the opcode must be created as we go back up the parse tree later. 647 * involve arguments to the opcode must be created as we go back up the
648 * parse tree later.
626 * 649 *
627 * Note: Name may already exist if we are executing a deferred opcode. 650 * Note: Name may already exist if we are executing a deferred opcode.
628 */ 651 */
@@ -635,7 +658,8 @@ acpi_ds_load2_begin_op (
635 } 658 }
636 659
637 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 660 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
638 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, walk_state, &(node)); 661 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH,
662 walk_state, &(node));
639 break; 663 break;
640 } 664 }
641 665
@@ -678,8 +702,6 @@ acpi_ds_load2_begin_op (
678 * FUNCTION: acpi_ds_load2_end_op 702 * FUNCTION: acpi_ds_load2_end_op
679 * 703 *
680 * PARAMETERS: walk_state - Current state of the parse tree walk 704 * PARAMETERS: walk_state - Current state of the parse tree walk
681 * Op - Op that has been just been completed in the
682 * walk; Arguments have now been evaluated.
683 * 705 *
684 * RETURN: Status 706 * RETURN: Status
685 * 707 *
@@ -738,7 +760,8 @@ acpi_ds_load2_end_op (
738 760
739 /* Pop the scope stack */ 761 /* Pop the scope stack */
740 762
741 if (acpi_ns_opens_scope (object_type) && (op->common.aml_opcode != AML_INT_METHODCALL_OP)) { 763 if (acpi_ns_opens_scope (object_type) &&
764 (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
742 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", 765 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
743 acpi_ut_get_type_name (object_type), op)); 766 acpi_ut_get_type_name (object_type), op));
744 767
@@ -803,7 +826,7 @@ acpi_ds_load2_end_op (
803 case AML_INDEX_FIELD_OP: 826 case AML_INDEX_FIELD_OP:
804 827
805 status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node, 828 status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node,
806 walk_state); 829 walk_state);
807 break; 830 break;
808 831
809 case AML_BANK_FIELD_OP: 832 case AML_BANK_FIELD_OP:
@@ -884,14 +907,16 @@ acpi_ds_load2_end_op (
884#ifndef ACPI_NO_METHOD_EXECUTION 907#ifndef ACPI_NO_METHOD_EXECUTION
885 case AML_REGION_OP: 908 case AML_REGION_OP:
886 /* 909 /*
887 * The op_region is not fully parsed at this time. Only valid argument is the space_id. 910 * The op_region is not fully parsed at this time. Only valid
888 * (We must save the address of the AML of the address and length operands) 911 * argument is the space_id. (We must save the address of the
912 * AML of the address and length operands)
889 */ 913 */
890 /* 914 /*
891 * If we have a valid region, initialize it 915 * If we have a valid region, initialize it
892 * Namespace is NOT locked at this point. 916 * Namespace is NOT locked at this point.
893 */ 917 */
894 status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node), FALSE); 918 status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node),
919 FALSE);
895 if (ACPI_FAILURE (status)) { 920 if (ACPI_FAILURE (status)) {
896 /* 921 /*
897 * If AE_NOT_EXIST is returned, it is not fatal 922 * If AE_NOT_EXIST is returned, it is not fatal
@@ -942,15 +967,16 @@ acpi_ds_load2_end_op (
942 if (ACPI_SUCCESS (status)) { 967 if (ACPI_SUCCESS (status)) {
943 /* 968 /*
944 * Make sure that what we found is indeed a method 969 * Make sure that what we found is indeed a method
945 * We didn't search for a method on purpose, to see if the name would resolve 970 * We didn't search for a method on purpose, to see if the name
971 * would resolve
946 */ 972 */
947 if (new_node->type != ACPI_TYPE_METHOD) { 973 if (new_node->type != ACPI_TYPE_METHOD) {
948 status = AE_AML_OPERAND_TYPE; 974 status = AE_AML_OPERAND_TYPE;
949 } 975 }
950 976
951 /* We could put the returned object (Node) on the object stack for later, but 977 /* We could put the returned object (Node) on the object stack for
952 * for now, we will put it in the "op" object that the parser uses, so we 978 * later, but for now, we will put it in the "op" object that the
953 * can get it again at the end of this scope 979 * parser uses, so we can get it again at the end of this scope
954 */ 980 */
955 op->common.node = new_node; 981 op->common.node = new_node;
956 } 982 }
diff --git a/drivers/acpi/dispatcher/dswscope.c b/drivers/acpi/dispatcher/dswscope.c
index 65f456151e25..21f4548ff323 100644
--- a/drivers/acpi/dispatcher/dswscope.c
+++ b/drivers/acpi/dispatcher/dswscope.c
@@ -50,14 +50,13 @@
50 ACPI_MODULE_NAME ("dswscope") 50 ACPI_MODULE_NAME ("dswscope")
51 51
52 52
53#define STACK_POP(head) head
54
55
56/**************************************************************************** 53/****************************************************************************
57 * 54 *
58 * FUNCTION: acpi_ds_scope_stack_clear 55 * FUNCTION: acpi_ds_scope_stack_clear
59 * 56 *
60 * PARAMETERS: None 57 * PARAMETERS: walk_state - Current state
58 *
59 * RETURN: None
61 * 60 *
62 * DESCRIPTION: Pop (and free) everything on the scope stack except the 61 * DESCRIPTION: Pop (and free) everything on the scope stack except the
63 * root scope object (which remains at the stack top.) 62 * root scope object (which remains at the stack top.)
@@ -80,7 +79,8 @@ acpi_ds_scope_stack_clear (
80 walk_state->scope_info = scope_info->scope.next; 79 walk_state->scope_info = scope_info->scope.next;
81 80
82 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 81 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
83 "Popped object type (%s)\n", acpi_ut_get_type_name (scope_info->common.value))); 82 "Popped object type (%s)\n",
83 acpi_ut_get_type_name (scope_info->common.value)));
84 acpi_ut_delete_generic_state (scope_info); 84 acpi_ut_delete_generic_state (scope_info);
85 } 85 }
86} 86}
@@ -90,8 +90,11 @@ acpi_ds_scope_stack_clear (
90 * 90 *
91 * FUNCTION: acpi_ds_scope_stack_push 91 * FUNCTION: acpi_ds_scope_stack_push
92 * 92 *
93 * PARAMETERS: *Node, - Name to be made current 93 * PARAMETERS: Node - Name to be made current
94 * Type, - Type of frame being pushed 94 * Type - Type of frame being pushed
95 * walk_state - Current state
96 *
97 * RETURN: Status
95 * 98 *
96 * DESCRIPTION: Push the current scope on the scope stack, and make the 99 * DESCRIPTION: Push the current scope on the scope stack, and make the
97 * passed Node current. 100 * passed Node current.
@@ -121,7 +124,8 @@ acpi_ds_scope_stack_push (
121 /* Make sure object type is valid */ 124 /* Make sure object type is valid */
122 125
123 if (!acpi_ut_valid_object_type (type)) { 126 if (!acpi_ut_valid_object_type (type)) {
124 ACPI_REPORT_WARNING (("ds_scope_stack_push: Invalid object type: 0x%X\n", type)); 127 ACPI_REPORT_WARNING ((
128 "ds_scope_stack_push: Invalid object type: 0x%X\n", type));
125 } 129 }
126 130
127 /* Allocate a new scope object */ 131 /* Allocate a new scope object */
@@ -170,16 +174,11 @@ acpi_ds_scope_stack_push (
170 * 174 *
171 * FUNCTION: acpi_ds_scope_stack_pop 175 * FUNCTION: acpi_ds_scope_stack_pop
172 * 176 *
173 * PARAMETERS: Type - The type of frame to be found 177 * PARAMETERS: walk_state - Current state
174 * 178 *
175 * DESCRIPTION: Pop the scope stack until a frame of the requested type 179 * RETURN: Status
176 * is found.
177 * 180 *
178 * RETURN: Count of frames popped. If no frame of the requested type 181 * DESCRIPTION: Pop the scope stack once.
179 * was found, the count is returned as a negative number and
180 * the scope stack is emptied (which sets the current scope
181 * to the root). If the scope stack was empty at entry, the
182 * function is a no-op and returns 0.
183 * 182 *
184 ***************************************************************************/ 183 ***************************************************************************/
185 184
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index e555b3fbd5e5..9cd3db652b31 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -50,67 +50,31 @@
50#define _COMPONENT ACPI_DISPATCHER 50#define _COMPONENT ACPI_DISPATCHER
51 ACPI_MODULE_NAME ("dswstate") 51 ACPI_MODULE_NAME ("dswstate")
52 52
53/* Local prototypes */
53 54
54#ifdef ACPI_FUTURE_USAGE 55#ifdef ACPI_OBSOLETE_FUNCTIONS
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ds_result_insert
59 *
60 * PARAMETERS: Object - Object to push
61 * Index - Where to insert the object
62 * walk_state - Current Walk state
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Insert an object onto this walk's result stack
67 *
68 ******************************************************************************/
69
70acpi_status 56acpi_status
71acpi_ds_result_insert ( 57acpi_ds_result_insert (
72 void *object, 58 void *object,
73 u32 index, 59 u32 index,
74 struct acpi_walk_state *walk_state) 60 struct acpi_walk_state *walk_state);
75{
76 union acpi_generic_state *state;
77
78 61
79 ACPI_FUNCTION_NAME ("ds_result_insert"); 62acpi_status
80 63acpi_ds_obj_stack_delete_all (
81 64 struct acpi_walk_state *walk_state);
82 state = walk_state->results;
83 if (!state) {
84 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
85 walk_state));
86 return (AE_NOT_EXIST);
87 }
88
89 if (index >= ACPI_OBJ_NUM_OPERANDS) {
90 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
91 "Index out of range: %X Obj=%p State=%p Num=%X\n",
92 index, object, walk_state, state->results.num_results));
93 return (AE_BAD_PARAMETER);
94 }
95
96 if (!object) {
97 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
98 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
99 index, object, walk_state, state->results.num_results));
100 return (AE_BAD_PARAMETER);
101 }
102
103 state->results.obj_desc [index] = object;
104 state->results.num_results++;
105 65
106 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 66acpi_status
107 "Obj=%p [%s] State=%p Num=%X Cur=%X\n", 67acpi_ds_obj_stack_pop_object (
108 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL", 68 union acpi_operand_object **object,
109 walk_state, state->results.num_results, walk_state->current_result)); 69 struct acpi_walk_state *walk_state);
110 70
111 return (AE_OK); 71void *
112} 72acpi_ds_obj_stack_get_value (
73 u32 index,
74 struct acpi_walk_state *walk_state);
75#endif
113 76
77#ifdef ACPI_FUTURE_USAGE
114 78
115/******************************************************************************* 79/*******************************************************************************
116 * 80 *
@@ -178,7 +142,6 @@ acpi_ds_result_remove (
178 142
179#endif /* ACPI_FUTURE_USAGE */ 143#endif /* ACPI_FUTURE_USAGE */
180 144
181
182/******************************************************************************* 145/*******************************************************************************
183 * 146 *
184 * FUNCTION: acpi_ds_result_pop 147 * FUNCTION: acpi_ds_result_pop
@@ -227,15 +190,18 @@ acpi_ds_result_pop (
227 *object = state->results.obj_desc [index -1]; 190 *object = state->results.obj_desc [index -1];
228 state->results.obj_desc [index -1] = NULL; 191 state->results.obj_desc [index -1] = NULL;
229 192
230 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", 193 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
231 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL", 194 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
195 *object,
196 (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
232 (u32) index -1, walk_state, state->results.num_results)); 197 (u32) index -1, walk_state, state->results.num_results));
233 198
234 return (AE_OK); 199 return (AE_OK);
235 } 200 }
236 } 201 }
237 202
238 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); 203 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
204 "No result objects! State=%p\n", walk_state));
239 return (AE_AML_NO_RETURN_VALUE); 205 return (AE_AML_NO_RETURN_VALUE);
240} 206}
241 207
@@ -274,7 +240,8 @@ acpi_ds_result_pop_from_bottom (
274 } 240 }
275 241
276 if (!state->results.num_results) { 242 if (!state->results.num_results) {
277 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); 243 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n",
244 walk_state));
278 return (AE_AML_NO_RETURN_VALUE); 245 return (AE_AML_NO_RETURN_VALUE);
279 } 246 }
280 247
@@ -293,7 +260,8 @@ acpi_ds_result_pop_from_bottom (
293 /* Check for a valid result object */ 260 /* Check for a valid result object */
294 261
295 if (!*object) { 262 if (!*object) {
296 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X, Index=%X\n", 263 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
264 "Null operand! State=%p #Ops=%X, Index=%X\n",
297 walk_state, state->results.num_results, (u32) index)); 265 walk_state, state->results.num_results, (u32) index));
298 return (AE_AML_NO_RETURN_VALUE); 266 return (AE_AML_NO_RETURN_VALUE);
299 } 267 }
@@ -344,7 +312,8 @@ acpi_ds_result_push (
344 } 312 }
345 313
346 if (!object) { 314 if (!object) {
347 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Object! Obj=%p State=%p Num=%X\n", 315 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
316 "Null Object! Obj=%p State=%p Num=%X\n",
348 object, walk_state, state->results.num_results)); 317 object, walk_state, state->results.num_results));
349 return (AE_BAD_PARAMETER); 318 return (AE_BAD_PARAMETER);
350 } 319 }
@@ -439,43 +408,6 @@ acpi_ds_result_stack_pop (
439 408
440/******************************************************************************* 409/*******************************************************************************
441 * 410 *
442 * FUNCTION: acpi_ds_obj_stack_delete_all
443 *
444 * PARAMETERS: walk_state - Current Walk state
445 *
446 * RETURN: Status
447 *
448 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
449 * Should be used with great care, if at all!
450 *
451 ******************************************************************************/
452#ifdef ACPI_FUTURE_USAGE
453acpi_status
454acpi_ds_obj_stack_delete_all (
455 struct acpi_walk_state *walk_state)
456{
457 u32 i;
458
459
460 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
461
462
463 /* The stack size is configurable, but fixed */
464
465 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
466 if (walk_state->operands[i]) {
467 acpi_ut_remove_reference (walk_state->operands[i]);
468 walk_state->operands[i] = NULL;
469 }
470 }
471
472 return_ACPI_STATUS (AE_OK);
473}
474#endif /* ACPI_FUTURE_USAGE */
475
476
477/*******************************************************************************
478 *
479 * FUNCTION: acpi_ds_obj_stack_push 411 * FUNCTION: acpi_ds_obj_stack_push
480 * 412 *
481 * PARAMETERS: Object - Object to push 413 * PARAMETERS: Object - Object to push
@@ -517,67 +449,6 @@ acpi_ds_obj_stack_push (
517} 449}
518 450
519 451
520#if 0
521/*******************************************************************************
522 *
523 * FUNCTION: acpi_ds_obj_stack_pop_object
524 *
525 * PARAMETERS: pop_count - Number of objects/entries to pop
526 * walk_state - Current Walk state
527 *
528 * RETURN: Status
529 *
530 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
531 * deleted by this routine.
532 *
533 ******************************************************************************/
534
535acpi_status
536acpi_ds_obj_stack_pop_object (
537 union acpi_operand_object **object,
538 struct acpi_walk_state *walk_state)
539{
540 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
541
542
543 /* Check for stack underflow */
544
545 if (walk_state->num_operands == 0) {
546 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
547 "Missing operand/stack empty! State=%p #Ops=%X\n",
548 walk_state, walk_state->num_operands));
549 *object = NULL;
550 return (AE_AML_NO_OPERAND);
551 }
552
553 /* Pop the stack */
554
555 walk_state->num_operands--;
556
557 /* Check for a valid operand */
558
559 if (!walk_state->operands [walk_state->num_operands]) {
560 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
561 "Null operand! State=%p #Ops=%X\n",
562 walk_state, walk_state->num_operands));
563 *object = NULL;
564 return (AE_AML_NO_OPERAND);
565 }
566
567 /* Get operand and set stack entry to null */
568
569 *object = walk_state->operands [walk_state->num_operands];
570 walk_state->operands [walk_state->num_operands] = NULL;
571
572 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
573 *object, acpi_ut_get_object_type_name (*object),
574 walk_state, walk_state->num_operands));
575
576 return (AE_OK);
577}
578#endif
579
580
581/******************************************************************************* 452/*******************************************************************************
582 * 453 *
583 * FUNCTION: acpi_ds_obj_stack_pop 454 * FUNCTION: acpi_ds_obj_stack_pop
@@ -680,48 +551,6 @@ acpi_ds_obj_stack_pop_and_delete (
680 551
681/******************************************************************************* 552/*******************************************************************************
682 * 553 *
683 * FUNCTION: acpi_ds_obj_stack_get_value
684 *
685 * PARAMETERS: Index - Stack index whose value is desired. Based
686 * on the top of the stack (index=0 == top)
687 * walk_state - Current Walk state
688 *
689 * RETURN: Status
690 *
691 * DESCRIPTION: Retrieve an object from this walk's object stack. Index must
692 * be within the range of the current stack pointer.
693 *
694 ******************************************************************************/
695#ifdef ACPI_FUTURE_USAGE
696void *
697acpi_ds_obj_stack_get_value (
698 u32 index,
699 struct acpi_walk_state *walk_state)
700{
701
702 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
703
704
705 /* Can't do it if the stack is empty */
706
707 if (walk_state->num_operands == 0) {
708 return_PTR (NULL);
709 }
710
711 /* or if the index is past the top of the stack */
712
713 if (index > (walk_state->num_operands - (u32) 1)) {
714 return_PTR (NULL);
715 }
716
717 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
718 index]);
719}
720#endif /* ACPI_FUTURE_USAGE */
721
722
723/*******************************************************************************
724 *
725 * FUNCTION: acpi_ds_get_current_walk_state 554 * FUNCTION: acpi_ds_get_current_walk_state
726 * 555 *
727 * PARAMETERS: Thread - Get current active state for this Thread 556 * PARAMETERS: Thread - Get current active state for this Thread
@@ -757,11 +586,11 @@ acpi_ds_get_current_walk_state (
757 * FUNCTION: acpi_ds_push_walk_state 586 * FUNCTION: acpi_ds_push_walk_state
758 * 587 *
759 * PARAMETERS: walk_state - State to push 588 * PARAMETERS: walk_state - State to push
760 * walk_list - The list that owns the walk stack 589 * Thread - Thread state object
761 * 590 *
762 * RETURN: None 591 * RETURN: None
763 * 592 *
764 * DESCRIPTION: Place the walk_state at the head of the state list. 593 * DESCRIPTION: Place the Thread state at the head of the state list.
765 * 594 *
766 ******************************************************************************/ 595 ******************************************************************************/
767 596
@@ -784,9 +613,9 @@ acpi_ds_push_walk_state (
784 * 613 *
785 * FUNCTION: acpi_ds_pop_walk_state 614 * FUNCTION: acpi_ds_pop_walk_state
786 * 615 *
787 * PARAMETERS: walk_list - The list that owns the walk stack 616 * PARAMETERS: Thread - Current thread state
788 * 617 *
789 * RETURN: A walk_state object popped from the stack 618 * RETURN: A walk_state object popped from the thread's stack
790 * 619 *
791 * DESCRIPTION: Remove and return the walkstate object that is at the head of 620 * DESCRIPTION: Remove and return the walkstate object that is at the head of
792 * the walk stack for the given walk list. NULL indicates that 621 * the walk stack for the given walk list. NULL indicates that
@@ -814,7 +643,7 @@ acpi_ds_pop_walk_state (
814 /* 643 /*
815 * Don't clear the NEXT field, this serves as an indicator 644 * Don't clear the NEXT field, this serves as an indicator
816 * that there is a parent WALK STATE 645 * that there is a parent WALK STATE
817 * NO: walk_state->Next = NULL; 646 * Do Not: walk_state->Next = NULL;
818 */ 647 */
819 } 648 }
820 649
@@ -826,7 +655,9 @@ acpi_ds_pop_walk_state (
826 * 655 *
827 * FUNCTION: acpi_ds_create_walk_state 656 * FUNCTION: acpi_ds_create_walk_state
828 * 657 *
829 * PARAMETERS: Origin - Starting point for this walk 658 * PARAMETERS: owner_id - ID for object creation
659 * Origin - Starting point for this walk
660 * mth_desc - Method object
830 * Thread - Current thread state 661 * Thread - Current thread state
831 * 662 *
832 * RETURN: Pointer to the new walk state. 663 * RETURN: Pointer to the new walk state.
@@ -896,8 +727,7 @@ acpi_ds_create_walk_state (
896 * method_node - Control method NS node, if any 727 * method_node - Control method NS node, if any
897 * aml_start - Start of AML 728 * aml_start - Start of AML
898 * aml_length - Length of AML 729 * aml_length - Length of AML
899 * Params - Method args, if any 730 * Info - Method info block (params, etc.)
900 * return_obj_desc - Where to store a return object, if any
901 * pass_number - 1, 2, or 3 731 * pass_number - 1, 2, or 3
902 * 732 *
903 * RETURN: Status 733 * RETURN: Status
@@ -931,7 +761,7 @@ acpi_ds_init_aml_walk (
931 761
932 /* The next_op of the next_walk will be the beginning of the method */ 762 /* The next_op of the next_walk will be the beginning of the method */
933 763
934 walk_state->next_op = NULL; 764 walk_state->next_op = NULL;
935 765
936 if (info) { 766 if (info) {
937 if (info->parameter_type == ACPI_PARAM_GPE) { 767 if (info->parameter_type == ACPI_PARAM_GPE) {
@@ -939,8 +769,8 @@ acpi_ds_init_aml_walk (
939 info->parameters); 769 info->parameters);
940 } 770 }
941 else { 771 else {
942 walk_state->params = info->parameters; 772 walk_state->params = info->parameters;
943 walk_state->caller_return_desc = &info->return_object; 773 walk_state->caller_return_desc = &info->return_object;
944 } 774 }
945 } 775 }
946 776
@@ -964,7 +794,8 @@ acpi_ds_init_aml_walk (
964 794
965 /* Init the method arguments */ 795 /* Init the method arguments */
966 796
967 status = acpi_ds_method_data_init_args (walk_state->params, ACPI_METHOD_NUM_ARGS, walk_state); 797 status = acpi_ds_method_data_init_args (walk_state->params,
798 ACPI_METHOD_NUM_ARGS, walk_state);
968 if (ACPI_FAILURE (status)) { 799 if (ACPI_FAILURE (status)) {
969 return_ACPI_STATUS (status); 800 return_ACPI_STATUS (status);
970 } 801 }
@@ -1031,12 +862,14 @@ acpi_ds_delete_walk_state (
1031 } 862 }
1032 863
1033 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) { 864 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
1034 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n", walk_state)); 865 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n",
866 walk_state));
1035 return; 867 return;
1036 } 868 }
1037 869
1038 if (walk_state->parser_state.scope) { 870 if (walk_state->parser_state.scope) {
1039 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n", walk_state)); 871 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n",
872 walk_state));
1040 } 873 }
1041 874
1042 /* Always must free any linked control states */ 875 /* Always must free any linked control states */
@@ -1078,7 +911,7 @@ acpi_ds_delete_walk_state (
1078 * 911 *
1079 * PARAMETERS: None 912 * PARAMETERS: None
1080 * 913 *
1081 * RETURN: Status 914 * RETURN: None
1082 * 915 *
1083 * DESCRIPTION: Purge the global state object cache. Used during subsystem 916 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1084 * termination. 917 * termination.
@@ -1098,3 +931,200 @@ acpi_ds_delete_walk_state_cache (
1098#endif 931#endif
1099 932
1100 933
934#ifdef ACPI_OBSOLETE_FUNCTIONS
935/*******************************************************************************
936 *
937 * FUNCTION: acpi_ds_result_insert
938 *
939 * PARAMETERS: Object - Object to push
940 * Index - Where to insert the object
941 * walk_state - Current Walk state
942 *
943 * RETURN: Status
944 *
945 * DESCRIPTION: Insert an object onto this walk's result stack
946 *
947 ******************************************************************************/
948
949acpi_status
950acpi_ds_result_insert (
951 void *object,
952 u32 index,
953 struct acpi_walk_state *walk_state)
954{
955 union acpi_generic_state *state;
956
957
958 ACPI_FUNCTION_NAME ("ds_result_insert");
959
960
961 state = walk_state->results;
962 if (!state) {
963 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
964 walk_state));
965 return (AE_NOT_EXIST);
966 }
967
968 if (index >= ACPI_OBJ_NUM_OPERANDS) {
969 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
970 "Index out of range: %X Obj=%p State=%p Num=%X\n",
971 index, object, walk_state, state->results.num_results));
972 return (AE_BAD_PARAMETER);
973 }
974
975 if (!object) {
976 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
977 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
978 index, object, walk_state, state->results.num_results));
979 return (AE_BAD_PARAMETER);
980 }
981
982 state->results.obj_desc [index] = object;
983 state->results.num_results++;
984
985 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
986 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
987 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
988 walk_state, state->results.num_results, walk_state->current_result));
989
990 return (AE_OK);
991}
992
993
994/*******************************************************************************
995 *
996 * FUNCTION: acpi_ds_obj_stack_delete_all
997 *
998 * PARAMETERS: walk_state - Current Walk state
999 *
1000 * RETURN: Status
1001 *
1002 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
1003 * Should be used with great care, if at all!
1004 *
1005 ******************************************************************************/
1006
1007acpi_status
1008acpi_ds_obj_stack_delete_all (
1009 struct acpi_walk_state *walk_state)
1010{
1011 u32 i;
1012
1013
1014 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
1015
1016
1017 /* The stack size is configurable, but fixed */
1018
1019 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
1020 if (walk_state->operands[i]) {
1021 acpi_ut_remove_reference (walk_state->operands[i]);
1022 walk_state->operands[i] = NULL;
1023 }
1024 }
1025
1026 return_ACPI_STATUS (AE_OK);
1027}
1028
1029
1030/*******************************************************************************
1031 *
1032 * FUNCTION: acpi_ds_obj_stack_pop_object
1033 *
1034 * PARAMETERS: Object - Where to return the popped object
1035 * walk_state - Current Walk state
1036 *
1037 * RETURN: Status
1038 *
1039 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
1040 * deleted by this routine.
1041 *
1042 ******************************************************************************/
1043
1044acpi_status
1045acpi_ds_obj_stack_pop_object (
1046 union acpi_operand_object **object,
1047 struct acpi_walk_state *walk_state)
1048{
1049 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
1050
1051
1052 /* Check for stack underflow */
1053
1054 if (walk_state->num_operands == 0) {
1055 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1056 "Missing operand/stack empty! State=%p #Ops=%X\n",
1057 walk_state, walk_state->num_operands));
1058 *object = NULL;
1059 return (AE_AML_NO_OPERAND);
1060 }
1061
1062 /* Pop the stack */
1063
1064 walk_state->num_operands--;
1065
1066 /* Check for a valid operand */
1067
1068 if (!walk_state->operands [walk_state->num_operands]) {
1069 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1070 "Null operand! State=%p #Ops=%X\n",
1071 walk_state, walk_state->num_operands));
1072 *object = NULL;
1073 return (AE_AML_NO_OPERAND);
1074 }
1075
1076 /* Get operand and set stack entry to null */
1077
1078 *object = walk_state->operands [walk_state->num_operands];
1079 walk_state->operands [walk_state->num_operands] = NULL;
1080
1081 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1082 *object, acpi_ut_get_object_type_name (*object),
1083 walk_state, walk_state->num_operands));
1084
1085 return (AE_OK);
1086}
1087
1088
1089/*******************************************************************************
1090 *
1091 * FUNCTION: acpi_ds_obj_stack_get_value
1092 *
1093 * PARAMETERS: Index - Stack index whose value is desired. Based
1094 * on the top of the stack (index=0 == top)
1095 * walk_state - Current Walk state
1096 *
1097 * RETURN: Pointer to the requested operand
1098 *
1099 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1100 * be within the range of the current stack pointer.
1101 *
1102 ******************************************************************************/
1103
1104void *
1105acpi_ds_obj_stack_get_value (
1106 u32 index,
1107 struct acpi_walk_state *walk_state)
1108{
1109
1110 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
1111
1112
1113 /* Can't do it if the stack is empty */
1114
1115 if (walk_state->num_operands == 0) {
1116 return_PTR (NULL);
1117 }
1118
1119 /* or if the index is past the top of the stack */
1120
1121 if (index > (walk_state->num_operands - (u32) 1)) {
1122 return_PTR (NULL);
1123 }
1124
1125 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
1126 index]);
1127}
1128#endif
1129
1130
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index fdf143b405be..fca4140a50a9 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -31,6 +31,7 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/interrupt.h>
34#include <asm/io.h> 35#include <asm/io.h>
35#include <acpi/acpi_bus.h> 36#include <acpi/acpi_bus.h>
36#include <acpi/acpi_drivers.h> 37#include <acpi/acpi_drivers.h>
@@ -49,17 +50,19 @@ ACPI_MODULE_NAME ("acpi_ec")
49 50
50#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
53#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
52#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ 54#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
53 55
54#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */ 56#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
55#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */ 57#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
56 58
57#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ 59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
58#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
59#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
60 61
61#define ACPI_EC_COMMAND_READ 0x80 62#define ACPI_EC_COMMAND_READ 0x80
62#define ACPI_EC_COMMAND_WRITE 0x81 63#define ACPI_EC_COMMAND_WRITE 0x81
64#define ACPI_EC_BURST_ENABLE 0x82
65#define ACPI_EC_BURST_DISABLE 0x83
63#define ACPI_EC_COMMAND_QUERY 0x84 66#define ACPI_EC_COMMAND_QUERY 0x84
64 67
65static int acpi_ec_add (struct acpi_device *device); 68static int acpi_ec_add (struct acpi_device *device);
@@ -87,7 +90,11 @@ struct acpi_ec {
87 struct acpi_generic_address command_addr; 90 struct acpi_generic_address command_addr;
88 struct acpi_generic_address data_addr; 91 struct acpi_generic_address data_addr;
89 unsigned long global_lock; 92 unsigned long global_lock;
90 spinlock_t lock; 93 unsigned int expect_event;
94 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/
95 atomic_t pending_gpe;
96 struct semaphore sem;
97 wait_queue_head_t wait;
91}; 98};
92 99
93/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 100/* If we find an EC via the ECDT, we need to keep a ptr to its context */
@@ -100,42 +107,111 @@ static struct acpi_device *first_ec;
100 Transaction Management 107 Transaction Management
101 -------------------------------------------------------------------------- */ 108 -------------------------------------------------------------------------- */
102 109
103static int 110static inline u32 acpi_ec_read_status(struct acpi_ec *ec)
104acpi_ec_wait (
105 struct acpi_ec *ec,
106 u8 event)
107{ 111{
108 u32 acpi_ec_status = 0; 112 u32 status = 0;
109 u32 i = ACPI_EC_UDELAY_COUNT;
110 113
111 if (!ec) 114 acpi_hw_low_level_read(8, &status, &ec->status_addr);
112 return -EINVAL; 115 return status;
116}
117
118static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event)
119{
120 int result = 0;
121
122 ACPI_FUNCTION_TRACE("acpi_ec_wait");
113 123
114 /* Poll the EC status register waiting for the event to occur. */ 124 ec->expect_event = event;
125 smp_mb();
126
127 result = wait_event_interruptible_timeout(ec->wait,
128 !ec->expect_event,
129 msecs_to_jiffies(ACPI_EC_DELAY));
130
131 ec->expect_event = 0;
132 smp_mb();
133
134 if (result < 0){
135 ACPI_DEBUG_PRINT((ACPI_DB_ERROR," result = %d ", result));
136 return_VALUE(result);
137 }
138
139 /*
140 * Verify that the event in question has actually happened by
141 * querying EC status. Do the check even if operation timed-out
142 * to make sure that we did not miss interrupt.
143 */
115 switch (event) { 144 switch (event) {
116 case ACPI_EC_EVENT_OBF: 145 case ACPI_EC_EVENT_OBF:
117 do { 146 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
118 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr); 147 return_VALUE(0);
119 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
120 return 0;
121 udelay(ACPI_EC_UDELAY);
122 } while (--i>0);
123 break; 148 break;
149
124 case ACPI_EC_EVENT_IBE: 150 case ACPI_EC_EVENT_IBE:
125 do { 151 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
126 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr); 152 return_VALUE(0);
127 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
128 return 0;
129 udelay(ACPI_EC_UDELAY);
130 } while (--i>0);
131 break; 153 break;
132 default:
133 return -EINVAL;
134 } 154 }
135 155
136 return -ETIME; 156 return_VALUE(-ETIME);
157}
158
159
160
161static int
162acpi_ec_enter_burst_mode (
163 struct acpi_ec *ec)
164{
165 u32 tmp = 0;
166 int status = 0;
167
168 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
169
170 status = acpi_ec_read_status(ec);
171 if (status != -EINVAL &&
172 !(status & ACPI_EC_FLAG_BURST)){
173 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
174 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
175 if (status){
176 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
177 return_VALUE(-EINVAL);
178 }
179 acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
180 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
181 if(tmp != 0x90 ) {/* Burst ACK byte*/
182 return_VALUE(-EINVAL);
183 }
184 }
185
186 atomic_set(&ec->leaving_burst , 0);
187 return_VALUE(0);
137} 188}
138 189
190static int
191acpi_ec_leave_burst_mode (
192 struct acpi_ec *ec)
193{
194 int status =0;
195
196 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
197
198 atomic_set(&ec->leaving_burst , 1);
199 status = acpi_ec_read_status(ec);
200 if (status != -EINVAL &&
201 (status & ACPI_EC_FLAG_BURST)){
202 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr);
203 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
204 if (status){
205 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n"));
207 return_VALUE(-EINVAL);
208 }
209 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
210 status = acpi_ec_read_status(ec);
211 }
212
213 return_VALUE(0);
214}
139 215
140static int 216static int
141acpi_ec_read ( 217acpi_ec_read (
@@ -143,16 +219,15 @@ acpi_ec_read (
143 u8 address, 219 u8 address,
144 u32 *data) 220 u32 *data)
145{ 221{
146 acpi_status status = AE_OK; 222 int status = 0;
147 int result = 0; 223 u32 glk;
148 unsigned long flags = 0;
149 u32 glk = 0;
150 224
151 ACPI_FUNCTION_TRACE("acpi_ec_read"); 225 ACPI_FUNCTION_TRACE("acpi_ec_read");
152 226
153 if (!ec || !data) 227 if (!ec || !data)
154 return_VALUE(-EINVAL); 228 return_VALUE(-EINVAL);
155 229
230retry:
156 *data = 0; 231 *data = 0;
157 232
158 if (ec->global_lock) { 233 if (ec->global_lock) {
@@ -160,32 +235,50 @@ acpi_ec_read (
160 if (ACPI_FAILURE(status)) 235 if (ACPI_FAILURE(status))
161 return_VALUE(-ENODEV); 236 return_VALUE(-ENODEV);
162 } 237 }
163 238
164 spin_lock_irqsave(&ec->lock, flags); 239 WARN_ON(in_interrupt());
240 down(&ec->sem);
241
242 if(acpi_ec_enter_burst_mode(ec))
243 goto end;
165 244
166 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr); 245 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr);
167 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
168 if (result) 247 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
248 if (status) {
169 goto end; 249 goto end;
250 }
170 251
171 acpi_hw_low_level_write(8, address, &ec->data_addr); 252 acpi_hw_low_level_write(8, address, &ec->data_addr);
172 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 253 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
173 if (result) 254 if (status){
255 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
174 goto end; 256 goto end;
175 257 }
176 258
177 acpi_hw_low_level_read(8, data, &ec->data_addr); 259 acpi_hw_low_level_read(8, data, &ec->data_addr);
260 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
178 261
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", 262 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
180 *data, address)); 263 *data, address));
181 264
182end: 265end:
183 spin_unlock_irqrestore(&ec->lock, flags); 266 acpi_ec_leave_burst_mode(ec);
267 up(&ec->sem);
184 268
185 if (ec->global_lock) 269 if (ec->global_lock)
186 acpi_release_global_lock(glk); 270 acpi_release_global_lock(glk);
187 271
188 return_VALUE(result); 272 if(atomic_read(&ec->leaving_burst) == 2){
273 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
274 while(atomic_read(&ec->pending_gpe)){
275 msleep(1);
276 }
277 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
278 goto retry;
279 }
280
281 return_VALUE(status);
189} 282}
190 283
191 284
@@ -195,49 +288,80 @@ acpi_ec_write (
195 u8 address, 288 u8 address,
196 u8 data) 289 u8 data)
197{ 290{
198 int result = 0; 291 int status = 0;
199 acpi_status status = AE_OK; 292 u32 glk;
200 unsigned long flags = 0; 293 u32 tmp;
201 u32 glk = 0;
202 294
203 ACPI_FUNCTION_TRACE("acpi_ec_write"); 295 ACPI_FUNCTION_TRACE("acpi_ec_write");
204 296
205 if (!ec) 297 if (!ec)
206 return_VALUE(-EINVAL); 298 return_VALUE(-EINVAL);
207 299retry:
208 if (ec->global_lock) { 300 if (ec->global_lock) {
209 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 301 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
210 if (ACPI_FAILURE(status)) 302 if (ACPI_FAILURE(status))
211 return_VALUE(-ENODEV); 303 return_VALUE(-ENODEV);
212 } 304 }
213 305
214 spin_lock_irqsave(&ec->lock, flags); 306 WARN_ON(in_interrupt());
307 down(&ec->sem);
308
309 if(acpi_ec_enter_burst_mode(ec))
310 goto end;
311
312 status = acpi_ec_read_status(ec);
313 if (status != -EINVAL &&
314 !(status & ACPI_EC_FLAG_BURST)){
315 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
316 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
317 if (status)
318 goto end;
319 acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
320 if(tmp != 0x90 ) /* Burst ACK byte*/
321 goto end;
322 }
323 /*Now we are in burst mode*/
215 324
216 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); 325 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr);
217 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 326 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
218 if (result) 327 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
328 if (status){
219 goto end; 329 goto end;
330 }
220 331
221 acpi_hw_low_level_write(8, address, &ec->data_addr); 332 acpi_hw_low_level_write(8, address, &ec->data_addr);
222 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 333 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
223 if (result) 334 if (status){
335 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
224 goto end; 336 goto end;
337 }
225 338
226 acpi_hw_low_level_write(8, data, &ec->data_addr); 339 acpi_hw_low_level_write(8, data, &ec->data_addr);
227 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 340 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
228 if (result) 341 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
342 if (status)
229 goto end; 343 goto end;
230 344
231 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", 345 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
232 data, address)); 346 data, address));
233 347
234end: 348end:
235 spin_unlock_irqrestore(&ec->lock, flags); 349 acpi_ec_leave_burst_mode(ec);
350 up(&ec->sem);
236 351
237 if (ec->global_lock) 352 if (ec->global_lock)
238 acpi_release_global_lock(glk); 353 acpi_release_global_lock(glk);
239 354
240 return_VALUE(result); 355 if(atomic_read(&ec->leaving_burst) == 2){
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
357 while(atomic_read(&ec->pending_gpe)){
358 msleep(1);
359 }
360 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
361 goto retry;
362 }
363
364 return_VALUE(status);
241} 365}
242 366
243/* 367/*
@@ -289,16 +413,13 @@ acpi_ec_query (
289 struct acpi_ec *ec, 413 struct acpi_ec *ec,
290 u32 *data) 414 u32 *data)
291{ 415{
292 int result = 0; 416 int status = 0;
293 acpi_status status = AE_OK; 417 u32 glk;
294 unsigned long flags = 0;
295 u32 glk = 0;
296 418
297 ACPI_FUNCTION_TRACE("acpi_ec_query"); 419 ACPI_FUNCTION_TRACE("acpi_ec_query");
298 420
299 if (!ec || !data) 421 if (!ec || !data)
300 return_VALUE(-EINVAL); 422 return_VALUE(-EINVAL);
301
302 *data = 0; 423 *data = 0;
303 424
304 if (ec->global_lock) { 425 if (ec->global_lock) {
@@ -307,29 +428,39 @@ acpi_ec_query (
307 return_VALUE(-ENODEV); 428 return_VALUE(-ENODEV);
308 } 429 }
309 430
431 down(&ec->sem);
432 if(acpi_ec_enter_burst_mode(ec))
433 goto end;
310 /* 434 /*
311 * Query the EC to find out which _Qxx method we need to evaluate. 435 * Query the EC to find out which _Qxx method we need to evaluate.
312 * Note that successful completion of the query causes the ACPI_EC_SCI 436 * Note that successful completion of the query causes the ACPI_EC_SCI
313 * bit to be cleared (and thus clearing the interrupt source). 437 * bit to be cleared (and thus clearing the interrupt source).
314 */ 438 */
315 spin_lock_irqsave(&ec->lock, flags);
316
317 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); 439 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr);
318 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 440 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
319 if (result) 441 if (status){
442 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
320 goto end; 443 goto end;
321 444 }
445
322 acpi_hw_low_level_read(8, data, &ec->data_addr); 446 acpi_hw_low_level_read(8, data, &ec->data_addr);
447 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
323 if (!*data) 448 if (!*data)
324 result = -ENODATA; 449 status = -ENODATA;
325 450
326end: 451end:
327 spin_unlock_irqrestore(&ec->lock, flags); 452 acpi_ec_leave_burst_mode(ec);
453 up(&ec->sem);
328 454
329 if (ec->global_lock) 455 if (ec->global_lock)
330 acpi_release_global_lock(glk); 456 acpi_release_global_lock(glk);
331 457
332 return_VALUE(result); 458 if(atomic_read(&ec->leaving_burst) == 2){
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
460 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
461 status = -ENODATA;
462 }
463 return_VALUE(status);
333} 464}
334 465
335 466
@@ -347,42 +478,29 @@ acpi_ec_gpe_query (
347 void *ec_cxt) 478 void *ec_cxt)
348{ 479{
349 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt; 480 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt;
350 u32 value = 0; 481 u32 value;
351 unsigned long flags = 0; 482 int result = -ENODATA;
352 static char object_name[5] = {'_','Q','0','0','\0'}; 483 static char object_name[5] = {'_','Q','0','0','\0'};
353 const char hex[] = {'0','1','2','3','4','5','6','7', 484 const char hex[] = {'0','1','2','3','4','5','6','7',
354 '8','9','A','B','C','D','E','F'}; 485 '8','9','A','B','C','D','E','F'};
355 486
356 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query"); 487 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
357 488
358 if (!ec_cxt) 489 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
359 goto end; 490 result = acpi_ec_query(ec, &value);
360
361 spin_lock_irqsave(&ec->lock, flags);
362 acpi_hw_low_level_read(8, &value, &ec->command_addr);
363 spin_unlock_irqrestore(&ec->lock, flags);
364 491
365 /* TBD: Implement asynch events! 492 if (result)
366 * NOTE: All we care about are EC-SCI's. Other EC events are
367 * handled via polling (yuck!). This is because some systems
368 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
369 * a purely interrupt-driven approach (grumble, grumble).
370 */
371 if (!(value & ACPI_EC_FLAG_SCI))
372 goto end; 493 goto end;
373 494
374 if (acpi_ec_query(ec, &value))
375 goto end;
376
377 object_name[2] = hex[((value >> 4) & 0x0F)]; 495 object_name[2] = hex[((value >> 4) & 0x0F)];
378 object_name[3] = hex[(value & 0x0F)]; 496 object_name[3] = hex[(value & 0x0F)];
379 497
380 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); 498 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
381 499
382 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 500 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
383 501end:
384end: 502 atomic_dec(&ec->pending_gpe);
385 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 503 return;
386} 504}
387 505
388static u32 506static u32
@@ -390,6 +508,7 @@ acpi_ec_gpe_handler (
390 void *data) 508 void *data)
391{ 509{
392 acpi_status status = AE_OK; 510 acpi_status status = AE_OK;
511 u32 value;
393 struct acpi_ec *ec = (struct acpi_ec *) data; 512 struct acpi_ec *ec = (struct acpi_ec *) data;
394 513
395 if (!ec) 514 if (!ec)
@@ -397,13 +516,41 @@ acpi_ec_gpe_handler (
397 516
398 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 517 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
399 518
400 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, 519 value = acpi_ec_read_status(ec);
401 acpi_ec_gpe_query, ec);
402 520
403 if (status == AE_OK) 521 if((value & ACPI_EC_FLAG_IBF) &&
404 return ACPI_INTERRUPT_HANDLED; 522 !(value & ACPI_EC_FLAG_BURST) &&
405 else 523 (atomic_read(&ec->leaving_burst) == 0)) {
406 return ACPI_INTERRUPT_NOT_HANDLED; 524 /*
525 * the embedded controller disables
526 * burst mode for any reason other
527 * than the burst disable command
528 * to process critical event.
529 */
530 atomic_set(&ec->leaving_burst , 2); /* block current pending transaction
531 and retry */
532 wake_up(&ec->wait);
533 }else {
534 if ((ec->expect_event == ACPI_EC_EVENT_OBF &&
535 (value & ACPI_EC_FLAG_OBF)) ||
536 (ec->expect_event == ACPI_EC_EVENT_IBE &&
537 !(value & ACPI_EC_FLAG_IBF))) {
538 ec->expect_event = 0;
539 wake_up(&ec->wait);
540 return ACPI_INTERRUPT_HANDLED;
541 }
542 }
543
544 if (value & ACPI_EC_FLAG_SCI){
545 atomic_add(1, &ec->pending_gpe) ;
546 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
547 acpi_ec_gpe_query, ec);
548 return status == AE_OK ?
549 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
550 }
551 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
552 return status == AE_OK ?
553 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
407} 554}
408 555
409/* -------------------------------------------------------------------------- 556/* --------------------------------------------------------------------------
@@ -421,10 +568,8 @@ acpi_ec_space_setup (
421 * The EC object is in the handler context and is needed 568 * The EC object is in the handler context and is needed
422 * when calling the acpi_ec_space_handler. 569 * when calling the acpi_ec_space_handler.
423 */ 570 */
424 if(function == ACPI_REGION_DEACTIVATE) 571 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
425 *return_context = NULL; 572 handler_context : NULL;
426 else
427 *return_context = handler_context;
428 573
429 return AE_OK; 574 return AE_OK;
430} 575}
@@ -441,7 +586,7 @@ acpi_ec_space_handler (
441{ 586{
442 int result = 0; 587 int result = 0;
443 struct acpi_ec *ec = NULL; 588 struct acpi_ec *ec = NULL;
444 u32 temp = 0; 589 u64 temp = *value;
445 acpi_integer f_v = 0; 590 acpi_integer f_v = 0;
446 int i = 0; 591 int i = 0;
447 592
@@ -450,10 +595,9 @@ acpi_ec_space_handler (
450 if ((address > 0xFF) || !value || !handler_context) 595 if ((address > 0xFF) || !value || !handler_context)
451 return_VALUE(AE_BAD_PARAMETER); 596 return_VALUE(AE_BAD_PARAMETER);
452 597
453 if(bit_width != 8) { 598 if (bit_width != 8 && acpi_strict) {
454 printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n"); 599 printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n");
455 if (acpi_strict) 600 return_VALUE(AE_BAD_PARAMETER);
456 return_VALUE(AE_BAD_PARAMETER);
457 } 601 }
458 602
459 ec = (struct acpi_ec *) handler_context; 603 ec = (struct acpi_ec *) handler_context;
@@ -461,11 +605,11 @@ acpi_ec_space_handler (
461next_byte: 605next_byte:
462 switch (function) { 606 switch (function) {
463 case ACPI_READ: 607 case ACPI_READ:
464 result = acpi_ec_read(ec, (u8) address, &temp); 608 temp = 0;
465 *value = (acpi_integer) temp; 609 result = acpi_ec_read(ec, (u8) address, (u32 *)&temp);
466 break; 610 break;
467 case ACPI_WRITE: 611 case ACPI_WRITE:
468 result = acpi_ec_write(ec, (u8) address, (u8) *value); 612 result = acpi_ec_write(ec, (u8) address, (u8) temp);
469 break; 613 break;
470 default: 614 default:
471 result = -EINVAL; 615 result = -EINVAL;
@@ -474,19 +618,18 @@ next_byte:
474 } 618 }
475 619
476 bit_width -= 8; 620 bit_width -= 8;
477 if(bit_width){ 621 if (bit_width) {
478 622 if (function == ACPI_READ)
479 if(function == ACPI_READ) 623 f_v |= temp << 8 * i;
480 f_v |= (acpi_integer) (*value) << 8*i; 624 if (function == ACPI_WRITE)
481 if(function == ACPI_WRITE) 625 temp >>= 8;
482 (*value) >>=8;
483 i++; 626 i++;
627 address++;
484 goto next_byte; 628 goto next_byte;
485 } 629 }
486 630
487 631 if (function == ACPI_READ) {
488 if(function == ACPI_READ){ 632 f_v |= temp << 8 * i;
489 f_v |= (acpi_integer) (*value) << 8*i;
490 *value = f_v; 633 *value = f_v;
491 } 634 }
492 635
@@ -505,8 +648,6 @@ out:
505 default: 648 default:
506 return_VALUE(AE_OK); 649 return_VALUE(AE_OK);
507 } 650 }
508
509
510} 651}
511 652
512 653
@@ -533,6 +674,7 @@ acpi_ec_read_info (struct seq_file *seq, void *offset)
533 (u32) ec->status_addr.address, (u32) ec->data_addr.address); 674 (u32) ec->status_addr.address, (u32) ec->data_addr.address);
534 seq_printf(seq, "use global lock: %s\n", 675 seq_printf(seq, "use global lock: %s\n",
535 ec->global_lock?"yes":"no"); 676 ec->global_lock?"yes":"no");
677 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
536 678
537end: 679end:
538 return_VALUE(0); 680 return_VALUE(0);
@@ -555,7 +697,7 @@ static int
555acpi_ec_add_fs ( 697acpi_ec_add_fs (
556 struct acpi_device *device) 698 struct acpi_device *device)
557{ 699{
558 struct proc_dir_entry *entry = NULL; 700 struct proc_dir_entry *entry;
559 701
560 ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); 702 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
561 703
@@ -606,9 +748,9 @@ static int
606acpi_ec_add ( 748acpi_ec_add (
607 struct acpi_device *device) 749 struct acpi_device *device)
608{ 750{
609 int result = 0; 751 int result;
610 acpi_status status = AE_OK; 752 acpi_status status;
611 struct acpi_ec *ec = NULL; 753 struct acpi_ec *ec;
612 unsigned long uid; 754 unsigned long uid;
613 755
614 ACPI_FUNCTION_TRACE("acpi_ec_add"); 756 ACPI_FUNCTION_TRACE("acpi_ec_add");
@@ -623,7 +765,10 @@ acpi_ec_add (
623 765
624 ec->handle = device->handle; 766 ec->handle = device->handle;
625 ec->uid = -1; 767 ec->uid = -1;
626 spin_lock_init(&ec->lock); 768 atomic_set(&ec->pending_gpe, 0);
769 atomic_set(&ec->leaving_burst , 1);
770 init_MUTEX(&ec->sem);
771 init_waitqueue_head(&ec->wait);
627 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); 772 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
628 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 773 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
629 acpi_driver_data(device) = ec; 774 acpi_driver_data(device) = ec;
@@ -637,7 +782,7 @@ acpi_ec_add (
637 if (ec_ecdt && ec_ecdt->uid == uid) { 782 if (ec_ecdt && ec_ecdt->uid == uid) {
638 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, 783 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
639 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 784 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
640 785
641 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler); 786 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler);
642 787
643 kfree(ec_ecdt); 788 kfree(ec_ecdt);
@@ -677,7 +822,7 @@ acpi_ec_remove (
677 struct acpi_device *device, 822 struct acpi_device *device,
678 int type) 823 int type)
679{ 824{
680 struct acpi_ec *ec = NULL; 825 struct acpi_ec *ec;
681 826
682 ACPI_FUNCTION_TRACE("acpi_ec_remove"); 827 ACPI_FUNCTION_TRACE("acpi_ec_remove");
683 828
@@ -732,8 +877,8 @@ static int
732acpi_ec_start ( 877acpi_ec_start (
733 struct acpi_device *device) 878 struct acpi_device *device)
734{ 879{
735 acpi_status status = AE_OK; 880 acpi_status status;
736 struct acpi_ec *ec = NULL; 881 struct acpi_ec *ec;
737 882
738 ACPI_FUNCTION_TRACE("acpi_ec_start"); 883 ACPI_FUNCTION_TRACE("acpi_ec_start");
739 884
@@ -789,8 +934,8 @@ acpi_ec_stop (
789 struct acpi_device *device, 934 struct acpi_device *device,
790 int type) 935 int type)
791{ 936{
792 acpi_status status = AE_OK; 937 acpi_status status;
793 struct acpi_ec *ec = NULL; 938 struct acpi_ec *ec;
794 939
795 ACPI_FUNCTION_TRACE("acpi_ec_stop"); 940 ACPI_FUNCTION_TRACE("acpi_ec_stop");
796 941
@@ -832,7 +977,6 @@ acpi_fake_ecdt_callback (
832 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); 977 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit);
833 if (ACPI_FAILURE(status)) 978 if (ACPI_FAILURE(status))
834 return status; 979 return status;
835 spin_lock_init(&ec_ecdt->lock);
836 ec_ecdt->global_lock = TRUE; 980 ec_ecdt->global_lock = TRUE;
837 ec_ecdt->handle = handle; 981 ec_ecdt->handle = handle;
838 982
@@ -890,7 +1034,7 @@ acpi_ec_get_real_ecdt(void)
890 acpi_status status; 1034 acpi_status status;
891 struct acpi_table_ecdt *ecdt_ptr; 1035 struct acpi_table_ecdt *ecdt_ptr;
892 1036
893 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, 1037 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
894 (struct acpi_table_header **) &ecdt_ptr); 1038 (struct acpi_table_header **) &ecdt_ptr);
895 if (ACPI_FAILURE(status)) 1039 if (ACPI_FAILURE(status))
896 return -ENODEV; 1040 return -ENODEV;
@@ -905,11 +1049,12 @@ acpi_ec_get_real_ecdt(void)
905 return -ENOMEM; 1049 return -ENOMEM;
906 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1050 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
907 1051
1052 init_MUTEX(&ec_ecdt->sem);
1053 init_waitqueue_head(&ec_ecdt->wait);
908 ec_ecdt->command_addr = ecdt_ptr->ec_control; 1054 ec_ecdt->command_addr = ecdt_ptr->ec_control;
909 ec_ecdt->status_addr = ecdt_ptr->ec_control; 1055 ec_ecdt->status_addr = ecdt_ptr->ec_control;
910 ec_ecdt->data_addr = ecdt_ptr->ec_data; 1056 ec_ecdt->data_addr = ecdt_ptr->ec_data;
911 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 1057 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
912 spin_lock_init(&ec_ecdt->lock);
913 /* use the GL just to be safe */ 1058 /* use the GL just to be safe */
914 ec_ecdt->global_lock = TRUE; 1059 ec_ecdt->global_lock = TRUE;
915 ec_ecdt->uid = ecdt_ptr->uid; 1060 ec_ecdt->uid = ecdt_ptr->uid;
@@ -978,7 +1123,7 @@ error:
978 1123
979static int __init acpi_ec_init (void) 1124static int __init acpi_ec_init (void)
980{ 1125{
981 int result = 0; 1126 int result;
982 1127
983 ACPI_FUNCTION_TRACE("acpi_ec_init"); 1128 ACPI_FUNCTION_TRACE("acpi_ec_init");
984 1129
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
index 2a213604ae51..dd3a72a869f4 100644
--- a/drivers/acpi/events/evevent.c
+++ b/drivers/acpi/events/evevent.c
@@ -47,6 +47,16 @@
47#define _COMPONENT ACPI_EVENTS 47#define _COMPONENT ACPI_EVENTS
48 ACPI_MODULE_NAME ("evevent") 48 ACPI_MODULE_NAME ("evevent")
49 49
50/* Local prototypes */
51
52static acpi_status
53acpi_ev_fixed_event_initialize (
54 void);
55
56static u32
57acpi_ev_fixed_event_dispatch (
58 u32 event);
59
50 60
51/******************************************************************************* 61/*******************************************************************************
52 * 62 *
@@ -56,7 +66,7 @@
56 * 66 *
57 * RETURN: Status 67 * RETURN: Status
58 * 68 *
59 * DESCRIPTION: Initialize global data structures for events. 69 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
60 * 70 *
61 ******************************************************************************/ 71 ******************************************************************************/
62 72
@@ -78,9 +88,9 @@ acpi_ev_initialize_events (
78 } 88 }
79 89
80 /* 90 /*
81 * Initialize the Fixed and General Purpose Events. This is 91 * Initialize the Fixed and General Purpose Events. This is done prior to
82 * done prior to enabling SCIs to prevent interrupts from 92 * enabling SCIs to prevent interrupts from occurring before the handlers are
83 * occurring before handers are installed. 93 * installed.
84 */ 94 */
85 status = acpi_ev_fixed_event_initialize (); 95 status = acpi_ev_fixed_event_initialize ();
86 if (ACPI_FAILURE (status)) { 96 if (ACPI_FAILURE (status)) {
@@ -161,7 +171,7 @@ acpi_ev_install_xrupt_handlers (
161 * 171 *
162 ******************************************************************************/ 172 ******************************************************************************/
163 173
164acpi_status 174static acpi_status
165acpi_ev_fixed_event_initialize ( 175acpi_ev_fixed_event_initialize (
166 void) 176 void)
167{ 177{
@@ -180,7 +190,8 @@ acpi_ev_fixed_event_initialize (
180 /* Enable the fixed event */ 190 /* Enable the fixed event */
181 191
182 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { 192 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
183 status = acpi_set_register (acpi_gbl_fixed_event_info[i].enable_register_id, 193 status = acpi_set_register (
194 acpi_gbl_fixed_event_info[i].enable_register_id,
184 0, ACPI_MTX_LOCK); 195 0, ACPI_MTX_LOCK);
185 if (ACPI_FAILURE (status)) { 196 if (ACPI_FAILURE (status)) {
186 return (status); 197 return (status);
@@ -200,7 +211,7 @@ acpi_ev_fixed_event_initialize (
200 * 211 *
201 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 212 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
202 * 213 *
203 * DESCRIPTION: Checks the PM status register for fixed events 214 * DESCRIPTION: Checks the PM status register for active fixed events
204 * 215 *
205 ******************************************************************************/ 216 ******************************************************************************/
206 217
@@ -221,8 +232,10 @@ acpi_ev_fixed_event_detect (
221 * Read the fixed feature status and enable registers, as all the cases 232 * Read the fixed feature status and enable registers, as all the cases
222 * depend on their values. Ignore errors here. 233 * depend on their values. Ignore errors here.
223 */ 234 */
224 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, &fixed_status); 235 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
225 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &fixed_enable); 236 &fixed_status);
237 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE,
238 &fixed_enable);
226 239
227 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, 240 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
228 "Fixed Event Block: Enable %08X Status %08X\n", 241 "Fixed Event Block: Enable %08X Status %08X\n",
@@ -259,7 +272,7 @@ acpi_ev_fixed_event_detect (
259 * 272 *
260 ******************************************************************************/ 273 ******************************************************************************/
261 274
262u32 275static u32
263acpi_ev_fixed_event_dispatch ( 276acpi_ev_fixed_event_dispatch (
264 u32 event) 277 u32 event)
265{ 278{
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index 118d72ac7c76..081120b109ba 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -48,6 +48,12 @@
48#define _COMPONENT ACPI_EVENTS 48#define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evgpe") 49 ACPI_MODULE_NAME ("evgpe")
50 50
51/* Local prototypes */
52
53static void ACPI_SYSTEM_XFACE
54acpi_ev_asynch_execute_gpe_method (
55 void *context);
56
51 57
52/******************************************************************************* 58/*******************************************************************************
53 * 59 *
@@ -335,8 +341,10 @@ acpi_ev_get_gpe_event_info (
335 gpe_block = acpi_gbl_gpe_fadt_blocks[i]; 341 gpe_block = acpi_gbl_gpe_fadt_blocks[i];
336 if (gpe_block) { 342 if (gpe_block) {
337 if ((gpe_number >= gpe_block->block_base_number) && 343 if ((gpe_number >= gpe_block->block_base_number) &&
338 (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) { 344 (gpe_number < gpe_block->block_base_number +
339 return (&gpe_block->event_info[gpe_number - gpe_block->block_base_number]); 345 (gpe_block->register_count * 8))) {
346 return (&gpe_block->event_info[gpe_number -
347 gpe_block->block_base_number]);
340 } 348 }
341 } 349 }
342 } 350 }
@@ -437,7 +445,7 @@ acpi_ev_gpe_detect (
437 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", 445 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
438 gpe_register_info->base_gpe_number, status_reg, enable_reg)); 446 gpe_register_info->base_gpe_number, status_reg, enable_reg));
439 447
440 /* First check if there is anything active at all in this register */ 448 /* Check if there is anything active at all in this register */
441 449
442 enabled_status_byte = (u8) (status_reg & enable_reg); 450 enabled_status_byte = (u8) (status_reg & enable_reg);
443 if (!enabled_status_byte) { 451 if (!enabled_status_byte) {
@@ -457,8 +465,8 @@ acpi_ev_gpe_detect (
457 * or method. 465 * or method.
458 */ 466 */
459 int_status |= acpi_ev_gpe_dispatch ( 467 int_status |= acpi_ev_gpe_dispatch (
460 &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j], 468 &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j],
461 (u32) j + gpe_register_info->base_gpe_number); 469 (u32) j + gpe_register_info->base_gpe_number);
462 } 470 }
463 } 471 }
464 } 472 }
@@ -523,7 +531,8 @@ acpi_ev_asynch_execute_gpe_method (
523 * Take a snapshot of the GPE info for this level - we copy the 531 * Take a snapshot of the GPE info for this level - we copy the
524 * info to prevent a race condition with remove_handler/remove_block. 532 * info to prevent a race condition with remove_handler/remove_block.
525 */ 533 */
526 ACPI_MEMCPY (&local_gpe_event_info, gpe_event_info, sizeof (struct acpi_gpe_event_info)); 534 ACPI_MEMCPY (&local_gpe_event_info, gpe_event_info,
535 sizeof (struct acpi_gpe_event_info));
527 536
528 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); 537 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
529 if (ACPI_FAILURE (status)) { 538 if (ACPI_FAILURE (status)) {
@@ -534,7 +543,8 @@ acpi_ev_asynch_execute_gpe_method (
534 * Must check for control method type dispatch one more 543 * Must check for control method type dispatch one more
535 * time to avoid race with ev_gpe_install_handler 544 * time to avoid race with ev_gpe_install_handler
536 */ 545 */
537 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) { 546 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
547 ACPI_GPE_DISPATCH_METHOD) {
538 /* 548 /*
539 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx 549 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
540 * control method that corresponds to this GPE 550 * control method that corresponds to this GPE
@@ -553,7 +563,8 @@ acpi_ev_asynch_execute_gpe_method (
553 } 563 }
554 } 564 }
555 565
556 if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { 566 if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
567 ACPI_GPE_LEVEL_TRIGGERED) {
557 /* 568 /*
558 * GPE is level-triggered, we clear the GPE status bit after 569 * GPE is level-triggered, we clear the GPE status bit after
559 * handling the event. 570 * handling the event.
@@ -575,7 +586,7 @@ acpi_ev_asynch_execute_gpe_method (
575 * 586 *
576 * FUNCTION: acpi_ev_gpe_dispatch 587 * FUNCTION: acpi_ev_gpe_dispatch
577 * 588 *
578 * PARAMETERS: gpe_event_info - info for this GPE 589 * PARAMETERS: gpe_event_info - Info for this GPE
579 * gpe_number - Number relative to the parent GPE block 590 * gpe_number - Number relative to the parent GPE block
580 * 591 *
581 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 592 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
@@ -602,10 +613,12 @@ acpi_ev_gpe_dispatch (
602 * If edge-triggered, clear the GPE status bit now. Note that 613 * If edge-triggered, clear the GPE status bit now. Note that
603 * level-triggered events are cleared after the GPE is serviced. 614 * level-triggered events are cleared after the GPE is serviced.
604 */ 615 */
605 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED) { 616 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
617 ACPI_GPE_EDGE_TRIGGERED) {
606 status = acpi_hw_clear_gpe (gpe_event_info); 618 status = acpi_hw_clear_gpe (gpe_event_info);
607 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
608 ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n", 620 ACPI_REPORT_ERROR ((
621 "acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n",
609 acpi_format_exception (status), gpe_number)); 622 acpi_format_exception (status), gpe_number));
610 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); 623 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
611 } 624 }
@@ -639,7 +652,8 @@ acpi_ev_gpe_dispatch (
639 652
640 /* It is now safe to clear level-triggered events. */ 653 /* It is now safe to clear level-triggered events. */
641 654
642 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { 655 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
656 ACPI_GPE_LEVEL_TRIGGERED) {
643 status = acpi_hw_clear_gpe (gpe_event_info); 657 status = acpi_hw_clear_gpe (gpe_event_info);
644 if (ACPI_FAILURE (status)) { 658 if (ACPI_FAILURE (status)) {
645 ACPI_REPORT_ERROR (( 659 ACPI_REPORT_ERROR ((
@@ -704,7 +718,6 @@ acpi_ev_gpe_dispatch (
704 718
705 719
706#ifdef ACPI_GPE_NOTIFY_CHECK 720#ifdef ACPI_GPE_NOTIFY_CHECK
707
708/******************************************************************************* 721/*******************************************************************************
709 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED 722 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
710 * 723 *
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index 00d981f53c6a..84186a7d17b2 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -48,6 +48,39 @@
48#define _COMPONENT ACPI_EVENTS 48#define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evgpeblk") 49 ACPI_MODULE_NAME ("evgpeblk")
50 50
51/* Local prototypes */
52
53static acpi_status
54acpi_ev_save_method_info (
55 acpi_handle obj_handle,
56 u32 level,
57 void *obj_desc,
58 void **return_value);
59
60static acpi_status
61acpi_ev_match_prw_and_gpe (
62 acpi_handle obj_handle,
63 u32 level,
64 void *info,
65 void **return_value);
66
67static struct acpi_gpe_xrupt_info *
68acpi_ev_get_gpe_xrupt_block (
69 u32 interrupt_level);
70
71static acpi_status
72acpi_ev_delete_gpe_xrupt (
73 struct acpi_gpe_xrupt_info *gpe_xrupt);
74
75static acpi_status
76acpi_ev_install_gpe_block (
77 struct acpi_gpe_block_info *gpe_block,
78 u32 interrupt_level);
79
80static acpi_status
81acpi_ev_create_gpe_info_blocks (
82 struct acpi_gpe_block_info *gpe_block);
83
51 84
52/******************************************************************************* 85/*******************************************************************************
53 * 86 *
@@ -155,7 +188,7 @@ unlock_and_exit:
155} 188}
156 189
157 190
158/****************************************************************************** 191/*******************************************************************************
159 * 192 *
160 * FUNCTION: acpi_ev_delete_gpe_handlers 193 * FUNCTION: acpi_ev_delete_gpe_handlers
161 * 194 *
@@ -190,7 +223,8 @@ acpi_ev_delete_gpe_handlers (
190 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { 223 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
191 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; 224 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
192 225
193 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) { 226 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
227 ACPI_GPE_DISPATCH_HANDLER) {
194 ACPI_MEM_FREE (gpe_event_info->dispatch.handler); 228 ACPI_MEM_FREE (gpe_event_info->dispatch.handler);
195 gpe_event_info->dispatch.handler = NULL; 229 gpe_event_info->dispatch.handler = NULL;
196 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; 230 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;
@@ -471,7 +505,7 @@ acpi_ev_get_gpe_xrupt_block (
471 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block"); 505 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
472 506
473 507
474 /* No need for spin lock since we are not changing any list elements here */ 508 /* No need for lock since we are not changing any list elements here */
475 509
476 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; 510 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
477 while (next_gpe_xrupt) { 511 while (next_gpe_xrupt) {
@@ -619,7 +653,7 @@ acpi_ev_install_gpe_block (
619 goto unlock_and_exit; 653 goto unlock_and_exit;
620 } 654 }
621 655
622 /* Install the new block at the end of the list for this interrupt with lock */ 656 /* Install the new block at the end of the list with lock */
623 657
624 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 658 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
625 if (gpe_xrupt_block->gpe_block_list_head) { 659 if (gpe_xrupt_block->gpe_block_list_head) {
@@ -756,10 +790,12 @@ acpi_ev_create_gpe_info_blocks (
756 * per register. Initialization to zeros is sufficient. 790 * per register. Initialization to zeros is sufficient.
757 */ 791 */
758 gpe_event_info = ACPI_MEM_CALLOCATE ( 792 gpe_event_info = ACPI_MEM_CALLOCATE (
759 ((acpi_size) gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) * 793 ((acpi_size) gpe_block->register_count *
794 ACPI_GPE_REGISTER_WIDTH) *
760 sizeof (struct acpi_gpe_event_info)); 795 sizeof (struct acpi_gpe_event_info));
761 if (!gpe_event_info) { 796 if (!gpe_event_info) {
762 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_event_info table\n")); 797 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
798 "Could not allocate the gpe_event_info table\n"));
763 status = AE_NO_MEMORY; 799 status = AE_NO_MEMORY;
764 goto error_exit; 800 goto error_exit;
765 } 801 }
@@ -899,7 +935,8 @@ acpi_ev_create_gpe_block (
899 gpe_block->block_base_number = gpe_block_base_number; 935 gpe_block->block_base_number = gpe_block_base_number;
900 gpe_block->node = gpe_device; 936 gpe_block->node = gpe_device;
901 937
902 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address, sizeof (struct acpi_generic_address)); 938 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address,
939 sizeof (struct acpi_generic_address));
903 940
904 /* Create the register_info and event_info sub-structures */ 941 /* Create the register_info and event_info sub-structures */
905 942
@@ -1061,8 +1098,9 @@ acpi_ev_gpe_initialize (
1061 1098
1062 /* Install GPE Block 0 */ 1099 /* Install GPE Block 0 */
1063 1100
1064 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe0_blk, 1101 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1065 register_count0, 0, acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]); 1102 &acpi_gbl_FADT->xgpe0_blk, register_count0, 0,
1103 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]);
1066 1104
1067 if (ACPI_FAILURE (status)) { 1105 if (ACPI_FAILURE (status)) {
1068 ACPI_REPORT_ERROR (( 1106 ACPI_REPORT_ERROR ((
@@ -1094,8 +1132,9 @@ acpi_ev_gpe_initialize (
1094 else { 1132 else {
1095 /* Install GPE Block 1 */ 1133 /* Install GPE Block 1 */
1096 1134
1097 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe1_blk, 1135 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1098 register_count1, acpi_gbl_FADT->gpe1_base, 1136 &acpi_gbl_FADT->xgpe1_blk, register_count1,
1137 acpi_gbl_FADT->gpe1_base,
1099 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]); 1138 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]);
1100 1139
1101 if (ACPI_FAILURE (status)) { 1140 if (ACPI_FAILURE (status)) {
@@ -1109,7 +1148,7 @@ acpi_ev_gpe_initialize (
1109 * space. However, GPE0 always starts at GPE number zero. 1148 * space. However, GPE0 always starts at GPE number zero.
1110 */ 1149 */
1111 gpe_number_max = acpi_gbl_FADT->gpe1_base + 1150 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1112 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); 1151 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1113 } 1152 }
1114 } 1153 }
1115 1154
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 2548efa7a45f..659e90956112 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -50,6 +50,35 @@
50 ACPI_MODULE_NAME ("evmisc") 50 ACPI_MODULE_NAME ("evmisc")
51 51
52 52
53#ifdef ACPI_DEBUG_OUTPUT
54static const char *acpi_notify_value_names[] =
55{
56 "Bus Check",
57 "Device Check",
58 "Device Wake",
59 "Eject request",
60 "Device Check Light",
61 "Frequency Mismatch",
62 "Bus Mode Mismatch",
63 "Power Fault"
64};
65#endif
66
67/* Local prototypes */
68
69static void ACPI_SYSTEM_XFACE
70acpi_ev_notify_dispatch (
71 void *context);
72
73static void ACPI_SYSTEM_XFACE
74acpi_ev_global_lock_thread (
75 void *context);
76
77static u32
78acpi_ev_global_lock_handler (
79 void *context);
80
81
53/******************************************************************************* 82/*******************************************************************************
54 * 83 *
55 * FUNCTION: acpi_ev_is_notify_object 84 * FUNCTION: acpi_ev_is_notify_object
@@ -98,20 +127,6 @@ acpi_ev_is_notify_object (
98 * 127 *
99 ******************************************************************************/ 128 ******************************************************************************/
100 129
101#ifdef ACPI_DEBUG_OUTPUT
102static const char *acpi_notify_value_names[] =
103{
104 "Bus Check",
105 "Device Check",
106 "Device Wake",
107 "Eject request",
108 "Device Check Light",
109 "Frequency Mismatch",
110 "Bus Mode Mismatch",
111 "Power Fault"
112};
113#endif
114
115acpi_status 130acpi_status
116acpi_ev_queue_notify_request ( 131acpi_ev_queue_notify_request (
117 struct acpi_namespace_node *node, 132 struct acpi_namespace_node *node,
@@ -128,9 +143,10 @@ acpi_ev_queue_notify_request (
128 143
129 /* 144 /*
130 * For value 3 (Ejection Request), some device method may need to be run. 145 * For value 3 (Ejection Request), some device method may need to be run.
131 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run. 146 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
147 * to be run.
132 * For value 0x80 (Status Change) on the power button or sleep button, 148 * For value 0x80 (Status Change) on the power button or sleep button,
133 * initiate soft-off or sleep operation? 149 * initiate soft-off or sleep operation?
134 */ 150 */
135 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 151 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
136 "Dispatching Notify(%X) on node %p\n", notify_value, node)); 152 "Dispatching Notify(%X) on node %p\n", notify_value, node));
@@ -140,8 +156,9 @@ acpi_ev_queue_notify_request (
140 acpi_notify_value_names[notify_value])); 156 acpi_notify_value_names[notify_value]));
141 } 157 }
142 else { 158 else {
143 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: 0x%2.2X **Device Specific**\n", 159 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
144 notify_value)); 160 "Notify value: 0x%2.2X **Device Specific**\n",
161 notify_value));
145 } 162 }
146 163
147 /* Get the notify object attached to the NS Node */ 164 /* Get the notify object attached to the NS Node */
@@ -210,7 +227,7 @@ acpi_ev_queue_notify_request (
210 * 227 *
211 * FUNCTION: acpi_ev_notify_dispatch 228 * FUNCTION: acpi_ev_notify_dispatch
212 * 229 *
213 * PARAMETERS: Context - To be passsed to the notify handler 230 * PARAMETERS: Context - To be passed to the notify handler
214 * 231 *
215 * RETURN: None. 232 * RETURN: None.
216 * 233 *
@@ -219,7 +236,7 @@ acpi_ev_queue_notify_request (
219 * 236 *
220 ******************************************************************************/ 237 ******************************************************************************/
221 238
222void ACPI_SYSTEM_XFACE 239static void ACPI_SYSTEM_XFACE
223acpi_ev_notify_dispatch ( 240acpi_ev_notify_dispatch (
224 void *context) 241 void *context)
225{ 242{
@@ -234,7 +251,8 @@ acpi_ev_notify_dispatch (
234 251
235 /* 252 /*
236 * We will invoke a global notify handler if installed. 253 * We will invoke a global notify handler if installed.
237 * This is done _before_ we invoke the per-device handler attached to the device. 254 * This is done _before_ we invoke the per-device handler attached
255 * to the device.
238 */ 256 */
239 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) { 257 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {
240 /* Global system notification handler */ 258 /* Global system notification handler */
@@ -256,15 +274,17 @@ acpi_ev_notify_dispatch (
256 /* Invoke the system handler first, if present */ 274 /* Invoke the system handler first, if present */
257 275
258 if (global_handler) { 276 if (global_handler) {
259 global_handler (notify_info->notify.node, notify_info->notify.value, global_context); 277 global_handler (notify_info->notify.node, notify_info->notify.value,
278 global_context);
260 } 279 }
261 280
262 /* Now invoke the per-device handler, if present */ 281 /* Now invoke the per-device handler, if present */
263 282
264 handler_obj = notify_info->notify.handler_obj; 283 handler_obj = notify_info->notify.handler_obj;
265 if (handler_obj) { 284 if (handler_obj) {
266 handler_obj->notify.handler (notify_info->notify.node, notify_info->notify.value, 285 handler_obj->notify.handler (notify_info->notify.node,
267 handler_obj->notify.context); 286 notify_info->notify.value,
287 handler_obj->notify.context);
268 } 288 }
269 289
270 /* All done with the info object */ 290 /* All done with the info object */
@@ -370,7 +390,8 @@ acpi_ev_global_lock_handler (
370 ******************************************************************************/ 390 ******************************************************************************/
371 391
372acpi_status 392acpi_status
373acpi_ev_init_global_lock_handler (void) 393acpi_ev_init_global_lock_handler (
394 void)
374{ 395{
375 acpi_status status; 396 acpi_status status;
376 397
@@ -380,7 +401,7 @@ acpi_ev_init_global_lock_handler (void)
380 401
381 acpi_gbl_global_lock_present = TRUE; 402 acpi_gbl_global_lock_present = TRUE;
382 status = acpi_install_fixed_event_handler (ACPI_EVENT_GLOBAL, 403 status = acpi_install_fixed_event_handler (ACPI_EVENT_GLOBAL,
383 acpi_ev_global_lock_handler, NULL); 404 acpi_ev_global_lock_handler, NULL);
384 405
385 /* 406 /*
386 * If the global lock does not exist on this platform, the attempt 407 * If the global lock does not exist on this platform, the attempt
@@ -433,8 +454,10 @@ acpi_ev_acquire_global_lock (
433 454
434 acpi_gbl_global_lock_thread_count++; 455 acpi_gbl_global_lock_thread_count++;
435 456
436 /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */ 457 /*
437 458 * If we (OS side vs. BIOS side) have the hardware lock already,
459 * we are done
460 */
438 if (acpi_gbl_global_lock_acquired) { 461 if (acpi_gbl_global_lock_acquired) {
439 return_ACPI_STATUS (AE_OK); 462 return_ACPI_STATUS (AE_OK);
440 } 463 }
@@ -480,7 +503,8 @@ acpi_ev_acquire_global_lock (
480 ******************************************************************************/ 503 ******************************************************************************/
481 504
482acpi_status 505acpi_status
483acpi_ev_release_global_lock (void) 506acpi_ev_release_global_lock (
507 void)
484{ 508{
485 u8 pending = FALSE; 509 u8 pending = FALSE;
486 acpi_status status = AE_OK; 510 acpi_status status = AE_OK;
@@ -490,7 +514,8 @@ acpi_ev_release_global_lock (void)
490 514
491 515
492 if (!acpi_gbl_global_lock_thread_count) { 516 if (!acpi_gbl_global_lock_thread_count) {
493 ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n")); 517 ACPI_REPORT_WARNING((
518 "Cannot release HW Global Lock, it has not been acquired\n"));
494 return_ACPI_STATUS (AE_NOT_ACQUIRED); 519 return_ACPI_STATUS (AE_NOT_ACQUIRED);
495 } 520 }
496 521
@@ -515,7 +540,8 @@ acpi_ev_release_global_lock (void)
515 * register 540 * register
516 */ 541 */
517 if (pending) { 542 if (pending) {
518 status = acpi_set_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK); 543 status = acpi_set_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE,
544 1, ACPI_MTX_LOCK);
519 } 545 }
520 546
521 return_ACPI_STATUS (status); 547 return_ACPI_STATUS (status);
@@ -535,7 +561,8 @@ acpi_ev_release_global_lock (void)
535 ******************************************************************************/ 561 ******************************************************************************/
536 562
537void 563void
538acpi_ev_terminate (void) 564acpi_ev_terminate (
565 void)
539{ 566{
540 acpi_native_uint i; 567 acpi_native_uint i;
541 acpi_status status; 568 acpi_status status;
@@ -555,7 +582,8 @@ acpi_ev_terminate (void)
555 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { 582 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
556 status = acpi_disable_event ((u32) i, 0); 583 status = acpi_disable_event ((u32) i, 0);
557 if (ACPI_FAILURE (status)) { 584 if (ACPI_FAILURE (status)) {
558 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (u32) i)); 585 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
586 "Could not disable fixed event %d\n", (u32) i));
559 } 587 }
560 } 588 }
561 589
@@ -567,7 +595,8 @@ acpi_ev_terminate (void)
567 595
568 status = acpi_ev_remove_sci_handler (); 596 status = acpi_ev_remove_sci_handler ();
569 if (ACPI_FAILURE(status)) { 597 if (ACPI_FAILURE(status)) {
570 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n")); 598 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
599 "Could not remove SCI handler\n"));
571 } 600 }
572 } 601 }
573 602
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 772342708a7a..a1d7276c5742 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -58,6 +58,22 @@ static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPA
58 ACPI_ADR_SPACE_PCI_CONFIG, 58 ACPI_ADR_SPACE_PCI_CONFIG,
59 ACPI_ADR_SPACE_DATA_TABLE}; 59 ACPI_ADR_SPACE_DATA_TABLE};
60 60
61/* Local prototypes */
62
63static acpi_status
64acpi_ev_reg_run (
65 acpi_handle obj_handle,
66 u32 level,
67 void *context,
68 void **return_value);
69
70static acpi_status
71acpi_ev_install_handler (
72 acpi_handle obj_handle,
73 u32 level,
74 void *context,
75 void **return_value);
76
61 77
62/******************************************************************************* 78/*******************************************************************************
63 * 79 *
@@ -179,8 +195,8 @@ acpi_ev_initialize_op_regions (
179 * 195 *
180 * FUNCTION: acpi_ev_execute_reg_method 196 * FUNCTION: acpi_ev_execute_reg_method
181 * 197 *
182 * PARAMETERS: region_obj - Object structure 198 * PARAMETERS: region_obj - Region object
183 * Function - Passed to _REG: On (1) or Off (0) 199 * Function - Passed to _REG: On (1) or Off (0)
184 * 200 *
185 * RETURN: Status 201 * RETURN: Status
186 * 202 *
@@ -323,14 +339,16 @@ acpi_ev_address_space_dispatch (
323 if (!region_setup) { 339 if (!region_setup) {
324 /* No initialization routine, exit with error */ 340 /* No initialization routine, exit with error */
325 341
326 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No init routine for region(%p) [%s]\n", 342 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
343 "No init routine for region(%p) [%s]\n",
327 region_obj, acpi_ut_get_region_name (region_obj->region.space_id))); 344 region_obj, acpi_ut_get_region_name (region_obj->region.space_id)));
328 return_ACPI_STATUS (AE_NOT_EXIST); 345 return_ACPI_STATUS (AE_NOT_EXIST);
329 } 346 }
330 347
331 /* 348 /*
332 * We must exit the interpreter because the region setup will potentially 349 * We must exit the interpreter because the region
333 * execute control methods (e.g., _REG method for this region) 350 * setup will potentially execute control methods
351 * (e.g., _REG method for this region)
334 */ 352 */
335 acpi_ex_exit_interpreter (); 353 acpi_ex_exit_interpreter ();
336 354
@@ -621,7 +639,7 @@ acpi_ev_attach_region (
621 * 639 *
622 ******************************************************************************/ 640 ******************************************************************************/
623 641
624acpi_status 642static acpi_status
625acpi_ev_install_handler ( 643acpi_ev_install_handler (
626 acpi_handle obj_handle, 644 acpi_handle obj_handle,
627 u32 level, 645 u32 level,
@@ -848,7 +866,8 @@ acpi_ev_install_space_handler (
848 if (handler_obj->address_space.handler == handler) { 866 if (handler_obj->address_space.handler == handler) {
849 /* 867 /*
850 * It is (relatively) OK to attempt to install the SAME 868 * It is (relatively) OK to attempt to install the SAME
851 * handler twice. This can easily happen with PCI_Config space. 869 * handler twice. This can easily happen
870 * with PCI_Config space.
852 */ 871 */
853 status = AE_SAME_HANDLER; 872 status = AE_SAME_HANDLER;
854 goto unlock_and_exit; 873 goto unlock_and_exit;
@@ -1011,7 +1030,7 @@ acpi_ev_execute_reg_methods (
1011 * 1030 *
1012 ******************************************************************************/ 1031 ******************************************************************************/
1013 1032
1014acpi_status 1033static acpi_status
1015acpi_ev_reg_run ( 1034acpi_ev_reg_run (
1016 acpi_handle obj_handle, 1035 acpi_handle obj_handle,
1017 u32 level, 1036 u32 level,
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 4983a3378be5..95bc09c73a6a 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -61,7 +61,7 @@
61 * 61 *
62 * RETURN: Status 62 * RETURN: Status
63 * 63 *
64 * DESCRIPTION: Do any prep work for region handling, a nop for now 64 * DESCRIPTION: Setup a system_memory operation region
65 * 65 *
66 ******************************************************************************/ 66 ******************************************************************************/
67 67
@@ -115,7 +115,7 @@ acpi_ev_system_memory_region_setup (
115 * 115 *
116 * RETURN: Status 116 * RETURN: Status
117 * 117 *
118 * DESCRIPTION: Do any prep work for region handling 118 * DESCRIPTION: Setup a IO operation region
119 * 119 *
120 ******************************************************************************/ 120 ******************************************************************************/
121 121
@@ -144,14 +144,14 @@ acpi_ev_io_space_region_setup (
144 * 144 *
145 * FUNCTION: acpi_ev_pci_config_region_setup 145 * FUNCTION: acpi_ev_pci_config_region_setup
146 * 146 *
147 * PARAMETERS: Handle - Region we are interested in 147 * PARAMETERS: Handle - Region we are interested in
148 * Function - Start or stop 148 * Function - Start or stop
149 * handler_context - Address space handler context 149 * handler_context - Address space handler context
150 * region_context - Region specific context 150 * region_context - Region specific context
151 * 151 *
152 * RETURN: Status 152 * RETURN: Status
153 * 153 *
154 * DESCRIPTION: Do any prep work for region handling 154 * DESCRIPTION: Setup a PCI_Config operation region
155 * 155 *
156 * MUTEX: Assumes namespace is not locked 156 * MUTEX: Assumes namespace is not locked
157 * 157 *
@@ -324,7 +324,7 @@ acpi_ev_pci_config_region_setup (
324 * 324 *
325 * RETURN: Status 325 * RETURN: Status
326 * 326 *
327 * DESCRIPTION: Do any prep work for region handling 327 * DESCRIPTION: Setup a pci_bAR operation region
328 * 328 *
329 * MUTEX: Assumes namespace is not locked 329 * MUTEX: Assumes namespace is not locked
330 * 330 *
@@ -355,7 +355,7 @@ acpi_ev_pci_bar_region_setup (
355 * 355 *
356 * RETURN: Status 356 * RETURN: Status
357 * 357 *
358 * DESCRIPTION: Do any prep work for region handling 358 * DESCRIPTION: Setup a CMOS operation region
359 * 359 *
360 * MUTEX: Assumes namespace is not locked 360 * MUTEX: Assumes namespace is not locked
361 * 361 *
@@ -386,7 +386,7 @@ acpi_ev_cmos_region_setup (
386 * 386 *
387 * RETURN: Status 387 * RETURN: Status
388 * 388 *
389 * DESCRIPTION: Do any prep work for region handling 389 * DESCRIPTION: Default region initialization
390 * 390 *
391 ******************************************************************************/ 391 ******************************************************************************/
392 392
diff --git a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c
index 46b31995c827..f3123c26ae98 100644
--- a/drivers/acpi/events/evsci.c
+++ b/drivers/acpi/events/evsci.c
@@ -49,6 +49,12 @@
49#define _COMPONENT ACPI_EVENTS 49#define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evsci") 50 ACPI_MODULE_NAME ("evsci")
51 51
52/* Local prototypes */
53
54static u32 ACPI_SYSTEM_XFACE
55acpi_ev_sci_xrupt_handler (
56 void *context);
57
52 58
53/******************************************************************************* 59/*******************************************************************************
54 * 60 *
@@ -146,7 +152,8 @@ acpi_ev_gpe_xrupt_handler (
146 ******************************************************************************/ 152 ******************************************************************************/
147 153
148u32 154u32
149acpi_ev_install_sci_handler (void) 155acpi_ev_install_sci_handler (
156 void)
150{ 157{
151 u32 status = AE_OK; 158 u32 status = AE_OK;
152 159
@@ -180,7 +187,8 @@ acpi_ev_install_sci_handler (void)
180 ******************************************************************************/ 187 ******************************************************************************/
181 188
182acpi_status 189acpi_status
183acpi_ev_remove_sci_handler (void) 190acpi_ev_remove_sci_handler (
191 void)
184{ 192{
185 acpi_status status; 193 acpi_status status;
186 194
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 0bfec10a5f1e..4092d47f6758 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -64,6 +64,7 @@
64 * DESCRIPTION: Saves the pointer to the handler function 64 * DESCRIPTION: Saves the pointer to the handler function
65 * 65 *
66 ******************************************************************************/ 66 ******************************************************************************/
67
67#ifdef ACPI_FUTURE_USAGE 68#ifdef ACPI_FUTURE_USAGE
68acpi_status 69acpi_status
69acpi_install_exception_handler ( 70acpi_install_exception_handler (
@@ -457,7 +458,8 @@ acpi_remove_notify_handler (
457 /* Root Object */ 458 /* Root Object */
458 459
459 if (device == ACPI_ROOT_OBJECT) { 460 if (device == ACPI_ROOT_OBJECT) {
460 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n")); 461 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
462 "Removing notify handler for ROOT object.\n"));
461 463
462 if (((handler_type & ACPI_SYSTEM_NOTIFY) && 464 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
463 !acpi_gbl_system_notify.handler) || 465 !acpi_gbl_system_notify.handler) ||
@@ -564,8 +566,9 @@ EXPORT_SYMBOL(acpi_remove_notify_handler);
564 * 566 *
565 * FUNCTION: acpi_install_gpe_handler 567 * FUNCTION: acpi_install_gpe_handler
566 * 568 *
567 * PARAMETERS: gpe_number - The GPE number within the GPE block 569 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
568 * gpe_block - GPE block (NULL == FADT GPEs) 570 * defined GPEs)
571 * gpe_number - The GPE number within the GPE block
569 * Type - Whether this GPE should be treated as an 572 * Type - Whether this GPE should be treated as an
570 * edge- or level-triggered interrupt. 573 * edge- or level-triggered interrupt.
571 * Address - Address of the handler 574 * Address - Address of the handler
@@ -662,8 +665,9 @@ EXPORT_SYMBOL(acpi_install_gpe_handler);
662 * 665 *
663 * FUNCTION: acpi_remove_gpe_handler 666 * FUNCTION: acpi_remove_gpe_handler
664 * 667 *
665 * PARAMETERS: gpe_number - The event to remove a handler 668 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
666 * gpe_block - GPE block (NULL == FADT GPEs) 669 * defined GPEs)
670 * gpe_number - The event to remove a handler
667 * Address - Address of the handler 671 * Address - Address of the handler
668 * 672 *
669 * RETURN: Status 673 * RETURN: Status
@@ -766,7 +770,8 @@ EXPORT_SYMBOL(acpi_remove_gpe_handler);
766 * FUNCTION: acpi_acquire_global_lock 770 * FUNCTION: acpi_acquire_global_lock
767 * 771 *
768 * PARAMETERS: Timeout - How long the caller is willing to wait 772 * PARAMETERS: Timeout - How long the caller is willing to wait
769 * out_handle - A handle to the lock if acquired 773 * Handle - Where the handle to the lock is returned
774 * (if acquired)
770 * 775 *
771 * RETURN: Status 776 * RETURN: Status
772 * 777 *
@@ -812,7 +817,7 @@ EXPORT_SYMBOL(acpi_acquire_global_lock);
812 * 817 *
813 * RETURN: Status 818 * RETURN: Status
814 * 819 *
815 * DESCRIPTION: Release the ACPI Global Lock 820 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
816 * 821 *
817 ******************************************************************************/ 822 ******************************************************************************/
818 823
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index fa8d5f25be62..f337dc2cc569 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -64,7 +64,8 @@
64 ******************************************************************************/ 64 ******************************************************************************/
65 65
66acpi_status 66acpi_status
67acpi_enable (void) 67acpi_enable (
68 void)
68{ 69{
69 acpi_status status = AE_OK; 70 acpi_status status = AE_OK;
70 71
@@ -91,7 +92,8 @@ acpi_enable (void)
91 return_ACPI_STATUS (status); 92 return_ACPI_STATUS (status);
92 } 93 }
93 94
94 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n")); 95 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
96 "Transition to ACPI mode successful\n"));
95 } 97 }
96 98
97 return_ACPI_STATUS (status); 99 return_ACPI_STATUS (status);
@@ -106,12 +108,13 @@ acpi_enable (void)
106 * 108 *
107 * RETURN: Status 109 * RETURN: Status
108 * 110 *
109 * DESCRIPTION: Transfers the system into LEGACY mode. 111 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
110 * 112 *
111 ******************************************************************************/ 113 ******************************************************************************/
112 114
113acpi_status 115acpi_status
114acpi_disable (void) 116acpi_disable (
117 void)
115{ 118{
116 acpi_status status = AE_OK; 119 acpi_status status = AE_OK;
117 120
@@ -125,7 +128,8 @@ acpi_disable (void)
125 } 128 }
126 129
127 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { 130 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
128 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n")); 131 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
132 "System is already in legacy (non-ACPI) mode\n"));
129 } 133 }
130 else { 134 else {
131 /* Transition to LEGACY mode */ 135 /* Transition to LEGACY mode */
@@ -133,7 +137,8 @@ acpi_disable (void)
133 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY); 137 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY);
134 138
135 if (ACPI_FAILURE (status)) { 139 if (ACPI_FAILURE (status)) {
136 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode")); 140 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
141 "Could not exit ACPI mode to legacy mode"));
137 return_ACPI_STATUS (status); 142 return_ACPI_STATUS (status);
138 } 143 }
139 144
@@ -214,7 +219,7 @@ EXPORT_SYMBOL(acpi_enable_event);
214 * 219 *
215 * RETURN: Status 220 * RETURN: Status
216 * 221 *
217 * DESCRIPTION: Enable an ACPI event (general purpose) 222 * DESCRIPTION: Set the type of an individual GPE
218 * 223 *
219 ******************************************************************************/ 224 ******************************************************************************/
220 225
@@ -519,13 +524,12 @@ unlock_and_exit:
519 524
520 525
521#ifdef ACPI_FUTURE_USAGE 526#ifdef ACPI_FUTURE_USAGE
522
523/******************************************************************************* 527/*******************************************************************************
524 * 528 *
525 * FUNCTION: acpi_get_event_status 529 * FUNCTION: acpi_get_event_status
526 * 530 *
527 * PARAMETERS: Event - The fixed event 531 * PARAMETERS: Event - The fixed event
528 * Event Status - Where the current status of the event will 532 * event_status - Where the current status of the event will
529 * be returned 533 * be returned
530 * 534 *
531 * RETURN: Status 535 * RETURN: Status
@@ -571,7 +575,7 @@ acpi_get_event_status (
571 * PARAMETERS: gpe_device - Parent GPE Device 575 * PARAMETERS: gpe_device - Parent GPE Device
572 * gpe_number - GPE level within the GPE block 576 * gpe_number - GPE level within the GPE block
573 * Flags - Called from an ISR or not 577 * Flags - Called from an ISR or not
574 * Event Status - Where the current status of the event will 578 * event_status - Where the current status of the event will
575 * be returned 579 * be returned
576 * 580 *
577 * RETURN: Status 581 * RETURN: Status
@@ -775,4 +779,5 @@ unlock_and_exit:
775 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 779 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
776 return_ACPI_STATUS (status); 780 return_ACPI_STATUS (status);
777} 781}
782
778EXPORT_SYMBOL(acpi_remove_gpe_block); 783EXPORT_SYMBOL(acpi_remove_gpe_block);
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index ac3c061967f2..734b2f24af48 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -54,6 +54,14 @@
54#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig") 55 ACPI_MODULE_NAME ("exconfig")
56 56
57/* Local prototypes */
58
59static acpi_status
60acpi_ex_add_table (
61 struct acpi_table_header *table,
62 struct acpi_namespace_node *parent_node,
63 union acpi_operand_object **ddb_handle);
64
57 65
58/******************************************************************************* 66/*******************************************************************************
59 * 67 *
@@ -70,7 +78,7 @@
70 * 78 *
71 ******************************************************************************/ 79 ******************************************************************************/
72 80
73acpi_status 81static acpi_status
74acpi_ex_add_table ( 82acpi_ex_add_table (
75 struct acpi_table_header *table, 83 struct acpi_table_header *table,
76 struct acpi_namespace_node *parent_node, 84 struct acpi_namespace_node *parent_node,
@@ -95,10 +103,10 @@ acpi_ex_add_table (
95 103
96 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc)); 104 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
97 105
98 table_info.type = ACPI_TABLE_SSDT; 106 table_info.type = ACPI_TABLE_SSDT;
99 table_info.pointer = table; 107 table_info.pointer = table;
100 table_info.length = (acpi_size) table->length; 108 table_info.length = (acpi_size) table->length;
101 table_info.allocation = ACPI_MEM_ALLOCATED; 109 table_info.allocation = ACPI_MEM_ALLOCATED;
102 110
103 status = acpi_tb_install_table (&table_info); 111 status = acpi_tb_install_table (&table_info);
104 if (ACPI_FAILURE (status)) { 112 if (ACPI_FAILURE (status)) {
@@ -226,11 +234,10 @@ acpi_ex_load_table_op (
226 start_node = parent_node; 234 start_node = parent_node;
227 } 235 }
228 236
229 /* 237 /* Find the node referenced by the parameter_path_string */
230 * Find the node referenced by the parameter_path_string 238
231 */
232 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node, 239 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
233 ACPI_NS_SEARCH_PARENT, &parameter_node); 240 ACPI_NS_SEARCH_PARENT, &parameter_node);
234 if (ACPI_FAILURE (status)) { 241 if (ACPI_FAILURE (status)) {
235 return_ACPI_STATUS (status); 242 return_ACPI_STATUS (status);
236 } 243 }
@@ -248,7 +255,8 @@ acpi_ex_load_table_op (
248 if (parameter_node) { 255 if (parameter_node) {
249 /* Store the parameter data into the optional parameter object */ 256 /* Store the parameter data into the optional parameter object */
250 257
251 status = acpi_ex_store (operand[5], ACPI_CAST_PTR (union acpi_operand_object, parameter_node), 258 status = acpi_ex_store (operand[5],
259 ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
252 walk_state); 260 walk_state);
253 if (ACPI_FAILURE (status)) { 261 if (ACPI_FAILURE (status)) {
254 (void) acpi_ex_unload_table (ddb_handle); 262 (void) acpi_ex_unload_table (ddb_handle);
@@ -371,7 +379,8 @@ acpi_ex_load_op (
371 goto cleanup; 379 goto cleanup;
372 } 380 }
373 381
374 table_ptr = ACPI_CAST_PTR (struct acpi_table_header, buffer_desc->buffer.pointer); 382 table_ptr = ACPI_CAST_PTR (struct acpi_table_header,
383 buffer_desc->buffer.pointer);
375 384
376 /* Sanity check the table length */ 385 /* Sanity check the table length */
377 386
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index df7ba1219bf6..97856c48bd74 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -50,6 +50,15 @@
50#define _COMPONENT ACPI_EXECUTER 50#define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exconvrt") 51 ACPI_MODULE_NAME ("exconvrt")
52 52
53/* Local prototypes */
54
55static u32
56acpi_ex_convert_to_ascii (
57 acpi_integer integer,
58 u16 base,
59 u8 *string,
60 u8 max_length);
61
53 62
54/******************************************************************************* 63/*******************************************************************************
55 * 64 *
@@ -115,9 +124,8 @@ acpi_ex_convert_to_integer (
115 */ 124 */
116 result = 0; 125 result = 0;
117 126
118 /* 127 /* String conversion is different than Buffer conversion */
119 * String conversion is different than Buffer conversion 128
120 */
121 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 129 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
122 case ACPI_TYPE_STRING: 130 case ACPI_TYPE_STRING:
123 131
@@ -168,9 +176,8 @@ acpi_ex_convert_to_integer (
168 break; 176 break;
169 } 177 }
170 178
171 /* 179 /* Create a new integer */
172 * Create a new integer 180
173 */
174 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 181 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
175 if (!return_desc) { 182 if (!return_desc) {
176 return_ACPI_STATUS (AE_NO_MEMORY); 183 return_ACPI_STATUS (AE_NO_MEMORY);
@@ -251,7 +258,8 @@ acpi_ex_convert_to_buffer (
251 * ASL/AML code that depends on the null being transferred to the new 258 * ASL/AML code that depends on the null being transferred to the new
252 * buffer. 259 * buffer.
253 */ 260 */
254 return_desc = acpi_ut_create_buffer_object ((acpi_size) obj_desc->string.length + 1); 261 return_desc = acpi_ut_create_buffer_object (
262 (acpi_size) obj_desc->string.length + 1);
255 if (!return_desc) { 263 if (!return_desc) {
256 return_ACPI_STATUS (AE_NO_MEMORY); 264 return_ACPI_STATUS (AE_NO_MEMORY);
257 } 265 }
@@ -291,7 +299,7 @@ acpi_ex_convert_to_buffer (
291 * 299 *
292 ******************************************************************************/ 300 ******************************************************************************/
293 301
294u32 302static u32
295acpi_ex_convert_to_ascii ( 303acpi_ex_convert_to_ascii (
296 acpi_integer integer, 304 acpi_integer integer,
297 u16 base, 305 u16 base,
@@ -357,8 +365,9 @@ acpi_ex_convert_to_ascii (
357 365
358 case 16: 366 case 16:
359 367
360 hex_length = ACPI_MUL_2 (data_width); /* 2 ascii hex chars per data byte */ 368 /* hex_length: 2 ascii hex chars per data byte */
361 369
370 hex_length = ACPI_MUL_2 (data_width);
362 for (i = 0, j = (hex_length-1); i < hex_length; i++, j--) { 371 for (i = 0, j = (hex_length-1); i < hex_length; i++, j--) {
363 /* Get one hex digit, most significant digits first */ 372 /* Get one hex digit, most significant digits first */
364 373
@@ -475,7 +484,7 @@ acpi_ex_convert_to_string (
475 /* Setup string length, base, and separator */ 484 /* Setup string length, base, and separator */
476 485
477 switch (type) { 486 switch (type) {
478 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by to_decimal_string operator */ 487 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by to_decimal_string */
479 /* 488 /*
480 * From ACPI: "If Data is a buffer, it is converted to a string of 489 * From ACPI: "If Data is a buffer, it is converted to a string of
481 * decimal values separated by commas." 490 * decimal values separated by commas."
@@ -509,7 +518,7 @@ acpi_ex_convert_to_string (
509 string_length = (obj_desc->buffer.length * 3); 518 string_length = (obj_desc->buffer.length * 3);
510 break; 519 break;
511 520
512 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string operator */ 521 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string */
513 /* 522 /*
514 * From ACPI: "If Data is a buffer, it is converted to a string of 523 * From ACPI: "If Data is a buffer, it is converted to a string of
515 * hexadecimal values separated by commas." 524 * hexadecimal values separated by commas."
@@ -530,9 +539,8 @@ acpi_ex_convert_to_string (
530 return_ACPI_STATUS (AE_AML_STRING_LIMIT); 539 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
531 } 540 }
532 541
533 /* 542 /* Create a new string object and string buffer */
534 * Create a new string object and string buffer 543
535 */
536 return_desc = acpi_ut_create_string_object ((acpi_size) string_length); 544 return_desc = acpi_ut_create_string_object ((acpi_size) string_length);
537 if (!return_desc) { 545 if (!return_desc) {
538 return_ACPI_STATUS (AE_NO_MEMORY); 546 return_ACPI_STATUS (AE_NO_MEMORY);
@@ -551,8 +559,10 @@ acpi_ex_convert_to_string (
551 *new_buf++ = separator; /* each separated by a comma or space */ 559 *new_buf++ = separator; /* each separated by a comma or space */
552 } 560 }
553 561
554 /* Null terminate the string (overwrites final comma/space from above) */ 562 /*
555 563 * Null terminate the string
564 * (overwrites final comma/space from above)
565 */
556 new_buf--; 566 new_buf--;
557 *new_buf = 0; 567 *new_buf = 0;
558 break; 568 break;
@@ -645,7 +655,6 @@ acpi_ex_convert_to_target_type (
645 655
646 656
647 case ACPI_TYPE_STRING: 657 case ACPI_TYPE_STRING:
648
649 /* 658 /*
650 * The operand must be a String. We can convert an 659 * The operand must be a String. We can convert an
651 * Integer or Buffer if necessary 660 * Integer or Buffer if necessary
@@ -656,7 +665,6 @@ acpi_ex_convert_to_target_type (
656 665
657 666
658 case ACPI_TYPE_BUFFER: 667 case ACPI_TYPE_BUFFER:
659
660 /* 668 /*
661 * The operand must be a Buffer. We can convert an 669 * The operand must be a Buffer. We can convert an
662 * Integer or String if necessary 670 * Integer or String if necessary
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index d94c260dac6d..812cdcb2e370 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -55,7 +55,7 @@
55 55
56 56
57#ifndef ACPI_NO_METHOD_EXECUTION 57#ifndef ACPI_NO_METHOD_EXECUTION
58/***************************************************************************** 58/*******************************************************************************
59 * 59 *
60 * FUNCTION: acpi_ex_create_alias 60 * FUNCTION: acpi_ex_create_alias
61 * 61 *
@@ -65,7 +65,7 @@
65 * 65 *
66 * DESCRIPTION: Create a new named alias 66 * DESCRIPTION: Create a new named alias
67 * 67 *
68 ****************************************************************************/ 68 ******************************************************************************/
69 69
70acpi_status 70acpi_status
71acpi_ex_create_alias ( 71acpi_ex_create_alias (
@@ -140,8 +140,7 @@ acpi_ex_create_alias (
140 * target node or the alias Node 140 * target node or the alias Node
141 */ 141 */
142 status = acpi_ns_attach_object (alias_node, 142 status = acpi_ns_attach_object (alias_node,
143 acpi_ns_get_attached_object (target_node), 143 acpi_ns_get_attached_object (target_node), target_node->type);
144 target_node->type);
145 break; 144 break;
146 } 145 }
147 146
@@ -151,7 +150,7 @@ acpi_ex_create_alias (
151} 150}
152 151
153 152
154/***************************************************************************** 153/*******************************************************************************
155 * 154 *
156 * FUNCTION: acpi_ex_create_event 155 * FUNCTION: acpi_ex_create_event
157 * 156 *
@@ -161,7 +160,7 @@ acpi_ex_create_alias (
161 * 160 *
162 * DESCRIPTION: Create a new event object 161 * DESCRIPTION: Create a new event object
163 * 162 *
164 ****************************************************************************/ 163 ******************************************************************************/
165 164
166acpi_status 165acpi_status
167acpi_ex_create_event ( 166acpi_ex_create_event (
@@ -185,7 +184,7 @@ acpi_ex_create_event (
185 * that the event is created in an unsignalled state 184 * that the event is created in an unsignalled state
186 */ 185 */
187 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, 186 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0,
188 &obj_desc->event.semaphore); 187 &obj_desc->event.semaphore);
189 if (ACPI_FAILURE (status)) { 188 if (ACPI_FAILURE (status)) {
190 goto cleanup; 189 goto cleanup;
191 } 190 }
@@ -193,7 +192,7 @@ acpi_ex_create_event (
193 /* Attach object to the Node */ 192 /* Attach object to the Node */
194 193
195 status = acpi_ns_attach_object ((struct acpi_namespace_node *) walk_state->operands[0], 194 status = acpi_ns_attach_object ((struct acpi_namespace_node *) walk_state->operands[0],
196 obj_desc, ACPI_TYPE_EVENT); 195 obj_desc, ACPI_TYPE_EVENT);
197 196
198cleanup: 197cleanup:
199 /* 198 /*
@@ -205,7 +204,7 @@ cleanup:
205} 204}
206 205
207 206
208/***************************************************************************** 207/*******************************************************************************
209 * 208 *
210 * FUNCTION: acpi_ex_create_mutex 209 * FUNCTION: acpi_ex_create_mutex
211 * 210 *
@@ -217,7 +216,7 @@ cleanup:
217 * 216 *
218 * Mutex (Name[0], sync_level[1]) 217 * Mutex (Name[0], sync_level[1])
219 * 218 *
220 ****************************************************************************/ 219 ******************************************************************************/
221 220
222acpi_status 221acpi_status
223acpi_ex_create_mutex ( 222acpi_ex_create_mutex (
@@ -267,20 +266,20 @@ cleanup:
267} 266}
268 267
269 268
270/***************************************************************************** 269/*******************************************************************************
271 * 270 *
272 * FUNCTION: acpi_ex_create_region 271 * FUNCTION: acpi_ex_create_region
273 * 272 *
274 * PARAMETERS: aml_start - Pointer to the region declaration AML 273 * PARAMETERS: aml_start - Pointer to the region declaration AML
275 * aml_length - Max length of the declaration AML 274 * aml_length - Max length of the declaration AML
276 * Operands - List of operands for the opcode 275 * region_space - space_iD for the region
277 * walk_state - Current state 276 * walk_state - Current state
278 * 277 *
279 * RETURN: Status 278 * RETURN: Status
280 * 279 *
281 * DESCRIPTION: Create a new operation region object 280 * DESCRIPTION: Create a new operation region object
282 * 281 *
283 ****************************************************************************/ 282 ******************************************************************************/
284 283
285acpi_status 284acpi_status
286acpi_ex_create_region ( 285acpi_ex_create_region (
@@ -321,7 +320,7 @@ acpi_ex_create_region (
321 } 320 }
322 321
323 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n", 322 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
324 acpi_ut_get_region_name (region_space), region_space)); 323 acpi_ut_get_region_name (region_space), region_space));
325 324
326 /* Create the region descriptor */ 325 /* Create the region descriptor */
327 326
@@ -360,7 +359,7 @@ cleanup:
360} 359}
361 360
362 361
363/***************************************************************************** 362/*******************************************************************************
364 * 363 *
365 * FUNCTION: acpi_ex_create_table_region 364 * FUNCTION: acpi_ex_create_table_region
366 * 365 *
@@ -370,7 +369,7 @@ cleanup:
370 * 369 *
371 * DESCRIPTION: Create a new data_table_region object 370 * DESCRIPTION: Create a new data_table_region object
372 * 371 *
373 ****************************************************************************/ 372 ******************************************************************************/
374 373
375acpi_status 374acpi_status
376acpi_ex_create_table_region ( 375acpi_ex_create_table_region (
@@ -455,7 +454,7 @@ cleanup:
455} 454}
456 455
457 456
458/***************************************************************************** 457/*******************************************************************************
459 * 458 *
460 * FUNCTION: acpi_ex_create_processor 459 * FUNCTION: acpi_ex_create_processor
461 * 460 *
@@ -467,7 +466,7 @@ cleanup:
467 * 466 *
468 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3]) 467 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
469 * 468 *
470 ****************************************************************************/ 469 ******************************************************************************/
471 470
472acpi_status 471acpi_status
473acpi_ex_create_processor ( 472acpi_ex_create_processor (
@@ -488,9 +487,8 @@ acpi_ex_create_processor (
488 return_ACPI_STATUS (AE_NO_MEMORY); 487 return_ACPI_STATUS (AE_NO_MEMORY);
489 } 488 }
490 489
491 /* 490 /* Initialize the processor object from the operands */
492 * Initialize the processor object from the operands 491
493 */
494 obj_desc->processor.proc_id = (u8) operand[1]->integer.value; 492 obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
495 obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value; 493 obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value;
496 obj_desc->processor.length = (u8) operand[3]->integer.value; 494 obj_desc->processor.length = (u8) operand[3]->integer.value;
@@ -507,7 +505,7 @@ acpi_ex_create_processor (
507} 505}
508 506
509 507
510/***************************************************************************** 508/*******************************************************************************
511 * 509 *
512 * FUNCTION: acpi_ex_create_power_resource 510 * FUNCTION: acpi_ex_create_power_resource
513 * 511 *
@@ -519,7 +517,7 @@ acpi_ex_create_processor (
519 * 517 *
520 * power_resource (Name[0], system_level[1], resource_order[2]) 518 * power_resource (Name[0], system_level[1], resource_order[2])
521 * 519 *
522 ****************************************************************************/ 520 ******************************************************************************/
523 521
524acpi_status 522acpi_status
525acpi_ex_create_power_resource ( 523acpi_ex_create_power_resource (
@@ -555,10 +553,10 @@ acpi_ex_create_power_resource (
555 acpi_ut_remove_reference (obj_desc); 553 acpi_ut_remove_reference (obj_desc);
556 return_ACPI_STATUS (status); 554 return_ACPI_STATUS (status);
557} 555}
558
559#endif 556#endif
560 557
561/***************************************************************************** 558
559/*******************************************************************************
562 * 560 *
563 * FUNCTION: acpi_ex_create_method 561 * FUNCTION: acpi_ex_create_method
564 * 562 *
@@ -570,7 +568,7 @@ acpi_ex_create_power_resource (
570 * 568 *
571 * DESCRIPTION: Create a new method object 569 * DESCRIPTION: Create a new method object
572 * 570 *
573 ****************************************************************************/ 571 ******************************************************************************/
574 572
575acpi_status 573acpi_status
576acpi_ex_create_method ( 574acpi_ex_create_method (
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index e2f7c32f28de..408500648114 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -51,23 +51,48 @@
51#define _COMPONENT ACPI_EXECUTER 51#define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exdump") 52 ACPI_MODULE_NAME ("exdump")
53 53
54/* Local prototypes */
55
56#ifdef ACPI_FUTURE_USAGE
57static void
58acpi_ex_out_string (
59 char *title,
60 char *value);
61
62static void
63acpi_ex_out_pointer (
64 char *title,
65 void *value);
66
67static void
68acpi_ex_out_integer (
69 char *title,
70 u32 value);
71
72static void
73acpi_ex_out_address (
74 char *title,
75 acpi_physical_address value);
76#endif /* ACPI_FUTURE_USAGE */
77
54 78
55/* 79/*
56 * The following routines are used for debug output only 80 * The following routines are used for debug output only
57 */ 81 */
58#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 82#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
59 83
60/***************************************************************************** 84/*******************************************************************************
61 * 85 *
62 * FUNCTION: acpi_ex_dump_operand 86 * FUNCTION: acpi_ex_dump_operand
63 * 87 *
64 * PARAMETERS: *obj_desc - Pointer to entry to be dumped 88 * PARAMETERS: *obj_desc - Pointer to entry to be dumped
89 * Depth - Current nesting depth
65 * 90 *
66 * RETURN: None 91 * RETURN: None
67 * 92 *
68 * DESCRIPTION: Dump an operand object 93 * DESCRIPTION: Dump an operand object
69 * 94 *
70 ****************************************************************************/ 95 ******************************************************************************/
71 96
72void 97void
73acpi_ex_dump_operand ( 98acpi_ex_dump_operand (
@@ -86,9 +111,8 @@ acpi_ex_dump_operand (
86 } 111 }
87 112
88 if (!obj_desc) { 113 if (!obj_desc) {
89 /* 114 /* This could be a null element of a package */
90 * This could be a null element of a package 115
91 */
92 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n")); 116 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n"));
93 return; 117 return;
94 } 118 }
@@ -117,6 +141,8 @@ acpi_ex_dump_operand (
117 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", obj_desc)); 141 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", obj_desc));
118 } 142 }
119 143
144 /* Decode object type */
145
120 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 146 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
121 case ACPI_TYPE_LOCAL_REFERENCE: 147 case ACPI_TYPE_LOCAL_REFERENCE:
122 148
@@ -274,7 +300,9 @@ acpi_ex_dump_operand (
274 case ACPI_TYPE_STRING: 300 case ACPI_TYPE_STRING:
275 301
276 acpi_os_printf ("String length %X @ %p ", 302 acpi_os_printf ("String length %X @ %p ",
277 obj_desc->string.length, obj_desc->string.pointer); 303 obj_desc->string.length,
304 obj_desc->string.pointer);
305
278 acpi_ut_print_string (obj_desc->string.pointer, ACPI_UINT8_MAX); 306 acpi_ut_print_string (obj_desc->string.pointer, ACPI_UINT8_MAX);
279 acpi_os_printf ("\n"); 307 acpi_os_printf ("\n");
280 break; 308 break;
@@ -290,10 +318,13 @@ acpi_ex_dump_operand (
290 318
291 acpi_os_printf ( 319 acpi_os_printf (
292 "region_field: Bits=%X acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n", 320 "region_field: Bits=%X acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n",
293 obj_desc->field.bit_length, obj_desc->field.access_byte_width, 321 obj_desc->field.bit_length,
322 obj_desc->field.access_byte_width,
294 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK, 323 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
295 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK, 324 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
296 obj_desc->field.base_byte_offset, obj_desc->field.start_field_bit_offset); 325 obj_desc->field.base_byte_offset,
326 obj_desc->field.start_field_bit_offset);
327
297 acpi_ex_dump_operand (obj_desc->field.region_obj, depth+1); 328 acpi_ex_dump_operand (obj_desc->field.region_obj, depth+1);
298 break; 329 break;
299 330
@@ -308,13 +339,15 @@ acpi_ex_dump_operand (
308 339
309 acpi_os_printf ( 340 acpi_os_printf (
310 "buffer_field: %X bits at byte %X bit %X of \n", 341 "buffer_field: %X bits at byte %X bit %X of \n",
311 obj_desc->buffer_field.bit_length, obj_desc->buffer_field.base_byte_offset, 342 obj_desc->buffer_field.bit_length,
343 obj_desc->buffer_field.base_byte_offset,
312 obj_desc->buffer_field.start_field_bit_offset); 344 obj_desc->buffer_field.start_field_bit_offset);
313 345
314 if (!obj_desc->buffer_field.buffer_obj) { 346 if (!obj_desc->buffer_field.buffer_obj) {
315 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*NULL* \n")); 347 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*NULL* \n"));
316 } 348 }
317 else if (ACPI_GET_OBJECT_TYPE (obj_desc->buffer_field.buffer_obj) != ACPI_TYPE_BUFFER) { 349 else if (ACPI_GET_OBJECT_TYPE (obj_desc->buffer_field.buffer_obj) !=
350 ACPI_TYPE_BUFFER) {
318 acpi_os_printf ("*not a Buffer* \n"); 351 acpi_os_printf ("*not a Buffer* \n");
319 } 352 }
320 else { 353 else {
@@ -331,10 +364,10 @@ acpi_ex_dump_operand (
331 364
332 case ACPI_TYPE_METHOD: 365 case ACPI_TYPE_METHOD:
333 366
334 acpi_os_printf ( 367 acpi_os_printf ("Method(%X) @ %p:%X\n",
335 "Method(%X) @ %p:%X\n",
336 obj_desc->method.param_count, 368 obj_desc->method.param_count,
337 obj_desc->method.aml_start, obj_desc->method.aml_length); 369 obj_desc->method.aml_start,
370 obj_desc->method.aml_length);
338 break; 371 break;
339 372
340 373
@@ -379,7 +412,7 @@ acpi_ex_dump_operand (
379} 412}
380 413
381 414
382/***************************************************************************** 415/*******************************************************************************
383 * 416 *
384 * FUNCTION: acpi_ex_dump_operands 417 * FUNCTION: acpi_ex_dump_operands
385 * 418 *
@@ -393,7 +426,7 @@ acpi_ex_dump_operand (
393 * 426 *
394 * DESCRIPTION: Dump the object stack 427 * DESCRIPTION: Dump the object stack
395 * 428 *
396 ****************************************************************************/ 429 ******************************************************************************/
397 430
398void 431void
399acpi_ex_dump_operands ( 432acpi_ex_dump_operands (
@@ -441,10 +474,9 @@ acpi_ex_dump_operands (
441 474
442 475
443#ifdef ACPI_FUTURE_USAGE 476#ifdef ACPI_FUTURE_USAGE
444 477/*******************************************************************************
445/*****************************************************************************
446 * 478 *
447 * FUNCTION: acpi_ex_out* 479 * FUNCTION: acpi_ex_out* functions
448 * 480 *
449 * PARAMETERS: Title - Descriptive text 481 * PARAMETERS: Title - Descriptive text
450 * Value - Value to be displayed 482 * Value - Value to be displayed
@@ -453,9 +485,9 @@ acpi_ex_dump_operands (
453 * reduce the number of format strings required and keeps them 485 * reduce the number of format strings required and keeps them
454 * all in one place for easy modification. 486 * all in one place for easy modification.
455 * 487 *
456 ****************************************************************************/ 488 ******************************************************************************/
457 489
458void 490static void
459acpi_ex_out_string ( 491acpi_ex_out_string (
460 char *title, 492 char *title,
461 char *value) 493 char *value)
@@ -463,7 +495,7 @@ acpi_ex_out_string (
463 acpi_os_printf ("%20s : %s\n", title, value); 495 acpi_os_printf ("%20s : %s\n", title, value);
464} 496}
465 497
466void 498static void
467acpi_ex_out_pointer ( 499acpi_ex_out_pointer (
468 char *title, 500 char *title,
469 void *value) 501 void *value)
@@ -471,7 +503,7 @@ acpi_ex_out_pointer (
471 acpi_os_printf ("%20s : %p\n", title, value); 503 acpi_os_printf ("%20s : %p\n", title, value);
472} 504}
473 505
474void 506static void
475acpi_ex_out_integer ( 507acpi_ex_out_integer (
476 char *title, 508 char *title,
477 u32 value) 509 u32 value)
@@ -479,7 +511,7 @@ acpi_ex_out_integer (
479 acpi_os_printf ("%20s : %X\n", title, value); 511 acpi_os_printf ("%20s : %X\n", title, value);
480} 512}
481 513
482void 514static void
483acpi_ex_out_address ( 515acpi_ex_out_address (
484 char *title, 516 char *title,
485 acpi_physical_address value) 517 acpi_physical_address value)
@@ -493,16 +525,16 @@ acpi_ex_out_address (
493} 525}
494 526
495 527
496/***************************************************************************** 528/*******************************************************************************
497 * 529 *
498 * FUNCTION: acpi_ex_dump_node 530 * FUNCTION: acpi_ex_dump_node
499 * 531 *
500 * PARAMETERS: *Node - Descriptor to dump 532 * PARAMETERS: *Node - Descriptor to dump
501 * Flags - Force display 533 * Flags - Force display if TRUE
502 * 534 *
503 * DESCRIPTION: Dumps the members of the given.Node 535 * DESCRIPTION: Dumps the members of the given.Node
504 * 536 *
505 ****************************************************************************/ 537 ******************************************************************************/
506 538
507void 539void
508acpi_ex_dump_node ( 540acpi_ex_dump_node (
@@ -531,16 +563,16 @@ acpi_ex_dump_node (
531} 563}
532 564
533 565
534/***************************************************************************** 566/*******************************************************************************
535 * 567 *
536 * FUNCTION: acpi_ex_dump_object_descriptor 568 * FUNCTION: acpi_ex_dump_object_descriptor
537 * 569 *
538 * PARAMETERS: *Object - Descriptor to dump 570 * PARAMETERS: *Object - Descriptor to dump
539 * Flags - Force display 571 * Flags - Force display if TRUE
540 * 572 *
541 * DESCRIPTION: Dumps the members of the object descriptor given. 573 * DESCRIPTION: Dumps the members of the object descriptor given.
542 * 574 *
543 ****************************************************************************/ 575 ******************************************************************************/
544 576
545void 577void
546acpi_ex_dump_object_descriptor ( 578acpi_ex_dump_object_descriptor (
@@ -553,6 +585,10 @@ acpi_ex_dump_object_descriptor (
553 ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor"); 585 ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor");
554 586
555 587
588 if (!obj_desc) {
589 return_VOID;
590 }
591
556 if (!flags) { 592 if (!flags) {
557 if (!((ACPI_LV_OBJECTS & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))) { 593 if (!((ACPI_LV_OBJECTS & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))) {
558 return_VOID; 594 return_VOID;
@@ -747,11 +783,17 @@ acpi_ex_dump_object_descriptor (
747 case ACPI_TYPE_LOCAL_REFERENCE: 783 case ACPI_TYPE_LOCAL_REFERENCE:
748 784
749 acpi_ex_out_integer ("target_type", obj_desc->reference.target_type); 785 acpi_ex_out_integer ("target_type", obj_desc->reference.target_type);
750 acpi_ex_out_string ("Opcode", (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name); 786 acpi_ex_out_string ("Opcode", (acpi_ps_get_opcode_info (
787 obj_desc->reference.opcode))->name);
751 acpi_ex_out_integer ("Offset", obj_desc->reference.offset); 788 acpi_ex_out_integer ("Offset", obj_desc->reference.offset);
752 acpi_ex_out_pointer ("obj_desc", obj_desc->reference.object); 789 acpi_ex_out_pointer ("obj_desc", obj_desc->reference.object);
753 acpi_ex_out_pointer ("Node", obj_desc->reference.node); 790 acpi_ex_out_pointer ("Node", obj_desc->reference.node);
754 acpi_ex_out_pointer ("Where", obj_desc->reference.where); 791 acpi_ex_out_pointer ("Where", obj_desc->reference.where);
792
793 if (obj_desc->reference.object) {
794 acpi_os_printf ("\nReferenced Object:\n");
795 acpi_ex_dump_object_descriptor (obj_desc->reference.object, flags);
796 }
755 break; 797 break;
756 798
757 799
@@ -788,6 +830,5 @@ acpi_ex_dump_object_descriptor (
788} 830}
789 831
790#endif /* ACPI_FUTURE_USAGE */ 832#endif /* ACPI_FUTURE_USAGE */
791
792#endif 833#endif
793 834
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
index be7f2124fa02..22c8fa480f60 100644
--- a/drivers/acpi/executer/exfield.c
+++ b/drivers/acpi/executer/exfield.c
@@ -120,8 +120,8 @@ acpi_ex_read_data_from_field (
120 * Note: Smbus protocol value is passed in upper 16-bits of Function 120 * Note: Smbus protocol value is passed in upper 16-bits of Function
121 */ 121 */
122 status = acpi_ex_access_region (obj_desc, 0, 122 status = acpi_ex_access_region (obj_desc, 0,
123 ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer), 123 ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer),
124 ACPI_READ | (obj_desc->field.attribute << 16)); 124 ACPI_READ | (obj_desc->field.attribute << 16));
125 acpi_ex_release_global_lock (locked); 125 acpi_ex_release_global_lock (locked);
126 goto exit; 126 goto exit;
127 } 127 }
@@ -196,6 +196,7 @@ exit:
196 * 196 *
197 * PARAMETERS: source_desc - Contains data to write 197 * PARAMETERS: source_desc - Contains data to write
198 * obj_desc - The named field 198 * obj_desc - The named field
199 * result_desc - Where the return value is returned, if any
199 * 200 *
200 * RETURN: Status 201 * RETURN: Status
201 * 202 *
@@ -250,12 +251,15 @@ acpi_ex_write_data_to_field (
250 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) { 251 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) {
251 ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n", 252 ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n",
252 acpi_ut_get_object_type_name (source_desc))); 253 acpi_ut_get_object_type_name (source_desc)));
254
253 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 255 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
254 } 256 }
255 257
256 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) { 258 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) {
257 ACPI_REPORT_ERROR (("SMBus write requires Buffer of length %X, found length %X\n", 259 ACPI_REPORT_ERROR ((
260 "SMBus write requires Buffer of length %X, found length %X\n",
258 ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length)); 261 ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length));
262
259 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 263 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
260 } 264 }
261 265
@@ -265,14 +269,16 @@ acpi_ex_write_data_to_field (
265 } 269 }
266 270
267 buffer = buffer_desc->buffer.pointer; 271 buffer = buffer_desc->buffer.pointer;
268 ACPI_MEMCPY (buffer, source_desc->buffer.pointer, ACPI_SMBUS_BUFFER_SIZE); 272 ACPI_MEMCPY (buffer, source_desc->buffer.pointer,
273 ACPI_SMBUS_BUFFER_SIZE);
269 274
270 /* Lock entire transaction if requested */ 275 /* Lock entire transaction if requested */
271 276
272 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 277 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags);
273 278
274 /* 279 /*
275 * Perform the write (returns status and perhaps data in the same buffer) 280 * Perform the write (returns status and perhaps data in the
281 * same buffer)
276 * Note: SMBus protocol type is passed in upper 16-bits of Function. 282 * Note: SMBus protocol type is passed in upper 16-bits of Function.
277 */ 283 */
278 status = acpi_ex_access_region (obj_desc, 0, 284 status = acpi_ex_access_region (obj_desc, 0,
@@ -284,9 +290,8 @@ acpi_ex_write_data_to_field (
284 return_ACPI_STATUS (status); 290 return_ACPI_STATUS (status);
285 } 291 }
286 292
287 /* 293 /* Get a pointer to the data to be written */
288 * Get a pointer to the data to be written 294
289 */
290 switch (ACPI_GET_OBJECT_TYPE (source_desc)) { 295 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
291 case ACPI_TYPE_INTEGER: 296 case ACPI_TYPE_INTEGER:
292 buffer = &source_desc->integer.value; 297 buffer = &source_desc->integer.value;
@@ -314,7 +319,8 @@ acpi_ex_write_data_to_field (
314 * the ACPI specification. 319 * the ACPI specification.
315 */ 320 */
316 new_buffer = NULL; 321 new_buffer = NULL;
317 required_length = ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->common_field.bit_length); 322 required_length = ACPI_ROUND_BITS_UP_TO_BYTES (
323 obj_desc->common_field.bit_length);
318 324
319 if (length < required_length) { 325 if (length < required_length) {
320 /* We need to create a new buffer */ 326 /* We need to create a new buffer */
@@ -338,6 +344,7 @@ acpi_ex_write_data_to_field (
338 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n", 344 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n",
339 source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)), 345 source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)),
340 ACPI_GET_OBJECT_TYPE (source_desc), buffer, length)); 346 ACPI_GET_OBJECT_TYPE (source_desc), buffer, length));
347
341 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 348 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
342 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n", 349 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n",
343 obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)), 350 obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)),
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index 9d0f9d2e9061..3c2f89e00f78 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -52,12 +52,31 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exfldio") 53 ACPI_MODULE_NAME ("exfldio")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ex_field_datum_io (
59 union acpi_operand_object *obj_desc,
60 u32 field_datum_byte_offset,
61 acpi_integer *value,
62 u32 read_write);
63
64static u8
65acpi_ex_register_overflow (
66 union acpi_operand_object *obj_desc,
67 acpi_integer value);
68
69static acpi_status
70acpi_ex_setup_region (
71 union acpi_operand_object *obj_desc,
72 u32 field_datum_byte_offset);
73
55 74
56/******************************************************************************* 75/*******************************************************************************
57 * 76 *
58 * FUNCTION: acpi_ex_setup_region 77 * FUNCTION: acpi_ex_setup_region
59 * 78 *
60 * PARAMETERS: *obj_desc - Field to be read or written 79 * PARAMETERS: obj_desc - Field to be read or written
61 * field_datum_byte_offset - Byte offset of this datum within the 80 * field_datum_byte_offset - Byte offset of this datum within the
62 * parent field 81 * parent field
63 * 82 *
@@ -69,7 +88,7 @@
69 * 88 *
70 ******************************************************************************/ 89 ******************************************************************************/
71 90
72acpi_status 91static acpi_status
73acpi_ex_setup_region ( 92acpi_ex_setup_region (
74 union acpi_operand_object *obj_desc, 93 union acpi_operand_object *obj_desc,
75 u32 field_datum_byte_offset) 94 u32 field_datum_byte_offset)
@@ -127,9 +146,9 @@ acpi_ex_setup_region (
127 * length of one field datum (access width) must fit within the region. 146 * length of one field datum (access width) must fit within the region.
128 * (Region length is specified in bytes) 147 * (Region length is specified in bytes)
129 */ 148 */
130 if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset 149 if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset +
131 + field_datum_byte_offset 150 field_datum_byte_offset +
132 + obj_desc->common_field.access_byte_width)) { 151 obj_desc->common_field.access_byte_width)) {
133 if (acpi_gbl_enable_interpreter_slack) { 152 if (acpi_gbl_enable_interpreter_slack) {
134 /* 153 /*
135 * Slack mode only: We will go ahead and allow access to this 154 * Slack mode only: We will go ahead and allow access to this
@@ -155,7 +174,8 @@ acpi_ex_setup_region (
155 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n", 174 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n",
156 acpi_ut_get_node_name (obj_desc->common_field.node), 175 acpi_ut_get_node_name (obj_desc->common_field.node),
157 obj_desc->common_field.access_byte_width, 176 obj_desc->common_field.access_byte_width,
158 acpi_ut_get_node_name (rgn_desc->region.node), rgn_desc->region.length)); 177 acpi_ut_get_node_name (rgn_desc->region.node),
178 rgn_desc->region.length));
159 } 179 }
160 180
161 /* 181 /*
@@ -167,7 +187,8 @@ acpi_ex_setup_region (
167 acpi_ut_get_node_name (obj_desc->common_field.node), 187 acpi_ut_get_node_name (obj_desc->common_field.node),
168 obj_desc->common_field.base_byte_offset, 188 obj_desc->common_field.base_byte_offset,
169 field_datum_byte_offset, obj_desc->common_field.access_byte_width, 189 field_datum_byte_offset, obj_desc->common_field.access_byte_width,
170 acpi_ut_get_node_name (rgn_desc->region.node), rgn_desc->region.length)); 190 acpi_ut_get_node_name (rgn_desc->region.node),
191 rgn_desc->region.length));
171 192
172 return_ACPI_STATUS (AE_AML_REGION_LIMIT); 193 return_ACPI_STATUS (AE_AML_REGION_LIMIT);
173 } 194 }
@@ -180,10 +201,10 @@ acpi_ex_setup_region (
180 * 201 *
181 * FUNCTION: acpi_ex_access_region 202 * FUNCTION: acpi_ex_access_region
182 * 203 *
183 * PARAMETERS: *obj_desc - Field to be read 204 * PARAMETERS: obj_desc - Field to be read
184 * field_datum_byte_offset - Byte offset of this datum within the 205 * field_datum_byte_offset - Byte offset of this datum within the
185 * parent field 206 * parent field
186 * *Value - Where to store value (must at least 207 * Value - Where to store value (must at least
187 * the size of acpi_integer) 208 * the size of acpi_integer)
188 * Function - Read or Write flag plus other region- 209 * Function - Read or Write flag plus other region-
189 * dependent flags 210 * dependent flags
@@ -226,9 +247,9 @@ acpi_ex_access_region (
226 * 3) The current offset into the field 247 * 3) The current offset into the field
227 */ 248 */
228 rgn_desc = obj_desc->common_field.region_obj; 249 rgn_desc = obj_desc->common_field.region_obj;
229 address = rgn_desc->region.address 250 address = rgn_desc->region.address +
230 + obj_desc->common_field.base_byte_offset 251 obj_desc->common_field.base_byte_offset +
231 + field_datum_byte_offset; 252 field_datum_byte_offset;
232 253
233 if ((function & ACPI_IO_MASK) == ACPI_READ) { 254 if ((function & ACPI_IO_MASK) == ACPI_READ) {
234 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "[READ]")); 255 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "[READ]"));
@@ -249,7 +270,8 @@ acpi_ex_access_region (
249 /* Invoke the appropriate address_space/op_region handler */ 270 /* Invoke the appropriate address_space/op_region handler */
250 271
251 status = acpi_ev_address_space_dispatch (rgn_desc, function, 272 status = acpi_ev_address_space_dispatch (rgn_desc, function,
252 address, ACPI_MUL_8 (obj_desc->common_field.access_byte_width), value); 273 address,
274 ACPI_MUL_8 (obj_desc->common_field.access_byte_width), value);
253 275
254 if (ACPI_FAILURE (status)) { 276 if (ACPI_FAILURE (status)) {
255 if (status == AE_NOT_IMPLEMENTED) { 277 if (status == AE_NOT_IMPLEMENTED) {
@@ -274,7 +296,7 @@ acpi_ex_access_region (
274 * 296 *
275 * FUNCTION: acpi_ex_register_overflow 297 * FUNCTION: acpi_ex_register_overflow
276 * 298 *
277 * PARAMETERS: *obj_desc - Register(Field) to be written 299 * PARAMETERS: obj_desc - Register(Field) to be written
278 * Value - Value to be stored 300 * Value - Value to be stored
279 * 301 *
280 * RETURN: TRUE if value overflows the field, FALSE otherwise 302 * RETURN: TRUE if value overflows the field, FALSE otherwise
@@ -287,7 +309,7 @@ acpi_ex_access_region (
287 * 309 *
288 ******************************************************************************/ 310 ******************************************************************************/
289 311
290u8 312static u8
291acpi_ex_register_overflow ( 313acpi_ex_register_overflow (
292 union acpi_operand_object *obj_desc, 314 union acpi_operand_object *obj_desc,
293 acpi_integer value) 315 acpi_integer value)
@@ -319,10 +341,10 @@ acpi_ex_register_overflow (
319 * 341 *
320 * FUNCTION: acpi_ex_field_datum_io 342 * FUNCTION: acpi_ex_field_datum_io
321 * 343 *
322 * PARAMETERS: *obj_desc - Field to be read 344 * PARAMETERS: obj_desc - Field to be read
323 * field_datum_byte_offset - Byte offset of this datum within the 345 * field_datum_byte_offset - Byte offset of this datum within the
324 * parent field 346 * parent field
325 * *Value - Where to store value (must be 64 bits) 347 * Value - Where to store value (must be 64 bits)
326 * read_write - Read or Write flag 348 * read_write - Read or Write flag
327 * 349 *
328 * RETURN: Status 350 * RETURN: Status
@@ -333,7 +355,7 @@ acpi_ex_register_overflow (
333 * 355 *
334 ******************************************************************************/ 356 ******************************************************************************/
335 357
336acpi_status 358static acpi_status
337acpi_ex_field_datum_io ( 359acpi_ex_field_datum_io (
338 union acpi_operand_object *obj_desc, 360 union acpi_operand_object *obj_desc,
339 u32 field_datum_byte_offset, 361 u32 field_datum_byte_offset,
@@ -350,7 +372,9 @@ acpi_ex_field_datum_io (
350 if (read_write == ACPI_READ) { 372 if (read_write == ACPI_READ) {
351 if (!value) { 373 if (!value) {
352 local_value = 0; 374 local_value = 0;
353 value = &local_value; /* To support reads without saving return value */ 375
376 /* To support reads without saving return value */
377 value = &local_value;
354 } 378 }
355 379
356 /* Clear the entire return buffer first, [Very Important!] */ 380 /* Clear the entire return buffer first, [Very Important!] */
@@ -363,8 +387,10 @@ acpi_ex_field_datum_io (
363 * 387 *
364 * buffer_field - Read/write from/to a Buffer 388 * buffer_field - Read/write from/to a Buffer
365 * region_field - Read/write from/to a Operation Region. 389 * region_field - Read/write from/to a Operation Region.
366 * bank_field - Write to a Bank Register, then read/write from/to an op_region 390 * bank_field - Write to a Bank Register, then read/write from/to an
367 * index_field - Write to an Index Register, then read/write from/to a Data Register 391 * operation_region
392 * index_field - Write to an Index Register, then read/write from/to a
393 * Data Register
368 */ 394 */
369 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 395 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
370 case ACPI_TYPE_BUFFER_FIELD: 396 case ACPI_TYPE_BUFFER_FIELD:
@@ -384,19 +410,20 @@ acpi_ex_field_datum_io (
384 * Copy the data from the source buffer. 410 * Copy the data from the source buffer.
385 * Length is the field width in bytes. 411 * Length is the field width in bytes.
386 */ 412 */
387 ACPI_MEMCPY (value, (obj_desc->buffer_field.buffer_obj)->buffer.pointer 413 ACPI_MEMCPY (value,
388 + obj_desc->buffer_field.base_byte_offset 414 (obj_desc->buffer_field.buffer_obj)->buffer.pointer +
389 + field_datum_byte_offset, 415 obj_desc->buffer_field.base_byte_offset +
390 obj_desc->common_field.access_byte_width); 416 field_datum_byte_offset,
417 obj_desc->common_field.access_byte_width);
391 } 418 }
392 else { 419 else {
393 /* 420 /*
394 * Copy the data to the target buffer. 421 * Copy the data to the target buffer.
395 * Length is the field width in bytes. 422 * Length is the field width in bytes.
396 */ 423 */
397 ACPI_MEMCPY ((obj_desc->buffer_field.buffer_obj)->buffer.pointer 424 ACPI_MEMCPY ((obj_desc->buffer_field.buffer_obj)->buffer.pointer +
398 + obj_desc->buffer_field.base_byte_offset 425 obj_desc->buffer_field.base_byte_offset +
399 + field_datum_byte_offset, 426 field_datum_byte_offset,
400 value, obj_desc->common_field.access_byte_width); 427 value, obj_desc->common_field.access_byte_width);
401 } 428 }
402 429
@@ -406,8 +433,10 @@ acpi_ex_field_datum_io (
406 433
407 case ACPI_TYPE_LOCAL_BANK_FIELD: 434 case ACPI_TYPE_LOCAL_BANK_FIELD:
408 435
409 /* Ensure that the bank_value is not beyond the capacity of the register */ 436 /*
410 437 * Ensure that the bank_value is not beyond the capacity of
438 * the register
439 */
411 if (acpi_ex_register_overflow (obj_desc->bank_field.bank_obj, 440 if (acpi_ex_register_overflow (obj_desc->bank_field.bank_obj,
412 (acpi_integer) obj_desc->bank_field.value)) { 441 (acpi_integer) obj_desc->bank_field.value)) {
413 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT); 442 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT);
@@ -445,8 +474,10 @@ acpi_ex_field_datum_io (
445 case ACPI_TYPE_LOCAL_INDEX_FIELD: 474 case ACPI_TYPE_LOCAL_INDEX_FIELD:
446 475
447 476
448 /* Ensure that the index_value is not beyond the capacity of the register */ 477 /*
449 478 * Ensure that the index_value is not beyond the capacity of
479 * the register
480 */
450 if (acpi_ex_register_overflow (obj_desc->index_field.index_obj, 481 if (acpi_ex_register_overflow (obj_desc->index_field.index_obj,
451 (acpi_integer) obj_desc->index_field.value)) { 482 (acpi_integer) obj_desc->index_field.value)) {
452 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT); 483 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT);
@@ -496,14 +527,16 @@ acpi_ex_field_datum_io (
496 527
497 if (ACPI_SUCCESS (status)) { 528 if (ACPI_SUCCESS (status)) {
498 if (read_write == ACPI_READ) { 529 if (read_write == ACPI_READ) {
499 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Value Read %8.8X%8.8X, Width %d\n", 530 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
500 ACPI_FORMAT_UINT64 (*value), 531 "Value Read %8.8X%8.8X, Width %d\n",
501 obj_desc->common_field.access_byte_width)); 532 ACPI_FORMAT_UINT64 (*value),
533 obj_desc->common_field.access_byte_width));
502 } 534 }
503 else { 535 else {
504 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Value Written %8.8X%8.8X, Width %d\n", 536 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
505 ACPI_FORMAT_UINT64 (*value), 537 "Value Written %8.8X%8.8X, Width %d\n",
506 obj_desc->common_field.access_byte_width)); 538 ACPI_FORMAT_UINT64 (*value),
539 obj_desc->common_field.access_byte_width));
507 } 540 }
508 } 541 }
509 542
@@ -515,8 +548,10 @@ acpi_ex_field_datum_io (
515 * 548 *
516 * FUNCTION: acpi_ex_write_with_update_rule 549 * FUNCTION: acpi_ex_write_with_update_rule
517 * 550 *
518 * PARAMETERS: *obj_desc - Field to be set 551 * PARAMETERS: obj_desc - Field to be written
519 * Value - Value to store 552 * Mask - bitmask within field datum
553 * field_value - Value to write
554 * field_datum_byte_offset - Offset of datum within field
520 * 555 *
521 * RETURN: Status 556 * RETURN: Status
522 * 557 *
@@ -689,7 +724,8 @@ acpi_ex_extract_from_field (
689 /* Merge with previous datum if necessary */ 724 /* Merge with previous datum if necessary */
690 725
691 merged_datum |= raw_datum << 726 merged_datum |= raw_datum <<
692 (obj_desc->common_field.access_bit_width - obj_desc->common_field.start_field_bit_offset); 727 (obj_desc->common_field.access_bit_width -
728 obj_desc->common_field.start_field_bit_offset);
693 729
694 if (i == datum_count) { 730 if (i == datum_count) {
695 break; 731 break;
@@ -707,7 +743,8 @@ acpi_ex_extract_from_field (
707 743
708 /* Mask off any extra bits in the last datum */ 744 /* Mask off any extra bits in the last datum */
709 745
710 buffer_tail_bits = obj_desc->common_field.bit_length % obj_desc->common_field.access_bit_width; 746 buffer_tail_bits = obj_desc->common_field.bit_length %
747 obj_desc->common_field.access_bit_width;
711 if (buffer_tail_bits) { 748 if (buffer_tail_bits) {
712 merged_datum &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits); 749 merged_datum &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits);
713 } 750 }
@@ -791,7 +828,8 @@ acpi_ex_insert_into_field (
791 /* Write merged datum to the target field */ 828 /* Write merged datum to the target field */
792 829
793 merged_datum &= mask; 830 merged_datum &= mask;
794 status = acpi_ex_write_with_update_rule (obj_desc, mask, merged_datum, field_offset); 831 status = acpi_ex_write_with_update_rule (obj_desc, mask,
832 merged_datum, field_offset);
795 if (ACPI_FAILURE (status)) { 833 if (ACPI_FAILURE (status)) {
796 return_ACPI_STATUS (status); 834 return_ACPI_STATUS (status);
797 } 835 }
@@ -800,7 +838,8 @@ acpi_ex_insert_into_field (
800 838
801 field_offset += obj_desc->common_field.access_byte_width; 839 field_offset += obj_desc->common_field.access_byte_width;
802 merged_datum = raw_datum >> 840 merged_datum = raw_datum >>
803 (obj_desc->common_field.access_bit_width - obj_desc->common_field.start_field_bit_offset); 841 (obj_desc->common_field.access_bit_width -
842 obj_desc->common_field.start_field_bit_offset);
804 mask = ACPI_INTEGER_MAX; 843 mask = ACPI_INTEGER_MAX;
805 844
806 if (i == datum_count) { 845 if (i == datum_count) {
@@ -819,7 +858,8 @@ acpi_ex_insert_into_field (
819 /* Mask off any extra bits in the last datum */ 858 /* Mask off any extra bits in the last datum */
820 859
821 buffer_tail_bits = (obj_desc->common_field.bit_length + 860 buffer_tail_bits = (obj_desc->common_field.bit_length +
822 obj_desc->common_field.start_field_bit_offset) % obj_desc->common_field.access_bit_width; 861 obj_desc->common_field.start_field_bit_offset) %
862 obj_desc->common_field.access_bit_width;
823 if (buffer_tail_bits) { 863 if (buffer_tail_bits) {
824 mask &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits); 864 mask &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits);
825 } 865 }
@@ -827,7 +867,8 @@ acpi_ex_insert_into_field (
827 /* Write the last datum to the field */ 867 /* Write the last datum to the field */
828 868
829 merged_datum &= mask; 869 merged_datum &= mask;
830 status = acpi_ex_write_with_update_rule (obj_desc, mask, merged_datum, field_offset); 870 status = acpi_ex_write_with_update_rule (obj_desc,
871 mask, merged_datum, field_offset);
831 872
832 return_ACPI_STATUS (status); 873 return_ACPI_STATUS (status);
833} 874}
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
index b542dcd58c07..022f281345b8 100644
--- a/drivers/acpi/executer/exmisc.c
+++ b/drivers/acpi/executer/exmisc.c
@@ -139,8 +139,9 @@ acpi_ex_get_object_reference (
139 reference_obj->reference.object = referenced_obj; 139 reference_obj->reference.object = referenced_obj;
140 *return_desc = reference_obj; 140 *return_desc = reference_obj;
141 141
142 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p Type [%s], returning Reference %p\n", 142 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
143 obj_desc, acpi_ut_get_object_type_name (obj_desc), *return_desc)); 143 "Object %p Type [%s], returning Reference %p\n",
144 obj_desc, acpi_ut_get_object_type_name (obj_desc), *return_desc));
144 145
145 return_ACPI_STATUS (AE_OK); 146 return_ACPI_STATUS (AE_OK);
146} 147}
@@ -456,7 +457,7 @@ acpi_ex_do_math_op (
456 return (integer0 * integer1); 457 return (integer0 * integer1);
457 458
458 459
459 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */ 460 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result)*/
460 461
461 return (integer0 << integer1); 462 return (integer0 << integer1);
462 463
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 68c4bb1970a5..c3cb714d2cba 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -49,6 +49,13 @@
49#define _COMPONENT ACPI_EXECUTER 49#define _COMPONENT ACPI_EXECUTER
50 ACPI_MODULE_NAME ("exmutex") 50 ACPI_MODULE_NAME ("exmutex")
51 51
52/* Local prototypes */
53
54static void
55acpi_ex_link_mutex (
56 union acpi_operand_object *obj_desc,
57 struct acpi_thread_state *thread);
58
52 59
53/******************************************************************************* 60/*******************************************************************************
54 * 61 *
@@ -56,7 +63,7 @@
56 * 63 *
57 * PARAMETERS: obj_desc - The mutex to be unlinked 64 * PARAMETERS: obj_desc - The mutex to be unlinked
58 * 65 *
59 * RETURN: Status 66 * RETURN: None
60 * 67 *
61 * DESCRIPTION: Remove a mutex from the "acquired_mutex" list 68 * DESCRIPTION: Remove a mutex from the "acquired_mutex" list
62 * 69 *
@@ -92,16 +99,16 @@ acpi_ex_unlink_mutex (
92 * 99 *
93 * FUNCTION: acpi_ex_link_mutex 100 * FUNCTION: acpi_ex_link_mutex
94 * 101 *
95 * PARAMETERS: obj_desc - The mutex to be linked 102 * PARAMETERS: obj_desc - The mutex to be linked
96 * list_head - head of the "acquired_mutex" list 103 * Thread - Current executing thread object
97 * 104 *
98 * RETURN: Status 105 * RETURN: None
99 * 106 *
100 * DESCRIPTION: Add a mutex to the "acquired_mutex" list for this walk 107 * DESCRIPTION: Add a mutex to the "acquired_mutex" list for this walk
101 * 108 *
102 ******************************************************************************/ 109 ******************************************************************************/
103 110
104void 111static void
105acpi_ex_link_mutex ( 112acpi_ex_link_mutex (
106 union acpi_operand_object *obj_desc, 113 union acpi_operand_object *obj_desc,
107 struct acpi_thread_state *thread) 114 struct acpi_thread_state *thread)
@@ -132,8 +139,9 @@ acpi_ex_link_mutex (
132 * 139 *
133 * FUNCTION: acpi_ex_acquire_mutex 140 * FUNCTION: acpi_ex_acquire_mutex
134 * 141 *
135 * PARAMETERS: time_desc - The 'time to delay' object descriptor 142 * PARAMETERS: time_desc - Timeout integer
136 * obj_desc - The object descriptor for this op 143 * obj_desc - Mutex object
144 * walk_state - Current method execution state
137 * 145 *
138 * RETURN: Status 146 * RETURN: Status
139 * 147 *
@@ -161,7 +169,7 @@ acpi_ex_acquire_mutex (
161 169
162 if (!walk_state->thread) { 170 if (!walk_state->thread) {
163 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], null thread info\n", 171 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], null thread info\n",
164 acpi_ut_get_node_name (obj_desc->mutex.node))); 172 acpi_ut_get_node_name (obj_desc->mutex.node)));
165 return_ACPI_STATUS (AE_AML_INTERNAL); 173 return_ACPI_STATUS (AE_AML_INTERNAL);
166 } 174 }
167 175
@@ -170,8 +178,9 @@ acpi_ex_acquire_mutex (
170 * mutex. This mechanism provides some deadlock prevention 178 * mutex. This mechanism provides some deadlock prevention
171 */ 179 */
172 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { 180 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
173 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], incorrect sync_level\n", 181 ACPI_REPORT_ERROR ((
174 acpi_ut_get_node_name (obj_desc->mutex.node))); 182 "Cannot acquire Mutex [%4.4s], incorrect sync_level\n",
183 acpi_ut_get_node_name (obj_desc->mutex.node)));
175 return_ACPI_STATUS (AE_AML_MUTEX_ORDER); 184 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
176 } 185 }
177 186
@@ -180,8 +189,10 @@ acpi_ex_acquire_mutex (
180 if (obj_desc->mutex.owner_thread) { 189 if (obj_desc->mutex.owner_thread) {
181 /* Special case for Global Lock, allow all threads */ 190 /* Special case for Global Lock, allow all threads */
182 191
183 if ((obj_desc->mutex.owner_thread->thread_id == walk_state->thread->thread_id) || 192 if ((obj_desc->mutex.owner_thread->thread_id ==
184 (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore)) { 193 walk_state->thread->thread_id) ||
194 (obj_desc->mutex.semaphore ==
195 acpi_gbl_global_lock_semaphore)) {
185 /* 196 /*
186 * The mutex is already owned by this thread, 197 * The mutex is already owned by this thread,
187 * just increment the acquisition depth 198 * just increment the acquisition depth
@@ -221,6 +232,7 @@ acpi_ex_acquire_mutex (
221 * FUNCTION: acpi_ex_release_mutex 232 * FUNCTION: acpi_ex_release_mutex
222 * 233 *
223 * PARAMETERS: obj_desc - The object descriptor for this op 234 * PARAMETERS: obj_desc - The object descriptor for this op
235 * walk_state - Current method execution state
224 * 236 *
225 * RETURN: Status 237 * RETURN: Status
226 * 238 *
@@ -278,8 +290,9 @@ acpi_ex_release_mutex (
278 * equal to the current sync level 290 * equal to the current sync level
279 */ 291 */
280 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { 292 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
281 ACPI_REPORT_ERROR (("Cannot release Mutex [%4.4s], incorrect sync_level\n", 293 ACPI_REPORT_ERROR ((
282 acpi_ut_get_node_name (obj_desc->mutex.node))); 294 "Cannot release Mutex [%4.4s], incorrect sync_level\n",
295 acpi_ut_get_node_name (obj_desc->mutex.node)));
283 return_ACPI_STATUS (AE_AML_MUTEX_ORDER); 296 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
284 } 297 }
285 298
@@ -313,11 +326,11 @@ acpi_ex_release_mutex (
313 * 326 *
314 * FUNCTION: acpi_ex_release_all_mutexes 327 * FUNCTION: acpi_ex_release_all_mutexes
315 * 328 *
316 * PARAMETERS: mutex_list - Head of the mutex list 329 * PARAMETERS: Thread - Current executing thread object
317 * 330 *
318 * RETURN: Status 331 * RETURN: Status
319 * 332 *
320 * DESCRIPTION: Release all mutexes in the list 333 * DESCRIPTION: Release all mutexes held by this thread
321 * 334 *
322 ******************************************************************************/ 335 ******************************************************************************/
323 336
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
index 7911c533c265..639f0bd3f6d8 100644
--- a/drivers/acpi/executer/exnames.c
+++ b/drivers/acpi/executer/exnames.c
@@ -50,13 +50,17 @@
50#define _COMPONENT ACPI_EXECUTER 50#define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exnames") 51 ACPI_MODULE_NAME ("exnames")
52 52
53/* Local prototypes */
53 54
54/* AML Package Length encodings */ 55static char *
56acpi_ex_allocate_name_string (
57 u32 prefix_count,
58 u32 num_name_segs);
55 59
56#define ACPI_AML_PACKAGE_TYPE1 0x40 60static acpi_status
57#define ACPI_AML_PACKAGE_TYPE2 0x4000 61acpi_ex_name_segment (
58#define ACPI_AML_PACKAGE_TYPE3 0x400000 62 u8 **in_aml_address,
59#define ACPI_AML_PACKAGE_TYPE4 0x40000000 63 char *name_string);
60 64
61 65
62/******************************************************************************* 66/*******************************************************************************
@@ -64,7 +68,7 @@
64 * FUNCTION: acpi_ex_allocate_name_string 68 * FUNCTION: acpi_ex_allocate_name_string
65 * 69 *
66 * PARAMETERS: prefix_count - Count of parent levels. Special cases: 70 * PARAMETERS: prefix_count - Count of parent levels. Special cases:
67 * (-1) = root, 0 = none 71 * (-1)==root, 0==none
68 * num_name_segs - count of 4-character name segments 72 * num_name_segs - count of 4-character name segments
69 * 73 *
70 * RETURN: A pointer to the allocated string segment. This segment must 74 * RETURN: A pointer to the allocated string segment. This segment must
@@ -75,7 +79,7 @@
75 * 79 *
76 ******************************************************************************/ 80 ******************************************************************************/
77 81
78char * 82static char *
79acpi_ex_allocate_name_string ( 83acpi_ex_allocate_name_string (
80 u32 prefix_count, 84 u32 prefix_count,
81 u32 num_name_segs) 85 u32 num_name_segs)
@@ -88,7 +92,7 @@ acpi_ex_allocate_name_string (
88 92
89 93
90 /* 94 /*
91 * Allow room for all \ and ^ prefixes, all segments, and a multi_name_prefix. 95 * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix.
92 * Also, one byte for the null terminator. 96 * Also, one byte for the null terminator.
93 * This may actually be somewhat longer than needed. 97 * This may actually be somewhat longer than needed.
94 */ 98 */
@@ -107,7 +111,8 @@ acpi_ex_allocate_name_string (
107 */ 111 */
108 name_string = ACPI_MEM_ALLOCATE (size_needed); 112 name_string = ACPI_MEM_ALLOCATE (size_needed);
109 if (!name_string) { 113 if (!name_string) {
110 ACPI_REPORT_ERROR (("ex_allocate_name_string: Could not allocate size %d\n", size_needed)); 114 ACPI_REPORT_ERROR ((
115 "ex_allocate_name_string: Could not allocate size %d\n", size_needed));
111 return_PTR (NULL); 116 return_PTR (NULL);
112 } 117 }
113 118
@@ -152,15 +157,17 @@ acpi_ex_allocate_name_string (
152 * 157 *
153 * FUNCTION: acpi_ex_name_segment 158 * FUNCTION: acpi_ex_name_segment
154 * 159 *
155 * PARAMETERS: interpreter_mode - Current running mode (load1/Load2/Exec) 160 * PARAMETERS: in_aml_address - Pointer to the name in the AML code
161 * name_string - Where to return the name. The name is appended
162 * to any existing string to form a namepath
156 * 163 *
157 * RETURN: Status 164 * RETURN: Status
158 * 165 *
159 * DESCRIPTION: Execute a name segment (4 bytes) 166 * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
160 * 167 *
161 ******************************************************************************/ 168 ******************************************************************************/
162 169
163acpi_status 170static acpi_status
164acpi_ex_name_segment ( 171acpi_ex_name_segment (
165 u8 **in_aml_address, 172 u8 **in_aml_address,
166 char *name_string) 173 char *name_string)
@@ -223,10 +230,13 @@ acpi_ex_name_segment (
223 status = AE_CTRL_PENDING; 230 status = AE_CTRL_PENDING;
224 } 231 }
225 else { 232 else {
226 /* Segment started with one or more valid characters, but fewer than 4 */ 233 /*
227 234 * Segment started with one or more valid characters, but fewer than
235 * the required 4
236 */
228 status = AE_AML_BAD_NAME; 237 status = AE_AML_BAD_NAME;
229 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad character %02x in name, at %p\n", 238 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
239 "Bad character %02x in name, at %p\n",
230 *aml_address, aml_address)); 240 *aml_address, aml_address));
231 } 241 }
232 242
@@ -239,11 +249,16 @@ acpi_ex_name_segment (
239 * 249 *
240 * FUNCTION: acpi_ex_get_name_string 250 * FUNCTION: acpi_ex_get_name_string
241 * 251 *
242 * PARAMETERS: data_type - Data type to be associated with this name 252 * PARAMETERS: data_type - Object type to be associated with this
253 * name
254 * in_aml_address - Pointer to the namestring in the AML code
255 * out_name_string - Where the namestring is returned
256 * out_name_length - Length of the returned string
243 * 257 *
244 * RETURN: Status 258 * RETURN: Status, namestring and length
245 * 259 *
246 * DESCRIPTION: Get a name, including any prefixes. 260 * DESCRIPTION: Extract a full namepath from the AML byte stream,
261 * including any prefixes.
247 * 262 *
248 ******************************************************************************/ 263 ******************************************************************************/
249 264
@@ -286,7 +301,8 @@ acpi_ex_get_name_string (
286 switch (*aml_address) { 301 switch (*aml_address) {
287 case AML_ROOT_PREFIX: 302 case AML_ROOT_PREFIX:
288 303
289 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "root_prefix(\\) at %p\n", aml_address)); 304 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "root_prefix(\\) at %p\n",
305 aml_address));
290 306
291 /* 307 /*
292 * Remember that we have a root_prefix -- 308 * Remember that we have a root_prefix --
@@ -303,7 +319,8 @@ acpi_ex_get_name_string (
303 /* Increment past possibly multiple parent prefixes */ 319 /* Increment past possibly multiple parent prefixes */
304 320
305 do { 321 do {
306 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "parent_prefix (^) at %p\n", aml_address)); 322 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "parent_prefix (^) at %p\n",
323 aml_address));
307 324
308 aml_address++; 325 aml_address++;
309 prefix_count++; 326 prefix_count++;
@@ -321,13 +338,13 @@ acpi_ex_get_name_string (
321 break; 338 break;
322 } 339 }
323 340
324
325 /* Examine first character of name for name segment prefix operator */ 341 /* Examine first character of name for name segment prefix operator */
326 342
327 switch (*aml_address) { 343 switch (*aml_address) {
328 case AML_DUAL_NAME_PREFIX: 344 case AML_DUAL_NAME_PREFIX:
329 345
330 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "dual_name_prefix at %p\n", aml_address)); 346 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "dual_name_prefix at %p\n",
347 aml_address));
331 348
332 aml_address++; 349 aml_address++;
333 name_string = acpi_ex_allocate_name_string (prefix_count, 2); 350 name_string = acpi_ex_allocate_name_string (prefix_count, 2);
@@ -349,7 +366,8 @@ acpi_ex_get_name_string (
349 366
350 case AML_MULTI_NAME_PREFIX_OP: 367 case AML_MULTI_NAME_PREFIX_OP:
351 368
352 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "multi_name_prefix at %p\n", aml_address)); 369 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "multi_name_prefix at %p\n",
370 aml_address));
353 371
354 /* Fetch count of segments remaining in name path */ 372 /* Fetch count of segments remaining in name path */
355 373
@@ -368,7 +386,8 @@ acpi_ex_get_name_string (
368 has_prefix = TRUE; 386 has_prefix = TRUE;
369 387
370 while (num_segments && 388 while (num_segments &&
371 (status = acpi_ex_name_segment (&aml_address, name_string)) == AE_OK) { 389 (status = acpi_ex_name_segment (&aml_address, name_string)) ==
390 AE_OK) {
372 num_segments--; 391 num_segments--;
373 } 392 }
374 393
@@ -380,7 +399,8 @@ acpi_ex_get_name_string (
380 /* null_name valid as of 8-12-98 ASL/AML Grammar Update */ 399 /* null_name valid as of 8-12-98 ASL/AML Grammar Update */
381 400
382 if (prefix_count == ACPI_UINT32_MAX) { 401 if (prefix_count == ACPI_UINT32_MAX) {
383 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "name_seg is \"\\\" followed by NULL\n")); 402 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
403 "name_seg is \"\\\" followed by NULL\n"));
384 } 404 }
385 405
386 /* Consume the NULL byte */ 406 /* Consume the NULL byte */
diff --git a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
index 8482aefaf38b..dbdf8262ba00 100644
--- a/drivers/acpi/executer/exoparg1.c
+++ b/drivers/acpi/executer/exoparg1.c
@@ -97,7 +97,8 @@ acpi_ex_opcode_0A_0T_1R (
97 union acpi_operand_object *return_desc = NULL; 97 union acpi_operand_object *return_desc = NULL;
98 98
99 99
100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_0A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_0A_0T_1R",
101 acpi_ps_get_opcode_name (walk_state->opcode));
101 102
102 103
103 /* Examine the AML opcode */ 104 /* Examine the AML opcode */
@@ -161,7 +162,8 @@ acpi_ex_opcode_1A_0T_0R (
161 acpi_status status = AE_OK; 162 acpi_status status = AE_OK;
162 163
163 164
164 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 165 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R",
166 acpi_ps_get_opcode_name (walk_state->opcode));
165 167
166 168
167 /* Examine the AML opcode */ 169 /* Examine the AML opcode */
@@ -236,7 +238,8 @@ acpi_ex_opcode_1A_1T_0R (
236 union acpi_operand_object **operand = &walk_state->operands[0]; 238 union acpi_operand_object **operand = &walk_state->operands[0];
237 239
238 240
239 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 241 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_0R",
242 acpi_ps_get_opcode_name (walk_state->opcode));
240 243
241 244
242 /* Examine the AML opcode */ 245 /* Examine the AML opcode */
@@ -289,7 +292,8 @@ acpi_ex_opcode_1A_1T_1R (
289 acpi_integer digit; 292 acpi_integer digit;
290 293
291 294
292 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 295 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_1R",
296 acpi_ps_get_opcode_name (walk_state->opcode));
293 297
294 298
295 /* Examine the AML opcode */ 299 /* Examine the AML opcode */
@@ -409,8 +413,10 @@ acpi_ex_opcode_1A_1T_1R (
409 for (i = 0; (i < acpi_gbl_integer_nybble_width) && (digit > 0); i++) { 413 for (i = 0; (i < acpi_gbl_integer_nybble_width) && (digit > 0); i++) {
410 (void) acpi_ut_short_divide (digit, 10, &digit, &temp32); 414 (void) acpi_ut_short_divide (digit, 10, &digit, &temp32);
411 415
412 /* Insert the BCD digit that resides in the remainder from above */ 416 /*
413 417 * Insert the BCD digit that resides in the
418 * remainder from above
419 */
414 return_desc->integer.value |= (((acpi_integer) temp32) << 420 return_desc->integer.value |= (((acpi_integer) temp32) <<
415 ACPI_MUL_4 (i)); 421 ACPI_MUL_4 (i));
416 } 422 }
@@ -445,7 +451,8 @@ acpi_ex_opcode_1A_1T_1R (
445 451
446 /* Get the object reference, store it, and remove our reference */ 452 /* Get the object reference, store it, and remove our reference */
447 453
448 status = acpi_ex_get_object_reference (operand[0], &return_desc2, walk_state); 454 status = acpi_ex_get_object_reference (operand[0],
455 &return_desc2, walk_state);
449 if (ACPI_FAILURE (status)) { 456 if (ACPI_FAILURE (status)) {
450 goto cleanup; 457 goto cleanup;
451 } 458 }
@@ -482,10 +489,10 @@ acpi_ex_opcode_1A_1T_1R (
482 489
483 if (!walk_state->result_obj) { 490 if (!walk_state->result_obj) {
484 /* 491 /*
485 * Normally, we would remove a reference on the Operand[0] parameter; 492 * Normally, we would remove a reference on the Operand[0]
486 * But since it is being used as the internal return object 493 * parameter; But since it is being used as the internal return
487 * (meaning we would normally increment it), the two cancel out, 494 * object (meaning we would normally increment it), the two
488 * and we simply don't do anything. 495 * cancel out, and we simply don't do anything.
489 */ 496 */
490 walk_state->result_obj = operand[0]; 497 walk_state->result_obj = operand[0];
491 walk_state->operands[0] = NULL; /* Prevent deletion */ 498 walk_state->operands[0] = NULL; /* Prevent deletion */
@@ -549,9 +556,8 @@ acpi_ex_opcode_1A_1T_1R (
549 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */ 556 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
550 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */ 557 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
551 558
552 /* 559 /* These are two obsolete opcodes */
553 * These are two obsolete opcodes 560
554 */
555 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 561 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
556 "%s is obsolete and not implemented\n", 562 "%s is obsolete and not implemented\n",
557 acpi_ps_get_opcode_name (walk_state->opcode))); 563 acpi_ps_get_opcode_name (walk_state->opcode)));
@@ -568,9 +574,8 @@ acpi_ex_opcode_1A_1T_1R (
568 } 574 }
569 575
570 if (ACPI_SUCCESS (status)) { 576 if (ACPI_SUCCESS (status)) {
571 /* 577 /* Store the return value computed above into the target object */
572 * Store the return value computed above into the target object 578
573 */
574 status = acpi_ex_store (return_desc, operand[1], walk_state); 579 status = acpi_ex_store (return_desc, operand[1], walk_state);
575 } 580 }
576 581
@@ -615,7 +620,8 @@ acpi_ex_opcode_1A_0T_1R (
615 acpi_integer value; 620 acpi_integer value;
616 621
617 622
618 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 623 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_1R",
624 acpi_ps_get_opcode_name (walk_state->opcode));
619 625
620 626
621 /* Examine the AML opcode */ 627 /* Examine the AML opcode */
@@ -706,9 +712,9 @@ acpi_ex_opcode_1A_0T_1R (
706 712
707 /* 713 /*
708 * Note: The operand is not resolved at this point because we want to 714 * Note: The operand is not resolved at this point because we want to
709 * get the associated object, not its value. For example, we don't want 715 * get the associated object, not its value. For example, we don't
710 * to resolve a field_unit to its value, we want the actual field_unit 716 * want to resolve a field_unit to its value, we want the actual
711 * object. 717 * field_unit object.
712 */ 718 */
713 719
714 /* Get the type of the base object */ 720 /* Get the type of the base object */
@@ -738,7 +744,8 @@ acpi_ex_opcode_1A_0T_1R (
738 744
739 /* Get the base object */ 745 /* Get the base object */
740 746
741 status = acpi_ex_resolve_multiple (walk_state, operand[0], &type, &temp_desc); 747 status = acpi_ex_resolve_multiple (walk_state,
748 operand[0], &type, &temp_desc);
742 if (ACPI_FAILURE (status)) { 749 if (ACPI_FAILURE (status)) {
743 goto cleanup; 750 goto cleanup;
744 } 751 }
@@ -818,8 +825,10 @@ acpi_ex_opcode_1A_0T_1R (
818 825
819 /* Set Operand[0] to the value of the local/arg */ 826 /* Set Operand[0] to the value of the local/arg */
820 827
821 status = acpi_ds_method_data_get_value (operand[0]->reference.opcode, 828 status = acpi_ds_method_data_get_value (
822 operand[0]->reference.offset, walk_state, &temp_desc); 829 operand[0]->reference.opcode,
830 operand[0]->reference.offset,
831 walk_state, &temp_desc);
823 if (ACPI_FAILURE (status)) { 832 if (ACPI_FAILURE (status)) {
824 goto cleanup; 833 goto cleanup;
825 } 834 }
@@ -852,21 +861,26 @@ acpi_ex_opcode_1A_0T_1R (
852 case ACPI_TYPE_STRING: 861 case ACPI_TYPE_STRING:
853 862
854 /* 863 /*
855 * This is a deref_of (String). The string is a reference to a named ACPI object. 864 * This is a deref_of (String). The string is a reference
865 * to a named ACPI object.
856 * 866 *
857 * 1) Find the owning Node 867 * 1) Find the owning Node
858 * 2) Dereference the node to an actual object. Could be a Field, so we nee 868 * 2) Dereference the node to an actual object. Could be a
859 * to resolve the node to a value. 869 * Field, so we need to resolve the node to a value.
860 */ 870 */
861 status = acpi_ns_get_node_by_path (operand[0]->string.pointer, 871 status = acpi_ns_get_node_by_path (operand[0]->string.pointer,
862 walk_state->scope_info->scope.node, ACPI_NS_SEARCH_PARENT, 872 walk_state->scope_info->scope.node,
863 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, &return_desc)); 873 ACPI_NS_SEARCH_PARENT,
874 ACPI_CAST_INDIRECT_PTR (
875 struct acpi_namespace_node, &return_desc));
864 if (ACPI_FAILURE (status)) { 876 if (ACPI_FAILURE (status)) {
865 goto cleanup; 877 goto cleanup;
866 } 878 }
867 879
868 status = acpi_ex_resolve_node_to_value ( 880 status = acpi_ex_resolve_node_to_value (
869 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, &return_desc), walk_state); 881 ACPI_CAST_INDIRECT_PTR (
882 struct acpi_namespace_node, &return_desc),
883 walk_state);
870 goto cleanup; 884 goto cleanup;
871 885
872 886
@@ -883,14 +897,16 @@ acpi_ex_opcode_1A_0T_1R (
883 /* 897 /*
884 * This is a deref_of (object_reference) 898 * This is a deref_of (object_reference)
885 * Get the actual object from the Node (This is the dereference). 899 * Get the actual object from the Node (This is the dereference).
886 * -- This case may only happen when a local_x or arg_x is dereferenced above. 900 * This case may only happen when a local_x or arg_x is
901 * dereferenced above.
887 */ 902 */
888 return_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) operand[0]); 903 return_desc = acpi_ns_get_attached_object (
904 (struct acpi_namespace_node *) operand[0]);
889 } 905 }
890 else { 906 else {
891 /* 907 /*
892 * This must be a reference object produced by either the Index() or 908 * This must be a reference object produced by either the
893 * ref_of() operator 909 * Index() or ref_of() operator
894 */ 910 */
895 switch (operand[0]->reference.opcode) { 911 switch (operand[0]->reference.opcode) {
896 case AML_INDEX_OP: 912 case AML_INDEX_OP:
@@ -931,8 +947,8 @@ acpi_ex_opcode_1A_0T_1R (
931 case ACPI_TYPE_PACKAGE: 947 case ACPI_TYPE_PACKAGE:
932 948
933 /* 949 /*
934 * Return the referenced element of the package. We must add 950 * Return the referenced element of the package. We must
935 * another reference to the referenced object, however. 951 * add another reference to the referenced object, however.
936 */ 952 */
937 return_desc = *(operand[0]->reference.where); 953 return_desc = *(operand[0]->reference.where);
938 if (!return_desc) { 954 if (!return_desc) {
@@ -967,9 +983,11 @@ acpi_ex_opcode_1A_0T_1R (
967 983
968 return_desc = operand[0]->reference.object; 984 return_desc = operand[0]->reference.object;
969 985
970 if (ACPI_GET_DESCRIPTOR_TYPE (return_desc) == ACPI_DESC_TYPE_NAMED) { 986 if (ACPI_GET_DESCRIPTOR_TYPE (return_desc) ==
987 ACPI_DESC_TYPE_NAMED) {
971 988
972 return_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) return_desc); 989 return_desc = acpi_ns_get_attached_object (
990 (struct acpi_namespace_node *) return_desc);
973 } 991 }
974 992
975 /* Add another reference to the object! */ 993 /* Add another reference to the object! */
diff --git a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
index 8be4d80ceed5..7429032c2b6c 100644
--- a/drivers/acpi/executer/exoparg2.c
+++ b/drivers/acpi/executer/exoparg2.c
@@ -118,7 +118,7 @@ acpi_ex_opcode_2A_0T_0R (
118 118
119 value = (u32) operand[1]->integer.value; 119 value = (u32) operand[1]->integer.value;
120 120
121 /* Notifies allowed on this object? */ 121 /* Are notifies allowed on this object? */
122 122
123 if (!acpi_ev_is_notify_object (node)) { 123 if (!acpi_ev_is_notify_object (node)) {
124 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 124 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
@@ -203,11 +203,12 @@ acpi_ex_opcode_2A_2T_1R (
203 acpi_ps_get_opcode_name (walk_state->opcode)); 203 acpi_ps_get_opcode_name (walk_state->opcode));
204 204
205 205
206 /* 206 /* Execute the opcode */
207 * Execute the opcode 207
208 */
209 switch (walk_state->opcode) { 208 switch (walk_state->opcode) {
210 case AML_DIVIDE_OP: /* Divide (Dividend, Divisor, remainder_result quotient_result) */ 209 case AML_DIVIDE_OP:
210
211 /* Divide (Dividend, Divisor, remainder_result quotient_result) */
211 212
212 return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 213 return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
213 if (!return_desc1) { 214 if (!return_desc1) {
@@ -241,7 +242,6 @@ acpi_ex_opcode_2A_2T_1R (
241 goto cleanup; 242 goto cleanup;
242 } 243 }
243 244
244
245 /* Store the results to the target reference operands */ 245 /* Store the results to the target reference operands */
246 246
247 status = acpi_ex_store (return_desc2, operand[2], walk_state); 247 status = acpi_ex_store (return_desc2, operand[2], walk_state);
@@ -295,7 +295,7 @@ acpi_ex_opcode_2A_1T_1R (
295{ 295{
296 union acpi_operand_object **operand = &walk_state->operands[0]; 296 union acpi_operand_object **operand = &walk_state->operands[0];
297 union acpi_operand_object *return_desc = NULL; 297 union acpi_operand_object *return_desc = NULL;
298 u32 index; 298 acpi_integer index;
299 acpi_status status = AE_OK; 299 acpi_status status = AE_OK;
300 acpi_size length; 300 acpi_size length;
301 301
@@ -304,9 +304,8 @@ acpi_ex_opcode_2A_1T_1R (
304 acpi_ps_get_opcode_name (walk_state->opcode)); 304 acpi_ps_get_opcode_name (walk_state->opcode));
305 305
306 306
307 /* 307 /* Execute the opcode */
308 * Execute the opcode 308
309 */
310 if (walk_state->op_info->flags & AML_MATH) { 309 if (walk_state->op_info->flags & AML_MATH) {
311 /* All simple math opcodes (add, etc.) */ 310 /* All simple math opcodes (add, etc.) */
312 311
@@ -322,9 +321,8 @@ acpi_ex_opcode_2A_1T_1R (
322 goto store_result_to_target; 321 goto store_result_to_target;
323 } 322 }
324 323
325
326 switch (walk_state->opcode) { 324 switch (walk_state->opcode) {
327 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */ 325 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
328 326
329 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 327 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
330 if (!return_desc) { 328 if (!return_desc) {
@@ -341,18 +339,19 @@ acpi_ex_opcode_2A_1T_1R (
341 break; 339 break;
342 340
343 341
344 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */ 342 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
345 343
346 status = acpi_ex_do_concatenate (operand[0], operand[1], 344 status = acpi_ex_do_concatenate (operand[0], operand[1],
347 &return_desc, walk_state); 345 &return_desc, walk_state);
348 break; 346 break;
349 347
350 348
351 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */ 349 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
352 350
353 /* 351 /*
354 * Input object is guaranteed to be a buffer at this point (it may have 352 * Input object is guaranteed to be a buffer at this point (it may have
355 * been converted.) Copy the raw buffer data to a new object of type String. 353 * been converted.) Copy the raw buffer data to a new object of
354 * type String.
356 */ 355 */
357 356
358 /* 357 /*
@@ -383,14 +382,16 @@ acpi_ex_opcode_2A_1T_1R (
383 goto cleanup; 382 goto cleanup;
384 } 383 }
385 384
386 /* Copy the raw buffer data with no transform. NULL terminated already. */ 385 /* Copy the raw buffer data with no transform. NULL terminated already*/
387 386
388 ACPI_MEMCPY (return_desc->string.pointer, 387 ACPI_MEMCPY (return_desc->string.pointer,
389 operand[0]->buffer.pointer, length); 388 operand[0]->buffer.pointer, length);
390 break; 389 break;
391 390
392 391
393 case AML_CONCAT_RES_OP: /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */ 392 case AML_CONCAT_RES_OP:
393
394 /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
394 395
395 status = acpi_ex_concat_template (operand[0], operand[1], 396 status = acpi_ex_concat_template (operand[0], operand[1],
396 &return_desc, walk_state); 397 &return_desc, walk_state);
@@ -407,33 +408,33 @@ acpi_ex_opcode_2A_1T_1R (
407 goto cleanup; 408 goto cleanup;
408 } 409 }
409 410
410 index = (u32) operand[1]->integer.value; 411 index = operand[1]->integer.value;
412
413 /* At this point, the Source operand is a Package, Buffer, or String */
411 414
412 /*
413 * At this point, the Source operand is a Package, Buffer, or String
414 */
415 if (ACPI_GET_OBJECT_TYPE (operand[0]) == ACPI_TYPE_PACKAGE) { 415 if (ACPI_GET_OBJECT_TYPE (operand[0]) == ACPI_TYPE_PACKAGE) {
416 /* Object to be indexed is a Package */ 416 /* Object to be indexed is a Package */
417 417
418 if (index >= operand[0]->package.count) { 418 if (index >= operand[0]->package.count) {
419 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 419 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
420 "Index value (%X) beyond package end (%X)\n", 420 "Index value (%X%8.8X) beyond package end (%X)\n",
421 index, operand[0]->package.count)); 421 ACPI_FORMAT_UINT64 (index), operand[0]->package.count));
422 status = AE_AML_PACKAGE_LIMIT; 422 status = AE_AML_PACKAGE_LIMIT;
423 goto cleanup; 423 goto cleanup;
424 } 424 }
425 425
426 return_desc->reference.target_type = ACPI_TYPE_PACKAGE; 426 return_desc->reference.target_type = ACPI_TYPE_PACKAGE;
427 return_desc->reference.object = operand[0]; 427 return_desc->reference.object = operand[0];
428 return_desc->reference.where = &operand[0]->package.elements [index]; 428 return_desc->reference.where = &operand[0]->package.elements [
429 index];
429 } 430 }
430 else { 431 else {
431 /* Object to be indexed is a Buffer/String */ 432 /* Object to be indexed is a Buffer/String */
432 433
433 if (index >= operand[0]->buffer.length) { 434 if (index >= operand[0]->buffer.length) {
434 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 435 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
435 "Index value (%X) beyond end of buffer (%X)\n", 436 "Index value (%X%8.8X) beyond end of buffer (%X)\n",
436 index, operand[0]->buffer.length)); 437 ACPI_FORMAT_UINT64 (index), operand[0]->buffer.length));
437 status = AE_AML_BUFFER_LIMIT; 438 status = AE_AML_BUFFER_LIMIT;
438 goto cleanup; 439 goto cleanup;
439 } 440 }
@@ -451,7 +452,7 @@ acpi_ex_opcode_2A_1T_1R (
451 /* Complete the Index reference object */ 452 /* Complete the Index reference object */
452 453
453 return_desc->reference.opcode = AML_INDEX_OP; 454 return_desc->reference.opcode = AML_INDEX_OP;
454 return_desc->reference.offset = index; 455 return_desc->reference.offset = (u32) index;
455 456
456 /* Store the reference to the Target */ 457 /* Store the reference to the Target */
457 458
@@ -536,22 +537,24 @@ acpi_ex_opcode_2A_0T_1R (
536 goto cleanup; 537 goto cleanup;
537 } 538 }
538 539
539 /* 540 /* Execute the Opcode */
540 * Execute the Opcode 541
541 */ 542 if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) {
542 if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) /* logical_op (Operand0, Operand1) */ { 543 /* logical_op (Operand0, Operand1) */
544
543 status = acpi_ex_do_logical_numeric_op (walk_state->opcode, 545 status = acpi_ex_do_logical_numeric_op (walk_state->opcode,
544 operand[0]->integer.value, operand[1]->integer.value, 546 operand[0]->integer.value, operand[1]->integer.value,
545 &logical_result); 547 &logical_result);
546 goto store_logical_result; 548 goto store_logical_result;
547 } 549 }
548 else if (walk_state->op_info->flags & AML_LOGICAL) /* logical_op (Operand0, Operand1) */ { 550 else if (walk_state->op_info->flags & AML_LOGICAL) {
551 /* logical_op (Operand0, Operand1) */
552
549 status = acpi_ex_do_logical_op (walk_state->opcode, operand[0], 553 status = acpi_ex_do_logical_op (walk_state->opcode, operand[0],
550 operand[1], &logical_result); 554 operand[1], &logical_result);
551 goto store_logical_result; 555 goto store_logical_result;
552 } 556 }
553 557
554
555 switch (walk_state->opcode) { 558 switch (walk_state->opcode) {
556 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */ 559 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */
557 560
diff --git a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
index 29d0b167745d..23b068adbf58 100644
--- a/drivers/acpi/executer/exoparg3.c
+++ b/drivers/acpi/executer/exoparg3.c
@@ -97,11 +97,12 @@ acpi_ex_opcode_3A_0T_0R (
97 acpi_status status = AE_OK; 97 acpi_status status = AE_OK;
98 98
99 99
100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R",
101 acpi_ps_get_opcode_name (walk_state->opcode));
101 102
102 103
103 switch (walk_state->opcode) { 104 switch (walk_state->opcode) {
104 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */ 105 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
105 106
106 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 107 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
107 "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", 108 "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
@@ -116,9 +117,8 @@ acpi_ex_opcode_3A_0T_0R (
116 fatal->argument = (u32) operand[2]->integer.value; 117 fatal->argument = (u32) operand[2]->integer.value;
117 } 118 }
118 119
119 /* 120 /* Always signal the OS! */
120 * Always signal the OS! 121
121 */
122 status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal); 122 status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal);
123 123
124 /* Might return while OS is shutting down, just continue */ 124 /* Might return while OS is shutting down, just continue */
@@ -162,21 +162,23 @@ acpi_ex_opcode_3A_1T_1R (
162 union acpi_operand_object *return_desc = NULL; 162 union acpi_operand_object *return_desc = NULL;
163 char *buffer; 163 char *buffer;
164 acpi_status status = AE_OK; 164 acpi_status status = AE_OK;
165 acpi_native_uint index; 165 acpi_integer index;
166 acpi_size length; 166 acpi_size length;
167 167
168 168
169 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 169 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R",
170 acpi_ps_get_opcode_name (walk_state->opcode));
170 171
171 172
172 switch (walk_state->opcode) { 173 switch (walk_state->opcode) {
173 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ 174 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
174 175
175 /* 176 /*
176 * Create the return object. The Source operand is guaranteed to be 177 * Create the return object. The Source operand is guaranteed to be
177 * either a String or a Buffer, so just use its type. 178 * either a String or a Buffer, so just use its type.
178 */ 179 */
179 return_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (operand[0])); 180 return_desc = acpi_ut_create_internal_object (
181 ACPI_GET_OBJECT_TYPE (operand[0]));
180 if (!return_desc) { 182 if (!return_desc) {
181 status = AE_NO_MEMORY; 183 status = AE_NO_MEMORY;
182 goto cleanup; 184 goto cleanup;
@@ -184,7 +186,7 @@ acpi_ex_opcode_3A_1T_1R (
184 186
185 /* Get the Integer values from the objects */ 187 /* Get the Integer values from the objects */
186 188
187 index = (acpi_native_uint) operand[1]->integer.value; 189 index = operand[1]->integer.value;
188 length = (acpi_size) operand[2]->integer.value; 190 length = (acpi_size) operand[2]->integer.value;
189 191
190 /* 192 /*
@@ -197,7 +199,8 @@ acpi_ex_opcode_3A_1T_1R (
197 199
198 if ((index + length) > 200 if ((index + length) >
199 operand[0]->string.length) { 201 operand[0]->string.length) {
200 length = (acpi_size) operand[0]->string.length - index; 202 length = (acpi_size) operand[0]->string.length -
203 (acpi_size) index;
201 } 204 }
202 205
203 /* Allocate a new buffer for the String/Buffer */ 206 /* Allocate a new buffer for the String/Buffer */
diff --git a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
index d32624331626..17f81d42ee41 100644
--- a/drivers/acpi/executer/exoparg6.c
+++ b/drivers/acpi/executer/exoparg6.c
@@ -75,6 +75,14 @@
75 * fully resolved operands. 75 * fully resolved operands.
76!*/ 76!*/
77 77
78/* Local prototypes */
79
80static u8
81acpi_ex_do_match (
82 u32 match_op,
83 union acpi_operand_object *package_obj,
84 union acpi_operand_object *match_obj);
85
78 86
79/******************************************************************************* 87/*******************************************************************************
80 * 88 *
@@ -92,7 +100,7 @@
92 * 100 *
93 ******************************************************************************/ 101 ******************************************************************************/
94 102
95u8 103static u8
96acpi_ex_do_match ( 104acpi_ex_do_match (
97 u32 match_op, 105 u32 match_op,
98 union acpi_operand_object *package_obj, 106 union acpi_operand_object *package_obj,
@@ -216,11 +224,12 @@ acpi_ex_opcode_6A_0T_1R (
216 union acpi_operand_object **operand = &walk_state->operands[0]; 224 union acpi_operand_object **operand = &walk_state->operands[0];
217 union acpi_operand_object *return_desc = NULL; 225 union acpi_operand_object *return_desc = NULL;
218 acpi_status status = AE_OK; 226 acpi_status status = AE_OK;
219 u32 index; 227 acpi_integer index;
220 union acpi_operand_object *this_element; 228 union acpi_operand_object *this_element;
221 229
222 230
223 ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 231 ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R",
232 acpi_ps_get_opcode_name (walk_state->opcode));
224 233
225 234
226 switch (walk_state->opcode) { 235 switch (walk_state->opcode) {
@@ -241,9 +250,11 @@ acpi_ex_opcode_6A_0T_1R (
241 250
242 /* Get the package start_index, validate against the package length */ 251 /* Get the package start_index, validate against the package length */
243 252
244 index = (u32) operand[5]->integer.value; 253 index = operand[5]->integer.value;
245 if (index >= (u32) operand[0]->package.count) { 254 if (index >= operand[0]->package.count) {
246 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index beyond package end\n")); 255 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
256 "Index (%X%8.8X) beyond package end (%X)\n",
257 ACPI_FORMAT_UINT64 (index), operand[0]->package.count));
247 status = AE_AML_PACKAGE_LIMIT; 258 status = AE_AML_PACKAGE_LIMIT;
248 goto cleanup; 259 goto cleanup;
249 } 260 }
@@ -314,13 +325,12 @@ acpi_ex_opcode_6A_0T_1R (
314 325
315 default: 326 default:
316 327
317 ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", 328 ACPI_REPORT_ERROR (("acpi_ex_opcode_6A_0T_1R: Unknown opcode %X\n",
318 walk_state->opcode)); 329 walk_state->opcode));
319 status = AE_AML_BAD_OPCODE; 330 status = AE_AML_BAD_OPCODE;
320 goto cleanup; 331 goto cleanup;
321 } 332 }
322 333
323
324 walk_state->result_obj = return_desc; 334 walk_state->result_obj = return_desc;
325 335
326 336
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index 264ef3bba31b..c9e3c68b5549 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -52,8 +52,23 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exprep") 53 ACPI_MODULE_NAME ("exprep")
54 54
55/* Local prototypes */
56
57static u32
58acpi_ex_decode_field_access (
59 union acpi_operand_object *obj_desc,
60 u8 field_flags,
61 u32 *return_byte_alignment);
62
55 63
56#ifdef ACPI_UNDER_DEVELOPMENT 64#ifdef ACPI_UNDER_DEVELOPMENT
65
66static u32
67acpi_ex_generate_access (
68 u32 field_bit_offset,
69 u32 field_bit_length,
70 u32 region_length);
71
57/******************************************************************************* 72/*******************************************************************************
58 * 73 *
59 * FUNCTION: acpi_ex_generate_access 74 * FUNCTION: acpi_ex_generate_access
@@ -99,12 +114,14 @@ acpi_ex_generate_access (
99 /* Round Field start offset and length to "minimal" byte boundaries */ 114 /* Round Field start offset and length to "minimal" byte boundaries */
100 115
101 field_byte_offset = ACPI_DIV_8 (ACPI_ROUND_DOWN (field_bit_offset, 8)); 116 field_byte_offset = ACPI_DIV_8 (ACPI_ROUND_DOWN (field_bit_offset, 8));
102 field_byte_end_offset = ACPI_DIV_8 (ACPI_ROUND_UP (field_bit_length + field_bit_offset, 8)); 117 field_byte_end_offset = ACPI_DIV_8 (ACPI_ROUND_UP (field_bit_length +
118 field_bit_offset, 8));
103 field_byte_length = field_byte_end_offset - field_byte_offset; 119 field_byte_length = field_byte_end_offset - field_byte_offset;
104 120
105 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 121 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
106 "Bit length %d, Bit offset %d\n", 122 "Bit length %d, Bit offset %d\n",
107 field_bit_length, field_bit_offset)); 123 field_bit_length, field_bit_offset));
124
108 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 125 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
109 "Byte Length %d, Byte Offset %d, End Offset %d\n", 126 "Byte Length %d, Byte Offset %d, End Offset %d\n",
110 field_byte_length, field_byte_offset, field_byte_end_offset)); 127 field_byte_length, field_byte_offset, field_byte_end_offset));
@@ -117,20 +134,26 @@ acpi_ex_generate_access (
117 */ 134 */
118 for (access_byte_width = 1; access_byte_width <= 8; access_byte_width <<= 1) { 135 for (access_byte_width = 1; access_byte_width <= 8; access_byte_width <<= 1) {
119 /* 136 /*
120 * 1) Round end offset up to next access boundary and make sure that this 137 * 1) Round end offset up to next access boundary and make sure that
121 * does not go beyond the end of the parent region. 138 * this does not go beyond the end of the parent region.
122 * 2) When the Access width is greater than the field_byte_length, we are done. 139 * 2) When the Access width is greater than the field_byte_length, we
123 * (This does not optimize for the perfectly aligned case yet). 140 * are done. (This does not optimize for the perfectly aligned
141 * case yet).
124 */ 142 */
125 if (ACPI_ROUND_UP (field_byte_end_offset, access_byte_width) <= region_length) { 143 if (ACPI_ROUND_UP (field_byte_end_offset, access_byte_width) <= region_length) {
126 field_start_offset = ACPI_ROUND_DOWN (field_byte_offset, access_byte_width) / 144 field_start_offset =
127 access_byte_width; 145 ACPI_ROUND_DOWN (field_byte_offset, access_byte_width) /
128 field_end_offset = ACPI_ROUND_UP ((field_byte_length + field_byte_offset), 146 access_byte_width;
129 access_byte_width) / access_byte_width; 147
130 accesses = field_end_offset - field_start_offset; 148 field_end_offset =
149 ACPI_ROUND_UP ((field_byte_length + field_byte_offset),
150 access_byte_width) / access_byte_width;
151
152 accesses = field_end_offset - field_start_offset;
131 153
132 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 154 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
133 "access_width %d end is within region\n", access_byte_width)); 155 "access_width %d end is within region\n", access_byte_width));
156
134 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 157 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
135 "Field Start %d, Field End %d -- requires %d accesses\n", 158 "Field Start %d, Field End %d -- requires %d accesses\n",
136 field_start_offset, field_end_offset, accesses)); 159 field_start_offset, field_end_offset, accesses));
@@ -139,8 +162,8 @@ acpi_ex_generate_access (
139 162
140 if (accesses <= 1) { 163 if (accesses <= 1) {
141 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 164 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
142 "Entire field can be accessed with one operation of size %d\n", 165 "Entire field can be accessed with one operation of size %d\n",
143 access_byte_width)); 166 access_byte_width));
144 return_VALUE (access_byte_width); 167 return_VALUE (access_byte_width);
145 } 168 }
146 169
@@ -155,15 +178,20 @@ acpi_ex_generate_access (
155 } 178 }
156 else { 179 else {
157 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 180 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
158 "access_width %d end is NOT within region\n", access_byte_width)); 181 "access_width %d end is NOT within region\n", access_byte_width));
159 if (access_byte_width == 1) { 182 if (access_byte_width == 1) {
160 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 183 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
161 "Field goes beyond end-of-region!\n")); 184 "Field goes beyond end-of-region!\n"));
162 return_VALUE (0); /* Field does not fit in the region at all */
163 }
164 185
165 /* This width goes beyond the end-of-region, back off to previous access */ 186 /* Field does not fit in the region at all */
166 187
188 return_VALUE (0);
189 }
190
191 /*
192 * This width goes beyond the end-of-region, back off to
193 * previous access
194 */
167 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 195 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
168 "Backing off to previous optimal access width of %d\n", 196 "Backing off to previous optimal access width of %d\n",
169 minimum_access_width)); 197 minimum_access_width));
@@ -171,8 +199,10 @@ acpi_ex_generate_access (
171 } 199 }
172 } 200 }
173 201
174 /* Could not read/write field with one operation, just use max access width */ 202 /*
175 203 * Could not read/write field with one operation,
204 * just use max access width
205 */
176 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 206 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
177 "Cannot access field in one operation, using width 8\n")); 207 "Cannot access field in one operation, using width 8\n"));
178 return_VALUE (8); 208 return_VALUE (8);
@@ -184,8 +214,9 @@ acpi_ex_generate_access (
184 * 214 *
185 * FUNCTION: acpi_ex_decode_field_access 215 * FUNCTION: acpi_ex_decode_field_access
186 * 216 *
187 * PARAMETERS: Access - Encoded field access bits 217 * PARAMETERS: obj_desc - Field object
188 * Length - Field length. 218 * field_flags - Encoded fieldflags (contains access bits)
219 * return_byte_alignment - Where the byte alignment is returned
189 * 220 *
190 * RETURN: Field granularity (8, 16, 32 or 64) and 221 * RETURN: Field granularity (8, 16, 32 or 64) and
191 * byte_alignment (1, 2, 3, or 4) 222 * byte_alignment (1, 2, 3, or 4)
@@ -214,9 +245,10 @@ acpi_ex_decode_field_access (
214 case AML_FIELD_ACCESS_ANY: 245 case AML_FIELD_ACCESS_ANY:
215 246
216#ifdef ACPI_UNDER_DEVELOPMENT 247#ifdef ACPI_UNDER_DEVELOPMENT
217 byte_alignment = acpi_ex_generate_access (obj_desc->common_field.start_field_bit_offset, 248 byte_alignment =
218 obj_desc->common_field.bit_length, 249 acpi_ex_generate_access (obj_desc->common_field.start_field_bit_offset,
219 0xFFFFFFFF /* Temp until we pass region_length as param */); 250 obj_desc->common_field.bit_length,
251 0xFFFFFFFF /* Temp until we pass region_length as parameter */);
220 bit_length = byte_alignment * 8; 252 bit_length = byte_alignment * 8;
221#endif 253#endif
222 254
@@ -276,6 +308,7 @@ acpi_ex_decode_field_access (
276 * field_flags - Access, lock_rule, and update_rule. 308 * field_flags - Access, lock_rule, and update_rule.
277 * The format of a field_flag is described 309 * The format of a field_flag is described
278 * in the ACPI specification 310 * in the ACPI specification
311 * field_attribute - Special attributes (not used)
279 * field_bit_position - Field start position 312 * field_bit_position - Field start position
280 * field_bit_length - Field length in number of bits 313 * field_bit_length - Field length in number of bits
281 * 314 *
@@ -337,7 +370,7 @@ acpi_ex_prep_common_field_object (
337 /* Setup width (access granularity) fields */ 370 /* Setup width (access granularity) fields */
338 371
339 obj_desc->common_field.access_byte_width = (u8) 372 obj_desc->common_field.access_byte_width = (u8)
340 ACPI_DIV_8 (access_bit_width); /* 1, 2, 4, 8 */ 373 ACPI_DIV_8 (access_bit_width); /* 1, 2, 4, 8 */
341 374
342 obj_desc->common_field.access_bit_width = (u8) access_bit_width; 375 obj_desc->common_field.access_bit_width = (u8) access_bit_width;
343 376
@@ -380,11 +413,7 @@ acpi_ex_prep_common_field_object (
380 * 413 *
381 * FUNCTION: acpi_ex_prep_field_value 414 * FUNCTION: acpi_ex_prep_field_value
382 * 415 *
383 * PARAMETERS: Node - Owning Node 416 * PARAMETERS: Info - Contains all field creation info
384 * region_node - Region in which field is being defined
385 * field_flags - Access, lock_rule, and update_rule.
386 * field_bit_position - Field start position
387 * field_bit_length - Field length in number of bits
388 * 417 *
389 * RETURN: Status 418 * RETURN: Status
390 * 419 *
@@ -445,7 +474,7 @@ acpi_ex_prep_field_value (
445 switch (info->field_type) { 474 switch (info->field_type) {
446 case ACPI_TYPE_LOCAL_REGION_FIELD: 475 case ACPI_TYPE_LOCAL_REGION_FIELD:
447 476
448 obj_desc->field.region_obj = acpi_ns_get_attached_object (info->region_node); 477 obj_desc->field.region_obj = acpi_ns_get_attached_object (info->region_node);
449 478
450 /* An additional reference for the container */ 479 /* An additional reference for the container */
451 480
@@ -461,8 +490,10 @@ acpi_ex_prep_field_value (
461 case ACPI_TYPE_LOCAL_BANK_FIELD: 490 case ACPI_TYPE_LOCAL_BANK_FIELD:
462 491
463 obj_desc->bank_field.value = info->bank_value; 492 obj_desc->bank_field.value = info->bank_value;
464 obj_desc->bank_field.region_obj = acpi_ns_get_attached_object (info->region_node); 493 obj_desc->bank_field.region_obj = acpi_ns_get_attached_object (
465 obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object (info->register_node); 494 info->region_node);
495 obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object (
496 info->register_node);
466 497
467 /* An additional reference for the attached objects */ 498 /* An additional reference for the attached objects */
468 499
@@ -481,10 +512,13 @@ acpi_ex_prep_field_value (
481 512
482 case ACPI_TYPE_LOCAL_INDEX_FIELD: 513 case ACPI_TYPE_LOCAL_INDEX_FIELD:
483 514
484 obj_desc->index_field.index_obj = acpi_ns_get_attached_object (info->register_node); 515 obj_desc->index_field.index_obj = acpi_ns_get_attached_object (
485 obj_desc->index_field.data_obj = acpi_ns_get_attached_object (info->data_register_node); 516 info->register_node);
517 obj_desc->index_field.data_obj = acpi_ns_get_attached_object (
518 info->data_register_node);
486 obj_desc->index_field.value = (u32) 519 obj_desc->index_field.value = (u32)
487 (info->field_bit_position / ACPI_MUL_8 (obj_desc->field.access_byte_width)); 520 (info->field_bit_position / ACPI_MUL_8 (
521 obj_desc->field.access_byte_width));
488 522
489 if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { 523 if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) {
490 ACPI_REPORT_ERROR (("Null Index Object during field prep\n")); 524 ACPI_REPORT_ERROR (("Null Index Object during field prep\n"));
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
index 7cfd0684c70b..723aaef4bb4a 100644
--- a/drivers/acpi/executer/exregion.c
+++ b/drivers/acpi/executer/exregion.c
@@ -115,7 +115,6 @@ acpi_ex_system_memory_space_handler (
115 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 115 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
116 } 116 }
117 117
118
119#ifndef ACPI_MISALIGNED_TRANSFERS 118#ifndef ACPI_MISALIGNED_TRANSFERS
120 /* 119 /*
121 * Hardware does not support non-aligned data transfers, we must verify 120 * Hardware does not support non-aligned data transfers, we must verify
@@ -134,7 +133,8 @@ acpi_ex_system_memory_space_handler (
134 */ 133 */
135 if ((address < mem_info->mapped_physical_address) || 134 if ((address < mem_info->mapped_physical_address) ||
136 (((acpi_integer) address + length) > 135 (((acpi_integer) address + length) >
137 ((acpi_integer) mem_info->mapped_physical_address + mem_info->mapped_length))) { 136 ((acpi_integer)
137 mem_info->mapped_physical_address + mem_info->mapped_length))) {
138 /* 138 /*
139 * The request cannot be resolved by the current memory mapping; 139 * The request cannot be resolved by the current memory mapping;
140 * Delete the existing mapping and create a new one. 140 * Delete the existing mapping and create a new one.
@@ -150,7 +150,9 @@ acpi_ex_system_memory_space_handler (
150 * Don't attempt to map memory beyond the end of the region, and 150 * Don't attempt to map memory beyond the end of the region, and
151 * constrain the maximum mapping size to something reasonable. 151 * constrain the maximum mapping size to something reasonable.
152 */ 152 */
153 window_size = (acpi_size) ((mem_info->address + mem_info->length) - address); 153 window_size = (acpi_size)
154 ((mem_info->address + mem_info->length) - address);
155
154 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) { 156 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
155 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE; 157 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
156 } 158 }
@@ -160,8 +162,9 @@ acpi_ex_system_memory_space_handler (
160 status = acpi_os_map_memory (address, window_size, 162 status = acpi_os_map_memory (address, window_size,
161 (void **) &mem_info->mapped_logical_address); 163 (void **) &mem_info->mapped_logical_address);
162 if (ACPI_FAILURE (status)) { 164 if (ACPI_FAILURE (status)) {
163 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %8.8X%8.8X, size %X\n", 165 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
164 ACPI_FORMAT_UINT64 (address), (u32) window_size)); 166 "Could not map memory at %8.8X%8.8X, size %X\n",
167 ACPI_FORMAT_UINT64 (address), (u32) window_size));
165 mem_info->mapped_length = 0; 168 mem_info->mapped_length = 0;
166 return_ACPI_STATUS (status); 169 return_ACPI_STATUS (status);
167 } 170 }
@@ -177,10 +180,12 @@ acpi_ex_system_memory_space_handler (
177 * access 180 * access
178 */ 181 */
179 logical_addr_ptr = mem_info->mapped_logical_address + 182 logical_addr_ptr = mem_info->mapped_logical_address +
180 ((acpi_integer) address - (acpi_integer) mem_info->mapped_physical_address); 183 ((acpi_integer) address -
184 (acpi_integer) mem_info->mapped_physical_address);
181 185
182 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 186 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
183 "system_memory %d (%d width) Address=%8.8X%8.8X\n", function, bit_width, 187 "system_memory %d (%d width) Address=%8.8X%8.8X\n",
188 function, bit_width,
184 ACPI_FORMAT_UINT64 (address))); 189 ACPI_FORMAT_UINT64 (address)));
185 190
186 /* 191 /*
@@ -298,13 +303,15 @@ acpi_ex_system_io_space_handler (
298 switch (function) { 303 switch (function) {
299 case ACPI_READ: 304 case ACPI_READ:
300 305
301 status = acpi_os_read_port ((acpi_io_address) address, &value32, bit_width); 306 status = acpi_os_read_port ((acpi_io_address) address,
307 &value32, bit_width);
302 *value = value32; 308 *value = value32;
303 break; 309 break;
304 310
305 case ACPI_WRITE: 311 case ACPI_WRITE:
306 312
307 status = acpi_os_write_port ((acpi_io_address) address, (u32) *value, bit_width); 313 status = acpi_os_write_port ((acpi_io_address) address,
314 (u32) *value, bit_width);
308 break; 315 break;
309 316
310 default: 317 default:
@@ -375,12 +382,14 @@ acpi_ex_pci_config_space_handler (
375 case ACPI_READ: 382 case ACPI_READ:
376 383
377 *value = 0; 384 *value = 0;
378 status = acpi_os_read_pci_configuration (pci_id, pci_register, value, bit_width); 385 status = acpi_os_read_pci_configuration (pci_id, pci_register,
386 value, bit_width);
379 break; 387 break;
380 388
381 case ACPI_WRITE: 389 case ACPI_WRITE:
382 390
383 status = acpi_os_write_pci_configuration (pci_id, pci_register, *value, bit_width); 391 status = acpi_os_write_pci_configuration (pci_id, pci_register,
392 *value, bit_width);
384 break; 393 break;
385 394
386 default: 395 default:
@@ -505,8 +514,7 @@ acpi_ex_data_table_space_handler (
505 514
506 logical_addr_ptr = ACPI_PHYSADDR_TO_PTR (address); 515 logical_addr_ptr = ACPI_PHYSADDR_TO_PTR (address);
507 516
508 517 /* Perform the memory read or write */
509 /* Perform the memory read or write */
510 518
511 switch (function) { 519 switch (function) {
512 case ACPI_READ: 520 case ACPI_READ:
diff --git a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
index 7936329a0e35..21d5c74fa309 100644
--- a/drivers/acpi/executer/exresnte.c
+++ b/drivers/acpi/executer/exresnte.c
@@ -210,15 +210,15 @@ acpi_ex_resolve_node_to_value (
210 case ACPI_TYPE_LOCAL_BANK_FIELD: 210 case ACPI_TYPE_LOCAL_BANK_FIELD:
211 case ACPI_TYPE_LOCAL_INDEX_FIELD: 211 case ACPI_TYPE_LOCAL_INDEX_FIELD:
212 212
213 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read Node=%p source_desc=%p Type=%X\n", 213 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
214 "field_read Node=%p source_desc=%p Type=%X\n",
214 node, source_desc, entry_type)); 215 node, source_desc, entry_type));
215 216
216 status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc); 217 status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc);
217 break; 218 break;
218 219
219 /* 220 /* For these objects, just return the object attached to the Node */
220 * For these objects, just return the object attached to the Node 221
221 */
222 case ACPI_TYPE_MUTEX: 222 case ACPI_TYPE_MUTEX:
223 case ACPI_TYPE_METHOD: 223 case ACPI_TYPE_METHOD:
224 case ACPI_TYPE_POWER: 224 case ACPI_TYPE_POWER:
@@ -233,12 +233,12 @@ acpi_ex_resolve_node_to_value (
233 acpi_ut_add_reference (obj_desc); 233 acpi_ut_add_reference (obj_desc);
234 break; 234 break;
235 235
236
237 /* TYPE_ANY is untyped, and thus there is no object associated with it */ 236 /* TYPE_ANY is untyped, and thus there is no object associated with it */
238 237
239 case ACPI_TYPE_ANY: 238 case ACPI_TYPE_ANY:
240 239
241 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Untyped entry %p, no attached object!\n", 240 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
241 "Untyped entry %p, no attached object!\n",
242 node)); 242 node));
243 243
244 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ 244 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
@@ -259,7 +259,8 @@ acpi_ex_resolve_node_to_value (
259 default: 259 default:
260 /* No named references are allowed here */ 260 /* No named references are allowed here */
261 261
262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported Reference opcode %X (%s)\n", 262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
263 "Unsupported Reference opcode %X (%s)\n",
263 source_desc->reference.opcode, 264 source_desc->reference.opcode,
264 acpi_ps_get_opcode_name (source_desc->reference.opcode))); 265 acpi_ps_get_opcode_name (source_desc->reference.opcode)));
265 266
@@ -268,11 +269,12 @@ acpi_ex_resolve_node_to_value (
268 break; 269 break;
269 270
270 271
271 /* Default case is for unknown types */
272
273 default: 272 default:
274 273
275 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Node %p - Unknown object type %X\n", 274 /* Default case is for unknown types */
275
276 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
277 "Node %p - Unknown object type %X\n",
276 node, entry_type)); 278 node, entry_type));
277 279
278 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 280 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
@@ -280,7 +282,7 @@ acpi_ex_resolve_node_to_value (
280 } /* switch (entry_type) */ 282 } /* switch (entry_type) */
281 283
282 284
283 /* Put the object descriptor on the stack */ 285 /* Return the object descriptor */
284 286
285 *object_ptr = (void *) obj_desc; 287 *object_ptr = (void *) obj_desc;
286 return_ACPI_STATUS (status); 288 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
index 7be604911156..3de45672379a 100644
--- a/drivers/acpi/executer/exresolv.c
+++ b/drivers/acpi/executer/exresolv.c
@@ -54,6 +54,13 @@
54#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exresolv") 55 ACPI_MODULE_NAME ("exresolv")
56 56
57/* Local prototypes */
58
59static acpi_status
60acpi_ex_resolve_object_to_value (
61 union acpi_operand_object **stack_ptr,
62 struct acpi_walk_state *walk_state);
63
57 64
58/******************************************************************************* 65/*******************************************************************************
59 * 66 *
@@ -96,6 +103,11 @@ acpi_ex_resolve_to_value (
96 if (ACPI_FAILURE (status)) { 103 if (ACPI_FAILURE (status)) {
97 return_ACPI_STATUS (status); 104 return_ACPI_STATUS (status);
98 } 105 }
106
107 if (!*stack_ptr) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null pointer\n"));
109 return_ACPI_STATUS (AE_AML_NO_OPERAND);
110 }
99 } 111 }
100 112
101 /* 113 /*
@@ -120,18 +132,17 @@ acpi_ex_resolve_to_value (
120 * 132 *
121 * FUNCTION: acpi_ex_resolve_object_to_value 133 * FUNCTION: acpi_ex_resolve_object_to_value
122 * 134 *
123 * PARAMETERS: stack_ptr - Pointer to a stack location that contains a 135 * PARAMETERS: stack_ptr - Pointer to an internal object
124 * ptr to an internal object.
125 * walk_state - Current method state 136 * walk_state - Current method state
126 * 137 *
127 * RETURN: Status 138 * RETURN: Status
128 * 139 *
129 * DESCRIPTION: Retrieve the value from an internal object. The Reference type 140 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
130 * uses the associated AML opcode to determine the value. 141 * uses the associated AML opcode to determine the value.
131 * 142 *
132 ******************************************************************************/ 143 ******************************************************************************/
133 144
134acpi_status 145static acpi_status
135acpi_ex_resolve_object_to_value ( 146acpi_ex_resolve_object_to_value (
136 union acpi_operand_object **stack_ptr, 147 union acpi_operand_object **stack_ptr,
137 struct acpi_walk_state *walk_state) 148 struct acpi_walk_state *walk_state)
@@ -159,7 +170,7 @@ acpi_ex_resolve_object_to_value (
159 case AML_NAME_OP: 170 case AML_NAME_OP:
160 171
161 /* 172 /*
162 * Convert indirect name ptr to a direct name ptr. 173 * Convert name reference to a namespace node
163 * Then, acpi_ex_resolve_node_to_value can be used to get the value 174 * Then, acpi_ex_resolve_node_to_value can be used to get the value
164 */ 175 */
165 temp_node = stack_desc->reference.object; 176 temp_node = stack_desc->reference.object;
@@ -168,7 +179,7 @@ acpi_ex_resolve_object_to_value (
168 179
169 acpi_ut_remove_reference (stack_desc); 180 acpi_ut_remove_reference (stack_desc);
170 181
171 /* Put direct name pointer onto stack and exit */ 182 /* Return the namespace node */
172 183
173 (*stack_ptr) = temp_node; 184 (*stack_ptr) = temp_node;
174 break; 185 break;
@@ -255,10 +266,19 @@ acpi_ex_resolve_object_to_value (
255 266
256 break; 267 break;
257 268
269 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
270
271 /* Get the object pointed to by the namespace node */
272
273 *stack_ptr = (stack_desc->reference.node)->object;
274 acpi_ut_add_reference (*stack_ptr);
275 acpi_ut_remove_reference (stack_desc);
276 break;
258 277
259 default: 278 default:
260 279
261 ACPI_REPORT_ERROR (("During resolve, Unknown Reference opcode %X (%s) in %p\n", 280 ACPI_REPORT_ERROR ((
281 "During resolve, Unknown Reference opcode %X (%s) in %p\n",
262 opcode, acpi_ps_get_opcode_name (opcode), stack_desc)); 282 opcode, acpi_ps_get_opcode_name (opcode), stack_desc));
263 status = AE_AML_INTERNAL; 283 status = AE_AML_INTERNAL;
264 break; 284 break;
@@ -278,9 +298,8 @@ acpi_ex_resolve_object_to_value (
278 break; 298 break;
279 299
280 300
281 /* 301 /* These cases may never happen here, but just in case.. */
282 * These cases may never happen here, but just in case.. 302
283 */
284 case ACPI_TYPE_BUFFER_FIELD: 303 case ACPI_TYPE_BUFFER_FIELD:
285 case ACPI_TYPE_LOCAL_REGION_FIELD: 304 case ACPI_TYPE_LOCAL_REGION_FIELD:
286 case ACPI_TYPE_LOCAL_BANK_FIELD: 305 case ACPI_TYPE_LOCAL_BANK_FIELD:
@@ -333,9 +352,8 @@ acpi_ex_resolve_multiple (
333 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple"); 352 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
334 353
335 354
336 /* 355 /* Operand can be either a namespace node or an operand descriptor */
337 * Operand can be either a namespace node or an operand descriptor 356
338 */
339 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) { 357 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
340 case ACPI_DESC_TYPE_OPERAND: 358 case ACPI_DESC_TYPE_OPERAND:
341 type = obj_desc->common.type; 359 type = obj_desc->common.type;
@@ -357,10 +375,8 @@ acpi_ex_resolve_multiple (
357 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 375 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
358 } 376 }
359 377
378 /* If type is anything other than a reference, we are done */
360 379
361 /*
362 * If type is anything other than a reference, we are done
363 */
364 if (type != ACPI_TYPE_LOCAL_REFERENCE) { 380 if (type != ACPI_TYPE_LOCAL_REFERENCE) {
365 goto exit; 381 goto exit;
366 } 382 }
@@ -382,8 +398,9 @@ acpi_ex_resolve_multiple (
382 /* All "References" point to a NS node */ 398 /* All "References" point to a NS node */
383 399
384 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) { 400 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
385 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n", 401 ACPI_REPORT_ERROR ((
386 node, acpi_ut_get_descriptor_name (node))); 402 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
403 node, acpi_ut_get_descriptor_name (node)));
387 return_ACPI_STATUS (AE_AML_INTERNAL); 404 return_ACPI_STATUS (AE_AML_INTERNAL);
388 } 405 }
389 406
@@ -440,8 +457,9 @@ acpi_ex_resolve_multiple (
440 /* All "References" point to a NS node */ 457 /* All "References" point to a NS node */
441 458
442 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) { 459 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
443 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n", 460 ACPI_REPORT_ERROR ((
444 node, acpi_ut_get_descriptor_name (node))); 461 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
462 node, acpi_ut_get_descriptor_name (node)));
445 return_ACPI_STATUS (AE_AML_INTERNAL); 463 return_ACPI_STATUS (AE_AML_INTERNAL);
446 } 464 }
447 465
@@ -468,7 +486,7 @@ acpi_ex_resolve_multiple (
468 486
469 if (return_desc) { 487 if (return_desc) {
470 status = acpi_ds_method_data_get_value (obj_desc->reference.opcode, 488 status = acpi_ds_method_data_get_value (obj_desc->reference.opcode,
471 obj_desc->reference.offset, walk_state, &obj_desc); 489 obj_desc->reference.offset, walk_state, &obj_desc);
472 if (ACPI_FAILURE (status)) { 490 if (ACPI_FAILURE (status)) {
473 return_ACPI_STATUS (status); 491 return_ACPI_STATUS (status);
474 } 492 }
@@ -500,7 +518,8 @@ acpi_ex_resolve_multiple (
500 518
501 default: 519 default:
502 520
503 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Unknown Reference subtype %X\n", 521 ACPI_REPORT_ERROR ((
522 "acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
504 obj_desc->reference.opcode)); 523 obj_desc->reference.opcode));
505 return_ACPI_STATUS (AE_AML_INTERNAL); 524 return_ACPI_STATUS (AE_AML_INTERNAL);
506 } 525 }
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index c92890220c32..d8b470eefe7a 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -52,6 +52,14 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop") 53 ACPI_MODULE_NAME ("exresop")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ex_check_object_type (
59 acpi_object_type type_needed,
60 acpi_object_type this_type,
61 void *object);
62
55 63
56/******************************************************************************* 64/*******************************************************************************
57 * 65 *
@@ -67,7 +75,7 @@
67 * 75 *
68 ******************************************************************************/ 76 ******************************************************************************/
69 77
70acpi_status 78static acpi_status
71acpi_ex_check_object_type ( 79acpi_ex_check_object_type (
72 acpi_object_type type_needed, 80 acpi_object_type type_needed,
73 acpi_object_type this_type, 81 acpi_object_type this_type,
@@ -142,6 +150,7 @@ acpi_ex_resolve_operands (
142 const struct acpi_opcode_info *op_info; 150 const struct acpi_opcode_info *op_info;
143 u32 this_arg_type; 151 u32 this_arg_type;
144 acpi_object_type type_needed; 152 acpi_object_type type_needed;
153 u16 target_op = 0;
145 154
146 155
147 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode); 156 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
@@ -160,7 +169,8 @@ acpi_ex_resolve_operands (
160 return_ACPI_STATUS (AE_AML_INTERNAL); 169 return_ACPI_STATUS (AE_AML_INTERNAL);
161 } 170 }
162 171
163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] required_operand_types=%8.8X \n", 172 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
173 "Opcode %X [%s] required_operand_types=%8.8X \n",
164 opcode, op_info->name, arg_types)); 174 opcode, op_info->name, arg_types));
165 175
166 /* 176 /*
@@ -187,7 +197,7 @@ acpi_ex_resolve_operands (
187 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) { 197 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
188 case ACPI_DESC_TYPE_NAMED: 198 case ACPI_DESC_TYPE_NAMED:
189 199
190 /* Node */ 200 /* Namespace Node */
191 201
192 object_type = ((struct acpi_namespace_node *) obj_desc)->type; 202 object_type = ((struct acpi_namespace_node *) obj_desc)->type;
193 break; 203 break;
@@ -202,16 +212,16 @@ acpi_ex_resolve_operands (
202 /* Check for bad acpi_object_type */ 212 /* Check for bad acpi_object_type */
203 213
204 if (!acpi_ut_valid_object_type (object_type)) { 214 if (!acpi_ut_valid_object_type (object_type)) {
205 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n", 215 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
216 "Bad operand object type [%X]\n",
206 object_type)); 217 object_type));
207 218
208 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 219 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
209 } 220 }
210 221
211 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) { 222 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
212 /* 223 /* Decode the Reference */
213 * Decode the Reference 224
214 */
215 op_info = acpi_ps_get_opcode_info (opcode); 225 op_info = acpi_ps_get_opcode_info (opcode);
216 if (op_info->class == AML_CLASS_UNKNOWN) { 226 if (op_info->class == AML_CLASS_UNKNOWN) {
217 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 227 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
@@ -219,12 +229,17 @@ acpi_ex_resolve_operands (
219 229
220 switch (obj_desc->reference.opcode) { 230 switch (obj_desc->reference.opcode) {
221 case AML_DEBUG_OP: 231 case AML_DEBUG_OP:
232 target_op = AML_DEBUG_OP;
233
234 /*lint -fallthrough */
235
222 case AML_NAME_OP: 236 case AML_NAME_OP:
223 case AML_INDEX_OP: 237 case AML_INDEX_OP:
224 case AML_REF_OF_OP: 238 case AML_REF_OF_OP:
225 case AML_ARG_OP: 239 case AML_ARG_OP:
226 case AML_LOCAL_OP: 240 case AML_LOCAL_OP:
227 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */ 241 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
242 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
228 243
229 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 244 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "Operand is a Reference, ref_opcode [%s]\n", 245 "Operand is a Reference, ref_opcode [%s]\n",
@@ -254,10 +269,8 @@ acpi_ex_resolve_operands (
254 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 269 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
255 } 270 }
256 271
272 /* Get one argument type, point to the next */
257 273
258 /*
259 * Get one argument type, point to the next
260 */
261 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types); 274 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types);
262 INCREMENT_ARG_LIST (arg_types); 275 INCREMENT_ARG_LIST (arg_types);
263 276
@@ -271,26 +284,31 @@ acpi_ex_resolve_operands (
271 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) && 284 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) &&
272 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) { 285 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) {
273 /* 286 /*
274 * String found - the string references a named object and must be 287 * String found - the string references a named object and
275 * resolved to a node 288 * must be resolved to a node
276 */ 289 */
277 goto next_operand; 290 goto next_operand;
278 } 291 }
279 292
280 /* Else not a string - fall through to the normal Reference case below */ 293 /*
294 * Else not a string - fall through to the normal Reference
295 * case below
296 */
281 /*lint -fallthrough */ 297 /*lint -fallthrough */
282 298
283 case ARGI_REFERENCE: /* References: */ 299 case ARGI_REFERENCE: /* References: */
284 case ARGI_INTEGER_REF: 300 case ARGI_INTEGER_REF:
285 case ARGI_OBJECT_REF: 301 case ARGI_OBJECT_REF:
286 case ARGI_DEVICE_REF: 302 case ARGI_DEVICE_REF:
287 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */ 303 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
288 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */ 304 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
289 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */ 305 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
290
291 /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
292 306
293 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */ { 307 /*
308 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
309 * A Namespace Node is OK as-is
310 */
311 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) {
294 goto next_operand; 312 goto next_operand;
295 } 313 }
296 314
@@ -300,11 +318,9 @@ acpi_ex_resolve_operands (
300 return_ACPI_STATUS (status); 318 return_ACPI_STATUS (status);
301 } 319 }
302 320
303 if (AML_NAME_OP == obj_desc->reference.opcode) { 321 if (obj_desc->reference.opcode == AML_NAME_OP) {
304 /* 322 /* Convert a named reference to the actual named object */
305 * Convert an indirect name ptr to direct name ptr and put 323
306 * it on the stack
307 */
308 temp_node = obj_desc->reference.object; 324 temp_node = obj_desc->reference.object;
309 acpi_ut_remove_reference (obj_desc); 325 acpi_ut_remove_reference (obj_desc);
310 (*stack_ptr) = temp_node; 326 (*stack_ptr) = temp_node;
@@ -332,7 +348,6 @@ acpi_ex_resolve_operands (
332 break; 348 break;
333 } 349 }
334 350
335
336 /* 351 /*
337 * Resolve this object to a value 352 * Resolve this object to a value
338 */ 353 */
@@ -392,7 +407,7 @@ acpi_ex_resolve_operands (
392 /* 407 /*
393 * The more complex cases allow multiple resolved object types 408 * The more complex cases allow multiple resolved object types
394 */ 409 */
395 case ARGI_INTEGER: /* Number */ 410 case ARGI_INTEGER:
396 411
397 /* 412 /*
398 * Need an operand of type ACPI_TYPE_INTEGER, 413 * Need an operand of type ACPI_TYPE_INTEGER,
@@ -563,7 +578,7 @@ acpi_ex_resolve_operands (
563 578
564 case ARGI_REGION_OR_FIELD: 579 case ARGI_REGION_OR_FIELD:
565 580
566 /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */ 581 /* Need an operand of type REGION or a FIELD in a region */
567 582
568 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 583 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
569 case ACPI_TYPE_REGION: 584 case ACPI_TYPE_REGION:
@@ -614,6 +629,12 @@ acpi_ex_resolve_operands (
614 break; 629 break;
615 } 630 }
616 631
632 if (target_op == AML_DEBUG_OP) {
633 /* Allow store of any object to the Debug object */
634
635 break;
636 }
637
617 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 638 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
618 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n", 639 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
619 acpi_ut_get_object_type_name (obj_desc), obj_desc)); 640 acpi_ut_get_object_type_name (obj_desc), obj_desc));
@@ -652,8 +673,7 @@ next_operand:
652 if (GET_CURRENT_ARG_TYPE (arg_types)) { 673 if (GET_CURRENT_ARG_TYPE (arg_types)) {
653 stack_ptr--; 674 stack_ptr--;
654 } 675 }
655 676 }
656 } /* while (*Types) */
657 677
658 return_ACPI_STATUS (status); 678 return_ACPI_STATUS (status);
659} 679}
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
index e0fc6aba1253..2725db0901b8 100644
--- a/drivers/acpi/executer/exstore.c
+++ b/drivers/acpi/executer/exstore.c
@@ -48,11 +48,171 @@
48#include <acpi/acinterp.h> 48#include <acpi/acinterp.h>
49#include <acpi/amlcode.h> 49#include <acpi/amlcode.h>
50#include <acpi/acnamesp.h> 50#include <acpi/acnamesp.h>
51#include <acpi/acparser.h>
51 52
52 53
53#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exstore") 55 ACPI_MODULE_NAME ("exstore")
55 56
57/* Local prototypes */
58
59static void
60acpi_ex_do_debug_object (
61 union acpi_operand_object *source_desc,
62 u32 level,
63 u32 index);
64
65static acpi_status
66acpi_ex_store_object_to_index (
67 union acpi_operand_object *val_desc,
68 union acpi_operand_object *dest_desc,
69 struct acpi_walk_state *walk_state);
70
71
72/*******************************************************************************
73 *
74 * FUNCTION: acpi_ex_do_debug_object
75 *
76 * PARAMETERS: source_desc - Value to be stored
77 * Level - Indentation level (used for packages)
78 * Index - Current package element, zero if not pkg
79 *
80 * RETURN: None
81 *
82 * DESCRIPTION: Handles stores to the Debug Object.
83 *
84 ******************************************************************************/
85
86static void
87acpi_ex_do_debug_object (
88 union acpi_operand_object *source_desc,
89 u32 level,
90 u32 index)
91{
92 u32 i;
93
94
95 ACPI_FUNCTION_TRACE_PTR ("ex_do_debug_object", source_desc);
96
97
98 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
99 level, " "));
100
101 /* Display index for package output only */
102
103 if (index > 0) {
104 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
105 "(%.2u) ", index -1));
106 }
107
108 if (!source_desc) {
109 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
110 return_VOID;
111 }
112
113 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc) == ACPI_DESC_TYPE_OPERAND) {
114 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: ",
115 acpi_ut_get_object_type_name (source_desc)));
116
117 if (!acpi_ut_valid_internal_object (source_desc)) {
118 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
119 "%p, Invalid Internal Object!\n", source_desc));
120 return_VOID;
121 }
122 }
123 else if (ACPI_GET_DESCRIPTOR_TYPE (source_desc) == ACPI_DESC_TYPE_NAMED) {
124 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
125 acpi_ut_get_type_name (((struct acpi_namespace_node *) source_desc)->type),
126 source_desc));
127 return_VOID;
128 }
129 else {
130 return_VOID;
131 }
132
133 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
134 case ACPI_TYPE_INTEGER:
135
136 /* Output correct integer width */
137
138 if (acpi_gbl_integer_byte_width == 4) {
139 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
140 (u32) source_desc->integer.value));
141 }
142 else {
143 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
144 ACPI_FORMAT_UINT64 (source_desc->integer.value)));
145 }
146 break;
147
148 case ACPI_TYPE_BUFFER:
149
150 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
151 (u32) source_desc->buffer.length));
152 ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
153 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
154 break;
155
156 case ACPI_TYPE_STRING:
157
158 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
159 source_desc->string.length, source_desc->string.pointer));
160 break;
161
162 case ACPI_TYPE_PACKAGE:
163
164 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X Elements]\n",
165 source_desc->package.count));
166
167 /* Output the entire contents of the package */
168
169 for (i = 0; i < source_desc->package.count; i++) {
170 acpi_ex_do_debug_object (source_desc->package.elements[i],
171 level+4, i+1);
172 }
173 break;
174
175 case ACPI_TYPE_LOCAL_REFERENCE:
176
177 if (source_desc->reference.opcode == AML_INDEX_OP) {
178 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s, 0x%X]\n",
179 acpi_ps_get_opcode_name (source_desc->reference.opcode),
180 source_desc->reference.offset));
181 }
182 else {
183 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
184 acpi_ps_get_opcode_name (source_desc->reference.opcode)));
185 }
186
187
188 if (source_desc->reference.object) {
189 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc->reference.object) ==
190 ACPI_DESC_TYPE_NAMED) {
191 acpi_ex_do_debug_object (((struct acpi_namespace_node *)
192 source_desc->reference.object)->object,
193 level+4, 0);
194 }
195 else {
196 acpi_ex_do_debug_object (source_desc->reference.object, level+4, 0);
197 }
198 }
199 else if (source_desc->reference.node) {
200 acpi_ex_do_debug_object ((source_desc->reference.node)->object,
201 level+4, 0);
202 }
203 break;
204
205 default:
206
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
208 source_desc, acpi_ut_get_object_type_name (source_desc)));
209 break;
210 }
211
212 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
213 return_VOID;
214}
215
56 216
57/******************************************************************************* 217/*******************************************************************************
58 * 218 *
@@ -154,8 +314,9 @@ acpi_ex_store (
154 314
155 /* Storing an object into a Name "container" */ 315 /* Storing an object into a Name "container" */
156 316
157 status = acpi_ex_store_object_to_node (source_desc, ref_desc->reference.object, 317 status = acpi_ex_store_object_to_node (source_desc,
158 walk_state, ACPI_IMPLICIT_CONVERSION); 318 ref_desc->reference.object,
319 walk_state, ACPI_IMPLICIT_CONVERSION);
159 break; 320 break;
160 321
161 322
@@ -173,7 +334,7 @@ acpi_ex_store (
173 /* Store to a method local/arg */ 334 /* Store to a method local/arg */
174 335
175 status = acpi_ds_store_object_to_local (ref_desc->reference.opcode, 336 status = acpi_ds_store_object_to_local (ref_desc->reference.opcode,
176 ref_desc->reference.offset, source_desc, walk_state); 337 ref_desc->reference.offset, source_desc, walk_state);
177 break; 338 break;
178 339
179 340
@@ -187,60 +348,7 @@ acpi_ex_store (
187 "**** Write to Debug Object: Object %p %s ****:\n\n", 348 "**** Write to Debug Object: Object %p %s ****:\n\n",
188 source_desc, acpi_ut_get_object_type_name (source_desc))); 349 source_desc, acpi_ut_get_object_type_name (source_desc)));
189 350
190 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ", 351 acpi_ex_do_debug_object (source_desc, 0, 0);
191 acpi_ut_get_object_type_name (source_desc)));
192
193 if (!acpi_ut_valid_internal_object (source_desc)) {
194 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
195 "%p, Invalid Internal Object!\n", source_desc));
196 break;
197 }
198
199 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
200 case ACPI_TYPE_INTEGER:
201
202 if (acpi_gbl_integer_byte_width == 4) {
203 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
204 (u32) source_desc->integer.value));
205 }
206 else {
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
208 ACPI_FORMAT_UINT64 (source_desc->integer.value)));
209 }
210 break;
211
212
213 case ACPI_TYPE_BUFFER:
214
215 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
216 (u32) source_desc->buffer.length));
217 ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
218 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
219 break;
220
221
222 case ACPI_TYPE_STRING:
223
224 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
225 source_desc->string.length, source_desc->string.pointer));
226 break;
227
228
229 case ACPI_TYPE_PACKAGE:
230
231 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] Elements Ptr - %p\n",
232 source_desc->package.count, source_desc->package.elements));
233 break;
234
235
236 default:
237
238 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n",
239 source_desc));
240 break;
241 }
242
243 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
244 break; 352 break;
245 353
246 354
@@ -272,7 +380,7 @@ acpi_ex_store (
272 * 380 *
273 ******************************************************************************/ 381 ******************************************************************************/
274 382
275acpi_status 383static acpi_status
276acpi_ex_store_object_to_index ( 384acpi_ex_store_object_to_index (
277 union acpi_operand_object *source_desc, 385 union acpi_operand_object *source_desc,
278 union acpi_operand_object *index_desc, 386 union acpi_operand_object *index_desc,
@@ -313,16 +421,22 @@ acpi_ex_store_object_to_index (
313 if (obj_desc) { 421 if (obj_desc) {
314 /* Decrement reference count by the ref count of the parent package */ 422 /* Decrement reference count by the ref count of the parent package */
315 423
316 for (i = 0; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) { 424 for (i = 0;
425 i < ((union acpi_operand_object *)
426 index_desc->reference.object)->common.reference_count;
427 i++) {
317 acpi_ut_remove_reference (obj_desc); 428 acpi_ut_remove_reference (obj_desc);
318 } 429 }
319 } 430 }
320 431
321 *(index_desc->reference.where) = new_desc; 432 *(index_desc->reference.where) = new_desc;
322 433
323 /* Increment reference count by the ref count of the parent package -1 */ 434 /* Increment ref count by the ref count of the parent package-1 */
324 435
325 for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) { 436 for (i = 1;
437 i < ((union acpi_operand_object *)
438 index_desc->reference.object)->common.reference_count;
439 i++) {
326 acpi_ut_add_reference (new_desc); 440 acpi_ut_add_reference (new_desc);
327 } 441 }
328 442
@@ -440,9 +554,8 @@ acpi_ex_store_object_to_node (
440 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc); 554 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
441 555
442 556
443 /* 557 /* Get current type of the node, and object attached to Node */
444 * Get current type of the node, and object attached to Node 558
445 */
446 target_type = acpi_ns_get_type (node); 559 target_type = acpi_ns_get_type (node);
447 target_desc = acpi_ns_get_attached_object (node); 560 target_desc = acpi_ns_get_attached_object (node);
448 561
@@ -467,19 +580,18 @@ acpi_ex_store_object_to_node (
467 target_type = ACPI_TYPE_ANY; 580 target_type = ACPI_TYPE_ANY;
468 } 581 }
469 582
470 /* 583 /* Do the actual store operation */
471 * Do the actual store operation 584
472 */
473 switch (target_type) { 585 switch (target_type) {
474 case ACPI_TYPE_BUFFER_FIELD: 586 case ACPI_TYPE_BUFFER_FIELD:
475 case ACPI_TYPE_LOCAL_REGION_FIELD: 587 case ACPI_TYPE_LOCAL_REGION_FIELD:
476 case ACPI_TYPE_LOCAL_BANK_FIELD: 588 case ACPI_TYPE_LOCAL_BANK_FIELD:
477 case ACPI_TYPE_LOCAL_INDEX_FIELD: 589 case ACPI_TYPE_LOCAL_INDEX_FIELD:
478 590
479 /* 591 /* For fields, copy the source data to the target field. */
480 * For fields, copy the source data to the target field. 592
481 */ 593 status = acpi_ex_write_data_to_field (source_desc, target_desc,
482 status = acpi_ex_write_data_to_field (source_desc, target_desc, &walk_state->result_obj); 594 &walk_state->result_obj);
483 break; 595 break;
484 596
485 597
@@ -493,7 +605,8 @@ acpi_ex_store_object_to_node (
493 * 605 *
494 * Copy and/or convert the source object to a new target object 606 * Copy and/or convert the source object to a new target object
495 */ 607 */
496 status = acpi_ex_store_object_to_object (source_desc, target_desc, &new_desc, walk_state); 608 status = acpi_ex_store_object_to_object (source_desc, target_desc,
609 &new_desc, walk_state);
497 if (ACPI_FAILURE (status)) { 610 if (ACPI_FAILURE (status)) {
498 return_ACPI_STATUS (status); 611 return_ACPI_STATUS (status);
499 } 612 }
@@ -526,7 +639,8 @@ acpi_ex_store_object_to_node (
526 639
527 /* No conversions for all other types. Just attach the source object */ 640 /* No conversions for all other types. Just attach the source object */
528 641
529 status = acpi_ns_attach_object (node, source_desc, ACPI_GET_OBJECT_TYPE (source_desc)); 642 status = acpi_ns_attach_object (node, source_desc,
643 ACPI_GET_OBJECT_TYPE (source_desc));
530 break; 644 break;
531 } 645 }
532 646
diff --git a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
index d3677feb07fd..120f30ed0bd4 100644
--- a/drivers/acpi/executer/exstoren.c
+++ b/drivers/acpi/executer/exstoren.c
@@ -81,9 +81,8 @@ acpi_ex_resolve_object (
81 ACPI_FUNCTION_TRACE ("ex_resolve_object"); 81 ACPI_FUNCTION_TRACE ("ex_resolve_object");
82 82
83 83
84 /* 84 /* Ensure we have a Target that can be stored to */
85 * Ensure we have a Target that can be stored to 85
86 */
87 switch (target_type) { 86 switch (target_type) {
88 case ACPI_TYPE_BUFFER_FIELD: 87 case ACPI_TYPE_BUFFER_FIELD:
89 case ACPI_TYPE_LOCAL_REGION_FIELD: 88 case ACPI_TYPE_LOCAL_REGION_FIELD:
@@ -118,16 +117,14 @@ acpi_ex_resolve_object (
118 break; 117 break;
119 } 118 }
120 119
121 /* 120 /* Must have a Integer, Buffer, or String */
122 * Must have a Integer, Buffer, or String 121
123 */
124 if ((ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) && 122 if ((ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) &&
125 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) && 123 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) &&
126 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) && 124 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) &&
127 !((ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.opcode == AML_LOAD_OP))) { 125 !((ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.opcode == AML_LOAD_OP))) {
128 /* 126 /* Conversion successful but still not a valid type */
129 * Conversion successful but still not a valid type 127
130 */
131 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 128 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
132 "Cannot assign type %s to %s (must be type Int/Str/Buf)\n", 129 "Cannot assign type %s to %s (must be type Int/Str/Buf)\n",
133 acpi_ut_get_object_type_name (source_desc), 130 acpi_ut_get_object_type_name (source_desc),
@@ -140,9 +137,8 @@ acpi_ex_resolve_object (
140 case ACPI_TYPE_LOCAL_ALIAS: 137 case ACPI_TYPE_LOCAL_ALIAS:
141 case ACPI_TYPE_LOCAL_METHOD_ALIAS: 138 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
142 139
143 /* 140 /* Aliases are resolved by acpi_ex_prep_operands */
144 * Aliases are resolved by acpi_ex_prep_operands 141
145 */
146 ACPI_REPORT_ERROR (("Store into Alias - should never happen\n")); 142 ACPI_REPORT_ERROR (("Store into Alias - should never happen\n"));
147 status = AE_AML_INTERNAL; 143 status = AE_AML_INTERNAL;
148 break; 144 break;
diff --git a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
index 05e1ecae8d92..12d1527669c8 100644
--- a/drivers/acpi/executer/exstorob.c
+++ b/drivers/acpi/executer/exstorob.c
@@ -128,7 +128,8 @@ acpi_ex_store_buffer_to_buffer (
128 else { 128 else {
129 /* Truncate the source, copy only what will fit */ 129 /* Truncate the source, copy only what will fit */
130 130
131 ACPI_MEMCPY (target_desc->buffer.pointer, buffer, target_desc->buffer.length); 131 ACPI_MEMCPY (target_desc->buffer.pointer, buffer,
132 target_desc->buffer.length);
132 133
133 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 134 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
134 "Truncating source buffer from %X to %X\n", 135 "Truncating source buffer from %X to %X\n",
@@ -183,7 +184,8 @@ acpi_ex_store_string_to_string (
183 * String will fit in existing non-static buffer. 184 * String will fit in existing non-static buffer.
184 * Clear old string and copy in the new one 185 * Clear old string and copy in the new one
185 */ 186 */
186 ACPI_MEMSET (target_desc->string.pointer, 0, (acpi_size) target_desc->string.length + 1); 187 ACPI_MEMSET (target_desc->string.pointer, 0,
188 (acpi_size) target_desc->string.length + 1);
187 ACPI_MEMCPY (target_desc->string.pointer, buffer, length); 189 ACPI_MEMCPY (target_desc->string.pointer, buffer, length);
188 } 190 }
189 else { 191 else {
@@ -198,7 +200,8 @@ acpi_ex_store_string_to_string (
198 ACPI_MEM_FREE (target_desc->string.pointer); 200 ACPI_MEM_FREE (target_desc->string.pointer);
199 } 201 }
200 202
201 target_desc->string.pointer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1); 203 target_desc->string.pointer = ACPI_MEM_CALLOCATE (
204 (acpi_size) length + 1);
202 if (!target_desc->string.pointer) { 205 if (!target_desc->string.pointer) {
203 return_ACPI_STATUS (AE_NO_MEMORY); 206 return_ACPI_STATUS (AE_NO_MEMORY);
204 } 207 }
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index f92efc512890..cafa702108dc 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -55,8 +55,8 @@
55 * 55 *
56 * FUNCTION: acpi_ex_system_wait_semaphore 56 * FUNCTION: acpi_ex_system_wait_semaphore
57 * 57 *
58 * PARAMETERS: Semaphore - OSD semaphore to wait on 58 * PARAMETERS: Semaphore - Semaphore to wait on
59 * Timeout - Max time to wait 59 * Timeout - Max time to wait
60 * 60 *
61 * RETURN: Status 61 * RETURN: Status
62 * 62 *
@@ -90,7 +90,8 @@ acpi_ex_system_wait_semaphore (
90 90
91 status = acpi_os_wait_semaphore (semaphore, 1, timeout); 91 status = acpi_os_wait_semaphore (semaphore, 1, timeout);
92 92
93 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*** Thread awake after blocking, %s\n", 93 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
94 "*** Thread awake after blocking, %s\n",
94 acpi_format_exception (status))); 95 acpi_format_exception (status)));
95 96
96 /* Reacquire the interpreter */ 97 /* Reacquire the interpreter */
@@ -111,8 +112,8 @@ acpi_ex_system_wait_semaphore (
111 * 112 *
112 * FUNCTION: acpi_ex_system_do_stall 113 * FUNCTION: acpi_ex_system_do_stall
113 * 114 *
114 * PARAMETERS: how_long - The amount of time to stall, 115 * PARAMETERS: how_long - The amount of time to stall,
115 * in microseconds 116 * in microseconds
116 * 117 *
117 * RETURN: Status 118 * RETURN: Status
118 * 119 *
@@ -141,7 +142,8 @@ acpi_ex_system_do_stall (
141 * (ACPI specifies 100 usec as max, but this gives some slack in 142 * (ACPI specifies 100 usec as max, but this gives some slack in
142 * order to support existing BIOSs) 143 * order to support existing BIOSs)
143 */ 144 */
144 ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n", how_long)); 145 ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n",
146 how_long));
145 status = AE_AML_OPERAND_VALUE; 147 status = AE_AML_OPERAND_VALUE;
146 } 148 }
147 else { 149 else {
@@ -156,8 +158,8 @@ acpi_ex_system_do_stall (
156 * 158 *
157 * FUNCTION: acpi_ex_system_do_suspend 159 * FUNCTION: acpi_ex_system_do_suspend
158 * 160 *
159 * PARAMETERS: how_long - The amount of time to suspend, 161 * PARAMETERS: how_long - The amount of time to suspend,
160 * in milliseconds 162 * in milliseconds
161 * 163 *
162 * RETURN: None 164 * RETURN: None
163 * 165 *
@@ -192,8 +194,8 @@ acpi_ex_system_do_suspend (
192 * 194 *
193 * FUNCTION: acpi_ex_system_acquire_mutex 195 * FUNCTION: acpi_ex_system_acquire_mutex
194 * 196 *
195 * PARAMETERS: *time_desc - The 'time to delay' object descriptor 197 * PARAMETERS: time_desc - The 'time to delay' object descriptor
196 * *obj_desc - The object descriptor for this op 198 * obj_desc - The object descriptor for this op
197 * 199 *
198 * RETURN: Status 200 * RETURN: Status
199 * 201 *
@@ -218,16 +220,15 @@ acpi_ex_system_acquire_mutex (
218 return_ACPI_STATUS (AE_BAD_PARAMETER); 220 return_ACPI_STATUS (AE_BAD_PARAMETER);
219 } 221 }
220 222
221 /* 223 /* Support for the _GL_ Mutex object -- go get the global lock */
222 * Support for the _GL_ Mutex object -- go get the global lock 224
223 */
224 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 225 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
225 status = acpi_ev_acquire_global_lock ((u16) time_desc->integer.value); 226 status = acpi_ev_acquire_global_lock ((u16) time_desc->integer.value);
226 return_ACPI_STATUS (status); 227 return_ACPI_STATUS (status);
227 } 228 }
228 229
229 status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore, 230 status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore,
230 (u16) time_desc->integer.value); 231 (u16) time_desc->integer.value);
231 return_ACPI_STATUS (status); 232 return_ACPI_STATUS (status);
232} 233}
233 234
@@ -236,7 +237,7 @@ acpi_ex_system_acquire_mutex (
236 * 237 *
237 * FUNCTION: acpi_ex_system_release_mutex 238 * FUNCTION: acpi_ex_system_release_mutex
238 * 239 *
239 * PARAMETERS: *obj_desc - The object descriptor for this op 240 * PARAMETERS: obj_desc - The object descriptor for this op
240 * 241 *
241 * RETURN: Status 242 * RETURN: Status
242 * 243 *
@@ -261,9 +262,8 @@ acpi_ex_system_release_mutex (
261 return_ACPI_STATUS (AE_BAD_PARAMETER); 262 return_ACPI_STATUS (AE_BAD_PARAMETER);
262 } 263 }
263 264
264 /* 265 /* Support for the _GL_ Mutex object -- release the global lock */
265 * Support for the _GL_ Mutex object -- release the global lock 266
266 */
267 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 267 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
268 status = acpi_ev_release_global_lock (); 268 status = acpi_ev_release_global_lock ();
269 return_ACPI_STATUS (status); 269 return_ACPI_STATUS (status);
@@ -278,9 +278,9 @@ acpi_ex_system_release_mutex (
278 * 278 *
279 * FUNCTION: acpi_ex_system_signal_event 279 * FUNCTION: acpi_ex_system_signal_event
280 * 280 *
281 * PARAMETERS: *obj_desc - The object descriptor for this op 281 * PARAMETERS: obj_desc - The object descriptor for this op
282 * 282 *
283 * RETURN: AE_OK 283 * RETURN: Status
284 * 284 *
285 * DESCRIPTION: Provides an access point to perform synchronization operations 285 * DESCRIPTION: Provides an access point to perform synchronization operations
286 * within the AML. 286 * within the AML.
@@ -309,8 +309,8 @@ acpi_ex_system_signal_event (
309 * 309 *
310 * FUNCTION: acpi_ex_system_wait_event 310 * FUNCTION: acpi_ex_system_wait_event
311 * 311 *
312 * PARAMETERS: *time_desc - The 'time to delay' object descriptor 312 * PARAMETERS: time_desc - The 'time to delay' object descriptor
313 * *obj_desc - The object descriptor for this op 313 * obj_desc - The object descriptor for this op
314 * 314 *
315 * RETURN: Status 315 * RETURN: Status
316 * 316 *
@@ -333,7 +333,7 @@ acpi_ex_system_wait_event (
333 333
334 if (obj_desc) { 334 if (obj_desc) {
335 status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore, 335 status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore,
336 (u16) time_desc->integer.value); 336 (u16) time_desc->integer.value);
337 } 337 }
338 338
339 return_ACPI_STATUS (status); 339 return_ACPI_STATUS (status);
@@ -344,7 +344,7 @@ acpi_ex_system_wait_event (
344 * 344 *
345 * FUNCTION: acpi_ex_system_reset_event 345 * FUNCTION: acpi_ex_system_reset_event
346 * 346 *
347 * PARAMETERS: *obj_desc - The object descriptor for this op 347 * PARAMETERS: obj_desc - The object descriptor for this op
348 * 348 *
349 * RETURN: Status 349 * RETURN: Status
350 * 350 *
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
index 40c6abb8b49a..5c7ec0c04177 100644
--- a/drivers/acpi/executer/exutils.c
+++ b/drivers/acpi/executer/exutils.c
@@ -67,22 +67,31 @@
67#define _COMPONENT ACPI_EXECUTER 67#define _COMPONENT ACPI_EXECUTER
68 ACPI_MODULE_NAME ("exutils") 68 ACPI_MODULE_NAME ("exutils")
69 69
70/* Local prototypes */
70 71
71#ifndef ACPI_NO_METHOD_EXECUTION 72static u32
73acpi_ex_digits_needed (
74 acpi_integer value,
75 u32 base);
72 76
77
78#ifndef ACPI_NO_METHOD_EXECUTION
73/******************************************************************************* 79/*******************************************************************************
74 * 80 *
75 * FUNCTION: acpi_ex_enter_interpreter 81 * FUNCTION: acpi_ex_enter_interpreter
76 * 82 *
77 * PARAMETERS: None 83 * PARAMETERS: None
78 * 84 *
85 * RETURN: Status
86 *
79 * DESCRIPTION: Enter the interpreter execution region. Failure to enter 87 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
80 * the interpreter region is a fatal system error 88 * the interpreter region is a fatal system error
81 * 89 *
82 ******************************************************************************/ 90 ******************************************************************************/
83 91
84acpi_status 92acpi_status
85acpi_ex_enter_interpreter (void) 93acpi_ex_enter_interpreter (
94 void)
86{ 95{
87 acpi_status status; 96 acpi_status status;
88 97
@@ -104,6 +113,8 @@ acpi_ex_enter_interpreter (void)
104 * 113 *
105 * PARAMETERS: None 114 * PARAMETERS: None
106 * 115 *
116 * RETURN: None
117 *
107 * DESCRIPTION: Exit the interpreter execution region 118 * DESCRIPTION: Exit the interpreter execution region
108 * 119 *
109 * Cases where the interpreter is unlocked: 120 * Cases where the interpreter is unlocked:
@@ -119,7 +130,8 @@ acpi_ex_enter_interpreter (void)
119 ******************************************************************************/ 130 ******************************************************************************/
120 131
121void 132void
122acpi_ex_exit_interpreter (void) 133acpi_ex_exit_interpreter (
134 void)
123{ 135{
124 acpi_status status; 136 acpi_status status;
125 137
@@ -212,7 +224,8 @@ acpi_ex_acquire_global_lock (
212 locked = TRUE; 224 locked = TRUE;
213 } 225 }
214 else { 226 else {
215 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not acquire Global Lock, %s\n", 227 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
228 "Could not acquire Global Lock, %s\n",
216 acpi_format_exception (status))); 229 acpi_format_exception (status)));
217 } 230 }
218 } 231 }
@@ -228,7 +241,7 @@ acpi_ex_acquire_global_lock (
228 * PARAMETERS: locked_by_me - Return value from corresponding call to 241 * PARAMETERS: locked_by_me - Return value from corresponding call to
229 * acquire_global_lock. 242 * acquire_global_lock.
230 * 243 *
231 * RETURN: Status 244 * RETURN: None
232 * 245 *
233 * DESCRIPTION: Release the global lock if it is locked. 246 * DESCRIPTION: Release the global lock if it is locked.
234 * 247 *
@@ -269,11 +282,14 @@ acpi_ex_release_global_lock (
269 * PARAMETERS: Value - Value to be represented 282 * PARAMETERS: Value - Value to be represented
270 * Base - Base of representation 283 * Base - Base of representation
271 * 284 *
272 * RETURN: the number of digits needed to represent Value in Base 285 * RETURN: The number of digits.
286 *
287 * DESCRIPTION: Calculate the number of digits needed to represent the Value
288 * in the given Base (Radix)
273 * 289 *
274 ******************************************************************************/ 290 ******************************************************************************/
275 291
276u32 292static u32
277acpi_ex_digits_needed ( 293acpi_ex_digits_needed (
278 acpi_integer value, 294 acpi_integer value,
279 u32 base) 295 u32 base)
@@ -312,6 +328,8 @@ acpi_ex_digits_needed (
312 * PARAMETERS: numeric_id - EISA ID to be converted 328 * PARAMETERS: numeric_id - EISA ID to be converted
313 * out_string - Where to put the converted string (8 bytes) 329 * out_string - Where to put the converted string (8 bytes)
314 * 330 *
331 * RETURN: None
332 *
315 * DESCRIPTION: Convert a numeric EISA ID to string representation 333 * DESCRIPTION: Convert a numeric EISA ID to string representation
316 * 334 *
317 ******************************************************************************/ 335 ******************************************************************************/
@@ -349,7 +367,10 @@ acpi_ex_eisa_id_to_string (
349 * PARAMETERS: Value - Value to be converted 367 * PARAMETERS: Value - Value to be converted
350 * out_string - Where to put the converted string (8 bytes) 368 * out_string - Where to put the converted string (8 bytes)
351 * 369 *
352 * RETURN: Convert a number to string representation 370 * RETURN: None, string
371 *
372 * DESCRIPTOIN: Convert a number to string representation. Assumes string
373 * buffer is large enough to hold the string.
353 * 374 *
354 ******************************************************************************/ 375 ******************************************************************************/
355 376
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
new file mode 100644
index 000000000000..770cfc8b17e0
--- /dev/null
+++ b/drivers/acpi/glue.c
@@ -0,0 +1,360 @@
1/*
2 * Link physical devices with ACPI devices support
3 *
4 * Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
5 * Copyright (c) 2005 Intel Corp.
6 *
7 * This file is released under the GPLv2.
8 */
9#include <linux/init.h>
10#include <linux/list.h>
11#include <linux/device.h>
12#include <linux/rwsem.h>
13#include <linux/acpi.h>
14
15#define ACPI_GLUE_DEBUG 0
16#if ACPI_GLUE_DEBUG
17#define DBG(x...) printk(PREFIX x)
18#else
19#define DBG(x...)
20#endif
21static LIST_HEAD(bus_type_list);
22static DECLARE_RWSEM(bus_type_sem);
23
24int register_acpi_bus_type(struct acpi_bus_type *type)
25{
26 if (acpi_disabled)
27 return -ENODEV;
28 if (type && type->bus && type->find_device) {
29 down_write(&bus_type_sem);
30 list_add_tail(&type->list, &bus_type_list);
31 up_write(&bus_type_sem);
32 printk(KERN_INFO PREFIX "bus type %s registered\n", type->bus->name);
33 return 0;
34 }
35 return -ENODEV;
36}
37
38EXPORT_SYMBOL(register_acpi_bus_type);
39
40int unregister_acpi_bus_type(struct acpi_bus_type *type)
41{
42 if (acpi_disabled)
43 return 0;
44 if (type) {
45 down_write(&bus_type_sem);
46 list_del_init(&type->list);
47 up_write(&bus_type_sem);
48 printk(KERN_INFO PREFIX "ACPI bus type %s unregistered\n", type->bus->name);
49 return 0;
50 }
51 return -ENODEV;
52}
53
54EXPORT_SYMBOL(unregister_acpi_bus_type);
55
56static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
57{
58 struct acpi_bus_type *tmp, *ret = NULL;
59
60 down_read(&bus_type_sem);
61 list_for_each_entry(tmp, &bus_type_list, list) {
62 if (tmp->bus == type) {
63 ret = tmp;
64 break;
65 }
66 }
67 up_read(&bus_type_sem);
68 return ret;
69}
70
71static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
72{
73 struct acpi_bus_type *tmp;
74 int ret = -ENODEV;
75
76 down_read(&bus_type_sem);
77 list_for_each_entry(tmp, &bus_type_list, list) {
78 if (tmp->find_bridge && !tmp->find_bridge(dev, handle)) {
79 ret = 0;
80 break;
81 }
82 }
83 up_read(&bus_type_sem);
84 return ret;
85}
86
87/* Get PCI root bridge's handle from its segment and bus number */
88struct acpi_find_pci_root {
89 unsigned int seg;
90 unsigned int bus;
91 acpi_handle handle;
92};
93
94static acpi_status
95do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
96{
97 int *busnr = (int *)data;
98 struct acpi_resource_address64 address;
99
100 if (resource->id != ACPI_RSTYPE_ADDRESS16 &&
101 resource->id != ACPI_RSTYPE_ADDRESS32 &&
102 resource->id != ACPI_RSTYPE_ADDRESS64)
103 return AE_OK;
104
105 acpi_resource_to_address64(resource, &address);
106 if ((address.address_length > 0) &&
107 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
108 *busnr = address.min_address_range;
109
110 return AE_OK;
111}
112
113static int get_root_bridge_busnr(acpi_handle handle)
114{
115 acpi_status status;
116 int bus, bbn;
117 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
118
119 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
120
121 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
122 (unsigned long *)&bbn);
123 if (status == AE_NOT_FOUND) {
124 /* Assume bus = 0 */
125 printk(KERN_INFO PREFIX
126 "Assume root bridge [%s] bus is 0\n",
127 (char *)buffer.pointer);
128 status = AE_OK;
129 bbn = 0;
130 }
131 if (ACPI_FAILURE(status)) {
132 bbn = -ENODEV;
133 goto exit;
134 }
135 if (bbn > 0)
136 goto exit;
137
138 /* _BBN in some systems return 0 for all root bridges */
139 bus = -1;
140 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
141 do_root_bridge_busnr_callback, &bus);
142 /* If _CRS failed, we just use _BBN */
143 if (ACPI_FAILURE(status) || (bus == -1))
144 goto exit;
145 /* We select _CRS */
146 if (bbn != bus) {
147 printk(KERN_INFO PREFIX
148 "_BBN and _CRS returns different value for %s. Select _CRS\n",
149 (char *)buffer.pointer);
150 bbn = bus;
151 }
152 exit:
153 acpi_os_free(buffer.pointer);
154 return bbn;
155}
156
157static acpi_status
158find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
159{
160 struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
161 unsigned long seg, bus;
162 acpi_status status;
163 int tmp;
164 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
165
166 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
167
168 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
169 if (status == AE_NOT_FOUND) {
170 /* Assume seg = 0 */
171 printk(KERN_INFO PREFIX
172 "Assume root bridge [%s] segment is 0\n",
173 (char *)buffer.pointer);
174 status = AE_OK;
175 seg = 0;
176 }
177 if (ACPI_FAILURE(status)) {
178 status = AE_CTRL_DEPTH;
179 goto exit;
180 }
181
182 tmp = get_root_bridge_busnr(handle);
183 if (tmp < 0) {
184 printk(KERN_ERR PREFIX
185 "Find root bridge failed for %s\n",
186 (char *)buffer.pointer);
187 status = AE_CTRL_DEPTH;
188 goto exit;
189 }
190 bus = tmp;
191
192 if (seg == find->seg && bus == find->bus)
193 find->handle = handle;
194 status = AE_OK;
195 exit:
196 acpi_os_free(buffer.pointer);
197 return status;
198}
199
200acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
201{
202 struct acpi_find_pci_root find = { seg, bus, NULL };
203
204 acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
205 return find.handle;
206}
207
208/* Get device's handler per its address under its parent */
209struct acpi_find_child {
210 acpi_handle handle;
211 acpi_integer address;
212};
213
214static acpi_status
215do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
216{
217 acpi_status status;
218 struct acpi_device_info *info;
219 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
220 struct acpi_find_child *find = (struct acpi_find_child *)context;
221
222 status = acpi_get_object_info(handle, &buffer);
223 if (ACPI_SUCCESS(status)) {
224 info = buffer.pointer;
225 if (info->address == find->address)
226 find->handle = handle;
227 acpi_os_free(buffer.pointer);
228 }
229 return AE_OK;
230}
231
232acpi_handle acpi_get_child(acpi_handle parent, acpi_integer address)
233{
234 struct acpi_find_child find = { NULL, address };
235
236 if (!parent)
237 return NULL;
238 acpi_walk_namespace(ACPI_TYPE_DEVICE, parent,
239 1, do_acpi_find_child, &find, NULL);
240 return find.handle;
241}
242
243EXPORT_SYMBOL(acpi_get_child);
244
245/* Link ACPI devices with physical devices */
246static void acpi_glue_data_handler(acpi_handle handle,
247 u32 function, void *context)
248{
249 /* we provide an empty handler */
250}
251
252/* Note: a success call will increase reference count by one */
253struct device *acpi_get_physical_device(acpi_handle handle)
254{
255 acpi_status status;
256 struct device *dev;
257
258 status = acpi_get_data(handle, acpi_glue_data_handler, (void **)&dev);
259 if (ACPI_SUCCESS(status))
260 return get_device(dev);
261 return NULL;
262}
263
264EXPORT_SYMBOL(acpi_get_physical_device);
265
266static int acpi_bind_one(struct device *dev, acpi_handle handle)
267{
268 acpi_status status;
269
270 if (dev->firmware_data) {
271 printk(KERN_WARNING PREFIX
272 "Drivers changed 'firmware_data' for %s\n", dev->bus_id);
273 return -EINVAL;
274 }
275 get_device(dev);
276 status = acpi_attach_data(handle, acpi_glue_data_handler, dev);
277 if (ACPI_FAILURE(status)) {
278 put_device(dev);
279 return -EINVAL;
280 }
281 dev->firmware_data = handle;
282
283 return 0;
284}
285
286static int acpi_unbind_one(struct device *dev)
287{
288 if (!dev->firmware_data)
289 return 0;
290 if (dev == acpi_get_physical_device(dev->firmware_data)) {
291 /* acpi_get_physical_device increase refcnt by one */
292 put_device(dev);
293 acpi_detach_data(dev->firmware_data, acpi_glue_data_handler);
294 dev->firmware_data = NULL;
295 /* acpi_bind_one increase refcnt by one */
296 put_device(dev);
297 } else {
298 printk(KERN_ERR PREFIX
299 "Oops, 'firmware_data' corrupt for %s\n", dev->bus_id);
300 }
301 return 0;
302}
303
304static int acpi_platform_notify(struct device *dev)
305{
306 struct acpi_bus_type *type;
307 acpi_handle handle;
308 int ret = -EINVAL;
309
310 if (!dev->bus || !dev->parent) {
311 /* bridge devices genernally haven't bus or parent */
312 ret = acpi_find_bridge_device(dev, &handle);
313 goto end;
314 }
315 type = acpi_get_bus_type(dev->bus);
316 if (!type) {
317 DBG("No ACPI bus support for %s\n", dev->bus_id);
318 ret = -EINVAL;
319 goto end;
320 }
321 if ((ret = type->find_device(dev, &handle)) != 0)
322 DBG("Can't get handler for %s\n", dev->bus_id);
323 end:
324 if (!ret)
325 acpi_bind_one(dev, handle);
326
327#if ACPI_GLUE_DEBUG
328 if (!ret) {
329 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
330
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 acpi_os_free(buffer.pointer);
334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336#endif
337
338 return ret;
339}
340
341static int acpi_platform_notify_remove(struct device *dev)
342{
343 acpi_unbind_one(dev);
344 return 0;
345}
346
347static int __init init_acpi_device_notify(void)
348{
349 if (acpi_disabled)
350 return 0;
351 if (platform_notify || platform_notify_remove) {
352 printk(KERN_ERR PREFIX "Can't use platform_notify\n");
353 return 0;
354 }
355 platform_notify = acpi_platform_notify;
356 platform_notify_remove = acpi_platform_notify_remove;
357 return 0;
358}
359
360arch_initcall(init_acpi_device_notify);
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
index 529e922bdc85..b51001e74eea 100644
--- a/drivers/acpi/hardware/hwacpi.c
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -58,7 +58,8 @@
58 * 58 *
59 * RETURN: Status 59 * RETURN: Status
60 * 60 *
61 * DESCRIPTION: Initialize and validate various ACPI registers 61 * DESCRIPTION: Initialize and validate the various ACPI registers defined in
62 * the FADT.
62 * 63 *
63 ******************************************************************************/ 64 ******************************************************************************/
64 65
@@ -75,7 +76,7 @@ acpi_hw_initialize (
75 /* We must have the ACPI tables by the time we get here */ 76 /* We must have the ACPI tables by the time we get here */
76 77
77 if (!acpi_gbl_FADT) { 78 if (!acpi_gbl_FADT) {
78 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "A FADT is not loaded\n")); 79 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No FADT is present\n"));
79 80
80 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 81 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
81 } 82 }
@@ -131,7 +132,8 @@ acpi_hw_set_mode (
131 * transitions are not supported. 132 * transitions are not supported.
132 */ 133 */
133 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) { 134 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
134 ACPI_REPORT_ERROR (("No ACPI mode transition supported in this system (enable/disable both zero)\n")); 135 ACPI_REPORT_ERROR ((
136 "No ACPI mode transition supported in this system (enable/disable both zero)\n"));
135 return_ACPI_STATUS (AE_OK); 137 return_ACPI_STATUS (AE_OK);
136 } 138 }
137 139
@@ -162,7 +164,8 @@ acpi_hw_set_mode (
162 } 164 }
163 165
164 if (ACPI_FAILURE (status)) { 166 if (ACPI_FAILURE (status)) {
165 ACPI_REPORT_ERROR (("Could not write mode change, %s\n", acpi_format_exception (status))); 167 ACPI_REPORT_ERROR (("Could not write mode change, %s\n",
168 acpi_format_exception (status)));
166 return_ACPI_STATUS (status); 169 return_ACPI_STATUS (status);
167 } 170 }
168 171
@@ -173,7 +176,8 @@ acpi_hw_set_mode (
173 retry = 3000; 176 retry = 3000;
174 while (retry) { 177 while (retry) {
175 if (acpi_hw_get_mode() == mode) { 178 if (acpi_hw_get_mode() == mode) {
176 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", mode)); 179 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n",
180 mode));
177 return_ACPI_STATUS (AE_OK); 181 return_ACPI_STATUS (AE_OK);
178 } 182 }
179 acpi_os_stall(1000); 183 acpi_os_stall(1000);
@@ -185,7 +189,7 @@ acpi_hw_set_mode (
185} 189}
186 190
187 191
188/****************************************************************************** 192/*******************************************************************************
189 * 193 *
190 * FUNCTION: acpi_hw_get_mode 194 * FUNCTION: acpi_hw_get_mode
191 * 195 *
@@ -199,7 +203,8 @@ acpi_hw_set_mode (
199 ******************************************************************************/ 203 ******************************************************************************/
200 204
201u32 205u32
202acpi_hw_get_mode (void) 206acpi_hw_get_mode (
207 void)
203{ 208{
204 acpi_status status; 209 acpi_status status;
205 u32 value; 210 u32 value;
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
index 9ac1d639bf51..8daeabb2fc7a 100644
--- a/drivers/acpi/hardware/hwgpe.c
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -48,6 +48,13 @@
48#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwgpe") 49 ACPI_MODULE_NAME ("hwgpe")
50 50
51/* Local prototypes */
52
53static acpi_status
54acpi_hw_enable_wakeup_gpe_block (
55 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block);
57
51 58
52/****************************************************************************** 59/******************************************************************************
53 * 60 *
@@ -135,6 +142,7 @@ acpi_hw_clear_gpe (
135 * DESCRIPTION: Return the status of a single GPE. 142 * DESCRIPTION: Return the status of a single GPE.
136 * 143 *
137 ******************************************************************************/ 144 ******************************************************************************/
145
138#ifdef ACPI_FUTURE_USAGE 146#ifdef ACPI_FUTURE_USAGE
139acpi_status 147acpi_status
140acpi_hw_get_gpe_status ( 148acpi_hw_get_gpe_status (
@@ -206,7 +214,7 @@ unlock_and_exit:
206 * 214 *
207 * RETURN: Status 215 * RETURN: Status
208 * 216 *
209 * DESCRIPTION: Disable all GPEs within a GPE block 217 * DESCRIPTION: Disable all GPEs within a single GPE block
210 * 218 *
211 ******************************************************************************/ 219 ******************************************************************************/
212 220
@@ -244,7 +252,7 @@ acpi_hw_disable_gpe_block (
244 * 252 *
245 * RETURN: Status 253 * RETURN: Status
246 * 254 *
247 * DESCRIPTION: Clear status bits for all GPEs within a GPE block 255 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
248 * 256 *
249 ******************************************************************************/ 257 ******************************************************************************/
250 258
@@ -282,8 +290,8 @@ acpi_hw_clear_gpe_block (
282 * 290 *
283 * RETURN: Status 291 * RETURN: Status
284 * 292 *
285 * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes 293 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
286 * combination wake/run GPEs.) 294 * combination wake/run GPEs.
287 * 295 *
288 ******************************************************************************/ 296 ******************************************************************************/
289 297
@@ -327,12 +335,12 @@ acpi_hw_enable_runtime_gpe_block (
327 * 335 *
328 * RETURN: Status 336 * RETURN: Status
329 * 337 *
330 * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes 338 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
331 * combination wake/run GPEs.) 339 * combination wake/run GPEs.
332 * 340 *
333 ******************************************************************************/ 341 ******************************************************************************/
334 342
335acpi_status 343static acpi_status
336acpi_hw_enable_wakeup_gpe_block ( 344acpi_hw_enable_wakeup_gpe_block (
337 struct acpi_gpe_xrupt_info *gpe_xrupt_info, 345 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
338 struct acpi_gpe_block_info *gpe_block) 346 struct acpi_gpe_block_info *gpe_block)
@@ -350,7 +358,8 @@ acpi_hw_enable_wakeup_gpe_block (
350 358
351 /* Enable all "wake" GPEs in this register */ 359 /* Enable all "wake" GPEs in this register */
352 360
353 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake, 361 status = acpi_hw_low_level_write (8,
362 gpe_block->register_info[i].enable_for_wake,
354 &gpe_block->register_info[i].enable_address); 363 &gpe_block->register_info[i].enable_address);
355 if (ACPI_FAILURE (status)) { 364 if (ACPI_FAILURE (status)) {
356 return (status); 365 return (status);
@@ -369,7 +378,7 @@ acpi_hw_enable_wakeup_gpe_block (
369 * 378 *
370 * RETURN: Status 379 * RETURN: Status
371 * 380 *
372 * DESCRIPTION: Disable and clear all GPEs 381 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
373 * 382 *
374 ******************************************************************************/ 383 ******************************************************************************/
375 384
@@ -397,7 +406,7 @@ acpi_hw_disable_all_gpes (
397 * 406 *
398 * RETURN: Status 407 * RETURN: Status
399 * 408 *
400 * DESCRIPTION: Enable all GPEs of the given type 409 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
401 * 410 *
402 ******************************************************************************/ 411 ******************************************************************************/
403 412
@@ -424,7 +433,7 @@ acpi_hw_enable_all_runtime_gpes (
424 * 433 *
425 * RETURN: Status 434 * RETURN: Status
426 * 435 *
427 * DESCRIPTION: Enable all GPEs of the given type 436 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
428 * 437 *
429 ******************************************************************************/ 438 ******************************************************************************/
430 439
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index 91af0c2ddcf7..6d9e4eb84836 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -87,8 +87,9 @@ acpi_hw_clear_acpi_status (
87 } 87 }
88 } 88 }
89 89
90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, 90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
91 ACPI_BITMASK_ALL_FIXED_STATUS); 91 ACPI_REGISTER_PM1_STATUS,
92 ACPI_BITMASK_ALL_FIXED_STATUS);
92 if (ACPI_FAILURE (status)) { 93 if (ACPI_FAILURE (status)) {
93 goto unlock_and_exit; 94 goto unlock_and_exit;
94 } 95 }
@@ -138,28 +139,30 @@ acpi_get_sleep_type_data (
138{ 139{
139 acpi_status status = AE_OK; 140 acpi_status status = AE_OK;
140 struct acpi_parameter_info info; 141 struct acpi_parameter_info info;
142 char *sleep_state_name;
141 143
142 144
143 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data"); 145 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
144 146
145 147
146 /* 148 /* Validate parameters */
147 * Validate parameters 149
148 */
149 if ((sleep_state > ACPI_S_STATES_MAX) || 150 if ((sleep_state > ACPI_S_STATES_MAX) ||
150 !sleep_type_a || !sleep_type_b) { 151 !sleep_type_a || !sleep_type_b) {
151 return_ACPI_STATUS (AE_BAD_PARAMETER); 152 return_ACPI_STATUS (AE_BAD_PARAMETER);
152 } 153 }
153 154
154 /* 155 /* Evaluate the namespace object containing the values for this state */
155 * Evaluate the namespace object containing the values for this state 156
156 */
157 info.parameters = NULL; 157 info.parameters = NULL;
158 status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_sleep_state_names[sleep_state], 158 info.return_object = NULL;
159 &info); 159 sleep_state_name = (char *) acpi_gbl_sleep_state_names[sleep_state];
160
161 status = acpi_ns_evaluate_by_name (sleep_state_name, &info);
160 if (ACPI_FAILURE (status)) { 162 if (ACPI_FAILURE (status)) {
161 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n", 163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
162 acpi_format_exception (status), acpi_gbl_sleep_state_names[sleep_state])); 164 "%s while evaluating sleep_state [%s]\n",
165 acpi_format_exception (status), sleep_state_name));
163 166
164 return_ACPI_STATUS (status); 167 return_ACPI_STATUS (status);
165 } 168 }
@@ -167,45 +170,57 @@ acpi_get_sleep_type_data (
167 /* Must have a return object */ 170 /* Must have a return object */
168 171
169 if (!info.return_object) { 172 if (!info.return_object) {
170 ACPI_REPORT_ERROR (("Missing Sleep State object\n")); 173 ACPI_REPORT_ERROR (("No Sleep State object returned from [%s]\n",
174 sleep_state_name));
171 status = AE_NOT_EXIST; 175 status = AE_NOT_EXIST;
172 } 176 }
173 177
174 /* It must be of type Package */ 178 /* It must be of type Package */
175 179
176 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) { 180 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) {
177 ACPI_REPORT_ERROR (("Sleep State object not a Package\n")); 181 ACPI_REPORT_ERROR (("Sleep State return object is not a Package\n"));
178 status = AE_AML_OPERAND_TYPE; 182 status = AE_AML_OPERAND_TYPE;
179 } 183 }
180 184
181 /* The package must have at least two elements */ 185 /*
182 186 * The package must have at least two elements. NOTE (March 2005): This
187 * goes against the current ACPI spec which defines this object as a
188 * package with one encoded DWORD element. However, existing practice
189 * by BIOS vendors seems to be to have 2 or more elements, at least
190 * one per sleep type (A/B).
191 */
183 else if (info.return_object->package.count < 2) { 192 else if (info.return_object->package.count < 2) {
184 ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n")); 193 ACPI_REPORT_ERROR ((
194 "Sleep State return package does not have at least two elements\n"));
185 status = AE_AML_NO_OPERAND; 195 status = AE_AML_NO_OPERAND;
186 } 196 }
187 197
188 /* The first two elements must both be of type Integer */ 198 /* The first two elements must both be of type Integer */
189 199
190 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0]) != ACPI_TYPE_INTEGER) || 200 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0])
191 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1]) != ACPI_TYPE_INTEGER)) { 201 != ACPI_TYPE_INTEGER) ||
192 ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n", 202 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1])
203 != ACPI_TYPE_INTEGER)) {
204 ACPI_REPORT_ERROR ((
205 "Sleep State return package elements are not both Integers (%s, %s)\n",
193 acpi_ut_get_object_type_name (info.return_object->package.elements[0]), 206 acpi_ut_get_object_type_name (info.return_object->package.elements[0]),
194 acpi_ut_get_object_type_name (info.return_object->package.elements[1]))); 207 acpi_ut_get_object_type_name (info.return_object->package.elements[1])));
195 status = AE_AML_OPERAND_TYPE; 208 status = AE_AML_OPERAND_TYPE;
196 } 209 }
197 else { 210 else {
198 /* 211 /* Valid _Sx_ package size, type, and value */
199 * Valid _Sx_ package size, type, and value 212
200 */ 213 *sleep_type_a = (u8)
201 *sleep_type_a = (u8) (info.return_object->package.elements[0])->integer.value; 214 (info.return_object->package.elements[0])->integer.value;
202 *sleep_type_b = (u8) (info.return_object->package.elements[1])->integer.value; 215 *sleep_type_b = (u8)
216 (info.return_object->package.elements[1])->integer.value;
203 } 217 }
204 218
205 if (ACPI_FAILURE (status)) { 219 if (ACPI_FAILURE (status)) {
206 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 220 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
207 "While evaluating sleep_state [%s], bad Sleep object %p type %s\n", 221 "%s While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
208 acpi_gbl_sleep_state_names[sleep_state], info.return_object, 222 acpi_format_exception (status),
223 sleep_state_name, info.return_object,
209 acpi_ut_get_object_type_name (info.return_object))); 224 acpi_ut_get_object_type_name (info.return_object)));
210 } 225 }
211 226
@@ -221,9 +236,9 @@ EXPORT_SYMBOL(acpi_get_sleep_type_data);
221 * 236 *
222 * PARAMETERS: register_id - Index of ACPI Register to access 237 * PARAMETERS: register_id - Index of ACPI Register to access
223 * 238 *
224 * RETURN: The bit mask to be used when accessing the register 239 * RETURN: The bitmask to be used when accessing the register
225 * 240 *
226 * DESCRIPTION: Map register_id into a register bit mask. 241 * DESCRIPTION: Map register_id into a register bitmask.
227 * 242 *
228 ******************************************************************************/ 243 ******************************************************************************/
229 244
@@ -359,7 +374,7 @@ acpi_set_register (
359 /* Always do a register read first so we can insert the new bits */ 374 /* Always do a register read first so we can insert the new bits */
360 375
361 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, 376 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
362 bit_reg_info->parent_register, &register_value); 377 bit_reg_info->parent_register, &register_value);
363 if (ACPI_FAILURE (status)) { 378 if (ACPI_FAILURE (status)) {
364 goto unlock_and_exit; 379 goto unlock_and_exit;
365 } 380 }
@@ -396,7 +411,7 @@ acpi_set_register (
396 bit_reg_info->access_bit_mask, value); 411 bit_reg_info->access_bit_mask, value);
397 412
398 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 413 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
399 ACPI_REGISTER_PM1_ENABLE, (u16) register_value); 414 ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
400 break; 415 break;
401 416
402 417
@@ -413,7 +428,7 @@ acpi_set_register (
413 bit_reg_info->access_bit_mask, value); 428 bit_reg_info->access_bit_mask, value);
414 429
415 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 430 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
416 ACPI_REGISTER_PM1_CONTROL, (u16) register_value); 431 ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
417 break; 432 break;
418 433
419 434
@@ -427,17 +442,19 @@ acpi_set_register (
427 442
428 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n", 443 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
429 register_value, 444 register_value,
430 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address))); 445 ACPI_FORMAT_UINT64 (
446 acpi_gbl_FADT->xpm2_cnt_blk.address)));
431 447
432 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position, 448 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
433 bit_reg_info->access_bit_mask, value); 449 bit_reg_info->access_bit_mask, value);
434 450
435 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n", 451 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
436 register_value, 452 register_value,
437 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address))); 453 ACPI_FORMAT_UINT64 (
454 acpi_gbl_FADT->xpm2_cnt_blk.address)));
438 455
439 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 456 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value)); 457 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
441 break; 458 break;
442 459
443 460
@@ -454,7 +471,9 @@ unlock_and_exit:
454 471
455 /* Normalize the value that was read */ 472 /* Normalize the value that was read */
456 473
457 ACPI_DEBUG_EXEC (register_value = ((register_value & bit_reg_info->access_bit_mask) >> bit_reg_info->bit_position)); 474 ACPI_DEBUG_EXEC (register_value =
475 ((register_value & bit_reg_info->access_bit_mask) >>
476 bit_reg_info->bit_position));
458 477
459 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n", 478 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
460 value, register_value, bit_reg_info->parent_register)); 479 value, register_value, bit_reg_info->parent_register));
@@ -469,7 +488,7 @@ EXPORT_SYMBOL(acpi_set_register);
469 * 488 *
470 * PARAMETERS: use_lock - Mutex hw access 489 * PARAMETERS: use_lock - Mutex hw access
471 * register_id - register_iD + Offset 490 * register_id - register_iD + Offset
472 * return_value - Value that was read from the register 491 * return_value - Where the register value is returned
473 * 492 *
474 * RETURN: Status and the value read. 493 * RETURN: Status and the value read.
475 * 494 *
@@ -557,7 +576,8 @@ acpi_hw_register_read (
557 break; 576 break;
558 577
559 default: 578 default:
560 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", register_id)); 579 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n",
580 register_id));
561 status = AE_BAD_PARAMETER; 581 status = AE_BAD_PARAMETER;
562 break; 582 break;
563 } 583 }
@@ -763,10 +783,11 @@ acpi_hw_low_level_read (
763 return (AE_BAD_PARAMETER); 783 return (AE_BAD_PARAMETER);
764 } 784 }
765 785
766 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", 786 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
767 *value, width, 787 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
768 ACPI_FORMAT_UINT64 (address), 788 *value, width,
769 acpi_ut_get_region_name (reg->address_space_id))); 789 ACPI_FORMAT_UINT64 (address),
790 acpi_ut_get_region_name (reg->address_space_id)));
770 791
771 return (status); 792 return (status);
772} 793}
@@ -841,10 +862,11 @@ acpi_hw_low_level_write (
841 return (AE_BAD_PARAMETER); 862 return (AE_BAD_PARAMETER);
842 } 863 }
843 864
844 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", 865 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
845 value, width, 866 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
846 ACPI_FORMAT_UINT64 (address), 867 value, width,
847 acpi_ut_get_region_name (reg->address_space_id))); 868 ACPI_FORMAT_UINT64 (address),
869 acpi_ut_get_region_name (reg->address_space_id)));
848 870
849 return (status); 871 return (status);
850} 872}
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 77b3e9a8550b..415d342aeab5 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -43,27 +43,13 @@
43 */ 43 */
44 44
45#include <linux/module.h> 45#include <linux/module.h>
46
47#include <acpi/acpi.h> 46#include <acpi/acpi.h>
48 47
49#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwsleep") 49 ACPI_MODULE_NAME ("hwsleep")
51 50
52 51
53#define METHOD_NAME__BFS "\\_BFS" 52/*******************************************************************************
54#define METHOD_NAME__GTS "\\_GTS"
55#define METHOD_NAME__PTS "\\_PTS"
56#define METHOD_NAME__SST "\\_SI._SST"
57#define METHOD_NAME__WAK "\\_WAK"
58
59#define ACPI_SST_INDICATOR_OFF 0
60#define ACPI_SST_WORKING 1
61#define ACPI_SST_WAKING 2
62#define ACPI_SST_SLEEPING 3
63#define ACPI_SST_SLEEP_CONTEXT 4
64
65
66/******************************************************************************
67 * 53 *
68 * FUNCTION: acpi_set_firmware_waking_vector 54 * FUNCTION: acpi_set_firmware_waking_vector
69 * 55 *
@@ -72,7 +58,7 @@
72 * 58 *
73 * RETURN: Status 59 * RETURN: Status
74 * 60 *
75 * DESCRIPTION: access function for d_firmware_waking_vector field in FACS 61 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
76 * 62 *
77 ******************************************************************************/ 63 ******************************************************************************/
78 64
@@ -99,19 +85,20 @@ acpi_set_firmware_waking_vector (
99} 85}
100 86
101 87
102/****************************************************************************** 88/*******************************************************************************
103 * 89 *
104 * FUNCTION: acpi_get_firmware_waking_vector 90 * FUNCTION: acpi_get_firmware_waking_vector
105 * 91 *
106 * PARAMETERS: *physical_address - Output buffer where contents of 92 * PARAMETERS: *physical_address - Where the contents of
107 * the firmware_waking_vector field of 93 * the firmware_waking_vector field of
108 * the FACS will be stored. 94 * the FACS will be returned.
109 * 95 *
110 * RETURN: Status 96 * RETURN: Status, vector
111 * 97 *
112 * DESCRIPTION: Access function for firmware_waking_vector field in FACS 98 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
113 * 99 *
114 ******************************************************************************/ 100 ******************************************************************************/
101
115#ifdef ACPI_FUTURE_USAGE 102#ifdef ACPI_FUTURE_USAGE
116acpi_status 103acpi_status
117acpi_get_firmware_waking_vector ( 104acpi_get_firmware_waking_vector (
@@ -141,7 +128,7 @@ acpi_get_firmware_waking_vector (
141#endif 128#endif
142 129
143 130
144/****************************************************************************** 131/*******************************************************************************
145 * 132 *
146 * FUNCTION: acpi_enter_sleep_state_prep 133 * FUNCTION: acpi_enter_sleep_state_prep
147 * 134 *
@@ -215,7 +202,7 @@ acpi_enter_sleep_state_prep (
215 break; 202 break;
216 203
217 default: 204 default:
218 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is indicator off */ 205 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */
219 break; 206 break;
220 } 207 }
221 208
@@ -223,14 +210,15 @@ acpi_enter_sleep_state_prep (
223 210
224 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 211 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
225 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 212 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
226 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 213 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
214 acpi_format_exception (status)));
227 } 215 }
228 216
229 return_ACPI_STATUS (AE_OK); 217 return_ACPI_STATUS (AE_OK);
230} 218}
231 219
232 220
233/****************************************************************************** 221/*******************************************************************************
234 * 222 *
235 * FUNCTION: acpi_enter_sleep_state 223 * FUNCTION: acpi_enter_sleep_state
236 * 224 *
@@ -299,15 +287,18 @@ acpi_enter_sleep_state (
299 287
300 /* Get current value of PM1A control */ 288 /* Get current value of PM1A control */
301 289
302 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); 290 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
291 ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
303 if (ACPI_FAILURE (status)) { 292 if (ACPI_FAILURE (status)) {
304 return_ACPI_STATUS (status); 293 return_ACPI_STATUS (status);
305 } 294 }
306 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%d]\n", sleep_state)); 295 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
296 "Entering sleep state [S%d]\n", sleep_state));
307 297
308 /* Clear SLP_EN and SLP_TYP fields */ 298 /* Clear SLP_EN and SLP_TYP fields */
309 299
310 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info->access_bit_mask); 300 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
301 sleep_enable_reg_info->access_bit_mask);
311 PM1Bcontrol = PM1Acontrol; 302 PM1Bcontrol = PM1Acontrol;
312 303
313 /* Insert SLP_TYP bits */ 304 /* Insert SLP_TYP bits */
@@ -322,12 +313,14 @@ acpi_enter_sleep_state (
322 313
323 /* Write #1: fill in SLP_TYP data */ 314 /* Write #1: fill in SLP_TYP data */
324 315
325 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol); 316 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
317 ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
326 if (ACPI_FAILURE (status)) { 318 if (ACPI_FAILURE (status)) {
327 return_ACPI_STATUS (status); 319 return_ACPI_STATUS (status);
328 } 320 }
329 321
330 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol); 322 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
323 ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
331 if (ACPI_FAILURE (status)) { 324 if (ACPI_FAILURE (status)) {
332 return_ACPI_STATUS (status); 325 return_ACPI_STATUS (status);
333 } 326 }
@@ -341,22 +334,25 @@ acpi_enter_sleep_state (
341 334
342 ACPI_FLUSH_CPU_CACHE (); 335 ACPI_FLUSH_CPU_CACHE ();
343 336
344 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol); 337 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
338 ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
345 if (ACPI_FAILURE (status)) { 339 if (ACPI_FAILURE (status)) {
346 return_ACPI_STATUS (status); 340 return_ACPI_STATUS (status);
347 } 341 }
348 342
349 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol); 343 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
344 ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
350 if (ACPI_FAILURE (status)) { 345 if (ACPI_FAILURE (status)) {
351 return_ACPI_STATUS (status); 346 return_ACPI_STATUS (status);
352 } 347 }
353 348
354 if (sleep_state > ACPI_STATE_S3) { 349 if (sleep_state > ACPI_STATE_S3) {
355 /* 350 /*
356 * We wanted to sleep > S3, but it didn't happen (by virtue of the fact that 351 * We wanted to sleep > S3, but it didn't happen (by virtue of the
357 * we are still executing!) 352 * fact that we are still executing!)
358 * 353 *
359 * Wait ten seconds, then try again. This is to get S4/S5 to work on all machines. 354 * Wait ten seconds, then try again. This is to get S4/S5 to work on
355 * all machines.
360 * 356 *
361 * We wait so long to allow chipsets that poll this reg very slowly to 357 * We wait so long to allow chipsets that poll this reg very slowly to
362 * still read the right value. Ideally, this block would go 358 * still read the right value. Ideally, this block would go
@@ -364,7 +360,8 @@ acpi_enter_sleep_state (
364 */ 360 */
365 acpi_os_stall (10000000); 361 acpi_os_stall (10000000);
366 362
367 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, 363 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
364 ACPI_REGISTER_PM1_CONTROL,
368 sleep_enable_reg_info->access_bit_mask); 365 sleep_enable_reg_info->access_bit_mask);
369 if (ACPI_FAILURE (status)) { 366 if (ACPI_FAILURE (status)) {
370 return_ACPI_STATUS (status); 367 return_ACPI_STATUS (status);
@@ -374,7 +371,8 @@ acpi_enter_sleep_state (
374 /* Wait until we enter sleep state */ 371 /* Wait until we enter sleep state */
375 372
376 do { 373 do {
377 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK); 374 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value,
375 ACPI_MTX_DO_NOT_LOCK);
378 if (ACPI_FAILURE (status)) { 376 if (ACPI_FAILURE (status)) {
379 return_ACPI_STATUS (status); 377 return_ACPI_STATUS (status);
380 } 378 }
@@ -388,7 +386,7 @@ acpi_enter_sleep_state (
388EXPORT_SYMBOL(acpi_enter_sleep_state); 386EXPORT_SYMBOL(acpi_enter_sleep_state);
389 387
390 388
391/****************************************************************************** 389/*******************************************************************************
392 * 390 *
393 * FUNCTION: acpi_enter_sleep_state_s4bios 391 * FUNCTION: acpi_enter_sleep_state_s4bios
394 * 392 *
@@ -439,11 +437,13 @@ acpi_enter_sleep_state_s4bios (
439 437
440 ACPI_FLUSH_CPU_CACHE (); 438 ACPI_FLUSH_CPU_CACHE ();
441 439
442 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, (u32) acpi_gbl_FADT->S4bios_req, 8); 440 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
441 (u32) acpi_gbl_FADT->S4bios_req, 8);
443 442
444 do { 443 do {
445 acpi_os_stall(1000); 444 acpi_os_stall(1000);
446 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK); 445 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value,
446 ACPI_MTX_DO_NOT_LOCK);
447 if (ACPI_FAILURE (status)) { 447 if (ACPI_FAILURE (status)) {
448 return_ACPI_STATUS (status); 448 return_ACPI_STATUS (status);
449 } 449 }
@@ -454,7 +454,7 @@ acpi_enter_sleep_state_s4bios (
454EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios); 454EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios);
455 455
456 456
457/****************************************************************************** 457/*******************************************************************************
458 * 458 *
459 * FUNCTION: acpi_leave_sleep_state 459 * FUNCTION: acpi_leave_sleep_state
460 * 460 *
@@ -534,18 +534,21 @@ acpi_leave_sleep_state (
534 arg.integer.value = ACPI_SST_WAKING; 534 arg.integer.value = ACPI_SST_WAKING;
535 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 535 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
536 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 536 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
537 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 537 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
538 acpi_format_exception (status)));
538 } 539 }
539 540
540 arg.integer.value = sleep_state; 541 arg.integer.value = sleep_state;
541 status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL); 542 status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL);
542 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 543 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
543 ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", acpi_format_exception (status))); 544 ACPI_REPORT_ERROR (("Method _BFS failed, %s\n",
545 acpi_format_exception (status)));
544 } 546 }
545 547
546 status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL); 548 status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL);
547 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 549 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
548 ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", acpi_format_exception (status))); 550 ACPI_REPORT_ERROR (("Method _WAK failed, %s\n",
551 acpi_format_exception (status)));
549 } 552 }
550 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ 553 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
551 554
@@ -567,15 +570,19 @@ acpi_leave_sleep_state (
567 570
568 /* Enable power button */ 571 /* Enable power button */
569 572
570 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id, 573 (void) acpi_set_register(
574 acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id,
571 1, ACPI_MTX_DO_NOT_LOCK); 575 1, ACPI_MTX_DO_NOT_LOCK);
572 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id, 576
577 (void) acpi_set_register(
578 acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id,
573 1, ACPI_MTX_DO_NOT_LOCK); 579 1, ACPI_MTX_DO_NOT_LOCK);
574 580
575 arg.integer.value = ACPI_SST_WORKING; 581 arg.integer.value = ACPI_SST_WORKING;
576 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 582 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
577 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 583 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
578 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 584 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
585 acpi_format_exception (status)));
579 } 586 }
580 587
581 return_ACPI_STATUS (status); 588 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
index 1906167d7294..49d7b395322e 100644
--- a/drivers/acpi/hardware/hwtimer.c
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -43,7 +43,6 @@
43 */ 43 */
44 44
45#include <linux/module.h> 45#include <linux/module.h>
46
47#include <acpi/acpi.h> 46#include <acpi/acpi.h>
48 47
49#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
@@ -90,7 +89,7 @@ acpi_get_timer_resolution (
90 * 89 *
91 * PARAMETERS: Ticks - Where the timer value is returned 90 * PARAMETERS: Ticks - Where the timer value is returned
92 * 91 *
93 * RETURN: Status and current ticks 92 * RETURN: Status and current timer value (ticks)
94 * 93 *
95 * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks). 94 * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks).
96 * 95 *
@@ -199,5 +198,6 @@ acpi_get_timer_duration (
199 *time_elapsed = (u32) quotient; 198 *time_elapsed = (u32) quotient;
200 return_ACPI_STATUS (status); 199 return_ACPI_STATUS (status);
201} 200}
201
202EXPORT_SYMBOL(acpi_get_timer_duration); 202EXPORT_SYMBOL(acpi_get_timer_duration);
203 203
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
new file mode 100644
index 000000000000..babdf762eadb
--- /dev/null
+++ b/drivers/acpi/hotkey.c
@@ -0,0 +1,1019 @@
1/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision:$)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/proc_fs.h>
29#include <linux/sched.h>
30#include <linux/kmod.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34#include <asm/uaccess.h>
35
36#define HOTKEY_ACPI_VERSION "0.1"
37
38#define HOTKEY_PROC "hotkey"
39#define HOTKEY_EV_CONFIG "event_config"
40#define HOTKEY_PL_CONFIG "poll_config"
41#define HOTKEY_ACTION "action"
42#define HOTKEY_INFO "info"
43
44#define ACPI_HOTK_NAME "Generic Hotkey Driver"
45#define ACPI_HOTK_CLASS "Hotkey"
46#define ACPI_HOTK_DEVICE_NAME "Hotkey"
47#define ACPI_HOTK_HID "Unknown?"
48#define ACPI_HOTKEY_COMPONENT 0x20000000
49
50#define ACPI_HOTKEY_EVENT 0x1
51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf
53
54#define MAX_CONFIG_RECORD_LEN 80
55#define MAX_NAME_PATH_LEN 80
56#define MAX_CALL_PARM 80
57
58#define IS_EVENT(e) 0xff /* ((e) & 0x40000000) */
59#define IS_POLL(e) 0xff /* (~((e) & 0x40000000)) */
60
61#define _COMPONENT ACPI_HOTKEY_COMPONENT
62ACPI_MODULE_NAME("acpi_hotkey")
63
64 MODULE_AUTHOR("luming.yu@intel.com");
65MODULE_DESCRIPTION(ACPI_HOTK_NAME);
66MODULE_LICENSE("GPL");
67
68/* standardized internal hotkey number/event */
69enum {
70 /* Video Extension event */
71 HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
72 HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
73 HK_EVENT_CYCLE_DISPLAY_OUTPUT,
74 HK_EVENT_NEXT_DISPLAY_OUTPUT,
75 HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
76 HK_EVENT_CYCLE_BRIGHTNESS,
77 HK_EVENT_INCREASE_BRIGHTNESS,
78 HK_EVENT_DECREASE_BRIGHTNESS,
79 HK_EVENT_ZERO_BRIGHTNESS,
80 HK_EVENT_DISPLAY_DEVICE_OFF,
81
82 /* Snd Card event */
83 HK_EVENT_VOLUME_MUTE,
84 HK_EVENT_VOLUME_INCLREASE,
85 HK_EVENT_VOLUME_DECREASE,
86
87 /* running state control */
88 HK_EVENT_ENTERRING_S3,
89 HK_EVENT_ENTERRING_S4,
90 HK_EVENT_ENTERRING_S5,
91};
92
93/* procdir we use */
94static struct proc_dir_entry *hotkey_proc_dir;
95static struct proc_dir_entry *hotkey_config;
96static struct proc_dir_entry *hotkey_poll_config;
97static struct proc_dir_entry *hotkey_action;
98static struct proc_dir_entry *hotkey_info;
99
100/* linkage for all type of hotkey */
101struct acpi_hotkey_link {
102 struct list_head entries;
103 int hotkey_type; /* event or polling based hotkey */
104 int hotkey_standard_num; /* standardized hotkey(event) number */
105};
106
107/* event based hotkey */
108struct acpi_event_hotkey {
109 struct acpi_hotkey_link hotkey_link;
110 int flag;
111 acpi_handle bus_handle; /* bus to install notify handler */
112 int external_hotkey_num; /* external hotkey/event number */
113 acpi_handle action_handle; /* acpi handle attached aml action method */
114 char *action_method; /* action method */
115};
116
117/*
118 * There are two ways to poll status
119 * 1. directy call read_xxx method, without any arguments passed in
120 * 2. call write_xxx method, with arguments passed in, you need
121 * the result is saved in acpi_polling_hotkey.poll_result.
122 * anthoer read command through polling interface.
123 *
124 */
125
126/* polling based hotkey */
127struct acpi_polling_hotkey {
128 struct acpi_hotkey_link hotkey_link;
129 int flag;
130 acpi_handle poll_handle; /* acpi handle attached polling method */
131 char *poll_method; /* poll method */
132 acpi_handle action_handle; /* acpi handle attached action method */
133 char *action_method; /* action method */
134 void *poll_result; /* polling_result */
135 struct proc_dir_entry *proc;
136};
137
138/* hotkey object union */
139union acpi_hotkey {
140 struct list_head entries;
141 struct acpi_hotkey_link link;
142 struct acpi_event_hotkey event_hotkey;
143 struct acpi_polling_hotkey poll_hotkey;
144};
145
146/* hotkey object list */
147struct acpi_hotkey_list {
148 struct list_head *entries;
149 int count;
150};
151
152static int auto_hotkey_add(struct acpi_device *device);
153static int auto_hotkey_remove(struct acpi_device *device, int type);
154
155static struct acpi_driver hotkey_driver = {
156 .name = ACPI_HOTK_NAME,
157 .class = ACPI_HOTK_CLASS,
158 .ids = ACPI_HOTK_HID,
159 .ops = {
160 .add = auto_hotkey_add,
161 .remove = auto_hotkey_remove,
162 },
163};
164
165static int hotkey_open_config(struct inode *inode, struct file *file);
166static ssize_t hotkey_write_config(struct file *file,
167 const char __user * buffer,
168 size_t count, loff_t * data);
169static ssize_t hotkey_write_poll_config(struct file *file,
170 const char __user * buffer,
171 size_t count, loff_t * data);
172static int hotkey_info_open_fs(struct inode *inode, struct file *file);
173static int hotkey_action_open_fs(struct inode *inode, struct file *file);
174static ssize_t hotkey_execute_aml_method(struct file *file,
175 const char __user * buffer,
176 size_t count, loff_t * data);
177static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
178static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
179
180/* event based config */
181static struct file_operations hotkey_config_fops = {
182 .open = hotkey_open_config,
183 .read = seq_read,
184 .write = hotkey_write_config,
185 .llseek = seq_lseek,
186 .release = single_release,
187};
188
189/* polling based config */
190static struct file_operations hotkey_poll_config_fops = {
191 .open = hotkey_open_config,
192 .read = seq_read,
193 .write = hotkey_write_poll_config,
194 .llseek = seq_lseek,
195 .release = single_release,
196};
197
198/* hotkey driver info */
199static struct file_operations hotkey_info_fops = {
200 .open = hotkey_info_open_fs,
201 .read = seq_read,
202 .llseek = seq_lseek,
203 .release = single_release,
204};
205
206/* action */
207static struct file_operations hotkey_action_fops = {
208 .open = hotkey_action_open_fs,
209 .read = seq_read,
210 .write = hotkey_execute_aml_method,
211 .llseek = seq_lseek,
212 .release = single_release,
213};
214
215/* polling results */
216static struct file_operations hotkey_polling_fops = {
217 .open = hotkey_polling_open_fs,
218 .read = seq_read,
219 .llseek = seq_lseek,
220 .release = single_release,
221};
222
223struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
224struct list_head hotkey_entries; /* head of the list of hotkey_list */
225
226static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
227{
228 ACPI_FUNCTION_TRACE("hotkey_info_seq_show");
229
230 seq_printf(seq, "Hotkey generic driver ver: %s", HOTKEY_ACPI_VERSION);
231
232 return_VALUE(0);
233}
234
235static int hotkey_info_open_fs(struct inode *inode, struct file *file)
236{
237 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
238}
239
240static char *format_result(union acpi_object *object)
241{
242 char *buf = (char *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
243
244 memset(buf, 0, sizeof(union acpi_object));
245
246 /* Now, just support integer type */
247 if (object->type == ACPI_TYPE_INTEGER)
248 sprintf(buf, "%d", (u32) object->integer.value);
249
250 return buf;
251}
252
253static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
254{
255 struct acpi_polling_hotkey *poll_hotkey =
256 (struct acpi_polling_hotkey *)seq->private;
257
258 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show");
259
260 if (poll_hotkey->poll_result)
261 seq_printf(seq, "%s", format_result(poll_hotkey->poll_result));
262
263 return_VALUE(0);
264}
265
266static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
267{
268 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
269}
270
271static int hotkey_action_open_fs(struct inode *inode, struct file *file)
272{
273 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
274}
275
276/* Mapping external hotkey number to standardized hotkey event num */
277static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
278{
279 struct list_head *entries, *next;
280 int val = 0;
281
282 ACPI_FUNCTION_TRACE("hotkey_get_internal_event");
283
284 list_for_each_safe(entries, next, list->entries) {
285 union acpi_hotkey *key =
286 container_of(entries, union acpi_hotkey, entries);
287 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
288 && key->event_hotkey.external_hotkey_num == event)
289 val = key->link.hotkey_standard_num;
290 else
291 val = -1;
292 }
293
294 return_VALUE(val);
295}
296
297static void
298acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
299{
300 struct acpi_device *device = NULL;
301 u32 internal_event;
302
303 ACPI_FUNCTION_TRACE("acpi_hotkey_notify_handler");
304
305 if (acpi_bus_get_device(handle, &device))
306 return_VOID;
307
308 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
309 acpi_bus_generate_event(device, event, 0);
310
311 return_VOID;
312}
313
314/* Need to invent automatically hotkey add method */
315static int auto_hotkey_add(struct acpi_device *device)
316{
317 /* Implement me */
318 return 0;
319}
320
321/* Need to invent automatically hotkey remove method */
322static int auto_hotkey_remove(struct acpi_device *device, int type)
323{
324 /* Implement me */
325 return 0;
326}
327
328/* Create a proc file for each polling method */
329static int create_polling_proc(union acpi_hotkey *device)
330{
331 struct proc_dir_entry *proc;
332 mode_t mode;
333
334 ACPI_FUNCTION_TRACE("create_polling_proc");
335 mode = S_IFREG | S_IRUGO | S_IWUGO;
336
337 proc = create_proc_entry(device->poll_hotkey.action_method,
338 mode, hotkey_proc_dir);
339
340 if (!proc) {
341 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
342 "Hotkey: Unable to create %s entry\n",
343 device->poll_hotkey.poll_method));
344 return_VALUE(-ENODEV);
345 } else {
346 proc->proc_fops = &hotkey_polling_fops;
347 proc->owner = THIS_MODULE;
348 proc->data = device;
349 proc->uid = 0;
350 proc->gid = 0;
351 device->poll_hotkey.proc = proc;
352 }
353 return_VALUE(0);
354}
355
356static int is_valid_acpi_path(const char *pathname)
357{
358 acpi_handle handle;
359 acpi_status status;
360 ACPI_FUNCTION_TRACE("is_valid_acpi_path");
361
362 status = acpi_get_handle(NULL, (char *)pathname, &handle);
363 return_VALUE(!ACPI_FAILURE(status));
364}
365
366static int is_valid_hotkey(union acpi_hotkey *device)
367{
368 ACPI_FUNCTION_TRACE("is_valid_hotkey");
369 /* Implement valid check */
370 return_VALUE(1);
371}
372
373static int hotkey_add(union acpi_hotkey *device)
374{
375 int status = 0;
376 struct acpi_device *dev = NULL;
377
378 ACPI_FUNCTION_TRACE("hotkey_add");
379
380 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
381 status =
382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
383 if (status)
384 return_VALUE(status);
385
386 status = acpi_install_notify_handler(dev->handle,
387 ACPI_SYSTEM_NOTIFY,
388 acpi_hotkey_notify_handler,
389 device);
390 } else /* Add polling hotkey */
391 create_polling_proc(device);
392
393 global_hotkey_list.count++;
394
395 list_add_tail(&device->link.entries, global_hotkey_list.entries);
396
397 return_VALUE(status);
398}
399
400static int hotkey_remove(union acpi_hotkey *device)
401{
402 struct list_head *entries, *next;
403
404 ACPI_FUNCTION_TRACE("hotkey_remove");
405
406 list_for_each_safe(entries, next, global_hotkey_list.entries) {
407 union acpi_hotkey *key =
408 container_of(entries, union acpi_hotkey, entries);
409 if (key->link.hotkey_standard_num ==
410 device->link.hotkey_standard_num) {
411 list_del(&key->link.entries);
412 remove_proc_entry(key->poll_hotkey.action_method,
413 hotkey_proc_dir);
414 global_hotkey_list.count--;
415 break;
416 }
417 }
418 return_VALUE(0);
419}
420
421static void hotkey_update(union acpi_hotkey *key)
422{
423 struct list_head *entries, *next;
424
425 ACPI_FUNCTION_TRACE("hotkey_update");
426
427 list_for_each_safe(entries, next, global_hotkey_list.entries) {
428 union acpi_hotkey *key =
429 container_of(entries, union acpi_hotkey, entries);
430 if (key->link.hotkey_standard_num ==
431 key->link.hotkey_standard_num) {
432 key->event_hotkey.bus_handle =
433 key->event_hotkey.bus_handle;
434 key->event_hotkey.external_hotkey_num =
435 key->event_hotkey.external_hotkey_num;
436 key->event_hotkey.action_handle =
437 key->event_hotkey.action_handle;
438 key->event_hotkey.action_method =
439 key->event_hotkey.action_method;
440 break;
441 }
442 }
443
444 return_VOID;
445}
446
447static void free_hotkey_device(union acpi_hotkey *key)
448{
449 struct acpi_device *dev;
450 int status;
451
452 ACPI_FUNCTION_TRACE("free_hotkey_device");
453
454 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
455 status =
456 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
457 if (dev->handle)
458 acpi_remove_notify_handler(dev->handle,
459 ACPI_SYSTEM_NOTIFY,
460 acpi_hotkey_notify_handler);
461 } else
462 remove_proc_entry(key->poll_hotkey.action_method,
463 hotkey_proc_dir);
464 kfree(key);
465 return_VOID;
466}
467
468static int
469init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str,
470 char *method, int std_num, int external_num)
471{
472 ACPI_FUNCTION_TRACE("init_hotkey_device");
473
474 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
475 key->link.hotkey_standard_num = std_num;
476 key->event_hotkey.flag = 0;
477 if (is_valid_acpi_path(bus_str))
478 acpi_get_handle((acpi_handle) 0,
479 bus_str, &(key->event_hotkey.bus_handle));
480 else
481 return_VALUE(-ENODEV);
482 key->event_hotkey.external_hotkey_num = external_num;
483 if (is_valid_acpi_path(action_str))
484 acpi_get_handle((acpi_handle) 0,
485 action_str, &(key->event_hotkey.action_handle));
486 key->event_hotkey.action_method = kmalloc(sizeof(method), GFP_KERNEL);
487 strcpy(key->event_hotkey.action_method, method);
488
489 return_VALUE(!is_valid_hotkey(key));
490}
491
492static int
493init_poll_hotkey_device(union acpi_hotkey *key,
494 char *poll_str,
495 char *poll_method,
496 char *action_str, char *action_method, int std_num)
497{
498 ACPI_FUNCTION_TRACE("init_poll_hotkey_device");
499
500 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
501 key->link.hotkey_standard_num = std_num;
502 key->poll_hotkey.flag = 0;
503 if (is_valid_acpi_path(poll_str))
504 acpi_get_handle((acpi_handle) 0,
505 poll_str, &(key->poll_hotkey.poll_handle));
506 else
507 return_VALUE(-ENODEV);
508 key->poll_hotkey.poll_method = poll_method;
509 if (is_valid_acpi_path(action_str))
510 acpi_get_handle((acpi_handle) 0,
511 action_str, &(key->poll_hotkey.action_handle));
512 key->poll_hotkey.action_method =
513 kmalloc(sizeof(action_method), GFP_KERNEL);
514 strcpy(key->poll_hotkey.action_method, action_method);
515 key->poll_hotkey.poll_result =
516 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
517 return_VALUE(is_valid_hotkey(key));
518}
519
520static int check_hotkey_valid(union acpi_hotkey *key,
521 struct acpi_hotkey_list *list)
522{
523 ACPI_FUNCTION_TRACE("check_hotkey_valid");
524 return_VALUE(0);
525}
526
527static int hotkey_open_config(struct inode *inode, struct file *file)
528{
529 ACPI_FUNCTION_TRACE("hotkey_open_config");
530 return_VALUE(single_open
531 (file, hotkey_config_seq_show, PDE(inode)->data));
532}
533
534static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
535{
536 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
537 struct list_head *entries, *next;
538 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
539 char action_name[ACPI_PATHNAME_MAX] = { 0 };
540 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
541 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
542
543 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
544
545 if (!hotkey_list)
546 goto end;
547
548 list_for_each_safe(entries, next, hotkey_list->entries) {
549 union acpi_hotkey *key =
550 container_of(entries, union acpi_hotkey, entries);
551 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
552 acpi_get_name(key->event_hotkey.bus_handle,
553 ACPI_NAME_TYPE_MAX, &bus);
554 acpi_get_name(key->event_hotkey.action_handle,
555 ACPI_NAME_TYPE_MAX, &act);
556 seq_printf(seq, "%s:%s:%s:%d:%d", bus_name,
557 action_name,
558 key->event_hotkey.action_method,
559 key->link.hotkey_standard_num,
560 key->event_hotkey.external_hotkey_num);
561 } /* ACPI_HOTKEY_POLLING */
562 else {
563 acpi_get_name(key->poll_hotkey.poll_handle,
564 ACPI_NAME_TYPE_MAX, &bus);
565 acpi_get_name(key->poll_hotkey.action_handle,
566 ACPI_NAME_TYPE_MAX, &act);
567 seq_printf(seq, "%s:%s:%s:%s:%d", bus_name,
568 key->poll_hotkey.poll_method,
569 action_name,
570 key->poll_hotkey.action_method,
571 key->link.hotkey_standard_num);
572 }
573 }
574 seq_puts(seq, "\n");
575 end:
576 return_VALUE(0);
577}
578
579static int
580get_parms(char *config_record,
581 int *cmd,
582 char *bus_handle,
583 char *bus_method,
584 char *action_handle,
585 char *method, int *internal_event_num, int *external_event_num)
586{
587 char *tmp, *tmp1;
588 ACPI_FUNCTION_TRACE(("get_parms"));
589
590 sscanf(config_record, "%d", cmd);
591
592 tmp = strchr(config_record, ':');
593 tmp++;
594 tmp1 = strchr(tmp, ':');
595 strncpy(bus_handle, tmp, tmp1 - tmp);
596 bus_handle[tmp1 - tmp] = 0;
597
598 tmp = tmp1;
599 tmp++;
600 tmp1 = strchr(tmp, ':');
601 strncpy(bus_method, tmp, tmp1 - tmp);
602 bus_method[tmp1 - tmp] = 0;
603
604 tmp = tmp1;
605 tmp++;
606 tmp1 = strchr(tmp, ':');
607 strncpy(action_handle, tmp, tmp1 - tmp);
608 action_handle[tmp1 - tmp] = 0;
609
610 tmp = tmp1;
611 tmp++;
612 tmp1 = strchr(tmp, ':');
613 strncpy(method, tmp, tmp1 - tmp);
614 method[tmp1 - tmp] = 0;
615
616 sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num);
617 return_VALUE(6);
618}
619
620/* count is length for one input record */
621static ssize_t hotkey_write_config(struct file *file,
622 const char __user * buffer,
623 size_t count, loff_t * data)
624{
625 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
626 char config_record[MAX_CONFIG_RECORD_LEN];
627 char bus_handle[MAX_NAME_PATH_LEN];
628 char bus_method[MAX_NAME_PATH_LEN];
629 char action_handle[MAX_NAME_PATH_LEN];
630 char method[20];
631 int cmd, internal_event_num, external_event_num;
632 int ret = 0;
633 union acpi_hotkey *key = NULL;
634
635 ACPI_FUNCTION_TRACE(("hotkey_write_config"));
636
637 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) {
638 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n"));
639 return_VALUE(-EINVAL);
640 }
641
642 if (copy_from_user(config_record, buffer, count)) {
643 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
644 return_VALUE(-EINVAL);
645 }
646 config_record[count] = '\0';
647
648 ret = get_parms(config_record,
649 &cmd,
650 bus_handle,
651 bus_method,
652 action_handle,
653 method, &internal_event_num, &external_event_num);
654 if (ret != 6) {
655 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
656 "Invalid data format ret=%d\n", ret));
657 return_VALUE(-EINVAL);
658 }
659
660 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
661 ret = init_hotkey_device(key, bus_handle, action_handle, method,
662 internal_event_num, external_event_num);
663
664 if (ret || check_hotkey_valid(key, hotkey_list)) {
665 kfree(key);
666 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
667 return_VALUE(-EINVAL);
668 }
669 switch (cmd) {
670 case 0:
671 hotkey_add(key);
672 break;
673 case 1:
674 hotkey_remove(key);
675 free_hotkey_device(key);
676 break;
677 case 2:
678 hotkey_update(key);
679 break;
680 default:
681 break;
682 }
683 return_VALUE(count);
684}
685
686/* count is length for one input record */
687static ssize_t hotkey_write_poll_config(struct file *file,
688 const char __user * buffer,
689 size_t count, loff_t * data)
690{
691 struct seq_file *m = (struct seq_file *)file->private_data;
692 struct acpi_hotkey_list *hotkey_list =
693 (struct acpi_hotkey_list *)m->private;
694
695 char config_record[MAX_CONFIG_RECORD_LEN];
696 char polling_handle[MAX_NAME_PATH_LEN];
697 char action_handle[MAX_NAME_PATH_LEN];
698 char poll_method[20], action_method[20];
699 int ret, internal_event_num, cmd, external_event_num;
700 union acpi_hotkey *key = NULL;
701
702 ACPI_FUNCTION_TRACE("hotkey_write_poll_config");
703
704 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) {
705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n"));
706 return_VALUE(-EINVAL);
707 }
708
709 if (copy_from_user(config_record, buffer, count)) {
710 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
711 return_VALUE(-EINVAL);
712 }
713 config_record[count] = '\0';
714
715 ret = get_parms(config_record,
716 &cmd,
717 polling_handle,
718 poll_method,
719 action_handle,
720 action_method,
721 &internal_event_num, &external_event_num);
722
723 if (ret != 6) {
724 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
725 return_VALUE(-EINVAL);
726 }
727
728 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
729 ret = init_poll_hotkey_device(key, polling_handle, poll_method,
730 action_handle, action_method,
731 internal_event_num);
732 if (ret || check_hotkey_valid(key, hotkey_list)) {
733 kfree(key);
734 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
735 return_VALUE(-EINVAL);
736 }
737 switch (cmd) {
738 case 0:
739 hotkey_add(key);
740 break;
741 case 1:
742 hotkey_remove(key);
743 break;
744 case 2:
745 hotkey_update(key);
746 break;
747 default:
748 break;
749 }
750 return_VALUE(count);
751}
752
753/*
754 * This function evaluates an ACPI method, given an int as parameter, the
755 * method is searched within the scope of the handle, can be NULL. The output
756 * of the method is written is output, which can also be NULL
757 *
758 * returns 1 if write is successful, 0 else.
759 */
760static int write_acpi_int(acpi_handle handle, const char *method, int val,
761 struct acpi_buffer *output)
762{
763 struct acpi_object_list params; /* list of input parameters (an int here) */
764 union acpi_object in_obj; /* the only param we use */
765 acpi_status status;
766
767 ACPI_FUNCTION_TRACE("write_acpi_int");
768 params.count = 1;
769 params.pointer = &in_obj;
770 in_obj.type = ACPI_TYPE_INTEGER;
771 in_obj.integer.value = val;
772
773 status = acpi_evaluate_object(handle, (char *)method, &params, output);
774
775 return_VALUE(status == AE_OK);
776}
777
778static int read_acpi_int(acpi_handle handle, const char *method, int *val)
779{
780 struct acpi_buffer output;
781 union acpi_object out_obj;
782 acpi_status status;
783
784 ACPI_FUNCTION_TRACE("read_acpi_int");
785 output.length = sizeof(out_obj);
786 output.pointer = &out_obj;
787
788 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
789 *val = out_obj.integer.value;
790 return_VALUE((status == AE_OK)
791 && (out_obj.type == ACPI_TYPE_INTEGER));
792}
793
794static acpi_handle
795get_handle_from_hotkeylist(struct acpi_hotkey_list *hotkey_list, int event_num)
796{
797 struct list_head *entries, *next;
798
799 list_for_each_safe(entries, next, hotkey_list->entries) {
800 union acpi_hotkey *key =
801 container_of(entries, union acpi_hotkey, entries);
802 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
803 && key->link.hotkey_standard_num == event_num) {
804 return (key->event_hotkey.action_handle);
805 }
806 }
807 return (NULL);
808}
809
810static
811char *get_method_from_hotkeylist(struct acpi_hotkey_list *hotkey_list,
812 int event_num)
813{
814 struct list_head *entries, *next;
815
816 list_for_each_safe(entries, next, hotkey_list->entries) {
817 union acpi_hotkey *key =
818 container_of(entries, union acpi_hotkey, entries);
819
820 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT &&
821 key->link.hotkey_standard_num == event_num)
822 return (key->event_hotkey.action_method);
823 }
824 return (NULL);
825}
826
827static struct acpi_polling_hotkey *get_hotkey_by_event(struct
828 acpi_hotkey_list
829 *hotkey_list, int event)
830{
831 struct list_head *entries, *next;
832
833 list_for_each_safe(entries, next, hotkey_list->entries) {
834 union acpi_hotkey *key =
835 container_of(entries, union acpi_hotkey, entries);
836 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING
837 && key->link.hotkey_standard_num == event) {
838 return (&key->poll_hotkey);
839 }
840 }
841 return (NULL);
842}
843
844/*
845 * user call AML method interface:
846 * Call convention:
847 * echo "event_num: arg type : value"
848 * example: echo "1:1:30" > /proc/acpi/action
849 * Just support 1 integer arg passing to AML method
850 */
851
852static ssize_t hotkey_execute_aml_method(struct file *file,
853 const char __user * buffer,
854 size_t count, loff_t * data)
855{
856 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
857 char arg[MAX_CALL_PARM];
858 int event, type, value;
859
860 char *method;
861 acpi_handle handle;
862
863 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method");
864
865 if (!hotkey_list || count > MAX_CALL_PARM) {
866 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 1"));
867 return_VALUE(-EINVAL);
868 }
869
870 if (copy_from_user(arg, buffer, count)) {
871 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2"));
872 return_VALUE(-EINVAL);
873 }
874
875 arg[count] = '\0';
876
877 if (sscanf(arg, "%d:%d:%d", &event, &type, &value) != 3) {
878 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3"));
879 return_VALUE(-EINVAL);
880 }
881
882 if (type == ACPI_TYPE_INTEGER) {
883 handle = get_handle_from_hotkeylist(hotkey_list, event);
884 method = (char *)get_method_from_hotkeylist(hotkey_list, event);
885 if (IS_EVENT(event))
886 write_acpi_int(handle, method, value, NULL);
887 else if (IS_POLL(event)) {
888 struct acpi_polling_hotkey *key;
889 key = (struct acpi_polling_hotkey *)
890 get_hotkey_by_event(hotkey_list, event);
891 read_acpi_int(handle, method, key->poll_result);
892 }
893 } else {
894 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported"));
895 return_VALUE(-EINVAL);
896 }
897
898 return_VALUE(count);
899}
900
901static int __init hotkey_init(void)
902{
903 int result;
904 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
905
906 ACPI_FUNCTION_TRACE("hotkey_init");
907
908 if (acpi_disabled)
909 return -ENODEV;
910
911 if (acpi_specific_hotkey_enabled) {
912 printk("Using specific hotkey driver\n");
913 return -ENODEV;
914 }
915
916 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
917 if (!hotkey_proc_dir) {
918 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
919 "Hotkey: Unable to create %s entry\n",
920 HOTKEY_PROC));
921 return (-ENODEV);
922 }
923 hotkey_proc_dir->owner = THIS_MODULE;
924
925 hotkey_config =
926 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
927 if (!hotkey_config) {
928 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
929 "Hotkey: Unable to create %s entry\n",
930 HOTKEY_EV_CONFIG));
931 return (-ENODEV);
932 } else {
933 hotkey_config->proc_fops = &hotkey_config_fops;
934 hotkey_config->data = &global_hotkey_list;
935 hotkey_config->owner = THIS_MODULE;
936 hotkey_config->uid = 0;
937 hotkey_config->gid = 0;
938 }
939
940 hotkey_poll_config =
941 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
942 if (!hotkey_poll_config) {
943 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
944 "Hotkey: Unable to create %s entry\n",
945 HOTKEY_EV_CONFIG));
946 return (-ENODEV);
947 } else {
948 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
949 hotkey_poll_config->data = &global_hotkey_list;
950 hotkey_poll_config->owner = THIS_MODULE;
951 hotkey_poll_config->uid = 0;
952 hotkey_poll_config->gid = 0;
953 }
954
955 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
956 if (!hotkey_action) {
957 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
958 "Hotkey: Unable to create %s entry\n",
959 HOTKEY_ACTION));
960 return (-ENODEV);
961 } else {
962 hotkey_action->proc_fops = &hotkey_action_fops;
963 hotkey_action->owner = THIS_MODULE;
964 hotkey_action->uid = 0;
965 hotkey_action->gid = 0;
966 }
967
968 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
969 if (!hotkey_info) {
970 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
971 "Hotkey: Unable to create %s entry\n",
972 HOTKEY_INFO));
973 return (-ENODEV);
974 } else {
975 hotkey_info->proc_fops = &hotkey_info_fops;
976 hotkey_info->owner = THIS_MODULE;
977 hotkey_info->uid = 0;
978 hotkey_info->gid = 0;
979 }
980
981 result = acpi_bus_register_driver(&hotkey_driver);
982 if (result < 0) {
983 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
984 return (-ENODEV);
985 }
986 global_hotkey_list.count = 0;
987 global_hotkey_list.entries = &hotkey_entries;
988
989 INIT_LIST_HEAD(&hotkey_entries);
990
991 return (0);
992}
993
994static void __exit hotkey_exit(void)
995{
996 struct list_head *entries, *next;
997
998 ACPI_FUNCTION_TRACE("hotkey_remove");
999
1000 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1001 union acpi_hotkey *key =
1002 container_of(entries, union acpi_hotkey, entries);
1003
1004 acpi_os_wait_events_complete(NULL);
1005 list_del(&key->link.entries);
1006 global_hotkey_list.count--;
1007 free_hotkey_device(key);
1008 }
1009 acpi_bus_unregister_driver(&hotkey_driver);
1010 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1011 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1012 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1013 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1014 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1015 return;
1016}
1017
1018module_init(hotkey_init);
1019module_exit(hotkey_exit);
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 0fb731a470dc..ad85e10001f4 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -1025,7 +1025,7 @@ static int setup_notify(struct ibm_struct *ibm)
1025 return 0; 1025 return 0;
1026} 1026}
1027 1027
1028static int device_add(struct acpi_device *device) 1028static int ibmacpi_device_add(struct acpi_device *device)
1029{ 1029{
1030 return 0; 1030 return 0;
1031} 1031}
@@ -1043,7 +1043,7 @@ static int register_driver(struct ibm_struct *ibm)
1043 memset(ibm->driver, 0, sizeof(struct acpi_driver)); 1043 memset(ibm->driver, 0, sizeof(struct acpi_driver));
1044 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name); 1044 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
1045 ibm->driver->ids = ibm->hid; 1045 ibm->driver->ids = ibm->hid;
1046 ibm->driver->ops.add = &device_add; 1046 ibm->driver->ops.add = &ibmacpi_device_add;
1047 1047
1048 ret = acpi_bus_register_driver(ibm->driver); 1048 ret = acpi_bus_register_driver(ibm->driver);
1049 if (ret < 0) { 1049 if (ret < 0) {
@@ -1185,6 +1185,10 @@ static int __init acpi_ibm_init(void)
1185 if (acpi_disabled) 1185 if (acpi_disabled)
1186 return -ENODEV; 1186 return -ENODEV;
1187 1187
1188 if (!acpi_specific_hotkey_enabled){
1189 printk(IBM_ERR "Using generic hotkey driver\n");
1190 return -ENODEV;
1191 }
1188 /* these handles are required */ 1192 /* these handles are required */
1189 if (IBM_HANDLE_INIT(ec, 1) < 0 || 1193 if (IBM_HANDLE_INIT(ec, 1) < 0 ||
1190 IBM_HANDLE_INIT(hkey, 1) < 0 || 1194 IBM_HANDLE_INIT(hkey, 1) < 0 ||
diff --git a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
index 1c0c12336c57..ece7a9dedd5c 100644
--- a/drivers/acpi/namespace/nsaccess.c
+++ b/drivers/acpi/namespace/nsaccess.c
@@ -67,7 +67,8 @@
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69acpi_status 69acpi_status
70acpi_ns_root_initialize (void) 70acpi_ns_root_initialize (
71 void)
71{ 72{
72 acpi_status status; 73 acpi_status status;
73 const struct acpi_predefined_names *init_val = NULL; 74 const struct acpi_predefined_names *init_val = NULL;
@@ -265,7 +266,7 @@ unlock_and_exit:
265 * 266 *
266 * FUNCTION: acpi_ns_lookup 267 * FUNCTION: acpi_ns_lookup
267 * 268 *
268 * PARAMETERS: prefix_node - Search scope if name is not fully qualified 269 * PARAMETERS: scope_info - Current scope info block
269 * Pathname - Search pathname, in internal format 270 * Pathname - Search pathname, in internal format
270 * (as represented in the AML stream) 271 * (as represented in the AML stream)
271 * Type - Type associated with name 272 * Type - Type associated with name
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index bfd922c5c7d1..5653a19d7172 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -49,14 +49,20 @@
49#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nsalloc") 50 ACPI_MODULE_NAME ("nsalloc")
51 51
52/* Local prototypes */
53
54static void
55acpi_ns_remove_reference (
56 struct acpi_namespace_node *node);
57
52 58
53/******************************************************************************* 59/*******************************************************************************
54 * 60 *
55 * FUNCTION: acpi_ns_create_node 61 * FUNCTION: acpi_ns_create_node
56 * 62 *
57 * PARAMETERS: acpi_name - Name of the new node 63 * PARAMETERS: Name - Name of the new node (4 char ACPI name)
58 * 64 *
59 * RETURN: None 65 * RETURN: New namespace node (Null on failure)
60 * 66 *
61 * DESCRIPTION: Create a namespace node 67 * DESCRIPTION: Create a namespace node
62 * 68 *
@@ -145,7 +151,6 @@ acpi_ns_delete_node (
145 } 151 }
146 } 152 }
147 153
148
149 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++); 154 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++);
150 155
151 /* 156 /*
@@ -157,57 +162,6 @@ acpi_ns_delete_node (
157} 162}
158 163
159 164
160#ifdef ACPI_ALPHABETIC_NAMESPACE
161/*******************************************************************************
162 *
163 * FUNCTION: acpi_ns_compare_names
164 *
165 * PARAMETERS: Name1 - First name to compare
166 * Name2 - Second name to compare
167 *
168 * RETURN: value from strncmp
169 *
170 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
171 * underscore are forced to be alphabetically first.
172 *
173 ******************************************************************************/
174
175int
176acpi_ns_compare_names (
177 char *name1,
178 char *name2)
179{
180 char reversed_name1[ACPI_NAME_SIZE];
181 char reversed_name2[ACPI_NAME_SIZE];
182 u32 i;
183 u32 j;
184
185
186 /*
187 * Replace all instances of "underscore" with a value that is smaller so
188 * that all names that are prefixed with underscore(s) are alphabetically
189 * first.
190 *
191 * Reverse the name bytewise so we can just do a 32-bit compare instead
192 * of a strncmp.
193 */
194 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--) {
195 reversed_name1[j] = name1[i];
196 if (name1[i] == '_') {
197 reversed_name1[j] = '*';
198 }
199
200 reversed_name2[j] = name2[i];
201 if (name2[i] == '_') {
202 reversed_name2[j] = '*';
203 }
204 }
205
206 return (*(int *) reversed_name1 - *(int *) reversed_name2);
207}
208#endif
209
210
211/******************************************************************************* 165/*******************************************************************************
212 * 166 *
213 * FUNCTION: acpi_ns_install_node 167 * FUNCTION: acpi_ns_install_node
@@ -271,7 +225,8 @@ acpi_ns_install_node (
271 * alphabetic placement. 225 * alphabetic placement.
272 */ 226 */
273 previous_child_node = NULL; 227 previous_child_node = NULL;
274 while (acpi_ns_compare_names (acpi_ut_get_node_name (child_node), acpi_ut_get_node_name (node)) < 0) { 228 while (acpi_ns_compare_names (acpi_ut_get_node_name (child_node),
229 acpi_ut_get_node_name (node)) < 0) {
275 if (child_node->flags & ANOBJ_END_OF_PEER_LIST) { 230 if (child_node->flags & ANOBJ_END_OF_PEER_LIST) {
276 /* Last peer; Clear end-of-list flag */ 231 /* Last peer; Clear end-of-list flag */
277 232
@@ -429,7 +384,8 @@ acpi_ns_delete_children (
429 /* There should be only one reference remaining on this node */ 384 /* There should be only one reference remaining on this node */
430 385
431 if (child_node->reference_count != 1) { 386 if (child_node->reference_count != 1) {
432 ACPI_REPORT_WARNING (("Existing references (%d) on node being deleted (%p)\n", 387 ACPI_REPORT_WARNING ((
388 "Existing references (%d) on node being deleted (%p)\n",
433 child_node->reference_count, child_node)); 389 child_node->reference_count, child_node));
434 } 390 }
435 391
@@ -548,7 +504,7 @@ acpi_ns_delete_namespace_subtree (
548 * 504 *
549 ******************************************************************************/ 505 ******************************************************************************/
550 506
551void 507static void
552acpi_ns_remove_reference ( 508acpi_ns_remove_reference (
553 struct acpi_namespace_node *node) 509 struct acpi_namespace_node *node)
554{ 510{
@@ -683,3 +639,54 @@ acpi_ns_delete_namespace_by_owner (
683} 639}
684 640
685 641
642#ifdef ACPI_ALPHABETIC_NAMESPACE
643/*******************************************************************************
644 *
645 * FUNCTION: acpi_ns_compare_names
646 *
647 * PARAMETERS: Name1 - First name to compare
648 * Name2 - Second name to compare
649 *
650 * RETURN: value from strncmp
651 *
652 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
653 * underscore are forced to be alphabetically first.
654 *
655 ******************************************************************************/
656
657int
658acpi_ns_compare_names (
659 char *name1,
660 char *name2)
661{
662 char reversed_name1[ACPI_NAME_SIZE];
663 char reversed_name2[ACPI_NAME_SIZE];
664 u32 i;
665 u32 j;
666
667
668 /*
669 * Replace all instances of "underscore" with a value that is smaller so
670 * that all names that are prefixed with underscore(s) are alphabetically
671 * first.
672 *
673 * Reverse the name bytewise so we can just do a 32-bit compare instead
674 * of a strncmp.
675 */
676 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--) {
677 reversed_name1[j] = name1[i];
678 if (name1[i] == '_') {
679 reversed_name1[j] = '*';
680 }
681
682 reversed_name2[j] = name2[i];
683 if (name2[i] == '_') {
684 reversed_name2[j] = '*';
685 }
686 }
687
688 return (*(int *) reversed_name1 - *(int *) reversed_name2);
689}
690#endif
691
692
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
index 1f6af3eb6c91..6c2aef0e0dd4 100644
--- a/drivers/acpi/namespace/nsdump.c
+++ b/drivers/acpi/namespace/nsdump.c
@@ -50,16 +50,32 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsdump") 51 ACPI_MODULE_NAME ("nsdump")
52 52
53/* Local prototypes */
53 54
54#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 55#ifdef ACPI_OBSOLETE_FUNCTIONS
56void
57acpi_ns_dump_root_devices (
58 void);
55 59
60static acpi_status
61acpi_ns_dump_one_device (
62 acpi_handle obj_handle,
63 u32 level,
64 void *context,
65 void **return_value);
66#endif
67
68
69#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56/******************************************************************************* 70/*******************************************************************************
57 * 71 *
58 * FUNCTION: acpi_ns_print_pathname 72 * FUNCTION: acpi_ns_print_pathname
59 * 73 *
60 * PARAMETERS: num_segment - Number of ACPI name segments 74 * PARAMETERS: num_segments - Number of ACPI name segments
61 * Pathname - The compressed (internal) path 75 * Pathname - The compressed (internal) path
62 * 76 *
77 * RETURN: None
78 *
63 * DESCRIPTION: Print an object's full namespace pathname 79 * DESCRIPTION: Print an object's full namespace pathname
64 * 80 *
65 ******************************************************************************/ 81 ******************************************************************************/
@@ -103,6 +119,8 @@ acpi_ns_print_pathname (
103 * Level - Desired debug level 119 * Level - Desired debug level
104 * Component - Caller's component ID 120 * Component - Caller's component ID
105 * 121 *
122 * RETURN: None
123 *
106 * DESCRIPTION: Print an object's full namespace pathname 124 * DESCRIPTION: Print an object's full namespace pathname
107 * Manages allocation/freeing of a pathname buffer 125 * Manages allocation/freeing of a pathname buffer
108 * 126 *
@@ -137,9 +155,12 @@ acpi_ns_dump_pathname (
137 * 155 *
138 * FUNCTION: acpi_ns_dump_one_object 156 * FUNCTION: acpi_ns_dump_one_object
139 * 157 *
140 * PARAMETERS: Handle - Node to be dumped 158 * PARAMETERS: obj_handle - Node to be dumped
141 * Level - Nesting level of the handle 159 * Level - Nesting level of the handle
142 * Context - Passed into walk_namespace 160 * Context - Passed into walk_namespace
161 * return_value - Not used
162 *
163 * RETURN: Status
143 * 164 *
144 * DESCRIPTION: Dump a single Node 165 * DESCRIPTION: Dump a single Node
145 * This procedure is a user_function called by acpi_ns_walk_namespace. 166 * This procedure is a user_function called by acpi_ns_walk_namespace.
@@ -394,8 +415,7 @@ acpi_ns_dump_one_object (
394 return (AE_OK); 415 return (AE_OK);
395 } 416 }
396 417
397 acpi_os_printf ("(R%d)", 418 acpi_os_printf ("(R%d)", obj_desc->common.reference_count);
398 obj_desc->common.reference_count);
399 419
400 switch (type) { 420 switch (type) {
401 case ACPI_TYPE_METHOD: 421 case ACPI_TYPE_METHOD:
@@ -551,18 +571,20 @@ cleanup:
551 571
552 572
553#ifdef ACPI_FUTURE_USAGE 573#ifdef ACPI_FUTURE_USAGE
554
555/******************************************************************************* 574/*******************************************************************************
556 * 575 *
557 * FUNCTION: acpi_ns_dump_objects 576 * FUNCTION: acpi_ns_dump_objects
558 * 577 *
559 * PARAMETERS: Type - Object type to be dumped 578 * PARAMETERS: Type - Object type to be dumped
579 * display_type - 0 or ACPI_DISPLAY_SUMMARY
560 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX 580 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
561 * for an effectively unlimited depth. 581 * for an effectively unlimited depth.
562 * owner_id - Dump only objects owned by this ID. Use 582 * owner_id - Dump only objects owned by this ID. Use
563 * ACPI_UINT32_MAX to match all owners. 583 * ACPI_UINT32_MAX to match all owners.
564 * start_handle - Where in namespace to start/end search 584 * start_handle - Where in namespace to start/end search
565 * 585 *
586 * RETURN: None
587 *
566 * DESCRIPTION: Dump typed objects within the loaded namespace. 588 * DESCRIPTION: Dump typed objects within the loaded namespace.
567 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object. 589 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
568 * 590 *
@@ -590,10 +612,44 @@ acpi_ns_dump_objects (
590 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object, 612 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object,
591 (void *) &info, NULL); 613 (void *) &info, NULL);
592} 614}
615#endif /* ACPI_FUTURE_USAGE */
593 616
594 617
595/******************************************************************************* 618/*******************************************************************************
596 * 619 *
620 * FUNCTION: acpi_ns_dump_entry
621 *
622 * PARAMETERS: Handle - Node to be dumped
623 * debug_level - Output level
624 *
625 * RETURN: None
626 *
627 * DESCRIPTION: Dump a single Node
628 *
629 ******************************************************************************/
630
631void
632acpi_ns_dump_entry (
633 acpi_handle handle,
634 u32 debug_level)
635{
636 struct acpi_walk_info info;
637
638
639 ACPI_FUNCTION_ENTRY ();
640
641
642 info.debug_level = debug_level;
643 info.owner_id = ACPI_UINT32_MAX;
644 info.display_type = ACPI_DISPLAY_SUMMARY;
645
646 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
647}
648
649
650#ifdef _ACPI_ASL_COMPILER
651/*******************************************************************************
652 *
597 * FUNCTION: acpi_ns_dump_tables 653 * FUNCTION: acpi_ns_dump_tables
598 * 654 *
599 * PARAMETERS: search_base - Root of subtree to be dumped, or 655 * PARAMETERS: search_base - Root of subtree to be dumped, or
@@ -601,6 +657,8 @@ acpi_ns_dump_objects (
601 * max_depth - Maximum depth of dump. Use INT_MAX 657 * max_depth - Maximum depth of dump. Use INT_MAX
602 * for an effectively unlimited depth. 658 * for an effectively unlimited depth.
603 * 659 *
660 * RETURN: None
661 *
604 * DESCRIPTION: Dump the name space, or a portion of it. 662 * DESCRIPTION: Dump the name space, or a portion of it.
605 * 663 *
606 ******************************************************************************/ 664 ******************************************************************************/
@@ -626,7 +684,7 @@ acpi_ns_dump_tables (
626 } 684 }
627 685
628 if (ACPI_NS_ALL == search_base) { 686 if (ACPI_NS_ALL == search_base) {
629 /* entire namespace */ 687 /* Entire namespace */
630 688
631 search_handle = acpi_gbl_root_node; 689 search_handle = acpi_gbl_root_node;
632 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n")); 690 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
@@ -636,38 +694,5 @@ acpi_ns_dump_tables (
636 ACPI_UINT32_MAX, search_handle); 694 ACPI_UINT32_MAX, search_handle);
637 return_VOID; 695 return_VOID;
638} 696}
639 697#endif /* _ACPI_ASL_COMPILER */
640#endif /* ACPI_FUTURE_USAGE */ 698#endif /* defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) */
641
642
643/*******************************************************************************
644 *
645 * FUNCTION: acpi_ns_dump_entry
646 *
647 * PARAMETERS: Handle - Node to be dumped
648 * debug_level - Output level
649 *
650 * DESCRIPTION: Dump a single Node
651 *
652 ******************************************************************************/
653
654void
655acpi_ns_dump_entry (
656 acpi_handle handle,
657 u32 debug_level)
658{
659 struct acpi_walk_info info;
660
661
662 ACPI_FUNCTION_ENTRY ();
663
664
665 info.debug_level = debug_level;
666 info.owner_id = ACPI_UINT32_MAX;
667 info.display_type = ACPI_DISPLAY_SUMMARY;
668
669 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
670}
671
672#endif
673
diff --git a/drivers/acpi/namespace/nsdumpdv.c b/drivers/acpi/namespace/nsdumpdv.c
index d30a59e6b07d..27c4f7cd2a43 100644
--- a/drivers/acpi/namespace/nsdumpdv.c
+++ b/drivers/acpi/namespace/nsdumpdv.c
@@ -43,15 +43,18 @@
43 43
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acnamesp.h>
47 46
48 47
48/* TBD: This entire module is apparently obsolete and should be removed */
49
49#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nsdumpdv") 51 ACPI_MODULE_NAME ("nsdumpdv")
51 52
52 53#ifdef ACPI_OBSOLETE_FUNCTIONS
53#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 54#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
54 55
56#include <acpi/acnamesp.h>
57
55/******************************************************************************* 58/*******************************************************************************
56 * 59 *
57 * FUNCTION: acpi_ns_dump_one_device 60 * FUNCTION: acpi_ns_dump_one_device
@@ -59,13 +62,16 @@
59 * PARAMETERS: Handle - Node to be dumped 62 * PARAMETERS: Handle - Node to be dumped
60 * Level - Nesting level of the handle 63 * Level - Nesting level of the handle
61 * Context - Passed into walk_namespace 64 * Context - Passed into walk_namespace
65 * return_value - Not used
66 *
67 * RETURN: Status
62 * 68 *
63 * DESCRIPTION: Dump a single Node that represents a device 69 * DESCRIPTION: Dump a single Node that represents a device
64 * This procedure is a user_function called by acpi_ns_walk_namespace. 70 * This procedure is a user_function called by acpi_ns_walk_namespace.
65 * 71 *
66 ******************************************************************************/ 72 ******************************************************************************/
67 73
68acpi_status 74static acpi_status
69acpi_ns_dump_one_device ( 75acpi_ns_dump_one_device (
70 acpi_handle obj_handle, 76 acpi_handle obj_handle,
71 u32 level, 77 u32 level,
@@ -108,12 +114,15 @@ acpi_ns_dump_one_device (
108 * 114 *
109 * PARAMETERS: None 115 * PARAMETERS: None
110 * 116 *
117 * RETURN: None
118 *
111 * DESCRIPTION: Dump all objects of type "device" 119 * DESCRIPTION: Dump all objects of type "device"
112 * 120 *
113 ******************************************************************************/ 121 ******************************************************************************/
114 122
115void 123void
116acpi_ns_dump_root_devices (void) 124acpi_ns_dump_root_devices (
125 void)
117{ 126{
118 acpi_handle sys_bus_handle; 127 acpi_handle sys_bus_handle;
119 acpi_status status; 128 acpi_status status;
@@ -142,5 +151,6 @@ acpi_ns_dump_root_devices (void)
142} 151}
143 152
144#endif 153#endif
154#endif
145 155
146 156
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 0d008d53657e..1ae89a1c8826 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -52,19 +52,33 @@
52#define _COMPONENT ACPI_NAMESPACE 52#define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nseval") 53 ACPI_MODULE_NAME ("nseval")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ns_execute_control_method (
59 struct acpi_parameter_info *info);
60
61static acpi_status
62acpi_ns_get_object_value (
63 struct acpi_parameter_info *info);
64
55 65
56/******************************************************************************* 66/*******************************************************************************
57 * 67 *
58 * FUNCTION: acpi_ns_evaluate_relative 68 * FUNCTION: acpi_ns_evaluate_relative
59 * 69 *
60 * PARAMETERS: Pathname - Name of method to execute, If NULL, the 70 * PARAMETERS: Pathname - Name of method to execute, If NULL, the
61 * handle is the object to execute 71 * handle is the object to execute
62 * Info - Method info block 72 * Info - Method info block, contains:
73 * return_object - Where to put method's return value (if
74 * any). If NULL, no value is returned.
75 * Params - List of parameters to pass to the method,
76 * terminated by NULL. Params itself may be
77 * NULL if no parameters are being passed.
63 * 78 *
64 * RETURN: Status 79 * RETURN: Status
65 * 80 *
66 * DESCRIPTION: Find and execute the requested method using the handle as a 81 * DESCRIPTION: Evaluate the object or find and execute the requested method
67 * scope
68 * 82 *
69 * MUTEX: Locks Namespace 83 * MUTEX: Locks Namespace
70 * 84 *
@@ -157,8 +171,8 @@ cleanup1:
157 * 171 *
158 * FUNCTION: acpi_ns_evaluate_by_name 172 * FUNCTION: acpi_ns_evaluate_by_name
159 * 173 *
160 * PARAMETERS: Pathname - Fully qualified pathname to the object 174 * PARAMETERS: Pathname - Fully qualified pathname to the object
161 * Info - Contains: 175 * Info - Method info block, contains:
162 * return_object - Where to put method's return value (if 176 * return_object - Where to put method's return value (if
163 * any). If NULL, no value is returned. 177 * any). If NULL, no value is returned.
164 * Params - List of parameters to pass to the method, 178 * Params - List of parameters to pass to the method,
@@ -167,8 +181,8 @@ cleanup1:
167 * 181 *
168 * RETURN: Status 182 * RETURN: Status
169 * 183 *
170 * DESCRIPTION: Find and execute the requested method passing the given 184 * DESCRIPTION: Evaluate the object or rind and execute the requested method
171 * parameters 185 * passing the given parameters
172 * 186 *
173 * MUTEX: Locks Namespace 187 * MUTEX: Locks Namespace
174 * 188 *
@@ -241,17 +255,21 @@ cleanup:
241 * 255 *
242 * FUNCTION: acpi_ns_evaluate_by_handle 256 * FUNCTION: acpi_ns_evaluate_by_handle
243 * 257 *
244 * PARAMETERS: Handle - Method Node to execute 258 * PARAMETERS: Info - Method info block, contains:
245 * Params - List of parameters to pass to the method, 259 * Node - Method/Object Node to execute
246 * terminated by NULL. Params itself may be 260 * Parameters - List of parameters to pass to the method,
261 * terminated by NULL. Params itself may be
247 * NULL if no parameters are being passed. 262 * NULL if no parameters are being passed.
248 * param_type - Type of Parameter list 263 * return_object - Where to put method's return value (if
249 * return_object - Where to put method's return value (if 264 * any). If NULL, no value is returned.
250 * any). If NULL, no value is returned. 265 * parameter_type - Type of Parameter list
266 * return_object - Where to put method's return value (if
267 * any). If NULL, no value is returned.
251 * 268 *
252 * RETURN: Status 269 * RETURN: Status
253 * 270 *
254 * DESCRIPTION: Execute the requested method passing the given parameters 271 * DESCRIPTION: Evaluate object or execute the requested method passing the
272 * given parameters
255 * 273 *
256 * MUTEX: Locks Namespace 274 * MUTEX: Locks Namespace
257 * 275 *
@@ -345,7 +363,16 @@ acpi_ns_evaluate_by_handle (
345 * 363 *
346 * FUNCTION: acpi_ns_execute_control_method 364 * FUNCTION: acpi_ns_execute_control_method
347 * 365 *
348 * PARAMETERS: Info - Method info block (w/params) 366 * PARAMETERS: Info - Method info block, contains:
367 * Node - Method Node to execute
368 * Parameters - List of parameters to pass to the method,
369 * terminated by NULL. Params itself may be
370 * NULL if no parameters are being passed.
371 * return_object - Where to put method's return value (if
372 * any). If NULL, no value is returned.
373 * parameter_type - Type of Parameter list
374 * return_object - Where to put method's return value (if
375 * any). If NULL, no value is returned.
349 * 376 *
350 * RETURN: Status 377 * RETURN: Status
351 * 378 *
@@ -355,7 +382,7 @@ acpi_ns_evaluate_by_handle (
355 * 382 *
356 ******************************************************************************/ 383 ******************************************************************************/
357 384
358acpi_status 385static acpi_status
359acpi_ns_execute_control_method ( 386acpi_ns_execute_control_method (
360 struct acpi_parameter_info *info) 387 struct acpi_parameter_info *info)
361{ 388{
@@ -414,7 +441,10 @@ acpi_ns_execute_control_method (
414 * 441 *
415 * FUNCTION: acpi_ns_get_object_value 442 * FUNCTION: acpi_ns_get_object_value
416 * 443 *
417 * PARAMETERS: Info - Method info block (w/params) 444 * PARAMETERS: Info - Method info block, contains:
445 * Node - Object's NS node
446 * return_object - Where to put object value (if
447 * any). If NULL, no value is returned.
418 * 448 *
419 * RETURN: Status 449 * RETURN: Status
420 * 450 *
@@ -424,7 +454,7 @@ acpi_ns_execute_control_method (
424 * 454 *
425 ******************************************************************************/ 455 ******************************************************************************/
426 456
427acpi_status 457static acpi_status
428acpi_ns_get_object_value ( 458acpi_ns_get_object_value (
429 struct acpi_parameter_info *info) 459 struct acpi_parameter_info *info)
430{ 460{
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index 4a46b380605b..362802ae29a2 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -50,6 +50,22 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsinit") 51 ACPI_MODULE_NAME ("nsinit")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_ns_init_one_object (
57 acpi_handle obj_handle,
58 u32 level,
59 void *context,
60 void **return_value);
61
62static acpi_status
63acpi_ns_init_one_device (
64 acpi_handle obj_handle,
65 u32 nesting_level,
66 void *context,
67 void **return_value);
68
53 69
54/******************************************************************************* 70/*******************************************************************************
55 * 71 *
@@ -191,7 +207,7 @@ acpi_ns_initialize_devices (
191 * 207 *
192 ******************************************************************************/ 208 ******************************************************************************/
193 209
194acpi_status 210static acpi_status
195acpi_ns_init_one_object ( 211acpi_ns_init_one_object (
196 acpi_handle obj_handle, 212 acpi_handle obj_handle,
197 u32 level, 213 u32 level,
@@ -331,7 +347,7 @@ acpi_ns_init_one_object (
331 * 347 *
332 ******************************************************************************/ 348 ******************************************************************************/
333 349
334acpi_status 350static acpi_status
335acpi_ns_init_one_device ( 351acpi_ns_init_one_device (
336 acpi_handle obj_handle, 352 acpi_handle obj_handle,
337 u32 nesting_level, 353 u32 nesting_level,
@@ -374,7 +390,8 @@ acpi_ns_init_one_device (
374 /* 390 /*
375 * Run _STA to determine if we can run _INI on the device. 391 * Run _STA to determine if we can run _INI on the device.
376 */ 392 */
377 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_STA")); 393 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD,
394 pinfo.node, METHOD_NAME__STA));
378 status = acpi_ut_execute_STA (pinfo.node, &flags); 395 status = acpi_ut_execute_STA (pinfo.node, &flags);
379 396
380 if (ACPI_FAILURE (status)) { 397 if (ACPI_FAILURE (status)) {
@@ -399,8 +416,9 @@ acpi_ns_init_one_device (
399 /* 416 /*
400 * The device is present. Run _INI. 417 * The device is present. Run _INI.
401 */ 418 */
402 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_INI")); 419 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD,
403 status = acpi_ns_evaluate_relative ("_INI", &pinfo); 420 pinfo.node, METHOD_NAME__INI));
421 status = acpi_ns_evaluate_relative (METHOD_NAME__INI, &pinfo);
404 if (ACPI_FAILURE (status)) { 422 if (ACPI_FAILURE (status)) {
405 /* No _INI (AE_NOT_FOUND) means device requires no initialization */ 423 /* No _INI (AE_NOT_FOUND) means device requires no initialization */
406 424
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
index 1d7aedf68a77..34e497016601 100644
--- a/drivers/acpi/namespace/nsload.c
+++ b/drivers/acpi/namespace/nsload.c
@@ -50,9 +50,24 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsload") 51 ACPI_MODULE_NAME ("nsload")
52 52
53/* Local prototypes */
53 54
54#ifndef ACPI_NO_METHOD_EXECUTION 55static acpi_status
56acpi_ns_load_table_by_type (
57 acpi_table_type table_type);
58
59#ifdef ACPI_FUTURE_IMPLEMENTATION
60acpi_status
61acpi_ns_unload_namespace (
62 acpi_handle handle);
63
64static acpi_status
65acpi_ns_delete_subtree (
66 acpi_handle start_handle);
67#endif
55 68
69
70#ifndef ACPI_NO_METHOD_EXECUTION
56/******************************************************************************* 71/*******************************************************************************
57 * 72 *
58 * FUNCTION: acpi_ns_load_table 73 * FUNCTION: acpi_ns_load_table
@@ -159,7 +174,7 @@ acpi_ns_load_table (
159 * 174 *
160 ******************************************************************************/ 175 ******************************************************************************/
161 176
162acpi_status 177static acpi_status
163acpi_ns_load_table_by_type ( 178acpi_ns_load_table_by_type (
164 acpi_table_type table_type) 179 acpi_table_type table_type)
165{ 180{
@@ -321,8 +336,7 @@ acpi_ns_load_namespace (
321} 336}
322 337
323 338
324#ifdef ACPI_FUTURE_USAGE 339#ifdef ACPI_FUTURE_IMPLEMENTATION
325
326/******************************************************************************* 340/*******************************************************************************
327 * 341 *
328 * FUNCTION: acpi_ns_delete_subtree 342 * FUNCTION: acpi_ns_delete_subtree
@@ -339,7 +353,7 @@ acpi_ns_load_namespace (
339 * 353 *
340 ******************************************************************************/ 354 ******************************************************************************/
341 355
342acpi_status 356static acpi_status
343acpi_ns_delete_subtree ( 357acpi_ns_delete_subtree (
344 acpi_handle start_handle) 358 acpi_handle start_handle)
345{ 359{
@@ -453,8 +467,6 @@ acpi_ns_unload_namespace (
453 467
454 return_ACPI_STATUS (status); 468 return_ACPI_STATUS (status);
455} 469}
456 470#endif
457#endif /* ACPI_FUTURE_USAGE */
458
459#endif 471#endif
460 472
diff --git a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
index b6f8f910eff0..d8ce7e39795f 100644
--- a/drivers/acpi/namespace/nsnames.c
+++ b/drivers/acpi/namespace/nsnames.c
@@ -50,6 +50,14 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsnames") 51 ACPI_MODULE_NAME ("nsnames")
52 52
53/* Local prototypes */
54
55static void
56acpi_ns_build_external_path (
57 struct acpi_namespace_node *node,
58 acpi_size size,
59 char *name_buffer);
60
53 61
54/******************************************************************************* 62/*******************************************************************************
55 * 63 *
@@ -66,7 +74,7 @@
66 * 74 *
67 ******************************************************************************/ 75 ******************************************************************************/
68 76
69void 77static void
70acpi_ns_build_external_path ( 78acpi_ns_build_external_path (
71 struct acpi_namespace_node *node, 79 struct acpi_namespace_node *node,
72 acpi_size size, 80 acpi_size size,
@@ -126,7 +134,7 @@ acpi_ns_build_external_path (
126 * 134 *
127 * FUNCTION: acpi_ns_get_external_pathname 135 * FUNCTION: acpi_ns_get_external_pathname
128 * 136 *
129 * PARAMETERS: Node - NS node whose pathname is needed 137 * PARAMETERS: Node - Namespace node whose pathname is needed
130 * 138 *
131 * RETURN: Pointer to storage containing the fully qualified name of 139 * RETURN: Pointer to storage containing the fully qualified name of
132 * the node, In external format (name segments separated by path 140 * the node, In external format (name segments separated by path
diff --git a/drivers/acpi/namespace/nsobject.c b/drivers/acpi/namespace/nsobject.c
index 4e41e66db61f..27258c1ca4f1 100644
--- a/drivers/acpi/namespace/nsobject.c
+++ b/drivers/acpi/namespace/nsobject.c
@@ -60,6 +60,8 @@
60 * Type - Type of object, or ACPI_TYPE_ANY if not 60 * Type - Type of object, or ACPI_TYPE_ANY if not
61 * known 61 * known
62 * 62 *
63 * RETURN: Status
64 *
63 * DESCRIPTION: Record the given object as the value associated with the 65 * DESCRIPTION: Record the given object as the value associated with the
64 * name whose acpi_handle is passed. If Object is NULL 66 * name whose acpi_handle is passed. If Object is NULL
65 * and Type is ACPI_TYPE_ANY, set the name as having no value. 67 * and Type is ACPI_TYPE_ANY, set the name as having no value.
@@ -97,7 +99,8 @@ acpi_ns_attach_object (
97 if (!object && (ACPI_TYPE_ANY != type)) { 99 if (!object && (ACPI_TYPE_ANY != type)) {
98 /* Null object */ 100 /* Null object */
99 101
100 ACPI_REPORT_ERROR (("ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n")); 102 ACPI_REPORT_ERROR ((
103 "ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
101 return_ACPI_STATUS (AE_BAD_PARAMETER); 104 return_ACPI_STATUS (AE_BAD_PARAMETER);
102 } 105 }
103 106
@@ -112,7 +115,8 @@ acpi_ns_attach_object (
112 /* Check if this object is already attached */ 115 /* Check if this object is already attached */
113 116
114 if (node->object == object) { 117 if (node->object == object) {
115 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj %p already installed in name_obj %p\n", 118 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
119 "Obj %p already installed in name_obj %p\n",
116 object, node)); 120 object, node));
117 121
118 return_ACPI_STATUS (AE_OK); 122 return_ACPI_STATUS (AE_OK);
@@ -192,7 +196,7 @@ acpi_ns_attach_object (
192 * 196 *
193 * FUNCTION: acpi_ns_detach_object 197 * FUNCTION: acpi_ns_detach_object
194 * 198 *
195 * PARAMETERS: Node - An node whose object will be detached 199 * PARAMETERS: Node - A Namespace node whose object will be detached
196 * 200 *
197 * RETURN: None. 201 * RETURN: None.
198 * 202 *
@@ -248,7 +252,7 @@ acpi_ns_detach_object (
248 * 252 *
249 * FUNCTION: acpi_ns_get_attached_object 253 * FUNCTION: acpi_ns_get_attached_object
250 * 254 *
251 * PARAMETERS: Node - Parent Node to be examined 255 * PARAMETERS: Node - Namespace node
252 * 256 *
253 * RETURN: Current value of the object field from the Node whose 257 * RETURN: Current value of the object field from the Node whose
254 * handle is passed 258 * handle is passed
@@ -284,7 +288,7 @@ acpi_ns_get_attached_object (
284 * 288 *
285 * FUNCTION: acpi_ns_get_secondary_object 289 * FUNCTION: acpi_ns_get_secondary_object
286 * 290 *
287 * PARAMETERS: Node - Parent Node to be examined 291 * PARAMETERS: Node - Namespace node
288 * 292 *
289 * RETURN: Current value of the object field from the Node whose 293 * RETURN: Current value of the object field from the Node whose
290 * handle is passed. 294 * handle is passed.
diff --git a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
index 0e6dea23603b..af8aaa9cc4f3 100644
--- a/drivers/acpi/namespace/nssearch.c
+++ b/drivers/acpi/namespace/nssearch.c
@@ -49,15 +49,24 @@
49#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nssearch") 50 ACPI_MODULE_NAME ("nssearch")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ns_search_parent_tree (
56 u32 target_name,
57 struct acpi_namespace_node *node,
58 acpi_object_type type,
59 struct acpi_namespace_node **return_node);
60
52 61
53/******************************************************************************* 62/*******************************************************************************
54 * 63 *
55 * FUNCTION: acpi_ns_search_node 64 * FUNCTION: acpi_ns_search_node
56 * 65 *
57 * PARAMETERS: *target_name - Ascii ACPI name to search for 66 * PARAMETERS: target_name - Ascii ACPI name to search for
58 * *Node - Starting node where search will begin 67 * Node - Starting node where search will begin
59 * Type - Object type to match 68 * Type - Object type to match
60 * **return_node - Where the matched Named obj is returned 69 * return_node - Where the matched Named obj is returned
61 * 70 *
62 * RETURN: Status 71 * RETURN: Status
63 * 72 *
@@ -163,10 +172,10 @@ acpi_ns_search_node (
163 * 172 *
164 * FUNCTION: acpi_ns_search_parent_tree 173 * FUNCTION: acpi_ns_search_parent_tree
165 * 174 *
166 * PARAMETERS: *target_name - Ascii ACPI name to search for 175 * PARAMETERS: target_name - Ascii ACPI name to search for
167 * *Node - Starting node where search will begin 176 * Node - Starting node where search will begin
168 * Type - Object type to match 177 * Type - Object type to match
169 * **return_node - Where the matched Node is returned 178 * return_node - Where the matched Node is returned
170 * 179 *
171 * RETURN: Status 180 * RETURN: Status
172 * 181 *
@@ -257,12 +266,12 @@ acpi_ns_search_parent_tree (
257 * 266 *
258 * PARAMETERS: target_name - Ascii ACPI name to search for (4 chars) 267 * PARAMETERS: target_name - Ascii ACPI name to search for (4 chars)
259 * walk_state - Current state of the walk 268 * walk_state - Current state of the walk
260 * *Node - Starting node where search will begin 269 * Node - Starting node where search will begin
261 * interpreter_mode - Add names only in ACPI_MODE_LOAD_PASS_x. 270 * interpreter_mode - Add names only in ACPI_MODE_LOAD_PASS_x.
262 * Otherwise,search only. 271 * Otherwise,search only.
263 * Type - Object type to match 272 * Type - Object type to match
264 * Flags - Flags describing the search restrictions 273 * Flags - Flags describing the search restrictions
265 * **return_node - Where the Node is returned 274 * return_node - Where the Node is returned
266 * 275 *
267 * RETURN: Status 276 * RETURN: Status
268 * 277 *
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
index 75da76cc0b19..c53b82e94ce3 100644
--- a/drivers/acpi/namespace/nsutils.c
+++ b/drivers/acpi/namespace/nsutils.c
@@ -51,6 +51,18 @@
51#define _COMPONENT ACPI_NAMESPACE 51#define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsutils") 52 ACPI_MODULE_NAME ("nsutils")
53 53
54/* Local prototypes */
55
56static u8
57acpi_ns_valid_path_separator (
58 char sep);
59
60#ifdef ACPI_OBSOLETE_FUNCTIONS
61acpi_name
62acpi_ns_find_parent_name (
63 struct acpi_namespace_node *node_to_search);
64#endif
65
54 66
55/******************************************************************************* 67/*******************************************************************************
56 * 68 *
@@ -59,7 +71,8 @@
59 * PARAMETERS: module_name - Caller's module name (for error output) 71 * PARAMETERS: module_name - Caller's module name (for error output)
60 * line_number - Caller's line number (for error output) 72 * line_number - Caller's line number (for error output)
61 * component_id - Caller's component ID (for error output) 73 * component_id - Caller's component ID (for error output)
62 * Message - Error message to use on failure 74 * internal_name - Name or path of the namespace node
75 * lookup_status - Exception code from NS lookup
63 * 76 *
64 * RETURN: None 77 * RETURN: None
65 * 78 *
@@ -121,6 +134,9 @@ acpi_ns_report_error (
121 * line_number - Caller's line number (for error output) 134 * line_number - Caller's line number (for error output)
122 * component_id - Caller's component ID (for error output) 135 * component_id - Caller's component ID (for error output)
123 * Message - Error message to use on failure 136 * Message - Error message to use on failure
137 * prefix_node - Prefix relative to the path
138 * Path - Path to the node
139 * method_status - Execution status
124 * 140 *
125 * RETURN: None 141 * RETURN: None
126 * 142 *
@@ -161,8 +177,8 @@ acpi_ns_report_method_error (
161 * 177 *
162 * FUNCTION: acpi_ns_print_node_pathname 178 * FUNCTION: acpi_ns_print_node_pathname
163 * 179 *
164 * PARAMETERS: Node - Object 180 * PARAMETERS: Node - Object
165 * Msg - Prefix message 181 * Message - Prefix message
166 * 182 *
167 * DESCRIPTION: Print an object's full namespace pathname 183 * DESCRIPTION: Print an object's full namespace pathname
168 * Manages allocation/freeing of a pathname buffer 184 * Manages allocation/freeing of a pathname buffer
@@ -172,7 +188,7 @@ acpi_ns_report_method_error (
172void 188void
173acpi_ns_print_node_pathname ( 189acpi_ns_print_node_pathname (
174 struct acpi_namespace_node *node, 190 struct acpi_namespace_node *node,
175 char *msg) 191 char *message)
176{ 192{
177 struct acpi_buffer buffer; 193 struct acpi_buffer buffer;
178 acpi_status status; 194 acpi_status status;
@@ -189,8 +205,8 @@ acpi_ns_print_node_pathname (
189 205
190 status = acpi_ns_handle_to_pathname (node, &buffer); 206 status = acpi_ns_handle_to_pathname (node, &buffer);
191 if (ACPI_SUCCESS (status)) { 207 if (ACPI_SUCCESS (status)) {
192 if (msg) { 208 if (message) {
193 acpi_os_printf ("%s ", msg); 209 acpi_os_printf ("%s ", message);
194 } 210 }
195 211
196 acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node); 212 acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node);
@@ -224,7 +240,7 @@ acpi_ns_valid_root_prefix (
224 * 240 *
225 * FUNCTION: acpi_ns_valid_path_separator 241 * FUNCTION: acpi_ns_valid_path_separator
226 * 242 *
227 * PARAMETERS: Sep - Character to be checked 243 * PARAMETERS: Sep - Character to be checked
228 * 244 *
229 * RETURN: TRUE if a valid path separator 245 * RETURN: TRUE if a valid path separator
230 * 246 *
@@ -232,7 +248,7 @@ acpi_ns_valid_root_prefix (
232 * 248 *
233 ******************************************************************************/ 249 ******************************************************************************/
234 250
235u8 251static u8
236acpi_ns_valid_path_separator ( 252acpi_ns_valid_path_separator (
237 char sep) 253 char sep)
238{ 254{
@@ -245,10 +261,12 @@ acpi_ns_valid_path_separator (
245 * 261 *
246 * FUNCTION: acpi_ns_get_type 262 * FUNCTION: acpi_ns_get_type
247 * 263 *
248 * PARAMETERS: Handle - Parent Node to be examined 264 * PARAMETERS: Node - Parent Node to be examined
249 * 265 *
250 * RETURN: Type field from Node whose handle is passed 266 * RETURN: Type field from Node whose handle is passed
251 * 267 *
268 * DESCRIPTION: Return the type of a Namespace node
269 *
252 ******************************************************************************/ 270 ******************************************************************************/
253 271
254acpi_object_type 272acpi_object_type
@@ -271,11 +289,13 @@ acpi_ns_get_type (
271 * 289 *
272 * FUNCTION: acpi_ns_local 290 * FUNCTION: acpi_ns_local
273 * 291 *
274 * PARAMETERS: Type - A namespace object type 292 * PARAMETERS: Type - A namespace object type
275 * 293 *
276 * RETURN: LOCAL if names must be found locally in objects of the 294 * RETURN: LOCAL if names must be found locally in objects of the
277 * passed type, 0 if enclosing scopes should be searched 295 * passed type, 0 if enclosing scopes should be searched
278 * 296 *
297 * DESCRIPTION: Returns scope rule for the given object type.
298 *
279 ******************************************************************************/ 299 ******************************************************************************/
280 300
281u32 301u32
@@ -303,7 +323,7 @@ acpi_ns_local (
303 * PARAMETERS: Info - Info struct initialized with the 323 * PARAMETERS: Info - Info struct initialized with the
304 * external name pointer. 324 * external name pointer.
305 * 325 *
306 * RETURN: Status 326 * RETURN: None
307 * 327 *
308 * DESCRIPTION: Calculate the length of the internal (AML) namestring 328 * DESCRIPTION: Calculate the length of the internal (AML) namestring
309 * corresponding to the external (ASL) namestring. 329 * corresponding to the external (ASL) namestring.
@@ -551,14 +571,16 @@ acpi_ns_internalize_name (
551 * 571 *
552 * FUNCTION: acpi_ns_externalize_name 572 * FUNCTION: acpi_ns_externalize_name
553 * 573 *
554 * PARAMETERS: *internal_name - Internal representation of name 574 * PARAMETERS: internal_name_length - Lenth of the internal name below
555 * **converted_name - Where to return the resulting 575 * internal_name - Internal representation of name
556 * external representation of name 576 * converted_name_length - Where the length is returned
577 * converted_name - Where the resulting external name
578 * is returned
557 * 579 *
558 * RETURN: Status 580 * RETURN: Status
559 * 581 *
560 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) 582 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
561 * to its external form (e.g. "\_PR_.CPU0") 583 * to its external (printable) form (e.g. "\_PR_.CPU0")
562 * 584 *
563 ******************************************************************************/ 585 ******************************************************************************/
564 586
@@ -717,8 +739,9 @@ acpi_ns_externalize_name (
717 * 739 *
718 * DESCRIPTION: Convert a namespace handle to a real Node 740 * DESCRIPTION: Convert a namespace handle to a real Node
719 * 741 *
720 * Note: Real integer handles allow for more verification 742 * Note: Real integer handles would allow for more verification
721 * and keep all pointers within this subsystem. 743 * and keep all pointers within this subsystem - however this introduces
744 * more (and perhaps unnecessary) overhead.
722 * 745 *
723 ******************************************************************************/ 746 ******************************************************************************/
724 747
@@ -775,7 +798,7 @@ acpi_ns_convert_entry_to_handle (
775 return ((acpi_handle) node); 798 return ((acpi_handle) node);
776 799
777 800
778/* --------------------------------------------------- 801/* Example future implementation ---------------------
779 802
780 if (!Node) 803 if (!Node)
781 { 804 {
@@ -801,12 +824,13 @@ acpi_ns_convert_entry_to_handle (
801 * 824 *
802 * RETURN: none 825 * RETURN: none
803 * 826 *
804 * DESCRIPTION: free memory allocated for table storage. 827 * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
805 * 828 *
806 ******************************************************************************/ 829 ******************************************************************************/
807 830
808void 831void
809acpi_ns_terminate (void) 832acpi_ns_terminate (
833 void)
810{ 834{
811 union acpi_operand_object *obj_desc; 835 union acpi_operand_object *obj_desc;
812 836
@@ -940,7 +964,6 @@ acpi_ns_get_node_by_path (
940 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 964 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
941 965
942cleanup: 966cleanup:
943 /* Cleanup */
944 if (internal_path) { 967 if (internal_path) {
945 ACPI_MEM_FREE (internal_path); 968 ACPI_MEM_FREE (internal_path);
946 } 969 }
@@ -950,55 +973,6 @@ cleanup:
950 973
951/******************************************************************************* 974/*******************************************************************************
952 * 975 *
953 * FUNCTION: acpi_ns_find_parent_name
954 *
955 * PARAMETERS: *child_node - Named Obj whose name is to be found
956 *
957 * RETURN: The ACPI name
958 *
959 * DESCRIPTION: Search for the given obj in its parent scope and return the
960 * name segment, or "????" if the parent name can't be found
961 * (which "should not happen").
962 *
963 ******************************************************************************/
964#ifdef ACPI_FUTURE_USAGE
965acpi_name
966acpi_ns_find_parent_name (
967 struct acpi_namespace_node *child_node)
968{
969 struct acpi_namespace_node *parent_node;
970
971
972 ACPI_FUNCTION_TRACE ("ns_find_parent_name");
973
974
975 if (child_node) {
976 /* Valid entry. Get the parent Node */
977
978 parent_node = acpi_ns_get_parent_node (child_node);
979 if (parent_node) {
980 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
981 "Parent of %p [%4.4s] is %p [%4.4s]\n",
982 child_node, acpi_ut_get_node_name (child_node),
983 parent_node, acpi_ut_get_node_name (parent_node)));
984
985 if (parent_node->name.integer) {
986 return_VALUE ((acpi_name) parent_node->name.integer);
987 }
988 }
989
990 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
991 "Unable to find parent of %p (%4.4s)\n",
992 child_node, acpi_ut_get_node_name (child_node)));
993 }
994
995 return_VALUE (ACPI_UNKNOWN_NAME);
996}
997#endif
998
999
1000/*******************************************************************************
1001 *
1002 * FUNCTION: acpi_ns_get_parent_node 976 * FUNCTION: acpi_ns_get_parent_node
1003 * 977 *
1004 * PARAMETERS: Node - Current table entry 978 * PARAMETERS: Node - Current table entry
@@ -1009,7 +983,6 @@ acpi_ns_find_parent_name (
1009 * 983 *
1010 ******************************************************************************/ 984 ******************************************************************************/
1011 985
1012
1013struct acpi_namespace_node * 986struct acpi_namespace_node *
1014acpi_ns_get_parent_node ( 987acpi_ns_get_parent_node (
1015 struct acpi_namespace_node *node) 988 struct acpi_namespace_node *node)
@@ -1030,7 +1003,6 @@ acpi_ns_get_parent_node (
1030 node = node->peer; 1003 node = node->peer;
1031 } 1004 }
1032 1005
1033
1034 return (node->peer); 1006 return (node->peer);
1035} 1007}
1036 1008
@@ -1049,7 +1021,6 @@ acpi_ns_get_parent_node (
1049 * 1021 *
1050 ******************************************************************************/ 1022 ******************************************************************************/
1051 1023
1052
1053struct acpi_namespace_node * 1024struct acpi_namespace_node *
1054acpi_ns_get_next_valid_node ( 1025acpi_ns_get_next_valid_node (
1055 struct acpi_namespace_node *node) 1026 struct acpi_namespace_node *node)
@@ -1067,3 +1038,53 @@ acpi_ns_get_next_valid_node (
1067} 1038}
1068 1039
1069 1040
1041#ifdef ACPI_OBSOLETE_FUNCTIONS
1042/*******************************************************************************
1043 *
1044 * FUNCTION: acpi_ns_find_parent_name
1045 *
1046 * PARAMETERS: *child_node - Named Obj whose name is to be found
1047 *
1048 * RETURN: The ACPI name
1049 *
1050 * DESCRIPTION: Search for the given obj in its parent scope and return the
1051 * name segment, or "????" if the parent name can't be found
1052 * (which "should not happen").
1053 *
1054 ******************************************************************************/
1055
1056acpi_name
1057acpi_ns_find_parent_name (
1058 struct acpi_namespace_node *child_node)
1059{
1060 struct acpi_namespace_node *parent_node;
1061
1062
1063 ACPI_FUNCTION_TRACE ("ns_find_parent_name");
1064
1065
1066 if (child_node) {
1067 /* Valid entry. Get the parent Node */
1068
1069 parent_node = acpi_ns_get_parent_node (child_node);
1070 if (parent_node) {
1071 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1072 "Parent of %p [%4.4s] is %p [%4.4s]\n",
1073 child_node, acpi_ut_get_node_name (child_node),
1074 parent_node, acpi_ut_get_node_name (parent_node)));
1075
1076 if (parent_node->name.integer) {
1077 return_VALUE ((acpi_name) parent_node->name.integer);
1078 }
1079 }
1080
1081 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1082 "Unable to find parent of %p (%4.4s)\n",
1083 child_node, acpi_ut_get_node_name (child_node)));
1084 }
1085
1086 return_VALUE (ACPI_UNKNOWN_NAME);
1087}
1088#endif
1089
1090
diff --git a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
index 4de2444df300..f9a7277dca6e 100644
--- a/drivers/acpi/namespace/nswalk.c
+++ b/drivers/acpi/namespace/nswalk.c
@@ -56,7 +56,7 @@
56 * 56 *
57 * PARAMETERS: Type - Type of node to be searched for 57 * PARAMETERS: Type - Type of node to be searched for
58 * parent_node - Parent node whose children we are 58 * parent_node - Parent node whose children we are
59 * getting 59 * getting
60 * child_node - Previous child that was found. 60 * child_node - Previous child that was found.
61 * The NEXT child will be returned 61 * The NEXT child will be returned
62 * 62 *
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 1dc995586cbe..12ea202257fa 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -58,11 +58,11 @@
58 * FUNCTION: acpi_evaluate_object_typed 58 * FUNCTION: acpi_evaluate_object_typed
59 * 59 *
60 * PARAMETERS: Handle - Object handle (optional) 60 * PARAMETERS: Handle - Object handle (optional)
61 * *Pathname - Object pathname (optional) 61 * Pathname - Object pathname (optional)
62 * **external_params - List of parameters to pass to method, 62 * external_params - List of parameters to pass to method,
63 * terminated by NULL. May be NULL 63 * terminated by NULL. May be NULL
64 * if no parameters are being passed. 64 * if no parameters are being passed.
65 * *return_buffer - Where to put method's return value (if 65 * return_buffer - Where to put method's return value (if
66 * any). If NULL, no value is returned. 66 * any). If NULL, no value is returned.
67 * return_type - Expected type of return object 67 * return_type - Expected type of return object
68 * 68 *
@@ -73,6 +73,7 @@
73 * be valid (non-null) 73 * be valid (non-null)
74 * 74 *
75 ******************************************************************************/ 75 ******************************************************************************/
76
76#ifdef ACPI_FUTURE_USAGE 77#ifdef ACPI_FUTURE_USAGE
77acpi_status 78acpi_status
78acpi_evaluate_object_typed ( 79acpi_evaluate_object_typed (
@@ -307,7 +308,8 @@ acpi_evaluate_object (
307 if (ACPI_SUCCESS (status)) { 308 if (ACPI_SUCCESS (status)) {
308 /* Validate/Allocate/Clear caller buffer */ 309 /* Validate/Allocate/Clear caller buffer */
309 310
310 status = acpi_ut_initialize_buffer (return_buffer, buffer_space_needed); 311 status = acpi_ut_initialize_buffer (return_buffer,
312 buffer_space_needed);
311 if (ACPI_FAILURE (status)) { 313 if (ACPI_FAILURE (status)) {
312 /* 314 /*
313 * Caller's buffer is too small or a new one can't be allocated 315 * Caller's buffer is too small or a new one can't be allocated
@@ -423,7 +425,8 @@ acpi_walk_namespace (
423 return_ACPI_STATUS (status); 425 return_ACPI_STATUS (status);
424 } 426 }
425 427
426 status = acpi_ns_walk_namespace (type, start_object, max_depth, ACPI_NS_WALK_UNLOCK, 428 status = acpi_ns_walk_namespace (type, start_object, max_depth,
429 ACPI_NS_WALK_UNLOCK,
427 user_function, context, return_value); 430 user_function, context, return_value);
428 431
429 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 432 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
@@ -525,7 +528,8 @@ acpi_ns_get_device_callback (
525 } 528 }
526 } 529 }
527 530
528 status = info->user_function (obj_handle, nesting_level, info->context, return_value); 531 status = info->user_function (obj_handle, nesting_level, info->context,
532 return_value);
529 return (status); 533 return (status);
530} 534}
531 535
diff --git a/drivers/acpi/namespace/nsxfname.c b/drivers/acpi/namespace/nsxfname.c
index f2405efd1b9a..8d097914c49a 100644
--- a/drivers/acpi/namespace/nsxfname.c
+++ b/drivers/acpi/namespace/nsxfname.c
@@ -57,9 +57,9 @@
57 * FUNCTION: acpi_get_handle 57 * FUNCTION: acpi_get_handle
58 * 58 *
59 * PARAMETERS: Parent - Object to search under (search scope). 59 * PARAMETERS: Parent - Object to search under (search scope).
60 * path_name - Pointer to an asciiz string containing the 60 * Pathname - Pointer to an asciiz string containing the
61 * name 61 * name
62 * ret_handle - Where the return handle is placed 62 * ret_handle - Where the return handle is returned
63 * 63 *
64 * RETURN: Status 64 * RETURN: Status
65 * 65 *
@@ -220,7 +220,7 @@ EXPORT_SYMBOL(acpi_get_name);
220 * FUNCTION: acpi_get_object_info 220 * FUNCTION: acpi_get_object_info
221 * 221 *
222 * PARAMETERS: Handle - Object Handle 222 * PARAMETERS: Handle - Object Handle
223 * Info - Where the info is returned 223 * Buffer - Where the info is returned
224 * 224 *
225 * RETURN: Status 225 * RETURN: Status
226 * 226 *
diff --git a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
index 19acf32674b9..363e1f6cfb18 100644
--- a/drivers/acpi/namespace/nsxfobj.c
+++ b/drivers/acpi/namespace/nsxfobj.c
@@ -56,7 +56,7 @@
56 * FUNCTION: acpi_get_type 56 * FUNCTION: acpi_get_type
57 * 57 *
58 * PARAMETERS: Handle - Handle of object whose type is desired 58 * PARAMETERS: Handle - Handle of object whose type is desired
59 * *ret_type - Where the type will be placed 59 * ret_type - Where the type will be placed
60 * 60 *
61 * RETURN: Status 61 * RETURN: Status
62 * 62 *
@@ -258,5 +258,5 @@ unlock_and_exit:
258 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 258 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
259 return (status); 259 return (status);
260} 260}
261EXPORT_SYMBOL(acpi_get_next_object);
262 261
262EXPORT_SYMBOL(acpi_get_next_object);
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 5a9128de6226..bdd9f37f8101 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -71,6 +71,9 @@ EXPORT_SYMBOL(acpi_in_debugger);
71extern char line_buf[80]; 71extern char line_buf[80];
72#endif /*ENABLE_DEBUGGER*/ 72#endif /*ENABLE_DEBUGGER*/
73 73
74int acpi_specific_hotkey_enabled;
75EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
76
74static unsigned int acpi_irq_irq; 77static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler; 78static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context; 79static void *acpi_irq_context;
@@ -1152,6 +1155,15 @@ acpi_wake_gpes_always_on_setup(char *str)
1152 1155
1153__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); 1156__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1154 1157
1158int __init
1159acpi_hotkey_setup(char *str)
1160{
1161 acpi_specific_hotkey_enabled = TRUE;
1162 return 1;
1163}
1164
1165__setup("acpi_specific_hotkey", acpi_hotkey_setup);
1166
1155/* 1167/*
1156 * max_cstate is defined in the base kernel so modules can 1168 * max_cstate is defined in the base kernel so modules can
1157 * change it w/o depending on the state of the processor module. 1169 * change it w/o depending on the state of the processor module.
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
index b5d98895f6a8..b7ac68cc9e1c 100644
--- a/drivers/acpi/parser/psargs.c
+++ b/drivers/acpi/parser/psargs.c
@@ -50,6 +50,16 @@
50#define _COMPONENT ACPI_PARSER 50#define _COMPONENT ACPI_PARSER
51 ACPI_MODULE_NAME ("psargs") 51 ACPI_MODULE_NAME ("psargs")
52 52
53/* Local prototypes */
54
55static u32
56acpi_ps_get_next_package_length (
57 struct acpi_parse_state *parser_state);
58
59static union acpi_parse_object *
60acpi_ps_get_next_field (
61 struct acpi_parse_state *parser_state);
62
53 63
54/******************************************************************************* 64/*******************************************************************************
55 * 65 *
@@ -64,7 +74,7 @@
64 * 74 *
65 ******************************************************************************/ 75 ******************************************************************************/
66 76
67u32 77static u32
68acpi_ps_get_next_package_length ( 78acpi_ps_get_next_package_length (
69 struct acpi_parse_state *parser_state) 79 struct acpi_parse_state *parser_state)
70{ 80{
@@ -78,7 +88,6 @@ acpi_ps_get_next_package_length (
78 encoded_length = (u32) ACPI_GET8 (parser_state->aml); 88 encoded_length = (u32) ACPI_GET8 (parser_state->aml);
79 parser_state->aml++; 89 parser_state->aml++;
80 90
81
82 switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ { 91 switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ {
83 case 0: /* 1-byte encoding (bits 0-5) */ 92 case 0: /* 1-byte encoding (bits 0-5) */
84 93
@@ -287,13 +296,14 @@ acpi_ps_get_next_namepath (
287 * parent tree, but don't open a new scope -- we just want to lookup the 296 * parent tree, but don't open a new scope -- we just want to lookup the
288 * object (MUST BE mode EXECUTE to perform upsearch) 297 * object (MUST BE mode EXECUTE to perform upsearch)
289 */ 298 */
290 status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 299 status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY,
291 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &node); 300 ACPI_IMODE_EXECUTE,
301 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
302 NULL, &node);
292 if (ACPI_SUCCESS (status) && method_call) { 303 if (ACPI_SUCCESS (status) && method_call) {
293 if (node->type == ACPI_TYPE_METHOD) { 304 if (node->type == ACPI_TYPE_METHOD) {
294 /* 305 /* This name is actually a control method invocation */
295 * This name is actually a control method invocation 306
296 */
297 method_desc = acpi_ns_get_attached_object (node); 307 method_desc = acpi_ns_get_attached_object (node);
298 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 308 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
299 "Control Method - %p Desc %p Path=%p\n", 309 "Control Method - %p Desc %p Path=%p\n",
@@ -360,7 +370,7 @@ acpi_ps_get_next_namepath (
360 /* 370 /*
361 * We got a NOT_FOUND during table load or we encountered 371 * We got a NOT_FOUND during table load or we encountered
362 * a cond_ref_of(x) where the target does not exist. 372 * a cond_ref_of(x) where the target does not exist.
363 * -- either case is ok 373 * Either case is ok
364 */ 374 */
365 status = AE_OK; 375 status = AE_OK;
366 } 376 }
@@ -486,12 +496,13 @@ acpi_ps_get_next_simple_arg (
486 * 496 *
487 ******************************************************************************/ 497 ******************************************************************************/
488 498
489union acpi_parse_object * 499static union acpi_parse_object *
490acpi_ps_get_next_field ( 500acpi_ps_get_next_field (
491 struct acpi_parse_state *parser_state) 501 struct acpi_parse_state *parser_state)
492{ 502{
493 u32 aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 503 u32 aml_offset = (u32)
494 parser_state->aml_start); 504 ACPI_PTR_DIFF (parser_state->aml,
505 parser_state->aml_start);
495 union acpi_parse_object *field; 506 union acpi_parse_object *field;
496 u16 opcode; 507 u16 opcode;
497 u32 name; 508 u32 name;
@@ -500,7 +511,7 @@ acpi_ps_get_next_field (
500 ACPI_FUNCTION_TRACE ("ps_get_next_field"); 511 ACPI_FUNCTION_TRACE ("ps_get_next_field");
501 512
502 513
503 /* determine field type */ 514 /* Determine field type */
504 515
505 switch (ACPI_GET8 (parser_state->aml)) { 516 switch (ACPI_GET8 (parser_state->aml)) {
506 default: 517 default:
@@ -521,7 +532,6 @@ acpi_ps_get_next_field (
521 break; 532 break;
522 } 533 }
523 534
524
525 /* Allocate a new field op */ 535 /* Allocate a new field op */
526 536
527 field = acpi_ps_alloc_op (opcode); 537 field = acpi_ps_alloc_op (opcode);
@@ -582,10 +592,10 @@ acpi_ps_get_next_field (
582 * 592 *
583 * FUNCTION: acpi_ps_get_next_arg 593 * FUNCTION: acpi_ps_get_next_arg
584 * 594 *
585 * PARAMETERS: parser_state - Current parser state object 595 * PARAMETERS: walk_state - Current state
596 * parser_state - Current parser state object
586 * arg_type - The argument type (AML_*_ARG) 597 * arg_type - The argument type (AML_*_ARG)
587 * arg_count - If the argument points to a control method 598 * return_arg - Where the next arg is returned
588 * the method's argument is returned here.
589 * 599 *
590 * RETURN: Status, and an op object containing the next argument. 600 * RETURN: Status, and an op object containing the next argument.
591 * 601 *
@@ -619,7 +629,7 @@ acpi_ps_get_next_arg (
619 case ARGP_NAME: 629 case ARGP_NAME:
620 case ARGP_NAMESTRING: 630 case ARGP_NAMESTRING:
621 631
622 /* constants, strings, and namestrings are all the same size */ 632 /* Constants, strings, and namestrings are all the same size */
623 633
624 arg = acpi_ps_alloc_op (AML_BYTE_OP); 634 arg = acpi_ps_alloc_op (AML_BYTE_OP);
625 if (!arg) { 635 if (!arg) {
@@ -654,7 +664,6 @@ acpi_ps_get_next_arg (
654 else { 664 else {
655 arg = field; 665 arg = field;
656 } 666 }
657
658 prev = field; 667 prev = field;
659 } 668 }
660 669
@@ -677,8 +686,8 @@ acpi_ps_get_next_arg (
677 686
678 /* Fill in bytelist data */ 687 /* Fill in bytelist data */
679 688
680 arg->common.value.size = (u32) ACPI_PTR_DIFF (parser_state->pkg_end, 689 arg->common.value.size = (u32)
681 parser_state->aml); 690 ACPI_PTR_DIFF (parser_state->pkg_end, parser_state->aml);
682 arg->named.data = parser_state->aml; 691 arg->named.data = parser_state->aml;
683 692
684 /* Skip to End of byte data */ 693 /* Skip to End of byte data */
@@ -706,7 +715,7 @@ acpi_ps_get_next_arg (
706 status = acpi_ps_get_next_namepath (walk_state, parser_state, arg, 0); 715 status = acpi_ps_get_next_namepath (walk_state, parser_state, arg, 0);
707 } 716 }
708 else { 717 else {
709 /* single complex argument, nothing returned */ 718 /* Single complex argument, nothing returned */
710 719
711 walk_state->arg_count = 1; 720 walk_state->arg_count = 1;
712 } 721 }
@@ -716,7 +725,7 @@ acpi_ps_get_next_arg (
716 case ARGP_DATAOBJ: 725 case ARGP_DATAOBJ:
717 case ARGP_TERMARG: 726 case ARGP_TERMARG:
718 727
719 /* single complex argument, nothing returned */ 728 /* Single complex argument, nothing returned */
720 729
721 walk_state->arg_count = 1; 730 walk_state->arg_count = 1;
722 break; 731 break;
@@ -727,7 +736,7 @@ acpi_ps_get_next_arg (
727 case ARGP_OBJLIST: 736 case ARGP_OBJLIST:
728 737
729 if (parser_state->aml < parser_state->pkg_end) { 738 if (parser_state->aml < parser_state->pkg_end) {
730 /* non-empty list of variable arguments, nothing returned */ 739 /* Non-empty list of variable arguments, nothing returned */
731 740
732 walk_state->arg_count = ACPI_VAR_ARGS; 741 walk_state->arg_count = ACPI_VAR_ARGS;
733 } 742 }
diff --git a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
index 03e33fedc11a..5744673568c0 100644
--- a/drivers/acpi/parser/psopcode.c
+++ b/drivers/acpi/parser/psopcode.c
@@ -44,6 +44,7 @@
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acparser.h> 46#include <acpi/acparser.h>
47#include <acpi/acopcode.h>
47#include <acpi/amlcode.h> 48#include <acpi/amlcode.h>
48 49
49 50
@@ -51,23 +52,6 @@
51 ACPI_MODULE_NAME ("psopcode") 52 ACPI_MODULE_NAME ("psopcode")
52 53
53 54
54#define _UNK 0x6B
55/*
56 * Reserved ASCII characters. Do not use any of these for
57 * internal opcodes, since they are used to differentiate
58 * name strings from AML opcodes
59 */
60#define _ASC 0x6C
61#define _NAM 0x6C
62#define _PFX 0x6D
63#define _UNKNOWN_OPCODE 0x02 /* An example unknown opcode */
64
65#define MAX_EXTENDED_OPCODE 0x88
66#define NUM_EXTENDED_OPCODE (MAX_EXTENDED_OPCODE + 1)
67#define MAX_INTERNAL_OPCODE
68#define NUM_INTERNAL_OPCODE (MAX_INTERNAL_OPCODE + 1)
69
70
71/******************************************************************************* 55/*******************************************************************************
72 * 56 *
73 * NAME: acpi_gbl_aml_op_info 57 * NAME: acpi_gbl_aml_op_info
@@ -79,274 +63,9 @@
79 * 63 *
80 ******************************************************************************/ 64 ******************************************************************************/
81 65
82
83/*
84 * All AML opcodes and the parse-time arguments for each. Used by the AML parser Each list is compressed
85 * into a 32-bit number and stored in the master opcode table at the end of this file.
86 */
87
88
89#define ARGP_ACCESSFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
90#define ARGP_ACQUIRE_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_WORDDATA)
91#define ARGP_ADD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
92#define ARGP_ALIAS_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_NAME)
93#define ARGP_ARG0 ARG_NONE
94#define ARGP_ARG1 ARG_NONE
95#define ARGP_ARG2 ARG_NONE
96#define ARGP_ARG3 ARG_NONE
97#define ARGP_ARG4 ARG_NONE
98#define ARGP_ARG5 ARG_NONE
99#define ARGP_ARG6 ARG_NONE
100#define ARGP_BANK_FIELD_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_TERMARG, ARGP_BYTEDATA, ARGP_FIELDLIST)
101#define ARGP_BIT_AND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
102#define ARGP_BIT_NAND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
103#define ARGP_BIT_NOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
104#define ARGP_BIT_NOT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
105#define ARGP_BIT_OR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
106#define ARGP_BIT_XOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
107#define ARGP_BREAK_OP ARG_NONE
108#define ARGP_BREAK_POINT_OP ARG_NONE
109#define ARGP_BUFFER_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_BYTELIST)
110#define ARGP_BYTE_OP ARGP_LIST1 (ARGP_BYTEDATA)
111#define ARGP_BYTELIST_OP ARGP_LIST1 (ARGP_NAMESTRING)
112#define ARGP_CONCAT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
113#define ARGP_CONCAT_RES_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
114#define ARGP_COND_REF_OF_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SUPERNAME)
115#define ARGP_CONTINUE_OP ARG_NONE
116#define ARGP_COPY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SIMPLENAME)
117#define ARGP_CREATE_BIT_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
118#define ARGP_CREATE_BYTE_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
119#define ARGP_CREATE_DWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
120#define ARGP_CREATE_FIELD_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
121#define ARGP_CREATE_QWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
122#define ARGP_CREATE_WORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
123#define ARGP_DATA_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
124#define ARGP_DEBUG_OP ARG_NONE
125#define ARGP_DECREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
126#define ARGP_DEREF_OF_OP ARGP_LIST1 (ARGP_TERMARG)
127#define ARGP_DEVICE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
128#define ARGP_DIVIDE_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET, ARGP_TARGET)
129#define ARGP_DWORD_OP ARGP_LIST1 (ARGP_DWORDDATA)
130#define ARGP_ELSE_OP ARGP_LIST2 (ARGP_PKGLENGTH, ARGP_TERMLIST)
131#define ARGP_EVENT_OP ARGP_LIST1 (ARGP_NAME)
132#define ARGP_FATAL_OP ARGP_LIST3 (ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_TERMARG)
133#define ARGP_FIELD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_BYTEDATA, ARGP_FIELDLIST)
134#define ARGP_FIND_SET_LEFT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
135#define ARGP_FIND_SET_RIGHT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
136#define ARGP_FROM_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
137#define ARGP_IF_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
138#define ARGP_INCREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
139#define ARGP_INDEX_FIELD_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_BYTEDATA, ARGP_FIELDLIST)
140#define ARGP_INDEX_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
141#define ARGP_LAND_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
142#define ARGP_LEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
143#define ARGP_LGREATER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
144#define ARGP_LGREATEREQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
145#define ARGP_LLESS_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
146#define ARGP_LLESSEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
147#define ARGP_LNOT_OP ARGP_LIST1 (ARGP_TERMARG)
148#define ARGP_LNOTEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
149#define ARGP_LOAD_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_SUPERNAME)
150#define ARGP_LOAD_TABLE_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
151#define ARGP_LOCAL0 ARG_NONE
152#define ARGP_LOCAL1 ARG_NONE
153#define ARGP_LOCAL2 ARG_NONE
154#define ARGP_LOCAL3 ARG_NONE
155#define ARGP_LOCAL4 ARG_NONE
156#define ARGP_LOCAL5 ARG_NONE
157#define ARGP_LOCAL6 ARG_NONE
158#define ARGP_LOCAL7 ARG_NONE
159#define ARGP_LOR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
160#define ARGP_MATCH_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
161#define ARGP_METHOD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMLIST)
162#define ARGP_METHODCALL_OP ARGP_LIST1 (ARGP_NAMESTRING)
163#define ARGP_MID_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
164#define ARGP_MOD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
165#define ARGP_MULTIPLY_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
166#define ARGP_MUTEX_OP ARGP_LIST2 (ARGP_NAME, ARGP_BYTEDATA)
167#define ARGP_NAME_OP ARGP_LIST2 (ARGP_NAME, ARGP_DATAOBJ)
168#define ARGP_NAMEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
169#define ARGP_NAMEPATH_OP ARGP_LIST1 (ARGP_NAMESTRING)
170#define ARGP_NOOP_OP ARG_NONE
171#define ARGP_NOTIFY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
172#define ARGP_ONE_OP ARG_NONE
173#define ARGP_ONES_OP ARG_NONE
174#define ARGP_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_BYTEDATA, ARGP_DATAOBJLIST)
175#define ARGP_POWER_RES_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_WORDDATA, ARGP_OBJLIST)
176#define ARGP_PROCESSOR_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_BYTEDATA, ARGP_OBJLIST)
177#define ARGP_QWORD_OP ARGP_LIST1 (ARGP_QWORDDATA)
178#define ARGP_REF_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
179#define ARGP_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
180#define ARGP_RELEASE_OP ARGP_LIST1 (ARGP_SUPERNAME)
181#define ARGP_RESERVEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
182#define ARGP_RESET_OP ARGP_LIST1 (ARGP_SUPERNAME)
183#define ARGP_RETURN_OP ARGP_LIST1 (ARGP_TERMARG)
184#define ARGP_REVISION_OP ARG_NONE
185#define ARGP_SCOPE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_TERMLIST)
186#define ARGP_SHIFT_LEFT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
187#define ARGP_SHIFT_RIGHT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
188#define ARGP_SIGNAL_OP ARGP_LIST1 (ARGP_SUPERNAME)
189#define ARGP_SIZE_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
190#define ARGP_SLEEP_OP ARGP_LIST1 (ARGP_TERMARG)
191#define ARGP_STALL_OP ARGP_LIST1 (ARGP_TERMARG)
192#define ARGP_STATICSTRING_OP ARGP_LIST1 (ARGP_NAMESTRING)
193#define ARGP_STORE_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_SUPERNAME)
194#define ARGP_STRING_OP ARGP_LIST1 (ARGP_CHARLIST)
195#define ARGP_SUBTRACT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
196#define ARGP_THERMAL_ZONE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
197#define ARGP_TIMER_OP ARG_NONE
198#define ARGP_TO_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
199#define ARGP_TO_BUFFER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
200#define ARGP_TO_DEC_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
201#define ARGP_TO_HEX_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
202#define ARGP_TO_INTEGER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
203#define ARGP_TO_STRING_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
204#define ARGP_TYPE_OP ARGP_LIST1 (ARGP_SUPERNAME)
205#define ARGP_UNLOAD_OP ARGP_LIST1 (ARGP_SUPERNAME)
206#define ARGP_VAR_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_DATAOBJLIST)
207#define ARGP_WAIT_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
208#define ARGP_WHILE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
209#define ARGP_WORD_OP ARGP_LIST1 (ARGP_WORDDATA)
210#define ARGP_ZERO_OP ARG_NONE
211
212
213/*
214 * All AML opcodes and the runtime arguments for each. Used by the AML interpreter Each list is compressed
215 * into a 32-bit number and stored in the master opcode table at the end of this file.
216 *
217 * (Used by prep_operands procedure and the ASL Compiler)
218 */
219
220
221#define ARGI_ACCESSFIELD_OP ARGI_INVALID_OPCODE
222#define ARGI_ACQUIRE_OP ARGI_LIST2 (ARGI_MUTEX, ARGI_INTEGER)
223#define ARGI_ADD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
224#define ARGI_ALIAS_OP ARGI_INVALID_OPCODE
225#define ARGI_ARG0 ARG_NONE
226#define ARGI_ARG1 ARG_NONE
227#define ARGI_ARG2 ARG_NONE
228#define ARGI_ARG3 ARG_NONE
229#define ARGI_ARG4 ARG_NONE
230#define ARGI_ARG5 ARG_NONE
231#define ARGI_ARG6 ARG_NONE
232#define ARGI_BANK_FIELD_OP ARGI_INVALID_OPCODE
233#define ARGI_BIT_AND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
234#define ARGI_BIT_NAND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
235#define ARGI_BIT_NOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
236#define ARGI_BIT_NOT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
237#define ARGI_BIT_OR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
238#define ARGI_BIT_XOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
239#define ARGI_BREAK_OP ARG_NONE
240#define ARGI_BREAK_POINT_OP ARG_NONE
241#define ARGI_BUFFER_OP ARGI_LIST1 (ARGI_INTEGER)
242#define ARGI_BYTE_OP ARGI_INVALID_OPCODE
243#define ARGI_BYTELIST_OP ARGI_INVALID_OPCODE
244#define ARGI_CONCAT_OP ARGI_LIST3 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA, ARGI_TARGETREF)
245#define ARGI_CONCAT_RES_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_BUFFER, ARGI_TARGETREF)
246#define ARGI_COND_REF_OF_OP ARGI_LIST2 (ARGI_OBJECT_REF, ARGI_TARGETREF)
247#define ARGI_CONTINUE_OP ARGI_INVALID_OPCODE
248#define ARGI_COPY_OP ARGI_LIST2 (ARGI_ANYTYPE, ARGI_SIMPLE_TARGET)
249#define ARGI_CREATE_BIT_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
250#define ARGI_CREATE_BYTE_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
251#define ARGI_CREATE_DWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
252#define ARGI_CREATE_FIELD_OP ARGI_LIST4 (ARGI_BUFFER, ARGI_INTEGER, ARGI_INTEGER, ARGI_REFERENCE)
253#define ARGI_CREATE_QWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
254#define ARGI_CREATE_WORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
255#define ARGI_DATA_REGION_OP ARGI_LIST3 (ARGI_STRING, ARGI_STRING, ARGI_STRING)
256#define ARGI_DEBUG_OP ARG_NONE
257#define ARGI_DECREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
258#define ARGI_DEREF_OF_OP ARGI_LIST1 (ARGI_REF_OR_STRING)
259#define ARGI_DEVICE_OP ARGI_INVALID_OPCODE
260#define ARGI_DIVIDE_OP ARGI_LIST4 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF, ARGI_TARGETREF)
261#define ARGI_DWORD_OP ARGI_INVALID_OPCODE
262#define ARGI_ELSE_OP ARGI_INVALID_OPCODE
263#define ARGI_EVENT_OP ARGI_INVALID_OPCODE
264#define ARGI_FATAL_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_INTEGER)
265#define ARGI_FIELD_OP ARGI_INVALID_OPCODE
266#define ARGI_FIND_SET_LEFT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
267#define ARGI_FIND_SET_RIGHT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
268#define ARGI_FROM_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
269#define ARGI_IF_OP ARGI_INVALID_OPCODE
270#define ARGI_INCREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
271#define ARGI_INDEX_FIELD_OP ARGI_INVALID_OPCODE
272#define ARGI_INDEX_OP ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER, ARGI_TARGETREF)
273#define ARGI_LAND_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
274#define ARGI_LEQUAL_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
275#define ARGI_LGREATER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
276#define ARGI_LGREATEREQUAL_OP ARGI_INVALID_OPCODE
277#define ARGI_LLESS_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
278#define ARGI_LLESSEQUAL_OP ARGI_INVALID_OPCODE
279#define ARGI_LNOT_OP ARGI_LIST1 (ARGI_INTEGER)
280#define ARGI_LNOTEQUAL_OP ARGI_INVALID_OPCODE
281#define ARGI_LOAD_OP ARGI_LIST2 (ARGI_REGION_OR_FIELD,ARGI_TARGETREF)
282#define ARGI_LOAD_TABLE_OP ARGI_LIST6 (ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_ANYTYPE)
283#define ARGI_LOCAL0 ARG_NONE
284#define ARGI_LOCAL1 ARG_NONE
285#define ARGI_LOCAL2 ARG_NONE
286#define ARGI_LOCAL3 ARG_NONE
287#define ARGI_LOCAL4 ARG_NONE
288#define ARGI_LOCAL5 ARG_NONE
289#define ARGI_LOCAL6 ARG_NONE
290#define ARGI_LOCAL7 ARG_NONE
291#define ARGI_LOR_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
292#define ARGI_MATCH_OP ARGI_LIST6 (ARGI_PACKAGE, ARGI_INTEGER, ARGI_COMPUTEDATA, ARGI_INTEGER,ARGI_COMPUTEDATA,ARGI_INTEGER)
293#define ARGI_METHOD_OP ARGI_INVALID_OPCODE
294#define ARGI_METHODCALL_OP ARGI_INVALID_OPCODE
295#define ARGI_MID_OP ARGI_LIST4 (ARGI_BUFFER_OR_STRING,ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
296#define ARGI_MOD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
297#define ARGI_MULTIPLY_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
298#define ARGI_MUTEX_OP ARGI_INVALID_OPCODE
299#define ARGI_NAME_OP ARGI_INVALID_OPCODE
300#define ARGI_NAMEDFIELD_OP ARGI_INVALID_OPCODE
301#define ARGI_NAMEPATH_OP ARGI_INVALID_OPCODE
302#define ARGI_NOOP_OP ARG_NONE
303#define ARGI_NOTIFY_OP ARGI_LIST2 (ARGI_DEVICE_REF, ARGI_INTEGER)
304#define ARGI_ONE_OP ARG_NONE
305#define ARGI_ONES_OP ARG_NONE
306#define ARGI_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
307#define ARGI_POWER_RES_OP ARGI_INVALID_OPCODE
308#define ARGI_PROCESSOR_OP ARGI_INVALID_OPCODE
309#define ARGI_QWORD_OP ARGI_INVALID_OPCODE
310#define ARGI_REF_OF_OP ARGI_LIST1 (ARGI_OBJECT_REF)
311#define ARGI_REGION_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
312#define ARGI_RELEASE_OP ARGI_LIST1 (ARGI_MUTEX)
313#define ARGI_RESERVEDFIELD_OP ARGI_INVALID_OPCODE
314#define ARGI_RESET_OP ARGI_LIST1 (ARGI_EVENT)
315#define ARGI_RETURN_OP ARGI_INVALID_OPCODE
316#define ARGI_REVISION_OP ARG_NONE
317#define ARGI_SCOPE_OP ARGI_INVALID_OPCODE
318#define ARGI_SHIFT_LEFT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
319#define ARGI_SHIFT_RIGHT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
320#define ARGI_SIGNAL_OP ARGI_LIST1 (ARGI_EVENT)
321#define ARGI_SIZE_OF_OP ARGI_LIST1 (ARGI_DATAOBJECT)
322#define ARGI_SLEEP_OP ARGI_LIST1 (ARGI_INTEGER)
323#define ARGI_STALL_OP ARGI_LIST1 (ARGI_INTEGER)
324#define ARGI_STATICSTRING_OP ARGI_INVALID_OPCODE
325#define ARGI_STORE_OP ARGI_LIST2 (ARGI_DATAREFOBJ, ARGI_TARGETREF)
326#define ARGI_STRING_OP ARGI_INVALID_OPCODE
327#define ARGI_SUBTRACT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
328#define ARGI_THERMAL_ZONE_OP ARGI_INVALID_OPCODE
329#define ARGI_TIMER_OP ARG_NONE
330#define ARGI_TO_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_FIXED_TARGET)
331#define ARGI_TO_BUFFER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
332#define ARGI_TO_DEC_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
333#define ARGI_TO_HEX_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
334#define ARGI_TO_INTEGER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
335#define ARGI_TO_STRING_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_FIXED_TARGET)
336#define ARGI_TYPE_OP ARGI_LIST1 (ARGI_ANYTYPE)
337#define ARGI_UNLOAD_OP ARGI_LIST1 (ARGI_DDBHANDLE)
338#define ARGI_VAR_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
339#define ARGI_WAIT_OP ARGI_LIST2 (ARGI_EVENT, ARGI_INTEGER)
340#define ARGI_WHILE_OP ARGI_INVALID_OPCODE
341#define ARGI_WORD_OP ARGI_INVALID_OPCODE
342#define ARGI_ZERO_OP ARG_NONE
343
344
345/* 66/*
346 * Summary of opcode types/flags 67 * Summary of opcode types/flags
347 */ 68 *
348
349/******************************************************************************
350 69
351 Opcodes that have associated namespace objects (AML_NSOBJECT flag) 70 Opcodes that have associated namespace objects (AML_NSOBJECT flag)
352 71
@@ -460,14 +179,13 @@
460 AML_CREATE_DWORD_FIELD_OP 179 AML_CREATE_DWORD_FIELD_OP
461 AML_CREATE_QWORD_FIELD_OP 180 AML_CREATE_QWORD_FIELD_OP
462 181
463******************************************************************************/ 182 ******************************************************************************/
464 183
465 184
466/* 185/*
467 * Master Opcode information table. A summary of everything we know about each opcode, all in one place. 186 * Master Opcode information table. A summary of everything we know about each
187 * opcode, all in one place.
468 */ 188 */
469
470
471const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = 189const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] =
472{ 190{
473/*! [Begin] no source code translation */ 191/*! [Begin] no source code translation */
@@ -693,8 +411,7 @@ static const u8 acpi_gbl_long_op_index[NUM_EXTENDED_OPCODE] =
693 * 411 *
694 * PARAMETERS: Opcode - The AML opcode 412 * PARAMETERS: Opcode - The AML opcode
695 * 413 *
696 * RETURN: A pointer to the info about the opcode. NULL if the opcode was 414 * RETURN: A pointer to the info about the opcode.
697 * not found in the table.
698 * 415 *
699 * DESCRIPTION: Find AML opcode description based on the opcode. 416 * DESCRIPTION: Find AML opcode description based on the opcode.
700 * NOTE: This procedure must ALWAYS return a valid pointer! 417 * NOTE: This procedure must ALWAYS return a valid pointer!
@@ -731,7 +448,8 @@ acpi_ps_get_opcode_info (
731 448
732 default: 449 default:
733 450
734 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown AML opcode [%4.4X]\n", opcode)); 451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
452 "Unknown AML opcode [%4.4X]\n", opcode));
735 break; 453 break;
736 } 454 }
737 455
diff --git a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
index e79edb53cb3b..bbfdc1a58c27 100644
--- a/drivers/acpi/parser/psparse.c
+++ b/drivers/acpi/parser/psparse.c
@@ -64,6 +64,23 @@
64 64
65static u32 acpi_gbl_depth = 0; 65static u32 acpi_gbl_depth = 0;
66 66
67/* Local prototypes */
68
69static void
70acpi_ps_complete_this_op (
71 struct acpi_walk_state *walk_state,
72 union acpi_parse_object *op);
73
74static acpi_status
75acpi_ps_next_parse_state (
76 struct acpi_walk_state *walk_state,
77 union acpi_parse_object *op,
78 acpi_status callback_status);
79
80static acpi_status
81acpi_ps_parse_loop (
82 struct acpi_walk_state *walk_state);
83
67 84
68/******************************************************************************* 85/*******************************************************************************
69 * 86 *
@@ -100,7 +117,7 @@ acpi_ps_get_opcode_size (
100 * 117 *
101 * PARAMETERS: parser_state - A parser state object 118 * PARAMETERS: parser_state - A parser state object
102 * 119 *
103 * RETURN: Status 120 * RETURN: Next AML opcode
104 * 121 *
105 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer) 122 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
106 * 123 *
@@ -117,7 +134,6 @@ acpi_ps_peek_opcode (
117 aml = parser_state->aml; 134 aml = parser_state->aml;
118 opcode = (u16) ACPI_GET8 (aml); 135 opcode = (u16) ACPI_GET8 (aml);
119 136
120
121 if (opcode == AML_EXTOP) { 137 if (opcode == AML_EXTOP) {
122 /* Extended opcode */ 138 /* Extended opcode */
123 139
@@ -142,7 +158,7 @@ acpi_ps_peek_opcode (
142 * 158 *
143 ******************************************************************************/ 159 ******************************************************************************/
144 160
145void 161static void
146acpi_ps_complete_this_op ( 162acpi_ps_complete_this_op (
147 struct acpi_walk_state *walk_state, 163 struct acpi_walk_state *walk_state,
148 union acpi_parse_object *op) 164 union acpi_parse_object *op)
@@ -272,7 +288,6 @@ acpi_ps_complete_this_op (
272 next = NULL; 288 next = NULL;
273 } 289 }
274 } 290 }
275
276 prev = next; 291 prev = next;
277 } 292 }
278 } 293 }
@@ -280,7 +295,7 @@ acpi_ps_complete_this_op (
280 295
281cleanup: 296cleanup:
282 297
283 /* Now we can actually delete the subtree rooted at op */ 298 /* Now we can actually delete the subtree rooted at Op */
284 299
285 acpi_ps_delete_parse_tree (op); 300 acpi_ps_delete_parse_tree (op);
286 return_VOID; 301 return_VOID;
@@ -291,7 +306,9 @@ cleanup:
291 * 306 *
292 * FUNCTION: acpi_ps_next_parse_state 307 * FUNCTION: acpi_ps_next_parse_state
293 * 308 *
294 * PARAMETERS: parser_state - Current parser state object 309 * PARAMETERS: walk_state - Current state
310 * Op - Current parse op
311 * callback_status - Status from previous operation
295 * 312 *
296 * RETURN: Status 313 * RETURN: Status
297 * 314 *
@@ -300,7 +317,7 @@ cleanup:
300 * 317 *
301 ******************************************************************************/ 318 ******************************************************************************/
302 319
303acpi_status 320static acpi_status
304acpi_ps_next_parse_state ( 321acpi_ps_next_parse_state (
305 struct acpi_walk_state *walk_state, 322 struct acpi_walk_state *walk_state,
306 union acpi_parse_object *op, 323 union acpi_parse_object *op,
@@ -382,9 +399,8 @@ acpi_ps_next_parse_state (
382 399
383 case AE_CTRL_TRANSFER: 400 case AE_CTRL_TRANSFER:
384 401
385 /* 402 /* A method call (invocation) -- transfer control */
386 * A method call (invocation) -- transfer control 403
387 */
388 status = AE_CTRL_TRANSFER; 404 status = AE_CTRL_TRANSFER;
389 walk_state->prev_op = op; 405 walk_state->prev_op = op;
390 walk_state->method_call_op = op; 406 walk_state->method_call_op = op;
@@ -397,6 +413,7 @@ acpi_ps_next_parse_state (
397 413
398 414
399 default: 415 default:
416
400 status = callback_status; 417 status = callback_status;
401 if ((callback_status & AE_CODE_MASK) == AE_CODE_CONTROL) { 418 if ((callback_status & AE_CODE_MASK) == AE_CODE_CONTROL) {
402 status = AE_OK; 419 status = AE_OK;
@@ -412,7 +429,7 @@ acpi_ps_next_parse_state (
412 * 429 *
413 * FUNCTION: acpi_ps_parse_loop 430 * FUNCTION: acpi_ps_parse_loop
414 * 431 *
415 * PARAMETERS: parser_state - Current parser state object 432 * PARAMETERS: walk_state - Current state
416 * 433 *
417 * RETURN: Status 434 * RETURN: Status
418 * 435 *
@@ -421,7 +438,7 @@ acpi_ps_next_parse_state (
421 * 438 *
422 ******************************************************************************/ 439 ******************************************************************************/
423 440
424acpi_status 441static acpi_status
425acpi_ps_parse_loop ( 442acpi_ps_parse_loop (
426 struct acpi_walk_state *walk_state) 443 struct acpi_walk_state *walk_state)
427{ 444{
@@ -443,6 +460,7 @@ acpi_ps_parse_loop (
443 walk_state->arg_types = 0; 460 walk_state->arg_types = 0;
444 461
445#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 462#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
463
446 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 464 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
447 /* We are restarting a preempted control method */ 465 /* We are restarting a preempted control method */
448 466
@@ -471,7 +489,8 @@ acpi_ps_parse_loop (
471 acpi_format_exception (status))); 489 acpi_format_exception (status)));
472 490
473 } 491 }
474 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "get_predicate Failed, %s\n", 492 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
493 "get_predicate Failed, %s\n",
475 acpi_format_exception (status))); 494 acpi_format_exception (status)));
476 return_ACPI_STATUS (status); 495 return_ACPI_STATUS (status);
477 } 496 }
@@ -492,16 +511,15 @@ acpi_ps_parse_loop (
492 } 511 }
493#endif 512#endif
494 513
495 /* 514 /* Iterative parsing loop, while there is more AML to process: */
496 * Iterative parsing loop, while there is more aml to process: 515
497 */
498 while ((parser_state->aml < parser_state->aml_end) || (op)) { 516 while ((parser_state->aml < parser_state->aml_end) || (op)) {
499 aml_op_start = parser_state->aml; 517 aml_op_start = parser_state->aml;
500 if (!op) { 518 if (!op) {
501 /* Get the next opcode from the AML stream */ 519 /* Get the next opcode from the AML stream */
502 520
503 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 521 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml,
504 parser_state->aml_start); 522 parser_state->aml_start);
505 walk_state->opcode = acpi_ps_peek_opcode (parser_state); 523 walk_state->opcode = acpi_ps_peek_opcode (parser_state);
506 524
507 /* 525 /*
@@ -578,8 +596,10 @@ acpi_ps_parse_loop (
578 INCREMENT_ARG_LIST (walk_state->arg_types); 596 INCREMENT_ARG_LIST (walk_state->arg_types);
579 } 597 }
580 598
581 /* Make sure that we found a NAME and didn't run out of arguments */ 599 /*
582 600 * Make sure that we found a NAME and didn't run out of
601 * arguments
602 */
583 if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) { 603 if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) {
584 status = AE_AML_NO_OPERAND; 604 status = AE_AML_NO_OPERAND;
585 goto close_this_op; 605 goto close_this_op;
@@ -597,12 +617,13 @@ acpi_ps_parse_loop (
597 617
598 status = walk_state->descending_callback (walk_state, &op); 618 status = walk_state->descending_callback (walk_state, &op);
599 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
600 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "During name lookup/catalog, %s\n", 620 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
601 acpi_format_exception (status))); 621 "During name lookup/catalog, %s\n",
622 acpi_format_exception (status)));
602 goto close_this_op; 623 goto close_this_op;
603 } 624 }
604 625
605 if (op == NULL) { 626 if (!op) {
606 continue; 627 continue;
607 } 628 }
608 629
@@ -659,7 +680,7 @@ acpi_ps_parse_loop (
659 680
660 if ((walk_state->descending_callback != NULL)) { 681 if ((walk_state->descending_callback != NULL)) {
661 /* 682 /*
662 * Find the object. This will either insert the object into 683 * Find the object. This will either insert the object into
663 * the namespace or simply look it up 684 * the namespace or simply look it up
664 */ 685 */
665 walk_state->op = op; 686 walk_state->op = op;
@@ -688,11 +709,15 @@ acpi_ps_parse_loop (
688 } 709 }
689 710
690 711
691 /* Start arg_count at zero because we don't know if there are any args yet */ 712 /*
692 713 * Start arg_count at zero because we don't know if there are
714 * any args yet
715 */
693 walk_state->arg_count = 0; 716 walk_state->arg_count = 0;
694 717
695 if (walk_state->arg_types) /* Are there any arguments that must be processed? */ { 718 /* Are there any arguments that must be processed? */
719
720 if (walk_state->arg_types) {
696 /* Get arguments */ 721 /* Get arguments */
697 722
698 switch (op->common.aml_opcode) { 723 switch (op->common.aml_opcode) {
@@ -720,14 +745,18 @@ acpi_ps_parse_loop (
720 745
721 default: 746 default:
722 747
723 /* Op is not a constant or string, append each argument to the Op */ 748 /*
724 749 * Op is not a constant or string, append each argument
750 * to the Op
751 */
725 while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 752 while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) &&
726 !walk_state->arg_count) { 753 !walk_state->arg_count) {
727 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 754 walk_state->aml_offset = (u32)
728 parser_state->aml_start); 755 ACPI_PTR_DIFF (parser_state->aml, parser_state->aml_start);
756
729 status = acpi_ps_get_next_arg (walk_state, parser_state, 757 status = acpi_ps_get_next_arg (walk_state, parser_state,
730 GET_CURRENT_ARG_TYPE (walk_state->arg_types), &arg); 758 GET_CURRENT_ARG_TYPE (walk_state->arg_types),
759 &arg);
731 if (ACPI_FAILURE (status)) { 760 if (ACPI_FAILURE (status)) {
732 goto close_this_op; 761 goto close_this_op;
733 } 762 }
@@ -752,7 +781,8 @@ acpi_ps_parse_loop (
752 * Save the length and address of the body 781 * Save the length and address of the body
753 */ 782 */
754 op->named.data = parser_state->aml; 783 op->named.data = parser_state->aml;
755 op->named.length = (u32) (parser_state->pkg_end - parser_state->aml); 784 op->named.length = (u32) (parser_state->pkg_end -
785 parser_state->aml);
756 786
757 /* Skip body of method */ 787 /* Skip body of method */
758 788
@@ -773,7 +803,8 @@ acpi_ps_parse_loop (
773 * to parse them correctly. 803 * to parse them correctly.
774 */ 804 */
775 op->named.data = aml_op_start; 805 op->named.data = aml_op_start;
776 op->named.length = (u32) (parser_state->pkg_end - aml_op_start); 806 op->named.length = (u32) (parser_state->pkg_end -
807 aml_op_start);
777 808
778 /* Skip body */ 809 /* Skip body */
779 810
@@ -785,7 +816,8 @@ acpi_ps_parse_loop (
785 case AML_WHILE_OP: 816 case AML_WHILE_OP:
786 817
787 if (walk_state->control_state) { 818 if (walk_state->control_state) {
788 walk_state->control_state->control.package_end = parser_state->pkg_end; 819 walk_state->control_state->control.package_end =
820 parser_state->pkg_end;
789 } 821 }
790 break; 822 break;
791 823
@@ -801,8 +833,10 @@ acpi_ps_parse_loop (
801 /* Check for arguments that need to be processed */ 833 /* Check for arguments that need to be processed */
802 834
803 if (walk_state->arg_count) { 835 if (walk_state->arg_count) {
804 /* There are arguments (complex ones), push Op and prepare for argument */ 836 /*
805 837 * There are arguments (complex ones), push Op and
838 * prepare for argument
839 */
806 status = acpi_ps_push_scope (parser_state, op, 840 status = acpi_ps_push_scope (parser_state, op,
807 walk_state->arg_types, walk_state->arg_count); 841 walk_state->arg_types, walk_state->arg_count);
808 if (ACPI_FAILURE (status)) { 842 if (ACPI_FAILURE (status)) {
@@ -812,8 +846,10 @@ acpi_ps_parse_loop (
812 continue; 846 continue;
813 } 847 }
814 848
815 /* All arguments have been processed -- Op is complete, prepare for next */ 849 /*
816 850 * All arguments have been processed -- Op is complete,
851 * prepare for next
852 */
817 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 853 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
818 if (walk_state->op_info->flags & AML_NAMED) { 854 if (walk_state->op_info->flags & AML_NAMED) {
819 if (acpi_gbl_depth) { 855 if (acpi_gbl_depth) {
@@ -880,9 +916,8 @@ close_this_op:
880 916
881 case AE_CTRL_TRANSFER: 917 case AE_CTRL_TRANSFER:
882 918
883 /* 919 /* We are about to transfer to a called method. */
884 * We are about to transfer to a called method. 920
885 */
886 walk_state->prev_op = op; 921 walk_state->prev_op = op;
887 walk_state->prev_arg_types = walk_state->arg_types; 922 walk_state->prev_arg_types = walk_state->arg_types;
888 return_ACPI_STATUS (status); 923 return_ACPI_STATUS (status);
@@ -1051,10 +1086,7 @@ close_this_op:
1051 * 1086 *
1052 * FUNCTION: acpi_ps_parse_aml 1087 * FUNCTION: acpi_ps_parse_aml
1053 * 1088 *
1054 * PARAMETERS: start_scope - The starting point of the parse. Becomes the 1089 * PARAMETERS: walk_state - Current state
1055 * root of the parsed op tree.
1056 * Aml - Pointer to the raw AML code to parse
1057 * aml_size - Length of the AML to parse
1058 * 1090 *
1059 * 1091 *
1060 * RETURN: Status 1092 * RETURN: Status
@@ -1076,8 +1108,10 @@ acpi_ps_parse_aml (
1076 1108
1077 ACPI_FUNCTION_TRACE ("ps_parse_aml"); 1109 ACPI_FUNCTION_TRACE ("ps_parse_aml");
1078 1110
1079 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Entered with walk_state=%p Aml=%p size=%X\n", 1111 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1080 walk_state, walk_state->parser_state.aml, walk_state->parser_state.aml_size)); 1112 "Entered with walk_state=%p Aml=%p size=%X\n",
1113 walk_state, walk_state->parser_state.aml,
1114 walk_state->parser_state.aml_size));
1081 1115
1082 1116
1083 /* Create and initialize a new thread state */ 1117 /* Create and initialize a new thread state */
@@ -1142,9 +1176,10 @@ acpi_ps_parse_aml (
1142 if ((status == AE_ALREADY_EXISTS) && 1176 if ((status == AE_ALREADY_EXISTS) &&
1143 (!walk_state->method_desc->method.semaphore)) { 1177 (!walk_state->method_desc->method.semaphore)) {
1144 /* 1178 /*
1145 * This method is marked not_serialized, but it tried to create a named 1179 * This method is marked not_serialized, but it tried to create
1146 * object, causing the second thread entrance to fail. We will workaround 1180 * a named object, causing the second thread entrance to fail.
1147 * this by marking the method permanently as Serialized. 1181 * We will workaround this by marking the method permanently
1182 * as Serialized.
1148 */ 1183 */
1149 walk_state->method_desc->method.method_flags |= AML_METHOD_SERIALIZED; 1184 walk_state->method_desc->method.method_flags |= AML_METHOD_SERIALIZED;
1150 walk_state->method_desc->method.concurrency = 1; 1185 walk_state->method_desc->method.concurrency = 1;
@@ -1187,7 +1222,8 @@ acpi_ps_parse_aml (
1187 1222
1188 previous_walk_state = walk_state; 1223 previous_walk_state = walk_state;
1189 1224
1190 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "return_value=%p, implicit_value=%p State=%p\n", 1225 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1226 "return_value=%p, implicit_value=%p State=%p\n",
1191 walk_state->return_desc, walk_state->implicit_return_obj, walk_state)); 1227 walk_state->return_desc, walk_state->implicit_return_obj, walk_state));
1192 1228
1193 /* Check if we have restarted a preempted walk */ 1229 /* Check if we have restarted a preempted walk */
@@ -1231,12 +1267,14 @@ acpi_ps_parse_aml (
1231 */ 1267 */
1232 else if (previous_walk_state->caller_return_desc) { 1268 else if (previous_walk_state->caller_return_desc) {
1233 if (previous_walk_state->implicit_return_obj) { 1269 if (previous_walk_state->implicit_return_obj) {
1234 *(previous_walk_state->caller_return_desc) = previous_walk_state->implicit_return_obj; 1270 *(previous_walk_state->caller_return_desc) =
1271 previous_walk_state->implicit_return_obj;
1235 } 1272 }
1236 else { 1273 else {
1237 /* NULL if no return value */ 1274 /* NULL if no return value */
1238 1275
1239 *(previous_walk_state->caller_return_desc) = previous_walk_state->return_desc; 1276 *(previous_walk_state->caller_return_desc) =
1277 previous_walk_state->return_desc;
1240 } 1278 }
1241 } 1279 }
1242 else { 1280 else {
diff --git a/drivers/acpi/parser/psscope.c b/drivers/acpi/parser/psscope.c
index dcbed49608b0..8dcd1b1e7131 100644
--- a/drivers/acpi/parser/psscope.c
+++ b/drivers/acpi/parser/psscope.c
@@ -65,6 +65,7 @@ union acpi_parse_object *
65acpi_ps_get_parent_scope ( 65acpi_ps_get_parent_scope (
66 struct acpi_parse_state *parser_state) 66 struct acpi_parse_state *parser_state)
67{ 67{
68
68 return (parser_state->scope->parse_scope.op); 69 return (parser_state->scope->parse_scope.op);
69} 70}
70 71
@@ -87,8 +88,10 @@ u8
87acpi_ps_has_completed_scope ( 88acpi_ps_has_completed_scope (
88 struct acpi_parse_state *parser_state) 89 struct acpi_parse_state *parser_state)
89{ 90{
90 return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end || 91
91 !parser_state->scope->parse_scope.arg_count))); 92 return ((u8)
93 ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
94 !parser_state->scope->parse_scope.arg_count)));
92} 95}
93 96
94 97
@@ -167,23 +170,23 @@ acpi_ps_push_scope (
167 return_ACPI_STATUS (AE_NO_MEMORY); 170 return_ACPI_STATUS (AE_NO_MEMORY);
168 } 171 }
169 172
170 scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE; 173 scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE;
171 scope->parse_scope.op = op; 174 scope->parse_scope.op = op;
172 scope->parse_scope.arg_list = remaining_args; 175 scope->parse_scope.arg_list = remaining_args;
173 scope->parse_scope.arg_count = arg_count; 176 scope->parse_scope.arg_count = arg_count;
174 scope->parse_scope.pkg_end = parser_state->pkg_end; 177 scope->parse_scope.pkg_end = parser_state->pkg_end;
175 178
176 /* Push onto scope stack */ 179 /* Push onto scope stack */
177 180
178 acpi_ut_push_generic_state (&parser_state->scope, scope); 181 acpi_ut_push_generic_state (&parser_state->scope, scope);
179 182
180 if (arg_count == ACPI_VAR_ARGS) { 183 if (arg_count == ACPI_VAR_ARGS) {
181 /* multiple arguments */ 184 /* Multiple arguments */
182 185
183 scope->parse_scope.arg_end = parser_state->pkg_end; 186 scope->parse_scope.arg_end = parser_state->pkg_end;
184 } 187 }
185 else { 188 else {
186 /* single argument */ 189 /* Single argument */
187 190
188 scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR); 191 scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR);
189 } 192 }
@@ -221,18 +224,17 @@ acpi_ps_pop_scope (
221 ACPI_FUNCTION_TRACE ("ps_pop_scope"); 224 ACPI_FUNCTION_TRACE ("ps_pop_scope");
222 225
223 226
224 /* 227 /* Only pop the scope if there is in fact a next scope */
225 * Only pop the scope if there is in fact a next scope 228
226 */
227 if (scope->common.next) { 229 if (scope->common.next) {
228 scope = acpi_ut_pop_generic_state (&parser_state->scope); 230 scope = acpi_ut_pop_generic_state (&parser_state->scope);
229 231
230 /* return to parsing previous op */ 232 /* return to parsing previous op */
231 233
232 *op = scope->parse_scope.op; 234 *op = scope->parse_scope.op;
233 *arg_list = scope->parse_scope.arg_list; 235 *arg_list = scope->parse_scope.arg_list;
234 *arg_count = scope->parse_scope.arg_count; 236 *arg_count = scope->parse_scope.arg_count;
235 parser_state->pkg_end = scope->parse_scope.pkg_end; 237 parser_state->pkg_end = scope->parse_scope.pkg_end;
236 238
237 /* All done with this scope state structure */ 239 /* All done with this scope state structure */
238 240
@@ -241,12 +243,13 @@ acpi_ps_pop_scope (
241 else { 243 else {
242 /* empty parse stack, prepare to fetch next opcode */ 244 /* empty parse stack, prepare to fetch next opcode */
243 245
244 *op = NULL; 246 *op = NULL;
245 *arg_list = 0; 247 *arg_list = 0;
246 *arg_count = 0; 248 *arg_count = 0;
247 } 249 }
248 250
249 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped Op %p Args %X\n", *op, *arg_count)); 251 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
252 "Popped Op %p Args %X\n", *op, *arg_count));
250 return_VOID; 253 return_VOID;
251} 254}
252 255
@@ -257,7 +260,7 @@ acpi_ps_pop_scope (
257 * 260 *
258 * PARAMETERS: parser_state - Current parser state object 261 * PARAMETERS: parser_state - Current parser state object
259 * 262 *
260 * RETURN: Status 263 * RETURN: None
261 * 264 *
262 * DESCRIPTION: Destroy available list, remaining stack levels, and return 265 * DESCRIPTION: Destroy available list, remaining stack levels, and return
263 * root scope 266 * root scope
diff --git a/drivers/acpi/parser/pstree.c b/drivers/acpi/parser/pstree.c
index 2140bd1ac10b..d5aafe73fca0 100644
--- a/drivers/acpi/parser/pstree.c
+++ b/drivers/acpi/parser/pstree.c
@@ -49,6 +49,14 @@
49#define _COMPONENT ACPI_PARSER 49#define _COMPONENT ACPI_PARSER
50 ACPI_MODULE_NAME ("pstree") 50 ACPI_MODULE_NAME ("pstree")
51 51
52/* Local prototypes */
53
54#ifdef ACPI_OBSOLETE_FUNCTIONS
55union acpi_parse_object *
56acpi_ps_get_child (
57 union acpi_parse_object *op);
58#endif
59
52 60
53/******************************************************************************* 61/*******************************************************************************
54 * 62 *
@@ -57,7 +65,7 @@
57 * PARAMETERS: Op - Get an argument for this op 65 * PARAMETERS: Op - Get an argument for this op
58 * Argn - Nth argument to get 66 * Argn - Nth argument to get
59 * 67 *
60 * RETURN: The argument (as an Op object). NULL if argument does not exist 68 * RETURN: The argument (as an Op object). NULL if argument does not exist
61 * 69 *
62 * DESCRIPTION: Get the specified op's argument. 70 * DESCRIPTION: Get the specified op's argument.
63 * 71 *
@@ -152,7 +160,6 @@ acpi_ps_append_arg (
152 return; 160 return;
153 } 161 }
154 162
155
156 /* Append the argument to the linked argument list */ 163 /* Append the argument to the linked argument list */
157 164
158 if (op->common.value.arg) { 165 if (op->common.value.arg) {
@@ -164,14 +171,12 @@ acpi_ps_append_arg (
164 } 171 }
165 prev_arg->common.next = arg; 172 prev_arg->common.next = arg;
166 } 173 }
167
168 else { 174 else {
169 /* No argument list, this will be the first argument */ 175 /* No argument list, this will be the first argument */
170 176
171 op->common.value.arg = arg; 177 op->common.value.arg = arg;
172 } 178 }
173 179
174
175 /* Set the parent in this arg and any args linked after it */ 180 /* Set the parent in this arg and any args linked after it */
176 181
177 while (arg) { 182 while (arg) {
@@ -182,73 +187,6 @@ acpi_ps_append_arg (
182 187
183 188
184#ifdef ACPI_FUTURE_USAGE 189#ifdef ACPI_FUTURE_USAGE
185
186/*******************************************************************************
187 *
188 * FUNCTION: acpi_ps_get_child
189 *
190 * PARAMETERS: Op - Get the child of this Op
191 *
192 * RETURN: Child Op, Null if none is found.
193 *
194 * DESCRIPTION: Get op's children or NULL if none
195 *
196 ******************************************************************************/
197union acpi_parse_object *
198acpi_ps_get_child (
199 union acpi_parse_object *op)
200{
201 union acpi_parse_object *child = NULL;
202
203
204 ACPI_FUNCTION_ENTRY ();
205
206
207 switch (op->common.aml_opcode) {
208 case AML_SCOPE_OP:
209 case AML_ELSE_OP:
210 case AML_DEVICE_OP:
211 case AML_THERMAL_ZONE_OP:
212 case AML_INT_METHODCALL_OP:
213
214 child = acpi_ps_get_arg (op, 0);
215 break;
216
217
218 case AML_BUFFER_OP:
219 case AML_PACKAGE_OP:
220 case AML_METHOD_OP:
221 case AML_IF_OP:
222 case AML_WHILE_OP:
223 case AML_FIELD_OP:
224
225 child = acpi_ps_get_arg (op, 1);
226 break;
227
228
229 case AML_POWER_RES_OP:
230 case AML_INDEX_FIELD_OP:
231
232 child = acpi_ps_get_arg (op, 2);
233 break;
234
235
236 case AML_PROCESSOR_OP:
237 case AML_BANK_FIELD_OP:
238
239 child = acpi_ps_get_arg (op, 3);
240 break;
241
242
243 default:
244 /* All others have no children */
245 break;
246 }
247
248 return (child);
249}
250
251
252/******************************************************************************* 190/*******************************************************************************
253 * 191 *
254 * FUNCTION: acpi_ps_get_depth_next 192 * FUNCTION: acpi_ps_get_depth_next
@@ -280,21 +218,21 @@ acpi_ps_get_depth_next (
280 return (NULL); 218 return (NULL);
281 } 219 }
282 220
283 /* look for an argument or child */ 221 /* Look for an argument or child */
284 222
285 next = acpi_ps_get_arg (op, 0); 223 next = acpi_ps_get_arg (op, 0);
286 if (next) { 224 if (next) {
287 return (next); 225 return (next);
288 } 226 }
289 227
290 /* look for a sibling */ 228 /* Look for a sibling */
291 229
292 next = op->common.next; 230 next = op->common.next;
293 if (next) { 231 if (next) {
294 return (next); 232 return (next);
295 } 233 }
296 234
297 /* look for a sibling of parent */ 235 /* Look for a sibling of parent */
298 236
299 parent = op->common.parent; 237 parent = op->common.parent;
300 238
@@ -305,13 +243,13 @@ acpi_ps_get_depth_next (
305 } 243 }
306 244
307 if (arg == origin) { 245 if (arg == origin) {
308 /* reached parent of origin, end search */ 246 /* Reached parent of origin, end search */
309 247
310 return (NULL); 248 return (NULL);
311 } 249 }
312 250
313 if (parent->common.next) { 251 if (parent->common.next) {
314 /* found sibling of parent */ 252 /* Found sibling of parent */
315 253
316 return (parent->common.next); 254 return (parent->common.next);
317 } 255 }
@@ -323,5 +261,74 @@ acpi_ps_get_depth_next (
323 return (next); 261 return (next);
324} 262}
325 263
264
265#ifdef ACPI_OBSOLETE_FUNCTIONS
266/*******************************************************************************
267 *
268 * FUNCTION: acpi_ps_get_child
269 *
270 * PARAMETERS: Op - Get the child of this Op
271 *
272 * RETURN: Child Op, Null if none is found.
273 *
274 * DESCRIPTION: Get op's children or NULL if none
275 *
276 ******************************************************************************/
277
278union acpi_parse_object *
279acpi_ps_get_child (
280 union acpi_parse_object *op)
281{
282 union acpi_parse_object *child = NULL;
283
284
285 ACPI_FUNCTION_ENTRY ();
286
287
288 switch (op->common.aml_opcode) {
289 case AML_SCOPE_OP:
290 case AML_ELSE_OP:
291 case AML_DEVICE_OP:
292 case AML_THERMAL_ZONE_OP:
293 case AML_INT_METHODCALL_OP:
294
295 child = acpi_ps_get_arg (op, 0);
296 break;
297
298
299 case AML_BUFFER_OP:
300 case AML_PACKAGE_OP:
301 case AML_METHOD_OP:
302 case AML_IF_OP:
303 case AML_WHILE_OP:
304 case AML_FIELD_OP:
305
306 child = acpi_ps_get_arg (op, 1);
307 break;
308
309
310 case AML_POWER_RES_OP:
311 case AML_INDEX_FIELD_OP:
312
313 child = acpi_ps_get_arg (op, 2);
314 break;
315
316
317 case AML_PROCESSOR_OP:
318 case AML_BANK_FIELD_OP:
319
320 child = acpi_ps_get_arg (op, 3);
321 break;
322
323
324 default:
325 /* All others have no children */
326 break;
327 }
328
329 return (child);
330}
331#endif
332
326#endif /* ACPI_FUTURE_USAGE */ 333#endif /* ACPI_FUTURE_USAGE */
327 334
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index b3597cb19f88..a10f88715d43 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -45,7 +45,6 @@
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acparser.h> 46#include <acpi/acparser.h>
47#include <acpi/amlcode.h> 47#include <acpi/amlcode.h>
48#include <acpi/acnamesp.h>
49 48
50#define _COMPONENT ACPI_PARSER 49#define _COMPONENT ACPI_PARSER
51 ACPI_MODULE_NAME ("psutils") 50 ACPI_MODULE_NAME ("psutils")
@@ -57,7 +56,7 @@
57 * 56 *
58 * PARAMETERS: None 57 * PARAMETERS: None
59 * 58 *
60 * RETURN: scope_op 59 * RETURN: A new Scope object, null on failure
61 * 60 *
62 * DESCRIPTION: Create a Scope and associated namepath op with the root name 61 * DESCRIPTION: Create a Scope and associated namepath op with the root name
63 * 62 *
@@ -75,7 +74,6 @@ acpi_ps_create_scope_op (
75 return (NULL); 74 return (NULL);
76 } 75 }
77 76
78
79 scope_op->named.name = ACPI_ROOT_NAME; 77 scope_op->named.name = ACPI_ROOT_NAME;
80 return (scope_op); 78 return (scope_op);
81} 79}
@@ -88,10 +86,9 @@ acpi_ps_create_scope_op (
88 * PARAMETERS: Op - A newly allocated Op object 86 * PARAMETERS: Op - A newly allocated Op object
89 * Opcode - Opcode to store in the Op 87 * Opcode - Opcode to store in the Op
90 * 88 *
91 * RETURN: Status 89 * RETURN: None
92 * 90 *
93 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 91 * DESCRIPTION: Initialize a parse (Op) object
94 * opcode
95 * 92 *
96 ******************************************************************************/ 93 ******************************************************************************/
97 94
@@ -107,7 +104,8 @@ acpi_ps_init_op (
107 op->common.aml_opcode = opcode; 104 op->common.aml_opcode = opcode;
108 105
109 ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (op->common.aml_op_name, 106 ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (op->common.aml_op_name,
110 (acpi_ps_get_opcode_info (opcode))->name, sizeof (op->common.aml_op_name))); 107 (acpi_ps_get_opcode_info (opcode))->name,
108 sizeof (op->common.aml_op_name)));
111} 109}
112 110
113 111
@@ -117,7 +115,7 @@ acpi_ps_init_op (
117 * 115 *
118 * PARAMETERS: Opcode - Opcode that will be stored in the new Op 116 * PARAMETERS: Opcode - Opcode that will be stored in the new Op
119 * 117 *
120 * RETURN: Pointer to the new Op. 118 * RETURN: Pointer to the new Op, null on failure
121 * 119 *
122 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 120 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
123 * opcode. A cache of opcodes is available for the pure 121 * opcode. A cache of opcodes is available for the pure
@@ -275,7 +273,6 @@ acpi_ps_get_name (
275 union acpi_parse_object *op) 273 union acpi_parse_object *op)
276{ 274{
277 275
278
279 /* The "generic" object has no name associated with it */ 276 /* The "generic" object has no name associated with it */
280 277
281 if (op->common.flags & ACPI_PARSEOP_GENERIC) { 278 if (op->common.flags & ACPI_PARSEOP_GENERIC) {
diff --git a/drivers/acpi/parser/pswalk.c b/drivers/acpi/parser/pswalk.c
index 110d2ce917b6..9d20cb2ceb51 100644
--- a/drivers/acpi/parser/pswalk.c
+++ b/drivers/acpi/parser/pswalk.c
@@ -90,17 +90,15 @@ acpi_ps_delete_parse_tree (
90 } 90 }
91 } 91 }
92 92
93 /* 93 /* No more children, this Op is complete. */
94 * No more children, this Op is complete. 94
95 */
96 next = op->common.next; 95 next = op->common.next;
97 parent = op->common.parent; 96 parent = op->common.parent;
98 97
99 acpi_ps_free_op (op); 98 acpi_ps_free_op (op);
100 99
101 /* 100 /* If we are back to the starting point, the walk is complete. */
102 * If we are back to the starting point, the walk is complete. 101
103 */
104 if (op == subtree_root) { 102 if (op == subtree_root) {
105 return_VOID; 103 return_VOID;
106 } 104 }
@@ -111,5 +109,6 @@ acpi_ps_delete_parse_tree (
111 op = parent; 109 op = parent;
112 } 110 }
113 } 111 }
112
114 return_VOID; 113 return_VOID;
115} 114}
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
index b318ad24726d..dba893648e84 100644
--- a/drivers/acpi/parser/psxface.c
+++ b/drivers/acpi/parser/psxface.c
@@ -57,13 +57,16 @@
57 * 57 *
58 * FUNCTION: acpi_psx_execute 58 * FUNCTION: acpi_psx_execute
59 * 59 *
60 * PARAMETERS: Info->Node - A method object containing both the AML 60 * PARAMETERS: Info - Method info block, contains:
61 * address and length. 61 * Node - Method Node to execute
62 * **Params - List of parameters to pass to method, 62 * Parameters - List of parameters to pass to the method,
63 * terminated by NULL. Params itself may be 63 * terminated by NULL. Params itself may be
64 * NULL if no parameters are being passed. 64 * NULL if no parameters are being passed.
65 * **return_obj_desc - Return object from execution of the 65 * return_object - Where to put method's return value (if
66 * method. 66 * any). If NULL, no value is returned.
67 * parameter_type - Type of Parameter list
68 * return_object - Where to put method's return value (if
69 * any). If NULL, no value is returned.
67 * 70 *
68 * RETURN: Status 71 * RETURN: Status
69 * 72 *
@@ -196,9 +199,8 @@ acpi_psx_execute (
196 goto cleanup3; 199 goto cleanup3;
197 } 200 }
198 201
199 /* 202 /* The walk of the parse tree is where we actually execute the method */
200 * The walk of the parse tree is where we actually execute the method 203
201 */
202 status = acpi_ps_parse_aml (walk_state); 204 status = acpi_ps_parse_aml (walk_state);
203 goto cleanup2; /* Walk state already deleted */ 205 goto cleanup2; /* Walk state already deleted */
204 206
@@ -217,7 +219,8 @@ cleanup1:
217 for (i = 0; info->parameters[i]; i++) { 219 for (i = 0; info->parameters[i]; i++) {
218 /* Ignore errors, just do them all */ 220 /* Ignore errors, just do them all */
219 221
220 (void) acpi_ut_update_object_reference (info->parameters[i], REF_DECREMENT); 222 (void) acpi_ut_update_object_reference (
223 info->parameters[i], REF_DECREMENT);
221 } 224 }
222 } 225 }
223 226
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 5d19b39e9e2b..5148f3c10b5c 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -61,15 +61,14 @@ acpi_pci_data_handler (
61 61
62 62
63/** 63/**
64 * acpi_os_get_pci_id 64 * acpi_get_pci_id
65 * ------------------ 65 * ------------------
66 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem) 66 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
67 * to resolve PCI information for ACPI-PCI devices defined in the namespace. 67 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
68 * This typically occurs when resolving PCI operation region information. 68 * This typically occurs when resolving PCI operation region information.
69 */ 69 */
70#ifdef ACPI_FUTURE_USAGE
71acpi_status 70acpi_status
72acpi_os_get_pci_id ( 71acpi_get_pci_id (
73 acpi_handle handle, 72 acpi_handle handle,
74 struct acpi_pci_id *id) 73 struct acpi_pci_id *id)
75{ 74{
@@ -78,7 +77,7 @@ acpi_os_get_pci_id (
78 struct acpi_device *device = NULL; 77 struct acpi_device *device = NULL;
79 struct acpi_pci_data *data = NULL; 78 struct acpi_pci_data *data = NULL;
80 79
81 ACPI_FUNCTION_TRACE("acpi_os_get_pci_id"); 80 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
82 81
83 if (!id) 82 if (!id)
84 return_ACPI_STATUS(AE_BAD_PARAMETER); 83 return_ACPI_STATUS(AE_BAD_PARAMETER);
@@ -92,7 +91,7 @@ acpi_os_get_pci_id (
92 } 91 }
93 92
94 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data); 93 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data);
95 if (ACPI_FAILURE(status) || !data || !data->dev) { 94 if (ACPI_FAILURE(status) || !data) {
96 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 95 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
97 "Invalid ACPI-PCI context for device %s\n", 96 "Invalid ACPI-PCI context for device %s\n",
98 acpi_device_bid(device))); 97 acpi_device_bid(device)));
@@ -115,7 +114,7 @@ acpi_os_get_pci_id (
115 114
116 return_ACPI_STATUS(AE_OK); 115 return_ACPI_STATUS(AE_OK);
117} 116}
118#endif /* ACPI_FUTURE_USAGE */ 117EXPORT_SYMBOL(acpi_get_pci_id);
119 118
120 119
121int 120int
@@ -129,6 +128,8 @@ acpi_pci_bind (
129 char *pathname = NULL; 128 char *pathname = NULL;
130 struct acpi_buffer buffer = {0, NULL}; 129 struct acpi_buffer buffer = {0, NULL};
131 acpi_handle handle = NULL; 130 acpi_handle handle = NULL;
131 struct pci_dev *dev;
132 struct pci_bus *bus;
132 133
133 ACPI_FUNCTION_TRACE("acpi_pci_bind"); 134 ACPI_FUNCTION_TRACE("acpi_pci_bind");
134 135
@@ -193,8 +194,20 @@ acpi_pci_bind (
193 * Locate matching device in PCI namespace. If it doesn't exist 194 * Locate matching device in PCI namespace. If it doesn't exist
194 * this typically means that the device isn't currently inserted 195 * this typically means that the device isn't currently inserted
195 * (e.g. docking station, port replicator, etc.). 196 * (e.g. docking station, port replicator, etc.).
197 * We cannot simply search the global pci device list, since
198 * PCI devices are added to the global pci list when the root
199 * bridge start ops are run, which may not have happened yet.
196 */ 200 */
197 data->dev = pci_find_slot(data->id.bus, PCI_DEVFN(data->id.device, data->id.function)); 201 bus = pci_find_bus(data->id.segment, data->id.bus);
202 if (bus) {
203 list_for_each_entry(dev, &bus->devices, bus_list) {
204 if (dev->devfn == PCI_DEVFN(data->id.device,
205 data->id.function)) {
206 data->dev = dev;
207 break;
208 }
209 }
210 }
198 if (!data->dev) { 211 if (!data->dev) {
199 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 212 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
200 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n", 213 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index 8dbf802ee7f8..d1f42b972821 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -433,7 +433,7 @@ acpi_pci_irq_enable (
433 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI", 433 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
434 pci_name(dev), ('A' + pin)); 434 pci_name(dev), ('A' + pin));
435 /* Interrupt Line values above 0xF are forbidden */ 435 /* Interrupt Line values above 0xF are forbidden */
436 if (dev->irq >= 0 && (dev->irq <= 0xF)) { 436 if (dev->irq > 0 && (dev->irq <= 0xF)) {
437 printk(" - using IRQ %d\n", dev->irq); 437 printk(" - using IRQ %d\n", dev->irq);
438 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW); 438 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
439 return_VALUE(0); 439 return_VALUE(0);
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 520b28ad0740..6ad0e77df9b3 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -72,10 +72,12 @@ struct acpi_pci_link_irq {
72 u8 active; /* Current IRQ */ 72 u8 active; /* Current IRQ */
73 u8 edge_level; /* All IRQs */ 73 u8 edge_level; /* All IRQs */
74 u8 active_high_low; /* All IRQs */ 74 u8 active_high_low; /* All IRQs */
75 u8 initialized;
76 u8 resource_type; 75 u8 resource_type;
77 u8 possible_count; 76 u8 possible_count;
78 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; 77 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
78 u8 initialized:1;
79 u8 suspend_resume:1;
80 u8 reserved:6;
79}; 81};
80 82
81struct acpi_pci_link { 83struct acpi_pci_link {
@@ -530,6 +532,10 @@ static int acpi_pci_link_allocate(
530 532
531 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate"); 533 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
532 534
535 if (link->irq.suspend_resume) {
536 acpi_pci_link_set(link, link->irq.active);
537 link->irq.suspend_resume = 0;
538 }
533 if (link->irq.initialized) 539 if (link->irq.initialized)
534 return_VALUE(0); 540 return_VALUE(0);
535 541
@@ -713,38 +719,24 @@ end:
713 return_VALUE(result); 719 return_VALUE(result);
714} 720}
715 721
716
717static int
718acpi_pci_link_resume (
719 struct acpi_pci_link *link)
720{
721 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
722
723 if (link->irq.active && link->irq.initialized)
724 return_VALUE(acpi_pci_link_set(link, link->irq.active));
725 else
726 return_VALUE(0);
727}
728
729
730static int 722static int
731irqrouter_resume( 723irqrouter_suspend(
732 struct sys_device *dev) 724 struct sys_device *dev,
725 u32 state)
733{ 726{
734 struct list_head *node = NULL; 727 struct list_head *node = NULL;
735 struct acpi_pci_link *link = NULL; 728 struct acpi_pci_link *link = NULL;
736 729
737 ACPI_FUNCTION_TRACE("irqrouter_resume"); 730 ACPI_FUNCTION_TRACE("irqrouter_suspend");
738 731
739 list_for_each(node, &acpi_link.entries) { 732 list_for_each(node, &acpi_link.entries) {
740
741 link = list_entry(node, struct acpi_pci_link, node); 733 link = list_entry(node, struct acpi_pci_link, node);
742 if (!link) { 734 if (!link) {
743 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
744 continue; 736 continue;
745 } 737 }
746 738 if (link->irq.active && link->irq.initialized)
747 acpi_pci_link_resume(link); 739 link->irq.suspend_resume = 1;
748 } 740 }
749 return_VALUE(0); 741 return_VALUE(0);
750} 742}
@@ -812,9 +804,12 @@ static int __init acpi_irq_penalty_update(char *str, int used)
812 * There is no ISA_POSSIBLE weight, so we simply use 804 * There is no ISA_POSSIBLE weight, so we simply use
813 * the (small) PCI_USING penalty. 805 * the (small) PCI_USING penalty.
814 */ 806 */
815void acpi_penalize_isa_irq(int irq) 807void acpi_penalize_isa_irq(int irq, int active)
816{ 808{
817 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; 809 if (active)
810 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
811 else
812 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
818} 813}
819 814
820/* 815/*
@@ -856,7 +851,7 @@ __setup("acpi_irq_balance", acpi_irq_balance_set);
856 851
857static struct sysdev_class irqrouter_sysdev_class = { 852static struct sysdev_class irqrouter_sysdev_class = {
858 set_kset_name("irqrouter"), 853 set_kset_name("irqrouter"),
859 .resume = irqrouter_resume, 854 .suspend = irqrouter_suspend,
860}; 855};
861 856
862 857
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 7e6b8e3b2ed4..5d2f77fcd50c 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -46,6 +46,7 @@ ACPI_MODULE_NAME ("pci_root")
46 46
47static int acpi_pci_root_add (struct acpi_device *device); 47static int acpi_pci_root_add (struct acpi_device *device);
48static int acpi_pci_root_remove (struct acpi_device *device, int type); 48static int acpi_pci_root_remove (struct acpi_device *device, int type);
49static int acpi_pci_root_start (struct acpi_device *device);
49 50
50static struct acpi_driver acpi_pci_root_driver = { 51static struct acpi_driver acpi_pci_root_driver = {
51 .name = ACPI_PCI_ROOT_DRIVER_NAME, 52 .name = ACPI_PCI_ROOT_DRIVER_NAME,
@@ -54,6 +55,7 @@ static struct acpi_driver acpi_pci_root_driver = {
54 .ops = { 55 .ops = {
55 .add = acpi_pci_root_add, 56 .add = acpi_pci_root_add,
56 .remove = acpi_pci_root_remove, 57 .remove = acpi_pci_root_remove,
58 .start = acpi_pci_root_start,
57 }, 59 },
58}; 60};
59 61
@@ -169,6 +171,7 @@ acpi_pci_root_add (
169 if (!root) 171 if (!root)
170 return_VALUE(-ENOMEM); 172 return_VALUE(-ENOMEM);
171 memset(root, 0, sizeof(struct acpi_pci_root)); 173 memset(root, 0, sizeof(struct acpi_pci_root));
174 INIT_LIST_HEAD(&root->node);
172 175
173 root->handle = device->handle; 176 root->handle = device->handle;
174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 177 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
@@ -298,12 +301,31 @@ acpi_pci_root_add (
298 root->id.bus); 301 root->id.bus);
299 302
300end: 303end:
301 if (result) 304 if (result) {
305 if (!list_empty(&root->node))
306 list_del(&root->node);
302 kfree(root); 307 kfree(root);
308 }
303 309
304 return_VALUE(result); 310 return_VALUE(result);
305} 311}
306 312
313static int
314acpi_pci_root_start (
315 struct acpi_device *device)
316{
317 struct acpi_pci_root *root;
318
319 ACPI_FUNCTION_TRACE("acpi_pci_root_start");
320
321 list_for_each_entry(root, &acpi_pci_roots, node) {
322 if (root->handle == device->handle) {
323 pci_bus_add_devices(root->bus);
324 return_VALUE(0);
325 }
326 }
327 return_VALUE(-ENODEV);
328}
307 329
308static int 330static int
309acpi_pci_root_remove ( 331acpi_pci_root_remove (
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index f4778747e889..d56a439ac614 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -256,6 +256,43 @@ acpi_processor_errata (
256 256
257 257
258/* -------------------------------------------------------------------------- 258/* --------------------------------------------------------------------------
259 Common ACPI processor fucntions
260 -------------------------------------------------------------------------- */
261
262/*
263 * _PDC is required for a BIOS-OS handshake for most of the newer
264 * ACPI processor features.
265 */
266
267int acpi_processor_set_pdc(struct acpi_processor *pr,
268 struct acpi_object_list *pdc_in)
269{
270 acpi_status status = AE_OK;
271 u32 arg0_buf[3];
272 union acpi_object arg0 = {ACPI_TYPE_BUFFER};
273 struct acpi_object_list no_object = {1, &arg0};
274 struct acpi_object_list *pdc;
275
276 ACPI_FUNCTION_TRACE("acpi_processor_set_pdc");
277
278 arg0.buffer.length = 12;
279 arg0.buffer.pointer = (u8 *) arg0_buf;
280 arg0_buf[0] = ACPI_PDC_REVISION_ID;
281 arg0_buf[1] = 0;
282 arg0_buf[2] = 0;
283
284 pdc = (pdc_in) ? pdc_in : &no_object;
285
286 status = acpi_evaluate_object(pr->handle, "_PDC", pdc, NULL);
287
288 if ((ACPI_FAILURE(status)) && (pdc_in))
289 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Error evaluating _PDC, using legacy perf. control...\n"));
290
291 return_VALUE(status);
292}
293
294
295/* --------------------------------------------------------------------------
259 FS Interface (/proc) 296 FS Interface (/proc)
260 -------------------------------------------------------------------------- */ 297 -------------------------------------------------------------------------- */
261 298
@@ -723,7 +760,7 @@ int acpi_processor_device_add(
723 return_VALUE(-ENODEV); 760 return_VALUE(-ENODEV);
724 } 761 }
725 762
726 acpi_bus_scan(*device); 763 acpi_bus_start(*device);
727 764
728 pr = acpi_driver_data(*device); 765 pr = acpi_driver_data(*device);
729 if (!pr) 766 if (!pr)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index c9d671cf7857..893b074e3d1a 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -6,6 +6,8 @@
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> 6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support 8 * - Added processor hotplug support
9 * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
10 * - Added support for C3 on SMP
9 * 11 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 * 13 *
@@ -142,7 +144,7 @@ acpi_processor_power_activate (
142 switch (old->type) { 144 switch (old->type) {
143 case ACPI_STATE_C3: 145 case ACPI_STATE_C3:
144 /* Disable bus master reload */ 146 /* Disable bus master reload */
145 if (new->type != ACPI_STATE_C3) 147 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
146 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK); 148 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK);
147 break; 149 break;
148 } 150 }
@@ -152,7 +154,7 @@ acpi_processor_power_activate (
152 switch (new->type) { 154 switch (new->type) {
153 case ACPI_STATE_C3: 155 case ACPI_STATE_C3:
154 /* Enable bus master reload */ 156 /* Enable bus master reload */
155 if (old->type != ACPI_STATE_C3) 157 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
156 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK); 158 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK);
157 break; 159 break;
158 } 160 }
@@ -163,6 +165,9 @@ acpi_processor_power_activate (
163} 165}
164 166
165 167
168static atomic_t c3_cpu_count;
169
170
166static void acpi_processor_idle (void) 171static void acpi_processor_idle (void)
167{ 172{
168 struct acpi_processor *pr = NULL; 173 struct acpi_processor *pr = NULL;
@@ -297,8 +302,22 @@ static void acpi_processor_idle (void)
297 break; 302 break;
298 303
299 case ACPI_STATE_C3: 304 case ACPI_STATE_C3:
300 /* Disable bus master arbitration */ 305
301 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK); 306 if (pr->flags.bm_check) {
307 if (atomic_inc_return(&c3_cpu_count) ==
308 num_online_cpus()) {
309 /*
310 * All CPUs are trying to go to C3
311 * Disable bus master arbitration
312 */
313 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
314 ACPI_MTX_DO_NOT_LOCK);
315 }
316 } else {
317 /* SMP with no shared cache... Invalidate cache */
318 ACPI_FLUSH_CPU_CACHE();
319 }
320
302 /* Get start time (ticks) */ 321 /* Get start time (ticks) */
303 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 322 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
304 /* Invoke C3 */ 323 /* Invoke C3 */
@@ -307,8 +326,12 @@ static void acpi_processor_idle (void)
307 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 326 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
308 /* Get end time (ticks) */ 327 /* Get end time (ticks) */
309 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 328 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
310 /* Enable bus master arbitration */ 329 if (pr->flags.bm_check) {
311 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK); 330 /* Enable bus master arbitration */
331 atomic_dec(&c3_cpu_count);
332 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
333 }
334
312 /* Re-enable interrupts */ 335 /* Re-enable interrupts */
313 local_irq_enable(); 336 local_irq_enable();
314 /* Compute time (ticks) that we were actually asleep */ 337 /* Compute time (ticks) that we were actually asleep */
@@ -519,6 +542,29 @@ static int acpi_processor_get_power_info_fadt (struct acpi_processor *pr)
519} 542}
520 543
521 544
545static int acpi_processor_get_power_info_default_c1 (struct acpi_processor *pr)
546{
547 int i;
548
549 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
550
551 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
552 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx));
553
554 /* if info is obtained from pblk/fadt, type equals state */
555 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
556 pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
557 pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
558
559 /* the C0 state only exists as a filler in our array,
560 * and all processors need to support C1 */
561 pr->power.states[ACPI_STATE_C0].valid = 1;
562 pr->power.states[ACPI_STATE_C1].valid = 1;
563
564 return_VALUE(0);
565}
566
567
522static int acpi_processor_get_power_info_cst (struct acpi_processor *pr) 568static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
523{ 569{
524 acpi_status status = 0; 570 acpi_status status = 0;
@@ -529,9 +575,6 @@ static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
529 575
530 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_cst"); 576 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_cst");
531 577
532 if (errata.smp)
533 return_VALUE(-ENODEV);
534
535 if (nocst) 578 if (nocst)
536 return_VALUE(-ENODEV); 579 return_VALUE(-ENODEV);
537 580
@@ -664,13 +707,6 @@ static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
664 return_VOID; 707 return_VOID;
665 } 708 }
666 709
667 /* We're (currently) only supporting C2 on UP */
668 else if (errata.smp) {
669 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
670 "C2 not supported in SMP mode\n"));
671 return_VOID;
672 }
673
674 /* 710 /*
675 * Otherwise we've met all of our C2 requirements. 711 * Otherwise we've met all of our C2 requirements.
676 * Normalize the C2 latency to expidite policy 712 * Normalize the C2 latency to expidite policy
@@ -686,6 +722,8 @@ static void acpi_processor_power_verify_c3(
686 struct acpi_processor *pr, 722 struct acpi_processor *pr,
687 struct acpi_processor_cx *cx) 723 struct acpi_processor_cx *cx)
688{ 724{
725 static int bm_check_flag;
726
689 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c3"); 727 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c3");
690 728
691 if (!cx->address) 729 if (!cx->address)
@@ -702,20 +740,6 @@ static void acpi_processor_power_verify_c3(
702 return_VOID; 740 return_VOID;
703 } 741 }
704 742
705 /* bus mastering control is necessary */
706 else if (!pr->flags.bm_control) {
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
708 "C3 support requires bus mastering control\n"));
709 return_VOID;
710 }
711
712 /* We're (currently) only supporting C2 on UP */
713 else if (errata.smp) {
714 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
715 "C3 not supported in SMP mode\n"));
716 return_VOID;
717 }
718
719 /* 743 /*
720 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast) 744 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
721 * DMA transfers are used by any ISA device to avoid livelock. 745 * DMA transfers are used by any ISA device to avoid livelock.
@@ -729,6 +753,39 @@ static void acpi_processor_power_verify_c3(
729 return_VOID; 753 return_VOID;
730 } 754 }
731 755
756 /* All the logic here assumes flags.bm_check is same across all CPUs */
757 if (!bm_check_flag) {
758 /* Determine whether bm_check is needed based on CPU */
759 acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
760 bm_check_flag = pr->flags.bm_check;
761 } else {
762 pr->flags.bm_check = bm_check_flag;
763 }
764
765 if (pr->flags.bm_check) {
766 printk("Disabling BM access before entering C3\n");
767 /* bus mastering control is necessary */
768 if (!pr->flags.bm_control) {
769 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
770 "C3 support requires bus mastering control\n"));
771 return_VOID;
772 }
773 } else {
774 printk("Invalidating cache before entering C3\n");
775 /*
776 * WBINVD should be set in fadt, for C3 state to be
777 * supported on when bm_check is not required.
778 */
779 if (acpi_fadt.wb_invd != 1) {
780 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
781 "Cache invalidation should work properly"
782 " for C3 to be enabled on SMP systems\n"));
783 return_VOID;
784 }
785 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD,
786 0, ACPI_MTX_DO_NOT_LOCK);
787 }
788
732 /* 789 /*
733 * Otherwise we've met all of our C3 requirements. 790 * Otherwise we've met all of our C3 requirements.
734 * Normalize the C3 latency to expidite policy. Enable 791 * Normalize the C3 latency to expidite policy. Enable
@@ -737,7 +794,6 @@ static void acpi_processor_power_verify_c3(
737 */ 794 */
738 cx->valid = 1; 795 cx->valid = 1;
739 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); 796 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
740 pr->flags.bm_check = 1;
741 797
742 return_VOID; 798 return_VOID;
743} 799}
@@ -787,10 +843,7 @@ static int acpi_processor_get_power_info (
787 if ((result) || (acpi_processor_power_verify(pr) < 2)) { 843 if ((result) || (acpi_processor_power_verify(pr) < 2)) {
788 result = acpi_processor_get_power_info_fadt(pr); 844 result = acpi_processor_get_power_info_fadt(pr);
789 if (result) 845 if (result)
790 return_VALUE(result); 846 result = acpi_processor_get_power_info_default_c1(pr);
791
792 if (acpi_processor_power_verify(pr) < 2)
793 return_VALUE(-ENODEV);
794 } 847 }
795 848
796 /* 849 /*
@@ -810,11 +863,10 @@ static int acpi_processor_get_power_info (
810 * CPU as being "idle manageable" 863 * CPU as being "idle manageable"
811 */ 864 */
812 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { 865 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
813 if (pr->power.states[i].valid) 866 if (pr->power.states[i].valid) {
814 pr->power.count = i; 867 pr->power.count = i;
815 if ((pr->power.states[i].valid) &&
816 (pr->power.states[i].type >= ACPI_STATE_C2))
817 pr->flags.power = 1; 868 pr->flags.power = 1;
869 }
818 } 870 }
819 871
820 return_VALUE(0); 872 return_VALUE(0);
@@ -829,7 +881,7 @@ int acpi_processor_cst_has_changed (struct acpi_processor *pr)
829 if (!pr) 881 if (!pr)
830 return_VALUE(-EINVAL); 882 return_VALUE(-EINVAL);
831 883
832 if (errata.smp || nocst) { 884 if ( nocst) {
833 return_VALUE(-ENODEV); 885 return_VALUE(-ENODEV);
834 } 886 }
835 887
@@ -929,7 +981,6 @@ static struct file_operations acpi_processor_power_fops = {
929 .release = single_release, 981 .release = single_release,
930}; 982};
931 983
932
933int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *device) 984int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *device)
934{ 985{
935 acpi_status status = 0; 986 acpi_status status = 0;
@@ -946,7 +997,10 @@ int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *dev
946 first_run++; 997 first_run++;
947 } 998 }
948 999
949 if (!errata.smp && (pr->id == 0) && acpi_fadt.cst_cnt && !nocst) { 1000 if (!pr)
1001 return_VALUE(-EINVAL);
1002
1003 if (acpi_fadt.cst_cnt && !nocst) {
950 status = acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8); 1004 status = acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8);
951 if (ACPI_FAILURE(status)) { 1005 if (ACPI_FAILURE(status)) {
952 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1006 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
@@ -954,6 +1008,8 @@ int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *dev
954 } 1008 }
955 } 1009 }
956 1010
1011 acpi_processor_power_init_pdc(&(pr->power), pr->id);
1012 acpi_processor_set_pdc(pr, pr->power.pdc);
957 acpi_processor_get_power_info(pr); 1013 acpi_processor_get_power_info(pr);
958 1014
959 /* 1015 /*
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index a9a1a8fe3199..1f0d6256302f 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -165,37 +165,6 @@ void acpi_processor_ppc_exit(void) {
165 acpi_processor_ppc_status &= ~PPC_REGISTERED; 165 acpi_processor_ppc_status &= ~PPC_REGISTERED;
166} 166}
167 167
168/*
169 * when registering a cpufreq driver with this ACPI processor driver, the
170 * _PCT and _PSS structures are read out and written into struct
171 * acpi_processor_performance.
172 */
173static int acpi_processor_set_pdc (struct acpi_processor *pr)
174{
175 acpi_status status = AE_OK;
176 u32 arg0_buf[3];
177 union acpi_object arg0 = {ACPI_TYPE_BUFFER};
178 struct acpi_object_list no_object = {1, &arg0};
179 struct acpi_object_list *pdc;
180
181 ACPI_FUNCTION_TRACE("acpi_processor_set_pdc");
182
183 arg0.buffer.length = 12;
184 arg0.buffer.pointer = (u8 *) arg0_buf;
185 arg0_buf[0] = ACPI_PDC_REVISION_ID;
186 arg0_buf[1] = 0;
187 arg0_buf[2] = 0;
188
189 pdc = (pr->performance->pdc) ? pr->performance->pdc : &no_object;
190
191 status = acpi_evaluate_object(pr->handle, "_PDC", pdc, NULL);
192
193 if ((ACPI_FAILURE(status)) && (pr->performance->pdc))
194 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Error evaluating _PDC, using legacy perf. control...\n"));
195
196 return_VALUE(status);
197}
198
199 168
200static int 169static int
201acpi_processor_get_performance_control ( 170acpi_processor_get_performance_control (
@@ -357,7 +326,7 @@ acpi_processor_get_performance_info (
357 if (!pr || !pr->performance || !pr->handle) 326 if (!pr || !pr->performance || !pr->handle)
358 return_VALUE(-EINVAL); 327 return_VALUE(-EINVAL);
359 328
360 acpi_processor_set_pdc(pr); 329 acpi_processor_set_pdc(pr, pr->performance->pdc);
361 330
362 status = acpi_get_handle(pr->handle, "_PCT", &handle); 331 status = acpi_get_handle(pr->handle, "_PCT", &handle);
363 if (ACPI_FAILURE(status)) { 332 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/resources/rsaddr.c b/drivers/acpi/resources/rsaddr.c
index 4788c079735d..55d264771c48 100644
--- a/drivers/acpi/resources/rsaddr.c
+++ b/drivers/acpi/resources/rsaddr.c
@@ -77,21 +77,21 @@ acpi_rs_address16_resource (
77 u8 **output_buffer, 77 u8 **output_buffer,
78 acpi_size *structure_size) 78 acpi_size *structure_size)
79{ 79{
80 u8 *buffer = byte_stream_buffer;
81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u8 *temp_ptr;
83 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16);
84 u32 index; 80 u32 index;
85 u16 temp16; 81 u16 temp16;
86 u8 temp8; 82 u8 temp8;
83 u8 *temp_ptr;
84 u8 *buffer = byte_stream_buffer;
85 struct acpi_resource *output_struct = (void *) *output_buffer;
86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
87 struct acpi_resource_address16);
87 88
88 89
89 ACPI_FUNCTION_TRACE ("rs_address16_resource"); 90 ACPI_FUNCTION_TRACE ("rs_address16_resource");
90 91
91 92
92 /* 93 /* Point past the Descriptor to get the number of bytes consumed */
93 * Point past the Descriptor to get the number of bytes consumed 94
94 */
95 buffer += 1; 95 buffer += 1;
96 ACPI_MOVE_16_TO_16 (&temp16, buffer); 96 ACPI_MOVE_16_TO_16 (&temp16, buffer);
97 97
@@ -104,9 +104,8 @@ acpi_rs_address16_resource (
104 *bytes_consumed = temp16 + 3; 104 *bytes_consumed = temp16 + 3;
105 output_struct->id = ACPI_RSTYPE_ADDRESS16; 105 output_struct->id = ACPI_RSTYPE_ADDRESS16;
106 106
107 /* 107 /* Get the Resource Type (Byte3) */
108 * Get the Resource Type (Byte3) 108
109 */
110 buffer += 2; 109 buffer += 2;
111 temp8 = *buffer; 110 temp8 = *buffer;
112 111
@@ -118,9 +117,8 @@ acpi_rs_address16_resource (
118 117
119 output_struct->data.address16.resource_type = temp8; 118 output_struct->data.address16.resource_type = temp8;
120 119
121 /* 120 /* Get the General Flags (Byte4) */
122 * Get the General Flags (Byte4) 121
123 */
124 buffer += 1; 122 buffer += 1;
125 temp8 = *buffer; 123 temp8 = *buffer;
126 124
@@ -140,9 +138,8 @@ acpi_rs_address16_resource (
140 138
141 output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01; 139 output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01;
142 140
143 /* 141 /* Get the Type Specific Flags (Byte5) */
144 * Get the Type Specific Flags (Byte5) 142
145 */
146 buffer += 1; 143 buffer += 1;
147 temp8 = *buffer; 144 temp8 = *buffer;
148 145
@@ -165,39 +162,34 @@ acpi_rs_address16_resource (
165 } 162 }
166 } 163 }
167 164
168 /* 165 /* Get Granularity (Bytes 6-7) */
169 * Get Granularity (Bytes 6-7) 166
170 */
171 buffer += 1; 167 buffer += 1;
172 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.granularity, buffer); 168 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.granularity, buffer);
173 169
174 /* 170 /* Get min_address_range (Bytes 8-9) */
175 * Get min_address_range (Bytes 8-9) 171
176 */
177 buffer += 2; 172 buffer += 2;
178 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.min_address_range, buffer); 173 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.min_address_range, buffer);
179 174
180 /* 175 /* Get max_address_range (Bytes 10-11) */
181 * Get max_address_range (Bytes 10-11) 176
182 */
183 buffer += 2; 177 buffer += 2;
184 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.max_address_range, buffer); 178 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.max_address_range, buffer);
185 179
186 /* 180 /* Get address_translation_offset (Bytes 12-13) */
187 * Get address_translation_offset (Bytes 12-13) 181
188 */
189 buffer += 2; 182 buffer += 2;
190 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_translation_offset, buffer); 183 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_translation_offset,
184 buffer);
185
186 /* Get address_length (Bytes 14-15) */
191 187
192 /*
193 * Get address_length (Bytes 14-15)
194 */
195 buffer += 2; 188 buffer += 2;
196 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_length, buffer); 189 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_length, buffer);
197 190
198 /* 191 /* Resource Source Index (if present) */
199 * Resource Source Index (if present) 192
200 */
201 buffer += 2; 193 buffer += 2;
202 194
203 /* 195 /*
@@ -225,7 +217,8 @@ acpi_rs_address16_resource (
225 output_struct->data.address16.resource_source.string_ptr = 217 output_struct->data.address16.resource_source.string_ptr =
226 (char *)((u8 * )output_struct + struct_size); 218 (char *)((u8 * )output_struct + struct_size);
227 219
228 temp_ptr = (u8 *) output_struct->data.address16.resource_source.string_ptr; 220 temp_ptr = (u8 *)
221 output_struct->data.address16.resource_source.string_ptr;
229 222
230 /* Copy the string into the buffer */ 223 /* Copy the string into the buffer */
231 224
@@ -239,9 +232,8 @@ acpi_rs_address16_resource (
239 index += 1; 232 index += 1;
240 } 233 }
241 234
242 /* 235 /* Add the terminating null */
243 * Add the terminating null 236
244 */
245 *temp_ptr = 0x00; 237 *temp_ptr = 0x00;
246 238
247 output_struct->data.address16.resource_source.string_length = index + 1; 239 output_struct->data.address16.resource_source.string_length = index + 1;
@@ -260,14 +252,12 @@ acpi_rs_address16_resource (
260 output_struct->data.address16.resource_source.string_ptr = NULL; 252 output_struct->data.address16.resource_source.string_ptr = NULL;
261 } 253 }
262 254
263 /* 255 /* Set the Length parameter */
264 * Set the Length parameter 256
265 */
266 output_struct->length = (u32) struct_size; 257 output_struct->length = (u32) struct_size;
267 258
268 /* 259 /* Return the final size of the structure */
269 * Return the final size of the structure 260
270 */
271 *structure_size = struct_size; 261 *structure_size = struct_size;
272 return_ACPI_STATUS (AE_OK); 262 return_ACPI_STATUS (AE_OK);
273} 263}
@@ -305,28 +295,24 @@ acpi_rs_address16_stream (
305 ACPI_FUNCTION_TRACE ("rs_address16_stream"); 295 ACPI_FUNCTION_TRACE ("rs_address16_stream");
306 296
307 297
308 /* 298 /* The descriptor field is static */
309 * The descriptor field is static 299
310 */
311 *buffer = 0x88; 300 *buffer = 0x88;
312 buffer += 1; 301 buffer += 1;
313 302
314 /* 303 /* Save a pointer to the Length field - to be filled in later */
315 * Save a pointer to the Length field - to be filled in later 304
316 */
317 length_field = buffer; 305 length_field = buffer;
318 buffer += 2; 306 buffer += 2;
319 307
320 /* 308 /* Set the Resource Type (Memory, Io, bus_number) */
321 * Set the Resource Type (Memory, Io, bus_number) 309
322 */
323 temp8 = (u8) (linked_list->data.address16.resource_type & 0x03); 310 temp8 = (u8) (linked_list->data.address16.resource_type & 0x03);
324 *buffer = temp8; 311 *buffer = temp8;
325 buffer += 1; 312 buffer += 1;
326 313
327 /* 314 /* Set the general flags */
328 * Set the general flags 315
329 */
330 temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01); 316 temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01);
331 317
332 temp8 |= (linked_list->data.address16.decode & 0x01) << 1; 318 temp8 |= (linked_list->data.address16.decode & 0x01) << 1;
@@ -336,9 +322,8 @@ acpi_rs_address16_stream (
336 *buffer = temp8; 322 *buffer = temp8;
337 buffer += 1; 323 buffer += 1;
338 324
339 /* 325 /* Set the type specific flags */
340 * Set the type specific flags 326
341 */
342 temp8 = 0; 327 temp8 = 0;
343 328
344 if (ACPI_MEMORY_RANGE == linked_list->data.address16.resource_type) { 329 if (ACPI_MEMORY_RANGE == linked_list->data.address16.resource_type) {
@@ -362,39 +347,34 @@ acpi_rs_address16_stream (
362 *buffer = temp8; 347 *buffer = temp8;
363 buffer += 1; 348 buffer += 1;
364 349
365 /* 350 /* Set the address space granularity */
366 * Set the address space granularity 351
367 */
368 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.granularity); 352 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.granularity);
369 buffer += 2; 353 buffer += 2;
370 354
371 /* 355 /* Set the address range minimum */
372 * Set the address range minimum 356
373 */
374 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.min_address_range); 357 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.min_address_range);
375 buffer += 2; 358 buffer += 2;
376 359
377 /* 360 /* Set the address range maximum */
378 * Set the address range maximum 361
379 */
380 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.max_address_range); 362 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.max_address_range);
381 buffer += 2; 363 buffer += 2;
382 364
383 /* 365 /* Set the address translation offset */
384 * Set the address translation offset 366
385 */ 367 ACPI_MOVE_32_TO_16 (buffer,
386 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_translation_offset); 368 &linked_list->data.address16.address_translation_offset);
387 buffer += 2; 369 buffer += 2;
388 370
389 /* 371 /* Set the address length */
390 * Set the address length 372
391 */
392 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_length); 373 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_length);
393 buffer += 2; 374 buffer += 2;
394 375
395 /* 376 /* Resource Source Index and Resource Source are optional */
396 * Resource Source Index and Resource Source are optional 377
397 */
398 if (0 != linked_list->data.address16.resource_source.string_length) { 378 if (0 != linked_list->data.address16.resource_source.string_length) {
399 temp8 = (u8) linked_list->data.address16.resource_source.index; 379 temp8 = (u8) linked_list->data.address16.resource_source.index;
400 380
@@ -403,9 +383,8 @@ acpi_rs_address16_stream (
403 383
404 temp_pointer = (char *) buffer; 384 temp_pointer = (char *) buffer;
405 385
406 /* 386 /* Copy the string */
407 * Copy the string 387
408 */
409 ACPI_STRCPY (temp_pointer, 388 ACPI_STRCPY (temp_pointer,
410 linked_list->data.address16.resource_source.string_ptr); 389 linked_list->data.address16.resource_source.string_ptr);
411 390
@@ -413,12 +392,12 @@ acpi_rs_address16_stream (
413 * Buffer needs to be set to the length of the sting + one for the 392 * Buffer needs to be set to the length of the sting + one for the
414 * terminating null 393 * terminating null
415 */ 394 */
416 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address16.resource_source.string_ptr) + 1); 395 buffer += (acpi_size)(ACPI_STRLEN (
396 linked_list->data.address16.resource_source.string_ptr) + 1);
417 } 397 }
418 398
419 /* 399 /* Return the number of bytes consumed in this operation */
420 * Return the number of bytes consumed in this operation 400
421 */
422 actual_bytes = ACPI_PTR_DIFF (buffer, *output_buffer); 401 actual_bytes = ACPI_PTR_DIFF (buffer, *output_buffer);
423 *bytes_consumed = actual_bytes; 402 *bytes_consumed = actual_bytes;
424 403
@@ -475,9 +454,8 @@ acpi_rs_address32_resource (
475 buffer = byte_stream_buffer; 454 buffer = byte_stream_buffer;
476 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32); 455 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32);
477 456
478 /* 457 /* Point past the Descriptor to get the number of bytes consumed */
479 * Point past the Descriptor to get the number of bytes consumed 458
480 */
481 buffer += 1; 459 buffer += 1;
482 ACPI_MOVE_16_TO_16 (&temp16, buffer); 460 ACPI_MOVE_16_TO_16 (&temp16, buffer);
483 461
@@ -490,9 +468,8 @@ acpi_rs_address32_resource (
490 *bytes_consumed = temp16 + 3; 468 *bytes_consumed = temp16 + 3;
491 output_struct->id = ACPI_RSTYPE_ADDRESS32; 469 output_struct->id = ACPI_RSTYPE_ADDRESS32;
492 470
493 /* 471 /* Get the Resource Type (Byte3) */
494 * Get the Resource Type (Byte3) 472
495 */
496 buffer += 2; 473 buffer += 2;
497 temp8 = *buffer; 474 temp8 = *buffer;
498 475
@@ -504,35 +481,29 @@ acpi_rs_address32_resource (
504 481
505 output_struct->data.address32.resource_type = temp8; 482 output_struct->data.address32.resource_type = temp8;
506 483
507 /* 484 /* Get the General Flags (Byte4) */
508 * Get the General Flags (Byte4) 485
509 */
510 buffer += 1; 486 buffer += 1;
511 temp8 = *buffer; 487 temp8 = *buffer;
512 488
513 /* 489 /* Producer / Consumer */
514 * Producer / Consumer 490
515 */
516 output_struct->data.address32.producer_consumer = temp8 & 0x01; 491 output_struct->data.address32.producer_consumer = temp8 & 0x01;
517 492
518 /* 493 /* Decode */
519 * Decode 494
520 */
521 output_struct->data.address32.decode = (temp8 >> 1) & 0x01; 495 output_struct->data.address32.decode = (temp8 >> 1) & 0x01;
522 496
523 /* 497 /* Min Address Fixed */
524 * Min Address Fixed 498
525 */
526 output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01; 499 output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01;
527 500
528 /* 501 /* Max Address Fixed */
529 * Max Address Fixed 502
530 */
531 output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01; 503 output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01;
532 504
533 /* 505 /* Get the Type Specific Flags (Byte5) */
534 * Get the Type Specific Flags (Byte5) 506
535 */
536 buffer += 1; 507 buffer += 1;
537 temp8 = *buffer; 508 temp8 = *buffer;
538 509
@@ -556,39 +527,34 @@ acpi_rs_address32_resource (
556 } 527 }
557 } 528 }
558 529
559 /* 530 /* Get Granularity (Bytes 6-9) */
560 * Get Granularity (Bytes 6-9) 531
561 */
562 buffer += 1; 532 buffer += 1;
563 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.granularity, buffer); 533 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.granularity, buffer);
564 534
565 /* 535 /* Get min_address_range (Bytes 10-13) */
566 * Get min_address_range (Bytes 10-13) 536
567 */
568 buffer += 4; 537 buffer += 4;
569 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.min_address_range, buffer); 538 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.min_address_range, buffer);
570 539
571 /* 540 /* Get max_address_range (Bytes 14-17) */
572 * Get max_address_range (Bytes 14-17) 541
573 */
574 buffer += 4; 542 buffer += 4;
575 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.max_address_range, buffer); 543 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.max_address_range, buffer);
576 544
577 /* 545 /* Get address_translation_offset (Bytes 18-21) */
578 * Get address_translation_offset (Bytes 18-21) 546
579 */
580 buffer += 4; 547 buffer += 4;
581 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_translation_offset, buffer); 548 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_translation_offset,
549 buffer);
550
551 /* Get address_length (Bytes 22-25) */
582 552
583 /*
584 * Get address_length (Bytes 22-25)
585 */
586 buffer += 4; 553 buffer += 4;
587 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_length, buffer); 554 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_length, buffer);
588 555
589 /* 556 /* Resource Source Index (if present) */
590 * Resource Source Index (if present) 557
591 */
592 buffer += 4; 558 buffer += 4;
593 559
594 /* 560 /*
@@ -615,7 +581,8 @@ acpi_rs_address32_resource (
615 output_struct->data.address32.resource_source.string_ptr = 581 output_struct->data.address32.resource_source.string_ptr =
616 (char *)((u8 *)output_struct + struct_size); 582 (char *)((u8 *)output_struct + struct_size);
617 583
618 temp_ptr = (u8 *) output_struct->data.address32.resource_source.string_ptr; 584 temp_ptr = (u8 *)
585 output_struct->data.address32.resource_source.string_ptr;
619 586
620 /* Copy the string into the buffer */ 587 /* Copy the string into the buffer */
621 588
@@ -628,9 +595,8 @@ acpi_rs_address32_resource (
628 index += 1; 595 index += 1;
629 } 596 }
630 597
631 /* 598 /* Add the terminating null */
632 * Add the terminating null 599
633 */
634 *temp_ptr = 0x00; 600 *temp_ptr = 0x00;
635 output_struct->data.address32.resource_source.string_length = index + 1; 601 output_struct->data.address32.resource_source.string_length = index + 1;
636 602
@@ -648,14 +614,12 @@ acpi_rs_address32_resource (
648 output_struct->data.address32.resource_source.string_ptr = NULL; 614 output_struct->data.address32.resource_source.string_ptr = NULL;
649 } 615 }
650 616
651 /* 617 /* Set the Length parameter */
652 * Set the Length parameter 618
653 */
654 output_struct->length = (u32) struct_size; 619 output_struct->length = (u32) struct_size;
655 620
656 /* 621 /* Return the final size of the structure */
657 * Return the final size of the structure 622
658 */
659 *structure_size = struct_size; 623 *structure_size = struct_size;
660 return_ACPI_STATUS (AE_OK); 624 return_ACPI_STATUS (AE_OK);
661} 625}
@@ -694,29 +658,25 @@ acpi_rs_address32_stream (
694 658
695 buffer = *output_buffer; 659 buffer = *output_buffer;
696 660
697 /* 661 /* The descriptor field is static */
698 * The descriptor field is static 662
699 */
700 *buffer = 0x87; 663 *buffer = 0x87;
701 buffer += 1; 664 buffer += 1;
702 665
703 /* 666 /* Set a pointer to the Length field - to be filled in later */
704 * Set a pointer to the Length field - to be filled in later 667
705 */
706 length_field = ACPI_CAST_PTR (u16, buffer); 668 length_field = ACPI_CAST_PTR (u16, buffer);
707 buffer += 2; 669 buffer += 2;
708 670
709 /* 671 /* Set the Resource Type (Memory, Io, bus_number) */
710 * Set the Resource Type (Memory, Io, bus_number) 672
711 */
712 temp8 = (u8) (linked_list->data.address32.resource_type & 0x03); 673 temp8 = (u8) (linked_list->data.address32.resource_type & 0x03);
713 674
714 *buffer = temp8; 675 *buffer = temp8;
715 buffer += 1; 676 buffer += 1;
716 677
717 /* 678 /* Set the general flags */
718 * Set the general flags 679
719 */
720 temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01); 680 temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01);
721 temp8 |= (linked_list->data.address32.decode & 0x01) << 1; 681 temp8 |= (linked_list->data.address32.decode & 0x01) << 1;
722 temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2; 682 temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2;
@@ -725,9 +685,8 @@ acpi_rs_address32_stream (
725 *buffer = temp8; 685 *buffer = temp8;
726 buffer += 1; 686 buffer += 1;
727 687
728 /* 688 /* Set the type specific flags */
729 * Set the type specific flags 689
730 */
731 temp8 = 0; 690 temp8 = 0;
732 691
733 if (ACPI_MEMORY_RANGE == linked_list->data.address32.resource_type) { 692 if (ACPI_MEMORY_RANGE == linked_list->data.address32.resource_type) {
@@ -751,39 +710,34 @@ acpi_rs_address32_stream (
751 *buffer = temp8; 710 *buffer = temp8;
752 buffer += 1; 711 buffer += 1;
753 712
754 /* 713 /* Set the address space granularity */
755 * Set the address space granularity 714
756 */
757 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.granularity); 715 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.granularity);
758 buffer += 4; 716 buffer += 4;
759 717
760 /* 718 /* Set the address range minimum */
761 * Set the address range minimum 719
762 */
763 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.min_address_range); 720 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.min_address_range);
764 buffer += 4; 721 buffer += 4;
765 722
766 /* 723 /* Set the address range maximum */
767 * Set the address range maximum 724
768 */
769 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.max_address_range); 725 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.max_address_range);
770 buffer += 4; 726 buffer += 4;
771 727
772 /* 728 /* Set the address translation offset */
773 * Set the address translation offset 729
774 */ 730 ACPI_MOVE_32_TO_32 (buffer,
775 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_translation_offset); 731 &linked_list->data.address32.address_translation_offset);
776 buffer += 4; 732 buffer += 4;
777 733
778 /* 734 /* Set the address length */
779 * Set the address length 735
780 */
781 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_length); 736 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_length);
782 buffer += 4; 737 buffer += 4;
783 738
784 /* 739 /* Resource Source Index and Resource Source are optional */
785 * Resource Source Index and Resource Source are optional 740
786 */
787 if (0 != linked_list->data.address32.resource_source.string_length) { 741 if (0 != linked_list->data.address32.resource_source.string_length) {
788 temp8 = (u8) linked_list->data.address32.resource_source.index; 742 temp8 = (u8) linked_list->data.address32.resource_source.index;
789 743
@@ -792,9 +746,8 @@ acpi_rs_address32_stream (
792 746
793 temp_pointer = (char *) buffer; 747 temp_pointer = (char *) buffer;
794 748
795 /* 749 /* Copy the string */
796 * Copy the string 750
797 */
798 ACPI_STRCPY (temp_pointer, 751 ACPI_STRCPY (temp_pointer,
799 linked_list->data.address32.resource_source.string_ptr); 752 linked_list->data.address32.resource_source.string_ptr);
800 753
@@ -802,12 +755,12 @@ acpi_rs_address32_stream (
802 * Buffer needs to be set to the length of the sting + one for the 755 * Buffer needs to be set to the length of the sting + one for the
803 * terminating null 756 * terminating null
804 */ 757 */
805 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address32.resource_source.string_ptr) + 1); 758 buffer += (acpi_size)(ACPI_STRLEN (
759 linked_list->data.address32.resource_source.string_ptr) + 1);
806 } 760 }
807 761
808 /* 762 /* Return the number of bytes consumed in this operation */
809 * Return the number of bytes consumed in this operation 763
810 */
811 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 764 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
812 765
813 /* 766 /*
@@ -864,9 +817,8 @@ acpi_rs_address64_resource (
864 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64); 817 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64);
865 resource_type = *buffer; 818 resource_type = *buffer;
866 819
867 /* 820 /* Point past the Descriptor to get the number of bytes consumed */
868 * Point past the Descriptor to get the number of bytes consumed 821
869 */
870 buffer += 1; 822 buffer += 1;
871 ACPI_MOVE_16_TO_16 (&temp16, buffer); 823 ACPI_MOVE_16_TO_16 (&temp16, buffer);
872 824
@@ -879,9 +831,8 @@ acpi_rs_address64_resource (
879 *bytes_consumed = temp16 + 3; 831 *bytes_consumed = temp16 + 3;
880 output_struct->id = ACPI_RSTYPE_ADDRESS64; 832 output_struct->id = ACPI_RSTYPE_ADDRESS64;
881 833
882 /* 834 /* Get the Resource Type (Byte3) */
883 * Get the Resource Type (Byte3) 835
884 */
885 buffer += 2; 836 buffer += 2;
886 temp8 = *buffer; 837 temp8 = *buffer;
887 838
@@ -893,35 +844,29 @@ acpi_rs_address64_resource (
893 844
894 output_struct->data.address64.resource_type = temp8; 845 output_struct->data.address64.resource_type = temp8;
895 846
896 /* 847 /* Get the General Flags (Byte4) */
897 * Get the General Flags (Byte4) 848
898 */
899 buffer += 1; 849 buffer += 1;
900 temp8 = *buffer; 850 temp8 = *buffer;
901 851
902 /* 852 /* Producer / Consumer */
903 * Producer / Consumer 853
904 */
905 output_struct->data.address64.producer_consumer = temp8 & 0x01; 854 output_struct->data.address64.producer_consumer = temp8 & 0x01;
906 855
907 /* 856 /* Decode */
908 * Decode 857
909 */
910 output_struct->data.address64.decode = (temp8 >> 1) & 0x01; 858 output_struct->data.address64.decode = (temp8 >> 1) & 0x01;
911 859
912 /* 860 /* Min Address Fixed */
913 * Min Address Fixed 861
914 */
915 output_struct->data.address64.min_address_fixed = (temp8 >> 2) & 0x01; 862 output_struct->data.address64.min_address_fixed = (temp8 >> 2) & 0x01;
916 863
917 /* 864 /* Max Address Fixed */
918 * Max Address Fixed 865
919 */
920 output_struct->data.address64.max_address_fixed = (temp8 >> 3) & 0x01; 866 output_struct->data.address64.max_address_fixed = (temp8 >> 3) & 0x01;
921 867
922 /* 868 /* Get the Type Specific Flags (Byte5) */
923 * Get the Type Specific Flags (Byte5) 869
924 */
925 buffer += 1; 870 buffer += 1;
926 temp8 = *buffer; 871 temp8 = *buffer;
927 872
@@ -951,33 +896,29 @@ acpi_rs_address64_resource (
951 buffer += 2; 896 buffer += 2;
952 } 897 }
953 898
954 /* 899 /* Get Granularity (Bytes 6-13) or (Bytes 8-15) */
955 * Get Granularity (Bytes 6-13) or (Bytes 8-15) 900
956 */
957 buffer += 1; 901 buffer += 1;
958 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.granularity, buffer); 902 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.granularity, buffer);
959 903
960 /* 904 /* Get min_address_range (Bytes 14-21) or (Bytes 16-23) */
961 * Get min_address_range (Bytes 14-21) or (Bytes 16-23) 905
962 */
963 buffer += 8; 906 buffer += 8;
964 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.min_address_range, buffer); 907 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.min_address_range, buffer);
965 908
966 /* 909 /* Get max_address_range (Bytes 22-29) or (Bytes 24-31) */
967 * Get max_address_range (Bytes 22-29) or (Bytes 24-31) 910
968 */
969 buffer += 8; 911 buffer += 8;
970 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.max_address_range, buffer); 912 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.max_address_range, buffer);
971 913
972 /* 914 /* Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) */
973 * Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) 915
974 */
975 buffer += 8; 916 buffer += 8;
976 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_translation_offset, buffer); 917 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_translation_offset,
918 buffer);
919
920 /* Get address_length (Bytes 38-45) or (Bytes 40-47) */
977 921
978 /*
979 * Get address_length (Bytes 38-45) or (Bytes 40-47)
980 */
981 buffer += 8; 922 buffer += 8;
982 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_length, buffer); 923 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_length, buffer);
983 924
@@ -989,14 +930,15 @@ acpi_rs_address64_resource (
989 /* Get type_specific_attribute (Bytes 48-55) */ 930 /* Get type_specific_attribute (Bytes 48-55) */
990 931
991 buffer += 8; 932 buffer += 8;
992 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.type_specific_attributes, buffer); 933 ACPI_MOVE_64_TO_64 (
934 &output_struct->data.address64.type_specific_attributes,
935 buffer);
993 } 936 }
994 else { 937 else {
995 output_struct->data.address64.type_specific_attributes = 0; 938 output_struct->data.address64.type_specific_attributes = 0;
996 939
997 /* 940 /* Resource Source Index (if present) */
998 * Resource Source Index (if present) 941
999 */
1000 buffer += 8; 942 buffer += 8;
1001 943
1002 /* 944 /*
@@ -1025,7 +967,8 @@ acpi_rs_address64_resource (
1025 output_struct->data.address64.resource_source.string_ptr = 967 output_struct->data.address64.resource_source.string_ptr =
1026 (char *)((u8 *)output_struct + struct_size); 968 (char *)((u8 *)output_struct + struct_size);
1027 969
1028 temp_ptr = (u8 *) output_struct->data.address64.resource_source.string_ptr; 970 temp_ptr = (u8 *)
971 output_struct->data.address64.resource_source.string_ptr;
1029 972
1030 /* Copy the string into the buffer */ 973 /* Copy the string into the buffer */
1031 974
@@ -1042,7 +985,8 @@ acpi_rs_address64_resource (
1042 * Add the terminating null 985 * Add the terminating null
1043 */ 986 */
1044 *temp_ptr = 0x00; 987 *temp_ptr = 0x00;
1045 output_struct->data.address64.resource_source.string_length = index + 1; 988 output_struct->data.address64.resource_source.string_length =
989 index + 1;
1046 990
1047 /* 991 /*
1048 * In order for the struct_size to fall on a 32-bit boundary, 992 * In order for the struct_size to fall on a 32-bit boundary,
@@ -1054,14 +998,12 @@ acpi_rs_address64_resource (
1054 } 998 }
1055 } 999 }
1056 1000
1057 /* 1001 /* Set the Length parameter */
1058 * Set the Length parameter 1002
1059 */
1060 output_struct->length = (u32) struct_size; 1003 output_struct->length = (u32) struct_size;
1061 1004
1062 /* 1005 /* Return the final size of the structure */
1063 * Return the final size of the structure 1006
1064 */
1065 *structure_size = struct_size; 1007 *structure_size = struct_size;
1066 return_ACPI_STATUS (AE_OK); 1008 return_ACPI_STATUS (AE_OK);
1067} 1009}
@@ -1100,29 +1042,25 @@ acpi_rs_address64_stream (
1100 1042
1101 buffer = *output_buffer; 1043 buffer = *output_buffer;
1102 1044
1103 /* 1045 /* The descriptor field is static */
1104 * The descriptor field is static 1046
1105 */
1106 *buffer = 0x8A; 1047 *buffer = 0x8A;
1107 buffer += 1; 1048 buffer += 1;
1108 1049
1109 /* 1050 /* Set a pointer to the Length field - to be filled in later */
1110 * Set a pointer to the Length field - to be filled in later 1051
1111 */
1112 length_field = ACPI_CAST_PTR (u16, buffer); 1052 length_field = ACPI_CAST_PTR (u16, buffer);
1113 buffer += 2; 1053 buffer += 2;
1114 1054
1115 /* 1055 /* Set the Resource Type (Memory, Io, bus_number) */
1116 * Set the Resource Type (Memory, Io, bus_number) 1056
1117 */
1118 temp8 = (u8) (linked_list->data.address64.resource_type & 0x03); 1057 temp8 = (u8) (linked_list->data.address64.resource_type & 0x03);
1119 1058
1120 *buffer = temp8; 1059 *buffer = temp8;
1121 buffer += 1; 1060 buffer += 1;
1122 1061
1123 /* 1062 /* Set the general flags */
1124 * Set the general flags 1063
1125 */
1126 temp8 = (u8) (linked_list->data.address64.producer_consumer & 0x01); 1064 temp8 = (u8) (linked_list->data.address64.producer_consumer & 0x01);
1127 temp8 |= (linked_list->data.address64.decode & 0x01) << 1; 1065 temp8 |= (linked_list->data.address64.decode & 0x01) << 1;
1128 temp8 |= (linked_list->data.address64.min_address_fixed & 0x01) << 2; 1066 temp8 |= (linked_list->data.address64.min_address_fixed & 0x01) << 2;
@@ -1131,9 +1069,8 @@ acpi_rs_address64_stream (
1131 *buffer = temp8; 1069 *buffer = temp8;
1132 buffer += 1; 1070 buffer += 1;
1133 1071
1134 /* 1072 /* Set the type specific flags */
1135 * Set the type specific flags 1073
1136 */
1137 temp8 = 0; 1074 temp8 = 0;
1138 1075
1139 if (ACPI_MEMORY_RANGE == linked_list->data.address64.resource_type) { 1076 if (ACPI_MEMORY_RANGE == linked_list->data.address64.resource_type) {
@@ -1157,39 +1094,34 @@ acpi_rs_address64_stream (
1157 *buffer = temp8; 1094 *buffer = temp8;
1158 buffer += 1; 1095 buffer += 1;
1159 1096
1160 /* 1097 /* Set the address space granularity */
1161 * Set the address space granularity 1098
1162 */
1163 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.granularity); 1099 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.granularity);
1164 buffer += 8; 1100 buffer += 8;
1165 1101
1166 /* 1102 /* Set the address range minimum */
1167 * Set the address range minimum 1103
1168 */
1169 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.min_address_range); 1104 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.min_address_range);
1170 buffer += 8; 1105 buffer += 8;
1171 1106
1172 /* 1107 /* Set the address range maximum */
1173 * Set the address range maximum 1108
1174 */
1175 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.max_address_range); 1109 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.max_address_range);
1176 buffer += 8; 1110 buffer += 8;
1177 1111
1178 /* 1112 /* Set the address translation offset */
1179 * Set the address translation offset 1113
1180 */ 1114 ACPI_MOVE_64_TO_64 (buffer,
1181 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_translation_offset); 1115 &linked_list->data.address64.address_translation_offset);
1182 buffer += 8; 1116 buffer += 8;
1183 1117
1184 /* 1118 /* Set the address length */
1185 * Set the address length 1119
1186 */
1187 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_length); 1120 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_length);
1188 buffer += 8; 1121 buffer += 8;
1189 1122
1190 /* 1123 /* Resource Source Index and Resource Source are optional */
1191 * Resource Source Index and Resource Source are optional 1124
1192 */
1193 if (0 != linked_list->data.address64.resource_source.string_length) { 1125 if (0 != linked_list->data.address64.resource_source.string_length) {
1194 temp8 = (u8) linked_list->data.address64.resource_source.index; 1126 temp8 = (u8) linked_list->data.address64.resource_source.index;
1195 1127
@@ -1198,21 +1130,21 @@ acpi_rs_address64_stream (
1198 1130
1199 temp_pointer = (char *) buffer; 1131 temp_pointer = (char *) buffer;
1200 1132
1201 /* 1133 /* Copy the string */
1202 * Copy the string 1134
1203 */ 1135 ACPI_STRCPY (temp_pointer,
1204 ACPI_STRCPY (temp_pointer, linked_list->data.address64.resource_source.string_ptr); 1136 linked_list->data.address64.resource_source.string_ptr);
1205 1137
1206 /* 1138 /*
1207 * Buffer needs to be set to the length of the sting + one for the 1139 * Buffer needs to be set to the length of the sting + one for the
1208 * terminating null 1140 * terminating null
1209 */ 1141 */
1210 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address64.resource_source.string_ptr) + 1); 1142 buffer += (acpi_size)(ACPI_STRLEN (
1143 linked_list->data.address64.resource_source.string_ptr) + 1);
1211 } 1144 }
1212 1145
1213 /* 1146 /* Return the number of bytes consumed in this operation */
1214 * Return the number of bytes consumed in this operation 1147
1215 */
1216 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 1148 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
1217 1149
1218 /* 1150 /*
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 8a5f0a52371d..98176f2fcb5d 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -81,9 +81,8 @@ acpi_rs_get_byte_stream_length (
81 81
82 82
83 while (!done) { 83 while (!done) {
84 /* 84 /* Init the variable that will hold the size to add to the total. */
85 * Init the variable that will hold the size to add to the total. 85
86 */
87 segment_size = 0; 86 segment_size = 0;
88 87
89 switch (linked_list->id) { 88 switch (linked_list->id) {
@@ -196,7 +195,8 @@ acpi_rs_get_byte_stream_length (
196 segment_size = 16; 195 segment_size = 16;
197 196
198 if (linked_list->data.address16.resource_source.string_ptr) { 197 if (linked_list->data.address16.resource_source.string_ptr) {
199 segment_size += linked_list->data.address16.resource_source.string_length; 198 segment_size +=
199 linked_list->data.address16.resource_source.string_length;
200 segment_size++; 200 segment_size++;
201 } 201 }
202 break; 202 break;
@@ -212,7 +212,8 @@ acpi_rs_get_byte_stream_length (
212 segment_size = 26; 212 segment_size = 26;
213 213
214 if (linked_list->data.address32.resource_source.string_ptr) { 214 if (linked_list->data.address32.resource_source.string_ptr) {
215 segment_size += linked_list->data.address32.resource_source.string_length; 215 segment_size +=
216 linked_list->data.address32.resource_source.string_length;
216 segment_size++; 217 segment_size++;
217 } 218 }
218 break; 219 break;
@@ -227,7 +228,8 @@ acpi_rs_get_byte_stream_length (
227 segment_size = 46; 228 segment_size = 46;
228 229
229 if (linked_list->data.address64.resource_source.string_ptr) { 230 if (linked_list->data.address64.resource_source.string_ptr) {
230 segment_size += linked_list->data.address64.resource_source.string_length; 231 segment_size +=
232 linked_list->data.address64.resource_source.string_length;
231 segment_size++; 233 segment_size++;
232 } 234 }
233 break; 235 break;
@@ -241,38 +243,36 @@ acpi_rs_get_byte_stream_length (
241 * Index + the length of the null terminated string 243 * Index + the length of the null terminated string
242 * Resource Source + 1 for the null. 244 * Resource Source + 1 for the null.
243 */ 245 */
244 segment_size = 9 + 246 segment_size = 9 + (((acpi_size)
245 (((acpi_size) linked_list->data.extended_irq.number_of_interrupts - 1) * 4); 247 linked_list->data.extended_irq.number_of_interrupts - 1) * 4);
246 248
247 if (linked_list->data.extended_irq.resource_source.string_ptr) { 249 if (linked_list->data.extended_irq.resource_source.string_ptr) {
248 segment_size += linked_list->data.extended_irq.resource_source.string_length; 250 segment_size +=
251 linked_list->data.extended_irq.resource_source.string_length;
249 segment_size++; 252 segment_size++;
250 } 253 }
251 break; 254 break;
252 255
253 default: 256 default:
254 /* 257
255 * If we get here, everything is out of sync, exit with error 258 /* If we get here, everything is out of sync, exit with error */
256 */ 259
257 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 260 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
258 261
259 } /* switch (linked_list->Id) */ 262 } /* switch (linked_list->Id) */
260 263
261 /* 264 /* Update the total */
262 * Update the total 265
263 */
264 byte_stream_size_needed += segment_size; 266 byte_stream_size_needed += segment_size;
265 267
266 /* 268 /* Point to the next object */
267 * Point to the next object 269
268 */
269 linked_list = ACPI_PTR_ADD (struct acpi_resource, 270 linked_list = ACPI_PTR_ADD (struct acpi_resource,
270 linked_list, linked_list->length); 271 linked_list, linked_list->length);
271 } 272 }
272 273
273 /* 274 /* This is the data the caller needs */
274 * This is the data the caller needs 275
275 */
276 *size_needed = byte_stream_size_needed; 276 *size_needed = byte_stream_size_needed;
277 return_ACPI_STATUS (AE_OK); 277 return_ACPI_STATUS (AE_OK);
278} 278}
@@ -320,9 +320,8 @@ acpi_rs_get_list_length (
320 320
321 321
322 while (bytes_parsed < byte_stream_buffer_length) { 322 while (bytes_parsed < byte_stream_buffer_length) {
323 /* 323 /* The next byte in the stream is the resource type */
324 * The next byte in the stream is the resource type 324
325 */
326 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer); 325 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
327 326
328 switch (resource_type) { 327 switch (resource_type) {
@@ -346,9 +345,8 @@ acpi_rs_get_list_length (
346 ACPI_MOVE_16_TO_16 (&temp16, buffer); 345 ACPI_MOVE_16_TO_16 (&temp16, buffer);
347 bytes_consumed = temp16 + 3; 346 bytes_consumed = temp16 + 3;
348 347
349 /* 348 /* Ensure a 32-bit boundary for the structure */
350 * Ensure a 32-bit boundary for the structure 349
351 */
352 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16); 350 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16);
353 351
354 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) + 352 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
@@ -416,9 +414,8 @@ acpi_rs_get_list_length (
416 temp8 = 0; 414 temp8 = 0;
417 } 415 }
418 416
419 /* 417 /* Ensure a 64-bit boundary for the structure */
420 * Ensure a 64-bit boundary for the structure 418
421 */
422 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8); 419 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8);
423 420
424 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64) + 421 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64) +
@@ -452,9 +449,8 @@ acpi_rs_get_list_length (
452 temp8 = 0; 449 temp8 = 0;
453 } 450 }
454 451
455 /* 452 /* Ensure a 32-bit boundary for the structure */
456 * Ensure a 32-bit boundary for the structure 453
457 */
458 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 454 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
459 455
460 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32) + 456 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32) +
@@ -488,9 +484,8 @@ acpi_rs_get_list_length (
488 temp8 = 0; 484 temp8 = 0;
489 } 485 }
490 486
491 /* 487 /* Ensure a 32-bit boundary for the structure */
492 * Ensure a 32-bit boundary for the structure 488
493 */
494 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 489 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
495 490
496 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16) + 491 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16) +
@@ -537,9 +532,8 @@ acpi_rs_get_list_length (
537 temp8 = 0; 532 temp8 = 0;
538 } 533 }
539 534
540 /* 535 /* Ensure a 32-bit boundary for the structure */
541 * Ensure a 32-bit boundary for the structure 536
542 */
543 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 537 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
544 538
545 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq) + 539 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq) +
@@ -567,9 +561,8 @@ acpi_rs_get_list_length (
567 561
568 ++buffer; 562 ++buffer;
569 563
570 /* 564 /* Look at the number of bits set */
571 * Look at the number of bits set 565
572 */
573 ACPI_MOVE_16_TO_16 (&temp16, buffer); 566 ACPI_MOVE_16_TO_16 (&temp16, buffer);
574 567
575 for (index = 0; index < 16; index++) { 568 for (index = 0; index < 16; index++) {
@@ -596,9 +589,8 @@ acpi_rs_get_list_length (
596 589
597 ++buffer; 590 ++buffer;
598 591
599 /* 592 /* Look at the number of bits set */
600 * Look at the number of bits set 593
601 */
602 temp8 = *buffer; 594 temp8 = *buffer;
603 595
604 for(index = 0; index < 8; index++) { 596 for(index = 0; index < 8; index++) {
@@ -670,9 +662,8 @@ acpi_rs_get_list_length (
670 temp8 = (u8) (temp8 & 0x7); 662 temp8 = (u8) (temp8 & 0x7);
671 bytes_consumed = temp8 + 1; 663 bytes_consumed = temp8 + 1;
672 664
673 /* 665 /* Ensure a 32-bit boundary for the structure */
674 * Ensure a 32-bit boundary for the structure 666
675 */
676 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 667 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
677 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) + 668 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
678 (temp8 * sizeof (u8)); 669 (temp8 * sizeof (u8));
@@ -697,21 +688,18 @@ acpi_rs_get_list_length (
697 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 688 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
698 } 689 }
699 690
700 /* 691 /* Update the return value and counter */
701 * Update the return value and counter 692
702 */
703 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE (structure_size); 693 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE (structure_size);
704 bytes_parsed += bytes_consumed; 694 bytes_parsed += bytes_consumed;
705 695
706 /* 696 /* Set the byte stream to point to the next resource */
707 * Set the byte stream to point to the next resource 697
708 */
709 byte_stream_buffer += bytes_consumed; 698 byte_stream_buffer += bytes_consumed;
710 } 699 }
711 700
712 /* 701 /* This is the data the caller needs */
713 * This is the data the caller needs 702
714 */
715 *size_needed = buffer_size; 703 *size_needed = buffer_size;
716 return_ACPI_STATUS (AE_OK); 704 return_ACPI_STATUS (AE_OK);
717} 705}
@@ -767,9 +755,8 @@ acpi_rs_get_pci_routing_table_length (
767 top_object_list = package_object->package.elements; 755 top_object_list = package_object->package.elements;
768 756
769 for (index = 0; index < number_of_elements; index++) { 757 for (index = 0; index < number_of_elements; index++) {
770 /* 758 /* Dereference the sub-package */
771 * Dereference the sub-package 759
772 */
773 package_element = *top_object_list; 760 package_element = *top_object_list;
774 761
775 /* 762 /*
@@ -778,37 +765,40 @@ acpi_rs_get_pci_routing_table_length (
778 */ 765 */
779 sub_object_list = package_element->package.elements; 766 sub_object_list = package_element->package.elements;
780 767
781 /* 768 /* Scan the irq_table_elements for the Source Name String */
782 * Scan the irq_table_elements for the Source Name String 769
783 */
784 name_found = FALSE; 770 name_found = FALSE;
785 771
786 for (table_index = 0; table_index < 4 && !name_found; table_index++) { 772 for (table_index = 0; table_index < 4 && !name_found; table_index++) {
787 if ((ACPI_TYPE_STRING == ACPI_GET_OBJECT_TYPE (*sub_object_list)) || 773 if ((ACPI_TYPE_STRING ==
788 ((ACPI_TYPE_LOCAL_REFERENCE == ACPI_GET_OBJECT_TYPE (*sub_object_list)) && 774 ACPI_GET_OBJECT_TYPE (*sub_object_list)) ||
789 ((*sub_object_list)->reference.opcode == AML_INT_NAMEPATH_OP))) { 775
776 ((ACPI_TYPE_LOCAL_REFERENCE ==
777 ACPI_GET_OBJECT_TYPE (*sub_object_list)) &&
778
779 ((*sub_object_list)->reference.opcode ==
780 AML_INT_NAMEPATH_OP))) {
790 name_found = TRUE; 781 name_found = TRUE;
791 } 782 }
792 else { 783 else {
793 /* 784 /* Look at the next element */
794 * Look at the next element 785
795 */
796 sub_object_list++; 786 sub_object_list++;
797 } 787 }
798 } 788 }
799 789
800 temp_size_needed += (sizeof (struct acpi_pci_routing_table) - 4); 790 temp_size_needed += (sizeof (struct acpi_pci_routing_table) - 4);
801 791
802 /* 792 /* Was a String type found? */
803 * Was a String type found? 793
804 */
805 if (name_found) { 794 if (name_found) {
806 if (ACPI_GET_OBJECT_TYPE (*sub_object_list) == ACPI_TYPE_STRING) { 795 if (ACPI_GET_OBJECT_TYPE (*sub_object_list) == ACPI_TYPE_STRING) {
807 /* 796 /*
808 * The length String.Length field does not include the 797 * The length String.Length field does not include the
809 * terminating NULL, add 1 798 * terminating NULL, add 1
810 */ 799 */
811 temp_size_needed += ((acpi_size) (*sub_object_list)->string.length + 1); 800 temp_size_needed += ((acpi_size)
801 (*sub_object_list)->string.length + 1);
812 } 802 }
813 else { 803 else {
814 temp_size_needed += acpi_ns_get_pathname_length ( 804 temp_size_needed += acpi_ns_get_pathname_length (
@@ -827,14 +817,14 @@ acpi_rs_get_pci_routing_table_length (
827 817
828 temp_size_needed = ACPI_ROUND_UP_to_64_bITS (temp_size_needed); 818 temp_size_needed = ACPI_ROUND_UP_to_64_bITS (temp_size_needed);
829 819
830 /* 820 /* Point to the next union acpi_operand_object */
831 * Point to the next union acpi_operand_object 821
832 */
833 top_object_list++; 822 top_object_list++;
834 } 823 }
835 824
836 /* 825 /*
837 * Adding an extra element to the end of the list, essentially a NULL terminator 826 * Adding an extra element to the end of the list, essentially a
827 * NULL terminator
838 */ 828 */
839 *buffer_size_needed = temp_size_needed + sizeof (struct acpi_pci_routing_table); 829 *buffer_size_needed = temp_size_needed + sizeof (struct acpi_pci_routing_table);
840 return_ACPI_STATUS (AE_OK); 830 return_ACPI_STATUS (AE_OK);
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index a3a0cbfda68d..8e0eae0d50bb 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -87,9 +87,8 @@ acpi_rs_create_resource_list (
87 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_buffer = %p\n", 87 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_buffer = %p\n",
88 byte_stream_buffer)); 88 byte_stream_buffer));
89 89
90 /* 90 /* Params already validated, so we don't re-validate here */
91 * Params already validated, so we don't re-validate here 91
92 */
93 byte_stream_buffer_length = byte_stream_buffer->buffer.length; 92 byte_stream_buffer_length = byte_stream_buffer->buffer.length;
94 byte_stream_start = byte_stream_buffer->buffer.pointer; 93 byte_stream_start = byte_stream_buffer->buffer.pointer;
95 94
@@ -171,9 +170,8 @@ acpi_rs_create_pci_routing_table (
171 170
172 /* Params already validated, so we don't re-validate here */ 171 /* Params already validated, so we don't re-validate here */
173 172
174 /* 173 /* Get the required buffer length */
175 * Get the required buffer length 174
176 */
177 status = acpi_rs_get_pci_routing_table_length (package_object, 175 status = acpi_rs_get_pci_routing_table_length (package_object,
178 &buffer_size_needed); 176 &buffer_size_needed);
179 if (ACPI_FAILURE (status)) { 177 if (ACPI_FAILURE (status)) {
@@ -217,9 +215,8 @@ acpi_rs_create_pci_routing_table (
217 */ 215 */
218 user_prt->length = (sizeof (struct acpi_pci_routing_table) - 4); 216 user_prt->length = (sizeof (struct acpi_pci_routing_table) - 4);
219 217
220 /* 218 /* Each element of the top-level package must also be a package */
221 * Each element of the top-level package must also be a package 219
222 */
223 if (ACPI_GET_OBJECT_TYPE (*top_object_list) != ACPI_TYPE_PACKAGE) { 220 if (ACPI_GET_OBJECT_TYPE (*top_object_list) != ACPI_TYPE_PACKAGE) {
224 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 221 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
225 "(PRT[%X]) Need sub-package, found %s\n", 222 "(PRT[%X]) Need sub-package, found %s\n",
@@ -243,9 +240,8 @@ acpi_rs_create_pci_routing_table (
243 */ 240 */
244 sub_object_list = (*top_object_list)->package.elements; 241 sub_object_list = (*top_object_list)->package.elements;
245 242
246 /* 243 /* 1) First subobject: Dereference the PRT.Address */
247 * 1) First subobject: Dereference the PRT.Address 244
248 */
249 obj_desc = sub_object_list[0]; 245 obj_desc = sub_object_list[0];
250 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 246 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
251 user_prt->address = obj_desc->integer.value; 247 user_prt->address = obj_desc->integer.value;
@@ -257,9 +253,8 @@ acpi_rs_create_pci_routing_table (
257 return_ACPI_STATUS (AE_BAD_DATA); 253 return_ACPI_STATUS (AE_BAD_DATA);
258 } 254 }
259 255
260 /* 256 /* 2) Second subobject: Dereference the PRT.Pin */
261 * 2) Second subobject: Dereference the PRT.Pin 257
262 */
263 obj_desc = sub_object_list[1]; 258 obj_desc = sub_object_list[1];
264 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 259 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
265 user_prt->pin = (u32) obj_desc->integer.value; 260 user_prt->pin = (u32) obj_desc->integer.value;
@@ -271,9 +266,8 @@ acpi_rs_create_pci_routing_table (
271 return_ACPI_STATUS (AE_BAD_DATA); 266 return_ACPI_STATUS (AE_BAD_DATA);
272 } 267 }
273 268
274 /* 269 /* 3) Third subobject: Dereference the PRT.source_name */
275 * 3) Third subobject: Dereference the PRT.source_name 270
276 */
277 obj_desc = sub_object_list[2]; 271 obj_desc = sub_object_list[2];
278 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 272 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
279 case ACPI_TYPE_LOCAL_REFERENCE: 273 case ACPI_TYPE_LOCAL_REFERENCE:
@@ -296,7 +290,9 @@ acpi_rs_create_pci_routing_table (
296 290
297 status = acpi_ns_handle_to_pathname ((acpi_handle) node, &path_buffer); 291 status = acpi_ns_handle_to_pathname ((acpi_handle) node, &path_buffer);
298 292
299 user_prt->length += (u32) ACPI_STRLEN (user_prt->source) + 1; /* include null terminator */ 293 /* +1 to include null terminator */
294
295 user_prt->length += (u32) ACPI_STRLEN (user_prt->source) + 1;
300 break; 296 break;
301 297
302 298
@@ -304,8 +300,10 @@ acpi_rs_create_pci_routing_table (
304 300
305 ACPI_STRCPY (user_prt->source, obj_desc->string.pointer); 301 ACPI_STRCPY (user_prt->source, obj_desc->string.pointer);
306 302
307 /* Add to the Length field the length of the string (add 1 for terminator) */ 303 /*
308 304 * Add to the Length field the length of the string
305 * (add 1 for terminator)
306 */
309 user_prt->length += obj_desc->string.length + 1; 307 user_prt->length += obj_desc->string.length + 1;
310 break; 308 break;
311 309
@@ -333,9 +331,8 @@ acpi_rs_create_pci_routing_table (
333 331
334 user_prt->length = (u32) ACPI_ROUND_UP_to_64_bITS (user_prt->length); 332 user_prt->length = (u32) ACPI_ROUND_UP_to_64_bITS (user_prt->length);
335 333
336 /* 334 /* 4) Fourth subobject: Dereference the PRT.source_index */
337 * 4) Fourth subobject: Dereference the PRT.source_index 335
338 */
339 obj_desc = sub_object_list[3]; 336 obj_desc = sub_object_list[3];
340 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 337 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
341 user_prt->source_index = (u32) obj_desc->integer.value; 338 user_prt->source_index = (u32) obj_desc->integer.value;
diff --git a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
index eef1b1f2c685..1935dab2ab51 100644
--- a/drivers/acpi/resources/rsdump.c
+++ b/drivers/acpi/resources/rsdump.c
@@ -48,9 +48,62 @@
48#define _COMPONENT ACPI_RESOURCES 48#define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsdump") 49 ACPI_MODULE_NAME ("rsdump")
50 50
51/* Local prototypes */
51 52
52#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 53static void
54acpi_rs_dump_irq (
55 union acpi_resource_data *data);
56
57static void
58acpi_rs_dump_address16 (
59 union acpi_resource_data *data);
60
61static void
62acpi_rs_dump_address32 (
63 union acpi_resource_data *data);
64
65static void
66acpi_rs_dump_address64 (
67 union acpi_resource_data *data);
68
69static void
70acpi_rs_dump_dma (
71 union acpi_resource_data *data);
72
73static void
74acpi_rs_dump_io (
75 union acpi_resource_data *data);
76
77static void
78acpi_rs_dump_extended_irq (
79 union acpi_resource_data *data);
53 80
81static void
82acpi_rs_dump_fixed_io (
83 union acpi_resource_data *data);
84
85static void
86acpi_rs_dump_fixed_memory32 (
87 union acpi_resource_data *data);
88
89static void
90acpi_rs_dump_memory24 (
91 union acpi_resource_data *data);
92
93static void
94acpi_rs_dump_memory32 (
95 union acpi_resource_data *data);
96
97static void
98acpi_rs_dump_start_depend_fns (
99 union acpi_resource_data *data);
100
101static void
102acpi_rs_dump_vendor_specific (
103 union acpi_resource_data *data);
104
105
106#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
54/******************************************************************************* 107/*******************************************************************************
55 * 108 *
56 * FUNCTION: acpi_rs_dump_irq 109 * FUNCTION: acpi_rs_dump_irq
@@ -63,7 +116,7 @@
63 * 116 *
64 ******************************************************************************/ 117 ******************************************************************************/
65 118
66void 119static void
67acpi_rs_dump_irq ( 120acpi_rs_dump_irq (
68 union acpi_resource_data *data) 121 union acpi_resource_data *data)
69{ 122{
@@ -77,13 +130,13 @@ acpi_rs_dump_irq (
77 acpi_os_printf ("IRQ Resource\n"); 130 acpi_os_printf ("IRQ Resource\n");
78 131
79 acpi_os_printf (" %s Triggered\n", 132 acpi_os_printf (" %s Triggered\n",
80 ACPI_LEVEL_SENSITIVE == irq_data->edge_level ? "Level" : "Edge"); 133 ACPI_LEVEL_SENSITIVE == irq_data->edge_level ? "Level" : "Edge");
81 134
82 acpi_os_printf (" Active %s\n", 135 acpi_os_printf (" Active %s\n",
83 ACPI_ACTIVE_LOW == irq_data->active_high_low ? "Low" : "High"); 136 ACPI_ACTIVE_LOW == irq_data->active_high_low ? "Low" : "High");
84 137
85 acpi_os_printf (" %s\n", 138 acpi_os_printf (" %s\n",
86 ACPI_SHARED == irq_data->shared_exclusive ? "Shared" : "Exclusive"); 139 ACPI_SHARED == irq_data->shared_exclusive ? "Shared" : "Exclusive");
87 140
88 acpi_os_printf (" %X Interrupts ( ", irq_data->number_of_interrupts); 141 acpi_os_printf (" %X Interrupts ( ", irq_data->number_of_interrupts);
89 142
@@ -108,7 +161,7 @@ acpi_rs_dump_irq (
108 * 161 *
109 ******************************************************************************/ 162 ******************************************************************************/
110 163
111void 164static void
112acpi_rs_dump_dma ( 165acpi_rs_dump_dma (
113 union acpi_resource_data *data) 166 union acpi_resource_data *data)
114{ 167{
@@ -144,7 +197,7 @@ acpi_rs_dump_dma (
144 } 197 }
145 198
146 acpi_os_printf (" %sBus Master\n", 199 acpi_os_printf (" %sBus Master\n",
147 ACPI_BUS_MASTER == dma_data->bus_master ? "" : "Not a "); 200 ACPI_BUS_MASTER == dma_data->bus_master ? "" : "Not a ");
148 201
149 202
150 switch (dma_data->transfer) { 203 switch (dma_data->transfer) {
@@ -165,7 +218,8 @@ acpi_rs_dump_dma (
165 break; 218 break;
166 } 219 }
167 220
168 acpi_os_printf (" Number of Channels: %X ( ", dma_data->number_of_channels); 221 acpi_os_printf (" Number of Channels: %X ( ",
222 dma_data->number_of_channels);
169 223
170 for (index = 0; index < dma_data->number_of_channels; index++) { 224 for (index = 0; index < dma_data->number_of_channels; index++) {
171 acpi_os_printf ("%X ", dma_data->channels[index]); 225 acpi_os_printf ("%X ", dma_data->channels[index]);
@@ -188,7 +242,7 @@ acpi_rs_dump_dma (
188 * 242 *
189 ******************************************************************************/ 243 ******************************************************************************/
190 244
191void 245static void
192acpi_rs_dump_start_depend_fns ( 246acpi_rs_dump_start_depend_fns (
193 union acpi_resource_data *data) 247 union acpi_resource_data *data)
194{ 248{
@@ -232,8 +286,7 @@ acpi_rs_dump_start_depend_fns (
232 break; 286 break;
233 287
234 default: 288 default:
235 acpi_os_printf (" Invalid performance " 289 acpi_os_printf (" Invalid performance robustness preference\n");
236 "robustness preference\n");
237 break; 290 break;
238 } 291 }
239 292
@@ -253,7 +306,7 @@ acpi_rs_dump_start_depend_fns (
253 * 306 *
254 ******************************************************************************/ 307 ******************************************************************************/
255 308
256void 309static void
257acpi_rs_dump_io ( 310acpi_rs_dump_io (
258 union acpi_resource_data *data) 311 union acpi_resource_data *data)
259{ 312{
@@ -266,19 +319,15 @@ acpi_rs_dump_io (
266 acpi_os_printf ("Io Resource\n"); 319 acpi_os_printf ("Io Resource\n");
267 320
268 acpi_os_printf (" %d bit decode\n", 321 acpi_os_printf (" %d bit decode\n",
269 ACPI_DECODE_16 == io_data->io_decode ? 16 : 10); 322 ACPI_DECODE_16 == io_data->io_decode ? 16 : 10);
270 323
271 acpi_os_printf (" Range minimum base: %08X\n", 324 acpi_os_printf (" Range minimum base: %08X\n", io_data->min_base_address);
272 io_data->min_base_address);
273 325
274 acpi_os_printf (" Range maximum base: %08X\n", 326 acpi_os_printf (" Range maximum base: %08X\n", io_data->max_base_address);
275 io_data->max_base_address);
276 327
277 acpi_os_printf (" Alignment: %08X\n", 328 acpi_os_printf (" Alignment: %08X\n", io_data->alignment);
278 io_data->alignment);
279 329
280 acpi_os_printf (" Range Length: %08X\n", 330 acpi_os_printf (" Range Length: %08X\n", io_data->range_length);
281 io_data->range_length);
282 331
283 return; 332 return;
284} 333}
@@ -296,7 +345,7 @@ acpi_rs_dump_io (
296 * 345 *
297 ******************************************************************************/ 346 ******************************************************************************/
298 347
299void 348static void
300acpi_rs_dump_fixed_io ( 349acpi_rs_dump_fixed_io (
301 union acpi_resource_data *data) 350 union acpi_resource_data *data)
302{ 351{
@@ -307,11 +356,9 @@ acpi_rs_dump_fixed_io (
307 356
308 357
309 acpi_os_printf ("Fixed Io Resource\n"); 358 acpi_os_printf ("Fixed Io Resource\n");
310 acpi_os_printf (" Range base address: %08X", 359 acpi_os_printf (" Range base address: %08X", fixed_io_data->base_address);
311 fixed_io_data->base_address);
312 360
313 acpi_os_printf (" Range length: %08X", 361 acpi_os_printf (" Range length: %08X", fixed_io_data->range_length);
314 fixed_io_data->range_length);
315 362
316 return; 363 return;
317} 364}
@@ -329,7 +376,7 @@ acpi_rs_dump_fixed_io (
329 * 376 *
330 ******************************************************************************/ 377 ******************************************************************************/
331 378
332void 379static void
333acpi_rs_dump_vendor_specific ( 380acpi_rs_dump_vendor_specific (
334 union acpi_resource_data *data) 381 union acpi_resource_data *data)
335{ 382{
@@ -346,7 +393,7 @@ acpi_rs_dump_vendor_specific (
346 393
347 for (index = 0; index < vendor_data->length; index++) { 394 for (index = 0; index < vendor_data->length; index++) {
348 acpi_os_printf (" Byte %X: %08X\n", 395 acpi_os_printf (" Byte %X: %08X\n",
349 index, vendor_data->reserved[index]); 396 index, vendor_data->reserved[index]);
350 } 397 }
351 398
352 return; 399 return;
@@ -365,7 +412,7 @@ acpi_rs_dump_vendor_specific (
365 * 412 *
366 ******************************************************************************/ 413 ******************************************************************************/
367 414
368void 415static void
369acpi_rs_dump_memory24 ( 416acpi_rs_dump_memory24 (
370 union acpi_resource_data *data) 417 union acpi_resource_data *data)
371{ 418{
@@ -378,21 +425,19 @@ acpi_rs_dump_memory24 (
378 acpi_os_printf ("24-Bit Memory Range Resource\n"); 425 acpi_os_printf ("24-Bit Memory Range Resource\n");
379 426
380 acpi_os_printf (" Read%s\n", 427 acpi_os_printf (" Read%s\n",
381 ACPI_READ_WRITE_MEMORY == 428 ACPI_READ_WRITE_MEMORY ==
382 memory24_data->read_write_attribute ? 429 memory24_data->read_write_attribute ?
383 "/Write" : " only"); 430 "/Write" : " only");
384 431
385 acpi_os_printf (" Range minimum base: %08X\n", 432 acpi_os_printf (" Range minimum base: %08X\n",
386 memory24_data->min_base_address); 433 memory24_data->min_base_address);
387 434
388 acpi_os_printf (" Range maximum base: %08X\n", 435 acpi_os_printf (" Range maximum base: %08X\n",
389 memory24_data->max_base_address); 436 memory24_data->max_base_address);
390 437
391 acpi_os_printf (" Alignment: %08X\n", 438 acpi_os_printf (" Alignment: %08X\n", memory24_data->alignment);
392 memory24_data->alignment);
393 439
394 acpi_os_printf (" Range length: %08X\n", 440 acpi_os_printf (" Range length: %08X\n", memory24_data->range_length);
395 memory24_data->range_length);
396 441
397 return; 442 return;
398} 443}
@@ -410,7 +455,7 @@ acpi_rs_dump_memory24 (
410 * 455 *
411 ******************************************************************************/ 456 ******************************************************************************/
412 457
413void 458static void
414acpi_rs_dump_memory32 ( 459acpi_rs_dump_memory32 (
415 union acpi_resource_data *data) 460 union acpi_resource_data *data)
416{ 461{
@@ -423,21 +468,19 @@ acpi_rs_dump_memory32 (
423 acpi_os_printf ("32-Bit Memory Range Resource\n"); 468 acpi_os_printf ("32-Bit Memory Range Resource\n");
424 469
425 acpi_os_printf (" Read%s\n", 470 acpi_os_printf (" Read%s\n",
426 ACPI_READ_WRITE_MEMORY == 471 ACPI_READ_WRITE_MEMORY ==
427 memory32_data->read_write_attribute ? 472 memory32_data->read_write_attribute ?
428 "/Write" : " only"); 473 "/Write" : " only");
429 474
430 acpi_os_printf (" Range minimum base: %08X\n", 475 acpi_os_printf (" Range minimum base: %08X\n",
431 memory32_data->min_base_address); 476 memory32_data->min_base_address);
432 477
433 acpi_os_printf (" Range maximum base: %08X\n", 478 acpi_os_printf (" Range maximum base: %08X\n",
434 memory32_data->max_base_address); 479 memory32_data->max_base_address);
435 480
436 acpi_os_printf (" Alignment: %08X\n", 481 acpi_os_printf (" Alignment: %08X\n", memory32_data->alignment);
437 memory32_data->alignment);
438 482
439 acpi_os_printf (" Range length: %08X\n", 483 acpi_os_printf (" Range length: %08X\n", memory32_data->range_length);
440 memory32_data->range_length);
441 484
442 return; 485 return;
443} 486}
@@ -455,11 +498,12 @@ acpi_rs_dump_memory32 (
455 * 498 *
456 ******************************************************************************/ 499 ******************************************************************************/
457 500
458void 501static void
459acpi_rs_dump_fixed_memory32 ( 502acpi_rs_dump_fixed_memory32 (
460 union acpi_resource_data *data) 503 union acpi_resource_data *data)
461{ 504{
462 struct acpi_resource_fixed_mem32 *fixed_memory32_data = (struct acpi_resource_fixed_mem32 *) data; 505 struct acpi_resource_fixed_mem32 *fixed_memory32_data =
506 (struct acpi_resource_fixed_mem32 *) data;
463 507
464 508
465 ACPI_FUNCTION_ENTRY (); 509 ACPI_FUNCTION_ENTRY ();
@@ -468,15 +512,14 @@ acpi_rs_dump_fixed_memory32 (
468 acpi_os_printf ("32-Bit Fixed Location Memory Range Resource\n"); 512 acpi_os_printf ("32-Bit Fixed Location Memory Range Resource\n");
469 513
470 acpi_os_printf (" Read%s\n", 514 acpi_os_printf (" Read%s\n",
471 ACPI_READ_WRITE_MEMORY == 515 ACPI_READ_WRITE_MEMORY ==
472 fixed_memory32_data->read_write_attribute ? 516 fixed_memory32_data->read_write_attribute ? "/Write" : " Only");
473 "/Write" : " Only");
474 517
475 acpi_os_printf (" Range base address: %08X\n", 518 acpi_os_printf (" Range base address: %08X\n",
476 fixed_memory32_data->range_base_address); 519 fixed_memory32_data->range_base_address);
477 520
478 acpi_os_printf (" Range length: %08X\n", 521 acpi_os_printf (" Range length: %08X\n",
479 fixed_memory32_data->range_length); 522 fixed_memory32_data->range_length);
480 523
481 return; 524 return;
482} 525}
@@ -494,7 +537,7 @@ acpi_rs_dump_fixed_memory32 (
494 * 537 *
495 ******************************************************************************/ 538 ******************************************************************************/
496 539
497void 540static void
498acpi_rs_dump_address16 ( 541acpi_rs_dump_address16 (
499 union acpi_resource_data *data) 542 union acpi_resource_data *data)
500{ 543{
@@ -514,35 +557,30 @@ acpi_rs_dump_address16 (
514 557
515 switch (address16_data->attribute.memory.cache_attribute) { 558 switch (address16_data->attribute.memory.cache_attribute) {
516 case ACPI_NON_CACHEABLE_MEMORY: 559 case ACPI_NON_CACHEABLE_MEMORY:
517 acpi_os_printf (" Type Specific: " 560 acpi_os_printf (" Type Specific: Noncacheable memory\n");
518 "Noncacheable memory\n");
519 break; 561 break;
520 562
521 case ACPI_CACHABLE_MEMORY: 563 case ACPI_CACHABLE_MEMORY:
522 acpi_os_printf (" Type Specific: " 564 acpi_os_printf (" Type Specific: Cacheable memory\n");
523 "Cacheable memory\n");
524 break; 565 break;
525 566
526 case ACPI_WRITE_COMBINING_MEMORY: 567 case ACPI_WRITE_COMBINING_MEMORY:
527 acpi_os_printf (" Type Specific: " 568 acpi_os_printf (" Type Specific: Write-combining memory\n");
528 "Write-combining memory\n");
529 break; 569 break;
530 570
531 case ACPI_PREFETCHABLE_MEMORY: 571 case ACPI_PREFETCHABLE_MEMORY:
532 acpi_os_printf (" Type Specific: " 572 acpi_os_printf (" Type Specific: Prefetchable memory\n");
533 "Prefetchable memory\n");
534 break; 573 break;
535 574
536 default: 575 default:
537 acpi_os_printf (" Type Specific: " 576 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
538 "Invalid cache attribute\n");
539 break; 577 break;
540 } 578 }
541 579
542 acpi_os_printf (" Type Specific: Read%s\n", 580 acpi_os_printf (" Type Specific: Read%s\n",
543 ACPI_READ_WRITE_MEMORY == 581 ACPI_READ_WRITE_MEMORY ==
544 address16_data->attribute.memory.read_write_attribute ? 582 address16_data->attribute.memory.read_write_attribute ?
545 "/Write" : " Only"); 583 "/Write" : " Only");
546 break; 584 break;
547 585
548 case ACPI_IO_RANGE: 586 case ACPI_IO_RANGE:
@@ -551,30 +589,26 @@ acpi_rs_dump_address16 (
551 589
552 switch (address16_data->attribute.io.range_attribute) { 590 switch (address16_data->attribute.io.range_attribute) {
553 case ACPI_NON_ISA_ONLY_RANGES: 591 case ACPI_NON_ISA_ONLY_RANGES:
554 acpi_os_printf (" Type Specific: " 592 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
555 "Non-ISA Io Addresses\n");
556 break; 593 break;
557 594
558 case ACPI_ISA_ONLY_RANGES: 595 case ACPI_ISA_ONLY_RANGES:
559 acpi_os_printf (" Type Specific: " 596 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
560 "ISA Io Addresses\n");
561 break; 597 break;
562 598
563 case ACPI_ENTIRE_RANGE: 599 case ACPI_ENTIRE_RANGE:
564 acpi_os_printf (" Type Specific: " 600 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
565 "ISA and non-ISA Io Addresses\n");
566 break; 601 break;
567 602
568 default: 603 default:
569 acpi_os_printf (" Type Specific: " 604 acpi_os_printf (" Type Specific: Invalid range attribute\n");
570 "Invalid range attribute\n");
571 break; 605 break;
572 } 606 }
573 607
574 acpi_os_printf (" Type Specific: %s Translation\n", 608 acpi_os_printf (" Type Specific: %s Translation\n",
575 ACPI_SPARSE_TRANSLATION == 609 ACPI_SPARSE_TRANSLATION ==
576 address16_data->attribute.io.translation_attribute ? 610 address16_data->attribute.io.translation_attribute ?
577 "Sparse" : "Dense"); 611 "Sparse" : "Dense");
578 break; 612 break;
579 613
580 case ACPI_BUS_NUMBER_RANGE: 614 case ACPI_BUS_NUMBER_RANGE:
@@ -589,41 +623,42 @@ acpi_rs_dump_address16 (
589 } 623 }
590 624
591 acpi_os_printf (" Resource %s\n", 625 acpi_os_printf (" Resource %s\n",
592 ACPI_CONSUMER == address16_data->producer_consumer ? 626 ACPI_CONSUMER == address16_data->producer_consumer ?
593 "Consumer" : "Producer"); 627 "Consumer" : "Producer");
594 628
595 acpi_os_printf (" %s decode\n", 629 acpi_os_printf (" %s decode\n",
596 ACPI_SUB_DECODE == address16_data->decode ? 630 ACPI_SUB_DECODE == address16_data->decode ?
597 "Subtractive" : "Positive"); 631 "Subtractive" : "Positive");
598 632
599 acpi_os_printf (" Min address is %s fixed\n", 633 acpi_os_printf (" Min address is %s fixed\n",
600 ACPI_ADDRESS_FIXED == address16_data->min_address_fixed ? 634 ACPI_ADDRESS_FIXED == address16_data->min_address_fixed ?
601 "" : "not"); 635 "" : "not");
602 636
603 acpi_os_printf (" Max address is %s fixed\n", 637 acpi_os_printf (" Max address is %s fixed\n",
604 ACPI_ADDRESS_FIXED == address16_data->max_address_fixed ? 638 ACPI_ADDRESS_FIXED == address16_data->max_address_fixed ?
605 "" : "not"); 639 "" : "not");
606 640
607 acpi_os_printf (" Granularity: %08X\n", 641 acpi_os_printf (" Granularity: %08X\n",
608 address16_data->granularity); 642 address16_data->granularity);
609 643
610 acpi_os_printf (" Address range min: %08X\n", 644 acpi_os_printf (" Address range min: %08X\n",
611 address16_data->min_address_range); 645 address16_data->min_address_range);
612 646
613 acpi_os_printf (" Address range max: %08X\n", 647 acpi_os_printf (" Address range max: %08X\n",
614 address16_data->max_address_range); 648 address16_data->max_address_range);
615 649
616 acpi_os_printf (" Address translation offset: %08X\n", 650 acpi_os_printf (" Address translation offset: %08X\n",
617 address16_data->address_translation_offset); 651 address16_data->address_translation_offset);
618 652
619 acpi_os_printf (" Address Length: %08X\n", 653 acpi_os_printf (" Address Length: %08X\n",
620 address16_data->address_length); 654 address16_data->address_length);
621 655
622 if (0xFF != address16_data->resource_source.index) { 656 if (0xFF != address16_data->resource_source.index) {
623 acpi_os_printf (" Resource Source Index: %X\n", 657 acpi_os_printf (" Resource Source Index: %X\n",
624 address16_data->resource_source.index); 658 address16_data->resource_source.index);
659
625 acpi_os_printf (" Resource Source: %s\n", 660 acpi_os_printf (" Resource Source: %s\n",
626 address16_data->resource_source.string_ptr); 661 address16_data->resource_source.string_ptr);
627 } 662 }
628 663
629 return; 664 return;
@@ -642,7 +677,7 @@ acpi_rs_dump_address16 (
642 * 677 *
643 ******************************************************************************/ 678 ******************************************************************************/
644 679
645void 680static void
646acpi_rs_dump_address32 ( 681acpi_rs_dump_address32 (
647 union acpi_resource_data *data) 682 union acpi_resource_data *data)
648{ 683{
@@ -661,35 +696,30 @@ acpi_rs_dump_address32 (
661 696
662 switch (address32_data->attribute.memory.cache_attribute) { 697 switch (address32_data->attribute.memory.cache_attribute) {
663 case ACPI_NON_CACHEABLE_MEMORY: 698 case ACPI_NON_CACHEABLE_MEMORY:
664 acpi_os_printf (" Type Specific: " 699 acpi_os_printf (" Type Specific: Noncacheable memory\n");
665 "Noncacheable memory\n");
666 break; 700 break;
667 701
668 case ACPI_CACHABLE_MEMORY: 702 case ACPI_CACHABLE_MEMORY:
669 acpi_os_printf (" Type Specific: " 703 acpi_os_printf (" Type Specific: Cacheable memory\n");
670 "Cacheable memory\n");
671 break; 704 break;
672 705
673 case ACPI_WRITE_COMBINING_MEMORY: 706 case ACPI_WRITE_COMBINING_MEMORY:
674 acpi_os_printf (" Type Specific: " 707 acpi_os_printf (" Type Specific: Write-combining memory\n");
675 "Write-combining memory\n");
676 break; 708 break;
677 709
678 case ACPI_PREFETCHABLE_MEMORY: 710 case ACPI_PREFETCHABLE_MEMORY:
679 acpi_os_printf (" Type Specific: " 711 acpi_os_printf (" Type Specific: Prefetchable memory\n");
680 "Prefetchable memory\n");
681 break; 712 break;
682 713
683 default: 714 default:
684 acpi_os_printf (" Type Specific: " 715 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
685 "Invalid cache attribute\n");
686 break; 716 break;
687 } 717 }
688 718
689 acpi_os_printf (" Type Specific: Read%s\n", 719 acpi_os_printf (" Type Specific: Read%s\n",
690 ACPI_READ_WRITE_MEMORY == 720 ACPI_READ_WRITE_MEMORY ==
691 address32_data->attribute.memory.read_write_attribute ? 721 address32_data->attribute.memory.read_write_attribute ?
692 "/Write" : " Only"); 722 "/Write" : " Only");
693 break; 723 break;
694 724
695 case ACPI_IO_RANGE: 725 case ACPI_IO_RANGE:
@@ -698,30 +728,26 @@ acpi_rs_dump_address32 (
698 728
699 switch (address32_data->attribute.io.range_attribute) { 729 switch (address32_data->attribute.io.range_attribute) {
700 case ACPI_NON_ISA_ONLY_RANGES: 730 case ACPI_NON_ISA_ONLY_RANGES:
701 acpi_os_printf (" Type Specific: " 731 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
702 "Non-ISA Io Addresses\n");
703 break; 732 break;
704 733
705 case ACPI_ISA_ONLY_RANGES: 734 case ACPI_ISA_ONLY_RANGES:
706 acpi_os_printf (" Type Specific: " 735 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
707 "ISA Io Addresses\n");
708 break; 736 break;
709 737
710 case ACPI_ENTIRE_RANGE: 738 case ACPI_ENTIRE_RANGE:
711 acpi_os_printf (" Type Specific: " 739 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
712 "ISA and non-ISA Io Addresses\n");
713 break; 740 break;
714 741
715 default: 742 default:
716 acpi_os_printf (" Type Specific: " 743 acpi_os_printf (" Type Specific: Invalid Range attribute");
717 "Invalid Range attribute");
718 break; 744 break;
719 } 745 }
720 746
721 acpi_os_printf (" Type Specific: %s Translation\n", 747 acpi_os_printf (" Type Specific: %s Translation\n",
722 ACPI_SPARSE_TRANSLATION == 748 ACPI_SPARSE_TRANSLATION ==
723 address32_data->attribute.io.translation_attribute ? 749 address32_data->attribute.io.translation_attribute ?
724 "Sparse" : "Dense"); 750 "Sparse" : "Dense");
725 break; 751 break;
726 752
727 case ACPI_BUS_NUMBER_RANGE: 753 case ACPI_BUS_NUMBER_RANGE:
@@ -731,46 +757,48 @@ acpi_rs_dump_address32 (
731 757
732 default: 758 default:
733 759
734 acpi_os_printf (" Resource Type: 0x%2.2X\n", address32_data->resource_type); 760 acpi_os_printf (" Resource Type: 0x%2.2X\n",
761 address32_data->resource_type);
735 break; 762 break;
736 } 763 }
737 764
738 acpi_os_printf (" Resource %s\n", 765 acpi_os_printf (" Resource %s\n",
739 ACPI_CONSUMER == address32_data->producer_consumer ? 766 ACPI_CONSUMER == address32_data->producer_consumer ?
740 "Consumer" : "Producer"); 767 "Consumer" : "Producer");
741 768
742 acpi_os_printf (" %s decode\n", 769 acpi_os_printf (" %s decode\n",
743 ACPI_SUB_DECODE == address32_data->decode ? 770 ACPI_SUB_DECODE == address32_data->decode ?
744 "Subtractive" : "Positive"); 771 "Subtractive" : "Positive");
745 772
746 acpi_os_printf (" Min address is %s fixed\n", 773 acpi_os_printf (" Min address is %s fixed\n",
747 ACPI_ADDRESS_FIXED == address32_data->min_address_fixed ? 774 ACPI_ADDRESS_FIXED == address32_data->min_address_fixed ?
748 "" : "not "); 775 "" : "not ");
749 776
750 acpi_os_printf (" Max address is %s fixed\n", 777 acpi_os_printf (" Max address is %s fixed\n",
751 ACPI_ADDRESS_FIXED == address32_data->max_address_fixed ? 778 ACPI_ADDRESS_FIXED == address32_data->max_address_fixed ?
752 "" : "not "); 779 "" : "not ");
753 780
754 acpi_os_printf (" Granularity: %08X\n", 781 acpi_os_printf (" Granularity: %08X\n",
755 address32_data->granularity); 782 address32_data->granularity);
756 783
757 acpi_os_printf (" Address range min: %08X\n", 784 acpi_os_printf (" Address range min: %08X\n",
758 address32_data->min_address_range); 785 address32_data->min_address_range);
759 786
760 acpi_os_printf (" Address range max: %08X\n", 787 acpi_os_printf (" Address range max: %08X\n",
761 address32_data->max_address_range); 788 address32_data->max_address_range);
762 789
763 acpi_os_printf (" Address translation offset: %08X\n", 790 acpi_os_printf (" Address translation offset: %08X\n",
764 address32_data->address_translation_offset); 791 address32_data->address_translation_offset);
765 792
766 acpi_os_printf (" Address Length: %08X\n", 793 acpi_os_printf (" Address Length: %08X\n",
767 address32_data->address_length); 794 address32_data->address_length);
768 795
769 if(0xFF != address32_data->resource_source.index) { 796 if(0xFF != address32_data->resource_source.index) {
770 acpi_os_printf (" Resource Source Index: %X\n", 797 acpi_os_printf (" Resource Source Index: %X\n",
771 address32_data->resource_source.index); 798 address32_data->resource_source.index);
799
772 acpi_os_printf (" Resource Source: %s\n", 800 acpi_os_printf (" Resource Source: %s\n",
773 address32_data->resource_source.string_ptr); 801 address32_data->resource_source.string_ptr);
774 } 802 }
775 803
776 return; 804 return;
@@ -789,7 +817,7 @@ acpi_rs_dump_address32 (
789 * 817 *
790 ******************************************************************************/ 818 ******************************************************************************/
791 819
792void 820static void
793acpi_rs_dump_address64 ( 821acpi_rs_dump_address64 (
794 union acpi_resource_data *data) 822 union acpi_resource_data *data)
795{ 823{
@@ -808,35 +836,30 @@ acpi_rs_dump_address64 (
808 836
809 switch (address64_data->attribute.memory.cache_attribute) { 837 switch (address64_data->attribute.memory.cache_attribute) {
810 case ACPI_NON_CACHEABLE_MEMORY: 838 case ACPI_NON_CACHEABLE_MEMORY:
811 acpi_os_printf (" Type Specific: " 839 acpi_os_printf (" Type Specific: Noncacheable memory\n");
812 "Noncacheable memory\n");
813 break; 840 break;
814 841
815 case ACPI_CACHABLE_MEMORY: 842 case ACPI_CACHABLE_MEMORY:
816 acpi_os_printf (" Type Specific: " 843 acpi_os_printf (" Type Specific: Cacheable memory\n");
817 "Cacheable memory\n");
818 break; 844 break;
819 845
820 case ACPI_WRITE_COMBINING_MEMORY: 846 case ACPI_WRITE_COMBINING_MEMORY:
821 acpi_os_printf (" Type Specific: " 847 acpi_os_printf (" Type Specific: Write-combining memory\n");
822 "Write-combining memory\n");
823 break; 848 break;
824 849
825 case ACPI_PREFETCHABLE_MEMORY: 850 case ACPI_PREFETCHABLE_MEMORY:
826 acpi_os_printf (" Type Specific: " 851 acpi_os_printf (" Type Specific: Prefetchable memory\n");
827 "Prefetchable memory\n");
828 break; 852 break;
829 853
830 default: 854 default:
831 acpi_os_printf (" Type Specific: " 855 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
832 "Invalid cache attribute\n");
833 break; 856 break;
834 } 857 }
835 858
836 acpi_os_printf (" Type Specific: Read%s\n", 859 acpi_os_printf (" Type Specific: Read%s\n",
837 ACPI_READ_WRITE_MEMORY == 860 ACPI_READ_WRITE_MEMORY ==
838 address64_data->attribute.memory.read_write_attribute ? 861 address64_data->attribute.memory.read_write_attribute ?
839 "/Write" : " Only"); 862 "/Write" : " Only");
840 break; 863 break;
841 864
842 case ACPI_IO_RANGE: 865 case ACPI_IO_RANGE:
@@ -845,30 +868,26 @@ acpi_rs_dump_address64 (
845 868
846 switch (address64_data->attribute.io.range_attribute) { 869 switch (address64_data->attribute.io.range_attribute) {
847 case ACPI_NON_ISA_ONLY_RANGES: 870 case ACPI_NON_ISA_ONLY_RANGES:
848 acpi_os_printf (" Type Specific: " 871 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
849 "Non-ISA Io Addresses\n");
850 break; 872 break;
851 873
852 case ACPI_ISA_ONLY_RANGES: 874 case ACPI_ISA_ONLY_RANGES:
853 acpi_os_printf (" Type Specific: " 875 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
854 "ISA Io Addresses\n");
855 break; 876 break;
856 877
857 case ACPI_ENTIRE_RANGE: 878 case ACPI_ENTIRE_RANGE:
858 acpi_os_printf (" Type Specific: " 879 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
859 "ISA and non-ISA Io Addresses\n");
860 break; 880 break;
861 881
862 default: 882 default:
863 acpi_os_printf (" Type Specific: " 883 acpi_os_printf (" Type Specific: Invalid Range attribute");
864 "Invalid Range attribute");
865 break; 884 break;
866 } 885 }
867 886
868 acpi_os_printf (" Type Specific: %s Translation\n", 887 acpi_os_printf (" Type Specific: %s Translation\n",
869 ACPI_SPARSE_TRANSLATION == 888 ACPI_SPARSE_TRANSLATION ==
870 address64_data->attribute.io.translation_attribute ? 889 address64_data->attribute.io.translation_attribute ?
871 "Sparse" : "Dense"); 890 "Sparse" : "Dense");
872 break; 891 break;
873 892
874 case ACPI_BUS_NUMBER_RANGE: 893 case ACPI_BUS_NUMBER_RANGE:
@@ -878,49 +897,51 @@ acpi_rs_dump_address64 (
878 897
879 default: 898 default:
880 899
881 acpi_os_printf (" Resource Type: 0x%2.2X\n", address64_data->resource_type); 900 acpi_os_printf (" Resource Type: 0x%2.2X\n",
901 address64_data->resource_type);
882 break; 902 break;
883 } 903 }
884 904
885 acpi_os_printf (" Resource %s\n", 905 acpi_os_printf (" Resource %s\n",
886 ACPI_CONSUMER == address64_data->producer_consumer ? 906 ACPI_CONSUMER == address64_data->producer_consumer ?
887 "Consumer" : "Producer"); 907 "Consumer" : "Producer");
888 908
889 acpi_os_printf (" %s decode\n", 909 acpi_os_printf (" %s decode\n",
890 ACPI_SUB_DECODE == address64_data->decode ? 910 ACPI_SUB_DECODE == address64_data->decode ?
891 "Subtractive" : "Positive"); 911 "Subtractive" : "Positive");
892 912
893 acpi_os_printf (" Min address is %s fixed\n", 913 acpi_os_printf (" Min address is %s fixed\n",
894 ACPI_ADDRESS_FIXED == address64_data->min_address_fixed ? 914 ACPI_ADDRESS_FIXED == address64_data->min_address_fixed ?
895 "" : "not "); 915 "" : "not ");
896 916
897 acpi_os_printf (" Max address is %s fixed\n", 917 acpi_os_printf (" Max address is %s fixed\n",
898 ACPI_ADDRESS_FIXED == address64_data->max_address_fixed ? 918 ACPI_ADDRESS_FIXED == address64_data->max_address_fixed ?
899 "" : "not "); 919 "" : "not ");
900 920
901 acpi_os_printf (" Granularity: %8.8X%8.8X\n", 921 acpi_os_printf (" Granularity: %8.8X%8.8X\n",
902 ACPI_FORMAT_UINT64 (address64_data->granularity)); 922 ACPI_FORMAT_UINT64 (address64_data->granularity));
903 923
904 acpi_os_printf (" Address range min: %8.8X%8.8X\n", 924 acpi_os_printf (" Address range min: %8.8X%8.8X\n",
905 ACPI_FORMAT_UINT64 (address64_data->min_address_range)); 925 ACPI_FORMAT_UINT64 (address64_data->min_address_range));
906 926
907 acpi_os_printf (" Address range max: %8.8X%8.8X\n", 927 acpi_os_printf (" Address range max: %8.8X%8.8X\n",
908 ACPI_FORMAT_UINT64 (address64_data->max_address_range)); 928 ACPI_FORMAT_UINT64 (address64_data->max_address_range));
909 929
910 acpi_os_printf (" Address translation offset: %8.8X%8.8X\n", 930 acpi_os_printf (" Address translation offset: %8.8X%8.8X\n",
911 ACPI_FORMAT_UINT64 (address64_data->address_translation_offset)); 931 ACPI_FORMAT_UINT64 (address64_data->address_translation_offset));
912 932
913 acpi_os_printf (" Address Length: %8.8X%8.8X\n", 933 acpi_os_printf (" Address Length: %8.8X%8.8X\n",
914 ACPI_FORMAT_UINT64 (address64_data->address_length)); 934 ACPI_FORMAT_UINT64 (address64_data->address_length));
915 935
916 acpi_os_printf (" Type Specific Attributes: %8.8X%8.8X\n", 936 acpi_os_printf (" Type Specific Attributes: %8.8X%8.8X\n",
917 ACPI_FORMAT_UINT64 (address64_data->type_specific_attributes)); 937 ACPI_FORMAT_UINT64 (address64_data->type_specific_attributes));
918 938
919 if (0xFF != address64_data->resource_source.index) { 939 if (0xFF != address64_data->resource_source.index) {
920 acpi_os_printf (" Resource Source Index: %X\n", 940 acpi_os_printf (" Resource Source Index: %X\n",
921 address64_data->resource_source.index); 941 address64_data->resource_source.index);
942
922 acpi_os_printf (" Resource Source: %s\n", 943 acpi_os_printf (" Resource Source: %s\n",
923 address64_data->resource_source.string_ptr); 944 address64_data->resource_source.string_ptr);
924 } 945 }
925 946
926 return; 947 return;
@@ -939,7 +960,7 @@ acpi_rs_dump_address64 (
939 * 960 *
940 ******************************************************************************/ 961 ******************************************************************************/
941 962
942void 963static void
943acpi_rs_dump_extended_irq ( 964acpi_rs_dump_extended_irq (
944 union acpi_resource_data *data) 965 union acpi_resource_data *data)
945{ 966{
@@ -953,23 +974,22 @@ acpi_rs_dump_extended_irq (
953 acpi_os_printf ("Extended IRQ Resource\n"); 974 acpi_os_printf ("Extended IRQ Resource\n");
954 975
955 acpi_os_printf (" Resource %s\n", 976 acpi_os_printf (" Resource %s\n",
956 ACPI_CONSUMER == ext_irq_data->producer_consumer ? 977 ACPI_CONSUMER == ext_irq_data->producer_consumer ?
957 "Consumer" : "Producer"); 978 "Consumer" : "Producer");
958 979
959 acpi_os_printf (" %s\n", 980 acpi_os_printf (" %s\n",
960 ACPI_LEVEL_SENSITIVE == ext_irq_data->edge_level ? 981 ACPI_LEVEL_SENSITIVE == ext_irq_data->edge_level ?
961 "Level" : "Edge"); 982 "Level" : "Edge");
962 983
963 acpi_os_printf (" Active %s\n", 984 acpi_os_printf (" Active %s\n",
964 ACPI_ACTIVE_LOW == ext_irq_data->active_high_low ? 985 ACPI_ACTIVE_LOW == ext_irq_data->active_high_low ?
965 "low" : "high"); 986 "low" : "high");
966 987
967 acpi_os_printf (" %s\n", 988 acpi_os_printf (" %s\n",
968 ACPI_SHARED == ext_irq_data->shared_exclusive ? 989 ACPI_SHARED == ext_irq_data->shared_exclusive ?
969 "Shared" : "Exclusive"); 990 "Shared" : "Exclusive");
970 991
971 acpi_os_printf (" Interrupts : %X ( ", 992 acpi_os_printf (" Interrupts : %X ( ", ext_irq_data->number_of_interrupts);
972 ext_irq_data->number_of_interrupts);
973 993
974 for (index = 0; index < ext_irq_data->number_of_interrupts; index++) { 994 for (index = 0; index < ext_irq_data->number_of_interrupts; index++) {
975 acpi_os_printf ("%X ", ext_irq_data->interrupts[index]); 995 acpi_os_printf ("%X ", ext_irq_data->interrupts[index]);
@@ -979,9 +999,10 @@ acpi_rs_dump_extended_irq (
979 999
980 if(0xFF != ext_irq_data->resource_source.index) { 1000 if(0xFF != ext_irq_data->resource_source.index) {
981 acpi_os_printf (" Resource Source Index: %X", 1001 acpi_os_printf (" Resource Source Index: %X",
982 ext_irq_data->resource_source.index); 1002 ext_irq_data->resource_source.index);
1003
983 acpi_os_printf (" Resource Source: %s", 1004 acpi_os_printf (" Resource Source: %s",
984 ext_irq_data->resource_source.string_ptr); 1005 ext_irq_data->resource_source.string_ptr);
985 } 1006 }
986 1007
987 return; 1008 return;
@@ -992,7 +1013,7 @@ acpi_rs_dump_extended_irq (
992 * 1013 *
993 * FUNCTION: acpi_rs_dump_resource_list 1014 * FUNCTION: acpi_rs_dump_resource_list
994 * 1015 *
995 * PARAMETERS: Data - pointer to the resource structure to dump. 1016 * PARAMETERS: Resource - pointer to the resource structure to dump.
996 * 1017 *
997 * RETURN: None 1018 * RETURN: None
998 * 1019 *
@@ -1096,7 +1117,7 @@ acpi_rs_dump_resource_list (
1096 * 1117 *
1097 * FUNCTION: acpi_rs_dump_irq_list 1118 * FUNCTION: acpi_rs_dump_irq_list
1098 * 1119 *
1099 * PARAMETERS: Data - pointer to the routing table to dump. 1120 * PARAMETERS: route_table - pointer to the routing table to dump.
1100 * 1121 *
1101 * RETURN: None 1122 * RETURN: None
1102 * 1123 *
@@ -1124,20 +1145,17 @@ acpi_rs_dump_irq_list (
1124 acpi_os_printf ("PCI IRQ Routing Table structure %X.\n", count++); 1145 acpi_os_printf ("PCI IRQ Routing Table structure %X.\n", count++);
1125 1146
1126 acpi_os_printf (" Address: %8.8X%8.8X\n", 1147 acpi_os_printf (" Address: %8.8X%8.8X\n",
1127 ACPI_FORMAT_UINT64 (prt_element->address)); 1148 ACPI_FORMAT_UINT64 (prt_element->address));
1128 1149
1129 acpi_os_printf (" Pin: %X\n", prt_element->pin); 1150 acpi_os_printf (" Pin: %X\n", prt_element->pin);
1130 1151
1131 acpi_os_printf (" Source: %s\n", prt_element->source); 1152 acpi_os_printf (" Source: %s\n", prt_element->source);
1132 1153
1133 acpi_os_printf (" source_index: %X\n", 1154 acpi_os_printf (" source_index: %X\n", prt_element->source_index);
1134 prt_element->source_index);
1135 1155
1136 buffer += prt_element->length; 1156 buffer += prt_element->length;
1137
1138 prt_element = ACPI_CAST_PTR (struct acpi_pci_routing_table, buffer); 1157 prt_element = ACPI_CAST_PTR (struct acpi_pci_routing_table, buffer);
1139 1158 if (0 == prt_element->length) {
1140 if(0 == prt_element->length) {
1141 done = TRUE; 1159 done = TRUE;
1142 } 1160 }
1143 } 1161 }
diff --git a/drivers/acpi/resources/rsio.c b/drivers/acpi/resources/rsio.c
index 972c746d37e4..23a4d149fac8 100644
--- a/drivers/acpi/resources/rsio.c
+++ b/drivers/acpi/resources/rsio.c
@@ -81,67 +81,60 @@ acpi_rs_io_resource (
81 struct acpi_resource *output_struct = (void *) *output_buffer; 81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u16 temp16 = 0; 82 u16 temp16 = 0;
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_io); 84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
85 struct acpi_resource_io);
85 86
86 87
87 ACPI_FUNCTION_TRACE ("rs_io_resource"); 88 ACPI_FUNCTION_TRACE ("rs_io_resource");
88 89
89 90
90 /* 91 /* The number of bytes consumed are Constant */
91 * The number of bytes consumed are Constant 92
92 */
93 *bytes_consumed = 8; 93 *bytes_consumed = 8;
94 94
95 output_struct->id = ACPI_RSTYPE_IO; 95 output_struct->id = ACPI_RSTYPE_IO;
96 96
97 /* 97 /* Check Decode */
98 * Check Decode 98
99 */
100 buffer += 1; 99 buffer += 1;
101 temp8 = *buffer; 100 temp8 = *buffer;
102 101
103 output_struct->data.io.io_decode = temp8 & 0x01; 102 output_struct->data.io.io_decode = temp8 & 0x01;
104 103
105 /* 104 /* Check min_base Address */
106 * Check min_base Address 105
107 */
108 buffer += 1; 106 buffer += 1;
109 ACPI_MOVE_16_TO_16 (&temp16, buffer); 107 ACPI_MOVE_16_TO_16 (&temp16, buffer);
110 108
111 output_struct->data.io.min_base_address = temp16; 109 output_struct->data.io.min_base_address = temp16;
112 110
113 /* 111 /* Check max_base Address */
114 * Check max_base Address 112
115 */
116 buffer += 2; 113 buffer += 2;
117 ACPI_MOVE_16_TO_16 (&temp16, buffer); 114 ACPI_MOVE_16_TO_16 (&temp16, buffer);
118 115
119 output_struct->data.io.max_base_address = temp16; 116 output_struct->data.io.max_base_address = temp16;
120 117
121 /* 118 /* Check Base alignment */
122 * Check Base alignment 119
123 */
124 buffer += 2; 120 buffer += 2;
125 temp8 = *buffer; 121 temp8 = *buffer;
126 122
127 output_struct->data.io.alignment = temp8; 123 output_struct->data.io.alignment = temp8;
128 124
129 /* 125 /* Check range_length */
130 * Check range_length 126
131 */
132 buffer += 1; 127 buffer += 1;
133 temp8 = *buffer; 128 temp8 = *buffer;
134 129
135 output_struct->data.io.range_length = temp8; 130 output_struct->data.io.range_length = temp8;
136 131
137 /* 132 /* Set the Length parameter */
138 * Set the Length parameter 133
139 */
140 output_struct->length = (u32) struct_size; 134 output_struct->length = (u32) struct_size;
141 135
142 /* 136 /* Return the final size of the structure */
143 * Return the final size of the structure 137
144 */
145 *structure_size = struct_size; 138 *structure_size = struct_size;
146 return_ACPI_STATUS (AE_OK); 139 return_ACPI_STATUS (AE_OK);
147} 140}
@@ -179,43 +172,39 @@ acpi_rs_fixed_io_resource (
179 struct acpi_resource *output_struct = (void *) *output_buffer; 172 struct acpi_resource *output_struct = (void *) *output_buffer;
180 u16 temp16 = 0; 173 u16 temp16 = 0;
181 u8 temp8 = 0; 174 u8 temp8 = 0;
182 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_io); 175 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
176 struct acpi_resource_fixed_io);
183 177
184 178
185 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource"); 179 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource");
186 180
187 181
188 /* 182 /* The number of bytes consumed are Constant */
189 * The number of bytes consumed are Constant 183
190 */
191 *bytes_consumed = 4; 184 *bytes_consumed = 4;
192 185
193 output_struct->id = ACPI_RSTYPE_FIXED_IO; 186 output_struct->id = ACPI_RSTYPE_FIXED_IO;
194 187
195 /* 188 /* Check Range Base Address */
196 * Check Range Base Address 189
197 */
198 buffer += 1; 190 buffer += 1;
199 ACPI_MOVE_16_TO_16 (&temp16, buffer); 191 ACPI_MOVE_16_TO_16 (&temp16, buffer);
200 192
201 output_struct->data.fixed_io.base_address = temp16; 193 output_struct->data.fixed_io.base_address = temp16;
202 194
203 /* 195 /* Check range_length */
204 * Check range_length 196
205 */
206 buffer += 2; 197 buffer += 2;
207 temp8 = *buffer; 198 temp8 = *buffer;
208 199
209 output_struct->data.fixed_io.range_length = temp8; 200 output_struct->data.fixed_io.range_length = temp8;
210 201
211 /* 202 /* Set the Length parameter */
212 * Set the Length parameter 203
213 */
214 output_struct->length = (u32) struct_size; 204 output_struct->length = (u32) struct_size;
215 205
216 /* 206 /* Return the final size of the structure */
217 * Return the final size of the structure 207
218 */
219 *structure_size = struct_size; 208 *structure_size = struct_size;
220 return_ACPI_STATUS (AE_OK); 209 return_ACPI_STATUS (AE_OK);
221} 210}
@@ -251,55 +240,48 @@ acpi_rs_io_stream (
251 ACPI_FUNCTION_TRACE ("rs_io_stream"); 240 ACPI_FUNCTION_TRACE ("rs_io_stream");
252 241
253 242
254 /* 243 /* The descriptor field is static */
255 * The descriptor field is static 244
256 */
257 *buffer = 0x47; 245 *buffer = 0x47;
258 buffer += 1; 246 buffer += 1;
259 247
260 /* 248 /* Io Information Byte */
261 * Io Information Byte 249
262 */
263 temp8 = (u8) (linked_list->data.io.io_decode & 0x01); 250 temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
264 251
265 *buffer = temp8; 252 *buffer = temp8;
266 buffer += 1; 253 buffer += 1;
267 254
268 /* 255 /* Set the Range minimum base address */
269 * Set the Range minimum base address 256
270 */
271 temp16 = (u16) linked_list->data.io.min_base_address; 257 temp16 = (u16) linked_list->data.io.min_base_address;
272 258
273 ACPI_MOVE_16_TO_16 (buffer, &temp16); 259 ACPI_MOVE_16_TO_16 (buffer, &temp16);
274 buffer += 2; 260 buffer += 2;
275 261
276 /* 262 /* Set the Range maximum base address */
277 * Set the Range maximum base address 263
278 */
279 temp16 = (u16) linked_list->data.io.max_base_address; 264 temp16 = (u16) linked_list->data.io.max_base_address;
280 265
281 ACPI_MOVE_16_TO_16 (buffer, &temp16); 266 ACPI_MOVE_16_TO_16 (buffer, &temp16);
282 buffer += 2; 267 buffer += 2;
283 268
284 /* 269 /* Set the base alignment */
285 * Set the base alignment 270
286 */
287 temp8 = (u8) linked_list->data.io.alignment; 271 temp8 = (u8) linked_list->data.io.alignment;
288 272
289 *buffer = temp8; 273 *buffer = temp8;
290 buffer += 1; 274 buffer += 1;
291 275
292 /* 276 /* Set the range length */
293 * Set the range length 277
294 */
295 temp8 = (u8) linked_list->data.io.range_length; 278 temp8 = (u8) linked_list->data.io.range_length;
296 279
297 *buffer = temp8; 280 *buffer = temp8;
298 buffer += 1; 281 buffer += 1;
299 282
300 /* 283 /* Return the number of bytes consumed in this operation */
301 * Return the number of bytes consumed in this operation 284
302 */
303 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 285 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
304 return_ACPI_STATUS (AE_OK); 286 return_ACPI_STATUS (AE_OK);
305} 287}
@@ -335,32 +317,28 @@ acpi_rs_fixed_io_stream (
335 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream"); 317 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream");
336 318
337 319
338 /* 320 /* The descriptor field is static */
339 * The descriptor field is static 321
340 */
341 *buffer = 0x4B; 322 *buffer = 0x4B;
342 323
343 buffer += 1; 324 buffer += 1;
344 325
345 /* 326 /* Set the Range base address */
346 * Set the Range base address 327
347 */
348 temp16 = (u16) linked_list->data.fixed_io.base_address; 328 temp16 = (u16) linked_list->data.fixed_io.base_address;
349 329
350 ACPI_MOVE_16_TO_16 (buffer, &temp16); 330 ACPI_MOVE_16_TO_16 (buffer, &temp16);
351 buffer += 2; 331 buffer += 2;
352 332
353 /* 333 /* Set the range length */
354 * Set the range length 334
355 */
356 temp8 = (u8) linked_list->data.fixed_io.range_length; 335 temp8 = (u8) linked_list->data.fixed_io.range_length;
357 336
358 *buffer = temp8; 337 *buffer = temp8;
359 buffer += 1; 338 buffer += 1;
360 339
361 /* 340 /* Return the number of bytes consumed in this operation */
362 * Return the number of bytes consumed in this operation 341
363 */
364 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 342 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
365 return_ACPI_STATUS (AE_OK); 343 return_ACPI_STATUS (AE_OK);
366} 344}
@@ -399,21 +377,20 @@ acpi_rs_dma_resource (
399 u8 temp8 = 0; 377 u8 temp8 = 0;
400 u8 index; 378 u8 index;
401 u8 i; 379 u8 i;
402 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_dma); 380 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
381 struct acpi_resource_dma);
403 382
404 383
405 ACPI_FUNCTION_TRACE ("rs_dma_resource"); 384 ACPI_FUNCTION_TRACE ("rs_dma_resource");
406 385
407 386
408 /* 387 /* The number of bytes consumed are Constant */
409 * The number of bytes consumed are Constant 388
410 */
411 *bytes_consumed = 3; 389 *bytes_consumed = 3;
412 output_struct->id = ACPI_RSTYPE_DMA; 390 output_struct->id = ACPI_RSTYPE_DMA;
413 391
414 /* 392 /* Point to the 8-bits of Byte 1 */
415 * Point to the 8-bits of Byte 1 393
416 */
417 buffer += 1; 394 buffer += 1;
418 temp8 = *buffer; 395 temp8 = *buffer;
419 396
@@ -430,46 +407,40 @@ acpi_rs_dma_resource (
430 407
431 output_struct->data.dma.number_of_channels = i; 408 output_struct->data.dma.number_of_channels = i;
432 if (i > 0) { 409 if (i > 0) {
433 /* 410 /* Calculate the structure size based upon the number of interrupts */
434 * Calculate the structure size based upon the number of interrupts 411
435 */
436 struct_size += ((acpi_size) i - 1) * 4; 412 struct_size += ((acpi_size) i - 1) * 4;
437 } 413 }
438 414
439 /* 415 /* Point to Byte 2 */
440 * Point to Byte 2 416
441 */
442 buffer += 1; 417 buffer += 1;
443 temp8 = *buffer; 418 temp8 = *buffer;
444 419
445 /* 420 /* Check for transfer preference (Bits[1:0]) */
446 * Check for transfer preference (Bits[1:0]) 421
447 */
448 output_struct->data.dma.transfer = temp8 & 0x03; 422 output_struct->data.dma.transfer = temp8 & 0x03;
449 423
450 if (0x03 == output_struct->data.dma.transfer) { 424 if (0x03 == output_struct->data.dma.transfer) {
451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid DMA.Transfer preference (3)\n")); 425 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
426 "Invalid DMA.Transfer preference (3)\n"));
452 return_ACPI_STATUS (AE_BAD_DATA); 427 return_ACPI_STATUS (AE_BAD_DATA);
453 } 428 }
454 429
455 /* 430 /* Get bus master preference (Bit[2]) */
456 * Get bus master preference (Bit[2]) 431
457 */
458 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01; 432 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
459 433
460 /* 434 /* Get channel speed support (Bits[6:5]) */
461 * Get channel speed support (Bits[6:5]) 435
462 */
463 output_struct->data.dma.type = (temp8 >> 5) & 0x03; 436 output_struct->data.dma.type = (temp8 >> 5) & 0x03;
464 437
465 /* 438 /* Set the Length parameter */
466 * Set the Length parameter 439
467 */
468 output_struct->length = (u32) struct_size; 440 output_struct->length = (u32) struct_size;
469 441
470 /* 442 /* Return the final size of the structure */
471 * Return the final size of the structure 443
472 */
473 *structure_size = struct_size; 444 *structure_size = struct_size;
474 return_ACPI_STATUS (AE_OK); 445 return_ACPI_STATUS (AE_OK);
475} 446}
@@ -506,16 +477,14 @@ acpi_rs_dma_stream (
506 ACPI_FUNCTION_TRACE ("rs_dma_stream"); 477 ACPI_FUNCTION_TRACE ("rs_dma_stream");
507 478
508 479
509 /* 480 /* The descriptor field is static */
510 * The descriptor field is static 481
511 */
512 *buffer = 0x2A; 482 *buffer = 0x2A;
513 buffer += 1; 483 buffer += 1;
514 temp8 = 0; 484 temp8 = 0;
515 485
516 /* 486 /* Loop through all of the Channels and set the mask bits */
517 * Loop through all of the Channels and set the mask bits 487
518 */
519 for (index = 0; 488 for (index = 0;
520 index < linked_list->data.dma.number_of_channels; 489 index < linked_list->data.dma.number_of_channels;
521 index++) { 490 index++) {
@@ -526,9 +495,8 @@ acpi_rs_dma_stream (
526 *buffer = temp8; 495 *buffer = temp8;
527 buffer += 1; 496 buffer += 1;
528 497
529 /* 498 /* Set the DMA Info */
530 * Set the DMA Info 499
531 */
532 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5); 500 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
533 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2); 501 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
534 temp8 |= (linked_list->data.dma.transfer & 0x03); 502 temp8 |= (linked_list->data.dma.transfer & 0x03);
@@ -536,9 +504,8 @@ acpi_rs_dma_stream (
536 *buffer = temp8; 504 *buffer = temp8;
537 buffer += 1; 505 buffer += 1;
538 506
539 /* 507 /* Return the number of bytes consumed in this operation */
540 * Return the number of bytes consumed in this operation 508
541 */
542 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 509 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
543 return_ACPI_STATUS (AE_OK); 510 return_ACPI_STATUS (AE_OK);
544} 511}
diff --git a/drivers/acpi/resources/rsirq.c b/drivers/acpi/resources/rsirq.c
index fd07a8702fbe..8a2b630be45b 100644
--- a/drivers/acpi/resources/rsirq.c
+++ b/drivers/acpi/resources/rsirq.c
@@ -83,7 +83,8 @@ acpi_rs_irq_resource (
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 u8 index; 84 u8 index;
85 u8 i; 85 u8 i;
86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_irq); 86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
87 struct acpi_resource_irq);
87 88
88 89
89 ACPI_FUNCTION_TRACE ("rs_irq_resource"); 90 ACPI_FUNCTION_TRACE ("rs_irq_resource");
@@ -91,15 +92,14 @@ acpi_rs_irq_resource (
91 92
92 /* 93 /*
93 * The number of bytes consumed are contained in the descriptor 94 * The number of bytes consumed are contained in the descriptor
94 * (Bits:0-1) 95 * (Bits:0-1)
95 */ 96 */
96 temp8 = *buffer; 97 temp8 = *buffer;
97 *bytes_consumed = (temp8 & 0x03) + 1; 98 *bytes_consumed = (temp8 & 0x03) + 1;
98 output_struct->id = ACPI_RSTYPE_IRQ; 99 output_struct->id = ACPI_RSTYPE_IRQ;
99 100
100 /* 101 /* Point to the 16-bits of Bytes 1 and 2 */
101 * Point to the 16-bits of Bytes 1 and 2 102
102 */
103 buffer += 1; 103 buffer += 1;
104 ACPI_MOVE_16_TO_16 (&temp16, buffer); 104 ACPI_MOVE_16_TO_16 (&temp16, buffer);
105 105
@@ -118,22 +118,19 @@ acpi_rs_irq_resource (
118 118
119 output_struct->data.irq.number_of_interrupts = i; 119 output_struct->data.irq.number_of_interrupts = i;
120 if (i > 0) { 120 if (i > 0) {
121 /* 121 /* Calculate the structure size based upon the number of interrupts */
122 * Calculate the structure size based upon the number of interrupts 122
123 */
124 struct_size += ((acpi_size) i - 1) * 4; 123 struct_size += ((acpi_size) i - 1) * 4;
125 } 124 }
126 125
127 /* 126 /* Point to Byte 3 if it is used */
128 * Point to Byte 3 if it is used 127
129 */
130 if (4 == *bytes_consumed) { 128 if (4 == *bytes_consumed) {
131 buffer += 2; 129 buffer += 2;
132 temp8 = *buffer; 130 temp8 = *buffer;
133 131
134 /* 132 /* Check for HE, LL interrupts */
135 * Check for HE, LL interrupts 133
136 */
137 switch (temp8 & 0x09) { 134 switch (temp8 & 0x09) {
138 case 0x01: /* HE */ 135 case 0x01: /* HE */
139 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE; 136 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE;
@@ -152,13 +149,13 @@ acpi_rs_irq_resource (
152 * so 0x00 and 0x09 are illegal. 149 * so 0x00 and 0x09 are illegal.
153 */ 150 */
154 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 151 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
155 "Invalid interrupt polarity/trigger in resource list, %X\n", temp8)); 152 "Invalid interrupt polarity/trigger in resource list, %X\n",
153 temp8));
156 return_ACPI_STATUS (AE_BAD_DATA); 154 return_ACPI_STATUS (AE_BAD_DATA);
157 } 155 }
158 156
159 /* 157 /* Check for sharable */
160 * Check for sharable 158
161 */
162 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01; 159 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01;
163 } 160 }
164 else { 161 else {
@@ -171,14 +168,12 @@ acpi_rs_irq_resource (
171 output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE; 168 output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
172 } 169 }
173 170
174 /* 171 /* Set the Length parameter */
175 * Set the Length parameter 172
176 */
177 output_struct->length = (u32) struct_size; 173 output_struct->length = (u32) struct_size;
178 174
179 /* 175 /* Return the final size of the structure */
180 * Return the final size of the structure 176
181 */
182 *structure_size = struct_size; 177 *structure_size = struct_size;
183 return_ACPI_STATUS (AE_OK); 178 return_ACPI_STATUS (AE_OK);
184} 179}
@@ -234,9 +229,8 @@ acpi_rs_irq_stream (
234 buffer += 1; 229 buffer += 1;
235 temp16 = 0; 230 temp16 = 0;
236 231
237 /* 232 /* Loop through all of the interrupts and set the mask bits */
238 * Loop through all of the interrupts and set the mask bits 233
239 */
240 for(index = 0; 234 for(index = 0;
241 index < linked_list->data.irq.number_of_interrupts; 235 index < linked_list->data.irq.number_of_interrupts;
242 index++) { 236 index++) {
@@ -247,9 +241,8 @@ acpi_rs_irq_stream (
247 ACPI_MOVE_16_TO_16 (buffer, &temp16); 241 ACPI_MOVE_16_TO_16 (buffer, &temp16);
248 buffer += 2; 242 buffer += 2;
249 243
250 /* 244 /* Set the IRQ Info byte if needed. */
251 * Set the IRQ Info byte if needed. 245
252 */
253 if (IRqinfo_byte_needed) { 246 if (IRqinfo_byte_needed) {
254 temp8 = 0; 247 temp8 = 0;
255 temp8 = (u8) ((linked_list->data.irq.shared_exclusive & 248 temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
@@ -267,9 +260,8 @@ acpi_rs_irq_stream (
267 buffer += 1; 260 buffer += 1;
268 } 261 }
269 262
270 /* 263 /* Return the number of bytes consumed in this operation */
271 * Return the number of bytes consumed in this operation 264
272 */
273 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 265 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
274 return_ACPI_STATUS (AE_OK); 266 return_ACPI_STATUS (AE_OK);
275} 267}
@@ -309,15 +301,15 @@ acpi_rs_extended_irq_resource (
309 u8 temp8 = 0; 301 u8 temp8 = 0;
310 u8 *temp_ptr; 302 u8 *temp_ptr;
311 u8 index; 303 u8 index;
312 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq); 304 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
305 struct acpi_resource_ext_irq);
313 306
314 307
315 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource"); 308 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource");
316 309
317 310
318 /* 311 /* Point past the Descriptor to get the number of bytes consumed */
319 * Point past the Descriptor to get the number of bytes consumed 312
320 */
321 buffer += 1; 313 buffer += 1;
322 ACPI_MOVE_16_TO_16 (&temp16, buffer); 314 ACPI_MOVE_16_TO_16 (&temp16, buffer);
323 315
@@ -330,9 +322,8 @@ acpi_rs_extended_irq_resource (
330 *bytes_consumed = temp16 + 3; 322 *bytes_consumed = temp16 + 3;
331 output_struct->id = ACPI_RSTYPE_EXT_IRQ; 323 output_struct->id = ACPI_RSTYPE_EXT_IRQ;
332 324
333 /* 325 /* Point to the Byte3 */
334 * Point to the Byte3 326
335 */
336 buffer += 2; 327 buffer += 2;
337 temp8 = *buffer; 328 temp8 = *buffer;
338 329
@@ -347,21 +338,18 @@ acpi_rs_extended_irq_resource (
347 * - Edge/Level are defined opposite in the table vs the headers 338 * - Edge/Level are defined opposite in the table vs the headers
348 */ 339 */
349 output_struct->data.extended_irq.edge_level = 340 output_struct->data.extended_irq.edge_level =
350 (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; 341 (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
342
343 /* Check Interrupt Polarity */
351 344
352 /*
353 * Check Interrupt Polarity
354 */
355 output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1; 345 output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1;
356 346
357 /* 347 /* Check for sharable */
358 * Check for sharable 348
359 */
360 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01; 349 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01;
361 350
362 /* 351 /* Point to Byte4 (IRQ Table length) */
363 * Point to Byte4 (IRQ Table length) 352
364 */
365 buffer += 1; 353 buffer += 1;
366 temp8 = *buffer; 354 temp8 = *buffer;
367 355
@@ -379,14 +367,12 @@ acpi_rs_extended_irq_resource (
379 */ 367 */
380 struct_size += (temp8 - 1) * 4; 368 struct_size += (temp8 - 1) * 4;
381 369
382 /* 370 /* Point to Byte5 (First IRQ Number) */
383 * Point to Byte5 (First IRQ Number) 371
384 */
385 buffer += 1; 372 buffer += 1;
386 373
387 /* 374 /* Cycle through every IRQ in the table */
388 * Cycle through every IRQ in the table 375
389 */
390 for (index = 0; index < temp8; index++) { 376 for (index = 0; index < temp8; index++) {
391 ACPI_MOVE_32_TO_32 ( 377 ACPI_MOVE_32_TO_32 (
392 &output_struct->data.extended_irq.interrupts[index], buffer); 378 &output_struct->data.extended_irq.interrupts[index], buffer);
@@ -407,7 +393,8 @@ acpi_rs_extended_irq_resource (
407 * we add 1 to the length. 393 * we add 1 to the length.
408 */ 394 */
409 if (*bytes_consumed > 395 if (*bytes_consumed >
410 ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) + (5 + 1)) { 396 ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) +
397 (5 + 1)) {
411 /* Dereference the Index */ 398 /* Dereference the Index */
412 399
413 temp8 = *buffer; 400 temp8 = *buffer;
@@ -417,13 +404,13 @@ acpi_rs_extended_irq_resource (
417 404
418 buffer += 1; 405 buffer += 1;
419 406
420 /* 407 /* Point the String pointer to the end of this structure. */
421 * Point the String pointer to the end of this structure. 408
422 */
423 output_struct->data.extended_irq.resource_source.string_ptr = 409 output_struct->data.extended_irq.resource_source.string_ptr =
424 (char *)((char *) output_struct + struct_size); 410 (char *)((char *) output_struct + struct_size);
425 411
426 temp_ptr = (u8 *) output_struct->data.extended_irq.resource_source.string_ptr; 412 temp_ptr = (u8 *)
413 output_struct->data.extended_irq.resource_source.string_ptr;
427 414
428 /* Copy the string into the buffer */ 415 /* Copy the string into the buffer */
429 416
@@ -436,9 +423,8 @@ acpi_rs_extended_irq_resource (
436 index += 1; 423 index += 1;
437 } 424 }
438 425
439 /* 426 /* Add the terminating null */
440 * Add the terminating null 427
441 */
442 *temp_ptr = 0x00; 428 *temp_ptr = 0x00;
443 output_struct->data.extended_irq.resource_source.string_length = index + 1; 429 output_struct->data.extended_irq.resource_source.string_length = index + 1;
444 430
@@ -456,14 +442,12 @@ acpi_rs_extended_irq_resource (
456 output_struct->data.extended_irq.resource_source.string_ptr = NULL; 442 output_struct->data.extended_irq.resource_source.string_ptr = NULL;
457 } 443 }
458 444
459 /* 445 /* Set the Length parameter */
460 * Set the Length parameter 446
461 */
462 output_struct->length = (u32) struct_size; 447 output_struct->length = (u32) struct_size;
463 448
464 /* 449 /* Return the final size of the structure */
465 * Return the final size of the structure 450
466 */
467 *structure_size = struct_size; 451 *structure_size = struct_size;
468 return_ACPI_STATUS (AE_OK); 452 return_ACPI_STATUS (AE_OK);
469} 453}
@@ -501,21 +485,18 @@ acpi_rs_extended_irq_stream (
501 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream"); 485 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream");
502 486
503 487
504 /* 488 /* The descriptor field is static */
505 * The descriptor field is static 489
506 */
507 *buffer = 0x89; 490 *buffer = 0x89;
508 buffer += 1; 491 buffer += 1;
509 492
510 /* 493 /* Set a pointer to the Length field - to be filled in later */
511 * Set a pointer to the Length field - to be filled in later 494
512 */
513 length_field = ACPI_CAST_PTR (u16, buffer); 495 length_field = ACPI_CAST_PTR (u16, buffer);
514 buffer += 2; 496 buffer += 2;
515 497
516 /* 498 /* Set the Interrupt vector flags */
517 * Set the Interrupt vector flags 499
518 */
519 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01); 500 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01);
520 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3); 501 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3);
521 502
@@ -532,17 +513,15 @@ acpi_rs_extended_irq_stream (
532 temp8 |= 0x2; 513 temp8 |= 0x2;
533 } 514 }
534 515
535 /* 516 /* Set the Interrupt Polarity */
536 * Set the Interrupt Polarity 517
537 */
538 temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2); 518 temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2);
539 519
540 *buffer = temp8; 520 *buffer = temp8;
541 buffer += 1; 521 buffer += 1;
542 522
543 /* 523 /* Set the Interrupt table length */
544 * Set the Interrupt table length 524
545 */
546 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts; 525 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts;
547 526
548 *buffer = temp8; 527 *buffer = temp8;
@@ -555,18 +534,16 @@ acpi_rs_extended_irq_stream (
555 buffer += 4; 534 buffer += 4;
556 } 535 }
557 536
558 /* 537 /* Resource Source Index and Resource Source are optional */
559 * Resource Source Index and Resource Source are optional 538
560 */
561 if (0 != linked_list->data.extended_irq.resource_source.string_length) { 539 if (0 != linked_list->data.extended_irq.resource_source.string_length) {
562 *buffer = (u8) linked_list->data.extended_irq.resource_source.index; 540 *buffer = (u8) linked_list->data.extended_irq.resource_source.index;
563 buffer += 1; 541 buffer += 1;
564 542
565 temp_pointer = (char *) buffer; 543 temp_pointer = (char *) buffer;
566 544
567 /* 545 /* Copy the string */
568 * Copy the string 546
569 */
570 ACPI_STRCPY (temp_pointer, 547 ACPI_STRCPY (temp_pointer,
571 linked_list->data.extended_irq.resource_source.string_ptr); 548 linked_list->data.extended_irq.resource_source.string_ptr);
572 549
@@ -574,12 +551,12 @@ acpi_rs_extended_irq_stream (
574 * Buffer needs to be set to the length of the sting + one for the 551 * Buffer needs to be set to the length of the sting + one for the
575 * terminating null 552 * terminating null
576 */ 553 */
577 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.extended_irq.resource_source.string_ptr) + 1); 554 buffer += (acpi_size) (ACPI_STRLEN (
555 linked_list->data.extended_irq.resource_source.string_ptr) + 1);
578 } 556 }
579 557
580 /* 558 /* Return the number of bytes consumed in this operation */
581 * Return the number of bytes consumed in this operation 559
582 */
583 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 560 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
584 561
585 /* 562 /*
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
index e49c1e030f99..db7bcb4e60e3 100644
--- a/drivers/acpi/resources/rslist.c
+++ b/drivers/acpi/resources/rslist.c
@@ -55,7 +55,7 @@
55 * 55 *
56 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor 56 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor
57 * 57 *
58 * RETURN: The Resource Type (Name) with no extraneous bits 58 * RETURN: The Resource Type with no extraneous bits
59 * 59 *
60 * DESCRIPTION: Extract the Resource Type/Name from the first byte of 60 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
61 * a resource descriptor. 61 * a resource descriptor.
@@ -70,28 +70,25 @@ acpi_rs_get_resource_type (
70 ACPI_FUNCTION_ENTRY (); 70 ACPI_FUNCTION_ENTRY ();
71 71
72 72
73 /* 73 /* Determine if this is a small or large resource */
74 * Determine if this is a small or large resource 74
75 */
76 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) { 75 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) {
77 case ACPI_RDESC_TYPE_SMALL: 76 case ACPI_RDESC_TYPE_SMALL:
78 77
79 /* 78 /* Small Resource Type -- Only bits 6:3 are valid */
80 * Small Resource Type -- Only bits 6:3 are valid 79
81 */
82 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK)); 80 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK));
83 81
84 82
85 case ACPI_RDESC_TYPE_LARGE: 83 case ACPI_RDESC_TYPE_LARGE:
86 84
87 /* 85 /* Large Resource Type -- All bits are valid */
88 * Large Resource Type -- All bits are valid 86
89 */
90 return (resource_start_byte); 87 return (resource_start_byte);
91 88
92 89
93 default: 90 default:
94 /* No other types of resource descriptor */ 91 /* Invalid type */
95 break; 92 break;
96 } 93 }
97 94
@@ -135,9 +132,8 @@ acpi_rs_byte_stream_to_list (
135 132
136 while (bytes_parsed < byte_stream_buffer_length && 133 while (bytes_parsed < byte_stream_buffer_length &&
137 !end_tag_processed) { 134 !end_tag_processed) {
138 /* 135 /* The next byte in the stream is the resource type */
139 * The next byte in the stream is the resource type 136
140 */
141 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer); 137 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
142 138
143 switch (resource_type) { 139 switch (resource_type) {
@@ -299,28 +295,23 @@ acpi_rs_byte_stream_to_list (
299 return_ACPI_STATUS (status); 295 return_ACPI_STATUS (status);
300 } 296 }
301 297
302 /* 298 /* Update the return value and counter */
303 * Update the return value and counter 299
304 */
305 bytes_parsed += bytes_consumed; 300 bytes_parsed += bytes_consumed;
306 301
307 /* 302 /* Set the byte stream to point to the next resource */
308 * Set the byte stream to point to the next resource 303
309 */
310 byte_stream_buffer += bytes_consumed; 304 byte_stream_buffer += bytes_consumed;
311 305
312 /* 306 /* Set the Buffer to the next structure */
313 * Set the Buffer to the next structure 307
314 */
315 resource = ACPI_CAST_PTR (struct acpi_resource, buffer); 308 resource = ACPI_CAST_PTR (struct acpi_resource, buffer);
316 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length); 309 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length);
317 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size); 310 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size);
311 }
318 312
319 } /* end while */ 313 /* Check the reason for exiting the while loop */
320 314
321 /*
322 * Check the reason for exiting the while loop
323 */
324 if (!end_tag_processed) { 315 if (!end_tag_processed) {
325 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 316 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
326 } 317 }
@@ -424,9 +415,8 @@ acpi_rs_list_to_byte_stream (
424 */ 415 */
425 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed); 416 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed);
426 417
427 /* 418 /* An End Tag indicates the end of the Resource Template */
428 * An End Tag indicates the end of the Resource Template 419
429 */
430 done = TRUE; 420 done = TRUE;
431 break; 421 break;
432 422
@@ -488,27 +478,25 @@ acpi_rs_list_to_byte_stream (
488 default: 478 default:
489 /* 479 /*
490 * If we get here, everything is out of sync, 480 * If we get here, everything is out of sync,
491 * so exit with an error 481 * so exit with an error
492 */ 482 */
493 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type (%X) in resource list\n", 483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Invalid descriptor type (%X) in resource list\n",
494 linked_list->id)); 485 linked_list->id));
495 status = AE_BAD_DATA; 486 status = AE_BAD_DATA;
496 break; 487 break;
497 488 }
498 } /* switch (linked_list->Id) */
499 489
500 if (ACPI_FAILURE (status)) { 490 if (ACPI_FAILURE (status)) {
501 return_ACPI_STATUS (status); 491 return_ACPI_STATUS (status);
502 } 492 }
503 493
504 /* 494 /* Set the Buffer to point to the open byte */
505 * Set the Buffer to point to the open byte 495
506 */
507 buffer += bytes_consumed; 496 buffer += bytes_consumed;
508 497
509 /* 498 /* Point to the next object */
510 * Point to the next object 499
511 */
512 linked_list = ACPI_PTR_ADD (struct acpi_resource, 500 linked_list = ACPI_PTR_ADD (struct acpi_resource,
513 linked_list, linked_list->length); 501 linked_list, linked_list->length);
514 } 502 }
diff --git a/drivers/acpi/resources/rsmemory.c b/drivers/acpi/resources/rsmemory.c
index 7c935aecf075..91d0207f01ac 100644
--- a/drivers/acpi/resources/rsmemory.c
+++ b/drivers/acpi/resources/rsmemory.c
@@ -81,15 +81,15 @@ acpi_rs_memory24_resource (
81 struct acpi_resource *output_struct = (void *) *output_buffer; 81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u16 temp16 = 0; 82 u16 temp16 = 0;
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem24); 84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
85 struct acpi_resource_mem24);
85 86
86 87
87 ACPI_FUNCTION_TRACE ("rs_memory24_resource"); 88 ACPI_FUNCTION_TRACE ("rs_memory24_resource");
88 89
89 90
90 /* 91 /* Point past the Descriptor to get the number of bytes consumed */
91 * Point past the Descriptor to get the number of bytes consumed 92
92 */
93 buffer += 1; 93 buffer += 1;
94 94
95 ACPI_MOVE_16_TO_16 (&temp16, buffer); 95 ACPI_MOVE_16_TO_16 (&temp16, buffer);
@@ -97,48 +97,41 @@ acpi_rs_memory24_resource (
97 *bytes_consumed = (acpi_size) temp16 + 3; 97 *bytes_consumed = (acpi_size) temp16 + 3;
98 output_struct->id = ACPI_RSTYPE_MEM24; 98 output_struct->id = ACPI_RSTYPE_MEM24;
99 99
100 /* 100 /* Check Byte 3 the Read/Write bit */
101 * Check Byte 3 the Read/Write bit 101
102 */
103 temp8 = *buffer; 102 temp8 = *buffer;
104 buffer += 1; 103 buffer += 1;
105 output_struct->data.memory24.read_write_attribute = temp8 & 0x01; 104 output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
106 105
107 /* 106 /* Get min_base_address (Bytes 4-5) */
108 * Get min_base_address (Bytes 4-5) 107
109 */
110 ACPI_MOVE_16_TO_16 (&temp16, buffer); 108 ACPI_MOVE_16_TO_16 (&temp16, buffer);
111 buffer += 2; 109 buffer += 2;
112 output_struct->data.memory24.min_base_address = temp16; 110 output_struct->data.memory24.min_base_address = temp16;
113 111
114 /* 112 /* Get max_base_address (Bytes 6-7) */
115 * Get max_base_address (Bytes 6-7) 113
116 */
117 ACPI_MOVE_16_TO_16 (&temp16, buffer); 114 ACPI_MOVE_16_TO_16 (&temp16, buffer);
118 buffer += 2; 115 buffer += 2;
119 output_struct->data.memory24.max_base_address = temp16; 116 output_struct->data.memory24.max_base_address = temp16;
120 117
121 /* 118 /* Get Alignment (Bytes 8-9) */
122 * Get Alignment (Bytes 8-9) 119
123 */
124 ACPI_MOVE_16_TO_16 (&temp16, buffer); 120 ACPI_MOVE_16_TO_16 (&temp16, buffer);
125 buffer += 2; 121 buffer += 2;
126 output_struct->data.memory24.alignment = temp16; 122 output_struct->data.memory24.alignment = temp16;
127 123
128 /* 124 /* Get range_length (Bytes 10-11) */
129 * Get range_length (Bytes 10-11) 125
130 */
131 ACPI_MOVE_16_TO_16 (&temp16, buffer); 126 ACPI_MOVE_16_TO_16 (&temp16, buffer);
132 output_struct->data.memory24.range_length = temp16; 127 output_struct->data.memory24.range_length = temp16;
133 128
134 /* 129 /* Set the Length parameter */
135 * Set the Length parameter 130
136 */
137 output_struct->length = (u32) struct_size; 131 output_struct->length = (u32) struct_size;
138 132
139 /* 133 /* Return the final size of the structure */
140 * Return the final size of the structure 134
141 */
142 *structure_size = struct_size; 135 *structure_size = struct_size;
143 return_ACPI_STATUS (AE_OK); 136 return_ACPI_STATUS (AE_OK);
144} 137}
@@ -174,53 +167,45 @@ acpi_rs_memory24_stream (
174 ACPI_FUNCTION_TRACE ("rs_memory24_stream"); 167 ACPI_FUNCTION_TRACE ("rs_memory24_stream");
175 168
176 169
177 /* 170 /* The descriptor field is static */
178 * The descriptor field is static 171
179 */
180 *buffer = 0x81; 172 *buffer = 0x81;
181 buffer += 1; 173 buffer += 1;
182 174
183 /* 175 /* The length field is static */
184 * The length field is static 176
185 */
186 temp16 = 0x09; 177 temp16 = 0x09;
187 ACPI_MOVE_16_TO_16 (buffer, &temp16); 178 ACPI_MOVE_16_TO_16 (buffer, &temp16);
188 buffer += 2; 179 buffer += 2;
189 180
190 /* 181 /* Set the Information Byte */
191 * Set the Information Byte 182
192 */
193 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01); 183 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
194 *buffer = temp8; 184 *buffer = temp8;
195 buffer += 1; 185 buffer += 1;
196 186
197 /* 187 /* Set the Range minimum base address */
198 * Set the Range minimum base address 188
199 */
200 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.min_base_address); 189 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.min_base_address);
201 buffer += 2; 190 buffer += 2;
202 191
203 /* 192 /* Set the Range maximum base address */
204 * Set the Range maximum base address 193
205 */
206 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.max_base_address); 194 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.max_base_address);
207 buffer += 2; 195 buffer += 2;
208 196
209 /* 197 /* Set the base alignment */
210 * Set the base alignment 198
211 */
212 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.alignment); 199 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.alignment);
213 buffer += 2; 200 buffer += 2;
214 201
215 /* 202 /* Set the range length */
216 * Set the range length 203
217 */
218 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.range_length); 204 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.range_length);
219 buffer += 2; 205 buffer += 2;
220 206
221 /* 207 /* Return the number of bytes consumed in this operation */
222 * Return the number of bytes consumed in this operation 208
223 */
224 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 209 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
225 return_ACPI_STATUS (AE_OK); 210 return_ACPI_STATUS (AE_OK);
226} 211}
@@ -258,15 +243,15 @@ acpi_rs_memory32_range_resource (
258 struct acpi_resource *output_struct = (void *) *output_buffer; 243 struct acpi_resource *output_struct = (void *) *output_buffer;
259 u16 temp16 = 0; 244 u16 temp16 = 0;
260 u8 temp8 = 0; 245 u8 temp8 = 0;
261 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem32); 246 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
247 struct acpi_resource_mem32);
262 248
263 249
264 ACPI_FUNCTION_TRACE ("rs_memory32_range_resource"); 250 ACPI_FUNCTION_TRACE ("rs_memory32_range_resource");
265 251
266 252
267 /* 253 /* Point past the Descriptor to get the number of bytes consumed */
268 * Point past the Descriptor to get the number of bytes consumed 254
269 */
270 buffer += 1; 255 buffer += 1;
271 256
272 ACPI_MOVE_16_TO_16 (&temp16, buffer); 257 ACPI_MOVE_16_TO_16 (&temp16, buffer);
@@ -285,45 +270,38 @@ acpi_rs_memory32_range_resource (
285 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8) 270 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
286 */ 271 */
287 272
288 /* 273 /* Check Byte 3 the Read/Write bit */
289 * Check Byte 3 the Read/Write bit 274
290 */
291 temp8 = *buffer; 275 temp8 = *buffer;
292 buffer += 1; 276 buffer += 1;
293 277
294 output_struct->data.memory32.read_write_attribute = temp8 & 0x01; 278 output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
295 279
296 /* 280 /* Get min_base_address (Bytes 4-7) */
297 * Get min_base_address (Bytes 4-7) 281
298 */
299 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer); 282 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer);
300 buffer += 4; 283 buffer += 4;
301 284
302 /* 285 /* Get max_base_address (Bytes 8-11) */
303 * Get max_base_address (Bytes 8-11) 286
304 */
305 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer); 287 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer);
306 buffer += 4; 288 buffer += 4;
307 289
308 /* 290 /* Get Alignment (Bytes 12-15) */
309 * Get Alignment (Bytes 12-15) 291
310 */
311 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer); 292 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer);
312 buffer += 4; 293 buffer += 4;
313 294
314 /* 295 /* Get range_length (Bytes 16-19) */
315 * Get range_length (Bytes 16-19) 296
316 */
317 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer); 297 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer);
318 298
319 /* 299 /* Set the Length parameter */
320 * Set the Length parameter 300
321 */
322 output_struct->length = (u32) struct_size; 301 output_struct->length = (u32) struct_size;
323 302
324 /* 303 /* Return the final size of the structure */
325 * Return the final size of the structure 304
326 */
327 *structure_size = struct_size; 305 *structure_size = struct_size;
328 return_ACPI_STATUS (AE_OK); 306 return_ACPI_STATUS (AE_OK);
329} 307}
@@ -361,15 +339,15 @@ acpi_rs_fixed_memory32_resource (
361 struct acpi_resource *output_struct = (void *) *output_buffer; 339 struct acpi_resource *output_struct = (void *) *output_buffer;
362 u16 temp16 = 0; 340 u16 temp16 = 0;
363 u8 temp8 = 0; 341 u8 temp8 = 0;
364 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_mem32); 342 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
343 struct acpi_resource_fixed_mem32);
365 344
366 345
367 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource"); 346 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource");
368 347
369 348
370 /* 349 /* Point past the Descriptor to get the number of bytes consumed */
371 * Point past the Descriptor to get the number of bytes consumed 350
372 */
373 buffer += 1; 351 buffer += 1;
374 ACPI_MOVE_16_TO_16 (&temp16, buffer); 352 ACPI_MOVE_16_TO_16 (&temp16, buffer);
375 353
@@ -378,32 +356,28 @@ acpi_rs_fixed_memory32_resource (
378 356
379 output_struct->id = ACPI_RSTYPE_FIXED_MEM32; 357 output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
380 358
381 /* 359 /* Check Byte 3 the Read/Write bit */
382 * Check Byte 3 the Read/Write bit 360
383 */
384 temp8 = *buffer; 361 temp8 = *buffer;
385 buffer += 1; 362 buffer += 1;
386 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01; 363 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
387 364
388 /* 365 /* Get range_base_address (Bytes 4-7) */
389 * Get range_base_address (Bytes 4-7) 366
390 */ 367 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_base_address,
391 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_base_address, buffer); 368 buffer);
392 buffer += 4; 369 buffer += 4;
393 370
394 /* 371 /* Get range_length (Bytes 8-11) */
395 * Get range_length (Bytes 8-11) 372
396 */
397 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_length, buffer); 373 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_length, buffer);
398 374
399 /* 375 /* Set the Length parameter */
400 * Set the Length parameter 376
401 */
402 output_struct->length = (u32) struct_size; 377 output_struct->length = (u32) struct_size;
403 378
404 /* 379 /* Return the final size of the structure */
405 * Return the final size of the structure 380
406 */
407 *structure_size = struct_size; 381 *structure_size = struct_size;
408 return_ACPI_STATUS (AE_OK); 382 return_ACPI_STATUS (AE_OK);
409} 383}
@@ -439,54 +413,46 @@ acpi_rs_memory32_range_stream (
439 ACPI_FUNCTION_TRACE ("rs_memory32_range_stream"); 413 ACPI_FUNCTION_TRACE ("rs_memory32_range_stream");
440 414
441 415
442 /* 416 /* The descriptor field is static */
443 * The descriptor field is static 417
444 */
445 *buffer = 0x85; 418 *buffer = 0x85;
446 buffer += 1; 419 buffer += 1;
447 420
448 /* 421 /* The length field is static */
449 * The length field is static 422
450 */
451 temp16 = 0x11; 423 temp16 = 0x11;
452 424
453 ACPI_MOVE_16_TO_16 (buffer, &temp16); 425 ACPI_MOVE_16_TO_16 (buffer, &temp16);
454 buffer += 2; 426 buffer += 2;
455 427
456 /* 428 /* Set the Information Byte */
457 * Set the Information Byte 429
458 */
459 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01); 430 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
460 *buffer = temp8; 431 *buffer = temp8;
461 buffer += 1; 432 buffer += 1;
462 433
463 /* 434 /* Set the Range minimum base address */
464 * Set the Range minimum base address 435
465 */
466 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address); 436 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
467 buffer += 4; 437 buffer += 4;
468 438
469 /* 439 /* Set the Range maximum base address */
470 * Set the Range maximum base address 440
471 */
472 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address); 441 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
473 buffer += 4; 442 buffer += 4;
474 443
475 /* 444 /* Set the base alignment */
476 * Set the base alignment 445
477 */
478 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment); 446 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment);
479 buffer += 4; 447 buffer += 4;
480 448
481 /* 449 /* Set the range length */
482 * Set the range length 450
483 */
484 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length); 451 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length);
485 buffer += 4; 452 buffer += 4;
486 453
487 /* 454 /* Return the number of bytes consumed in this operation */
488 * Return the number of bytes consumed in this operation 455
489 */
490 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 456 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
491 return_ACPI_STATUS (AE_OK); 457 return_ACPI_STATUS (AE_OK);
492} 458}
@@ -522,44 +488,38 @@ acpi_rs_fixed_memory32_stream (
522 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream"); 488 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream");
523 489
524 490
525 /* 491 /* The descriptor field is static */
526 * The descriptor field is static 492
527 */
528 *buffer = 0x86; 493 *buffer = 0x86;
529 buffer += 1; 494 buffer += 1;
530 495
531 /* 496 /* The length field is static */
532 * The length field is static 497
533 */
534 temp16 = 0x09; 498 temp16 = 0x09;
535 499
536 ACPI_MOVE_16_TO_16 (buffer, &temp16); 500 ACPI_MOVE_16_TO_16 (buffer, &temp16);
537 buffer += 2; 501 buffer += 2;
538 502
539 /* 503 /* Set the Information Byte */
540 * Set the Information Byte 504
541 */
542 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01); 505 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
543 *buffer = temp8; 506 *buffer = temp8;
544 buffer += 1; 507 buffer += 1;
545 508
546 /* 509 /* Set the Range base address */
547 * Set the Range base address 510
548 */
549 ACPI_MOVE_32_TO_32 (buffer, 511 ACPI_MOVE_32_TO_32 (buffer,
550 &linked_list->data.fixed_memory32.range_base_address); 512 &linked_list->data.fixed_memory32.range_base_address);
551 buffer += 4; 513 buffer += 4;
552 514
553 /* 515 /* Set the range length */
554 * Set the range length 516
555 */
556 ACPI_MOVE_32_TO_32 (buffer, 517 ACPI_MOVE_32_TO_32 (buffer,
557 &linked_list->data.fixed_memory32.range_length); 518 &linked_list->data.fixed_memory32.range_length);
558 buffer += 4; 519 buffer += 4;
559 520
560 /* 521 /* Return the number of bytes consumed in this operation */
561 * Return the number of bytes consumed in this operation 522
562 */
563 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 523 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
564 return_ACPI_STATUS (AE_OK); 524 return_ACPI_STATUS (AE_OK);
565} 525}
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index d16be44b5df7..a1f1741f0d83 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -84,24 +84,20 @@ acpi_rs_end_tag_resource (
84 ACPI_FUNCTION_TRACE ("rs_end_tag_resource"); 84 ACPI_FUNCTION_TRACE ("rs_end_tag_resource");
85 85
86 86
87 /* 87 /* The number of bytes consumed is static */
88 * The number of bytes consumed is static 88
89 */
90 *bytes_consumed = 2; 89 *bytes_consumed = 2;
91 90
92 /* 91 /* Fill out the structure */
93 * Fill out the structure 92
94 */
95 output_struct->id = ACPI_RSTYPE_END_TAG; 93 output_struct->id = ACPI_RSTYPE_END_TAG;
96 94
97 /* 95 /* Set the Length parameter */
98 * Set the Length parameter 96
99 */
100 output_struct->length = 0; 97 output_struct->length = 0;
101 98
102 /* 99 /* Return the final size of the structure */
103 * Return the final size of the structure 100
104 */
105 *structure_size = struct_size; 101 *structure_size = struct_size;
106 return_ACPI_STATUS (AE_OK); 102 return_ACPI_STATUS (AE_OK);
107} 103}
@@ -136,9 +132,8 @@ acpi_rs_end_tag_stream (
136 ACPI_FUNCTION_TRACE ("rs_end_tag_stream"); 132 ACPI_FUNCTION_TRACE ("rs_end_tag_stream");
137 133
138 134
139 /* 135 /* The descriptor field is static */
140 * The descriptor field is static 136
141 */
142 *buffer = 0x79; 137 *buffer = 0x79;
143 buffer += 1; 138 buffer += 1;
144 139
@@ -151,9 +146,8 @@ acpi_rs_end_tag_stream (
151 *buffer = temp8; 146 *buffer = temp8;
152 buffer += 1; 147 buffer += 1;
153 148
154 /* 149 /* Return the number of bytes consumed in this operation */
155 * Return the number of bytes consumed in this operation 150
156 */
157 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 151 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
158 return_ACPI_STATUS (AE_OK); 152 return_ACPI_STATUS (AE_OK);
159} 153}
@@ -192,21 +186,20 @@ acpi_rs_vendor_resource (
192 u16 temp16 = 0; 186 u16 temp16 = 0;
193 u8 temp8 = 0; 187 u8 temp8 = 0;
194 u8 index; 188 u8 index;
195 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor); 189 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
190 struct acpi_resource_vendor);
196 191
197 192
198 ACPI_FUNCTION_TRACE ("rs_vendor_resource"); 193 ACPI_FUNCTION_TRACE ("rs_vendor_resource");
199 194
200 195
201 /* 196 /* Dereference the Descriptor to find if this is a large or small item. */
202 * Dereference the Descriptor to find if this is a large or small item. 197
203 */
204 temp8 = *buffer; 198 temp8 = *buffer;
205 199
206 if (temp8 & 0x80) { 200 if (temp8 & 0x80) {
207 /* 201 /* Large Item, point to the length field */
208 * Large Item, point to the length field 202
209 */
210 buffer += 1; 203 buffer += 1;
211 204
212 /* Dereference */ 205 /* Dereference */
@@ -222,9 +215,8 @@ acpi_rs_vendor_resource (
222 buffer += 2; 215 buffer += 2;
223 } 216 }
224 else { 217 else {
225 /* 218 /* Small Item, dereference the size */
226 * Small Item, dereference the size 219
227 */
228 temp16 = (u8)(*buffer & 0x07); 220 temp16 = (u8)(*buffer & 0x07);
229 221
230 /* Calculate bytes consumed */ 222 /* Calculate bytes consumed */
@@ -251,14 +243,12 @@ acpi_rs_vendor_resource (
251 */ 243 */
252 struct_size += ACPI_ROUND_UP_to_32_bITS (temp16); 244 struct_size += ACPI_ROUND_UP_to_32_bITS (temp16);
253 245
254 /* 246 /* Set the Length parameter */
255 * Set the Length parameter 247
256 */
257 output_struct->length = (u32) struct_size; 248 output_struct->length = (u32) struct_size;
258 249
259 /* 250 /* Return the final size of the structure */
260 * Return the final size of the structure 251
261 */
262 *structure_size = struct_size; 252 *structure_size = struct_size;
263 return_ACPI_STATUS (AE_OK); 253 return_ACPI_STATUS (AE_OK);
264} 254}
@@ -295,13 +285,11 @@ acpi_rs_vendor_stream (
295 ACPI_FUNCTION_TRACE ("rs_vendor_stream"); 285 ACPI_FUNCTION_TRACE ("rs_vendor_stream");
296 286
297 287
298 /* 288 /* Dereference the length to find if this is a large or small item. */
299 * Dereference the length to find if this is a large or small item. 289
300 */
301 if(linked_list->data.vendor_specific.length > 7) { 290 if(linked_list->data.vendor_specific.length > 7) {
302 /* 291 /* Large Item, Set the descriptor field and length bytes */
303 * Large Item, Set the descriptor field and length bytes 292
304 */
305 *buffer = 0x84; 293 *buffer = 0x84;
306 buffer += 1; 294 buffer += 1;
307 295
@@ -311,9 +299,8 @@ acpi_rs_vendor_stream (
311 buffer += 2; 299 buffer += 2;
312 } 300 }
313 else { 301 else {
314 /* 302 /* Small Item, Set the descriptor field */
315 * Small Item, Set the descriptor field 303
316 */
317 temp8 = 0x70; 304 temp8 = 0x70;
318 temp8 |= (u8) linked_list->data.vendor_specific.length; 305 temp8 |= (u8) linked_list->data.vendor_specific.length;
319 306
@@ -321,9 +308,8 @@ acpi_rs_vendor_stream (
321 buffer += 1; 308 buffer += 1;
322 } 309 }
323 310
324 /* 311 /* Loop through all of the Vendor Specific fields */
325 * Loop through all of the Vendor Specific fields 312
326 */
327 for (index = 0; index < linked_list->data.vendor_specific.length; index++) { 313 for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
328 temp8 = linked_list->data.vendor_specific.reserved[index]; 314 temp8 = linked_list->data.vendor_specific.reserved[index];
329 315
@@ -331,9 +317,8 @@ acpi_rs_vendor_stream (
331 buffer += 1; 317 buffer += 1;
332 } 318 }
333 319
334 /* 320 /* Return the number of bytes consumed in this operation */
335 * Return the number of bytes consumed in this operation 321
336 */
337 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 322 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
338 return_ACPI_STATUS (AE_OK); 323 return_ACPI_STATUS (AE_OK);
339} 324}
@@ -370,40 +355,37 @@ acpi_rs_start_depend_fns_resource (
370 u8 *buffer = byte_stream_buffer; 355 u8 *buffer = byte_stream_buffer;
371 struct acpi_resource *output_struct = (void *) *output_buffer; 356 struct acpi_resource *output_struct = (void *) *output_buffer;
372 u8 temp8 = 0; 357 u8 temp8 = 0;
373 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_start_dpf); 358 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
359 struct acpi_resource_start_dpf);
374 360
375 361
376 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource"); 362 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource");
377 363
378 364
379 /* 365 /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
380 * The number of bytes consumed are contained in the descriptor (Bits:0-1) 366
381 */
382 temp8 = *buffer; 367 temp8 = *buffer;
383 368
384 *bytes_consumed = (temp8 & 0x01) + 1; 369 *bytes_consumed = (temp8 & 0x01) + 1;
385 370
386 output_struct->id = ACPI_RSTYPE_START_DPF; 371 output_struct->id = ACPI_RSTYPE_START_DPF;
387 372
388 /* 373 /* Point to Byte 1 if it is used */
389 * Point to Byte 1 if it is used 374
390 */
391 if (2 == *bytes_consumed) { 375 if (2 == *bytes_consumed) {
392 buffer += 1; 376 buffer += 1;
393 temp8 = *buffer; 377 temp8 = *buffer;
394 378
395 /* 379 /* Check Compatibility priority */
396 * Check Compatibility priority 380
397 */
398 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03; 381 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
399 382
400 if (3 == output_struct->data.start_dpf.compatibility_priority) { 383 if (3 == output_struct->data.start_dpf.compatibility_priority) {
401 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE); 384 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
402 } 385 }
403 386
404 /* 387 /* Check Performance/Robustness preference */
405 * Check Performance/Robustness preference 388
406 */
407 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03; 389 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
408 390
409 if (3 == output_struct->data.start_dpf.performance_robustness) { 391 if (3 == output_struct->data.start_dpf.performance_robustness) {
@@ -412,20 +394,18 @@ acpi_rs_start_depend_fns_resource (
412 } 394 }
413 else { 395 else {
414 output_struct->data.start_dpf.compatibility_priority = 396 output_struct->data.start_dpf.compatibility_priority =
415 ACPI_ACCEPTABLE_CONFIGURATION; 397 ACPI_ACCEPTABLE_CONFIGURATION;
416 398
417 output_struct->data.start_dpf.performance_robustness = 399 output_struct->data.start_dpf.performance_robustness =
418 ACPI_ACCEPTABLE_CONFIGURATION; 400 ACPI_ACCEPTABLE_CONFIGURATION;
419 } 401 }
420 402
421 /* 403 /* Set the Length parameter */
422 * Set the Length parameter 404
423 */
424 output_struct->length = (u32) struct_size; 405 output_struct->length = (u32) struct_size;
425 406
426 /* 407 /* Return the final size of the structure */
427 * Return the final size of the structure 408
428 */
429 *structure_size = struct_size; 409 *structure_size = struct_size;
430 return_ACPI_STATUS (AE_OK); 410 return_ACPI_STATUS (AE_OK);
431} 411}
@@ -466,24 +446,20 @@ acpi_rs_end_depend_fns_resource (
466 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource"); 446 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource");
467 447
468 448
469 /* 449 /* The number of bytes consumed is static */
470 * The number of bytes consumed is static 450
471 */
472 *bytes_consumed = 1; 451 *bytes_consumed = 1;
473 452
474 /* 453 /* Fill out the structure */
475 * Fill out the structure 454
476 */
477 output_struct->id = ACPI_RSTYPE_END_DPF; 455 output_struct->id = ACPI_RSTYPE_END_DPF;
478 456
479 /* 457 /* Set the Length parameter */
480 * Set the Length parameter 458
481 */
482 output_struct->length = (u32) struct_size; 459 output_struct->length = (u32) struct_size;
483 460
484 /* 461 /* Return the final size of the structure */
485 * Return the final size of the structure 462
486 */
487 *structure_size = struct_size; 463 *structure_size = struct_size;
488 return_ACPI_STATUS (AE_OK); 464 return_ACPI_STATUS (AE_OK);
489} 465}
@@ -533,9 +509,8 @@ acpi_rs_start_depend_fns_stream (
533 *buffer = 0x31; 509 *buffer = 0x31;
534 buffer += 1; 510 buffer += 1;
535 511
536 /* 512 /* Set the Priority Byte Definition */
537 * Set the Priority Byte Definition 513
538 */
539 temp8 = 0; 514 temp8 = 0;
540 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness & 515 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
541 0x03) << 2); 516 0x03) << 2);
@@ -546,9 +521,8 @@ acpi_rs_start_depend_fns_stream (
546 521
547 buffer += 1; 522 buffer += 1;
548 523
549 /* 524 /* Return the number of bytes consumed in this operation */
550 * Return the number of bytes consumed in this operation 525
551 */
552 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 526 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
553 return_ACPI_STATUS (AE_OK); 527 return_ACPI_STATUS (AE_OK);
554} 528}
@@ -582,15 +556,13 @@ acpi_rs_end_depend_fns_stream (
582 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream"); 556 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream");
583 557
584 558
585 /* 559 /* The descriptor field is static */
586 * The descriptor field is static 560
587 */
588 *buffer = 0x38; 561 *buffer = 0x38;
589 buffer += 1; 562 buffer += 1;
590 563
591 /* 564 /* Return the number of bytes consumed in this operation */
592 * Return the number of bytes consumed in this operation 565
593 */
594 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 566 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
595 return_ACPI_STATUS (AE_OK); 567 return_ACPI_STATUS (AE_OK);
596} 568}
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index ee9ce13c053d..700cf7d65d76 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -83,10 +83,10 @@ acpi_rs_get_prt_method_data (
83 83
84 /* Parameters guaranteed valid by caller */ 84 /* Parameters guaranteed valid by caller */
85 85
86 /* 86 /* Execute the method, no parameters */
87 * Execute the method, no parameters 87
88 */ 88 status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRT,
89 status = acpi_ut_evaluate_object (handle, "_PRT", ACPI_BTYPE_PACKAGE, &obj_desc); 89 ACPI_BTYPE_PACKAGE, &obj_desc);
90 if (ACPI_FAILURE (status)) { 90 if (ACPI_FAILURE (status)) {
91 return_ACPI_STATUS (status); 91 return_ACPI_STATUS (status);
92 } 92 }
@@ -136,10 +136,10 @@ acpi_rs_get_crs_method_data (
136 136
137 /* Parameters guaranteed valid by caller */ 137 /* Parameters guaranteed valid by caller */
138 138
139 /* 139 /* Execute the method, no parameters */
140 * Execute the method, no parameters 140
141 */ 141 status = acpi_ut_evaluate_object (handle, METHOD_NAME__CRS,
142 status = acpi_ut_evaluate_object (handle, "_CRS", ACPI_BTYPE_BUFFER, &obj_desc); 142 ACPI_BTYPE_BUFFER, &obj_desc);
143 if (ACPI_FAILURE (status)) { 143 if (ACPI_FAILURE (status)) {
144 return_ACPI_STATUS (status); 144 return_ACPI_STATUS (status);
145 } 145 }
@@ -175,6 +175,7 @@ acpi_rs_get_crs_method_data (
175 * and the contents of the callers buffer is undefined. 175 * and the contents of the callers buffer is undefined.
176 * 176 *
177 ******************************************************************************/ 177 ******************************************************************************/
178
178#ifdef ACPI_FUTURE_USAGE 179#ifdef ACPI_FUTURE_USAGE
179acpi_status 180acpi_status
180acpi_rs_get_prs_method_data ( 181acpi_rs_get_prs_method_data (
@@ -190,10 +191,10 @@ acpi_rs_get_prs_method_data (
190 191
191 /* Parameters guaranteed valid by caller */ 192 /* Parameters guaranteed valid by caller */
192 193
193 /* 194 /* Execute the method, no parameters */
194 * Execute the method, no parameters 195
195 */ 196 status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRS,
196 status = acpi_ut_evaluate_object (handle, "_PRS", ACPI_BTYPE_BUFFER, &obj_desc); 197 ACPI_BTYPE_BUFFER, &obj_desc);
197 if (ACPI_FAILURE (status)) { 198 if (ACPI_FAILURE (status)) {
198 return_ACPI_STATUS (status); 199 return_ACPI_STATUS (status);
199 } 200 }
@@ -218,6 +219,7 @@ acpi_rs_get_prs_method_data (
218 * FUNCTION: acpi_rs_get_method_data 219 * FUNCTION: acpi_rs_get_method_data
219 * 220 *
220 * PARAMETERS: Handle - a handle to the containing object 221 * PARAMETERS: Handle - a handle to the containing object
222 * Path - Path to method, relative to Handle
221 * ret_buffer - a pointer to a buffer structure for the 223 * ret_buffer - a pointer to a buffer structure for the
222 * results 224 * results
223 * 225 *
@@ -246,9 +248,8 @@ acpi_rs_get_method_data (
246 248
247 /* Parameters guaranteed valid by caller */ 249 /* Parameters guaranteed valid by caller */
248 250
249 /* 251 /* Execute the method, no parameters */
250 * Execute the method, no parameters 252
251 */
252 status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc); 253 status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
253 if (ACPI_FAILURE (status)) { 254 if (ACPI_FAILURE (status)) {
254 return_ACPI_STATUS (status); 255 return_ACPI_STATUS (status);
@@ -314,18 +315,16 @@ acpi_rs_set_srs_method_data (
314 return_ACPI_STATUS (status); 315 return_ACPI_STATUS (status);
315 } 316 }
316 317
317 /* 318 /* Init the param object */
318 * Init the param object 319
319 */
320 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER); 320 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
321 if (!params[0]) { 321 if (!params[0]) {
322 acpi_os_free (buffer.pointer); 322 acpi_os_free (buffer.pointer);
323 return_ACPI_STATUS (AE_NO_MEMORY); 323 return_ACPI_STATUS (AE_NO_MEMORY);
324 } 324 }
325 325
326 /* 326 /* Set up the parameter object */
327 * Set up the parameter object 327
328 */
329 params[0]->buffer.length = (u32) buffer.length; 328 params[0]->buffer.length = (u32) buffer.length;
330 params[0]->buffer.pointer = buffer.pointer; 329 params[0]->buffer.pointer = buffer.pointer;
331 params[0]->common.flags = AOPOBJ_DATA_VALID; 330 params[0]->common.flags = AOPOBJ_DATA_VALID;
@@ -335,10 +334,9 @@ acpi_rs_set_srs_method_data (
335 info.parameters = params; 334 info.parameters = params;
336 info.parameter_type = ACPI_PARAM_ARGS; 335 info.parameter_type = ACPI_PARAM_ARGS;
337 336
338 /* 337 /* Execute the method, no return value */
339 * Execute the method, no return value 338
340 */ 339 status = acpi_ns_evaluate_relative (METHOD_NAME__SRS, &info);
341 status = acpi_ns_evaluate_relative ("_SRS", &info);
342 if (ACPI_SUCCESS (status)) { 340 if (ACPI_SUCCESS (status)) {
343 /* Delete any return object (especially if implicit_return is enabled) */ 341 /* Delete any return object (especially if implicit_return is enabled) */
344 342
@@ -347,9 +345,8 @@ acpi_rs_set_srs_method_data (
347 } 345 }
348 } 346 }
349 347
350 /* 348 /* Clean up and return the status from acpi_ns_evaluate_relative */
351 * Clean up and return the status from acpi_ns_evaluate_relative 349
352 */
353 acpi_ut_remove_reference (params[0]); 350 acpi_ut_remove_reference (params[0]);
354 return_ACPI_STATUS (status); 351 return_ACPI_STATUS (status);
355} 352}
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index a9cdcbeb3432..83c944b8b097 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -49,6 +49,23 @@
49#define _COMPONENT ACPI_RESOURCES 49#define _COMPONENT ACPI_RESOURCES
50 ACPI_MODULE_NAME ("rsxface") 50 ACPI_MODULE_NAME ("rsxface")
51 51
52/* Local macros for 16,32-bit to 64-bit conversion */
53
54#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
55#define ACPI_COPY_ADDRESS(out, in) \
56 ACPI_COPY_FIELD(out, in, resource_type); \
57 ACPI_COPY_FIELD(out, in, producer_consumer); \
58 ACPI_COPY_FIELD(out, in, decode); \
59 ACPI_COPY_FIELD(out, in, min_address_fixed); \
60 ACPI_COPY_FIELD(out, in, max_address_fixed); \
61 ACPI_COPY_FIELD(out, in, attribute); \
62 ACPI_COPY_FIELD(out, in, granularity); \
63 ACPI_COPY_FIELD(out, in, min_address_range); \
64 ACPI_COPY_FIELD(out, in, max_address_range); \
65 ACPI_COPY_FIELD(out, in, address_translation_offset); \
66 ACPI_COPY_FIELD(out, in, address_length); \
67 ACPI_COPY_FIELD(out, in, resource_source);
68
52 69
53/******************************************************************************* 70/*******************************************************************************
54 * 71 *
@@ -180,6 +197,7 @@ EXPORT_SYMBOL(acpi_get_current_resources);
180 * and the value of ret_buffer is undefined. 197 * and the value of ret_buffer is undefined.
181 * 198 *
182 ******************************************************************************/ 199 ******************************************************************************/
200
183#ifdef ACPI_FUTURE_USAGE 201#ifdef ACPI_FUTURE_USAGE
184acpi_status 202acpi_status
185acpi_get_possible_resources ( 203acpi_get_possible_resources (
@@ -346,9 +364,8 @@ acpi_set_current_resources (
346 ACPI_FUNCTION_TRACE ("acpi_set_current_resources"); 364 ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
347 365
348 366
349 /* 367 /* Must have a valid handle and buffer */
350 * Must have a valid handle and buffer 368
351 */
352 if ((!device_handle) || 369 if ((!device_handle) ||
353 (!in_buffer) || 370 (!in_buffer) ||
354 (!in_buffer->pointer) || 371 (!in_buffer->pointer) ||
@@ -362,21 +379,6 @@ acpi_set_current_resources (
362EXPORT_SYMBOL(acpi_set_current_resources); 379EXPORT_SYMBOL(acpi_set_current_resources);
363 380
364 381
365#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
366#define ACPI_COPY_ADDRESS(out, in) \
367 ACPI_COPY_FIELD(out, in, resource_type); \
368 ACPI_COPY_FIELD(out, in, producer_consumer); \
369 ACPI_COPY_FIELD(out, in, decode); \
370 ACPI_COPY_FIELD(out, in, min_address_fixed); \
371 ACPI_COPY_FIELD(out, in, max_address_fixed); \
372 ACPI_COPY_FIELD(out, in, attribute); \
373 ACPI_COPY_FIELD(out, in, granularity); \
374 ACPI_COPY_FIELD(out, in, min_address_range); \
375 ACPI_COPY_FIELD(out, in, max_address_range); \
376 ACPI_COPY_FIELD(out, in, address_translation_offset); \
377 ACPI_COPY_FIELD(out, in, address_length); \
378 ACPI_COPY_FIELD(out, in, resource_source);
379
380/****************************************************************************** 382/******************************************************************************
381 * 383 *
382 * FUNCTION: acpi_resource_to_address64 384 * FUNCTION: acpi_resource_to_address64
@@ -408,14 +410,14 @@ acpi_resource_to_address64 (
408 case ACPI_RSTYPE_ADDRESS16: 410 case ACPI_RSTYPE_ADDRESS16:
409 411
410 address16 = (struct acpi_resource_address16 *) &resource->data; 412 address16 = (struct acpi_resource_address16 *) &resource->data;
411 ACPI_COPY_ADDRESS(out, address16); 413 ACPI_COPY_ADDRESS (out, address16);
412 break; 414 break;
413 415
414 416
415 case ACPI_RSTYPE_ADDRESS32: 417 case ACPI_RSTYPE_ADDRESS32:
416 418
417 address32 = (struct acpi_resource_address32 *) &resource->data; 419 address32 = (struct acpi_resource_address32 *) &resource->data;
418 ACPI_COPY_ADDRESS(out, address32); 420 ACPI_COPY_ADDRESS (out, address32);
419 break; 421 break;
420 422
421 423
@@ -434,4 +436,3 @@ acpi_resource_to_address64 (
434 return (AE_OK); 436 return (AE_OK);
435} 437}
436EXPORT_SYMBOL(acpi_resource_to_address64); 438EXPORT_SYMBOL(acpi_resource_to_address64);
437
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index e85885593280..cbcda30c172d 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -553,20 +553,29 @@ acpi_bus_driver_init (
553 * upon possible configuration and currently allocated resources. 553 * upon possible configuration and currently allocated resources.
554 */ 554 */
555 555
556 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n"));
557 return_VALUE(0);
558}
559
560int
561acpi_start_single_object (
562 struct acpi_device *device)
563{
564 int result = 0;
565 struct acpi_driver *driver;
566
567 ACPI_FUNCTION_TRACE("acpi_start_single_object");
568
569 if (!(driver = device->driver))
570 return_VALUE(0);
571
556 if (driver->ops.start) { 572 if (driver->ops.start) {
557 result = driver->ops.start(device); 573 result = driver->ops.start(device);
558 if (result && driver->ops.remove) 574 if (result && driver->ops.remove)
559 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); 575 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
560 return_VALUE(result);
561 }
562
563 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n"));
564
565 if (driver->ops.scan) {
566 driver->ops.scan(device);
567 } 576 }
568 577
569 return_VALUE(0); 578 return_VALUE(result);
570} 579}
571 580
572static int acpi_driver_attach(struct acpi_driver * drv) 581static int acpi_driver_attach(struct acpi_driver * drv)
@@ -586,6 +595,7 @@ static int acpi_driver_attach(struct acpi_driver * drv)
586 595
587 if (!acpi_bus_match(dev, drv)) { 596 if (!acpi_bus_match(dev, drv)) {
588 if (!acpi_bus_driver_init(dev, drv)) { 597 if (!acpi_bus_driver_init(dev, drv)) {
598 acpi_start_single_object(dev);
589 atomic_inc(&drv->references); 599 atomic_inc(&drv->references);
590 count++; 600 count++;
591 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n", 601 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
@@ -1009,8 +1019,8 @@ acpi_bus_remove (
1009} 1019}
1010 1020
1011 1021
1012int 1022static int
1013acpi_bus_add ( 1023acpi_add_single_object (
1014 struct acpi_device **child, 1024 struct acpi_device **child,
1015 struct acpi_device *parent, 1025 struct acpi_device *parent,
1016 acpi_handle handle, 1026 acpi_handle handle,
@@ -1019,7 +1029,7 @@ acpi_bus_add (
1019 int result = 0; 1029 int result = 0;
1020 struct acpi_device *device = NULL; 1030 struct acpi_device *device = NULL;
1021 1031
1022 ACPI_FUNCTION_TRACE("acpi_bus_add"); 1032 ACPI_FUNCTION_TRACE("acpi_add_single_object");
1023 1033
1024 if (!child) 1034 if (!child)
1025 return_VALUE(-EINVAL); 1035 return_VALUE(-EINVAL);
@@ -1051,13 +1061,15 @@ acpi_bus_add (
1051 /* 1061 /*
1052 * Status 1062 * Status
1053 * ------ 1063 * ------
1054 * See if the device is present. We always assume that non-Device() 1064 * See if the device is present. We always assume that non-Device
1055 * objects (e.g. thermal zones, power resources, processors, etc.) are 1065 * and non-Processor objects (e.g. thermal zones, power resources,
1056 * present, functioning, etc. (at least when parent object is present). 1066 * etc.) are present, functioning, etc. (at least when parent object
1057 * Note that _STA has a different meaning for some objects (e.g. 1067 * is present). Note that _STA has a different meaning for some
1058 * power resources) so we need to be careful how we use it. 1068 * objects (e.g. power resources) so we need to be careful how we use
1069 * it.
1059 */ 1070 */
1060 switch (type) { 1071 switch (type) {
1072 case ACPI_BUS_TYPE_PROCESSOR:
1061 case ACPI_BUS_TYPE_DEVICE: 1073 case ACPI_BUS_TYPE_DEVICE:
1062 result = acpi_bus_get_status(device); 1074 result = acpi_bus_get_status(device);
1063 if (ACPI_FAILURE(result) || !device->status.present) { 1075 if (ACPI_FAILURE(result) || !device->status.present) {
@@ -1140,7 +1152,7 @@ acpi_bus_add (
1140 * 1152 *
1141 * TBD: Assumes LDM provides driver hot-plug capability. 1153 * TBD: Assumes LDM provides driver hot-plug capability.
1142 */ 1154 */
1143 acpi_bus_find_driver(device); 1155 result = acpi_bus_find_driver(device);
1144 1156
1145end: 1157end:
1146 if (!result) 1158 if (!result)
@@ -1153,10 +1165,10 @@ end:
1153 1165
1154 return_VALUE(result); 1166 return_VALUE(result);
1155} 1167}
1156EXPORT_SYMBOL(acpi_bus_add);
1157 1168
1158 1169
1159int acpi_bus_scan (struct acpi_device *start) 1170static int acpi_bus_scan (struct acpi_device *start,
1171 struct acpi_bus_ops *ops)
1160{ 1172{
1161 acpi_status status = AE_OK; 1173 acpi_status status = AE_OK;
1162 struct acpi_device *parent = NULL; 1174 struct acpi_device *parent = NULL;
@@ -1229,9 +1241,20 @@ int acpi_bus_scan (struct acpi_device *start)
1229 continue; 1241 continue;
1230 } 1242 }
1231 1243
1232 status = acpi_bus_add(&child, parent, chandle, type); 1244 if (ops->acpi_op_add)
1233 if (ACPI_FAILURE(status)) 1245 status = acpi_add_single_object(&child, parent,
1234 continue; 1246 chandle, type);
1247 else
1248 status = acpi_bus_get_device(chandle, &child);
1249
1250 if (ACPI_FAILURE(status))
1251 continue;
1252
1253 if (ops->acpi_op_start) {
1254 status = acpi_start_single_object(child);
1255 if (ACPI_FAILURE(status))
1256 continue;
1257 }
1235 1258
1236 /* 1259 /*
1237 * If the device is present, enabled, and functioning then 1260 * If the device is present, enabled, and functioning then
@@ -1257,8 +1280,50 @@ int acpi_bus_scan (struct acpi_device *start)
1257 1280
1258 return_VALUE(0); 1281 return_VALUE(0);
1259} 1282}
1260EXPORT_SYMBOL(acpi_bus_scan);
1261 1283
1284int
1285acpi_bus_add (
1286 struct acpi_device **child,
1287 struct acpi_device *parent,
1288 acpi_handle handle,
1289 int type)
1290{
1291 int result;
1292 struct acpi_bus_ops ops;
1293
1294 ACPI_FUNCTION_TRACE("acpi_bus_add");
1295
1296 result = acpi_add_single_object(child, parent, handle, type);
1297 if (!result) {
1298 memset(&ops, 0, sizeof(ops));
1299 ops.acpi_op_add = 1;
1300 result = acpi_bus_scan(*child, &ops);
1301 }
1302 return_VALUE(result);
1303}
1304EXPORT_SYMBOL(acpi_bus_add);
1305
1306int
1307acpi_bus_start (
1308 struct acpi_device *device)
1309{
1310 int result;
1311 struct acpi_bus_ops ops;
1312
1313 ACPI_FUNCTION_TRACE("acpi_bus_start");
1314
1315 if (!device)
1316 return_VALUE(-EINVAL);
1317
1318 result = acpi_start_single_object(device);
1319 if (!result) {
1320 memset(&ops, 0, sizeof(ops));
1321 ops.acpi_op_start = 1;
1322 result = acpi_bus_scan(device, &ops);
1323 }
1324 return_VALUE(result);
1325}
1326EXPORT_SYMBOL(acpi_bus_start);
1262 1327
1263static int 1328static int
1264acpi_bus_trim(struct acpi_device *start, 1329acpi_bus_trim(struct acpi_device *start,
@@ -1331,13 +1396,19 @@ acpi_bus_scan_fixed (
1331 /* 1396 /*
1332 * Enumerate all fixed-feature devices. 1397 * Enumerate all fixed-feature devices.
1333 */ 1398 */
1334 if (acpi_fadt.pwr_button == 0) 1399 if (acpi_fadt.pwr_button == 0) {
1335 result = acpi_bus_add(&device, acpi_root, 1400 result = acpi_add_single_object(&device, acpi_root,
1336 NULL, ACPI_BUS_TYPE_POWER_BUTTON); 1401 NULL, ACPI_BUS_TYPE_POWER_BUTTON);
1402 if (!result)
1403 result = acpi_start_single_object(device);
1404 }
1337 1405
1338 if (acpi_fadt.sleep_button == 0) 1406 if (acpi_fadt.sleep_button == 0) {
1339 result = acpi_bus_add(&device, acpi_root, 1407 result = acpi_add_single_object(&device, acpi_root,
1340 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON); 1408 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON);
1409 if (!result)
1410 result = acpi_start_single_object(device);
1411 }
1341 1412
1342 return_VALUE(result); 1413 return_VALUE(result);
1343} 1414}
@@ -1346,6 +1417,7 @@ acpi_bus_scan_fixed (
1346static int __init acpi_scan_init(void) 1417static int __init acpi_scan_init(void)
1347{ 1418{
1348 int result; 1419 int result;
1420 struct acpi_bus_ops ops;
1349 1421
1350 ACPI_FUNCTION_TRACE("acpi_scan_init"); 1422 ACPI_FUNCTION_TRACE("acpi_scan_init");
1351 1423
@@ -1357,17 +1429,23 @@ static int __init acpi_scan_init(void)
1357 /* 1429 /*
1358 * Create the root device in the bus's device tree 1430 * Create the root device in the bus's device tree
1359 */ 1431 */
1360 result = acpi_bus_add(&acpi_root, NULL, ACPI_ROOT_OBJECT, 1432 result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
1361 ACPI_BUS_TYPE_SYSTEM); 1433 ACPI_BUS_TYPE_SYSTEM);
1362 if (result) 1434 if (result)
1363 goto Done; 1435 goto Done;
1364 1436
1437 result = acpi_start_single_object(acpi_root);
1438
1365 /* 1439 /*
1366 * Enumerate devices in the ACPI namespace. 1440 * Enumerate devices in the ACPI namespace.
1367 */ 1441 */
1368 result = acpi_bus_scan_fixed(acpi_root); 1442 result = acpi_bus_scan_fixed(acpi_root);
1369 if (!result) 1443 if (!result) {
1370 result = acpi_bus_scan(acpi_root); 1444 memset(&ops, 0, sizeof(ops));
1445 ops.acpi_op_add = 1;
1446 ops.acpi_op_start = 1;
1447 result = acpi_bus_scan(acpi_root, &ops);
1448 }
1371 1449
1372 if (result) 1450 if (result)
1373 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1451 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 0a5d2a94131e..7249ba2b7a27 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * sleep.c - ACPI sleep support. 2 * sleep.c - ACPI sleep support.
3 * 3 *
4 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
4 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com> 5 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
5 * Copyright (c) 2000-2003 Patrick Mochel 6 * Copyright (c) 2000-2003 Patrick Mochel
6 * Copyright (c) 2003 Open Source Development Lab 7 * Copyright (c) 2003 Open Source Development Lab
@@ -14,7 +15,6 @@
14#include <linux/dmi.h> 15#include <linux/dmi.h>
15#include <linux/device.h> 16#include <linux/device.h>
16#include <linux/suspend.h> 17#include <linux/suspend.h>
17#include <asm/io.h>
18#include <acpi/acpi_bus.h> 18#include <acpi/acpi_bus.h>
19#include <acpi/acpi_drivers.h> 19#include <acpi/acpi_drivers.h>
20#include "sleep.h" 20#include "sleep.h"
@@ -27,10 +27,11 @@ extern void do_suspend_lowlevel_s4bios(void);
27extern void do_suspend_lowlevel(void); 27extern void do_suspend_lowlevel(void);
28 28
29static u32 acpi_suspend_states[] = { 29static u32 acpi_suspend_states[] = {
30 [PM_SUSPEND_ON] = ACPI_STATE_S0, 30 [PM_SUSPEND_ON] = ACPI_STATE_S0,
31 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, 31 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
32 [PM_SUSPEND_MEM] = ACPI_STATE_S3, 32 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
33 [PM_SUSPEND_DISK] = ACPI_STATE_S4, 33 [PM_SUSPEND_DISK] = ACPI_STATE_S4,
34 [PM_SUSPEND_MAX] = ACPI_STATE_S5
34}; 35};
35 36
36static int init_8259A_after_S1; 37static int init_8259A_after_S1;
@@ -44,30 +45,20 @@ static int init_8259A_after_S1;
44 * wakeup code to the waking vector. 45 * wakeup code to the waking vector.
45 */ 46 */
46 47
48extern int acpi_sleep_prepare(u32 acpi_state);
49extern void acpi_power_off(void);
50
47static int acpi_pm_prepare(suspend_state_t pm_state) 51static int acpi_pm_prepare(suspend_state_t pm_state)
48{ 52{
49 u32 acpi_state = acpi_suspend_states[pm_state]; 53 u32 acpi_state = acpi_suspend_states[pm_state];
50 54
51 if (!sleep_states[acpi_state]) 55 if (!sleep_states[acpi_state]) {
56 printk("acpi_pm_prepare does not support %d \n", pm_state);
52 return -EPERM; 57 return -EPERM;
53
54 /* do we have a wakeup address for S2 and S3? */
55 /* Here, we support only S4BIOS, those we set the wakeup address */
56 /* S4OS is only supported for now via swsusp.. */
57 if (pm_state == PM_SUSPEND_MEM || pm_state == PM_SUSPEND_DISK) {
58 if (!acpi_wakeup_address)
59 return -EFAULT;
60 acpi_set_firmware_waking_vector(
61 (acpi_physical_address) virt_to_phys(
62 (void *)acpi_wakeup_address));
63 } 58 }
64 ACPI_FLUSH_CPU_CACHE(); 59 return acpi_sleep_prepare(acpi_state);
65 acpi_enable_wakeup_device_prep(acpi_state);
66 acpi_enter_sleep_state_prep(acpi_state);
67 return 0;
68} 60}
69 61
70
71/** 62/**
72 * acpi_pm_enter - Actually enter a sleep state. 63 * acpi_pm_enter - Actually enter a sleep state.
73 * @pm_state: State we're entering. 64 * @pm_state: State we're entering.
@@ -92,11 +83,9 @@ static int acpi_pm_enter(suspend_state_t pm_state)
92 return error; 83 return error;
93 } 84 }
94 85
95
96 local_irq_save(flags); 86 local_irq_save(flags);
97 acpi_enable_wakeup_device(acpi_state); 87 acpi_enable_wakeup_device(acpi_state);
98 switch (pm_state) 88 switch (pm_state) {
99 {
100 case PM_SUSPEND_STANDBY: 89 case PM_SUSPEND_STANDBY:
101 barrier(); 90 barrier();
102 status = acpi_enter_sleep_state(acpi_state); 91 status = acpi_enter_sleep_state(acpi_state);
@@ -112,6 +101,10 @@ static int acpi_pm_enter(suspend_state_t pm_state)
112 else 101 else
113 do_suspend_lowlevel_s4bios(); 102 do_suspend_lowlevel_s4bios();
114 break; 103 break;
104 case PM_SUSPEND_MAX:
105 acpi_power_off();
106 break;
107
115 default: 108 default:
116 return -EINVAL; 109 return -EINVAL;
117 } 110 }
@@ -126,11 +119,9 @@ static int acpi_pm_enter(suspend_state_t pm_state)
126 if (pm_state > PM_SUSPEND_STANDBY) 119 if (pm_state > PM_SUSPEND_STANDBY)
127 acpi_restore_state_mem(); 120 acpi_restore_state_mem();
128 121
129
130 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 122 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
131} 123}
132 124
133
134/** 125/**
135 * acpi_pm_finish - Finish up suspend sequence. 126 * acpi_pm_finish - Finish up suspend sequence.
136 * @pm_state: State we're coming out of. 127 * @pm_state: State we're coming out of.
@@ -156,27 +147,26 @@ static int acpi_pm_finish(suspend_state_t pm_state)
156 return 0; 147 return 0;
157} 148}
158 149
159
160int acpi_suspend(u32 acpi_state) 150int acpi_suspend(u32 acpi_state)
161{ 151{
162 suspend_state_t states[] = { 152 suspend_state_t states[] = {
163 [1] = PM_SUSPEND_STANDBY, 153 [1] = PM_SUSPEND_STANDBY,
164 [3] = PM_SUSPEND_MEM, 154 [3] = PM_SUSPEND_MEM,
165 [4] = PM_SUSPEND_DISK, 155 [4] = PM_SUSPEND_DISK,
156 [5] = PM_SUSPEND_MAX
166 }; 157 };
167 158
168 if (acpi_state <= 4 && states[acpi_state]) 159 if (acpi_state < 6 && states[acpi_state])
169 return pm_suspend(states[acpi_state]); 160 return pm_suspend(states[acpi_state]);
170 return -EINVAL; 161 return -EINVAL;
171} 162}
172 163
173static struct pm_ops acpi_pm_ops = { 164static struct pm_ops acpi_pm_ops = {
174 .prepare = acpi_pm_prepare, 165 .prepare = acpi_pm_prepare,
175 .enter = acpi_pm_enter, 166 .enter = acpi_pm_enter,
176 .finish = acpi_pm_finish, 167 .finish = acpi_pm_finish,
177}; 168};
178 169
179
180/* 170/*
181 * Toshiba fails to preserve interrupts over S1, reinitialization 171 * Toshiba fails to preserve interrupts over S1, reinitialization
182 * of 8259 is needed after S1 resume. 172 * of 8259 is needed after S1 resume.
@@ -190,16 +180,16 @@ static int __init init_ints_after_s1(struct dmi_system_id *d)
190 180
191static struct dmi_system_id __initdata acpisleep_dmi_table[] = { 181static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
192 { 182 {
193 .callback = init_ints_after_s1, 183 .callback = init_ints_after_s1,
194 .ident = "Toshiba Satellite 4030cdt", 184 .ident = "Toshiba Satellite 4030cdt",
195 .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"), }, 185 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
196 }, 186 },
197 { }, 187 {},
198}; 188};
199 189
200static int __init acpi_sleep_init(void) 190static int __init acpi_sleep_init(void)
201{ 191{
202 int i = 0; 192 int i = 0;
203 193
204 dmi_check_system(acpisleep_dmi_table); 194 dmi_check_system(acpisleep_dmi_table);
205 195
@@ -207,7 +197,7 @@ static int __init acpi_sleep_init(void)
207 return 0; 197 return 0;
208 198
209 printk(KERN_INFO PREFIX "(supports"); 199 printk(KERN_INFO PREFIX "(supports");
210 for (i=0; i < ACPI_S_STATE_COUNT; i++) { 200 for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
211 acpi_status status; 201 acpi_status status;
212 u8 type_a, type_b; 202 u8 type_a, type_b;
213 status = acpi_get_sleep_type_data(i, &type_a, &type_b); 203 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
diff --git a/drivers/acpi/sleep/poweroff.c b/drivers/acpi/sleep/poweroff.c
index da237754ded9..1fc86e6b5ab9 100644
--- a/drivers/acpi/sleep/poweroff.c
+++ b/drivers/acpi/sleep/poweroff.c
@@ -3,35 +3,100 @@
3 * 3 *
4 * AKA S5, but it is independent of whether or not the kernel supports 4 * AKA S5, but it is independent of whether or not the kernel supports
5 * any other sleep support in the system. 5 * any other sleep support in the system.
6 *
7 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
8 *
9 * This file is released under the GPLv2.
6 */ 10 */
7 11
8#include <linux/pm.h> 12#include <linux/pm.h>
9#include <linux/init.h> 13#include <linux/init.h>
10#include <acpi/acpi_bus.h> 14#include <acpi/acpi_bus.h>
11#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/sysdev.h>
17#include <asm/io.h>
12#include "sleep.h" 18#include "sleep.h"
13 19
14static void 20int acpi_sleep_prepare(u32 acpi_state)
15acpi_power_off (void) 21{
22 /* Flag to do not allow second time invocation for S5 state */
23 static int shutdown_prepared = 0;
24#ifdef CONFIG_ACPI_SLEEP
25 /* do we have a wakeup address for S2 and S3? */
26 /* Here, we support only S4BIOS, those we set the wakeup address */
27 /* S4OS is only supported for now via swsusp.. */
28 if (acpi_state == ACPI_STATE_S3 || acpi_state == ACPI_STATE_S4) {
29 if (!acpi_wakeup_address) {
30 return -EFAULT;
31 }
32 acpi_set_firmware_waking_vector((acpi_physical_address)
33 virt_to_phys((void *)
34 acpi_wakeup_address));
35
36 }
37 ACPI_FLUSH_CPU_CACHE();
38 acpi_enable_wakeup_device_prep(acpi_state);
39#endif
40 if (acpi_state == ACPI_STATE_S5) {
41 /* Check if we were already called */
42 if (shutdown_prepared)
43 return 0;
44 acpi_wakeup_gpe_poweroff_prepare();
45 shutdown_prepared = 1;
46 }
47 acpi_enter_sleep_state_prep(acpi_state);
48 return 0;
49}
50
51void acpi_power_off(void)
16{ 52{
17 printk("%s called\n",__FUNCTION__); 53 printk("%s called\n", __FUNCTION__);
54 acpi_sleep_prepare(ACPI_STATE_S5);
55 local_irq_disable();
18 /* Some SMP machines only can poweroff in boot CPU */ 56 /* Some SMP machines only can poweroff in boot CPU */
19 set_cpus_allowed(current, cpumask_of_cpu(0)); 57 set_cpus_allowed(current, cpumask_of_cpu(0));
20 acpi_wakeup_gpe_poweroff_prepare();
21 acpi_enter_sleep_state_prep(ACPI_STATE_S5);
22 ACPI_DISABLE_IRQS();
23 acpi_enter_sleep_state(ACPI_STATE_S5); 58 acpi_enter_sleep_state(ACPI_STATE_S5);
24} 59}
25 60
61#ifdef CONFIG_PM
62
63static int acpi_shutdown(struct sys_device *x)
64{
65 return acpi_sleep_prepare(ACPI_STATE_S5);
66}
67
68static struct sysdev_class acpi_sysclass = {
69 set_kset_name("acpi"),
70 .shutdown = acpi_shutdown
71};
72
73static struct sys_device device_acpi = {
74 .id = 0,
75 .cls = &acpi_sysclass,
76};
77
78#endif
79
26static int acpi_poweroff_init(void) 80static int acpi_poweroff_init(void)
27{ 81{
28 if (!acpi_disabled) { 82 if (!acpi_disabled) {
29 u8 type_a, type_b; 83 u8 type_a, type_b;
30 acpi_status status; 84 acpi_status status;
31 85
32 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 86 status =
33 if (ACPI_SUCCESS(status)) 87 acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
88 if (ACPI_SUCCESS(status)) {
34 pm_power_off = acpi_power_off; 89 pm_power_off = acpi_power_off;
90#ifdef CONFIG_PM
91 {
92 int error;
93 error = sysdev_class_register(&acpi_sysclass);
94 if (!error)
95 error = sysdev_register(&device_acpi);
96 return error;
97 }
98#endif
99 }
35 } 100 }
36 return 0; 101 return 0;
37} 102}
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index fd7c5a0649af..1be99f0996d6 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -13,13 +13,17 @@
13 13
14#include "sleep.h" 14#include "sleep.h"
15 15
16#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
16#define ACPI_SYSTEM_FILE_SLEEP "sleep" 17#define ACPI_SYSTEM_FILE_SLEEP "sleep"
18#endif
19
17#define ACPI_SYSTEM_FILE_ALARM "alarm" 20#define ACPI_SYSTEM_FILE_ALARM "alarm"
18#define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup" 21#define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup"
19 22
20#define _COMPONENT ACPI_SYSTEM_COMPONENT 23#define _COMPONENT ACPI_SYSTEM_COMPONENT
21ACPI_MODULE_NAME ("sleep") 24ACPI_MODULE_NAME ("sleep")
22 25
26#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
23 27
24static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset) 28static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
25{ 29{
@@ -78,6 +82,7 @@ acpi_system_write_sleep (
78 Done: 82 Done:
79 return error ? error : count; 83 return error ? error : count;
80} 84}
85#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
81 86
82static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) 87static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
83{ 88{
@@ -452,6 +457,7 @@ static struct file_operations acpi_system_wakeup_device_fops = {
452 .release = single_release, 457 .release = single_release,
453}; 458};
454 459
460#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
455static struct file_operations acpi_system_sleep_fops = { 461static struct file_operations acpi_system_sleep_fops = {
456 .open = acpi_system_sleep_open_fs, 462 .open = acpi_system_sleep_open_fs,
457 .read = seq_read, 463 .read = seq_read,
@@ -459,6 +465,7 @@ static struct file_operations acpi_system_sleep_fops = {
459 .llseek = seq_lseek, 465 .llseek = seq_lseek,
460 .release = single_release, 466 .release = single_release,
461}; 467};
468#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
462 469
463static struct file_operations acpi_system_alarm_fops = { 470static struct file_operations acpi_system_alarm_fops = {
464 .open = acpi_system_alarm_open_fs, 471 .open = acpi_system_alarm_open_fs,
@@ -484,11 +491,13 @@ static int acpi_sleep_proc_init(void)
484 if (acpi_disabled) 491 if (acpi_disabled)
485 return 0; 492 return 0;
486 493
494#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
487 /* 'sleep' [R/W]*/ 495 /* 'sleep' [R/W]*/
488 entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP, 496 entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP,
489 S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir); 497 S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
490 if (entry) 498 if (entry)
491 entry->proc_fops = &acpi_system_sleep_fops; 499 entry->proc_fops = &acpi_system_sleep_fops;
500#endif
492 501
493 /* 'alarm' [R/W] */ 502 /* 'alarm' [R/W] */
494 entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM, 503 entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM,
diff --git a/drivers/acpi/tables/tbconvrt.c b/drivers/acpi/tables/tbconvrt.c
index 334327c1f66f..92e0c31539be 100644
--- a/drivers/acpi/tables/tbconvrt.c
+++ b/drivers/acpi/tables/tbconvrt.c
@@ -50,6 +50,24 @@
50#define _COMPONENT ACPI_TABLES 50#define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbconvrt") 51 ACPI_MODULE_NAME ("tbconvrt")
52 52
53/* Local prototypes */
54
55static void
56acpi_tb_init_generic_address (
57 struct acpi_generic_address *new_gas_struct,
58 u8 register_bit_width,
59 acpi_physical_address address);
60
61static void
62acpi_tb_convert_fadt1 (
63 struct fadt_descriptor_rev2 *local_fadt,
64 struct fadt_descriptor_rev1 *original_fadt);
65
66static void
67acpi_tb_convert_fadt2 (
68 struct fadt_descriptor_rev2 *local_fadt,
69 struct fadt_descriptor_rev2 *original_fadt);
70
53 71
54u8 acpi_fadt_is_v1; 72u8 acpi_fadt_is_v1;
55EXPORT_SYMBOL(acpi_fadt_is_v1); 73EXPORT_SYMBOL(acpi_fadt_is_v1);
@@ -142,11 +160,13 @@ acpi_tb_convert_to_xsdt (
142 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { 160 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
143 if (acpi_gbl_RSDP->revision < 2) { 161 if (acpi_gbl_RSDP->revision < 2) {
144 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i], 162 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i],
145 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1, table_info->pointer))->table_offset_entry[i]); 163 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1,
164 table_info->pointer))->table_offset_entry[i]);
146 } 165 }
147 else { 166 else {
148 new_table->table_offset_entry[i] = 167 new_table->table_offset_entry[i] =
149 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info->pointer))->table_offset_entry[i]; 168 (ACPI_CAST_PTR (XSDT_DESCRIPTOR,
169 table_info->pointer))->table_offset_entry[i];
150 } 170 }
151 } 171 }
152 172
@@ -164,7 +184,7 @@ acpi_tb_convert_to_xsdt (
164} 184}
165 185
166 186
167/****************************************************************************** 187/*******************************************************************************
168 * 188 *
169 * FUNCTION: acpi_tb_init_generic_address 189 * FUNCTION: acpi_tb_init_generic_address
170 * 190 *
@@ -201,7 +221,7 @@ acpi_tb_init_generic_address (
201 * PARAMETERS: local_fadt - Pointer to new FADT 221 * PARAMETERS: local_fadt - Pointer to new FADT
202 * original_fadt - Pointer to old FADT 222 * original_fadt - Pointer to old FADT
203 * 223 *
204 * RETURN: Populates local_fadt 224 * RETURN: None, populates local_fadt
205 * 225 *
206 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format 226 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
207 * 227 *
@@ -213,7 +233,6 @@ acpi_tb_convert_fadt1 (
213 struct fadt_descriptor_rev1 *original_fadt) 233 struct fadt_descriptor_rev1 *original_fadt)
214{ 234{
215 235
216
217 /* ACPI 1.0 FACS */ 236 /* ACPI 1.0 FACS */
218 /* The BIOS stored FADT should agree with Revision 1.0 */ 237 /* The BIOS stored FADT should agree with Revision 1.0 */
219 acpi_fadt_is_v1 = 1; 238 acpi_fadt_is_v1 = 1;
@@ -232,7 +251,8 @@ acpi_tb_convert_fadt1 (
232 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt); 251 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
233 252
234 /* 253 /*
235 * System Interrupt Model isn't used in ACPI 2.0 (local_fadt->Reserved1 = 0;) 254 * System Interrupt Model isn't used in ACPI 2.0
255 * (local_fadt->Reserved1 = 0;)
236 */ 256 */
237 257
238 /* 258 /*
@@ -269,7 +289,8 @@ acpi_tb_convert_fadt1 (
269 * that immediately follows. 289 * that immediately follows.
270 */ 290 */
271 ACPI_MEMCPY (&local_fadt->reset_register, 291 ACPI_MEMCPY (&local_fadt->reset_register,
272 &(ACPI_CAST_PTR (struct fadt_descriptor_rev2_minus, original_fadt))->reset_register, 292 &(ACPI_CAST_PTR (struct fadt_descriptor_rev2_minus,
293 original_fadt))->reset_register,
273 sizeof (struct acpi_generic_address) + 1); 294 sizeof (struct acpi_generic_address) + 1);
274 } 295 }
275 else { 296 else {
@@ -304,7 +325,8 @@ acpi_tb_convert_fadt1 (
304 325
305 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable, 326 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
306 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 327 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
307 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address + 328 (acpi_physical_address)
329 (local_fadt->xpm1a_evt_blk.address +
308 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 330 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
309 331
310 /* PM1B is optional; leave null if not present */ 332 /* PM1B is optional; leave null if not present */
@@ -312,7 +334,8 @@ acpi_tb_convert_fadt1 (
312 if (local_fadt->xpm1b_evt_blk.address) { 334 if (local_fadt->xpm1b_evt_blk.address) {
313 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable, 335 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
314 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 336 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
315 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address + 337 (acpi_physical_address)
338 (local_fadt->xpm1b_evt_blk.address +
316 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 339 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
317 } 340 }
318} 341}
@@ -325,7 +348,7 @@ acpi_tb_convert_fadt1 (
325 * PARAMETERS: local_fadt - Pointer to new FADT 348 * PARAMETERS: local_fadt - Pointer to new FADT
326 * original_fadt - Pointer to old FADT 349 * original_fadt - Pointer to old FADT
327 * 350 *
328 * RETURN: Populates local_fadt 351 * RETURN: None, populates local_fadt
329 * 352 *
330 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format. 353 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
331 * Handles optional "X" fields. 354 * Handles optional "X" fields.
@@ -348,7 +371,8 @@ acpi_tb_convert_fadt2 (
348 * is zero. 371 * is zero.
349 */ 372 */
350 if (!(local_fadt->xfirmware_ctrl)) { 373 if (!(local_fadt->xfirmware_ctrl)) {
351 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl); 374 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl,
375 local_fadt->V1_firmware_ctrl);
352 } 376 }
353 377
354 if (!(local_fadt->Xdsdt)) { 378 if (!(local_fadt->Xdsdt)) {
@@ -357,32 +381,38 @@ acpi_tb_convert_fadt2 (
357 381
358 if (!(local_fadt->xpm1a_evt_blk.address)) { 382 if (!(local_fadt->xpm1a_evt_blk.address)) {
359 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk, 383 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk,
360 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1a_evt_blk); 384 local_fadt->pm1_evt_len,
385 (acpi_physical_address) local_fadt->V1_pm1a_evt_blk);
361 } 386 }
362 387
363 if (!(local_fadt->xpm1b_evt_blk.address)) { 388 if (!(local_fadt->xpm1b_evt_blk.address)) {
364 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk, 389 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk,
365 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1b_evt_blk); 390 local_fadt->pm1_evt_len,
391 (acpi_physical_address) local_fadt->V1_pm1b_evt_blk);
366 } 392 }
367 393
368 if (!(local_fadt->xpm1a_cnt_blk.address)) { 394 if (!(local_fadt->xpm1a_cnt_blk.address)) {
369 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk, 395 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk,
370 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk); 396 local_fadt->pm1_cnt_len,
397 (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk);
371 } 398 }
372 399
373 if (!(local_fadt->xpm1b_cnt_blk.address)) { 400 if (!(local_fadt->xpm1b_cnt_blk.address)) {
374 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk, 401 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk,
375 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk); 402 local_fadt->pm1_cnt_len,
403 (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk);
376 } 404 }
377 405
378 if (!(local_fadt->xpm2_cnt_blk.address)) { 406 if (!(local_fadt->xpm2_cnt_blk.address)) {
379 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk, 407 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk,
380 local_fadt->pm2_cnt_len, (acpi_physical_address) local_fadt->V1_pm2_cnt_blk); 408 local_fadt->pm2_cnt_len,
409 (acpi_physical_address) local_fadt->V1_pm2_cnt_blk);
381 } 410 }
382 411
383 if (!(local_fadt->xpm_tmr_blk.address)) { 412 if (!(local_fadt->xpm_tmr_blk.address)) {
384 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk, 413 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk,
385 local_fadt->pm_tm_len, (acpi_physical_address) local_fadt->V1_pm_tmr_blk); 414 local_fadt->pm_tm_len,
415 (acpi_physical_address) local_fadt->V1_pm_tmr_blk);
386 } 416 }
387 417
388 if (!(local_fadt->xgpe0_blk.address)) { 418 if (!(local_fadt->xgpe0_blk.address)) {
@@ -399,18 +429,24 @@ acpi_tb_convert_fadt2 (
399 429
400 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable, 430 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
401 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 431 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
402 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address + 432 (acpi_physical_address)
433 (local_fadt->xpm1a_evt_blk.address +
403 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 434 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
404 acpi_gbl_xpm1a_enable.address_space_id = local_fadt->xpm1a_evt_blk.address_space_id; 435
436 acpi_gbl_xpm1a_enable.address_space_id =
437 local_fadt->xpm1a_evt_blk.address_space_id;
405 438
406 /* PM1B is optional; leave null if not present */ 439 /* PM1B is optional; leave null if not present */
407 440
408 if (local_fadt->xpm1b_evt_blk.address) { 441 if (local_fadt->xpm1b_evt_blk.address) {
409 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable, 442 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
410 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 443 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
411 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address + 444 (acpi_physical_address)
445 (local_fadt->xpm1b_evt_blk.address +
412 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 446 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
413 acpi_gbl_xpm1b_enable.address_space_id = local_fadt->xpm1b_evt_blk.address_space_id; 447
448 acpi_gbl_xpm1b_enable.address_space_id =
449 local_fadt->xpm1b_evt_blk.address_space_id;
414 } 450 }
415} 451}
416 452
@@ -432,7 +468,8 @@ acpi_tb_convert_fadt2 (
432 ******************************************************************************/ 468 ******************************************************************************/
433 469
434acpi_status 470acpi_status
435acpi_tb_convert_table_fadt (void) 471acpi_tb_convert_table_fadt (
472 void)
436{ 473{
437 struct fadt_descriptor_rev2 *local_fadt; 474 struct fadt_descriptor_rev2 *local_fadt;
438 struct acpi_table_desc *table_desc; 475 struct acpi_table_desc *table_desc;
@@ -446,7 +483,8 @@ acpi_tb_convert_table_fadt (void)
446 * at least as long as the version 1.0 FADT 483 * at least as long as the version 1.0 FADT
447 */ 484 */
448 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev1)) { 485 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev1)) {
449 ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n", acpi_gbl_FADT->length)); 486 ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n",
487 acpi_gbl_FADT->length));
450 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 488 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
451 } 489 }
452 490
@@ -461,8 +499,9 @@ acpi_tb_convert_table_fadt (void)
461 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev2)) { 499 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev2)) {
462 /* Length is too short to be a V2.0 table */ 500 /* Length is too short to be a V2.0 table */
463 501
464 ACPI_REPORT_WARNING (("Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n", 502 ACPI_REPORT_WARNING ((
465 acpi_gbl_FADT->length, acpi_gbl_FADT->revision)); 503 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n",
504 acpi_gbl_FADT->length, acpi_gbl_FADT->revision));
466 505
467 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT); 506 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
468 } 507 }
@@ -478,9 +517,8 @@ acpi_tb_convert_table_fadt (void)
478 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT); 517 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
479 } 518 }
480 519
481 /* 520 /* Global FADT pointer will point to the new common V2.0 FADT */
482 * Global FADT pointer will point to the new common V2.0 FADT 521
483 */
484 acpi_gbl_FADT = local_fadt; 522 acpi_gbl_FADT = local_fadt;
485 acpi_gbl_FADT->length = sizeof (FADT_DESCRIPTOR); 523 acpi_gbl_FADT->length = sizeof (FADT_DESCRIPTOR);
486 524
@@ -508,7 +546,7 @@ acpi_tb_convert_table_fadt (void)
508 546
509/******************************************************************************* 547/*******************************************************************************
510 * 548 *
511 * FUNCTION: acpi_tb_convert_table_facs 549 * FUNCTION: acpi_tb_build_common_facs
512 * 550 *
513 * PARAMETERS: table_info - Info for currently installed FACS 551 * PARAMETERS: table_info - Info for currently installed FACS
514 * 552 *
@@ -530,12 +568,14 @@ acpi_tb_build_common_facs (
530 /* Absolute minimum length is 24, but the ACPI spec says 64 */ 568 /* Absolute minimum length is 24, but the ACPI spec says 64 */
531 569
532 if (acpi_gbl_FACS->length < 24) { 570 if (acpi_gbl_FACS->length < 24) {
533 ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n", acpi_gbl_FACS->length)); 571 ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n",
572 acpi_gbl_FACS->length));
534 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 573 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
535 } 574 }
536 575
537 if (acpi_gbl_FACS->length < 64) { 576 if (acpi_gbl_FACS->length < 64) {
538 ACPI_REPORT_WARNING (("FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n", 577 ACPI_REPORT_WARNING ((
578 "FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n",
539 acpi_gbl_FACS->length)); 579 acpi_gbl_FACS->length));
540 } 580 }
541 581
@@ -548,7 +588,8 @@ acpi_tb_build_common_facs (
548 (!(acpi_gbl_FACS->xfirmware_waking_vector))) { 588 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
549 /* ACPI 1.0 FACS or short table or optional X_ field is zero */ 589 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
550 590
551 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64, &(acpi_gbl_FACS->firmware_waking_vector)); 591 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64,
592 &(acpi_gbl_FACS->firmware_waking_vector));
552 acpi_gbl_common_fACS.vector_width = 32; 593 acpi_gbl_common_fACS.vector_width = 32;
553 } 594 }
554 else { 595 else {
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
index 896f3ddda62e..4ab2aadc6133 100644
--- a/drivers/acpi/tables/tbget.c
+++ b/drivers/acpi/tables/tbget.c
@@ -49,6 +49,19 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbget") 50 ACPI_MODULE_NAME ("tbget")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_get_this_table (
56 struct acpi_pointer *address,
57 struct acpi_table_header *header,
58 struct acpi_table_desc *table_info);
59
60static acpi_status
61acpi_tb_table_override (
62 struct acpi_table_header *header,
63 struct acpi_table_desc *table_info);
64
52 65
53/******************************************************************************* 66/*******************************************************************************
54 * 67 *
@@ -76,9 +89,8 @@ acpi_tb_get_table (
76 ACPI_FUNCTION_TRACE ("tb_get_table"); 89 ACPI_FUNCTION_TRACE ("tb_get_table");
77 90
78 91
79 /* 92 /* Get the header in order to get signature and table size */
80 * Get the header in order to get signature and table size 93
81 */
82 status = acpi_tb_get_table_header (address, &header); 94 status = acpi_tb_get_table_header (address, &header);
83 if (ACPI_FAILURE (status)) { 95 if (ACPI_FAILURE (status)) {
84 return_ACPI_STATUS (status); 96 return_ACPI_STATUS (status);
@@ -127,8 +139,8 @@ acpi_tb_get_table_header (
127 139
128 140
129 /* 141 /*
130 * Flags contains the current processor mode (Virtual or Physical addressing) 142 * Flags contains the current processor mode (Virtual or Physical
131 * The pointer_type is either Logical or Physical 143 * addressing) The pointer_type is either Logical or Physical
132 */ 144 */
133 switch (address->pointer_type) { 145 switch (address->pointer_type) {
134 case ACPI_PHYSMODE_PHYSPTR: 146 case ACPI_PHYSMODE_PHYSPTR:
@@ -136,7 +148,8 @@ acpi_tb_get_table_header (
136 148
137 /* Pointer matches processor mode, copy the header */ 149 /* Pointer matches processor mode, copy the header */
138 150
139 ACPI_MEMCPY (return_header, address->pointer.logical, sizeof (struct acpi_table_header)); 151 ACPI_MEMCPY (return_header, address->pointer.logical,
152 sizeof (struct acpi_table_header));
140 break; 153 break;
141 154
142 155
@@ -144,10 +157,11 @@ acpi_tb_get_table_header (
144 157
145 /* Create a logical address for the physical pointer*/ 158 /* Create a logical address for the physical pointer*/
146 159
147 status = acpi_os_map_memory (address->pointer.physical, sizeof (struct acpi_table_header), 160 status = acpi_os_map_memory (address->pointer.physical,
148 (void *) &header); 161 sizeof (struct acpi_table_header), (void *) &header);
149 if (ACPI_FAILURE (status)) { 162 if (ACPI_FAILURE (status)) {
150 ACPI_REPORT_ERROR (("Could not map memory at %8.8X%8.8X for length %X\n", 163 ACPI_REPORT_ERROR ((
164 "Could not map memory at %8.8X%8.8X for length %X\n",
151 ACPI_FORMAT_UINT64 (address->pointer.physical), 165 ACPI_FORMAT_UINT64 (address->pointer.physical),
152 sizeof (struct acpi_table_header))); 166 sizeof (struct acpi_table_header)));
153 return_ACPI_STATUS (status); 167 return_ACPI_STATUS (status);
@@ -210,9 +224,8 @@ acpi_tb_get_table_body (
210 return_ACPI_STATUS (AE_BAD_PARAMETER); 224 return_ACPI_STATUS (AE_BAD_PARAMETER);
211 } 225 }
212 226
213 /* 227 /* Attempt table override. */
214 * Attempt table override. 228
215 */
216 status = acpi_tb_table_override (header, table_info); 229 status = acpi_tb_table_override (header, table_info);
217 if (ACPI_SUCCESS (status)) { 230 if (ACPI_SUCCESS (status)) {
218 /* Table was overridden by the host OS */ 231 /* Table was overridden by the host OS */
@@ -241,7 +254,7 @@ acpi_tb_get_table_body (
241 * 254 *
242 ******************************************************************************/ 255 ******************************************************************************/
243 256
244acpi_status 257static acpi_status
245acpi_tb_table_override ( 258acpi_tb_table_override (
246 struct acpi_table_header *header, 259 struct acpi_table_header *header,
247 struct acpi_table_desc *table_info) 260 struct acpi_table_desc *table_info)
@@ -315,7 +328,7 @@ acpi_tb_table_override (
315 * 328 *
316 ******************************************************************************/ 329 ******************************************************************************/
317 330
318acpi_status 331static acpi_status
319acpi_tb_get_this_table ( 332acpi_tb_get_this_table (
320 struct acpi_pointer *address, 333 struct acpi_pointer *address,
321 struct acpi_table_header *header, 334 struct acpi_table_header *header,
@@ -330,8 +343,8 @@ acpi_tb_get_this_table (
330 343
331 344
332 /* 345 /*
333 * Flags contains the current processor mode (Virtual or Physical addressing) 346 * Flags contains the current processor mode (Virtual or Physical
334 * The pointer_type is either Logical or Physical 347 * addressing) The pointer_type is either Logical or Physical
335 */ 348 */
336 switch (address->pointer_type) { 349 switch (address->pointer_type) {
337 case ACPI_PHYSMODE_PHYSPTR: 350 case ACPI_PHYSMODE_PHYSPTR:
@@ -341,7 +354,8 @@ acpi_tb_get_this_table (
341 354
342 full_table = ACPI_MEM_ALLOCATE (header->length); 355 full_table = ACPI_MEM_ALLOCATE (header->length);
343 if (!full_table) { 356 if (!full_table) {
344 ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n", 357 ACPI_REPORT_ERROR ((
358 "Could not allocate table memory for [%4.4s] length %X\n",
345 header->signature, header->length)); 359 header->signature, header->length));
346 return_ACPI_STATUS (AE_NO_MEMORY); 360 return_ACPI_STATUS (AE_NO_MEMORY);
347 } 361 }
@@ -362,12 +376,14 @@ acpi_tb_get_this_table (
362 * Just map the table's physical memory 376 * Just map the table's physical memory
363 * into our address space. 377 * into our address space.
364 */ 378 */
365 status = acpi_os_map_memory (address->pointer.physical, (acpi_size) header->length, 379 status = acpi_os_map_memory (address->pointer.physical,
366 (void *) &full_table); 380 (acpi_size) header->length, (void *) &full_table);
367 if (ACPI_FAILURE (status)) { 381 if (ACPI_FAILURE (status)) {
368 ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n", 382 ACPI_REPORT_ERROR ((
383 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
369 header->signature, 384 header->signature,
370 ACPI_FORMAT_UINT64 (address->pointer.physical), header->length)); 385 ACPI_FORMAT_UINT64 (address->pointer.physical),
386 header->length));
371 return (status); 387 return (status);
372 } 388 }
373 389
@@ -465,9 +481,8 @@ acpi_tb_get_table_ptr (
465 return_ACPI_STATUS (AE_OK); 481 return_ACPI_STATUS (AE_OK);
466 } 482 }
467 483
468 /* 484 /* Check for instance out of range */
469 * Check for instance out of range 485
470 */
471 if (instance > acpi_gbl_table_lists[table_type].count) { 486 if (instance > acpi_gbl_table_lists[table_type].count) {
472 return_ACPI_STATUS (AE_NOT_EXIST); 487 return_ACPI_STATUS (AE_NOT_EXIST);
473 } 488 }
diff --git a/drivers/acpi/tables/tbgetall.c b/drivers/acpi/tables/tbgetall.c
index adc4270988bc..eea5b8cb5ebb 100644
--- a/drivers/acpi/tables/tbgetall.c
+++ b/drivers/acpi/tables/tbgetall.c
@@ -49,6 +49,19 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbgetall") 50 ACPI_MODULE_NAME ("tbgetall")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_get_primary_table (
56 struct acpi_pointer *address,
57 struct acpi_table_desc *table_info);
58
59static acpi_status
60acpi_tb_get_secondary_table (
61 struct acpi_pointer *address,
62 acpi_string signature,
63 struct acpi_table_desc *table_info);
64
52 65
53/******************************************************************************* 66/*******************************************************************************
54 * 67 *
@@ -63,7 +76,7 @@
63 * 76 *
64 ******************************************************************************/ 77 ******************************************************************************/
65 78
66acpi_status 79static acpi_status
67acpi_tb_get_primary_table ( 80acpi_tb_get_primary_table (
68 struct acpi_pointer *address, 81 struct acpi_pointer *address,
69 struct acpi_table_desc *table_info) 82 struct acpi_table_desc *table_info)
@@ -81,9 +94,8 @@ acpi_tb_get_primary_table (
81 return_ACPI_STATUS (AE_OK); 94 return_ACPI_STATUS (AE_OK);
82 } 95 }
83 96
84 /* 97 /* Get the header in order to get signature and table size */
85 * Get the header in order to get signature and table size 98
86 */
87 status = acpi_tb_get_table_header (address, &header); 99 status = acpi_tb_get_table_header (address, &header);
88 if (ACPI_FAILURE (status)) { 100 if (ACPI_FAILURE (status)) {
89 return_ACPI_STATUS (status); 101 return_ACPI_STATUS (status);
@@ -130,7 +142,7 @@ acpi_tb_get_primary_table (
130 * 142 *
131 ******************************************************************************/ 143 ******************************************************************************/
132 144
133acpi_status 145static acpi_status
134acpi_tb_get_secondary_table ( 146acpi_tb_get_secondary_table (
135 struct acpi_pointer *address, 147 struct acpi_pointer *address,
136 acpi_string signature, 148 acpi_string signature,
@@ -153,7 +165,8 @@ acpi_tb_get_secondary_table (
153 /* Signature must match request */ 165 /* Signature must match request */
154 166
155 if (ACPI_STRNCMP (header.signature, signature, ACPI_NAME_SIZE)) { 167 if (ACPI_STRNCMP (header.signature, signature, ACPI_NAME_SIZE)) {
156 ACPI_REPORT_ERROR (("Incorrect table signature - wanted [%s] found [%4.4s]\n", 168 ACPI_REPORT_ERROR ((
169 "Incorrect table signature - wanted [%s] found [%4.4s]\n",
157 signature, header.signature)); 170 signature, header.signature));
158 return_ACPI_STATUS (AE_BAD_SIGNATURE); 171 return_ACPI_STATUS (AE_BAD_SIGNATURE);
159 } 172 }
@@ -230,7 +243,8 @@ acpi_tb_get_required_tables (
230 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { 243 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
231 /* Get the table address from the common internal XSDT */ 244 /* Get the table address from the common internal XSDT */
232 245
233 address.pointer.value = acpi_gbl_XSDT->table_offset_entry[i]; 246 address.pointer.value =
247 acpi_gbl_XSDT->table_offset_entry[i];
234 248
235 /* 249 /*
236 * Get the tables needed by this subsystem (FADT and any SSDTs). 250 * Get the tables needed by this subsystem (FADT and any SSDTs).
@@ -252,18 +266,18 @@ acpi_tb_get_required_tables (
252 } 266 }
253 267
254 /* 268 /*
255 * Convert the FADT to a common format. This allows earlier revisions of the 269 * Convert the FADT to a common format. This allows earlier revisions of
256 * table to coexist with newer versions, using common access code. 270 * the table to coexist with newer versions, using common access code.
257 */ 271 */
258 status = acpi_tb_convert_table_fadt (); 272 status = acpi_tb_convert_table_fadt ();
259 if (ACPI_FAILURE (status)) { 273 if (ACPI_FAILURE (status)) {
260 ACPI_REPORT_ERROR (("Could not convert FADT to internal common format\n")); 274 ACPI_REPORT_ERROR ((
275 "Could not convert FADT to internal common format\n"));
261 return_ACPI_STATUS (status); 276 return_ACPI_STATUS (status);
262 } 277 }
263 278
264 /* 279 /* Get the FACS (Pointed to by the FADT) */
265 * Get the FACS (Pointed to by the FADT) 280
266 */
267 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl; 281 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
268 282
269 status = acpi_tb_get_secondary_table (&address, FACS_SIG, &table_info); 283 status = acpi_tb_get_secondary_table (&address, FACS_SIG, &table_info);
@@ -282,9 +296,8 @@ acpi_tb_get_required_tables (
282 return_ACPI_STATUS (status); 296 return_ACPI_STATUS (status);
283 } 297 }
284 298
285 /* 299 /* Get/install the DSDT (Pointed to by the FADT) */
286 * Get/install the DSDT (Pointed to by the FADT) 300
287 */
288 address.pointer.value = acpi_gbl_FADT->Xdsdt; 301 address.pointer.value = acpi_gbl_FADT->Xdsdt;
289 302
290 status = acpi_tb_get_secondary_table (&address, DSDT_SIG, &table_info); 303 status = acpi_tb_get_secondary_table (&address, DSDT_SIG, &table_info);
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 85d5bb01022c..629b64c8193d 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -49,6 +49,14 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbinstal") 50 ACPI_MODULE_NAME ("tbinstal")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_match_signature (
56 char *signature,
57 struct acpi_table_desc *table_info,
58 u8 search_type);
59
52 60
53/******************************************************************************* 61/*******************************************************************************
54 * 62 *
@@ -56,6 +64,7 @@
56 * 64 *
57 * PARAMETERS: Signature - Table signature to match 65 * PARAMETERS: Signature - Table signature to match
58 * table_info - Return data 66 * table_info - Return data
67 * search_type - Table type to match (primary/secondary)
59 * 68 *
60 * RETURN: Status 69 * RETURN: Status
61 * 70 *
@@ -64,7 +73,7 @@
64 * 73 *
65 ******************************************************************************/ 74 ******************************************************************************/
66 75
67acpi_status 76static acpi_status
68acpi_tb_match_signature ( 77acpi_tb_match_signature (
69 char *signature, 78 char *signature,
70 struct acpi_table_desc *table_info, 79 struct acpi_table_desc *table_info,
@@ -76,9 +85,8 @@ acpi_tb_match_signature (
76 ACPI_FUNCTION_TRACE ("tb_match_signature"); 85 ACPI_FUNCTION_TRACE ("tb_match_signature");
77 86
78 87
79 /* 88 /* Search for a signature match among the known table types */
80 * Search for a signature match among the known table types 89
81 */
82 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) { 90 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) {
83 if (!(acpi_gbl_table_data[i].flags & search_type)) { 91 if (!(acpi_gbl_table_data[i].flags & search_type)) {
84 continue; 92 continue;
@@ -161,6 +169,7 @@ acpi_tb_install_table (
161 * FUNCTION: acpi_tb_recognize_table 169 * FUNCTION: acpi_tb_recognize_table
162 * 170 *
163 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body 171 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
172 * search_type - Table type to match (primary/secondary)
164 * 173 *
165 * RETURN: Status 174 * RETURN: Status
166 * 175 *
@@ -203,7 +212,8 @@ acpi_tb_recognize_table (
203 * This can be any one of many valid ACPI tables, it just isn't one of 212 * This can be any one of many valid ACPI tables, it just isn't one of
204 * the tables that is consumed by the core subsystem 213 * the tables that is consumed by the core subsystem
205 */ 214 */
206 status = acpi_tb_match_signature (table_header->signature, table_info, search_type); 215 status = acpi_tb_match_signature (table_header->signature,
216 table_info, search_type);
207 if (ACPI_FAILURE (status)) { 217 if (ACPI_FAILURE (status)) {
208 return_ACPI_STATUS (status); 218 return_ACPI_STATUS (status);
209 } 219 }
@@ -253,9 +263,8 @@ acpi_tb_init_table_descriptor (
253 return_ACPI_STATUS (AE_NO_MEMORY); 263 return_ACPI_STATUS (AE_NO_MEMORY);
254 } 264 }
255 265
256 /* 266 /* Install the table into the global data structure */
257 * Install the table into the global data structure 267
258 */
259 list_head = &acpi_gbl_table_lists[table_type]; 268 list_head = &acpi_gbl_table_lists[table_type];
260 269
261 /* 270 /*
@@ -316,7 +325,8 @@ acpi_tb_init_table_descriptor (
316 table_desc->aml_start = (u8 *) (table_desc->pointer + 1), 325 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
317 table_desc->aml_length = (u32) (table_desc->length - 326 table_desc->aml_length = (u32) (table_desc->length -
318 (u32) sizeof (struct acpi_table_header)); 327 (u32) sizeof (struct acpi_table_header));
319 table_desc->table_id = acpi_ut_allocate_owner_id (ACPI_OWNER_TYPE_TABLE); 328 table_desc->table_id = acpi_ut_allocate_owner_id (
329 ACPI_OWNER_TYPE_TABLE);
320 table_desc->loaded_into_namespace = FALSE; 330 table_desc->loaded_into_namespace = FALSE;
321 331
322 /* 332 /*
@@ -349,7 +359,8 @@ acpi_tb_init_table_descriptor (
349 ******************************************************************************/ 359 ******************************************************************************/
350 360
351void 361void
352acpi_tb_delete_all_tables (void) 362acpi_tb_delete_all_tables (
363 void)
353{ 364{
354 acpi_table_type type; 365 acpi_table_type type;
355 366
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
index 9c6913238d52..b7ffe39c3626 100644
--- a/drivers/acpi/tables/tbrsdt.c
+++ b/drivers/acpi/tables/tbrsdt.c
@@ -84,8 +84,9 @@ acpi_tb_verify_rsdp (
84 /* 84 /*
85 * Obtain access to the RSDP structure 85 * Obtain access to the RSDP structure
86 */ 86 */
87 status = acpi_os_map_memory (address->pointer.physical, sizeof (struct rsdp_descriptor), 87 status = acpi_os_map_memory (address->pointer.physical,
88 (void *) &rsdp); 88 sizeof (struct rsdp_descriptor),
89 (void *) &rsdp);
89 if (ACPI_FAILURE (status)) { 90 if (ACPI_FAILURE (status)) {
90 return_ACPI_STATUS (status); 91 return_ACPI_STATUS (status);
91 } 92 }
@@ -154,9 +155,9 @@ cleanup:
154 * 155 *
155 * FUNCTION: acpi_tb_get_rsdt_address 156 * FUNCTION: acpi_tb_get_rsdt_address
156 * 157 *
157 * PARAMETERS: None 158 * PARAMETERS: out_address - Where the address is returned
158 * 159 *
159 * RETURN: RSDT physical address 160 * RETURN: None, Address
160 * 161 *
161 * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the 162 * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the
162 * version of the RSDP 163 * version of the RSDP
@@ -181,7 +182,8 @@ acpi_tb_get_rsdt_address (
181 out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address; 182 out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address;
182 } 183 }
183 else { 184 else {
184 out_address->pointer.value = acpi_gbl_RSDP->xsdt_physical_address; 185 out_address->pointer.value =
186 acpi_gbl_RSDP->xsdt_physical_address;
185 } 187 }
186} 188}
187 189
@@ -224,7 +226,8 @@ acpi_tb_validate_rsdt (
224 if (no_match) { 226 if (no_match) {
225 /* Invalid RSDT or XSDT signature */ 227 /* Invalid RSDT or XSDT signature */
226 228
227 ACPI_REPORT_ERROR (("Invalid signature where RSDP indicates RSDT/XSDT should be located\n")); 229 ACPI_REPORT_ERROR ((
230 "Invalid signature where RSDP indicates RSDT/XSDT should be located\n"));
228 231
229 ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20); 232 ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20);
230 233
@@ -282,6 +285,7 @@ acpi_tb_get_table_rsdt (
282 if (ACPI_FAILURE (status)) { 285 if (ACPI_FAILURE (status)) {
283 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n", 286 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n",
284 acpi_format_exception (status))); 287 acpi_format_exception (status)));
288
285 return_ACPI_STATUS (status); 289 return_ACPI_STATUS (status);
286 } 290 }
287 291
@@ -299,7 +303,8 @@ acpi_tb_get_table_rsdt (
299 303
300 /* Get the number of tables defined in the RSDT or XSDT */ 304 /* Get the number of tables defined in the RSDT or XSDT */
301 305
302 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP, table_info.pointer); 306 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP,
307 table_info.pointer);
303 308
304 /* Convert and/or copy to an XSDT structure */ 309 /* Convert and/or copy to an XSDT structure */
305 310
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index fede5804c783..e69d01d443d2 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -49,48 +49,14 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbutils") 50 ACPI_MODULE_NAME ("tbutils")
51 51
52/* Local prototypes */
52 53
53/******************************************************************************* 54#ifdef ACPI_OBSOLETE_FUNCTIONS
54 *
55 * FUNCTION: acpi_tb_handle_to_object
56 *
57 * PARAMETERS: table_id - Id for which the function is searching
58 * table_desc - Pointer to return the matching table
59 * descriptor.
60 *
61 * RETURN: Search the tables to find one with a matching table_id and
62 * return a pointer to that table descriptor.
63 *
64 ******************************************************************************/
65#ifdef ACPI_FUTURE_USAGE
66acpi_status 55acpi_status
67acpi_tb_handle_to_object ( 56acpi_tb_handle_to_object (
68 u16 table_id, 57 u16 table_id,
69 struct acpi_table_desc **return_table_desc) 58 struct acpi_table_desc **table_desc);
70{ 59#endif
71 u32 i;
72 struct acpi_table_desc *table_desc;
73
74
75 ACPI_FUNCTION_NAME ("tb_handle_to_object");
76
77
78 for (i = 0; i < ACPI_TABLE_MAX; i++) {
79 table_desc = acpi_gbl_table_lists[i].next;
80 while (table_desc) {
81 if (table_desc->table_id == table_id) {
82 *return_table_desc = table_desc;
83 return (AE_OK);
84 }
85
86 table_desc = table_desc->next;
87 }
88 }
89
90 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
91 return (AE_BAD_PARAMETER);
92}
93#endif /* ACPI_FUTURE_USAGE */
94 60
95 61
96/******************************************************************************* 62/*******************************************************************************
@@ -128,6 +94,7 @@ acpi_tb_validate_table_header (
128 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) { 94 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) {
129 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 95 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
130 "Cannot read table header at %p\n", table_header)); 96 "Cannot read table header at %p\n", table_header));
97
131 return (AE_BAD_ADDRESS); 98 return (AE_BAD_ADDRESS);
132 } 99 }
133 100
@@ -141,6 +108,7 @@ acpi_tb_validate_table_header (
141 108
142 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n", 109 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n",
143 (char *) &signature)); 110 (char *) &signature));
111
144 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); 112 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
145 return (AE_BAD_SIGNATURE); 113 return (AE_BAD_SIGNATURE);
146 } 114 }
@@ -154,6 +122,7 @@ acpi_tb_validate_table_header (
154 122
155 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n", 123 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n",
156 (u32) table_header->length)); 124 (u32) table_header->length));
125
157 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); 126 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
158 return (AE_BAD_HEADER); 127 return (AE_BAD_HEADER);
159 } 128 }
@@ -193,8 +162,10 @@ acpi_tb_verify_table_checksum (
193 /* Return the appropriate exception */ 162 /* Return the appropriate exception */
194 163
195 if (checksum) { 164 if (checksum) {
196 ACPI_REPORT_WARNING (("Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n", 165 ACPI_REPORT_WARNING ((
197 table_header->signature, (u32) table_header->checksum, (u32) checksum)); 166 "Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n",
167 table_header->signature, (u32) table_header->checksum,
168 (u32) checksum));
198 169
199 status = AE_BAD_CHECKSUM; 170 status = AE_BAD_CHECKSUM;
200 } 171 }
@@ -209,7 +180,7 @@ acpi_tb_verify_table_checksum (
209 * PARAMETERS: Buffer - Buffer to checksum 180 * PARAMETERS: Buffer - Buffer to checksum
210 * Length - Size of the buffer 181 * Length - Size of the buffer
211 * 182 *
212 * RETURNS 8 bit checksum of buffer 183 * RETURN: 8 bit checksum of buffer
213 * 184 *
214 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. 185 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
215 * 186 *
@@ -238,3 +209,47 @@ acpi_tb_checksum (
238} 209}
239 210
240 211
212#ifdef ACPI_OBSOLETE_FUNCTIONS
213/*******************************************************************************
214 *
215 * FUNCTION: acpi_tb_handle_to_object
216 *
217 * PARAMETERS: table_id - Id for which the function is searching
218 * table_desc - Pointer to return the matching table
219 * descriptor.
220 *
221 * RETURN: Search the tables to find one with a matching table_id and
222 * return a pointer to that table descriptor.
223 *
224 ******************************************************************************/
225
226acpi_status
227acpi_tb_handle_to_object (
228 u16 table_id,
229 struct acpi_table_desc **return_table_desc)
230{
231 u32 i;
232 struct acpi_table_desc *table_desc;
233
234
235 ACPI_FUNCTION_NAME ("tb_handle_to_object");
236
237
238 for (i = 0; i < ACPI_TABLE_MAX; i++) {
239 table_desc = acpi_gbl_table_lists[i].next;
240 while (table_desc) {
241 if (table_desc->table_id == table_id) {
242 *return_table_desc = table_desc;
243 return (AE_OK);
244 }
245
246 table_desc = table_desc->next;
247 }
248 }
249
250 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
251 return (AE_BAD_PARAMETER);
252}
253#endif
254
255
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 7715043461c4..0c0b9085dbeb 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -67,7 +67,8 @@
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69acpi_status 69acpi_status
70acpi_load_tables (void) 70acpi_load_tables (
71 void)
71{ 72{
72 struct acpi_pointer rsdp_address; 73 struct acpi_pointer rsdp_address;
73 acpi_status status; 74 acpi_status status;
@@ -82,7 +83,7 @@ acpi_load_tables (void)
82 &rsdp_address); 83 &rsdp_address);
83 if (ACPI_FAILURE (status)) { 84 if (ACPI_FAILURE (status)) {
84 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n", 85 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
85 acpi_format_exception (status))); 86 acpi_format_exception (status)));
86 goto error_exit; 87 goto error_exit;
87 } 88 }
88 89
@@ -93,7 +94,7 @@ acpi_load_tables (void)
93 status = acpi_tb_verify_rsdp (&rsdp_address); 94 status = acpi_tb_verify_rsdp (&rsdp_address);
94 if (ACPI_FAILURE (status)) { 95 if (ACPI_FAILURE (status)) {
95 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n", 96 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
96 acpi_format_exception (status))); 97 acpi_format_exception (status)));
97 goto error_exit; 98 goto error_exit;
98 } 99 }
99 100
@@ -102,7 +103,7 @@ acpi_load_tables (void)
102 status = acpi_tb_get_table_rsdt (); 103 status = acpi_tb_get_table_rsdt ();
103 if (ACPI_FAILURE (status)) { 104 if (ACPI_FAILURE (status)) {
104 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n", 105 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
105 acpi_format_exception (status))); 106 acpi_format_exception (status)));
106 goto error_exit; 107 goto error_exit;
107 } 108 }
108 109
@@ -110,20 +111,20 @@ acpi_load_tables (void)
110 111
111 status = acpi_tb_get_required_tables (); 112 status = acpi_tb_get_required_tables ();
112 if (ACPI_FAILURE (status)) { 113 if (ACPI_FAILURE (status)) {
113 ACPI_REPORT_ERROR (("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n", 114 ACPI_REPORT_ERROR ((
114 acpi_format_exception (status))); 115 "acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
116 acpi_format_exception (status)));
115 goto error_exit; 117 goto error_exit;
116 } 118 }
117 119
118 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); 120 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
119 121
120
121 /* Load the namespace from the tables */ 122 /* Load the namespace from the tables */
122 123
123 status = acpi_ns_load_namespace (); 124 status = acpi_ns_load_namespace ();
124 if (ACPI_FAILURE (status)) { 125 if (ACPI_FAILURE (status)) {
125 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n", 126 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
126 acpi_format_exception (status))); 127 acpi_format_exception (status)));
127 goto error_exit; 128 goto error_exit;
128 } 129 }
129 130
@@ -139,7 +140,6 @@ error_exit:
139 140
140 141
141#ifdef ACPI_FUTURE_USAGE 142#ifdef ACPI_FUTURE_USAGE
142
143/******************************************************************************* 143/*******************************************************************************
144 * 144 *
145 * FUNCTION: acpi_load_table 145 * FUNCTION: acpi_load_table
@@ -250,7 +250,6 @@ acpi_unload_table (
250 return_ACPI_STATUS (AE_BAD_PARAMETER); 250 return_ACPI_STATUS (AE_BAD_PARAMETER);
251 } 251 }
252 252
253
254 /* Find all tables of the requested type */ 253 /* Find all tables of the requested type */
255 254
256 table_desc = acpi_gbl_table_lists[table_type].next; 255 table_desc = acpi_gbl_table_lists[table_type].next;
@@ -321,7 +320,6 @@ acpi_get_table_header (
321 return_ACPI_STATUS (AE_BAD_PARAMETER); 320 return_ACPI_STATUS (AE_BAD_PARAMETER);
322 } 321 }
323 322
324
325 /* Get a pointer to the entire table */ 323 /* Get a pointer to the entire table */
326 324
327 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); 325 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
@@ -329,23 +327,20 @@ acpi_get_table_header (
329 return_ACPI_STATUS (status); 327 return_ACPI_STATUS (status);
330 } 328 }
331 329
332 /* 330 /* The function will return a NULL pointer if the table is not loaded */
333 * The function will return a NULL pointer if the table is not loaded 331
334 */
335 if (tbl_ptr == NULL) { 332 if (tbl_ptr == NULL) {
336 return_ACPI_STATUS (AE_NOT_EXIST); 333 return_ACPI_STATUS (AE_NOT_EXIST);
337 } 334 }
338 335
339 /* 336 /* Copy the header to the caller's buffer */
340 * Copy the header to the caller's buffer 337
341 */
342 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr, 338 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr,
343 sizeof (struct acpi_table_header)); 339 sizeof (struct acpi_table_header));
344 340
345 return_ACPI_STATUS (status); 341 return_ACPI_STATUS (status);
346} 342}
347 343
348
349#endif /* ACPI_FUTURE_USAGE */ 344#endif /* ACPI_FUTURE_USAGE */
350 345
351/******************************************************************************* 346/*******************************************************************************
@@ -404,7 +399,6 @@ acpi_get_table (
404 return_ACPI_STATUS (AE_BAD_PARAMETER); 399 return_ACPI_STATUS (AE_BAD_PARAMETER);
405 } 400 }
406 401
407
408 /* Get a pointer to the entire table */ 402 /* Get a pointer to the entire table */
409 403
410 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); 404 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
@@ -423,9 +417,8 @@ acpi_get_table (
423 /* Get the table length */ 417 /* Get the table length */
424 418
425 if (table_type == ACPI_TABLE_RSDP) { 419 if (table_type == ACPI_TABLE_RSDP) {
426 /* 420 /* RSD PTR is the only "table" without a header */
427 * RSD PTR is the only "table" without a header 421
428 */
429 table_length = sizeof (struct rsdp_descriptor); 422 table_length = sizeof (struct rsdp_descriptor);
430 } 423 }
431 else { 424 else {
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
index 6e8072ebbac6..dc3c3f6a9f62 100644
--- a/drivers/acpi/tables/tbxfroot.c
+++ b/drivers/acpi/tables/tbxfroot.c
@@ -50,6 +50,18 @@
50#define _COMPONENT ACPI_TABLES 50#define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbxfroot") 51 ACPI_MODULE_NAME ("tbxfroot")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_tb_find_rsdp (
57 struct acpi_table_desc *table_info,
58 u32 flags);
59
60static u8 *
61acpi_tb_scan_memory_for_rsdp (
62 u8 *start_address,
63 u32 length);
64
53 65
54/******************************************************************************* 66/*******************************************************************************
55 * 67 *
@@ -57,7 +69,8 @@
57 * 69 *
58 * PARAMETERS: Signature - String with ACPI table signature 70 * PARAMETERS: Signature - String with ACPI table signature
59 * oem_id - String with the table OEM ID 71 * oem_id - String with the table OEM ID
60 * oem_table_id - String with the OEM Table ID. 72 * oem_table_id - String with the OEM Table ID
73 * table_ptr - Where the table pointer is returned
61 * 74 *
62 * RETURN: Status 75 * RETURN: Status
63 * 76 *
@@ -99,14 +112,13 @@ acpi_tb_find_table (
99 if (!acpi_gbl_DSDT) { 112 if (!acpi_gbl_DSDT) {
100 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 113 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
101 } 114 }
102
103 table = acpi_gbl_DSDT; 115 table = acpi_gbl_DSDT;
104 } 116 }
105 else { 117 else {
106 /* Find the table */ 118 /* Find the table */
107 119
108 status = acpi_get_firmware_table (signature, 1, 120 status = acpi_get_firmware_table (signature, 1,
109 ACPI_LOGICAL_ADDRESSING, &table); 121 ACPI_LOGICAL_ADDRESSING, &table);
110 if (ACPI_FAILURE (status)) { 122 if (ACPI_FAILURE (status)) {
111 return_ACPI_STATUS (status); 123 return_ACPI_STATUS (status);
112 } 124 }
@@ -114,14 +126,19 @@ acpi_tb_find_table (
114 126
115 /* Check oem_id and oem_table_id */ 127 /* Check oem_id and oem_table_id */
116 128
117 if ((oem_id[0] && ACPI_STRNCMP ( 129 if ((oem_id[0] && ACPI_STRNCMP (
118 oem_id, table->oem_id, sizeof (table->oem_id))) || 130 oem_id, table->oem_id,
131 sizeof (table->oem_id))) ||
132
119 (oem_table_id[0] && ACPI_STRNCMP ( 133 (oem_table_id[0] && ACPI_STRNCMP (
120 oem_table_id, table->oem_table_id, sizeof (table->oem_table_id)))) { 134 oem_table_id, table->oem_table_id,
135 sizeof (table->oem_table_id)))) {
121 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND); 136 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
122 } 137 }
123 138
124 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n", table->signature)); 139 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
140 table->signature));
141
125 *table_ptr = table; 142 *table_ptr = table;
126 return_ACPI_STATUS (AE_OK); 143 return_ACPI_STATUS (AE_OK);
127} 144}
@@ -191,8 +208,8 @@ acpi_get_firmware_table (
191 /* Map and validate the RSDP */ 208 /* Map and validate the RSDP */
192 209
193 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) { 210 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
194 status = acpi_os_map_memory (address.pointer.physical, sizeof (struct rsdp_descriptor), 211 status = acpi_os_map_memory (address.pointer.physical,
195 (void *) &acpi_gbl_RSDP); 212 sizeof (struct rsdp_descriptor), (void *) &acpi_gbl_RSDP);
196 if (ACPI_FAILURE (status)) { 213 if (ACPI_FAILURE (status)) {
197 return_ACPI_STATUS (status); 214 return_ACPI_STATUS (status);
198 } 215 }
@@ -203,7 +220,8 @@ acpi_get_firmware_table (
203 220
204 /* The signature and checksum must both be correct */ 221 /* The signature and checksum must both be correct */
205 222
206 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) { 223 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP, RSDP_SIG,
224 sizeof (RSDP_SIG)-1) != 0) {
207 /* Nope, BAD Signature */ 225 /* Nope, BAD Signature */
208 226
209 return_ACPI_STATUS (AE_BAD_SIGNATURE); 227 return_ACPI_STATUS (AE_BAD_SIGNATURE);
@@ -313,7 +331,8 @@ acpi_get_firmware_table (
313 331
314 332
315cleanup: 333cleanup:
316 acpi_os_unmap_memory (rsdt_info->pointer, (acpi_size) rsdt_info->pointer->length); 334 acpi_os_unmap_memory (rsdt_info->pointer,
335 (acpi_size) rsdt_info->pointer->length);
317 ACPI_MEM_FREE (rsdt_info); 336 ACPI_MEM_FREE (rsdt_info);
318 337
319 if (header) { 338 if (header) {
@@ -335,8 +354,8 @@ EXPORT_SYMBOL(acpi_get_firmware_table);
335 * 354 *
336 * FUNCTION: acpi_find_root_pointer 355 * FUNCTION: acpi_find_root_pointer
337 * 356 *
338 * PARAMETERS: **rsdp_address - Where to place the RSDP address 357 * PARAMETERS: Flags - Logical/Physical addressing
339 * Flags - Logical/Physical addressing 358 * rsdp_address - Where to place the RSDP address
340 * 359 *
341 * RETURN: Status, Physical address of the RSDP 360 * RETURN: Status, Physical address of the RSDP
342 * 361 *
@@ -363,6 +382,7 @@ acpi_find_root_pointer (
363 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 382 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
364 "RSDP structure not found, %s Flags=%X\n", 383 "RSDP structure not found, %s Flags=%X\n",
365 acpi_format_exception (status), flags)); 384 acpi_format_exception (status), flags));
385
366 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 386 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
367 } 387 }
368 388
@@ -385,7 +405,7 @@ acpi_find_root_pointer (
385 * 405 *
386 ******************************************************************************/ 406 ******************************************************************************/
387 407
388u8 * 408static u8 *
389acpi_tb_scan_memory_for_rsdp ( 409acpi_tb_scan_memory_for_rsdp (
390 u8 *start_address, 410 u8 *start_address,
391 u32 length) 411 u32 length)
@@ -406,7 +426,8 @@ acpi_tb_scan_memory_for_rsdp (
406 mem_rover += ACPI_RSDP_SCAN_STEP) { 426 mem_rover += ACPI_RSDP_SCAN_STEP) {
407 /* The signature and checksum must both be correct */ 427 /* The signature and checksum must both be correct */
408 428
409 if (ACPI_STRNCMP ((char *) mem_rover, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) { 429 if (ACPI_STRNCMP ((char *) mem_rover,
430 RSDP_SIG, sizeof (RSDP_SIG) - 1) != 0) {
410 /* No signature match, keep looking */ 431 /* No signature match, keep looking */
411 432
412 continue; 433 continue;
@@ -450,7 +471,7 @@ acpi_tb_scan_memory_for_rsdp (
450 * 471 *
451 * FUNCTION: acpi_tb_find_rsdp 472 * FUNCTION: acpi_tb_find_rsdp
452 * 473 *
453 * PARAMETERS: *table_info - Where the table info is returned 474 * PARAMETERS: table_info - Where the table info is returned
454 * Flags - Current memory mode (logical vs. 475 * Flags - Current memory mode (logical vs.
455 * physical addressing) 476 * physical addressing)
456 * 477 *
@@ -468,7 +489,7 @@ acpi_tb_scan_memory_for_rsdp (
468 * 489 *
469 ******************************************************************************/ 490 ******************************************************************************/
470 491
471acpi_status 492static acpi_status
472acpi_tb_find_rsdp ( 493acpi_tb_find_rsdp (
473 struct acpi_table_desc *table_info, 494 struct acpi_table_desc *table_info,
474 u32 flags) 495 u32 flags)
@@ -483,43 +504,49 @@ acpi_tb_find_rsdp (
483 504
484 505
485 /* 506 /*
486 * Scan supports either 1) Logical addressing or 2) Physical addressing 507 * Scan supports either logical addressing or physical addressing
487 */ 508 */
488 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) { 509 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
489 /* 510 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
490 * 1a) Get the location of the EBDA 511
491 */ 512 status = acpi_os_map_memory (
492 status = acpi_os_map_memory ((acpi_physical_address) ACPI_EBDA_PTR_LOCATION, 513 (acpi_physical_address) ACPI_EBDA_PTR_LOCATION,
493 ACPI_EBDA_PTR_LENGTH, 514 ACPI_EBDA_PTR_LENGTH, (void *) &table_ptr);
494 (void *) &table_ptr);
495 if (ACPI_FAILURE (status)) { 515 if (ACPI_FAILURE (status)) {
496 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
497 "Could not map memory at %8.8X for length %X\n", 517 "Could not map memory at %8.8X for length %X\n",
498 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH)); 518 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
519
499 return_ACPI_STATUS (status); 520 return_ACPI_STATUS (status);
500 } 521 }
501 522
502 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr); 523 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr);
503 physical_address <<= 4; /* Convert segment to physical address */ 524
525 /* Convert segment part to physical address */
526
527 physical_address <<= 4;
504 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH); 528 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH);
505 529
506 /* EBDA present? */ 530 /* EBDA present? */
507 531
508 if (physical_address > 0x400) { 532 if (physical_address > 0x400) {
509 /* 533 /*
510 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length) 534 * 1b) Search EBDA paragraphs (EBDa is required to be a
535 * minimum of 1_k length)
511 */ 536 */
512 status = acpi_os_map_memory ((acpi_physical_address) physical_address, 537 status = acpi_os_map_memory (
513 ACPI_EBDA_WINDOW_SIZE, 538 (acpi_physical_address) physical_address,
514 (void *) &table_ptr); 539 ACPI_EBDA_WINDOW_SIZE, (void *) &table_ptr);
515 if (ACPI_FAILURE (status)) { 540 if (ACPI_FAILURE (status)) {
516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 541 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
517 "Could not map memory at %8.8X for length %X\n", 542 "Could not map memory at %8.8X for length %X\n",
518 physical_address, ACPI_EBDA_WINDOW_SIZE)); 543 physical_address, ACPI_EBDA_WINDOW_SIZE));
544
519 return_ACPI_STATUS (status); 545 return_ACPI_STATUS (status);
520 } 546 }
521 547
522 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr, ACPI_EBDA_WINDOW_SIZE); 548 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr,
549 ACPI_EBDA_WINDOW_SIZE);
523 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE); 550 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE);
524 551
525 if (mem_rover) { 552 if (mem_rover) {
@@ -527,7 +554,8 @@ acpi_tb_find_rsdp (
527 554
528 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr); 555 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr);
529 556
530 table_info->physical_address = (acpi_physical_address) physical_address; 557 table_info->physical_address =
558 (acpi_physical_address) physical_address;
531 return_ACPI_STATUS (AE_OK); 559 return_ACPI_STATUS (AE_OK);
532 } 560 }
533 } 561 }
@@ -535,13 +563,15 @@ acpi_tb_find_rsdp (
535 /* 563 /*
536 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh 564 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
537 */ 565 */
538 status = acpi_os_map_memory ((acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE, 566 status = acpi_os_map_memory (
539 ACPI_HI_RSDP_WINDOW_SIZE, 567 (acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE,
540 (void *) &table_ptr); 568 ACPI_HI_RSDP_WINDOW_SIZE, (void *) &table_ptr);
569
541 if (ACPI_FAILURE (status)) { 570 if (ACPI_FAILURE (status)) {
542 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 571 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
543 "Could not map memory at %8.8X for length %X\n", 572 "Could not map memory at %8.8X for length %X\n",
544 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE)); 573 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
574
545 return_ACPI_STATUS (status); 575 return_ACPI_STATUS (status);
546 } 576 }
547 577
@@ -551,9 +581,11 @@ acpi_tb_find_rsdp (
551 if (mem_rover) { 581 if (mem_rover) {
552 /* Found it, return the physical address */ 582 /* Found it, return the physical address */
553 583
554 physical_address = ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr); 584 physical_address =
585 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr);
555 586
556 table_info->physical_address = (acpi_physical_address) physical_address; 587 table_info->physical_address =
588 (acpi_physical_address) physical_address;
557 return_ACPI_STATUS (AE_OK); 589 return_ACPI_STATUS (AE_OK);
558 } 590 }
559 } 591 }
@@ -562,9 +594,8 @@ acpi_tb_find_rsdp (
562 * Physical addressing 594 * Physical addressing
563 */ 595 */
564 else { 596 else {
565 /* 597 /* 1a) Get the location of the EBDA */
566 * 1a) Get the location of the EBDA 598
567 */
568 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION); 599 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION);
569 physical_address <<= 4; /* Convert segment to physical address */ 600 physical_address <<= 4; /* Convert segment to physical address */
570 601
@@ -572,9 +603,11 @@ acpi_tb_find_rsdp (
572 603
573 if (physical_address > 0x400) { 604 if (physical_address > 0x400) {
574 /* 605 /*
575 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length) 606 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
607 * 1_k length)
576 */ 608 */
577 mem_rover = acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (physical_address), 609 mem_rover = acpi_tb_scan_memory_for_rsdp (
610 ACPI_PHYSADDR_TO_PTR (physical_address),
578 ACPI_EBDA_WINDOW_SIZE); 611 ACPI_EBDA_WINDOW_SIZE);
579 if (mem_rover) { 612 if (mem_rover) {
580 /* Found it, return the physical address */ 613 /* Found it, return the physical address */
@@ -584,10 +617,10 @@ acpi_tb_find_rsdp (
584 } 617 }
585 } 618 }
586 619
587 /* 620 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
588 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh 621
589 */ 622 mem_rover = acpi_tb_scan_memory_for_rsdp (
590 mem_rover = acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE), 623 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
591 ACPI_HI_RSDP_WINDOW_SIZE); 624 ACPI_HI_RSDP_WINDOW_SIZE);
592 if (mem_rover) { 625 if (mem_rover) {
593 /* Found it, return the physical address */ 626 /* Found it, return the physical address */
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index c84997c9f964..73b1d8aeae9d 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -263,6 +263,9 @@ dispatch_write(struct file* file, const char __user * buffer,
263 * destination so that sscanf can be used on it safely. 263 * destination so that sscanf can be used on it safely.
264 */ 264 */
265 tmp_buffer = kmalloc(count + 1, GFP_KERNEL); 265 tmp_buffer = kmalloc(count + 1, GFP_KERNEL);
266 if(!tmp_buffer)
267 return -ENOMEM;
268
266 if (copy_from_user(tmp_buffer, buffer, count)) { 269 if (copy_from_user(tmp_buffer, buffer, count)) {
267 result = -EFAULT; 270 result = -EFAULT;
268 } 271 }
@@ -529,6 +532,11 @@ toshiba_acpi_init(void)
529 532
530 if (acpi_disabled) 533 if (acpi_disabled)
531 return -ENODEV; 534 return -ENODEV;
535
536 if (!acpi_specific_hotkey_enabled){
537 printk(MY_INFO "Using generic hotkey driver\n");
538 return -ENODEV;
539 }
532 /* simple device detection: look for HCI method */ 540 /* simple device detection: look for HCI method */
533 if (is_valid_acpi_path(METHOD_HCI_1)) 541 if (is_valid_acpi_path(METHOD_HCI_1))
534 method_hci = METHOD_HCI_1; 542 method_hci = METHOD_HCI_1;
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 3313439c4bc7..c4e7f989a2bd 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -47,8 +47,35 @@
47#define _COMPONENT ACPI_UTILITIES 47#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utalloc") 48 ACPI_MODULE_NAME ("utalloc")
49 49
50/* Local prototypes */
50 51
51/****************************************************************************** 52#ifdef ACPI_DBG_TRACK_ALLOCATIONS
53static struct acpi_debug_mem_block *
54acpi_ut_find_allocation (
55 u32 list_id,
56 void *allocation);
57
58static acpi_status
59acpi_ut_track_allocation (
60 u32 list_id,
61 struct acpi_debug_mem_block *address,
62 acpi_size size,
63 u8 alloc_type,
64 u32 component,
65 char *module,
66 u32 line);
67
68static acpi_status
69acpi_ut_remove_allocation (
70 u32 list_id,
71 struct acpi_debug_mem_block *address,
72 u32 component,
73 char *module,
74 u32 line);
75#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
76
77
78/*******************************************************************************
52 * 79 *
53 * FUNCTION: acpi_ut_release_to_cache 80 * FUNCTION: acpi_ut_release_to_cache
54 * 81 *
@@ -98,7 +125,8 @@ acpi_ut_release_to_cache (
98 125
99 /* Put the object at the head of the cache list */ 126 /* Put the object at the head of the cache list */
100 127
101 * (ACPI_CAST_INDIRECT_PTR (char, &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head; 128 * (ACPI_CAST_INDIRECT_PTR (char,
129 &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head;
102 cache_info->list_head = object; 130 cache_info->list_head = object;
103 cache_info->cache_depth++; 131 cache_info->cache_depth++;
104 132
@@ -115,7 +143,7 @@ acpi_ut_release_to_cache (
115} 143}
116 144
117 145
118/****************************************************************************** 146/*******************************************************************************
119 * 147 *
120 * FUNCTION: acpi_ut_acquire_from_cache 148 * FUNCTION: acpi_ut_acquire_from_cache
121 * 149 *
@@ -156,7 +184,8 @@ acpi_ut_acquire_from_cache (
156 /* There is an object available, use it */ 184 /* There is an object available, use it */
157 185
158 object = cache_info->list_head; 186 object = cache_info->list_head;
159 cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) object)[cache_info->link_offset]))); 187 cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char,
188 &(((char *) object)[cache_info->link_offset])));
160 189
161 ACPI_MEM_TRACKING (cache_info->cache_hits++); 190 ACPI_MEM_TRACKING (cache_info->cache_hits++);
162 cache_info->cache_depth--; 191 cache_info->cache_depth--;
@@ -201,7 +230,7 @@ acpi_ut_acquire_from_cache (
201 230
202 231
203#ifdef ACPI_ENABLE_OBJECT_CACHE 232#ifdef ACPI_ENABLE_OBJECT_CACHE
204/****************************************************************************** 233/*******************************************************************************
205 * 234 *
206 * FUNCTION: acpi_ut_delete_generic_cache 235 * FUNCTION: acpi_ut_delete_generic_cache
207 * 236 *
@@ -228,7 +257,8 @@ acpi_ut_delete_generic_cache (
228 while (cache_info->list_head) { 257 while (cache_info->list_head) {
229 /* Delete one cached state object */ 258 /* Delete one cached state object */
230 259
231 next = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) cache_info->list_head)[cache_info->link_offset]))); 260 next = *(ACPI_CAST_INDIRECT_PTR (char,
261 &(((char *) cache_info->list_head)[cache_info->link_offset])));
232 ACPI_MEM_FREE (cache_info->list_head); 262 ACPI_MEM_FREE (cache_info->list_head);
233 263
234 cache_info->list_head = next; 264 cache_info->list_head = next;
@@ -497,8 +527,8 @@ acpi_ut_allocate_and_track (
497 acpi_status status; 527 acpi_status status;
498 528
499 529
500 allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header), component, 530 allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header),
501 module, line); 531 component, module, line);
502 if (!allocation) { 532 if (!allocation) {
503 return (NULL); 533 return (NULL);
504 } 534 }
@@ -543,8 +573,8 @@ acpi_ut_callocate_and_track (
543 acpi_status status; 573 acpi_status status;
544 574
545 575
546 allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header), component, 576 allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header),
547 module, line); 577 component, module, line);
548 if (!allocation) { 578 if (!allocation) {
549 /* Report allocation error */ 579 /* Report allocation error */
550 580
@@ -637,7 +667,7 @@ acpi_ut_free_and_track (
637 * 667 *
638 ******************************************************************************/ 668 ******************************************************************************/
639 669
640struct acpi_debug_mem_block * 670static struct acpi_debug_mem_block *
641acpi_ut_find_allocation ( 671acpi_ut_find_allocation (
642 u32 list_id, 672 u32 list_id,
643 void *allocation) 673 void *allocation)
@@ -686,7 +716,7 @@ acpi_ut_find_allocation (
686 * 716 *
687 ******************************************************************************/ 717 ******************************************************************************/
688 718
689acpi_status 719static acpi_status
690acpi_ut_track_allocation ( 720acpi_ut_track_allocation (
691 u32 list_id, 721 u32 list_id,
692 struct acpi_debug_mem_block *allocation, 722 struct acpi_debug_mem_block *allocation,
@@ -721,10 +751,12 @@ acpi_ut_track_allocation (
721 751
722 element = acpi_ut_find_allocation (list_id, allocation); 752 element = acpi_ut_find_allocation (list_id, allocation);
723 if (element) { 753 if (element) {
724 ACPI_REPORT_ERROR (("ut_track_allocation: Allocation already present in list! (%p)\n", 754 ACPI_REPORT_ERROR ((
755 "ut_track_allocation: Allocation already present in list! (%p)\n",
725 allocation)); 756 allocation));
726 757
727 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", element, allocation)); 758 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n",
759 element, allocation));
728 760
729 goto unlock_and_exit; 761 goto unlock_and_exit;
730 } 762 }
@@ -773,7 +805,7 @@ unlock_and_exit:
773 * 805 *
774 ******************************************************************************/ 806 ******************************************************************************/
775 807
776acpi_status 808static acpi_status
777acpi_ut_remove_allocation ( 809acpi_ut_remove_allocation (
778 u32 list_id, 810 u32 list_id,
779 struct acpi_debug_mem_block *allocation, 811 struct acpi_debug_mem_block *allocation,
@@ -797,7 +829,7 @@ acpi_ut_remove_allocation (
797 /* No allocations! */ 829 /* No allocations! */
798 830
799 _ACPI_REPORT_ERROR (module, line, component, 831 _ACPI_REPORT_ERROR (module, line, component,
800 ("ut_remove_allocation: Empty allocation list, nothing to free!\n")); 832 ("ut_remove_allocation: Empty allocation list, nothing to free!\n"));
801 833
802 return_ACPI_STATUS (AE_OK); 834 return_ACPI_STATUS (AE_OK);
803 } 835 }
@@ -824,7 +856,8 @@ acpi_ut_remove_allocation (
824 856
825 ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size); 857 ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size);
826 858
827 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n", allocation->size)); 859 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
860 allocation->size));
828 861
829 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY); 862 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY);
830 return_ACPI_STATUS (status); 863 return_ACPI_STATUS (status);
@@ -842,6 +875,7 @@ acpi_ut_remove_allocation (
842 * DESCRIPTION: Print some info about the outstanding allocations. 875 * DESCRIPTION: Print some info about the outstanding allocations.
843 * 876 *
844 ******************************************************************************/ 877 ******************************************************************************/
878
845#ifdef ACPI_FUTURE_USAGE 879#ifdef ACPI_FUTURE_USAGE
846void 880void
847acpi_ut_dump_allocation_info ( 881acpi_ut_dump_allocation_info (
@@ -884,7 +918,8 @@ acpi_ut_dump_allocation_info (
884 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 918 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
885 ("%30s: %4d (%3d Kb)\n", "Max Nodes", 919 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
886 acpi_gbl_max_concurrent_node_count, 920 acpi_gbl_max_concurrent_node_count,
887 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count * sizeof (struct acpi_namespace_node))))); 921 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count *
922 sizeof (struct acpi_namespace_node)))));
888*/ 923*/
889 return_VOID; 924 return_VOID;
890} 925}
@@ -933,26 +968,26 @@ acpi_ut_dump_allocations (
933 descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space); 968 descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space);
934 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) { 969 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
935 acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ", 970 acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ",
936 descriptor, element->size, element->module, 971 descriptor, element->size, element->module,
937 element->line, acpi_ut_get_descriptor_name (descriptor)); 972 element->line, acpi_ut_get_descriptor_name (descriptor));
938 973
939 /* Most of the elements will be Operand objects. */ 974 /* Most of the elements will be Operand objects. */
940 975
941 switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) { 976 switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) {
942 case ACPI_DESC_TYPE_OPERAND: 977 case ACPI_DESC_TYPE_OPERAND:
943 acpi_os_printf ("%12.12s R%hd", 978 acpi_os_printf ("%12.12s R%hd",
944 acpi_ut_get_type_name (descriptor->object.common.type), 979 acpi_ut_get_type_name (descriptor->object.common.type),
945 descriptor->object.common.reference_count); 980 descriptor->object.common.reference_count);
946 break; 981 break;
947 982
948 case ACPI_DESC_TYPE_PARSER: 983 case ACPI_DESC_TYPE_PARSER:
949 acpi_os_printf ("aml_opcode %04hX", 984 acpi_os_printf ("aml_opcode %04hX",
950 descriptor->op.asl.aml_opcode); 985 descriptor->op.asl.aml_opcode);
951 break; 986 break;
952 987
953 case ACPI_DESC_TYPE_NAMED: 988 case ACPI_DESC_TYPE_NAMED:
954 acpi_os_printf ("%4.4s", 989 acpi_os_printf ("%4.4s",
955 acpi_ut_get_node_name (&descriptor->node)); 990 acpi_ut_get_node_name (&descriptor->node));
956 break; 991 break;
957 992
958 default: 993 default:
@@ -983,6 +1018,5 @@ acpi_ut_dump_allocations (
983 return_VOID; 1018 return_VOID;
984} 1019}
985 1020
986
987#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 1021#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */
988 1022
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 0fcd98bde0d1..11e884957162 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -49,21 +49,69 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utcopy") 50 ACPI_MODULE_NAME ("utcopy")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ut_copy_isimple_to_esimple (
56 union acpi_operand_object *internal_object,
57 union acpi_object *external_object,
58 u8 *data_space,
59 acpi_size *buffer_space_used);
60
61static acpi_status
62acpi_ut_copy_ielement_to_ielement (
63 u8 object_type,
64 union acpi_operand_object *source_object,
65 union acpi_generic_state *state,
66 void *context);
67
68static acpi_status
69acpi_ut_copy_ipackage_to_epackage (
70 union acpi_operand_object *internal_object,
71 u8 *buffer,
72 acpi_size *space_used);
73
74static acpi_status
75acpi_ut_copy_esimple_to_isimple(
76 union acpi_object *user_obj,
77 union acpi_operand_object **return_obj);
78
79static acpi_status
80acpi_ut_copy_simple_object (
81 union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc);
83
84static acpi_status
85acpi_ut_copy_ielement_to_eelement (
86 u8 object_type,
87 union acpi_operand_object *source_object,
88 union acpi_generic_state *state,
89 void *context);
90
91static acpi_status
92acpi_ut_copy_ipackage_to_ipackage (
93 union acpi_operand_object *source_obj,
94 union acpi_operand_object *dest_obj,
95 struct acpi_walk_state *walk_state);
96
52 97
53/******************************************************************************* 98/*******************************************************************************
54 * 99 *
55 * FUNCTION: acpi_ut_copy_isimple_to_esimple 100 * FUNCTION: acpi_ut_copy_isimple_to_esimple
56 * 101 *
57 * PARAMETERS: *internal_object - Pointer to the object we are examining 102 * PARAMETERS: internal_object - Source object to be copied
58 * *Buffer - Where the object is returned 103 * external_object - Where to return the copied object
59 * *space_used - Where the data length is returned 104 * data_space - Where object data is returned (such as
105 * buffer and string data)
106 * buffer_space_used - Length of data_space that was used
60 * 107 *
61 * RETURN: Status 108 * RETURN: Status
62 * 109 *
63 * DESCRIPTION: This function is called to place a simple object in a user 110 * DESCRIPTION: This function is called to copy a simple internal object to
64 * buffer. 111 * an external object.
65 * 112 *
66 * The buffer is assumed to have sufficient space for the object. 113 * The data_space buffer is assumed to have sufficient space for
114 * the object.
67 * 115 *
68 ******************************************************************************/ 116 ******************************************************************************/
69 117
@@ -107,10 +155,12 @@ acpi_ut_copy_isimple_to_esimple (
107 155
108 external_object->string.pointer = (char *) data_space; 156 external_object->string.pointer = (char *) data_space;
109 external_object->string.length = internal_object->string.length; 157 external_object->string.length = internal_object->string.length;
110 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((acpi_size) internal_object->string.length + 1); 158 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
159 (acpi_size) internal_object->string.length + 1);
111 160
112 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->string.pointer, 161 ACPI_MEMCPY ((void *) data_space,
113 (acpi_size) internal_object->string.length + 1); 162 (void *) internal_object->string.pointer,
163 (acpi_size) internal_object->string.length + 1);
114 break; 164 break;
115 165
116 166
@@ -118,10 +168,12 @@ acpi_ut_copy_isimple_to_esimple (
118 168
119 external_object->buffer.pointer = data_space; 169 external_object->buffer.pointer = data_space;
120 external_object->buffer.length = internal_object->buffer.length; 170 external_object->buffer.length = internal_object->buffer.length;
121 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (internal_object->string.length); 171 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
172 internal_object->string.length);
122 173
123 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->buffer.pointer, 174 ACPI_MEMCPY ((void *) data_space,
124 internal_object->buffer.length); 175 (void *) internal_object->buffer.pointer,
176 internal_object->buffer.length);
125 break; 177 break;
126 178
127 179
@@ -194,7 +246,7 @@ acpi_ut_copy_isimple_to_esimple (
194 * 246 *
195 ******************************************************************************/ 247 ******************************************************************************/
196 248
197acpi_status 249static acpi_status
198acpi_ut_copy_ielement_to_eelement ( 250acpi_ut_copy_ielement_to_eelement (
199 u8 object_type, 251 u8 object_type,
200 union acpi_operand_object *source_object, 252 union acpi_operand_object *source_object,
@@ -213,7 +265,7 @@ acpi_ut_copy_ielement_to_eelement (
213 265
214 this_index = state->pkg.index; 266 this_index = state->pkg.index;
215 target_object = (union acpi_object *) 267 target_object = (union acpi_object *)
216 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index]; 268 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
217 269
218 switch (object_type) { 270 switch (object_type) {
219 case ACPI_COPY_TYPE_SIMPLE: 271 case ACPI_COPY_TYPE_SIMPLE:
@@ -236,7 +288,8 @@ acpi_ut_copy_ielement_to_eelement (
236 */ 288 */
237 target_object->type = ACPI_TYPE_PACKAGE; 289 target_object->type = ACPI_TYPE_PACKAGE;
238 target_object->package.count = source_object->package.count; 290 target_object->package.count = source_object->package.count;
239 target_object->package.elements = ACPI_CAST_PTR (union acpi_object, info->free_space); 291 target_object->package.elements =
292 ACPI_CAST_PTR (union acpi_object, info->free_space);
240 293
241 /* 294 /*
242 * Pass the new package object back to the package walk routine 295 * Pass the new package object back to the package walk routine
@@ -248,7 +301,8 @@ acpi_ut_copy_ielement_to_eelement (
248 * update the buffer length counter 301 * update the buffer length counter
249 */ 302 */
250 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD ( 303 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
251 (acpi_size) target_object->package.count * sizeof (union acpi_object)); 304 (acpi_size) target_object->package.count *
305 sizeof (union acpi_object));
252 break; 306 break;
253 307
254 308
@@ -266,9 +320,9 @@ acpi_ut_copy_ielement_to_eelement (
266 * 320 *
267 * FUNCTION: acpi_ut_copy_ipackage_to_epackage 321 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
268 * 322 *
269 * PARAMETERS: *internal_object - Pointer to the object we are returning 323 * PARAMETERS: internal_object - Pointer to the object we are returning
270 * *Buffer - Where the object is returned 324 * Buffer - Where the object is returned
271 * *space_used - Where the object length is returned 325 * space_used - Where the object length is returned
272 * 326 *
273 * RETURN: Status 327 * RETURN: Status
274 * 328 *
@@ -304,13 +358,15 @@ acpi_ut_copy_ipackage_to_epackage (
304 * Free space begins right after the first package 358 * Free space begins right after the first package
305 */ 359 */
306 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object)); 360 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
307 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object)); 361 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
362 sizeof (union acpi_object));
308 info.object_space = 0; 363 info.object_space = 0;
309 info.num_packages = 1; 364 info.num_packages = 1;
310 365
311 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object); 366 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
312 external_object->package.count = internal_object->package.count; 367 external_object->package.count = internal_object->package.count;
313 external_object->package.elements = ACPI_CAST_PTR (union acpi_object, info.free_space); 368 external_object->package.elements = ACPI_CAST_PTR (union acpi_object,
369 info.free_space);
314 370
315 /* 371 /*
316 * Leave room for an array of ACPI_OBJECTS in the buffer 372 * Leave room for an array of ACPI_OBJECTS in the buffer
@@ -333,8 +389,8 @@ acpi_ut_copy_ipackage_to_epackage (
333 * 389 *
334 * FUNCTION: acpi_ut_copy_iobject_to_eobject 390 * FUNCTION: acpi_ut_copy_iobject_to_eobject
335 * 391 *
336 * PARAMETERS: *internal_object - The internal object to be converted 392 * PARAMETERS: internal_object - The internal object to be converted
337 * *buffer_ptr - Where the object is returned 393 * buffer_ptr - Where the object is returned
338 * 394 *
339 * RETURN: Status 395 * RETURN: Status
340 * 396 *
@@ -367,10 +423,10 @@ acpi_ut_copy_iobject_to_eobject (
367 * Build a simple object (no nested objects) 423 * Build a simple object (no nested objects)
368 */ 424 */
369 status = acpi_ut_copy_isimple_to_esimple (internal_object, 425 status = acpi_ut_copy_isimple_to_esimple (internal_object,
370 (union acpi_object *) ret_buffer->pointer, 426 (union acpi_object *) ret_buffer->pointer,
371 ((u8 *) ret_buffer->pointer + 427 ((u8 *) ret_buffer->pointer +
372 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))), 428 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))),
373 &ret_buffer->length); 429 &ret_buffer->length);
374 /* 430 /*
375 * build simple does not include the object size in the length 431 * build simple does not include the object size in the length
376 * so we add it in here 432 * so we add it in here
@@ -386,8 +442,8 @@ acpi_ut_copy_iobject_to_eobject (
386 * 442 *
387 * FUNCTION: acpi_ut_copy_esimple_to_isimple 443 * FUNCTION: acpi_ut_copy_esimple_to_isimple
388 * 444 *
389 * PARAMETERS: *external_object - The external object to be converted 445 * PARAMETERS: external_object - The external object to be converted
390 * *internal_object - Where the internal object is returned 446 * ret_internal_object - Where the internal object is returned
391 * 447 *
392 * RETURN: Status 448 * RETURN: Status
393 * 449 *
@@ -398,7 +454,7 @@ acpi_ut_copy_iobject_to_eobject (
398 * 454 *
399 ******************************************************************************/ 455 ******************************************************************************/
400 456
401acpi_status 457static acpi_status
402acpi_ut_copy_esimple_to_isimple ( 458acpi_ut_copy_esimple_to_isimple (
403 union acpi_object *external_object, 459 union acpi_object *external_object,
404 union acpi_operand_object **ret_internal_object) 460 union acpi_operand_object **ret_internal_object)
@@ -417,7 +473,8 @@ acpi_ut_copy_esimple_to_isimple (
417 case ACPI_TYPE_BUFFER: 473 case ACPI_TYPE_BUFFER:
418 case ACPI_TYPE_INTEGER: 474 case ACPI_TYPE_INTEGER:
419 475
420 internal_object = acpi_ut_create_internal_object ((u8) external_object->type); 476 internal_object = acpi_ut_create_internal_object (
477 (u8) external_object->type);
421 if (!internal_object) { 478 if (!internal_object) {
422 return_ACPI_STATUS (AE_NO_MEMORY); 479 return_ACPI_STATUS (AE_NO_MEMORY);
423 } 480 }
@@ -486,7 +543,6 @@ error_exit:
486 543
487 544
488#ifdef ACPI_FUTURE_IMPLEMENTATION 545#ifdef ACPI_FUTURE_IMPLEMENTATION
489
490/* Code to convert packages that are parameters to control methods */ 546/* Code to convert packages that are parameters to control methods */
491 547
492/******************************************************************************* 548/*******************************************************************************
@@ -614,7 +670,7 @@ acpi_ut_copy_eobject_to_iobject (
614 * 670 *
615 ******************************************************************************/ 671 ******************************************************************************/
616 672
617acpi_status 673static acpi_status
618acpi_ut_copy_simple_object ( 674acpi_ut_copy_simple_object (
619 union acpi_operand_object *source_desc, 675 union acpi_operand_object *source_desc,
620 union acpi_operand_object *dest_desc) 676 union acpi_operand_object *dest_desc)
@@ -724,7 +780,7 @@ acpi_ut_copy_simple_object (
724 * 780 *
725 ******************************************************************************/ 781 ******************************************************************************/
726 782
727acpi_status 783static acpi_status
728acpi_ut_copy_ielement_to_ielement ( 784acpi_ut_copy_ielement_to_ielement (
729 u8 object_type, 785 u8 object_type,
730 union acpi_operand_object *source_object, 786 union acpi_operand_object *source_object,
@@ -837,7 +893,7 @@ error_exit:
837 * 893 *
838 ******************************************************************************/ 894 ******************************************************************************/
839 895
840acpi_status 896static acpi_status
841acpi_ut_copy_ipackage_to_ipackage ( 897acpi_ut_copy_ipackage_to_ipackage (
842 union acpi_operand_object *source_obj, 898 union acpi_operand_object *source_obj,
843 union acpi_operand_object *dest_obj, 899 union acpi_operand_object *dest_obj,
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 985c5d045b78..794c7df3f2ad 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -56,7 +56,7 @@ static char *acpi_gbl_fn_entry_str = "----Entry";
56static char *acpi_gbl_fn_exit_str = "----Exit-"; 56static char *acpi_gbl_fn_exit_str = "----Exit-";
57 57
58 58
59/***************************************************************************** 59/*******************************************************************************
60 * 60 *
61 * FUNCTION: acpi_ut_init_stack_ptr_trace 61 * FUNCTION: acpi_ut_init_stack_ptr_trace
62 * 62 *
@@ -64,9 +64,9 @@ static char *acpi_gbl_fn_exit_str = "----Exit-";
64 * 64 *
65 * RETURN: None 65 * RETURN: None
66 * 66 *
67 * DESCRIPTION: Save the current stack pointer 67 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
68 * 68 *
69 ****************************************************************************/ 69 ******************************************************************************/
70 70
71void 71void
72acpi_ut_init_stack_ptr_trace ( 72acpi_ut_init_stack_ptr_trace (
@@ -79,7 +79,7 @@ acpi_ut_init_stack_ptr_trace (
79} 79}
80 80
81 81
82/***************************************************************************** 82/*******************************************************************************
83 * 83 *
84 * FUNCTION: acpi_ut_track_stack_ptr 84 * FUNCTION: acpi_ut_track_stack_ptr
85 * 85 *
@@ -87,9 +87,9 @@ acpi_ut_init_stack_ptr_trace (
87 * 87 *
88 * RETURN: None 88 * RETURN: None
89 * 89 *
90 * DESCRIPTION: Save the current stack pointer 90 * DESCRIPTION: Save the current CPU stack pointer
91 * 91 *
92 ****************************************************************************/ 92 ******************************************************************************/
93 93
94void 94void
95acpi_ut_track_stack_ptr ( 95acpi_ut_track_stack_ptr (
@@ -110,16 +110,16 @@ acpi_ut_track_stack_ptr (
110} 110}
111 111
112 112
113/***************************************************************************** 113/*******************************************************************************
114 * 114 *
115 * FUNCTION: acpi_ut_debug_print 115 * FUNCTION: acpi_ut_debug_print
116 * 116 *
117 * PARAMETERS: debug_level - Requested debug print level 117 * PARAMETERS: requested_debug_level - Requested debug print level
118 * proc_name - Caller's procedure name
119 * module_name - Caller's module name (for error output)
120 * line_number - Caller's line number (for error output) 118 * line_number - Caller's line number (for error output)
121 * component_id - Caller's component ID (for error output) 119 * dbg_info - Contains:
122 * 120 * proc_name - Caller's procedure name
121 * module_name - Caller's module name
122 * component_id - Caller's component ID
123 * Format - Printf format field 123 * Format - Printf format field
124 * ... - Optional printf arguments 124 * ... - Optional printf arguments
125 * 125 *
@@ -128,7 +128,7 @@ acpi_ut_track_stack_ptr (
128 * DESCRIPTION: Print error message with prefix consisting of the module name, 128 * DESCRIPTION: Print error message with prefix consisting of the module name,
129 * line number, and component ID. 129 * line number, and component ID.
130 * 130 *
131 ****************************************************************************/ 131 ******************************************************************************/
132 132
133void ACPI_INTERNAL_VAR_XFACE 133void ACPI_INTERNAL_VAR_XFACE
134acpi_ut_debug_print ( 134acpi_ut_debug_print (
@@ -157,7 +157,8 @@ acpi_ut_debug_print (
157 157
158 if (thread_id != acpi_gbl_prev_thread_id) { 158 if (thread_id != acpi_gbl_prev_thread_id) {
159 if (ACPI_LV_THREADS & acpi_dbg_level) { 159 if (ACPI_LV_THREADS & acpi_dbg_level) {
160 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 160 acpi_os_printf (
161 "\n**** Context Switch from TID %X to TID %X ****\n\n",
161 acpi_gbl_prev_thread_id, thread_id); 162 acpi_gbl_prev_thread_id, thread_id);
162 } 163 }
163 164
@@ -174,15 +175,16 @@ acpi_ut_debug_print (
174 acpi_os_printf ("[%04lX] ", thread_id); 175 acpi_os_printf ("[%04lX] ", thread_id);
175 } 176 }
176 177
177 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name); 178 acpi_os_printf ("[%02ld] %-22.22s: ",
179 acpi_gbl_nesting_level, dbg_info->proc_name);
178 180
179 va_start (args, format); 181 va_start (args, format);
180 acpi_os_vprintf (format, args); 182 acpi_os_vprintf (format, args);
181} 183}
182EXPORT_SYMBOL(acpi_ut_debug_print);
183 184
185EXPORT_SYMBOL(acpi_ut_debug_print);
184 186
185/***************************************************************************** 187/*******************************************************************************
186 * 188 *
187 * FUNCTION: acpi_ut_debug_print_raw 189 * FUNCTION: acpi_ut_debug_print_raw
188 * 190 *
@@ -200,7 +202,7 @@ EXPORT_SYMBOL(acpi_ut_debug_print);
200 * DESCRIPTION: Print message with no headers. Has same interface as 202 * DESCRIPTION: Print message with no headers. Has same interface as
201 * debug_print so that the same macros can be used. 203 * debug_print so that the same macros can be used.
202 * 204 *
203 ****************************************************************************/ 205 ******************************************************************************/
204 206
205void ACPI_INTERNAL_VAR_XFACE 207void ACPI_INTERNAL_VAR_XFACE
206acpi_ut_debug_print_raw ( 208acpi_ut_debug_print_raw (
@@ -224,7 +226,7 @@ acpi_ut_debug_print_raw (
224EXPORT_SYMBOL(acpi_ut_debug_print_raw); 226EXPORT_SYMBOL(acpi_ut_debug_print_raw);
225 227
226 228
227/***************************************************************************** 229/*******************************************************************************
228 * 230 *
229 * FUNCTION: acpi_ut_trace 231 * FUNCTION: acpi_ut_trace
230 * 232 *
@@ -239,7 +241,7 @@ EXPORT_SYMBOL(acpi_ut_debug_print_raw);
239 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 241 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
240 * set in debug_level 242 * set in debug_level
241 * 243 *
242 ****************************************************************************/ 244 ******************************************************************************/
243 245
244void 246void
245acpi_ut_trace ( 247acpi_ut_trace (
@@ -256,7 +258,7 @@ acpi_ut_trace (
256EXPORT_SYMBOL(acpi_ut_trace); 258EXPORT_SYMBOL(acpi_ut_trace);
257 259
258 260
259/***************************************************************************** 261/*******************************************************************************
260 * 262 *
261 * FUNCTION: acpi_ut_trace_ptr 263 * FUNCTION: acpi_ut_trace_ptr
262 * 264 *
@@ -272,7 +274,7 @@ EXPORT_SYMBOL(acpi_ut_trace);
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 274 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
273 * set in debug_level 275 * set in debug_level
274 * 276 *
275 ****************************************************************************/ 277 ******************************************************************************/
276 278
277void 279void
278acpi_ut_trace_ptr ( 280acpi_ut_trace_ptr (
@@ -288,7 +290,7 @@ acpi_ut_trace_ptr (
288} 290}
289 291
290 292
291/***************************************************************************** 293/*******************************************************************************
292 * 294 *
293 * FUNCTION: acpi_ut_trace_str 295 * FUNCTION: acpi_ut_trace_str
294 * 296 *
@@ -304,7 +306,7 @@ acpi_ut_trace_ptr (
304 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
305 * set in debug_level 307 * set in debug_level
306 * 308 *
307 ****************************************************************************/ 309 ******************************************************************************/
308 310
309void 311void
310acpi_ut_trace_str ( 312acpi_ut_trace_str (
@@ -321,7 +323,7 @@ acpi_ut_trace_str (
321} 323}
322 324
323 325
324/***************************************************************************** 326/*******************************************************************************
325 * 327 *
326 * FUNCTION: acpi_ut_trace_u32 328 * FUNCTION: acpi_ut_trace_u32
327 * 329 *
@@ -337,7 +339,7 @@ acpi_ut_trace_str (
337 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 339 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
338 * set in debug_level 340 * set in debug_level
339 * 341 *
340 ****************************************************************************/ 342 ******************************************************************************/
341 343
342void 344void
343acpi_ut_trace_u32 ( 345acpi_ut_trace_u32 (
@@ -354,7 +356,7 @@ acpi_ut_trace_u32 (
354} 356}
355 357
356 358
357/***************************************************************************** 359/*******************************************************************************
358 * 360 *
359 * FUNCTION: acpi_ut_exit 361 * FUNCTION: acpi_ut_exit
360 * 362 *
@@ -369,7 +371,7 @@ acpi_ut_trace_u32 (
369 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 371 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
370 * set in debug_level 372 * set in debug_level
371 * 373 *
372 ****************************************************************************/ 374 ******************************************************************************/
373 375
374void 376void
375acpi_ut_exit ( 377acpi_ut_exit (
@@ -385,7 +387,7 @@ acpi_ut_exit (
385EXPORT_SYMBOL(acpi_ut_exit); 387EXPORT_SYMBOL(acpi_ut_exit);
386 388
387 389
388/***************************************************************************** 390/*******************************************************************************
389 * 391 *
390 * FUNCTION: acpi_ut_status_exit 392 * FUNCTION: acpi_ut_status_exit
391 * 393 *
@@ -401,7 +403,7 @@ EXPORT_SYMBOL(acpi_ut_exit);
401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 403 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
402 * set in debug_level. Prints exit status also. 404 * set in debug_level. Prints exit status also.
403 * 405 *
404 ****************************************************************************/ 406 ******************************************************************************/
405 407
406void 408void
407acpi_ut_status_exit ( 409acpi_ut_status_exit (
@@ -426,7 +428,7 @@ acpi_ut_status_exit (
426EXPORT_SYMBOL(acpi_ut_status_exit); 428EXPORT_SYMBOL(acpi_ut_status_exit);
427 429
428 430
429/***************************************************************************** 431/*******************************************************************************
430 * 432 *
431 * FUNCTION: acpi_ut_value_exit 433 * FUNCTION: acpi_ut_value_exit
432 * 434 *
@@ -442,7 +444,7 @@ EXPORT_SYMBOL(acpi_ut_status_exit);
442 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 444 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
443 * set in debug_level. Prints exit value also. 445 * set in debug_level. Prints exit value also.
444 * 446 *
445 ****************************************************************************/ 447 ******************************************************************************/
446 448
447void 449void
448acpi_ut_value_exit ( 450acpi_ut_value_exit (
@@ -460,7 +462,7 @@ acpi_ut_value_exit (
460EXPORT_SYMBOL(acpi_ut_value_exit); 462EXPORT_SYMBOL(acpi_ut_value_exit);
461 463
462 464
463/***************************************************************************** 465/*******************************************************************************
464 * 466 *
465 * FUNCTION: acpi_ut_ptr_exit 467 * FUNCTION: acpi_ut_ptr_exit
466 * 468 *
@@ -469,14 +471,14 @@ EXPORT_SYMBOL(acpi_ut_value_exit);
469 * proc_name - Caller's procedure name 471 * proc_name - Caller's procedure name
470 * module_name - Caller's module name 472 * module_name - Caller's module name
471 * component_id - Caller's component ID 473 * component_id - Caller's component ID
472 * Value - Value to be printed with exit msg 474 * Ptr - Pointer to display
473 * 475 *
474 * RETURN: None 476 * RETURN: None
475 * 477 *
476 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 478 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
477 * set in debug_level. Prints exit value also. 479 * set in debug_level. Prints exit value also.
478 * 480 *
479 ****************************************************************************/ 481 ******************************************************************************/
480 482
481void 483void
482acpi_ut_ptr_exit ( 484acpi_ut_ptr_exit (
@@ -494,7 +496,7 @@ acpi_ut_ptr_exit (
494#endif 496#endif
495 497
496 498
497/***************************************************************************** 499/*******************************************************************************
498 * 500 *
499 * FUNCTION: acpi_ut_dump_buffer 501 * FUNCTION: acpi_ut_dump_buffer
500 * 502 *
@@ -507,7 +509,7 @@ acpi_ut_ptr_exit (
507 * 509 *
508 * DESCRIPTION: Generic dump buffer in both hex and ascii. 510 * DESCRIPTION: Generic dump buffer in both hex and ascii.
509 * 511 *
510 ****************************************************************************/ 512 ******************************************************************************/
511 513
512void 514void
513acpi_ut_dump_buffer ( 515acpi_ut_dump_buffer (
@@ -533,34 +535,28 @@ acpi_ut_dump_buffer (
533 display = DB_BYTE_DISPLAY; 535 display = DB_BYTE_DISPLAY;
534 } 536 }
535 537
536 acpi_os_printf ("\nOffset Value\n"); 538 /* Nasty little dump buffer routine! */
537 539
538 /*
539 * Nasty little dump buffer routine!
540 */
541 while (i < count) { 540 while (i < count) {
542 /* Print current offset */ 541 /* Print current offset */
543 542
544 acpi_os_printf ("%05X ", (u32) i); 543 acpi_os_printf ("%6.4X: ", (u32) i);
545 544
546 /* Print 16 hex chars */ 545 /* Print 16 hex chars */
547 546
548 for (j = 0; j < 16;) { 547 for (j = 0; j < 16;) {
549 if (i + j >= count) { 548 if (i + j >= count) {
550 acpi_os_printf ("\n"); 549 /* Dump fill spaces */
551 return;
552 }
553 550
554 /* Make sure that the s8 doesn't get sign-extended! */ 551 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
552 j += display;
553 continue;
554 }
555 555
556 switch (display) { 556 switch (display) {
557 /* Default is BYTE display */ 557 default: /* Default is BYTE display */
558 558
559 default: 559 acpi_os_printf ("%02X ", buffer[i + j]);
560
561 acpi_os_printf ("%02X ",
562 *((u8 *) &buffer[i + j]));
563 j += 1;
564 break; 560 break;
565 561
566 562
@@ -568,7 +564,6 @@ acpi_ut_dump_buffer (
568 564
569 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]); 565 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
570 acpi_os_printf ("%04X ", temp32); 566 acpi_os_printf ("%04X ", temp32);
571 j += 2;
572 break; 567 break;
573 568
574 569
@@ -576,7 +571,6 @@ acpi_ut_dump_buffer (
576 571
577 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]); 572 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
578 acpi_os_printf ("%08X ", temp32); 573 acpi_os_printf ("%08X ", temp32);
579 j += 4;
580 break; 574 break;
581 575
582 576
@@ -587,15 +581,17 @@ acpi_ut_dump_buffer (
587 581
588 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]); 582 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
589 acpi_os_printf ("%08X ", temp32); 583 acpi_os_printf ("%08X ", temp32);
590 j += 8;
591 break; 584 break;
592 } 585 }
586
587 j += display;
593 } 588 }
594 589
595 /* 590 /*
596 * Print the ASCII equivalent characters 591 * Print the ASCII equivalent characters
597 * But watch out for the bad unprintable ones... 592 * But watch out for the bad unprintable ones...
598 */ 593 */
594 acpi_os_printf (" ");
599 for (j = 0; j < 16; j++) { 595 for (j = 0; j < 16; j++) {
600 if (i + j >= count) { 596 if (i + j >= count) {
601 acpi_os_printf ("\n"); 597 acpi_os_printf ("\n");
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 9a52ad52a23a..bc5403022681 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -51,12 +51,23 @@
51#define _COMPONENT ACPI_UTILITIES 51#define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utdelete") 52 ACPI_MODULE_NAME ("utdelete")
53 53
54/* Local prototypes */
55
56static void
57acpi_ut_delete_internal_obj (
58 union acpi_operand_object *object);
59
60static void
61acpi_ut_update_ref_count (
62 union acpi_operand_object *object,
63 u32 action);
64
54 65
55/******************************************************************************* 66/*******************************************************************************
56 * 67 *
57 * FUNCTION: acpi_ut_delete_internal_obj 68 * FUNCTION: acpi_ut_delete_internal_obj
58 * 69 *
59 * PARAMETERS: *Object - Pointer to the list to be deleted 70 * PARAMETERS: Object - Object to be deleted
60 * 71 *
61 * RETURN: None 72 * RETURN: None
62 * 73 *
@@ -65,7 +76,7 @@
65 * 76 *
66 ******************************************************************************/ 77 ******************************************************************************/
67 78
68void 79static void
69acpi_ut_delete_internal_obj ( 80acpi_ut_delete_internal_obj (
70 union acpi_operand_object *object) 81 union acpi_operand_object *object)
71{ 82{
@@ -152,7 +163,8 @@ acpi_ut_delete_internal_obj (
152 163
153 case ACPI_TYPE_MUTEX: 164 case ACPI_TYPE_MUTEX:
154 165
155 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Mutex %p, Semaphore %p\n", 166 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
167 "***** Mutex %p, Semaphore %p\n",
156 object, object->mutex.semaphore)); 168 object, object->mutex.semaphore));
157 169
158 acpi_ex_unlink_mutex (object); 170 acpi_ex_unlink_mutex (object);
@@ -162,7 +174,8 @@ acpi_ut_delete_internal_obj (
162 174
163 case ACPI_TYPE_EVENT: 175 case ACPI_TYPE_EVENT:
164 176
165 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Event %p, Semaphore %p\n", 177 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
178 "***** Event %p, Semaphore %p\n",
166 object, object->event.semaphore)); 179 object, object->event.semaphore));
167 180
168 (void) acpi_os_delete_semaphore (object->event.semaphore); 181 (void) acpi_os_delete_semaphore (object->event.semaphore);
@@ -172,7 +185,8 @@ acpi_ut_delete_internal_obj (
172 185
173 case ACPI_TYPE_METHOD: 186 case ACPI_TYPE_METHOD:
174 187
175 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Method %p\n", object)); 188 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
189 "***** Method %p\n", object));
176 190
177 /* Delete the method semaphore if it exists */ 191 /* Delete the method semaphore if it exists */
178 192
@@ -185,7 +199,8 @@ acpi_ut_delete_internal_obj (
185 199
186 case ACPI_TYPE_REGION: 200 case ACPI_TYPE_REGION:
187 201
188 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Region %p\n", object)); 202 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
203 "***** Region %p\n", object));
189 204
190 second_desc = acpi_ns_get_secondary_object (object); 205 second_desc = acpi_ns_get_secondary_object (object);
191 if (second_desc) { 206 if (second_desc) {
@@ -212,7 +227,8 @@ acpi_ut_delete_internal_obj (
212 227
213 case ACPI_TYPE_BUFFER_FIELD: 228 case ACPI_TYPE_BUFFER_FIELD:
214 229
215 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", object)); 230 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
231 "***** Buffer Field %p\n", object));
216 232
217 second_desc = acpi_ns_get_secondary_object (object); 233 second_desc = acpi_ns_get_secondary_object (object);
218 if (second_desc) { 234 if (second_desc) {
@@ -247,7 +263,7 @@ acpi_ut_delete_internal_obj (
247 * 263 *
248 * FUNCTION: acpi_ut_delete_internal_object_list 264 * FUNCTION: acpi_ut_delete_internal_object_list
249 * 265 *
250 * PARAMETERS: *obj_list - Pointer to the list to be deleted 266 * PARAMETERS: obj_list - Pointer to the list to be deleted
251 * 267 *
252 * RETURN: None 268 * RETURN: None
253 * 269 *
@@ -283,7 +299,7 @@ acpi_ut_delete_internal_object_list (
283 * 299 *
284 * FUNCTION: acpi_ut_update_ref_count 300 * FUNCTION: acpi_ut_update_ref_count
285 * 301 *
286 * PARAMETERS: *Object - Object whose ref count is to be updated 302 * PARAMETERS: Object - Object whose ref count is to be updated
287 * Action - What to do 303 * Action - What to do
288 * 304 *
289 * RETURN: New ref count 305 * RETURN: New ref count
@@ -312,7 +328,8 @@ acpi_ut_update_ref_count (
312 new_count = count; 328 new_count = count;
313 329
314 /* 330 /*
315 * Perform the reference count action (increment, decrement, or force delete) 331 * Perform the reference count action
332 * (increment, decrement, or force delete)
316 */ 333 */
317 switch (action) { 334 switch (action) {
318 335
@@ -321,7 +338,8 @@ acpi_ut_update_ref_count (
321 new_count++; 338 new_count++;
322 object->common.reference_count = new_count; 339 object->common.reference_count = new_count;
323 340
324 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Incremented]\n", 341 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
342 "Obj %p Refs=%X, [Incremented]\n",
325 object, new_count)); 343 object, new_count));
326 break; 344 break;
327 345
@@ -329,7 +347,8 @@ acpi_ut_update_ref_count (
329 case REF_DECREMENT: 347 case REF_DECREMENT:
330 348
331 if (count < 1) { 349 if (count < 1) {
332 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, can't decrement! (Set to 0)\n", 350 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
351 "Obj %p Refs=%X, can't decrement! (Set to 0)\n",
333 object, new_count)); 352 object, new_count));
334 353
335 new_count = 0; 354 new_count = 0;
@@ -337,12 +356,14 @@ acpi_ut_update_ref_count (
337 else { 356 else {
338 new_count--; 357 new_count--;
339 358
340 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Decremented]\n", 359 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
360 "Obj %p Refs=%X, [Decremented]\n",
341 object, new_count)); 361 object, new_count));
342 } 362 }
343 363
344 if (ACPI_GET_OBJECT_TYPE (object) == ACPI_TYPE_METHOD) { 364 if (ACPI_GET_OBJECT_TYPE (object) == ACPI_TYPE_METHOD) {
345 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Method Obj %p Refs=%X, [Decremented]\n", 365 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
366 "Method Obj %p Refs=%X, [Decremented]\n",
346 object, new_count)); 367 object, new_count));
347 } 368 }
348 369
@@ -356,7 +377,8 @@ acpi_ut_update_ref_count (
356 377
357 case REF_FORCE_DELETE: 378 case REF_FORCE_DELETE:
358 379
359 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, Force delete! (Set to 0)\n", 380 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
381 "Obj %p Refs=%X, Force delete! (Set to 0)\n",
360 object, count)); 382 object, count));
361 383
362 new_count = 0; 384 new_count = 0;
@@ -390,7 +412,7 @@ acpi_ut_update_ref_count (
390 * 412 *
391 * FUNCTION: acpi_ut_update_object_reference 413 * FUNCTION: acpi_ut_update_object_reference
392 * 414 *
393 * PARAMETERS: *Object - Increment ref count for this object 415 * PARAMETERS: Object - Increment ref count for this object
394 * and all sub-objects 416 * and all sub-objects
395 * Action - Either REF_INCREMENT or REF_DECREMENT or 417 * Action - Either REF_INCREMENT or REF_DECREMENT or
396 * REF_FORCE_DELETE 418 * REF_FORCE_DELETE
@@ -431,7 +453,8 @@ acpi_ut_update_object_reference (
431 /* Make sure that this isn't a namespace handle */ 453 /* Make sure that this isn't a namespace handle */
432 454
433 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) { 455 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) {
434 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p is NS handle\n", object)); 456 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
457 "Object %p is NS handle\n", object));
435 return_ACPI_STATUS (AE_OK); 458 return_ACPI_STATUS (AE_OK);
436 } 459 }
437 460
@@ -614,8 +637,8 @@ error_exit:
614 * 637 *
615 * FUNCTION: acpi_ut_add_reference 638 * FUNCTION: acpi_ut_add_reference
616 * 639 *
617 * PARAMETERS: *Object - Object whose reference count is to be 640 * PARAMETERS: Object - Object whose reference count is to be
618 * incremented 641 * incremented
619 * 642 *
620 * RETURN: None 643 * RETURN: None
621 * 644 *
@@ -652,7 +675,7 @@ acpi_ut_add_reference (
652 * 675 *
653 * FUNCTION: acpi_ut_remove_reference 676 * FUNCTION: acpi_ut_remove_reference
654 * 677 *
655 * PARAMETERS: *Object - Object whose ref count will be decremented 678 * PARAMETERS: Object - Object whose ref count will be decremented
656 * 679 *
657 * RETURN: None 680 * RETURN: None
658 * 681 *
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index ead27d2c4d18..00046dd5d925 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -50,6 +50,19 @@
50#define _COMPONENT ACPI_UTILITIES 50#define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("uteval") 51 ACPI_MODULE_NAME ("uteval")
52 52
53/* Local prototypes */
54
55static void
56acpi_ut_copy_id_string (
57 char *destination,
58 char *source,
59 acpi_size max_length);
60
61static acpi_status
62acpi_ut_translate_one_cid (
63 union acpi_operand_object *obj_desc,
64 struct acpi_compatible_id *one_cid);
65
53 66
54/******************************************************************************* 67/*******************************************************************************
55 * 68 *
@@ -237,9 +250,9 @@ acpi_ut_evaluate_object (
237 * 250 *
238 * FUNCTION: acpi_ut_evaluate_numeric_object 251 * FUNCTION: acpi_ut_evaluate_numeric_object
239 * 252 *
240 * PARAMETERS: *object_name - Object name to be evaluated 253 * PARAMETERS: object_name - Object name to be evaluated
241 * device_node - Node for the device 254 * device_node - Node for the device
242 * *Address - Where the value is returned 255 * Address - Where the value is returned
243 * 256 *
244 * RETURN: Status 257 * RETURN: Status
245 * 258 *
@@ -303,7 +316,6 @@ acpi_ut_copy_id_string (
303 acpi_size max_length) 316 acpi_size max_length)
304{ 317{
305 318
306
307 /* 319 /*
308 * Workaround for ID strings that have a leading asterisk. This construct 320 * Workaround for ID strings that have a leading asterisk. This construct
309 * is not allowed by the ACPI specification (ID strings must be 321 * is not allowed by the ACPI specification (ID strings must be
@@ -325,7 +337,7 @@ acpi_ut_copy_id_string (
325 * FUNCTION: acpi_ut_execute_HID 337 * FUNCTION: acpi_ut_execute_HID
326 * 338 *
327 * PARAMETERS: device_node - Node for the device 339 * PARAMETERS: device_node - Node for the device
328 * *Hid - Where the HID is returned 340 * Hid - Where the HID is returned
329 * 341 *
330 * RETURN: Status 342 * RETURN: Status
331 * 343 *
@@ -429,7 +441,7 @@ acpi_ut_translate_one_cid (
429 * FUNCTION: acpi_ut_execute_CID 441 * FUNCTION: acpi_ut_execute_CID
430 * 442 *
431 * PARAMETERS: device_node - Node for the device 443 * PARAMETERS: device_node - Node for the device
432 * *Cid - Where the CID is returned 444 * return_cid_list - Where the CID list is returned
433 * 445 *
434 * RETURN: Status 446 * RETURN: Status
435 * 447 *
@@ -488,10 +500,10 @@ acpi_ut_execute_CID (
488 cid_list->size = size; 500 cid_list->size = size;
489 501
490 /* 502 /*
491 * A _CID can return either a single compatible ID or a package of compatible 503 * A _CID can return either a single compatible ID or a package of
492 * IDs. Each compatible ID can be one of the following: 504 * compatible IDs. Each compatible ID can be one of the following:
493 * -- Number (32 bit compressed EISA ID) or 505 * 1) Integer (32 bit compressed EISA ID) or
494 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss"). 506 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
495 */ 507 */
496 508
497 /* The _CID object can be either a single CID or a package (list) of CIDs */ 509 /* The _CID object can be either a single CID or a package (list) of CIDs */
@@ -534,7 +546,7 @@ acpi_ut_execute_CID (
534 * FUNCTION: acpi_ut_execute_UID 546 * FUNCTION: acpi_ut_execute_UID
535 * 547 *
536 * PARAMETERS: device_node - Node for the device 548 * PARAMETERS: device_node - Node for the device
537 * *Uid - Where the UID is returned 549 * Uid - Where the UID is returned
538 * 550 *
539 * RETURN: Status 551 * RETURN: Status
540 * 552 *
@@ -587,7 +599,7 @@ acpi_ut_execute_UID (
587 * FUNCTION: acpi_ut_execute_STA 599 * FUNCTION: acpi_ut_execute_STA
588 * 600 *
589 * PARAMETERS: device_node - Node for the device 601 * PARAMETERS: device_node - Node for the device
590 * *Flags - Where the status flags are returned 602 * Flags - Where the status flags are returned
591 * 603 *
592 * RETURN: Status 604 * RETURN: Status
593 * 605 *
@@ -641,7 +653,7 @@ acpi_ut_execute_STA (
641 * FUNCTION: acpi_ut_execute_Sxds 653 * FUNCTION: acpi_ut_execute_Sxds
642 * 654 *
643 * PARAMETERS: device_node - Node for the device 655 * PARAMETERS: device_node - Node for the device
644 * *Flags - Where the status flags are returned 656 * Flags - Where the status flags are returned
645 * 657 *
646 * RETURN: Status 658 * RETURN: Status
647 * 659 *
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index 25b0f8ae1bc6..4146019b543f 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -44,7 +44,6 @@
44#define DEFINE_ACPI_GLOBALS 44#define DEFINE_ACPI_GLOBALS
45 45
46#include <linux/module.h> 46#include <linux/module.h>
47
48#include <acpi/acpi.h> 47#include <acpi/acpi.h>
49#include <acpi/acnamesp.h> 48#include <acpi/acnamesp.h>
50 49
@@ -52,13 +51,14 @@
52 ACPI_MODULE_NAME ("utglobal") 51 ACPI_MODULE_NAME ("utglobal")
53 52
54 53
55/****************************************************************************** 54/*******************************************************************************
56 * 55 *
57 * FUNCTION: acpi_format_exception 56 * FUNCTION: acpi_format_exception
58 * 57 *
59 * PARAMETERS: Status - The acpi_status code to be formatted 58 * PARAMETERS: Status - The acpi_status code to be formatted
60 * 59 *
61 * RETURN: A string containing the exception text 60 * RETURN: A string containing the exception text. A valid pointer is
61 * always returned.
62 * 62 *
63 * DESCRIPTION: This function translates an ACPI exception into an ASCII string. 63 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
64 * 64 *
@@ -68,8 +68,8 @@ const char *
68acpi_format_exception ( 68acpi_format_exception (
69 acpi_status status) 69 acpi_status status)
70{ 70{
71 const char *exception = "UNKNOWN_STATUS_CODE";
72 acpi_status sub_status; 71 acpi_status sub_status;
72 const char *exception = NULL;
73 73
74 74
75 ACPI_FUNCTION_NAME ("format_exception"); 75 ACPI_FUNCTION_NAME ("format_exception");
@@ -82,57 +82,55 @@ acpi_format_exception (
82 82
83 if (sub_status <= AE_CODE_ENV_MAX) { 83 if (sub_status <= AE_CODE_ENV_MAX) {
84 exception = acpi_gbl_exception_names_env [sub_status]; 84 exception = acpi_gbl_exception_names_env [sub_status];
85 break;
86 } 85 }
87 goto unknown; 86 break;
88 87
89 case AE_CODE_PROGRAMMER: 88 case AE_CODE_PROGRAMMER:
90 89
91 if (sub_status <= AE_CODE_PGM_MAX) { 90 if (sub_status <= AE_CODE_PGM_MAX) {
92 exception = acpi_gbl_exception_names_pgm [sub_status -1]; 91 exception = acpi_gbl_exception_names_pgm [sub_status -1];
93 break;
94 } 92 }
95 goto unknown; 93 break;
96 94
97 case AE_CODE_ACPI_TABLES: 95 case AE_CODE_ACPI_TABLES:
98 96
99 if (sub_status <= AE_CODE_TBL_MAX) { 97 if (sub_status <= AE_CODE_TBL_MAX) {
100 exception = acpi_gbl_exception_names_tbl [sub_status -1]; 98 exception = acpi_gbl_exception_names_tbl [sub_status -1];
101 break;
102 } 99 }
103 goto unknown; 100 break;
104 101
105 case AE_CODE_AML: 102 case AE_CODE_AML:
106 103
107 if (sub_status <= AE_CODE_AML_MAX) { 104 if (sub_status <= AE_CODE_AML_MAX) {
108 exception = acpi_gbl_exception_names_aml [sub_status -1]; 105 exception = acpi_gbl_exception_names_aml [sub_status -1];
109 break;
110 } 106 }
111 goto unknown; 107 break;
112 108
113 case AE_CODE_CONTROL: 109 case AE_CODE_CONTROL:
114 110
115 if (sub_status <= AE_CODE_CTRL_MAX) { 111 if (sub_status <= AE_CODE_CTRL_MAX) {
116 exception = acpi_gbl_exception_names_ctrl [sub_status -1]; 112 exception = acpi_gbl_exception_names_ctrl [sub_status -1];
117 break;
118 } 113 }
119 goto unknown; 114 break;
120 115
121 default: 116 default:
122 goto unknown; 117 break;
123 } 118 }
124 119
120 if (!exception) {
121 /* Exception code was not recognized */
125 122
126 return ((const char *) exception); 123 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
124 "Unknown exception code: 0x%8.8X\n", status));
127 125
128unknown: 126 return ((const char *) "UNKNOWN_STATUS_CODE");
127 }
129 128
130 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown exception code: 0x%8.8X\n", status));
131 return ((const char *) exception); 129 return ((const char *) exception);
132} 130}
133 131
134 132
135/****************************************************************************** 133/*******************************************************************************
136 * 134 *
137 * Static global variable initialization. 135 * Static global variable initialization.
138 * 136 *
@@ -212,13 +210,12 @@ const char *acpi_gbl_valid_osi_strings[ACPI_NUM_OSI_STR
212}; 210};
213 211
214 212
215/****************************************************************************** 213/*******************************************************************************
216 * 214 *
217 * Namespace globals 215 * Namespace globals
218 * 216 *
219 ******************************************************************************/ 217 ******************************************************************************/
220 218
221
222/* 219/*
223 * Predefined ACPI Names (Built-in to the Interpreter) 220 * Predefined ACPI Names (Built-in to the Interpreter)
224 * 221 *
@@ -241,9 +238,11 @@ const struct acpi_predefined_names acpi_gbl_pre_defined_names[] =
241#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY) 238#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
242 {"_OSI", ACPI_TYPE_METHOD, (char *) 1}, 239 {"_OSI", ACPI_TYPE_METHOD, (char *) 1},
243#endif 240#endif
244 {NULL, ACPI_TYPE_ANY, NULL} /* Table terminator */
245};
246 241
242 /* Table terminator */
243
244 {NULL, ACPI_TYPE_ANY, NULL}
245};
247 246
248/* 247/*
249 * Properties of the ACPI Object Types, both internal and external. 248 * Properties of the ACPI Object Types, both internal and external.
@@ -288,22 +287,25 @@ const u8 acpi_gbl_ns_properties[] =
288/* Hex to ASCII conversion table */ 287/* Hex to ASCII conversion table */
289 288
290static const char acpi_gbl_hex_to_ascii[] = 289static const char acpi_gbl_hex_to_ascii[] =
291 {'0','1','2','3','4','5','6','7', 290{
292 '8','9','A','B','C','D','E','F'}; 291 '0','1','2','3','4','5','6','7',
292 '8','9','A','B','C','D','E','F'
293};
294
293 295
294/***************************************************************************** 296/*******************************************************************************
295 * 297 *
296 * FUNCTION: acpi_ut_hex_to_ascii_char 298 * FUNCTION: acpi_ut_hex_to_ascii_char
297 * 299 *
298 * PARAMETERS: Integer - Contains the hex digit 300 * PARAMETERS: Integer - Contains the hex digit
299 * Position - bit position of the digit within the 301 * Position - bit position of the digit within the
300 * integer 302 * integer (multiple of 4)
301 * 303 *
302 * RETURN: Ascii character 304 * RETURN: The converted Ascii character
303 * 305 *
304 * DESCRIPTION: Convert a hex digit to an ascii character 306 * DESCRIPTION: Convert a hex digit to an Ascii character
305 * 307 *
306 ****************************************************************************/ 308 ******************************************************************************/
307 309
308char 310char
309acpi_ut_hex_to_ascii_char ( 311acpi_ut_hex_to_ascii_char (
@@ -315,7 +317,7 @@ acpi_ut_hex_to_ascii_char (
315} 317}
316 318
317 319
318/****************************************************************************** 320/*******************************************************************************
319 * 321 *
320 * Table name globals 322 * Table name globals
321 * 323 *
@@ -324,7 +326,7 @@ acpi_ut_hex_to_ascii_char (
324 * that are not used by the subsystem are simply ignored. 326 * that are not used by the subsystem are simply ignored.
325 * 327 *
326 * Do NOT add any table to this list that is not consumed directly by this 328 * Do NOT add any table to this list that is not consumed directly by this
327 * subsystem. 329 * subsystem (No MADT, ECDT, SBST, etc.)
328 * 330 *
329 ******************************************************************************/ 331 ******************************************************************************/
330 332
@@ -391,7 +393,7 @@ struct acpi_fixed_event_info acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVE
391 /* ACPI_EVENT_RTC */ {ACPI_BITREG_RT_CLOCK_STATUS, ACPI_BITREG_RT_CLOCK_ENABLE, ACPI_BITMASK_RT_CLOCK_STATUS, ACPI_BITMASK_RT_CLOCK_ENABLE}, 393 /* ACPI_EVENT_RTC */ {ACPI_BITREG_RT_CLOCK_STATUS, ACPI_BITREG_RT_CLOCK_ENABLE, ACPI_BITMASK_RT_CLOCK_STATUS, ACPI_BITMASK_RT_CLOCK_ENABLE},
392}; 394};
393 395
394/***************************************************************************** 396/*******************************************************************************
395 * 397 *
396 * FUNCTION: acpi_ut_get_region_name 398 * FUNCTION: acpi_ut_get_region_name
397 * 399 *
@@ -401,7 +403,7 @@ struct acpi_fixed_event_info acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVE
401 * 403 *
402 * DESCRIPTION: Translate a Space ID into a name string (Debug only) 404 * DESCRIPTION: Translate a Space ID into a name string (Debug only)
403 * 405 *
404 ****************************************************************************/ 406 ******************************************************************************/
405 407
406/* Region type decoding */ 408/* Region type decoding */
407 409
@@ -429,7 +431,6 @@ acpi_ut_get_region_name (
429 { 431 {
430 return ("user_defined_region"); 432 return ("user_defined_region");
431 } 433 }
432
433 else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) 434 else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS)
434 { 435 {
435 return ("invalid_space_id"); 436 return ("invalid_space_id");
@@ -439,7 +440,7 @@ acpi_ut_get_region_name (
439} 440}
440 441
441 442
442/***************************************************************************** 443/*******************************************************************************
443 * 444 *
444 * FUNCTION: acpi_ut_get_event_name 445 * FUNCTION: acpi_ut_get_event_name
445 * 446 *
@@ -449,7 +450,7 @@ acpi_ut_get_region_name (
449 * 450 *
450 * DESCRIPTION: Translate a Event ID into a name string (Debug only) 451 * DESCRIPTION: Translate a Event ID into a name string (Debug only)
451 * 452 *
452 ****************************************************************************/ 453 ******************************************************************************/
453 454
454/* Event type decoding */ 455/* Event type decoding */
455 456
@@ -477,7 +478,7 @@ acpi_ut_get_event_name (
477} 478}
478 479
479 480
480/***************************************************************************** 481/*******************************************************************************
481 * 482 *
482 * FUNCTION: acpi_ut_get_type_name 483 * FUNCTION: acpi_ut_get_type_name
483 * 484 *
@@ -487,20 +488,21 @@ acpi_ut_get_event_name (
487 * 488 *
488 * DESCRIPTION: Translate a Type ID into a name string (Debug only) 489 * DESCRIPTION: Translate a Type ID into a name string (Debug only)
489 * 490 *
490 ****************************************************************************/ 491 ******************************************************************************/
491 492
492/* 493/*
493 * Elements of acpi_gbl_ns_type_names below must match 494 * Elements of acpi_gbl_ns_type_names below must match
494 * one-to-one with values of acpi_object_type 495 * one-to-one with values of acpi_object_type
495 * 496 *
496 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching; when 497 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
497 * stored in a table it really means that we have thus far seen no evidence to 498 * when stored in a table it really means that we have thus far seen no
498 * indicate what type is actually going to be stored for this entry. 499 * evidence to indicate what type is actually going to be stored for this entry.
499 */ 500 */
500static const char acpi_gbl_bad_type[] = "UNDEFINED"; 501static const char acpi_gbl_bad_type[] = "UNDEFINED";
501#define TYPE_NAME_LENGTH 12 /* Maximum length of each string */
502 502
503static const char *acpi_gbl_ns_type_names[] = /* printable names of ACPI types */ 503/* Printable names of the ACPI object types */
504
505static const char *acpi_gbl_ns_type_names[] =
504{ 506{
505 /* 00 */ "Untyped", 507 /* 00 */ "Untyped",
506 /* 01 */ "Integer", 508 /* 01 */ "Integer",
@@ -564,7 +566,7 @@ acpi_ut_get_object_type_name (
564} 566}
565 567
566 568
567/***************************************************************************** 569/*******************************************************************************
568 * 570 *
569 * FUNCTION: acpi_ut_get_node_name 571 * FUNCTION: acpi_ut_get_node_name
570 * 572 *
@@ -574,7 +576,7 @@ acpi_ut_get_object_type_name (
574 * 576 *
575 * DESCRIPTION: Validate the node and return the node's ACPI name. 577 * DESCRIPTION: Validate the node and return the node's ACPI name.
576 * 578 *
577 ****************************************************************************/ 579 ******************************************************************************/
578 580
579char * 581char *
580acpi_ut_get_node_name ( 582acpi_ut_get_node_name (
@@ -618,7 +620,7 @@ acpi_ut_get_node_name (
618} 620}
619 621
620 622
621/***************************************************************************** 623/*******************************************************************************
622 * 624 *
623 * FUNCTION: acpi_ut_get_descriptor_name 625 * FUNCTION: acpi_ut_get_descriptor_name
624 * 626 *
@@ -628,9 +630,11 @@ acpi_ut_get_node_name (
628 * 630 *
629 * DESCRIPTION: Validate object and return the descriptor type 631 * DESCRIPTION: Validate object and return the descriptor type
630 * 632 *
631 ****************************************************************************/ 633 ******************************************************************************/
634
635/* Printable names of object descriptor types */
632 636
633static const char *acpi_gbl_desc_type_names[] = /* printable names of descriptor types */ 637static const char *acpi_gbl_desc_type_names[] =
634{ 638{
635 /* 00 */ "Invalid", 639 /* 00 */ "Invalid",
636 /* 01 */ "Cached", 640 /* 01 */ "Cached",
@@ -676,17 +680,18 @@ acpi_ut_get_descriptor_name (
676 * Strings and procedures used for debug only 680 * Strings and procedures used for debug only
677 */ 681 */
678 682
679/***************************************************************************** 683/*******************************************************************************
680 * 684 *
681 * FUNCTION: acpi_ut_get_mutex_name 685 * FUNCTION: acpi_ut_get_mutex_name
682 * 686 *
683 * PARAMETERS: None. 687 * PARAMETERS: mutex_id - The predefined ID for this mutex.
684 * 688 *
685 * RETURN: Status 689 * RETURN: String containing the name of the mutex. Always returns a valid
690 * pointer.
686 * 691 *
687 * DESCRIPTION: Translate a mutex ID into a name string (Debug only) 692 * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
688 * 693 *
689 ****************************************************************************/ 694 ******************************************************************************/
690 695
691char * 696char *
692acpi_ut_get_mutex_name ( 697acpi_ut_get_mutex_name (
@@ -700,21 +705,20 @@ acpi_ut_get_mutex_name (
700 705
701 return (acpi_gbl_mutex_names[mutex_id]); 706 return (acpi_gbl_mutex_names[mutex_id]);
702} 707}
703
704#endif 708#endif
705 709
706 710
707/***************************************************************************** 711/*******************************************************************************
708 * 712 *
709 * FUNCTION: acpi_ut_valid_object_type 713 * FUNCTION: acpi_ut_valid_object_type
710 * 714 *
711 * PARAMETERS: Type - Object type to be validated 715 * PARAMETERS: Type - Object type to be validated
712 * 716 *
713 * RETURN: TRUE if valid object type 717 * RETURN: TRUE if valid object type, FALSE otherwise
714 * 718 *
715 * DESCRIPTION: Validate an object type 719 * DESCRIPTION: Validate an object type
716 * 720 *
717 ****************************************************************************/ 721 ******************************************************************************/
718 722
719u8 723u8
720acpi_ut_valid_object_type ( 724acpi_ut_valid_object_type (
@@ -732,7 +736,7 @@ acpi_ut_valid_object_type (
732} 736}
733 737
734 738
735/**************************************************************************** 739/*******************************************************************************
736 * 740 *
737 * FUNCTION: acpi_ut_allocate_owner_id 741 * FUNCTION: acpi_ut_allocate_owner_id
738 * 742 *
@@ -740,7 +744,10 @@ acpi_ut_valid_object_type (
740 * 744 *
741 * DESCRIPTION: Allocate a table or method owner id 745 * DESCRIPTION: Allocate a table or method owner id
742 * 746 *
743 ***************************************************************************/ 747 * NOTE: this algorithm has a wraparound problem at 64_k method invocations, and
748 * should be revisited (TBD)
749 *
750 ******************************************************************************/
744 751
745acpi_owner_id 752acpi_owner_id
746acpi_ut_allocate_owner_id ( 753acpi_ut_allocate_owner_id (
@@ -796,16 +803,18 @@ acpi_ut_allocate_owner_id (
796} 803}
797 804
798 805
799/**************************************************************************** 806/*******************************************************************************
800 * 807 *
801 * FUNCTION: acpi_ut_init_globals 808 * FUNCTION: acpi_ut_init_globals
802 * 809 *
803 * PARAMETERS: none 810 * PARAMETERS: None
811 *
812 * RETURN: None
804 * 813 *
805 * DESCRIPTION: Init library globals. All globals that require specific 814 * DESCRIPTION: Init library globals. All globals that require specific
806 * initialization should be initialized here! 815 * initialization should be initialized here!
807 * 816 *
808 ***************************************************************************/ 817 ******************************************************************************/
809 818
810void 819void
811acpi_ut_init_globals ( 820acpi_ut_init_globals (
diff --git a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
index bdbadaf48d29..7f3713889ff0 100644
--- a/drivers/acpi/utilities/utinit.c
+++ b/drivers/acpi/utilities/utinit.c
@@ -49,19 +49,29 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utinit") 50 ACPI_MODULE_NAME ("utinit")
51 51
52/* Local prototypes */
53
54static void
55acpi_ut_fadt_register_error (
56 char *register_name,
57 u32 value,
58 acpi_size offset);
59
60static void acpi_ut_terminate (
61 void);
62
52 63
53/******************************************************************************* 64/*******************************************************************************
54 * 65 *
55 * FUNCTION: acpi_ut_fadt_register_error 66 * FUNCTION: acpi_ut_fadt_register_error
56 * 67 *
57 * PARAMETERS: *register_name - Pointer to string identifying register 68 * PARAMETERS: register_name - Pointer to string identifying register
58 * Value - Actual register contents value 69 * Value - Actual register contents value
59 * acpi_test_spec_section - TDS section containing assertion 70 * Offset - Byte offset in the FADT
60 * acpi_assertion - Assertion number being tested
61 * 71 *
62 * RETURN: AE_BAD_VALUE 72 * RETURN: AE_BAD_VALUE
63 * 73 *
64 * DESCRIPTION: Display failure message and link failure to TDS assertion 74 * DESCRIPTION: Display failure message
65 * 75 *
66 ******************************************************************************/ 76 ******************************************************************************/
67 77
@@ -166,12 +176,13 @@ acpi_ut_validate_fadt (
166 * 176 *
167 * RETURN: none 177 * RETURN: none
168 * 178 *
169 * DESCRIPTION: free global memory 179 * DESCRIPTION: Free global memory
170 * 180 *
171 ******************************************************************************/ 181 ******************************************************************************/
172 182
173void 183static void
174acpi_ut_terminate (void) 184acpi_ut_terminate (
185 void)
175{ 186{
176 struct acpi_gpe_block_info *gpe_block; 187 struct acpi_gpe_block_info *gpe_block;
177 struct acpi_gpe_block_info *next_gpe_block; 188 struct acpi_gpe_block_info *next_gpe_block;
@@ -183,8 +194,6 @@ acpi_ut_terminate (void)
183 194
184 195
185 /* Free global tables, etc. */ 196 /* Free global tables, etc. */
186
187
188 /* Free global GPE blocks and related info structures */ 197 /* Free global GPE blocks and related info structures */
189 198
190 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; 199 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
@@ -221,7 +230,8 @@ acpi_ut_terminate (void)
221 ******************************************************************************/ 230 ******************************************************************************/
222 231
223void 232void
224acpi_ut_subsystem_shutdown (void) 233acpi_ut_subsystem_shutdown (
234 void)
225{ 235{
226 236
227 ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown"); 237 ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown");
@@ -229,14 +239,16 @@ acpi_ut_subsystem_shutdown (void)
229 /* Just exit if subsystem is already shutdown */ 239 /* Just exit if subsystem is already shutdown */
230 240
231 if (acpi_gbl_shutdown) { 241 if (acpi_gbl_shutdown) {
232 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "ACPI Subsystem is already terminated\n")); 242 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
243 "ACPI Subsystem is already terminated\n"));
233 return_VOID; 244 return_VOID;
234 } 245 }
235 246
236 /* Subsystem appears active, go ahead and shut it down */ 247 /* Subsystem appears active, go ahead and shut it down */
237 248
238 acpi_gbl_shutdown = TRUE; 249 acpi_gbl_shutdown = TRUE;
239 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem...\n")); 250 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
251 "Shutting down ACPI Subsystem...\n"));
240 252
241 /* Close the acpi_event Handling */ 253 /* Close the acpi_event Handling */
242 254
diff --git a/drivers/acpi/utilities/utmath.c b/drivers/acpi/utilities/utmath.c
index 2525c1a93547..0d527c91543c 100644
--- a/drivers/acpi/utilities/utmath.c
+++ b/drivers/acpi/utilities/utmath.c
@@ -259,6 +259,8 @@ acpi_ut_divide (
259 * 259 *
260 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide 260 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide
261 * 261 *
262 * PARAMETERS: See function headers above
263 *
262 * DESCRIPTION: Native versions of the ut_divide functions. Use these if either 264 * DESCRIPTION: Native versions of the ut_divide functions. Use these if either
263 * 1) The target is a 64-bit platform and therefore 64-bit 265 * 1) The target is a 64-bit platform and therefore 64-bit
264 * integer math is supported directly by the machine. 266 * integer math is supported directly by the machine.
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index f6598547389b..f6de4ed3d527 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -49,12 +49,57 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utmisc") 50 ACPI_MODULE_NAME ("utmisc")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ut_create_mutex (
56 acpi_mutex_handle mutex_id);
57
58static acpi_status
59acpi_ut_delete_mutex (
60 acpi_mutex_handle mutex_id);
61
62
63/*******************************************************************************
64 *
65 * FUNCTION: acpi_ut_strupr (strupr)
66 *
67 * PARAMETERS: src_string - The source string to convert
68 *
69 * RETURN: Converted src_string (same as input pointer)
70 *
71 * DESCRIPTION: Convert string to uppercase
72 *
73 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
74 *
75 ******************************************************************************/
76
77char *
78acpi_ut_strupr (
79 char *src_string)
80{
81 char *string;
82
83
84 ACPI_FUNCTION_ENTRY ();
85
86
87 /* Walk entire string, uppercasing the letters */
88
89 for (string = src_string; *string; string++) {
90 *string = (char) ACPI_TOUPPER (*string);
91 }
92
93 return (src_string);
94}
95
52 96
53/******************************************************************************* 97/*******************************************************************************
54 * 98 *
55 * FUNCTION: acpi_ut_print_string 99 * FUNCTION: acpi_ut_print_string
56 * 100 *
57 * PARAMETERS: String - Null terminated ASCII string 101 * PARAMETERS: String - Null terminated ASCII string
102 * max_length - Maximum output length
58 * 103 *
59 * RETURN: None 104 * RETURN: None
60 * 105 *
@@ -148,6 +193,8 @@ acpi_ut_print_string (
148 * 193 *
149 * PARAMETERS: Value - Value to be converted 194 * PARAMETERS: Value - Value to be converted
150 * 195 *
196 * RETURN: u32 integer with bytes swapped
197 *
151 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) 198 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
152 * 199 *
153 ******************************************************************************/ 200 ******************************************************************************/
@@ -160,7 +207,6 @@ acpi_ut_dword_byte_swap (
160 u32 value; 207 u32 value;
161 u8 bytes[4]; 208 u8 bytes[4];
162 } out; 209 } out;
163
164 union { 210 union {
165 u32 value; 211 u32 value;
166 u8 bytes[4]; 212 u8 bytes[4];
@@ -219,7 +265,8 @@ acpi_ut_set_integer_width (
219 * 265 *
220 * FUNCTION: acpi_ut_display_init_pathname 266 * FUNCTION: acpi_ut_display_init_pathname
221 * 267 *
222 * PARAMETERS: obj_handle - Handle whose pathname will be displayed 268 * PARAMETERS: Type - Object type of the node
269 * obj_handle - Handle whose pathname will be displayed
223 * Path - Additional path string to be appended. 270 * Path - Additional path string to be appended.
224 * (NULL if no extra path) 271 * (NULL if no extra path)
225 * 272 *
@@ -270,7 +317,8 @@ acpi_ut_display_init_pathname (
270 317
271 /* Print the object type and pathname */ 318 /* Print the object type and pathname */
272 319
273 acpi_os_printf ("%-12s %s", acpi_ut_get_type_name (type), (char *) buffer.pointer); 320 acpi_os_printf ("%-12s %s",
321 acpi_ut_get_type_name (type), (char *) buffer.pointer);
274 322
275 /* Extra path is used to append names like _STA, _INI, etc. */ 323 /* Extra path is used to append names like _STA, _INI, etc. */
276 324
@@ -288,9 +336,9 @@ acpi_ut_display_init_pathname (
288 * 336 *
289 * FUNCTION: acpi_ut_valid_acpi_name 337 * FUNCTION: acpi_ut_valid_acpi_name
290 * 338 *
291 * PARAMETERS: Character - The character to be examined 339 * PARAMETERS: Name - The name to be examined
292 * 340 *
293 * RETURN: 1 if Character may appear in a name, else 0 341 * RETURN: TRUE if the name is valid, FALSE otherwise
294 * 342 *
295 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of: 343 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
296 * 1) Upper case alpha 344 * 1) Upper case alpha
@@ -495,40 +543,6 @@ error_exit:
495 543
496/******************************************************************************* 544/*******************************************************************************
497 * 545 *
498 * FUNCTION: acpi_ut_strupr
499 *
500 * PARAMETERS: src_string - The source string to convert to
501 *
502 * RETURN: src_string
503 *
504 * DESCRIPTION: Convert string to uppercase
505 *
506 ******************************************************************************/
507#ifdef ACPI_FUTURE_USAGE
508char *
509acpi_ut_strupr (
510 char *src_string)
511{
512 char *string;
513
514
515 ACPI_FUNCTION_ENTRY ();
516
517
518 /* Walk entire string, uppercasing the letters */
519
520 for (string = src_string; *string; ) {
521 *string = (char) ACPI_TOUPPER (*string);
522 string++;
523 }
524
525 return (src_string);
526}
527#endif /* ACPI_FUTURE_USAGE */
528
529
530/*******************************************************************************
531 *
532 * FUNCTION: acpi_ut_mutex_initialize 546 * FUNCTION: acpi_ut_mutex_initialize
533 * 547 *
534 * PARAMETERS: None. 548 * PARAMETERS: None.
@@ -611,7 +625,7 @@ acpi_ut_mutex_terminate (
611 * 625 *
612 ******************************************************************************/ 626 ******************************************************************************/
613 627
614acpi_status 628static acpi_status
615acpi_ut_create_mutex ( 629acpi_ut_create_mutex (
616 acpi_mutex_handle mutex_id) 630 acpi_mutex_handle mutex_id)
617{ 631{
@@ -648,7 +662,7 @@ acpi_ut_create_mutex (
648 * 662 *
649 ******************************************************************************/ 663 ******************************************************************************/
650 664
651acpi_status 665static acpi_status
652acpi_ut_delete_mutex ( 666acpi_ut_delete_mutex (
653 acpi_mutex_handle mutex_id) 667 acpi_mutex_handle mutex_id)
654{ 668{
@@ -715,16 +729,16 @@ acpi_ut_acquire_mutex (
715 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 729 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
716 if (i == mutex_id) { 730 if (i == mutex_id) {
717 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
718 "Mutex [%s] already acquired by this thread [%X]\n", 732 "Mutex [%s] already acquired by this thread [%X]\n",
719 acpi_ut_get_mutex_name (mutex_id), this_thread_id)); 733 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
720 734
721 return (AE_ALREADY_ACQUIRED); 735 return (AE_ALREADY_ACQUIRED);
722 } 736 }
723 737
724 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 738 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
725 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n", 739 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
726 this_thread_id, acpi_ut_get_mutex_name (i), 740 this_thread_id, acpi_ut_get_mutex_name (i),
727 acpi_ut_get_mutex_name (mutex_id))); 741 acpi_ut_get_mutex_name (mutex_id)));
728 742
729 return (AE_ACQUIRE_DEADLOCK); 743 return (AE_ACQUIRE_DEADLOCK);
730 } 744 }
@@ -733,22 +747,23 @@ acpi_ut_acquire_mutex (
733#endif 747#endif
734 748
735 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 749 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
736 "Thread %X attempting to acquire Mutex [%s]\n", 750 "Thread %X attempting to acquire Mutex [%s]\n",
737 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 751 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
738 752
739 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 753 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
740 1, ACPI_WAIT_FOREVER); 754 1, ACPI_WAIT_FOREVER);
741 if (ACPI_SUCCESS (status)) { 755 if (ACPI_SUCCESS (status)) {
742 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n", 756 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
743 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 757 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
744 758
745 acpi_gbl_mutex_info[mutex_id].use_count++; 759 acpi_gbl_mutex_info[mutex_id].use_count++;
746 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id; 760 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id;
747 } 761 }
748 else { 762 else {
749 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n", 763 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
750 this_thread_id, acpi_ut_get_mutex_name (mutex_id), 764 "Thread %X could not acquire Mutex [%s] %s\n",
751 acpi_format_exception (status))); 765 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
766 acpi_format_exception (status)));
752 } 767 }
753 768
754 return (status); 769 return (status);
@@ -793,8 +808,8 @@ acpi_ut_release_mutex (
793 */ 808 */
794 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) { 809 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
795 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 810 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
796 "Mutex [%s] is not acquired, cannot release\n", 811 "Mutex [%s] is not acquired, cannot release\n",
797 acpi_ut_get_mutex_name (mutex_id))); 812 acpi_ut_get_mutex_name (mutex_id)));
798 813
799 return (AE_NOT_ACQUIRED); 814 return (AE_NOT_ACQUIRED);
800 } 815 }
@@ -812,8 +827,8 @@ acpi_ut_release_mutex (
812 } 827 }
813 828
814 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
815 "Invalid release order: owns [%s], releasing [%s]\n", 830 "Invalid release order: owns [%s], releasing [%s]\n",
816 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id))); 831 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
817 832
818 return (AE_RELEASE_DEADLOCK); 833 return (AE_RELEASE_DEADLOCK);
819 } 834 }
@@ -826,13 +841,14 @@ acpi_ut_release_mutex (
826 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1); 841 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
827 842
828 if (ACPI_FAILURE (status)) { 843 if (ACPI_FAILURE (status)) {
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n", 844 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
830 this_thread_id, acpi_ut_get_mutex_name (mutex_id), 845 "Thread %X could not release Mutex [%s] %s\n",
831 acpi_format_exception (status))); 846 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
847 acpi_format_exception (status)));
832 } 848 }
833 else { 849 else {
834 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n", 850 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
835 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 851 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
836 } 852 }
837 853
838 return (status); 854 return (status);
@@ -843,11 +859,11 @@ acpi_ut_release_mutex (
843 * 859 *
844 * FUNCTION: acpi_ut_create_update_state_and_push 860 * FUNCTION: acpi_ut_create_update_state_and_push
845 * 861 *
846 * PARAMETERS: *Object - Object to be added to the new state 862 * PARAMETERS: Object - Object to be added to the new state
847 * Action - Increment/Decrement 863 * Action - Increment/Decrement
848 * state_list - List the state will be added to 864 * state_list - List the state will be added to
849 * 865 *
850 * RETURN: None 866 * RETURN: Status
851 * 867 *
852 * DESCRIPTION: Create a new state and push it 868 * DESCRIPTION: Create a new state and push it
853 * 869 *
@@ -885,15 +901,16 @@ acpi_ut_create_update_state_and_push (
885 * 901 *
886 * FUNCTION: acpi_ut_create_pkg_state_and_push 902 * FUNCTION: acpi_ut_create_pkg_state_and_push
887 * 903 *
888 * PARAMETERS: *Object - Object to be added to the new state 904 * PARAMETERS: Object - Object to be added to the new state
889 * Action - Increment/Decrement 905 * Action - Increment/Decrement
890 * state_list - List the state will be added to 906 * state_list - List the state will be added to
891 * 907 *
892 * RETURN: None 908 * RETURN: Status
893 * 909 *
894 * DESCRIPTION: Create a new state and push it 910 * DESCRIPTION: Create a new state and push it
895 * 911 *
896 ******************************************************************************/ 912 ******************************************************************************/
913
897#ifdef ACPI_FUTURE_USAGE 914#ifdef ACPI_FUTURE_USAGE
898acpi_status 915acpi_status
899acpi_ut_create_pkg_state_and_push ( 916acpi_ut_create_pkg_state_and_push (
@@ -925,7 +942,7 @@ acpi_ut_create_pkg_state_and_push (
925 * PARAMETERS: list_head - Head of the state stack 942 * PARAMETERS: list_head - Head of the state stack
926 * State - State object to push 943 * State - State object to push
927 * 944 *
928 * RETURN: Status 945 * RETURN: None
929 * 946 *
930 * DESCRIPTION: Push a state object onto a state stack 947 * DESCRIPTION: Push a state object onto a state stack
931 * 948 *
@@ -954,7 +971,7 @@ acpi_ut_push_generic_state (
954 * 971 *
955 * PARAMETERS: list_head - Head of the state stack 972 * PARAMETERS: list_head - Head of the state stack
956 * 973 *
957 * RETURN: Status 974 * RETURN: The popped state object
958 * 975 *
959 * DESCRIPTION: Pop a state object from a state stack 976 * DESCRIPTION: Pop a state object from a state stack
960 * 977 *
@@ -989,7 +1006,7 @@ acpi_ut_pop_generic_state (
989 * 1006 *
990 * PARAMETERS: None 1007 * PARAMETERS: None
991 * 1008 *
992 * RETURN: Status 1009 * RETURN: The new state object. NULL on failure.
993 * 1010 *
994 * DESCRIPTION: Create a generic state object. Attempt to obtain one from 1011 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
995 * the global state cache; If none available, create a new one. 1012 * the global state cache; If none available, create a new one.
@@ -997,7 +1014,8 @@ acpi_ut_pop_generic_state (
997 ******************************************************************************/ 1014 ******************************************************************************/
998 1015
999union acpi_generic_state * 1016union acpi_generic_state *
1000acpi_ut_create_generic_state (void) 1017acpi_ut_create_generic_state (
1018 void)
1001{ 1019{
1002 union acpi_generic_state *state; 1020 union acpi_generic_state *state;
1003 1021
@@ -1023,7 +1041,7 @@ acpi_ut_create_generic_state (void)
1023 * 1041 *
1024 * PARAMETERS: None 1042 * PARAMETERS: None
1025 * 1043 *
1026 * RETURN: Thread State 1044 * RETURN: New Thread State. NULL on failure
1027 * 1045 *
1028 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 1046 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1029 * to track per-thread info during method execution 1047 * to track per-thread info during method execution
@@ -1060,11 +1078,10 @@ acpi_ut_create_thread_state (
1060 * 1078 *
1061 * FUNCTION: acpi_ut_create_update_state 1079 * FUNCTION: acpi_ut_create_update_state
1062 * 1080 *
1063 * PARAMETERS: Object - Initial Object to be installed in the 1081 * PARAMETERS: Object - Initial Object to be installed in the state
1064 * state 1082 * Action - Update action to be performed
1065 * Action - Update action to be performed
1066 * 1083 *
1067 * RETURN: Status 1084 * RETURN: New state object, null on failure
1068 * 1085 *
1069 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 1086 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1070 * to update reference counts and delete complex objects such 1087 * to update reference counts and delete complex objects such
@@ -1104,11 +1121,10 @@ acpi_ut_create_update_state (
1104 * 1121 *
1105 * FUNCTION: acpi_ut_create_pkg_state 1122 * FUNCTION: acpi_ut_create_pkg_state
1106 * 1123 *
1107 * PARAMETERS: Object - Initial Object to be installed in the 1124 * PARAMETERS: Object - Initial Object to be installed in the state
1108 * state 1125 * Action - Update action to be performed
1109 * Action - Update action to be performed
1110 * 1126 *
1111 * RETURN: Status 1127 * RETURN: New state object, null on failure
1112 * 1128 *
1113 * DESCRIPTION: Create a "Package State" 1129 * DESCRIPTION: Create a "Package State"
1114 * 1130 *
@@ -1151,7 +1167,7 @@ acpi_ut_create_pkg_state (
1151 * 1167 *
1152 * PARAMETERS: None 1168 * PARAMETERS: None
1153 * 1169 *
1154 * RETURN: Status 1170 * RETURN: New state object, null on failure
1155 * 1171 *
1156 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 1172 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1157 * to support nested IF/WHILE constructs in the AML. 1173 * to support nested IF/WHILE constructs in the AML.
@@ -1190,7 +1206,7 @@ acpi_ut_create_control_state (
1190 * 1206 *
1191 * PARAMETERS: State - The state object to be deleted 1207 * PARAMETERS: State - The state object to be deleted
1192 * 1208 *
1193 * RETURN: Status 1209 * RETURN: None
1194 * 1210 *
1195 * DESCRIPTION: Put a state object back into the global state cache. The object 1211 * DESCRIPTION: Put a state object back into the global state cache. The object
1196 * is not actually freed at this time. 1212 * is not actually freed at this time.
@@ -1216,7 +1232,7 @@ acpi_ut_delete_generic_state (
1216 * 1232 *
1217 * PARAMETERS: None 1233 * PARAMETERS: None
1218 * 1234 *
1219 * RETURN: Status 1235 * RETURN: None
1220 * 1236 *
1221 * DESCRIPTION: Purge the global state object cache. Used during subsystem 1237 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1222 * termination. 1238 * termination.
@@ -1240,7 +1256,10 @@ acpi_ut_delete_generic_state_cache (
1240 * 1256 *
1241 * FUNCTION: acpi_ut_walk_package_tree 1257 * FUNCTION: acpi_ut_walk_package_tree
1242 * 1258 *
1243 * PARAMETERS: obj_desc - The Package object on which to resolve refs 1259 * PARAMETERS: source_object - The package to walk
1260 * target_object - Target object (if package is being copied)
1261 * walk_callback - Called once for each package element
1262 * Context - Passed to the callback function
1244 * 1263 *
1245 * RETURN: Status 1264 * RETURN: Status
1246 * 1265 *
@@ -1359,7 +1378,7 @@ acpi_ut_walk_package_tree (
1359 * PARAMETERS: Buffer - Buffer to be scanned 1378 * PARAMETERS: Buffer - Buffer to be scanned
1360 * Length - number of bytes to examine 1379 * Length - number of bytes to examine
1361 * 1380 *
1362 * RETURN: checksum 1381 * RETURN: The generated checksum
1363 * 1382 *
1364 * DESCRIPTION: Generate a checksum on a raw buffer 1383 * DESCRIPTION: Generate a checksum on a raw buffer
1365 * 1384 *
@@ -1442,7 +1461,6 @@ acpi_ut_get_resource_end_tag (
1442 * PARAMETERS: module_name - Caller's module name (for error output) 1461 * PARAMETERS: module_name - Caller's module name (for error output)
1443 * line_number - Caller's line number (for error output) 1462 * line_number - Caller's line number (for error output)
1444 * component_id - Caller's component ID (for error output) 1463 * component_id - Caller's component ID (for error output)
1445 * Message - Error message to use on failure
1446 * 1464 *
1447 * RETURN: None 1465 * RETURN: None
1448 * 1466 *
@@ -1457,7 +1475,6 @@ acpi_ut_report_error (
1457 u32 component_id) 1475 u32 component_id)
1458{ 1476{
1459 1477
1460
1461 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number); 1478 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
1462} 1479}
1463 1480
@@ -1469,7 +1486,6 @@ acpi_ut_report_error (
1469 * PARAMETERS: module_name - Caller's module name (for error output) 1486 * PARAMETERS: module_name - Caller's module name (for error output)
1470 * line_number - Caller's line number (for error output) 1487 * line_number - Caller's line number (for error output)
1471 * component_id - Caller's component ID (for error output) 1488 * component_id - Caller's component ID (for error output)
1472 * Message - Error message to use on failure
1473 * 1489 *
1474 * RETURN: None 1490 * RETURN: None
1475 * 1491 *
@@ -1495,7 +1511,6 @@ acpi_ut_report_warning (
1495 * PARAMETERS: module_name - Caller's module name (for error output) 1511 * PARAMETERS: module_name - Caller's module name (for error output)
1496 * line_number - Caller's line number (for error output) 1512 * line_number - Caller's line number (for error output)
1497 * component_id - Caller's component ID (for error output) 1513 * component_id - Caller's component ID (for error output)
1498 * Message - Error message to use on failure
1499 * 1514 *
1500 * RETURN: None 1515 * RETURN: None
1501 * 1516 *
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index 9ee40a484e07..cd3899b9cc5a 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -50,6 +50,25 @@
50#define _COMPONENT ACPI_UTILITIES 50#define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utobject") 51 ACPI_MODULE_NAME ("utobject")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_ut_get_simple_object_size (
57 union acpi_operand_object *obj,
58 acpi_size *obj_length);
59
60static acpi_status
61acpi_ut_get_package_object_size (
62 union acpi_operand_object *obj,
63 acpi_size *obj_length);
64
65static acpi_status
66acpi_ut_get_element_length (
67 u8 object_type,
68 union acpi_operand_object *source_object,
69 union acpi_generic_state *state,
70 void *context);
71
53 72
54/******************************************************************************* 73/*******************************************************************************
55 * 74 *
@@ -60,7 +79,7 @@
60 * component_id - Component type of caller 79 * component_id - Component type of caller
61 * Type - ACPI Type of the new object 80 * Type - ACPI Type of the new object
62 * 81 *
63 * RETURN: Object - The new object. Null on failure 82 * RETURN: A new internal object, null on failure
64 * 83 *
65 * DESCRIPTION: Create and initialize a new internal object. 84 * DESCRIPTION: Create and initialize a new internal object.
66 * 85 *
@@ -83,7 +102,8 @@ acpi_ut_create_internal_object_dbg (
83 union acpi_operand_object *second_object; 102 union acpi_operand_object *second_object;
84 103
85 104
86 ACPI_FUNCTION_TRACE_STR ("ut_create_internal_object_dbg", acpi_ut_get_type_name (type)); 105 ACPI_FUNCTION_TRACE_STR ("ut_create_internal_object_dbg",
106 acpi_ut_get_type_name (type));
87 107
88 108
89 /* Allocate the raw object descriptor */ 109 /* Allocate the raw object descriptor */
@@ -99,7 +119,8 @@ acpi_ut_create_internal_object_dbg (
99 119
100 /* These types require a secondary object */ 120 /* These types require a secondary object */
101 121
102 second_object = acpi_ut_allocate_object_desc_dbg (module_name, line_number, component_id); 122 second_object = acpi_ut_allocate_object_desc_dbg (module_name,
123 line_number, component_id);
103 if (!second_object) { 124 if (!second_object) {
104 acpi_ut_delete_object_desc (object); 125 acpi_ut_delete_object_desc (object);
105 return_PTR (NULL); 126 return_PTR (NULL);
@@ -138,7 +159,7 @@ acpi_ut_create_internal_object_dbg (
138 * 159 *
139 * PARAMETERS: buffer_size - Size of buffer to be created 160 * PARAMETERS: buffer_size - Size of buffer to be created
140 * 161 *
141 * RETURN: Pointer to a new Buffer object 162 * RETURN: Pointer to a new Buffer object, null on failure
142 * 163 *
143 * DESCRIPTION: Create a fully initialized buffer object 164 * DESCRIPTION: Create a fully initialized buffer object
144 * 165 *
@@ -192,9 +213,9 @@ acpi_ut_create_buffer_object (
192 * 213 *
193 * FUNCTION: acpi_ut_create_string_object 214 * FUNCTION: acpi_ut_create_string_object
194 * 215 *
195 * PARAMETERS: string_size - Size of string to be created. Does not 216 * PARAMETERS: string_size - Size of string to be created. Does not
196 * include NULL terminator, this is added 217 * include NULL terminator, this is added
197 * automatically. 218 * automatically.
198 * 219 *
199 * RETURN: Pointer to a new String object 220 * RETURN: Pointer to a new String object
200 * 221 *
@@ -249,7 +270,9 @@ acpi_ut_create_string_object (
249 * 270 *
250 * PARAMETERS: Object - Object to be validated 271 * PARAMETERS: Object - Object to be validated
251 * 272 *
252 * RETURN: Validate a pointer to be an union acpi_operand_object 273 * RETURN: TRUE if object is valid, FALSE otherwise
274 *
275 * DESCRIPTION: Validate a pointer to be an union acpi_operand_object
253 * 276 *
254 ******************************************************************************/ 277 ******************************************************************************/
255 278
@@ -399,8 +422,8 @@ acpi_ut_delete_object_cache (
399 * 422 *
400 * FUNCTION: acpi_ut_get_simple_object_size 423 * FUNCTION: acpi_ut_get_simple_object_size
401 * 424 *
402 * PARAMETERS: *internal_object - Pointer to the object we are examining 425 * PARAMETERS: internal_object - An ACPI operand object
403 * *obj_length - Where the length is returned 426 * obj_length - Where the length is returned
404 * 427 *
405 * RETURN: Status 428 * RETURN: Status
406 * 429 *
@@ -412,7 +435,7 @@ acpi_ut_delete_object_cache (
412 * 435 *
413 ******************************************************************************/ 436 ******************************************************************************/
414 437
415acpi_status 438static acpi_status
416acpi_ut_get_simple_object_size ( 439acpi_ut_get_simple_object_size (
417 union acpi_operand_object *internal_object, 440 union acpi_operand_object *internal_object,
418 acpi_size *obj_length) 441 acpi_size *obj_length)
@@ -424,8 +447,10 @@ acpi_ut_get_simple_object_size (
424 ACPI_FUNCTION_TRACE_PTR ("ut_get_simple_object_size", internal_object); 447 ACPI_FUNCTION_TRACE_PTR ("ut_get_simple_object_size", internal_object);
425 448
426 449
427 /* Handle a null object (Could be a uninitialized package element -- which is legal) */ 450 /*
428 451 * Handle a null object (Could be a uninitialized package
452 * element -- which is legal)
453 */
429 if (!internal_object) { 454 if (!internal_object) {
430 *obj_length = 0; 455 *obj_length = 0;
431 return_ACPI_STATUS (AE_OK); 456 return_ACPI_STATUS (AE_OK);
@@ -480,7 +505,8 @@ acpi_ut_get_simple_object_size (
480 * Get the actual length of the full pathname to this object. 505 * Get the actual length of the full pathname to this object.
481 * The reference will be converted to the pathname to the object 506 * The reference will be converted to the pathname to the object
482 */ 507 */
483 length += ACPI_ROUND_UP_TO_NATIVE_WORD (acpi_ns_get_pathname_length (internal_object->reference.node)); 508 length += ACPI_ROUND_UP_TO_NATIVE_WORD (
509 acpi_ns_get_pathname_length (internal_object->reference.node));
484 break; 510 break;
485 511
486 default: 512 default:
@@ -530,7 +556,7 @@ acpi_ut_get_simple_object_size (
530 * 556 *
531 ******************************************************************************/ 557 ******************************************************************************/
532 558
533acpi_status 559static acpi_status
534acpi_ut_get_element_length ( 560acpi_ut_get_element_length (
535 u8 object_type, 561 u8 object_type,
536 union acpi_operand_object *source_object, 562 union acpi_operand_object *source_object,
@@ -582,8 +608,8 @@ acpi_ut_get_element_length (
582 * 608 *
583 * FUNCTION: acpi_ut_get_package_object_size 609 * FUNCTION: acpi_ut_get_package_object_size
584 * 610 *
585 * PARAMETERS: *internal_object - Pointer to the object we are examining 611 * PARAMETERS: internal_object - An ACPI internal object
586 * *obj_length - Where the length is returned 612 * obj_length - Where the length is returned
587 * 613 *
588 * RETURN: Status 614 * RETURN: Status
589 * 615 *
@@ -595,7 +621,7 @@ acpi_ut_get_element_length (
595 * 621 *
596 ******************************************************************************/ 622 ******************************************************************************/
597 623
598acpi_status 624static acpi_status
599acpi_ut_get_package_object_size ( 625acpi_ut_get_package_object_size (
600 union acpi_operand_object *internal_object, 626 union acpi_operand_object *internal_object,
601 acpi_size *obj_length) 627 acpi_size *obj_length)
@@ -636,8 +662,8 @@ acpi_ut_get_package_object_size (
636 * 662 *
637 * FUNCTION: acpi_ut_get_object_size 663 * FUNCTION: acpi_ut_get_object_size
638 * 664 *
639 * PARAMETERS: *internal_object - Pointer to the object we are examining 665 * PARAMETERS: internal_object - An ACPI internal object
640 * *obj_length - Where the length will be returned 666 * obj_length - Where the length will be returned
641 * 667 *
642 * RETURN: Status 668 * RETURN: Status
643 * 669 *
@@ -647,7 +673,7 @@ acpi_ut_get_package_object_size (
647 ******************************************************************************/ 673 ******************************************************************************/
648 674
649acpi_status 675acpi_status
650acpi_ut_get_object_size( 676acpi_ut_get_object_size (
651 union acpi_operand_object *internal_object, 677 union acpi_operand_object *internal_object,
652 acpi_size *obj_length) 678 acpi_size *obj_length)
653{ 679{
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index 97a91f3f06f0..e8803d810656 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -73,6 +73,7 @@ acpi_initialize_subsystem (
73{ 73{
74 acpi_status status; 74 acpi_status status;
75 75
76
76 ACPI_FUNCTION_TRACE ("acpi_initialize_subsystem"); 77 ACPI_FUNCTION_TRACE ("acpi_initialize_subsystem");
77 78
78 79
@@ -105,7 +106,6 @@ acpi_initialize_subsystem (
105 * Initialize the namespace manager and 106 * Initialize the namespace manager and
106 * the root of the namespace tree 107 * the root of the namespace tree
107 */ 108 */
108
109 status = acpi_ns_root_initialize (); 109 status = acpi_ns_root_initialize ();
110 if (ACPI_FAILURE (status)) { 110 if (ACPI_FAILURE (status)) {
111 ACPI_REPORT_ERROR (("Namespace initialization failure, %s\n", 111 ACPI_REPORT_ERROR (("Namespace initialization failure, %s\n",
@@ -113,7 +113,6 @@ acpi_initialize_subsystem (
113 return_ACPI_STATUS (status); 113 return_ACPI_STATUS (status);
114 } 114 }
115 115
116
117 /* If configured, initialize the AML debugger */ 116 /* If configured, initialize the AML debugger */
118 117
119 ACPI_DEBUGGER_EXEC (status = acpi_db_initialize ()); 118 ACPI_DEBUGGER_EXEC (status = acpi_db_initialize ());
@@ -150,7 +149,8 @@ acpi_enable_subsystem (
150 * The values from the FADT are validated here. 149 * The values from the FADT are validated here.
151 */ 150 */
152 if (!(flags & ACPI_NO_HARDWARE_INIT)) { 151 if (!(flags & ACPI_NO_HARDWARE_INIT)) {
153 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI hardware\n")); 152 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
153 "[Init] Initializing ACPI hardware\n"));
154 154
155 status = acpi_hw_initialize (); 155 status = acpi_hw_initialize ();
156 if (ACPI_FAILURE (status)) { 156 if (ACPI_FAILURE (status)) {
@@ -178,7 +178,8 @@ acpi_enable_subsystem (
178 * install_address_space_handler interface. 178 * install_address_space_handler interface.
179 */ 179 */
180 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 180 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
181 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing default address space handlers\n")); 181 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
182 "[Init] Installing default address space handlers\n"));
182 183
183 status = acpi_ev_install_region_handlers (); 184 status = acpi_ev_install_region_handlers ();
184 if (ACPI_FAILURE (status)) { 185 if (ACPI_FAILURE (status)) {
@@ -189,12 +190,14 @@ acpi_enable_subsystem (
189 /* 190 /*
190 * Initialize ACPI Event handling (Fixed and General Purpose) 191 * Initialize ACPI Event handling (Fixed and General Purpose)
191 * 192 *
192 * NOTE: We must have the hardware AND events initialized before we can execute 193 * NOTE: We must have the hardware AND events initialized before we can
193 * ANY control methods SAFELY. Any control method can require ACPI hardware 194 * execute ANY control methods SAFELY. Any control method can require
194 * support, so the hardware MUST be initialized before execution! 195 * ACPI hardware support, so the hardware MUST be initialized before
196 * execution!
195 */ 197 */
196 if (!(flags & ACPI_NO_EVENT_INIT)) { 198 if (!(flags & ACPI_NO_EVENT_INIT)) {
197 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI events\n")); 199 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
200 "[Init] Initializing ACPI events\n"));
198 201
199 status = acpi_ev_initialize_events (); 202 status = acpi_ev_initialize_events ();
200 if (ACPI_FAILURE (status)) { 203 if (ACPI_FAILURE (status)) {
@@ -205,7 +208,8 @@ acpi_enable_subsystem (
205 /* Install the SCI handler and Global Lock handler */ 208 /* Install the SCI handler and Global Lock handler */
206 209
207 if (!(flags & ACPI_NO_HANDLER_INIT)) { 210 if (!(flags & ACPI_NO_HANDLER_INIT)) {
208 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing SCI/GL handlers\n")); 211 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
212 "[Init] Installing SCI/GL handlers\n"));
209 213
210 status = acpi_ev_install_xrupt_handlers (); 214 status = acpi_ev_install_xrupt_handlers ();
211 if (ACPI_FAILURE (status)) { 215 if (ACPI_FAILURE (status)) {
@@ -247,7 +251,8 @@ acpi_initialize_objects (
247 * contain executable AML (see call to acpi_ns_initialize_objects below). 251 * contain executable AML (see call to acpi_ns_initialize_objects below).
248 */ 252 */
249 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 253 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
250 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Executing _REG op_region methods\n")); 254 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
255 "[Init] Executing _REG op_region methods\n"));
251 256
252 status = acpi_ev_initialize_op_regions (); 257 status = acpi_ev_initialize_op_regions ();
253 if (ACPI_FAILURE (status)) { 258 if (ACPI_FAILURE (status)) {
@@ -261,7 +266,8 @@ acpi_initialize_objects (
261 * objects: operation_regions, buffer_fields, Buffers, and Packages. 266 * objects: operation_regions, buffer_fields, Buffers, and Packages.
262 */ 267 */
263 if (!(flags & ACPI_NO_OBJECT_INIT)) { 268 if (!(flags & ACPI_NO_OBJECT_INIT)) {
264 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Completing Initialization of ACPI Objects\n")); 269 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
270 "[Init] Completing Initialization of ACPI Objects\n"));
265 271
266 status = acpi_ns_initialize_objects (); 272 status = acpi_ns_initialize_objects ();
267 if (ACPI_FAILURE (status)) { 273 if (ACPI_FAILURE (status)) {
@@ -274,7 +280,8 @@ acpi_initialize_objects (
274 * This runs the _STA and _INI methods. 280 * This runs the _STA and _INI methods.
275 */ 281 */
276 if (!(flags & ACPI_NO_DEVICE_INIT)) { 282 if (!(flags & ACPI_NO_DEVICE_INIT)) {
277 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI Devices\n")); 283 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
284 "[Init] Initializing ACPI Devices\n"));
278 285
279 status = acpi_ns_initialize_devices (); 286 status = acpi_ns_initialize_devices ();
280 if (ACPI_FAILURE (status)) { 287 if (ACPI_FAILURE (status)) {
@@ -307,7 +314,8 @@ acpi_initialize_objects (
307 ******************************************************************************/ 314 ******************************************************************************/
308 315
309acpi_status 316acpi_status
310acpi_terminate (void) 317acpi_terminate (
318 void)
311{ 319{
312 acpi_status status; 320 acpi_status status;
313 321
@@ -344,8 +352,7 @@ acpi_terminate (void)
344 352
345 353
346#ifdef ACPI_FUTURE_USAGE 354#ifdef ACPI_FUTURE_USAGE
347 355/*******************************************************************************
348/*****************************************************************************
349 * 356 *
350 * FUNCTION: acpi_subsystem_status 357 * FUNCTION: acpi_subsystem_status
351 * 358 *
@@ -354,14 +361,16 @@ acpi_terminate (void)
354 * RETURN: Status of the ACPI subsystem 361 * RETURN: Status of the ACPI subsystem
355 * 362 *
356 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this 363 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
357 * before making any other calls, to ensure the subsystem initial- 364 * before making any other calls, to ensure the subsystem
358 * ized successfully. 365 * initialized successfully.
359 * 366 *
360 ****************************************************************************/ 367 ******************************************************************************/
361 368
362acpi_status 369acpi_status
363acpi_subsystem_status (void) 370acpi_subsystem_status (
371 void)
364{ 372{
373
365 if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) { 374 if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) {
366 return (AE_OK); 375 return (AE_OK);
367 } 376 }
@@ -371,13 +380,12 @@ acpi_subsystem_status (void)
371} 380}
372 381
373 382
374/****************************************************************************** 383/*******************************************************************************
375 * 384 *
376 * FUNCTION: acpi_get_system_info 385 * FUNCTION: acpi_get_system_info
377 * 386 *
378 * PARAMETERS: out_buffer - a pointer to a buffer to receive the 387 * PARAMETERS: out_buffer - A buffer to receive the resources for the
379 * resources for the device 388 * device
380 * buffer_length - the number of bytes available in the buffer
381 * 389 *
382 * RETURN: Status - the status of the call 390 * RETURN: Status - the status of the call
383 * 391 *
@@ -395,8 +403,8 @@ acpi_get_system_info (
395 struct acpi_buffer *out_buffer) 403 struct acpi_buffer *out_buffer)
396{ 404{
397 struct acpi_system_info *info_ptr; 405 struct acpi_system_info *info_ptr;
398 u32 i;
399 acpi_status status; 406 acpi_status status;
407 u32 i;
400 408
401 409
402 ACPI_FUNCTION_TRACE ("acpi_get_system_info"); 410 ACPI_FUNCTION_TRACE ("acpi_get_system_info");
@@ -466,6 +474,7 @@ EXPORT_SYMBOL(acpi_get_system_info);
466 * FUNCTION: acpi_install_initialization_handler 474 * FUNCTION: acpi_install_initialization_handler
467 * 475 *
468 * PARAMETERS: Handler - Callback procedure 476 * PARAMETERS: Handler - Callback procedure
477 * Function - Not (currently) used, see below
469 * 478 *
470 * RETURN: Status 479 * RETURN: Status
471 * 480 *
@@ -495,7 +504,6 @@ acpi_install_initialization_handler (
495 504
496#endif /* ACPI_FUTURE_USAGE */ 505#endif /* ACPI_FUTURE_USAGE */
497 506
498
499/***************************************************************************** 507/*****************************************************************************
500 * 508 *
501 * FUNCTION: acpi_purge_cached_objects 509 * FUNCTION: acpi_purge_cached_objects
@@ -509,7 +517,8 @@ acpi_install_initialization_handler (
509 ****************************************************************************/ 517 ****************************************************************************/
510 518
511acpi_status 519acpi_status
512acpi_purge_cached_objects (void) 520acpi_purge_cached_objects (
521 void)
513{ 522{
514 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects"); 523 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects");
515 524
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 71fa1011715f..2cf264fd52e0 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -564,12 +564,13 @@ acpi_video_device_find_cap (struct acpi_video_device *device)
564 int count = 0; 564 int count = 0;
565 union acpi_object *o; 565 union acpi_object *o;
566 566
567 br = kmalloc(sizeof &br, GFP_KERNEL); 567 br = kmalloc(sizeof(*br), GFP_KERNEL);
568 if (!br) { 568 if (!br) {
569 printk(KERN_ERR "can't allocate memory\n"); 569 printk(KERN_ERR "can't allocate memory\n");
570 } else { 570 } else {
571 memset(br, 0, sizeof &br); 571 memset(br, 0, sizeof(*br));
572 br->levels = kmalloc(obj->package.count * sizeof &br->levels, GFP_KERNEL); 572 br->levels = kmalloc(obj->package.count *
573 sizeof *(br->levels), GFP_KERNEL);
573 if (!br->levels) 574 if (!br->levels)
574 goto out; 575 goto out;
575 576
@@ -584,8 +585,7 @@ acpi_video_device_find_cap (struct acpi_video_device *device)
584 } 585 }
585out: 586out:
586 if (count < 2) { 587 if (count < 2) {
587 if (br->levels) 588 kfree(br->levels);
588 kfree(br->levels);
589 kfree(br); 589 kfree(br);
590 } else { 590 } else {
591 br->count = count; 591 br->count = count;
@@ -595,8 +595,7 @@ out:
595 } 595 }
596 } 596 }
597 597
598 if (obj) 598 kfree(obj);
599 kfree(obj);
600 599
601 return_VOID; 600 return_VOID;
602} 601}
@@ -1585,7 +1584,7 @@ acpi_video_switch_output(
1585 ACPI_FUNCTION_TRACE("acpi_video_switch_output"); 1584 ACPI_FUNCTION_TRACE("acpi_video_switch_output");
1586 1585
1587 list_for_each_safe(node, next, &video->video_device_list) { 1586 list_for_each_safe(node, next, &video->video_device_list) {
1588 struct acpi_video_device * dev = container_of(node, struct acpi_video_device, entry); 1587 dev = container_of(node, struct acpi_video_device, entry);
1589 status = acpi_video_device_get_state(dev, &state); 1588 status = acpi_video_device_get_state(dev, &state);
1590 if (state & 0x2){ 1589 if (state & 0x2){
1591 dev_next = container_of(node->next, struct acpi_video_device, entry); 1590 dev_next = container_of(node->next, struct acpi_video_device, entry);
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index c46d9520c5a7..73c6b85299c1 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -794,7 +794,9 @@ static void drain_rx_pools (amb_dev * dev) {
794 drain_rx_pool (dev, pool); 794 drain_rx_pool (dev, pool);
795} 795}
796 796
797static inline void fill_rx_pool (amb_dev * dev, unsigned char pool, int priority) { 797static inline void fill_rx_pool (amb_dev * dev, unsigned char pool,
798 unsigned int __nocast priority)
799{
798 rx_in rx; 800 rx_in rx;
799 amb_rxq * rxq; 801 amb_rxq * rxq;
800 802
diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
index 101f0cc33d10..b078fa548ebf 100644
--- a/drivers/atm/firestream.c
+++ b/drivers/atm/firestream.c
@@ -1374,7 +1374,8 @@ static void reset_chip (struct fs_dev *dev)
1374 } 1374 }
1375} 1375}
1376 1376
1377static void __devinit *aligned_kmalloc (int size, int flags, int alignment) 1377static void __devinit *aligned_kmalloc (int size, unsigned int __nocast flags,
1378 int alignment)
1378{ 1379{
1379 void *t; 1380 void *t;
1380 1381
@@ -1464,7 +1465,8 @@ static inline int nr_buffers_in_freepool (struct fs_dev *dev, struct freepool *f
1464 does. I've seen "receive abort: no buffers" and things started 1465 does. I've seen "receive abort: no buffers" and things started
1465 working again after that... -- REW */ 1466 working again after that... -- REW */
1466 1467
1467static void top_off_fp (struct fs_dev *dev, struct freepool *fp, int gfp_flags) 1468static void top_off_fp (struct fs_dev *dev, struct freepool *fp,
1469 unsigned int __nocast gfp_flags)
1468{ 1470{
1469 struct FS_BPENTRY *qe, *ne; 1471 struct FS_BPENTRY *qe, *ne;
1470 struct sk_buff *skb; 1472 struct sk_buff *skb;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index df2c83fd5496..28250c9b32d6 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -57,7 +57,6 @@
57 57
58#include <linux/config.h> 58#include <linux/config.h>
59#include <linux/module.h> 59#include <linux/module.h>
60#include <linux/version.h>
61#include <linux/kernel.h> 60#include <linux/kernel.h>
62#include <linux/skbuff.h> 61#include <linux/skbuff.h>
63#include <linux/pci.h> 62#include <linux/pci.h>
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index baaf1a3d2242..30b7e990ed0b 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -46,6 +46,7 @@ static char const rcsid[] =
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/bitops.h> 47#include <linux/bitops.h>
48#include <linux/wait.h> 48#include <linux/wait.h>
49#include <linux/jiffies.h>
49#include <asm/semaphore.h> 50#include <asm/semaphore.h>
50#include <asm/io.h> 51#include <asm/io.h>
51#include <asm/uaccess.h> 52#include <asm/uaccess.h>
@@ -780,7 +781,7 @@ push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
780 return 0; 781 return 0;
781 782
782out: 783out:
783 if (jiffies - scq->trans_start > HZ) { 784 if (time_after(jiffies, scq->trans_start + HZ)) {
784 printk("%s: Error pushing TBD for %d.%d\n", 785 printk("%s: Error pushing TBD for %d.%d\n",
785 card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci); 786 card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci);
786#ifdef CONFIG_ATM_IDT77252_DEBUG 787#ifdef CONFIG_ATM_IDT77252_DEBUG
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 8d5e65cb9755..a2b236a966e0 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -16,9 +16,9 @@
16#include <linux/skbuff.h> 16#include <linux/skbuff.h>
17#include <linux/netdevice.h> 17#include <linux/netdevice.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/ioport.h> /* for request_region */
20#include <linux/uio.h> 19#include <linux/uio.h>
21#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/dma-mapping.h>
22#include <linux/atm_zatm.h> 22#include <linux/atm_zatm.h>
23#include <linux/capability.h> 23#include <linux/capability.h>
24#include <linux/bitops.h> 24#include <linux/bitops.h>
@@ -1257,22 +1257,22 @@ static int __init zatm_init(struct atm_dev *dev)
1257 1257
1258static int __init zatm_start(struct atm_dev *dev) 1258static int __init zatm_start(struct atm_dev *dev)
1259{ 1259{
1260 struct zatm_dev *zatm_dev; 1260 struct zatm_dev *zatm_dev = ZATM_DEV(dev);
1261 struct pci_dev *pdev = zatm_dev->pci_dev;
1261 unsigned long curr; 1262 unsigned long curr;
1262 int pools,vccs,rx; 1263 int pools,vccs,rx;
1263 int error,i,ld; 1264 int error, i, ld;
1264 1265
1265 DPRINTK("zatm_start\n"); 1266 DPRINTK("zatm_start\n");
1266 zatm_dev = ZATM_DEV(dev);
1267 zatm_dev->rx_map = zatm_dev->tx_map = NULL; 1267 zatm_dev->rx_map = zatm_dev->tx_map = NULL;
1268 for (i = 0; i < NR_MBX; i++) 1268 for (i = 0; i < NR_MBX; i++)
1269 zatm_dev->mbx_start[i] = 0; 1269 zatm_dev->mbx_start[i] = 0;
1270 if (request_irq(zatm_dev->irq,&zatm_int,SA_SHIRQ,DEV_LABEL,dev)) { 1270 error = request_irq(zatm_dev->irq, zatm_int, SA_SHIRQ, DEV_LABEL, dev);
1271 printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n", 1271 if (error < 0) {
1272 dev->number,zatm_dev->irq); 1272 printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
1273 return -EAGAIN; 1273 dev->number,zatm_dev->irq);
1274 goto done;
1274 } 1275 }
1275 request_region(zatm_dev->base,uPD98401_PORTS,DEV_LABEL);
1276 /* define memory regions */ 1276 /* define memory regions */
1277 pools = NR_POOLS; 1277 pools = NR_POOLS;
1278 if (NR_SHAPERS*SHAPER_SIZE > pools*POOL_SIZE) 1278 if (NR_SHAPERS*SHAPER_SIZE > pools*POOL_SIZE)
@@ -1299,51 +1299,66 @@ static int __init zatm_start(struct atm_dev *dev)
1299 "%ld VCs\n",dev->number,NR_SHAPERS,pools,rx, 1299 "%ld VCs\n",dev->number,NR_SHAPERS,pools,rx,
1300 (zatm_dev->mem-curr*4)/VC_SIZE); 1300 (zatm_dev->mem-curr*4)/VC_SIZE);
1301 /* create mailboxes */ 1301 /* create mailboxes */
1302 for (i = 0; i < NR_MBX; i++) 1302 for (i = 0; i < NR_MBX; i++) {
1303 if (mbx_entries[i]) { 1303 void *mbx;
1304 unsigned long here; 1304 dma_addr_t mbx_dma;
1305 1305
1306 here = (unsigned long) kmalloc(2*MBX_SIZE(i), 1306 if (!mbx_entries[i])
1307 GFP_KERNEL); 1307 continue;
1308 if (!here) { 1308 mbx = pci_alloc_consistent(pdev, 2*MBX_SIZE(i), &mbx_dma);
1309 error = -ENOMEM; 1309 if (!mbx) {
1310 goto out; 1310 error = -ENOMEM;
1311 } 1311 goto out;
1312 if ((here^(here+MBX_SIZE(i))) & ~0xffffUL)/* paranoia */
1313 here = (here & ~0xffffUL)+0x10000;
1314 zatm_dev->mbx_start[i] = here;
1315 if ((here^virt_to_bus((void *) here)) & 0xffff) {
1316 printk(KERN_ERR DEV_LABEL "(itf %d): system "
1317 "bus incompatible with driver\n",
1318 dev->number);
1319 error = -ENODEV;
1320 goto out;
1321 }
1322 DPRINTK("mbx@0x%08lx-0x%08lx\n",here,here+MBX_SIZE(i));
1323 zatm_dev->mbx_end[i] = (here+MBX_SIZE(i)) & 0xffff;
1324 zout(virt_to_bus((void *) here) >> 16,MSH(i));
1325 zout(virt_to_bus((void *) here),MSL(i));
1326 zout((here+MBX_SIZE(i)) & 0xffff,MBA(i));
1327 zout(here & 0xffff,MTA(i));
1328 zout(here & 0xffff,MWA(i));
1329 } 1312 }
1313 /*
1314 * Alignment provided by pci_alloc_consistent() isn't enough
1315 * for this device.
1316 */
1317 if (((unsigned long)mbx ^ mbx_dma) & 0xffff) {
1318 printk(KERN_ERR DEV_LABEL "(itf %d): system "
1319 "bus incompatible with driver\n", dev->number);
1320 pci_free_consistent(pdev, 2*MBX_SIZE(i), mbx, mbx_dma);
1321 error = -ENODEV;
1322 goto out;
1323 }
1324 DPRINTK("mbx@0x%08lx-0x%08lx\n", mbx, mbx + MBX_SIZE(i));
1325 zatm_dev->mbx_start[i] = (unsigned long)mbx;
1326 zatm_dev->mbx_dma[i] = mbx_dma;
1327 zatm_dev->mbx_end[i] = (zatm_dev->mbx_start[i] + MBX_SIZE(i)) &
1328 0xffff;
1329 zout(mbx_dma >> 16, MSH(i));
1330 zout(mbx_dma, MSL(i));
1331 zout(zatm_dev->mbx_end[i], MBA(i));
1332 zout((unsigned long)mbx & 0xffff, MTA(i));
1333 zout((unsigned long)mbx & 0xffff, MWA(i));
1334 }
1330 error = start_tx(dev); 1335 error = start_tx(dev);
1331 if (error) goto out; 1336 if (error)
1337 goto out;
1332 error = start_rx(dev); 1338 error = start_rx(dev);
1333 if (error) goto out; 1339 if (error)
1340 goto out_tx;
1334 error = dev->phy->start(dev); 1341 error = dev->phy->start(dev);
1335 if (error) goto out; 1342 if (error)
1343 goto out_rx;
1336 zout(0xffffffff,IMR); /* enable interrupts */ 1344 zout(0xffffffff,IMR); /* enable interrupts */
1337 /* enable TX & RX */ 1345 /* enable TX & RX */
1338 zout(zin(GMR) | uPD98401_GMR_SE | uPD98401_GMR_RE,GMR); 1346 zout(zin(GMR) | uPD98401_GMR_SE | uPD98401_GMR_RE,GMR);
1339 return 0; 1347done:
1340 out: 1348 return error;
1341 for (i = 0; i < NR_MBX; i++) 1349
1342 kfree(zatm_dev->mbx_start[i]); 1350out_rx:
1343 kfree(zatm_dev->rx_map); 1351 kfree(zatm_dev->rx_map);
1352out_tx:
1344 kfree(zatm_dev->tx_map); 1353 kfree(zatm_dev->tx_map);
1354out:
1355 while (i-- > 0) {
1356 pci_free_consistent(pdev, 2*MBX_SIZE(i),
1357 (void *)zatm_dev->mbx_start[i],
1358 zatm_dev->mbx_dma[i]);
1359 }
1345 free_irq(zatm_dev->irq, dev); 1360 free_irq(zatm_dev->irq, dev);
1346 return error; 1361 goto done;
1347} 1362}
1348 1363
1349 1364
diff --git a/drivers/atm/zatm.h b/drivers/atm/zatm.h
index 34a0480f63d6..416fe0fda60c 100644
--- a/drivers/atm/zatm.h
+++ b/drivers/atm/zatm.h
@@ -73,6 +73,7 @@ struct zatm_dev {
73 int chans; /* map size, must be 2^n */ 73 int chans; /* map size, must be 2^n */
74 /*-------------------------------- mailboxes */ 74 /*-------------------------------- mailboxes */
75 unsigned long mbx_start[NR_MBX];/* start addresses */ 75 unsigned long mbx_start[NR_MBX];/* start addresses */
76 dma_addr_t mbx_dma[NR_MBX];
76 u16 mbx_end[NR_MBX]; /* end offset (in bytes) */ 77 u16 mbx_end[NR_MBX]; /* end offset (in bytes) */
77 /*-------------------------------- other pointers */ 78 /*-------------------------------- other pointers */
78 u32 pool_base; /* Free buffer pool dsc (word addr) */ 79 u32 pool_base; /* Free buffer pool dsc (word addr) */
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 645f62692920..783752b68a9a 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -5,6 +5,7 @@ extern int bus_add_driver(struct device_driver *);
5extern void bus_remove_driver(struct device_driver *); 5extern void bus_remove_driver(struct device_driver *);
6 6
7extern void driver_detach(struct device_driver * drv); 7extern void driver_detach(struct device_driver * drv);
8extern int driver_probe_device(struct device_driver *, struct device *);
8 9
9static inline struct class_device *to_class_dev(struct kobject *obj) 10static inline struct class_device *to_class_dev(struct kobject *obj)
10{ 11{
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index c3fac7fd555e..96fe2f956754 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -133,6 +133,58 @@ static struct kobj_type ktype_bus = {
133decl_subsys(bus, &ktype_bus, NULL); 133decl_subsys(bus, &ktype_bus, NULL);
134 134
135 135
136/* Manually detach a device from it's associated driver. */
137static int driver_helper(struct device *dev, void *data)
138{
139 const char *name = data;
140
141 if (strcmp(name, dev->bus_id) == 0)
142 return 1;
143 return 0;
144}
145
146static ssize_t driver_unbind(struct device_driver *drv,
147 const char *buf, size_t count)
148{
149 struct bus_type *bus = get_bus(drv->bus);
150 struct device *dev;
151 int err = -ENODEV;
152
153 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
154 if ((dev) &&
155 (dev->driver == drv)) {
156 device_release_driver(dev);
157 err = count;
158 }
159 return err;
160}
161static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
162
163/*
164 * Manually attach a device to a driver.
165 * Note: the driver must want to bind to the device,
166 * it is not possible to override the driver's id table.
167 */
168static ssize_t driver_bind(struct device_driver *drv,
169 const char *buf, size_t count)
170{
171 struct bus_type *bus = get_bus(drv->bus);
172 struct device *dev;
173 int err = -ENODEV;
174
175 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
176 if ((dev) &&
177 (dev->driver == NULL)) {
178 down(&dev->sem);
179 err = driver_probe_device(drv, dev);
180 up(&dev->sem);
181 put_device(dev);
182 }
183 return err;
184}
185static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
186
187
136static struct device * next_device(struct klist_iter * i) 188static struct device * next_device(struct klist_iter * i)
137{ 189{
138 struct klist_node * n = klist_next(i); 190 struct klist_node * n = klist_next(i);
@@ -177,6 +229,39 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
177 return error; 229 return error;
178} 230}
179 231
232/**
233 * bus_find_device - device iterator for locating a particular device.
234 * @bus: bus type
235 * @start: Device to begin with
236 * @data: Data to pass to match function
237 * @match: Callback function to check device
238 *
239 * This is similar to the bus_for_each_dev() function above, but it
240 * returns a reference to a device that is 'found' for later use, as
241 * determined by the @match callback.
242 *
243 * The callback should return 0 if the device doesn't match and non-zero
244 * if it does. If the callback returns non-zero, this function will
245 * return to the caller and not iterate over any more devices.
246 */
247struct device * bus_find_device(struct bus_type *bus,
248 struct device *start, void *data,
249 int (*match)(struct device *, void *))
250{
251 struct klist_iter i;
252 struct device *dev;
253
254 if (!bus)
255 return NULL;
256
257 klist_iter_init_node(&bus->klist_devices, &i,
258 (start ? &start->knode_bus : NULL));
259 while ((dev = next_device(&i)))
260 if (match(dev, data) && get_device(dev))
261 break;
262 klist_iter_exit(&i);
263 return dev;
264}
180 265
181 266
182static struct device_driver * next_driver(struct klist_iter * i) 267static struct device_driver * next_driver(struct klist_iter * i)
@@ -363,6 +448,8 @@ int bus_add_driver(struct device_driver * drv)
363 module_add_driver(drv->owner, drv); 448 module_add_driver(drv->owner, drv);
364 449
365 driver_add_attrs(bus, drv); 450 driver_add_attrs(bus, drv);
451 driver_create_file(drv, &driver_attr_unbind);
452 driver_create_file(drv, &driver_attr_bind);
366 } 453 }
367 return error; 454 return error;
368} 455}
@@ -380,6 +467,8 @@ int bus_add_driver(struct device_driver * drv)
380void bus_remove_driver(struct device_driver * drv) 467void bus_remove_driver(struct device_driver * drv)
381{ 468{
382 if (drv->bus) { 469 if (drv->bus) {
470 driver_remove_file(drv, &driver_attr_bind);
471 driver_remove_file(drv, &driver_attr_unbind);
383 driver_remove_attrs(drv->bus, drv); 472 driver_remove_attrs(drv->bus, drv);
384 klist_remove(&drv->knode_bus); 473 klist_remove(&drv->knode_bus);
385 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); 474 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
@@ -394,31 +483,22 @@ void bus_remove_driver(struct device_driver * drv)
394/* Helper for bus_rescan_devices's iter */ 483/* Helper for bus_rescan_devices's iter */
395static int bus_rescan_devices_helper(struct device *dev, void *data) 484static int bus_rescan_devices_helper(struct device *dev, void *data)
396{ 485{
397 int *count = data; 486 if (!dev->driver)
398 487 device_attach(dev);
399 if (!dev->driver && (device_attach(dev) > 0))
400 (*count)++;
401
402 return 0; 488 return 0;
403} 489}
404 490
405
406/** 491/**
407 * bus_rescan_devices - rescan devices on the bus for possible drivers 492 * bus_rescan_devices - rescan devices on the bus for possible drivers
408 * @bus: the bus to scan. 493 * @bus: the bus to scan.
409 * 494 *
410 * This function will look for devices on the bus with no driver 495 * This function will look for devices on the bus with no driver
411 * attached and rescan it against existing drivers to see if it 496 * attached and rescan it against existing drivers to see if it matches
412 * matches any. Calls device_attach(). Returns the number of devices 497 * any by calling device_attach() for the unbound devices.
413 * that were sucessfully bound to a driver.
414 */ 498 */
415int bus_rescan_devices(struct bus_type * bus) 499void bus_rescan_devices(struct bus_type * bus)
416{ 500{
417 int count = 0; 501 bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
418
419 bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
420
421 return count;
422} 502}
423 503
424 504
@@ -557,6 +637,7 @@ int __init buses_init(void)
557 637
558 638
559EXPORT_SYMBOL_GPL(bus_for_each_dev); 639EXPORT_SYMBOL_GPL(bus_for_each_dev);
640EXPORT_SYMBOL_GPL(bus_find_device);
560EXPORT_SYMBOL_GPL(bus_for_each_drv); 641EXPORT_SYMBOL_GPL(bus_for_each_drv);
561 642
562EXPORT_SYMBOL_GPL(bus_add_device); 643EXPORT_SYMBOL_GPL(bus_add_device);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 86d79755fbfb..efe03a024a5b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -333,7 +333,7 @@ void device_del(struct device * dev)
333 struct device * parent = dev->parent; 333 struct device * parent = dev->parent;
334 334
335 if (parent) 335 if (parent)
336 klist_remove(&dev->knode_parent); 336 klist_del(&dev->knode_parent);
337 337
338 /* Notify the platform of the removal, in case they 338 /* Notify the platform of the removal, in case they
339 * need to do anything... 339 * need to do anything...
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 6db3a789c54f..16323f9cbff0 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -65,7 +65,7 @@ void device_bind_driver(struct device * dev)
65 * 65 *
66 * This function must be called with @dev->sem held. 66 * This function must be called with @dev->sem held.
67 */ 67 */
68static int driver_probe_device(struct device_driver * drv, struct device * dev) 68int driver_probe_device(struct device_driver * drv, struct device * dev)
69{ 69{
70 int ret = 0; 70 int ret = 0;
71 71
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1b645886e9eb..291c5954a3af 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -56,6 +56,41 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
56 56
57 57
58/** 58/**
59 * driver_find_device - device iterator for locating a particular device.
60 * @driver: The device's driver
61 * @start: Device to begin with
62 * @data: Data to pass to match function
63 * @match: Callback function to check device
64 *
65 * This is similar to the driver_for_each_device() function above, but
66 * it returns a reference to a device that is 'found' for later use, as
67 * determined by the @match callback.
68 *
69 * The callback should return 0 if the device doesn't match and non-zero
70 * if it does. If the callback returns non-zero, this function will
71 * return to the caller and not iterate over any more devices.
72 */
73struct device * driver_find_device(struct device_driver *drv,
74 struct device * start, void * data,
75 int (*match)(struct device *, void *))
76{
77 struct klist_iter i;
78 struct device *dev;
79
80 if (!drv)
81 return NULL;
82
83 klist_iter_init_node(&drv->klist_devices, &i,
84 (start ? &start->knode_driver : NULL));
85 while ((dev = next_device(&i)))
86 if (match(dev, data) && get_device(dev))
87 break;
88 klist_iter_exit(&i);
89 return dev;
90}
91EXPORT_SYMBOL_GPL(driver_find_device);
92
93/**
59 * driver_create_file - create sysfs file for driver. 94 * driver_create_file - create sysfs file for driver.
60 * @drv: driver. 95 * @drv: driver.
61 * @attr: driver attribute descriptor. 96 * @attr: driver attribute descriptor.
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 97fe13f7f07c..652281402c92 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -74,6 +74,8 @@ static ssize_t
74firmware_timeout_store(struct class *class, const char *buf, size_t count) 74firmware_timeout_store(struct class *class, const char *buf, size_t count)
75{ 75{
76 loading_timeout = simple_strtol(buf, NULL, 10); 76 loading_timeout = simple_strtol(buf, NULL, 10);
77 if (loading_timeout < 0)
78 loading_timeout = 0;
77 return count; 79 return count;
78} 80}
79 81
@@ -138,6 +140,10 @@ firmware_loading_store(struct class_device *class_dev,
138 switch (loading) { 140 switch (loading) {
139 case 1: 141 case 1:
140 down(&fw_lock); 142 down(&fw_lock);
143 if (!fw_priv->fw) {
144 up(&fw_lock);
145 break;
146 }
141 vfree(fw_priv->fw->data); 147 vfree(fw_priv->fw->data);
142 fw_priv->fw->data = NULL; 148 fw_priv->fw->data = NULL;
143 fw_priv->fw->size = 0; 149 fw_priv->fw->size = 0;
@@ -178,7 +184,7 @@ firmware_data_read(struct kobject *kobj,
178 184
179 down(&fw_lock); 185 down(&fw_lock);
180 fw = fw_priv->fw; 186 fw = fw_priv->fw;
181 if (test_bit(FW_STATUS_DONE, &fw_priv->status)) { 187 if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
182 ret_count = -ENODEV; 188 ret_count = -ENODEV;
183 goto out; 189 goto out;
184 } 190 }
@@ -238,9 +244,10 @@ firmware_data_write(struct kobject *kobj,
238 244
239 if (!capable(CAP_SYS_RAWIO)) 245 if (!capable(CAP_SYS_RAWIO))
240 return -EPERM; 246 return -EPERM;
247
241 down(&fw_lock); 248 down(&fw_lock);
242 fw = fw_priv->fw; 249 fw = fw_priv->fw;
243 if (test_bit(FW_STATUS_DONE, &fw_priv->status)) { 250 if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
244 retval = -ENODEV; 251 retval = -ENODEV;
245 goto out; 252 goto out;
246 } 253 }
@@ -418,7 +425,7 @@ request_firmware(const struct firmware **firmware_p, const char *name,
418 425
419 fw_priv = class_get_devdata(class_dev); 426 fw_priv = class_get_devdata(class_dev);
420 427
421 if (loading_timeout) { 428 if (loading_timeout > 0) {
422 fw_priv->timeout.expires = jiffies + loading_timeout * HZ; 429 fw_priv->timeout.expires = jiffies + loading_timeout * HZ;
423 add_timer(&fw_priv->timeout); 430 add_timer(&fw_priv->timeout);
424 } 431 }
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index f37a13de804a..214b96435409 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -22,7 +22,6 @@
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/pm.h> 23#include <linux/pm.h>
24 24
25
26extern struct subsystem devices_subsys; 25extern struct subsystem devices_subsys;
27 26
28#define to_sysdev(k) container_of(k, struct sys_device, kobj) 27#define to_sysdev(k) container_of(k, struct sys_device, kobj)
diff --git a/drivers/block/as-iosched.c b/drivers/block/as-iosched.c
index 3410b4d294b9..91aeb678135d 100644
--- a/drivers/block/as-iosched.c
+++ b/drivers/block/as-iosched.c
@@ -1806,7 +1806,8 @@ static void as_put_request(request_queue_t *q, struct request *rq)
1806 rq->elevator_private = NULL; 1806 rq->elevator_private = NULL;
1807} 1807}
1808 1808
1809static int as_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 1809static int as_set_request(request_queue_t *q, struct request *rq,
1810 struct bio *bio, int gfp_mask)
1810{ 1811{
1811 struct as_data *ad = q->elevator->elevator_data; 1812 struct as_data *ad = q->elevator->elevator_data;
1812 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask); 1813 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask);
@@ -1827,7 +1828,7 @@ static int as_set_request(request_queue_t *q, struct request *rq, int gfp_mask)
1827 return 1; 1828 return 1;
1828} 1829}
1829 1830
1830static int as_may_queue(request_queue_t *q, int rw) 1831static int as_may_queue(request_queue_t *q, int rw, struct bio *bio)
1831{ 1832{
1832 int ret = ELV_MQUEUE_MAY; 1833 int ret = ELV_MQUEUE_MAY;
1833 struct as_data *ad = q->elevator->elevator_data; 1834 struct as_data *ad = q->elevator->elevator_data;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index abde27027c06..3e9fb6e4a52a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Disk Array driver for HP SA 5xxx and 6xxx Controllers 2 * Disk Array driver for HP SA 5xxx and 6xxx Controllers
3 * Copyright 2000, 2002 Hewlett-Packard Development Company, L.P. 3 * Copyright 2000, 2005 Hewlett-Packard Development Company, L.P.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@
54MODULE_AUTHOR("Hewlett-Packard Company"); 54MODULE_AUTHOR("Hewlett-Packard Company");
55MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.6"); 55MODULE_DESCRIPTION("Driver for HP Controller SA5xxx SA6xxx version 2.6.6");
56MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" 56MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400"
57 " SA6i P600 P800 E400"); 57 " SA6i P600 P800 E400 E300");
58MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
59 59
60#include "cciss_cmd.h" 60#include "cciss_cmd.h"
@@ -85,8 +85,10 @@ static const struct pci_device_id cciss_pci_device_id[] = {
85 0x103C, 0x3225, 0, 0, 0}, 85 0x103C, 0x3225, 0, 0, 0},
86 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB, 86 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB,
87 0x103c, 0x3223, 0, 0, 0}, 87 0x103c, 0x3223, 0, 0, 0},
88 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSB, 88 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
89 0x103c, 0x3231, 0, 0, 0}, 89 0x103c, 0x3231, 0, 0, 0},
90 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC,
91 0x103c, 0x3233, 0, 0, 0},
90 {0,} 92 {0,}
91}; 93};
92MODULE_DEVICE_TABLE(pci, cciss_pci_device_id); 94MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
@@ -110,6 +112,7 @@ static struct board_type products[] = {
110 { 0x3225103C, "Smart Array P600", &SA5_access}, 112 { 0x3225103C, "Smart Array P600", &SA5_access},
111 { 0x3223103C, "Smart Array P800", &SA5_access}, 113 { 0x3223103C, "Smart Array P800", &SA5_access},
112 { 0x3231103C, "Smart Array E400", &SA5_access}, 114 { 0x3231103C, "Smart Array E400", &SA5_access},
115 { 0x3233103C, "Smart Array E300", &SA5_access},
113}; 116};
114 117
115/* How long to wait (in millesconds) for board to go into simple mode */ 118/* How long to wait (in millesconds) for board to go into simple mode */
@@ -635,6 +638,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
635 cciss_pci_info_struct pciinfo; 638 cciss_pci_info_struct pciinfo;
636 639
637 if (!arg) return -EINVAL; 640 if (!arg) return -EINVAL;
641 pciinfo.domain = pci_domain_nr(host->pdev->bus);
638 pciinfo.bus = host->pdev->bus->number; 642 pciinfo.bus = host->pdev->bus->number;
639 pciinfo.dev_fn = host->pdev->devfn; 643 pciinfo.dev_fn = host->pdev->devfn;
640 pciinfo.board_id = host->board_id; 644 pciinfo.board_id = host->board_id;
@@ -782,18 +786,10 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
782 786
783 case CCISS_GETLUNINFO: { 787 case CCISS_GETLUNINFO: {
784 LogvolInfo_struct luninfo; 788 LogvolInfo_struct luninfo;
785 int i;
786 789
787 luninfo.LunID = drv->LunID; 790 luninfo.LunID = drv->LunID;
788 luninfo.num_opens = drv->usage_count; 791 luninfo.num_opens = drv->usage_count;
789 luninfo.num_parts = 0; 792 luninfo.num_parts = 0;
790 /* count partitions 1 to 15 with sizes > 0 */
791 for (i = 0; i < MAX_PART - 1; i++) {
792 if (!disk->part[i])
793 continue;
794 if (disk->part[i]->nr_sects != 0)
795 luninfo.num_parts++;
796 }
797 if (copy_to_user(argp, &luninfo, 793 if (copy_to_user(argp, &luninfo,
798 sizeof(LogvolInfo_struct))) 794 sizeof(LogvolInfo_struct)))
799 return -EFAULT; 795 return -EFAULT;
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index 3ac47dde64da..de5746e38af9 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -21,22 +21,34 @@
21#include <linux/hash.h> 21#include <linux/hash.h>
22#include <linux/rbtree.h> 22#include <linux/rbtree.h>
23#include <linux/mempool.h> 23#include <linux/mempool.h>
24 24#include <linux/ioprio.h>
25static unsigned long max_elapsed_crq; 25#include <linux/writeback.h>
26static unsigned long max_elapsed_dispatch;
27 26
28/* 27/*
29 * tunables 28 * tunables
30 */ 29 */
31static int cfq_quantum = 4; /* max queue in one round of service */ 30static int cfq_quantum = 4; /* max queue in one round of service */
32static int cfq_queued = 8; /* minimum rq allocate limit per-queue*/ 31static int cfq_queued = 8; /* minimum rq allocate limit per-queue*/
33static int cfq_service = HZ; /* period over which service is avg */ 32static int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 };
34static int cfq_fifo_expire_r = HZ / 2; /* fifo timeout for sync requests */
35static int cfq_fifo_expire_w = 5 * HZ; /* fifo timeout for async requests */
36static int cfq_fifo_rate = HZ / 8; /* fifo expiry rate */
37static int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */ 33static int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */
38static int cfq_back_penalty = 2; /* penalty of a backwards seek */ 34static int cfq_back_penalty = 2; /* penalty of a backwards seek */
39 35
36static int cfq_slice_sync = HZ / 10;
37static int cfq_slice_async = HZ / 25;
38static int cfq_slice_async_rq = 2;
39static int cfq_slice_idle = HZ / 100;
40
41#define CFQ_IDLE_GRACE (HZ / 10)
42#define CFQ_SLICE_SCALE (5)
43
44#define CFQ_KEY_ASYNC (0)
45#define CFQ_KEY_ANY (0xffff)
46
47/*
48 * disable queueing at the driver/hardware level
49 */
50static int cfq_max_depth = 1;
51
40/* 52/*
41 * for the hash of cfqq inside the cfqd 53 * for the hash of cfqq inside the cfqd
42 */ 54 */
@@ -55,6 +67,7 @@ static int cfq_back_penalty = 2; /* penalty of a backwards seek */
55#define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash) 67#define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash)
56 68
57#define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list) 69#define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list)
70#define list_entry_fifo(ptr) list_entry((ptr), struct request, queuelist)
58 71
59#define RQ_DATA(rq) (rq)->elevator_private 72#define RQ_DATA(rq) (rq)->elevator_private
60 73
@@ -75,78 +88,110 @@ static int cfq_back_penalty = 2; /* penalty of a backwards seek */
75#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) 88#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node)
76#define rq_rb_key(rq) (rq)->sector 89#define rq_rb_key(rq) (rq)->sector
77 90
78/*
79 * threshold for switching off non-tag accounting
80 */
81#define CFQ_MAX_TAG (4)
82
83/*
84 * sort key types and names
85 */
86enum {
87 CFQ_KEY_PGID,
88 CFQ_KEY_TGID,
89 CFQ_KEY_UID,
90 CFQ_KEY_GID,
91 CFQ_KEY_LAST,
92};
93
94static char *cfq_key_types[] = { "pgid", "tgid", "uid", "gid", NULL };
95
96static kmem_cache_t *crq_pool; 91static kmem_cache_t *crq_pool;
97static kmem_cache_t *cfq_pool; 92static kmem_cache_t *cfq_pool;
98static kmem_cache_t *cfq_ioc_pool; 93static kmem_cache_t *cfq_ioc_pool;
99 94
95#define CFQ_PRIO_LISTS IOPRIO_BE_NR
96#define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
97#define cfq_class_be(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_BE)
98#define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT)
99
100#define ASYNC (0)
101#define SYNC (1)
102
103#define cfq_cfqq_dispatched(cfqq) \
104 ((cfqq)->on_dispatch[ASYNC] + (cfqq)->on_dispatch[SYNC])
105
106#define cfq_cfqq_class_sync(cfqq) ((cfqq)->key != CFQ_KEY_ASYNC)
107
108#define cfq_cfqq_sync(cfqq) \
109 (cfq_cfqq_class_sync(cfqq) || (cfqq)->on_dispatch[SYNC])
110
111/*
112 * Per block device queue structure
113 */
100struct cfq_data { 114struct cfq_data {
101 struct list_head rr_list; 115 atomic_t ref;
116 request_queue_t *queue;
117
118 /*
119 * rr list of queues with requests and the count of them
120 */
121 struct list_head rr_list[CFQ_PRIO_LISTS];
122 struct list_head busy_rr;
123 struct list_head cur_rr;
124 struct list_head idle_rr;
125 unsigned int busy_queues;
126
127 /*
128 * non-ordered list of empty cfqq's
129 */
102 struct list_head empty_list; 130 struct list_head empty_list;
103 131
132 /*
133 * cfqq lookup hash
134 */
104 struct hlist_head *cfq_hash; 135 struct hlist_head *cfq_hash;
105 struct hlist_head *crq_hash;
106 136
107 /* queues on rr_list (ie they have pending requests */ 137 /*
108 unsigned int busy_queues; 138 * global crq hash for all queues
139 */
140 struct hlist_head *crq_hash;
109 141
110 unsigned int max_queued; 142 unsigned int max_queued;
111 143
112 atomic_t ref; 144 mempool_t *crq_pool;
113 145
114 int key_type; 146 int rq_in_driver;
115 147
116 mempool_t *crq_pool; 148 /*
149 * schedule slice state info
150 */
151 /*
152 * idle window management
153 */
154 struct timer_list idle_slice_timer;
155 struct work_struct unplug_work;
117 156
118 request_queue_t *queue; 157 struct cfq_queue *active_queue;
158 struct cfq_io_context *active_cic;
159 int cur_prio, cur_end_prio;
160 unsigned int dispatch_slice;
161
162 struct timer_list idle_class_timer;
119 163
120 sector_t last_sector; 164 sector_t last_sector;
165 unsigned long last_end_request;
121 166
122 int rq_in_driver; 167 unsigned int rq_starved;
123 168
124 /* 169 /*
125 * tunables, see top of file 170 * tunables, see top of file
126 */ 171 */
127 unsigned int cfq_quantum; 172 unsigned int cfq_quantum;
128 unsigned int cfq_queued; 173 unsigned int cfq_queued;
129 unsigned int cfq_fifo_expire_r; 174 unsigned int cfq_fifo_expire[2];
130 unsigned int cfq_fifo_expire_w;
131 unsigned int cfq_fifo_batch_expire;
132 unsigned int cfq_back_penalty; 175 unsigned int cfq_back_penalty;
133 unsigned int cfq_back_max; 176 unsigned int cfq_back_max;
134 unsigned int find_best_crq; 177 unsigned int cfq_slice[2];
135 178 unsigned int cfq_slice_async_rq;
136 unsigned int cfq_tagged; 179 unsigned int cfq_slice_idle;
180 unsigned int cfq_max_depth;
137}; 181};
138 182
183/*
184 * Per process-grouping structure
185 */
139struct cfq_queue { 186struct cfq_queue {
140 /* reference count */ 187 /* reference count */
141 atomic_t ref; 188 atomic_t ref;
142 /* parent cfq_data */ 189 /* parent cfq_data */
143 struct cfq_data *cfqd; 190 struct cfq_data *cfqd;
144 /* hash of mergeable requests */ 191 /* cfqq lookup hash */
145 struct hlist_node cfq_hash; 192 struct hlist_node cfq_hash;
146 /* hash key */ 193 /* hash key */
147 unsigned long key; 194 unsigned int key;
148 /* whether queue is on rr (or empty) list */
149 int on_rr;
150 /* on either rr or empty list of cfqd */ 195 /* on either rr or empty list of cfqd */
151 struct list_head cfq_list; 196 struct list_head cfq_list;
152 /* sorted list of pending requests */ 197 /* sorted list of pending requests */
@@ -158,21 +203,22 @@ struct cfq_queue {
158 /* currently allocated requests */ 203 /* currently allocated requests */
159 int allocated[2]; 204 int allocated[2];
160 /* fifo list of requests in sort_list */ 205 /* fifo list of requests in sort_list */
161 struct list_head fifo[2]; 206 struct list_head fifo;
162 /* last time fifo expired */
163 unsigned long last_fifo_expire;
164 207
165 int key_type; 208 unsigned long slice_start;
209 unsigned long slice_end;
210 unsigned long slice_left;
211 unsigned long service_last;
166 212
167 unsigned long service_start; 213 /* number of requests that are on the dispatch list */
168 unsigned long service_used; 214 int on_dispatch[2];
169 215
170 unsigned int max_rate; 216 /* io prio of this group */
217 unsigned short ioprio, org_ioprio;
218 unsigned short ioprio_class, org_ioprio_class;
171 219
172 /* number of requests that have been handed to the driver */ 220 /* various state flags, see below */
173 int in_flight; 221 unsigned int flags;
174 /* number of currently allocated requests */
175 int alloc_limit[2];
176}; 222};
177 223
178struct cfq_rq { 224struct cfq_rq {
@@ -184,42 +230,78 @@ struct cfq_rq {
184 struct cfq_queue *cfq_queue; 230 struct cfq_queue *cfq_queue;
185 struct cfq_io_context *io_context; 231 struct cfq_io_context *io_context;
186 232
187 unsigned long service_start; 233 unsigned int crq_flags;
188 unsigned long queue_start; 234};
235
236enum cfqq_state_flags {
237 CFQ_CFQQ_FLAG_on_rr = 0,
238 CFQ_CFQQ_FLAG_wait_request,
239 CFQ_CFQQ_FLAG_must_alloc,
240 CFQ_CFQQ_FLAG_must_alloc_slice,
241 CFQ_CFQQ_FLAG_must_dispatch,
242 CFQ_CFQQ_FLAG_fifo_expire,
243 CFQ_CFQQ_FLAG_idle_window,
244 CFQ_CFQQ_FLAG_prio_changed,
245 CFQ_CFQQ_FLAG_expired,
246};
189 247
190 unsigned int in_flight : 1; 248#define CFQ_CFQQ_FNS(name) \
191 unsigned int accounted : 1; 249static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \
192 unsigned int is_sync : 1; 250{ \
193 unsigned int is_write : 1; 251 cfqq->flags |= (1 << CFQ_CFQQ_FLAG_##name); \
252} \
253static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \
254{ \
255 cfqq->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \
256} \
257static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \
258{ \
259 return (cfqq->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \
260}
261
262CFQ_CFQQ_FNS(on_rr);
263CFQ_CFQQ_FNS(wait_request);
264CFQ_CFQQ_FNS(must_alloc);
265CFQ_CFQQ_FNS(must_alloc_slice);
266CFQ_CFQQ_FNS(must_dispatch);
267CFQ_CFQQ_FNS(fifo_expire);
268CFQ_CFQQ_FNS(idle_window);
269CFQ_CFQQ_FNS(prio_changed);
270CFQ_CFQQ_FNS(expired);
271#undef CFQ_CFQQ_FNS
272
273enum cfq_rq_state_flags {
274 CFQ_CRQ_FLAG_in_flight = 0,
275 CFQ_CRQ_FLAG_in_driver,
276 CFQ_CRQ_FLAG_is_sync,
277 CFQ_CRQ_FLAG_requeued,
194}; 278};
195 279
196static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned long); 280#define CFQ_CRQ_FNS(name) \
281static inline void cfq_mark_crq_##name(struct cfq_rq *crq) \
282{ \
283 crq->crq_flags |= (1 << CFQ_CRQ_FLAG_##name); \
284} \
285static inline void cfq_clear_crq_##name(struct cfq_rq *crq) \
286{ \
287 crq->crq_flags &= ~(1 << CFQ_CRQ_FLAG_##name); \
288} \
289static inline int cfq_crq_##name(const struct cfq_rq *crq) \
290{ \
291 return (crq->crq_flags & (1 << CFQ_CRQ_FLAG_##name)) != 0; \
292}
293
294CFQ_CRQ_FNS(in_flight);
295CFQ_CRQ_FNS(in_driver);
296CFQ_CRQ_FNS(is_sync);
297CFQ_CRQ_FNS(requeued);
298#undef CFQ_CRQ_FNS
299
300static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short);
197static void cfq_dispatch_sort(request_queue_t *, struct cfq_rq *); 301static void cfq_dispatch_sort(request_queue_t *, struct cfq_rq *);
198static void cfq_update_next_crq(struct cfq_rq *);
199static void cfq_put_cfqd(struct cfq_data *cfqd); 302static void cfq_put_cfqd(struct cfq_data *cfqd);
200 303
201/* 304#define process_sync(tsk) ((tsk)->flags & PF_SYNCWRITE)
202 * what the fairness is based on (ie how processes are grouped and
203 * differentiated)
204 */
205static inline unsigned long
206cfq_hash_key(struct cfq_data *cfqd, struct task_struct *tsk)
207{
208 /*
209 * optimize this so that ->key_type is the offset into the struct
210 */
211 switch (cfqd->key_type) {
212 case CFQ_KEY_PGID:
213 return process_group(tsk);
214 default:
215 case CFQ_KEY_TGID:
216 return tsk->tgid;
217 case CFQ_KEY_UID:
218 return tsk->uid;
219 case CFQ_KEY_GID:
220 return tsk->gid;
221 }
222}
223 305
224/* 306/*
225 * lots of deadline iosched dupes, can be abstracted later... 307 * lots of deadline iosched dupes, can be abstracted later...
@@ -235,16 +317,12 @@ static void cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq)
235 317
236 if (q->last_merge == crq->request) 318 if (q->last_merge == crq->request)
237 q->last_merge = NULL; 319 q->last_merge = NULL;
238
239 cfq_update_next_crq(crq);
240} 320}
241 321
242static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq) 322static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq)
243{ 323{
244 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request)); 324 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request));
245 325
246 BUG_ON(!hlist_unhashed(&crq->hash));
247
248 hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]); 326 hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]);
249} 327}
250 328
@@ -257,8 +335,6 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset)
257 struct cfq_rq *crq = list_entry_hash(entry); 335 struct cfq_rq *crq = list_entry_hash(entry);
258 struct request *__rq = crq->request; 336 struct request *__rq = crq->request;
259 337
260 BUG_ON(hlist_unhashed(&crq->hash));
261
262 if (!rq_mergeable(__rq)) { 338 if (!rq_mergeable(__rq)) {
263 cfq_del_crq_hash(crq); 339 cfq_del_crq_hash(crq);
264 continue; 340 continue;
@@ -271,6 +347,28 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset)
271 return NULL; 347 return NULL;
272} 348}
273 349
350static inline int cfq_pending_requests(struct cfq_data *cfqd)
351{
352 return !list_empty(&cfqd->queue->queue_head) || cfqd->busy_queues;
353}
354
355/*
356 * scheduler run of queue, if there are requests pending and no one in the
357 * driver that will restart queueing
358 */
359static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
360{
361 if (!cfqd->rq_in_driver && cfq_pending_requests(cfqd))
362 kblockd_schedule_work(&cfqd->unplug_work);
363}
364
365static int cfq_queue_empty(request_queue_t *q)
366{
367 struct cfq_data *cfqd = q->elevator->elevator_data;
368
369 return !cfq_pending_requests(cfqd);
370}
371
274/* 372/*
275 * Lifted from AS - choose which of crq1 and crq2 that is best served now. 373 * Lifted from AS - choose which of crq1 and crq2 that is best served now.
276 * We choose the request that is closest to the head right now. Distance 374 * We choose the request that is closest to the head right now. Distance
@@ -287,36 +385,16 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2)
287 return crq2; 385 return crq2;
288 if (crq2 == NULL) 386 if (crq2 == NULL)
289 return crq1; 387 return crq1;
388 if (cfq_crq_requeued(crq1))
389 return crq1;
390 if (cfq_crq_requeued(crq2))
391 return crq2;
290 392
291 s1 = crq1->request->sector; 393 s1 = crq1->request->sector;
292 s2 = crq2->request->sector; 394 s2 = crq2->request->sector;
293 395
294 last = cfqd->last_sector; 396 last = cfqd->last_sector;
295 397
296#if 0
297 if (!list_empty(&cfqd->queue->queue_head)) {
298 struct list_head *entry = &cfqd->queue->queue_head;
299 unsigned long distance = ~0UL;
300 struct request *rq;
301
302 while ((entry = entry->prev) != &cfqd->queue->queue_head) {
303 rq = list_entry_rq(entry);
304
305 if (blk_barrier_rq(rq))
306 break;
307
308 if (distance < abs(s1 - rq->sector + rq->nr_sectors)) {
309 distance = abs(s1 - rq->sector +rq->nr_sectors);
310 last = rq->sector + rq->nr_sectors;
311 }
312 if (distance < abs(s2 - rq->sector + rq->nr_sectors)) {
313 distance = abs(s2 - rq->sector +rq->nr_sectors);
314 last = rq->sector + rq->nr_sectors;
315 }
316 }
317 }
318#endif
319
320 /* 398 /*
321 * by definition, 1KiB is 2 sectors 399 * by definition, 1KiB is 2 sectors
322 */ 400 */
@@ -377,11 +455,14 @@ cfq_find_next_crq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
377 struct cfq_rq *crq_next = NULL, *crq_prev = NULL; 455 struct cfq_rq *crq_next = NULL, *crq_prev = NULL;
378 struct rb_node *rbnext, *rbprev; 456 struct rb_node *rbnext, *rbprev;
379 457
380 if (!ON_RB(&last->rb_node)) 458 rbnext = NULL;
381 return NULL; 459 if (ON_RB(&last->rb_node))
382 460 rbnext = rb_next(&last->rb_node);
383 if ((rbnext = rb_next(&last->rb_node)) == NULL) 461 if (!rbnext) {
384 rbnext = rb_first(&cfqq->sort_list); 462 rbnext = rb_first(&cfqq->sort_list);
463 if (rbnext == &last->rb_node)
464 rbnext = NULL;
465 }
385 466
386 rbprev = rb_prev(&last->rb_node); 467 rbprev = rb_prev(&last->rb_node);
387 468
@@ -401,67 +482,53 @@ static void cfq_update_next_crq(struct cfq_rq *crq)
401 cfqq->next_crq = cfq_find_next_crq(cfqq->cfqd, cfqq, crq); 482 cfqq->next_crq = cfq_find_next_crq(cfqq->cfqd, cfqq, crq);
402} 483}
403 484
404static int cfq_check_sort_rr_list(struct cfq_queue *cfqq) 485static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted)
405{ 486{
406 struct list_head *head = &cfqq->cfqd->rr_list; 487 struct cfq_data *cfqd = cfqq->cfqd;
407 struct list_head *next, *prev; 488 struct list_head *list, *entry;
408
409 /*
410 * list might still be ordered
411 */
412 next = cfqq->cfq_list.next;
413 if (next != head) {
414 struct cfq_queue *cnext = list_entry_cfqq(next);
415 489
416 if (cfqq->service_used > cnext->service_used) 490 BUG_ON(!cfq_cfqq_on_rr(cfqq));
417 return 1;
418 }
419 491
420 prev = cfqq->cfq_list.prev; 492 list_del(&cfqq->cfq_list);
421 if (prev != head) {
422 struct cfq_queue *cprev = list_entry_cfqq(prev);
423 493
424 if (cfqq->service_used < cprev->service_used) 494 if (cfq_class_rt(cfqq))
425 return 1; 495 list = &cfqd->cur_rr;
496 else if (cfq_class_idle(cfqq))
497 list = &cfqd->idle_rr;
498 else {
499 /*
500 * if cfqq has requests in flight, don't allow it to be
501 * found in cfq_set_active_queue before it has finished them.
502 * this is done to increase fairness between a process that
503 * has lots of io pending vs one that only generates one
504 * sporadically or synchronously
505 */
506 if (cfq_cfqq_dispatched(cfqq))
507 list = &cfqd->busy_rr;
508 else
509 list = &cfqd->rr_list[cfqq->ioprio];
426 } 510 }
427 511
428 return 0; 512 /*
429} 513 * if queue was preempted, just add to front to be fair. busy_rr
430 514 * isn't sorted.
431static void cfq_sort_rr_list(struct cfq_queue *cfqq, int new_queue) 515 */
432{ 516 if (preempted || list == &cfqd->busy_rr) {
433 struct list_head *entry = &cfqq->cfqd->rr_list; 517 list_add(&cfqq->cfq_list, list);
434
435 if (!cfqq->on_rr)
436 return;
437 if (!new_queue && !cfq_check_sort_rr_list(cfqq))
438 return; 518 return;
439 519 }
440 list_del(&cfqq->cfq_list);
441 520
442 /* 521 /*
443 * sort by our mean service_used, sub-sort by in-flight requests 522 * sort by when queue was last serviced
444 */ 523 */
445 while ((entry = entry->prev) != &cfqq->cfqd->rr_list) { 524 entry = list;
525 while ((entry = entry->prev) != list) {
446 struct cfq_queue *__cfqq = list_entry_cfqq(entry); 526 struct cfq_queue *__cfqq = list_entry_cfqq(entry);
447 527
448 if (cfqq->service_used > __cfqq->service_used) 528 if (!__cfqq->service_last)
529 break;
530 if (time_before(__cfqq->service_last, cfqq->service_last))
449 break; 531 break;
450 else if (cfqq->service_used == __cfqq->service_used) {
451 struct list_head *prv;
452
453 while ((prv = entry->prev) != &cfqq->cfqd->rr_list) {
454 __cfqq = list_entry_cfqq(prv);
455
456 WARN_ON(__cfqq->service_used > cfqq->service_used);
457 if (cfqq->service_used != __cfqq->service_used)
458 break;
459 if (cfqq->in_flight > __cfqq->in_flight)
460 break;
461
462 entry = prv;
463 }
464 }
465 } 532 }
466 533
467 list_add(&cfqq->cfq_list, entry); 534 list_add(&cfqq->cfq_list, entry);
@@ -469,28 +536,24 @@ static void cfq_sort_rr_list(struct cfq_queue *cfqq, int new_queue)
469 536
470/* 537/*
471 * add to busy list of queues for service, trying to be fair in ordering 538 * add to busy list of queues for service, trying to be fair in ordering
472 * the pending list according to requests serviced 539 * the pending list according to last request service
473 */ 540 */
474static inline void 541static inline void
475cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) 542cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq, int requeue)
476{ 543{
477 /* 544 BUG_ON(cfq_cfqq_on_rr(cfqq));
478 * it's currently on the empty list 545 cfq_mark_cfqq_on_rr(cfqq);
479 */
480 cfqq->on_rr = 1;
481 cfqd->busy_queues++; 546 cfqd->busy_queues++;
482 547
483 if (time_after(jiffies, cfqq->service_start + cfq_service)) 548 cfq_resort_rr_list(cfqq, requeue);
484 cfqq->service_used >>= 3;
485
486 cfq_sort_rr_list(cfqq, 1);
487} 549}
488 550
489static inline void 551static inline void
490cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) 552cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
491{ 553{
554 BUG_ON(!cfq_cfqq_on_rr(cfqq));
555 cfq_clear_cfqq_on_rr(cfqq);
492 list_move(&cfqq->cfq_list, &cfqd->empty_list); 556 list_move(&cfqq->cfq_list, &cfqd->empty_list);
493 cfqq->on_rr = 0;
494 557
495 BUG_ON(!cfqd->busy_queues); 558 BUG_ON(!cfqd->busy_queues);
496 cfqd->busy_queues--; 559 cfqd->busy_queues--;
@@ -505,16 +568,17 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq)
505 568
506 if (ON_RB(&crq->rb_node)) { 569 if (ON_RB(&crq->rb_node)) {
507 struct cfq_data *cfqd = cfqq->cfqd; 570 struct cfq_data *cfqd = cfqq->cfqd;
571 const int sync = cfq_crq_is_sync(crq);
508 572
509 BUG_ON(!cfqq->queued[crq->is_sync]); 573 BUG_ON(!cfqq->queued[sync]);
574 cfqq->queued[sync]--;
510 575
511 cfq_update_next_crq(crq); 576 cfq_update_next_crq(crq);
512 577
513 cfqq->queued[crq->is_sync]--;
514 rb_erase(&crq->rb_node, &cfqq->sort_list); 578 rb_erase(&crq->rb_node, &cfqq->sort_list);
515 RB_CLEAR_COLOR(&crq->rb_node); 579 RB_CLEAR_COLOR(&crq->rb_node);
516 580
517 if (RB_EMPTY(&cfqq->sort_list) && cfqq->on_rr) 581 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list))
518 cfq_del_cfqq_rr(cfqd, cfqq); 582 cfq_del_cfqq_rr(cfqd, cfqq);
519 } 583 }
520} 584}
@@ -550,7 +614,7 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
550 struct cfq_rq *__alias; 614 struct cfq_rq *__alias;
551 615
552 crq->rb_key = rq_rb_key(rq); 616 crq->rb_key = rq_rb_key(rq);
553 cfqq->queued[crq->is_sync]++; 617 cfqq->queued[cfq_crq_is_sync(crq)]++;
554 618
555 /* 619 /*
556 * looks a little odd, but the first insert might return an alias. 620 * looks a little odd, but the first insert might return an alias.
@@ -561,8 +625,8 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
561 625
562 rb_insert_color(&crq->rb_node, &cfqq->sort_list); 626 rb_insert_color(&crq->rb_node, &cfqq->sort_list);
563 627
564 if (!cfqq->on_rr) 628 if (!cfq_cfqq_on_rr(cfqq))
565 cfq_add_cfqq_rr(cfqd, cfqq); 629 cfq_add_cfqq_rr(cfqd, cfqq, cfq_crq_requeued(crq));
566 630
567 /* 631 /*
568 * check if this request is a better next-serve candidate 632 * check if this request is a better next-serve candidate
@@ -575,17 +639,16 @@ cfq_reposition_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq)
575{ 639{
576 if (ON_RB(&crq->rb_node)) { 640 if (ON_RB(&crq->rb_node)) {
577 rb_erase(&crq->rb_node, &cfqq->sort_list); 641 rb_erase(&crq->rb_node, &cfqq->sort_list);
578 cfqq->queued[crq->is_sync]--; 642 cfqq->queued[cfq_crq_is_sync(crq)]--;
579 } 643 }
580 644
581 cfq_add_crq_rb(crq); 645 cfq_add_crq_rb(crq);
582} 646}
583 647
584static struct request * 648static struct request *cfq_find_rq_rb(struct cfq_data *cfqd, sector_t sector)
585cfq_find_rq_rb(struct cfq_data *cfqd, sector_t sector) 649
586{ 650{
587 const unsigned long key = cfq_hash_key(cfqd, current); 651 struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, current->pid, CFQ_KEY_ANY);
588 struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, key);
589 struct rb_node *n; 652 struct rb_node *n;
590 653
591 if (!cfqq) 654 if (!cfqq)
@@ -609,20 +672,25 @@ out:
609 672
610static void cfq_deactivate_request(request_queue_t *q, struct request *rq) 673static void cfq_deactivate_request(request_queue_t *q, struct request *rq)
611{ 674{
675 struct cfq_data *cfqd = q->elevator->elevator_data;
612 struct cfq_rq *crq = RQ_DATA(rq); 676 struct cfq_rq *crq = RQ_DATA(rq);
613 677
614 if (crq) { 678 if (crq) {
615 struct cfq_queue *cfqq = crq->cfq_queue; 679 struct cfq_queue *cfqq = crq->cfq_queue;
616 680
617 if (cfqq->cfqd->cfq_tagged) { 681 if (cfq_crq_in_driver(crq)) {
618 cfqq->service_used--; 682 cfq_clear_crq_in_driver(crq);
619 cfq_sort_rr_list(cfqq, 0); 683 WARN_ON(!cfqd->rq_in_driver);
684 cfqd->rq_in_driver--;
620 } 685 }
686 if (cfq_crq_in_flight(crq)) {
687 const int sync = cfq_crq_is_sync(crq);
621 688
622 if (crq->accounted) { 689 cfq_clear_crq_in_flight(crq);
623 crq->accounted = 0; 690 WARN_ON(!cfqq->on_dispatch[sync]);
624 cfqq->cfqd->rq_in_driver--; 691 cfqq->on_dispatch[sync]--;
625 } 692 }
693 cfq_mark_crq_requeued(crq);
626 } 694 }
627} 695}
628 696
@@ -640,11 +708,10 @@ static void cfq_remove_request(request_queue_t *q, struct request *rq)
640 struct cfq_rq *crq = RQ_DATA(rq); 708 struct cfq_rq *crq = RQ_DATA(rq);
641 709
642 if (crq) { 710 if (crq) {
643 cfq_remove_merge_hints(q, crq);
644 list_del_init(&rq->queuelist); 711 list_del_init(&rq->queuelist);
712 cfq_del_crq_rb(crq);
713 cfq_remove_merge_hints(q, crq);
645 714
646 if (crq->cfq_queue)
647 cfq_del_crq_rb(crq);
648 } 715 }
649} 716}
650 717
@@ -662,21 +729,15 @@ cfq_merge(request_queue_t *q, struct request **req, struct bio *bio)
662 } 729 }
663 730
664 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector); 731 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector);
665 if (__rq) { 732 if (__rq && elv_rq_merge_ok(__rq, bio)) {
666 BUG_ON(__rq->sector + __rq->nr_sectors != bio->bi_sector); 733 ret = ELEVATOR_BACK_MERGE;
667 734 goto out;
668 if (elv_rq_merge_ok(__rq, bio)) {
669 ret = ELEVATOR_BACK_MERGE;
670 goto out;
671 }
672 } 735 }
673 736
674 __rq = cfq_find_rq_rb(cfqd, bio->bi_sector + bio_sectors(bio)); 737 __rq = cfq_find_rq_rb(cfqd, bio->bi_sector + bio_sectors(bio));
675 if (__rq) { 738 if (__rq && elv_rq_merge_ok(__rq, bio)) {
676 if (elv_rq_merge_ok(__rq, bio)) { 739 ret = ELEVATOR_FRONT_MERGE;
677 ret = ELEVATOR_FRONT_MERGE; 740 goto out;
678 goto out;
679 }
680 } 741 }
681 742
682 return ELEVATOR_NO_MERGE; 743 return ELEVATOR_NO_MERGE;
@@ -709,20 +770,220 @@ static void
709cfq_merged_requests(request_queue_t *q, struct request *rq, 770cfq_merged_requests(request_queue_t *q, struct request *rq,
710 struct request *next) 771 struct request *next)
711{ 772{
712 struct cfq_rq *crq = RQ_DATA(rq);
713 struct cfq_rq *cnext = RQ_DATA(next);
714
715 cfq_merged_request(q, rq); 773 cfq_merged_request(q, rq);
716 774
717 if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist)) { 775 /*
718 if (time_before(cnext->queue_start, crq->queue_start)) { 776 * reposition in fifo if next is older than rq
719 list_move(&rq->queuelist, &next->queuelist); 777 */
720 crq->queue_start = cnext->queue_start; 778 if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist) &&
779 time_before(next->start_time, rq->start_time))
780 list_move(&rq->queuelist, &next->queuelist);
781
782 cfq_remove_request(q, next);
783}
784
785static inline void
786__cfq_set_active_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
787{
788 if (cfqq) {
789 /*
790 * stop potential idle class queues waiting service
791 */
792 del_timer(&cfqd->idle_class_timer);
793
794 cfqq->slice_start = jiffies;
795 cfqq->slice_end = 0;
796 cfqq->slice_left = 0;
797 cfq_clear_cfqq_must_alloc_slice(cfqq);
798 cfq_clear_cfqq_fifo_expire(cfqq);
799 cfq_clear_cfqq_expired(cfqq);
800 }
801
802 cfqd->active_queue = cfqq;
803}
804
805/*
806 * 0
807 * 0,1
808 * 0,1,2
809 * 0,1,2,3
810 * 0,1,2,3,4
811 * 0,1,2,3,4,5
812 * 0,1,2,3,4,5,6
813 * 0,1,2,3,4,5,6,7
814 */
815static int cfq_get_next_prio_level(struct cfq_data *cfqd)
816{
817 int prio, wrap;
818
819 prio = -1;
820 wrap = 0;
821 do {
822 int p;
823
824 for (p = cfqd->cur_prio; p <= cfqd->cur_end_prio; p++) {
825 if (!list_empty(&cfqd->rr_list[p])) {
826 prio = p;
827 break;
828 }
829 }
830
831 if (prio != -1)
832 break;
833 cfqd->cur_prio = 0;
834 if (++cfqd->cur_end_prio == CFQ_PRIO_LISTS) {
835 cfqd->cur_end_prio = 0;
836 if (wrap)
837 break;
838 wrap = 1;
721 } 839 }
840 } while (1);
841
842 if (unlikely(prio == -1))
843 return -1;
844
845 BUG_ON(prio >= CFQ_PRIO_LISTS);
846
847 list_splice_init(&cfqd->rr_list[prio], &cfqd->cur_rr);
848
849 cfqd->cur_prio = prio + 1;
850 if (cfqd->cur_prio > cfqd->cur_end_prio) {
851 cfqd->cur_end_prio = cfqd->cur_prio;
852 cfqd->cur_prio = 0;
853 }
854 if (cfqd->cur_end_prio == CFQ_PRIO_LISTS) {
855 cfqd->cur_prio = 0;
856 cfqd->cur_end_prio = 0;
722 } 857 }
723 858
724 cfq_update_next_crq(cnext); 859 return prio;
725 cfq_remove_request(q, next); 860}
861
862static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd)
863{
864 struct cfq_queue *cfqq;
865
866 /*
867 * if current queue is expired but not done with its requests yet,
868 * wait for that to happen
869 */
870 if ((cfqq = cfqd->active_queue) != NULL) {
871 if (cfq_cfqq_expired(cfqq) && cfq_cfqq_dispatched(cfqq))
872 return NULL;
873 }
874
875 /*
876 * if current list is non-empty, grab first entry. if it is empty,
877 * get next prio level and grab first entry then if any are spliced
878 */
879 if (!list_empty(&cfqd->cur_rr) || cfq_get_next_prio_level(cfqd) != -1)
880 cfqq = list_entry_cfqq(cfqd->cur_rr.next);
881
882 /*
883 * if we have idle queues and no rt or be queues had pending
884 * requests, either allow immediate service if the grace period
885 * has passed or arm the idle grace timer
886 */
887 if (!cfqq && !list_empty(&cfqd->idle_rr)) {
888 unsigned long end = cfqd->last_end_request + CFQ_IDLE_GRACE;
889
890 if (time_after_eq(jiffies, end))
891 cfqq = list_entry_cfqq(cfqd->idle_rr.next);
892 else
893 mod_timer(&cfqd->idle_class_timer, end);
894 }
895
896 __cfq_set_active_queue(cfqd, cfqq);
897 return cfqq;
898}
899
900/*
901 * current cfqq expired its slice (or was too idle), select new one
902 */
903static void
904__cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
905 int preempted)
906{
907 unsigned long now = jiffies;
908
909 if (cfq_cfqq_wait_request(cfqq))
910 del_timer(&cfqd->idle_slice_timer);
911
912 if (!preempted && !cfq_cfqq_dispatched(cfqq))
913 cfqq->service_last = now;
914
915 cfq_clear_cfqq_must_dispatch(cfqq);
916 cfq_clear_cfqq_wait_request(cfqq);
917
918 /*
919 * store what was left of this slice, if the queue idled out
920 * or was preempted
921 */
922 if (time_after(now, cfqq->slice_end))
923 cfqq->slice_left = now - cfqq->slice_end;
924 else
925 cfqq->slice_left = 0;
926
927 if (cfq_cfqq_on_rr(cfqq))
928 cfq_resort_rr_list(cfqq, preempted);
929
930 if (cfqq == cfqd->active_queue)
931 cfqd->active_queue = NULL;
932
933 if (cfqd->active_cic) {
934 put_io_context(cfqd->active_cic->ioc);
935 cfqd->active_cic = NULL;
936 }
937
938 cfqd->dispatch_slice = 0;
939}
940
941static inline void cfq_slice_expired(struct cfq_data *cfqd, int preempted)
942{
943 struct cfq_queue *cfqq = cfqd->active_queue;
944
945 if (cfqq) {
946 /*
947 * use deferred expiry, if there are requests in progress as
948 * not to disturb the slice of the next queue
949 */
950 if (cfq_cfqq_dispatched(cfqq))
951 cfq_mark_cfqq_expired(cfqq);
952 else
953 __cfq_slice_expired(cfqd, cfqq, preempted);
954 }
955}
956
957static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
958
959{
960 WARN_ON(!RB_EMPTY(&cfqq->sort_list));
961 WARN_ON(cfqq != cfqd->active_queue);
962
963 /*
964 * idle is disabled, either manually or by past process history
965 */
966 if (!cfqd->cfq_slice_idle)
967 return 0;
968 if (!cfq_cfqq_idle_window(cfqq))
969 return 0;
970 /*
971 * task has exited, don't wait
972 */
973 if (cfqd->active_cic && !cfqd->active_cic->ioc->task)
974 return 0;
975
976 cfq_mark_cfqq_must_dispatch(cfqq);
977 cfq_mark_cfqq_wait_request(cfqq);
978
979 if (!timer_pending(&cfqd->idle_slice_timer)) {
980 unsigned long slice_left = min(cfqq->slice_end - 1, (unsigned long) cfqd->cfq_slice_idle);
981
982 cfqd->idle_slice_timer.expires = jiffies + slice_left;
983 add_timer(&cfqd->idle_slice_timer);
984 }
985
986 return 1;
726} 987}
727 988
728/* 989/*
@@ -738,31 +999,40 @@ static void cfq_dispatch_sort(request_queue_t *q, struct cfq_rq *crq)
738 struct request *__rq; 999 struct request *__rq;
739 sector_t last; 1000 sector_t last;
740 1001
741 cfq_del_crq_rb(crq);
742 cfq_remove_merge_hints(q, crq);
743 list_del(&crq->request->queuelist); 1002 list_del(&crq->request->queuelist);
744 1003
745 last = cfqd->last_sector; 1004 last = cfqd->last_sector;
746 while ((entry = entry->prev) != head) { 1005 list_for_each_entry_reverse(__rq, head, queuelist) {
747 __rq = list_entry_rq(entry); 1006 struct cfq_rq *__crq = RQ_DATA(__rq);
748 1007
749 if (blk_barrier_rq(crq->request)) 1008 if (blk_barrier_rq(__rq))
750 break; 1009 break;
751 if (!blk_fs_request(crq->request)) 1010 if (!blk_fs_request(__rq))
1011 break;
1012 if (cfq_crq_requeued(__crq))
752 break; 1013 break;
753 1014
754 if (crq->request->sector > __rq->sector) 1015 if (__rq->sector <= crq->request->sector)
755 break; 1016 break;
756 if (__rq->sector > last && crq->request->sector < last) { 1017 if (__rq->sector > last && crq->request->sector < last) {
757 last = crq->request->sector; 1018 last = crq->request->sector + crq->request->nr_sectors;
758 break; 1019 break;
759 } 1020 }
1021 entry = &__rq->queuelist;
760 } 1022 }
761 1023
762 cfqd->last_sector = last; 1024 cfqd->last_sector = last;
763 crq->in_flight = 1; 1025
764 cfqq->in_flight++; 1026 cfqq->next_crq = cfq_find_next_crq(cfqd, cfqq, crq);
765 list_add(&crq->request->queuelist, entry); 1027
1028 cfq_del_crq_rb(crq);
1029 cfq_remove_merge_hints(q, crq);
1030
1031 cfq_mark_crq_in_flight(crq);
1032 cfq_clear_crq_requeued(crq);
1033
1034 cfqq->on_dispatch[cfq_crq_is_sync(crq)]++;
1035 list_add_tail(&crq->request->queuelist, entry);
766} 1036}
767 1037
768/* 1038/*
@@ -771,173 +1041,225 @@ static void cfq_dispatch_sort(request_queue_t *q, struct cfq_rq *crq)
771static inline struct cfq_rq *cfq_check_fifo(struct cfq_queue *cfqq) 1041static inline struct cfq_rq *cfq_check_fifo(struct cfq_queue *cfqq)
772{ 1042{
773 struct cfq_data *cfqd = cfqq->cfqd; 1043 struct cfq_data *cfqd = cfqq->cfqd;
774 const int reads = !list_empty(&cfqq->fifo[0]); 1044 struct request *rq;
775 const int writes = !list_empty(&cfqq->fifo[1]);
776 unsigned long now = jiffies;
777 struct cfq_rq *crq; 1045 struct cfq_rq *crq;
778 1046
779 if (time_before(now, cfqq->last_fifo_expire + cfqd->cfq_fifo_batch_expire)) 1047 if (cfq_cfqq_fifo_expire(cfqq))
780 return NULL; 1048 return NULL;
781 1049
782 crq = RQ_DATA(list_entry(cfqq->fifo[0].next, struct request, queuelist)); 1050 if (!list_empty(&cfqq->fifo)) {
783 if (reads && time_after(now, crq->queue_start + cfqd->cfq_fifo_expire_r)) { 1051 int fifo = cfq_cfqq_class_sync(cfqq);
784 cfqq->last_fifo_expire = now;
785 return crq;
786 }
787 1052
788 crq = RQ_DATA(list_entry(cfqq->fifo[1].next, struct request, queuelist)); 1053 crq = RQ_DATA(list_entry_fifo(cfqq->fifo.next));
789 if (writes && time_after(now, crq->queue_start + cfqd->cfq_fifo_expire_w)) { 1054 rq = crq->request;
790 cfqq->last_fifo_expire = now; 1055 if (time_after(jiffies, rq->start_time + cfqd->cfq_fifo_expire[fifo])) {
791 return crq; 1056 cfq_mark_cfqq_fifo_expire(cfqq);
1057 return crq;
1058 }
792 } 1059 }
793 1060
794 return NULL; 1061 return NULL;
795} 1062}
796 1063
797/* 1064/*
798 * dispatch a single request from given queue 1065 * Scale schedule slice based on io priority. Use the sync time slice only
1066 * if a queue is marked sync and has sync io queued. A sync queue with async
1067 * io only, should not get full sync slice length.
799 */ 1068 */
1069static inline int
1070cfq_prio_to_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1071{
1072 const int base_slice = cfqd->cfq_slice[cfq_cfqq_sync(cfqq)];
1073
1074 WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
1075
1076 return base_slice + (base_slice/CFQ_SLICE_SCALE * (4 - cfqq->ioprio));
1077}
1078
800static inline void 1079static inline void
801cfq_dispatch_request(request_queue_t *q, struct cfq_data *cfqd, 1080cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
802 struct cfq_queue *cfqq)
803{ 1081{
804 struct cfq_rq *crq; 1082 cfqq->slice_end = cfq_prio_to_slice(cfqd, cfqq) + jiffies;
1083}
1084
1085static inline int
1086cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1087{
1088 const int base_rq = cfqd->cfq_slice_async_rq;
1089
1090 WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
1091
1092 return 2 * (base_rq + base_rq * (CFQ_PRIO_LISTS - 1 - cfqq->ioprio));
1093}
1094
1095/*
1096 * get next queue for service
1097 */
1098static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd, int force)
1099{
1100 unsigned long now = jiffies;
1101 struct cfq_queue *cfqq;
1102
1103 cfqq = cfqd->active_queue;
1104 if (!cfqq)
1105 goto new_queue;
1106
1107 if (cfq_cfqq_expired(cfqq))
1108 goto new_queue;
805 1109
806 /* 1110 /*
807 * follow expired path, else get first next available 1111 * slice has expired
808 */ 1112 */
809 if ((crq = cfq_check_fifo(cfqq)) == NULL) { 1113 if (!cfq_cfqq_must_dispatch(cfqq) && time_after(now, cfqq->slice_end))
810 if (cfqd->find_best_crq) 1114 goto expire;
811 crq = cfqq->next_crq;
812 else
813 crq = rb_entry_crq(rb_first(&cfqq->sort_list));
814 }
815
816 cfqd->last_sector = crq->request->sector + crq->request->nr_sectors;
817 1115
818 /* 1116 /*
819 * finally, insert request into driver list 1117 * if queue has requests, dispatch one. if not, check if
1118 * enough slice is left to wait for one
820 */ 1119 */
821 cfq_dispatch_sort(q, crq); 1120 if (!RB_EMPTY(&cfqq->sort_list))
1121 goto keep_queue;
1122 else if (!force && cfq_cfqq_class_sync(cfqq) &&
1123 time_before(now, cfqq->slice_end)) {
1124 if (cfq_arm_slice_timer(cfqd, cfqq))
1125 return NULL;
1126 }
1127
1128expire:
1129 cfq_slice_expired(cfqd, 0);
1130new_queue:
1131 cfqq = cfq_set_active_queue(cfqd);
1132keep_queue:
1133 return cfqq;
822} 1134}
823 1135
824static int cfq_dispatch_requests(request_queue_t *q, int max_dispatch) 1136static int
1137__cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1138 int max_dispatch)
825{ 1139{
826 struct cfq_data *cfqd = q->elevator->elevator_data; 1140 int dispatched = 0;
827 struct cfq_queue *cfqq;
828 struct list_head *entry, *tmp;
829 int queued, busy_queues, first_round;
830 1141
831 if (list_empty(&cfqd->rr_list)) 1142 BUG_ON(RB_EMPTY(&cfqq->sort_list));
832 return 0;
833 1143
834 queued = 0; 1144 do {
835 first_round = 1; 1145 struct cfq_rq *crq;
836restart:
837 busy_queues = 0;
838 list_for_each_safe(entry, tmp, &cfqd->rr_list) {
839 cfqq = list_entry_cfqq(entry);
840 1146
841 BUG_ON(RB_EMPTY(&cfqq->sort_list)); 1147 /*
1148 * follow expired path, else get first next available
1149 */
1150 if ((crq = cfq_check_fifo(cfqq)) == NULL)
1151 crq = cfqq->next_crq;
842 1152
843 /* 1153 /*
844 * first round of queueing, only select from queues that 1154 * finally, insert request into driver dispatch list
845 * don't already have io in-flight
846 */ 1155 */
847 if (first_round && cfqq->in_flight) 1156 cfq_dispatch_sort(cfqd->queue, crq);
848 continue;
849 1157
850 cfq_dispatch_request(q, cfqd, cfqq); 1158 cfqd->dispatch_slice++;
1159 dispatched++;
851 1160
852 if (!RB_EMPTY(&cfqq->sort_list)) 1161 if (!cfqd->active_cic) {
853 busy_queues++; 1162 atomic_inc(&crq->io_context->ioc->refcount);
1163 cfqd->active_cic = crq->io_context;
1164 }
854 1165
855 queued++; 1166 if (RB_EMPTY(&cfqq->sort_list))
856 } 1167 break;
1168
1169 } while (dispatched < max_dispatch);
1170
1171 /*
1172 * if slice end isn't set yet, set it. if at least one request was
1173 * sync, use the sync time slice value
1174 */
1175 if (!cfqq->slice_end)
1176 cfq_set_prio_slice(cfqd, cfqq);
1177
1178 /*
1179 * expire an async queue immediately if it has used up its slice. idle
1180 * queue always expire after 1 dispatch round.
1181 */
1182 if ((!cfq_cfqq_sync(cfqq) &&
1183 cfqd->dispatch_slice >= cfq_prio_to_maxrq(cfqd, cfqq)) ||
1184 cfq_class_idle(cfqq))
1185 cfq_slice_expired(cfqd, 0);
1186
1187 return dispatched;
1188}
1189
1190static int
1191cfq_dispatch_requests(request_queue_t *q, int max_dispatch, int force)
1192{
1193 struct cfq_data *cfqd = q->elevator->elevator_data;
1194 struct cfq_queue *cfqq;
1195
1196 if (!cfqd->busy_queues)
1197 return 0;
1198
1199 cfqq = cfq_select_queue(cfqd, force);
1200 if (cfqq) {
1201 cfq_clear_cfqq_must_dispatch(cfqq);
1202 cfq_clear_cfqq_wait_request(cfqq);
1203 del_timer(&cfqd->idle_slice_timer);
857 1204
858 if ((queued < max_dispatch) && (busy_queues || first_round)) { 1205 if (cfq_class_idle(cfqq))
859 first_round = 0; 1206 max_dispatch = 1;
860 goto restart; 1207
1208 return __cfq_dispatch_requests(cfqd, cfqq, max_dispatch);
861 } 1209 }
862 1210
863 return queued; 1211 return 0;
864} 1212}
865 1213
866static inline void cfq_account_dispatch(struct cfq_rq *crq) 1214static inline void cfq_account_dispatch(struct cfq_rq *crq)
867{ 1215{
868 struct cfq_queue *cfqq = crq->cfq_queue; 1216 struct cfq_queue *cfqq = crq->cfq_queue;
869 struct cfq_data *cfqd = cfqq->cfqd; 1217 struct cfq_data *cfqd = cfqq->cfqd;
870 unsigned long now, elapsed;
871 1218
872 if (!blk_fs_request(crq->request)) 1219 if (unlikely(!blk_fs_request(crq->request)))
873 return; 1220 return;
874 1221
875 /* 1222 /*
876 * accounted bit is necessary since some drivers will call 1223 * accounted bit is necessary since some drivers will call
877 * elv_next_request() many times for the same request (eg ide) 1224 * elv_next_request() many times for the same request (eg ide)
878 */ 1225 */
879 if (crq->accounted) 1226 if (cfq_crq_in_driver(crq))
880 return; 1227 return;
881 1228
882 now = jiffies; 1229 cfq_mark_crq_in_driver(crq);
883 if (cfqq->service_start == ~0UL) 1230 cfqd->rq_in_driver++;
884 cfqq->service_start = now;
885
886 /*
887 * on drives with tagged command queueing, command turn-around time
888 * doesn't necessarily reflect the time spent processing this very
889 * command inside the drive. so do the accounting differently there,
890 * by just sorting on the number of requests
891 */
892 if (cfqd->cfq_tagged) {
893 if (time_after(now, cfqq->service_start + cfq_service)) {
894 cfqq->service_start = now;
895 cfqq->service_used /= 10;
896 }
897
898 cfqq->service_used++;
899 cfq_sort_rr_list(cfqq, 0);
900 }
901
902 elapsed = now - crq->queue_start;
903 if (elapsed > max_elapsed_dispatch)
904 max_elapsed_dispatch = elapsed;
905
906 crq->accounted = 1;
907 crq->service_start = now;
908
909 if (++cfqd->rq_in_driver >= CFQ_MAX_TAG && !cfqd->cfq_tagged) {
910 cfqq->cfqd->cfq_tagged = 1;
911 printk("cfq: depth %d reached, tagging now on\n", CFQ_MAX_TAG);
912 }
913} 1231}
914 1232
915static inline void 1233static inline void
916cfq_account_completion(struct cfq_queue *cfqq, struct cfq_rq *crq) 1234cfq_account_completion(struct cfq_queue *cfqq, struct cfq_rq *crq)
917{ 1235{
918 struct cfq_data *cfqd = cfqq->cfqd; 1236 struct cfq_data *cfqd = cfqq->cfqd;
1237 unsigned long now;
919 1238
920 if (!crq->accounted) 1239 if (!cfq_crq_in_driver(crq))
921 return; 1240 return;
922 1241
1242 now = jiffies;
1243
923 WARN_ON(!cfqd->rq_in_driver); 1244 WARN_ON(!cfqd->rq_in_driver);
924 cfqd->rq_in_driver--; 1245 cfqd->rq_in_driver--;
925 1246
926 if (!cfqd->cfq_tagged) { 1247 if (!cfq_class_idle(cfqq))
927 unsigned long now = jiffies; 1248 cfqd->last_end_request = now;
928 unsigned long duration = now - crq->service_start;
929 1249
930 if (time_after(now, cfqq->service_start + cfq_service)) { 1250 if (!cfq_cfqq_dispatched(cfqq)) {
931 cfqq->service_start = now; 1251 if (cfq_cfqq_on_rr(cfqq)) {
932 cfqq->service_used >>= 3; 1252 cfqq->service_last = now;
1253 cfq_resort_rr_list(cfqq, 0);
1254 }
1255 if (cfq_cfqq_expired(cfqq)) {
1256 __cfq_slice_expired(cfqd, cfqq, 0);
1257 cfq_schedule_dispatch(cfqd);
933 } 1258 }
934
935 cfqq->service_used += duration;
936 cfq_sort_rr_list(cfqq, 0);
937
938 if (duration > max_elapsed_crq)
939 max_elapsed_crq = duration;
940 } 1259 }
1260
1261 if (cfq_crq_is_sync(crq))
1262 crq->io_context->last_end_request = now;
941} 1263}
942 1264
943static struct request *cfq_next_request(request_queue_t *q) 1265static struct request *cfq_next_request(request_queue_t *q)
@@ -950,7 +1272,18 @@ static struct request *cfq_next_request(request_queue_t *q)
950dispatch: 1272dispatch:
951 rq = list_entry_rq(q->queue_head.next); 1273 rq = list_entry_rq(q->queue_head.next);
952 1274
953 if ((crq = RQ_DATA(rq)) != NULL) { 1275 crq = RQ_DATA(rq);
1276 if (crq) {
1277 struct cfq_queue *cfqq = crq->cfq_queue;
1278
1279 /*
1280 * if idle window is disabled, allow queue buildup
1281 */
1282 if (!cfq_crq_in_driver(crq) &&
1283 !cfq_cfqq_idle_window(cfqq) &&
1284 cfqd->rq_in_driver >= cfqd->cfq_max_depth)
1285 return NULL;
1286
954 cfq_remove_merge_hints(q, crq); 1287 cfq_remove_merge_hints(q, crq);
955 cfq_account_dispatch(crq); 1288 cfq_account_dispatch(crq);
956 } 1289 }
@@ -958,7 +1291,7 @@ dispatch:
958 return rq; 1291 return rq;
959 } 1292 }
960 1293
961 if (cfq_dispatch_requests(q, cfqd->cfq_quantum)) 1294 if (cfq_dispatch_requests(q, cfqd->cfq_quantum, 0))
962 goto dispatch; 1295 goto dispatch;
963 1296
964 return NULL; 1297 return NULL;
@@ -972,13 +1305,21 @@ dispatch:
972 */ 1305 */
973static void cfq_put_queue(struct cfq_queue *cfqq) 1306static void cfq_put_queue(struct cfq_queue *cfqq)
974{ 1307{
975 BUG_ON(!atomic_read(&cfqq->ref)); 1308 struct cfq_data *cfqd = cfqq->cfqd;
1309
1310 BUG_ON(atomic_read(&cfqq->ref) <= 0);
976 1311
977 if (!atomic_dec_and_test(&cfqq->ref)) 1312 if (!atomic_dec_and_test(&cfqq->ref))
978 return; 1313 return;
979 1314
980 BUG_ON(rb_first(&cfqq->sort_list)); 1315 BUG_ON(rb_first(&cfqq->sort_list));
981 BUG_ON(cfqq->on_rr); 1316 BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
1317 BUG_ON(cfq_cfqq_on_rr(cfqq));
1318
1319 if (unlikely(cfqd->active_queue == cfqq)) {
1320 __cfq_slice_expired(cfqd, cfqq, 0);
1321 cfq_schedule_dispatch(cfqd);
1322 }
982 1323
983 cfq_put_cfqd(cfqq->cfqd); 1324 cfq_put_cfqd(cfqq->cfqd);
984 1325
@@ -991,15 +1332,17 @@ static void cfq_put_queue(struct cfq_queue *cfqq)
991} 1332}
992 1333
993static inline struct cfq_queue * 1334static inline struct cfq_queue *
994__cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key, const int hashval) 1335__cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned int prio,
1336 const int hashval)
995{ 1337{
996 struct hlist_head *hash_list = &cfqd->cfq_hash[hashval]; 1338 struct hlist_head *hash_list = &cfqd->cfq_hash[hashval];
997 struct hlist_node *entry, *next; 1339 struct hlist_node *entry, *next;
998 1340
999 hlist_for_each_safe(entry, next, hash_list) { 1341 hlist_for_each_safe(entry, next, hash_list) {
1000 struct cfq_queue *__cfqq = list_entry_qhash(entry); 1342 struct cfq_queue *__cfqq = list_entry_qhash(entry);
1343 const unsigned short __p = IOPRIO_PRIO_VALUE(__cfqq->ioprio_class, __cfqq->ioprio);
1001 1344
1002 if (__cfqq->key == key) 1345 if (__cfqq->key == key && (__p == prio || prio == CFQ_KEY_ANY))
1003 return __cfqq; 1346 return __cfqq;
1004 } 1347 }
1005 1348
@@ -1007,94 +1350,220 @@ __cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key, const int hashval)
1007} 1350}
1008 1351
1009static struct cfq_queue * 1352static struct cfq_queue *
1010cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned long key) 1353cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned short prio)
1011{ 1354{
1012 return __cfq_find_cfq_hash(cfqd, key, hash_long(key, CFQ_QHASH_SHIFT)); 1355 return __cfq_find_cfq_hash(cfqd, key, prio, hash_long(key, CFQ_QHASH_SHIFT));
1013} 1356}
1014 1357
1015static inline void 1358static void cfq_free_io_context(struct cfq_io_context *cic)
1016cfq_rehash_cfqq(struct cfq_data *cfqd, struct cfq_queue **cfqq,
1017 struct cfq_io_context *cic)
1018{ 1359{
1019 unsigned long hashkey = cfq_hash_key(cfqd, current); 1360 struct cfq_io_context *__cic;
1020 unsigned long hashval = hash_long(hashkey, CFQ_QHASH_SHIFT); 1361 struct list_head *entry, *next;
1021 struct cfq_queue *__cfqq;
1022 unsigned long flags;
1023
1024 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
1025 1362
1026 hlist_del(&(*cfqq)->cfq_hash); 1363 list_for_each_safe(entry, next, &cic->list) {
1027 1364 __cic = list_entry(entry, struct cfq_io_context, list);
1028 __cfqq = __cfq_find_cfq_hash(cfqd, hashkey, hashval); 1365 kmem_cache_free(cfq_ioc_pool, __cic);
1029 if (!__cfqq || __cfqq == *cfqq) {
1030 __cfqq = *cfqq;
1031 hlist_add_head(&__cfqq->cfq_hash, &cfqd->cfq_hash[hashval]);
1032 __cfqq->key_type = cfqd->key_type;
1033 } else {
1034 atomic_inc(&__cfqq->ref);
1035 cic->cfqq = __cfqq;
1036 cfq_put_queue(*cfqq);
1037 *cfqq = __cfqq;
1038 } 1366 }
1039 1367
1040 cic->cfqq = __cfqq; 1368 kmem_cache_free(cfq_ioc_pool, cic);
1041 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
1042} 1369}
1043 1370
1044static void cfq_free_io_context(struct cfq_io_context *cic) 1371/*
1372 * Called with interrupts disabled
1373 */
1374static void cfq_exit_single_io_context(struct cfq_io_context *cic)
1045{ 1375{
1046 kmem_cache_free(cfq_ioc_pool, cic); 1376 struct cfq_data *cfqd = cic->cfqq->cfqd;
1377 request_queue_t *q = cfqd->queue;
1378
1379 WARN_ON(!irqs_disabled());
1380
1381 spin_lock(q->queue_lock);
1382
1383 if (unlikely(cic->cfqq == cfqd->active_queue)) {
1384 __cfq_slice_expired(cfqd, cic->cfqq, 0);
1385 cfq_schedule_dispatch(cfqd);
1386 }
1387
1388 cfq_put_queue(cic->cfqq);
1389 cic->cfqq = NULL;
1390 spin_unlock(q->queue_lock);
1047} 1391}
1048 1392
1049/* 1393/*
1050 * locking hierarchy is: io_context lock -> queue locks 1394 * Another task may update the task cic list, if it is doing a queue lookup
1395 * on its behalf. cfq_cic_lock excludes such concurrent updates
1051 */ 1396 */
1052static void cfq_exit_io_context(struct cfq_io_context *cic) 1397static void cfq_exit_io_context(struct cfq_io_context *cic)
1053{ 1398{
1054 struct cfq_queue *cfqq = cic->cfqq; 1399 struct cfq_io_context *__cic;
1055 struct list_head *entry = &cic->list; 1400 struct list_head *entry;
1056 request_queue_t *q;
1057 unsigned long flags; 1401 unsigned long flags;
1058 1402
1403 local_irq_save(flags);
1404
1059 /* 1405 /*
1060 * put the reference this task is holding to the various queues 1406 * put the reference this task is holding to the various queues
1061 */ 1407 */
1062 spin_lock_irqsave(&cic->ioc->lock, flags); 1408 list_for_each(entry, &cic->list) {
1063 while ((entry = cic->list.next) != &cic->list) {
1064 struct cfq_io_context *__cic;
1065
1066 __cic = list_entry(entry, struct cfq_io_context, list); 1409 __cic = list_entry(entry, struct cfq_io_context, list);
1067 list_del(entry); 1410 cfq_exit_single_io_context(__cic);
1068
1069 q = __cic->cfqq->cfqd->queue;
1070 spin_lock(q->queue_lock);
1071 cfq_put_queue(__cic->cfqq);
1072 spin_unlock(q->queue_lock);
1073 } 1411 }
1074 1412
1075 q = cfqq->cfqd->queue; 1413 cfq_exit_single_io_context(cic);
1076 spin_lock(q->queue_lock); 1414 local_irq_restore(flags);
1077 cfq_put_queue(cfqq);
1078 spin_unlock(q->queue_lock);
1079
1080 cic->cfqq = NULL;
1081 spin_unlock_irqrestore(&cic->ioc->lock, flags);
1082} 1415}
1083 1416
1084static struct cfq_io_context *cfq_alloc_io_context(int gfp_flags) 1417static struct cfq_io_context *
1418cfq_alloc_io_context(struct cfq_data *cfqd, int gfp_mask)
1085{ 1419{
1086 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_flags); 1420 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_mask);
1087 1421
1088 if (cic) { 1422 if (cic) {
1089 cic->dtor = cfq_free_io_context;
1090 cic->exit = cfq_exit_io_context;
1091 INIT_LIST_HEAD(&cic->list); 1423 INIT_LIST_HEAD(&cic->list);
1092 cic->cfqq = NULL; 1424 cic->cfqq = NULL;
1425 cic->key = NULL;
1426 cic->last_end_request = jiffies;
1427 cic->ttime_total = 0;
1428 cic->ttime_samples = 0;
1429 cic->ttime_mean = 0;
1430 cic->dtor = cfq_free_io_context;
1431 cic->exit = cfq_exit_io_context;
1093 } 1432 }
1094 1433
1095 return cic; 1434 return cic;
1096} 1435}
1097 1436
1437static void cfq_init_prio_data(struct cfq_queue *cfqq)
1438{
1439 struct task_struct *tsk = current;
1440 int ioprio_class;
1441
1442 if (!cfq_cfqq_prio_changed(cfqq))
1443 return;
1444
1445 ioprio_class = IOPRIO_PRIO_CLASS(tsk->ioprio);
1446 switch (ioprio_class) {
1447 default:
1448 printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
1449 case IOPRIO_CLASS_NONE:
1450 /*
1451 * no prio set, place us in the middle of the BE classes
1452 */
1453 cfqq->ioprio = task_nice_ioprio(tsk);
1454 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1455 break;
1456 case IOPRIO_CLASS_RT:
1457 cfqq->ioprio = task_ioprio(tsk);
1458 cfqq->ioprio_class = IOPRIO_CLASS_RT;
1459 break;
1460 case IOPRIO_CLASS_BE:
1461 cfqq->ioprio = task_ioprio(tsk);
1462 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1463 break;
1464 case IOPRIO_CLASS_IDLE:
1465 cfqq->ioprio_class = IOPRIO_CLASS_IDLE;
1466 cfqq->ioprio = 7;
1467 cfq_clear_cfqq_idle_window(cfqq);
1468 break;
1469 }
1470
1471 /*
1472 * keep track of original prio settings in case we have to temporarily
1473 * elevate the priority of this queue
1474 */
1475 cfqq->org_ioprio = cfqq->ioprio;
1476 cfqq->org_ioprio_class = cfqq->ioprio_class;
1477
1478 if (cfq_cfqq_on_rr(cfqq))
1479 cfq_resort_rr_list(cfqq, 0);
1480
1481 cfq_clear_cfqq_prio_changed(cfqq);
1482}
1483
1484static inline void changed_ioprio(struct cfq_queue *cfqq)
1485{
1486 if (cfqq) {
1487 struct cfq_data *cfqd = cfqq->cfqd;
1488
1489 spin_lock(cfqd->queue->queue_lock);
1490 cfq_mark_cfqq_prio_changed(cfqq);
1491 cfq_init_prio_data(cfqq);
1492 spin_unlock(cfqd->queue->queue_lock);
1493 }
1494}
1495
1496/*
1497 * callback from sys_ioprio_set, irqs are disabled
1498 */
1499static int cfq_ioc_set_ioprio(struct io_context *ioc, unsigned int ioprio)
1500{
1501 struct cfq_io_context *cic = ioc->cic;
1502
1503 changed_ioprio(cic->cfqq);
1504
1505 list_for_each_entry(cic, &cic->list, list)
1506 changed_ioprio(cic->cfqq);
1507
1508 return 0;
1509}
1510
1511static struct cfq_queue *
1512cfq_get_queue(struct cfq_data *cfqd, unsigned int key, unsigned short ioprio,
1513 int gfp_mask)
1514{
1515 const int hashval = hash_long(key, CFQ_QHASH_SHIFT);
1516 struct cfq_queue *cfqq, *new_cfqq = NULL;
1517
1518retry:
1519 cfqq = __cfq_find_cfq_hash(cfqd, key, ioprio, hashval);
1520
1521 if (!cfqq) {
1522 if (new_cfqq) {
1523 cfqq = new_cfqq;
1524 new_cfqq = NULL;
1525 } else if (gfp_mask & __GFP_WAIT) {
1526 spin_unlock_irq(cfqd->queue->queue_lock);
1527 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask);
1528 spin_lock_irq(cfqd->queue->queue_lock);
1529 goto retry;
1530 } else {
1531 cfqq = kmem_cache_alloc(cfq_pool, gfp_mask);
1532 if (!cfqq)
1533 goto out;
1534 }
1535
1536 memset(cfqq, 0, sizeof(*cfqq));
1537
1538 INIT_HLIST_NODE(&cfqq->cfq_hash);
1539 INIT_LIST_HEAD(&cfqq->cfq_list);
1540 RB_CLEAR_ROOT(&cfqq->sort_list);
1541 INIT_LIST_HEAD(&cfqq->fifo);
1542
1543 cfqq->key = key;
1544 hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]);
1545 atomic_set(&cfqq->ref, 0);
1546 cfqq->cfqd = cfqd;
1547 atomic_inc(&cfqd->ref);
1548 cfqq->service_last = 0;
1549 /*
1550 * set ->slice_left to allow preemption for a new process
1551 */
1552 cfqq->slice_left = 2 * cfqd->cfq_slice_idle;
1553 cfq_mark_cfqq_idle_window(cfqq);
1554 cfq_mark_cfqq_prio_changed(cfqq);
1555 cfq_init_prio_data(cfqq);
1556 }
1557
1558 if (new_cfqq)
1559 kmem_cache_free(cfq_pool, new_cfqq);
1560
1561 atomic_inc(&cfqq->ref);
1562out:
1563 WARN_ON((gfp_mask & __GFP_WAIT) && !cfqq);
1564 return cfqq;
1565}
1566
1098/* 1567/*
1099 * Setup general io context and cfq io context. There can be several cfq 1568 * Setup general io context and cfq io context. There can be several cfq
1100 * io contexts per general io context, if this process is doing io to more 1569 * io contexts per general io context, if this process is doing io to more
@@ -1102,39 +1571,39 @@ static struct cfq_io_context *cfq_alloc_io_context(int gfp_flags)
1102 * cfqq, so we don't need to worry about it disappearing 1571 * cfqq, so we don't need to worry about it disappearing
1103 */ 1572 */
1104static struct cfq_io_context * 1573static struct cfq_io_context *
1105cfq_get_io_context(struct cfq_queue **cfqq, int gfp_flags) 1574cfq_get_io_context(struct cfq_data *cfqd, pid_t pid, int gfp_mask)
1106{ 1575{
1107 struct cfq_data *cfqd = (*cfqq)->cfqd; 1576 struct io_context *ioc = NULL;
1108 struct cfq_queue *__cfqq = *cfqq;
1109 struct cfq_io_context *cic; 1577 struct cfq_io_context *cic;
1110 struct io_context *ioc;
1111 1578
1112 might_sleep_if(gfp_flags & __GFP_WAIT); 1579 might_sleep_if(gfp_mask & __GFP_WAIT);
1113 1580
1114 ioc = get_io_context(gfp_flags); 1581 ioc = get_io_context(gfp_mask);
1115 if (!ioc) 1582 if (!ioc)
1116 return NULL; 1583 return NULL;
1117 1584
1118 if ((cic = ioc->cic) == NULL) { 1585 if ((cic = ioc->cic) == NULL) {
1119 cic = cfq_alloc_io_context(gfp_flags); 1586 cic = cfq_alloc_io_context(cfqd, gfp_mask);
1120 1587
1121 if (cic == NULL) 1588 if (cic == NULL)
1122 goto err; 1589 goto err;
1123 1590
1591 /*
1592 * manually increment generic io_context usage count, it
1593 * cannot go away since we are already holding one ref to it
1594 */
1124 ioc->cic = cic; 1595 ioc->cic = cic;
1596 ioc->set_ioprio = cfq_ioc_set_ioprio;
1125 cic->ioc = ioc; 1597 cic->ioc = ioc;
1126 cic->cfqq = __cfqq; 1598 cic->key = cfqd;
1127 atomic_inc(&__cfqq->ref); 1599 atomic_inc(&cfqd->ref);
1128 } else { 1600 } else {
1129 struct cfq_io_context *__cic; 1601 struct cfq_io_context *__cic;
1130 unsigned long flags;
1131 1602
1132 /* 1603 /*
1133 * since the first cic on the list is actually the head 1604 * the first cic on the list is actually the head itself
1134 * itself, need to check this here or we'll duplicate an
1135 * cic per ioc for no reason
1136 */ 1605 */
1137 if (cic->cfqq == __cfqq) 1606 if (cic->key == cfqd)
1138 goto out; 1607 goto out;
1139 1608
1140 /* 1609 /*
@@ -1142,152 +1611,250 @@ cfq_get_io_context(struct cfq_queue **cfqq, int gfp_flags)
1142 * should be ok here, the list will usually not be more than 1611 * should be ok here, the list will usually not be more than
1143 * 1 or a few entries long 1612 * 1 or a few entries long
1144 */ 1613 */
1145 spin_lock_irqsave(&ioc->lock, flags);
1146 list_for_each_entry(__cic, &cic->list, list) { 1614 list_for_each_entry(__cic, &cic->list, list) {
1147 /* 1615 /*
1148 * this process is already holding a reference to 1616 * this process is already holding a reference to
1149 * this queue, so no need to get one more 1617 * this queue, so no need to get one more
1150 */ 1618 */
1151 if (__cic->cfqq == __cfqq) { 1619 if (__cic->key == cfqd) {
1152 cic = __cic; 1620 cic = __cic;
1153 spin_unlock_irqrestore(&ioc->lock, flags);
1154 goto out; 1621 goto out;
1155 } 1622 }
1156 } 1623 }
1157 spin_unlock_irqrestore(&ioc->lock, flags);
1158 1624
1159 /* 1625 /*
1160 * nope, process doesn't have a cic assoicated with this 1626 * nope, process doesn't have a cic assoicated with this
1161 * cfqq yet. get a new one and add to list 1627 * cfqq yet. get a new one and add to list
1162 */ 1628 */
1163 __cic = cfq_alloc_io_context(gfp_flags); 1629 __cic = cfq_alloc_io_context(cfqd, gfp_mask);
1164 if (__cic == NULL) 1630 if (__cic == NULL)
1165 goto err; 1631 goto err;
1166 1632
1167 __cic->ioc = ioc; 1633 __cic->ioc = ioc;
1168 __cic->cfqq = __cfqq; 1634 __cic->key = cfqd;
1169 atomic_inc(&__cfqq->ref); 1635 atomic_inc(&cfqd->ref);
1170 spin_lock_irqsave(&ioc->lock, flags);
1171 list_add(&__cic->list, &cic->list); 1636 list_add(&__cic->list, &cic->list);
1172 spin_unlock_irqrestore(&ioc->lock, flags);
1173
1174 cic = __cic; 1637 cic = __cic;
1175 *cfqq = __cfqq;
1176 } 1638 }
1177 1639
1178out: 1640out:
1179 /*
1180 * if key_type has been changed on the fly, we lazily rehash
1181 * each queue at lookup time
1182 */
1183 if ((*cfqq)->key_type != cfqd->key_type)
1184 cfq_rehash_cfqq(cfqd, cfqq, cic);
1185
1186 return cic; 1641 return cic;
1187err: 1642err:
1188 put_io_context(ioc); 1643 put_io_context(ioc);
1189 return NULL; 1644 return NULL;
1190} 1645}
1191 1646
1192static struct cfq_queue * 1647static void
1193__cfq_get_queue(struct cfq_data *cfqd, unsigned long key, int gfp_mask) 1648cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_io_context *cic)
1194{ 1649{
1195 const int hashval = hash_long(key, CFQ_QHASH_SHIFT); 1650 unsigned long elapsed, ttime;
1196 struct cfq_queue *cfqq, *new_cfqq = NULL;
1197
1198retry:
1199 cfqq = __cfq_find_cfq_hash(cfqd, key, hashval);
1200 1651
1201 if (!cfqq) { 1652 /*
1202 if (new_cfqq) { 1653 * if this context already has stuff queued, thinktime is from
1203 cfqq = new_cfqq; 1654 * last queue not last end
1204 new_cfqq = NULL; 1655 */
1205 } else { 1656#if 0
1206 spin_unlock_irq(cfqd->queue->queue_lock); 1657 if (time_after(cic->last_end_request, cic->last_queue))
1207 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask); 1658 elapsed = jiffies - cic->last_end_request;
1208 spin_lock_irq(cfqd->queue->queue_lock); 1659 else
1660 elapsed = jiffies - cic->last_queue;
1661#else
1662 elapsed = jiffies - cic->last_end_request;
1663#endif
1209 1664
1210 if (!new_cfqq && !(gfp_mask & __GFP_WAIT)) 1665 ttime = min(elapsed, 2UL * cfqd->cfq_slice_idle);
1211 goto out;
1212 1666
1213 goto retry; 1667 cic->ttime_samples = (7*cic->ttime_samples + 256) / 8;
1214 } 1668 cic->ttime_total = (7*cic->ttime_total + 256*ttime) / 8;
1669 cic->ttime_mean = (cic->ttime_total + 128) / cic->ttime_samples;
1670}
1215 1671
1216 memset(cfqq, 0, sizeof(*cfqq)); 1672#define sample_valid(samples) ((samples) > 80)
1217 1673
1218 INIT_HLIST_NODE(&cfqq->cfq_hash); 1674/*
1219 INIT_LIST_HEAD(&cfqq->cfq_list); 1675 * Disable idle window if the process thinks too long or seeks so much that
1220 RB_CLEAR_ROOT(&cfqq->sort_list); 1676 * it doesn't matter
1221 INIT_LIST_HEAD(&cfqq->fifo[0]); 1677 */
1222 INIT_LIST_HEAD(&cfqq->fifo[1]); 1678static void
1679cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1680 struct cfq_io_context *cic)
1681{
1682 int enable_idle = cfq_cfqq_idle_window(cfqq);
1223 1683
1224 cfqq->key = key; 1684 if (!cic->ioc->task || !cfqd->cfq_slice_idle)
1225 hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); 1685 enable_idle = 0;
1226 atomic_set(&cfqq->ref, 0); 1686 else if (sample_valid(cic->ttime_samples)) {
1227 cfqq->cfqd = cfqd; 1687 if (cic->ttime_mean > cfqd->cfq_slice_idle)
1228 atomic_inc(&cfqd->ref); 1688 enable_idle = 0;
1229 cfqq->key_type = cfqd->key_type; 1689 else
1230 cfqq->service_start = ~0UL; 1690 enable_idle = 1;
1231 } 1691 }
1232 1692
1233 if (new_cfqq) 1693 if (enable_idle)
1234 kmem_cache_free(cfq_pool, new_cfqq); 1694 cfq_mark_cfqq_idle_window(cfqq);
1695 else
1696 cfq_clear_cfqq_idle_window(cfqq);
1697}
1235 1698
1236 atomic_inc(&cfqq->ref); 1699
1237out: 1700/*
1238 WARN_ON((gfp_mask & __GFP_WAIT) && !cfqq); 1701 * Check if new_cfqq should preempt the currently active queue. Return 0 for
1239 return cfqq; 1702 * no or if we aren't sure, a 1 will cause a preempt.
1703 */
1704static int
1705cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
1706 struct cfq_rq *crq)
1707{
1708 struct cfq_queue *cfqq = cfqd->active_queue;
1709
1710 if (cfq_class_idle(new_cfqq))
1711 return 0;
1712
1713 if (!cfqq)
1714 return 1;
1715
1716 if (cfq_class_idle(cfqq))
1717 return 1;
1718 if (!cfq_cfqq_wait_request(new_cfqq))
1719 return 0;
1720 /*
1721 * if it doesn't have slice left, forget it
1722 */
1723 if (new_cfqq->slice_left < cfqd->cfq_slice_idle)
1724 return 0;
1725 if (cfq_crq_is_sync(crq) && !cfq_cfqq_sync(cfqq))
1726 return 1;
1727
1728 return 0;
1729}
1730
1731/*
1732 * cfqq preempts the active queue. if we allowed preempt with no slice left,
1733 * let it have half of its nominal slice.
1734 */
1735static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1736{
1737 struct cfq_queue *__cfqq, *next;
1738
1739 list_for_each_entry_safe(__cfqq, next, &cfqd->cur_rr, cfq_list)
1740 cfq_resort_rr_list(__cfqq, 1);
1741
1742 if (!cfqq->slice_left)
1743 cfqq->slice_left = cfq_prio_to_slice(cfqd, cfqq) / 2;
1744
1745 cfqq->slice_end = cfqq->slice_left + jiffies;
1746 __cfq_slice_expired(cfqd, cfqq, 1);
1747 __cfq_set_active_queue(cfqd, cfqq);
1240} 1748}
1241 1749
1242static void cfq_enqueue(struct cfq_data *cfqd, struct cfq_rq *crq) 1750/*
1751 * should really be a ll_rw_blk.c helper
1752 */
1753static void cfq_start_queueing(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1754{
1755 request_queue_t *q = cfqd->queue;
1756
1757 if (!blk_queue_plugged(q))
1758 q->request_fn(q);
1759 else
1760 __generic_unplug_device(q);
1761}
1762
1763/*
1764 * Called when a new fs request (crq) is added (to cfqq). Check if there's
1765 * something we should do about it
1766 */
1767static void
1768cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1769 struct cfq_rq *crq)
1243{ 1770{
1244 crq->is_sync = 0; 1771 const int sync = cfq_crq_is_sync(crq);
1245 if (rq_data_dir(crq->request) == READ || current->flags & PF_SYNCWRITE) 1772
1246 crq->is_sync = 1; 1773 cfqq->next_crq = cfq_choose_req(cfqd, cfqq->next_crq, crq);
1774
1775 if (sync) {
1776 struct cfq_io_context *cic = crq->io_context;
1777
1778 cfq_update_io_thinktime(cfqd, cic);
1779 cfq_update_idle_window(cfqd, cfqq, cic);
1780
1781 cic->last_queue = jiffies;
1782 }
1783
1784 if (cfqq == cfqd->active_queue) {
1785 /*
1786 * if we are waiting for a request for this queue, let it rip
1787 * immediately and flag that we must not expire this queue
1788 * just now
1789 */
1790 if (cfq_cfqq_wait_request(cfqq)) {
1791 cfq_mark_cfqq_must_dispatch(cfqq);
1792 del_timer(&cfqd->idle_slice_timer);
1793 cfq_start_queueing(cfqd, cfqq);
1794 }
1795 } else if (cfq_should_preempt(cfqd, cfqq, crq)) {
1796 /*
1797 * not the active queue - expire current slice if it is
1798 * idle and has expired it's mean thinktime or this new queue
1799 * has some old slice time left and is of higher priority
1800 */
1801 cfq_preempt_queue(cfqd, cfqq);
1802 cfq_mark_cfqq_must_dispatch(cfqq);
1803 cfq_start_queueing(cfqd, cfqq);
1804 }
1805}
1806
1807static void cfq_enqueue(struct cfq_data *cfqd, struct request *rq)
1808{
1809 struct cfq_rq *crq = RQ_DATA(rq);
1810 struct cfq_queue *cfqq = crq->cfq_queue;
1811
1812 cfq_init_prio_data(cfqq);
1247 1813
1248 cfq_add_crq_rb(crq); 1814 cfq_add_crq_rb(crq);
1249 crq->queue_start = jiffies;
1250 1815
1251 list_add_tail(&crq->request->queuelist, &crq->cfq_queue->fifo[crq->is_sync]); 1816 list_add_tail(&rq->queuelist, &cfqq->fifo);
1817
1818 if (rq_mergeable(rq)) {
1819 cfq_add_crq_hash(cfqd, crq);
1820
1821 if (!cfqd->queue->last_merge)
1822 cfqd->queue->last_merge = rq;
1823 }
1824
1825 cfq_crq_enqueued(cfqd, cfqq, crq);
1252} 1826}
1253 1827
1254static void 1828static void
1255cfq_insert_request(request_queue_t *q, struct request *rq, int where) 1829cfq_insert_request(request_queue_t *q, struct request *rq, int where)
1256{ 1830{
1257 struct cfq_data *cfqd = q->elevator->elevator_data; 1831 struct cfq_data *cfqd = q->elevator->elevator_data;
1258 struct cfq_rq *crq = RQ_DATA(rq);
1259 1832
1260 switch (where) { 1833 switch (where) {
1261 case ELEVATOR_INSERT_BACK: 1834 case ELEVATOR_INSERT_BACK:
1262 while (cfq_dispatch_requests(q, cfqd->cfq_quantum)) 1835 while (cfq_dispatch_requests(q, INT_MAX, 1))
1263 ; 1836 ;
1264 list_add_tail(&rq->queuelist, &q->queue_head); 1837 list_add_tail(&rq->queuelist, &q->queue_head);
1838 /*
1839 * If we were idling with pending requests on
1840 * inactive cfqqs, force dispatching will
1841 * remove the idle timer and the queue won't
1842 * be kicked by __make_request() afterward.
1843 * Kick it here.
1844 */
1845 cfq_schedule_dispatch(cfqd);
1265 break; 1846 break;
1266 case ELEVATOR_INSERT_FRONT: 1847 case ELEVATOR_INSERT_FRONT:
1267 list_add(&rq->queuelist, &q->queue_head); 1848 list_add(&rq->queuelist, &q->queue_head);
1268 break; 1849 break;
1269 case ELEVATOR_INSERT_SORT: 1850 case ELEVATOR_INSERT_SORT:
1270 BUG_ON(!blk_fs_request(rq)); 1851 BUG_ON(!blk_fs_request(rq));
1271 cfq_enqueue(cfqd, crq); 1852 cfq_enqueue(cfqd, rq);
1272 break; 1853 break;
1273 default: 1854 default:
1274 printk("%s: bad insert point %d\n", __FUNCTION__,where); 1855 printk("%s: bad insert point %d\n", __FUNCTION__,where);
1275 return; 1856 return;
1276 } 1857 }
1277
1278 if (rq_mergeable(rq)) {
1279 cfq_add_crq_hash(cfqd, crq);
1280
1281 if (!q->last_merge)
1282 q->last_merge = rq;
1283 }
1284}
1285
1286static int cfq_queue_empty(request_queue_t *q)
1287{
1288 struct cfq_data *cfqd = q->elevator->elevator_data;
1289
1290 return list_empty(&q->queue_head) && list_empty(&cfqd->rr_list);
1291} 1858}
1292 1859
1293static void cfq_completed_request(request_queue_t *q, struct request *rq) 1860static void cfq_completed_request(request_queue_t *q, struct request *rq)
@@ -1300,9 +1867,11 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq)
1300 1867
1301 cfqq = crq->cfq_queue; 1868 cfqq = crq->cfq_queue;
1302 1869
1303 if (crq->in_flight) { 1870 if (cfq_crq_in_flight(crq)) {
1304 WARN_ON(!cfqq->in_flight); 1871 const int sync = cfq_crq_is_sync(crq);
1305 cfqq->in_flight--; 1872
1873 WARN_ON(!cfqq->on_dispatch[sync]);
1874 cfqq->on_dispatch[sync]--;
1306 } 1875 }
1307 1876
1308 cfq_account_completion(cfqq, crq); 1877 cfq_account_completion(cfqq, crq);
@@ -1332,51 +1901,136 @@ cfq_latter_request(request_queue_t *q, struct request *rq)
1332 return NULL; 1901 return NULL;
1333} 1902}
1334 1903
1335static int cfq_may_queue(request_queue_t *q, int rw) 1904/*
1905 * we temporarily boost lower priority queues if they are holding fs exclusive
1906 * resources. they are boosted to normal prio (CLASS_BE/4)
1907 */
1908static void cfq_prio_boost(struct cfq_queue *cfqq)
1336{ 1909{
1337 struct cfq_data *cfqd = q->elevator->elevator_data; 1910 const int ioprio_class = cfqq->ioprio_class;
1338 struct cfq_queue *cfqq; 1911 const int ioprio = cfqq->ioprio;
1339 int ret = ELV_MQUEUE_MAY;
1340 1912
1341 if (current->flags & PF_MEMALLOC) 1913 if (has_fs_excl()) {
1342 return ELV_MQUEUE_MAY; 1914 /*
1915 * boost idle prio on transactions that would lock out other
1916 * users of the filesystem
1917 */
1918 if (cfq_class_idle(cfqq))
1919 cfqq->ioprio_class = IOPRIO_CLASS_BE;
1920 if (cfqq->ioprio > IOPRIO_NORM)
1921 cfqq->ioprio = IOPRIO_NORM;
1922 } else {
1923 /*
1924 * check if we need to unboost the queue
1925 */
1926 if (cfqq->ioprio_class != cfqq->org_ioprio_class)
1927 cfqq->ioprio_class = cfqq->org_ioprio_class;
1928 if (cfqq->ioprio != cfqq->org_ioprio)
1929 cfqq->ioprio = cfqq->org_ioprio;
1930 }
1343 1931
1344 cfqq = cfq_find_cfq_hash(cfqd, cfq_hash_key(cfqd, current)); 1932 /*
1345 if (cfqq) { 1933 * refile between round-robin lists if we moved the priority class
1346 int limit = cfqd->max_queued; 1934 */
1935 if ((ioprio_class != cfqq->ioprio_class || ioprio != cfqq->ioprio) &&
1936 cfq_cfqq_on_rr(cfqq))
1937 cfq_resort_rr_list(cfqq, 0);
1938}
1347 1939
1348 if (cfqq->allocated[rw] < cfqd->cfq_queued) 1940static inline pid_t cfq_queue_pid(struct task_struct *task, int rw)
1349 return ELV_MQUEUE_MUST; 1941{
1942 if (rw == READ || process_sync(task))
1943 return task->pid;
1350 1944
1351 if (cfqd->busy_queues) 1945 return CFQ_KEY_ASYNC;
1352 limit = q->nr_requests / cfqd->busy_queues; 1946}
1353 1947
1354 if (limit < cfqd->cfq_queued) 1948static inline int
1355 limit = cfqd->cfq_queued; 1949__cfq_may_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1356 else if (limit > cfqd->max_queued) 1950 struct task_struct *task, int rw)
1357 limit = cfqd->max_queued; 1951{
1952#if 1
1953 if ((cfq_cfqq_wait_request(cfqq) || cfq_cfqq_must_alloc(cfqq)) &&
1954 !cfq_cfqq_must_alloc_slice(cfqq)) {
1955 cfq_mark_cfqq_must_alloc_slice(cfqq);
1956 return ELV_MQUEUE_MUST;
1957 }
1358 1958
1359 if (cfqq->allocated[rw] >= limit) { 1959 return ELV_MQUEUE_MAY;
1360 if (limit > cfqq->alloc_limit[rw]) 1960#else
1361 cfqq->alloc_limit[rw] = limit; 1961 if (!cfqq || task->flags & PF_MEMALLOC)
1962 return ELV_MQUEUE_MAY;
1963 if (!cfqq->allocated[rw] || cfq_cfqq_must_alloc(cfqq)) {
1964 if (cfq_cfqq_wait_request(cfqq))
1965 return ELV_MQUEUE_MUST;
1362 1966
1363 ret = ELV_MQUEUE_NO; 1967 /*
1968 * only allow 1 ELV_MQUEUE_MUST per slice, otherwise we
1969 * can quickly flood the queue with writes from a single task
1970 */
1971 if (rw == READ || !cfq_cfqq_must_alloc_slice(cfqq)) {
1972 cfq_mark_cfqq_must_alloc_slice(cfqq);
1973 return ELV_MQUEUE_MUST;
1364 } 1974 }
1975
1976 return ELV_MQUEUE_MAY;
1365 } 1977 }
1978 if (cfq_class_idle(cfqq))
1979 return ELV_MQUEUE_NO;
1980 if (cfqq->allocated[rw] >= cfqd->max_queued) {
1981 struct io_context *ioc = get_io_context(GFP_ATOMIC);
1982 int ret = ELV_MQUEUE_NO;
1366 1983
1367 return ret; 1984 if (ioc && ioc->nr_batch_requests)
1985 ret = ELV_MQUEUE_MAY;
1986
1987 put_io_context(ioc);
1988 return ret;
1989 }
1990
1991 return ELV_MQUEUE_MAY;
1992#endif
1993}
1994
1995static int cfq_may_queue(request_queue_t *q, int rw, struct bio *bio)
1996{
1997 struct cfq_data *cfqd = q->elevator->elevator_data;
1998 struct task_struct *tsk = current;
1999 struct cfq_queue *cfqq;
2000
2001 /*
2002 * don't force setup of a queue from here, as a call to may_queue
2003 * does not necessarily imply that a request actually will be queued.
2004 * so just lookup a possibly existing queue, or return 'may queue'
2005 * if that fails
2006 */
2007 cfqq = cfq_find_cfq_hash(cfqd, cfq_queue_pid(tsk, rw), tsk->ioprio);
2008 if (cfqq) {
2009 cfq_init_prio_data(cfqq);
2010 cfq_prio_boost(cfqq);
2011
2012 return __cfq_may_queue(cfqd, cfqq, tsk, rw);
2013 }
2014
2015 return ELV_MQUEUE_MAY;
1368} 2016}
1369 2017
1370static void cfq_check_waiters(request_queue_t *q, struct cfq_queue *cfqq) 2018static void cfq_check_waiters(request_queue_t *q, struct cfq_queue *cfqq)
1371{ 2019{
2020 struct cfq_data *cfqd = q->elevator->elevator_data;
1372 struct request_list *rl = &q->rq; 2021 struct request_list *rl = &q->rq;
1373 const int write = waitqueue_active(&rl->wait[WRITE]);
1374 const int read = waitqueue_active(&rl->wait[READ]);
1375 2022
1376 if (read && cfqq->allocated[READ] < cfqq->alloc_limit[READ]) 2023 if (cfqq->allocated[READ] <= cfqd->max_queued || cfqd->rq_starved) {
1377 wake_up(&rl->wait[READ]); 2024 smp_mb();
1378 if (write && cfqq->allocated[WRITE] < cfqq->alloc_limit[WRITE]) 2025 if (waitqueue_active(&rl->wait[READ]))
1379 wake_up(&rl->wait[WRITE]); 2026 wake_up(&rl->wait[READ]);
2027 }
2028
2029 if (cfqq->allocated[WRITE] <= cfqd->max_queued || cfqd->rq_starved) {
2030 smp_mb();
2031 if (waitqueue_active(&rl->wait[WRITE]))
2032 wake_up(&rl->wait[WRITE]);
2033 }
1380} 2034}
1381 2035
1382/* 2036/*
@@ -1389,69 +2043,61 @@ static void cfq_put_request(request_queue_t *q, struct request *rq)
1389 2043
1390 if (crq) { 2044 if (crq) {
1391 struct cfq_queue *cfqq = crq->cfq_queue; 2045 struct cfq_queue *cfqq = crq->cfq_queue;
2046 const int rw = rq_data_dir(rq);
1392 2047
1393 BUG_ON(q->last_merge == rq); 2048 BUG_ON(!cfqq->allocated[rw]);
1394 BUG_ON(!hlist_unhashed(&crq->hash)); 2049 cfqq->allocated[rw]--;
1395 2050
1396 if (crq->io_context) 2051 put_io_context(crq->io_context->ioc);
1397 put_io_context(crq->io_context->ioc);
1398
1399 BUG_ON(!cfqq->allocated[crq->is_write]);
1400 cfqq->allocated[crq->is_write]--;
1401 2052
1402 mempool_free(crq, cfqd->crq_pool); 2053 mempool_free(crq, cfqd->crq_pool);
1403 rq->elevator_private = NULL; 2054 rq->elevator_private = NULL;
1404 2055
1405 smp_mb();
1406 cfq_check_waiters(q, cfqq); 2056 cfq_check_waiters(q, cfqq);
1407 cfq_put_queue(cfqq); 2057 cfq_put_queue(cfqq);
1408 } 2058 }
1409} 2059}
1410 2060
1411/* 2061/*
1412 * Allocate cfq data structures associated with this request. A queue and 2062 * Allocate cfq data structures associated with this request.
1413 */ 2063 */
1414static int cfq_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 2064static int
2065cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
2066 int gfp_mask)
1415{ 2067{
1416 struct cfq_data *cfqd = q->elevator->elevator_data; 2068 struct cfq_data *cfqd = q->elevator->elevator_data;
2069 struct task_struct *tsk = current;
1417 struct cfq_io_context *cic; 2070 struct cfq_io_context *cic;
1418 const int rw = rq_data_dir(rq); 2071 const int rw = rq_data_dir(rq);
1419 struct cfq_queue *cfqq, *saved_cfqq; 2072 pid_t key = cfq_queue_pid(tsk, rw);
2073 struct cfq_queue *cfqq;
1420 struct cfq_rq *crq; 2074 struct cfq_rq *crq;
1421 unsigned long flags; 2075 unsigned long flags;
1422 2076
1423 might_sleep_if(gfp_mask & __GFP_WAIT); 2077 might_sleep_if(gfp_mask & __GFP_WAIT);
1424 2078
2079 cic = cfq_get_io_context(cfqd, key, gfp_mask);
2080
1425 spin_lock_irqsave(q->queue_lock, flags); 2081 spin_lock_irqsave(q->queue_lock, flags);
1426 2082
1427 cfqq = __cfq_get_queue(cfqd, cfq_hash_key(cfqd, current), gfp_mask); 2083 if (!cic)
1428 if (!cfqq) 2084 goto queue_fail;
1429 goto out_lock; 2085
2086 if (!cic->cfqq) {
2087 cfqq = cfq_get_queue(cfqd, key, tsk->ioprio, gfp_mask);
2088 if (!cfqq)
2089 goto queue_fail;
1430 2090
1431repeat: 2091 cic->cfqq = cfqq;
1432 if (cfqq->allocated[rw] >= cfqd->max_queued) 2092 } else
1433 goto out_lock; 2093 cfqq = cic->cfqq;
1434 2094
1435 cfqq->allocated[rw]++; 2095 cfqq->allocated[rw]++;
2096 cfq_clear_cfqq_must_alloc(cfqq);
2097 cfqd->rq_starved = 0;
2098 atomic_inc(&cfqq->ref);
1436 spin_unlock_irqrestore(q->queue_lock, flags); 2099 spin_unlock_irqrestore(q->queue_lock, flags);
1437 2100
1438 /*
1439 * if hashing type has changed, the cfq_queue might change here.
1440 */
1441 saved_cfqq = cfqq;
1442 cic = cfq_get_io_context(&cfqq, gfp_mask);
1443 if (!cic)
1444 goto err;
1445
1446 /*
1447 * repeat allocation checks on queue change
1448 */
1449 if (unlikely(saved_cfqq != cfqq)) {
1450 spin_lock_irqsave(q->queue_lock, flags);
1451 saved_cfqq->allocated[rw]--;
1452 goto repeat;
1453 }
1454
1455 crq = mempool_alloc(cfqd->crq_pool, gfp_mask); 2101 crq = mempool_alloc(cfqd->crq_pool, gfp_mask);
1456 if (crq) { 2102 if (crq) {
1457 RB_CLEAR(&crq->rb_node); 2103 RB_CLEAR(&crq->rb_node);
@@ -1460,24 +2106,141 @@ repeat:
1460 INIT_HLIST_NODE(&crq->hash); 2106 INIT_HLIST_NODE(&crq->hash);
1461 crq->cfq_queue = cfqq; 2107 crq->cfq_queue = cfqq;
1462 crq->io_context = cic; 2108 crq->io_context = cic;
1463 crq->service_start = crq->queue_start = 0; 2109 cfq_clear_crq_in_flight(crq);
1464 crq->in_flight = crq->accounted = crq->is_sync = 0; 2110 cfq_clear_crq_in_driver(crq);
1465 crq->is_write = rw; 2111 cfq_clear_crq_requeued(crq);
2112
2113 if (rw == READ || process_sync(tsk))
2114 cfq_mark_crq_is_sync(crq);
2115 else
2116 cfq_clear_crq_is_sync(crq);
2117
1466 rq->elevator_private = crq; 2118 rq->elevator_private = crq;
1467 cfqq->alloc_limit[rw] = 0;
1468 return 0; 2119 return 0;
1469 } 2120 }
1470 2121
1471 put_io_context(cic->ioc);
1472err:
1473 spin_lock_irqsave(q->queue_lock, flags); 2122 spin_lock_irqsave(q->queue_lock, flags);
1474 cfqq->allocated[rw]--; 2123 cfqq->allocated[rw]--;
2124 if (!(cfqq->allocated[0] + cfqq->allocated[1]))
2125 cfq_mark_cfqq_must_alloc(cfqq);
1475 cfq_put_queue(cfqq); 2126 cfq_put_queue(cfqq);
1476out_lock: 2127queue_fail:
2128 if (cic)
2129 put_io_context(cic->ioc);
2130 /*
2131 * mark us rq allocation starved. we need to kickstart the process
2132 * ourselves if there are no pending requests that can do it for us.
2133 * that would be an extremely rare OOM situation
2134 */
2135 cfqd->rq_starved = 1;
2136 cfq_schedule_dispatch(cfqd);
1477 spin_unlock_irqrestore(q->queue_lock, flags); 2137 spin_unlock_irqrestore(q->queue_lock, flags);
1478 return 1; 2138 return 1;
1479} 2139}
1480 2140
2141static void cfq_kick_queue(void *data)
2142{
2143 request_queue_t *q = data;
2144 struct cfq_data *cfqd = q->elevator->elevator_data;
2145 unsigned long flags;
2146
2147 spin_lock_irqsave(q->queue_lock, flags);
2148
2149 if (cfqd->rq_starved) {
2150 struct request_list *rl = &q->rq;
2151
2152 /*
2153 * we aren't guaranteed to get a request after this, but we
2154 * have to be opportunistic
2155 */
2156 smp_mb();
2157 if (waitqueue_active(&rl->wait[READ]))
2158 wake_up(&rl->wait[READ]);
2159 if (waitqueue_active(&rl->wait[WRITE]))
2160 wake_up(&rl->wait[WRITE]);
2161 }
2162
2163 blk_remove_plug(q);
2164 q->request_fn(q);
2165 spin_unlock_irqrestore(q->queue_lock, flags);
2166}
2167
2168/*
2169 * Timer running if the active_queue is currently idling inside its time slice
2170 */
2171static void cfq_idle_slice_timer(unsigned long data)
2172{
2173 struct cfq_data *cfqd = (struct cfq_data *) data;
2174 struct cfq_queue *cfqq;
2175 unsigned long flags;
2176
2177 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
2178
2179 if ((cfqq = cfqd->active_queue) != NULL) {
2180 unsigned long now = jiffies;
2181
2182 /*
2183 * expired
2184 */
2185 if (time_after(now, cfqq->slice_end))
2186 goto expire;
2187
2188 /*
2189 * only expire and reinvoke request handler, if there are
2190 * other queues with pending requests
2191 */
2192 if (!cfq_pending_requests(cfqd)) {
2193 cfqd->idle_slice_timer.expires = min(now + cfqd->cfq_slice_idle, cfqq->slice_end);
2194 add_timer(&cfqd->idle_slice_timer);
2195 goto out_cont;
2196 }
2197
2198 /*
2199 * not expired and it has a request pending, let it dispatch
2200 */
2201 if (!RB_EMPTY(&cfqq->sort_list)) {
2202 cfq_mark_cfqq_must_dispatch(cfqq);
2203 goto out_kick;
2204 }
2205 }
2206expire:
2207 cfq_slice_expired(cfqd, 0);
2208out_kick:
2209 cfq_schedule_dispatch(cfqd);
2210out_cont:
2211 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
2212}
2213
2214/*
2215 * Timer running if an idle class queue is waiting for service
2216 */
2217static void cfq_idle_class_timer(unsigned long data)
2218{
2219 struct cfq_data *cfqd = (struct cfq_data *) data;
2220 unsigned long flags, end;
2221
2222 spin_lock_irqsave(cfqd->queue->queue_lock, flags);
2223
2224 /*
2225 * race with a non-idle queue, reset timer
2226 */
2227 end = cfqd->last_end_request + CFQ_IDLE_GRACE;
2228 if (!time_after_eq(jiffies, end)) {
2229 cfqd->idle_class_timer.expires = end;
2230 add_timer(&cfqd->idle_class_timer);
2231 } else
2232 cfq_schedule_dispatch(cfqd);
2233
2234 spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
2235}
2236
2237static void cfq_shutdown_timer_wq(struct cfq_data *cfqd)
2238{
2239 del_timer_sync(&cfqd->idle_slice_timer);
2240 del_timer_sync(&cfqd->idle_class_timer);
2241 blk_sync_queue(cfqd->queue);
2242}
2243
1481static void cfq_put_cfqd(struct cfq_data *cfqd) 2244static void cfq_put_cfqd(struct cfq_data *cfqd)
1482{ 2245{
1483 request_queue_t *q = cfqd->queue; 2246 request_queue_t *q = cfqd->queue;
@@ -1487,6 +2250,9 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
1487 2250
1488 blk_put_queue(q); 2251 blk_put_queue(q);
1489 2252
2253 cfq_shutdown_timer_wq(cfqd);
2254 q->elevator->elevator_data = NULL;
2255
1490 mempool_destroy(cfqd->crq_pool); 2256 mempool_destroy(cfqd->crq_pool);
1491 kfree(cfqd->crq_hash); 2257 kfree(cfqd->crq_hash);
1492 kfree(cfqd->cfq_hash); 2258 kfree(cfqd->cfq_hash);
@@ -1495,7 +2261,10 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
1495 2261
1496static void cfq_exit_queue(elevator_t *e) 2262static void cfq_exit_queue(elevator_t *e)
1497{ 2263{
1498 cfq_put_cfqd(e->elevator_data); 2264 struct cfq_data *cfqd = e->elevator_data;
2265
2266 cfq_shutdown_timer_wq(cfqd);
2267 cfq_put_cfqd(cfqd);
1499} 2268}
1500 2269
1501static int cfq_init_queue(request_queue_t *q, elevator_t *e) 2270static int cfq_init_queue(request_queue_t *q, elevator_t *e)
@@ -1508,7 +2277,13 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
1508 return -ENOMEM; 2277 return -ENOMEM;
1509 2278
1510 memset(cfqd, 0, sizeof(*cfqd)); 2279 memset(cfqd, 0, sizeof(*cfqd));
1511 INIT_LIST_HEAD(&cfqd->rr_list); 2280
2281 for (i = 0; i < CFQ_PRIO_LISTS; i++)
2282 INIT_LIST_HEAD(&cfqd->rr_list[i]);
2283
2284 INIT_LIST_HEAD(&cfqd->busy_rr);
2285 INIT_LIST_HEAD(&cfqd->cur_rr);
2286 INIT_LIST_HEAD(&cfqd->idle_rr);
1512 INIT_LIST_HEAD(&cfqd->empty_list); 2287 INIT_LIST_HEAD(&cfqd->empty_list);
1513 2288
1514 cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL); 2289 cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL);
@@ -1533,24 +2308,32 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
1533 cfqd->queue = q; 2308 cfqd->queue = q;
1534 atomic_inc(&q->refcnt); 2309 atomic_inc(&q->refcnt);
1535 2310
1536 /* 2311 cfqd->max_queued = q->nr_requests / 4;
1537 * just set it to some high value, we want anyone to be able to queue
1538 * some requests. fairness is handled differently
1539 */
1540 q->nr_requests = 1024;
1541 cfqd->max_queued = q->nr_requests / 16;
1542 q->nr_batching = cfq_queued; 2312 q->nr_batching = cfq_queued;
1543 cfqd->key_type = CFQ_KEY_TGID; 2313
1544 cfqd->find_best_crq = 1; 2314 init_timer(&cfqd->idle_slice_timer);
2315 cfqd->idle_slice_timer.function = cfq_idle_slice_timer;
2316 cfqd->idle_slice_timer.data = (unsigned long) cfqd;
2317
2318 init_timer(&cfqd->idle_class_timer);
2319 cfqd->idle_class_timer.function = cfq_idle_class_timer;
2320 cfqd->idle_class_timer.data = (unsigned long) cfqd;
2321
2322 INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q);
2323
1545 atomic_set(&cfqd->ref, 1); 2324 atomic_set(&cfqd->ref, 1);
1546 2325
1547 cfqd->cfq_queued = cfq_queued; 2326 cfqd->cfq_queued = cfq_queued;
1548 cfqd->cfq_quantum = cfq_quantum; 2327 cfqd->cfq_quantum = cfq_quantum;
1549 cfqd->cfq_fifo_expire_r = cfq_fifo_expire_r; 2328 cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
1550 cfqd->cfq_fifo_expire_w = cfq_fifo_expire_w; 2329 cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1];
1551 cfqd->cfq_fifo_batch_expire = cfq_fifo_rate;
1552 cfqd->cfq_back_max = cfq_back_max; 2330 cfqd->cfq_back_max = cfq_back_max;
1553 cfqd->cfq_back_penalty = cfq_back_penalty; 2331 cfqd->cfq_back_penalty = cfq_back_penalty;
2332 cfqd->cfq_slice[0] = cfq_slice_async;
2333 cfqd->cfq_slice[1] = cfq_slice_sync;
2334 cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
2335 cfqd->cfq_slice_idle = cfq_slice_idle;
2336 cfqd->cfq_max_depth = cfq_max_depth;
1554 2337
1555 return 0; 2338 return 0;
1556out_crqpool: 2339out_crqpool:
@@ -1595,7 +2378,6 @@ fail:
1595 return -ENOMEM; 2378 return -ENOMEM;
1596} 2379}
1597 2380
1598
1599/* 2381/*
1600 * sysfs parts below --> 2382 * sysfs parts below -->
1601 */ 2383 */
@@ -1620,45 +2402,6 @@ cfq_var_store(unsigned int *var, const char *page, size_t count)
1620 return count; 2402 return count;
1621} 2403}
1622 2404
1623static ssize_t
1624cfq_clear_elapsed(struct cfq_data *cfqd, const char *page, size_t count)
1625{
1626 max_elapsed_dispatch = max_elapsed_crq = 0;
1627 return count;
1628}
1629
1630static ssize_t
1631cfq_set_key_type(struct cfq_data *cfqd, const char *page, size_t count)
1632{
1633 spin_lock_irq(cfqd->queue->queue_lock);
1634 if (!strncmp(page, "pgid", 4))
1635 cfqd->key_type = CFQ_KEY_PGID;
1636 else if (!strncmp(page, "tgid", 4))
1637 cfqd->key_type = CFQ_KEY_TGID;
1638 else if (!strncmp(page, "uid", 3))
1639 cfqd->key_type = CFQ_KEY_UID;
1640 else if (!strncmp(page, "gid", 3))
1641 cfqd->key_type = CFQ_KEY_GID;
1642 spin_unlock_irq(cfqd->queue->queue_lock);
1643 return count;
1644}
1645
1646static ssize_t
1647cfq_read_key_type(struct cfq_data *cfqd, char *page)
1648{
1649 ssize_t len = 0;
1650 int i;
1651
1652 for (i = CFQ_KEY_PGID; i < CFQ_KEY_LAST; i++) {
1653 if (cfqd->key_type == i)
1654 len += sprintf(page+len, "[%s] ", cfq_key_types[i]);
1655 else
1656 len += sprintf(page+len, "%s ", cfq_key_types[i]);
1657 }
1658 len += sprintf(page+len, "\n");
1659 return len;
1660}
1661
1662#define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \ 2405#define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \
1663static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \ 2406static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \
1664{ \ 2407{ \
@@ -1669,12 +2412,15 @@ static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \
1669} 2412}
1670SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0); 2413SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
1671SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0); 2414SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0);
1672SHOW_FUNCTION(cfq_fifo_expire_r_show, cfqd->cfq_fifo_expire_r, 1); 2415SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
1673SHOW_FUNCTION(cfq_fifo_expire_w_show, cfqd->cfq_fifo_expire_w, 1); 2416SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
1674SHOW_FUNCTION(cfq_fifo_batch_expire_show, cfqd->cfq_fifo_batch_expire, 1);
1675SHOW_FUNCTION(cfq_find_best_show, cfqd->find_best_crq, 0);
1676SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0); 2417SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0);
1677SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0); 2418SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0);
2419SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
2420SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
2421SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
2422SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0);
2423SHOW_FUNCTION(cfq_max_depth_show, cfqd->cfq_max_depth, 0);
1678#undef SHOW_FUNCTION 2424#undef SHOW_FUNCTION
1679 2425
1680#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \ 2426#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
@@ -1694,12 +2440,15 @@ static ssize_t __FUNC(struct cfq_data *cfqd, const char *page, size_t count) \
1694} 2440}
1695STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0); 2441STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
1696STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0); 2442STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0);
1697STORE_FUNCTION(cfq_fifo_expire_r_store, &cfqd->cfq_fifo_expire_r, 1, UINT_MAX, 1); 2443STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1);
1698STORE_FUNCTION(cfq_fifo_expire_w_store, &cfqd->cfq_fifo_expire_w, 1, UINT_MAX, 1); 2444STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1);
1699STORE_FUNCTION(cfq_fifo_batch_expire_store, &cfqd->cfq_fifo_batch_expire, 0, UINT_MAX, 1);
1700STORE_FUNCTION(cfq_find_best_store, &cfqd->find_best_crq, 0, 1, 0);
1701STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0); 2445STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
1702STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0); 2446STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
2447STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
2448STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
2449STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
2450STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, UINT_MAX, 0);
2451STORE_FUNCTION(cfq_max_depth_store, &cfqd->cfq_max_depth, 1, UINT_MAX, 0);
1703#undef STORE_FUNCTION 2452#undef STORE_FUNCTION
1704 2453
1705static struct cfq_fs_entry cfq_quantum_entry = { 2454static struct cfq_fs_entry cfq_quantum_entry = {
@@ -1712,25 +2461,15 @@ static struct cfq_fs_entry cfq_queued_entry = {
1712 .show = cfq_queued_show, 2461 .show = cfq_queued_show,
1713 .store = cfq_queued_store, 2462 .store = cfq_queued_store,
1714}; 2463};
1715static struct cfq_fs_entry cfq_fifo_expire_r_entry = { 2464static struct cfq_fs_entry cfq_fifo_expire_sync_entry = {
1716 .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR }, 2465 .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR },
1717 .show = cfq_fifo_expire_r_show, 2466 .show = cfq_fifo_expire_sync_show,
1718 .store = cfq_fifo_expire_r_store, 2467 .store = cfq_fifo_expire_sync_store,
1719}; 2468};
1720static struct cfq_fs_entry cfq_fifo_expire_w_entry = { 2469static struct cfq_fs_entry cfq_fifo_expire_async_entry = {
1721 .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR }, 2470 .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR },
1722 .show = cfq_fifo_expire_w_show, 2471 .show = cfq_fifo_expire_async_show,
1723 .store = cfq_fifo_expire_w_store, 2472 .store = cfq_fifo_expire_async_store,
1724};
1725static struct cfq_fs_entry cfq_fifo_batch_expire_entry = {
1726 .attr = {.name = "fifo_batch_expire", .mode = S_IRUGO | S_IWUSR },
1727 .show = cfq_fifo_batch_expire_show,
1728 .store = cfq_fifo_batch_expire_store,
1729};
1730static struct cfq_fs_entry cfq_find_best_entry = {
1731 .attr = {.name = "find_best_crq", .mode = S_IRUGO | S_IWUSR },
1732 .show = cfq_find_best_show,
1733 .store = cfq_find_best_store,
1734}; 2473};
1735static struct cfq_fs_entry cfq_back_max_entry = { 2474static struct cfq_fs_entry cfq_back_max_entry = {
1736 .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR }, 2475 .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR },
@@ -1742,27 +2481,44 @@ static struct cfq_fs_entry cfq_back_penalty_entry = {
1742 .show = cfq_back_penalty_show, 2481 .show = cfq_back_penalty_show,
1743 .store = cfq_back_penalty_store, 2482 .store = cfq_back_penalty_store,
1744}; 2483};
1745static struct cfq_fs_entry cfq_clear_elapsed_entry = { 2484static struct cfq_fs_entry cfq_slice_sync_entry = {
1746 .attr = {.name = "clear_elapsed", .mode = S_IWUSR }, 2485 .attr = {.name = "slice_sync", .mode = S_IRUGO | S_IWUSR },
1747 .store = cfq_clear_elapsed, 2486 .show = cfq_slice_sync_show,
2487 .store = cfq_slice_sync_store,
2488};
2489static struct cfq_fs_entry cfq_slice_async_entry = {
2490 .attr = {.name = "slice_async", .mode = S_IRUGO | S_IWUSR },
2491 .show = cfq_slice_async_show,
2492 .store = cfq_slice_async_store,
1748}; 2493};
1749static struct cfq_fs_entry cfq_key_type_entry = { 2494static struct cfq_fs_entry cfq_slice_async_rq_entry = {
1750 .attr = {.name = "key_type", .mode = S_IRUGO | S_IWUSR }, 2495 .attr = {.name = "slice_async_rq", .mode = S_IRUGO | S_IWUSR },
1751 .show = cfq_read_key_type, 2496 .show = cfq_slice_async_rq_show,
1752 .store = cfq_set_key_type, 2497 .store = cfq_slice_async_rq_store,
2498};
2499static struct cfq_fs_entry cfq_slice_idle_entry = {
2500 .attr = {.name = "slice_idle", .mode = S_IRUGO | S_IWUSR },
2501 .show = cfq_slice_idle_show,
2502 .store = cfq_slice_idle_store,
2503};
2504static struct cfq_fs_entry cfq_max_depth_entry = {
2505 .attr = {.name = "max_depth", .mode = S_IRUGO | S_IWUSR },
2506 .show = cfq_max_depth_show,
2507 .store = cfq_max_depth_store,
1753}; 2508};
1754 2509
1755static struct attribute *default_attrs[] = { 2510static struct attribute *default_attrs[] = {
1756 &cfq_quantum_entry.attr, 2511 &cfq_quantum_entry.attr,
1757 &cfq_queued_entry.attr, 2512 &cfq_queued_entry.attr,
1758 &cfq_fifo_expire_r_entry.attr, 2513 &cfq_fifo_expire_sync_entry.attr,
1759 &cfq_fifo_expire_w_entry.attr, 2514 &cfq_fifo_expire_async_entry.attr,
1760 &cfq_fifo_batch_expire_entry.attr,
1761 &cfq_key_type_entry.attr,
1762 &cfq_find_best_entry.attr,
1763 &cfq_back_max_entry.attr, 2515 &cfq_back_max_entry.attr,
1764 &cfq_back_penalty_entry.attr, 2516 &cfq_back_penalty_entry.attr,
1765 &cfq_clear_elapsed_entry.attr, 2517 &cfq_slice_sync_entry.attr,
2518 &cfq_slice_async_entry.attr,
2519 &cfq_slice_async_rq_entry.attr,
2520 &cfq_slice_idle_entry.attr,
2521 &cfq_max_depth_entry.attr,
1766 NULL, 2522 NULL,
1767}; 2523};
1768 2524
@@ -1832,21 +2588,46 @@ static int __init cfq_init(void)
1832{ 2588{
1833 int ret; 2589 int ret;
1834 2590
2591 /*
2592 * could be 0 on HZ < 1000 setups
2593 */
2594 if (!cfq_slice_async)
2595 cfq_slice_async = 1;
2596 if (!cfq_slice_idle)
2597 cfq_slice_idle = 1;
2598
1835 if (cfq_slab_setup()) 2599 if (cfq_slab_setup())
1836 return -ENOMEM; 2600 return -ENOMEM;
1837 2601
1838 ret = elv_register(&iosched_cfq); 2602 ret = elv_register(&iosched_cfq);
1839 if (!ret) { 2603 if (ret)
1840 __module_get(THIS_MODULE); 2604 cfq_slab_kill();
1841 return 0;
1842 }
1843 2605
1844 cfq_slab_kill();
1845 return ret; 2606 return ret;
1846} 2607}
1847 2608
1848static void __exit cfq_exit(void) 2609static void __exit cfq_exit(void)
1849{ 2610{
2611 struct task_struct *g, *p;
2612 unsigned long flags;
2613
2614 read_lock_irqsave(&tasklist_lock, flags);
2615
2616 /*
2617 * iterate each process in the system, removing our io_context
2618 */
2619 do_each_thread(g, p) {
2620 struct io_context *ioc = p->io_context;
2621
2622 if (ioc && ioc->cic) {
2623 ioc->cic->exit(ioc->cic);
2624 cfq_free_io_context(ioc->cic);
2625 ioc->cic = NULL;
2626 }
2627 } while_each_thread(g, p);
2628
2629 read_unlock_irqrestore(&tasklist_lock, flags);
2630
1850 cfq_slab_kill(); 2631 cfq_slab_kill();
1851 elv_unregister(&iosched_cfq); 2632 elv_unregister(&iosched_cfq);
1852} 2633}
diff --git a/drivers/block/deadline-iosched.c b/drivers/block/deadline-iosched.c
index 4bc2fea73273..ff5201e02153 100644
--- a/drivers/block/deadline-iosched.c
+++ b/drivers/block/deadline-iosched.c
@@ -760,7 +760,8 @@ static void deadline_put_request(request_queue_t *q, struct request *rq)
760} 760}
761 761
762static int 762static int
763deadline_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 763deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
764 int gfp_mask)
764{ 765{
765 struct deadline_data *dd = q->elevator->elevator_data; 766 struct deadline_data *dd = q->elevator->elevator_data;
766 struct deadline_rq *drq; 767 struct deadline_rq *drq;
diff --git a/drivers/block/elevator.c b/drivers/block/elevator.c
index f831f08f839c..98f0126a2deb 100644
--- a/drivers/block/elevator.c
+++ b/drivers/block/elevator.c
@@ -486,12 +486,13 @@ struct request *elv_former_request(request_queue_t *q, struct request *rq)
486 return NULL; 486 return NULL;
487} 487}
488 488
489int elv_set_request(request_queue_t *q, struct request *rq, int gfp_mask) 489int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
490 int gfp_mask)
490{ 491{
491 elevator_t *e = q->elevator; 492 elevator_t *e = q->elevator;
492 493
493 if (e->ops->elevator_set_req_fn) 494 if (e->ops->elevator_set_req_fn)
494 return e->ops->elevator_set_req_fn(q, rq, gfp_mask); 495 return e->ops->elevator_set_req_fn(q, rq, bio, gfp_mask);
495 496
496 rq->elevator_private = NULL; 497 rq->elevator_private = NULL;
497 return 0; 498 return 0;
@@ -505,12 +506,12 @@ void elv_put_request(request_queue_t *q, struct request *rq)
505 e->ops->elevator_put_req_fn(q, rq); 506 e->ops->elevator_put_req_fn(q, rq);
506} 507}
507 508
508int elv_may_queue(request_queue_t *q, int rw) 509int elv_may_queue(request_queue_t *q, int rw, struct bio *bio)
509{ 510{
510 elevator_t *e = q->elevator; 511 elevator_t *e = q->elevator;
511 512
512 if (e->ops->elevator_may_queue_fn) 513 if (e->ops->elevator_may_queue_fn)
513 return e->ops->elevator_may_queue_fn(q, rw); 514 return e->ops->elevator_may_queue_fn(q, rw, bio);
514 515
515 return ELV_MQUEUE_MAY; 516 return ELV_MQUEUE_MAY;
516} 517}
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
index 60e64091de1b..692a5fced76e 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/drivers/block/ll_rw_blk.c
@@ -276,6 +276,7 @@ static inline void rq_init(request_queue_t *q, struct request *rq)
276 rq->errors = 0; 276 rq->errors = 0;
277 rq->rq_status = RQ_ACTIVE; 277 rq->rq_status = RQ_ACTIVE;
278 rq->bio = rq->biotail = NULL; 278 rq->bio = rq->biotail = NULL;
279 rq->ioprio = 0;
279 rq->buffer = NULL; 280 rq->buffer = NULL;
280 rq->ref_count = 1; 281 rq->ref_count = 1;
281 rq->q = q; 282 rq->q = q;
@@ -1442,11 +1443,7 @@ void __generic_unplug_device(request_queue_t *q)
1442 if (!blk_remove_plug(q)) 1443 if (!blk_remove_plug(q))
1443 return; 1444 return;
1444 1445
1445 /* 1446 q->request_fn(q);
1446 * was plugged, fire request_fn if queue has stuff to do
1447 */
1448 if (elv_next_request(q))
1449 q->request_fn(q);
1450} 1447}
1451EXPORT_SYMBOL(__generic_unplug_device); 1448EXPORT_SYMBOL(__generic_unplug_device);
1452 1449
@@ -1776,8 +1773,8 @@ static inline void blk_free_request(request_queue_t *q, struct request *rq)
1776 mempool_free(rq, q->rq.rq_pool); 1773 mempool_free(rq, q->rq.rq_pool);
1777} 1774}
1778 1775
1779static inline struct request *blk_alloc_request(request_queue_t *q, int rw, 1776static inline struct request *
1780 int gfp_mask) 1777blk_alloc_request(request_queue_t *q, int rw, struct bio *bio, int gfp_mask)
1781{ 1778{
1782 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask); 1779 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask);
1783 1780
@@ -1790,7 +1787,7 @@ static inline struct request *blk_alloc_request(request_queue_t *q, int rw,
1790 */ 1787 */
1791 rq->flags = rw; 1788 rq->flags = rw;
1792 1789
1793 if (!elv_set_request(q, rq, gfp_mask)) 1790 if (!elv_set_request(q, rq, bio, gfp_mask))
1794 return rq; 1791 return rq;
1795 1792
1796 mempool_free(rq, q->rq.rq_pool); 1793 mempool_free(rq, q->rq.rq_pool);
@@ -1870,18 +1867,20 @@ static void freed_request(request_queue_t *q, int rw)
1870 1867
1871#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist) 1868#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist)
1872/* 1869/*
1873 * Get a free request, queue_lock must not be held 1870 * Get a free request, queue_lock must be held.
1871 * Returns NULL on failure, with queue_lock held.
1872 * Returns !NULL on success, with queue_lock *not held*.
1874 */ 1873 */
1875static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) 1874static struct request *get_request(request_queue_t *q, int rw, struct bio *bio,
1875 int gfp_mask)
1876{ 1876{
1877 struct request *rq = NULL; 1877 struct request *rq = NULL;
1878 struct request_list *rl = &q->rq; 1878 struct request_list *rl = &q->rq;
1879 struct io_context *ioc = get_io_context(gfp_mask); 1879 struct io_context *ioc = current_io_context(GFP_ATOMIC);
1880 1880
1881 if (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags))) 1881 if (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags)))
1882 goto out; 1882 goto out;
1883 1883
1884 spin_lock_irq(q->queue_lock);
1885 if (rl->count[rw]+1 >= q->nr_requests) { 1884 if (rl->count[rw]+1 >= q->nr_requests) {
1886 /* 1885 /*
1887 * The queue will fill after this allocation, so set it as 1886 * The queue will fill after this allocation, so set it as
@@ -1895,7 +1894,7 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask)
1895 } 1894 }
1896 } 1895 }
1897 1896
1898 switch (elv_may_queue(q, rw)) { 1897 switch (elv_may_queue(q, rw, bio)) {
1899 case ELV_MQUEUE_NO: 1898 case ELV_MQUEUE_NO:
1900 goto rq_starved; 1899 goto rq_starved;
1901 case ELV_MQUEUE_MAY: 1900 case ELV_MQUEUE_MAY:
@@ -1909,18 +1908,25 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask)
1909 * The queue is full and the allocating process is not a 1908 * The queue is full and the allocating process is not a
1910 * "batcher", and not exempted by the IO scheduler 1909 * "batcher", and not exempted by the IO scheduler
1911 */ 1910 */
1912 spin_unlock_irq(q->queue_lock);
1913 goto out; 1911 goto out;
1914 } 1912 }
1915 1913
1916get_rq: 1914get_rq:
1915 /*
1916 * Only allow batching queuers to allocate up to 50% over the defined
1917 * limit of requests, otherwise we could have thousands of requests
1918 * allocated with any setting of ->nr_requests
1919 */
1920 if (rl->count[rw] >= (3 * q->nr_requests / 2))
1921 goto out;
1922
1917 rl->count[rw]++; 1923 rl->count[rw]++;
1918 rl->starved[rw] = 0; 1924 rl->starved[rw] = 0;
1919 if (rl->count[rw] >= queue_congestion_on_threshold(q)) 1925 if (rl->count[rw] >= queue_congestion_on_threshold(q))
1920 set_queue_congested(q, rw); 1926 set_queue_congested(q, rw);
1921 spin_unlock_irq(q->queue_lock); 1927 spin_unlock_irq(q->queue_lock);
1922 1928
1923 rq = blk_alloc_request(q, rw, gfp_mask); 1929 rq = blk_alloc_request(q, rw, bio, gfp_mask);
1924 if (!rq) { 1930 if (!rq) {
1925 /* 1931 /*
1926 * Allocation failed presumably due to memory. Undo anything 1932 * Allocation failed presumably due to memory. Undo anything
@@ -1943,7 +1949,6 @@ rq_starved:
1943 if (unlikely(rl->count[rw] == 0)) 1949 if (unlikely(rl->count[rw] == 0))
1944 rl->starved[rw] = 1; 1950 rl->starved[rw] = 1;
1945 1951
1946 spin_unlock_irq(q->queue_lock);
1947 goto out; 1952 goto out;
1948 } 1953 }
1949 1954
@@ -1953,31 +1958,35 @@ rq_starved:
1953 rq_init(q, rq); 1958 rq_init(q, rq);
1954 rq->rl = rl; 1959 rq->rl = rl;
1955out: 1960out:
1956 put_io_context(ioc);
1957 return rq; 1961 return rq;
1958} 1962}
1959 1963
1960/* 1964/*
1961 * No available requests for this queue, unplug the device and wait for some 1965 * No available requests for this queue, unplug the device and wait for some
1962 * requests to become available. 1966 * requests to become available.
1967 *
1968 * Called with q->queue_lock held, and returns with it unlocked.
1963 */ 1969 */
1964static struct request *get_request_wait(request_queue_t *q, int rw) 1970static struct request *get_request_wait(request_queue_t *q, int rw,
1971 struct bio *bio)
1965{ 1972{
1966 DEFINE_WAIT(wait);
1967 struct request *rq; 1973 struct request *rq;
1968 1974
1969 do { 1975 rq = get_request(q, rw, bio, GFP_NOIO);
1976 while (!rq) {
1977 DEFINE_WAIT(wait);
1970 struct request_list *rl = &q->rq; 1978 struct request_list *rl = &q->rq;
1971 1979
1972 prepare_to_wait_exclusive(&rl->wait[rw], &wait, 1980 prepare_to_wait_exclusive(&rl->wait[rw], &wait,
1973 TASK_UNINTERRUPTIBLE); 1981 TASK_UNINTERRUPTIBLE);
1974 1982
1975 rq = get_request(q, rw, GFP_NOIO); 1983 rq = get_request(q, rw, bio, GFP_NOIO);
1976 1984
1977 if (!rq) { 1985 if (!rq) {
1978 struct io_context *ioc; 1986 struct io_context *ioc;
1979 1987
1980 generic_unplug_device(q); 1988 __generic_unplug_device(q);
1989 spin_unlock_irq(q->queue_lock);
1981 io_schedule(); 1990 io_schedule();
1982 1991
1983 /* 1992 /*
@@ -1986,12 +1995,13 @@ static struct request *get_request_wait(request_queue_t *q, int rw)
1986 * up to a big batch of them for a small period time. 1995 * up to a big batch of them for a small period time.
1987 * See ioc_batching, ioc_set_batching 1996 * See ioc_batching, ioc_set_batching
1988 */ 1997 */
1989 ioc = get_io_context(GFP_NOIO); 1998 ioc = current_io_context(GFP_NOIO);
1990 ioc_set_batching(q, ioc); 1999 ioc_set_batching(q, ioc);
1991 put_io_context(ioc); 2000
2001 spin_lock_irq(q->queue_lock);
1992 } 2002 }
1993 finish_wait(&rl->wait[rw], &wait); 2003 finish_wait(&rl->wait[rw], &wait);
1994 } while (!rq); 2004 }
1995 2005
1996 return rq; 2006 return rq;
1997} 2007}
@@ -2002,14 +2012,18 @@ struct request *blk_get_request(request_queue_t *q, int rw, int gfp_mask)
2002 2012
2003 BUG_ON(rw != READ && rw != WRITE); 2013 BUG_ON(rw != READ && rw != WRITE);
2004 2014
2005 if (gfp_mask & __GFP_WAIT) 2015 spin_lock_irq(q->queue_lock);
2006 rq = get_request_wait(q, rw); 2016 if (gfp_mask & __GFP_WAIT) {
2007 else 2017 rq = get_request_wait(q, rw, NULL);
2008 rq = get_request(q, rw, gfp_mask); 2018 } else {
2019 rq = get_request(q, rw, NULL, gfp_mask);
2020 if (!rq)
2021 spin_unlock_irq(q->queue_lock);
2022 }
2023 /* q->queue_lock is unlocked at this point */
2009 2024
2010 return rq; 2025 return rq;
2011} 2026}
2012
2013EXPORT_SYMBOL(blk_get_request); 2027EXPORT_SYMBOL(blk_get_request);
2014 2028
2015/** 2029/**
@@ -2333,7 +2347,6 @@ static void __blk_put_request(request_queue_t *q, struct request *req)
2333 return; 2347 return;
2334 2348
2335 req->rq_status = RQ_INACTIVE; 2349 req->rq_status = RQ_INACTIVE;
2336 req->q = NULL;
2337 req->rl = NULL; 2350 req->rl = NULL;
2338 2351
2339 /* 2352 /*
@@ -2462,6 +2475,8 @@ static int attempt_merge(request_queue_t *q, struct request *req,
2462 req->rq_disk->in_flight--; 2475 req->rq_disk->in_flight--;
2463 } 2476 }
2464 2477
2478 req->ioprio = ioprio_best(req->ioprio, next->ioprio);
2479
2465 __blk_put_request(q, next); 2480 __blk_put_request(q, next);
2466 return 1; 2481 return 1;
2467} 2482}
@@ -2512,13 +2527,15 @@ EXPORT_SYMBOL(blk_attempt_remerge);
2512 2527
2513static int __make_request(request_queue_t *q, struct bio *bio) 2528static int __make_request(request_queue_t *q, struct bio *bio)
2514{ 2529{
2515 struct request *req, *freereq = NULL; 2530 struct request *req;
2516 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync; 2531 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync;
2532 unsigned short prio;
2517 sector_t sector; 2533 sector_t sector;
2518 2534
2519 sector = bio->bi_sector; 2535 sector = bio->bi_sector;
2520 nr_sectors = bio_sectors(bio); 2536 nr_sectors = bio_sectors(bio);
2521 cur_nr_sectors = bio_cur_sectors(bio); 2537 cur_nr_sectors = bio_cur_sectors(bio);
2538 prio = bio_prio(bio);
2522 2539
2523 rw = bio_data_dir(bio); 2540 rw = bio_data_dir(bio);
2524 sync = bio_sync(bio); 2541 sync = bio_sync(bio);
@@ -2538,14 +2555,9 @@ static int __make_request(request_queue_t *q, struct bio *bio)
2538 goto end_io; 2555 goto end_io;
2539 } 2556 }
2540 2557
2541again:
2542 spin_lock_irq(q->queue_lock); 2558 spin_lock_irq(q->queue_lock);
2543 2559
2544 if (elv_queue_empty(q)) { 2560 if (unlikely(barrier) || elv_queue_empty(q))
2545 blk_plug_device(q);
2546 goto get_rq;
2547 }
2548 if (barrier)
2549 goto get_rq; 2561 goto get_rq;
2550 2562
2551 el_ret = elv_merge(q, &req, bio); 2563 el_ret = elv_merge(q, &req, bio);
@@ -2559,6 +2571,7 @@ again:
2559 req->biotail->bi_next = bio; 2571 req->biotail->bi_next = bio;
2560 req->biotail = bio; 2572 req->biotail = bio;
2561 req->nr_sectors = req->hard_nr_sectors += nr_sectors; 2573 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
2574 req->ioprio = ioprio_best(req->ioprio, prio);
2562 drive_stat_acct(req, nr_sectors, 0); 2575 drive_stat_acct(req, nr_sectors, 0);
2563 if (!attempt_back_merge(q, req)) 2576 if (!attempt_back_merge(q, req))
2564 elv_merged_request(q, req); 2577 elv_merged_request(q, req);
@@ -2583,45 +2596,30 @@ again:
2583 req->hard_cur_sectors = cur_nr_sectors; 2596 req->hard_cur_sectors = cur_nr_sectors;
2584 req->sector = req->hard_sector = sector; 2597 req->sector = req->hard_sector = sector;
2585 req->nr_sectors = req->hard_nr_sectors += nr_sectors; 2598 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
2599 req->ioprio = ioprio_best(req->ioprio, prio);
2586 drive_stat_acct(req, nr_sectors, 0); 2600 drive_stat_acct(req, nr_sectors, 0);
2587 if (!attempt_front_merge(q, req)) 2601 if (!attempt_front_merge(q, req))
2588 elv_merged_request(q, req); 2602 elv_merged_request(q, req);
2589 goto out; 2603 goto out;
2590 2604
2591 /* 2605 /* ELV_NO_MERGE: elevator says don't/can't merge. */
2592 * elevator says don't/can't merge. get new request
2593 */
2594 case ELEVATOR_NO_MERGE:
2595 break;
2596
2597 default: 2606 default:
2598 printk("elevator returned crap (%d)\n", el_ret); 2607 ;
2599 BUG();
2600 } 2608 }
2601 2609
2610get_rq:
2602 /* 2611 /*
2603 * Grab a free request from the freelist - if that is empty, check 2612 * Grab a free request. This is might sleep but can not fail.
2604 * if we are doing read ahead and abort instead of blocking for 2613 * Returns with the queue unlocked.
2605 * a free slot. 2614 */
2615 req = get_request_wait(q, rw, bio);
2616
2617 /*
2618 * After dropping the lock and possibly sleeping here, our request
2619 * may now be mergeable after it had proven unmergeable (above).
2620 * We don't worry about that case for efficiency. It won't happen
2621 * often, and the elevators are able to handle it.
2606 */ 2622 */
2607get_rq:
2608 if (freereq) {
2609 req = freereq;
2610 freereq = NULL;
2611 } else {
2612 spin_unlock_irq(q->queue_lock);
2613 if ((freereq = get_request(q, rw, GFP_ATOMIC)) == NULL) {
2614 /*
2615 * READA bit set
2616 */
2617 err = -EWOULDBLOCK;
2618 if (bio_rw_ahead(bio))
2619 goto end_io;
2620
2621 freereq = get_request_wait(q, rw);
2622 }
2623 goto again;
2624 }
2625 2623
2626 req->flags |= REQ_CMD; 2624 req->flags |= REQ_CMD;
2627 2625
@@ -2646,13 +2644,15 @@ get_rq:
2646 req->buffer = bio_data(bio); /* see ->buffer comment above */ 2644 req->buffer = bio_data(bio); /* see ->buffer comment above */
2647 req->waiting = NULL; 2645 req->waiting = NULL;
2648 req->bio = req->biotail = bio; 2646 req->bio = req->biotail = bio;
2647 req->ioprio = prio;
2649 req->rq_disk = bio->bi_bdev->bd_disk; 2648 req->rq_disk = bio->bi_bdev->bd_disk;
2650 req->start_time = jiffies; 2649 req->start_time = jiffies;
2651 2650
2651 spin_lock_irq(q->queue_lock);
2652 if (elv_queue_empty(q))
2653 blk_plug_device(q);
2652 add_request(q, req); 2654 add_request(q, req);
2653out: 2655out:
2654 if (freereq)
2655 __blk_put_request(q, freereq);
2656 if (sync) 2656 if (sync)
2657 __generic_unplug_device(q); 2657 __generic_unplug_device(q);
2658 2658
@@ -2674,7 +2674,7 @@ static inline void blk_partition_remap(struct bio *bio)
2674 if (bdev != bdev->bd_contains) { 2674 if (bdev != bdev->bd_contains) {
2675 struct hd_struct *p = bdev->bd_part; 2675 struct hd_struct *p = bdev->bd_part;
2676 2676
2677 switch (bio->bi_rw) { 2677 switch (bio_data_dir(bio)) {
2678 case READ: 2678 case READ:
2679 p->read_sectors += bio_sectors(bio); 2679 p->read_sectors += bio_sectors(bio);
2680 p->reads++; 2680 p->reads++;
@@ -2693,6 +2693,7 @@ void blk_finish_queue_drain(request_queue_t *q)
2693{ 2693{
2694 struct request_list *rl = &q->rq; 2694 struct request_list *rl = &q->rq;
2695 struct request *rq; 2695 struct request *rq;
2696 int requeued = 0;
2696 2697
2697 spin_lock_irq(q->queue_lock); 2698 spin_lock_irq(q->queue_lock);
2698 clear_bit(QUEUE_FLAG_DRAIN, &q->queue_flags); 2699 clear_bit(QUEUE_FLAG_DRAIN, &q->queue_flags);
@@ -2701,9 +2702,13 @@ void blk_finish_queue_drain(request_queue_t *q)
2701 rq = list_entry_rq(q->drain_list.next); 2702 rq = list_entry_rq(q->drain_list.next);
2702 2703
2703 list_del_init(&rq->queuelist); 2704 list_del_init(&rq->queuelist);
2704 __elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1); 2705 elv_requeue_request(q, rq);
2706 requeued++;
2705 } 2707 }
2706 2708
2709 if (requeued)
2710 q->request_fn(q);
2711
2707 spin_unlock_irq(q->queue_lock); 2712 spin_unlock_irq(q->queue_lock);
2708 2713
2709 wake_up(&rl->wait[0]); 2714 wake_up(&rl->wait[0]);
@@ -2900,7 +2905,7 @@ void submit_bio(int rw, struct bio *bio)
2900 2905
2901 BIO_BUG_ON(!bio->bi_size); 2906 BIO_BUG_ON(!bio->bi_size);
2902 BIO_BUG_ON(!bio->bi_io_vec); 2907 BIO_BUG_ON(!bio->bi_io_vec);
2903 bio->bi_rw = rw; 2908 bio->bi_rw |= rw;
2904 if (rw & WRITE) 2909 if (rw & WRITE)
2905 mod_page_state(pgpgout, count); 2910 mod_page_state(pgpgout, count);
2906 else 2911 else
@@ -3257,8 +3262,11 @@ void exit_io_context(void)
3257 struct io_context *ioc; 3262 struct io_context *ioc;
3258 3263
3259 local_irq_save(flags); 3264 local_irq_save(flags);
3265 task_lock(current);
3260 ioc = current->io_context; 3266 ioc = current->io_context;
3261 current->io_context = NULL; 3267 current->io_context = NULL;
3268 ioc->task = NULL;
3269 task_unlock(current);
3262 local_irq_restore(flags); 3270 local_irq_restore(flags);
3263 3271
3264 if (ioc->aic && ioc->aic->exit) 3272 if (ioc->aic && ioc->aic->exit)
@@ -3271,53 +3279,49 @@ void exit_io_context(void)
3271 3279
3272/* 3280/*
3273 * If the current task has no IO context then create one and initialise it. 3281 * If the current task has no IO context then create one and initialise it.
3274 * If it does have a context, take a ref on it. 3282 * Otherwise, return its existing IO context.
3275 * 3283 *
3276 * This is always called in the context of the task which submitted the I/O. 3284 * This returned IO context doesn't have a specifically elevated refcount,
3277 * But weird things happen, so we disable local interrupts to ensure exclusive 3285 * but since the current task itself holds a reference, the context can be
3278 * access to *current. 3286 * used in general code, so long as it stays within `current` context.
3279 */ 3287 */
3280struct io_context *get_io_context(int gfp_flags) 3288struct io_context *current_io_context(int gfp_flags)
3281{ 3289{
3282 struct task_struct *tsk = current; 3290 struct task_struct *tsk = current;
3283 unsigned long flags;
3284 struct io_context *ret; 3291 struct io_context *ret;
3285 3292
3286 local_irq_save(flags);
3287 ret = tsk->io_context; 3293 ret = tsk->io_context;
3288 if (ret) 3294 if (likely(ret))
3289 goto out; 3295 return ret;
3290
3291 local_irq_restore(flags);
3292 3296
3293 ret = kmem_cache_alloc(iocontext_cachep, gfp_flags); 3297 ret = kmem_cache_alloc(iocontext_cachep, gfp_flags);
3294 if (ret) { 3298 if (ret) {
3295 atomic_set(&ret->refcount, 1); 3299 atomic_set(&ret->refcount, 1);
3296 ret->pid = tsk->pid; 3300 ret->task = current;
3301 ret->set_ioprio = NULL;
3297 ret->last_waited = jiffies; /* doesn't matter... */ 3302 ret->last_waited = jiffies; /* doesn't matter... */
3298 ret->nr_batch_requests = 0; /* because this is 0 */ 3303 ret->nr_batch_requests = 0; /* because this is 0 */
3299 ret->aic = NULL; 3304 ret->aic = NULL;
3300 ret->cic = NULL; 3305 ret->cic = NULL;
3301 spin_lock_init(&ret->lock); 3306 tsk->io_context = ret;
3302 3307 }
3303 local_irq_save(flags);
3304 3308
3305 /* 3309 return ret;
3306 * very unlikely, someone raced with us in setting up the task 3310}
3307 * io context. free new context and just grab a reference. 3311EXPORT_SYMBOL(current_io_context);
3308 */
3309 if (!tsk->io_context)
3310 tsk->io_context = ret;
3311 else {
3312 kmem_cache_free(iocontext_cachep, ret);
3313 ret = tsk->io_context;
3314 }
3315 3312
3316out: 3313/*
3314 * If the current task has no IO context then create one and initialise it.
3315 * If it does have a context, take a ref on it.
3316 *
3317 * This is always called in the context of the task which submitted the I/O.
3318 */
3319struct io_context *get_io_context(int gfp_flags)
3320{
3321 struct io_context *ret;
3322 ret = current_io_context(gfp_flags);
3323 if (likely(ret))
3317 atomic_inc(&ret->refcount); 3324 atomic_inc(&ret->refcount);
3318 local_irq_restore(flags);
3319 }
3320
3321 return ret; 3325 return ret;
3322} 3326}
3323EXPORT_SYMBOL(get_io_context); 3327EXPORT_SYMBOL(get_io_context);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 5b09cf154ac7..e5f7494c00ee 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -253,7 +253,7 @@ static int floppy_revalidate(struct gendisk *disk);
253static int swim3_add_device(struct device_node *swims); 253static int swim3_add_device(struct device_node *swims);
254int swim3_init(void); 254int swim3_init(void);
255 255
256#ifndef CONFIG_PMAC_PBOOK 256#ifndef CONFIG_PMAC_MEDIABAY
257#define check_media_bay(which, what) 1 257#define check_media_bay(which, what) 1
258#endif 258#endif
259 259
@@ -297,9 +297,11 @@ static void do_fd_request(request_queue_t * q)
297 int i; 297 int i;
298 for(i=0;i<floppy_count;i++) 298 for(i=0;i<floppy_count;i++)
299 { 299 {
300#ifdef CONFIG_PMAC_MEDIABAY
300 if (floppy_states[i].media_bay && 301 if (floppy_states[i].media_bay &&
301 check_media_bay(floppy_states[i].media_bay, MB_FD)) 302 check_media_bay(floppy_states[i].media_bay, MB_FD))
302 continue; 303 continue;
304#endif /* CONFIG_PMAC_MEDIABAY */
303 start_request(&floppy_states[i]); 305 start_request(&floppy_states[i]);
304 } 306 }
305 sti(); 307 sti();
@@ -856,8 +858,10 @@ static int floppy_ioctl(struct inode *inode, struct file *filp,
856 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)) 858 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
857 return -EPERM; 859 return -EPERM;
858 860
861#ifdef CONFIG_PMAC_MEDIABAY
859 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 862 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
860 return -ENXIO; 863 return -ENXIO;
864#endif
861 865
862 switch (cmd) { 866 switch (cmd) {
863 case FDEJECT: 867 case FDEJECT:
@@ -881,8 +885,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
881 int n, err = 0; 885 int n, err = 0;
882 886
883 if (fs->ref_count == 0) { 887 if (fs->ref_count == 0) {
888#ifdef CONFIG_PMAC_MEDIABAY
884 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 889 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
885 return -ENXIO; 890 return -ENXIO;
891#endif
886 out_8(&sw->setup, S_IBM_DRIVE | S_FCLK_DIV2); 892 out_8(&sw->setup, S_IBM_DRIVE | S_FCLK_DIV2);
887 out_8(&sw->control_bic, 0xff); 893 out_8(&sw->control_bic, 0xff);
888 out_8(&sw->mode, 0x95); 894 out_8(&sw->mode, 0x95);
@@ -967,8 +973,10 @@ static int floppy_revalidate(struct gendisk *disk)
967 struct swim3 __iomem *sw; 973 struct swim3 __iomem *sw;
968 int ret, n; 974 int ret, n;
969 975
976#ifdef CONFIG_PMAC_MEDIABAY
970 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD)) 977 if (fs->media_bay && check_media_bay(fs->media_bay, MB_FD))
971 return -ENXIO; 978 return -ENXIO;
979#endif
972 980
973 sw = fs->swim3; 981 sw = fs->swim3;
974 grab_drive(fs, revalidating, 0); 982 grab_drive(fs, revalidating, 0);
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 5ed3a6379452..9db0a9e3e59c 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/hdreg.h> 28#include <linux/hdreg.h>
29#include <linux/dma-mapping.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/semaphore.h> 31#include <asm/semaphore.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -1582,9 +1583,9 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1582 goto err_out; 1583 goto err_out;
1583 1584
1584#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */ 1585#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */
1585 rc = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 1586 rc = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1586 if (!rc) { 1587 if (!rc) {
1587 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); 1588 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1588 if (rc) { 1589 if (rc) {
1589 printk(KERN_ERR DRV_NAME "(%s): consistent DMA mask failure\n", 1590 printk(KERN_ERR DRV_NAME "(%s): consistent DMA mask failure\n",
1590 pci_name(pdev)); 1591 pci_name(pdev));
@@ -1593,7 +1594,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1593 pci_dac = 1; 1594 pci_dac = 1;
1594 } else { 1595 } else {
1595#endif 1596#endif
1596 rc = pci_set_dma_mask(pdev, 0xffffffffULL); 1597 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1597 if (rc) { 1598 if (rc) {
1598 printk(KERN_ERR DRV_NAME "(%s): DMA mask failure\n", 1599 printk(KERN_ERR DRV_NAME "(%s): DMA mask failure\n",
1599 pci_name(pdev)); 1600 pci_name(pdev));
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index e481cc411b5d..bd2ec7e284cc 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -40,7 +40,6 @@
40#include <linux/skbuff.h> 40#include <linux/skbuff.h>
41#include <asm/io.h> 41#include <asm/io.h>
42 42
43#include <pcmcia/version.h>
44#include <pcmcia/cs_types.h> 43#include <pcmcia/cs_types.h>
45#include <pcmcia/cs.h> 44#include <pcmcia/cs.h>
46#include <pcmcia/cistpl.h> 45#include <pcmcia/cistpl.h>
@@ -895,11 +894,6 @@ static dev_link_t *bluecard_attach(void)
895 link->next = dev_list; 894 link->next = dev_list;
896 dev_list = link; 895 dev_list = link;
897 client_reg.dev_info = &dev_info; 896 client_reg.dev_info = &dev_info;
898 client_reg.EventMask =
899 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
900 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
901 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
902 client_reg.event_handler = &bluecard_event;
903 client_reg.Version = 0x0210; 897 client_reg.Version = 0x0210;
904 client_reg.event_callback_args.client_data = link; 898 client_reg.event_callback_args.client_data = link;
905 899
@@ -1089,13 +1083,23 @@ static int bluecard_event(event_t event, int priority, event_callback_args_t *ar
1089 return 0; 1083 return 0;
1090} 1084}
1091 1085
1086static struct pcmcia_device_id bluecard_ids[] = {
1087 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
1088 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
1089 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
1090 PCMCIA_DEVICE_NULL
1091};
1092MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
1093
1092static struct pcmcia_driver bluecard_driver = { 1094static struct pcmcia_driver bluecard_driver = {
1093 .owner = THIS_MODULE, 1095 .owner = THIS_MODULE,
1094 .drv = { 1096 .drv = {
1095 .name = "bluecard_cs", 1097 .name = "bluecard_cs",
1096 }, 1098 },
1097 .attach = bluecard_attach, 1099 .attach = bluecard_attach,
1100 .event = bluecard_event,
1098 .detach = bluecard_detach, 1101 .detach = bluecard_detach,
1102 .id_table = bluecard_ids,
1099}; 1103};
1100 1104
1101static int __init init_bluecard_cs(void) 1105static int __init init_bluecard_cs(void)
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index f71e5c76963d..adf1750ea58d 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -47,7 +47,6 @@
47#include <linux/device.h> 47#include <linux/device.h>
48#include <linux/firmware.h> 48#include <linux/firmware.h>
49 49
50#include <pcmcia/version.h>
51#include <pcmcia/cs_types.h> 50#include <pcmcia/cs_types.h>
52#include <pcmcia/cs.h> 51#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
@@ -696,11 +695,6 @@ static dev_link_t *bt3c_attach(void)
696 link->next = dev_list; 695 link->next = dev_list;
697 dev_list = link; 696 dev_list = link;
698 client_reg.dev_info = &dev_info; 697 client_reg.dev_info = &dev_info;
699 client_reg.EventMask =
700 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
701 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
702 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
703 client_reg.event_handler = &bt3c_event;
704 client_reg.Version = 0x0210; 698 client_reg.Version = 0x0210;
705 client_reg.event_callback_args.client_data = link; 699 client_reg.event_callback_args.client_data = link;
706 700
@@ -935,13 +929,21 @@ static int bt3c_event(event_t event, int priority, event_callback_args_t *args)
935 return 0; 929 return 0;
936} 930}
937 931
932static struct pcmcia_device_id bt3c_ids[] = {
933 PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
934 PCMCIA_DEVICE_NULL
935};
936MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
937
938static struct pcmcia_driver bt3c_driver = { 938static struct pcmcia_driver bt3c_driver = {
939 .owner = THIS_MODULE, 939 .owner = THIS_MODULE,
940 .drv = { 940 .drv = {
941 .name = "bt3c_cs", 941 .name = "bt3c_cs",
942 }, 942 },
943 .attach = bt3c_attach, 943 .attach = bt3c_attach,
944 .event = bt3c_event,
944 .detach = bt3c_detach, 945 .detach = bt3c_detach,
946 .id_table = bt3c_ids,
945}; 947};
946 948
947static int __init init_bt3c_cs(void) 949static int __init init_bt3c_cs(void)
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index ad8d972444a5..e4c59fdc0e12 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -43,7 +43,6 @@
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/io.h> 44#include <asm/io.h>
45 45
46#include <pcmcia/version.h>
47#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
48#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
@@ -615,11 +614,6 @@ static dev_link_t *btuart_attach(void)
615 link->next = dev_list; 614 link->next = dev_list;
616 dev_list = link; 615 dev_list = link;
617 client_reg.dev_info = &dev_info; 616 client_reg.dev_info = &dev_info;
618 client_reg.EventMask =
619 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
620 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
621 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
622 client_reg.event_handler = &btuart_event;
623 client_reg.Version = 0x0210; 617 client_reg.Version = 0x0210;
624 client_reg.event_callback_args.client_data = link; 618 client_reg.event_callback_args.client_data = link;
625 619
@@ -855,13 +849,21 @@ static int btuart_event(event_t event, int priority, event_callback_args_t *args
855 return 0; 849 return 0;
856} 850}
857 851
852static struct pcmcia_device_id btuart_ids[] = {
853 /* don't use this driver. Use serial_cs + hci_uart instead */
854 PCMCIA_DEVICE_NULL
855};
856MODULE_DEVICE_TABLE(pcmcia, btuart_ids);
857
858static struct pcmcia_driver btuart_driver = { 858static struct pcmcia_driver btuart_driver = {
859 .owner = THIS_MODULE, 859 .owner = THIS_MODULE,
860 .drv = { 860 .drv = {
861 .name = "btuart_cs", 861 .name = "btuart_cs",
862 }, 862 },
863 .attach = btuart_attach, 863 .attach = btuart_attach,
864 .event = btuart_event,
864 .detach = btuart_detach, 865 .detach = btuart_detach,
866 .id_table = btuart_ids,
865}; 867};
866 868
867static int __init init_btuart_cs(void) 869static int __init init_btuart_cs(void)
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index fe954e5d9a1d..e39868c3da48 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -43,7 +43,6 @@
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/io.h> 44#include <asm/io.h>
45 45
46#include <pcmcia/version.h>
47#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
48#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
@@ -594,11 +593,6 @@ static dev_link_t *dtl1_attach(void)
594 link->next = dev_list; 593 link->next = dev_list;
595 dev_list = link; 594 dev_list = link;
596 client_reg.dev_info = &dev_info; 595 client_reg.dev_info = &dev_info;
597 client_reg.EventMask =
598 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
599 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
600 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
601 client_reg.event_handler = &dtl1_event;
602 client_reg.Version = 0x0210; 596 client_reg.Version = 0x0210;
603 client_reg.event_callback_args.client_data = link; 597 client_reg.event_callback_args.client_data = link;
604 598
@@ -807,13 +801,22 @@ static int dtl1_event(event_t event, int priority, event_callback_args_t *args)
807 return 0; 801 return 0;
808} 802}
809 803
804static struct pcmcia_device_id dtl1_ids[] = {
805 PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
806 PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
807 PCMCIA_DEVICE_NULL
808};
809MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
810
810static struct pcmcia_driver dtl1_driver = { 811static struct pcmcia_driver dtl1_driver = {
811 .owner = THIS_MODULE, 812 .owner = THIS_MODULE,
812 .drv = { 813 .drv = {
813 .name = "dtl1_cs", 814 .name = "dtl1_cs",
814 }, 815 },
815 .attach = dtl1_attach, 816 .attach = dtl1_attach,
817 .event = dtl1_event,
816 .detach = dtl1_detach, 818 .detach = dtl1_detach,
819 .id_table = dtl1_ids,
817}; 820};
818 821
819static int __init init_dtl1_cs(void) 822static int __init init_dtl1_cs(void)
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 3256192dcde8..f9b956fb2b8b 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -120,7 +120,7 @@ static unsigned int hci_vhci_chr_poll(struct file *file, poll_table * wait)
120 120
121 poll_wait(file, &hci_vhci->read_wait, wait); 121 poll_wait(file, &hci_vhci->read_wait, wait);
122 122
123 if (skb_queue_len(&hci_vhci->readq)) 123 if (!skb_queue_empty(&hci_vhci->readq))
124 return POLLIN | POLLRDNORM; 124 return POLLIN | POLLRDNORM;
125 125
126 return POLLOUT | POLLWRNORM; 126 return POLLOUT | POLLWRNORM;
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 1aff819f3832..08f69287ea36 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -40,7 +40,7 @@ obj-$(CONFIG_N_HDLC) += n_hdlc.o
40obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o 40obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
41obj-$(CONFIG_SX) += sx.o generic_serial.o 41obj-$(CONFIG_SX) += sx.o generic_serial.o
42obj-$(CONFIG_RIO) += rio/ generic_serial.o 42obj-$(CONFIG_RIO) += rio/ generic_serial.o
43obj-$(CONFIG_HVC_CONSOLE) += hvc_console.o hvsi.o 43obj-$(CONFIG_HVC_CONSOLE) += hvc_console.o hvc_vio.o hvsi.o
44obj-$(CONFIG_RAW_DRIVER) += raw.o 44obj-$(CONFIG_RAW_DRIVER) += raw.o
45obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 45obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
46obj-$(CONFIG_MMTIMER) += mmtimer.o 46obj-$(CONFIG_MMTIMER) += mmtimer.o
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 1407945a5892..59f589d733f9 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -686,6 +686,15 @@ static struct pci_device_id agp_amd64_pci_table[] = {
686 .subvendor = PCI_ANY_ID, 686 .subvendor = PCI_ANY_ID,
687 .subdevice = PCI_ANY_ID, 687 .subdevice = PCI_ANY_ID,
688 }, 688 },
689 /* SIS 760 */
690 {
691 .class = (PCI_CLASS_BRIDGE_HOST << 8),
692 .class_mask = ~0,
693 .vendor = PCI_VENDOR_ID_SI,
694 .device = PCI_DEVICE_ID_SI_760,
695 .subvendor = PCI_ANY_ID,
696 .subdevice = PCI_ANY_ID,
697 },
689 { } 698 { }
690}; 699};
691 700
diff --git a/drivers/char/drm/Kconfig b/drivers/char/drm/Kconfig
index d9a029934678..123417e43040 100644
--- a/drivers/char/drm/Kconfig
+++ b/drivers/char/drm/Kconfig
@@ -6,7 +6,7 @@
6# 6#
7config DRM 7config DRM
8 tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)" 8 tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
9 depends on AGP || AGP=n 9 depends on (AGP || AGP=n) && PCI
10 help 10 help
11 Kernel-level support for the Direct Rendering Infrastructure (DRI) 11 Kernel-level support for the Direct Rendering Infrastructure (DRI)
12 introduced in XFree86 4.0. If you say Y here, you need to select 12 introduced in XFree86 4.0. If you say Y here, you need to select
@@ -96,3 +96,10 @@ config DRM_SIS
96 chipset. If M is selected the module will be called sis. AGP 96 chipset. If M is selected the module will be called sis. AGP
97 support is required for this driver to work. 97 support is required for this driver to work.
98 98
99config DRM_VIA
100 tristate "Via unichrome video cards"
101 depends on DRM
102 help
103 Choose this option if you have a Via unichrome or compatible video
104 chipset. If M is selected the module will be called via.
105
diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile
index 23ab26321e9a..ddd941045b1f 100644
--- a/drivers/char/drm/Makefile
+++ b/drivers/char/drm/Makefile
@@ -18,6 +18,15 @@ i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
18radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o 18radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o
19ffb-objs := ffb_drv.o ffb_context.o 19ffb-objs := ffb_drv.o ffb_context.o
20sis-objs := sis_drv.o sis_ds.o sis_mm.o 20sis-objs := sis_drv.o sis_ds.o sis_mm.o
21via-objs := via_irq.o via_drv.o via_ds.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o
22
23ifeq ($(CONFIG_COMPAT),y)
24drm-objs += drm_ioc32.o
25radeon-objs += radeon_ioc32.o
26mga-objs += mga_ioc32.o
27r128-objs += r128_ioc32.o
28i915-objs += i915_ioc32.o
29endif
21 30
22obj-$(CONFIG_DRM) += drm.o 31obj-$(CONFIG_DRM) += drm.o
23obj-$(CONFIG_DRM_GAMMA) += gamma.o 32obj-$(CONFIG_DRM_GAMMA) += gamma.o
@@ -30,4 +39,5 @@ obj-$(CONFIG_DRM_I830) += i830.o
30obj-$(CONFIG_DRM_I915) += i915.o 39obj-$(CONFIG_DRM_I915) += i915.o
31obj-$(CONFIG_DRM_FFB) += ffb.o 40obj-$(CONFIG_DRM_FFB) += ffb.o
32obj-$(CONFIG_DRM_SIS) += sis.o 41obj-$(CONFIG_DRM_SIS) += sis.o
42obj-$(CONFIG_DRM_VIA) +=via.o
33 43
diff --git a/drivers/char/drm/ati_pcigart.c b/drivers/char/drm/ati_pcigart.c
index fdca1876ecd5..0aec5ef481b8 100644
--- a/drivers/char/drm/ati_pcigart.c
+++ b/drivers/char/drm/ati_pcigart.c
@@ -52,7 +52,7 @@
52# define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */ 52# define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */
53# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ 53# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
54 54
55unsigned long drm_ati_alloc_pcigart_table( void ) 55static unsigned long drm_ati_alloc_pcigart_table( void )
56{ 56{
57 unsigned long address; 57 unsigned long address;
58 struct page *page; 58 struct page *page;
diff --git a/drivers/char/drm/drm.h b/drivers/char/drm/drm.h
index 587305282ea8..e8371dd87fbc 100644
--- a/drivers/char/drm/drm.h
+++ b/drivers/char/drm/drm.h
@@ -38,7 +38,9 @@
38#define _DRM_H_ 38#define _DRM_H_
39 39
40#if defined(__linux__) 40#if defined(__linux__)
41#if defined(__KERNEL__)
41#include <linux/config.h> 42#include <linux/config.h>
43#endif
42#include <asm/ioctl.h> /* For _IO* macros */ 44#include <asm/ioctl.h> /* For _IO* macros */
43#define DRM_IOCTL_NR(n) _IOC_NR(n) 45#define DRM_IOCTL_NR(n) _IOC_NR(n)
44#define DRM_IOC_VOID _IOC_NONE 46#define DRM_IOC_VOID _IOC_NONE
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 21f4c54e1a8d..5df09cc8c6db 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -316,6 +316,9 @@ do { \
316typedef int drm_ioctl_t( struct inode *inode, struct file *filp, 316typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
317 unsigned int cmd, unsigned long arg ); 317 unsigned int cmd, unsigned long arg );
318 318
319typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
320 unsigned long arg);
321
319typedef struct drm_ioctl_desc { 322typedef struct drm_ioctl_desc {
320 drm_ioctl_t *func; 323 drm_ioctl_t *func;
321 int auth_needed; 324 int auth_needed;
@@ -771,37 +774,28 @@ extern int drm_cpu_valid( void );
771 /* Driver support (drm_drv.h) */ 774 /* Driver support (drm_drv.h) */
772extern int drm_init(struct drm_driver *driver); 775extern int drm_init(struct drm_driver *driver);
773extern void drm_exit(struct drm_driver *driver); 776extern void drm_exit(struct drm_driver *driver);
774extern int drm_version(struct inode *inode, struct file *filp,
775 unsigned int cmd, unsigned long arg);
776extern int drm_ioctl(struct inode *inode, struct file *filp, 777extern int drm_ioctl(struct inode *inode, struct file *filp,
777 unsigned int cmd, unsigned long arg); 778 unsigned int cmd, unsigned long arg);
779extern long drm_compat_ioctl(struct file *filp,
780 unsigned int cmd, unsigned long arg);
778extern int drm_takedown(drm_device_t * dev); 781extern int drm_takedown(drm_device_t * dev);
779 782
780 /* Device support (drm_fops.h) */ 783 /* Device support (drm_fops.h) */
781extern int drm_open(struct inode *inode, struct file *filp); 784extern int drm_open(struct inode *inode, struct file *filp);
782extern int drm_stub_open(struct inode *inode, struct file *filp); 785extern int drm_stub_open(struct inode *inode, struct file *filp);
783extern int drm_open_helper(struct inode *inode, struct file *filp,
784 drm_device_t *dev);
785extern int drm_flush(struct file *filp); 786extern int drm_flush(struct file *filp);
786extern int drm_fasync(int fd, struct file *filp, int on); 787extern int drm_fasync(int fd, struct file *filp, int on);
787extern int drm_release(struct inode *inode, struct file *filp); 788extern int drm_release(struct inode *inode, struct file *filp);
788 789
789 /* Mapping support (drm_vm.h) */ 790 /* Mapping support (drm_vm.h) */
790extern void drm_vm_open(struct vm_area_struct *vma);
791extern void drm_vm_close(struct vm_area_struct *vma);
792extern void drm_vm_shm_close(struct vm_area_struct *vma);
793extern int drm_mmap_dma(struct file *filp,
794 struct vm_area_struct *vma);
795extern int drm_mmap(struct file *filp, struct vm_area_struct *vma); 791extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
796extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); 792extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
797extern ssize_t drm_read(struct file *filp, char __user *buf, size_t count, loff_t *off);
798 793
799 /* Memory management support (drm_memory.h) */ 794 /* Memory management support (drm_memory.h) */
800#include "drm_memory.h" 795#include "drm_memory.h"
801extern void drm_mem_init(void); 796extern void drm_mem_init(void);
802extern int drm_mem_info(char *buf, char **start, off_t offset, 797extern int drm_mem_info(char *buf, char **start, off_t offset,
803 int request, int *eof, void *data); 798 int request, int *eof, void *data);
804extern void *drm_calloc(size_t nmemb, size_t size, int area);
805extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, 799extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
806 int area); 800 int area);
807extern unsigned long drm_alloc_pages(int order, int area); 801extern unsigned long drm_alloc_pages(int order, int area);
@@ -849,9 +843,6 @@ extern int drm_newctx( struct inode *inode, struct file *filp,
849extern int drm_rmctx( struct inode *inode, struct file *filp, 843extern int drm_rmctx( struct inode *inode, struct file *filp,
850 unsigned int cmd, unsigned long arg ); 844 unsigned int cmd, unsigned long arg );
851 845
852extern int drm_context_switch(drm_device_t *dev, int old, int new);
853extern int drm_context_switch_complete(drm_device_t *dev, int new);
854
855extern int drm_ctxbitmap_init( drm_device_t *dev ); 846extern int drm_ctxbitmap_init( drm_device_t *dev );
856extern void drm_ctxbitmap_cleanup( drm_device_t *dev ); 847extern void drm_ctxbitmap_cleanup( drm_device_t *dev );
857extern void drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle ); 848extern void drm_ctxbitmap_free( drm_device_t *dev, int ctx_handle );
@@ -869,9 +860,6 @@ extern int drm_rmdraw(struct inode *inode, struct file *filp,
869 860
870 861
871 /* Authentication IOCTL support (drm_auth.h) */ 862 /* Authentication IOCTL support (drm_auth.h) */
872extern int drm_add_magic(drm_device_t *dev, drm_file_t *priv,
873 drm_magic_t magic);
874extern int drm_remove_magic(drm_device_t *dev, drm_magic_t magic);
875extern int drm_getmagic(struct inode *inode, struct file *filp, 863extern int drm_getmagic(struct inode *inode, struct file *filp,
876 unsigned int cmd, unsigned long arg); 864 unsigned int cmd, unsigned long arg);
877extern int drm_authmagic(struct inode *inode, struct file *filp, 865extern int drm_authmagic(struct inode *inode, struct file *filp,
@@ -888,13 +876,9 @@ extern int drm_unlock(struct inode *inode, struct file *filp,
888 unsigned int cmd, unsigned long arg); 876 unsigned int cmd, unsigned long arg);
889extern int drm_lock_take(__volatile__ unsigned int *lock, 877extern int drm_lock_take(__volatile__ unsigned int *lock,
890 unsigned int context); 878 unsigned int context);
891extern int drm_lock_transfer(drm_device_t *dev,
892 __volatile__ unsigned int *lock,
893 unsigned int context);
894extern int drm_lock_free(drm_device_t *dev, 879extern int drm_lock_free(drm_device_t *dev,
895 __volatile__ unsigned int *lock, 880 __volatile__ unsigned int *lock,
896 unsigned int context); 881 unsigned int context);
897extern int drm_notifier(void *priv);
898 882
899 /* Buffer management support (drm_bufs.h) */ 883 /* Buffer management support (drm_bufs.h) */
900extern int drm_order( unsigned long size ); 884extern int drm_order( unsigned long size );
@@ -922,7 +906,6 @@ extern void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
922 /* IRQ support (drm_irq.h) */ 906 /* IRQ support (drm_irq.h) */
923extern int drm_control( struct inode *inode, struct file *filp, 907extern int drm_control( struct inode *inode, struct file *filp,
924 unsigned int cmd, unsigned long arg ); 908 unsigned int cmd, unsigned long arg );
925extern int drm_irq_install( drm_device_t *dev );
926extern int drm_irq_uninstall( drm_device_t *dev ); 909extern int drm_irq_uninstall( drm_device_t *dev );
927extern irqreturn_t drm_irq_handler( DRM_IRQ_ARGS ); 910extern irqreturn_t drm_irq_handler( DRM_IRQ_ARGS );
928extern void drm_driver_irq_preinstall( drm_device_t *dev ); 911extern void drm_driver_irq_preinstall( drm_device_t *dev );
@@ -962,7 +945,6 @@ extern int drm_agp_unbind_memory(DRM_AGP_MEM *handle);
962extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent, 945extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
963 struct drm_driver *driver); 946 struct drm_driver *driver);
964extern int drm_put_dev(drm_device_t * dev); 947extern int drm_put_dev(drm_device_t * dev);
965extern int drm_get_head(drm_device_t * dev, drm_head_t *head);
966extern int drm_put_head(drm_head_t * head); 948extern int drm_put_head(drm_head_t * head);
967extern unsigned int drm_debug; 949extern unsigned int drm_debug;
968extern unsigned int drm_cards_limit; 950extern unsigned int drm_cards_limit;
@@ -1059,9 +1041,16 @@ static __inline__ void drm_free(void *pt, size_t size, int area)
1059{ 1041{
1060 kfree(pt); 1042 kfree(pt);
1061} 1043}
1044
1045/** Wrapper around kcalloc() */
1046static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
1047{
1048 return kcalloc(nmemb, size, GFP_KERNEL);
1049}
1062#else 1050#else
1063extern void *drm_alloc(size_t size, int area); 1051extern void *drm_alloc(size_t size, int area);
1064extern void drm_free(void *pt, size_t size, int area); 1052extern void drm_free(void *pt, size_t size, int area);
1053extern void *drm_calloc(size_t nmemb, size_t size, int area);
1065#endif 1054#endif
1066 1055
1067/*@}*/ 1056/*@}*/
diff --git a/drivers/char/drm/drm_auth.c b/drivers/char/drm/drm_auth.c
index b428761c4e91..dd140bca8f71 100644
--- a/drivers/char/drm/drm_auth.c
+++ b/drivers/char/drm/drm_auth.c
@@ -87,7 +87,7 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
87 * associated the magic number hash key in drm_device::magiclist, while holding 87 * associated the magic number hash key in drm_device::magiclist, while holding
88 * the drm_device::struct_sem lock. 88 * the drm_device::struct_sem lock.
89 */ 89 */
90int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) 90static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
91{ 91{
92 int hash; 92 int hash;
93 drm_magic_entry_t *entry; 93 drm_magic_entry_t *entry;
@@ -124,7 +124,7 @@ int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
124 * Searches and unlinks the entry in drm_device::magiclist with the magic 124 * Searches and unlinks the entry in drm_device::magiclist with the magic
125 * number hash key, while holding the drm_device::struct_sem lock. 125 * number hash key, while holding the drm_device::struct_sem lock.
126 */ 126 */
127int drm_remove_magic(drm_device_t *dev, drm_magic_t magic) 127static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
128{ 128{
129 drm_magic_entry_t *prev = NULL; 129 drm_magic_entry_t *prev = NULL;
130 drm_magic_entry_t *pt; 130 drm_magic_entry_t *pt;
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index 4113bcba67fe..4c6191d231b8 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -60,6 +60,15 @@ int drm_order( unsigned long size )
60} 60}
61EXPORT_SYMBOL(drm_order); 61EXPORT_SYMBOL(drm_order);
62 62
63#ifdef CONFIG_COMPAT
64/*
65 * Used to allocate 32-bit handles for _DRM_SHM regions
66 * The 0x10000000 value is chosen to be out of the way of
67 * FB/register and GART physical addresses.
68 */
69static unsigned int map32_handle = 0x10000000;
70#endif
71
63/** 72/**
64 * Ioctl to specify a range of memory that is available for mapping by a non-root process. 73 * Ioctl to specify a range of memory that is available for mapping by a non-root process.
65 * 74 *
@@ -187,16 +196,18 @@ int drm_addmap( struct inode *inode, struct file *filp,
187 196
188 down(&dev->struct_sem); 197 down(&dev->struct_sem);
189 list_add(&list->head, &dev->maplist->head); 198 list_add(&list->head, &dev->maplist->head);
199#ifdef CONFIG_COMPAT
200 /* Assign a 32-bit handle for _DRM_SHM mappings */
201 /* We do it here so that dev->struct_sem protects the increment */
202 if (map->type == _DRM_SHM)
203 map->offset = map32_handle += PAGE_SIZE;
204#endif
190 up(&dev->struct_sem); 205 up(&dev->struct_sem);
191 206
192 if ( copy_to_user( argp, map, sizeof(*map) ) ) 207 if ( copy_to_user( argp, map, sizeof(*map) ) )
193 return -EFAULT; 208 return -EFAULT;
194 if ( map->type != _DRM_SHM ) { 209 if (copy_to_user(&argp->handle, &map->offset, sizeof(map->offset)))
195 if ( copy_to_user( &argp->handle, 210 return -EFAULT;
196 &map->offset,
197 sizeof(map->offset) ) )
198 return -EFAULT;
199 }
200 return 0; 211 return 0;
201} 212}
202 213
@@ -240,7 +251,7 @@ int drm_rmmap(struct inode *inode, struct file *filp,
240 r_list = list_entry(list, drm_map_list_t, head); 251 r_list = list_entry(list, drm_map_list_t, head);
241 252
242 if(r_list->map && 253 if(r_list->map &&
243 r_list->map->handle == request.handle && 254 r_list->map->offset == (unsigned long) request.handle &&
244 r_list->map->flags & _DRM_REMOVABLE) break; 255 r_list->map->flags & _DRM_REMOVABLE) break;
245 } 256 }
246 257
@@ -345,8 +356,8 @@ static void drm_cleanup_buf_error(drm_device_t *dev, drm_buf_entry_t *entry)
345 * reallocates the buffer list of the same size order to accommodate the new 356 * reallocates the buffer list of the same size order to accommodate the new
346 * buffers. 357 * buffers.
347 */ 358 */
348int drm_addbufs_agp( struct inode *inode, struct file *filp, 359static int drm_addbufs_agp( struct inode *inode, struct file *filp,
349 unsigned int cmd, unsigned long arg ) 360 unsigned int cmd, unsigned long arg )
350{ 361{
351 drm_file_t *priv = filp->private_data; 362 drm_file_t *priv = filp->private_data;
352 drm_device_t *dev = priv->head->dev; 363 drm_device_t *dev = priv->head->dev;
@@ -510,8 +521,8 @@ int drm_addbufs_agp( struct inode *inode, struct file *filp,
510} 521}
511#endif /* __OS_HAS_AGP */ 522#endif /* __OS_HAS_AGP */
512 523
513int drm_addbufs_pci( struct inode *inode, struct file *filp, 524static int drm_addbufs_pci( struct inode *inode, struct file *filp,
514 unsigned int cmd, unsigned long arg ) 525 unsigned int cmd, unsigned long arg )
515{ 526{
516 drm_file_t *priv = filp->private_data; 527 drm_file_t *priv = filp->private_data;
517 drm_device_t *dev = priv->head->dev; 528 drm_device_t *dev = priv->head->dev;
@@ -740,8 +751,8 @@ int drm_addbufs_pci( struct inode *inode, struct file *filp,
740 751
741} 752}
742 753
743int drm_addbufs_sg( struct inode *inode, struct file *filp, 754static int drm_addbufs_sg( struct inode *inode, struct file *filp,
744 unsigned int cmd, unsigned long arg ) 755 unsigned int cmd, unsigned long arg )
745{ 756{
746 drm_file_t *priv = filp->private_data; 757 drm_file_t *priv = filp->private_data;
747 drm_device_t *dev = priv->head->dev; 758 drm_device_t *dev = priv->head->dev;
diff --git a/drivers/char/drm/drm_context.c b/drivers/char/drm/drm_context.c
index f15c86c57875..a7cfabd1ca2e 100644
--- a/drivers/char/drm/drm_context.c
+++ b/drivers/char/drm/drm_context.c
@@ -84,7 +84,7 @@ failed:
84 * drm_device::context_sareas to accommodate the new entry while holding the 84 * drm_device::context_sareas to accommodate the new entry while holding the
85 * drm_device::struct_sem lock. 85 * drm_device::struct_sem lock.
86 */ 86 */
87int drm_ctxbitmap_next( drm_device_t *dev ) 87static int drm_ctxbitmap_next( drm_device_t *dev )
88{ 88{
89 int bit; 89 int bit;
90 90
@@ -225,7 +225,7 @@ int drm_getsareactx(struct inode *inode, struct file *filp,
225 map = dev->context_sareas[request.ctx_id]; 225 map = dev->context_sareas[request.ctx_id];
226 up(&dev->struct_sem); 226 up(&dev->struct_sem);
227 227
228 request.handle = map->handle; 228 request.handle = (void *) map->offset;
229 if (copy_to_user(argp, &request, sizeof(request))) 229 if (copy_to_user(argp, &request, sizeof(request)))
230 return -EFAULT; 230 return -EFAULT;
231 return 0; 231 return 0;
@@ -261,8 +261,8 @@ int drm_setsareactx(struct inode *inode, struct file *filp,
261 down(&dev->struct_sem); 261 down(&dev->struct_sem);
262 list_for_each(list, &dev->maplist->head) { 262 list_for_each(list, &dev->maplist->head) {
263 r_list = list_entry(list, drm_map_list_t, head); 263 r_list = list_entry(list, drm_map_list_t, head);
264 if(r_list->map && 264 if (r_list->map
265 r_list->map->handle == request.handle) 265 && r_list->map->offset == (unsigned long) request.handle)
266 goto found; 266 goto found;
267 } 267 }
268bad: 268bad:
@@ -326,7 +326,7 @@ int drm_context_switch( drm_device_t *dev, int old, int new )
326 * hardware lock is held, clears the drm_device::context_flag and wakes up 326 * hardware lock is held, clears the drm_device::context_flag and wakes up
327 * drm_device::context_wait. 327 * drm_device::context_wait.
328 */ 328 */
329int drm_context_switch_complete( drm_device_t *dev, int new ) 329static int drm_context_switch_complete( drm_device_t *dev, int new )
330{ 330{
331 dev->last_context = new; /* PRE/POST: This is the _only_ writer. */ 331 dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
332 dev->last_switch = jiffies; 332 dev->last_switch = jiffies;
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index 1e37ed0c6b8d..3333c250c4d9 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -51,8 +51,11 @@
51#include "drmP.h" 51#include "drmP.h"
52#include "drm_core.h" 52#include "drm_core.h"
53 53
54static int drm_version(struct inode *inode, struct file *filp,
55 unsigned int cmd, unsigned long arg);
56
54/** Ioctl table */ 57/** Ioctl table */
55drm_ioctl_desc_t drm_ioctls[] = { 58static drm_ioctl_desc_t drm_ioctls[] = {
56 [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 }, 59 [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 },
57 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 }, 60 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 },
58 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 }, 61 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 },
@@ -447,8 +450,8 @@ module_exit( drm_core_exit );
447 * 450 *
448 * Fills in the version information in \p arg. 451 * Fills in the version information in \p arg.
449 */ 452 */
450int drm_version( struct inode *inode, struct file *filp, 453static int drm_version( struct inode *inode, struct file *filp,
451 unsigned int cmd, unsigned long arg ) 454 unsigned int cmd, unsigned long arg )
452{ 455{
453 drm_file_t *priv = filp->private_data; 456 drm_file_t *priv = filp->private_data;
454 drm_device_t *dev = priv->head->dev; 457 drm_device_t *dev = priv->head->dev;
diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c
index 906794247aeb..10e64fde8d78 100644
--- a/drivers/char/drm/drm_fops.c
+++ b/drivers/char/drm/drm_fops.c
@@ -37,6 +37,8 @@
37#include "drmP.h" 37#include "drmP.h"
38#include <linux/poll.h> 38#include <linux/poll.h>
39 39
40static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev);
41
40static int drm_setup( drm_device_t *dev ) 42static int drm_setup( drm_device_t *dev )
41{ 43{
42 int i; 44 int i;
@@ -251,7 +253,7 @@ int drm_release( struct inode *inode, struct file *filp )
251 } 253 }
252 } 254 }
253 255
254 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) 256 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) && !dev->driver->release)
255 { 257 {
256 dev->driver->reclaim_buffers(dev, filp); 258 dev->driver->reclaim_buffers(dev, filp);
257 } 259 }
@@ -259,7 +261,7 @@ int drm_release( struct inode *inode, struct file *filp )
259 drm_fasync( -1, filp, 0 ); 261 drm_fasync( -1, filp, 0 );
260 262
261 down( &dev->ctxlist_sem ); 263 down( &dev->ctxlist_sem );
262 if ( !list_empty( &dev->ctxlist->head ) ) { 264 if ( dev->ctxlist && (!list_empty(&dev->ctxlist->head))) {
263 drm_ctx_list_t *pos, *n; 265 drm_ctx_list_t *pos, *n;
264 266
265 list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) { 267 list_for_each_entry_safe( pos, n, &dev->ctxlist->head, head ) {
@@ -341,7 +343,7 @@ EXPORT_SYMBOL(drm_release);
341 * Creates and initializes a drm_file structure for the file private data in \p 343 * Creates and initializes a drm_file structure for the file private data in \p
342 * filp and add it into the double linked list in \p dev. 344 * filp and add it into the double linked list in \p dev.
343 */ 345 */
344int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev) 346static int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev)
345{ 347{
346 int minor = iminor(inode); 348 int minor = iminor(inode);
347 drm_file_t *priv; 349 drm_file_t *priv;
@@ -443,9 +445,3 @@ unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
443} 445}
444EXPORT_SYMBOL(drm_poll); 446EXPORT_SYMBOL(drm_poll);
445 447
446
447/** No-op. */
448ssize_t drm_read(struct file *filp, char __user *buf, size_t count, loff_t *off)
449{
450 return 0;
451}
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
new file mode 100644
index 000000000000..8087a9636399
--- /dev/null
+++ b/drivers/char/drm/drm_ioc32.c
@@ -0,0 +1,1069 @@
1/**
2 * \file drm_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the DRM.
5 *
6 * \author Paul Mackerras <paulus@samba.org>
7 *
8 * Copyright (C) Paul Mackerras 2005.
9 * All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30#include <linux/compat.h>
31#include <linux/ioctl32.h>
32
33#include "drmP.h"
34#include "drm_core.h"
35
36#define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t)
37#define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t)
38#define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t)
39#define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t)
40#define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t)
41
42#define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t)
43#define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t)
44#define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t)
45#define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t)
46#define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t)
47#define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t)
48#define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t)
49
50#define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t)
51
52#define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
53#define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
54
55#define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t)
56#define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t)
57
58#define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t)
59#define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t)
60#define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t)
61#define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t)
62#define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t)
63#define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t)
64
65#define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t)
66#define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t)
67
68#define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t)
69
70typedef struct drm_version_32 {
71 int version_major; /**< Major version */
72 int version_minor; /**< Minor version */
73 int version_patchlevel;/**< Patch level */
74 u32 name_len; /**< Length of name buffer */
75 u32 name; /**< Name of driver */
76 u32 date_len; /**< Length of date buffer */
77 u32 date; /**< User-space buffer to hold date */
78 u32 desc_len; /**< Length of desc buffer */
79 u32 desc; /**< User-space buffer to hold desc */
80} drm_version32_t;
81
82static int compat_drm_version(struct file *file, unsigned int cmd,
83 unsigned long arg)
84{
85 drm_version32_t v32;
86 drm_version_t __user *version;
87 int err;
88
89 if (copy_from_user(&v32, (void __user *) arg, sizeof(v32)))
90 return -EFAULT;
91
92 version = compat_alloc_user_space(sizeof(*version));
93 if (!access_ok(VERIFY_WRITE, version, sizeof(*version)))
94 return -EFAULT;
95 if (__put_user(v32.name_len, &version->name_len)
96 || __put_user((void __user *)(unsigned long)v32.name,
97 &version->name)
98 || __put_user(v32.date_len, &version->date_len)
99 || __put_user((void __user *)(unsigned long)v32.date,
100 &version->date)
101 || __put_user(v32.desc_len, &version->desc_len)
102 || __put_user((void __user *)(unsigned long)v32.desc,
103 &version->desc))
104 return -EFAULT;
105
106 err = drm_ioctl(file->f_dentry->d_inode, file,
107 DRM_IOCTL_VERSION, (unsigned long) version);
108 if (err)
109 return err;
110
111 if (__get_user(v32.version_major, &version->version_major)
112 || __get_user(v32.version_minor, &version->version_minor)
113 || __get_user(v32.version_patchlevel, &version->version_patchlevel)
114 || __get_user(v32.name_len, &version->name_len)
115 || __get_user(v32.date_len, &version->date_len)
116 || __get_user(v32.desc_len, &version->desc_len))
117 return -EFAULT;
118
119 if (copy_to_user((void __user *) arg, &v32, sizeof(v32)))
120 return -EFAULT;
121 return 0;
122}
123
124typedef struct drm_unique32 {
125 u32 unique_len; /**< Length of unique */
126 u32 unique; /**< Unique name for driver instantiation */
127} drm_unique32_t;
128
129static int compat_drm_getunique(struct file *file, unsigned int cmd,
130 unsigned long arg)
131{
132 drm_unique32_t uq32;
133 drm_unique_t __user *u;
134 int err;
135
136 if (copy_from_user(&uq32, (void __user *) arg, sizeof(uq32)))
137 return -EFAULT;
138
139 u = compat_alloc_user_space(sizeof(*u));
140 if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
141 return -EFAULT;
142 if (__put_user(uq32.unique_len, &u->unique_len)
143 || __put_user((void __user *)(unsigned long) uq32.unique,
144 &u->unique))
145 return -EFAULT;
146
147 err = drm_ioctl(file->f_dentry->d_inode, file,
148 DRM_IOCTL_GET_UNIQUE, (unsigned long) u);
149 if (err)
150 return err;
151
152 if (__get_user(uq32.unique_len, &u->unique_len))
153 return -EFAULT;
154 if (copy_to_user((void __user *) arg, &uq32, sizeof(uq32)))
155 return -EFAULT;
156 return 0;
157}
158
159static int compat_drm_setunique(struct file *file, unsigned int cmd,
160 unsigned long arg)
161{
162 drm_unique32_t uq32;
163 drm_unique_t __user *u;
164
165 if (copy_from_user(&uq32, (void __user *) arg, sizeof(uq32)))
166 return -EFAULT;
167
168 u = compat_alloc_user_space(sizeof(*u));
169 if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
170 return -EFAULT;
171 if (__put_user(uq32.unique_len, &u->unique_len)
172 || __put_user((void __user *)(unsigned long) uq32.unique,
173 &u->unique))
174 return -EFAULT;
175
176 return drm_ioctl(file->f_dentry->d_inode, file,
177 DRM_IOCTL_SET_UNIQUE, (unsigned long) u);
178}
179
180typedef struct drm_map32 {
181 u32 offset; /**< Requested physical address (0 for SAREA)*/
182 u32 size; /**< Requested physical size (bytes) */
183 drm_map_type_t type; /**< Type of memory to map */
184 drm_map_flags_t flags; /**< Flags */
185 u32 handle; /**< User-space: "Handle" to pass to mmap() */
186 int mtrr; /**< MTRR slot used */
187} drm_map32_t;
188
189static int compat_drm_getmap(struct file *file, unsigned int cmd,
190 unsigned long arg)
191{
192 drm_map32_t __user *argp = (void __user *)arg;
193 drm_map32_t m32;
194 drm_map_t __user *map;
195 int idx, err;
196 void *handle;
197
198 if (get_user(idx, &argp->offset))
199 return -EFAULT;
200
201 map = compat_alloc_user_space(sizeof(*map));
202 if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
203 return -EFAULT;
204 if (__put_user(idx, &map->offset))
205 return -EFAULT;
206
207 err = drm_ioctl(file->f_dentry->d_inode, file,
208 DRM_IOCTL_GET_MAP, (unsigned long) map);
209 if (err)
210 return err;
211
212 if (__get_user(m32.offset, &map->offset)
213 || __get_user(m32.size, &map->size)
214 || __get_user(m32.type, &map->type)
215 || __get_user(m32.flags, &map->flags)
216 || __get_user(handle, &map->handle)
217 || __get_user(m32.mtrr, &map->mtrr))
218 return -EFAULT;
219
220 m32.handle = (unsigned long) handle;
221 if (copy_to_user(argp, &m32, sizeof(m32)))
222 return -EFAULT;
223 return 0;
224
225}
226
227static int compat_drm_addmap(struct file *file, unsigned int cmd,
228 unsigned long arg)
229{
230 drm_map32_t __user *argp = (void __user *)arg;
231 drm_map32_t m32;
232 drm_map_t __user *map;
233 int err;
234 void *handle;
235
236 if (copy_from_user(&m32, argp, sizeof(m32)))
237 return -EFAULT;
238
239 map = compat_alloc_user_space(sizeof(*map));
240 if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
241 return -EFAULT;
242 if (__put_user(m32.offset, &map->offset)
243 || __put_user(m32.size, &map->size)
244 || __put_user(m32.type, &map->type)
245 || __put_user(m32.flags, &map->flags))
246 return -EFAULT;
247
248 err = drm_ioctl(file->f_dentry->d_inode, file,
249 DRM_IOCTL_ADD_MAP, (unsigned long) map);
250 if (err)
251 return err;
252
253 if (__get_user(m32.offset, &map->offset)
254 || __get_user(m32.mtrr, &map->mtrr)
255 || __get_user(handle, &map->handle))
256 return -EFAULT;
257
258 m32.handle = (unsigned long) handle;
259 if (m32.handle != (unsigned long) handle && printk_ratelimit())
260 printk(KERN_ERR "compat_drm_addmap truncated handle"
261 " %p for type %d offset %x\n",
262 handle, m32.type, m32.offset);
263
264 if (copy_to_user(argp, &m32, sizeof(m32)))
265 return -EFAULT;
266
267 return 0;
268}
269
270static int compat_drm_rmmap(struct file *file, unsigned int cmd,
271 unsigned long arg)
272{
273 drm_map32_t __user *argp = (void __user *)arg;
274 drm_map_t __user *map;
275 u32 handle;
276
277 if (get_user(handle, &argp->handle))
278 return -EFAULT;
279
280 map = compat_alloc_user_space(sizeof(*map));
281 if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
282 return -EFAULT;
283 if (__put_user((void *)(unsigned long) handle, &map->handle))
284 return -EFAULT;
285
286 return drm_ioctl(file->f_dentry->d_inode, file,
287 DRM_IOCTL_RM_MAP, (unsigned long) map);
288}
289
290typedef struct drm_client32 {
291 int idx; /**< Which client desired? */
292 int auth; /**< Is client authenticated? */
293 u32 pid; /**< Process ID */
294 u32 uid; /**< User ID */
295 u32 magic; /**< Magic */
296 u32 iocs; /**< Ioctl count */
297} drm_client32_t;
298
299static int compat_drm_getclient(struct file *file, unsigned int cmd,
300 unsigned long arg)
301{
302 drm_client32_t c32;
303 drm_client32_t __user *argp = (void __user *)arg;
304 drm_client_t __user *client;
305 int idx, err;
306
307 if (get_user(idx, &argp->idx))
308 return -EFAULT;
309
310 client = compat_alloc_user_space(sizeof(*client));
311 if (!access_ok(VERIFY_WRITE, client, sizeof(*client)))
312 return -EFAULT;
313 if (__put_user(idx, &client->idx))
314 return -EFAULT;
315
316 err = drm_ioctl(file->f_dentry->d_inode, file,
317 DRM_IOCTL_GET_CLIENT, (unsigned long) client);
318 if (err)
319 return err;
320
321 if (__get_user(c32.auth, &client->auth)
322 || __get_user(c32.pid, &client->pid)
323 || __get_user(c32.uid, &client->uid)
324 || __get_user(c32.magic, &client->magic)
325 || __get_user(c32.iocs, &client->iocs))
326 return -EFAULT;
327
328 if (copy_to_user(argp, &c32, sizeof(c32)))
329 return -EFAULT;
330 return 0;
331}
332
333typedef struct drm_stats32 {
334 u32 count;
335 struct {
336 u32 value;
337 drm_stat_type_t type;
338 } data[15];
339} drm_stats32_t;
340
341static int compat_drm_getstats(struct file *file, unsigned int cmd,
342 unsigned long arg)
343{
344 drm_stats32_t s32;
345 drm_stats32_t __user *argp = (void __user *)arg;
346 drm_stats_t __user *stats;
347 int i, err;
348
349 stats = compat_alloc_user_space(sizeof(*stats));
350 if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
351 return -EFAULT;
352
353 err = drm_ioctl(file->f_dentry->d_inode, file,
354 DRM_IOCTL_GET_STATS, (unsigned long) stats);
355 if (err)
356 return err;
357
358 if (__get_user(s32.count, &stats->count))
359 return -EFAULT;
360 for (i = 0; i < 15; ++i)
361 if (__get_user(s32.data[i].value, &stats->data[i].value)
362 || __get_user(s32.data[i].type, &stats->data[i].type))
363 return -EFAULT;
364
365 if (copy_to_user(argp, &s32, sizeof(s32)))
366 return -EFAULT;
367 return 0;
368}
369
370typedef struct drm_buf_desc32 {
371 int count; /**< Number of buffers of this size */
372 int size; /**< Size in bytes */
373 int low_mark; /**< Low water mark */
374 int high_mark; /**< High water mark */
375 int flags;
376 u32 agp_start; /**< Start address in the AGP aperture */
377} drm_buf_desc32_t;
378
379static int compat_drm_addbufs(struct file *file, unsigned int cmd,
380 unsigned long arg)
381{
382 drm_buf_desc32_t __user *argp = (void __user *)arg;
383 drm_buf_desc_t __user *buf;
384 int err;
385 unsigned long agp_start;
386
387 buf = compat_alloc_user_space(sizeof(*buf));
388 if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf))
389 || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)))
390 return -EFAULT;
391
392 if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start))
393 || __get_user(agp_start, &argp->agp_start)
394 || __put_user(agp_start, &buf->agp_start))
395 return -EFAULT;
396
397 err = drm_ioctl(file->f_dentry->d_inode, file,
398 DRM_IOCTL_ADD_BUFS, (unsigned long) buf);
399 if (err)
400 return err;
401
402 if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start))
403 || __get_user(agp_start, &buf->agp_start)
404 || __put_user(agp_start, &argp->agp_start))
405 return -EFAULT;
406
407 return 0;
408}
409
410static int compat_drm_markbufs(struct file *file, unsigned int cmd,
411 unsigned long arg)
412{
413 drm_buf_desc32_t b32;
414 drm_buf_desc32_t __user *argp = (void __user *)arg;
415 drm_buf_desc_t __user *buf;
416
417 if (copy_from_user(&b32, argp, sizeof(b32)))
418 return -EFAULT;
419
420 buf = compat_alloc_user_space(sizeof(*buf));
421 if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))
422 return -EFAULT;
423
424 if (__put_user(b32.size, &buf->size)
425 || __put_user(b32.low_mark, &buf->low_mark)
426 || __put_user(b32.high_mark, &buf->high_mark))
427 return -EFAULT;
428
429 return drm_ioctl(file->f_dentry->d_inode, file,
430 DRM_IOCTL_MARK_BUFS, (unsigned long) buf);
431}
432
433typedef struct drm_buf_info32 {
434 int count; /**< Entries in list */
435 u32 list;
436} drm_buf_info32_t;
437
438static int compat_drm_infobufs(struct file *file, unsigned int cmd,
439 unsigned long arg)
440{
441 drm_buf_info32_t req32;
442 drm_buf_info32_t __user *argp = (void __user *)arg;
443 drm_buf_desc32_t __user *to;
444 drm_buf_info_t __user *request;
445 drm_buf_desc_t __user *list;
446 size_t nbytes;
447 int i, err;
448 int count, actual;
449
450 if (copy_from_user(&req32, argp, sizeof(req32)))
451 return -EFAULT;
452
453 count = req32.count;
454 to = (drm_buf_desc32_t __user *)(unsigned long) req32.list;
455 if (count < 0)
456 count = 0;
457 if (count > 0
458 && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t)))
459 return -EFAULT;
460
461 nbytes = sizeof(*request) + count * sizeof(drm_buf_desc_t);
462 request = compat_alloc_user_space(nbytes);
463 if (!access_ok(VERIFY_WRITE, request, nbytes))
464 return -EFAULT;
465 list = (drm_buf_desc_t *) (request + 1);
466
467 if (__put_user(count, &request->count)
468 || __put_user(list, &request->list))
469 return -EFAULT;
470
471 err = drm_ioctl(file->f_dentry->d_inode, file,
472 DRM_IOCTL_INFO_BUFS, (unsigned long) request);
473 if (err)
474 return err;
475
476 if (__get_user(actual, &request->count))
477 return -EFAULT;
478 if (count >= actual)
479 for (i = 0; i < actual; ++i)
480 if (__copy_in_user(&to[i], &list[i],
481 offsetof(drm_buf_desc_t, flags)))
482 return -EFAULT;
483
484 if (__put_user(actual, &argp->count))
485 return -EFAULT;
486
487 return 0;
488}
489
490typedef struct drm_buf_pub32 {
491 int idx; /**< Index into the master buffer list */
492 int total; /**< Buffer size */
493 int used; /**< Amount of buffer in use (for DMA) */
494 u32 address; /**< Address of buffer */
495} drm_buf_pub32_t;
496
497typedef struct drm_buf_map32 {
498 int count; /**< Length of the buffer list */
499 u32 virtual; /**< Mmap'd area in user-virtual */
500 u32 list; /**< Buffer information */
501} drm_buf_map32_t;
502
503static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
504 unsigned long arg)
505{
506 drm_buf_map32_t __user *argp = (void __user *)arg;
507 drm_buf_map32_t req32;
508 drm_buf_pub32_t __user *list32;
509 drm_buf_map_t __user *request;
510 drm_buf_pub_t __user *list;
511 int i, err;
512 int count, actual;
513 size_t nbytes;
514 void __user *addr;
515
516 if (copy_from_user(&req32, argp, sizeof(req32)))
517 return -EFAULT;
518 count = req32.count;
519 list32 = (void __user *)(unsigned long)req32.list;
520
521 if (count < 0)
522 return -EINVAL;
523 nbytes = sizeof(*request) + count * sizeof(drm_buf_pub_t);
524 request = compat_alloc_user_space(nbytes);
525 if (!access_ok(VERIFY_WRITE, request, nbytes))
526 return -EFAULT;
527 list = (drm_buf_pub_t *) (request + 1);
528
529 if (__put_user(count, &request->count)
530 || __put_user(list, &request->list))
531 return -EFAULT;
532
533 err = drm_ioctl(file->f_dentry->d_inode, file,
534 DRM_IOCTL_MAP_BUFS, (unsigned long) request);
535 if (err)
536 return err;
537
538 if (__get_user(actual, &request->count))
539 return -EFAULT;
540 if (count >= actual)
541 for (i = 0; i < actual; ++i)
542 if (__copy_in_user(&list32[i], &list[i],
543 offsetof(drm_buf_pub_t, address))
544 || __get_user(addr, &list[i].address)
545 || __put_user((unsigned long) addr,
546 &list32[i].address))
547 return -EFAULT;
548
549 if (__put_user(actual, &argp->count)
550 || __get_user(addr, &request->virtual)
551 || __put_user((unsigned long) addr, &argp->virtual))
552 return -EFAULT;
553
554 return 0;
555}
556
557typedef struct drm_buf_free32 {
558 int count;
559 u32 list;
560} drm_buf_free32_t;
561
562static int compat_drm_freebufs(struct file *file, unsigned int cmd,
563 unsigned long arg)
564{
565 drm_buf_free32_t req32;
566 drm_buf_free_t __user *request;
567 drm_buf_free32_t __user *argp = (void __user *)arg;
568
569 if (copy_from_user(&req32, argp, sizeof(req32)))
570 return -EFAULT;
571
572 request = compat_alloc_user_space(sizeof(*request));
573 if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
574 return -EFAULT;
575 if (__put_user(req32.count, &request->count)
576 || __put_user((int __user *)(unsigned long) req32.list,
577 &request->list))
578 return -EFAULT;
579
580 return drm_ioctl(file->f_dentry->d_inode, file,
581 DRM_IOCTL_FREE_BUFS, (unsigned long) request);
582}
583
584typedef struct drm_ctx_priv_map32 {
585 unsigned int ctx_id; /**< Context requesting private mapping */
586 u32 handle; /**< Handle of map */
587} drm_ctx_priv_map32_t;
588
589static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
590 unsigned long arg)
591{
592 drm_ctx_priv_map32_t req32;
593 drm_ctx_priv_map_t __user *request;
594 drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
595
596 if (copy_from_user(&req32, argp, sizeof(req32)))
597 return -EFAULT;
598
599 request = compat_alloc_user_space(sizeof(*request));
600 if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
601 return -EFAULT;
602 if (__put_user(req32.ctx_id, &request->ctx_id)
603 || __put_user((void *)(unsigned long) req32.handle,
604 &request->handle))
605 return -EFAULT;
606
607 return drm_ioctl(file->f_dentry->d_inode, file,
608 DRM_IOCTL_SET_SAREA_CTX, (unsigned long) request);
609}
610
611static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
612 unsigned long arg)
613{
614 drm_ctx_priv_map_t __user *request;
615 drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
616 int err;
617 unsigned int ctx_id;
618 void *handle;
619
620 if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp))
621 || __get_user(ctx_id, &argp->ctx_id))
622 return -EFAULT;
623
624 request = compat_alloc_user_space(sizeof(*request));
625 if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
626 return -EFAULT;
627 if (__put_user(ctx_id, &request->ctx_id))
628 return -EFAULT;
629
630 err = drm_ioctl(file->f_dentry->d_inode, file,
631 DRM_IOCTL_GET_SAREA_CTX, (unsigned long) request);
632 if (err)
633 return err;
634
635 if (__get_user(handle, &request->handle)
636 || __put_user((unsigned long) handle, &argp->handle))
637 return -EFAULT;
638
639 return 0;
640}
641
642typedef struct drm_ctx_res32 {
643 int count;
644 u32 contexts;
645} drm_ctx_res32_t;
646
647static int compat_drm_resctx(struct file *file, unsigned int cmd,
648 unsigned long arg)
649{
650 drm_ctx_res32_t __user *argp = (void __user *)arg;
651 drm_ctx_res32_t res32;
652 drm_ctx_res_t __user *res;
653 int err;
654
655 if (copy_from_user(&res32, argp, sizeof(res32)))
656 return -EFAULT;
657
658 res = compat_alloc_user_space(sizeof(*res));
659 if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
660 return -EFAULT;
661 if (__put_user(res32.count, &res->count)
662 || __put_user((drm_ctx_t __user *)(unsigned long) res32.contexts,
663 &res->contexts))
664 return -EFAULT;
665
666 err = drm_ioctl(file->f_dentry->d_inode, file,
667 DRM_IOCTL_RES_CTX, (unsigned long) res);
668 if (err)
669 return err;
670
671 if (__get_user(res32.count, &res->count)
672 || __put_user(res32.count, &argp->count))
673 return -EFAULT;
674
675 return 0;
676}
677
678typedef struct drm_dma32 {
679 int context; /**< Context handle */
680 int send_count; /**< Number of buffers to send */
681 u32 send_indices; /**< List of handles to buffers */
682 u32 send_sizes; /**< Lengths of data to send */
683 drm_dma_flags_t flags; /**< Flags */
684 int request_count; /**< Number of buffers requested */
685 int request_size; /**< Desired size for buffers */
686 u32 request_indices; /**< Buffer information */
687 u32 request_sizes;
688 int granted_count; /**< Number of buffers granted */
689} drm_dma32_t;
690
691static int compat_drm_dma(struct file *file, unsigned int cmd,
692 unsigned long arg)
693{
694 drm_dma32_t d32;
695 drm_dma32_t __user *argp = (void __user *) arg;
696 drm_dma_t __user *d;
697 int err;
698
699 if (copy_from_user(&d32, argp, sizeof(d32)))
700 return -EFAULT;
701
702 d = compat_alloc_user_space(sizeof(*d));
703 if (!access_ok(VERIFY_WRITE, d, sizeof(*d)))
704 return -EFAULT;
705
706 if (__put_user(d32.context, &d->context)
707 || __put_user(d32.send_count, &d->send_count)
708 || __put_user((int __user *)(unsigned long) d32.send_indices,
709 &d->send_indices)
710 || __put_user((int __user *)(unsigned long) d32.send_sizes,
711 &d->send_sizes)
712 || __put_user(d32.flags, &d->flags)
713 || __put_user(d32.request_count, &d->request_count)
714 || __put_user((int __user *)(unsigned long) d32.request_indices,
715 &d->request_indices)
716 || __put_user((int __user *)(unsigned long) d32.request_sizes,
717 &d->request_sizes))
718 return -EFAULT;
719
720 err = drm_ioctl(file->f_dentry->d_inode, file,
721 DRM_IOCTL_DMA, (unsigned long) d);
722 if (err)
723 return err;
724
725 if (__get_user(d32.request_size, &d->request_size)
726 || __get_user(d32.granted_count, &d->granted_count)
727 || __put_user(d32.request_size, &argp->request_size)
728 || __put_user(d32.granted_count, &argp->granted_count))
729 return -EFAULT;
730
731 return 0;
732}
733
734#if __OS_HAS_AGP
735typedef struct drm_agp_mode32 {
736 u32 mode; /**< AGP mode */
737} drm_agp_mode32_t;
738
739static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
740 unsigned long arg)
741{
742 drm_agp_mode32_t __user *argp = (void __user *)arg;
743 drm_agp_mode32_t m32;
744 drm_agp_mode_t __user *mode;
745
746 if (get_user(m32.mode, &argp->mode))
747 return -EFAULT;
748
749 mode = compat_alloc_user_space(sizeof(*mode));
750 if (put_user(m32.mode, &mode->mode))
751 return -EFAULT;
752
753 return drm_ioctl(file->f_dentry->d_inode, file,
754 DRM_IOCTL_AGP_ENABLE, (unsigned long) mode);
755}
756
757typedef struct drm_agp_info32 {
758 int agp_version_major;
759 int agp_version_minor;
760 u32 mode;
761 u32 aperture_base; /* physical address */
762 u32 aperture_size; /* bytes */
763 u32 memory_allowed; /* bytes */
764 u32 memory_used;
765
766 /* PCI information */
767 unsigned short id_vendor;
768 unsigned short id_device;
769} drm_agp_info32_t;
770
771static int compat_drm_agp_info(struct file *file, unsigned int cmd,
772 unsigned long arg)
773{
774 drm_agp_info32_t __user *argp = (void __user *)arg;
775 drm_agp_info32_t i32;
776 drm_agp_info_t __user *info;
777 int err;
778
779 info = compat_alloc_user_space(sizeof(*info));
780 if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
781 return -EFAULT;
782
783 err = drm_ioctl(file->f_dentry->d_inode, file,
784 DRM_IOCTL_AGP_INFO, (unsigned long) info);
785 if (err)
786 return err;
787
788 if (__get_user(i32.agp_version_major, &info->agp_version_major)
789 || __get_user(i32.agp_version_minor, &info->agp_version_minor)
790 || __get_user(i32.mode, &info->mode)
791 || __get_user(i32.aperture_base, &info->aperture_base)
792 || __get_user(i32.aperture_size, &info->aperture_size)
793 || __get_user(i32.memory_allowed, &info->memory_allowed)
794 || __get_user(i32.memory_used, &info->memory_used)
795 || __get_user(i32.id_vendor, &info->id_vendor)
796 || __get_user(i32.id_device, &info->id_device))
797 return -EFAULT;
798
799 if (copy_to_user(argp, &i32, sizeof(i32)))
800 return -EFAULT;
801
802 return 0;
803}
804
805typedef struct drm_agp_buffer32 {
806 u32 size; /**< In bytes -- will round to page boundary */
807 u32 handle; /**< Used for binding / unbinding */
808 u32 type; /**< Type of memory to allocate */
809 u32 physical; /**< Physical used by i810 */
810} drm_agp_buffer32_t;
811
812static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
813 unsigned long arg)
814{
815 drm_agp_buffer32_t __user *argp = (void __user *)arg;
816 drm_agp_buffer32_t req32;
817 drm_agp_buffer_t __user *request;
818 int err;
819
820 if (copy_from_user(&req32, argp, sizeof(req32)))
821 return -EFAULT;
822
823 request = compat_alloc_user_space(sizeof(*request));
824 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
825 || __put_user(req32.size, &request->size)
826 || __put_user(req32.type, &request->type))
827 return -EFAULT;
828
829 err = drm_ioctl(file->f_dentry->d_inode, file,
830 DRM_IOCTL_AGP_ALLOC, (unsigned long) request);
831 if (err)
832 return err;
833
834 if (__get_user(req32.handle, &request->handle)
835 || __get_user(req32.physical, &request->physical)
836 || copy_to_user(argp, &req32, sizeof(req32))) {
837 drm_ioctl(file->f_dentry->d_inode, file,
838 DRM_IOCTL_AGP_FREE, (unsigned long) request);
839 return -EFAULT;
840 }
841
842 return 0;
843}
844
845static int compat_drm_agp_free(struct file *file, unsigned int cmd,
846 unsigned long arg)
847{
848 drm_agp_buffer32_t __user *argp = (void __user *)arg;
849 drm_agp_buffer_t __user *request;
850 u32 handle;
851
852 request = compat_alloc_user_space(sizeof(*request));
853 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
854 || get_user(handle, &argp->handle)
855 || __put_user(handle, &request->handle))
856 return -EFAULT;
857
858 return drm_ioctl(file->f_dentry->d_inode, file,
859 DRM_IOCTL_AGP_FREE, (unsigned long) request);
860}
861
862typedef struct drm_agp_binding32 {
863 u32 handle; /**< From drm_agp_buffer */
864 u32 offset; /**< In bytes -- will round to page boundary */
865} drm_agp_binding32_t;
866
867static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
868 unsigned long arg)
869{
870 drm_agp_binding32_t __user *argp = (void __user *)arg;
871 drm_agp_binding32_t req32;
872 drm_agp_binding_t __user *request;
873
874 if (copy_from_user(&req32, argp, sizeof(req32)))
875 return -EFAULT;
876
877 request = compat_alloc_user_space(sizeof(*request));
878 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
879 || __put_user(req32.handle, &request->handle)
880 || __put_user(req32.offset, &request->offset))
881 return -EFAULT;
882
883 return drm_ioctl(file->f_dentry->d_inode, file,
884 DRM_IOCTL_AGP_BIND, (unsigned long) request);
885}
886
887static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
888 unsigned long arg)
889{
890 drm_agp_binding32_t __user *argp = (void __user *)arg;
891 drm_agp_binding_t __user *request;
892 u32 handle;
893
894 request = compat_alloc_user_space(sizeof(*request));
895 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
896 || get_user(handle, &argp->handle)
897 || __put_user(handle, &request->handle))
898 return -EFAULT;
899
900 return drm_ioctl(file->f_dentry->d_inode, file,
901 DRM_IOCTL_AGP_UNBIND, (unsigned long) request);
902}
903#endif /* __OS_HAS_AGP */
904
905typedef struct drm_scatter_gather32 {
906 u32 size; /**< In bytes -- will round to page boundary */
907 u32 handle; /**< Used for mapping / unmapping */
908} drm_scatter_gather32_t;
909
910static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
911 unsigned long arg)
912{
913 drm_scatter_gather32_t __user *argp = (void __user *)arg;
914 drm_scatter_gather_t __user *request;
915 int err;
916 unsigned long x;
917
918 request = compat_alloc_user_space(sizeof(*request));
919 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
920 || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
921 || __get_user(x, &argp->size)
922 || __put_user(x, &request->size))
923 return -EFAULT;
924
925 err = drm_ioctl(file->f_dentry->d_inode, file,
926 DRM_IOCTL_SG_ALLOC, (unsigned long) request);
927 if (err)
928 return err;
929
930 /* XXX not sure about the handle conversion here... */
931 if (__get_user(x, &request->handle)
932 || __put_user(x >> PAGE_SHIFT, &argp->handle))
933 return -EFAULT;
934
935 return 0;
936}
937
938static int compat_drm_sg_free(struct file *file, unsigned int cmd,
939 unsigned long arg)
940{
941 drm_scatter_gather32_t __user *argp = (void __user *)arg;
942 drm_scatter_gather_t __user *request;
943 unsigned long x;
944
945 request = compat_alloc_user_space(sizeof(*request));
946 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
947 || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
948 || __get_user(x, &argp->handle)
949 || __put_user(x << PAGE_SHIFT, &request->handle))
950 return -EFAULT;
951
952 return drm_ioctl(file->f_dentry->d_inode, file,
953 DRM_IOCTL_SG_FREE, (unsigned long) request);
954}
955
956struct drm_wait_vblank_request32 {
957 drm_vblank_seq_type_t type;
958 unsigned int sequence;
959 u32 signal;
960};
961
962struct drm_wait_vblank_reply32 {
963 drm_vblank_seq_type_t type;
964 unsigned int sequence;
965 s32 tval_sec;
966 s32 tval_usec;
967};
968
969typedef union drm_wait_vblank32 {
970 struct drm_wait_vblank_request32 request;
971 struct drm_wait_vblank_reply32 reply;
972} drm_wait_vblank32_t;
973
974static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
975 unsigned long arg)
976{
977 drm_wait_vblank32_t __user *argp = (void __user *)arg;
978 drm_wait_vblank32_t req32;
979 drm_wait_vblank_t __user *request;
980 int err;
981
982 if (copy_from_user(&req32, argp, sizeof(req32)))
983 return -EFAULT;
984
985 request = compat_alloc_user_space(sizeof(*request));
986 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
987 || __put_user(req32.request.type, &request->request.type)
988 || __put_user(req32.request.sequence, &request->request.sequence)
989 || __put_user(req32.request.signal, &request->request.signal))
990 return -EFAULT;
991
992 err = drm_ioctl(file->f_dentry->d_inode, file,
993 DRM_IOCTL_WAIT_VBLANK, (unsigned long) request);
994 if (err)
995 return err;
996
997 if (__get_user(req32.reply.type, &request->reply.type)
998 || __get_user(req32.reply.sequence, &request->reply.sequence)
999 || __get_user(req32.reply.tval_sec, &request->reply.tval_sec)
1000 || __get_user(req32.reply.tval_usec, &request->reply.tval_usec))
1001 return -EFAULT;
1002
1003 if (copy_to_user(argp, &req32, sizeof(req32)))
1004 return -EFAULT;
1005
1006 return 0;
1007}
1008
1009drm_ioctl_compat_t *drm_compat_ioctls[] = {
1010 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
1011 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
1012 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
1013 [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient,
1014 [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats,
1015 [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique,
1016 [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap,
1017 [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs,
1018 [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs,
1019 [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs,
1020 [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs,
1021 [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs,
1022 [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap,
1023 [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx,
1024 [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx,
1025 [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx,
1026 [DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma,
1027#if __OS_HAS_AGP
1028 [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable,
1029 [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info,
1030 [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc,
1031 [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free,
1032 [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind,
1033 [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind,
1034#endif
1035 [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
1036 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
1037 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
1038};
1039
1040/**
1041 * Called whenever a 32-bit process running under a 64-bit kernel
1042 * performs an ioctl on /dev/drm.
1043 *
1044 * \param filp file pointer.
1045 * \param cmd command.
1046 * \param arg user argument.
1047 * \return zero on success or negative number on failure.
1048 */
1049long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1050{
1051 unsigned int nr = DRM_IOCTL_NR(cmd);
1052 drm_ioctl_compat_t *fn;
1053 int ret;
1054
1055 if (nr >= DRM_ARRAY_SIZE(drm_compat_ioctls))
1056 return -ENOTTY;
1057
1058 fn = drm_compat_ioctls[nr];
1059
1060 lock_kernel(); /* XXX for now */
1061 if (fn != NULL)
1062 ret = (*fn)(filp, cmd, arg);
1063 else
1064 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
1065 unlock_kernel();
1066
1067 return ret;
1068}
1069EXPORT_SYMBOL(drm_compat_ioctl);
diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c
index 2e236ebcf27b..cdd4aecd25e2 100644
--- a/drivers/char/drm/drm_irq.c
+++ b/drivers/char/drm/drm_irq.c
@@ -89,7 +89,7 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp,
89 * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions 89 * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
90 * before and after the installation. 90 * before and after the installation.
91 */ 91 */
92int drm_irq_install( drm_device_t *dev ) 92static int drm_irq_install( drm_device_t *dev )
93{ 93{
94 int ret; 94 int ret;
95 unsigned long sh_flags=0; 95 unsigned long sh_flags=0;
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index d0d6fc661625..4702d863bcc6 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -35,6 +35,11 @@
35 35
36#include "drmP.h" 36#include "drmP.h"
37 37
38static int drm_lock_transfer(drm_device_t *dev,
39 __volatile__ unsigned int *lock,
40 unsigned int context);
41static int drm_notifier(void *priv);
42
38/** 43/**
39 * Lock ioctl. 44 * Lock ioctl.
40 * 45 *
@@ -225,8 +230,9 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
225 * Resets the lock file pointer. 230 * Resets the lock file pointer.
226 * Marks the lock as held by the given context, via the \p cmpxchg instruction. 231 * Marks the lock as held by the given context, via the \p cmpxchg instruction.
227 */ 232 */
228int drm_lock_transfer(drm_device_t *dev, 233static int drm_lock_transfer(drm_device_t *dev,
229 __volatile__ unsigned int *lock, unsigned int context) 234 __volatile__ unsigned int *lock,
235 unsigned int context)
230{ 236{
231 unsigned int old, new, prev; 237 unsigned int old, new, prev;
232 238
@@ -282,7 +288,7 @@ int drm_lock_free(drm_device_t *dev,
282 * \return one if the signal should be delivered normally, or zero if the 288 * \return one if the signal should be delivered normally, or zero if the
283 * signal should be blocked. 289 * signal should be blocked.
284 */ 290 */
285int drm_notifier(void *priv) 291static int drm_notifier(void *priv)
286{ 292{
287 drm_sigdata_t *s = (drm_sigdata_t *)priv; 293 drm_sigdata_t *s = (drm_sigdata_t *)priv;
288 unsigned int old, new, prev; 294 unsigned int old, new, prev;
diff --git a/drivers/char/drm/drm_memory.c b/drivers/char/drm/drm_memory.c
index 7f53f756c052..ace3d42f4407 100644
--- a/drivers/char/drm/drm_memory.c
+++ b/drivers/char/drm/drm_memory.c
@@ -65,19 +65,6 @@ int drm_mem_info(char *buf, char **start, off_t offset,
65 return 0; 65 return 0;
66} 66}
67 67
68/** Wrapper around kmalloc() */
69void *drm_calloc(size_t nmemb, size_t size, int area)
70{
71 void *addr;
72
73 addr = kmalloc(size * nmemb, GFP_KERNEL);
74 if (addr != NULL)
75 memset((void *)addr, 0, size * nmemb);
76
77 return addr;
78}
79EXPORT_SYMBOL(drm_calloc);
80
81/** Wrapper around kmalloc() and kfree() */ 68/** Wrapper around kmalloc() and kfree() */
82void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area) 69void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
83{ 70{
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index 11c6950158b3..70ca4fa55c9d 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -223,3 +223,10 @@
223 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 223 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
224 {0, 0, 0} 224 {0, 0, 0}
225 225
226#define viadrv_PCI_IDS \
227 {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
228 {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
229 {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
230 {0x1106, 0x7204, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
231 {0, 0, 0}
232
diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
index 6e06e8c6a516..4774087d2e9e 100644
--- a/drivers/char/drm/drm_proc.c
+++ b/drivers/char/drm/drm_proc.c
@@ -57,7 +57,7 @@ static int drm_vma_info(char *buf, char **start, off_t offset,
57/** 57/**
58 * Proc file list. 58 * Proc file list.
59 */ 59 */
60struct drm_proc_list { 60static struct drm_proc_list {
61 const char *name; /**< file name */ 61 const char *name; /**< file name */
62 int (*f)(char *, char **, off_t, int, int *, void *); /**< proc callback*/ 62 int (*f)(char *, char **, off_t, int, int *, void *); /**< proc callback*/
63} drm_proc_list[] = { 63} drm_proc_list[] = {
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 8ccbdef7bb3e..48829a1a086a 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -157,52 +157,6 @@ int drm_stub_open(struct inode *inode, struct file *filp)
157 return err; 157 return err;
158} 158}
159 159
160
161/**
162 * Register.
163 *
164 * \param pdev - PCI device structure
165 * \param ent entry from the PCI ID table with device type flags
166 * \return zero on success or a negative number on failure.
167 *
168 * Attempt to gets inter module "drm" information. If we are first
169 * then register the character device and inter module information.
170 * Try and register, if we fail to register, backout previous work.
171 */
172int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
173 struct drm_driver *driver)
174{
175 drm_device_t *dev;
176 int ret;
177
178 DRM_DEBUG("\n");
179
180 dev = drm_calloc(1, sizeof(*dev), DRM_MEM_STUB);
181 if (!dev)
182 return -ENOMEM;
183
184 pci_enable_device(pdev);
185
186 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
187 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
188 goto err_g1;
189 }
190 if ((ret = drm_get_head(dev, &dev->primary)))
191 goto err_g1;
192
193 /* postinit is a required function to display the signon banner */
194 /* drivers add secondary heads here if needed */
195 if ((ret = dev->driver->postinit(dev, ent->driver_data)))
196 goto err_g1;
197
198 return 0;
199
200err_g1:
201 drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
202 return ret;
203}
204EXPORT_SYMBOL(drm_get_dev);
205
206/** 160/**
207 * Get a secondary minor number. 161 * Get a secondary minor number.
208 * 162 *
@@ -214,7 +168,7 @@ EXPORT_SYMBOL(drm_get_dev);
214 * create the proc init entry via proc_init(). This routines assigns 168 * create the proc init entry via proc_init(). This routines assigns
215 * minor numbers to secondary heads of multi-headed cards 169 * minor numbers to secondary heads of multi-headed cards
216 */ 170 */
217int drm_get_head(drm_device_t *dev, drm_head_t *head) 171static int drm_get_head(drm_device_t *dev, drm_head_t *head)
218{ 172{
219 drm_head_t **heads = drm_heads; 173 drm_head_t **heads = drm_heads;
220 int ret; 174 int ret;
@@ -262,6 +216,50 @@ err_g1:
262 return ret; 216 return ret;
263} 217}
264 218
219/**
220 * Register.
221 *
222 * \param pdev - PCI device structure
223 * \param ent entry from the PCI ID table with device type flags
224 * \return zero on success or a negative number on failure.
225 *
226 * Attempt to gets inter module "drm" information. If we are first
227 * then register the character device and inter module information.
228 * Try and register, if we fail to register, backout previous work.
229 */
230int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
231 struct drm_driver *driver)
232{
233 drm_device_t *dev;
234 int ret;
235
236 DRM_DEBUG("\n");
237
238 dev = drm_calloc(1, sizeof(*dev), DRM_MEM_STUB);
239 if (!dev)
240 return -ENOMEM;
241
242 pci_enable_device(pdev);
243
244 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
245 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
246 goto err_g1;
247 }
248 if ((ret = drm_get_head(dev, &dev->primary)))
249 goto err_g1;
250
251 /* postinit is a required function to display the signon banner */
252 /* drivers add secondary heads here if needed */
253 if ((ret = dev->driver->postinit(dev, ent->driver_data)))
254 goto err_g1;
255
256 return 0;
257
258err_g1:
259 drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
260 return ret;
261}
262EXPORT_SYMBOL(drm_get_dev);
265 263
266/** 264/**
267 * Put a device minor number. 265 * Put a device minor number.
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index fc72f30f312b..621220f3f372 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -38,6 +38,8 @@
38#include <linux/efi.h> 38#include <linux/efi.h>
39#endif 39#endif
40 40
41static void drm_vm_open(struct vm_area_struct *vma);
42static void drm_vm_close(struct vm_area_struct *vma);
41 43
42/** 44/**
43 * \c nopage method for AGP virtual memory. 45 * \c nopage method for AGP virtual memory.
@@ -163,7 +165,7 @@ static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
163 * Deletes map information if we are the last 165 * Deletes map information if we are the last
164 * person to close a mapping and it's not in the global maplist. 166 * person to close a mapping and it's not in the global maplist.
165 */ 167 */
166void drm_vm_shm_close(struct vm_area_struct *vma) 168static void drm_vm_shm_close(struct vm_area_struct *vma)
167{ 169{
168 drm_file_t *priv = vma->vm_file->private_data; 170 drm_file_t *priv = vma->vm_file->private_data;
169 drm_device_t *dev = priv->head->dev; 171 drm_device_t *dev = priv->head->dev;
@@ -399,7 +401,7 @@ static struct vm_operations_struct drm_vm_sg_ops = {
399 * Create a new drm_vma_entry structure as the \p vma private data entry and 401 * Create a new drm_vma_entry structure as the \p vma private data entry and
400 * add it to drm_device::vmalist. 402 * add it to drm_device::vmalist.
401 */ 403 */
402void drm_vm_open(struct vm_area_struct *vma) 404static void drm_vm_open(struct vm_area_struct *vma)
403{ 405{
404 drm_file_t *priv = vma->vm_file->private_data; 406 drm_file_t *priv = vma->vm_file->private_data;
405 drm_device_t *dev = priv->head->dev; 407 drm_device_t *dev = priv->head->dev;
@@ -428,7 +430,7 @@ void drm_vm_open(struct vm_area_struct *vma)
428 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and 430 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
429 * free it. 431 * free it.
430 */ 432 */
431void drm_vm_close(struct vm_area_struct *vma) 433static void drm_vm_close(struct vm_area_struct *vma)
432{ 434{
433 drm_file_t *priv = vma->vm_file->private_data; 435 drm_file_t *priv = vma->vm_file->private_data;
434 drm_device_t *dev = priv->head->dev; 436 drm_device_t *dev = priv->head->dev;
@@ -463,7 +465,7 @@ void drm_vm_close(struct vm_area_struct *vma)
463 * Sets the virtual memory area operations structure to vm_dma_ops, the file 465 * Sets the virtual memory area operations structure to vm_dma_ops, the file
464 * pointer, and calls vm_open(). 466 * pointer, and calls vm_open().
465 */ 467 */
466int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma) 468static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
467{ 469{
468 drm_file_t *priv = filp->private_data; 470 drm_file_t *priv = filp->private_data;
469 drm_device_t *dev; 471 drm_device_t *dev;
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
index 24857cc6c23b..18e0b7622893 100644
--- a/drivers/char/drm/i810_dma.c
+++ b/drivers/char/drm/i810_dma.c
@@ -90,16 +90,7 @@ static int i810_freelist_put(drm_device_t *dev, drm_buf_t *buf)
90 return 0; 90 return 0;
91} 91}
92 92
93static struct file_operations i810_buffer_fops = { 93static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
94 .open = drm_open,
95 .flush = drm_flush,
96 .release = drm_release,
97 .ioctl = drm_ioctl,
98 .mmap = i810_mmap_buffers,
99 .fasync = drm_fasync,
100};
101
102int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
103{ 94{
104 drm_file_t *priv = filp->private_data; 95 drm_file_t *priv = filp->private_data;
105 drm_device_t *dev; 96 drm_device_t *dev;
@@ -126,6 +117,15 @@ int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
126 return 0; 117 return 0;
127} 118}
128 119
120static struct file_operations i810_buffer_fops = {
121 .open = drm_open,
122 .flush = drm_flush,
123 .release = drm_release,
124 .ioctl = drm_ioctl,
125 .mmap = i810_mmap_buffers,
126 .fasync = drm_fasync,
127};
128
129static int i810_map_buffer(drm_buf_t *buf, struct file *filp) 129static int i810_map_buffer(drm_buf_t *buf, struct file *filp)
130{ 130{
131 drm_file_t *priv = filp->private_data; 131 drm_file_t *priv = filp->private_data;
@@ -1003,8 +1003,8 @@ void i810_reclaim_buffers(drm_device_t *dev, struct file *filp)
1003 } 1003 }
1004} 1004}
1005 1005
1006int i810_flush_ioctl(struct inode *inode, struct file *filp, 1006static int i810_flush_ioctl(struct inode *inode, struct file *filp,
1007 unsigned int cmd, unsigned long arg) 1007 unsigned int cmd, unsigned long arg)
1008{ 1008{
1009 drm_file_t *priv = filp->private_data; 1009 drm_file_t *priv = filp->private_data;
1010 drm_device_t *dev = priv->head->dev; 1010 drm_device_t *dev = priv->head->dev;
diff --git a/drivers/char/drm/i810_drv.h b/drivers/char/drm/i810_drv.h
index fa23ca454e57..1b40538d1725 100644
--- a/drivers/char/drm/i810_drv.h
+++ b/drivers/char/drm/i810_drv.h
@@ -115,7 +115,6 @@ typedef struct drm_i810_private {
115 115
116 /* i810_dma.c */ 116 /* i810_dma.c */
117extern void i810_reclaim_buffers(drm_device_t *dev, struct file *filp); 117extern void i810_reclaim_buffers(drm_device_t *dev, struct file *filp);
118extern int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
119 118
120extern int i810_driver_dma_quiescent(drm_device_t *dev); 119extern int i810_driver_dma_quiescent(drm_device_t *dev);
121extern void i810_driver_release(drm_device_t *dev, struct file *filp); 120extern void i810_driver_release(drm_device_t *dev, struct file *filp);
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index 98adccf8e434..dc7733035864 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -92,16 +92,7 @@ static int i830_freelist_put(drm_device_t *dev, drm_buf_t *buf)
92 return 0; 92 return 0;
93} 93}
94 94
95static struct file_operations i830_buffer_fops = { 95static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
96 .open = drm_open,
97 .flush = drm_flush,
98 .release = drm_release,
99 .ioctl = drm_ioctl,
100 .mmap = i830_mmap_buffers,
101 .fasync = drm_fasync,
102};
103
104int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
105{ 96{
106 drm_file_t *priv = filp->private_data; 97 drm_file_t *priv = filp->private_data;
107 drm_device_t *dev; 98 drm_device_t *dev;
@@ -128,6 +119,15 @@ int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
128 return 0; 119 return 0;
129} 120}
130 121
122static struct file_operations i830_buffer_fops = {
123 .open = drm_open,
124 .flush = drm_flush,
125 .release = drm_release,
126 .ioctl = drm_ioctl,
127 .mmap = i830_mmap_buffers,
128 .fasync = drm_fasync,
129};
130
131static int i830_map_buffer(drm_buf_t *buf, struct file *filp) 131static int i830_map_buffer(drm_buf_t *buf, struct file *filp)
132{ 132{
133 drm_file_t *priv = filp->private_data; 133 drm_file_t *priv = filp->private_data;
diff --git a/drivers/char/drm/i830_drv.c b/drivers/char/drm/i830_drv.c
index aa80ad6a5ee0..bc36be76b8b2 100644
--- a/drivers/char/drm/i830_drv.c
+++ b/drivers/char/drm/i830_drv.c
@@ -40,7 +40,7 @@
40 40
41#include "drm_pciids.h" 41#include "drm_pciids.h"
42 42
43int postinit( struct drm_device *dev, unsigned long flags ) 43static int postinit( struct drm_device *dev, unsigned long flags )
44{ 44{
45 dev->counters += 4; 45 dev->counters += 4;
46 dev->types[6] = _DRM_STAT_IRQ; 46 dev->types[6] = _DRM_STAT_IRQ;
diff --git a/drivers/char/drm/i830_drv.h b/drivers/char/drm/i830_drv.h
index d4b2d093d6ab..df7746131dea 100644
--- a/drivers/char/drm/i830_drv.h
+++ b/drivers/char/drm/i830_drv.h
@@ -123,8 +123,6 @@ typedef struct drm_i830_private {
123/* i830_dma.c */ 123/* i830_dma.c */
124extern void i830_reclaim_buffers(drm_device_t *dev, struct file *filp); 124extern void i830_reclaim_buffers(drm_device_t *dev, struct file *filp);
125 125
126extern int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma);
127
128/* i830_irq.c */ 126/* i830_irq.c */
129extern int i830_irq_emit( struct inode *inode, struct file *filp, 127extern int i830_irq_emit( struct inode *inode, struct file *filp,
130 unsigned int cmd, unsigned long arg ); 128 unsigned int cmd, unsigned long arg );
diff --git a/drivers/char/drm/i830_irq.c b/drivers/char/drm/i830_irq.c
index 6d7729ffe2dc..a5923e5d0a77 100644
--- a/drivers/char/drm/i830_irq.c
+++ b/drivers/char/drm/i830_irq.c
@@ -54,8 +54,7 @@ irqreturn_t i830_driver_irq_handler( DRM_IRQ_ARGS )
54 return IRQ_HANDLED; 54 return IRQ_HANDLED;
55} 55}
56 56
57 57static int i830_emit_irq(drm_device_t *dev)
58int i830_emit_irq(drm_device_t *dev)
59{ 58{
60 drm_i830_private_t *dev_priv = dev->dev_private; 59 drm_i830_private_t *dev_priv = dev->dev_private;
61 RING_LOCALS; 60 RING_LOCALS;
@@ -73,7 +72,7 @@ int i830_emit_irq(drm_device_t *dev)
73} 72}
74 73
75 74
76int i830_wait_irq(drm_device_t *dev, int irq_nr) 75static int i830_wait_irq(drm_device_t *dev, int irq_nr)
77{ 76{
78 drm_i830_private_t *dev_priv = 77 drm_i830_private_t *dev_priv =
79 (drm_i830_private_t *)dev->dev_private; 78 (drm_i830_private_t *)dev->dev_private;
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index 7300a09dbd5c..acf9e52a9507 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -1,10 +1,30 @@
1/* i915_dma.c -- DMA support for the I915 -*- linux-c -*- 1/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
2 */ 2 */
3/************************************************************************** 3/**************************************************************************
4 * 4 *
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
8 **************************************************************************/ 28 **************************************************************************/
9 29
10#include "drmP.h" 30#include "drmP.h"
@@ -12,23 +32,6 @@
12#include "i915_drm.h" 32#include "i915_drm.h"
13#include "i915_drv.h" 33#include "i915_drv.h"
14 34
15drm_ioctl_desc_t i915_ioctls[] = {
16 [DRM_IOCTL_NR(DRM_I915_INIT)] = {i915_dma_init, 1, 1},
17 [DRM_IOCTL_NR(DRM_I915_FLUSH)] = {i915_flush_ioctl, 1, 0},
18 [DRM_IOCTL_NR(DRM_I915_FLIP)] = {i915_flip_bufs, 1, 0},
19 [DRM_IOCTL_NR(DRM_I915_BATCHBUFFER)] = {i915_batchbuffer, 1, 0},
20 [DRM_IOCTL_NR(DRM_I915_IRQ_EMIT)] = {i915_irq_emit, 1, 0},
21 [DRM_IOCTL_NR(DRM_I915_IRQ_WAIT)] = {i915_irq_wait, 1, 0},
22 [DRM_IOCTL_NR(DRM_I915_GETPARAM)] = {i915_getparam, 1, 0},
23 [DRM_IOCTL_NR(DRM_I915_SETPARAM)] = {i915_setparam, 1, 1},
24 [DRM_IOCTL_NR(DRM_I915_ALLOC)] = {i915_mem_alloc, 1, 0},
25 [DRM_IOCTL_NR(DRM_I915_FREE)] = {i915_mem_free, 1, 0},
26 [DRM_IOCTL_NR(DRM_I915_INIT_HEAP)] = {i915_mem_init_heap, 1, 1},
27 [DRM_IOCTL_NR(DRM_I915_CMDBUFFER)] = {i915_cmdbuffer, 1, 0}
28};
29
30int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
31
32/* Really want an OS-independent resettable timer. Would like to have 35/* Really want an OS-independent resettable timer. Would like to have
33 * this loop run for (eg) 3 sec, but have the timer reset every time 36 * this loop run for (eg) 3 sec, but have the timer reset every time
34 * the head pointer changes, so that EBUSY only happens if the ring 37 * the head pointer changes, so that EBUSY only happens if the ring
@@ -75,7 +78,7 @@ void i915_kernel_lost_context(drm_device_t * dev)
75 dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY; 78 dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
76} 79}
77 80
78int i915_dma_cleanup(drm_device_t * dev) 81static int i915_dma_cleanup(drm_device_t * dev)
79{ 82{
80 /* Make sure interrupts are disabled here because the uninstall ioctl 83 /* Make sure interrupts are disabled here because the uninstall ioctl
81 * may not have been called from userspace and after dev_private 84 * may not have been called from userspace and after dev_private
@@ -227,7 +230,7 @@ static int i915_resume(drm_device_t * dev)
227 return 0; 230 return 0;
228} 231}
229 232
230int i915_dma_init(DRM_IOCTL_ARGS) 233static int i915_dma_init(DRM_IOCTL_ARGS)
231{ 234{
232 DRM_DEVICE; 235 DRM_DEVICE;
233 drm_i915_private_t *dev_priv; 236 drm_i915_private_t *dev_priv;
@@ -538,7 +541,7 @@ static int i915_quiescent(drm_device_t * dev)
538 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__); 541 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__);
539} 542}
540 543
541int i915_flush_ioctl(DRM_IOCTL_ARGS) 544static int i915_flush_ioctl(DRM_IOCTL_ARGS)
542{ 545{
543 DRM_DEVICE; 546 DRM_DEVICE;
544 547
@@ -547,7 +550,7 @@ int i915_flush_ioctl(DRM_IOCTL_ARGS)
547 return i915_quiescent(dev); 550 return i915_quiescent(dev);
548} 551}
549 552
550int i915_batchbuffer(DRM_IOCTL_ARGS) 553static int i915_batchbuffer(DRM_IOCTL_ARGS)
551{ 554{
552 DRM_DEVICE; 555 DRM_DEVICE;
553 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 556 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
@@ -581,7 +584,7 @@ int i915_batchbuffer(DRM_IOCTL_ARGS)
581 return ret; 584 return ret;
582} 585}
583 586
584int i915_cmdbuffer(DRM_IOCTL_ARGS) 587static int i915_cmdbuffer(DRM_IOCTL_ARGS)
585{ 588{
586 DRM_DEVICE; 589 DRM_DEVICE;
587 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 590 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
@@ -617,18 +620,7 @@ int i915_cmdbuffer(DRM_IOCTL_ARGS)
617 return 0; 620 return 0;
618} 621}
619 622
620int i915_do_cleanup_pageflip(drm_device_t * dev) 623static int i915_flip_bufs(DRM_IOCTL_ARGS)
621{
622 drm_i915_private_t *dev_priv = dev->dev_private;
623
624 DRM_DEBUG("%s\n", __FUNCTION__);
625 if (dev_priv->current_page != 0)
626 i915_dispatch_flip(dev);
627
628 return 0;
629}
630
631int i915_flip_bufs(DRM_IOCTL_ARGS)
632{ 624{
633 DRM_DEVICE; 625 DRM_DEVICE;
634 626
@@ -639,7 +631,7 @@ int i915_flip_bufs(DRM_IOCTL_ARGS)
639 return i915_dispatch_flip(dev); 631 return i915_dispatch_flip(dev);
640} 632}
641 633
642int i915_getparam(DRM_IOCTL_ARGS) 634static int i915_getparam(DRM_IOCTL_ARGS)
643{ 635{
644 DRM_DEVICE; 636 DRM_DEVICE;
645 drm_i915_private_t *dev_priv = dev->dev_private; 637 drm_i915_private_t *dev_priv = dev->dev_private;
@@ -674,7 +666,7 @@ int i915_getparam(DRM_IOCTL_ARGS)
674 return 0; 666 return 0;
675} 667}
676 668
677int i915_setparam(DRM_IOCTL_ARGS) 669static int i915_setparam(DRM_IOCTL_ARGS)
678{ 670{
679 DRM_DEVICE; 671 DRM_DEVICE;
680 drm_i915_private_t *dev_priv = dev->dev_private; 672 drm_i915_private_t *dev_priv = dev->dev_private;
@@ -723,3 +715,19 @@ void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp)
723 } 715 }
724} 716}
725 717
718drm_ioctl_desc_t i915_ioctls[] = {
719 [DRM_IOCTL_NR(DRM_I915_INIT)] = {i915_dma_init, 1, 1},
720 [DRM_IOCTL_NR(DRM_I915_FLUSH)] = {i915_flush_ioctl, 1, 0},
721 [DRM_IOCTL_NR(DRM_I915_FLIP)] = {i915_flip_bufs, 1, 0},
722 [DRM_IOCTL_NR(DRM_I915_BATCHBUFFER)] = {i915_batchbuffer, 1, 0},
723 [DRM_IOCTL_NR(DRM_I915_IRQ_EMIT)] = {i915_irq_emit, 1, 0},
724 [DRM_IOCTL_NR(DRM_I915_IRQ_WAIT)] = {i915_irq_wait, 1, 0},
725 [DRM_IOCTL_NR(DRM_I915_GETPARAM)] = {i915_getparam, 1, 0},
726 [DRM_IOCTL_NR(DRM_I915_SETPARAM)] = {i915_setparam, 1, 1},
727 [DRM_IOCTL_NR(DRM_I915_ALLOC)] = {i915_mem_alloc, 1, 0},
728 [DRM_IOCTL_NR(DRM_I915_FREE)] = {i915_mem_free, 1, 0},
729 [DRM_IOCTL_NR(DRM_I915_INIT_HEAP)] = {i915_mem_init_heap, 1, 1},
730 [DRM_IOCTL_NR(DRM_I915_CMDBUFFER)] = {i915_cmdbuffer, 1, 0}
731};
732
733int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
index 7e55edf45c4f..23e027d29080 100644
--- a/drivers/char/drm/i915_drm.h
+++ b/drivers/char/drm/i915_drm.h
@@ -1,3 +1,30 @@
1/**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
1#ifndef _I915_DRM_H_ 28#ifndef _I915_DRM_H_
2#define _I915_DRM_H_ 29#define _I915_DRM_H_
3 30
diff --git a/drivers/char/drm/i915_drv.c b/drivers/char/drm/i915_drv.c
index 002b7082e21b..1f59d3fc79bc 100644
--- a/drivers/char/drm/i915_drv.c
+++ b/drivers/char/drm/i915_drv.c
@@ -1,11 +1,30 @@
1/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*- 1/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2 */ 2 */
3
4/************************************************************************** 3/**************************************************************************
5 * 4 *
6 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * All Rights Reserved. 6 * All Rights Reserved.
8 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
9 **************************************************************************/ 28 **************************************************************************/
10 29
11#include "drmP.h" 30#include "drmP.h"
@@ -15,7 +34,7 @@
15 34
16#include "drm_pciids.h" 35#include "drm_pciids.h"
17 36
18int postinit( struct drm_device *dev, unsigned long flags ) 37static int postinit( struct drm_device *dev, unsigned long flags )
19{ 38{
20 dev->counters += 4; 39 dev->counters += 4;
21 dev->types[6] = _DRM_STAT_IRQ; 40 dev->types[6] = _DRM_STAT_IRQ;
@@ -78,6 +97,9 @@ static struct drm_driver driver = {
78 .mmap = drm_mmap, 97 .mmap = drm_mmap,
79 .poll = drm_poll, 98 .poll = drm_poll,
80 .fasync = drm_fasync, 99 .fasync = drm_fasync,
100#ifdef CONFIG_COMPAT
101 .compat_ioctl = i915_compat_ioctl,
102#endif
81 }, 103 },
82 .pci_driver = { 104 .pci_driver = {
83 .name = DRIVER_NAME, 105 .name = DRIVER_NAME,
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index f6ca92a565db..9c37d2367dd5 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -1,10 +1,30 @@
1/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*- 1/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2 */ 2 */
3/************************************************************************** 3/**************************************************************************
4 * 4 *
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
8 **************************************************************************/ 28 **************************************************************************/
9 29
10#ifndef _I915_DRV_H_ 30#ifndef _I915_DRV_H_
@@ -79,14 +99,6 @@ typedef struct drm_i915_private {
79} drm_i915_private_t; 99} drm_i915_private_t;
80 100
81 /* i915_dma.c */ 101 /* i915_dma.c */
82extern int i915_dma_init(DRM_IOCTL_ARGS);
83extern int i915_dma_cleanup(drm_device_t * dev);
84extern int i915_flush_ioctl(DRM_IOCTL_ARGS);
85extern int i915_batchbuffer(DRM_IOCTL_ARGS);
86extern int i915_flip_bufs(DRM_IOCTL_ARGS);
87extern int i915_getparam(DRM_IOCTL_ARGS);
88extern int i915_setparam(DRM_IOCTL_ARGS);
89extern int i915_cmdbuffer(DRM_IOCTL_ARGS);
90extern void i915_kernel_lost_context(drm_device_t * dev); 102extern void i915_kernel_lost_context(drm_device_t * dev);
91extern void i915_driver_pretakedown(drm_device_t *dev); 103extern void i915_driver_pretakedown(drm_device_t *dev);
92extern void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp); 104extern void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp);
@@ -94,8 +106,6 @@ extern void i915_driver_prerelease(drm_device_t *dev, DRMFILE filp);
94/* i915_irq.c */ 106/* i915_irq.c */
95extern int i915_irq_emit(DRM_IOCTL_ARGS); 107extern int i915_irq_emit(DRM_IOCTL_ARGS);
96extern int i915_irq_wait(DRM_IOCTL_ARGS); 108extern int i915_irq_wait(DRM_IOCTL_ARGS);
97extern int i915_wait_irq(drm_device_t * dev, int irq_nr);
98extern int i915_emit_irq(drm_device_t * dev);
99 109
100extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS); 110extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
101extern void i915_driver_irq_preinstall(drm_device_t *dev); 111extern void i915_driver_irq_preinstall(drm_device_t *dev);
@@ -110,6 +120,10 @@ extern void i915_mem_takedown(struct mem_block **heap);
110extern void i915_mem_release(drm_device_t * dev, 120extern void i915_mem_release(drm_device_t * dev,
111 DRMFILE filp, struct mem_block *heap); 121 DRMFILE filp, struct mem_block *heap);
112 122
123extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
124 unsigned long arg);
125
126
113#define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, reg) 127#define I915_READ(reg) DRM_READ32(dev_priv->mmio_map, reg)
114#define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, reg, val) 128#define I915_WRITE(reg,val) DRM_WRITE32(dev_priv->mmio_map, reg, val)
115#define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, reg) 129#define I915_READ16(reg) DRM_READ16(dev_priv->mmio_map, reg)
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c
new file mode 100644
index 000000000000..fe009e1b3a3f
--- /dev/null
+++ b/drivers/char/drm/i915_ioc32.c
@@ -0,0 +1,221 @@
1/**
2 * \file i915_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the i915 DRM.
5 *
6 * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
7 *
8 *
9 * Copyright (C) Paul Mackerras 2005
10 * Copyright (C) Alan Hourihane 2005
11 * All Rights Reserved.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
22 * Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 * IN THE SOFTWARE.
31 */
32#include <linux/compat.h>
33#include <linux/ioctl32.h>
34
35#include "drmP.h"
36#include "drm.h"
37#include "i915_drm.h"
38
39typedef struct _drm_i915_batchbuffer32 {
40 int start; /* agp offset */
41 int used; /* nr bytes in use */
42 int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
43 int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
44 int num_cliprects; /* mulitpass with multiple cliprects? */
45 u32 cliprects; /* pointer to userspace cliprects */
46} drm_i915_batchbuffer32_t;
47
48static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
49 unsigned long arg)
50{
51 drm_i915_batchbuffer32_t batchbuffer32;
52 drm_i915_batchbuffer_t __user *batchbuffer;
53
54 if (copy_from_user(&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
55 return -EFAULT;
56
57 batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
58 if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
59 || __put_user(batchbuffer32.start, &batchbuffer->start)
60 || __put_user(batchbuffer32.used, &batchbuffer->used)
61 || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
62 || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
63 || __put_user(batchbuffer32.num_cliprects, &batchbuffer->num_cliprects)
64 || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
65 &batchbuffer->cliprects))
66 return -EFAULT;
67
68 return drm_ioctl(file->f_dentry->d_inode, file,
69 DRM_IOCTL_I915_BATCHBUFFER, (unsigned long) batchbuffer);
70}
71
72typedef struct _drm_i915_cmdbuffer32 {
73 u32 buf; /* pointer to userspace command buffer */
74 int sz; /* nr bytes in buf */
75 int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
76 int DR4; /* window origin for GFX_OP_DRAWRECT_INFO */
77 int num_cliprects; /* mulitpass with multiple cliprects? */
78 u32 cliprects; /* pointer to userspace cliprects */
79} drm_i915_cmdbuffer32_t;
80
81static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
82 unsigned long arg)
83{
84 drm_i915_cmdbuffer32_t cmdbuffer32;
85 drm_i915_cmdbuffer_t __user *cmdbuffer;
86
87 if (copy_from_user(&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
88 return -EFAULT;
89
90 cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
91 if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
92 || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
93 &cmdbuffer->buf)
94 || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
95 || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
96 || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
97 || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
98 || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
99 &cmdbuffer->cliprects))
100 return -EFAULT;
101
102 return drm_ioctl(file->f_dentry->d_inode, file,
103 DRM_IOCTL_I915_CMDBUFFER, (unsigned long) cmdbuffer);
104}
105
106typedef struct drm_i915_irq_emit32 {
107 u32 irq_seq;
108} drm_i915_irq_emit32_t;
109
110static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
111 unsigned long arg)
112{
113 drm_i915_irq_emit32_t req32;
114 drm_i915_irq_emit_t __user *request;
115
116 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
117 return -EFAULT;
118
119 request = compat_alloc_user_space(sizeof(*request));
120 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
121 || __put_user((int __user *)(unsigned long)req32.irq_seq,
122 &request->irq_seq))
123 return -EFAULT;
124
125 return drm_ioctl(file->f_dentry->d_inode, file,
126 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long) request);
127}
128typedef struct drm_i915_getparam32 {
129 int param;
130 u32 value;
131} drm_i915_getparam32_t;
132
133static int compat_i915_getparam(struct file *file, unsigned int cmd,
134 unsigned long arg)
135{
136 drm_i915_getparam32_t req32;
137 drm_i915_getparam_t __user *request;
138
139 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
140 return -EFAULT;
141
142 request = compat_alloc_user_space(sizeof(*request));
143 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
144 || __put_user(req32.param, &request->param)
145 || __put_user((void __user *)(unsigned long)req32.value,
146 &request->value))
147 return -EFAULT;
148
149 return drm_ioctl(file->f_dentry->d_inode, file,
150 DRM_IOCTL_I915_GETPARAM, (unsigned long) request);
151}
152
153typedef struct drm_i915_mem_alloc32 {
154 int region;
155 int alignment;
156 int size;
157 u32 region_offset; /* offset from start of fb or agp */
158} drm_i915_mem_alloc32_t;
159
160static int compat_i915_alloc(struct file *file, unsigned int cmd,
161 unsigned long arg)
162{
163 drm_i915_mem_alloc32_t req32;
164 drm_i915_mem_alloc_t __user *request;
165
166 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
167 return -EFAULT;
168
169 request = compat_alloc_user_space(sizeof(*request));
170 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
171 || __put_user(req32.region, &request->region)
172 || __put_user(req32.alignment, &request->alignment)
173 || __put_user(req32.size, &request->size)
174 || __put_user((void __user *)(unsigned long)req32.region_offset,
175 &request->region_offset))
176 return -EFAULT;
177
178 return drm_ioctl(file->f_dentry->d_inode, file,
179 DRM_IOCTL_I915_ALLOC, (unsigned long) request);
180}
181
182
183drm_ioctl_compat_t *i915_compat_ioctls[] = {
184 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
185 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
186 [DRM_I915_GETPARAM] = compat_i915_getparam,
187 [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
188 [DRM_I915_ALLOC] = compat_i915_alloc
189};
190
191/**
192 * Called whenever a 32-bit process running under a 64-bit kernel
193 * performs an ioctl on /dev/dri/card<n>.
194 *
195 * \param filp file pointer.
196 * \param cmd command.
197 * \param arg user argument.
198 * \return zero on success or negative number on failure.
199 */
200long i915_compat_ioctl(struct file *filp, unsigned int cmd,
201 unsigned long arg)
202{
203 unsigned int nr = DRM_IOCTL_NR(cmd);
204 drm_ioctl_compat_t *fn = NULL;
205 int ret;
206
207 if (nr < DRM_COMMAND_BASE)
208 return drm_compat_ioctl(filp, cmd, arg);
209
210 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
211 fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
212
213 lock_kernel(); /* XXX for now */
214 if (fn != NULL)
215 ret = (*fn)(filp, cmd, arg);
216 else
217 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
218 unlock_kernel();
219
220 return ret;
221}
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index b0239262a84a..4fa448ee846b 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -1,10 +1,30 @@
1/* i915_dma.c -- DMA support for the I915 -*- linux-c -*- 1/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
2 */ 2 */
3/************************************************************************** 3/**************************************************************************
4 * 4 *
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
8 **************************************************************************/ 28 **************************************************************************/
9 29
10#include "drmP.h" 30#include "drmP.h"
@@ -36,7 +56,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
36 return IRQ_HANDLED; 56 return IRQ_HANDLED;
37} 57}
38 58
39int i915_emit_irq(drm_device_t * dev) 59static int i915_emit_irq(drm_device_t * dev)
40{ 60{
41 drm_i915_private_t *dev_priv = dev->dev_private; 61 drm_i915_private_t *dev_priv = dev->dev_private;
42 u32 ret; 62 u32 ret;
@@ -56,7 +76,7 @@ int i915_emit_irq(drm_device_t * dev)
56 return ret; 76 return ret;
57} 77}
58 78
59int i915_wait_irq(drm_device_t * dev, int irq_nr) 79static int i915_wait_irq(drm_device_t * dev, int irq_nr)
60{ 80{
61 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 81 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
62 int ret = 0; 82 int ret = 0;
diff --git a/drivers/char/drm/i915_mem.c b/drivers/char/drm/i915_mem.c
index d54a3005946b..9b1698f521be 100644
--- a/drivers/char/drm/i915_mem.c
+++ b/drivers/char/drm/i915_mem.c
@@ -1,10 +1,30 @@
1/* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*- 1/* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*-
2 */ 2 */
3/************************************************************************** 3/**************************************************************************
4 * 4 *
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
8 **************************************************************************/ 28 **************************************************************************/
9 29
10#include "drmP.h" 30#include "drmP.h"
diff --git a/drivers/char/drm/mga_drv.c b/drivers/char/drm/mga_drv.c
index 22dab3e9d92a..844cca9cb29d 100644
--- a/drivers/char/drm/mga_drv.c
+++ b/drivers/char/drm/mga_drv.c
@@ -101,6 +101,9 @@ static struct drm_driver driver = {
101 .mmap = drm_mmap, 101 .mmap = drm_mmap,
102 .poll = drm_poll, 102 .poll = drm_poll,
103 .fasync = drm_fasync, 103 .fasync = drm_fasync,
104#ifdef CONFIG_COMPAT
105 .compat_ioctl = mga_compat_ioctl,
106#endif
104 }, 107 },
105 .pci_driver = { 108 .pci_driver = {
106 .name = DRIVER_NAME, 109 .name = DRIVER_NAME,
diff --git a/drivers/char/drm/mga_drv.h b/drivers/char/drm/mga_drv.h
index 1d84a1eb34db..9412e2816eb7 100644
--- a/drivers/char/drm/mga_drv.h
+++ b/drivers/char/drm/mga_drv.h
@@ -137,6 +137,8 @@ extern irqreturn_t mga_driver_irq_handler( DRM_IRQ_ARGS );
137extern void mga_driver_irq_preinstall( drm_device_t *dev ); 137extern void mga_driver_irq_preinstall( drm_device_t *dev );
138extern void mga_driver_irq_postinstall( drm_device_t *dev ); 138extern void mga_driver_irq_postinstall( drm_device_t *dev );
139extern void mga_driver_irq_uninstall( drm_device_t *dev ); 139extern void mga_driver_irq_uninstall( drm_device_t *dev );
140extern long mga_compat_ioctl(struct file *filp, unsigned int cmd,
141 unsigned long arg);
140 142
141#define mga_flush_write_combine() DRM_WRITEMEMORYBARRIER() 143#define mga_flush_write_combine() DRM_WRITEMEMORYBARRIER()
142 144
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c
new file mode 100644
index 000000000000..bc745cfa2095
--- /dev/null
+++ b/drivers/char/drm/mga_ioc32.c
@@ -0,0 +1,167 @@
1/**
2 * \file mga_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the MGA DRM.
5 *
6 * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
7 *
8 *
9 * Copyright (C) Paul Mackerras 2005
10 * Copyright (C) Egbert Eich 2003,2004
11 * Copyright (C) Dave Airlie 2005
12 * All Rights Reserved.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice (including the next
22 * paragraph) shall be included in all copies or substantial portions of the
23 * Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
29 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 * IN THE SOFTWARE.
32 */
33#include <linux/compat.h>
34#include <linux/ioctl32.h>
35
36#include "drmP.h"
37#include "drm.h"
38#include "mga_drm.h"
39
40typedef struct drm32_mga_init {
41 int func;
42 u32 sarea_priv_offset;
43 int chipset;
44 int sgram;
45 unsigned int maccess;
46 unsigned int fb_cpp;
47 unsigned int front_offset, front_pitch;
48 unsigned int back_offset, back_pitch;
49 unsigned int depth_cpp;
50 unsigned int depth_offset, depth_pitch;
51 unsigned int texture_offset[MGA_NR_TEX_HEAPS];
52 unsigned int texture_size[MGA_NR_TEX_HEAPS];
53 u32 fb_offset;
54 u32 mmio_offset;
55 u32 status_offset;
56 u32 warp_offset;
57 u32 primary_offset;
58 u32 buffers_offset;
59} drm_mga_init32_t;
60
61static int compat_mga_init(struct file *file, unsigned int cmd,
62 unsigned long arg)
63{
64 drm_mga_init32_t init32;
65 drm_mga_init_t __user *init;
66 int err = 0, i;
67
68 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
69 return -EFAULT;
70
71 init = compat_alloc_user_space(sizeof(*init));
72 if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
73 || __put_user(init32.func, &init->func)
74 || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
75 || __put_user(init32.chipset, &init->chipset)
76 || __put_user(init32.sgram, &init->sgram)
77 || __put_user(init32.maccess, &init->maccess)
78 || __put_user(init32.fb_cpp, &init->fb_cpp)
79 || __put_user(init32.front_offset, &init->front_offset)
80 || __put_user(init32.front_pitch, &init->front_pitch)
81 || __put_user(init32.back_offset, &init->back_offset)
82 || __put_user(init32.back_pitch, &init->back_pitch)
83 || __put_user(init32.depth_cpp, &init->depth_cpp)
84 || __put_user(init32.depth_offset, &init->depth_offset)
85 || __put_user(init32.depth_pitch, &init->depth_pitch)
86 || __put_user(init32.fb_offset, &init->fb_offset)
87 || __put_user(init32.mmio_offset, &init->mmio_offset)
88 || __put_user(init32.status_offset, &init->status_offset)
89 || __put_user(init32.warp_offset, &init->warp_offset)
90 || __put_user(init32.primary_offset, &init->primary_offset)
91 || __put_user(init32.buffers_offset, &init->buffers_offset))
92 return -EFAULT;
93
94 for (i=0; i<MGA_NR_TEX_HEAPS; i++)
95 {
96 err |= __put_user(init32.texture_offset[i], &init->texture_offset[i]);
97 err |= __put_user(init32.texture_size[i], &init->texture_size[i]);
98 }
99 if (err)
100 return -EFAULT;
101
102 return drm_ioctl(file->f_dentry->d_inode, file,
103 DRM_IOCTL_MGA_INIT, (unsigned long) init);
104}
105
106
107typedef struct drm_mga_getparam32 {
108 int param;
109 u32 value;
110} drm_mga_getparam32_t;
111
112
113static int compat_mga_getparam(struct file *file, unsigned int cmd,
114 unsigned long arg)
115{
116 drm_mga_getparam32_t getparam32;
117 drm_mga_getparam_t __user *getparam;
118
119 if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
120 return -EFAULT;
121
122 getparam = compat_alloc_user_space(sizeof(*getparam));
123 if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
124 || __put_user(getparam32.param, &getparam->param)
125 || __put_user((void __user *)(unsigned long)getparam32.value, &getparam->value))
126 return -EFAULT;
127
128 return drm_ioctl(file->f_dentry->d_inode, file,
129 DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
130}
131
132drm_ioctl_compat_t *mga_compat_ioctls[] = {
133 [DRM_MGA_INIT] = compat_mga_init,
134 [DRM_MGA_GETPARAM] = compat_mga_getparam,
135};
136
137/**
138 * Called whenever a 32-bit process running under a 64-bit kernel
139 * performs an ioctl on /dev/dri/card<n>.
140 *
141 * \param filp file pointer.
142 * \param cmd command.
143 * \param arg user argument.
144 * \return zero on success or negative number on failure.
145 */
146long mga_compat_ioctl(struct file *filp, unsigned int cmd,
147 unsigned long arg)
148{
149 unsigned int nr = DRM_IOCTL_NR(cmd);
150 drm_ioctl_compat_t *fn = NULL;
151 int ret;
152
153 if (nr < DRM_COMMAND_BASE)
154 return drm_compat_ioctl(filp, cmd, arg);
155
156 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
157 fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
158
159 lock_kernel(); /* XXX for now */
160 if (fn != NULL)
161 ret = (*fn)(filp, cmd, arg);
162 else
163 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
164 unlock_kernel();
165
166 return ret;
167}
diff --git a/drivers/char/drm/r128_drv.c b/drivers/char/drm/r128_drv.c
index ced63810237b..bc446da1b210 100644
--- a/drivers/char/drm/r128_drv.c
+++ b/drivers/char/drm/r128_drv.c
@@ -96,6 +96,9 @@ static struct drm_driver driver = {
96 .mmap = drm_mmap, 96 .mmap = drm_mmap,
97 .poll = drm_poll, 97 .poll = drm_poll,
98 .fasync = drm_fasync, 98 .fasync = drm_fasync,
99#ifdef CONFIG_COMPAT
100 .compat_ioctl = r128_compat_ioctl,
101#endif
99 }, 102 },
100 .pci_driver = { 103 .pci_driver = {
101 .name = DRIVER_NAME, 104 .name = DRIVER_NAME,
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h
index cf1aa5df459e..0fb687c9505e 100644
--- a/drivers/char/drm/r128_drv.h
+++ b/drivers/char/drm/r128_drv.h
@@ -156,6 +156,9 @@ extern void r128_driver_irq_uninstall( drm_device_t *dev );
156extern void r128_driver_pretakedown(drm_device_t *dev); 156extern void r128_driver_pretakedown(drm_device_t *dev);
157extern void r128_driver_prerelease(drm_device_t *dev, DRMFILE filp); 157extern void r128_driver_prerelease(drm_device_t *dev, DRMFILE filp);
158 158
159extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
160 unsigned long arg);
161
159/* Register definitions, register access macros and drmAddMap constants 162/* Register definitions, register access macros and drmAddMap constants
160 * for Rage 128 kernel driver. 163 * for Rage 128 kernel driver.
161 */ 164 */
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c
new file mode 100644
index 000000000000..60598ef9475a
--- /dev/null
+++ b/drivers/char/drm/r128_ioc32.c
@@ -0,0 +1,219 @@
1/**
2 * \file r128_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the R128 DRM.
5 *
6 * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
7 *
8 * Copyright (C) Paul Mackerras 2005
9 * Copyright (C) Egbert Eich 2003,2004
10 * Copyright (C) Dave Airlie 2005
11 * All Rights Reserved.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
22 * Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 * IN THE SOFTWARE.
31 */
32#include <linux/compat.h>
33#include <linux/ioctl32.h>
34
35#include "drmP.h"
36#include "drm.h"
37#include "r128_drm.h"
38
39typedef struct drm_r128_init32 {
40 int func;
41 unsigned int sarea_priv_offset;
42 int is_pci;
43 int cce_mode;
44 int cce_secure;
45 int ring_size;
46 int usec_timeout;
47
48 unsigned int fb_bpp;
49 unsigned int front_offset, front_pitch;
50 unsigned int back_offset, back_pitch;
51 unsigned int depth_bpp;
52 unsigned int depth_offset, depth_pitch;
53 unsigned int span_offset;
54
55 unsigned int fb_offset;
56 unsigned int mmio_offset;
57 unsigned int ring_offset;
58 unsigned int ring_rptr_offset;
59 unsigned int buffers_offset;
60 unsigned int agp_textures_offset;
61} drm_r128_init32_t;
62
63static int compat_r128_init(struct file *file, unsigned int cmd,
64 unsigned long arg)
65{
66 drm_r128_init32_t init32;
67 drm_r128_init_t __user *init;
68
69 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
70 return -EFAULT;
71
72 init = compat_alloc_user_space(sizeof(*init));
73 if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
74 || __put_user(init32.func, &init->func)
75 || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
76 || __put_user(init32.is_pci, &init->is_pci)
77 || __put_user(init32.cce_mode, &init->cce_mode)
78 || __put_user(init32.cce_secure, &init->cce_secure)
79 || __put_user(init32.ring_size, &init->ring_size)
80 || __put_user(init32.usec_timeout, &init->usec_timeout)
81 || __put_user(init32.fb_bpp, &init->fb_bpp)
82 || __put_user(init32.front_offset, &init->front_offset)
83 || __put_user(init32.front_pitch, &init->front_pitch)
84 || __put_user(init32.back_offset, &init->back_offset)
85 || __put_user(init32.back_pitch, &init->back_pitch)
86 || __put_user(init32.depth_bpp, &init->depth_bpp)
87 || __put_user(init32.depth_offset, &init->depth_offset)
88 || __put_user(init32.depth_pitch, &init->depth_pitch)
89 || __put_user(init32.span_offset, &init->span_offset)
90 || __put_user(init32.fb_offset, &init->fb_offset)
91 || __put_user(init32.mmio_offset, &init->mmio_offset)
92 || __put_user(init32.ring_offset, &init->ring_offset)
93 || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
94 || __put_user(init32.buffers_offset, &init->buffers_offset)
95 || __put_user(init32.agp_textures_offset, &init->agp_textures_offset))
96 return -EFAULT;
97
98 return drm_ioctl(file->f_dentry->d_inode, file,
99 DRM_IOCTL_R128_INIT, (unsigned long)init);
100}
101
102
103typedef struct drm_r128_depth32 {
104 int func;
105 int n;
106 u32 x;
107 u32 y;
108 u32 buffer;
109 u32 mask;
110} drm_r128_depth32_t;
111
112static int compat_r128_depth(struct file *file, unsigned int cmd,
113 unsigned long arg)
114{
115 drm_r128_depth32_t depth32;
116 drm_r128_depth_t __user *depth;
117
118 if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
119 return -EFAULT;
120
121 depth = compat_alloc_user_space(sizeof(*depth));
122 if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
123 || __put_user(depth32.func, &depth->func)
124 || __put_user(depth32.n, &depth->n)
125 || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
126 || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
127 || __put_user((unsigned int __user *)(unsigned long)depth32.buffer, &depth->buffer)
128 || __put_user((unsigned char __user *)(unsigned long)depth32.mask, &depth->mask))
129 return -EFAULT;
130
131 return drm_ioctl(file->f_dentry->d_inode, file,
132 DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
133
134}
135
136typedef struct drm_r128_stipple32 {
137 u32 mask;
138} drm_r128_stipple32_t;
139
140static int compat_r128_stipple(struct file *file, unsigned int cmd,
141 unsigned long arg)
142{
143 drm_r128_stipple32_t stipple32;
144 drm_r128_stipple_t __user *stipple;
145
146 if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
147 return -EFAULT;
148
149 stipple = compat_alloc_user_space(sizeof(*stipple));
150 if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
151 || __put_user((unsigned int __user *)(unsigned long)stipple32.mask, &stipple->mask))
152 return -EFAULT;
153
154 return drm_ioctl(file->f_dentry->d_inode, file,
155 DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
156}
157
158typedef struct drm_r128_getparam32 {
159 int param;
160 u32 value;
161} drm_r128_getparam32_t;
162
163static int compat_r128_getparam(struct file *file, unsigned int cmd,
164 unsigned long arg)
165{
166 drm_r128_getparam32_t getparam32;
167 drm_r128_getparam_t __user *getparam;
168
169 if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
170 return -EFAULT;
171
172 getparam = compat_alloc_user_space(sizeof(*getparam));
173 if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
174 || __put_user(getparam32.param, &getparam->param)
175 || __put_user((void __user *)(unsigned long)getparam32.value, &getparam->value))
176 return -EFAULT;
177
178 return drm_ioctl(file->f_dentry->d_inode, file,
179 DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
180}
181
182drm_ioctl_compat_t *r128_compat_ioctls[] = {
183 [DRM_R128_INIT] = compat_r128_init,
184 [DRM_R128_DEPTH] = compat_r128_depth,
185 [DRM_R128_STIPPLE] = compat_r128_stipple,
186 [DRM_R128_GETPARAM] = compat_r128_getparam,
187};
188
189/**
190 * Called whenever a 32-bit process running under a 64-bit kernel
191 * performs an ioctl on /dev/dri/card<n>.
192 *
193 * \param filp file pointer.
194 * \param cmd command.
195 * \param arg user argument.
196 * \return zero on success or negative number on failure.
197 */
198long r128_compat_ioctl(struct file *filp, unsigned int cmd,
199 unsigned long arg)
200{
201 unsigned int nr = DRM_IOCTL_NR(cmd);
202 drm_ioctl_compat_t *fn = NULL;
203 int ret;
204
205 if (nr < DRM_COMMAND_BASE)
206 return drm_compat_ioctl(filp, cmd, arg);
207
208 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
209 fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
210
211 lock_kernel(); /* XXX for now */
212 if (fn != NULL)
213 ret = (*fn)(filp, cmd, arg);
214 else
215 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
216 unlock_kernel();
217
218 return ret;
219}
diff --git a/drivers/char/drm/r128_state.c b/drivers/char/drm/r128_state.c
index 53af69162829..426a71c049d9 100644
--- a/drivers/char/drm/r128_state.c
+++ b/drivers/char/drm/r128_state.c
@@ -1307,7 +1307,7 @@ static int r128_do_init_pageflip( drm_device_t *dev )
1307 return 0; 1307 return 0;
1308} 1308}
1309 1309
1310int r128_do_cleanup_pageflip( drm_device_t *dev ) 1310static int r128_do_cleanup_pageflip( drm_device_t *dev )
1311{ 1311{
1312 drm_r128_private_t *dev_priv = dev->dev_private; 1312 drm_r128_private_t *dev_priv = dev->dev_private;
1313 DRM_DEBUG( "\n" ); 1313 DRM_DEBUG( "\n" );
diff --git a/drivers/char/drm/radeon_drv.c b/drivers/char/drm/radeon_drv.c
index 7b983d96e53b..18e4e5b0952f 100644
--- a/drivers/char/drm/radeon_drv.c
+++ b/drivers/char/drm/radeon_drv.c
@@ -101,6 +101,9 @@ static struct drm_driver driver = {
101 .mmap = drm_mmap, 101 .mmap = drm_mmap,
102 .poll = drm_poll, 102 .poll = drm_poll,
103 .fasync = drm_fasync, 103 .fasync = drm_fasync,
104#ifdef CONFIG_COMPAT
105 .compat_ioctl = radeon_compat_ioctl,
106#endif
104 }, 107 },
105 .pci_driver = { 108 .pci_driver = {
106 .name = DRIVER_NAME, 109 .name = DRIVER_NAME,
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index 5837098afae8..771aa80a5e8c 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -317,6 +317,9 @@ extern int radeon_preinit( struct drm_device *dev, unsigned long flags );
317extern int radeon_postinit( struct drm_device *dev, unsigned long flags ); 317extern int radeon_postinit( struct drm_device *dev, unsigned long flags );
318extern int radeon_postcleanup( struct drm_device *dev ); 318extern int radeon_postcleanup( struct drm_device *dev );
319 319
320extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
321 unsigned long arg);
322
320/* Flags for stats.boxes 323/* Flags for stats.boxes
321 */ 324 */
322#define RADEON_BOX_DMA_IDLE 0x1 325#define RADEON_BOX_DMA_IDLE 0x1
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
new file mode 100644
index 000000000000..bfe612215fb3
--- /dev/null
+++ b/drivers/char/drm/radeon_ioc32.c
@@ -0,0 +1,395 @@
1/**
2 * \file radeon_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the Radeon DRM.
5 *
6 * \author Paul Mackerras <paulus@samba.org>
7 *
8 * Copyright (C) Paul Mackerras 2005
9 * All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30#include <linux/compat.h>
31#include <linux/ioctl32.h>
32
33#include "drmP.h"
34#include "drm.h"
35#include "radeon_drm.h"
36#include "radeon_drv.h"
37
38typedef struct drm_radeon_init32 {
39 int func;
40 u32 sarea_priv_offset;
41 int is_pci;
42 int cp_mode;
43 int gart_size;
44 int ring_size;
45 int usec_timeout;
46
47 unsigned int fb_bpp;
48 unsigned int front_offset, front_pitch;
49 unsigned int back_offset, back_pitch;
50 unsigned int depth_bpp;
51 unsigned int depth_offset, depth_pitch;
52
53 u32 fb_offset;
54 u32 mmio_offset;
55 u32 ring_offset;
56 u32 ring_rptr_offset;
57 u32 buffers_offset;
58 u32 gart_textures_offset;
59} drm_radeon_init32_t;
60
61static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
62 unsigned long arg)
63{
64 drm_radeon_init32_t init32;
65 drm_radeon_init_t __user *init;
66
67 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
68 return -EFAULT;
69
70 init = compat_alloc_user_space(sizeof(*init));
71 if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
72 || __put_user(init32.func, &init->func)
73 || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
74 || __put_user(init32.is_pci, &init->is_pci)
75 || __put_user(init32.cp_mode, &init->cp_mode)
76 || __put_user(init32.gart_size, &init->gart_size)
77 || __put_user(init32.ring_size, &init->ring_size)
78 || __put_user(init32.usec_timeout, &init->usec_timeout)
79 || __put_user(init32.fb_bpp, &init->fb_bpp)
80 || __put_user(init32.front_offset, &init->front_offset)
81 || __put_user(init32.front_pitch, &init->front_pitch)
82 || __put_user(init32.back_offset, &init->back_offset)
83 || __put_user(init32.back_pitch, &init->back_pitch)
84 || __put_user(init32.depth_bpp, &init->depth_bpp)
85 || __put_user(init32.depth_offset, &init->depth_offset)
86 || __put_user(init32.depth_pitch, &init->depth_pitch)
87 || __put_user(init32.fb_offset, &init->fb_offset)
88 || __put_user(init32.mmio_offset, &init->mmio_offset)
89 || __put_user(init32.ring_offset, &init->ring_offset)
90 || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
91 || __put_user(init32.buffers_offset, &init->buffers_offset)
92 || __put_user(init32.gart_textures_offset,
93 &init->gart_textures_offset))
94 return -EFAULT;
95
96 return drm_ioctl(file->f_dentry->d_inode, file,
97 DRM_IOCTL_RADEON_CP_INIT, (unsigned long) init);
98}
99
100typedef struct drm_radeon_clear32 {
101 unsigned int flags;
102 unsigned int clear_color;
103 unsigned int clear_depth;
104 unsigned int color_mask;
105 unsigned int depth_mask; /* misnamed field: should be stencil */
106 u32 depth_boxes;
107} drm_radeon_clear32_t;
108
109static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
110 unsigned long arg)
111{
112 drm_radeon_clear32_t clr32;
113 drm_radeon_clear_t __user *clr;
114
115 if (copy_from_user(&clr32, (void __user *)arg, sizeof(clr32)))
116 return -EFAULT;
117
118 clr = compat_alloc_user_space(sizeof(*clr));
119 if (!access_ok(VERIFY_WRITE, clr, sizeof(*clr))
120 || __put_user(clr32.flags, &clr->flags)
121 || __put_user(clr32.clear_color, &clr->clear_color)
122 || __put_user(clr32.clear_depth, &clr->clear_depth)
123 || __put_user(clr32.color_mask, &clr->color_mask)
124 || __put_user(clr32.depth_mask, &clr->depth_mask)
125 || __put_user((void __user *)(unsigned long)clr32.depth_boxes,
126 &clr->depth_boxes))
127 return -EFAULT;
128
129 return drm_ioctl(file->f_dentry->d_inode, file,
130 DRM_IOCTL_RADEON_CLEAR, (unsigned long) clr);
131}
132
133typedef struct drm_radeon_stipple32 {
134 u32 mask;
135} drm_radeon_stipple32_t;
136
137static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
138 unsigned long arg)
139{
140 drm_radeon_stipple32_t __user *argp = (void __user *) arg;
141 drm_radeon_stipple_t __user *request;
142 u32 mask;
143
144 if (get_user(mask, &argp->mask))
145 return -EFAULT;
146
147 request = compat_alloc_user_space(sizeof(*request));
148 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
149 || __put_user((unsigned int __user *)(unsigned long) mask,
150 &request->mask))
151 return -EFAULT;
152
153 return drm_ioctl(file->f_dentry->d_inode, file,
154 DRM_IOCTL_RADEON_STIPPLE, (unsigned long) request);
155}
156
157typedef struct drm_radeon_tex_image32 {
158 unsigned int x, y; /* Blit coordinates */
159 unsigned int width, height;
160 u32 data;
161} drm_radeon_tex_image32_t;
162
163typedef struct drm_radeon_texture32 {
164 unsigned int offset;
165 int pitch;
166 int format;
167 int width; /* Texture image coordinates */
168 int height;
169 u32 image;
170} drm_radeon_texture32_t;
171
172static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
173 unsigned long arg)
174{
175 drm_radeon_texture32_t req32;
176 drm_radeon_texture_t __user *request;
177 drm_radeon_tex_image32_t img32;
178 drm_radeon_tex_image_t __user *image;
179
180 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
181 return -EFAULT;
182 if (req32.image == 0)
183 return -EINVAL;
184 if (copy_from_user(&img32, (void __user *)(unsigned long)req32.image,
185 sizeof(img32)))
186 return -EFAULT;
187
188 request = compat_alloc_user_space(sizeof(*request) + sizeof(*image));
189 if (!access_ok(VERIFY_WRITE, request,
190 sizeof(*request) + sizeof(*image)))
191 return -EFAULT;
192 image = (drm_radeon_tex_image_t __user *) (request + 1);
193
194 if (__put_user(req32.offset, &request->offset)
195 || __put_user(req32.pitch, &request->pitch)
196 || __put_user(req32.format, &request->format)
197 || __put_user(req32.width, &request->width)
198 || __put_user(req32.height, &request->height)
199 || __put_user(image, &request->image)
200 || __put_user(img32.x, &image->x)
201 || __put_user(img32.y, &image->y)
202 || __put_user(img32.width, &image->width)
203 || __put_user(img32.height, &image->height)
204 || __put_user((const void __user *)(unsigned long)img32.data,
205 &image->data))
206 return -EFAULT;
207
208 return drm_ioctl(file->f_dentry->d_inode, file,
209 DRM_IOCTL_RADEON_TEXTURE, (unsigned long) request);
210}
211
212typedef struct drm_radeon_vertex2_32 {
213 int idx; /* Index of vertex buffer */
214 int discard; /* Client finished with buffer? */
215 int nr_states;
216 u32 state;
217 int nr_prims;
218 u32 prim;
219} drm_radeon_vertex2_32_t;
220
221static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
222 unsigned long arg)
223{
224 drm_radeon_vertex2_32_t req32;
225 drm_radeon_vertex2_t __user *request;
226
227 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
228 return -EFAULT;
229
230 request = compat_alloc_user_space(sizeof(*request));
231 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
232 || __put_user(req32.idx, &request->idx)
233 || __put_user(req32.discard, &request->discard)
234 || __put_user(req32.nr_states, &request->nr_states)
235 || __put_user((void __user *)(unsigned long)req32.state,
236 &request->state)
237 || __put_user(req32.nr_prims, &request->nr_prims)
238 || __put_user((void __user *)(unsigned long)req32.prim,
239 &request->prim))
240 return -EFAULT;
241
242 return drm_ioctl(file->f_dentry->d_inode, file,
243 DRM_IOCTL_RADEON_VERTEX2, (unsigned long) request);
244}
245
246typedef struct drm_radeon_cmd_buffer32 {
247 int bufsz;
248 u32 buf;
249 int nbox;
250 u32 boxes;
251} drm_radeon_cmd_buffer32_t;
252
253static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
254 unsigned long arg)
255{
256 drm_radeon_cmd_buffer32_t req32;
257 drm_radeon_cmd_buffer_t __user *request;
258
259 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
260 return -EFAULT;
261
262 request = compat_alloc_user_space(sizeof(*request));
263 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
264 || __put_user(req32.bufsz, &request->bufsz)
265 || __put_user((void __user *)(unsigned long)req32.buf,
266 &request->buf)
267 || __put_user(req32.nbox, &request->nbox)
268 || __put_user((void __user *)(unsigned long)req32.boxes,
269 &request->boxes))
270 return -EFAULT;
271
272 return drm_ioctl(file->f_dentry->d_inode, file,
273 DRM_IOCTL_RADEON_CMDBUF, (unsigned long) request);
274}
275
276typedef struct drm_radeon_getparam32 {
277 int param;
278 u32 value;
279} drm_radeon_getparam32_t;
280
281static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
282 unsigned long arg)
283{
284 drm_radeon_getparam32_t req32;
285 drm_radeon_getparam_t __user *request;
286
287 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
288 return -EFAULT;
289
290 request = compat_alloc_user_space(sizeof(*request));
291 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
292 || __put_user(req32.param, &request->param)
293 || __put_user((void __user *)(unsigned long)req32.value,
294 &request->value))
295 return -EFAULT;
296
297 return drm_ioctl(file->f_dentry->d_inode, file,
298 DRM_IOCTL_RADEON_GETPARAM, (unsigned long) request);
299}
300
301typedef struct drm_radeon_mem_alloc32 {
302 int region;
303 int alignment;
304 int size;
305 u32 region_offset; /* offset from start of fb or GART */
306} drm_radeon_mem_alloc32_t;
307
308static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
309 unsigned long arg)
310{
311 drm_radeon_mem_alloc32_t req32;
312 drm_radeon_mem_alloc_t __user *request;
313
314 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
315 return -EFAULT;
316
317 request = compat_alloc_user_space(sizeof(*request));
318 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
319 || __put_user(req32.region, &request->region)
320 || __put_user(req32.alignment, &request->alignment)
321 || __put_user(req32.size, &request->size)
322 || __put_user((int __user *)(unsigned long)req32.region_offset,
323 &request->region_offset))
324 return -EFAULT;
325
326 return drm_ioctl(file->f_dentry->d_inode, file,
327 DRM_IOCTL_RADEON_ALLOC, (unsigned long) request);
328}
329
330typedef struct drm_radeon_irq_emit32 {
331 u32 irq_seq;
332} drm_radeon_irq_emit32_t;
333
334static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
335 unsigned long arg)
336{
337 drm_radeon_irq_emit32_t req32;
338 drm_radeon_irq_emit_t __user *request;
339
340 if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
341 return -EFAULT;
342
343 request = compat_alloc_user_space(sizeof(*request));
344 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
345 || __put_user((int __user *)(unsigned long)req32.irq_seq,
346 &request->irq_seq))
347 return -EFAULT;
348
349 return drm_ioctl(file->f_dentry->d_inode, file,
350 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long) request);
351}
352
353drm_ioctl_compat_t *radeon_compat_ioctls[] = {
354 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
355 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
356 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
357 [DRM_RADEON_TEXTURE] = compat_radeon_cp_texture,
358 [DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
359 [DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
360 [DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
361 [DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
362 [DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
363};
364
365/**
366 * Called whenever a 32-bit process running under a 64-bit kernel
367 * performs an ioctl on /dev/dri/card<n>.
368 *
369 * \param filp file pointer.
370 * \param cmd command.
371 * \param arg user argument.
372 * \return zero on success or negative number on failure.
373 */
374long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
375 unsigned long arg)
376{
377 unsigned int nr = DRM_IOCTL_NR(cmd);
378 drm_ioctl_compat_t *fn = NULL;
379 int ret;
380
381 if (nr < DRM_COMMAND_BASE)
382 return drm_compat_ioctl(filp, cmd, arg);
383
384 if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
385 fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
386
387 lock_kernel(); /* XXX for now */
388 if (fn != NULL)
389 ret = (*fn)(filp, cmd, arg);
390 else
391 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
392 unlock_kernel();
393
394 return ret;
395}
diff --git a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
index cd25f28e26a3..40474a65f56d 100644
--- a/drivers/char/drm/radeon_irq.c
+++ b/drivers/char/drm/radeon_irq.c
@@ -35,6 +35,14 @@
35#include "radeon_drm.h" 35#include "radeon_drm.h"
36#include "radeon_drv.h" 36#include "radeon_drv.h"
37 37
38static __inline__ u32 radeon_acknowledge_irqs(drm_radeon_private_t *dev_priv, u32 mask)
39{
40 u32 irqs = RADEON_READ(RADEON_GEN_INT_STATUS) & mask;
41 if (irqs)
42 RADEON_WRITE(RADEON_GEN_INT_STATUS, irqs);
43 return irqs;
44}
45
38/* Interrupts - Used for device synchronization and flushing in the 46/* Interrupts - Used for device synchronization and flushing in the
39 * following circumstances: 47 * following circumstances:
40 * 48 *
@@ -63,8 +71,8 @@ irqreturn_t radeon_driver_irq_handler( DRM_IRQ_ARGS )
63 /* Only consider the bits we're interested in - others could be used 71 /* Only consider the bits we're interested in - others could be used
64 * outside the DRM 72 * outside the DRM
65 */ 73 */
66 stat = RADEON_READ(RADEON_GEN_INT_STATUS) 74 stat = radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
67 & (RADEON_SW_INT_TEST | RADEON_CRTC_VBLANK_STAT); 75 RADEON_CRTC_VBLANK_STAT));
68 if (!stat) 76 if (!stat)
69 return IRQ_NONE; 77 return IRQ_NONE;
70 78
@@ -80,19 +88,9 @@ irqreturn_t radeon_driver_irq_handler( DRM_IRQ_ARGS )
80 drm_vbl_send_signals( dev ); 88 drm_vbl_send_signals( dev );
81 } 89 }
82 90
83 /* Acknowledge interrupts we handle */
84 RADEON_WRITE(RADEON_GEN_INT_STATUS, stat);
85 return IRQ_HANDLED; 91 return IRQ_HANDLED;
86} 92}
87 93
88static __inline__ void radeon_acknowledge_irqs(drm_radeon_private_t *dev_priv)
89{
90 u32 tmp = RADEON_READ( RADEON_GEN_INT_STATUS )
91 & (RADEON_SW_INT_TEST_ACK | RADEON_CRTC_VBLANK_STAT);
92 if (tmp)
93 RADEON_WRITE( RADEON_GEN_INT_STATUS, tmp );
94}
95
96static int radeon_emit_irq(drm_device_t *dev) 94static int radeon_emit_irq(drm_device_t *dev)
97{ 95{
98 drm_radeon_private_t *dev_priv = dev->dev_private; 96 drm_radeon_private_t *dev_priv = dev->dev_private;
@@ -141,7 +139,7 @@ int radeon_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
141 return DRM_ERR(EINVAL); 139 return DRM_ERR(EINVAL);
142 } 140 }
143 141
144 radeon_acknowledge_irqs( dev_priv ); 142 radeon_acknowledge_irqs(dev_priv, RADEON_CRTC_VBLANK_STAT);
145 143
146 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; 144 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
147 145
@@ -219,7 +217,8 @@ void radeon_driver_irq_preinstall( drm_device_t *dev ) {
219 RADEON_WRITE( RADEON_GEN_INT_CNTL, 0 ); 217 RADEON_WRITE( RADEON_GEN_INT_CNTL, 0 );
220 218
221 /* Clear bits if they're already high */ 219 /* Clear bits if they're already high */
222 radeon_acknowledge_irqs( dev_priv ); 220 radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
221 RADEON_CRTC_VBLANK_STAT));
223} 222}
224 223
225void radeon_driver_irq_postinstall( drm_device_t *dev ) { 224void radeon_driver_irq_postinstall( drm_device_t *dev ) {
diff --git a/drivers/char/drm/via_3d_reg.h b/drivers/char/drm/via_3d_reg.h
new file mode 100644
index 000000000000..cf61bb514db1
--- /dev/null
+++ b/drivers/char/drm/via_3d_reg.h
@@ -0,0 +1,1651 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef VIA_3D_REG_H
26#define VIA_3D_REG_H
27#define HC_REG_BASE 0x0400
28
29#define HC_REG_TRANS_SPACE 0x0040
30
31#define HC_ParaN_MASK 0xffffffff
32#define HC_Para_MASK 0x00ffffff
33#define HC_SubA_MASK 0xff000000
34#define HC_SubA_SHIFT 24
35/* Transmission Setting
36 */
37#define HC_REG_TRANS_SET 0x003c
38#define HC_ParaSubType_MASK 0xff000000
39#define HC_ParaType_MASK 0x00ff0000
40#define HC_ParaOS_MASK 0x0000ff00
41#define HC_ParaAdr_MASK 0x000000ff
42#define HC_ParaSubType_SHIFT 24
43#define HC_ParaType_SHIFT 16
44#define HC_ParaOS_SHIFT 8
45#define HC_ParaAdr_SHIFT 0
46
47#define HC_ParaType_CmdVdata 0x0000
48#define HC_ParaType_NotTex 0x0001
49#define HC_ParaType_Tex 0x0002
50#define HC_ParaType_Palette 0x0003
51#define HC_ParaType_PreCR 0x0010
52#define HC_ParaType_Auto 0x00fe
53
54/* Transmission Space
55 */
56#define HC_REG_Hpara0 0x0040
57#define HC_REG_HpataAF 0x02fc
58
59/* Read
60 */
61#define HC_REG_HREngSt 0x0000
62#define HC_REG_HRFIFOempty 0x0004
63#define HC_REG_HRFIFOfull 0x0008
64#define HC_REG_HRErr 0x000c
65#define HC_REG_FIFOstatus 0x0010
66/* HC_REG_HREngSt 0x0000
67 */
68#define HC_HDASZC_MASK 0x00010000
69#define HC_HSGEMI_MASK 0x0000f000
70#define HC_HLGEMISt_MASK 0x00000f00
71#define HC_HCRSt_MASK 0x00000080
72#define HC_HSE0St_MASK 0x00000040
73#define HC_HSE1St_MASK 0x00000020
74#define HC_HPESt_MASK 0x00000010
75#define HC_HXESt_MASK 0x00000008
76#define HC_HBESt_MASK 0x00000004
77#define HC_HE2St_MASK 0x00000002
78#define HC_HE3St_MASK 0x00000001
79/* HC_REG_HRFIFOempty 0x0004
80 */
81#define HC_HRZDempty_MASK 0x00000010
82#define HC_HRTXAempty_MASK 0x00000008
83#define HC_HRTXDempty_MASK 0x00000004
84#define HC_HWZDempty_MASK 0x00000002
85#define HC_HWCDempty_MASK 0x00000001
86/* HC_REG_HRFIFOfull 0x0008
87 */
88#define HC_HRZDfull_MASK 0x00000010
89#define HC_HRTXAfull_MASK 0x00000008
90#define HC_HRTXDfull_MASK 0x00000004
91#define HC_HWZDfull_MASK 0x00000002
92#define HC_HWCDfull_MASK 0x00000001
93/* HC_REG_HRErr 0x000c
94 */
95#define HC_HAGPCMErr_MASK 0x80000000
96#define HC_HAGPCMErrC_MASK 0x70000000
97/* HC_REG_FIFOstatus 0x0010
98 */
99#define HC_HRFIFOATall_MASK 0x80000000
100#define HC_HRFIFOATbusy_MASK 0x40000000
101#define HC_HRATFGMDo_MASK 0x00000100
102#define HC_HRATFGMDi_MASK 0x00000080
103#define HC_HRATFRZD_MASK 0x00000040
104#define HC_HRATFRTXA_MASK 0x00000020
105#define HC_HRATFRTXD_MASK 0x00000010
106#define HC_HRATFWZD_MASK 0x00000008
107#define HC_HRATFWCD_MASK 0x00000004
108#define HC_HRATTXTAG_MASK 0x00000002
109#define HC_HRATTXCH_MASK 0x00000001
110
111/* AGP Command Setting
112 */
113#define HC_SubA_HAGPBstL 0x0060
114#define HC_SubA_HAGPBendL 0x0061
115#define HC_SubA_HAGPCMNT 0x0062
116#define HC_SubA_HAGPBpL 0x0063
117#define HC_SubA_HAGPBpH 0x0064
118/* HC_SubA_HAGPCMNT 0x0062
119 */
120#define HC_HAGPCMNT_MASK 0x00800000
121#define HC_HCmdErrClr_MASK 0x00400000
122#define HC_HAGPBendH_MASK 0x0000ff00
123#define HC_HAGPBstH_MASK 0x000000ff
124#define HC_HAGPBendH_SHIFT 8
125#define HC_HAGPBstH_SHIFT 0
126/* HC_SubA_HAGPBpL 0x0063
127 */
128#define HC_HAGPBpL_MASK 0x00fffffc
129#define HC_HAGPBpID_MASK 0x00000003
130#define HC_HAGPBpID_PAUSE 0x00000000
131#define HC_HAGPBpID_JUMP 0x00000001
132#define HC_HAGPBpID_STOP 0x00000002
133/* HC_SubA_HAGPBpH 0x0064
134 */
135#define HC_HAGPBpH_MASK 0x00ffffff
136
137/* Miscellaneous Settings
138 */
139#define HC_SubA_HClipTB 0x0070
140#define HC_SubA_HClipLR 0x0071
141#define HC_SubA_HFPClipTL 0x0072
142#define HC_SubA_HFPClipBL 0x0073
143#define HC_SubA_HFPClipLL 0x0074
144#define HC_SubA_HFPClipRL 0x0075
145#define HC_SubA_HFPClipTBH 0x0076
146#define HC_SubA_HFPClipLRH 0x0077
147#define HC_SubA_HLP 0x0078
148#define HC_SubA_HLPRF 0x0079
149#define HC_SubA_HSolidCL 0x007a
150#define HC_SubA_HPixGC 0x007b
151#define HC_SubA_HSPXYOS 0x007c
152#define HC_SubA_HVertexCNT 0x007d
153
154#define HC_HClipT_MASK 0x00fff000
155#define HC_HClipT_SHIFT 12
156#define HC_HClipB_MASK 0x00000fff
157#define HC_HClipB_SHIFT 0
158#define HC_HClipL_MASK 0x00fff000
159#define HC_HClipL_SHIFT 12
160#define HC_HClipR_MASK 0x00000fff
161#define HC_HClipR_SHIFT 0
162#define HC_HFPClipBH_MASK 0x0000ff00
163#define HC_HFPClipBH_SHIFT 8
164#define HC_HFPClipTH_MASK 0x000000ff
165#define HC_HFPClipTH_SHIFT 0
166#define HC_HFPClipRH_MASK 0x0000ff00
167#define HC_HFPClipRH_SHIFT 8
168#define HC_HFPClipLH_MASK 0x000000ff
169#define HC_HFPClipLH_SHIFT 0
170#define HC_HSolidCH_MASK 0x000000ff
171#define HC_HPixGC_MASK 0x00800000
172#define HC_HSPXOS_MASK 0x00fff000
173#define HC_HSPXOS_SHIFT 12
174#define HC_HSPYOS_MASK 0x00000fff
175
176/* Command
177 * Command A
178 */
179#define HC_HCmdHeader_MASK 0xfe000000 /*0xffe00000 */
180#define HC_HE3Fire_MASK 0x00100000
181#define HC_HPMType_MASK 0x000f0000
182#define HC_HEFlag_MASK 0x0000e000
183#define HC_HShading_MASK 0x00001c00
184#define HC_HPMValidN_MASK 0x00000200
185#define HC_HPLEND_MASK 0x00000100
186#define HC_HVCycle_MASK 0x000000ff
187#define HC_HVCycle_Style_MASK 0x000000c0
188#define HC_HVCycle_ChgA_MASK 0x00000030
189#define HC_HVCycle_ChgB_MASK 0x0000000c
190#define HC_HVCycle_ChgC_MASK 0x00000003
191#define HC_HPMType_Point 0x00000000
192#define HC_HPMType_Line 0x00010000
193#define HC_HPMType_Tri 0x00020000
194#define HC_HPMType_TriWF 0x00040000
195#define HC_HEFlag_NoAA 0x00000000
196#define HC_HEFlag_ab 0x00008000
197#define HC_HEFlag_bc 0x00004000
198#define HC_HEFlag_ca 0x00002000
199#define HC_HShading_Solid 0x00000000
200#define HC_HShading_FlatA 0x00000400
201#define HC_HShading_FlatB 0x00000800
202#define HC_HShading_FlatC 0x00000c00
203#define HC_HShading_Gouraud 0x00001000
204#define HC_HVCycle_Full 0x00000000
205#define HC_HVCycle_AFP 0x00000040
206#define HC_HVCycle_One 0x000000c0
207#define HC_HVCycle_NewA 0x00000000
208#define HC_HVCycle_AA 0x00000010
209#define HC_HVCycle_AB 0x00000020
210#define HC_HVCycle_AC 0x00000030
211#define HC_HVCycle_NewB 0x00000000
212#define HC_HVCycle_BA 0x00000004
213#define HC_HVCycle_BB 0x00000008
214#define HC_HVCycle_BC 0x0000000c
215#define HC_HVCycle_NewC 0x00000000
216#define HC_HVCycle_CA 0x00000001
217#define HC_HVCycle_CB 0x00000002
218#define HC_HVCycle_CC 0x00000003
219
220/* Command B
221 */
222#define HC_HLPrst_MASK 0x00010000
223#define HC_HLLastP_MASK 0x00008000
224#define HC_HVPMSK_MASK 0x00007f80
225#define HC_HBFace_MASK 0x00000040
226#define HC_H2nd1VT_MASK 0x0000003f
227#define HC_HVPMSK_X 0x00004000
228#define HC_HVPMSK_Y 0x00002000
229#define HC_HVPMSK_Z 0x00001000
230#define HC_HVPMSK_W 0x00000800
231#define HC_HVPMSK_Cd 0x00000400
232#define HC_HVPMSK_Cs 0x00000200
233#define HC_HVPMSK_S 0x00000100
234#define HC_HVPMSK_T 0x00000080
235
236/* Enable Setting
237 */
238#define HC_SubA_HEnable 0x0000
239#define HC_HenTXEnvMap_MASK 0x00200000
240#define HC_HenVertexCNT_MASK 0x00100000
241#define HC_HenCPUDAZ_MASK 0x00080000
242#define HC_HenDASZWC_MASK 0x00040000
243#define HC_HenFBCull_MASK 0x00020000
244#define HC_HenCW_MASK 0x00010000
245#define HC_HenAA_MASK 0x00008000
246#define HC_HenST_MASK 0x00004000
247#define HC_HenZT_MASK 0x00002000
248#define HC_HenZW_MASK 0x00001000
249#define HC_HenAT_MASK 0x00000800
250#define HC_HenAW_MASK 0x00000400
251#define HC_HenSP_MASK 0x00000200
252#define HC_HenLP_MASK 0x00000100
253#define HC_HenTXCH_MASK 0x00000080
254#define HC_HenTXMP_MASK 0x00000040
255#define HC_HenTXPP_MASK 0x00000020
256#define HC_HenTXTR_MASK 0x00000010
257#define HC_HenCS_MASK 0x00000008
258#define HC_HenFOG_MASK 0x00000004
259#define HC_HenABL_MASK 0x00000002
260#define HC_HenDT_MASK 0x00000001
261
262/* Z Setting
263 */
264#define HC_SubA_HZWBBasL 0x0010
265#define HC_SubA_HZWBBasH 0x0011
266#define HC_SubA_HZWBType 0x0012
267#define HC_SubA_HZBiasL 0x0013
268#define HC_SubA_HZWBend 0x0014
269#define HC_SubA_HZWTMD 0x0015
270#define HC_SubA_HZWCDL 0x0016
271#define HC_SubA_HZWCTAGnum 0x0017
272#define HC_SubA_HZCYNum 0x0018
273#define HC_SubA_HZWCFire 0x0019
274/* HC_SubA_HZWBType
275 */
276#define HC_HZWBType_MASK 0x00800000
277#define HC_HZBiasedWB_MASK 0x00400000
278#define HC_HZONEasFF_MASK 0x00200000
279#define HC_HZOONEasFF_MASK 0x00100000
280#define HC_HZWBFM_MASK 0x00030000
281#define HC_HZWBLoc_MASK 0x0000c000
282#define HC_HZWBPit_MASK 0x00003fff
283#define HC_HZWBFM_16 0x00000000
284#define HC_HZWBFM_32 0x00020000
285#define HC_HZWBFM_24 0x00030000
286#define HC_HZWBLoc_Local 0x00000000
287#define HC_HZWBLoc_SyS 0x00004000
288/* HC_SubA_HZWBend
289 */
290#define HC_HZWBend_MASK 0x00ffe000
291#define HC_HZBiasH_MASK 0x000000ff
292#define HC_HZWBend_SHIFT 10
293/* HC_SubA_HZWTMD
294 */
295#define HC_HZWTMD_MASK 0x00070000
296#define HC_HEBEBias_MASK 0x00007f00
297#define HC_HZNF_MASK 0x000000ff
298#define HC_HZWTMD_NeverPass 0x00000000
299#define HC_HZWTMD_LT 0x00010000
300#define HC_HZWTMD_EQ 0x00020000
301#define HC_HZWTMD_LE 0x00030000
302#define HC_HZWTMD_GT 0x00040000
303#define HC_HZWTMD_NE 0x00050000
304#define HC_HZWTMD_GE 0x00060000
305#define HC_HZWTMD_AllPass 0x00070000
306#define HC_HEBEBias_SHIFT 8
307/* HC_SubA_HZWCDL 0x0016
308 */
309#define HC_HZWCDL_MASK 0x00ffffff
310/* HC_SubA_HZWCTAGnum 0x0017
311 */
312#define HC_HZWCTAGnum_MASK 0x00ff0000
313#define HC_HZWCTAGnum_SHIFT 16
314#define HC_HZWCDH_MASK 0x000000ff
315#define HC_HZWCDH_SHIFT 0
316/* HC_SubA_HZCYNum 0x0018
317 */
318#define HC_HZCYNum_MASK 0x00030000
319#define HC_HZCYNum_SHIFT 16
320#define HC_HZWCQWnum_MASK 0x00003fff
321#define HC_HZWCQWnum_SHIFT 0
322/* HC_SubA_HZWCFire 0x0019
323 */
324#define HC_ZWCFire_MASK 0x00010000
325#define HC_HZWCQWnumLast_MASK 0x00003fff
326#define HC_HZWCQWnumLast_SHIFT 0
327
328/* Stencil Setting
329 */
330#define HC_SubA_HSTREF 0x0023
331#define HC_SubA_HSTMD 0x0024
332/* HC_SubA_HSBFM
333 */
334#define HC_HSBFM_MASK 0x00030000
335#define HC_HSBLoc_MASK 0x0000c000
336#define HC_HSBPit_MASK 0x00003fff
337/* HC_SubA_HSTREF
338 */
339#define HC_HSTREF_MASK 0x00ff0000
340#define HC_HSTOPMSK_MASK 0x0000ff00
341#define HC_HSTBMSK_MASK 0x000000ff
342#define HC_HSTREF_SHIFT 16
343#define HC_HSTOPMSK_SHIFT 8
344/* HC_SubA_HSTMD
345 */
346#define HC_HSTMD_MASK 0x00070000
347#define HC_HSTOPSF_MASK 0x000001c0
348#define HC_HSTOPSPZF_MASK 0x00000038
349#define HC_HSTOPSPZP_MASK 0x00000007
350#define HC_HSTMD_NeverPass 0x00000000
351#define HC_HSTMD_LT 0x00010000
352#define HC_HSTMD_EQ 0x00020000
353#define HC_HSTMD_LE 0x00030000
354#define HC_HSTMD_GT 0x00040000
355#define HC_HSTMD_NE 0x00050000
356#define HC_HSTMD_GE 0x00060000
357#define HC_HSTMD_AllPass 0x00070000
358#define HC_HSTOPSF_KEEP 0x00000000
359#define HC_HSTOPSF_ZERO 0x00000040
360#define HC_HSTOPSF_REPLACE 0x00000080
361#define HC_HSTOPSF_INCRSAT 0x000000c0
362#define HC_HSTOPSF_DECRSAT 0x00000100
363#define HC_HSTOPSF_INVERT 0x00000140
364#define HC_HSTOPSF_INCR 0x00000180
365#define HC_HSTOPSF_DECR 0x000001c0
366#define HC_HSTOPSPZF_KEEP 0x00000000
367#define HC_HSTOPSPZF_ZERO 0x00000008
368#define HC_HSTOPSPZF_REPLACE 0x00000010
369#define HC_HSTOPSPZF_INCRSAT 0x00000018
370#define HC_HSTOPSPZF_DECRSAT 0x00000020
371#define HC_HSTOPSPZF_INVERT 0x00000028
372#define HC_HSTOPSPZF_INCR 0x00000030
373#define HC_HSTOPSPZF_DECR 0x00000038
374#define HC_HSTOPSPZP_KEEP 0x00000000
375#define HC_HSTOPSPZP_ZERO 0x00000001
376#define HC_HSTOPSPZP_REPLACE 0x00000002
377#define HC_HSTOPSPZP_INCRSAT 0x00000003
378#define HC_HSTOPSPZP_DECRSAT 0x00000004
379#define HC_HSTOPSPZP_INVERT 0x00000005
380#define HC_HSTOPSPZP_INCR 0x00000006
381#define HC_HSTOPSPZP_DECR 0x00000007
382
383/* Alpha Setting
384 */
385#define HC_SubA_HABBasL 0x0030
386#define HC_SubA_HABBasH 0x0031
387#define HC_SubA_HABFM 0x0032
388#define HC_SubA_HATMD 0x0033
389#define HC_SubA_HABLCsat 0x0034
390#define HC_SubA_HABLCop 0x0035
391#define HC_SubA_HABLAsat 0x0036
392#define HC_SubA_HABLAop 0x0037
393#define HC_SubA_HABLRCa 0x0038
394#define HC_SubA_HABLRFCa 0x0039
395#define HC_SubA_HABLRCbias 0x003a
396#define HC_SubA_HABLRCb 0x003b
397#define HC_SubA_HABLRFCb 0x003c
398#define HC_SubA_HABLRAa 0x003d
399#define HC_SubA_HABLRAb 0x003e
400/* HC_SubA_HABFM
401 */
402#define HC_HABFM_MASK 0x00030000
403#define HC_HABLoc_MASK 0x0000c000
404#define HC_HABPit_MASK 0x000007ff
405/* HC_SubA_HATMD
406 */
407#define HC_HATMD_MASK 0x00000700
408#define HC_HATREF_MASK 0x000000ff
409#define HC_HATMD_NeverPass 0x00000000
410#define HC_HATMD_LT 0x00000100
411#define HC_HATMD_EQ 0x00000200
412#define HC_HATMD_LE 0x00000300
413#define HC_HATMD_GT 0x00000400
414#define HC_HATMD_NE 0x00000500
415#define HC_HATMD_GE 0x00000600
416#define HC_HATMD_AllPass 0x00000700
417/* HC_SubA_HABLCsat
418 */
419#define HC_HABLCsat_MASK 0x00010000
420#define HC_HABLCa_MASK 0x0000fc00
421#define HC_HABLCa_C_MASK 0x0000c000
422#define HC_HABLCa_OPC_MASK 0x00003c00
423#define HC_HABLFCa_MASK 0x000003f0
424#define HC_HABLFCa_C_MASK 0x00000300
425#define HC_HABLFCa_OPC_MASK 0x000000f0
426#define HC_HABLCbias_MASK 0x0000000f
427#define HC_HABLCbias_C_MASK 0x00000008
428#define HC_HABLCbias_OPC_MASK 0x00000007
429/*-- Define the input color.
430 */
431#define HC_XC_Csrc 0x00000000
432#define HC_XC_Cdst 0x00000001
433#define HC_XC_Asrc 0x00000002
434#define HC_XC_Adst 0x00000003
435#define HC_XC_Fog 0x00000004
436#define HC_XC_HABLRC 0x00000005
437#define HC_XC_minSrcDst 0x00000006
438#define HC_XC_maxSrcDst 0x00000007
439#define HC_XC_mimAsrcInvAdst 0x00000008
440#define HC_XC_OPC 0x00000000
441#define HC_XC_InvOPC 0x00000010
442#define HC_XC_OPCp5 0x00000020
443/*-- Define the input Alpha
444 */
445#define HC_XA_OPA 0x00000000
446#define HC_XA_InvOPA 0x00000010
447#define HC_XA_OPAp5 0x00000020
448#define HC_XA_0 0x00000000
449#define HC_XA_Asrc 0x00000001
450#define HC_XA_Adst 0x00000002
451#define HC_XA_Fog 0x00000003
452#define HC_XA_minAsrcFog 0x00000004
453#define HC_XA_minAsrcAdst 0x00000005
454#define HC_XA_maxAsrcFog 0x00000006
455#define HC_XA_maxAsrcAdst 0x00000007
456#define HC_XA_HABLRA 0x00000008
457#define HC_XA_minAsrcInvAdst 0x00000008
458#define HC_XA_HABLFRA 0x00000009
459/*--
460 */
461#define HC_HABLCa_OPC (HC_XC_OPC << 10)
462#define HC_HABLCa_InvOPC (HC_XC_InvOPC << 10)
463#define HC_HABLCa_OPCp5 (HC_XC_OPCp5 << 10)
464#define HC_HABLCa_Csrc (HC_XC_Csrc << 10)
465#define HC_HABLCa_Cdst (HC_XC_Cdst << 10)
466#define HC_HABLCa_Asrc (HC_XC_Asrc << 10)
467#define HC_HABLCa_Adst (HC_XC_Adst << 10)
468#define HC_HABLCa_Fog (HC_XC_Fog << 10)
469#define HC_HABLCa_HABLRCa (HC_XC_HABLRC << 10)
470#define HC_HABLCa_minSrcDst (HC_XC_minSrcDst << 10)
471#define HC_HABLCa_maxSrcDst (HC_XC_maxSrcDst << 10)
472#define HC_HABLFCa_OPC (HC_XC_OPC << 4)
473#define HC_HABLFCa_InvOPC (HC_XC_InvOPC << 4)
474#define HC_HABLFCa_OPCp5 (HC_XC_OPCp5 << 4)
475#define HC_HABLFCa_Csrc (HC_XC_Csrc << 4)
476#define HC_HABLFCa_Cdst (HC_XC_Cdst << 4)
477#define HC_HABLFCa_Asrc (HC_XC_Asrc << 4)
478#define HC_HABLFCa_Adst (HC_XC_Adst << 4)
479#define HC_HABLFCa_Fog (HC_XC_Fog << 4)
480#define HC_HABLFCa_HABLRCa (HC_XC_HABLRC << 4)
481#define HC_HABLFCa_minSrcDst (HC_XC_minSrcDst << 4)
482#define HC_HABLFCa_maxSrcDst (HC_XC_maxSrcDst << 4)
483#define HC_HABLFCa_mimAsrcInvAdst (HC_XC_mimAsrcInvAdst << 4)
484#define HC_HABLCbias_HABLRCbias 0x00000000
485#define HC_HABLCbias_Asrc 0x00000001
486#define HC_HABLCbias_Adst 0x00000002
487#define HC_HABLCbias_Fog 0x00000003
488#define HC_HABLCbias_Cin 0x00000004
489/* HC_SubA_HABLCop 0x0035
490 */
491#define HC_HABLdot_MASK 0x00010000
492#define HC_HABLCop_MASK 0x00004000
493#define HC_HABLCb_MASK 0x00003f00
494#define HC_HABLCb_C_MASK 0x00003000
495#define HC_HABLCb_OPC_MASK 0x00000f00
496#define HC_HABLFCb_MASK 0x000000fc
497#define HC_HABLFCb_C_MASK 0x000000c0
498#define HC_HABLFCb_OPC_MASK 0x0000003c
499#define HC_HABLCshift_MASK 0x00000003
500#define HC_HABLCb_OPC (HC_XC_OPC << 8)
501#define HC_HABLCb_InvOPC (HC_XC_InvOPC << 8)
502#define HC_HABLCb_OPCp5 (HC_XC_OPCp5 << 8)
503#define HC_HABLCb_Csrc (HC_XC_Csrc << 8)
504#define HC_HABLCb_Cdst (HC_XC_Cdst << 8)
505#define HC_HABLCb_Asrc (HC_XC_Asrc << 8)
506#define HC_HABLCb_Adst (HC_XC_Adst << 8)
507#define HC_HABLCb_Fog (HC_XC_Fog << 8)
508#define HC_HABLCb_HABLRCa (HC_XC_HABLRC << 8)
509#define HC_HABLCb_minSrcDst (HC_XC_minSrcDst << 8)
510#define HC_HABLCb_maxSrcDst (HC_XC_maxSrcDst << 8)
511#define HC_HABLFCb_OPC (HC_XC_OPC << 2)
512#define HC_HABLFCb_InvOPC (HC_XC_InvOPC << 2)
513#define HC_HABLFCb_OPCp5 (HC_XC_OPCp5 << 2)
514#define HC_HABLFCb_Csrc (HC_XC_Csrc << 2)
515#define HC_HABLFCb_Cdst (HC_XC_Cdst << 2)
516#define HC_HABLFCb_Asrc (HC_XC_Asrc << 2)
517#define HC_HABLFCb_Adst (HC_XC_Adst << 2)
518#define HC_HABLFCb_Fog (HC_XC_Fog << 2)
519#define HC_HABLFCb_HABLRCb (HC_XC_HABLRC << 2)
520#define HC_HABLFCb_minSrcDst (HC_XC_minSrcDst << 2)
521#define HC_HABLFCb_maxSrcDst (HC_XC_maxSrcDst << 2)
522#define HC_HABLFCb_mimAsrcInvAdst (HC_XC_mimAsrcInvAdst << 2)
523/* HC_SubA_HABLAsat 0x0036
524 */
525#define HC_HABLAsat_MASK 0x00010000
526#define HC_HABLAa_MASK 0x0000fc00
527#define HC_HABLAa_A_MASK 0x0000c000
528#define HC_HABLAa_OPA_MASK 0x00003c00
529#define HC_HABLFAa_MASK 0x000003f0
530#define HC_HABLFAa_A_MASK 0x00000300
531#define HC_HABLFAa_OPA_MASK 0x000000f0
532#define HC_HABLAbias_MASK 0x0000000f
533#define HC_HABLAbias_A_MASK 0x00000008
534#define HC_HABLAbias_OPA_MASK 0x00000007
535#define HC_HABLAa_OPA (HC_XA_OPA << 10)
536#define HC_HABLAa_InvOPA (HC_XA_InvOPA << 10)
537#define HC_HABLAa_OPAp5 (HC_XA_OPAp5 << 10)
538#define HC_HABLAa_0 (HC_XA_0 << 10)
539#define HC_HABLAa_Asrc (HC_XA_Asrc << 10)
540#define HC_HABLAa_Adst (HC_XA_Adst << 10)
541#define HC_HABLAa_Fog (HC_XA_Fog << 10)
542#define HC_HABLAa_minAsrcFog (HC_XA_minAsrcFog << 10)
543#define HC_HABLAa_minAsrcAdst (HC_XA_minAsrcAdst << 10)
544#define HC_HABLAa_maxAsrcFog (HC_XA_maxAsrcFog << 10)
545#define HC_HABLAa_maxAsrcAdst (HC_XA_maxAsrcAdst << 10)
546#define HC_HABLAa_HABLRA (HC_XA_HABLRA << 10)
547#define HC_HABLFAa_OPA (HC_XA_OPA << 4)
548#define HC_HABLFAa_InvOPA (HC_XA_InvOPA << 4)
549#define HC_HABLFAa_OPAp5 (HC_XA_OPAp5 << 4)
550#define HC_HABLFAa_0 (HC_XA_0 << 4)
551#define HC_HABLFAa_Asrc (HC_XA_Asrc << 4)
552#define HC_HABLFAa_Adst (HC_XA_Adst << 4)
553#define HC_HABLFAa_Fog (HC_XA_Fog << 4)
554#define HC_HABLFAa_minAsrcFog (HC_XA_minAsrcFog << 4)
555#define HC_HABLFAa_minAsrcAdst (HC_XA_minAsrcAdst << 4)
556#define HC_HABLFAa_maxAsrcFog (HC_XA_maxAsrcFog << 4)
557#define HC_HABLFAa_maxAsrcAdst (HC_XA_maxAsrcAdst << 4)
558#define HC_HABLFAa_minAsrcInvAdst (HC_XA_minAsrcInvAdst << 4)
559#define HC_HABLFAa_HABLFRA (HC_XA_HABLFRA << 4)
560#define HC_HABLAbias_HABLRAbias 0x00000000
561#define HC_HABLAbias_Asrc 0x00000001
562#define HC_HABLAbias_Adst 0x00000002
563#define HC_HABLAbias_Fog 0x00000003
564#define HC_HABLAbias_Aaa 0x00000004
565/* HC_SubA_HABLAop 0x0037
566 */
567#define HC_HABLAop_MASK 0x00004000
568#define HC_HABLAb_MASK 0x00003f00
569#define HC_HABLAb_OPA_MASK 0x00000f00
570#define HC_HABLFAb_MASK 0x000000fc
571#define HC_HABLFAb_OPA_MASK 0x0000003c
572#define HC_HABLAshift_MASK 0x00000003
573#define HC_HABLAb_OPA (HC_XA_OPA << 8)
574#define HC_HABLAb_InvOPA (HC_XA_InvOPA << 8)
575#define HC_HABLAb_OPAp5 (HC_XA_OPAp5 << 8)
576#define HC_HABLAb_0 (HC_XA_0 << 8)
577#define HC_HABLAb_Asrc (HC_XA_Asrc << 8)
578#define HC_HABLAb_Adst (HC_XA_Adst << 8)
579#define HC_HABLAb_Fog (HC_XA_Fog << 8)
580#define HC_HABLAb_minAsrcFog (HC_XA_minAsrcFog << 8)
581#define HC_HABLAb_minAsrcAdst (HC_XA_minAsrcAdst << 8)
582#define HC_HABLAb_maxAsrcFog (HC_XA_maxAsrcFog << 8)
583#define HC_HABLAb_maxAsrcAdst (HC_XA_maxAsrcAdst << 8)
584#define HC_HABLAb_HABLRA (HC_XA_HABLRA << 8)
585#define HC_HABLFAb_OPA (HC_XA_OPA << 2)
586#define HC_HABLFAb_InvOPA (HC_XA_InvOPA << 2)
587#define HC_HABLFAb_OPAp5 (HC_XA_OPAp5 << 2)
588#define HC_HABLFAb_0 (HC_XA_0 << 2)
589#define HC_HABLFAb_Asrc (HC_XA_Asrc << 2)
590#define HC_HABLFAb_Adst (HC_XA_Adst << 2)
591#define HC_HABLFAb_Fog (HC_XA_Fog << 2)
592#define HC_HABLFAb_minAsrcFog (HC_XA_minAsrcFog << 2)
593#define HC_HABLFAb_minAsrcAdst (HC_XA_minAsrcAdst << 2)
594#define HC_HABLFAb_maxAsrcFog (HC_XA_maxAsrcFog << 2)
595#define HC_HABLFAb_maxAsrcAdst (HC_XA_maxAsrcAdst << 2)
596#define HC_HABLFAb_minAsrcInvAdst (HC_XA_minAsrcInvAdst << 2)
597#define HC_HABLFAb_HABLFRA (HC_XA_HABLFRA << 2)
598/* HC_SubA_HABLRAa 0x003d
599 */
600#define HC_HABLRAa_MASK 0x00ff0000
601#define HC_HABLRFAa_MASK 0x0000ff00
602#define HC_HABLRAbias_MASK 0x000000ff
603#define HC_HABLRAa_SHIFT 16
604#define HC_HABLRFAa_SHIFT 8
605/* HC_SubA_HABLRAb 0x003e
606 */
607#define HC_HABLRAb_MASK 0x0000ff00
608#define HC_HABLRFAb_MASK 0x000000ff
609#define HC_HABLRAb_SHIFT 8
610
611/* Destination Setting
612 */
613#define HC_SubA_HDBBasL 0x0040
614#define HC_SubA_HDBBasH 0x0041
615#define HC_SubA_HDBFM 0x0042
616#define HC_SubA_HFBBMSKL 0x0043
617#define HC_SubA_HROP 0x0044
618/* HC_SubA_HDBFM 0x0042
619 */
620#define HC_HDBFM_MASK 0x001f0000
621#define HC_HDBLoc_MASK 0x0000c000
622#define HC_HDBPit_MASK 0x00003fff
623#define HC_HDBFM_RGB555 0x00000000
624#define HC_HDBFM_RGB565 0x00010000
625#define HC_HDBFM_ARGB4444 0x00020000
626#define HC_HDBFM_ARGB1555 0x00030000
627#define HC_HDBFM_BGR555 0x00040000
628#define HC_HDBFM_BGR565 0x00050000
629#define HC_HDBFM_ABGR4444 0x00060000
630#define HC_HDBFM_ABGR1555 0x00070000
631#define HC_HDBFM_ARGB0888 0x00080000
632#define HC_HDBFM_ARGB8888 0x00090000
633#define HC_HDBFM_ABGR0888 0x000a0000
634#define HC_HDBFM_ABGR8888 0x000b0000
635#define HC_HDBLoc_Local 0x00000000
636#define HC_HDBLoc_Sys 0x00004000
637/* HC_SubA_HROP 0x0044
638 */
639#define HC_HROP_MASK 0x00000f00
640#define HC_HFBBMSKH_MASK 0x000000ff
641#define HC_HROP_BLACK 0x00000000
642#define HC_HROP_DPon 0x00000100
643#define HC_HROP_DPna 0x00000200
644#define HC_HROP_Pn 0x00000300
645#define HC_HROP_PDna 0x00000400
646#define HC_HROP_Dn 0x00000500
647#define HC_HROP_DPx 0x00000600
648#define HC_HROP_DPan 0x00000700
649#define HC_HROP_DPa 0x00000800
650#define HC_HROP_DPxn 0x00000900
651#define HC_HROP_D 0x00000a00
652#define HC_HROP_DPno 0x00000b00
653#define HC_HROP_P 0x00000c00
654#define HC_HROP_PDno 0x00000d00
655#define HC_HROP_DPo 0x00000e00
656#define HC_HROP_WHITE 0x00000f00
657
658/* Fog Setting
659 */
660#define HC_SubA_HFogLF 0x0050
661#define HC_SubA_HFogCL 0x0051
662#define HC_SubA_HFogCH 0x0052
663#define HC_SubA_HFogStL 0x0053
664#define HC_SubA_HFogStH 0x0054
665#define HC_SubA_HFogOOdMF 0x0055
666#define HC_SubA_HFogOOdEF 0x0056
667#define HC_SubA_HFogEndL 0x0057
668#define HC_SubA_HFogDenst 0x0058
669/* HC_SubA_FogLF 0x0050
670 */
671#define HC_FogLF_MASK 0x00000010
672#define HC_FogEq_MASK 0x00000008
673#define HC_FogMD_MASK 0x00000007
674#define HC_FogMD_LocalFog 0x00000000
675#define HC_FogMD_LinearFog 0x00000002
676#define HC_FogMD_ExponentialFog 0x00000004
677#define HC_FogMD_Exponential2Fog 0x00000005
678/* #define HC_FogMD_FogTable 0x00000003 */
679
680/* HC_SubA_HFogDenst 0x0058
681 */
682#define HC_FogDenst_MASK 0x001fff00
683#define HC_FogEndL_MASK 0x000000ff
684
685/* Texture subtype definitions
686 */
687#define HC_SubType_Tex0 0x00000000
688#define HC_SubType_Tex1 0x00000001
689#define HC_SubType_TexGeneral 0x000000fe
690
691/* Attribute of texture n
692 */
693#define HC_SubA_HTXnL0BasL 0x0000
694#define HC_SubA_HTXnL1BasL 0x0001
695#define HC_SubA_HTXnL2BasL 0x0002
696#define HC_SubA_HTXnL3BasL 0x0003
697#define HC_SubA_HTXnL4BasL 0x0004
698#define HC_SubA_HTXnL5BasL 0x0005
699#define HC_SubA_HTXnL6BasL 0x0006
700#define HC_SubA_HTXnL7BasL 0x0007
701#define HC_SubA_HTXnL8BasL 0x0008
702#define HC_SubA_HTXnL9BasL 0x0009
703#define HC_SubA_HTXnLaBasL 0x000a
704#define HC_SubA_HTXnLbBasL 0x000b
705#define HC_SubA_HTXnLcBasL 0x000c
706#define HC_SubA_HTXnLdBasL 0x000d
707#define HC_SubA_HTXnLeBasL 0x000e
708#define HC_SubA_HTXnLfBasL 0x000f
709#define HC_SubA_HTXnL10BasL 0x0010
710#define HC_SubA_HTXnL11BasL 0x0011
711#define HC_SubA_HTXnL012BasH 0x0020
712#define HC_SubA_HTXnL345BasH 0x0021
713#define HC_SubA_HTXnL678BasH 0x0022
714#define HC_SubA_HTXnL9abBasH 0x0023
715#define HC_SubA_HTXnLcdeBasH 0x0024
716#define HC_SubA_HTXnLf1011BasH 0x0025
717#define HC_SubA_HTXnL0Pit 0x002b
718#define HC_SubA_HTXnL1Pit 0x002c
719#define HC_SubA_HTXnL2Pit 0x002d
720#define HC_SubA_HTXnL3Pit 0x002e
721#define HC_SubA_HTXnL4Pit 0x002f
722#define HC_SubA_HTXnL5Pit 0x0030
723#define HC_SubA_HTXnL6Pit 0x0031
724#define HC_SubA_HTXnL7Pit 0x0032
725#define HC_SubA_HTXnL8Pit 0x0033
726#define HC_SubA_HTXnL9Pit 0x0034
727#define HC_SubA_HTXnLaPit 0x0035
728#define HC_SubA_HTXnLbPit 0x0036
729#define HC_SubA_HTXnLcPit 0x0037
730#define HC_SubA_HTXnLdPit 0x0038
731#define HC_SubA_HTXnLePit 0x0039
732#define HC_SubA_HTXnLfPit 0x003a
733#define HC_SubA_HTXnL10Pit 0x003b
734#define HC_SubA_HTXnL11Pit 0x003c
735#define HC_SubA_HTXnL0_5WE 0x004b
736#define HC_SubA_HTXnL6_bWE 0x004c
737#define HC_SubA_HTXnLc_11WE 0x004d
738#define HC_SubA_HTXnL0_5HE 0x0051
739#define HC_SubA_HTXnL6_bHE 0x0052
740#define HC_SubA_HTXnLc_11HE 0x0053
741#define HC_SubA_HTXnL0OS 0x0077
742#define HC_SubA_HTXnTB 0x0078
743#define HC_SubA_HTXnMPMD 0x0079
744#define HC_SubA_HTXnCLODu 0x007a
745#define HC_SubA_HTXnFM 0x007b
746#define HC_SubA_HTXnTRCH 0x007c
747#define HC_SubA_HTXnTRCL 0x007d
748#define HC_SubA_HTXnTBC 0x007e
749#define HC_SubA_HTXnTRAH 0x007f
750#define HC_SubA_HTXnTBLCsat 0x0080
751#define HC_SubA_HTXnTBLCop 0x0081
752#define HC_SubA_HTXnTBLMPfog 0x0082
753#define HC_SubA_HTXnTBLAsat 0x0083
754#define HC_SubA_HTXnTBLRCa 0x0085
755#define HC_SubA_HTXnTBLRCb 0x0086
756#define HC_SubA_HTXnTBLRCc 0x0087
757#define HC_SubA_HTXnTBLRCbias 0x0088
758#define HC_SubA_HTXnTBLRAa 0x0089
759#define HC_SubA_HTXnTBLRFog 0x008a
760#define HC_SubA_HTXnBumpM00 0x0090
761#define HC_SubA_HTXnBumpM01 0x0091
762#define HC_SubA_HTXnBumpM10 0x0092
763#define HC_SubA_HTXnBumpM11 0x0093
764#define HC_SubA_HTXnLScale 0x0094
765#define HC_SubA_HTXSMD 0x0000
766/* HC_SubA_HTXnL012BasH 0x0020
767 */
768#define HC_HTXnL0BasH_MASK 0x000000ff
769#define HC_HTXnL1BasH_MASK 0x0000ff00
770#define HC_HTXnL2BasH_MASK 0x00ff0000
771#define HC_HTXnL1BasH_SHIFT 8
772#define HC_HTXnL2BasH_SHIFT 16
773/* HC_SubA_HTXnL345BasH 0x0021
774 */
775#define HC_HTXnL3BasH_MASK 0x000000ff
776#define HC_HTXnL4BasH_MASK 0x0000ff00
777#define HC_HTXnL5BasH_MASK 0x00ff0000
778#define HC_HTXnL4BasH_SHIFT 8
779#define HC_HTXnL5BasH_SHIFT 16
780/* HC_SubA_HTXnL678BasH 0x0022
781 */
782#define HC_HTXnL6BasH_MASK 0x000000ff
783#define HC_HTXnL7BasH_MASK 0x0000ff00
784#define HC_HTXnL8BasH_MASK 0x00ff0000
785#define HC_HTXnL7BasH_SHIFT 8
786#define HC_HTXnL8BasH_SHIFT 16
787/* HC_SubA_HTXnL9abBasH 0x0023
788 */
789#define HC_HTXnL9BasH_MASK 0x000000ff
790#define HC_HTXnLaBasH_MASK 0x0000ff00
791#define HC_HTXnLbBasH_MASK 0x00ff0000
792#define HC_HTXnLaBasH_SHIFT 8
793#define HC_HTXnLbBasH_SHIFT 16
794/* HC_SubA_HTXnLcdeBasH 0x0024
795 */
796#define HC_HTXnLcBasH_MASK 0x000000ff
797#define HC_HTXnLdBasH_MASK 0x0000ff00
798#define HC_HTXnLeBasH_MASK 0x00ff0000
799#define HC_HTXnLdBasH_SHIFT 8
800#define HC_HTXnLeBasH_SHIFT 16
801/* HC_SubA_HTXnLcdeBasH 0x0025
802 */
803#define HC_HTXnLfBasH_MASK 0x000000ff
804#define HC_HTXnL10BasH_MASK 0x0000ff00
805#define HC_HTXnL11BasH_MASK 0x00ff0000
806#define HC_HTXnL10BasH_SHIFT 8
807#define HC_HTXnL11BasH_SHIFT 16
808/* HC_SubA_HTXnL0Pit 0x002b
809 */
810#define HC_HTXnLnPit_MASK 0x00003fff
811#define HC_HTXnEnPit_MASK 0x00080000
812#define HC_HTXnLnPitE_MASK 0x00f00000
813#define HC_HTXnLnPitE_SHIFT 20
814/* HC_SubA_HTXnL0_5WE 0x004b
815 */
816#define HC_HTXnL0WE_MASK 0x0000000f
817#define HC_HTXnL1WE_MASK 0x000000f0
818#define HC_HTXnL2WE_MASK 0x00000f00
819#define HC_HTXnL3WE_MASK 0x0000f000
820#define HC_HTXnL4WE_MASK 0x000f0000
821#define HC_HTXnL5WE_MASK 0x00f00000
822#define HC_HTXnL1WE_SHIFT 4
823#define HC_HTXnL2WE_SHIFT 8
824#define HC_HTXnL3WE_SHIFT 12
825#define HC_HTXnL4WE_SHIFT 16
826#define HC_HTXnL5WE_SHIFT 20
827/* HC_SubA_HTXnL6_bWE 0x004c
828 */
829#define HC_HTXnL6WE_MASK 0x0000000f
830#define HC_HTXnL7WE_MASK 0x000000f0
831#define HC_HTXnL8WE_MASK 0x00000f00
832#define HC_HTXnL9WE_MASK 0x0000f000
833#define HC_HTXnLaWE_MASK 0x000f0000
834#define HC_HTXnLbWE_MASK 0x00f00000
835#define HC_HTXnL7WE_SHIFT 4
836#define HC_HTXnL8WE_SHIFT 8
837#define HC_HTXnL9WE_SHIFT 12
838#define HC_HTXnLaWE_SHIFT 16
839#define HC_HTXnLbWE_SHIFT 20
840/* HC_SubA_HTXnLc_11WE 0x004d
841 */
842#define HC_HTXnLcWE_MASK 0x0000000f
843#define HC_HTXnLdWE_MASK 0x000000f0
844#define HC_HTXnLeWE_MASK 0x00000f00
845#define HC_HTXnLfWE_MASK 0x0000f000
846#define HC_HTXnL10WE_MASK 0x000f0000
847#define HC_HTXnL11WE_MASK 0x00f00000
848#define HC_HTXnLdWE_SHIFT 4
849#define HC_HTXnLeWE_SHIFT 8
850#define HC_HTXnLfWE_SHIFT 12
851#define HC_HTXnL10WE_SHIFT 16
852#define HC_HTXnL11WE_SHIFT 20
853/* HC_SubA_HTXnL0_5HE 0x0051
854 */
855#define HC_HTXnL0HE_MASK 0x0000000f
856#define HC_HTXnL1HE_MASK 0x000000f0
857#define HC_HTXnL2HE_MASK 0x00000f00
858#define HC_HTXnL3HE_MASK 0x0000f000
859#define HC_HTXnL4HE_MASK 0x000f0000
860#define HC_HTXnL5HE_MASK 0x00f00000
861#define HC_HTXnL1HE_SHIFT 4
862#define HC_HTXnL2HE_SHIFT 8
863#define HC_HTXnL3HE_SHIFT 12
864#define HC_HTXnL4HE_SHIFT 16
865#define HC_HTXnL5HE_SHIFT 20
866/* HC_SubA_HTXnL6_bHE 0x0052
867 */
868#define HC_HTXnL6HE_MASK 0x0000000f
869#define HC_HTXnL7HE_MASK 0x000000f0
870#define HC_HTXnL8HE_MASK 0x00000f00
871#define HC_HTXnL9HE_MASK 0x0000f000
872#define HC_HTXnLaHE_MASK 0x000f0000
873#define HC_HTXnLbHE_MASK 0x00f00000
874#define HC_HTXnL7HE_SHIFT 4
875#define HC_HTXnL8HE_SHIFT 8
876#define HC_HTXnL9HE_SHIFT 12
877#define HC_HTXnLaHE_SHIFT 16
878#define HC_HTXnLbHE_SHIFT 20
879/* HC_SubA_HTXnLc_11HE 0x0053
880 */
881#define HC_HTXnLcHE_MASK 0x0000000f
882#define HC_HTXnLdHE_MASK 0x000000f0
883#define HC_HTXnLeHE_MASK 0x00000f00
884#define HC_HTXnLfHE_MASK 0x0000f000
885#define HC_HTXnL10HE_MASK 0x000f0000
886#define HC_HTXnL11HE_MASK 0x00f00000
887#define HC_HTXnLdHE_SHIFT 4
888#define HC_HTXnLeHE_SHIFT 8
889#define HC_HTXnLfHE_SHIFT 12
890#define HC_HTXnL10HE_SHIFT 16
891#define HC_HTXnL11HE_SHIFT 20
892/* HC_SubA_HTXnL0OS 0x0077
893 */
894#define HC_HTXnL0OS_MASK 0x003ff000
895#define HC_HTXnLVmax_MASK 0x00000fc0
896#define HC_HTXnLVmin_MASK 0x0000003f
897#define HC_HTXnL0OS_SHIFT 12
898#define HC_HTXnLVmax_SHIFT 6
899/* HC_SubA_HTXnTB 0x0078
900 */
901#define HC_HTXnTB_MASK 0x00f00000
902#define HC_HTXnFLSe_MASK 0x0000e000
903#define HC_HTXnFLSs_MASK 0x00001c00
904#define HC_HTXnFLTe_MASK 0x00000380
905#define HC_HTXnFLTs_MASK 0x00000070
906#define HC_HTXnFLDs_MASK 0x0000000f
907#define HC_HTXnTB_NoTB 0x00000000
908#define HC_HTXnTB_TBC_S 0x00100000
909#define HC_HTXnTB_TBC_T 0x00200000
910#define HC_HTXnTB_TB_S 0x00400000
911#define HC_HTXnTB_TB_T 0x00800000
912#define HC_HTXnFLSe_Nearest 0x00000000
913#define HC_HTXnFLSe_Linear 0x00002000
914#define HC_HTXnFLSe_NonLinear 0x00004000
915#define HC_HTXnFLSe_Sharp 0x00008000
916#define HC_HTXnFLSe_Flat_Gaussian_Cubic 0x0000c000
917#define HC_HTXnFLSs_Nearest 0x00000000
918#define HC_HTXnFLSs_Linear 0x00000400
919#define HC_HTXnFLSs_NonLinear 0x00000800
920#define HC_HTXnFLSs_Flat_Gaussian_Cubic 0x00001800
921#define HC_HTXnFLTe_Nearest 0x00000000
922#define HC_HTXnFLTe_Linear 0x00000080
923#define HC_HTXnFLTe_NonLinear 0x00000100
924#define HC_HTXnFLTe_Sharp 0x00000180
925#define HC_HTXnFLTe_Flat_Gaussian_Cubic 0x00000300
926#define HC_HTXnFLTs_Nearest 0x00000000
927#define HC_HTXnFLTs_Linear 0x00000010
928#define HC_HTXnFLTs_NonLinear 0x00000020
929#define HC_HTXnFLTs_Flat_Gaussian_Cubic 0x00000060
930#define HC_HTXnFLDs_Tex0 0x00000000
931#define HC_HTXnFLDs_Nearest 0x00000001
932#define HC_HTXnFLDs_Linear 0x00000002
933#define HC_HTXnFLDs_NonLinear 0x00000003
934#define HC_HTXnFLDs_Dither 0x00000004
935#define HC_HTXnFLDs_ConstLOD 0x00000005
936#define HC_HTXnFLDs_Ani 0x00000006
937#define HC_HTXnFLDs_AniDither 0x00000007
938/* HC_SubA_HTXnMPMD 0x0079
939 */
940#define HC_HTXnMPMD_SMASK 0x00070000
941#define HC_HTXnMPMD_TMASK 0x00380000
942#define HC_HTXnLODDTf_MASK 0x00000007
943#define HC_HTXnXY2ST_MASK 0x00000008
944#define HC_HTXnMPMD_Tsingle 0x00000000
945#define HC_HTXnMPMD_Tclamp 0x00080000
946#define HC_HTXnMPMD_Trepeat 0x00100000
947#define HC_HTXnMPMD_Tmirror 0x00180000
948#define HC_HTXnMPMD_Twrap 0x00200000
949#define HC_HTXnMPMD_Ssingle 0x00000000
950#define HC_HTXnMPMD_Sclamp 0x00010000
951#define HC_HTXnMPMD_Srepeat 0x00020000
952#define HC_HTXnMPMD_Smirror 0x00030000
953#define HC_HTXnMPMD_Swrap 0x00040000
954/* HC_SubA_HTXnCLODu 0x007a
955 */
956#define HC_HTXnCLODu_MASK 0x000ffc00
957#define HC_HTXnCLODd_MASK 0x000003ff
958#define HC_HTXnCLODu_SHIFT 10
959/* HC_SubA_HTXnFM 0x007b
960 */
961#define HC_HTXnFM_MASK 0x00ff0000
962#define HC_HTXnLoc_MASK 0x00000003
963#define HC_HTXnFM_INDEX 0x00000000
964#define HC_HTXnFM_Intensity 0x00080000
965#define HC_HTXnFM_Lum 0x00100000
966#define HC_HTXnFM_Alpha 0x00180000
967#define HC_HTXnFM_DX 0x00280000
968#define HC_HTXnFM_ARGB16 0x00880000
969#define HC_HTXnFM_ARGB32 0x00980000
970#define HC_HTXnFM_ABGR16 0x00a80000
971#define HC_HTXnFM_ABGR32 0x00b80000
972#define HC_HTXnFM_RGBA16 0x00c80000
973#define HC_HTXnFM_RGBA32 0x00d80000
974#define HC_HTXnFM_BGRA16 0x00e80000
975#define HC_HTXnFM_BGRA32 0x00f80000
976#define HC_HTXnFM_BUMPMAP 0x00380000
977#define HC_HTXnFM_Index1 (HC_HTXnFM_INDEX | 0x00000000)
978#define HC_HTXnFM_Index2 (HC_HTXnFM_INDEX | 0x00010000)
979#define HC_HTXnFM_Index4 (HC_HTXnFM_INDEX | 0x00020000)
980#define HC_HTXnFM_Index8 (HC_HTXnFM_INDEX | 0x00030000)
981#define HC_HTXnFM_T1 (HC_HTXnFM_Intensity | 0x00000000)
982#define HC_HTXnFM_T2 (HC_HTXnFM_Intensity | 0x00010000)
983#define HC_HTXnFM_T4 (HC_HTXnFM_Intensity | 0x00020000)
984#define HC_HTXnFM_T8 (HC_HTXnFM_Intensity | 0x00030000)
985#define HC_HTXnFM_L1 (HC_HTXnFM_Lum | 0x00000000)
986#define HC_HTXnFM_L2 (HC_HTXnFM_Lum | 0x00010000)
987#define HC_HTXnFM_L4 (HC_HTXnFM_Lum | 0x00020000)
988#define HC_HTXnFM_L8 (HC_HTXnFM_Lum | 0x00030000)
989#define HC_HTXnFM_AL44 (HC_HTXnFM_Lum | 0x00040000)
990#define HC_HTXnFM_AL88 (HC_HTXnFM_Lum | 0x00050000)
991#define HC_HTXnFM_A1 (HC_HTXnFM_Alpha | 0x00000000)
992#define HC_HTXnFM_A2 (HC_HTXnFM_Alpha | 0x00010000)
993#define HC_HTXnFM_A4 (HC_HTXnFM_Alpha | 0x00020000)
994#define HC_HTXnFM_A8 (HC_HTXnFM_Alpha | 0x00030000)
995#define HC_HTXnFM_DX1 (HC_HTXnFM_DX | 0x00010000)
996#define HC_HTXnFM_DX23 (HC_HTXnFM_DX | 0x00020000)
997#define HC_HTXnFM_DX45 (HC_HTXnFM_DX | 0x00030000)
998#define HC_HTXnFM_RGB555 (HC_HTXnFM_ARGB16 | 0x00000000)
999#define HC_HTXnFM_RGB565 (HC_HTXnFM_ARGB16 | 0x00010000)
1000#define HC_HTXnFM_ARGB1555 (HC_HTXnFM_ARGB16 | 0x00020000)
1001#define HC_HTXnFM_ARGB4444 (HC_HTXnFM_ARGB16 | 0x00030000)
1002#define HC_HTXnFM_ARGB0888 (HC_HTXnFM_ARGB32 | 0x00000000)
1003#define HC_HTXnFM_ARGB8888 (HC_HTXnFM_ARGB32 | 0x00010000)
1004#define HC_HTXnFM_BGR555 (HC_HTXnFM_ABGR16 | 0x00000000)
1005#define HC_HTXnFM_BGR565 (HC_HTXnFM_ABGR16 | 0x00010000)
1006#define HC_HTXnFM_ABGR1555 (HC_HTXnFM_ABGR16 | 0x00020000)
1007#define HC_HTXnFM_ABGR4444 (HC_HTXnFM_ABGR16 | 0x00030000)
1008#define HC_HTXnFM_ABGR0888 (HC_HTXnFM_ABGR32 | 0x00000000)
1009#define HC_HTXnFM_ABGR8888 (HC_HTXnFM_ABGR32 | 0x00010000)
1010#define HC_HTXnFM_RGBA5550 (HC_HTXnFM_RGBA16 | 0x00000000)
1011#define HC_HTXnFM_RGBA5551 (HC_HTXnFM_RGBA16 | 0x00020000)
1012#define HC_HTXnFM_RGBA4444 (HC_HTXnFM_RGBA16 | 0x00030000)
1013#define HC_HTXnFM_RGBA8880 (HC_HTXnFM_RGBA32 | 0x00000000)
1014#define HC_HTXnFM_RGBA8888 (HC_HTXnFM_RGBA32 | 0x00010000)
1015#define HC_HTXnFM_BGRA5550 (HC_HTXnFM_BGRA16 | 0x00000000)
1016#define HC_HTXnFM_BGRA5551 (HC_HTXnFM_BGRA16 | 0x00020000)
1017#define HC_HTXnFM_BGRA4444 (HC_HTXnFM_BGRA16 | 0x00030000)
1018#define HC_HTXnFM_BGRA8880 (HC_HTXnFM_BGRA32 | 0x00000000)
1019#define HC_HTXnFM_BGRA8888 (HC_HTXnFM_BGRA32 | 0x00010000)
1020#define HC_HTXnFM_VU88 (HC_HTXnFM_BUMPMAP | 0x00000000)
1021#define HC_HTXnFM_LVU655 (HC_HTXnFM_BUMPMAP | 0x00010000)
1022#define HC_HTXnFM_LVU888 (HC_HTXnFM_BUMPMAP | 0x00020000)
1023#define HC_HTXnLoc_Local 0x00000000
1024#define HC_HTXnLoc_Sys 0x00000002
1025#define HC_HTXnLoc_AGP 0x00000003
1026/* HC_SubA_HTXnTRAH 0x007f
1027 */
1028#define HC_HTXnTRAH_MASK 0x00ff0000
1029#define HC_HTXnTRAL_MASK 0x0000ff00
1030#define HC_HTXnTBA_MASK 0x000000ff
1031#define HC_HTXnTRAH_SHIFT 16
1032#define HC_HTXnTRAL_SHIFT 8
1033/* HC_SubA_HTXnTBLCsat 0x0080
1034 *-- Define the input texture.
1035 */
1036#define HC_XTC_TOPC 0x00000000
1037#define HC_XTC_InvTOPC 0x00000010
1038#define HC_XTC_TOPCp5 0x00000020
1039#define HC_XTC_Cbias 0x00000000
1040#define HC_XTC_InvCbias 0x00000010
1041#define HC_XTC_0 0x00000000
1042#define HC_XTC_Dif 0x00000001
1043#define HC_XTC_Spec 0x00000002
1044#define HC_XTC_Tex 0x00000003
1045#define HC_XTC_Cur 0x00000004
1046#define HC_XTC_Adif 0x00000005
1047#define HC_XTC_Fog 0x00000006
1048#define HC_XTC_Atex 0x00000007
1049#define HC_XTC_Acur 0x00000008
1050#define HC_XTC_HTXnTBLRC 0x00000009
1051#define HC_XTC_Ctexnext 0x0000000a
1052/*--
1053 */
1054#define HC_HTXnTBLCsat_MASK 0x00800000
1055#define HC_HTXnTBLCa_MASK 0x000fc000
1056#define HC_HTXnTBLCb_MASK 0x00001f80
1057#define HC_HTXnTBLCc_MASK 0x0000003f
1058#define HC_HTXnTBLCa_TOPC (HC_XTC_TOPC << 14)
1059#define HC_HTXnTBLCa_InvTOPC (HC_XTC_InvTOPC << 14)
1060#define HC_HTXnTBLCa_TOPCp5 (HC_XTC_TOPCp5 << 14)
1061#define HC_HTXnTBLCa_0 (HC_XTC_0 << 14)
1062#define HC_HTXnTBLCa_Dif (HC_XTC_Dif << 14)
1063#define HC_HTXnTBLCa_Spec (HC_XTC_Spec << 14)
1064#define HC_HTXnTBLCa_Tex (HC_XTC_Tex << 14)
1065#define HC_HTXnTBLCa_Cur (HC_XTC_Cur << 14)
1066#define HC_HTXnTBLCa_Adif (HC_XTC_Adif << 14)
1067#define HC_HTXnTBLCa_Fog (HC_XTC_Fog << 14)
1068#define HC_HTXnTBLCa_Atex (HC_XTC_Atex << 14)
1069#define HC_HTXnTBLCa_Acur (HC_XTC_Acur << 14)
1070#define HC_HTXnTBLCa_HTXnTBLRC (HC_XTC_HTXnTBLRC << 14)
1071#define HC_HTXnTBLCa_Ctexnext (HC_XTC_Ctexnext << 14)
1072#define HC_HTXnTBLCb_TOPC (HC_XTC_TOPC << 7)
1073#define HC_HTXnTBLCb_InvTOPC (HC_XTC_InvTOPC << 7)
1074#define HC_HTXnTBLCb_TOPCp5 (HC_XTC_TOPCp5 << 7)
1075#define HC_HTXnTBLCb_0 (HC_XTC_0 << 7)
1076#define HC_HTXnTBLCb_Dif (HC_XTC_Dif << 7)
1077#define HC_HTXnTBLCb_Spec (HC_XTC_Spec << 7)
1078#define HC_HTXnTBLCb_Tex (HC_XTC_Tex << 7)
1079#define HC_HTXnTBLCb_Cur (HC_XTC_Cur << 7)
1080#define HC_HTXnTBLCb_Adif (HC_XTC_Adif << 7)
1081#define HC_HTXnTBLCb_Fog (HC_XTC_Fog << 7)
1082#define HC_HTXnTBLCb_Atex (HC_XTC_Atex << 7)
1083#define HC_HTXnTBLCb_Acur (HC_XTC_Acur << 7)
1084#define HC_HTXnTBLCb_HTXnTBLRC (HC_XTC_HTXnTBLRC << 7)
1085#define HC_HTXnTBLCb_Ctexnext (HC_XTC_Ctexnext << 7)
1086#define HC_HTXnTBLCc_TOPC (HC_XTC_TOPC << 0)
1087#define HC_HTXnTBLCc_InvTOPC (HC_XTC_InvTOPC << 0)
1088#define HC_HTXnTBLCc_TOPCp5 (HC_XTC_TOPCp5 << 0)
1089#define HC_HTXnTBLCc_0 (HC_XTC_0 << 0)
1090#define HC_HTXnTBLCc_Dif (HC_XTC_Dif << 0)
1091#define HC_HTXnTBLCc_Spec (HC_XTC_Spec << 0)
1092#define HC_HTXnTBLCc_Tex (HC_XTC_Tex << 0)
1093#define HC_HTXnTBLCc_Cur (HC_XTC_Cur << 0)
1094#define HC_HTXnTBLCc_Adif (HC_XTC_Adif << 0)
1095#define HC_HTXnTBLCc_Fog (HC_XTC_Fog << 0)
1096#define HC_HTXnTBLCc_Atex (HC_XTC_Atex << 0)
1097#define HC_HTXnTBLCc_Acur (HC_XTC_Acur << 0)
1098#define HC_HTXnTBLCc_HTXnTBLRC (HC_XTC_HTXnTBLRC << 0)
1099#define HC_HTXnTBLCc_Ctexnext (HC_XTC_Ctexnext << 0)
1100/* HC_SubA_HTXnTBLCop 0x0081
1101 */
1102#define HC_HTXnTBLdot_MASK 0x00c00000
1103#define HC_HTXnTBLCop_MASK 0x00380000
1104#define HC_HTXnTBLCbias_MASK 0x0007c000
1105#define HC_HTXnTBLCshift_MASK 0x00001800
1106#define HC_HTXnTBLAop_MASK 0x00000380
1107#define HC_HTXnTBLAbias_MASK 0x00000078
1108#define HC_HTXnTBLAshift_MASK 0x00000003
1109#define HC_HTXnTBLCop_Add 0x00000000
1110#define HC_HTXnTBLCop_Sub 0x00080000
1111#define HC_HTXnTBLCop_Min 0x00100000
1112#define HC_HTXnTBLCop_Max 0x00180000
1113#define HC_HTXnTBLCop_Mask 0x00200000
1114#define HC_HTXnTBLCbias_Cbias (HC_XTC_Cbias << 14)
1115#define HC_HTXnTBLCbias_InvCbias (HC_XTC_InvCbias << 14)
1116#define HC_HTXnTBLCbias_0 (HC_XTC_0 << 14)
1117#define HC_HTXnTBLCbias_Dif (HC_XTC_Dif << 14)
1118#define HC_HTXnTBLCbias_Spec (HC_XTC_Spec << 14)
1119#define HC_HTXnTBLCbias_Tex (HC_XTC_Tex << 14)
1120#define HC_HTXnTBLCbias_Cur (HC_XTC_Cur << 14)
1121#define HC_HTXnTBLCbias_Adif (HC_XTC_Adif << 14)
1122#define HC_HTXnTBLCbias_Fog (HC_XTC_Fog << 14)
1123#define HC_HTXnTBLCbias_Atex (HC_XTC_Atex << 14)
1124#define HC_HTXnTBLCbias_Acur (HC_XTC_Acur << 14)
1125#define HC_HTXnTBLCbias_HTXnTBLRC (HC_XTC_HTXnTBLRC << 14)
1126#define HC_HTXnTBLCshift_1 0x00000000
1127#define HC_HTXnTBLCshift_2 0x00000800
1128#define HC_HTXnTBLCshift_No 0x00001000
1129#define HC_HTXnTBLCshift_DotP 0x00001800
1130/*=* John Sheng [2003.7.18] texture combine *=*/
1131#define HC_HTXnTBLDOT3 0x00080000
1132#define HC_HTXnTBLDOT4 0x000C0000
1133
1134#define HC_HTXnTBLAop_Add 0x00000000
1135#define HC_HTXnTBLAop_Sub 0x00000080
1136#define HC_HTXnTBLAop_Min 0x00000100
1137#define HC_HTXnTBLAop_Max 0x00000180
1138#define HC_HTXnTBLAop_Mask 0x00000200
1139#define HC_HTXnTBLAbias_Inv 0x00000040
1140#define HC_HTXnTBLAbias_Adif 0x00000000
1141#define HC_HTXnTBLAbias_Fog 0x00000008
1142#define HC_HTXnTBLAbias_Acur 0x00000010
1143#define HC_HTXnTBLAbias_HTXnTBLRAbias 0x00000018
1144#define HC_HTXnTBLAbias_Atex 0x00000020
1145#define HC_HTXnTBLAshift_1 0x00000000
1146#define HC_HTXnTBLAshift_2 0x00000001
1147#define HC_HTXnTBLAshift_No 0x00000002
1148/* #define HC_HTXnTBLAshift_DotP 0x00000003 */
1149/* HC_SubA_HTXnTBLMPFog 0x0082
1150 */
1151#define HC_HTXnTBLMPfog_MASK 0x00e00000
1152#define HC_HTXnTBLMPfog_0 0x00000000
1153#define HC_HTXnTBLMPfog_Adif 0x00200000
1154#define HC_HTXnTBLMPfog_Fog 0x00400000
1155#define HC_HTXnTBLMPfog_Atex 0x00600000
1156#define HC_HTXnTBLMPfog_Acur 0x00800000
1157#define HC_HTXnTBLMPfog_GHTXnTBLRFog 0x00a00000
1158/* HC_SubA_HTXnTBLAsat 0x0083
1159 *-- Define the texture alpha input.
1160 */
1161#define HC_XTA_TOPA 0x00000000
1162#define HC_XTA_InvTOPA 0x00000008
1163#define HC_XTA_TOPAp5 0x00000010
1164#define HC_XTA_Adif 0x00000000
1165#define HC_XTA_Fog 0x00000001
1166#define HC_XTA_Acur 0x00000002
1167#define HC_XTA_HTXnTBLRA 0x00000003
1168#define HC_XTA_Atex 0x00000004
1169#define HC_XTA_Atexnext 0x00000005
1170/*--
1171 */
1172#define HC_HTXnTBLAsat_MASK 0x00800000
1173#define HC_HTXnTBLAMB_MASK 0x00700000
1174#define HC_HTXnTBLAa_MASK 0x0007c000
1175#define HC_HTXnTBLAb_MASK 0x00000f80
1176#define HC_HTXnTBLAc_MASK 0x0000001f
1177#define HC_HTXnTBLAMB_SHIFT 20
1178#define HC_HTXnTBLAa_TOPA (HC_XTA_TOPA << 14)
1179#define HC_HTXnTBLAa_InvTOPA (HC_XTA_InvTOPA << 14)
1180#define HC_HTXnTBLAa_TOPAp5 (HC_XTA_TOPAp5 << 14)
1181#define HC_HTXnTBLAa_Adif (HC_XTA_Adif << 14)
1182#define HC_HTXnTBLAa_Fog (HC_XTA_Fog << 14)
1183#define HC_HTXnTBLAa_Acur (HC_XTA_Acur << 14)
1184#define HC_HTXnTBLAa_HTXnTBLRA (HC_XTA_HTXnTBLRA << 14)
1185#define HC_HTXnTBLAa_Atex (HC_XTA_Atex << 14)
1186#define HC_HTXnTBLAa_Atexnext (HC_XTA_Atexnext << 14)
1187#define HC_HTXnTBLAb_TOPA (HC_XTA_TOPA << 7)
1188#define HC_HTXnTBLAb_InvTOPA (HC_XTA_InvTOPA << 7)
1189#define HC_HTXnTBLAb_TOPAp5 (HC_XTA_TOPAp5 << 7)
1190#define HC_HTXnTBLAb_Adif (HC_XTA_Adif << 7)
1191#define HC_HTXnTBLAb_Fog (HC_XTA_Fog << 7)
1192#define HC_HTXnTBLAb_Acur (HC_XTA_Acur << 7)
1193#define HC_HTXnTBLAb_HTXnTBLRA (HC_XTA_HTXnTBLRA << 7)
1194#define HC_HTXnTBLAb_Atex (HC_XTA_Atex << 7)
1195#define HC_HTXnTBLAb_Atexnext (HC_XTA_Atexnext << 7)
1196#define HC_HTXnTBLAc_TOPA (HC_XTA_TOPA << 0)
1197#define HC_HTXnTBLAc_InvTOPA (HC_XTA_InvTOPA << 0)
1198#define HC_HTXnTBLAc_TOPAp5 (HC_XTA_TOPAp5 << 0)
1199#define HC_HTXnTBLAc_Adif (HC_XTA_Adif << 0)
1200#define HC_HTXnTBLAc_Fog (HC_XTA_Fog << 0)
1201#define HC_HTXnTBLAc_Acur (HC_XTA_Acur << 0)
1202#define HC_HTXnTBLAc_HTXnTBLRA (HC_XTA_HTXnTBLRA << 0)
1203#define HC_HTXnTBLAc_Atex (HC_XTA_Atex << 0)
1204#define HC_HTXnTBLAc_Atexnext (HC_XTA_Atexnext << 0)
1205/* HC_SubA_HTXnTBLRAa 0x0089
1206 */
1207#define HC_HTXnTBLRAa_MASK 0x00ff0000
1208#define HC_HTXnTBLRAb_MASK 0x0000ff00
1209#define HC_HTXnTBLRAc_MASK 0x000000ff
1210#define HC_HTXnTBLRAa_SHIFT 16
1211#define HC_HTXnTBLRAb_SHIFT 8
1212#define HC_HTXnTBLRAc_SHIFT 0
1213/* HC_SubA_HTXnTBLRFog 0x008a
1214 */
1215#define HC_HTXnTBLRFog_MASK 0x0000ff00
1216#define HC_HTXnTBLRAbias_MASK 0x000000ff
1217#define HC_HTXnTBLRFog_SHIFT 8
1218#define HC_HTXnTBLRAbias_SHIFT 0
1219/* HC_SubA_HTXnLScale 0x0094
1220 */
1221#define HC_HTXnLScale_MASK 0x0007fc00
1222#define HC_HTXnLOff_MASK 0x000001ff
1223#define HC_HTXnLScale_SHIFT 10
1224/* HC_SubA_HTXSMD 0x0000
1225 */
1226#define HC_HTXSMD_MASK 0x00000080
1227#define HC_HTXTMD_MASK 0x00000040
1228#define HC_HTXNum_MASK 0x00000038
1229#define HC_HTXTRMD_MASK 0x00000006
1230#define HC_HTXCHCLR_MASK 0x00000001
1231#define HC_HTXNum_SHIFT 3
1232
1233/* Texture Palette n
1234 */
1235#define HC_SubType_TexPalette0 0x00000000
1236#define HC_SubType_TexPalette1 0x00000001
1237#define HC_SubType_FogTable 0x00000010
1238#define HC_SubType_Stipple 0x00000014
1239/* HC_SubA_TexPalette0 0x0000
1240 */
1241#define HC_HTPnA_MASK 0xff000000
1242#define HC_HTPnR_MASK 0x00ff0000
1243#define HC_HTPnG_MASK 0x0000ff00
1244#define HC_HTPnB_MASK 0x000000ff
1245/* HC_SubA_FogTable 0x0010
1246 */
1247#define HC_HFPn3_MASK 0xff000000
1248#define HC_HFPn2_MASK 0x00ff0000
1249#define HC_HFPn1_MASK 0x0000ff00
1250#define HC_HFPn_MASK 0x000000ff
1251#define HC_HFPn3_SHIFT 24
1252#define HC_HFPn2_SHIFT 16
1253#define HC_HFPn1_SHIFT 8
1254
1255/* Auto Testing & Security
1256 */
1257#define HC_SubA_HenFIFOAT 0x0000
1258#define HC_SubA_HFBDrawFirst 0x0004
1259#define HC_SubA_HFBBasL 0x0005
1260#define HC_SubA_HFBDst 0x0006
1261/* HC_SubA_HenFIFOAT 0x0000
1262 */
1263#define HC_HenFIFOAT_MASK 0x00000020
1264#define HC_HenGEMILock_MASK 0x00000010
1265#define HC_HenFBASwap_MASK 0x00000008
1266#define HC_HenOT_MASK 0x00000004
1267#define HC_HenCMDQ_MASK 0x00000002
1268#define HC_HenTXCTSU_MASK 0x00000001
1269/* HC_SubA_HFBDrawFirst 0x0004
1270 */
1271#define HC_HFBDrawFirst_MASK 0x00000800
1272#define HC_HFBQueue_MASK 0x00000400
1273#define HC_HFBLock_MASK 0x00000200
1274#define HC_HEOF_MASK 0x00000100
1275#define HC_HFBBasH_MASK 0x000000ff
1276
1277/* GEMI Setting
1278 */
1279#define HC_SubA_HTArbRCM 0x0008
1280#define HC_SubA_HTArbRZ 0x000a
1281#define HC_SubA_HTArbWZ 0x000b
1282#define HC_SubA_HTArbRTX 0x000c
1283#define HC_SubA_HTArbRCW 0x000d
1284#define HC_SubA_HTArbE2 0x000e
1285#define HC_SubA_HArbRQCM 0x0010
1286#define HC_SubA_HArbWQCM 0x0011
1287#define HC_SubA_HGEMITout 0x0020
1288#define HC_SubA_HFthRTXD 0x0040
1289#define HC_SubA_HFthRTXA 0x0044
1290#define HC_SubA_HCMDQstL 0x0050
1291#define HC_SubA_HCMDQendL 0x0051
1292#define HC_SubA_HCMDQLen 0x0052
1293/* HC_SubA_HTArbRCM 0x0008
1294 */
1295#define HC_HTArbRCM_MASK 0x0000ffff
1296/* HC_SubA_HTArbRZ 0x000a
1297 */
1298#define HC_HTArbRZ_MASK 0x0000ffff
1299/* HC_SubA_HTArbWZ 0x000b
1300 */
1301#define HC_HTArbWZ_MASK 0x0000ffff
1302/* HC_SubA_HTArbRTX 0x000c
1303 */
1304#define HC_HTArbRTX_MASK 0x0000ffff
1305/* HC_SubA_HTArbRCW 0x000d
1306 */
1307#define HC_HTArbRCW_MASK 0x0000ffff
1308/* HC_SubA_HTArbE2 0x000e
1309 */
1310#define HC_HTArbE2_MASK 0x0000ffff
1311/* HC_SubA_HArbRQCM 0x0010
1312 */
1313#define HC_HTArbRQCM_MASK 0x0000ffff
1314/* HC_SubA_HArbWQCM 0x0011
1315 */
1316#define HC_HArbWQCM_MASK 0x0000ffff
1317/* HC_SubA_HGEMITout 0x0020
1318 */
1319#define HC_HGEMITout_MASK 0x000f0000
1320#define HC_HNPArbZC_MASK 0x0000ffff
1321#define HC_HGEMITout_SHIFT 16
1322/* HC_SubA_HFthRTXD 0x0040
1323 */
1324#define HC_HFthRTXD_MASK 0x00ff0000
1325#define HC_HFthRZD_MASK 0x0000ff00
1326#define HC_HFthWZD_MASK 0x000000ff
1327#define HC_HFthRTXD_SHIFT 16
1328#define HC_HFthRZD_SHIFT 8
1329/* HC_SubA_HFthRTXA 0x0044
1330 */
1331#define HC_HFthRTXA_MASK 0x000000ff
1332
1333/******************************************************************************
1334** Define the Halcyon Internal register access constants. For simulator only.
1335******************************************************************************/
1336#define HC_SIMA_HAGPBstL 0x0000
1337#define HC_SIMA_HAGPBendL 0x0001
1338#define HC_SIMA_HAGPCMNT 0x0002
1339#define HC_SIMA_HAGPBpL 0x0003
1340#define HC_SIMA_HAGPBpH 0x0004
1341#define HC_SIMA_HClipTB 0x0005
1342#define HC_SIMA_HClipLR 0x0006
1343#define HC_SIMA_HFPClipTL 0x0007
1344#define HC_SIMA_HFPClipBL 0x0008
1345#define HC_SIMA_HFPClipLL 0x0009
1346#define HC_SIMA_HFPClipRL 0x000a
1347#define HC_SIMA_HFPClipTBH 0x000b
1348#define HC_SIMA_HFPClipLRH 0x000c
1349#define HC_SIMA_HLP 0x000d
1350#define HC_SIMA_HLPRF 0x000e
1351#define HC_SIMA_HSolidCL 0x000f
1352#define HC_SIMA_HPixGC 0x0010
1353#define HC_SIMA_HSPXYOS 0x0011
1354#define HC_SIMA_HCmdA 0x0012
1355#define HC_SIMA_HCmdB 0x0013
1356#define HC_SIMA_HEnable 0x0014
1357#define HC_SIMA_HZWBBasL 0x0015
1358#define HC_SIMA_HZWBBasH 0x0016
1359#define HC_SIMA_HZWBType 0x0017
1360#define HC_SIMA_HZBiasL 0x0018
1361#define HC_SIMA_HZWBend 0x0019
1362#define HC_SIMA_HZWTMD 0x001a
1363#define HC_SIMA_HZWCDL 0x001b
1364#define HC_SIMA_HZWCTAGnum 0x001c
1365#define HC_SIMA_HZCYNum 0x001d
1366#define HC_SIMA_HZWCFire 0x001e
1367/* #define HC_SIMA_HSBBasL 0x001d */
1368/* #define HC_SIMA_HSBBasH 0x001e */
1369/* #define HC_SIMA_HSBFM 0x001f */
1370#define HC_SIMA_HSTREF 0x0020
1371#define HC_SIMA_HSTMD 0x0021
1372#define HC_SIMA_HABBasL 0x0022
1373#define HC_SIMA_HABBasH 0x0023
1374#define HC_SIMA_HABFM 0x0024
1375#define HC_SIMA_HATMD 0x0025
1376#define HC_SIMA_HABLCsat 0x0026
1377#define HC_SIMA_HABLCop 0x0027
1378#define HC_SIMA_HABLAsat 0x0028
1379#define HC_SIMA_HABLAop 0x0029
1380#define HC_SIMA_HABLRCa 0x002a
1381#define HC_SIMA_HABLRFCa 0x002b
1382#define HC_SIMA_HABLRCbias 0x002c
1383#define HC_SIMA_HABLRCb 0x002d
1384#define HC_SIMA_HABLRFCb 0x002e
1385#define HC_SIMA_HABLRAa 0x002f
1386#define HC_SIMA_HABLRAb 0x0030
1387#define HC_SIMA_HDBBasL 0x0031
1388#define HC_SIMA_HDBBasH 0x0032
1389#define HC_SIMA_HDBFM 0x0033
1390#define HC_SIMA_HFBBMSKL 0x0034
1391#define HC_SIMA_HROP 0x0035
1392#define HC_SIMA_HFogLF 0x0036
1393#define HC_SIMA_HFogCL 0x0037
1394#define HC_SIMA_HFogCH 0x0038
1395#define HC_SIMA_HFogStL 0x0039
1396#define HC_SIMA_HFogStH 0x003a
1397#define HC_SIMA_HFogOOdMF 0x003b
1398#define HC_SIMA_HFogOOdEF 0x003c
1399#define HC_SIMA_HFogEndL 0x003d
1400#define HC_SIMA_HFogDenst 0x003e
1401/*---- start of texture 0 setting ----
1402 */
1403#define HC_SIMA_HTX0L0BasL 0x0040
1404#define HC_SIMA_HTX0L1BasL 0x0041
1405#define HC_SIMA_HTX0L2BasL 0x0042
1406#define HC_SIMA_HTX0L3BasL 0x0043
1407#define HC_SIMA_HTX0L4BasL 0x0044
1408#define HC_SIMA_HTX0L5BasL 0x0045
1409#define HC_SIMA_HTX0L6BasL 0x0046
1410#define HC_SIMA_HTX0L7BasL 0x0047
1411#define HC_SIMA_HTX0L8BasL 0x0048
1412#define HC_SIMA_HTX0L9BasL 0x0049
1413#define HC_SIMA_HTX0LaBasL 0x004a
1414#define HC_SIMA_HTX0LbBasL 0x004b
1415#define HC_SIMA_HTX0LcBasL 0x004c
1416#define HC_SIMA_HTX0LdBasL 0x004d
1417#define HC_SIMA_HTX0LeBasL 0x004e
1418#define HC_SIMA_HTX0LfBasL 0x004f
1419#define HC_SIMA_HTX0L10BasL 0x0050
1420#define HC_SIMA_HTX0L11BasL 0x0051
1421#define HC_SIMA_HTX0L012BasH 0x0052
1422#define HC_SIMA_HTX0L345BasH 0x0053
1423#define HC_SIMA_HTX0L678BasH 0x0054
1424#define HC_SIMA_HTX0L9abBasH 0x0055
1425#define HC_SIMA_HTX0LcdeBasH 0x0056
1426#define HC_SIMA_HTX0Lf1011BasH 0x0057
1427#define HC_SIMA_HTX0L0Pit 0x0058
1428#define HC_SIMA_HTX0L1Pit 0x0059
1429#define HC_SIMA_HTX0L2Pit 0x005a
1430#define HC_SIMA_HTX0L3Pit 0x005b
1431#define HC_SIMA_HTX0L4Pit 0x005c
1432#define HC_SIMA_HTX0L5Pit 0x005d
1433#define HC_SIMA_HTX0L6Pit 0x005e
1434#define HC_SIMA_HTX0L7Pit 0x005f
1435#define HC_SIMA_HTX0L8Pit 0x0060
1436#define HC_SIMA_HTX0L9Pit 0x0061
1437#define HC_SIMA_HTX0LaPit 0x0062
1438#define HC_SIMA_HTX0LbPit 0x0063
1439#define HC_SIMA_HTX0LcPit 0x0064
1440#define HC_SIMA_HTX0LdPit 0x0065
1441#define HC_SIMA_HTX0LePit 0x0066
1442#define HC_SIMA_HTX0LfPit 0x0067
1443#define HC_SIMA_HTX0L10Pit 0x0068
1444#define HC_SIMA_HTX0L11Pit 0x0069
1445#define HC_SIMA_HTX0L0_5WE 0x006a
1446#define HC_SIMA_HTX0L6_bWE 0x006b
1447#define HC_SIMA_HTX0Lc_11WE 0x006c
1448#define HC_SIMA_HTX0L0_5HE 0x006d
1449#define HC_SIMA_HTX0L6_bHE 0x006e
1450#define HC_SIMA_HTX0Lc_11HE 0x006f
1451#define HC_SIMA_HTX0L0OS 0x0070
1452#define HC_SIMA_HTX0TB 0x0071
1453#define HC_SIMA_HTX0MPMD 0x0072
1454#define HC_SIMA_HTX0CLODu 0x0073
1455#define HC_SIMA_HTX0FM 0x0074
1456#define HC_SIMA_HTX0TRCH 0x0075
1457#define HC_SIMA_HTX0TRCL 0x0076
1458#define HC_SIMA_HTX0TBC 0x0077
1459#define HC_SIMA_HTX0TRAH 0x0078
1460#define HC_SIMA_HTX0TBLCsat 0x0079
1461#define HC_SIMA_HTX0TBLCop 0x007a
1462#define HC_SIMA_HTX0TBLMPfog 0x007b
1463#define HC_SIMA_HTX0TBLAsat 0x007c
1464#define HC_SIMA_HTX0TBLRCa 0x007d
1465#define HC_SIMA_HTX0TBLRCb 0x007e
1466#define HC_SIMA_HTX0TBLRCc 0x007f
1467#define HC_SIMA_HTX0TBLRCbias 0x0080
1468#define HC_SIMA_HTX0TBLRAa 0x0081
1469#define HC_SIMA_HTX0TBLRFog 0x0082
1470#define HC_SIMA_HTX0BumpM00 0x0083
1471#define HC_SIMA_HTX0BumpM01 0x0084
1472#define HC_SIMA_HTX0BumpM10 0x0085
1473#define HC_SIMA_HTX0BumpM11 0x0086
1474#define HC_SIMA_HTX0LScale 0x0087
1475/*---- end of texture 0 setting ---- 0x008f
1476 */
1477#define HC_SIMA_TX0TX1_OFF 0x0050
1478/*---- start of texture 1 setting ----
1479 */
1480#define HC_SIMA_HTX1L0BasL (HC_SIMA_HTX0L0BasL + HC_SIMA_TX0TX1_OFF)
1481#define HC_SIMA_HTX1L1BasL (HC_SIMA_HTX0L1BasL + HC_SIMA_TX0TX1_OFF)
1482#define HC_SIMA_HTX1L2BasL (HC_SIMA_HTX0L2BasL + HC_SIMA_TX0TX1_OFF)
1483#define HC_SIMA_HTX1L3BasL (HC_SIMA_HTX0L3BasL + HC_SIMA_TX0TX1_OFF)
1484#define HC_SIMA_HTX1L4BasL (HC_SIMA_HTX0L4BasL + HC_SIMA_TX0TX1_OFF)
1485#define HC_SIMA_HTX1L5BasL (HC_SIMA_HTX0L5BasL + HC_SIMA_TX0TX1_OFF)
1486#define HC_SIMA_HTX1L6BasL (HC_SIMA_HTX0L6BasL + HC_SIMA_TX0TX1_OFF)
1487#define HC_SIMA_HTX1L7BasL (HC_SIMA_HTX0L7BasL + HC_SIMA_TX0TX1_OFF)
1488#define HC_SIMA_HTX1L8BasL (HC_SIMA_HTX0L8BasL + HC_SIMA_TX0TX1_OFF)
1489#define HC_SIMA_HTX1L9BasL (HC_SIMA_HTX0L9BasL + HC_SIMA_TX0TX1_OFF)
1490#define HC_SIMA_HTX1LaBasL (HC_SIMA_HTX0LaBasL + HC_SIMA_TX0TX1_OFF)
1491#define HC_SIMA_HTX1LbBasL (HC_SIMA_HTX0LbBasL + HC_SIMA_TX0TX1_OFF)
1492#define HC_SIMA_HTX1LcBasL (HC_SIMA_HTX0LcBasL + HC_SIMA_TX0TX1_OFF)
1493#define HC_SIMA_HTX1LdBasL (HC_SIMA_HTX0LdBasL + HC_SIMA_TX0TX1_OFF)
1494#define HC_SIMA_HTX1LeBasL (HC_SIMA_HTX0LeBasL + HC_SIMA_TX0TX1_OFF)
1495#define HC_SIMA_HTX1LfBasL (HC_SIMA_HTX0LfBasL + HC_SIMA_TX0TX1_OFF)
1496#define HC_SIMA_HTX1L10BasL (HC_SIMA_HTX0L10BasL + HC_SIMA_TX0TX1_OFF)
1497#define HC_SIMA_HTX1L11BasL (HC_SIMA_HTX0L11BasL + HC_SIMA_TX0TX1_OFF)
1498#define HC_SIMA_HTX1L012BasH (HC_SIMA_HTX0L012BasH + HC_SIMA_TX0TX1_OFF)
1499#define HC_SIMA_HTX1L345BasH (HC_SIMA_HTX0L345BasH + HC_SIMA_TX0TX1_OFF)
1500#define HC_SIMA_HTX1L678BasH (HC_SIMA_HTX0L678BasH + HC_SIMA_TX0TX1_OFF)
1501#define HC_SIMA_HTX1L9abBasH (HC_SIMA_HTX0L9abBasH + HC_SIMA_TX0TX1_OFF)
1502#define HC_SIMA_HTX1LcdeBasH (HC_SIMA_HTX0LcdeBasH + HC_SIMA_TX0TX1_OFF)
1503#define HC_SIMA_HTX1Lf1011BasH (HC_SIMA_HTX0Lf1011BasH + HC_SIMA_TX0TX1_OFF)
1504#define HC_SIMA_HTX1L0Pit (HC_SIMA_HTX0L0Pit + HC_SIMA_TX0TX1_OFF)
1505#define HC_SIMA_HTX1L1Pit (HC_SIMA_HTX0L1Pit + HC_SIMA_TX0TX1_OFF)
1506#define HC_SIMA_HTX1L2Pit (HC_SIMA_HTX0L2Pit + HC_SIMA_TX0TX1_OFF)
1507#define HC_SIMA_HTX1L3Pit (HC_SIMA_HTX0L3Pit + HC_SIMA_TX0TX1_OFF)
1508#define HC_SIMA_HTX1L4Pit (HC_SIMA_HTX0L4Pit + HC_SIMA_TX0TX1_OFF)
1509#define HC_SIMA_HTX1L5Pit (HC_SIMA_HTX0L5Pit + HC_SIMA_TX0TX1_OFF)
1510#define HC_SIMA_HTX1L6Pit (HC_SIMA_HTX0L6Pit + HC_SIMA_TX0TX1_OFF)
1511#define HC_SIMA_HTX1L7Pit (HC_SIMA_HTX0L7Pit + HC_SIMA_TX0TX1_OFF)
1512#define HC_SIMA_HTX1L8Pit (HC_SIMA_HTX0L8Pit + HC_SIMA_TX0TX1_OFF)
1513#define HC_SIMA_HTX1L9Pit (HC_SIMA_HTX0L9Pit + HC_SIMA_TX0TX1_OFF)
1514#define HC_SIMA_HTX1LaPit (HC_SIMA_HTX0LaPit + HC_SIMA_TX0TX1_OFF)
1515#define HC_SIMA_HTX1LbPit (HC_SIMA_HTX0LbPit + HC_SIMA_TX0TX1_OFF)
1516#define HC_SIMA_HTX1LcPit (HC_SIMA_HTX0LcPit + HC_SIMA_TX0TX1_OFF)
1517#define HC_SIMA_HTX1LdPit (HC_SIMA_HTX0LdPit + HC_SIMA_TX0TX1_OFF)
1518#define HC_SIMA_HTX1LePit (HC_SIMA_HTX0LePit + HC_SIMA_TX0TX1_OFF)
1519#define HC_SIMA_HTX1LfPit (HC_SIMA_HTX0LfPit + HC_SIMA_TX0TX1_OFF)
1520#define HC_SIMA_HTX1L10Pit (HC_SIMA_HTX0L10Pit + HC_SIMA_TX0TX1_OFF)
1521#define HC_SIMA_HTX1L11Pit (HC_SIMA_HTX0L11Pit + HC_SIMA_TX0TX1_OFF)
1522#define HC_SIMA_HTX1L0_5WE (HC_SIMA_HTX0L0_5WE + HC_SIMA_TX0TX1_OFF)
1523#define HC_SIMA_HTX1L6_bWE (HC_SIMA_HTX0L6_bWE + HC_SIMA_TX0TX1_OFF)
1524#define HC_SIMA_HTX1Lc_11WE (HC_SIMA_HTX0Lc_11WE + HC_SIMA_TX0TX1_OFF)
1525#define HC_SIMA_HTX1L0_5HE (HC_SIMA_HTX0L0_5HE + HC_SIMA_TX0TX1_OFF)
1526#define HC_SIMA_HTX1L6_bHE (HC_SIMA_HTX0L6_bHE + HC_SIMA_TX0TX1_OFF)
1527#define HC_SIMA_HTX1Lc_11HE (HC_SIMA_HTX0Lc_11HE + HC_SIMA_TX0TX1_OFF)
1528#define HC_SIMA_HTX1L0OS (HC_SIMA_HTX0L0OS + HC_SIMA_TX0TX1_OFF)
1529#define HC_SIMA_HTX1TB (HC_SIMA_HTX0TB + HC_SIMA_TX0TX1_OFF)
1530#define HC_SIMA_HTX1MPMD (HC_SIMA_HTX0MPMD + HC_SIMA_TX0TX1_OFF)
1531#define HC_SIMA_HTX1CLODu (HC_SIMA_HTX0CLODu + HC_SIMA_TX0TX1_OFF)
1532#define HC_SIMA_HTX1FM (HC_SIMA_HTX0FM + HC_SIMA_TX0TX1_OFF)
1533#define HC_SIMA_HTX1TRCH (HC_SIMA_HTX0TRCH + HC_SIMA_TX0TX1_OFF)
1534#define HC_SIMA_HTX1TRCL (HC_SIMA_HTX0TRCL + HC_SIMA_TX0TX1_OFF)
1535#define HC_SIMA_HTX1TBC (HC_SIMA_HTX0TBC + HC_SIMA_TX0TX1_OFF)
1536#define HC_SIMA_HTX1TRAH (HC_SIMA_HTX0TRAH + HC_SIMA_TX0TX1_OFF)
1537#define HC_SIMA_HTX1LTC (HC_SIMA_HTX0LTC + HC_SIMA_TX0TX1_OFF)
1538#define HC_SIMA_HTX1LTA (HC_SIMA_HTX0LTA + HC_SIMA_TX0TX1_OFF)
1539#define HC_SIMA_HTX1TBLCsat (HC_SIMA_HTX0TBLCsat + HC_SIMA_TX0TX1_OFF)
1540#define HC_SIMA_HTX1TBLCop (HC_SIMA_HTX0TBLCop + HC_SIMA_TX0TX1_OFF)
1541#define HC_SIMA_HTX1TBLMPfog (HC_SIMA_HTX0TBLMPfog + HC_SIMA_TX0TX1_OFF)
1542#define HC_SIMA_HTX1TBLAsat (HC_SIMA_HTX0TBLAsat + HC_SIMA_TX0TX1_OFF)
1543#define HC_SIMA_HTX1TBLRCa (HC_SIMA_HTX0TBLRCa + HC_SIMA_TX0TX1_OFF)
1544#define HC_SIMA_HTX1TBLRCb (HC_SIMA_HTX0TBLRCb + HC_SIMA_TX0TX1_OFF)
1545#define HC_SIMA_HTX1TBLRCc (HC_SIMA_HTX0TBLRCc + HC_SIMA_TX0TX1_OFF)
1546#define HC_SIMA_HTX1TBLRCbias (HC_SIMA_HTX0TBLRCbias + HC_SIMA_TX0TX1_OFF)
1547#define HC_SIMA_HTX1TBLRAa (HC_SIMA_HTX0TBLRAa + HC_SIMA_TX0TX1_OFF)
1548#define HC_SIMA_HTX1TBLRFog (HC_SIMA_HTX0TBLRFog + HC_SIMA_TX0TX1_OFF)
1549#define HC_SIMA_HTX1BumpM00 (HC_SIMA_HTX0BumpM00 + HC_SIMA_TX0TX1_OFF)
1550#define HC_SIMA_HTX1BumpM01 (HC_SIMA_HTX0BumpM01 + HC_SIMA_TX0TX1_OFF)
1551#define HC_SIMA_HTX1BumpM10 (HC_SIMA_HTX0BumpM10 + HC_SIMA_TX0TX1_OFF)
1552#define HC_SIMA_HTX1BumpM11 (HC_SIMA_HTX0BumpM11 + HC_SIMA_TX0TX1_OFF)
1553#define HC_SIMA_HTX1LScale (HC_SIMA_HTX0LScale + HC_SIMA_TX0TX1_OFF)
1554/*---- end of texture 1 setting ---- 0xaf
1555 */
1556#define HC_SIMA_HTXSMD 0x00b0
1557#define HC_SIMA_HenFIFOAT 0x00b1
1558#define HC_SIMA_HFBDrawFirst 0x00b2
1559#define HC_SIMA_HFBBasL 0x00b3
1560#define HC_SIMA_HTArbRCM 0x00b4
1561#define HC_SIMA_HTArbRZ 0x00b5
1562#define HC_SIMA_HTArbWZ 0x00b6
1563#define HC_SIMA_HTArbRTX 0x00b7
1564#define HC_SIMA_HTArbRCW 0x00b8
1565#define HC_SIMA_HTArbE2 0x00b9
1566#define HC_SIMA_HGEMITout 0x00ba
1567#define HC_SIMA_HFthRTXD 0x00bb
1568#define HC_SIMA_HFthRTXA 0x00bc
1569/* Define the texture palette 0
1570 */
1571#define HC_SIMA_HTP0 0x0100
1572#define HC_SIMA_HTP1 0x0200
1573#define HC_SIMA_FOGTABLE 0x0300
1574#define HC_SIMA_STIPPLE 0x0400
1575#define HC_SIMA_HE3Fire 0x0440
1576#define HC_SIMA_TRANS_SET 0x0441
1577#define HC_SIMA_HREngSt 0x0442
1578#define HC_SIMA_HRFIFOempty 0x0443
1579#define HC_SIMA_HRFIFOfull 0x0444
1580#define HC_SIMA_HRErr 0x0445
1581#define HC_SIMA_FIFOstatus 0x0446
1582
1583/******************************************************************************
1584** Define the AGP command header.
1585******************************************************************************/
1586#define HC_ACMD_MASK 0xfe000000
1587#define HC_ACMD_SUB_MASK 0x0c000000
1588#define HC_ACMD_HCmdA 0xee000000
1589#define HC_ACMD_HCmdB 0xec000000
1590#define HC_ACMD_HCmdC 0xea000000
1591#define HC_ACMD_H1 0xf0000000
1592#define HC_ACMD_H2 0xf2000000
1593#define HC_ACMD_H3 0xf4000000
1594#define HC_ACMD_H4 0xf6000000
1595
1596#define HC_ACMD_H1IO_MASK 0x000001ff
1597#define HC_ACMD_H2IO1_MASK 0x001ff000
1598#define HC_ACMD_H2IO2_MASK 0x000001ff
1599#define HC_ACMD_H2IO1_SHIFT 12
1600#define HC_ACMD_H2IO2_SHIFT 0
1601#define HC_ACMD_H3IO_MASK 0x000001ff
1602#define HC_ACMD_H3COUNT_MASK 0x01fff000
1603#define HC_ACMD_H3COUNT_SHIFT 12
1604#define HC_ACMD_H4ID_MASK 0x000001ff
1605#define HC_ACMD_H4COUNT_MASK 0x01fffe00
1606#define HC_ACMD_H4COUNT_SHIFT 9
1607
1608/********************************************************************************
1609** Define Header
1610********************************************************************************/
1611#define HC_HEADER2 0xF210F110
1612
1613/********************************************************************************
1614** Define Dummy Value
1615********************************************************************************/
1616#define HC_DUMMY 0xCCCCCCCC
1617/********************************************************************************
1618** Define for DMA use
1619********************************************************************************/
1620#define HALCYON_HEADER2 0XF210F110
1621#define HALCYON_FIRECMD 0XEE100000
1622#define HALCYON_FIREMASK 0XFFF00000
1623#define HALCYON_CMDB 0XEC000000
1624#define HALCYON_CMDBMASK 0XFFFE0000
1625#define HALCYON_SUB_ADDR0 0X00000000
1626#define HALCYON_HEADER1MASK 0XFFFFFC00
1627#define HALCYON_HEADER1 0XF0000000
1628#define HC_SubA_HAGPBstL 0x0060
1629#define HC_SubA_HAGPBendL 0x0061
1630#define HC_SubA_HAGPCMNT 0x0062
1631#define HC_SubA_HAGPBpL 0x0063
1632#define HC_SubA_HAGPBpH 0x0064
1633#define HC_HAGPCMNT_MASK 0x00800000
1634#define HC_HCmdErrClr_MASK 0x00400000
1635#define HC_HAGPBendH_MASK 0x0000ff00
1636#define HC_HAGPBstH_MASK 0x000000ff
1637#define HC_HAGPBendH_SHIFT 8
1638#define HC_HAGPBstH_SHIFT 0
1639#define HC_HAGPBpL_MASK 0x00fffffc
1640#define HC_HAGPBpID_MASK 0x00000003
1641#define HC_HAGPBpID_PAUSE 0x00000000
1642#define HC_HAGPBpID_JUMP 0x00000001
1643#define HC_HAGPBpID_STOP 0x00000002
1644#define HC_HAGPBpH_MASK 0x00ffffff
1645
1646
1647#define VIA_VIDEO_HEADER5 0xFE040000
1648#define VIA_VIDEO_HEADER6 0xFE050000
1649#define VIA_VIDEO_HEADER7 0xFE060000
1650#define VIA_VIDEOMASK 0xFFFF0000
1651#endif
diff --git a/drivers/char/drm/via_dma.c b/drivers/char/drm/via_dma.c
new file mode 100644
index 000000000000..82f839451622
--- /dev/null
+++ b/drivers/char/drm/via_dma.c
@@ -0,0 +1,741 @@
1/* via_dma.c -- DMA support for the VIA Unichrome/Pro
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Copyright 2004 Digeo, Inc., Palo Alto, CA, U.S.A.
7 * All Rights Reserved.
8 *
9 * Copyright 2004 The Unichrome project.
10 * All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sub license,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice (including the
20 * next paragraph) shall be included in all copies or substantial portions
21 * of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
26 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
27 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29 * USE OR OTHER DEALINGS IN THE SOFTWARE.
30 *
31 * Authors:
32 * Tungsten Graphics,
33 * Erdi Chen,
34 * Thomas Hellstrom.
35 */
36
37#include "drmP.h"
38#include "drm.h"
39#include "via_drm.h"
40#include "via_drv.h"
41#include "via_3d_reg.h"
42
43#define CMDBUF_ALIGNMENT_SIZE (0x100)
44#define CMDBUF_ALIGNMENT_MASK (0x0ff)
45
46/* defines for VIA 3D registers */
47#define VIA_REG_STATUS 0x400
48#define VIA_REG_TRANSET 0x43C
49#define VIA_REG_TRANSPACE 0x440
50
51/* VIA_REG_STATUS(0x400): Engine Status */
52#define VIA_CMD_RGTR_BUSY 0x00000080 /* Command Regulator is busy */
53#define VIA_2D_ENG_BUSY 0x00000001 /* 2D Engine is busy */
54#define VIA_3D_ENG_BUSY 0x00000002 /* 3D Engine is busy */
55#define VIA_VR_QUEUE_BUSY 0x00020000 /* Virtual Queue is busy */
56
57#define SetReg2DAGP(nReg, nData) { \
58 *((uint32_t *)(vb)) = ((nReg) >> 2) | HALCYON_HEADER1; \
59 *((uint32_t *)(vb) + 1) = (nData); \
60 vb = ((uint32_t *)vb) + 2; \
61 dev_priv->dma_low +=8; \
62}
63
64#define via_flush_write_combine() DRM_MEMORYBARRIER()
65
66#define VIA_OUT_RING_QW(w1,w2) \
67 *vb++ = (w1); \
68 *vb++ = (w2); \
69 dev_priv->dma_low += 8;
70
71static void via_cmdbuf_start(drm_via_private_t * dev_priv);
72static void via_cmdbuf_pause(drm_via_private_t * dev_priv);
73static void via_cmdbuf_reset(drm_via_private_t * dev_priv);
74static void via_cmdbuf_rewind(drm_via_private_t * dev_priv);
75static int via_wait_idle(drm_via_private_t * dev_priv);
76static void via_pad_cache(drm_via_private_t *dev_priv, int qwords);
77
78
79/*
80 * Free space in command buffer.
81 */
82
83static uint32_t
84via_cmdbuf_space(drm_via_private_t *dev_priv)
85{
86 uint32_t agp_base = dev_priv->dma_offset +
87 (uint32_t) dev_priv->agpAddr;
88 uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
89
90 return ((hw_addr <= dev_priv->dma_low) ?
91 (dev_priv->dma_high + hw_addr - dev_priv->dma_low) :
92 (hw_addr - dev_priv->dma_low));
93}
94
95/*
96 * How much does the command regulator lag behind?
97 */
98
99static uint32_t
100via_cmdbuf_lag(drm_via_private_t *dev_priv)
101{
102 uint32_t agp_base = dev_priv->dma_offset +
103 (uint32_t) dev_priv->agpAddr;
104 uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
105
106 return ((hw_addr <= dev_priv->dma_low) ?
107 (dev_priv->dma_low - hw_addr) :
108 (dev_priv->dma_wrap + dev_priv->dma_low - hw_addr));
109}
110
111/*
112 * Check that the given size fits in the buffer, otherwise wait.
113 */
114
115static inline int
116via_cmdbuf_wait(drm_via_private_t * dev_priv, unsigned int size)
117{
118 uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
119 uint32_t cur_addr, hw_addr, next_addr;
120 volatile uint32_t *hw_addr_ptr;
121 uint32_t count;
122 hw_addr_ptr = dev_priv->hw_addr_ptr;
123 cur_addr = dev_priv->dma_low;
124 next_addr = cur_addr + size + 512*1024;
125 count = 1000000;
126 do {
127 hw_addr = *hw_addr_ptr - agp_base;
128 if (count-- == 0) {
129 DRM_ERROR("via_cmdbuf_wait timed out hw %x cur_addr %x next_addr %x\n",
130 hw_addr, cur_addr, next_addr);
131 return -1;
132 }
133 } while ((cur_addr < hw_addr) && (next_addr >= hw_addr));
134 return 0;
135}
136
137
138/*
139 * Checks whether buffer head has reach the end. Rewind the ring buffer
140 * when necessary.
141 *
142 * Returns virtual pointer to ring buffer.
143 */
144
145static inline uint32_t *via_check_dma(drm_via_private_t * dev_priv,
146 unsigned int size)
147{
148 if ((dev_priv->dma_low + size + 4*CMDBUF_ALIGNMENT_SIZE) > dev_priv->dma_high) {
149 via_cmdbuf_rewind(dev_priv);
150 }
151 if (via_cmdbuf_wait(dev_priv, size) != 0) {
152 return NULL;
153 }
154
155 return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
156}
157
158int via_dma_cleanup(drm_device_t * dev)
159{
160 if (dev->dev_private) {
161 drm_via_private_t *dev_priv =
162 (drm_via_private_t *) dev->dev_private;
163
164 if (dev_priv->ring.virtual_start) {
165 via_cmdbuf_reset(dev_priv);
166
167 drm_core_ioremapfree(&dev_priv->ring.map, dev);
168 dev_priv->ring.virtual_start = NULL;
169 }
170
171 }
172
173 return 0;
174}
175
176static int via_initialize(drm_device_t * dev,
177 drm_via_private_t * dev_priv,
178 drm_via_dma_init_t * init)
179{
180 if (!dev_priv || !dev_priv->mmio) {
181 DRM_ERROR("via_dma_init called before via_map_init\n");
182 return DRM_ERR(EFAULT);
183 }
184
185 if (dev_priv->ring.virtual_start != NULL) {
186 DRM_ERROR("%s called again without calling cleanup\n",
187 __FUNCTION__);
188 return DRM_ERR(EFAULT);
189 }
190
191 if (!dev->agp || !dev->agp->base) {
192 DRM_ERROR("%s called with no agp memory available\n",
193 __FUNCTION__);
194 return DRM_ERR(EFAULT);
195 }
196
197 dev_priv->ring.map.offset = dev->agp->base + init->offset;
198 dev_priv->ring.map.size = init->size;
199 dev_priv->ring.map.type = 0;
200 dev_priv->ring.map.flags = 0;
201 dev_priv->ring.map.mtrr = 0;
202
203 drm_core_ioremap(&dev_priv->ring.map, dev);
204
205 if (dev_priv->ring.map.handle == NULL) {
206 via_dma_cleanup(dev);
207 DRM_ERROR("can not ioremap virtual address for"
208 " ring buffer\n");
209 return DRM_ERR(ENOMEM);
210 }
211
212 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
213
214 dev_priv->dma_ptr = dev_priv->ring.virtual_start;
215 dev_priv->dma_low = 0;
216 dev_priv->dma_high = init->size;
217 dev_priv->dma_wrap = init->size;
218 dev_priv->dma_offset = init->offset;
219 dev_priv->last_pause_ptr = NULL;
220 dev_priv->hw_addr_ptr = dev_priv->mmio->handle + init->reg_pause_addr;
221
222 via_cmdbuf_start(dev_priv);
223
224 return 0;
225}
226
227int via_dma_init(DRM_IOCTL_ARGS)
228{
229 DRM_DEVICE;
230 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
231 drm_via_dma_init_t init;
232 int retcode = 0;
233
234 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_dma_init_t *) data,
235 sizeof(init));
236
237 switch (init.func) {
238 case VIA_INIT_DMA:
239 if (!capable(CAP_SYS_ADMIN))
240 retcode = DRM_ERR(EPERM);
241 else
242 retcode = via_initialize(dev, dev_priv, &init);
243 break;
244 case VIA_CLEANUP_DMA:
245 if (!capable(CAP_SYS_ADMIN))
246 retcode = DRM_ERR(EPERM);
247 else
248 retcode = via_dma_cleanup(dev);
249 break;
250 case VIA_DMA_INITIALIZED:
251 retcode = (dev_priv->ring.virtual_start != NULL) ?
252 0: DRM_ERR( EFAULT );
253 break;
254 default:
255 retcode = DRM_ERR(EINVAL);
256 break;
257 }
258
259 return retcode;
260}
261
262
263
264static int via_dispatch_cmdbuffer(drm_device_t * dev, drm_via_cmdbuffer_t * cmd)
265{
266 drm_via_private_t *dev_priv;
267 uint32_t *vb;
268 int ret;
269
270 dev_priv = (drm_via_private_t *) dev->dev_private;
271
272 if (dev_priv->ring.virtual_start == NULL) {
273 DRM_ERROR("%s called without initializing AGP ring buffer.\n",
274 __FUNCTION__);
275 return DRM_ERR(EFAULT);
276 }
277
278 if (cmd->size > VIA_PCI_BUF_SIZE) {
279 return DRM_ERR(ENOMEM);
280 }
281
282
283 if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
284 return DRM_ERR(EFAULT);
285
286 /*
287 * Running this function on AGP memory is dead slow. Therefore
288 * we run it on a temporary cacheable system memory buffer and
289 * copy it to AGP memory when ready.
290 */
291
292
293 if ((ret = via_verify_command_stream((uint32_t *)dev_priv->pci_buf, cmd->size, dev, 1))) {
294 return ret;
295 }
296
297
298 vb = via_check_dma(dev_priv, (cmd->size < 0x100) ? 0x102 : cmd->size);
299 if (vb == NULL) {
300 return DRM_ERR(EAGAIN);
301 }
302
303 memcpy(vb, dev_priv->pci_buf, cmd->size);
304
305 dev_priv->dma_low += cmd->size;
306
307 /*
308 * Small submissions somehow stalls the CPU. (AGP cache effects?)
309 * pad to greater size.
310 */
311
312 if (cmd->size < 0x100)
313 via_pad_cache(dev_priv,(0x100 - cmd->size) >> 3);
314 via_cmdbuf_pause(dev_priv);
315
316 return 0;
317}
318
319int via_driver_dma_quiescent(drm_device_t * dev)
320{
321 drm_via_private_t *dev_priv = dev->dev_private;
322
323 if (!via_wait_idle(dev_priv)) {
324 return DRM_ERR(EBUSY);
325 }
326 return 0;
327}
328
329int via_flush_ioctl(DRM_IOCTL_ARGS)
330{
331 DRM_DEVICE;
332
333 LOCK_TEST_WITH_RETURN( dev, filp );
334
335 return via_driver_dma_quiescent(dev);
336}
337
338int via_cmdbuffer(DRM_IOCTL_ARGS)
339{
340 DRM_DEVICE;
341 drm_via_cmdbuffer_t cmdbuf;
342 int ret;
343
344 LOCK_TEST_WITH_RETURN( dev, filp );
345
346 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t *) data,
347 sizeof(cmdbuf));
348
349 DRM_DEBUG("via cmdbuffer, buf %p size %lu\n", cmdbuf.buf, cmdbuf.size);
350
351 ret = via_dispatch_cmdbuffer(dev, &cmdbuf);
352 if (ret) {
353 return ret;
354 }
355
356 return 0;
357}
358
359extern int
360via_parse_command_stream(drm_device_t *dev, const uint32_t * buf, unsigned int size);
361static int via_dispatch_pci_cmdbuffer(drm_device_t * dev,
362 drm_via_cmdbuffer_t * cmd)
363{
364 drm_via_private_t *dev_priv = dev->dev_private;
365 int ret;
366
367 if (cmd->size > VIA_PCI_BUF_SIZE) {
368 return DRM_ERR(ENOMEM);
369 }
370 if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
371 return DRM_ERR(EFAULT);
372
373 if ((ret = via_verify_command_stream((uint32_t *)dev_priv->pci_buf, cmd->size, dev, 0))) {
374 return ret;
375 }
376
377 ret = via_parse_command_stream(dev, (const uint32_t *)dev_priv->pci_buf, cmd->size);
378 return ret;
379}
380
381int via_pci_cmdbuffer(DRM_IOCTL_ARGS)
382{
383 DRM_DEVICE;
384 drm_via_cmdbuffer_t cmdbuf;
385 int ret;
386
387 LOCK_TEST_WITH_RETURN( dev, filp );
388
389 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t *) data,
390 sizeof(cmdbuf));
391
392 DRM_DEBUG("via_pci_cmdbuffer, buf %p size %lu\n", cmdbuf.buf,
393 cmdbuf.size);
394
395 ret = via_dispatch_pci_cmdbuffer(dev, &cmdbuf);
396 if (ret) {
397 return ret;
398 }
399
400 return 0;
401}
402
403
404static inline uint32_t *via_align_buffer(drm_via_private_t * dev_priv,
405 uint32_t * vb, int qw_count)
406{
407 for (; qw_count > 0; --qw_count) {
408 VIA_OUT_RING_QW(HC_DUMMY, HC_DUMMY);
409 }
410 return vb;
411}
412
413
414/*
415 * This function is used internally by ring buffer mangement code.
416 *
417 * Returns virtual pointer to ring buffer.
418 */
419static inline uint32_t *via_get_dma(drm_via_private_t * dev_priv)
420{
421 return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
422}
423
424/*
425 * Hooks a segment of data into the tail of the ring-buffer by
426 * modifying the pause address stored in the buffer itself. If
427 * the regulator has already paused, restart it.
428 */
429static int via_hook_segment(drm_via_private_t *dev_priv,
430 uint32_t pause_addr_hi, uint32_t pause_addr_lo,
431 int no_pci_fire)
432{
433 int paused, count;
434 volatile uint32_t *paused_at = dev_priv->last_pause_ptr;
435
436 via_flush_write_combine();
437 while(! *(via_get_dma(dev_priv)-1));
438 *dev_priv->last_pause_ptr = pause_addr_lo;
439 via_flush_write_combine();
440
441 /*
442 * The below statement is inserted to really force the flush.
443 * Not sure it is needed.
444 */
445
446 while(! *dev_priv->last_pause_ptr);
447 dev_priv->last_pause_ptr = via_get_dma(dev_priv) - 1;
448 while(! *dev_priv->last_pause_ptr);
449
450
451 paused = 0;
452 count = 20;
453
454 while (!(paused = (VIA_READ(0x41c) & 0x80000000)) && count--);
455 if ((count <= 8) && (count >= 0)) {
456 uint32_t rgtr, ptr;
457 rgtr = *(dev_priv->hw_addr_ptr);
458 ptr = ((char *)dev_priv->last_pause_ptr - dev_priv->dma_ptr) +
459 dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4 -
460 CMDBUF_ALIGNMENT_SIZE;
461 if (rgtr <= ptr) {
462 DRM_ERROR("Command regulator\npaused at count %d, address %x, "
463 "while current pause address is %x.\n"
464 "Please mail this message to "
465 "<unichrome-devel@lists.sourceforge.net>\n",
466 count, rgtr, ptr);
467 }
468 }
469
470 if (paused && !no_pci_fire) {
471 uint32_t rgtr,ptr;
472 uint32_t ptr_low;
473
474 count = 1000000;
475 while ((VIA_READ(VIA_REG_STATUS) & VIA_CMD_RGTR_BUSY) && count--);
476
477 rgtr = *(dev_priv->hw_addr_ptr);
478 ptr = ((char *)paused_at - dev_priv->dma_ptr) +
479 dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
480
481
482 ptr_low = (ptr > 3*CMDBUF_ALIGNMENT_SIZE) ?
483 ptr - 3*CMDBUF_ALIGNMENT_SIZE : 0;
484 if (rgtr <= ptr && rgtr >= ptr_low) {
485 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
486 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
487 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
488 }
489 }
490 return paused;
491}
492
493
494
495static int via_wait_idle(drm_via_private_t * dev_priv)
496{
497 int count = 10000000;
498 while (count-- && (VIA_READ(VIA_REG_STATUS) &
499 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
500 VIA_3D_ENG_BUSY))) ;
501 return count;
502}
503
504static uint32_t *via_align_cmd(drm_via_private_t * dev_priv, uint32_t cmd_type,
505 uint32_t addr, uint32_t *cmd_addr_hi,
506 uint32_t *cmd_addr_lo,
507 int skip_wait)
508{
509 uint32_t agp_base;
510 uint32_t cmd_addr, addr_lo, addr_hi;
511 uint32_t *vb;
512 uint32_t qw_pad_count;
513
514 if (!skip_wait)
515 via_cmdbuf_wait(dev_priv, 2*CMDBUF_ALIGNMENT_SIZE);
516
517 vb = via_get_dma(dev_priv);
518 VIA_OUT_RING_QW( HC_HEADER2 | ((VIA_REG_TRANSET >> 2) << 12) |
519 (VIA_REG_TRANSPACE >> 2), HC_ParaType_PreCR << 16);
520 agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
521 qw_pad_count = (CMDBUF_ALIGNMENT_SIZE >> 3) -
522 ((dev_priv->dma_low & CMDBUF_ALIGNMENT_MASK) >> 3);
523
524
525 cmd_addr = (addr) ? addr :
526 agp_base + dev_priv->dma_low - 8 + (qw_pad_count << 3);
527 addr_lo = ((HC_SubA_HAGPBpL << 24) | (cmd_type & HC_HAGPBpID_MASK) |
528 (cmd_addr & HC_HAGPBpL_MASK));
529 addr_hi = ((HC_SubA_HAGPBpH << 24) | (cmd_addr >> 24));
530
531 vb = via_align_buffer(dev_priv, vb, qw_pad_count - 1);
532 VIA_OUT_RING_QW(*cmd_addr_hi = addr_hi,
533 *cmd_addr_lo = addr_lo);
534 return vb;
535}
536
537
538
539
540static void via_cmdbuf_start(drm_via_private_t * dev_priv)
541{
542 uint32_t pause_addr_lo, pause_addr_hi;
543 uint32_t start_addr, start_addr_lo;
544 uint32_t end_addr, end_addr_lo;
545 uint32_t command;
546 uint32_t agp_base;
547
548
549 dev_priv->dma_low = 0;
550
551 agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
552 start_addr = agp_base;
553 end_addr = agp_base + dev_priv->dma_high;
554
555 start_addr_lo = ((HC_SubA_HAGPBstL << 24) | (start_addr & 0xFFFFFF));
556 end_addr_lo = ((HC_SubA_HAGPBendL << 24) | (end_addr & 0xFFFFFF));
557 command = ((HC_SubA_HAGPCMNT << 24) | (start_addr >> 24) |
558 ((end_addr & 0xff000000) >> 16));
559
560 dev_priv->last_pause_ptr =
561 via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0,
562 &pause_addr_hi, & pause_addr_lo, 1) - 1;
563
564 via_flush_write_combine();
565 while(! *dev_priv->last_pause_ptr);
566
567 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
568 VIA_WRITE(VIA_REG_TRANSPACE, command);
569 VIA_WRITE(VIA_REG_TRANSPACE, start_addr_lo);
570 VIA_WRITE(VIA_REG_TRANSPACE, end_addr_lo);
571
572 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
573 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
574
575 VIA_WRITE(VIA_REG_TRANSPACE, command | HC_HAGPCMNT_MASK);
576}
577
578static void via_pad_cache(drm_via_private_t *dev_priv, int qwords)
579{
580 uint32_t *vb;
581
582 via_cmdbuf_wait(dev_priv, qwords + 2);
583 vb = via_get_dma(dev_priv);
584 VIA_OUT_RING_QW( HC_HEADER2, HC_ParaType_NotTex << 16);
585 via_align_buffer(dev_priv,vb,qwords);
586}
587
588static inline void via_dummy_bitblt(drm_via_private_t * dev_priv)
589{
590 uint32_t *vb = via_get_dma(dev_priv);
591 SetReg2DAGP(0x0C, (0 | (0 << 16)));
592 SetReg2DAGP(0x10, 0 | (0 << 16));
593 SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xAA000000);
594}
595
596
597static void via_cmdbuf_jump(drm_via_private_t * dev_priv)
598{
599 uint32_t agp_base;
600 uint32_t pause_addr_lo, pause_addr_hi;
601 uint32_t jump_addr_lo, jump_addr_hi;
602 volatile uint32_t *last_pause_ptr;
603 uint32_t dma_low_save1, dma_low_save2;
604
605 agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
606 via_align_cmd(dev_priv, HC_HAGPBpID_JUMP, 0, &jump_addr_hi,
607 &jump_addr_lo, 0);
608
609 dev_priv->dma_wrap = dev_priv->dma_low;
610
611
612 /*
613 * Wrap command buffer to the beginning.
614 */
615
616 dev_priv->dma_low = 0;
617 if (via_cmdbuf_wait(dev_priv, CMDBUF_ALIGNMENT_SIZE) != 0) {
618 DRM_ERROR("via_cmdbuf_jump failed\n");
619 }
620
621 via_dummy_bitblt(dev_priv);
622 via_dummy_bitblt(dev_priv);
623
624 last_pause_ptr = via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
625 &pause_addr_lo, 0) -1;
626 via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
627 &pause_addr_lo, 0);
628
629 *last_pause_ptr = pause_addr_lo;
630 dma_low_save1 = dev_priv->dma_low;
631
632 /*
633 * Now, set a trap that will pause the regulator if it tries to rerun the old
634 * command buffer. (Which may happen if via_hook_segment detecs a command regulator pause
635 * and reissues the jump command over PCI, while the regulator has already taken the jump
636 * and actually paused at the current buffer end).
637 * There appears to be no other way to detect this condition, since the hw_addr_pointer
638 * does not seem to get updated immediately when a jump occurs.
639 */
640
641 last_pause_ptr = via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
642 &pause_addr_lo, 0) -1;
643 via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
644 &pause_addr_lo, 0);
645 *last_pause_ptr = pause_addr_lo;
646
647 dma_low_save2 = dev_priv->dma_low;
648 dev_priv->dma_low = dma_low_save1;
649 via_hook_segment( dev_priv, jump_addr_hi, jump_addr_lo, 0);
650 dev_priv->dma_low = dma_low_save2;
651 via_hook_segment( dev_priv, pause_addr_hi, pause_addr_lo, 0);
652}
653
654
655static void via_cmdbuf_rewind(drm_via_private_t * dev_priv)
656{
657 via_cmdbuf_jump(dev_priv);
658}
659
660static void via_cmdbuf_flush(drm_via_private_t * dev_priv, uint32_t cmd_type)
661{
662 uint32_t pause_addr_lo, pause_addr_hi;
663
664 via_align_cmd(dev_priv, cmd_type, 0, &pause_addr_hi, &pause_addr_lo, 0);
665 via_hook_segment( dev_priv, pause_addr_hi, pause_addr_lo, 0);
666}
667
668
669static void via_cmdbuf_pause(drm_via_private_t * dev_priv)
670{
671 via_cmdbuf_flush(dev_priv, HC_HAGPBpID_PAUSE);
672}
673
674static void via_cmdbuf_reset(drm_via_private_t * dev_priv)
675{
676 via_cmdbuf_flush(dev_priv, HC_HAGPBpID_STOP);
677 via_wait_idle(dev_priv);
678}
679
680/*
681 * User interface to the space and lag functions.
682 */
683
684int
685via_cmdbuf_size(DRM_IOCTL_ARGS)
686{
687 DRM_DEVICE;
688 drm_via_cmdbuf_size_t d_siz;
689 int ret = 0;
690 uint32_t tmp_size, count;
691 drm_via_private_t *dev_priv;
692
693 DRM_DEBUG("via cmdbuf_size\n");
694 LOCK_TEST_WITH_RETURN( dev, filp );
695
696 dev_priv = (drm_via_private_t *) dev->dev_private;
697
698 if (dev_priv->ring.virtual_start == NULL) {
699 DRM_ERROR("%s called without initializing AGP ring buffer.\n",
700 __FUNCTION__);
701 return DRM_ERR(EFAULT);
702 }
703
704 DRM_COPY_FROM_USER_IOCTL(d_siz, (drm_via_cmdbuf_size_t *) data,
705 sizeof(d_siz));
706
707
708 count = 1000000;
709 tmp_size = d_siz.size;
710 switch(d_siz.func) {
711 case VIA_CMDBUF_SPACE:
712 while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz.size) && count--) {
713 if (!d_siz.wait) {
714 break;
715 }
716 }
717 if (!count) {
718 DRM_ERROR("VIA_CMDBUF_SPACE timed out.\n");
719 ret = DRM_ERR(EAGAIN);
720 }
721 break;
722 case VIA_CMDBUF_LAG:
723 while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz.size) && count--) {
724 if (!d_siz.wait) {
725 break;
726 }
727 }
728 if (!count) {
729 DRM_ERROR("VIA_CMDBUF_LAG timed out.\n");
730 ret = DRM_ERR(EAGAIN);
731 }
732 break;
733 default:
734 ret = DRM_ERR(EFAULT);
735 }
736 d_siz.size = tmp_size;
737
738 DRM_COPY_TO_USER_IOCTL((drm_via_cmdbuf_size_t *) data, d_siz,
739 sizeof(d_siz));
740 return ret;
741}
diff --git a/drivers/char/drm/via_drm.h b/drivers/char/drm/via_drm.h
new file mode 100644
index 000000000000..4588c9bd1816
--- /dev/null
+++ b/drivers/char/drm/via_drm.h
@@ -0,0 +1,243 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#ifndef _VIA_DRM_H_
25#define _VIA_DRM_H_
26
27/* WARNING: These defines must be the same as what the Xserver uses.
28 * if you change them, you must change the defines in the Xserver.
29 */
30
31#ifndef _VIA_DEFINES_
32#define _VIA_DEFINES_
33
34#ifndef __KERNEL__
35#include "via_drmclient.h"
36#endif
37
38#define VIA_NR_SAREA_CLIPRECTS 8
39#define VIA_NR_XVMC_PORTS 10
40#define VIA_NR_XVMC_LOCKS 5
41#define VIA_MAX_CACHELINE_SIZE 64
42#define XVMCLOCKPTR(saPriv,lockNo) \
43 ((volatile drm_hw_lock_t *)(((((unsigned long) (saPriv)->XvMCLockArea) + \
44 (VIA_MAX_CACHELINE_SIZE - 1)) & \
45 ~(VIA_MAX_CACHELINE_SIZE - 1)) + \
46 VIA_MAX_CACHELINE_SIZE*(lockNo)))
47
48/* Each region is a minimum of 64k, and there are at most 64 of them.
49 */
50#define VIA_NR_TEX_REGIONS 64
51#define VIA_LOG_MIN_TEX_REGION_SIZE 16
52#endif
53
54#define VIA_UPLOAD_TEX0IMAGE 0x1 /* handled clientside */
55#define VIA_UPLOAD_TEX1IMAGE 0x2 /* handled clientside */
56#define VIA_UPLOAD_CTX 0x4
57#define VIA_UPLOAD_BUFFERS 0x8
58#define VIA_UPLOAD_TEX0 0x10
59#define VIA_UPLOAD_TEX1 0x20
60#define VIA_UPLOAD_CLIPRECTS 0x40
61#define VIA_UPLOAD_ALL 0xff
62
63/* VIA specific ioctls */
64#define DRM_VIA_ALLOCMEM 0x00
65#define DRM_VIA_FREEMEM 0x01
66#define DRM_VIA_AGP_INIT 0x02
67#define DRM_VIA_FB_INIT 0x03
68#define DRM_VIA_MAP_INIT 0x04
69#define DRM_VIA_DEC_FUTEX 0x05
70#define NOT_USED
71#define DRM_VIA_DMA_INIT 0x07
72#define DRM_VIA_CMDBUFFER 0x08
73#define DRM_VIA_FLUSH 0x09
74#define DRM_VIA_PCICMD 0x0a
75#define DRM_VIA_CMDBUF_SIZE 0x0b
76#define NOT_USED
77#define DRM_VIA_WAIT_IRQ 0x0d
78
79#define DRM_IOCTL_VIA_ALLOCMEM DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, drm_via_mem_t)
80#define DRM_IOCTL_VIA_FREEMEM DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, drm_via_mem_t)
81#define DRM_IOCTL_VIA_AGP_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_AGP_INIT, drm_via_agp_t)
82#define DRM_IOCTL_VIA_FB_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, drm_via_fb_t)
83#define DRM_IOCTL_VIA_MAP_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, drm_via_init_t)
84#define DRM_IOCTL_VIA_DEC_FUTEX DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_DEC_FUTEX, drm_via_futex_t)
85#define DRM_IOCTL_VIA_DMA_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, drm_via_dma_init_t)
86#define DRM_IOCTL_VIA_CMDBUFFER DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
87#define DRM_IOCTL_VIA_FLUSH DRM_IO( DRM_COMMAND_BASE + DRM_VIA_FLUSH)
88#define DRM_IOCTL_VIA_PCICMD DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_PCICMD, drm_via_cmdbuffer_t)
89#define DRM_IOCTL_VIA_CMDBUF_SIZE DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_CMDBUF_SIZE, \
90 drm_via_cmdbuf_size_t)
91#define DRM_IOCTL_VIA_WAIT_IRQ DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_WAIT_IRQ, drm_via_irqwait_t)
92
93/* Indices into buf.Setup where various bits of state are mirrored per
94 * context and per buffer. These can be fired at the card as a unit,
95 * or in a piecewise fashion as required.
96 */
97
98#define VIA_TEX_SETUP_SIZE 8
99
100/* Flags for clear ioctl
101 */
102#define VIA_FRONT 0x1
103#define VIA_BACK 0x2
104#define VIA_DEPTH 0x4
105#define VIA_STENCIL 0x8
106#define VIDEO 0
107#define AGP 1
108typedef struct {
109 uint32_t offset;
110 uint32_t size;
111} drm_via_agp_t;
112
113typedef struct {
114 uint32_t offset;
115 uint32_t size;
116} drm_via_fb_t;
117
118typedef struct {
119 uint32_t context;
120 uint32_t type;
121 uint32_t size;
122 unsigned long index;
123 unsigned long offset;
124} drm_via_mem_t;
125
126typedef struct _drm_via_init {
127 enum {
128 VIA_INIT_MAP = 0x01,
129 VIA_CLEANUP_MAP = 0x02
130 } func;
131
132 unsigned long sarea_priv_offset;
133 unsigned long fb_offset;
134 unsigned long mmio_offset;
135 unsigned long agpAddr;
136} drm_via_init_t;
137
138typedef struct _drm_via_futex {
139 enum {
140 VIA_FUTEX_WAIT = 0x00,
141 VIA_FUTEX_WAKE = 0X01
142 } func;
143 uint32_t ms;
144 uint32_t lock;
145 uint32_t val;
146} drm_via_futex_t;
147
148typedef struct _drm_via_dma_init {
149 enum {
150 VIA_INIT_DMA = 0x01,
151 VIA_CLEANUP_DMA = 0x02,
152 VIA_DMA_INITIALIZED = 0x03
153 } func;
154
155 unsigned long offset;
156 unsigned long size;
157 unsigned long reg_pause_addr;
158} drm_via_dma_init_t;
159
160typedef struct _drm_via_cmdbuffer {
161 char *buf;
162 unsigned long size;
163} drm_via_cmdbuffer_t;
164
165/* Warning: If you change the SAREA structure you must change the Xserver
166 * structure as well */
167
168typedef struct _drm_via_tex_region {
169 unsigned char next, prev; /* indices to form a circular LRU */
170 unsigned char inUse; /* owned by a client, or free? */
171 int age; /* tracked by clients to update local LRU's */
172} drm_via_tex_region_t;
173
174typedef struct _drm_via_sarea {
175 unsigned int dirty;
176 unsigned int nbox;
177 drm_clip_rect_t boxes[VIA_NR_SAREA_CLIPRECTS];
178 drm_via_tex_region_t texList[VIA_NR_TEX_REGIONS + 1];
179 int texAge; /* last time texture was uploaded */
180 int ctxOwner; /* last context to upload state */
181 int vertexPrim;
182
183 /*
184 * Below is for XvMC.
185 * We want the lock integers alone on, and aligned to, a cache line.
186 * Therefore this somewhat strange construct.
187 */
188
189 char XvMCLockArea[VIA_MAX_CACHELINE_SIZE * (VIA_NR_XVMC_LOCKS + 1)];
190
191 unsigned int XvMCDisplaying[VIA_NR_XVMC_PORTS];
192 unsigned int XvMCSubPicOn[VIA_NR_XVMC_PORTS];
193 unsigned int XvMCCtxNoGrabbed; /* Last context to hold decoder */
194
195} drm_via_sarea_t;
196
197typedef struct _drm_via_cmdbuf_size {
198 enum {
199 VIA_CMDBUF_SPACE = 0x01,
200 VIA_CMDBUF_LAG = 0x02
201 } func;
202 int wait;
203 uint32_t size;
204} drm_via_cmdbuf_size_t;
205
206typedef enum {
207 VIA_IRQ_ABSOLUTE = 0x0,
208 VIA_IRQ_RELATIVE = 0x1,
209 VIA_IRQ_SIGNAL = 0x10000000,
210 VIA_IRQ_FORCE_SEQUENCE = 0x20000000
211} via_irq_seq_type_t;
212
213#define VIA_IRQ_FLAGS_MASK 0xF0000000
214
215struct drm_via_wait_irq_request{
216 unsigned irq;
217 via_irq_seq_type_t type;
218 uint32_t sequence;
219 uint32_t signal;
220};
221
222typedef union drm_via_irqwait {
223 struct drm_via_wait_irq_request request;
224 struct drm_wait_vblank_reply reply;
225} drm_via_irqwait_t;
226
227#ifdef __KERNEL__
228
229int via_fb_init(DRM_IOCTL_ARGS);
230int via_mem_alloc(DRM_IOCTL_ARGS);
231int via_mem_free(DRM_IOCTL_ARGS);
232int via_agp_init(DRM_IOCTL_ARGS);
233int via_map_init(DRM_IOCTL_ARGS);
234int via_decoder_futex(DRM_IOCTL_ARGS);
235int via_dma_init(DRM_IOCTL_ARGS);
236int via_cmdbuffer(DRM_IOCTL_ARGS);
237int via_flush_ioctl(DRM_IOCTL_ARGS);
238int via_pci_cmdbuffer(DRM_IOCTL_ARGS);
239int via_cmdbuf_size(DRM_IOCTL_ARGS);
240int via_wait_irq(DRM_IOCTL_ARGS);
241
242#endif
243#endif /* _VIA_DRM_H_ */
diff --git a/drivers/char/drm/via_drv.c b/drivers/char/drm/via_drv.c
new file mode 100644
index 000000000000..275eefc79221
--- /dev/null
+++ b/drivers/char/drm/via_drv.c
@@ -0,0 +1,126 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <linux/config.h>
26#include "drmP.h"
27#include "via_drm.h"
28#include "via_drv.h"
29
30#include "drm_pciids.h"
31
32static int postinit(struct drm_device *dev, unsigned long flags)
33{
34 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d: %s\n",
35 DRIVER_NAME,
36 DRIVER_MAJOR,
37 DRIVER_MINOR,
38 DRIVER_PATCHLEVEL,
39 DRIVER_DATE, dev->primary.minor, pci_pretty_name(dev->pdev)
40 );
41 return 0;
42}
43
44static int version(drm_version_t * version)
45{
46 int len;
47
48 version->version_major = DRIVER_MAJOR;
49 version->version_minor = DRIVER_MINOR;
50 version->version_patchlevel = DRIVER_PATCHLEVEL;
51 DRM_COPY(version->name, DRIVER_NAME);
52 DRM_COPY(version->date, DRIVER_DATE);
53 DRM_COPY(version->desc, DRIVER_DESC);
54 return 0;
55}
56
57static struct pci_device_id pciidlist[] = {
58 viadrv_PCI_IDS
59};
60
61static drm_ioctl_desc_t ioctls[] = {
62 [DRM_IOCTL_NR(DRM_VIA_ALLOCMEM)] = {via_mem_alloc, 1, 0},
63 [DRM_IOCTL_NR(DRM_VIA_FREEMEM)] = {via_mem_free, 1, 0},
64 [DRM_IOCTL_NR(DRM_VIA_AGP_INIT)] = {via_agp_init, 1, 0},
65 [DRM_IOCTL_NR(DRM_VIA_FB_INIT)] = {via_fb_init, 1, 0},
66 [DRM_IOCTL_NR(DRM_VIA_MAP_INIT)] = {via_map_init, 1, 0},
67 [DRM_IOCTL_NR(DRM_VIA_DEC_FUTEX)] = {via_decoder_futex, 1, 0},
68 [DRM_IOCTL_NR(DRM_VIA_DMA_INIT)] = {via_dma_init, 1, 0},
69 [DRM_IOCTL_NR(DRM_VIA_CMDBUFFER)] = {via_cmdbuffer, 1, 0},
70 [DRM_IOCTL_NR(DRM_VIA_FLUSH)] = {via_flush_ioctl, 1, 0},
71 [DRM_IOCTL_NR(DRM_VIA_PCICMD)] = {via_pci_cmdbuffer, 1, 0},
72 [DRM_IOCTL_NR(DRM_VIA_CMDBUF_SIZE)] = {via_cmdbuf_size, 1, 0},
73 [DRM_IOCTL_NR(DRM_VIA_WAIT_IRQ)] = {via_wait_irq, 1, 0}
74};
75
76static struct drm_driver driver = {
77 .driver_features =
78 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
79 DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
80 .context_ctor = via_init_context,
81 .context_dtor = via_final_context,
82 .vblank_wait = via_driver_vblank_wait,
83 .irq_preinstall = via_driver_irq_preinstall,
84 .irq_postinstall = via_driver_irq_postinstall,
85 .irq_uninstall = via_driver_irq_uninstall,
86 .irq_handler = via_driver_irq_handler,
87 .dma_quiescent = via_driver_dma_quiescent,
88 .reclaim_buffers = drm_core_reclaim_buffers,
89 .get_map_ofs = drm_core_get_map_ofs,
90 .get_reg_ofs = drm_core_get_reg_ofs,
91 .postinit = postinit,
92 .version = version,
93 .ioctls = ioctls,
94 .num_ioctls = DRM_ARRAY_SIZE(ioctls),
95 .fops = {
96 .owner = THIS_MODULE,
97 .open = drm_open,
98 .release = drm_release,
99 .ioctl = drm_ioctl,
100 .mmap = drm_mmap,
101 .poll = drm_poll,
102 .fasync = drm_fasync,
103 },
104 .pci_driver = {
105 .name = DRIVER_NAME,
106 .id_table = pciidlist,
107 }
108};
109
110static int __init via_init(void)
111{
112 via_init_command_verifier();
113 return drm_init(&driver);
114}
115
116static void __exit via_exit(void)
117{
118 drm_exit(&driver);
119}
120
121module_init(via_init);
122module_exit(via_exit);
123
124MODULE_AUTHOR(DRIVER_AUTHOR);
125MODULE_DESCRIPTION(DRIVER_DESC);
126MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/via_drv.h b/drivers/char/drm/via_drv.h
new file mode 100644
index 000000000000..4eaa8b7c4c96
--- /dev/null
+++ b/drivers/char/drm/via_drv.h
@@ -0,0 +1,118 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#ifndef _VIA_DRV_H_
25#define _VIA_DRV_H_
26
27#define DRIVER_AUTHOR "VIA"
28
29#define DRIVER_NAME "via"
30#define DRIVER_DESC "VIA Unichrome / Pro"
31#define DRIVER_DATE "20050523"
32
33#define DRIVER_MAJOR 2
34#define DRIVER_MINOR 6
35#define DRIVER_PATCHLEVEL 3
36
37#include "via_verifier.h"
38
39#define VIA_PCI_BUF_SIZE 60000
40#define VIA_FIRE_BUF_SIZE 1024
41#define VIA_NUM_IRQS 2
42
43
44
45typedef struct drm_via_ring_buffer {
46 drm_map_t map;
47 char *virtual_start;
48} drm_via_ring_buffer_t;
49
50typedef uint32_t maskarray_t[5];
51
52typedef struct drm_via_irq {
53 atomic_t irq_received;
54 uint32_t pending_mask;
55 uint32_t enable_mask;
56 wait_queue_head_t irq_queue;
57} drm_via_irq_t;
58
59typedef struct drm_via_private {
60 drm_via_sarea_t *sarea_priv;
61 drm_map_t *sarea;
62 drm_map_t *fb;
63 drm_map_t *mmio;
64 unsigned long agpAddr;
65 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
66 char *dma_ptr;
67 unsigned int dma_low;
68 unsigned int dma_high;
69 unsigned int dma_offset;
70 uint32_t dma_wrap;
71 volatile uint32_t *last_pause_ptr;
72 volatile uint32_t *hw_addr_ptr;
73 drm_via_ring_buffer_t ring;
74 struct timeval last_vblank;
75 int last_vblank_valid;
76 unsigned usec_per_vblank;
77 drm_via_state_t hc_state;
78 char pci_buf[VIA_PCI_BUF_SIZE];
79 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
80 uint32_t num_fire_offsets;
81 int pro_group_a;
82 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
83 unsigned num_irqs;
84 maskarray_t *irq_masks;
85 uint32_t irq_enable_mask;
86 uint32_t irq_pending_mask;
87} drm_via_private_t;
88
89/* VIA MMIO register access */
90#define VIA_BASE ((dev_priv->mmio))
91
92#define VIA_READ(reg) DRM_READ32(VIA_BASE, reg)
93#define VIA_WRITE(reg,val) DRM_WRITE32(VIA_BASE, reg, val)
94#define VIA_READ8(reg) DRM_READ8(VIA_BASE, reg)
95#define VIA_WRITE8(reg,val) DRM_WRITE8(VIA_BASE, reg, val)
96
97extern int via_init_context(drm_device_t * dev, int context);
98extern int via_final_context(drm_device_t * dev, int context);
99
100extern int via_do_cleanup_map(drm_device_t * dev);
101extern int via_map_init(struct inode *inode, struct file *filp,
102 unsigned int cmd, unsigned long arg);
103extern int via_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence);
104
105extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
106extern void via_driver_irq_preinstall(drm_device_t * dev);
107extern void via_driver_irq_postinstall(drm_device_t * dev);
108extern void via_driver_irq_uninstall(drm_device_t * dev);
109
110extern int via_dma_cleanup(drm_device_t * dev);
111extern void via_init_command_verifier(void);
112extern int via_driver_dma_quiescent(drm_device_t * dev);
113extern void via_init_futex(drm_via_private_t *dev_priv);
114extern void via_cleanup_futex(drm_via_private_t *dev_priv);
115extern void via_release_futex(drm_via_private_t *dev_priv, int context);
116
117
118#endif
diff --git a/drivers/char/drm/via_ds.c b/drivers/char/drm/via_ds.c
new file mode 100644
index 000000000000..daf3df75a20e
--- /dev/null
+++ b/drivers/char/drm/via_ds.c
@@ -0,0 +1,280 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25#include <linux/module.h>
26#include <linux/delay.h>
27#include <linux/errno.h>
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/poll.h>
31#include <linux/pci.h>
32#include <asm/io.h>
33
34#include "via_ds.h"
35extern unsigned int VIA_DEBUG;
36
37set_t *via_setInit(void)
38{
39 int i;
40 set_t *set;
41 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
42 for (i = 0; i < SET_SIZE; i++) {
43 set->list[i].free_next = i + 1;
44 set->list[i].alloc_next = -1;
45 }
46 set->list[SET_SIZE - 1].free_next = -1;
47 set->free = 0;
48 set->alloc = -1;
49 set->trace = -1;
50 return set;
51}
52
53int via_setAdd(set_t * set, ITEM_TYPE item)
54{
55 int free = set->free;
56 if (free != -1) {
57 set->list[free].val = item;
58 set->free = set->list[free].free_next;
59 } else {
60 return 0;
61 }
62 set->list[free].alloc_next = set->alloc;
63 set->alloc = free;
64 set->list[free].free_next = -1;
65 return 1;
66}
67
68int via_setDel(set_t * set, ITEM_TYPE item)
69{
70 int alloc = set->alloc;
71 int prev = -1;
72
73 while (alloc != -1) {
74 if (set->list[alloc].val == item) {
75 if (prev != -1)
76 set->list[prev].alloc_next =
77 set->list[alloc].alloc_next;
78 else
79 set->alloc = set->list[alloc].alloc_next;
80 break;
81 }
82 prev = alloc;
83 alloc = set->list[alloc].alloc_next;
84 }
85
86 if (alloc == -1)
87 return 0;
88
89 set->list[alloc].free_next = set->free;
90 set->free = alloc;
91 set->list[alloc].alloc_next = -1;
92
93 return 1;
94}
95
96/* setFirst -> setAdd -> setNext is wrong */
97
98int via_setFirst(set_t * set, ITEM_TYPE * item)
99{
100 if (set->alloc == -1)
101 return 0;
102
103 *item = set->list[set->alloc].val;
104 set->trace = set->list[set->alloc].alloc_next;
105
106 return 1;
107}
108
109int via_setNext(set_t * set, ITEM_TYPE * item)
110{
111 if (set->trace == -1)
112 return 0;
113
114 *item = set->list[set->trace].val;
115 set->trace = set->list[set->trace].alloc_next;
116
117 return 1;
118}
119
120int via_setDestroy(set_t * set)
121{
122 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
123
124 return 1;
125}
126
127#define ISFREE(bptr) ((bptr)->free)
128
129#define fprintf(fmt, arg...) do{}while(0)
130
131memHeap_t *via_mmInit(int ofs, int size)
132{
133 PMemBlock blocks;
134
135 if (size <= 0)
136 return 0;
137
138 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
139
140 if (blocks) {
141 blocks->ofs = ofs;
142 blocks->size = size;
143 blocks->free = 1;
144 return (memHeap_t *) blocks;
145 } else
146 return 0;
147}
148
149static TMemBlock *SliceBlock(TMemBlock * p,
150 int startofs, int size,
151 int reserved, int alignment)
152{
153 TMemBlock *newblock;
154
155 /* break left */
156 if (startofs > p->ofs) {
157 newblock =
158 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
159 DRM_MEM_DRIVER);
160 newblock->ofs = startofs;
161 newblock->size = p->size - (startofs - p->ofs);
162 newblock->free = 1;
163 newblock->next = p->next;
164 p->size -= newblock->size;
165 p->next = newblock;
166 p = newblock;
167 }
168
169 /* break right */
170 if (size < p->size) {
171 newblock =
172 (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
173 DRM_MEM_DRIVER);
174 newblock->ofs = startofs + size;
175 newblock->size = p->size - size;
176 newblock->free = 1;
177 newblock->next = p->next;
178 p->size = size;
179 p->next = newblock;
180 }
181
182 /* p = middle block */
183 p->align = alignment;
184 p->free = 0;
185 p->reserved = reserved;
186 return p;
187}
188
189PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
190 int startSearch)
191{
192 int mask, startofs, endofs;
193 TMemBlock *p;
194
195 if (!heap || align2 < 0 || size <= 0)
196 return NULL;
197
198 mask = (1 << align2) - 1;
199 startofs = 0;
200 p = (TMemBlock *) heap;
201
202 while (p) {
203 if (ISFREE(p)) {
204 startofs = (p->ofs + mask) & ~mask;
205
206 if (startofs < startSearch)
207 startofs = startSearch;
208
209 endofs = startofs + size;
210
211 if (endofs <= (p->ofs + p->size))
212 break;
213 }
214
215 p = p->next;
216 }
217
218 if (!p)
219 return NULL;
220
221 p = SliceBlock(p, startofs, size, 0, mask + 1);
222 p->heap = heap;
223
224 return p;
225}
226
227static __inline__ int Join2Blocks(TMemBlock * p)
228{
229 if (p->free && p->next && p->next->free) {
230 TMemBlock *q = p->next;
231 p->size += q->size;
232 p->next = q->next;
233 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
234
235 return 1;
236 }
237
238 return 0;
239}
240
241int via_mmFreeMem(PMemBlock b)
242{
243 TMemBlock *p, *prev;
244
245 if (!b)
246 return 0;
247
248 if (!b->heap) {
249 fprintf(stderr, "no heap\n");
250
251 return -1;
252 }
253
254 p = b->heap;
255 prev = NULL;
256
257 while (p && p != b) {
258 prev = p;
259 p = p->next;
260 }
261
262 if (!p || p->free || p->reserved) {
263 if (!p)
264 fprintf(stderr, "block not found in heap\n");
265 else if (p->free)
266 fprintf(stderr, "block already free\n");
267 else
268 fprintf(stderr, "block is reserved\n");
269
270 return -1;
271 }
272
273 p->free = 1;
274 Join2Blocks(p);
275
276 if (prev)
277 Join2Blocks(prev);
278
279 return 0;
280}
diff --git a/drivers/char/drm/via_ds.h b/drivers/char/drm/via_ds.h
new file mode 100644
index 000000000000..be9c7f9f1aee
--- /dev/null
+++ b/drivers/char/drm/via_ds.h
@@ -0,0 +1,104 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sub license,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26#ifndef _via_ds_h_
27#define _via_ds_h_
28
29#include "drmP.h"
30
31/* Set Data Structure */
32#define SET_SIZE 5000
33typedef unsigned long ITEM_TYPE;
34
35typedef struct {
36 ITEM_TYPE val;
37 int alloc_next, free_next;
38} list_item_t;
39
40typedef struct {
41 int alloc;
42 int free;
43 int trace;
44 list_item_t list[SET_SIZE];
45} set_t;
46
47set_t *via_setInit(void);
48int via_setAdd(set_t * set, ITEM_TYPE item);
49int via_setDel(set_t * set, ITEM_TYPE item);
50int via_setFirst(set_t * set, ITEM_TYPE * item);
51int via_setNext(set_t * set, ITEM_TYPE * item);
52int via_setDestroy(set_t * set);
53
54#endif
55
56#ifndef MM_INC
57#define MM_INC
58
59struct mem_block_t {
60 struct mem_block_t *next;
61 struct mem_block_t *heap;
62 int ofs, size;
63 int align;
64 int free:1;
65 int reserved:1;
66};
67typedef struct mem_block_t TMemBlock;
68typedef struct mem_block_t *PMemBlock;
69
70/* a heap is just the first block in a chain */
71typedef struct mem_block_t memHeap_t;
72
73static __inline__ int mmBlockSize(PMemBlock b)
74{
75 return b->size;
76}
77
78static __inline__ int mmOffset(PMemBlock b)
79{
80 return b->ofs;
81}
82
83static __inline__ void mmMarkReserved(PMemBlock b)
84{
85 b->reserved = 1;
86}
87
88/*
89 * input: total size in bytes
90 * return: a heap pointer if OK, NULL if error
91 */
92memHeap_t *via_mmInit(int ofs, int size);
93
94PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
95 int startSearch);
96
97/*
98 * Free block starts at offset
99 * input: pointer to a block
100 * return: 0 if OK, -1 if error
101 */
102int via_mmFreeMem(PMemBlock b);
103
104#endif
diff --git a/drivers/char/drm/via_irq.c b/drivers/char/drm/via_irq.c
new file mode 100644
index 000000000000..e8027f3a93b0
--- /dev/null
+++ b/drivers/char/drm/via_irq.c
@@ -0,0 +1,339 @@
1/* via_irq.c
2 *
3 * Copyright 2004 BEAM Ltd.
4 * Copyright 2002 Tungsten Graphics, Inc.
5 * Copyright 2005 Thomas Hellstrom.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BEAM LTD, TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 * Authors:
29 * Terry Barnaby <terry1@beam.ltd.uk>
30 * Keith Whitwell <keith@tungstengraphics.com>
31 * Thomas Hellstrom <unichrome@shipmail.org>
32 *
33 * This code provides standard DRM access to the Via Unichrome / Pro Vertical blank
34 * interrupt, as well as an infrastructure to handle other interrupts of the chip.
35 * The refresh rate is also calculated for video playback sync purposes.
36 */
37
38#include "drmP.h"
39#include "drm.h"
40#include "via_drm.h"
41#include "via_drv.h"
42
43#define VIA_REG_INTERRUPT 0x200
44
45/* VIA_REG_INTERRUPT */
46#define VIA_IRQ_GLOBAL (1 << 31)
47#define VIA_IRQ_VBLANK_ENABLE (1 << 19)
48#define VIA_IRQ_VBLANK_PENDING (1 << 3)
49#define VIA_IRQ_HQV0_ENABLE (1 << 11)
50#define VIA_IRQ_HQV1_ENABLE (1 << 25)
51#define VIA_IRQ_HQV0_PENDING (1 << 9)
52#define VIA_IRQ_HQV1_PENDING (1 << 10)
53
54/*
55 * Device-specific IRQs go here. This type might need to be extended with
56 * the register if there are multiple IRQ control registers.
57 * Currently we activate the HQV interrupts of Unichrome Pro group A.
58 */
59
60static maskarray_t via_pro_group_a_irqs[] = {
61 {VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010, 0x00000000 },
62 {VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010, 0x00000000 }};
63static int via_num_pro_group_a = sizeof(via_pro_group_a_irqs)/sizeof(maskarray_t);
64
65static maskarray_t via_unichrome_irqs[] = {};
66static int via_num_unichrome = sizeof(via_unichrome_irqs)/sizeof(maskarray_t);
67
68
69static unsigned time_diff(struct timeval *now,struct timeval *then)
70{
71 return (now->tv_usec >= then->tv_usec) ?
72 now->tv_usec - then->tv_usec :
73 1000000 - (then->tv_usec - now->tv_usec);
74}
75
76irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
77{
78 drm_device_t *dev = (drm_device_t *) arg;
79 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
80 u32 status;
81 int handled = 0;
82 struct timeval cur_vblank;
83 drm_via_irq_t *cur_irq = dev_priv->via_irqs;
84 int i;
85
86 status = VIA_READ(VIA_REG_INTERRUPT);
87 if (status & VIA_IRQ_VBLANK_PENDING) {
88 atomic_inc(&dev->vbl_received);
89 if (!(atomic_read(&dev->vbl_received) & 0x0F)) {
90 do_gettimeofday(&cur_vblank);
91 if (dev_priv->last_vblank_valid) {
92 dev_priv->usec_per_vblank =
93 time_diff( &cur_vblank,&dev_priv->last_vblank) >> 4;
94 }
95 dev_priv->last_vblank = cur_vblank;
96 dev_priv->last_vblank_valid = 1;
97 }
98 if (!(atomic_read(&dev->vbl_received) & 0xFF)) {
99 DRM_DEBUG("US per vblank is: %u\n",
100 dev_priv->usec_per_vblank);
101 }
102 DRM_WAKEUP(&dev->vbl_queue);
103 drm_vbl_send_signals(dev);
104 handled = 1;
105 }
106
107
108 for (i=0; i<dev_priv->num_irqs; ++i) {
109 if (status & cur_irq->pending_mask) {
110 atomic_inc( &cur_irq->irq_received );
111 DRM_WAKEUP( &cur_irq->irq_queue );
112 handled = 1;
113 }
114 cur_irq++;
115 }
116
117 /* Acknowlege interrupts */
118 VIA_WRITE(VIA_REG_INTERRUPT, status);
119
120
121 if (handled)
122 return IRQ_HANDLED;
123 else
124 return IRQ_NONE;
125}
126
127static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t * dev_priv)
128{
129 u32 status;
130
131 if (dev_priv) {
132 /* Acknowlege interrupts */
133 status = VIA_READ(VIA_REG_INTERRUPT);
134 VIA_WRITE(VIA_REG_INTERRUPT, status |
135 dev_priv->irq_pending_mask);
136 }
137}
138
139int via_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence)
140{
141 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
142 unsigned int cur_vblank;
143 int ret = 0;
144
145 DRM_DEBUG("viadrv_vblank_wait\n");
146 if (!dev_priv) {
147 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
148 return -EINVAL;
149 }
150
151 viadrv_acknowledge_irqs(dev_priv);
152
153 /* Assume that the user has missed the current sequence number
154 * by about a day rather than she wants to wait for years
155 * using vertical blanks...
156 */
157
158 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
159 (((cur_vblank = atomic_read(&dev->vbl_received)) -
160 *sequence) <= (1 << 23)));
161
162 *sequence = cur_vblank;
163 return ret;
164}
165
166static int
167via_driver_irq_wait(drm_device_t * dev, unsigned int irq, int force_sequence,
168 unsigned int *sequence)
169{
170 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
171 unsigned int cur_irq_sequence;
172 drm_via_irq_t *cur_irq = dev_priv->via_irqs;
173 int ret = 0;
174 maskarray_t *masks = dev_priv->irq_masks;
175
176 DRM_DEBUG("%s\n", __FUNCTION__);
177
178 if (!dev_priv) {
179 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
180 return DRM_ERR(EINVAL);
181 }
182
183 if (irq >= dev_priv->num_irqs ) {
184 DRM_ERROR("%s Trying to wait on unknown irq %d\n", __FUNCTION__, irq);
185 return DRM_ERR(EINVAL);
186 }
187
188 cur_irq += irq;
189
190 if (masks[irq][2] && !force_sequence) {
191 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
192 ((VIA_READ(masks[irq][2]) & masks[irq][3]) == masks[irq][4]));
193 cur_irq_sequence = atomic_read(&cur_irq->irq_received);
194 } else {
195 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
196 (((cur_irq_sequence = atomic_read(&cur_irq->irq_received)) -
197 *sequence) <= (1 << 23)));
198 }
199 *sequence = cur_irq_sequence;
200 return ret;
201}
202
203
204/*
205 * drm_dma.h hooks
206 */
207
208void via_driver_irq_preinstall(drm_device_t * dev)
209{
210 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
211 u32 status;
212 drm_via_irq_t *cur_irq = dev_priv->via_irqs;
213 int i;
214
215 DRM_DEBUG("driver_irq_preinstall: dev_priv: %p\n", dev_priv);
216 if (dev_priv) {
217
218 dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE;
219 dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING;
220
221 dev_priv->irq_masks = (dev_priv->pro_group_a) ?
222 via_pro_group_a_irqs : via_unichrome_irqs;
223 dev_priv->num_irqs = (dev_priv->pro_group_a) ?
224 via_num_pro_group_a : via_num_unichrome;
225
226 for(i=0; i < dev_priv->num_irqs; ++i) {
227 atomic_set(&cur_irq->irq_received, 0);
228 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
229 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
230 DRM_INIT_WAITQUEUE( &cur_irq->irq_queue );
231 dev_priv->irq_enable_mask |= cur_irq->enable_mask;
232 dev_priv->irq_pending_mask |= cur_irq->pending_mask;
233 cur_irq++;
234
235 DRM_DEBUG("Initializing IRQ %d\n", i);
236 }
237
238 dev_priv->last_vblank_valid = 0;
239
240 // Clear VSync interrupt regs
241 status = VIA_READ(VIA_REG_INTERRUPT);
242 VIA_WRITE(VIA_REG_INTERRUPT, status &
243 ~(dev_priv->irq_enable_mask));
244
245 /* Clear bits if they're already high */
246 viadrv_acknowledge_irqs(dev_priv);
247 }
248}
249
250void via_driver_irq_postinstall(drm_device_t * dev)
251{
252 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
253 u32 status;
254
255 DRM_DEBUG("via_driver_irq_postinstall\n");
256 if (dev_priv) {
257 status = VIA_READ(VIA_REG_INTERRUPT);
258 VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_GLOBAL
259 | dev_priv->irq_enable_mask);
260
261 /* Some magic, oh for some data sheets ! */
262
263 VIA_WRITE8(0x83d4, 0x11);
264 VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30);
265
266 }
267}
268
269void via_driver_irq_uninstall(drm_device_t * dev)
270{
271 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
272 u32 status;
273
274 DRM_DEBUG("driver_irq_uninstall)\n");
275 if (dev_priv) {
276
277 /* Some more magic, oh for some data sheets ! */
278
279 VIA_WRITE8(0x83d4, 0x11);
280 VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30);
281
282 status = VIA_READ(VIA_REG_INTERRUPT);
283 VIA_WRITE(VIA_REG_INTERRUPT, status &
284 ~(VIA_IRQ_VBLANK_ENABLE | dev_priv->irq_enable_mask));
285 }
286}
287
288int via_wait_irq(DRM_IOCTL_ARGS)
289{
290 drm_file_t *priv = filp->private_data;
291 drm_device_t *dev = priv->head->dev;
292 drm_via_irqwait_t __user *argp = (void __user *)data;
293 drm_via_irqwait_t irqwait;
294 struct timeval now;
295 int ret = 0;
296 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
297 drm_via_irq_t *cur_irq = dev_priv->via_irqs;
298 int force_sequence;
299
300 if (!dev->irq)
301 return DRM_ERR(EINVAL);
302
303 DRM_COPY_FROM_USER_IOCTL(irqwait, argp, sizeof(irqwait));
304 if (irqwait.request.irq >= dev_priv->num_irqs) {
305 DRM_ERROR("%s Trying to wait on unknown irq %d\n", __FUNCTION__,
306 irqwait.request.irq);
307 return DRM_ERR(EINVAL);
308 }
309
310 cur_irq += irqwait.request.irq;
311
312 switch (irqwait.request.type & ~VIA_IRQ_FLAGS_MASK) {
313 case VIA_IRQ_RELATIVE:
314 irqwait.request.sequence += atomic_read(&cur_irq->irq_received);
315 irqwait.request.type &= ~_DRM_VBLANK_RELATIVE;
316 case VIA_IRQ_ABSOLUTE:
317 break;
318 default:
319 return DRM_ERR(EINVAL);
320 }
321
322 if (irqwait.request.type & VIA_IRQ_SIGNAL) {
323 DRM_ERROR("%s Signals on Via IRQs not implemented yet.\n",
324 __FUNCTION__);
325 return DRM_ERR(EINVAL);
326 }
327
328 force_sequence = (irqwait.request.type & VIA_IRQ_FORCE_SEQUENCE);
329
330 ret = via_driver_irq_wait(dev, irqwait.request.irq, force_sequence,
331 &irqwait.request.sequence);
332 do_gettimeofday(&now);
333 irqwait.reply.tval_sec = now.tv_sec;
334 irqwait.reply.tval_usec = now.tv_usec;
335
336 DRM_COPY_TO_USER_IOCTL(argp, irqwait, sizeof(irqwait));
337
338 return ret;
339}
diff --git a/drivers/char/drm/via_map.c b/drivers/char/drm/via_map.c
new file mode 100644
index 000000000000..0be829b6ec65
--- /dev/null
+++ b/drivers/char/drm/via_map.c
@@ -0,0 +1,110 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include "drmP.h"
25#include "via_drm.h"
26#include "via_drv.h"
27
28static int via_do_init_map(drm_device_t * dev, drm_via_init_t * init)
29{
30 drm_via_private_t *dev_priv;
31
32 DRM_DEBUG("%s\n", __FUNCTION__);
33
34 dev_priv = drm_alloc(sizeof(drm_via_private_t), DRM_MEM_DRIVER);
35 if (dev_priv == NULL)
36 return -ENOMEM;
37
38 memset(dev_priv, 0, sizeof(drm_via_private_t));
39
40 DRM_GETSAREA();
41 if (!dev_priv->sarea) {
42 DRM_ERROR("could not find sarea!\n");
43 dev->dev_private = (void *)dev_priv;
44 via_do_cleanup_map(dev);
45 return -EINVAL;
46 }
47
48 dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
49 if (!dev_priv->fb) {
50 DRM_ERROR("could not find framebuffer!\n");
51 dev->dev_private = (void *)dev_priv;
52 via_do_cleanup_map(dev);
53 return -EINVAL;
54 }
55 dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
56 if (!dev_priv->mmio) {
57 DRM_ERROR("could not find mmio region!\n");
58 dev->dev_private = (void *)dev_priv;
59 via_do_cleanup_map(dev);
60 return -EINVAL;
61 }
62
63 dev_priv->sarea_priv =
64 (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
65 init->sarea_priv_offset);
66
67 dev_priv->agpAddr = init->agpAddr;
68
69 via_init_futex( dev_priv );
70 dev_priv->pro_group_a = (dev->pdev->device == 0x3118);
71
72 dev->dev_private = (void *)dev_priv;
73 return 0;
74}
75
76int via_do_cleanup_map(drm_device_t * dev)
77{
78 if (dev->dev_private) {
79
80 drm_via_private_t *dev_priv = dev->dev_private;
81
82 via_dma_cleanup(dev);
83
84 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
85 dev->dev_private = NULL;
86 }
87
88 return 0;
89}
90
91int via_map_init(DRM_IOCTL_ARGS)
92{
93 DRM_DEVICE;
94 drm_via_init_t init;
95
96 DRM_DEBUG("%s\n", __FUNCTION__);
97
98 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t *) data, sizeof(init));
99
100 switch (init.func) {
101 case VIA_INIT_MAP:
102 return via_do_init_map(dev, &init);
103 case VIA_CLEANUP_MAP:
104 return via_do_cleanup_map(dev);
105 }
106
107 return -EINVAL;
108}
109
110
diff --git a/drivers/char/drm/via_mm.c b/drivers/char/drm/via_mm.c
new file mode 100644
index 000000000000..c22712f44d42
--- /dev/null
+++ b/drivers/char/drm/via_mm.c
@@ -0,0 +1,358 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include "drmP.h"
25#include "via_drm.h"
26#include "via_drv.h"
27#include "via_ds.h"
28#include "via_mm.h"
29
30#define MAX_CONTEXT 100
31
32typedef struct {
33 int used;
34 int context;
35 set_t *sets[2]; /* 0 for frame buffer, 1 for AGP , 2 for System */
36} via_context_t;
37
38static via_context_t global_ppriv[MAX_CONTEXT];
39
40static int via_agp_alloc(drm_via_mem_t * mem);
41static int via_agp_free(drm_via_mem_t * mem);
42static int via_fb_alloc(drm_via_mem_t * mem);
43static int via_fb_free(drm_via_mem_t * mem);
44
45static int add_alloc_set(int context, int type, unsigned int val)
46{
47 int i, retval = 0;
48
49 for (i = 0; i < MAX_CONTEXT; i++) {
50 if (global_ppriv[i].used && global_ppriv[i].context == context) {
51 retval = via_setAdd(global_ppriv[i].sets[type], val);
52 break;
53 }
54 }
55
56 return retval;
57}
58
59static int del_alloc_set(int context, int type, unsigned int val)
60{
61 int i, retval = 0;
62
63 for (i = 0; i < MAX_CONTEXT; i++)
64 if (global_ppriv[i].used && global_ppriv[i].context == context) {
65 retval = via_setDel(global_ppriv[i].sets[type], val);
66 break;
67 }
68
69 return retval;
70}
71
72/* agp memory management */
73static memHeap_t *AgpHeap = NULL;
74
75int via_agp_init(DRM_IOCTL_ARGS)
76{
77 drm_via_agp_t agp;
78
79 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t *) data, sizeof(agp));
80
81 AgpHeap = via_mmInit(agp.offset, agp.size);
82
83 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)agp.offset, (unsigned long)agp.size);
84
85 return 0;
86}
87
88/* fb memory management */
89static memHeap_t *FBHeap = NULL;
90
91int via_fb_init(DRM_IOCTL_ARGS)
92{
93 drm_via_fb_t fb;
94
95 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t *) data, sizeof(fb));
96
97 FBHeap = via_mmInit(fb.offset, fb.size);
98
99 DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)fb.offset, (unsigned long)fb.size);
100
101 return 0;
102}
103
104int via_init_context(struct drm_device *dev, int context)
105{
106 int i;
107
108 for (i = 0; i < MAX_CONTEXT; i++)
109 if (global_ppriv[i].used &&
110 (global_ppriv[i].context == context))
111 break;
112
113 if (i >= MAX_CONTEXT) {
114 for (i = 0; i < MAX_CONTEXT; i++) {
115 if (!global_ppriv[i].used) {
116 global_ppriv[i].context = context;
117 global_ppriv[i].used = 1;
118 global_ppriv[i].sets[0] = via_setInit();
119 global_ppriv[i].sets[1] = via_setInit();
120 DRM_DEBUG("init allocation set, socket=%d,"
121 " context = %d\n", i, context);
122 break;
123 }
124 }
125
126 if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
127 (global_ppriv[i].sets[1] == NULL)) {
128 return 0;
129 }
130 }
131
132 return 1;
133}
134
135int via_final_context(struct drm_device *dev, int context)
136{
137 int i;
138 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
139
140 for (i = 0; i < MAX_CONTEXT; i++)
141 if (global_ppriv[i].used &&
142 (global_ppriv[i].context == context))
143 break;
144
145 if (i < MAX_CONTEXT) {
146 set_t *set;
147 ITEM_TYPE item;
148 int retval;
149
150 DRM_DEBUG("find socket %d, context = %d\n", i, context);
151
152 /* Video Memory */
153 set = global_ppriv[i].sets[0];
154 retval = via_setFirst(set, &item);
155 while (retval) {
156 DRM_DEBUG("free video memory 0x%lx\n", item);
157 via_mmFreeMem((PMemBlock) item);
158 retval = via_setNext(set, &item);
159 }
160 via_setDestroy(set);
161
162 /* AGP Memory */
163 set = global_ppriv[i].sets[1];
164 retval = via_setFirst(set, &item);
165 while (retval) {
166 DRM_DEBUG("free agp memory 0x%lx\n", item);
167 via_mmFreeMem((PMemBlock) item);
168 retval = via_setNext(set, &item);
169 }
170 via_setDestroy(set);
171 global_ppriv[i].used = 0;
172 }
173 via_release_futex(dev_priv, context);
174
175
176#if defined(__linux__)
177 /* Linux specific until context tracking code gets ported to BSD */
178 /* Last context, perform cleanup */
179 if (dev->ctx_count == 1 && dev->dev_private) {
180 DRM_DEBUG("Last Context\n");
181 if (dev->irq)
182 drm_irq_uninstall(dev);
183
184 via_cleanup_futex(dev_priv);
185 via_do_cleanup_map(dev);
186 }
187#endif
188
189 return 1;
190}
191
192int via_mem_alloc(DRM_IOCTL_ARGS)
193{
194 drm_via_mem_t mem;
195
196 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t *) data, sizeof(mem));
197
198 switch (mem.type) {
199 case VIDEO:
200 if (via_fb_alloc(&mem) < 0)
201 return -EFAULT;
202 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t *) data, mem,
203 sizeof(mem));
204 return 0;
205 case AGP:
206 if (via_agp_alloc(&mem) < 0)
207 return -EFAULT;
208 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t *) data, mem,
209 sizeof(mem));
210 return 0;
211 }
212
213 return -EFAULT;
214}
215
216static int via_fb_alloc(drm_via_mem_t * mem)
217{
218 drm_via_mm_t fb;
219 PMemBlock block;
220 int retval = 0;
221
222 if (!FBHeap)
223 return -1;
224
225 fb.size = mem->size;
226 fb.context = mem->context;
227
228 block = via_mmAllocMem(FBHeap, fb.size, 5, 0);
229 if (block) {
230 fb.offset = block->ofs;
231 fb.free = (unsigned long)block;
232 if (!add_alloc_set(fb.context, VIDEO, fb.free)) {
233 DRM_DEBUG("adding to allocation set fails\n");
234 via_mmFreeMem((PMemBlock) fb.free);
235 retval = -1;
236 }
237 } else {
238 fb.offset = 0;
239 fb.size = 0;
240 fb.free = 0;
241 retval = -1;
242 }
243
244 mem->offset = fb.offset;
245 mem->index = fb.free;
246
247 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size,
248 (int)fb.offset);
249
250 return retval;
251}
252
253static int via_agp_alloc(drm_via_mem_t * mem)
254{
255 drm_via_mm_t agp;
256 PMemBlock block;
257 int retval = 0;
258
259 if (!AgpHeap)
260 return -1;
261
262 agp.size = mem->size;
263 agp.context = mem->context;
264
265 block = via_mmAllocMem(AgpHeap, agp.size, 5, 0);
266 if (block) {
267 agp.offset = block->ofs;
268 agp.free = (unsigned long)block;
269 if (!add_alloc_set(agp.context, AGP, agp.free)) {
270 DRM_DEBUG("adding to allocation set fails\n");
271 via_mmFreeMem((PMemBlock) agp.free);
272 retval = -1;
273 }
274 } else {
275 agp.offset = 0;
276 agp.size = 0;
277 agp.free = 0;
278 }
279
280 mem->offset = agp.offset;
281 mem->index = agp.free;
282
283 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size,
284 (unsigned int)agp.offset);
285 return retval;
286}
287
288int via_mem_free(DRM_IOCTL_ARGS)
289{
290 drm_via_mem_t mem;
291
292 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t *) data, sizeof(mem));
293
294 switch (mem.type) {
295
296 case VIDEO:
297 if (via_fb_free(&mem) == 0)
298 return 0;
299 break;
300 case AGP:
301 if (via_agp_free(&mem) == 0)
302 return 0;
303 break;
304 }
305
306 return -EFAULT;
307}
308
309static int via_fb_free(drm_via_mem_t * mem)
310{
311 drm_via_mm_t fb;
312 int retval = 0;
313
314 if (!FBHeap) {
315 return -1;
316 }
317
318 fb.free = mem->index;
319 fb.context = mem->context;
320
321 if (!fb.free) {
322 return -1;
323
324 }
325
326 via_mmFreeMem((PMemBlock) fb.free);
327
328 if (!del_alloc_set(fb.context, VIDEO, fb.free)) {
329 retval = -1;
330 }
331
332 DRM_DEBUG("free fb, free = %ld\n", fb.free);
333
334 return retval;
335}
336
337static int via_agp_free(drm_via_mem_t * mem)
338{
339 drm_via_mm_t agp;
340
341 int retval = 0;
342
343 agp.free = mem->index;
344 agp.context = mem->context;
345
346 if (!agp.free)
347 return -1;
348
349 via_mmFreeMem((PMemBlock) agp.free);
350
351 if (!del_alloc_set(agp.context, AGP, agp.free)) {
352 retval = -1;
353 }
354
355 DRM_DEBUG("free agp, free = %ld\n", agp.free);
356
357 return retval;
358}
diff --git a/drivers/char/drm/via_mm.h b/drivers/char/drm/via_mm.h
new file mode 100644
index 000000000000..d57efda57c76
--- /dev/null
+++ b/drivers/char/drm/via_mm.h
@@ -0,0 +1,40 @@
1/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#ifndef _via_drm_mm_h_
25#define _via_drm_mm_h_
26
27typedef struct {
28 unsigned int context;
29 unsigned int size;
30 unsigned long offset;
31 unsigned long free;
32} drm_via_mm_t;
33
34typedef struct {
35 unsigned int size;
36 unsigned long handle;
37 void *virtual;
38} drm_via_dma_t;
39
40#endif
diff --git a/drivers/char/drm/via_verifier.c b/drivers/char/drm/via_verifier.c
new file mode 100644
index 000000000000..07923b0c7a97
--- /dev/null
+++ b/drivers/char/drm/via_verifier.c
@@ -0,0 +1,1061 @@
1/*
2 * Copyright 2004 The Unichrome Project. All Rights Reserved.
3 * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Author: Thomas Hellstrom 2004, 2005.
25 * This code was written using docs obtained under NDA from VIA Inc.
26 *
27 * Don't run this code directly on an AGP buffer. Due to cache problems it will
28 * be very slow.
29 */
30
31
32#include "via_3d_reg.h"
33#include "drmP.h"
34#include "drm.h"
35#include "via_drm.h"
36#include "via_verifier.h"
37#include "via_drv.h"
38
39typedef enum{
40 state_command,
41 state_header2,
42 state_header1,
43 state_vheader5,
44 state_vheader6,
45 state_error
46} verifier_state_t;
47
48
49typedef enum{
50 no_check = 0,
51 check_for_header2,
52 check_for_header1,
53 check_for_header2_err,
54 check_for_header1_err,
55 check_for_fire,
56 check_z_buffer_addr0,
57 check_z_buffer_addr1,
58 check_z_buffer_addr_mode,
59 check_destination_addr0,
60 check_destination_addr1,
61 check_destination_addr_mode,
62 check_for_dummy,
63 check_for_dd,
64 check_texture_addr0,
65 check_texture_addr1,
66 check_texture_addr2,
67 check_texture_addr3,
68 check_texture_addr4,
69 check_texture_addr5,
70 check_texture_addr6,
71 check_texture_addr7,
72 check_texture_addr8,
73 check_texture_addr_mode,
74 check_for_vertex_count,
75 check_number_texunits,
76 forbidden_command
77}hazard_t;
78
79/*
80 * Associates each hazard above with a possible multi-command
81 * sequence. For example an address that is split over multiple
82 * commands and that needs to be checked at the first command
83 * that does not include any part of the address.
84 */
85
86static drm_via_sequence_t seqs[] = {
87 no_sequence,
88 no_sequence,
89 no_sequence,
90 no_sequence,
91 no_sequence,
92 no_sequence,
93 z_address,
94 z_address,
95 z_address,
96 dest_address,
97 dest_address,
98 dest_address,
99 no_sequence,
100 no_sequence,
101 tex_address,
102 tex_address,
103 tex_address,
104 tex_address,
105 tex_address,
106 tex_address,
107 tex_address,
108 tex_address,
109 tex_address,
110 tex_address,
111 no_sequence
112};
113
114typedef struct{
115 unsigned int code;
116 hazard_t hz;
117} hz_init_t;
118
119
120
121static hz_init_t init_table1[] = {
122 {0xf2, check_for_header2_err},
123 {0xf0, check_for_header1_err},
124 {0xee, check_for_fire},
125 {0xcc, check_for_dummy},
126 {0xdd, check_for_dd},
127 {0x00, no_check},
128 {0x10, check_z_buffer_addr0},
129 {0x11, check_z_buffer_addr1},
130 {0x12, check_z_buffer_addr_mode},
131 {0x13, no_check},
132 {0x14, no_check},
133 {0x15, no_check},
134 {0x23, no_check},
135 {0x24, no_check},
136 {0x33, no_check},
137 {0x34, no_check},
138 {0x35, no_check},
139 {0x36, no_check},
140 {0x37, no_check},
141 {0x38, no_check},
142 {0x39, no_check},
143 {0x3A, no_check},
144 {0x3B, no_check},
145 {0x3C, no_check},
146 {0x3D, no_check},
147 {0x3E, no_check},
148 {0x40, check_destination_addr0},
149 {0x41, check_destination_addr1},
150 {0x42, check_destination_addr_mode},
151 {0x43, no_check},
152 {0x44, no_check},
153 {0x50, no_check},
154 {0x51, no_check},
155 {0x52, no_check},
156 {0x53, no_check},
157 {0x54, no_check},
158 {0x55, no_check},
159 {0x56, no_check},
160 {0x57, no_check},
161 {0x58, no_check},
162 {0x70, no_check},
163 {0x71, no_check},
164 {0x78, no_check},
165 {0x79, no_check},
166 {0x7A, no_check},
167 {0x7B, no_check},
168 {0x7C, no_check},
169 {0x7D, check_for_vertex_count}
170};
171
172
173
174static hz_init_t init_table2[] = {
175 {0xf2, check_for_header2_err},
176 {0xf0, check_for_header1_err},
177 {0xee, check_for_fire},
178 {0xcc, check_for_dummy},
179 {0x00, check_texture_addr0},
180 {0x01, check_texture_addr0},
181 {0x02, check_texture_addr0},
182 {0x03, check_texture_addr0},
183 {0x04, check_texture_addr0},
184 {0x05, check_texture_addr0},
185 {0x06, check_texture_addr0},
186 {0x07, check_texture_addr0},
187 {0x08, check_texture_addr0},
188 {0x09, check_texture_addr0},
189 {0x20, check_texture_addr1},
190 {0x21, check_texture_addr1},
191 {0x22, check_texture_addr1},
192 {0x23, check_texture_addr4},
193 {0x2B, check_texture_addr3},
194 {0x2C, check_texture_addr3},
195 {0x2D, check_texture_addr3},
196 {0x2E, check_texture_addr3},
197 {0x2F, check_texture_addr3},
198 {0x30, check_texture_addr3},
199 {0x31, check_texture_addr3},
200 {0x32, check_texture_addr3},
201 {0x33, check_texture_addr3},
202 {0x34, check_texture_addr3},
203 {0x4B, check_texture_addr5},
204 {0x4C, check_texture_addr6},
205 {0x51, check_texture_addr7},
206 {0x52, check_texture_addr8},
207 {0x77, check_texture_addr2},
208 {0x78, no_check},
209 {0x79, no_check},
210 {0x7A, no_check},
211 {0x7B, check_texture_addr_mode},
212 {0x7C, no_check},
213 {0x7D, no_check},
214 {0x7E, no_check},
215 {0x7F, no_check},
216 {0x80, no_check},
217 {0x81, no_check},
218 {0x82, no_check},
219 {0x83, no_check},
220 {0x85, no_check},
221 {0x86, no_check},
222 {0x87, no_check},
223 {0x88, no_check},
224 {0x89, no_check},
225 {0x8A, no_check},
226 {0x90, no_check},
227 {0x91, no_check},
228 {0x92, no_check},
229 {0x93, no_check}
230};
231
232static hz_init_t init_table3[] = {
233 {0xf2, check_for_header2_err},
234 {0xf0, check_for_header1_err},
235 {0xcc, check_for_dummy},
236 {0x00, check_number_texunits}
237};
238
239
240static hazard_t table1[256];
241static hazard_t table2[256];
242static hazard_t table3[256];
243
244
245
246static __inline__ int
247eat_words(const uint32_t **buf, const uint32_t *buf_end, unsigned num_words)
248{
249 if ((*buf - buf_end) >= num_words) {
250 *buf += num_words;
251 return 0;
252 }
253 DRM_ERROR("Illegal termination of DMA command buffer\n");
254 return 1;
255}
256
257
258/*
259 * Partially stolen from drm_memory.h
260 */
261
262static __inline__ drm_map_t *
263via_drm_lookup_agp_map (drm_via_state_t *seq, unsigned long offset, unsigned long size,
264 drm_device_t *dev)
265{
266 struct list_head *list;
267 drm_map_list_t *r_list;
268 drm_map_t *map = seq->map_cache;
269
270 if (map && map->offset <= offset && (offset + size) <= (map->offset + map->size)) {
271 return map;
272 }
273
274 list_for_each(list, &dev->maplist->head) {
275 r_list = (drm_map_list_t *) list;
276 map = r_list->map;
277 if (!map)
278 continue;
279 if (map->offset <= offset && (offset + size) <= (map->offset + map->size) &&
280 !(map->flags & _DRM_RESTRICTED) && (map->type == _DRM_AGP)) {
281 seq->map_cache = map;
282 return map;
283 }
284 }
285 return NULL;
286}
287
288
289/*
290 * Require that all AGP texture levels reside in the same AGP map which should
291 * be mappable by the client. This is not a big restriction.
292 * FIXME: To actually enforce this security policy strictly, drm_rmmap
293 * would have to wait for dma quiescent before removing an AGP map.
294 * The via_drm_lookup_agp_map call in reality seems to take
295 * very little CPU time.
296 */
297
298
299static __inline__ int
300finish_current_sequence(drm_via_state_t *cur_seq)
301{
302 switch(cur_seq->unfinished) {
303 case z_address:
304 DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq->z_addr);
305 break;
306 case dest_address:
307 DRM_DEBUG("Destination start address is 0x%x\n", cur_seq->d_addr);
308 break;
309 case tex_address:
310 if (cur_seq->agp_texture) {
311 unsigned start = cur_seq->tex_level_lo[cur_seq->texture];
312 unsigned end = cur_seq->tex_level_hi[cur_seq->texture];
313 unsigned long lo=~0, hi=0, tmp;
314 uint32_t *addr, *pitch, *height, tex;
315 unsigned i;
316
317 if (end > 9) end = 9;
318 if (start > 9) start = 9;
319
320 addr =&(cur_seq->t_addr[tex = cur_seq->texture][start]);
321 pitch = &(cur_seq->pitch[tex][start]);
322 height = &(cur_seq->height[tex][start]);
323
324 for (i=start; i<= end; ++i) {
325 tmp = *addr++;
326 if (tmp < lo) lo = tmp;
327 tmp += (*height++ << *pitch++);
328 if (tmp > hi) hi = tmp;
329 }
330
331 if (! via_drm_lookup_agp_map (cur_seq, lo, hi - lo, cur_seq->dev)) {
332 DRM_ERROR("AGP texture is not in allowed map\n");
333 return 2;
334 }
335 }
336 break;
337 default:
338 break;
339 }
340 cur_seq->unfinished = no_sequence;
341 return 0;
342}
343
344static __inline__ int
345investigate_hazard( uint32_t cmd, hazard_t hz, drm_via_state_t *cur_seq)
346{
347 register uint32_t tmp, *tmp_addr;
348
349 if (cur_seq->unfinished && (cur_seq->unfinished != seqs[hz])) {
350 int ret;
351 if ((ret = finish_current_sequence(cur_seq))) return ret;
352 }
353
354 switch(hz) {
355 case check_for_header2:
356 if (cmd == HALCYON_HEADER2) return 1;
357 return 0;
358 case check_for_header1:
359 if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) return 1;
360 return 0;
361 case check_for_header2_err:
362 if (cmd == HALCYON_HEADER2) return 1;
363 DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n");
364 break;
365 case check_for_header1_err:
366 if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1) return 1;
367 DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n");
368 break;
369 case check_for_fire:
370 if ((cmd & HALCYON_FIREMASK) == HALCYON_FIRECMD) return 1;
371 DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n");
372 break;
373 case check_for_dummy:
374 if (HC_DUMMY == cmd) return 0;
375 DRM_ERROR("Illegal DMA HC_DUMMY command\n");
376 break;
377 case check_for_dd:
378 if (0xdddddddd == cmd) return 0;
379 DRM_ERROR("Illegal DMA 0xdddddddd command\n");
380 break;
381 case check_z_buffer_addr0:
382 cur_seq->unfinished = z_address;
383 cur_seq->z_addr = (cur_seq->z_addr & 0xFF000000) |
384 (cmd & 0x00FFFFFF);
385 return 0;
386 case check_z_buffer_addr1:
387 cur_seq->unfinished = z_address;
388 cur_seq->z_addr = (cur_seq->z_addr & 0x00FFFFFF) |
389 ((cmd & 0xFF) << 24);
390 return 0;
391 case check_z_buffer_addr_mode:
392 cur_seq->unfinished = z_address;
393 if ((cmd & 0x0000C000) == 0) return 0;
394 DRM_ERROR("Attempt to place Z buffer in system memory\n");
395 return 2;
396 case check_destination_addr0:
397 cur_seq->unfinished = dest_address;
398 cur_seq->d_addr = (cur_seq->d_addr & 0xFF000000) |
399 (cmd & 0x00FFFFFF);
400 return 0;
401 case check_destination_addr1:
402 cur_seq->unfinished = dest_address;
403 cur_seq->d_addr = (cur_seq->d_addr & 0x00FFFFFF) |
404 ((cmd & 0xFF) << 24);
405 return 0;
406 case check_destination_addr_mode:
407 cur_seq->unfinished = dest_address;
408 if ((cmd & 0x0000C000) == 0) return 0;
409 DRM_ERROR("Attempt to place 3D drawing buffer in system memory\n");
410 return 2;
411 case check_texture_addr0:
412 cur_seq->unfinished = tex_address;
413 tmp = (cmd >> 24);
414 tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
415 *tmp_addr = (*tmp_addr & 0xFF000000) | (cmd & 0x00FFFFFF);
416 return 0;
417 case check_texture_addr1:
418 cur_seq->unfinished = tex_address;
419 tmp = ((cmd >> 24) - 0x20);
420 tmp += tmp << 1;
421 tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
422 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
423 tmp_addr++;
424 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF00) << 16);
425 tmp_addr++;
426 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF0000) << 8);
427 return 0;
428 case check_texture_addr2:
429 cur_seq->unfinished = tex_address;
430 cur_seq->tex_level_lo[tmp = cur_seq->texture] = cmd & 0x3F;
431 cur_seq->tex_level_hi[tmp] = (cmd & 0xFC0) >> 6;
432 return 0;
433 case check_texture_addr3:
434 cur_seq->unfinished = tex_address;
435 tmp = ((cmd >> 24) - 0x2B);
436 cur_seq->pitch[cur_seq->texture][tmp] = (cmd & 0x00F00000) >> 20;
437 if (!tmp && (cmd & 0x000FFFFF)) {
438 DRM_ERROR("Unimplemented texture level 0 pitch mode.\n");
439 return 2;
440 }
441 return 0;
442 case check_texture_addr4:
443 cur_seq->unfinished = tex_address;
444 tmp_addr = &cur_seq->t_addr[cur_seq->texture][9];
445 *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
446 return 0;
447 case check_texture_addr5:
448 case check_texture_addr6:
449 cur_seq->unfinished = tex_address;
450 /*
451 * Texture width. We don't care since we have the pitch.
452 */
453 return 0;
454 case check_texture_addr7:
455 cur_seq->unfinished = tex_address;
456 tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
457 tmp_addr[5] = 1 << ((cmd & 0x00F00000) >> 20);
458 tmp_addr[4] = 1 << ((cmd & 0x000F0000) >> 16);
459 tmp_addr[3] = 1 << ((cmd & 0x0000F000) >> 12);
460 tmp_addr[2] = 1 << ((cmd & 0x00000F00) >> 8);
461 tmp_addr[1] = 1 << ((cmd & 0x000000F0) >> 4);
462 tmp_addr[0] = 1 << (cmd & 0x0000000F);
463 return 0;
464 case check_texture_addr8:
465 cur_seq->unfinished = tex_address;
466 tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
467 tmp_addr[9] = 1 << ((cmd & 0x0000F000) >> 12);
468 tmp_addr[8] = 1 << ((cmd & 0x00000F00) >> 8);
469 tmp_addr[7] = 1 << ((cmd & 0x000000F0) >> 4);
470 tmp_addr[6] = 1 << (cmd & 0x0000000F);
471 return 0;
472 case check_texture_addr_mode:
473 cur_seq->unfinished = tex_address;
474 if ( 2 == (tmp = cmd & 0x00000003)) {
475 DRM_ERROR("Attempt to fetch texture from system memory.\n");
476 return 2;
477 }
478 cur_seq->agp_texture = (tmp == 3);
479 cur_seq->tex_palette_size[cur_seq->texture] =
480 (cmd >> 16) & 0x000000007;
481 return 0;
482 case check_for_vertex_count:
483 cur_seq->vertex_count = cmd & 0x0000FFFF;
484 return 0;
485 case check_number_texunits:
486 cur_seq->multitex = (cmd >> 3) & 1;
487 return 0;
488 default:
489 DRM_ERROR("Illegal DMA data: 0x%x\n", cmd);
490 return 2;
491 }
492 return 2;
493}
494
495
496static __inline__ int
497via_check_prim_list(uint32_t const **buffer, const uint32_t *buf_end,
498 drm_via_state_t *cur_seq)
499{
500 drm_via_private_t *dev_priv = (drm_via_private_t *) cur_seq->dev->dev_private;
501 uint32_t a_fire, bcmd , dw_count;
502 int ret = 0;
503 int have_fire;
504 const uint32_t *buf = *buffer;
505
506 while(buf < buf_end) {
507 have_fire = 0;
508 if ((buf_end - buf) < 2) {
509 DRM_ERROR("Unexpected termination of primitive list.\n");
510 ret = 1;
511 break;
512 }
513 if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdB) break;
514 bcmd = *buf++;
515 if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdA) {
516 DRM_ERROR("Expected Vertex List A command, got 0x%x\n",
517 *buf);
518 ret = 1;
519 break;
520 }
521 a_fire = *buf++ | HC_HPLEND_MASK | HC_HPMValidN_MASK | HC_HE3Fire_MASK;
522
523 /*
524 * How many dwords per vertex ?
525 */
526
527 if (cur_seq->agp && ((bcmd & (0xF << 11)) == 0)) {
528 DRM_ERROR("Illegal B command vertex data for AGP.\n");
529 ret = 1;
530 break;
531 }
532
533 dw_count = 0;
534 if (bcmd & (1 << 7)) dw_count += (cur_seq->multitex) ? 2:1;
535 if (bcmd & (1 << 8)) dw_count += (cur_seq->multitex) ? 2:1;
536 if (bcmd & (1 << 9)) dw_count++;
537 if (bcmd & (1 << 10)) dw_count++;
538 if (bcmd & (1 << 11)) dw_count++;
539 if (bcmd & (1 << 12)) dw_count++;
540 if (bcmd & (1 << 13)) dw_count++;
541 if (bcmd & (1 << 14)) dw_count++;
542
543 while(buf < buf_end) {
544 if (*buf == a_fire) {
545 if (dev_priv->num_fire_offsets >= VIA_FIRE_BUF_SIZE) {
546 DRM_ERROR("Fire offset buffer full.\n");
547 ret = 1;
548 break;
549 }
550 dev_priv->fire_offsets[dev_priv->num_fire_offsets++] = buf;
551 have_fire = 1;
552 buf++;
553 if (buf < buf_end && *buf == a_fire)
554 buf++;
555 break;
556 }
557 if ((*buf == HALCYON_HEADER2) ||
558 ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) {
559 DRM_ERROR("Missing Vertex Fire command, "
560 "Stray Vertex Fire command or verifier "
561 "lost sync.\n");
562 ret = 1;
563 break;
564 }
565 if ((ret = eat_words(&buf, buf_end, dw_count)))
566 break;
567 }
568 if (buf >= buf_end && !have_fire) {
569 DRM_ERROR("Missing Vertex Fire command or verifier "
570 "lost sync.\n");
571 ret = 1;
572 break;
573 }
574 if (cur_seq->agp && ((buf - cur_seq->buf_start) & 0x01)) {
575 DRM_ERROR("AGP Primitive list end misaligned.\n");
576 ret = 1;
577 break;
578 }
579 }
580 *buffer = buf;
581 return ret;
582}
583
584
585
586
587
588static __inline__ verifier_state_t
589via_check_header2( uint32_t const **buffer, const uint32_t *buf_end,
590 drm_via_state_t *hc_state)
591{
592 uint32_t cmd;
593 int hz_mode;
594 hazard_t hz;
595 const uint32_t *buf = *buffer;
596 const hazard_t *hz_table;
597
598
599 if ((buf_end - buf) < 2) {
600 DRM_ERROR("Illegal termination of DMA HALCYON_HEADER2 sequence.\n");
601 return state_error;
602 }
603 buf++;
604 cmd = (*buf++ & 0xFFFF0000) >> 16;
605
606 switch(cmd) {
607 case HC_ParaType_CmdVdata:
608 if (via_check_prim_list(&buf, buf_end, hc_state ))
609 return state_error;
610 *buffer = buf;
611 return state_command;
612 case HC_ParaType_NotTex:
613 hz_table = table1;
614 break;
615 case HC_ParaType_Tex:
616 hc_state->texture = 0;
617 hz_table = table2;
618 break;
619 case (HC_ParaType_Tex | (HC_SubType_Tex1 << 8)):
620 hc_state->texture = 1;
621 hz_table = table2;
622 break;
623 case (HC_ParaType_Tex | (HC_SubType_TexGeneral << 8)):
624 hz_table = table3;
625 break;
626 case HC_ParaType_Auto:
627 if (eat_words(&buf, buf_end, 2))
628 return state_error;
629 *buffer = buf;
630 return state_command;
631 case (HC_ParaType_Palette | (HC_SubType_Stipple << 8)):
632 if (eat_words(&buf, buf_end, 32))
633 return state_error;
634 *buffer = buf;
635 return state_command;
636 case (HC_ParaType_Palette | (HC_SubType_TexPalette0 << 8)):
637 case (HC_ParaType_Palette | (HC_SubType_TexPalette1 << 8)):
638 DRM_ERROR("Texture palettes are rejected because of "
639 "lack of info how to determine their size.\n");
640 return state_error;
641 case (HC_ParaType_Palette | (HC_SubType_FogTable << 8)):
642 DRM_ERROR("Fog factor palettes are rejected because of "
643 "lack of info how to determine their size.\n");
644 return state_error;
645 default:
646
647 /*
648 * There are some unimplemented HC_ParaTypes here, that
649 * need to be implemented if the Mesa driver is extended.
650 */
651
652 DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 "
653 "DMA subcommand: 0x%x. Previous dword: 0x%x\n",
654 cmd, *(buf -2));
655 *buffer = buf;
656 return state_error;
657 }
658
659 while(buf < buf_end) {
660 cmd = *buf++;
661 if ((hz = hz_table[cmd >> 24])) {
662 if ((hz_mode = investigate_hazard(cmd, hz, hc_state))) {
663 if (hz_mode == 1) {
664 buf--;
665 break;
666 }
667 return state_error;
668 }
669 } else if (hc_state->unfinished &&
670 finish_current_sequence(hc_state)) {
671 return state_error;
672 }
673 }
674 if (hc_state->unfinished && finish_current_sequence(hc_state)) {
675 return state_error;
676 }
677 *buffer = buf;
678 return state_command;
679}
680
681static __inline__ verifier_state_t
682via_parse_header2( drm_via_private_t *dev_priv, uint32_t const **buffer, const uint32_t *buf_end,
683 int *fire_count)
684{
685 uint32_t cmd;
686 const uint32_t *buf = *buffer;
687 const uint32_t *next_fire;
688 int burst = 0;
689
690 next_fire = dev_priv->fire_offsets[*fire_count];
691 buf++;
692 cmd = (*buf & 0xFFFF0000) >> 16;
693 VIA_WRITE(HC_REG_TRANS_SET + HC_REG_BASE, *buf++);
694 switch(cmd) {
695 case HC_ParaType_CmdVdata:
696 while ((buf < buf_end) &&
697 (*fire_count < dev_priv->num_fire_offsets) &&
698 (*buf & HC_ACMD_MASK) == HC_ACMD_HCmdB ) {
699 while(buf <= next_fire) {
700 VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE + (burst & 63), *buf++);
701 burst += 4;
702 }
703 if ( ( buf < buf_end ) && ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD))
704 buf++;
705
706 if (++(*fire_count) < dev_priv->num_fire_offsets)
707 next_fire = dev_priv->fire_offsets[*fire_count];
708 }
709 break;
710 default:
711 while(buf < buf_end) {
712
713 if ( *buf == HC_HEADER2 ||
714 (*buf & HALCYON_HEADER1MASK) == HALCYON_HEADER1 ||
715 (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5 ||
716 (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6 ) break;
717
718 VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE + (burst & 63), *buf++);
719 burst +=4;
720 }
721 }
722 *buffer = buf;
723 return state_command;
724}
725
726
727
728static __inline__ int
729verify_mmio_address( uint32_t address)
730{
731 if ((address > 0x3FF) && (address < 0xC00 )) {
732 DRM_ERROR("Invalid VIDEO DMA command. "
733 "Attempt to access 3D- or command burst area.\n");
734 return 1;
735 } else if ((address > 0xCFF) && (address < 0x1300)) {
736 DRM_ERROR("Invalid VIDEO DMA command. "
737 "Attempt to access PCI DMA area.\n");
738 return 1;
739 } else if (address > 0x13FF ) {
740 DRM_ERROR("Invalid VIDEO DMA command. "
741 "Attempt to access VGA registers.\n");
742 return 1;
743 }
744 return 0;
745}
746
747static __inline__ int
748verify_video_tail( uint32_t const **buffer, const uint32_t *buf_end, uint32_t dwords)
749{
750 const uint32_t *buf = *buffer;
751
752 if (buf_end - buf < dwords) {
753 DRM_ERROR("Illegal termination of video command.\n");
754 return 1;
755 }
756 while (dwords--) {
757 if (*buf++) {
758 DRM_ERROR("Illegal video command tail.\n");
759 return 1;
760 }
761 }
762 *buffer = buf;
763 return 0;
764}
765
766
767static __inline__ verifier_state_t
768via_check_header1( uint32_t const **buffer, const uint32_t *buf_end )
769{
770 uint32_t cmd;
771 const uint32_t *buf = *buffer;
772 verifier_state_t ret = state_command;
773
774 while (buf < buf_end) {
775 cmd = *buf;
776 if ((cmd > ((0x3FF >> 2) | HALCYON_HEADER1)) &&
777 (cmd < ((0xC00 >> 2) | HALCYON_HEADER1))) {
778 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
779 break;
780 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
781 "Attempt to access 3D- or command burst area.\n");
782 ret = state_error;
783 break;
784 } else if (cmd > ((0xCFF >> 2) | HALCYON_HEADER1)) {
785 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
786 break;
787 DRM_ERROR("Invalid HALCYON_HEADER1 command. "
788 "Attempt to access VGA registers.\n");
789 ret = state_error;
790 break;
791 } else {
792 buf += 2;
793 }
794 }
795 *buffer = buf;
796 return ret;
797}
798
799static __inline__ verifier_state_t
800via_parse_header1( drm_via_private_t *dev_priv, uint32_t const **buffer, const uint32_t *buf_end )
801{
802 register uint32_t cmd;
803 const uint32_t *buf = *buffer;
804
805 while (buf < buf_end) {
806 cmd = *buf;
807 if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1) break;
808 VIA_WRITE( (cmd & ~HALCYON_HEADER1MASK) << 2, *++buf);
809 buf++;
810 }
811 *buffer = buf;
812 return state_command;
813}
814
815static __inline__ verifier_state_t
816via_check_vheader5( uint32_t const **buffer, const uint32_t *buf_end )
817{
818 uint32_t data;
819 const uint32_t *buf = *buffer;
820
821 if (buf_end - buf < 4) {
822 DRM_ERROR("Illegal termination of video header5 command\n");
823 return state_error;
824 }
825
826 data = *buf++ & ~VIA_VIDEOMASK;
827 if (verify_mmio_address(data))
828 return state_error;
829
830 data = *buf++;
831 if (*buf++ != 0x00F50000) {
832 DRM_ERROR("Illegal header5 header data\n");
833 return state_error;
834 }
835 if (*buf++ != 0x00000000) {
836 DRM_ERROR("Illegal header5 header data\n");
837 return state_error;
838 }
839 if (eat_words(&buf, buf_end, data))
840 return state_error;
841 if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
842 return state_error;
843 *buffer = buf;
844 return state_command;
845
846}
847
848static __inline__ verifier_state_t
849via_parse_vheader5( drm_via_private_t *dev_priv, uint32_t const **buffer, const uint32_t *buf_end )
850{
851 uint32_t addr, count, i;
852 const uint32_t *buf = *buffer;
853
854 addr = *buf++ & ~VIA_VIDEOMASK;
855 i = count = *buf;
856 buf += 3;
857 while(i--) {
858 VIA_WRITE(addr, *buf++);
859 }
860 if (count & 3) buf += 4 - (count & 3);
861 *buffer = buf;
862 return state_command;
863}
864
865
866static __inline__ verifier_state_t
867via_check_vheader6( uint32_t const **buffer, const uint32_t *buf_end )
868{
869 uint32_t data;
870 const uint32_t *buf = *buffer;
871 uint32_t i;
872
873
874 if (buf_end - buf < 4) {
875 DRM_ERROR("Illegal termination of video header6 command\n");
876 return state_error;
877 }
878 buf++;
879 data = *buf++;
880 if (*buf++ != 0x00F60000) {
881 DRM_ERROR("Illegal header6 header data\n");
882 return state_error;
883 }
884 if (*buf++ != 0x00000000) {
885 DRM_ERROR("Illegal header6 header data\n");
886 return state_error;
887 }
888 if ((buf_end - buf) < (data << 1)) {
889 DRM_ERROR("Illegal termination of video header6 command\n");
890 return state_error;
891 }
892 for (i=0; i<data; ++i) {
893 if (verify_mmio_address(*buf++))
894 return state_error;
895 buf++;
896 }
897 data <<= 1;
898 if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
899 return state_error;
900 *buffer = buf;
901 return state_command;
902}
903
904static __inline__ verifier_state_t
905via_parse_vheader6( drm_via_private_t *dev_priv, uint32_t const **buffer, const uint32_t *buf_end )
906{
907
908 uint32_t addr, count, i;
909 const uint32_t *buf = *buffer;
910
911 i = count = *++buf;
912 buf += 3;
913 while(i--) {
914 addr = *buf++;
915 VIA_WRITE(addr, *buf++);
916 }
917 count <<= 1;
918 if (count & 3) buf += 4 - (count & 3);
919 *buffer = buf;
920 return state_command;
921}
922
923
924
925int
926via_verify_command_stream(const uint32_t * buf, unsigned int size, drm_device_t *dev,
927 int agp)
928{
929
930 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
931 drm_via_state_t *hc_state = &dev_priv->hc_state;
932 drm_via_state_t saved_state = *hc_state;
933 uint32_t cmd;
934 const uint32_t *buf_end = buf + ( size >> 2 );
935 verifier_state_t state = state_command;
936 int pro_group_a = dev_priv->pro_group_a;
937
938 hc_state->dev = dev;
939 hc_state->unfinished = no_sequence;
940 hc_state->map_cache = NULL;
941 hc_state->agp = agp;
942 hc_state->buf_start = buf;
943 dev_priv->num_fire_offsets = 0;
944
945 while (buf < buf_end) {
946
947 switch (state) {
948 case state_header2:
949 state = via_check_header2( &buf, buf_end, hc_state );
950 break;
951 case state_header1:
952 state = via_check_header1( &buf, buf_end );
953 break;
954 case state_vheader5:
955 state = via_check_vheader5( &buf, buf_end );
956 break;
957 case state_vheader6:
958 state = via_check_vheader6( &buf, buf_end );
959 break;
960 case state_command:
961 if (HALCYON_HEADER2 == (cmd = *buf))
962 state = state_header2;
963 else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
964 state = state_header1;
965 else if (pro_group_a && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
966 state = state_vheader5;
967 else if (pro_group_a && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
968 state = state_vheader6;
969 else {
970 DRM_ERROR("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
971 cmd);
972 state = state_error;
973 }
974 break;
975 case state_error:
976 default:
977 *hc_state = saved_state;
978 return DRM_ERR(EINVAL);
979 }
980 }
981 if (state == state_error) {
982 *hc_state = saved_state;
983 return DRM_ERR(EINVAL);
984 }
985 return 0;
986}
987
988int
989via_parse_command_stream(drm_device_t *dev, const uint32_t * buf, unsigned int size)
990{
991
992 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
993 uint32_t cmd;
994 const uint32_t *buf_end = buf + ( size >> 2 );
995 verifier_state_t state = state_command;
996 int fire_count = 0;
997
998 while (buf < buf_end) {
999
1000 switch (state) {
1001 case state_header2:
1002 state = via_parse_header2( dev_priv, &buf, buf_end, &fire_count );
1003 break;
1004 case state_header1:
1005 state = via_parse_header1( dev_priv, &buf, buf_end );
1006 break;
1007 case state_vheader5:
1008 state = via_parse_vheader5( dev_priv, &buf, buf_end );
1009 break;
1010 case state_vheader6:
1011 state = via_parse_vheader6( dev_priv, &buf, buf_end );
1012 break;
1013 case state_command:
1014 if (HALCYON_HEADER2 == (cmd = *buf))
1015 state = state_header2;
1016 else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
1017 state = state_header1;
1018 else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
1019 state = state_vheader5;
1020 else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
1021 state = state_vheader6;
1022 else {
1023 DRM_ERROR("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
1024 cmd);
1025 state = state_error;
1026 }
1027 break;
1028 case state_error:
1029 default:
1030 return DRM_ERR(EINVAL);
1031 }
1032 }
1033 if (state == state_error) {
1034 return DRM_ERR(EINVAL);
1035 }
1036 return 0;
1037}
1038
1039
1040
1041static void
1042setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size)
1043{
1044 int i;
1045
1046 for(i=0; i<256; ++i) {
1047 table[i] = forbidden_command;
1048 }
1049
1050 for(i=0; i<size; ++i) {
1051 table[init_table[i].code] = init_table[i].hz;
1052 }
1053}
1054
1055void
1056via_init_command_verifier( void )
1057{
1058 setup_hazard_table(init_table1, table1, sizeof(init_table1) / sizeof(hz_init_t));
1059 setup_hazard_table(init_table2, table2, sizeof(init_table2) / sizeof(hz_init_t));
1060 setup_hazard_table(init_table3, table3, sizeof(init_table3) / sizeof(hz_init_t));
1061}
diff --git a/drivers/char/drm/via_verifier.h b/drivers/char/drm/via_verifier.h
new file mode 100644
index 000000000000..a8e13592620f
--- /dev/null
+++ b/drivers/char/drm/via_verifier.h
@@ -0,0 +1,61 @@
1/*
2 * Copyright 2004 The Unichrome Project. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE UNICHROME PROJECT, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Thomas Hellström 2004.
24 */
25
26#ifndef _VIA_VERIFIER_H_
27#define _VIA_VERIFIER_H_
28
29typedef enum{
30 no_sequence = 0,
31 z_address,
32 dest_address,
33 tex_address
34}drm_via_sequence_t;
35
36
37
38typedef struct{
39 unsigned texture;
40 uint32_t z_addr;
41 uint32_t d_addr;
42 uint32_t t_addr[2][10];
43 uint32_t pitch[2][10];
44 uint32_t height[2][10];
45 uint32_t tex_level_lo[2];
46 uint32_t tex_level_hi[2];
47 uint32_t tex_palette_size[2];
48 drm_via_sequence_t unfinished;
49 int agp_texture;
50 int multitex;
51 drm_device_t *dev;
52 drm_map_t *map_cache;
53 uint32_t vertex_count;
54 int agp;
55 const uint32_t *buf_start;
56} drm_via_state_t;
57
58extern int via_verify_command_stream(const uint32_t * buf, unsigned int size,
59 drm_device_t *dev, int agp);
60
61#endif
diff --git a/drivers/char/drm/via_video.c b/drivers/char/drm/via_video.c
new file mode 100644
index 000000000000..37a61c67b292
--- /dev/null
+++ b/drivers/char/drm/via_video.c
@@ -0,0 +1,97 @@
1/*
2 * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Thomas Hellstrom 2005.
24 *
25 * Video and XvMC related functions.
26 */
27
28#include "drmP.h"
29#include "via_drm.h"
30#include "via_drv.h"
31
32void
33via_init_futex(drm_via_private_t *dev_priv)
34{
35 unsigned int i;
36
37 DRM_DEBUG("%s\n", __FUNCTION__);
38
39 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
40 DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
41 XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
42 }
43}
44
45void
46via_cleanup_futex(drm_via_private_t *dev_priv)
47{
48}
49
50void
51via_release_futex(drm_via_private_t *dev_priv, int context)
52{
53 unsigned int i;
54 volatile int *lock;
55
56 for (i=0; i < VIA_NR_XVMC_LOCKS; ++i) {
57 lock = (int *) XVMCLOCKPTR(dev_priv->sarea_priv, i);
58 if ( (_DRM_LOCKING_CONTEXT( *lock ) == context)) {
59 if (_DRM_LOCK_IS_HELD( *lock ) && (*lock & _DRM_LOCK_CONT)) {
60 DRM_WAKEUP( &(dev_priv->decoder_queue[i]));
61 }
62 *lock = 0;
63 }
64 }
65}
66
67int
68via_decoder_futex(DRM_IOCTL_ARGS)
69{
70 DRM_DEVICE;
71 drm_via_futex_t fx;
72 volatile int *lock;
73 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
74 drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
75 int ret = 0;
76
77 DRM_DEBUG("%s\n", __FUNCTION__);
78
79 DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t *) data, sizeof(fx));
80
81 if (fx.lock > VIA_NR_XVMC_LOCKS)
82 return -EFAULT;
83
84 lock = (int *)XVMCLOCKPTR(sAPriv, fx.lock);
85
86 switch (fx.func) {
87 case VIA_FUTEX_WAIT:
88 DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx.lock],
89 (fx.ms / 10) * (DRM_HZ / 100), *lock != fx.val);
90 return ret;
91 case VIA_FUTEX_WAKE:
92 DRM_WAKEUP(&(dev_priv->decoder_queue[fx.lock]));
93 return 0;
94 }
95 return 0;
96}
97
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 88cd858f74d0..cddb789902db 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -22,6 +22,7 @@
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */ 23 */
24 24
25#include <linux/config.h>
25#include <linux/console.h> 26#include <linux/console.h>
26#include <linux/cpumask.h> 27#include <linux/cpumask.h>
27#include <linux/init.h> 28#include <linux/init.h>
@@ -40,7 +41,6 @@
40#include <linux/delay.h> 41#include <linux/delay.h>
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
42#include <asm/hvconsole.h> 43#include <asm/hvconsole.h>
43#include <asm/vio.h>
44 44
45#define HVC_MAJOR 229 45#define HVC_MAJOR 229
46#define HVC_MINOR 0 46#define HVC_MINOR 0
@@ -61,16 +61,21 @@
61 */ 61 */
62#define HVC_ALLOC_TTY_ADAPTERS 8 62#define HVC_ALLOC_TTY_ADAPTERS 8
63 63
64static struct tty_driver *hvc_driver;
65#ifdef CONFIG_MAGIC_SYSRQ
66static int sysrq_pressed;
67#endif
68
69#define N_OUTBUF 16 64#define N_OUTBUF 16
70#define N_INBUF 16 65#define N_INBUF 16
71 66
72#define __ALIGNED__ __attribute__((__aligned__(8))) 67#define __ALIGNED__ __attribute__((__aligned__(8)))
73 68
69static struct tty_driver *hvc_driver;
70static struct task_struct *hvc_task;
71
72/* Picks up late kicks after list walk but before schedule() */
73static int hvc_kicked;
74
75#ifdef CONFIG_MAGIC_SYSRQ
76static int sysrq_pressed;
77#endif
78
74struct hvc_struct { 79struct hvc_struct {
75 spinlock_t lock; 80 spinlock_t lock;
76 int index; 81 int index;
@@ -80,11 +85,11 @@ struct hvc_struct {
80 char outbuf[N_OUTBUF] __ALIGNED__; 85 char outbuf[N_OUTBUF] __ALIGNED__;
81 int n_outbuf; 86 int n_outbuf;
82 uint32_t vtermno; 87 uint32_t vtermno;
88 struct hv_ops *ops;
83 int irq_requested; 89 int irq_requested;
84 int irq; 90 int irq;
85 struct list_head next; 91 struct list_head next;
86 struct kobject kobj; /* ref count & hvc_struct lifetime */ 92 struct kobject kobj; /* ref count & hvc_struct lifetime */
87 struct vio_dev *vdev;
88}; 93};
89 94
90/* dynamic list of hvc_struct instances */ 95/* dynamic list of hvc_struct instances */
@@ -97,26 +102,185 @@ static struct list_head hvc_structs = LIST_HEAD_INIT(hvc_structs);
97static DEFINE_SPINLOCK(hvc_structs_lock); 102static DEFINE_SPINLOCK(hvc_structs_lock);
98 103
99/* 104/*
105 * This value is used to assign a tty->index value to a hvc_struct based
106 * upon order of exposure via hvc_probe(), when we can not match it to
107 * a console canidate registered with hvc_instantiate().
108 */
109static int last_hvc = -1;
110
111/*
112 * Do not call this function with either the hvc_strucst_lock or the hvc_struct
113 * lock held. If successful, this function increments the kobject reference
114 * count against the target hvc_struct so it should be released when finished.
115 */
116struct hvc_struct *hvc_get_by_index(int index)
117{
118 struct hvc_struct *hp;
119 unsigned long flags;
120
121 spin_lock(&hvc_structs_lock);
122
123 list_for_each_entry(hp, &hvc_structs, next) {
124 spin_lock_irqsave(&hp->lock, flags);
125 if (hp->index == index) {
126 kobject_get(&hp->kobj);
127 spin_unlock_irqrestore(&hp->lock, flags);
128 spin_unlock(&hvc_structs_lock);
129 return hp;
130 }
131 spin_unlock_irqrestore(&hp->lock, flags);
132 }
133 hp = NULL;
134
135 spin_unlock(&hvc_structs_lock);
136 return hp;
137}
138
139
140/*
100 * Initial console vtermnos for console API usage prior to full console 141 * Initial console vtermnos for console API usage prior to full console
101 * initialization. Any vty adapter outside this range will not have usable 142 * initialization. Any vty adapter outside this range will not have usable
102 * console interfaces but can still be used as a tty device. This has to be 143 * console interfaces but can still be used as a tty device. This has to be
103 * static because kmalloc will not work during early console init. 144 * static because kmalloc will not work during early console init.
104 */ 145 */
105static uint32_t vtermnos[MAX_NR_HVC_CONSOLES]; 146static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
147static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
148 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
106 149
107/* Used for accounting purposes */ 150/*
108static int num_vterms = 0; 151 * Console APIs, NOT TTY. These APIs are available immediately when
152 * hvc_console_setup() finds adapters.
153 */
109 154
110static struct task_struct *hvc_task; 155void hvc_console_print(struct console *co, const char *b, unsigned count)
156{
157 char c[16] __ALIGNED__;
158 unsigned i = 0, n = 0;
159 int r, donecr = 0, index = co->index;
160
161 /* Console access attempt outside of acceptable console range. */
162 if (index >= MAX_NR_HVC_CONSOLES)
163 return;
164
165 /* This console adapter was removed so it is not useable. */
166 if (vtermnos[index] < 0)
167 return;
168
169 while (count > 0 || i > 0) {
170 if (count > 0 && i < sizeof(c)) {
171 if (b[n] == '\n' && !donecr) {
172 c[i++] = '\r';
173 donecr = 1;
174 } else {
175 c[i++] = b[n++];
176 donecr = 0;
177 --count;
178 }
179 } else {
180 r = cons_ops[index]->put_chars(vtermnos[index], c, i);
181 if (r < 0) {
182 /* throw away chars on error */
183 i = 0;
184 } else if (r > 0) {
185 i -= r;
186 if (i > 0)
187 memmove(c, c+r, i);
188 }
189 }
190 }
191}
192
193static struct tty_driver *hvc_console_device(struct console *c, int *index)
194{
195 if (vtermnos[c->index] == -1)
196 return NULL;
197
198 *index = c->index;
199 return hvc_driver;
200}
201
202static int __init hvc_console_setup(struct console *co, char *options)
203{
204 if (co->index < 0 || co->index >= MAX_NR_HVC_CONSOLES)
205 return -ENODEV;
206
207 if (vtermnos[co->index] == -1)
208 return -ENODEV;
209
210 return 0;
211}
212
213struct console hvc_con_driver = {
214 .name = "hvc",
215 .write = hvc_console_print,
216 .device = hvc_console_device,
217 .setup = hvc_console_setup,
218 .flags = CON_PRINTBUFFER,
219 .index = -1,
220};
111 221
112/* 222/*
113 * This value is used to associate a tty->index value to a hvc_struct based 223 * Early console initialization. Preceeds driver initialization.
114 * upon order of exposure via hvc_probe(). 224 *
225 * (1) we are first, and the user specified another driver
226 * -- index will remain -1
227 * (2) we are first and the user specified no driver
228 * -- index will be set to 0, then we will fail setup.
229 * (3) we are first and the user specified our driver
230 * -- index will be set to user specified driver, and we will fail
231 * (4) we are after driver, and this initcall will register us
232 * -- if the user didn't specify a driver then the console will match
233 *
234 * Note that for cases 2 and 3, we will match later when the io driver
235 * calls hvc_instantiate() and call register again.
115 */ 236 */
116static int hvc_count = -1; 237static int __init hvc_console_init(void)
238{
239 register_console(&hvc_con_driver);
240 return 0;
241}
242console_initcall(hvc_console_init);
117 243
118/* Picks up late kicks after list walk but before schedule() */ 244/*
119static int hvc_kicked; 245 * hvc_instantiate() is an early console discovery method which locates
246 * consoles * prior to the vio subsystem discovering them. Hotplugged
247 * vty adapters do NOT get an hvc_instantiate() callback since they
248 * appear after early console init.
249 */
250int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
251{
252 struct hvc_struct *hp;
253
254 if (index < 0 || index >= MAX_NR_HVC_CONSOLES)
255 return -1;
256
257 if (vtermnos[index] != -1)
258 return -1;
259
260 /* make sure no no tty has been registerd in this index */
261 hp = hvc_get_by_index(index);
262 if (hp) {
263 kobject_put(&hp->kobj);
264 return -1;
265 }
266
267 vtermnos[index] = vtermno;
268 cons_ops[index] = ops;
269
270 /* reserve all indices upto and including this index */
271 if (last_hvc < index)
272 last_hvc = index;
273
274 /* if this index is what the user requested, then register
275 * now (setup won't fail at this point). It's ok to just
276 * call register again if previously .setup failed.
277 */
278 if (index == hvc_con_driver.index)
279 register_console(&hvc_con_driver);
280
281 return 0;
282}
283EXPORT_SYMBOL(hvc_instantiate);
120 284
121/* Wake the sleeping khvcd */ 285/* Wake the sleeping khvcd */
122static void hvc_kick(void) 286static void hvc_kick(void)
@@ -125,13 +289,17 @@ static void hvc_kick(void)
125 wake_up_process(hvc_task); 289 wake_up_process(hvc_task);
126} 290}
127 291
292static int hvc_poll(struct hvc_struct *hp);
293
128/* 294/*
129 * NOTE: This API isn't used if the console adapter doesn't support interrupts. 295 * NOTE: This API isn't used if the console adapter doesn't support interrupts.
130 * In this case the console is poll driven. 296 * In this case the console is poll driven.
131 */ 297 */
132static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance, struct pt_regs *regs) 298static irqreturn_t hvc_handle_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
133{ 299{
134 hvc_kick(); 300 /* if hvc_poll request a repoll, then kick the hvcd thread */
301 if (hvc_poll(dev_instance))
302 hvc_kick();
135 return IRQ_HANDLED; 303 return IRQ_HANDLED;
136} 304}
137 305
@@ -141,34 +309,6 @@ static void hvc_unthrottle(struct tty_struct *tty)
141} 309}
142 310
143/* 311/*
144 * Do not call this function with either the hvc_strucst_lock or the hvc_struct
145 * lock held. If successful, this function increments the kobject reference
146 * count against the target hvc_struct so it should be released when finished.
147 */
148struct hvc_struct *hvc_get_by_index(int index)
149{
150 struct hvc_struct *hp;
151 unsigned long flags;
152
153 spin_lock(&hvc_structs_lock);
154
155 list_for_each_entry(hp, &hvc_structs, next) {
156 spin_lock_irqsave(&hp->lock, flags);
157 if (hp->index == index) {
158 kobject_get(&hp->kobj);
159 spin_unlock_irqrestore(&hp->lock, flags);
160 spin_unlock(&hvc_structs_lock);
161 return hp;
162 }
163 spin_unlock_irqrestore(&hp->lock, flags);
164 }
165 hp = NULL;
166
167 spin_unlock(&hvc_structs_lock);
168 return hp;
169}
170
171/*
172 * The TTY interface won't be used until after the vio layer has exposed the vty 312 * The TTY interface won't be used until after the vio layer has exposed the vty
173 * adapter to the kernel. 313 * adapter to the kernel.
174 */ 314 */
@@ -329,7 +469,7 @@ static void hvc_push(struct hvc_struct *hp)
329{ 469{
330 int n; 470 int n;
331 471
332 n = hvc_put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); 472 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
333 if (n <= 0) { 473 if (n <= 0) {
334 if (n == 0) 474 if (n == 0)
335 return; 475 return;
@@ -467,7 +607,7 @@ static int hvc_poll(struct hvc_struct *hp)
467 break; 607 break;
468 } 608 }
469 609
470 n = hvc_get_chars(hp->vtermno, buf, count); 610 n = hp->ops->get_chars(hp->vtermno, buf, count);
471 if (n <= 0) { 611 if (n <= 0) {
472 /* Hangup the tty when disconnected from host */ 612 /* Hangup the tty when disconnected from host */
473 if (n == -EPIPE) { 613 if (n == -EPIPE) {
@@ -479,14 +619,17 @@ static int hvc_poll(struct hvc_struct *hp)
479 } 619 }
480 for (i = 0; i < n; ++i) { 620 for (i = 0; i < n; ++i) {
481#ifdef CONFIG_MAGIC_SYSRQ 621#ifdef CONFIG_MAGIC_SYSRQ
482 /* Handle the SysRq Hack */ 622 if (hp->index == hvc_con_driver.index) {
483 if (buf[i] == '\x0f') { /* ^O -- should support a sequence */ 623 /* Handle the SysRq Hack */
484 sysrq_pressed = 1; 624 /* XXX should support a sequence */
485 continue; 625 if (buf[i] == '\x0f') { /* ^O */
486 } else if (sysrq_pressed) { 626 sysrq_pressed = 1;
487 handle_sysrq(buf[i], NULL, tty); 627 continue;
488 sysrq_pressed = 0; 628 } else if (sysrq_pressed) {
489 continue; 629 handle_sysrq(buf[i], NULL, tty);
630 sysrq_pressed = 0;
631 continue;
632 }
490 } 633 }
491#endif /* CONFIG_MAGIC_SYSRQ */ 634#endif /* CONFIG_MAGIC_SYSRQ */
492 tty_insert_flip_char(tty, buf[i], 0); 635 tty_insert_flip_char(tty, buf[i], 0);
@@ -497,8 +640,8 @@ static int hvc_poll(struct hvc_struct *hp)
497 640
498 /* 641 /*
499 * Account for the total amount read in one loop, and if above 642 * Account for the total amount read in one loop, and if above
500 * 64 bytes, we do a quick schedule loop to let the tty grok the 643 * 64 bytes, we do a quick schedule loop to let the tty grok
501 * data and eventually throttle us. 644 * the data and eventually throttle us.
502 */ 645 */
503 read_total += n; 646 read_total += n;
504 if (read_total >= 64) { 647 if (read_total >= 64) {
@@ -542,7 +685,6 @@ int khvcd(void *unused)
542 if (cpus_empty(cpus_in_xmon)) { 685 if (cpus_empty(cpus_in_xmon)) {
543 spin_lock(&hvc_structs_lock); 686 spin_lock(&hvc_structs_lock);
544 list_for_each_entry(hp, &hvc_structs, next) { 687 list_for_each_entry(hp, &hvc_structs, next) {
545 /*hp = list_entry(node, struct hvc_struct, * next); */
546 poll_mask |= hvc_poll(hp); 688 poll_mask |= hvc_poll(hp);
547 } 689 }
548 spin_unlock(&hvc_structs_lock); 690 spin_unlock(&hvc_structs_lock);
@@ -577,14 +719,6 @@ static struct tty_operations hvc_ops = {
577 .chars_in_buffer = hvc_chars_in_buffer, 719 .chars_in_buffer = hvc_chars_in_buffer,
578}; 720};
579 721
580char hvc_driver_name[] = "hvc_console";
581
582static struct vio_device_id hvc_driver_table[] __devinitdata= {
583 {"serial", "hvterm1"},
584 { NULL, }
585};
586MODULE_DEVICE_TABLE(vio, hvc_driver_table);
587
588/* callback when the kboject ref count reaches zero. */ 722/* callback when the kboject ref count reaches zero. */
589static void destroy_hvc_struct(struct kobject *kobj) 723static void destroy_hvc_struct(struct kobject *kobj)
590{ 724{
@@ -606,41 +740,51 @@ static struct kobj_type hvc_kobj_type = {
606 .release = destroy_hvc_struct, 740 .release = destroy_hvc_struct,
607}; 741};
608 742
609static int __devinit hvc_probe( 743struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
610 struct vio_dev *dev, 744 struct hv_ops *ops)
611 const struct vio_device_id *id)
612{ 745{
613 struct hvc_struct *hp; 746 struct hvc_struct *hp;
614 747 int i;
615 /* probed with invalid parameters. */
616 if (!dev || !id)
617 return -EPERM;
618 748
619 hp = kmalloc(sizeof(*hp), GFP_KERNEL); 749 hp = kmalloc(sizeof(*hp), GFP_KERNEL);
620 if (!hp) 750 if (!hp)
621 return -ENOMEM; 751 return ERR_PTR(-ENOMEM);
622 752
623 memset(hp, 0x00, sizeof(*hp)); 753 memset(hp, 0x00, sizeof(*hp));
624 hp->vtermno = dev->unit_address; 754
625 hp->vdev = dev; 755 hp->vtermno = vtermno;
626 hp->vdev->dev.driver_data = hp; 756 hp->irq = irq;
627 hp->irq = dev->irq; 757 hp->ops = ops;
628 758
629 kobject_init(&hp->kobj); 759 kobject_init(&hp->kobj);
630 hp->kobj.ktype = &hvc_kobj_type; 760 hp->kobj.ktype = &hvc_kobj_type;
631 761
632 spin_lock_init(&hp->lock); 762 spin_lock_init(&hp->lock);
633 spin_lock(&hvc_structs_lock); 763 spin_lock(&hvc_structs_lock);
634 hp->index = ++hvc_count; 764
765 /*
766 * find index to use:
767 * see if this vterm id matches one registered for console.
768 */
769 for (i=0; i < MAX_NR_HVC_CONSOLES; i++)
770 if (vtermnos[i] == hp->vtermno)
771 break;
772
773 /* no matching slot, just use a counter */
774 if (i >= MAX_NR_HVC_CONSOLES)
775 i = ++last_hvc;
776
777 hp->index = i;
778
635 list_add_tail(&(hp->next), &hvc_structs); 779 list_add_tail(&(hp->next), &hvc_structs);
636 spin_unlock(&hvc_structs_lock); 780 spin_unlock(&hvc_structs_lock);
637 781
638 return 0; 782 return hp;
639} 783}
784EXPORT_SYMBOL(hvc_alloc);
640 785
641static int __devexit hvc_remove(struct vio_dev *dev) 786int __devexit hvc_remove(struct hvc_struct *hp)
642{ 787{
643 struct hvc_struct *hp = dev->dev.driver_data;
644 unsigned long flags; 788 unsigned long flags;
645 struct kobject *kobjp; 789 struct kobject *kobjp;
646 struct tty_struct *tty; 790 struct tty_struct *tty;
@@ -673,23 +817,14 @@ static int __devexit hvc_remove(struct vio_dev *dev)
673 tty_hangup(tty); 817 tty_hangup(tty);
674 return 0; 818 return 0;
675} 819}
676 820EXPORT_SYMBOL(hvc_remove);
677static struct vio_driver hvc_vio_driver = {
678 .name = hvc_driver_name,
679 .id_table = hvc_driver_table,
680 .probe = hvc_probe,
681 .remove = hvc_remove,
682};
683 821
684/* Driver initialization. Follow console initialization. This is where the TTY 822/* Driver initialization. Follow console initialization. This is where the TTY
685 * interfaces start to become available. */ 823 * interfaces start to become available. */
686int __init hvc_init(void) 824int __init hvc_init(void)
687{ 825{
688 int rc; 826 /* We need more than hvc_count adapters due to hotplug additions. */
689
690 /* We need more than num_vterms adapters due to hotplug additions. */
691 hvc_driver = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS); 827 hvc_driver = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS);
692 /* hvc_driver = alloc_tty_driver(num_vterms); */
693 if (!hvc_driver) 828 if (!hvc_driver)
694 return -ENOMEM; 829 return -ENOMEM;
695 830
@@ -716,116 +851,20 @@ int __init hvc_init(void)
716 return -EIO; 851 return -EIO;
717 } 852 }
718 853
719 /* Register as a vio device to receive callbacks */ 854 return 0;
720 rc = vio_register_driver(&hvc_vio_driver);
721
722 return rc;
723} 855}
856module_init(hvc_init);
724 857
725/* This isn't particularily necessary due to this being a console driver but it 858/* This isn't particularily necessary due to this being a console driver
726 * is nice to be thorough */ 859 * but it is nice to be thorough.
860 */
727static void __exit hvc_exit(void) 861static void __exit hvc_exit(void)
728{ 862{
729 kthread_stop(hvc_task); 863 kthread_stop(hvc_task);
730 864
731 vio_unregister_driver(&hvc_vio_driver);
732 tty_unregister_driver(hvc_driver); 865 tty_unregister_driver(hvc_driver);
733 /* return tty_struct instances allocated in hvc_init(). */ 866 /* return tty_struct instances allocated in hvc_init(). */
734 put_tty_driver(hvc_driver); 867 put_tty_driver(hvc_driver);
868 unregister_console(&hvc_con_driver);
735} 869}
736
737/*
738 * Console APIs, NOT TTY. These APIs are available immediately when
739 * hvc_console_setup() finds adapters.
740 */
741
742/*
743 * hvc_instantiate() is an early console discovery method which locates consoles
744 * prior to the vio subsystem discovering them. Hotplugged vty adapters do NOT
745 * get an hvc_instantiate() callback since the appear after early console init.
746 */
747int hvc_instantiate(uint32_t vtermno, int index)
748{
749 if (index < 0 || index >= MAX_NR_HVC_CONSOLES)
750 return -1;
751
752 if (vtermnos[index] != -1)
753 return -1;
754
755 vtermnos[index] = vtermno;
756 return 0;
757}
758
759void hvc_console_print(struct console *co, const char *b, unsigned count)
760{
761 char c[16] __ALIGNED__;
762 unsigned i = 0, n = 0;
763 int r, donecr = 0;
764
765 /* Console access attempt outside of acceptable console range. */
766 if (co->index >= MAX_NR_HVC_CONSOLES)
767 return;
768
769 /* This console adapter was removed so it is not useable. */
770 if (vtermnos[co->index] < 0)
771 return;
772
773 while (count > 0 || i > 0) {
774 if (count > 0 && i < sizeof(c)) {
775 if (b[n] == '\n' && !donecr) {
776 c[i++] = '\r';
777 donecr = 1;
778 } else {
779 c[i++] = b[n++];
780 donecr = 0;
781 --count;
782 }
783 } else {
784 r = hvc_put_chars(vtermnos[co->index], c, i);
785 if (r < 0) {
786 /* throw away chars on error */
787 i = 0;
788 } else if (r > 0) {
789 i -= r;
790 if (i > 0)
791 memmove(c, c+r, i);
792 }
793 }
794 }
795}
796
797static struct tty_driver *hvc_console_device(struct console *c, int *index)
798{
799 *index = c->index;
800 return hvc_driver;
801}
802
803static int __init hvc_console_setup(struct console *co, char *options)
804{
805 return 0;
806}
807
808struct console hvc_con_driver = {
809 .name = "hvc",
810 .write = hvc_console_print,
811 .device = hvc_console_device,
812 .setup = hvc_console_setup,
813 .flags = CON_PRINTBUFFER,
814 .index = -1,
815};
816
817/* Early console initialization. Preceeds driver initialization. */
818static int __init hvc_console_init(void)
819{
820 int i;
821
822 for (i=0; i<MAX_NR_HVC_CONSOLES; i++)
823 vtermnos[i] = -1;
824 num_vterms = hvc_find_vtys();
825 register_console(&hvc_con_driver);
826 return 0;
827}
828console_initcall(hvc_console_init);
829
830module_init(hvc_init);
831module_exit(hvc_exit); 870module_exit(hvc_exit);
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
new file mode 100644
index 000000000000..60bb9152b832
--- /dev/null
+++ b/drivers/char/hvc_vio.c
@@ -0,0 +1,152 @@
1/*
2 * vio driver interface to hvc_console.c
3 *
4 * This code was moved here to allow the remaing code to be reused as a
5 * generic polling mode with semi-reliable transport driver core to the
6 * console and tty subsystems.
7 *
8 *
9 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
10 * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM
11 * Copyright (C) 2004 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
12 * Copyright (C) 2004 IBM Corporation
13 *
14 * Additional Author(s):
15 * Ryan S. Arnold <rsa@us.ibm.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31
32#include <linux/types.h>
33#include <linux/init.h>
34#include <asm/hvconsole.h>
35#include <asm/vio.h>
36#include <asm/prom.h>
37
38char hvc_driver_name[] = "hvc_console";
39
40static struct vio_device_id hvc_driver_table[] __devinitdata = {
41 {"serial", "hvterm1"},
42 { NULL, }
43};
44MODULE_DEVICE_TABLE(vio, hvc_driver_table);
45
46static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
47{
48 unsigned long got;
49 int i;
50
51 got = hvc_get_chars(vtermno, buf, count);
52
53 /*
54 * Work around a HV bug where it gives us a null
55 * after every \r. -- paulus
56 */
57 for (i = 1; i < got; ++i) {
58 if (buf[i] == 0 && buf[i-1] == '\r') {
59 --got;
60 if (i < got)
61 memmove(&buf[i], &buf[i+1],
62 got - i);
63 }
64 }
65 return got;
66}
67
68static struct hv_ops hvc_get_put_ops = {
69 .get_chars = filtered_get_chars,
70 .put_chars = hvc_put_chars,
71};
72
73static int __devinit hvc_vio_probe(struct vio_dev *vdev,
74 const struct vio_device_id *id)
75{
76 struct hvc_struct *hp;
77
78 /* probed with invalid parameters. */
79 if (!vdev || !id)
80 return -EPERM;
81
82 hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops);
83 if (IS_ERR(hp))
84 return PTR_ERR(hp);
85 dev_set_drvdata(&vdev->dev, hp);
86
87 return 0;
88}
89
90static int __devexit hvc_vio_remove(struct vio_dev *vdev)
91{
92 struct hvc_struct *hp = dev_get_drvdata(&vdev->dev);
93
94 return hvc_remove(hp);
95}
96
97static struct vio_driver hvc_vio_driver = {
98 .name = hvc_driver_name,
99 .id_table = hvc_driver_table,
100 .probe = hvc_vio_probe,
101 .remove = hvc_vio_remove,
102 .driver = {
103 .owner = THIS_MODULE,
104 }
105};
106
107static int hvc_vio_init(void)
108{
109 int rc;
110
111 /* Register as a vio device to receive callbacks */
112 rc = vio_register_driver(&hvc_vio_driver);
113
114 return rc;
115}
116module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */
117
118static void hvc_vio_exit(void)
119{
120 vio_unregister_driver(&hvc_vio_driver);
121}
122module_exit(hvc_vio_exit);
123
124/* the device tree order defines our numbering */
125static int hvc_find_vtys(void)
126{
127 struct device_node *vty;
128 int num_found = 0;
129
130 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
131 vty = of_find_node_by_name(vty, "vty")) {
132 uint32_t *vtermno;
133
134 /* We have statically defined space for only a certain number
135 * of console adapters.
136 */
137 if (num_found >= MAX_NR_HVC_CONSOLES)
138 break;
139
140 vtermno = (uint32_t *)get_property(vty, "reg", NULL);
141 if (!vtermno)
142 continue;
143
144 if (device_is_compatible(vty, "hvterm1")) {
145 hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
146 ++num_found;
147 }
148 }
149
150 return num_found;
151}
152console_initcall(hvc_find_vtys);
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index f1f1192ba2b5..a22aa940e01e 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -291,15 +291,13 @@ static void dump_packet(uint8_t *packet)
291 dump_hex(packet, header->len); 291 dump_hex(packet, header->len);
292} 292}
293 293
294/* can't use hvc_get_chars because that strips CRs */
295static int hvsi_read(struct hvsi_struct *hp, char *buf, int count) 294static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
296{ 295{
297 unsigned long got; 296 unsigned long got;
298 297
299 if (plpar_hcall(H_GET_TERM_CHAR, hp->vtermno, 0, 0, 0, &got, 298 got = hvc_get_chars(hp->vtermno, buf, count);
300 (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) 299
301 return got; 300 return got;
302 return 0;
303} 301}
304 302
305static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, 303static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
diff --git a/drivers/char/hw_random.c b/drivers/char/hw_random.c
index 7e6ac14c2450..3480535a09c5 100644
--- a/drivers/char/hw_random.c
+++ b/drivers/char/hw_random.c
@@ -579,7 +579,7 @@ static int __init rng_init (void)
579 579
580 /* Probe for Intel, AMD RNGs */ 580 /* Probe for Intel, AMD RNGs */
581 for_each_pci_dev(pdev) { 581 for_each_pci_dev(pdev) {
582 ent = pci_match_device (rng_pci_tbl, pdev); 582 ent = pci_match_id(rng_pci_tbl, pdev);
583 if (ent) { 583 if (ent) {
584 rng_ops = &rng_vendor_ops[ent->driver_data]; 584 rng_ops = &rng_vendor_ops[ent->driver_data];
585 goto match; 585 goto match;
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 1813d0d198f1..e16c13fe698d 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1088,8 +1088,8 @@ static inline int i_ipmi_request(ipmi_user_t user,
1088 long seqid; 1088 long seqid;
1089 int broadcast = 0; 1089 int broadcast = 0;
1090 1090
1091 if (addr->channel > IPMI_NUM_CHANNELS) { 1091 if (addr->channel >= IPMI_MAX_CHANNELS) {
1092 spin_lock_irqsave(&intf->counter_lock, flags); 1092 spin_lock_irqsave(&intf->counter_lock, flags);
1093 intf->sent_invalid_commands++; 1093 intf->sent_invalid_commands++;
1094 spin_unlock_irqrestore(&intf->counter_lock, flags); 1094 spin_unlock_irqrestore(&intf->counter_lock, flags);
1095 rv = -EINVAL; 1095 rv = -EINVAL;
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 31cf84d69026..931efd58f87a 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -309,9 +309,6 @@ static int __init misc_init(void)
309#ifdef CONFIG_BVME6000 309#ifdef CONFIG_BVME6000
310 rtc_DP8570A_init(); 310 rtc_DP8570A_init();
311#endif 311#endif
312#ifdef CONFIG_PMAC_PBOOK
313 pmu_device_init();
314#endif
315 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) { 312 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
316 printk("unable to get major %d for misc devices\n", 313 printk("unable to get major %d for misc devices\n",
317 MISC_MAJOR); 314 MISC_MAJOR);
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 7c24fbe831f8..95f7046ff059 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -451,7 +451,7 @@ static int __init moxa_init(void)
451 int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1; 451 int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1;
452 i = 0; 452 i = 0;
453 while (i < n) { 453 while (i < n) {
454 while ((p = pci_find_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) 454 while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL)
455 { 455 {
456 if (pci_enable_device(p)) 456 if (pci_enable_device(p))
457 continue; 457 continue;
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index edba5a35bf21..09103b3d8f05 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -770,10 +770,8 @@ send_signal:
770 } 770 }
771 if (c == '\n') { 771 if (c == '\n') {
772 if (L_ECHO(tty) || L_ECHONL(tty)) { 772 if (L_ECHO(tty) || L_ECHONL(tty)) {
773 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 773 if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
774 put_char('\a', tty); 774 put_char('\a', tty);
775 return;
776 }
777 opost('\n', tty); 775 opost('\n', tty);
778 } 776 }
779 goto handle_newline; 777 goto handle_newline;
@@ -790,10 +788,8 @@ send_signal:
790 * XXX are EOL_CHAR and EOL2_CHAR echoed?!? 788 * XXX are EOL_CHAR and EOL2_CHAR echoed?!?
791 */ 789 */
792 if (L_ECHO(tty)) { 790 if (L_ECHO(tty)) {
793 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 791 if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
794 put_char('\a', tty); 792 put_char('\a', tty);
795 return;
796 }
797 /* Record the column of first canon char. */ 793 /* Record the column of first canon char. */
798 if (tty->canon_head == tty->read_head) 794 if (tty->canon_head == tty->read_head)
799 tty->canon_column = tty->column; 795 tty->canon_column = tty->column;
@@ -862,12 +858,9 @@ static int n_tty_receive_room(struct tty_struct *tty)
862 * that erase characters will be handled. Other excess 858 * that erase characters will be handled. Other excess
863 * characters will be beeped. 859 * characters will be beeped.
864 */ 860 */
865 if (tty->icanon && !tty->canon_data) 861 if (left <= 0)
866 return N_TTY_BUF_SIZE; 862 left = tty->icanon && !tty->canon_data;
867 863 return left;
868 if (left > 0)
869 return left;
870 return 0;
871} 864}
872 865
873/** 866/**
@@ -1473,13 +1466,17 @@ static ssize_t write_chan(struct tty_struct * tty, struct file * file,
1473 if (tty->driver->flush_chars) 1466 if (tty->driver->flush_chars)
1474 tty->driver->flush_chars(tty); 1467 tty->driver->flush_chars(tty);
1475 } else { 1468 } else {
1476 c = tty->driver->write(tty, b, nr); 1469 while (nr > 0) {
1477 if (c < 0) { 1470 c = tty->driver->write(tty, b, nr);
1478 retval = c; 1471 if (c < 0) {
1479 goto break_out; 1472 retval = c;
1473 goto break_out;
1474 }
1475 if (!c)
1476 break;
1477 b += c;
1478 nr -= c;
1480 } 1479 }
1481 b += c;
1482 nr -= c;
1483 } 1480 }
1484 if (!nr) 1481 if (!nr)
1485 break; 1482 break;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 1c8d866a49dc..7a0c74648124 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -71,7 +71,6 @@
71#include <linux/workqueue.h> 71#include <linux/workqueue.h>
72#include <linux/hdlc.h> 72#include <linux/hdlc.h>
73 73
74#include <pcmcia/version.h>
75#include <pcmcia/cs_types.h> 74#include <pcmcia/cs_types.h>
76#include <pcmcia/cs.h> 75#include <pcmcia/cs.h>
77#include <pcmcia/cistpl.h> 76#include <pcmcia/cistpl.h>
@@ -581,7 +580,7 @@ static dev_link_t *mgslpc_attach(void)
581 580
582 /* Interrupt setup */ 581 /* Interrupt setup */
583 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 582 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
584 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID; 583 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
585 link->irq.Handler = NULL; 584 link->irq.Handler = NULL;
586 585
587 link->conf.Attributes = 0; 586 link->conf.Attributes = 0;
@@ -593,11 +592,6 @@ static dev_link_t *mgslpc_attach(void)
593 dev_list = link; 592 dev_list = link;
594 593
595 client_reg.dev_info = &dev_info; 594 client_reg.dev_info = &dev_info;
596 client_reg.EventMask =
597 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
598 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
599 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
600 client_reg.event_handler = &mgslpc_event;
601 client_reg.Version = 0x0210; 595 client_reg.Version = 0x0210;
602 client_reg.event_callback_args.client_data = link; 596 client_reg.event_callback_args.client_data = link;
603 597
@@ -3081,13 +3075,21 @@ void mgslpc_remove_device(MGSLPC_INFO *remove_info)
3081 } 3075 }
3082} 3076}
3083 3077
3078static struct pcmcia_device_id mgslpc_ids[] = {
3079 PCMCIA_DEVICE_MANF_CARD(0x02c5, 0x0050),
3080 PCMCIA_DEVICE_NULL
3081};
3082MODULE_DEVICE_TABLE(pcmcia, mgslpc_ids);
3083
3084static struct pcmcia_driver mgslpc_driver = { 3084static struct pcmcia_driver mgslpc_driver = {
3085 .owner = THIS_MODULE, 3085 .owner = THIS_MODULE,
3086 .drv = { 3086 .drv = {
3087 .name = "synclink_cs", 3087 .name = "synclink_cs",
3088 }, 3088 },
3089 .attach = mgslpc_attach, 3089 .attach = mgslpc_attach,
3090 .event = mgslpc_event,
3090 .detach = mgslpc_detach, 3091 .detach = mgslpc_detach,
3092 .id_table = mgslpc_ids,
3091}; 3093};
3092 3094
3093static struct tty_operations mgslpc_ops = { 3095static struct tty_operations mgslpc_ops = {
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 460b5d475edd..6b11d6b2129f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -271,7 +271,7 @@ static int random_write_wakeup_thresh = 128;
271 * samples to avoid wasting CPU time and reduce lock contention. 271 * samples to avoid wasting CPU time and reduce lock contention.
272 */ 272 */
273 273
274static int trickle_thresh = INPUT_POOL_WORDS * 28; 274static int trickle_thresh __read_mostly = INPUT_POOL_WORDS * 28;
275 275
276static DEFINE_PER_CPU(int, trickle_count) = 0; 276static DEFINE_PER_CPU(int, trickle_count) = 0;
277 277
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 7db3370f4972..d7d484024e2b 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -1095,7 +1095,7 @@ static int __init rio_init(void)
1095 1095
1096#ifdef CONFIG_PCI 1096#ifdef CONFIG_PCI
1097 /* First look for the JET devices: */ 1097 /* First look for the JET devices: */
1098 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1098 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1099 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, 1099 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1100 pdev))) { 1100 pdev))) {
1101 if (pci_enable_device(pdev)) continue; 1101 if (pci_enable_device(pdev)) continue;
@@ -1169,7 +1169,7 @@ static int __init rio_init(void)
1169 */ 1169 */
1170 1170
1171 /* Then look for the older RIO/PCI devices: */ 1171 /* Then look for the older RIO/PCI devices: */
1172 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1172 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1173 PCI_DEVICE_ID_SPECIALIX_RIO, 1173 PCI_DEVICE_ID_SPECIALIX_RIO,
1174 pdev))) { 1174 pdev))) {
1175 if (pci_enable_device(pdev)) continue; 1175 if (pci_enable_device(pdev)) continue;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index f463d6baa685..5b1d3680c8ab 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -355,7 +355,7 @@ static void rp_do_receive(struct r_port *info,
355 ToRecv = space; 355 ToRecv = space;
356 356
357 if (ToRecv <= 0) 357 if (ToRecv <= 0)
358 return; 358 goto done;
359 359
360 /* 360 /*
361 * if status indicates there are errored characters in the 361 * if status indicates there are errored characters in the
@@ -437,6 +437,7 @@ static void rp_do_receive(struct r_port *info,
437 } 437 }
438 /* Push the data up to the tty layer */ 438 /* Push the data up to the tty layer */
439 ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count); 439 ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
440done:
440 tty_ldisc_deref(ld); 441 tty_ldisc_deref(ld);
441} 442}
442 443
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index ff4f09804865..d8f9e94ae475 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -78,6 +78,7 @@
78#include <linux/sysctl.h> 78#include <linux/sysctl.h>
79#include <linux/wait.h> 79#include <linux/wait.h>
80#include <linux/bcd.h> 80#include <linux/bcd.h>
81#include <linux/delay.h>
81 82
82#include <asm/current.h> 83#include <asm/current.h>
83#include <asm/uaccess.h> 84#include <asm/uaccess.h>
@@ -894,7 +895,6 @@ static int __init rtc_init(void)
894 struct proc_dir_entry *ent; 895 struct proc_dir_entry *ent;
895#if defined(__alpha__) || defined(__mips__) 896#if defined(__alpha__) || defined(__mips__)
896 unsigned int year, ctrl; 897 unsigned int year, ctrl;
897 unsigned long uip_watchdog;
898 char *guess = NULL; 898 char *guess = NULL;
899#endif 899#endif
900#ifdef __sparc__ 900#ifdef __sparc__
@@ -1000,12 +1000,8 @@ no_irq:
1000 /* Each operating system on an Alpha uses its own epoch. 1000 /* Each operating system on an Alpha uses its own epoch.
1001 Let's try to guess which one we are using now. */ 1001 Let's try to guess which one we are using now. */
1002 1002
1003 uip_watchdog = jiffies;
1004 if (rtc_is_updating() != 0) 1003 if (rtc_is_updating() != 0)
1005 while (jiffies - uip_watchdog < 2*HZ/100) { 1004 msleep(20);
1006 barrier();
1007 cpu_relax();
1008 }
1009 1005
1010 spin_lock_irq(&rtc_lock); 1006 spin_lock_irq(&rtc_lock);
1011 year = CMOS_READ(RTC_YEAR); 1007 year = CMOS_READ(RTC_YEAR);
@@ -1213,7 +1209,6 @@ static int rtc_proc_open(struct inode *inode, struct file *file)
1213 1209
1214void rtc_get_rtc_time(struct rtc_time *rtc_tm) 1210void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1215{ 1211{
1216 unsigned long uip_watchdog = jiffies;
1217 unsigned char ctrl; 1212 unsigned char ctrl;
1218#ifdef CONFIG_MACH_DECSTATION 1213#ifdef CONFIG_MACH_DECSTATION
1219 unsigned int real_year; 1214 unsigned int real_year;
@@ -1221,7 +1216,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1221 1216
1222 /* 1217 /*
1223 * read RTC once any update in progress is done. The update 1218 * read RTC once any update in progress is done. The update
1224 * can take just over 2ms. We wait 10 to 20ms. There is no need to 1219 * can take just over 2ms. We wait 20ms. There is no need to
1225 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP. 1220 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
1226 * If you need to know *exactly* when a second has started, enable 1221 * If you need to know *exactly* when a second has started, enable
1227 * periodic update complete interrupts, (via ioctl) and then 1222 * periodic update complete interrupts, (via ioctl) and then
@@ -1230,10 +1225,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1230 */ 1225 */
1231 1226
1232 if (rtc_is_updating() != 0) 1227 if (rtc_is_updating() != 0)
1233 while (jiffies - uip_watchdog < 2*HZ/100) { 1228 msleep(20);
1234 barrier();
1235 cpu_relax();
1236 }
1237 1229
1238 /* 1230 /*
1239 * Only the values that we read from the RTC are set. We leave 1231 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index af79805b5576..12d563c648f7 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -228,7 +228,7 @@ static struct sysrq_key_op sysrq_term_op = {
228 228
229static void moom_callback(void *ignored) 229static void moom_callback(void *ignored)
230{ 230{
231 out_of_memory(GFP_KERNEL); 231 out_of_memory(GFP_KERNEL, 0);
232} 232}
233 233
234static DECLARE_WORK(moom_work, moom_callback, NULL); 234static DECLARE_WORK(moom_work, moom_callback, NULL);
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index 5413f2908859..eb7058cbf015 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -24,6 +24,8 @@
24 24
25#include <asm/io.h> 25#include <asm/io.h>
26#include <asm/reboot.h> 26#include <asm/reboot.h>
27#include <asm/vr41xx/giu.h>
28#include <asm/vr41xx/tb0219.h>
27 29
28MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>"); 30MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
29MODULE_DESCRIPTION("TANBAC TB0219 base board driver"); 31MODULE_DESCRIPTION("TANBAC TB0219 base board driver");
@@ -266,6 +268,21 @@ static void tb0219_restart(char *command)
266 tb0219_write(TB0219_RESET, 0); 268 tb0219_write(TB0219_RESET, 0);
267} 269}
268 270
271static void tb0219_pci_irq_init(void)
272{
273 /* PCI Slot 1 */
274 vr41xx_set_irq_trigger(TB0219_PCI_SLOT1_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
275 vr41xx_set_irq_level(TB0219_PCI_SLOT1_PIN, IRQ_LEVEL_LOW);
276
277 /* PCI Slot 2 */
278 vr41xx_set_irq_trigger(TB0219_PCI_SLOT2_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
279 vr41xx_set_irq_level(TB0219_PCI_SLOT2_PIN, IRQ_LEVEL_LOW);
280
281 /* PCI Slot 3 */
282 vr41xx_set_irq_trigger(TB0219_PCI_SLOT3_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
283 vr41xx_set_irq_level(TB0219_PCI_SLOT3_PIN, IRQ_LEVEL_LOW);
284}
285
269static int tb0219_probe(struct device *dev) 286static int tb0219_probe(struct device *dev)
270{ 287{
271 int retval; 288 int retval;
@@ -292,6 +309,8 @@ static int tb0219_probe(struct device *dev)
292 old_machine_restart = _machine_restart; 309 old_machine_restart = _machine_restart;
293 _machine_restart = tb0219_restart; 310 _machine_restart = tb0219_restart;
294 311
312 tb0219_pci_irq_init();
313
295 if (major == 0) { 314 if (major == 0) {
296 major = retval; 315 major = retval;
297 printk(KERN_INFO "TB0219: major number %d\n", major); 316 printk(KERN_INFO "TB0219: major number %d\n", major);
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index 659335d80ee7..ec78d2f161f7 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -396,7 +396,7 @@ static struct file_operations tipar_fops = {
396static int __init 396static int __init
397tipar_setup(char *str) 397tipar_setup(char *str)
398{ 398{
399 int ints[2]; 399 int ints[3];
400 400
401 str = get_options(str, ARRAY_SIZE(ints), ints); 401 str = get_options(str, ARRAY_SIZE(ints), ints);
402 402
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 854475c54f0e..049d128ae7f0 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -464,7 +464,7 @@ void __devexit tpm_remove(struct pci_dev *pci_dev)
464 464
465 pci_set_drvdata(pci_dev, NULL); 465 pci_set_drvdata(pci_dev, NULL);
466 misc_deregister(&chip->vendor->miscdev); 466 misc_deregister(&chip->vendor->miscdev);
467 kfree(&chip->vendor->miscdev.name); 467 kfree(chip->vendor->miscdev.name);
468 468
469 sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group); 469 sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group);
470 470
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 58597993954f..f19cf9d7792d 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -476,11 +476,11 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
476 ld = tty_ldisc_ref(tty); 476 ld = tty_ldisc_ref(tty);
477 switch (arg) { 477 switch (arg) {
478 case TCIFLUSH: 478 case TCIFLUSH:
479 if (ld->flush_buffer) 479 if (ld && ld->flush_buffer)
480 ld->flush_buffer(tty); 480 ld->flush_buffer(tty);
481 break; 481 break;
482 case TCIOFLUSH: 482 case TCIOFLUSH:
483 if (ld->flush_buffer) 483 if (ld && ld->flush_buffer)
484 ld->flush_buffer(tty); 484 ld->flush_buffer(tty);
485 /* fall through */ 485 /* fall through */
486 case TCOFLUSH: 486 case TCOFLUSH:
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index d7aa7a29f67e..30d96739fb23 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2796,7 +2796,7 @@ void do_blank_screen(int entering_gfx)
2796 return; 2796 return;
2797 2797
2798 if (vesa_off_interval) { 2798 if (vesa_off_interval) {
2799 blank_state = blank_vesa_wait, 2799 blank_state = blank_vesa_wait;
2800 mod_timer(&console_timer, jiffies + vesa_off_interval); 2800 mod_timer(&console_timer, jiffies + vesa_off_interval);
2801 } 2801 }
2802 2802
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 8971484b956b..1d44f69e1fda 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -25,6 +25,7 @@
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/console.h> 26#include <linux/console.h>
27#include <linux/signal.h> 27#include <linux/signal.h>
28#include <linux/timex.h>
28 29
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
@@ -386,7 +387,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
386 if (!perm) 387 if (!perm)
387 return -EPERM; 388 return -EPERM;
388 if (arg) 389 if (arg)
389 arg = 1193182 / arg; 390 arg = CLOCK_TICK_RATE / arg;
390 kd_mksound(arg, 0); 391 kd_mksound(arg, 0);
391 return 0; 392 return 0;
392 393
@@ -403,7 +404,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
403 ticks = HZ * ((arg >> 16) & 0xffff) / 1000; 404 ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
404 count = ticks ? (arg & 0xffff) : 0; 405 count = ticks ? (arg & 0xffff) : 0;
405 if (count) 406 if (count)
406 count = 1193182 / count; 407 count = CLOCK_TICK_RATE / count;
407 kd_mksound(count, ticks); 408 kd_mksound(count, ticks);
408 return 0; 409 return 0;
409 } 410 }
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index b14d642439ed..5d07ee59679d 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -401,7 +401,7 @@ static unsigned char __init i8xx_tco_getdevice (void)
401 */ 401 */
402 402
403 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 403 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
404 if (pci_match_device(i8xx_tco_pci_tbl, dev)) { 404 if (pci_match_id(i8xx_tco_pci_tbl, dev)) {
405 i8xx_tco_pci = dev; 405 i8xx_tco_pci = dev;
406 break; 406 break;
407 } 407 }
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index 4e98c215e5b1..4b039516cc86 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -162,7 +162,7 @@ ixp2000_wdt_release(struct inode *inode, struct file *file)
162 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) { 162 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
163 wdt_disable(); 163 wdt_disable();
164 } else { 164 } else {
165 printk(KERN_CRIT "WATCHDOG: Device closed unexpectdly - " 165 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
166 "timer will not stop\n"); 166 "timer will not stop\n");
167 } 167 }
168 168
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 82396e06c8a8..83df369113a4 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -156,7 +156,7 @@ ixp4xx_wdt_release(struct inode *inode, struct file *file)
156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) { 156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
157 wdt_disable(); 157 wdt_disable();
158 } else { 158 } else {
159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectdly - " 159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
160 "timer will not stop\n"); 160 "timer will not stop\n");
161 } 161 }
162 162
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index bf62dfe4976a..7a7859dd0d98 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -869,7 +869,7 @@ EXPORT_SYMBOL(cpufreq_get);
869 * cpufreq_suspend - let the low level driver prepare for suspend 869 * cpufreq_suspend - let the low level driver prepare for suspend
870 */ 870 */
871 871
872static int cpufreq_suspend(struct sys_device * sysdev, u32 state) 872static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
873{ 873{
874 int cpu = sysdev->id; 874 int cpu = sysdev->id;
875 unsigned int ret = 0; 875 unsigned int ret = 0;
@@ -897,7 +897,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, u32 state)
897 } 897 }
898 898
899 if (cpufreq_driver->suspend) { 899 if (cpufreq_driver->suspend) {
900 ret = cpufreq_driver->suspend(cpu_policy, state); 900 ret = cpufreq_driver->suspend(cpu_policy, pmsg);
901 if (ret) { 901 if (ret) {
902 printk(KERN_ERR "cpufreq: suspend failed in ->suspend " 902 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
903 "step on CPU %u\n", cpu_policy->cpu); 903 "step on CPU %u\n", cpu_policy->cpu);
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index ed708b4427b0..71407c578afe 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -49,6 +49,7 @@
49#include <linux/errno.h> 49#include <linux/errno.h>
50#include <linux/crypto.h> 50#include <linux/crypto.h>
51#include <linux/interrupt.h> 51#include <linux/interrupt.h>
52#include <linux/kernel.h>
52#include <asm/byteorder.h> 53#include <asm/byteorder.h>
53#include "padlock.h" 54#include "padlock.h"
54 55
@@ -59,8 +60,12 @@
59#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t)) 60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
60 61
61struct aes_ctx { 62struct aes_ctx {
62 uint32_t e_data[AES_EXTENDED_KEY_SIZE+4]; 63 uint32_t e_data[AES_EXTENDED_KEY_SIZE];
63 uint32_t d_data[AES_EXTENDED_KEY_SIZE+4]; 64 uint32_t d_data[AES_EXTENDED_KEY_SIZE];
65 struct {
66 struct cword encrypt;
67 struct cword decrypt;
68 } cword;
64 uint32_t *E; 69 uint32_t *E;
65 uint32_t *D; 70 uint32_t *D;
66 int key_length; 71 int key_length;
@@ -280,10 +285,15 @@ aes_hw_extkey_available(uint8_t key_len)
280 return 0; 285 return 0;
281} 286}
282 287
288static inline struct aes_ctx *aes_ctx(void *ctx)
289{
290 return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT);
291}
292
283static int 293static int
284aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags) 294aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags)
285{ 295{
286 struct aes_ctx *ctx = ctx_arg; 296 struct aes_ctx *ctx = aes_ctx(ctx_arg);
287 uint32_t i, t, u, v, w; 297 uint32_t i, t, u, v, w;
288 uint32_t P[AES_EXTENDED_KEY_SIZE]; 298 uint32_t P[AES_EXTENDED_KEY_SIZE];
289 uint32_t rounds; 299 uint32_t rounds;
@@ -295,25 +305,36 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
295 305
296 ctx->key_length = key_len; 306 ctx->key_length = key_len;
297 307
308 /*
309 * If the hardware is capable of generating the extended key
310 * itself we must supply the plain key for both encryption
311 * and decryption.
312 */
298 ctx->E = ctx->e_data; 313 ctx->E = ctx->e_data;
299 ctx->D = ctx->d_data; 314 ctx->D = ctx->e_data;
300
301 /* Ensure 16-Bytes alignmentation of keys for VIA PadLock. */
302 if ((int)(ctx->e_data) & 0x0F)
303 ctx->E += 4 - (((int)(ctx->e_data) & 0x0F) / sizeof (ctx->e_data[0]));
304
305 if ((int)(ctx->d_data) & 0x0F)
306 ctx->D += 4 - (((int)(ctx->d_data) & 0x0F) / sizeof (ctx->d_data[0]));
307 315
308 E_KEY[0] = uint32_t_in (in_key); 316 E_KEY[0] = uint32_t_in (in_key);
309 E_KEY[1] = uint32_t_in (in_key + 4); 317 E_KEY[1] = uint32_t_in (in_key + 4);
310 E_KEY[2] = uint32_t_in (in_key + 8); 318 E_KEY[2] = uint32_t_in (in_key + 8);
311 E_KEY[3] = uint32_t_in (in_key + 12); 319 E_KEY[3] = uint32_t_in (in_key + 12);
312 320
321 /* Prepare control words. */
322 memset(&ctx->cword, 0, sizeof(ctx->cword));
323
324 ctx->cword.decrypt.encdec = 1;
325 ctx->cword.encrypt.rounds = 10 + (key_len - 16) / 4;
326 ctx->cword.decrypt.rounds = ctx->cword.encrypt.rounds;
327 ctx->cword.encrypt.ksize = (key_len - 16) / 8;
328 ctx->cword.decrypt.ksize = ctx->cword.encrypt.ksize;
329
313 /* Don't generate extended keys if the hardware can do it. */ 330 /* Don't generate extended keys if the hardware can do it. */
314 if (aes_hw_extkey_available(key_len)) 331 if (aes_hw_extkey_available(key_len))
315 return 0; 332 return 0;
316 333
334 ctx->D = ctx->d_data;
335 ctx->cword.encrypt.keygen = 1;
336 ctx->cword.decrypt.keygen = 1;
337
317 switch (key_len) { 338 switch (key_len) {
318 case 16: 339 case 16:
319 t = E_KEY[3]; 340 t = E_KEY[3];
@@ -369,10 +390,9 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
369 390
370/* ====== Encryption/decryption routines ====== */ 391/* ====== Encryption/decryption routines ====== */
371 392
372/* This is the real call to PadLock. */ 393/* These are the real call to PadLock. */
373static inline void 394static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
374padlock_xcrypt_ecb(uint8_t *input, uint8_t *output, uint8_t *key, 395 void *control_word, u32 count)
375 void *control_word, uint32_t count)
376{ 396{
377 asm volatile ("pushfl; popfl"); /* enforce key reload. */ 397 asm volatile ("pushfl; popfl"); /* enforce key reload. */
378 asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */ 398 asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
@@ -380,60 +400,70 @@ padlock_xcrypt_ecb(uint8_t *input, uint8_t *output, uint8_t *key,
380 : "d"(control_word), "b"(key), "c"(count)); 400 : "d"(control_word), "b"(key), "c"(count));
381} 401}
382 402
383static void 403static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
384aes_padlock(void *ctx_arg, uint8_t *out_arg, const uint8_t *in_arg, int encdec) 404 u8 *iv, void *control_word, u32 count)
385{ 405{
386 /* Don't blindly modify this structure - the items must 406 /* Enforce key reload. */
387 fit on 16-Bytes boundaries! */ 407 asm volatile ("pushfl; popfl");
388 struct padlock_xcrypt_data { 408 /* rep xcryptcbc */
389 uint8_t buf[AES_BLOCK_SIZE]; 409 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
390 union cword cword; 410 : "+S" (input), "+D" (output), "+a" (iv)
391 }; 411 : "d" (control_word), "b" (key), "c" (count));
392 412 return iv;
393 struct aes_ctx *ctx = ctx_arg;
394 char bigbuf[sizeof(struct padlock_xcrypt_data) + 16];
395 struct padlock_xcrypt_data *data;
396 void *key;
397
398 /* Place 'data' at the first 16-Bytes aligned address in 'bigbuf'. */
399 if (((long)bigbuf) & 0x0F)
400 data = (void*)(bigbuf + 16 - ((long)bigbuf & 0x0F));
401 else
402 data = (void*)bigbuf;
403
404 /* Prepare Control word. */
405 memset (data, 0, sizeof(struct padlock_xcrypt_data));
406 data->cword.b.encdec = !encdec; /* in the rest of cryptoapi ENC=1/DEC=0 */
407 data->cword.b.rounds = 10 + (ctx->key_length - 16) / 4;
408 data->cword.b.ksize = (ctx->key_length - 16) / 8;
409
410 /* Is the hardware capable to generate the extended key? */
411 if (!aes_hw_extkey_available(ctx->key_length))
412 data->cword.b.keygen = 1;
413
414 /* ctx->E starts with a plain key - if the hardware is capable
415 to generate the extended key itself we must supply
416 the plain key for both Encryption and Decryption. */
417 if (encdec == CRYPTO_DIR_ENCRYPT || data->cword.b.keygen == 0)
418 key = ctx->E;
419 else
420 key = ctx->D;
421
422 memcpy(data->buf, in_arg, AES_BLOCK_SIZE);
423 padlock_xcrypt_ecb(data->buf, data->buf, key, &data->cword, 1);
424 memcpy(out_arg, data->buf, AES_BLOCK_SIZE);
425} 413}
426 414
427static void 415static void
428aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in) 416aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
429{ 417{
430 aes_padlock(ctx_arg, out, in, CRYPTO_DIR_ENCRYPT); 418 struct aes_ctx *ctx = aes_ctx(ctx_arg);
419 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1);
431} 420}
432 421
433static void 422static void
434aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in) 423aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
435{ 424{
436 aes_padlock(ctx_arg, out, in, CRYPTO_DIR_DECRYPT); 425 struct aes_ctx *ctx = aes_ctx(ctx_arg);
426 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1);
427}
428
429static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
430 const u8 *in, unsigned int nbytes)
431{
432 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
433 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt,
434 nbytes / AES_BLOCK_SIZE);
435 return nbytes & ~(AES_BLOCK_SIZE - 1);
436}
437
438static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
439 const u8 *in, unsigned int nbytes)
440{
441 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
442 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt,
443 nbytes / AES_BLOCK_SIZE);
444 return nbytes & ~(AES_BLOCK_SIZE - 1);
445}
446
447static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
448 const u8 *in, unsigned int nbytes)
449{
450 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
451 u8 *iv;
452
453 iv = padlock_xcrypt_cbc(in, out, ctx->E, desc->info,
454 &ctx->cword.encrypt, nbytes / AES_BLOCK_SIZE);
455 memcpy(desc->info, iv, AES_BLOCK_SIZE);
456
457 return nbytes & ~(AES_BLOCK_SIZE - 1);
458}
459
460static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
461 const u8 *in, unsigned int nbytes)
462{
463 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
464 padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt,
465 nbytes / AES_BLOCK_SIZE);
466 return nbytes & ~(AES_BLOCK_SIZE - 1);
437} 467}
438 468
439static struct crypto_alg aes_alg = { 469static struct crypto_alg aes_alg = {
@@ -441,6 +471,7 @@ static struct crypto_alg aes_alg = {
441 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 471 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
442 .cra_blocksize = AES_BLOCK_SIZE, 472 .cra_blocksize = AES_BLOCK_SIZE,
443 .cra_ctxsize = sizeof(struct aes_ctx), 473 .cra_ctxsize = sizeof(struct aes_ctx),
474 .cra_alignmask = PADLOCK_ALIGNMENT - 1,
444 .cra_module = THIS_MODULE, 475 .cra_module = THIS_MODULE,
445 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list), 476 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
446 .cra_u = { 477 .cra_u = {
@@ -449,7 +480,11 @@ static struct crypto_alg aes_alg = {
449 .cia_max_keysize = AES_MAX_KEY_SIZE, 480 .cia_max_keysize = AES_MAX_KEY_SIZE,
450 .cia_setkey = aes_set_key, 481 .cia_setkey = aes_set_key,
451 .cia_encrypt = aes_encrypt, 482 .cia_encrypt = aes_encrypt,
452 .cia_decrypt = aes_decrypt 483 .cia_decrypt = aes_decrypt,
484 .cia_encrypt_ecb = aes_encrypt_ecb,
485 .cia_decrypt_ecb = aes_decrypt_ecb,
486 .cia_encrypt_cbc = aes_encrypt_cbc,
487 .cia_decrypt_cbc = aes_decrypt_cbc,
453 } 488 }
454 } 489 }
455}; 490};
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
index 7a500605e449..3cf2b7a12348 100644
--- a/drivers/crypto/padlock.h
+++ b/drivers/crypto/padlock.h
@@ -13,18 +13,18 @@
13#ifndef _CRYPTO_PADLOCK_H 13#ifndef _CRYPTO_PADLOCK_H
14#define _CRYPTO_PADLOCK_H 14#define _CRYPTO_PADLOCK_H
15 15
16#define PADLOCK_ALIGNMENT 16
17
16/* Control word. */ 18/* Control word. */
17union cword { 19struct cword {
18 uint32_t cword[4]; 20 int __attribute__ ((__packed__))
19 struct { 21 rounds:4,
20 int rounds:4; 22 algo:3,
21 int algo:3; 23 keygen:1,
22 int keygen:1; 24 interm:1,
23 int interm:1; 25 encdec:1,
24 int encdec:1; 26 ksize:2;
25 int ksize:2; 27} __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
26 } b;
27};
28 28
29#define PFX "padlock: " 29#define PFX "padlock: "
30 30
diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c
index 839b44a7e08b..53c95c0bbf46 100644
--- a/drivers/firmware/pcdp.c
+++ b/drivers/firmware/pcdp.c
@@ -16,6 +16,7 @@
16#include <linux/console.h> 16#include <linux/console.h>
17#include <linux/efi.h> 17#include <linux/efi.h>
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <asm/vga.h>
19#include "pcdp.h" 20#include "pcdp.h"
20 21
21static int __init 22static int __init
@@ -40,10 +41,27 @@ setup_serial_console(struct pcdp_uart *uart)
40} 41}
41 42
42static int __init 43static int __init
43setup_vga_console(struct pcdp_vga *vga) 44setup_vga_console(struct pcdp_device *dev)
44{ 45{
45#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) 46#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
46 if (efi_mem_type(0xA0000) == EFI_CONVENTIONAL_MEMORY) { 47 u8 *if_ptr;
48
49 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
50 if (if_ptr[0] == PCDP_IF_PCI) {
51 struct pcdp_if_pci if_pci;
52
53 /* struct copy since ifptr might not be correctly aligned */
54
55 memcpy(&if_pci, if_ptr, sizeof(if_pci));
56
57 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
58 vga_console_iobase = if_pci.ioport_tra;
59
60 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
61 vga_console_membase = if_pci.mmio_tra;
62 }
63
64 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
47 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n"); 65 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
48 return -ENODEV; 66 return -ENODEV;
49 } 67 }
@@ -95,7 +113,7 @@ efi_setup_pcdp_console(char *cmdline)
95 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) { 113 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
96 if (dev->flags & PCDP_PRIMARY_CONSOLE) { 114 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
97 if (dev->type == PCDP_CONSOLE_VGA) { 115 if (dev->type == PCDP_CONSOLE_VGA) {
98 return setup_vga_console((struct pcdp_vga *) dev); 116 return setup_vga_console(dev);
99 } 117 }
100 } 118 }
101 } 119 }
diff --git a/drivers/firmware/pcdp.h b/drivers/firmware/pcdp.h
index 1dc7c88b7b4d..ce910d68bd19 100644
--- a/drivers/firmware/pcdp.h
+++ b/drivers/firmware/pcdp.h
@@ -52,11 +52,36 @@ struct pcdp_uart {
52 u32 clock_rate; 52 u32 clock_rate;
53 u8 pci_prog_intfc; 53 u8 pci_prog_intfc;
54 u8 flags; 54 u8 flags;
55}; 55 u16 conout_index;
56 u32 reserved;
57} __attribute__((packed));
58
59#define PCDP_IF_PCI 1
60
61/* pcdp_if_pci.trans */
62#define PCDP_PCI_TRANS_IOPORT 0x02
63#define PCDP_PCI_TRANS_MMIO 0x01
64
65struct pcdp_if_pci {
66 u8 interconnect;
67 u8 reserved;
68 u16 length;
69 u8 segment;
70 u8 bus;
71 u8 dev;
72 u8 fun;
73 u16 dev_id;
74 u16 vendor_id;
75 u32 acpi_interrupt;
76 u64 mmio_tra;
77 u64 ioport_tra;
78 u8 flags;
79 u8 trans;
80} __attribute__((packed));
56 81
57struct pcdp_vga { 82struct pcdp_vga {
58 u8 count; /* address space descriptors */ 83 u8 count; /* address space descriptors */
59}; 84} __attribute__((packed));
60 85
61/* pcdp_device.flags */ 86/* pcdp_device.flags */
62#define PCDP_PRIMARY_CONSOLE 1 87#define PCDP_PRIMARY_CONSOLE 1
@@ -66,7 +91,9 @@ struct pcdp_device {
66 u8 flags; 91 u8 flags;
67 u16 length; 92 u16 length;
68 u16 efi_index; 93 u16 efi_index;
69}; 94 /* next data is pcdp_if_pci or pcdp_if_acpi (not yet supported) */
95 /* next data is device specific type (currently only pcdp_vga) */
96} __attribute__((packed));
70 97
71struct pcdp { 98struct pcdp {
72 u8 signature[4]; 99 u8 signature[4];
@@ -81,4 +108,4 @@ struct pcdp {
81 u32 num_uarts; 108 u32 num_uarts;
82 struct pcdp_uart uart[0]; /* actual size is num_uarts */ 109 struct pcdp_uart uart[0]; /* actual size is num_uarts */
83 /* remainder of table is pcdp_device structures */ 110 /* remainder of table is pcdp_device structures */
84}; 111} __attribute__((packed));
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
new file mode 100644
index 000000000000..140d5f851a5b
--- /dev/null
+++ b/drivers/hwmon/Kconfig
@@ -0,0 +1,420 @@
1#
2# I2C Sensor chip drivers configuration
3#
4
5menu "Hardware Monitoring support"
6
7config HWMON
8 tristate "Hardware Monitoring support"
9 default y
10 help
11 Hardware monitoring devices let you monitor the hardware health
12 of a system. Most modern motherboards include such a device. It
13 can include temperature sensors, voltage sensors, fan speed
14 sensors and various additional features such as the ability to
15 control the speed of the fans.
16
17config SENSORS_ADM1021
18 tristate "Analog Devices ADM1021 and compatibles"
19 depends on HWMON && I2C
20 select I2C_SENSOR
21 help
22 If you say yes here you get support for Analog Devices ADM1021
23 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
24 Genesys Logic GL523SM, National Semiconductor LM84, TI THMC10,
25 and the XEON processor built-in sensor.
26
27 This driver can also be built as a module. If so, the module
28 will be called adm1021.
29
30config SENSORS_ADM1025
31 tristate "Analog Devices ADM1025 and compatibles"
32 depends on HWMON && I2C && EXPERIMENTAL
33 select I2C_SENSOR
34 help
35 If you say yes here you get support for Analog Devices ADM1025
36 and Philips NE1619 sensor chips.
37
38 This driver can also be built as a module. If so, the module
39 will be called adm1025.
40
41config SENSORS_ADM1026
42 tristate "Analog Devices ADM1026 and compatibles"
43 depends on HWMON && I2C && EXPERIMENTAL
44 select I2C_SENSOR
45 help
46 If you say yes here you get support for Analog Devices ADM1026
47 sensor chip.
48
49 This driver can also be built as a module. If so, the module
50 will be called adm1026.
51
52config SENSORS_ADM1031
53 tristate "Analog Devices ADM1031 and compatibles"
54 depends on HWMON && I2C && EXPERIMENTAL
55 select I2C_SENSOR
56 help
57 If you say yes here you get support for Analog Devices ADM1031
58 and ADM1030 sensor chips.
59
60 This driver can also be built as a module. If so, the module
61 will be called adm1031.
62
63config SENSORS_ADM9240
64 tristate "Analog Devices ADM9240 and compatibles"
65 depends on HWMON && I2C && EXPERIMENTAL
66 select I2C_SENSOR
67 help
68 If you say yes here you get support for Analog Devices ADM9240,
69 Dallas DS1780, National Semiconductor LM81 sensor chips.
70
71 This driver can also be built as a module. If so, the module
72 will be called adm9240.
73
74config SENSORS_ASB100
75 tristate "Asus ASB100 Bach"
76 depends on HWMON && I2C && EXPERIMENTAL
77 select I2C_SENSOR
78 help
79 If you say yes here you get support for the ASB100 Bach sensor
80 chip found on some Asus mainboards.
81
82 This driver can also be built as a module. If so, the module
83 will be called asb100.
84
85config SENSORS_ATXP1
86 tristate "Attansic ATXP1 VID controller"
87 depends on HWMON && I2C && EXPERIMENTAL
88 select I2C_SENSOR
89 help
90 If you say yes here you get support for the Attansic ATXP1 VID
91 controller.
92
93 If your board have such a chip, you are able to control your CPU
94 core and other voltages.
95
96 This driver can also be built as a module. If so, the module
97 will be called atxp1.
98
99config SENSORS_DS1621
100 tristate "Dallas Semiconductor DS1621 and DS1625"
101 depends on HWMON && I2C && EXPERIMENTAL
102 select I2C_SENSOR
103 help
104 If you say yes here you get support for Dallas Semiconductor
105 DS1621 and DS1625 sensor chips.
106
107 This driver can also be built as a module. If so, the module
108 will be called ds1621.
109
110config SENSORS_FSCHER
111 tristate "FSC Hermes"
112 depends on HWMON && I2C && EXPERIMENTAL
113 select I2C_SENSOR
114 help
115 If you say yes here you get support for Fujitsu Siemens
116 Computers Hermes sensor chips.
117
118 This driver can also be built as a module. If so, the module
119 will be called fscher.
120
121config SENSORS_FSCPOS
122 tristate "FSC Poseidon"
123 depends on HWMON && I2C && EXPERIMENTAL
124 select I2C_SENSOR
125 help
126 If you say yes here you get support for Fujitsu Siemens
127 Computers Poseidon sensor chips.
128
129 This driver can also be built as a module. If so, the module
130 will be called fscpos.
131
132config SENSORS_GL518SM
133 tristate "Genesys Logic GL518SM"
134 depends on HWMON && I2C
135 select I2C_SENSOR
136 help
137 If you say yes here you get support for Genesys Logic GL518SM
138 sensor chips.
139
140 This driver can also be built as a module. If so, the module
141 will be called gl518sm.
142
143config SENSORS_GL520SM
144 tristate "Genesys Logic GL520SM"
145 depends on HWMON && I2C && EXPERIMENTAL
146 select I2C_SENSOR
147 help
148 If you say yes here you get support for Genesys Logic GL520SM
149 sensor chips.
150
151 This driver can also be built as a module. If so, the module
152 will be called gl520sm.
153
154config SENSORS_IT87
155 tristate "ITE IT87xx and compatibles"
156 depends on HWMON && I2C
157 select I2C_SENSOR
158 help
159 If you say yes here you get support for ITE IT87xx sensor chips
160 and clones: SiS960.
161
162 This driver can also be built as a module. If so, the module
163 will be called it87.
164
165config SENSORS_LM63
166 tristate "National Semiconductor LM63"
167 depends on HWMON && I2C && EXPERIMENTAL
168 select I2C_SENSOR
169 help
170 If you say yes here you get support for the National Semiconductor
171 LM63 remote diode digital temperature sensor with integrated fan
172 control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro)
173 motherboard, among others.
174
175 This driver can also be built as a module. If so, the module
176 will be called lm63.
177
178config SENSORS_LM75
179 tristate "National Semiconductor LM75 and compatibles"
180 depends on HWMON && I2C
181 select I2C_SENSOR
182 help
183 If you say yes here you get support for National Semiconductor LM75
184 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
185 9-bit precision mode), and TelCom (now Microchip) TCN75.
186
187 The DS75 and DS1775 in 10- to 12-bit precision modes will require
188 a force module parameter. The driver will not handle the extra
189 precision anyhow.
190
191 This driver can also be built as a module. If so, the module
192 will be called lm75.
193
194config SENSORS_LM77
195 tristate "National Semiconductor LM77"
196 depends on HWMON && I2C && EXPERIMENTAL
197 select I2C_SENSOR
198 help
199 If you say yes here you get support for National Semiconductor LM77
200 sensor chips.
201
202 This driver can also be built as a module. If so, the module
203 will be called lm77.
204
205config SENSORS_LM78
206 tristate "National Semiconductor LM78 and compatibles"
207 depends on HWMON && I2C && EXPERIMENTAL
208 select I2C_SENSOR
209 help
210 If you say yes here you get support for National Semiconductor LM78,
211 LM78-J and LM79.
212
213 This driver can also be built as a module. If so, the module
214 will be called lm78.
215
216config SENSORS_LM80
217 tristate "National Semiconductor LM80"
218 depends on HWMON && I2C && EXPERIMENTAL
219 select I2C_SENSOR
220 help
221 If you say yes here you get support for National Semiconductor
222 LM80 sensor chips.
223
224 This driver can also be built as a module. If so, the module
225 will be called lm80.
226
227config SENSORS_LM83
228 tristate "National Semiconductor LM83"
229 depends on HWMON && I2C
230 select I2C_SENSOR
231 help
232 If you say yes here you get support for National Semiconductor
233 LM83 sensor chips.
234
235 This driver can also be built as a module. If so, the module
236 will be called lm83.
237
238config SENSORS_LM85
239 tristate "National Semiconductor LM85 and compatibles"
240 depends on HWMON && I2C && EXPERIMENTAL
241 select I2C_SENSOR
242 help
243 If you say yes here you get support for National Semiconductor LM85
244 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027.
245
246 This driver can also be built as a module. If so, the module
247 will be called lm85.
248
249config SENSORS_LM87
250 tristate "National Semiconductor LM87"
251 depends on HWMON && I2C && EXPERIMENTAL
252 select I2C_SENSOR
253 help
254 If you say yes here you get support for National Semiconductor LM87
255 sensor chips.
256
257 This driver can also be built as a module. If so, the module
258 will be called lm87.
259
260config SENSORS_LM90
261 tristate "National Semiconductor LM90 and compatibles"
262 depends on HWMON && I2C
263 select I2C_SENSOR
264 help
265 If you say yes here you get support for National Semiconductor LM90,
266 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
267 MAX6658 sensor chips.
268
269 The Analog Devices ADT7461 sensor chip is also supported, but only
270 if found in ADM1032 compatibility mode.
271
272 This driver can also be built as a module. If so, the module
273 will be called lm90.
274
275config SENSORS_LM92
276 tristate "National Semiconductor LM92 and compatibles"
277 depends on HWMON && I2C && EXPERIMENTAL
278 select I2C_SENSOR
279 help
280 If you say yes here you get support for National Semiconductor LM92
281 and Maxim MAX6635 sensor chips.
282
283 This driver can also be built as a module. If so, the module
284 will be called lm92.
285
286config SENSORS_MAX1619
287 tristate "Maxim MAX1619 sensor chip"
288 depends on HWMON && I2C && EXPERIMENTAL
289 select I2C_SENSOR
290 help
291 If you say yes here you get support for MAX1619 sensor chip.
292
293 This driver can also be built as a module. If so, the module
294 will be called max1619.
295
296config SENSORS_PC87360
297 tristate "National Semiconductor PC87360 family"
298 depends on HWMON && I2C && EXPERIMENTAL
299 select I2C_SENSOR
300 select I2C_ISA
301 help
302 If you say yes here you get access to the hardware monitoring
303 functions of the National Semiconductor PC8736x Super-I/O chips.
304 The PC87360, PC87363 and PC87364 only have fan monitoring and
305 control. The PC87365 and PC87366 additionally have voltage and
306 temperature monitoring.
307
308 This driver can also be built as a module. If so, the module
309 will be called pc87360.
310
311config SENSORS_SIS5595
312 tristate "Silicon Integrated Systems Corp. SiS5595"
313 depends on HWMON && I2C && PCI && EXPERIMENTAL
314 select I2C_SENSOR
315 select I2C_ISA
316 help
317 If you say yes here you get support for the integrated sensors in
318 SiS5595 South Bridges.
319
320 This driver can also be built as a module. If so, the module
321 will be called sis5595.
322
323config SENSORS_SMSC47M1
324 tristate "SMSC LPC47M10x and compatibles"
325 depends on HWMON && I2C && EXPERIMENTAL
326 select I2C_SENSOR
327 select I2C_ISA
328 help
329 If you say yes here you get support for the integrated fan
330 monitoring and control capabilities of the SMSC LPC47B27x,
331 LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x and LPC47M192 chips.
332
333 This driver can also be built as a module. If so, the module
334 will be called smsc47m1.
335
336config SENSORS_SMSC47B397
337 tristate "SMSC LPC47B397-NC"
338 depends on HWMON && I2C && EXPERIMENTAL
339 select I2C_SENSOR
340 select I2C_ISA
341 help
342 If you say yes here you get support for the SMSC LPC47B397-NC
343 sensor chip.
344
345 This driver can also be built as a module. If so, the module
346 will be called smsc47b397.
347
348config SENSORS_VIA686A
349 tristate "VIA686A"
350 depends on HWMON && I2C && PCI
351 select I2C_SENSOR
352 select I2C_ISA
353 help
354 If you say yes here you get support for the integrated sensors in
355 Via 686A/B South Bridges.
356
357 This driver can also be built as a module. If so, the module
358 will be called via686a.
359
360config SENSORS_W83781D
361 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
362 depends on HWMON && I2C
363 select I2C_SENSOR
364 help
365 If you say yes here you get support for the Winbond W8378x series
366 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
367 and the similar Asus AS99127F.
368
369 This driver can also be built as a module. If so, the module
370 will be called w83781d.
371
372config SENSORS_W83L785TS
373 tristate "Winbond W83L785TS-S"
374 depends on HWMON && I2C && EXPERIMENTAL
375 select I2C_SENSOR
376 help
377 If you say yes here you get support for the Winbond W83L785TS-S
378 sensor chip, which is used on the Asus A7N8X, among other
379 motherboards.
380
381 This driver can also be built as a module. If so, the module
382 will be called w83l785ts.
383
384config SENSORS_W83627HF
385 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
386 depends on HWMON && I2C && EXPERIMENTAL
387 select I2C_SENSOR
388 select I2C_ISA
389 help
390 If you say yes here you get support for the Winbond W836X7 series
391 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
392
393 This driver can also be built as a module. If so, the module
394 will be called w83627hf.
395
396config SENSORS_W83627EHF
397 tristate "Winbond W83627EHF"
398 depends on HWMON && I2C && EXPERIMENTAL
399 select I2C_SENSOR
400 select I2C_ISA
401 help
402 If you say yes here you get preliminary support for the hardware
403 monitoring functionality of the Winbond W83627EHF Super-I/O chip.
404 Only fan and temperature inputs are supported at the moment, while
405 the chip does much more than that.
406
407 This driver can also be built as a module. If so, the module
408 will be called w83627ehf.
409
410config HWMON_DEBUG_CHIP
411 bool "Hardware Monitoring Chip debugging messages"
412 depends on HWMON
413 default n
414 help
415 Say Y here if you want the I2C chip drivers to produce a bunch of
416 debug messages to the system log. Select this if you are having
417 a problem with I2C support and want to see more of what is going
418 on.
419
420endmenu
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
new file mode 100644
index 000000000000..2781403a0236
--- /dev/null
+++ b/drivers/hwmon/Makefile
@@ -0,0 +1,44 @@
1#
2# Makefile for sensor chip drivers.
3#
4
5# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
11obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
12obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
13obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
14obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
15obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
16obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
17obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
18obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
19obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
20obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
21obj-$(CONFIG_SENSORS_IT87) += it87.o
22obj-$(CONFIG_SENSORS_LM63) += lm63.o
23obj-$(CONFIG_SENSORS_LM75) += lm75.o
24obj-$(CONFIG_SENSORS_LM77) += lm77.o
25obj-$(CONFIG_SENSORS_LM78) += lm78.o
26obj-$(CONFIG_SENSORS_LM80) += lm80.o
27obj-$(CONFIG_SENSORS_LM83) += lm83.o
28obj-$(CONFIG_SENSORS_LM85) += lm85.o
29obj-$(CONFIG_SENSORS_LM87) += lm87.o
30obj-$(CONFIG_SENSORS_LM90) += lm90.o
31obj-$(CONFIG_SENSORS_LM92) += lm92.o
32obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
33obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
34obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
35obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
36obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
37obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
38obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
39obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
40
41ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
42EXTRA_CFLAGS += -DDEBUG
43endif
44
diff --git a/drivers/i2c/chips/adm1021.c b/drivers/hwmon/adm1021.c
index d2c774c32f45..d2c774c32f45 100644
--- a/drivers/i2c/chips/adm1021.c
+++ b/drivers/hwmon/adm1021.c
diff --git a/drivers/i2c/chips/adm1025.c b/drivers/hwmon/adm1025.c
index e452d0daf906..e452d0daf906 100644
--- a/drivers/i2c/chips/adm1025.c
+++ b/drivers/hwmon/adm1025.c
diff --git a/drivers/i2c/chips/adm1026.c b/drivers/hwmon/adm1026.c
index 3c85fe150cd7..3c85fe150cd7 100644
--- a/drivers/i2c/chips/adm1026.c
+++ b/drivers/hwmon/adm1026.c
diff --git a/drivers/i2c/chips/adm1031.c b/drivers/hwmon/adm1031.c
index 9168e983ca1d..9168e983ca1d 100644
--- a/drivers/i2c/chips/adm1031.c
+++ b/drivers/hwmon/adm1031.c
diff --git a/drivers/i2c/chips/adm9240.c b/drivers/hwmon/adm9240.c
index 5c68e9c311aa..5c68e9c311aa 100644
--- a/drivers/i2c/chips/adm9240.c
+++ b/drivers/hwmon/adm9240.c
diff --git a/drivers/i2c/chips/asb100.c b/drivers/hwmon/asb100.c
index 70d996d6fe0a..70d996d6fe0a 100644
--- a/drivers/i2c/chips/asb100.c
+++ b/drivers/hwmon/asb100.c
diff --git a/drivers/i2c/chips/atxp1.c b/drivers/hwmon/atxp1.c
index 5c6597aa2c7f..0bcf82b4c07b 100644
--- a/drivers/i2c/chips/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -144,7 +144,7 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
144 if (vid == cvid) 144 if (vid == cvid)
145 return count; 145 return count;
146 146
147 dev_info(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid); 147 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid);
148 148
149 /* Write every 25 mV step to increase stability */ 149 /* Write every 25 mV step to increase stability */
150 if (cvid > vid) { 150 if (cvid > vid) {
diff --git a/drivers/i2c/chips/ds1621.c b/drivers/hwmon/ds1621.c
index 5360d58804f6..5360d58804f6 100644
--- a/drivers/i2c/chips/ds1621.c
+++ b/drivers/hwmon/ds1621.c
diff --git a/drivers/i2c/chips/fscher.c b/drivers/hwmon/fscher.c
index da411741c2c5..da411741c2c5 100644
--- a/drivers/i2c/chips/fscher.c
+++ b/drivers/hwmon/fscher.c
diff --git a/drivers/i2c/chips/fscpos.c b/drivers/hwmon/fscpos.c
index 3beaa6191ef4..3beaa6191ef4 100644
--- a/drivers/i2c/chips/fscpos.c
+++ b/drivers/hwmon/fscpos.c
diff --git a/drivers/i2c/chips/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6bedf729dcf5..6bedf729dcf5 100644
--- a/drivers/i2c/chips/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
diff --git a/drivers/i2c/chips/gl520sm.c b/drivers/hwmon/gl520sm.c
index a13a504f5bfa..a13a504f5bfa 100644
--- a/drivers/i2c/chips/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
diff --git a/drivers/i2c/chips/it87.c b/drivers/hwmon/it87.c
index db20c9e47393..db20c9e47393 100644
--- a/drivers/i2c/chips/it87.c
+++ b/drivers/hwmon/it87.c
diff --git a/drivers/i2c/chips/lm63.c b/drivers/hwmon/lm63.c
index 7c6f9ea5a254..7c6f9ea5a254 100644
--- a/drivers/i2c/chips/lm63.c
+++ b/drivers/hwmon/lm63.c
diff --git a/drivers/i2c/chips/lm75.c b/drivers/hwmon/lm75.c
index 5be164ed278e..5be164ed278e 100644
--- a/drivers/i2c/chips/lm75.c
+++ b/drivers/hwmon/lm75.c
diff --git a/drivers/i2c/chips/lm75.h b/drivers/hwmon/lm75.h
index 63e3f2fb4c21..63e3f2fb4c21 100644
--- a/drivers/i2c/chips/lm75.h
+++ b/drivers/hwmon/lm75.h
diff --git a/drivers/i2c/chips/lm77.c b/drivers/hwmon/lm77.c
index b98f44952997..b98f44952997 100644
--- a/drivers/i2c/chips/lm77.c
+++ b/drivers/hwmon/lm77.c
diff --git a/drivers/i2c/chips/lm78.c b/drivers/hwmon/lm78.c
index 29241469dcba..29241469dcba 100644
--- a/drivers/i2c/chips/lm78.c
+++ b/drivers/hwmon/lm78.c
diff --git a/drivers/i2c/chips/lm80.c b/drivers/hwmon/lm80.c
index 8100595feb44..8100595feb44 100644
--- a/drivers/i2c/chips/lm80.c
+++ b/drivers/hwmon/lm80.c
diff --git a/drivers/i2c/chips/lm83.c b/drivers/hwmon/lm83.c
index a49008b444c8..a49008b444c8 100644
--- a/drivers/i2c/chips/lm83.c
+++ b/drivers/hwmon/lm83.c
diff --git a/drivers/i2c/chips/lm85.c b/drivers/hwmon/lm85.c
index b4d7fd418264..b4d7fd418264 100644
--- a/drivers/i2c/chips/lm85.c
+++ b/drivers/hwmon/lm85.c
diff --git a/drivers/i2c/chips/lm87.c b/drivers/hwmon/lm87.c
index 1921ed1af182..1921ed1af182 100644
--- a/drivers/i2c/chips/lm87.c
+++ b/drivers/hwmon/lm87.c
diff --git a/drivers/i2c/chips/lm90.c b/drivers/hwmon/lm90.c
index a67dcadf7cb0..a67dcadf7cb0 100644
--- a/drivers/i2c/chips/lm90.c
+++ b/drivers/hwmon/lm90.c
diff --git a/drivers/i2c/chips/lm92.c b/drivers/hwmon/lm92.c
index 215c8e40ffdd..215c8e40ffdd 100644
--- a/drivers/i2c/chips/lm92.c
+++ b/drivers/hwmon/lm92.c
diff --git a/drivers/i2c/chips/max1619.c b/drivers/hwmon/max1619.c
index bf553dcd97d6..bf553dcd97d6 100644
--- a/drivers/i2c/chips/max1619.c
+++ b/drivers/hwmon/max1619.c
diff --git a/drivers/i2c/chips/pc87360.c b/drivers/hwmon/pc87360.c
index 876c68f3af31..876c68f3af31 100644
--- a/drivers/i2c/chips/pc87360.c
+++ b/drivers/hwmon/pc87360.c
diff --git a/drivers/i2c/chips/sis5595.c b/drivers/hwmon/sis5595.c
index 6bbfc8fb4f13..6bbfc8fb4f13 100644
--- a/drivers/i2c/chips/sis5595.c
+++ b/drivers/hwmon/sis5595.c
diff --git a/drivers/i2c/chips/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 251ac2659554..251ac2659554 100644
--- a/drivers/i2c/chips/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
diff --git a/drivers/i2c/chips/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 897117a7213f..897117a7213f 100644
--- a/drivers/i2c/chips/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
diff --git a/drivers/i2c/chips/via686a.c b/drivers/hwmon/via686a.c
index 137d9b7cacd4..164d47948390 100644
--- a/drivers/i2c/chips/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -1,9 +1,9 @@
1/* 1/*
2 via686a.c - Part of lm_sensors, Linux kernel modules 2 via686a.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 for hardware monitoring
4 4
5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>, 6 Kyösti Mälkki <kmalkki@cc.hut.fi>,
7 Mark Studebaker <mdsxyz123@yahoo.com>, 7 Mark Studebaker <mdsxyz123@yahoo.com>,
8 and Bob Dougherty <bobd@stanford.edu> 8 and Bob Dougherty <bobd@stanford.edu>
9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew 9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
@@ -171,18 +171,18 @@ static inline u8 FAN_TO_REG(long rpm, int div)
171/******** TEMP CONVERSIONS (Bob Dougherty) *********/ 171/******** TEMP CONVERSIONS (Bob Dougherty) *********/
172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew) 172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
173 if(temp<169) 173 if(temp<169)
174 return double(temp)*0.427-32.08; 174 return double(temp)*0.427-32.08;
175 else if(temp>=169 && temp<=202) 175 else if(temp>=169 && temp<=202)
176 return double(temp)*0.582-58.16; 176 return double(temp)*0.582-58.16;
177 else 177 else
178 return double(temp)*0.924-127.33; 178 return double(temp)*0.924-127.33;
179 179
180 A fifth-order polynomial fits the unofficial data (provided by Alex van 180 A fifth-order polynomial fits the unofficial data (provided by Alex van
181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable 181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
182 numbers on my machine (ie. they agree with what my BIOS tells me). 182 numbers on my machine (ie. they agree with what my BIOS tells me).
183 Here's the fifth-order fit to the 8-bit data: 183 Here's the fifth-order fit to the 8-bit data:
184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - 184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. 185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
186 186
187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for 187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
188 finding my typos in this formula!) 188 finding my typos in this formula!)
diff --git a/drivers/i2c/chips/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 8a40b6976e1a..8a40b6976e1a 100644
--- a/drivers/i2c/chips/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
diff --git a/drivers/i2c/chips/w83627hf.c b/drivers/hwmon/w83627hf.c
index bd87a42e068a..bd87a42e068a 100644
--- a/drivers/i2c/chips/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
diff --git a/drivers/i2c/chips/w83781d.c b/drivers/hwmon/w83781d.c
index 0bb131ce09eb..0bb131ce09eb 100644
--- a/drivers/i2c/chips/w83781d.c
+++ b/drivers/hwmon/w83781d.c
diff --git a/drivers/i2c/chips/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 4469d52aba4c..4469d52aba4c 100644
--- a/drivers/i2c/chips/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
index 68e9e6832ca0..e6cae39f47aa 100644
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ b/drivers/i2c/algos/i2c-algo-ite.c
@@ -208,7 +208,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
208 goto bailout; 208 goto bailout;
209 } 209 }
210 sdalo(adap); 210 sdalo(adap);
211 printk("test_bus:1 scl: %d sda: %d \n",getscl(adap), 211 printk("test_bus:1 scl: %d sda: %d\n", getscl(adap),
212 getsda(adap)); 212 getsda(adap));
213 if ( 0 != getsda(adap) ) { 213 if ( 0 != getsda(adap) ) {
214 printk("test_bus: %s SDA stuck high!\n",name); 214 printk("test_bus: %s SDA stuck high!\n",name);
@@ -221,7 +221,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
221 goto bailout; 221 goto bailout;
222 } 222 }
223 sdahi(adap); 223 sdahi(adap);
224 printk("test_bus:2 scl: %d sda: %d \n",getscl(adap), 224 printk("test_bus:2 scl: %d sda: %d\n", getscl(adap),
225 getsda(adap)); 225 getsda(adap));
226 if ( 0 == getsda(adap) ) { 226 if ( 0 == getsda(adap) ) {
227 printk("test_bus: %s SDA stuck low!\n",name); 227 printk("test_bus: %s SDA stuck low!\n",name);
@@ -234,7 +234,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
234 goto bailout; 234 goto bailout;
235 } 235 }
236 scllo(adap); 236 scllo(adap);
237 printk("test_bus:3 scl: %d sda: %d \n",getscl(adap), 237 printk("test_bus:3 scl: %d sda: %d\n", getscl(adap),
238 getsda(adap)); 238 getsda(adap));
239 if ( 0 != getscl(adap) ) { 239 if ( 0 != getscl(adap) ) {
240 240
@@ -247,7 +247,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
247 goto bailout; 247 goto bailout;
248 } 248 }
249 sclhi(adap); 249 sclhi(adap);
250 printk("test_bus:4 scl: %d sda: %d \n",getscl(adap), 250 printk("test_bus:4 scl: %d sda: %d\n", getscl(adap),
251 getsda(adap)); 251 getsda(adap));
252 if ( 0 == getscl(adap) ) { 252 if ( 0 == getscl(adap) ) {
253 printk("test_bus: %s SCL stuck low!\n",name); 253 printk("test_bus: %s SCL stuck low!\n",name);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 45e6efb1dcd1..0ab7e37f5b00 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -194,7 +194,7 @@ static int i801_transaction(void)
194 /* Make sure the SMBus host is ready to start transmitting */ 194 /* Make sure the SMBus host is ready to start transmitting */
195 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ 195 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
196 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 196 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
197 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting... \n", 197 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting...\n",
198 temp); 198 temp);
199 outb_p(temp, SMBHSTSTS); 199 outb_p(temp, SMBHSTSTS);
200 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 200 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
@@ -315,7 +315,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
315 } 315 }
316 if (temp & errmask) { 316 if (temp & errmask) {
317 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). " 317 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
318 "Resetting... \n", temp); 318 "Resetting...\n", temp);
319 outb_p(temp, SMBHSTSTS); 319 outb_p(temp, SMBHSTSTS);
320 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 320 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
321 dev_err(&I801_dev->dev, 321 dev_err(&I801_dev->dev,
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index 363e545fc01f..94ae808314f7 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -698,7 +698,7 @@ dispose_iface(struct device *dev)
698} 698}
699 699
700static int 700static int
701create_iface_macio(struct macio_dev* dev, const struct of_match *match) 701create_iface_macio(struct macio_dev* dev, const struct of_device_id *match)
702{ 702{
703 return create_iface(dev->ofdev.node, &dev->ofdev.dev); 703 return create_iface(dev->ofdev.node, &dev->ofdev.dev);
704} 704}
@@ -710,7 +710,7 @@ dispose_iface_macio(struct macio_dev* dev)
710} 710}
711 711
712static int 712static int
713create_iface_of_platform(struct of_device* dev, const struct of_match *match) 713create_iface_of_platform(struct of_device* dev, const struct of_device_id *match)
714{ 714{
715 return create_iface(dev->node, &dev->dev); 715 return create_iface(dev->node, &dev->dev);
716} 716}
@@ -721,10 +721,9 @@ dispose_iface_of_platform(struct of_device* dev)
721 return dispose_iface(&dev->dev); 721 return dispose_iface(&dev->dev);
722} 722}
723 723
724static struct of_match i2c_keywest_match[] = 724static struct of_device_id i2c_keywest_match[] =
725{ 725{
726 { 726 {
727 .name = OF_ANY_MATCH,
728 .type = "i2c", 727 .type = "i2c",
729 .compatible = "keywest" 728 .compatible = "keywest"
730 }, 729 },
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 1f80ba9da6f1..6d34ee381ce1 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -243,7 +243,7 @@ static int piix4_transaction(void)
243 /* Make sure the SMBus host is ready to start transmitting */ 243 /* Make sure the SMBus host is ready to start transmitting */
244 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 244 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
245 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). " 245 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). "
246 "Resetting... \n", temp); 246 "Resetting...\n", temp);
247 outb_p(temp, SMBHSTSTS); 247 outb_p(temp, SMBHSTSTS);
248 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 248 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
249 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 249 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 2b5911cfb7b5..bbd5e4e52f09 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -228,7 +228,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
228 /* Make sure the SMBus host is ready to start transmitting */ 228 /* Make sure the SMBus host is ready to start transmitting */
229 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); 229 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
230 if (temp != 0x00) { 230 if (temp != 0x00) {
231 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting... \n", temp); 231 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting...\n", temp);
232 sis5595_write(SMB_STS_LO, temp & 0xff); 232 sis5595_write(SMB_STS_LO, temp & 0xff);
233 sis5595_write(SMB_STS_HI, temp >> 8); 233 sis5595_write(SMB_STS_HI, temp >> 8);
234 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { 234 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index a0982da09803..43f70dbfc03f 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -1,409 +1,12 @@
1# 1#
2# I2C Sensor and "other" chip configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4 4
5menu "Hardware Sensors Chip support"
6 depends on I2C
7
8config I2C_SENSOR 5config I2C_SENSOR
9 tristate 6 tristate
10 default n 7 default n
11 8
12config SENSORS_ADM1021 9menu "Miscellaneous I2C Chip support"
13 tristate "Analog Devices ADM1021 and compatibles"
14 depends on I2C
15 select I2C_SENSOR
16 help
17 If you say yes here you get support for Analog Devices ADM1021
18 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
19 Genesys Logic GL523SM, National Semiconductor LM84, TI THMC10,
20 and the XEON processor built-in sensor.
21
22 This driver can also be built as a module. If so, the module
23 will be called adm1021.
24
25config SENSORS_ADM1025
26 tristate "Analog Devices ADM1025 and compatibles"
27 depends on I2C && EXPERIMENTAL
28 select I2C_SENSOR
29 help
30 If you say yes here you get support for Analog Devices ADM1025
31 and Philips NE1619 sensor chips.
32
33 This driver can also be built as a module. If so, the module
34 will be called adm1025.
35
36config SENSORS_ADM1026
37 tristate "Analog Devices ADM1026 and compatibles"
38 depends on I2C && EXPERIMENTAL
39 select I2C_SENSOR
40 help
41 If you say yes here you get support for Analog Devices ADM1026
42 sensor chip.
43
44 This driver can also be built as a module. If so, the module
45 will be called adm1026.
46
47config SENSORS_ADM1031
48 tristate "Analog Devices ADM1031 and compatibles"
49 depends on I2C && EXPERIMENTAL
50 select I2C_SENSOR
51 help
52 If you say yes here you get support for Analog Devices ADM1031
53 and ADM1030 sensor chips.
54
55 This driver can also be built as a module. If so, the module
56 will be called adm1031.
57
58config SENSORS_ADM9240
59 tristate "Analog Devices ADM9240 and compatibles"
60 depends on I2C && EXPERIMENTAL
61 select I2C_SENSOR
62 help
63 If you say yes here you get support for Analog Devices ADM9240,
64 Dallas DS1780, National Semiconductor LM81 sensor chips.
65
66 This driver can also be built as a module. If so, the module
67 will be called adm9240.
68
69config SENSORS_ASB100
70 tristate "Asus ASB100 Bach"
71 depends on I2C && EXPERIMENTAL
72 select I2C_SENSOR
73 help
74 If you say yes here you get support for the ASB100 Bach sensor
75 chip found on some Asus mainboards.
76
77 This driver can also be built as a module. If so, the module
78 will be called asb100.
79
80config SENSORS_ATXP1
81 tristate "Attansic ATXP1 VID controller"
82 depends on I2C && EXPERIMENTAL
83 help
84 If you say yes here you get support for the Attansic ATXP1 VID
85 controller.
86
87 If your board have such a chip, you are able to control your CPU
88 core and other voltages.
89
90 This driver can also be built as a module. If so, the module
91 will be called atxp1.
92
93config SENSORS_DS1621
94 tristate "Dallas Semiconductor DS1621 and DS1625"
95 depends on I2C && EXPERIMENTAL
96 select I2C_SENSOR
97 help
98 If you say yes here you get support for Dallas Semiconductor
99 DS1621 and DS1625 sensor chips.
100
101 This driver can also be built as a module. If so, the module
102 will be called ds1621.
103
104config SENSORS_FSCHER
105 tristate "FSC Hermes"
106 depends on I2C && EXPERIMENTAL
107 select I2C_SENSOR
108 help
109 If you say yes here you get support for Fujitsu Siemens
110 Computers Hermes sensor chips.
111
112 This driver can also be built as a module. If so, the module
113 will be called fscher.
114
115config SENSORS_FSCPOS
116 tristate "FSC Poseidon"
117 depends on I2C && EXPERIMENTAL
118 select I2C_SENSOR
119 help
120 If you say yes here you get support for Fujitsu Siemens
121 Computers Poseidon sensor chips.
122
123 This driver can also be built as a module. If so, the module
124 will be called fscpos.
125
126config SENSORS_GL518SM
127 tristate "Genesys Logic GL518SM"
128 depends on I2C
129 select I2C_SENSOR
130 help
131 If you say yes here you get support for Genesys Logic GL518SM
132 sensor chips.
133
134 This driver can also be built as a module. If so, the module
135 will be called gl518sm.
136
137config SENSORS_GL520SM
138 tristate "Genesys Logic GL520SM"
139 depends on I2C && EXPERIMENTAL
140 select I2C_SENSOR
141 help
142 If you say yes here you get support for Genesys Logic GL520SM
143 sensor chips.
144
145 This driver can also be built as a module. If so, the module
146 will be called gl520sm.
147
148config SENSORS_IT87
149 tristate "ITE IT87xx and compatibles"
150 depends on I2C
151 select I2C_SENSOR
152 help
153 If you say yes here you get support for ITE IT87xx sensor chips
154 and clones: SiS960.
155
156 This driver can also be built as a module. If so, the module
157 will be called it87.
158
159config SENSORS_LM63
160 tristate "National Semiconductor LM63"
161 depends on I2C && EXPERIMENTAL
162 select I2C_SENSOR
163 help
164 If you say yes here you get support for the National Semiconductor
165 LM63 remote diode digital temperature sensor with integrated fan
166 control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro)
167 motherboard, among others.
168
169 This driver can also be built as a module. If so, the module
170 will be called lm63.
171
172config SENSORS_LM75
173 tristate "National Semiconductor LM75 and compatibles"
174 depends on I2C
175 select I2C_SENSOR
176 help
177 If you say yes here you get support for National Semiconductor LM75
178 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
179 9-bit precision mode), and TelCom (now Microchip) TCN75.
180
181 The DS75 and DS1775 in 10- to 12-bit precision modes will require
182 a force module parameter. The driver will not handle the extra
183 precision anyhow.
184
185 This driver can also be built as a module. If so, the module
186 will be called lm75.
187
188config SENSORS_LM77
189 tristate "National Semiconductor LM77"
190 depends on I2C && EXPERIMENTAL
191 select I2C_SENSOR
192 help
193 If you say yes here you get support for National Semiconductor LM77
194 sensor chips.
195
196 This driver can also be built as a module. If so, the module
197 will be called lm77.
198
199config SENSORS_LM78
200 tristate "National Semiconductor LM78 and compatibles"
201 depends on I2C && EXPERIMENTAL
202 select I2C_SENSOR
203 help
204 If you say yes here you get support for National Semiconductor LM78,
205 LM78-J and LM79.
206
207 This driver can also be built as a module. If so, the module
208 will be called lm78.
209
210config SENSORS_LM80
211 tristate "National Semiconductor LM80"
212 depends on I2C && EXPERIMENTAL
213 select I2C_SENSOR
214 help
215 If you say yes here you get support for National Semiconductor
216 LM80 sensor chips.
217
218 This driver can also be built as a module. If so, the module
219 will be called lm80.
220
221config SENSORS_LM83
222 tristate "National Semiconductor LM83"
223 depends on I2C
224 select I2C_SENSOR
225 help
226 If you say yes here you get support for National Semiconductor
227 LM83 sensor chips.
228
229 This driver can also be built as a module. If so, the module
230 will be called lm83.
231
232config SENSORS_LM85
233 tristate "National Semiconductor LM85 and compatibles"
234 depends on I2C && EXPERIMENTAL
235 select I2C_SENSOR
236 help
237 If you say yes here you get support for National Semiconductor LM85
238 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027.
239
240 This driver can also be built as a module. If so, the module
241 will be called lm85.
242
243config SENSORS_LM87
244 tristate "National Semiconductor LM87"
245 depends on I2C && EXPERIMENTAL
246 select I2C_SENSOR
247 help
248 If you say yes here you get support for National Semiconductor LM87
249 sensor chips.
250
251 This driver can also be built as a module. If so, the module
252 will be called lm87.
253
254config SENSORS_LM90
255 tristate "National Semiconductor LM90 and compatibles"
256 depends on I2C
257 select I2C_SENSOR
258 help
259 If you say yes here you get support for National Semiconductor LM90,
260 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
261 MAX6658 sensor chips.
262
263 The Analog Devices ADT7461 sensor chip is also supported, but only
264 if found in ADM1032 compatibility mode.
265
266 This driver can also be built as a module. If so, the module
267 will be called lm90.
268
269config SENSORS_LM92
270 tristate "National Semiconductor LM92 and compatibles"
271 depends on I2C && EXPERIMENTAL
272 select I2C_SENSOR
273 help
274 If you say yes here you get support for National Semiconductor LM92
275 and Maxim MAX6635 sensor chips.
276
277 This driver can also be built as a module. If so, the module
278 will be called lm92.
279
280config SENSORS_MAX1619
281 tristate "Maxim MAX1619 sensor chip"
282 depends on I2C && EXPERIMENTAL
283 select I2C_SENSOR
284 help
285 If you say yes here you get support for MAX1619 sensor chip.
286
287 This driver can also be built as a module. If so, the module
288 will be called max1619.
289
290config SENSORS_PC87360
291 tristate "National Semiconductor PC87360 family"
292 depends on I2C && EXPERIMENTAL
293 select I2C_SENSOR
294 select I2C_ISA
295 help
296 If you say yes here you get access to the hardware monitoring
297 functions of the National Semiconductor PC8736x Super-I/O chips.
298 The PC87360, PC87363 and PC87364 only have fan monitoring and
299 control. The PC87365 and PC87366 additionally have voltage and
300 temperature monitoring.
301
302 This driver can also be built as a module. If so, the module
303 will be called pc87360.
304
305config SENSORS_SMSC47B397
306 tristate "SMSC LPC47B397-NC"
307 depends on I2C && EXPERIMENTAL
308 select I2C_SENSOR
309 select I2C_ISA
310 help
311 If you say yes here you get support for the SMSC LPC47B397-NC
312 sensor chip.
313
314 This driver can also be built as a module. If so, the module
315 will be called smsc47b397.
316
317config SENSORS_SIS5595
318 tristate "Silicon Integrated Systems Corp. SiS5595"
319 depends on I2C && PCI && EXPERIMENTAL
320 select I2C_SENSOR
321 select I2C_ISA
322 help
323 If you say yes here you get support for the integrated sensors in
324 SiS5595 South Bridges.
325
326 This driver can also be built as a module. If so, the module
327 will be called sis5595.
328
329config SENSORS_SMSC47M1
330 tristate "SMSC LPC47M10x and compatibles"
331 depends on I2C && EXPERIMENTAL
332 select I2C_SENSOR
333 select I2C_ISA
334 help
335 If you say yes here you get support for the integrated fan
336 monitoring and control capabilities of the SMSC LPC47B27x,
337 LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x and LPC47M192 chips.
338
339 This driver can also be built as a module. If so, the module
340 will be called smsc47m1.
341
342config SENSORS_VIA686A
343 tristate "VIA686A"
344 depends on I2C && PCI
345 select I2C_SENSOR
346 select I2C_ISA
347 help
348 If you say yes here you get support for the integrated sensors in
349 Via 686A/B South Bridges.
350
351 This driver can also be built as a module. If so, the module
352 will be called via686a.
353
354config SENSORS_W83781D
355 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
356 depends on I2C
357 select I2C_SENSOR
358 help
359 If you say yes here you get support for the Winbond W8378x series
360 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
361 and the similar Asus AS99127F.
362
363 This driver can also be built as a module. If so, the module
364 will be called w83781d.
365
366config SENSORS_W83L785TS
367 tristate "Winbond W83L785TS-S"
368 depends on I2C && EXPERIMENTAL
369 select I2C_SENSOR
370 help
371 If you say yes here you get support for the Winbond W83L785TS-S
372 sensor chip, which is used on the Asus A7N8X, among other
373 motherboards.
374
375 This driver can also be built as a module. If so, the module
376 will be called w83l785ts.
377
378config SENSORS_W83627HF
379 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
380 depends on I2C && EXPERIMENTAL
381 select I2C_SENSOR
382 select I2C_ISA
383 help
384 If you say yes here you get support for the Winbond W836X7 series
385 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
386
387 This driver can also be built as a module. If so, the module
388 will be called w83627hf.
389
390config SENSORS_W83627EHF
391 tristate "Winbond W83627EHF"
392 depends on I2C && EXPERIMENTAL
393 select I2C_SENSOR
394 select I2C_ISA
395 help
396 If you say yes here you get preliminary support for the hardware
397 monitoring functionality of the Winbond W83627EHF Super-I/O chip.
398 Only fan and temperature inputs are supported at the moment, while
399 the chip does much more than that.
400
401 This driver can also be built as a module. If so, the module
402 will be called w83627ehf.
403
404endmenu
405
406menu "Other I2C Chip support"
407 depends on I2C 10 depends on I2C
408 11
409config SENSORS_DS1337 12config SENSORS_DS1337
@@ -509,7 +112,6 @@ config TPS65010
509 This driver can also be built as a module. If so, the module 112 This driver can also be built as a module. If so, the module
510 will be called tps65010. 113 will be called tps65010.
511 114
512
513config SENSORS_M41T00 115config SENSORS_M41T00
514 tristate "ST M41T00 RTC chip" 116 tristate "ST M41T00 RTC chip"
515 depends on I2C && PPC32 117 depends on I2C && PPC32
@@ -520,13 +122,16 @@ config SENSORS_M41T00
520 will be called m41t00. 122 will be called m41t00.
521 123
522config SENSORS_MAX6875 124config SENSORS_MAX6875
523 tristate "MAXIM MAX6875 Power supply supervisor" 125 tristate "Maxim MAX6875 Power supply supervisor"
524 depends on I2C && EXPERIMENTAL 126 depends on I2C && EXPERIMENTAL
525 help 127 help
526 If you say yes here you get support for the MAX6875 128 If you say yes here you get support for the Maxim MAX6875
527 EEPROM-Programmable, Hex/Quad, Power-Suppy Sequencers/Supervisors. 129 EEPROM-programmable, quad power-supply sequencer/supervisor.
130
131 This provides an interface to program the EEPROM and reset the chip.
528 132
529 This provides a interface to program the EEPROM and reset the chip. 133 This driver also supports the Maxim MAX6874 hex power-supply
134 sequencer/supervisor if found at a compatible address.
530 135
531 This driver can also be built as a module. If so, the module 136 This driver can also be built as a module. If so, the module
532 will be called max6875. 137 will be called max6875.
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index b5e6d2f84f97..a876dd42b860 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -1,52 +1,16 @@
1# 1#
2# Makefile for sensor and "other" I2C chip drivers. 2# Makefile for miscellaneous I2C chip drivers.
3# 3#
4 4
5# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
11obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
12obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
13obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
14obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
15obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
16obj-$(CONFIG_SENSORS_DS1337) += ds1337.o 5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o
17obj-$(CONFIG_SENSORS_DS1374) += ds1374.o 6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o
18obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
19obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 7obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
20obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
21obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
22obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
23obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
24obj-$(CONFIG_SENSORS_IT87) += it87.o
25obj-$(CONFIG_SENSORS_LM63) += lm63.o
26obj-$(CONFIG_SENSORS_LM75) += lm75.o
27obj-$(CONFIG_SENSORS_LM77) += lm77.o
28obj-$(CONFIG_SENSORS_LM78) += lm78.o
29obj-$(CONFIG_SENSORS_LM80) += lm80.o
30obj-$(CONFIG_SENSORS_LM83) += lm83.o
31obj-$(CONFIG_SENSORS_LM85) += lm85.o
32obj-$(CONFIG_SENSORS_LM87) += lm87.o
33obj-$(CONFIG_SENSORS_LM90) += lm90.o
34obj-$(CONFIG_SENSORS_LM92) += lm92.o
35obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
36obj-$(CONFIG_SENSORS_MAX6875) += max6875.o 8obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
37obj-$(CONFIG_SENSORS_M41T00) += m41t00.o 9obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
38obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
39obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o 10obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
40obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o 11obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
41obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
42obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o 13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
43obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
44obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
45obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
46obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
47obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
48obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
49
50obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
51obj-$(CONFIG_TPS65010) += tps65010.o 15obj-$(CONFIG_TPS65010) += tps65010.o
52 16
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index addf0adc24d4..6ea413f6d5e5 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -173,9 +173,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
173 | I2C_FUNC_SMBUS_BYTE)) 173 | I2C_FUNC_SMBUS_BYTE))
174 goto exit; 174 goto exit;
175 175
176 /* OK. For now, we presume we have a valid client. We now create the
177 client structure, even though we cannot fill it completely yet.
178 But it allows us to access eeprom_{read,write}_value. */
179 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 176 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
180 err = -ENOMEM; 177 err = -ENOMEM;
181 goto exit; 178 goto exit;
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 5e463c47bfbc..778d7e12859d 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -207,7 +207,7 @@ m41t00_detach(struct i2c_client *client)
207 int rc; 207 int rc;
208 208
209 if ((rc = i2c_detach_client(client)) == 0) { 209 if ((rc = i2c_detach_client(client)) == 0) {
210 kfree(i2c_get_clientdata(client)); 210 kfree(client);
211 tasklet_kill(&m41t00_tasklet); 211 tasklet_kill(&m41t00_tasklet);
212 } 212 }
213 return rc; 213 return rc;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index fe6b150ec4c2..c4f14d9623c4 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -37,7 +37,8 @@
37#include <linux/i2c-sensor.h> 37#include <linux/i2c-sensor.h>
38 38
39/* Addresses to scan */ 39/* Addresses to scan */
40static unsigned short normal_i2c[] = {0x50, 0x52, I2C_CLIENT_END}; 40/* No address scanned by default, as this could corrupt standard EEPROMS. */
41static unsigned short normal_i2c[] = {I2C_CLIENT_END};
41static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END}; 42static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
42 43
43/* Insmod parameters */ 44/* Insmod parameters */
@@ -369,6 +370,9 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
369 new_client->driver = &max6875_driver; 370 new_client->driver = &max6875_driver;
370 new_client->flags = 0; 371 new_client->flags = 0;
371 372
373 /* Prevent 24RF08 corruption */
374 i2c_smbus_write_quick(new_client, 0);
375
372 /* Setup the user section */ 376 /* Setup the user section */
373 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; 377 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user;
374 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; 378 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES;
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index c0ac01b60039..280e9638c0f8 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -18,7 +18,6 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21#undef DEBUG
22 21
23#include <linux/config.h> 22#include <linux/config.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
@@ -49,11 +48,7 @@
49MODULE_DESCRIPTION("TPS6501x Power Management Driver"); 48MODULE_DESCRIPTION("TPS6501x Power Management Driver");
50MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
51 50
52/* only two addresses possible */ 51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
53#define TPS_BASE 0x48
54static unsigned short normal_i2c[] = {
55 TPS_BASE,
56 I2C_CLIENT_END };
57static unsigned short normal_i2c_range[] = { I2C_CLIENT_END }; 52static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
58 53
59I2C_CLIENT_INSMOD; 54I2C_CLIENT_INSMOD;
@@ -102,7 +97,7 @@ struct tps65010 {
102 u8 chgstatus, regstatus, chgconf; 97 u8 chgstatus, regstatus, chgconf;
103 u8 nmask1, nmask2; 98 u8 nmask1, nmask2;
104 99
105 /* plus four GPIOs, probably used to switch power */ 100 /* not currently tracking GPIO state */
106}; 101};
107 102
108#define POWER_POLL_DELAY msecs_to_jiffies(800) 103#define POWER_POLL_DELAY msecs_to_jiffies(800)
@@ -135,7 +130,7 @@ static void dbg_regstat(char *buf, size_t len, u8 regstatus)
135 (regstatus & TPS_REG_COVER) ? " uncover" : "", 130 (regstatus & TPS_REG_COVER) ? " uncover" : "",
136 (regstatus & TPS_REG_UVLO) ? " UVLO" : "", 131 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
137 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "", 132 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
138 (regstatus & TPS_REG_PG_LD02) ? " ld01_bad" : "", 133 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
139 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "", 134 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
140 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "", 135 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
141 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : ""); 136 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
@@ -143,7 +138,7 @@ static void dbg_regstat(char *buf, size_t len, u8 regstatus)
143 138
144static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig) 139static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
145{ 140{
146 char *hibit; 141 const char *hibit;
147 142
148 if (por) 143 if (por)
149 hibit = (chgconfig & TPS_CHARGE_POR) 144 hibit = (chgconfig & TPS_CHARGE_POR)
@@ -295,7 +290,7 @@ static int dbg_show(struct seq_file *s, void *_)
295 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2); 290 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
296 291
297 for (i = 0; i < 4; i++) { 292 for (i = 0; i < 4; i++) {
298 if (value & (1 << (4 +i))) 293 if (value & (1 << (4 + i)))
299 seq_printf(s, " gpio%d-out %s\n", i + 1, 294 seq_printf(s, " gpio%d-out %s\n", i + 1,
300 (value & (1 << i)) ? "low" : "hi "); 295 (value & (1 << i)) ? "low" : "hi ");
301 else 296 else
@@ -481,7 +476,7 @@ static int __exit tps65010_detach_client(struct i2c_client *client)
481 debugfs_remove(tps->file); 476 debugfs_remove(tps->file);
482 if (i2c_detach_client(client) == 0) 477 if (i2c_detach_client(client) == 0)
483 kfree(tps); 478 kfree(tps);
484 the_tps = 0; 479 the_tps = NULL;
485 return 0; 480 return 0;
486} 481}
487 482
@@ -514,7 +509,6 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
514 INIT_WORK(&tps->work, tps65010_work, tps); 509 INIT_WORK(&tps->work, tps65010_work, tps);
515 tps->irq = -1; 510 tps->irq = -1;
516 tps->client.addr = address; 511 tps->client.addr = address;
517 i2c_set_clientdata(&tps->client, tps);
518 tps->client.adapter = bus; 512 tps->client.adapter = bus;
519 tps->client.driver = &tps65010_driver; 513 tps->client.driver = &tps65010_driver;
520 strlcpy(tps->client.name, DRIVER_NAME, I2C_NAME_SIZE); 514 strlcpy(tps->client.name, DRIVER_NAME, I2C_NAME_SIZE);
@@ -523,9 +517,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
523 if (status < 0) { 517 if (status < 0) {
524 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", 518 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
525 DRIVER_NAME, address, status); 519 DRIVER_NAME, address, status);
526fail1: 520 goto fail1;
527 kfree(tps);
528 return 0;
529 } 521 }
530 522
531#ifdef CONFIG_ARM 523#ifdef CONFIG_ARM
@@ -535,7 +527,7 @@ fail1:
535 tps->irq = OMAP_GPIO_IRQ(58); 527 tps->irq = OMAP_GPIO_IRQ(58);
536 omap_request_gpio(58); 528 omap_request_gpio(58);
537 omap_set_gpio_direction(58, 1); 529 omap_set_gpio_direction(58, 1);
538 omap_set_gpio_edge_ctrl(58, OMAP_GPIO_FALLING_EDGE); 530 set_irq_type(tps->irq, IRQT_FALLING);
539 } 531 }
540 if (machine_is_omap_osk()) { 532 if (machine_is_omap_osk()) {
541 tps->model = TPS65010; 533 tps->model = TPS65010;
@@ -543,7 +535,7 @@ fail1:
543 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1)); 535 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1));
544 omap_request_gpio(OMAP_MPUIO(1)); 536 omap_request_gpio(OMAP_MPUIO(1));
545 omap_set_gpio_direction(OMAP_MPUIO(1), 1); 537 omap_set_gpio_direction(OMAP_MPUIO(1), 1);
546 omap_set_gpio_edge_ctrl(OMAP_MPUIO(1), OMAP_GPIO_FALLING_EDGE); 538 set_irq_type(tps->irq, IRQT_FALLING);
547 } 539 }
548 if (machine_is_omap_h3()) { 540 if (machine_is_omap_h3()) {
549 tps->model = TPS65013; 541 tps->model = TPS65013;
@@ -633,6 +625,9 @@ fail1:
633 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, 625 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
634 tps, DEBUG_FOPS); 626 tps, DEBUG_FOPS);
635 return 0; 627 return 0;
628fail1:
629 kfree(tps);
630 return 0;
636} 631}
637 632
638static int __init tps65010_scan_bus(struct i2c_adapter *bus) 633static int __init tps65010_scan_bus(struct i2c_adapter *bus)
@@ -645,7 +640,6 @@ static int __init tps65010_scan_bus(struct i2c_adapter *bus)
645static struct i2c_driver tps65010_driver = { 640static struct i2c_driver tps65010_driver = {
646 .owner = THIS_MODULE, 641 .owner = THIS_MODULE,
647 .name = "tps65010", 642 .name = "tps65010",
648 .id = 888, /* FIXME assign "official" value */
649 .flags = I2C_DF_NOTIFY, 643 .flags = I2C_DF_NOTIFY,
650 .attach_adapter = tps65010_scan_bus, 644 .attach_adapter = tps65010_scan_bus,
651 .detach_client = __exit_p(tps65010_detach_client), 645 .detach_client = __exit_p(tps65010_detach_client),
@@ -744,7 +738,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
744 if (!the_tps) 738 if (!the_tps)
745 return -ENODEV; 739 return -ENODEV;
746 740
747 if(led == LED1) 741 if (led == LED1)
748 offs = 0; 742 offs = 0;
749 else { 743 else {
750 offs = 2; 744 offs = 2;
@@ -753,11 +747,13 @@ int tps65010_set_led(unsigned led, unsigned mode)
753 747
754 down(&the_tps->lock); 748 down(&the_tps->lock);
755 749
756 dev_dbg (&the_tps->client.dev, "led%i_on 0x%02x\n", led, 750 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
757 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs)); 751 i2c_smbus_read_byte_data(&the_tps->client,
752 TPS_LED1_ON + offs));
758 753
759 dev_dbg (&the_tps->client.dev, "led%i_per 0x%02x\n", led, 754 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
760 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_PER + offs)); 755 i2c_smbus_read_byte_data(&the_tps->client,
756 TPS_LED1_PER + offs));
761 757
762 switch (mode) { 758 switch (mode) {
763 case OFF: 759 case OFF:
@@ -773,7 +769,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
773 led_per = 0x08 | (1 << 7); 769 led_per = 0x08 | (1 << 7);
774 break; 770 break;
775 default: 771 default:
776 printk(KERN_ERR "%s: Wrong mode parameter for tps65010_set_led()\n", 772 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
777 DRIVER_NAME); 773 DRIVER_NAME);
778 up(&the_tps->lock); 774 up(&the_tps->lock);
779 return -EINVAL; 775 return -EINVAL;
@@ -789,7 +785,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
789 return status; 785 return status;
790 } 786 }
791 787
792 dev_dbg (&the_tps->client.dev, "led%i_on 0x%02x\n", led, 788 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
793 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs)); 789 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs));
794 790
795 status = i2c_smbus_write_byte_data(&the_tps->client, 791 status = i2c_smbus_write_byte_data(&the_tps->client,
@@ -802,8 +798,9 @@ int tps65010_set_led(unsigned led, unsigned mode)
802 return status; 798 return status;
803 } 799 }
804 800
805 dev_dbg (&the_tps->client.dev, "led%i_per 0x%02x\n", led, 801 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
806 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_PER + offs)); 802 i2c_smbus_read_byte_data(&the_tps->client,
803 TPS_LED1_PER + offs));
807 804
808 up(&the_tps->lock); 805 up(&the_tps->lock);
809 806
@@ -874,7 +871,7 @@ int tps65010_set_low_pwr(unsigned mode)
874 871
875 if (status != 0) 872 if (status != 0)
876 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n", 873 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
877 DRIVER_NAME); 874 DRIVER_NAME);
878 else 875 else
879 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, 876 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
880 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1)); 877 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
@@ -900,14 +897,14 @@ int tps65010_config_vregs1(unsigned value)
900 down(&the_tps->lock); 897 down(&the_tps->lock);
901 898
902 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 899 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
903 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 900 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
904 901
905 status = i2c_smbus_write_byte_data(&the_tps->client, 902 status = i2c_smbus_write_byte_data(&the_tps->client,
906 TPS_VREGS1, value); 903 TPS_VREGS1, value);
907 904
908 if (status != 0) 905 if (status != 0)
909 printk(KERN_ERR "%s: Failed to write vregs1 register\n", 906 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
910 DRIVER_NAME); 907 DRIVER_NAME);
911 else 908 else
912 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 909 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
913 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 910 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
@@ -1009,7 +1006,7 @@ static int __init tps_init(void)
1009 msleep(10); 1006 msleep(10);
1010 } 1007 }
1011 1008
1012#if defined(CONFIG_ARM) 1009#ifdef CONFIG_ARM
1013 if (machine_is_omap_osk()) { 1010 if (machine_is_omap_osk()) {
1014 1011
1015 // FIXME: More should be placed in the initialization code 1012 // FIXME: More should be placed in the initialization code
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 51ce268998cd..4fd4f52c8e9b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -156,7 +156,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
156 goto out_unlock; 156 goto out_unlock;
157 } 157 }
158 158
159 res = idr_get_new(&i2c_adapter_idr, NULL, &id); 159 res = idr_get_new(&i2c_adapter_idr, adap, &id);
160 if (res < 0) { 160 if (res < 0) {
161 if (res == -EAGAIN) 161 if (res == -EAGAIN)
162 res = -ENOMEM; 162 res = -ENOMEM;
@@ -765,20 +765,15 @@ int i2c_adapter_id(struct i2c_adapter *adap)
765 765
766struct i2c_adapter* i2c_get_adapter(int id) 766struct i2c_adapter* i2c_get_adapter(int id)
767{ 767{
768 struct list_head *item;
769 struct i2c_adapter *adapter; 768 struct i2c_adapter *adapter;
770 769
771 down(&core_lists); 770 down(&core_lists);
772 list_for_each(item,&adapters) { 771 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
773 adapter = list_entry(item, struct i2c_adapter, list); 772 if (adapter && !try_module_get(adapter->owner))
774 if (id == adapter->nr && 773 adapter = NULL;
775 try_module_get(adapter->owner)) { 774
776 up(&core_lists);
777 return adapter;
778 }
779 }
780 up(&core_lists); 775 up(&core_lists);
781 return NULL; 776 return adapter;
782} 777}
783 778
784void i2c_put_adapter(struct i2c_adapter *adap) 779void i2c_put_adapter(struct i2c_adapter *adap)
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 0273f124a4f7..5f33df47aa74 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -606,6 +606,12 @@ config BLK_DEV_IT8172
606 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the 606 <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the
607 board at <http://www.mvista.com/partners/semiconductor/ite.html>. 607 board at <http://www.mvista.com/partners/semiconductor/ite.html>.
608 608
609config BLK_DEV_IT821X
610 tristate "IT821X IDE support"
611 help
612 This driver adds support for the ITE 8211 IDE controller and the
613 IT 8212 IDE RAID controller in both RAID and pass-through mode.
614
609config BLK_DEV_NS87415 615config BLK_DEV_NS87415
610 tristate "NS87415 chipset support" 616 tristate "NS87415 chipset support"
611 help 617 help
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 5be8ad6dc9ed..cca9c075966d 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -20,7 +20,6 @@ ide-core-$(CONFIG_BLK_DEV_CMD640) += pci/cmd640.o
20# Core IDE code - must come before legacy 20# Core IDE code - must come before legacy
21ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 21ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
22ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o 22ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
23ide-core-$(CONFIG_BLK_DEV_IDE_TCQ) += ide-tcq.o
24ide-core-$(CONFIG_PROC_FS) += ide-proc.o 23ide-core-$(CONFIG_PROC_FS) += ide-proc.o
25ide-core-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 24ide-core-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
26 25
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 0a31cfda08a0..74af7e074868 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -431,7 +431,7 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
431#if VERBOSE_IDE_CD_ERRORS 431#if VERBOSE_IDE_CD_ERRORS
432 { 432 {
433 int i; 433 int i;
434 const char *s; 434 const char *s = "bad sense key!";
435 char buf[80]; 435 char buf[80];
436 436
437 printk ("ATAPI device %s:\n", drive->name); 437 printk ("ATAPI device %s:\n", drive->name);
@@ -446,8 +446,6 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
446 446
447 if (sense->sense_key < ARY_LEN(sense_key_texts)) 447 if (sense->sense_key < ARY_LEN(sense_key_texts))
448 s = sense_key_texts[sense->sense_key]; 448 s = sense_key_texts[sense->sense_key];
449 else
450 s = "bad sense key!";
451 449
452 printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key); 450 printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
453 451
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index d6f934886b04..f9c1acb4ed6a 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -119,6 +119,10 @@ static int lba_capacity_is_ok (struct hd_driveid *id)
119{ 119{
120 unsigned long lba_sects, chs_sects, head, tail; 120 unsigned long lba_sects, chs_sects, head, tail;
121 121
122 /* No non-LBA info .. so valid! */
123 if (id->cyls == 0)
124 return 1;
125
122 /* 126 /*
123 * The ATA spec tells large drives to return 127 * The ATA spec tells large drives to return
124 * C/H/S = 16383/16/63 independent of their size. 128 * C/H/S = 16383/16/63 independent of their size.
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 2d2eefb610dd..1e1531334c25 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -132,7 +132,6 @@ static const struct drive_list_entry drive_blacklist [] = {
132 { "SAMSUNG CD-ROM SC-148C", "ALL" }, 132 { "SAMSUNG CD-ROM SC-148C", "ALL" },
133 { "SAMSUNG CD-ROM SC", "ALL" }, 133 { "SAMSUNG CD-ROM SC", "ALL" },
134 { "SanDisk SDP3B-64" , "ALL" }, 134 { "SanDisk SDP3B-64" , "ALL" },
135 { "SAMSUNG CD-ROM SN-124", "ALL" },
136 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" }, 135 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" },
137 { "_NEC DV5800A", "ALL" }, 136 { "_NEC DV5800A", "ALL" },
138 { NULL , NULL } 137 { NULL , NULL }
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 53024942a7eb..b443b04a4c5a 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -1181,7 +1181,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1181 pre_reset(drive); 1181 pre_reset(drive);
1182 SELECT_DRIVE(drive); 1182 SELECT_DRIVE(drive);
1183 udelay (20); 1183 udelay (20);
1184 hwif->OUTB(WIN_SRST, IDE_COMMAND_REG); 1184 hwif->OUTBSYNC(drive, WIN_SRST, IDE_COMMAND_REG);
1185 ndelay(400);
1185 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; 1186 hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
1186 hwgroup->polling = 1; 1187 hwgroup->polling = 1;
1187 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 1188 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 6806d407e9c1..b09a6537c7a8 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -487,8 +487,7 @@ static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
487 u8 err = 0; 487 u8 err = 0;
488 488
489 local_irq_set(flags); 489 local_irq_set(flags);
490 printk("%s: %s: status=0x%02x", drive->name, msg, stat); 490 printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
491 printk(" { ");
492 if (stat & BUSY_STAT) 491 if (stat & BUSY_STAT)
493 printk("Busy "); 492 printk("Busy ");
494 else { 493 else {
@@ -500,15 +499,13 @@ static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
500 if (stat & INDEX_STAT) printk("Index "); 499 if (stat & INDEX_STAT) printk("Index ");
501 if (stat & ERR_STAT) printk("Error "); 500 if (stat & ERR_STAT) printk("Error ");
502 } 501 }
503 printk("}"); 502 printk("}\n");
504 printk("\n");
505 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) { 503 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
506 err = hwif->INB(IDE_ERROR_REG); 504 err = hwif->INB(IDE_ERROR_REG);
507 printk("%s: %s: error=0x%02x", drive->name, msg, err); 505 printk("%s: %s: error=0x%02x { ", drive->name, msg, err);
508 printk(" { ");
509 if (err & ABRT_ERR) printk("DriveStatusError "); 506 if (err & ABRT_ERR) printk("DriveStatusError ");
510 if (err & ICRC_ERR) 507 if (err & ICRC_ERR)
511 printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector"); 508 printk((err & ABRT_ERR) ? "BadCRC " : "BadSector ");
512 if (err & ECC_ERR) printk("UncorrectableError "); 509 if (err & ECC_ERR) printk("UncorrectableError ");
513 if (err & ID_ERR) printk("SectorIdNotFound "); 510 if (err & ID_ERR) printk("SectorIdNotFound ");
514 if (err & TRK0_ERR) printk("TrackZeroNotFound "); 511 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
@@ -546,8 +543,8 @@ static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
546 printk(", sector=%llu", 543 printk(", sector=%llu",
547 (unsigned long long)HWGROUP(drive)->rq->sector); 544 (unsigned long long)HWGROUP(drive)->rq->sector);
548 } 545 }
546 printk("\n");
549 } 547 }
550 printk("\n");
551 ide_dump_opcode(drive); 548 ide_dump_opcode(drive);
552 local_irq_restore(flags); 549 local_irq_restore(flags);
553 return err; 550 return err;
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index e884cd4b22fd..242029c9c0ca 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -156,11 +156,13 @@ else \
156 156
157 157
158#if (HD_DELAY > 0) 158#if (HD_DELAY > 0)
159
160#include <asm/i8253.h>
161
159unsigned long last_req; 162unsigned long last_req;
160 163
161unsigned long read_timer(void) 164unsigned long read_timer(void)
162{ 165{
163 extern spinlock_t i8253_lock;
164 unsigned long t, flags; 166 unsigned long t, flags;
165 int i; 167 int i;
166 168
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index e20327e54b1a..aac59751e1b4 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -46,7 +46,6 @@
46#include <asm/io.h> 46#include <asm/io.h>
47#include <asm/system.h> 47#include <asm/system.h>
48 48
49#include <pcmcia/version.h>
50#include <pcmcia/cs_types.h> 49#include <pcmcia/cs_types.h>
51#include <pcmcia/cs.h> 50#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
@@ -134,11 +133,6 @@ static dev_link_t *ide_attach(void)
134 link->next = dev_list; 133 link->next = dev_list;
135 dev_list = link; 134 dev_list = link;
136 client_reg.dev_info = &dev_info; 135 client_reg.dev_info = &dev_info;
137 client_reg.EventMask =
138 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
139 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
140 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
141 client_reg.event_handler = &ide_event;
142 client_reg.Version = 0x0210; 136 client_reg.Version = 0x0210;
143 client_reg.event_callback_args.client_data = link; 137 client_reg.event_callback_args.client_data = link;
144 ret = pcmcia_register_client(&link->handle, &client_reg); 138 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -457,13 +451,49 @@ int ide_event(event_t event, int priority,
457 return 0; 451 return 0;
458} /* ide_event */ 452} /* ide_event */
459 453
454static struct pcmcia_device_id ide_ids[] = {
455 PCMCIA_DEVICE_FUNC_ID(4),
456 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
457 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
458 PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001),
459 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),
460 PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0),
461 PCMCIA_DEVICE_PROD_ID123("CDROM", "IDE", "MCD-601p", 0x1b9179ca, 0xede88951, 0x0d902f74),
462 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "IDE CARD", "F1", 0x281f1c5d, 0x1907960c, 0xf7fde8b9),
463 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "CD-ROM", 0x78f308dc, 0x66536591),
464 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "PnPIDE", 0x78f308dc, 0x0c694728),
465 PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591),
466 PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4),
467 PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde),
468 PCMCIA_DEVICE_PROD_ID12("EXP", "CD", 0x6f58c983, 0xaae5994f),
469 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
470 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
471 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
472 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
473 PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b),
474 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149),
475 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674),
476 PCMCIA_DEVICE_PROD_ID12("LOOKMEET", "CBIDE2 ", 0xe37be2b5, 0x8671043b),
477 PCMCIA_DEVICE_PROD_ID12(" ", "NinjaATA-", 0x3b6e20c8, 0xebe0bd79),
478 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "CD-ROM", 0x281f1c5d, 0x66536591),
479 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "PnPIDE", 0x281f1c5d, 0x0c694728),
480 PCMCIA_DEVICE_PROD_ID12("SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", 0x4a3f0ba0, 0x322560e1),
481 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
482 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
483 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
484 PCMCIA_DEVICE_NULL,
485};
486MODULE_DEVICE_TABLE(pcmcia, ide_ids);
487
460static struct pcmcia_driver ide_cs_driver = { 488static struct pcmcia_driver ide_cs_driver = {
461 .owner = THIS_MODULE, 489 .owner = THIS_MODULE,
462 .drv = { 490 .drv = {
463 .name = "ide-cs", 491 .name = "ide-cs",
464 }, 492 },
465 .attach = ide_attach, 493 .attach = ide_attach,
494 .event = ide_event,
466 .detach = ide_detach, 495 .detach = ide_detach,
496 .id_table = ide_ids,
467}; 497};
468 498
469static int __init init_ide_cs(void) 499static int __init init_ide_cs(void)
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile
index 55e6e553e497..af46226c1796 100644
--- a/drivers/ide/pci/Makefile
+++ b/drivers/ide/pci/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_BLK_DEV_HPT34X) += hpt34x.o
12obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o 12obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o
13#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o 13#obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o
14obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o 14obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o
15obj-$(CONFIG_BLK_DEV_IT821X) += it821x.o
15obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o 16obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o
16obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o 17obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o
17obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o 18obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 67efb38a9f6c..6cf49394a80f 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -583,7 +583,7 @@ static int ali15x3_dma_setup(ide_drive_t *drive)
583 * appropriate also sets up the 1533 southbridge. 583 * appropriate also sets up the 1533 southbridge.
584 */ 584 */
585 585
586static unsigned int __init init_chipset_ali15x3 (struct pci_dev *dev, const char *name) 586static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const char *name)
587{ 587{
588 unsigned long flags; 588 unsigned long flags;
589 u8 tmpbyte; 589 u8 tmpbyte;
@@ -677,7 +677,7 @@ static unsigned int __init init_chipset_ali15x3 (struct pci_dev *dev, const char
677 * FIXME: frobs bits that are not defined on newer ALi devicea 677 * FIXME: frobs bits that are not defined on newer ALi devicea
678 */ 678 */
679 679
680static unsigned int __init ata66_ali15x3 (ide_hwif_t *hwif) 680static unsigned int __devinit ata66_ali15x3 (ide_hwif_t *hwif)
681{ 681{
682 struct pci_dev *dev = hwif->pci_dev; 682 struct pci_dev *dev = hwif->pci_dev;
683 unsigned int ata66 = 0; 683 unsigned int ata66 = 0;
@@ -748,7 +748,7 @@ static unsigned int __init ata66_ali15x3 (ide_hwif_t *hwif)
748 * Initialize the IDE structure side of the ALi 15x3 driver. 748 * Initialize the IDE structure side of the ALi 15x3 driver.
749 */ 749 */
750 750
751static void __init init_hwif_common_ali15x3 (ide_hwif_t *hwif) 751static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
752{ 752{
753 hwif->autodma = 0; 753 hwif->autodma = 0;
754 hwif->tuneproc = &ali15x3_tune_drive; 754 hwif->tuneproc = &ali15x3_tune_drive;
@@ -794,7 +794,7 @@ static void __init init_hwif_common_ali15x3 (ide_hwif_t *hwif)
794 * Sparc systems 794 * Sparc systems
795 */ 795 */
796 796
797static void __init init_hwif_ali15x3 (ide_hwif_t *hwif) 797static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
798{ 798{
799 u8 ideic, inmir; 799 u8 ideic, inmir;
800 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, 800 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
@@ -847,7 +847,7 @@ static void __init init_hwif_ali15x3 (ide_hwif_t *hwif)
847 * the actual work. 847 * the actual work.
848 */ 848 */
849 849
850static void __init init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase) 850static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
851{ 851{
852 if (m5229_revision < 0x20) 852 if (m5229_revision < 0x20)
853 return; 853 return;
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 4e0f13d1d060..844a6c9fb949 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -73,6 +73,7 @@ static struct amd_ide_chip {
73 { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, 0x50, AMD_UDMA_133 }, 73 { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, 0x50, AMD_UDMA_133 },
74 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, 0x50, AMD_UDMA_133 }, 74 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, 0x50, AMD_UDMA_133 },
75 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, 0x50, AMD_UDMA_133 }, 75 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, 0x50, AMD_UDMA_133 },
76 { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE, 0x50, AMD_UDMA_133 },
76 { 0 } 77 { 0 }
77}; 78};
78 79
@@ -309,7 +310,7 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive)
309 * and initialize its drive independent registers. 310 * and initialize its drive independent registers.
310 */ 311 */
311 312
312static unsigned int __init init_chipset_amd74xx(struct pci_dev *dev, const char *name) 313static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const char *name)
313{ 314{
314 unsigned char t; 315 unsigned char t;
315 unsigned int u; 316 unsigned int u;
@@ -413,7 +414,7 @@ static unsigned int __init init_chipset_amd74xx(struct pci_dev *dev, const char
413 return dev->irq; 414 return dev->irq;
414} 415}
415 416
416static void __init init_hwif_amd74xx(ide_hwif_t *hwif) 417static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
417{ 418{
418 int i; 419 int i;
419 420
@@ -489,6 +490,7 @@ static ide_pci_device_t amd74xx_chipsets[] __devinitdata = {
489 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804"), 490 /* 13 */ DECLARE_NV_DEV("NFORCE-CK804"),
490 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04"), 491 /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04"),
491 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51"), 492 /* 15 */ DECLARE_NV_DEV("NFORCE-MCP51"),
493 /* 16 */ DECLARE_NV_DEV("NFORCE-MCP55"),
492}; 494};
493 495
494static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id) 496static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id)
@@ -524,6 +526,7 @@ static struct pci_device_id amd74xx_pci_tbl[] = {
524 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 }, 526 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
525 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 }, 527 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
526 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15 }, 528 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15 },
529 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16 },
527 { 0, }, 530 { 0, },
528}; 531};
529MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); 532MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 0381961db263..09269e574b3e 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -217,7 +217,7 @@ static int cs5530_config_dma (ide_drive_t *drive)
217 * Initialize the cs5530 bridge for reliable IDE DMA operation. 217 * Initialize the cs5530 bridge for reliable IDE DMA operation.
218 */ 218 */
219 219
220static unsigned int __init init_chipset_cs5530 (struct pci_dev *dev, const char *name) 220static unsigned int __devinit init_chipset_cs5530 (struct pci_dev *dev, const char *name)
221{ 221{
222 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL; 222 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL;
223 unsigned long flags; 223 unsigned long flags;
@@ -308,7 +308,7 @@ static unsigned int __init init_chipset_cs5530 (struct pci_dev *dev, const char
308 * performs channel-specific pre-initialization before drive probing. 308 * performs channel-specific pre-initialization before drive probing.
309 */ 309 */
310 310
311static void __init init_hwif_cs5530 (ide_hwif_t *hwif) 311static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
312{ 312{
313 unsigned long basereg; 313 unsigned long basereg;
314 u32 d0_timings; 314 u32 d0_timings;
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 80d67e99ccb5..5a33513f3dd1 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -391,7 +391,7 @@ static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio)
391/* 391/*
392 * this function is called during init and is used to setup the cy82c693 chip 392 * this function is called during init and is used to setup the cy82c693 chip
393 */ 393 */
394static unsigned int __init init_chipset_cy82c693(struct pci_dev *dev, const char *name) 394static unsigned int __devinit init_chipset_cy82c693(struct pci_dev *dev, const char *name)
395{ 395{
396 if (PCI_FUNC(dev->devfn) != 1) 396 if (PCI_FUNC(dev->devfn) != 1)
397 return 0; 397 return 0;
@@ -443,7 +443,7 @@ static unsigned int __init init_chipset_cy82c693(struct pci_dev *dev, const char
443/* 443/*
444 * the init function - called for each ide channel once 444 * the init function - called for each ide channel once
445 */ 445 */
446static void __init init_hwif_cy82c693(ide_hwif_t *hwif) 446static void __devinit init_hwif_cy82c693(ide_hwif_t *hwif)
447{ 447{
448 hwif->autodma = 0; 448 hwif->autodma = 0;
449 449
@@ -467,9 +467,9 @@ static void __init init_hwif_cy82c693(ide_hwif_t *hwif)
467 hwif->drives[1].autodma = hwif->autodma; 467 hwif->drives[1].autodma = hwif->autodma;
468} 468}
469 469
470static __initdata ide_hwif_t *primary; 470static __devinitdata ide_hwif_t *primary;
471 471
472void __init init_iops_cy82c693(ide_hwif_t *hwif) 472void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
473{ 473{
474 if (PCI_FUNC(hwif->pci_dev->devfn) == 1) 474 if (PCI_FUNC(hwif->pci_dev->devfn) == 1)
475 primary = hwif; 475 primary = hwif;
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 4565cc311ff3..da46577380f3 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -39,6 +39,17 @@
39 39
40#include <asm/io.h> 40#include <asm/io.h>
41 41
42static int ide_generic_all; /* Set to claim all devices */
43
44static int __init ide_generic_all_on(char *unused)
45{
46 ide_generic_all = 1;
47 printk(KERN_INFO "IDE generic will claim all unknown PCI IDE storage controllers.\n");
48 return 1;
49}
50
51__setup("all-generic-ide", ide_generic_all_on);
52
42static void __devinit init_hwif_generic (ide_hwif_t *hwif) 53static void __devinit init_hwif_generic (ide_hwif_t *hwif)
43{ 54{
44 switch(hwif->pci_dev->device) { 55 switch(hwif->pci_dev->device) {
@@ -78,79 +89,85 @@ static void __devinit init_hwif_generic (ide_hwif_t *hwif)
78 89
79static ide_pci_device_t generic_chipsets[] __devinitdata = { 90static ide_pci_device_t generic_chipsets[] __devinitdata = {
80 { /* 0 */ 91 { /* 0 */
92 .name = "Unknown",
93 .init_hwif = init_hwif_generic,
94 .channels = 2,
95 .autodma = AUTODMA,
96 .bootable = ON_BOARD,
97 },{ /* 1 */
81 .name = "NS87410", 98 .name = "NS87410",
82 .init_hwif = init_hwif_generic, 99 .init_hwif = init_hwif_generic,
83 .channels = 2, 100 .channels = 2,
84 .autodma = AUTODMA, 101 .autodma = AUTODMA,
85 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, 102 .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}},
86 .bootable = ON_BOARD, 103 .bootable = ON_BOARD,
87 },{ /* 1 */ 104 },{ /* 2 */
88 .name = "SAMURAI", 105 .name = "SAMURAI",
89 .init_hwif = init_hwif_generic, 106 .init_hwif = init_hwif_generic,
90 .channels = 2, 107 .channels = 2,
91 .autodma = AUTODMA, 108 .autodma = AUTODMA,
92 .bootable = ON_BOARD, 109 .bootable = ON_BOARD,
93 },{ /* 2 */ 110 },{ /* 3 */
94 .name = "HT6565", 111 .name = "HT6565",
95 .init_hwif = init_hwif_generic, 112 .init_hwif = init_hwif_generic,
96 .channels = 2, 113 .channels = 2,
97 .autodma = AUTODMA, 114 .autodma = AUTODMA,
98 .bootable = ON_BOARD, 115 .bootable = ON_BOARD,
99 },{ /* 3 */ 116 },{ /* 4 */
100 .name = "UM8673F", 117 .name = "UM8673F",
101 .init_hwif = init_hwif_generic, 118 .init_hwif = init_hwif_generic,
102 .channels = 2, 119 .channels = 2,
103 .autodma = NODMA, 120 .autodma = NODMA,
104 .bootable = ON_BOARD, 121 .bootable = ON_BOARD,
105 },{ /* 4 */ 122 },{ /* 5 */
106 .name = "UM8886A", 123 .name = "UM8886A",
107 .init_hwif = init_hwif_generic, 124 .init_hwif = init_hwif_generic,
108 .channels = 2, 125 .channels = 2,
109 .autodma = NODMA, 126 .autodma = NODMA,
110 .bootable = ON_BOARD, 127 .bootable = ON_BOARD,
111 },{ /* 5 */ 128 },{ /* 6 */
112 .name = "UM8886BF", 129 .name = "UM8886BF",
113 .init_hwif = init_hwif_generic, 130 .init_hwif = init_hwif_generic,
114 .channels = 2, 131 .channels = 2,
115 .autodma = NODMA, 132 .autodma = NODMA,
116 .bootable = ON_BOARD, 133 .bootable = ON_BOARD,
117 },{ /* 6 */ 134 },{ /* 7 */
118 .name = "HINT_IDE", 135 .name = "HINT_IDE",
119 .init_hwif = init_hwif_generic, 136 .init_hwif = init_hwif_generic,
120 .channels = 2, 137 .channels = 2,
121 .autodma = AUTODMA, 138 .autodma = AUTODMA,
122 .bootable = ON_BOARD, 139 .bootable = ON_BOARD,
123 },{ /* 7 */ 140 },{ /* 8 */
124 .name = "VIA_IDE", 141 .name = "VIA_IDE",
125 .init_hwif = init_hwif_generic, 142 .init_hwif = init_hwif_generic,
126 .channels = 2, 143 .channels = 2,
127 .autodma = NOAUTODMA, 144 .autodma = NOAUTODMA,
128 .bootable = ON_BOARD, 145 .bootable = ON_BOARD,
129 },{ /* 8 */ 146 },{ /* 9 */
130 .name = "OPTI621V", 147 .name = "OPTI621V",
131 .init_hwif = init_hwif_generic, 148 .init_hwif = init_hwif_generic,
132 .channels = 2, 149 .channels = 2,
133 .autodma = NOAUTODMA, 150 .autodma = NOAUTODMA,
134 .bootable = ON_BOARD, 151 .bootable = ON_BOARD,
135 },{ /* 9 */ 152 },{ /* 10 */
136 .name = "VIA8237SATA", 153 .name = "VIA8237SATA",
137 .init_hwif = init_hwif_generic, 154 .init_hwif = init_hwif_generic,
138 .channels = 2, 155 .channels = 2,
139 .autodma = AUTODMA, 156 .autodma = AUTODMA,
140 .bootable = OFF_BOARD, 157 .bootable = OFF_BOARD,
141 },{ /* 10 */ 158 },{ /* 11 */
142 .name = "Piccolo0102", 159 .name = "Piccolo0102",
143 .init_hwif = init_hwif_generic, 160 .init_hwif = init_hwif_generic,
144 .channels = 2, 161 .channels = 2,
145 .autodma = NOAUTODMA, 162 .autodma = NOAUTODMA,
146 .bootable = ON_BOARD, 163 .bootable = ON_BOARD,
147 },{ /* 11 */ 164 },{ /* 12 */
148 .name = "Piccolo0103", 165 .name = "Piccolo0103",
149 .init_hwif = init_hwif_generic, 166 .init_hwif = init_hwif_generic,
150 .channels = 2, 167 .channels = 2,
151 .autodma = NOAUTODMA, 168 .autodma = NOAUTODMA,
152 .bootable = ON_BOARD, 169 .bootable = ON_BOARD,
153 },{ /* 12 */ 170 },{ /* 13 */
154 .name = "Piccolo0105", 171 .name = "Piccolo0105",
155 .init_hwif = init_hwif_generic, 172 .init_hwif = init_hwif_generic,
156 .channels = 2, 173 .channels = 2,
@@ -174,6 +191,10 @@ static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_devi
174 u16 command; 191 u16 command;
175 int ret = -ENODEV; 192 int ret = -ENODEV;
176 193
194 /* Don't use the generic entry unless instructed to do so */
195 if (id->driver_data == 0 && ide_generic_all == 0)
196 goto out;
197
177 if (dev->vendor == PCI_VENDOR_ID_UMC && 198 if (dev->vendor == PCI_VENDOR_ID_UMC &&
178 dev->device == PCI_DEVICE_ID_UMC_UM8886A && 199 dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
179 (!(PCI_FUNC(dev->devfn) & 1))) 200 (!(PCI_FUNC(dev->devfn) & 1)))
@@ -195,21 +216,23 @@ out:
195} 216}
196 217
197static struct pci_device_id generic_pci_tbl[] = { 218static struct pci_device_id generic_pci_tbl[] = {
198 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 219 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
199 { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, 220 { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
200 { PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, 221 { PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
201 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, 222 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
202 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, 223 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
203 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, 224 { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6},
204 { PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, 225 { PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7},
205 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7}, 226 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8},
206 { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8}, 227 { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9},
207#ifdef CONFIG_BLK_DEV_IDE_SATA 228#ifdef CONFIG_BLK_DEV_IDE_SATA
208 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9}, 229 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10},
209#endif 230#endif
210 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10}, 231 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11},
211 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11}, 232 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12},
212 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, 233 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13},
234 /* Must come last. If you add entries adjust this table appropriately and the init_one code */
235 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0},
213 { 0, }, 236 { 0, },
214}; 237};
215MODULE_DEVICE_TABLE(pci, generic_pci_tbl); 238MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index c8ee0b8c0292..7b64db10d1b0 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -10,6 +10,11 @@
10 * donation of an ABit BP6 mainboard, processor, and memory acellerated 10 * donation of an ABit BP6 mainboard, processor, and memory acellerated
11 * development and support. 11 * development and support.
12 * 12 *
13 *
14 * Highpoint have their own driver (source except for the raid part)
15 * available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz
16 * This may be useful to anyone wanting to work on the mainstream hpt IDE.
17 *
13 * Note that final HPT370 support was done by force extraction of GPL. 18 * Note that final HPT370 support was done by force extraction of GPL.
14 * 19 *
15 * - add function for getting/setting power status of drive 20 * - add function for getting/setting power status of drive
@@ -446,44 +451,29 @@ static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = {
446#define F_LOW_PCI_50 0x2d 451#define F_LOW_PCI_50 0x2d
447#define F_LOW_PCI_66 0x42 452#define F_LOW_PCI_66 0x42
448 453
449/* FIXME: compare with driver's code before removing */ 454/*
450#if 0 455 * Hold all the highpoint quirks and revision information in one
451 if (hpt_minimum_revision(dev, 3)) { 456 * place.
452 u8 cbl; 457 */
453 cbl = inb(iobase + 0x7b);
454 outb(cbl | 1, iobase + 0x7b);
455 outb(cbl & ~1, iobase + 0x7b);
456 cbl = inb(iobase + 0x7a);
457 p += sprintf(p, "Cable: ATA-%d"
458 " ATA-%d\n",
459 (cbl & 0x02) ? 33 : 66,
460 (cbl & 0x01) ? 33 : 66);
461 p += sprintf(p, "\n");
462 }
463 {
464 u8 c2, c3;
465 /* older revs don't have these registers mapped
466 * into io space */
467 pci_read_config_byte(dev, 0x43, &c0);
468 pci_read_config_byte(dev, 0x47, &c1);
469 pci_read_config_byte(dev, 0x4b, &c2);
470 pci_read_config_byte(dev, 0x4f, &c3);
471
472 p += sprintf(p, "Mode: %s %s"
473 " %s %s\n",
474 (c0 & 0x10) ? "UDMA" : (c0 & 0x20) ? "DMA " :
475 (c0 & 0x80) ? "PIO " : "off ",
476 (c1 & 0x10) ? "UDMA" : (c1 & 0x20) ? "DMA " :
477 (c1 & 0x80) ? "PIO " : "off ",
478 (c2 & 0x10) ? "UDMA" : (c2 & 0x20) ? "DMA " :
479 (c2 & 0x80) ? "PIO " : "off ",
480 (c3 & 0x10) ? "UDMA" : (c3 & 0x20) ? "DMA " :
481 (c3 & 0x80) ? "PIO " : "off ");
482 }
483 }
484#endif
485 458
486static u32 hpt_revision (struct pci_dev *dev) 459struct hpt_info
460{
461 u8 max_mode; /* Speeds allowed */
462 int revision; /* Chipset revision */
463 int flags; /* Chipset properties */
464#define PLL_MODE 1
465#define IS_372N 2
466 /* Speed table */
467 struct chipset_bus_clock_list_entry *speed;
468};
469
470/*
471 * This wants fixing so that we do everything not by classrev
472 * (which breaks on the newest chips) but by creating an
473 * enumeration of chip variants and using that
474 */
475
476static __devinit u32 hpt_revision (struct pci_dev *dev)
487{ 477{
488 u32 class_rev; 478 u32 class_rev;
489 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); 479 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
@@ -507,37 +497,33 @@ static u32 hpt_revision (struct pci_dev *dev)
507 return class_rev; 497 return class_rev;
508} 498}
509 499
510static u32 hpt_minimum_revision (struct pci_dev *dev, int revision)
511{
512 unsigned int class_rev = hpt_revision(dev);
513 revision--;
514 return ((int) (class_rev > revision) ? 1 : 0);
515}
516
517static int check_in_drive_lists(ide_drive_t *drive, const char **list); 500static int check_in_drive_lists(ide_drive_t *drive, const char **list);
518 501
519static u8 hpt3xx_ratemask (ide_drive_t *drive) 502static u8 hpt3xx_ratemask (ide_drive_t *drive)
520{ 503{
521 struct pci_dev *dev = HWIF(drive)->pci_dev; 504 ide_hwif_t *hwif = drive->hwif;
505 struct hpt_info *info = ide_get_hwifdata(hwif);
522 u8 mode = 0; 506 u8 mode = 0;
523 507
524 if (hpt_minimum_revision(dev, 8)) { /* HPT374 */ 508 /* FIXME: TODO - move this to set info->mode once at boot */
509
510 if (info->revision >= 8) { /* HPT374 */
525 mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3; 511 mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3;
526 } else if (hpt_minimum_revision(dev, 7)) { /* HPT371 */ 512 } else if (info->revision >= 7) { /* HPT371 */
527 mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3; 513 mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3;
528 } else if (hpt_minimum_revision(dev, 6)) { /* HPT302 */ 514 } else if (info->revision >= 6) { /* HPT302 */
529 mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3; 515 mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3;
530 } else if (hpt_minimum_revision(dev, 5)) { /* HPT372 */ 516 } else if (info->revision >= 5) { /* HPT372 */
531 mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3; 517 mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3;
532 } else if (hpt_minimum_revision(dev, 4)) { /* HPT370A */ 518 } else if (info->revision >= 4) { /* HPT370A */
533 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; 519 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
534 } else if (hpt_minimum_revision(dev, 3)) { /* HPT370 */ 520 } else if (info->revision >= 3) { /* HPT370 */
535 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; 521 mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
536 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode; 522 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode;
537 } else { /* HPT366 and HPT368 */ 523 } else { /* HPT366 and HPT368 */
538 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2; 524 mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2;
539 } 525 }
540 if (!eighty_ninty_three(drive) && (mode)) 526 if (!eighty_ninty_three(drive) && mode)
541 mode = min(mode, (u8)1); 527 mode = min(mode, (u8)1);
542 return mode; 528 return mode;
543} 529}
@@ -549,7 +535,8 @@ static u8 hpt3xx_ratemask (ide_drive_t *drive)
549 535
550static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed) 536static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
551{ 537{
552 struct pci_dev *dev = HWIF(drive)->pci_dev; 538 ide_hwif_t *hwif = drive->hwif;
539 struct hpt_info *info = ide_get_hwifdata(hwif);
553 u8 mode = hpt3xx_ratemask(drive); 540 u8 mode = hpt3xx_ratemask(drive);
554 541
555 if (drive->media != ide_disk) 542 if (drive->media != ide_disk)
@@ -561,7 +548,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
561 break; 548 break;
562 case 0x03: 549 case 0x03:
563 speed = min(speed, (u8)XFER_UDMA_5); 550 speed = min(speed, (u8)XFER_UDMA_5);
564 if (hpt_minimum_revision(dev, 5)) 551 if (info->revision >= 5)
565 break; 552 break;
566 if (check_in_drive_lists(drive, bad_ata100_5)) 553 if (check_in_drive_lists(drive, bad_ata100_5))
567 speed = min(speed, (u8)XFER_UDMA_4); 554 speed = min(speed, (u8)XFER_UDMA_4);
@@ -571,7 +558,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
571 /* 558 /*
572 * CHECK ME, Does this need to be set to 5 ?? 559 * CHECK ME, Does this need to be set to 5 ??
573 */ 560 */
574 if (hpt_minimum_revision(dev, 3)) 561 if (info->revision >= 3)
575 break; 562 break;
576 if ((check_in_drive_lists(drive, bad_ata66_4)) || 563 if ((check_in_drive_lists(drive, bad_ata66_4)) ||
577 (!(HPT366_ALLOW_ATA66_4))) 564 (!(HPT366_ALLOW_ATA66_4)))
@@ -585,7 +572,7 @@ static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
585 /* 572 /*
586 * CHECK ME, Does this need to be set to 5 ?? 573 * CHECK ME, Does this need to be set to 5 ??
587 */ 574 */
588 if (hpt_minimum_revision(dev, 3)) 575 if (info->revision >= 3)
589 break; 576 break;
590 if (check_in_drive_lists(drive, bad_ata33)) 577 if (check_in_drive_lists(drive, bad_ata33))
591 speed = min(speed, (u8)XFER_MW_DMA_2); 578 speed = min(speed, (u8)XFER_MW_DMA_2);
@@ -624,11 +611,12 @@ static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_
624 611
625static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) 612static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
626{ 613{
627 struct pci_dev *dev = HWIF(drive)->pci_dev; 614 ide_hwif_t *hwif = drive->hwif;
615 struct pci_dev *dev = hwif->pci_dev;
616 struct hpt_info *info = ide_get_hwifdata(hwif);
628 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 617 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
629// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed);
630 u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40; 618 u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40;
631 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51; 619 u8 regfast = (hwif->channel) ? 0x55 : 0x51;
632 u8 drive_fast = 0; 620 u8 drive_fast = 0;
633 u32 reg1 = 0, reg2 = 0; 621 u32 reg1 = 0, reg2 = 0;
634 622
@@ -636,16 +624,11 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
636 * Disable the "fast interrupt" prediction. 624 * Disable the "fast interrupt" prediction.
637 */ 625 */
638 pci_read_config_byte(dev, regfast, &drive_fast); 626 pci_read_config_byte(dev, regfast, &drive_fast);
639#if 0
640 if (drive_fast & 0x02)
641 pci_write_config_byte(dev, regfast, drive_fast & ~0x20);
642#else
643 if (drive_fast & 0x80) 627 if (drive_fast & 0x80)
644 pci_write_config_byte(dev, regfast, drive_fast & ~0x80); 628 pci_write_config_byte(dev, regfast, drive_fast & ~0x80);
645#endif
646 629
647 reg2 = pci_bus_clock_list(speed, 630 reg2 = pci_bus_clock_list(speed, info->speed);
648 (struct chipset_bus_clock_list_entry *) pci_get_drvdata(dev)); 631
649 /* 632 /*
650 * Disable on-chip PIO FIFO/buffer 633 * Disable on-chip PIO FIFO/buffer
651 * (to avoid problems handling I/O errors later) 634 * (to avoid problems handling I/O errors later)
@@ -665,10 +648,11 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
665 648
666static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed) 649static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
667{ 650{
668 struct pci_dev *dev = HWIF(drive)->pci_dev; 651 ide_hwif_t *hwif = drive->hwif;
652 struct pci_dev *dev = hwif->pci_dev;
653 struct hpt_info *info = ide_get_hwifdata(hwif);
669 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 654 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
670// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); 655 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
671 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
672 u8 drive_pci = 0x40 + (drive->dn * 4); 656 u8 drive_pci = 0x40 + (drive->dn * 4);
673 u8 new_fast = 0, drive_fast = 0; 657 u8 new_fast = 0, drive_fast = 0;
674 u32 list_conf = 0, drive_conf = 0; 658 u32 list_conf = 0, drive_conf = 0;
@@ -693,17 +677,13 @@ static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
693 if (new_fast != drive_fast) 677 if (new_fast != drive_fast)
694 pci_write_config_byte(dev, regfast, new_fast); 678 pci_write_config_byte(dev, regfast, new_fast);
695 679
696 list_conf = pci_bus_clock_list(speed, 680 list_conf = pci_bus_clock_list(speed, info->speed);
697 (struct chipset_bus_clock_list_entry *)
698 pci_get_drvdata(dev));
699 681
700 pci_read_config_dword(dev, drive_pci, &drive_conf); 682 pci_read_config_dword(dev, drive_pci, &drive_conf);
701 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); 683 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
702 684
703 if (speed < XFER_MW_DMA_0) { 685 if (speed < XFER_MW_DMA_0)
704 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */ 686 list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
705 }
706
707 pci_write_config_dword(dev, drive_pci, list_conf); 687 pci_write_config_dword(dev, drive_pci, list_conf);
708 688
709 return ide_config_drive_speed(drive, speed); 689 return ide_config_drive_speed(drive, speed);
@@ -711,10 +691,11 @@ static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
711 691
712static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed) 692static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
713{ 693{
714 struct pci_dev *dev = HWIF(drive)->pci_dev; 694 ide_hwif_t *hwif = drive->hwif;
695 struct pci_dev *dev = hwif->pci_dev;
696 struct hpt_info *info = ide_get_hwifdata(hwif);
715 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 697 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
716// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); 698 u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
717 u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
718 u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4); 699 u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4);
719 u32 list_conf = 0, drive_conf = 0; 700 u32 list_conf = 0, drive_conf = 0;
720 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000; 701 u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
@@ -726,10 +707,8 @@ static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
726 pci_read_config_byte(dev, regfast, &drive_fast); 707 pci_read_config_byte(dev, regfast, &drive_fast);
727 drive_fast &= ~0x07; 708 drive_fast &= ~0x07;
728 pci_write_config_byte(dev, regfast, drive_fast); 709 pci_write_config_byte(dev, regfast, drive_fast);
729 710
730 list_conf = pci_bus_clock_list(speed, 711 list_conf = pci_bus_clock_list(speed, info->speed);
731 (struct chipset_bus_clock_list_entry *)
732 pci_get_drvdata(dev));
733 pci_read_config_dword(dev, drive_pci, &drive_conf); 712 pci_read_config_dword(dev, drive_pci, &drive_conf);
734 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); 713 list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
735 if (speed < XFER_MW_DMA_0) 714 if (speed < XFER_MW_DMA_0)
@@ -741,19 +720,14 @@ static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
741 720
742static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed) 721static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed)
743{ 722{
744 struct pci_dev *dev = HWIF(drive)->pci_dev; 723 ide_hwif_t *hwif = drive->hwif;
724 struct hpt_info *info = ide_get_hwifdata(hwif);
745 725
746 if (hpt_minimum_revision(dev, 8)) 726 if (info->revision >= 8)
747 return hpt372_tune_chipset(drive, speed); /* not a typo */ 727 return hpt372_tune_chipset(drive, speed); /* not a typo */
748#if 0 728 else if (info->revision >= 5)
749 else if (hpt_minimum_revision(dev, 7))
750 hpt371_tune_chipset(drive, speed);
751 else if (hpt_minimum_revision(dev, 6))
752 hpt302_tune_chipset(drive, speed);
753#endif
754 else if (hpt_minimum_revision(dev, 5))
755 return hpt372_tune_chipset(drive, speed); 729 return hpt372_tune_chipset(drive, speed);
756 else if (hpt_minimum_revision(dev, 3)) 730 else if (info->revision >= 3)
757 return hpt370_tune_chipset(drive, speed); 731 return hpt370_tune_chipset(drive, speed);
758 else /* hpt368: hpt_minimum_revision(dev, 2) */ 732 else /* hpt368: hpt_minimum_revision(dev, 2) */
759 return hpt36x_tune_chipset(drive, speed); 733 return hpt36x_tune_chipset(drive, speed);
@@ -779,8 +753,14 @@ static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio)
779static int config_chipset_for_dma (ide_drive_t *drive) 753static int config_chipset_for_dma (ide_drive_t *drive)
780{ 754{
781 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); 755 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
756 ide_hwif_t *hwif = drive->hwif;
757 struct hpt_info *info = ide_get_hwifdata(hwif);
782 758
783 if (!(speed)) 759 if (!speed)
760 return 0;
761
762 /* If we don't have any timings we can't do a lot */
763 if (info->speed == NULL)
784 return 0; 764 return 0;
785 765
786 (void) hpt3xx_tune_chipset(drive, speed); 766 (void) hpt3xx_tune_chipset(drive, speed);
@@ -794,7 +774,7 @@ static int hpt3xx_quirkproc (ide_drive_t *drive)
794 774
795static void hpt3xx_intrproc (ide_drive_t *drive) 775static void hpt3xx_intrproc (ide_drive_t *drive)
796{ 776{
797 ide_hwif_t *hwif = HWIF(drive); 777 ide_hwif_t *hwif = drive->hwif;
798 778
799 if (drive->quirk_list) 779 if (drive->quirk_list)
800 return; 780 return;
@@ -804,24 +784,26 @@ static void hpt3xx_intrproc (ide_drive_t *drive)
804 784
805static void hpt3xx_maskproc (ide_drive_t *drive, int mask) 785static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
806{ 786{
807 struct pci_dev *dev = HWIF(drive)->pci_dev; 787 ide_hwif_t *hwif = drive->hwif;
788 struct hpt_info *info = ide_get_hwifdata(hwif);
789 struct pci_dev *dev = hwif->pci_dev;
808 790
809 if (drive->quirk_list) { 791 if (drive->quirk_list) {
810 if (hpt_minimum_revision(dev,3)) { 792 if (info->revision >= 3) {
811 u8 reg5a = 0; 793 u8 reg5a = 0;
812 pci_read_config_byte(dev, 0x5a, &reg5a); 794 pci_read_config_byte(dev, 0x5a, &reg5a);
813 if (((reg5a & 0x10) >> 4) != mask) 795 if (((reg5a & 0x10) >> 4) != mask)
814 pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10)); 796 pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10));
815 } else { 797 } else {
816 if (mask) { 798 if (mask) {
817 disable_irq(HWIF(drive)->irq); 799 disable_irq(hwif->irq);
818 } else { 800 } else {
819 enable_irq(HWIF(drive)->irq); 801 enable_irq(hwif->irq);
820 } 802 }
821 } 803 }
822 } else { 804 } else {
823 if (IDE_CONTROL_REG) 805 if (IDE_CONTROL_REG)
824 HWIF(drive)->OUTB(mask ? (drive->ctl | 2) : 806 hwif->OUTB(mask ? (drive->ctl | 2) :
825 (drive->ctl & ~2), 807 (drive->ctl & ~2),
826 IDE_CONTROL_REG); 808 IDE_CONTROL_REG);
827 } 809 }
@@ -829,12 +811,12 @@ static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
829 811
830static int hpt366_config_drive_xfer_rate (ide_drive_t *drive) 812static int hpt366_config_drive_xfer_rate (ide_drive_t *drive)
831{ 813{
832 ide_hwif_t *hwif = HWIF(drive); 814 ide_hwif_t *hwif = drive->hwif;
833 struct hd_driveid *id = drive->id; 815 struct hd_driveid *id = drive->id;
834 816
835 drive->init_speed = 0; 817 drive->init_speed = 0;
836 818
837 if (id && (id->capability & 1) && drive->autodma) { 819 if ((id->capability & 1) && drive->autodma) {
838 820
839 if (ide_use_dma(drive)) { 821 if (ide_use_dma(drive)) {
840 if (config_chipset_for_dma(drive)) 822 if (config_chipset_for_dma(drive))
@@ -868,15 +850,6 @@ static int hpt366_ide_dma_lostirq (ide_drive_t *drive)
868 drive->name, __FUNCTION__, reg50h, reg52h, reg5ah); 850 drive->name, __FUNCTION__, reg50h, reg52h, reg5ah);
869 if (reg5ah & 0x10) 851 if (reg5ah & 0x10)
870 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); 852 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
871#if 0
872 /* how about we flush and reset, mmmkay? */
873 pci_write_config_byte(dev, 0x51, 0x1F);
874 /* fall through to a reset */
875 case dma_start:
876 case ide_dma_end:
877 /* reset the chips state over and over.. */
878 pci_write_config_byte(dev, 0x51, 0x13);
879#endif
880 return __ide_dma_lostirq(drive); 853 return __ide_dma_lostirq(drive);
881} 854}
882 855
@@ -919,7 +892,7 @@ static void hpt370_lostirq_timeout (ide_drive_t *drive)
919 u8 dma_stat = 0, dma_cmd = 0; 892 u8 dma_stat = 0, dma_cmd = 0;
920 893
921 pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo); 894 pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo);
922 printk("%s: %d bytes in FIFO\n", drive->name, bfifo); 895 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo);
923 hpt370_clear_engine(drive); 896 hpt370_clear_engine(drive);
924 /* get dma command mode */ 897 /* get dma command mode */
925 dma_cmd = hwif->INB(hwif->dma_command); 898 dma_cmd = hwif->INB(hwif->dma_command);
@@ -1047,15 +1020,6 @@ static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq)
1047 1020
1048static void hpt3xx_reset (ide_drive_t *drive) 1021static void hpt3xx_reset (ide_drive_t *drive)
1049{ 1022{
1050#if 0
1051 unsigned long high_16 = pci_resource_start(HWIF(drive)->pci_dev, 4);
1052 u8 reset = (HWIF(drive)->channel) ? 0x80 : 0x40;
1053 u8 reg59h = 0;
1054
1055 pci_read_config_byte(HWIF(drive)->pci_dev, 0x59, &reg59h);
1056 pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h|reset);
1057 pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h);
1058#endif
1059} 1023}
1060 1024
1061static int hpt3xx_tristate (ide_drive_t * drive, int state) 1025static int hpt3xx_tristate (ide_drive_t * drive, int state)
@@ -1065,8 +1029,6 @@ static int hpt3xx_tristate (ide_drive_t * drive, int state)
1065 u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40; 1029 u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40;
1066 u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53; 1030 u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
1067 1031
1068// hwif->bus_state = state;
1069
1070 pci_read_config_byte(dev, 0x59, &reg59h); 1032 pci_read_config_byte(dev, 0x59, &reg59h);
1071 pci_read_config_byte(dev, state_reg, &regXXh); 1033 pci_read_config_byte(dev, state_reg, &regXXh);
1072 1034
@@ -1093,7 +1055,7 @@ static int hpt3xx_tristate (ide_drive_t * drive, int state)
1093#define TRISTATE_BIT 0x8000 1055#define TRISTATE_BIT 0x8000
1094static int hpt370_busproc(ide_drive_t * drive, int state) 1056static int hpt370_busproc(ide_drive_t * drive, int state)
1095{ 1057{
1096 ide_hwif_t *hwif = HWIF(drive); 1058 ide_hwif_t *hwif = drive->hwif;
1097 struct pci_dev *dev = hwif->pci_dev; 1059 struct pci_dev *dev = hwif->pci_dev;
1098 u8 tristate = 0, resetmask = 0, bus_reg = 0; 1060 u8 tristate = 0, resetmask = 0, bus_reg = 0;
1099 u16 tri_reg; 1061 u16 tri_reg;
@@ -1148,33 +1110,44 @@ static int hpt370_busproc(ide_drive_t * drive, int state)
1148 return 0; 1110 return 0;
1149} 1111}
1150 1112
1151static int __devinit init_hpt37x(struct pci_dev *dev) 1113static void __devinit hpt366_clocking(ide_hwif_t *hwif)
1152{ 1114{
1115 u32 reg1 = 0;
1116 struct hpt_info *info = ide_get_hwifdata(hwif);
1117
1118 pci_read_config_dword(hwif->pci_dev, 0x40, &reg1);
1119
1120 /* detect bus speed by looking at control reg timing: */
1121 switch((reg1 >> 8) & 7) {
1122 case 5:
1123 info->speed = forty_base_hpt366;
1124 break;
1125 case 9:
1126 info->speed = twenty_five_base_hpt366;
1127 break;
1128 case 7:
1129 default:
1130 info->speed = thirty_three_base_hpt366;
1131 break;
1132 }
1133}
1134
1135static void __devinit hpt37x_clocking(ide_hwif_t *hwif)
1136{
1137 struct hpt_info *info = ide_get_hwifdata(hwif);
1138 struct pci_dev *dev = hwif->pci_dev;
1153 int adjust, i; 1139 int adjust, i;
1154 u16 freq; 1140 u16 freq;
1155 u32 pll; 1141 u32 pll;
1156 u8 reg5bh; 1142 u8 reg5bh;
1157 u8 reg5ah = 0;
1158 unsigned long dmabase = pci_resource_start(dev, 4);
1159 u8 did, rid;
1160 int is_372n = 0;
1161 1143
1162 pci_read_config_byte(dev, 0x5a, &reg5ah);
1163 /* interrupt force enable */
1164 pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
1165
1166 if(dmabase)
1167 {
1168 did = inb(dmabase + 0x22);
1169 rid = inb(dmabase + 0x28);
1170
1171 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1172 is_372n = 1;
1173 }
1174
1175 /* 1144 /*
1176 * default to pci clock. make sure MA15/16 are set to output 1145 * default to pci clock. make sure MA15/16 are set to output
1177 * to prevent drives having problems with 40-pin cables. 1146 * to prevent drives having problems with 40-pin cables. Needed
1147 * for some drives such as IBM-DTLA which will not enter ready
1148 * state on reset when PDIAG is a input.
1149 *
1150 * ToDo: should we set 0x21 when using PLL mode ?
1178 */ 1151 */
1179 pci_write_config_byte(dev, 0x5b, 0x23); 1152 pci_write_config_byte(dev, 0x5b, 0x23);
1180 1153
@@ -1197,9 +1170,7 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1197 * Currently we always set up the PLL for the 372N 1170 * Currently we always set up the PLL for the 372N
1198 */ 1171 */
1199 1172
1200 pci_set_drvdata(dev, NULL); 1173 if(info->flags & IS_372N)
1201
1202 if(is_372n)
1203 { 1174 {
1204 printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n"); 1175 printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n");
1205 if(freq < 0x55) 1176 if(freq < 0x55)
@@ -1227,39 +1198,38 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1227 pll = F_LOW_PCI_66; 1198 pll = F_LOW_PCI_66;
1228 1199
1229 if (pll == F_LOW_PCI_33) { 1200 if (pll == F_LOW_PCI_33) {
1230 if (hpt_minimum_revision(dev,8)) 1201 if (info->revision >= 8)
1231 pci_set_drvdata(dev, (void *) thirty_three_base_hpt374); 1202 info->speed = thirty_three_base_hpt374;
1232 else if (hpt_minimum_revision(dev,5)) 1203 else if (info->revision >= 5)
1233 pci_set_drvdata(dev, (void *) thirty_three_base_hpt372); 1204 info->speed = thirty_three_base_hpt372;
1234 else if (hpt_minimum_revision(dev,4)) 1205 else if (info->revision >= 4)
1235 pci_set_drvdata(dev, (void *) thirty_three_base_hpt370a); 1206 info->speed = thirty_three_base_hpt370a;
1236 else 1207 else
1237 pci_set_drvdata(dev, (void *) thirty_three_base_hpt370); 1208 info->speed = thirty_three_base_hpt370;
1238 printk("HPT37X: using 33MHz PCI clock\n"); 1209 printk(KERN_DEBUG "HPT37X: using 33MHz PCI clock\n");
1239 } else if (pll == F_LOW_PCI_40) { 1210 } else if (pll == F_LOW_PCI_40) {
1240 /* Unsupported */ 1211 /* Unsupported */
1241 } else if (pll == F_LOW_PCI_50) { 1212 } else if (pll == F_LOW_PCI_50) {
1242 if (hpt_minimum_revision(dev,8)) 1213 if (info->revision >= 8)
1243 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1214 info->speed = fifty_base_hpt370a;
1244 else if (hpt_minimum_revision(dev,5)) 1215 else if (info->revision >= 5)
1245 pci_set_drvdata(dev, (void *) fifty_base_hpt372); 1216 info->speed = fifty_base_hpt372;
1246 else if (hpt_minimum_revision(dev,4)) 1217 else if (info->revision >= 4)
1247 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1218 info->speed = fifty_base_hpt370a;
1248 else 1219 else
1249 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1220 info->speed = fifty_base_hpt370a;
1250 printk("HPT37X: using 50MHz PCI clock\n"); 1221 printk(KERN_DEBUG "HPT37X: using 50MHz PCI clock\n");
1251 } else { 1222 } else {
1252 if (hpt_minimum_revision(dev,8)) 1223 if (info->revision >= 8) {
1253 {
1254 printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n"); 1224 printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n");
1255 } 1225 }
1256 else if (hpt_minimum_revision(dev,5)) 1226 else if (info->revision >= 5)
1257 pci_set_drvdata(dev, (void *) sixty_six_base_hpt372); 1227 info->speed = sixty_six_base_hpt372;
1258 else if (hpt_minimum_revision(dev,4)) 1228 else if (info->revision >= 4)
1259 pci_set_drvdata(dev, (void *) sixty_six_base_hpt370a); 1229 info->speed = sixty_six_base_hpt370a;
1260 else 1230 else
1261 pci_set_drvdata(dev, (void *) sixty_six_base_hpt370); 1231 info->speed = sixty_six_base_hpt370;
1262 printk("HPT37X: using 66MHz PCI clock\n"); 1232 printk(KERN_DEBUG "HPT37X: using 66MHz PCI clock\n");
1263 } 1233 }
1264 } 1234 }
1265 1235
@@ -1269,11 +1239,19 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1269 * result in slow reads when using a 33MHz PCI clock. we also 1239 * result in slow reads when using a 33MHz PCI clock. we also
1270 * don't like to use the PLL because it will cause glitches 1240 * don't like to use the PLL because it will cause glitches
1271 * on PRST/SRST when the HPT state engine gets reset. 1241 * on PRST/SRST when the HPT state engine gets reset.
1242 *
1243 * ToDo: Use 66MHz PLL when ATA133 devices are present on a
1244 * 372 device so we can get ATA133 support
1272 */ 1245 */
1273 if (pci_get_drvdata(dev)) 1246 if (info->speed)
1274 goto init_hpt37X_done; 1247 goto init_hpt37X_done;
1248
1249 info->flags |= PLL_MODE;
1275 1250
1276 /* 1251 /*
1252 * FIXME: make this work correctly, esp with 372N as per
1253 * reference driver code.
1254 *
1277 * adjust PLL based upon PCI clock, enable it, and wait for 1255 * adjust PLL based upon PCI clock, enable it, and wait for
1278 * stabilization. 1256 * stabilization.
1279 */ 1257 */
@@ -1298,14 +1276,14 @@ static int __devinit init_hpt37x(struct pci_dev *dev)
1298 pci_write_config_dword(dev, 0x5c, 1276 pci_write_config_dword(dev, 0x5c,
1299 pll & ~0x100); 1277 pll & ~0x100);
1300 pci_write_config_byte(dev, 0x5b, 0x21); 1278 pci_write_config_byte(dev, 0x5b, 0x21);
1301 if (hpt_minimum_revision(dev,8)) 1279 if (info->revision >= 8)
1302 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1280 info->speed = fifty_base_hpt370a;
1303 else if (hpt_minimum_revision(dev,5)) 1281 else if (info->revision >= 5)
1304 pci_set_drvdata(dev, (void *) fifty_base_hpt372); 1282 info->speed = fifty_base_hpt372;
1305 else if (hpt_minimum_revision(dev,4)) 1283 else if (info->revision >= 4)
1306 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1284 info->speed = fifty_base_hpt370a;
1307 else 1285 else
1308 pci_set_drvdata(dev, (void *) fifty_base_hpt370a); 1286 info->speed = fifty_base_hpt370a;
1309 printk("HPT37X: using 50MHz internal PLL\n"); 1287 printk("HPT37X: using 50MHz internal PLL\n");
1310 goto init_hpt37X_done; 1288 goto init_hpt37X_done;
1311 } 1289 }
@@ -1318,10 +1296,22 @@ pll_recal:
1318 } 1296 }
1319 1297
1320init_hpt37X_done: 1298init_hpt37X_done:
1299 if (!info->speed)
1300 printk(KERN_ERR "HPT37X%s: unknown bus timing [%d %d].\n",
1301 (info->flags & IS_372N)?"N":"", pll, freq);
1321 /* reset state engine */ 1302 /* reset state engine */
1322 pci_write_config_byte(dev, 0x50, 0x37); 1303 pci_write_config_byte(dev, 0x50, 0x37);
1323 pci_write_config_byte(dev, 0x54, 0x37); 1304 pci_write_config_byte(dev, 0x54, 0x37);
1324 udelay(100); 1305 udelay(100);
1306}
1307
1308static int __devinit init_hpt37x(struct pci_dev *dev)
1309{
1310 u8 reg5ah;
1311
1312 pci_read_config_byte(dev, 0x5a, &reg5ah);
1313 /* interrupt force enable */
1314 pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
1325 return 0; 1315 return 0;
1326} 1316}
1327 1317
@@ -1338,59 +1328,27 @@ static int __devinit init_hpt366(struct pci_dev *dev)
1338 pci_write_config_byte(dev, 0x51, drive_fast & ~0x80); 1328 pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
1339 pci_read_config_dword(dev, 0x40, &reg1); 1329 pci_read_config_dword(dev, 0x40, &reg1);
1340 1330
1341 /* detect bus speed by looking at control reg timing: */
1342 switch((reg1 >> 8) & 7) {
1343 case 5:
1344 pci_set_drvdata(dev, (void *) forty_base_hpt366);
1345 break;
1346 case 9:
1347 pci_set_drvdata(dev, (void *) twenty_five_base_hpt366);
1348 break;
1349 case 7:
1350 default:
1351 pci_set_drvdata(dev, (void *) thirty_three_base_hpt366);
1352 break;
1353 }
1354
1355 if (!pci_get_drvdata(dev))
1356 {
1357 printk(KERN_ERR "hpt366: unknown bus timing.\n");
1358 pci_set_drvdata(dev, NULL);
1359 }
1360 return 0; 1331 return 0;
1361} 1332}
1362 1333
1363static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) 1334static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
1364{ 1335{
1365 int ret = 0; 1336 int ret = 0;
1366 u8 test = 0; 1337 /* FIXME: Not portable */
1367
1368 if (dev->resource[PCI_ROM_RESOURCE].start) 1338 if (dev->resource[PCI_ROM_RESOURCE].start)
1369 pci_write_config_byte(dev, PCI_ROM_ADDRESS, 1339 pci_write_config_byte(dev, PCI_ROM_ADDRESS,
1370 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); 1340 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1371 1341
1372 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &test); 1342 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
1373 if (test != (L1_CACHE_BYTES / 4)) 1343 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1374 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 1344 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1375 (L1_CACHE_BYTES / 4)); 1345 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
1376
1377 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &test);
1378 if (test != 0x78)
1379 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1380 1346
1381 pci_read_config_byte(dev, PCI_MIN_GNT, &test); 1347 if (hpt_revision(dev) >= 3)
1382 if (test != 0x08)
1383 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1384
1385 pci_read_config_byte(dev, PCI_MAX_LAT, &test);
1386 if (test != 0x08)
1387 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
1388
1389 if (hpt_minimum_revision(dev, 3)) {
1390 ret = init_hpt37x(dev); 1348 ret = init_hpt37x(dev);
1391 } else { 1349 else
1392 ret =init_hpt366(dev); 1350 ret = init_hpt366(dev);
1393 } 1351
1394 if (ret) 1352 if (ret)
1395 return ret; 1353 return ret;
1396 1354
@@ -1400,27 +1358,16 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1400static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1358static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1401{ 1359{
1402 struct pci_dev *dev = hwif->pci_dev; 1360 struct pci_dev *dev = hwif->pci_dev;
1361 struct hpt_info *info = ide_get_hwifdata(hwif);
1403 u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02; 1362 u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02;
1404 u8 did, rid;
1405 unsigned long dmabase = hwif->dma_base;
1406 int is_372n = 0;
1407 1363
1408 if(dmabase)
1409 {
1410 did = inb(dmabase + 0x22);
1411 rid = inb(dmabase + 0x28);
1412
1413 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1414 is_372n = 1;
1415 }
1416
1417 hwif->tuneproc = &hpt3xx_tune_drive; 1364 hwif->tuneproc = &hpt3xx_tune_drive;
1418 hwif->speedproc = &hpt3xx_tune_chipset; 1365 hwif->speedproc = &hpt3xx_tune_chipset;
1419 hwif->quirkproc = &hpt3xx_quirkproc; 1366 hwif->quirkproc = &hpt3xx_quirkproc;
1420 hwif->intrproc = &hpt3xx_intrproc; 1367 hwif->intrproc = &hpt3xx_intrproc;
1421 hwif->maskproc = &hpt3xx_maskproc; 1368 hwif->maskproc = &hpt3xx_maskproc;
1422 1369
1423 if(is_372n) 1370 if(info->flags & IS_372N)
1424 hwif->rw_disk = &hpt372n_rw_disk; 1371 hwif->rw_disk = &hpt372n_rw_disk;
1425 1372
1426 /* 1373 /*
@@ -1428,7 +1375,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1428 * address lines to access an external eeprom. To read valid 1375 * address lines to access an external eeprom. To read valid
1429 * cable detect state the pins must be enabled as inputs. 1376 * cable detect state the pins must be enabled as inputs.
1430 */ 1377 */
1431 if (hpt_minimum_revision(dev, 8) && PCI_FUNC(dev->devfn) & 1) { 1378 if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) {
1432 /* 1379 /*
1433 * HPT374 PCI function 1 1380 * HPT374 PCI function 1
1434 * - set bit 15 of reg 0x52 to enable TCBLID as input 1381 * - set bit 15 of reg 0x52 to enable TCBLID as input
@@ -1443,7 +1390,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1443 pci_read_config_byte(dev, 0x5a, &ata66); 1390 pci_read_config_byte(dev, 0x5a, &ata66);
1444 pci_write_config_word(dev, 0x52, mcr3); 1391 pci_write_config_word(dev, 0x52, mcr3);
1445 pci_write_config_word(dev, 0x56, mcr6); 1392 pci_write_config_word(dev, 0x56, mcr6);
1446 } else if (hpt_minimum_revision(dev, 3)) { 1393 } else if (info->revision >= 3) {
1447 /* 1394 /*
1448 * HPT370/372 and 374 pcifn 0 1395 * HPT370/372 and 374 pcifn 0
1449 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs 1396 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs
@@ -1470,7 +1417,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1470 hwif->serialized = hwif->mate->serialized = 1; 1417 hwif->serialized = hwif->mate->serialized = 1;
1471#endif 1418#endif
1472 1419
1473 if (hpt_minimum_revision(dev,3)) { 1420 if (info->revision >= 3) {
1474 u8 reg5ah = 0; 1421 u8 reg5ah = 0;
1475 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); 1422 pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
1476 /* 1423 /*
@@ -1480,8 +1427,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1480 */ 1427 */
1481 hwif->resetproc = &hpt3xx_reset; 1428 hwif->resetproc = &hpt3xx_reset;
1482 hwif->busproc = &hpt370_busproc; 1429 hwif->busproc = &hpt370_busproc;
1483// hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 1430 } else if (info->revision >= 2) {
1484 } else if (hpt_minimum_revision(dev,2)) {
1485 hwif->resetproc = &hpt3xx_reset; 1431 hwif->resetproc = &hpt3xx_reset;
1486 hwif->busproc = &hpt3xx_tristate; 1432 hwif->busproc = &hpt3xx_tristate;
1487 } else { 1433 } else {
@@ -1502,18 +1448,18 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1502 hwif->udma_four = ((ata66 & regmask) ? 0 : 1); 1448 hwif->udma_four = ((ata66 & regmask) ? 0 : 1);
1503 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate; 1449 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
1504 1450
1505 if (hpt_minimum_revision(dev,8)) { 1451 if (info->revision >= 8) {
1506 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; 1452 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1507 hwif->ide_dma_end = &hpt374_ide_dma_end; 1453 hwif->ide_dma_end = &hpt374_ide_dma_end;
1508 } else if (hpt_minimum_revision(dev,5)) { 1454 } else if (info->revision >= 5) {
1509 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; 1455 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1510 hwif->ide_dma_end = &hpt374_ide_dma_end; 1456 hwif->ide_dma_end = &hpt374_ide_dma_end;
1511 } else if (hpt_minimum_revision(dev,3)) { 1457 } else if (info->revision >= 3) {
1512 hwif->dma_start = &hpt370_ide_dma_start; 1458 hwif->dma_start = &hpt370_ide_dma_start;
1513 hwif->ide_dma_end = &hpt370_ide_dma_end; 1459 hwif->ide_dma_end = &hpt370_ide_dma_end;
1514 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout; 1460 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
1515 hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq; 1461 hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;
1516 } else if (hpt_minimum_revision(dev,2)) 1462 } else if (info->revision >= 2)
1517 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; 1463 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
1518 else 1464 else
1519 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; 1465 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
@@ -1526,6 +1472,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1526 1472
1527static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) 1473static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1528{ 1474{
1475 struct hpt_info *info = ide_get_hwifdata(hwif);
1529 u8 masterdma = 0, slavedma = 0; 1476 u8 masterdma = 0, slavedma = 0;
1530 u8 dma_new = 0, dma_old = 0; 1477 u8 dma_new = 0, dma_old = 0;
1531 u8 primary = hwif->channel ? 0x4b : 0x43; 1478 u8 primary = hwif->channel ? 0x4b : 0x43;
@@ -1535,8 +1482,7 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1535 if (!dmabase) 1482 if (!dmabase)
1536 return; 1483 return;
1537 1484
1538 if(pci_get_drvdata(hwif->pci_dev) == NULL) 1485 if(info->speed == NULL) {
1539 {
1540 printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n"); 1486 printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");
1541 return; 1487 return;
1542 } 1488 }
@@ -1559,6 +1505,40 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1559 ide_setup_dma(hwif, dmabase, 8); 1505 ide_setup_dma(hwif, dmabase, 8);
1560} 1506}
1561 1507
1508/*
1509 * We "borrow" this hook in order to set the data structures
1510 * up early enough before dma or init_hwif calls are made.
1511 */
1512
1513static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
1514{
1515 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
1516 unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);
1517 u8 did, rid;
1518
1519 if(info == NULL) {
1520 printk(KERN_WARNING "hpt366: out of memory.\n");
1521 return;
1522 }
1523 memset(info, 0, sizeof(struct hpt_info));
1524 ide_set_hwifdata(hwif, info);
1525
1526 if(dmabase) {
1527 did = inb(dmabase + 0x22);
1528 rid = inb(dmabase + 0x28);
1529
1530 if((did == 4 && rid == 6) || (did == 5 && rid > 1))
1531 info->flags |= IS_372N;
1532 }
1533
1534 info->revision = hpt_revision(hwif->pci_dev);
1535
1536 if (info->revision >= 3)
1537 hpt37x_clocking(hwif);
1538 else
1539 hpt366_clocking(hwif);
1540}
1541
1562static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) 1542static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d)
1563{ 1543{
1564 struct pci_dev *findev = NULL; 1544 struct pci_dev *findev = NULL;
@@ -1646,6 +1626,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1646 .name = "HPT366", 1626 .name = "HPT366",
1647 .init_setup = init_setup_hpt366, 1627 .init_setup = init_setup_hpt366,
1648 .init_chipset = init_chipset_hpt366, 1628 .init_chipset = init_chipset_hpt366,
1629 .init_iops = init_iops_hpt366,
1649 .init_hwif = init_hwif_hpt366, 1630 .init_hwif = init_hwif_hpt366,
1650 .init_dma = init_dma_hpt366, 1631 .init_dma = init_dma_hpt366,
1651 .channels = 2, 1632 .channels = 2,
@@ -1656,6 +1637,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1656 .name = "HPT372A", 1637 .name = "HPT372A",
1657 .init_setup = init_setup_hpt37x, 1638 .init_setup = init_setup_hpt37x,
1658 .init_chipset = init_chipset_hpt366, 1639 .init_chipset = init_chipset_hpt366,
1640 .init_iops = init_iops_hpt366,
1659 .init_hwif = init_hwif_hpt366, 1641 .init_hwif = init_hwif_hpt366,
1660 .init_dma = init_dma_hpt366, 1642 .init_dma = init_dma_hpt366,
1661 .channels = 2, 1643 .channels = 2,
@@ -1665,6 +1647,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1665 .name = "HPT302", 1647 .name = "HPT302",
1666 .init_setup = init_setup_hpt37x, 1648 .init_setup = init_setup_hpt37x,
1667 .init_chipset = init_chipset_hpt366, 1649 .init_chipset = init_chipset_hpt366,
1650 .init_iops = init_iops_hpt366,
1668 .init_hwif = init_hwif_hpt366, 1651 .init_hwif = init_hwif_hpt366,
1669 .init_dma = init_dma_hpt366, 1652 .init_dma = init_dma_hpt366,
1670 .channels = 2, 1653 .channels = 2,
@@ -1674,6 +1657,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1674 .name = "HPT371", 1657 .name = "HPT371",
1675 .init_setup = init_setup_hpt37x, 1658 .init_setup = init_setup_hpt37x,
1676 .init_chipset = init_chipset_hpt366, 1659 .init_chipset = init_chipset_hpt366,
1660 .init_iops = init_iops_hpt366,
1677 .init_hwif = init_hwif_hpt366, 1661 .init_hwif = init_hwif_hpt366,
1678 .init_dma = init_dma_hpt366, 1662 .init_dma = init_dma_hpt366,
1679 .channels = 2, 1663 .channels = 2,
@@ -1683,6 +1667,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1683 .name = "HPT374", 1667 .name = "HPT374",
1684 .init_setup = init_setup_hpt374, 1668 .init_setup = init_setup_hpt374,
1685 .init_chipset = init_chipset_hpt366, 1669 .init_chipset = init_chipset_hpt366,
1670 .init_iops = init_iops_hpt366,
1686 .init_hwif = init_hwif_hpt366, 1671 .init_hwif = init_hwif_hpt366,
1687 .init_dma = init_dma_hpt366, 1672 .init_dma = init_dma_hpt366,
1688 .channels = 2, /* 4 */ 1673 .channels = 2, /* 4 */
@@ -1692,6 +1677,7 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1692 .name = "HPT372N", 1677 .name = "HPT372N",
1693 .init_setup = init_setup_hpt37x, 1678 .init_setup = init_setup_hpt37x,
1694 .init_chipset = init_chipset_hpt366, 1679 .init_chipset = init_chipset_hpt366,
1680 .init_iops = init_iops_hpt366,
1695 .init_hwif = init_hwif_hpt366, 1681 .init_hwif = init_hwif_hpt366,
1696 .init_dma = init_dma_hpt366, 1682 .init_dma = init_dma_hpt366,
1697 .channels = 2, /* 4 */ 1683 .channels = 2, /* 4 */
diff --git a/drivers/ide/pci/it8172.c b/drivers/ide/pci/it8172.c
index 631927cf17d4..93462926b9d5 100644
--- a/drivers/ide/pci/it8172.c
+++ b/drivers/ide/pci/it8172.c
@@ -216,7 +216,7 @@ fast_ata_pio:
216 return 0; 216 return 0;
217} 217}
218 218
219static unsigned int __init init_chipset_it8172 (struct pci_dev *dev, const char *name) 219static unsigned int __devinit init_chipset_it8172 (struct pci_dev *dev, const char *name)
220{ 220{
221 unsigned char progif; 221 unsigned char progif;
222 222
@@ -230,7 +230,7 @@ static unsigned int __init init_chipset_it8172 (struct pci_dev *dev, const char
230} 230}
231 231
232 232
233static void __init init_hwif_it8172 (ide_hwif_t *hwif) 233static void __devinit init_hwif_it8172 (ide_hwif_t *hwif)
234{ 234{
235 struct pci_dev* dev = hwif->pci_dev; 235 struct pci_dev* dev = hwif->pci_dev;
236 unsigned long cmdBase, ctrlBase; 236 unsigned long cmdBase, ctrlBase;
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
new file mode 100644
index 000000000000..e440036e651f
--- /dev/null
+++ b/drivers/ide/pci/it821x.c
@@ -0,0 +1,812 @@
1
2/*
3 * linux/drivers/ide/pci/it821x.c Version 0.09 December 2004
4 *
5 * Copyright (C) 2004 Red Hat <alan@redhat.com>
6 *
7 * May be copied or modified under the terms of the GNU General Public License
8 * Based in part on the ITE vendor provided SCSI driver.
9 *
10 * Documentation available from
11 * http://www.ite.com.tw/pc/IT8212F_V04.pdf
12 * Some other documents are NDA.
13 *
14 * The ITE8212 isn't exactly a standard IDE controller. It has two
15 * modes. In pass through mode then it is an IDE controller. In its smart
16 * mode its actually quite a capable hardware raid controller disguised
17 * as an IDE controller. Smart mode only understands DMA read/write and
18 * identify, none of the fancier commands apply. The IT8211 is identical
19 * in other respects but lacks the raid mode.
20 *
21 * Errata:
22 * o Rev 0x10 also requires master/slave hold the same DMA timings and
23 * cannot do ATAPI MWDMA.
24 * o The identify data for raid volumes lacks CHS info (technically ok)
25 * but also fails to set the LBA28 and other bits. We fix these in
26 * the IDE probe quirk code.
27 * o If you write LBA48 sized I/O's (ie > 256 sector) in smart mode
28 * raid then the controller firmware dies
29 * o Smart mode without RAID doesn't clear all the necessary identify
30 * bits to reduce the command set to the one used
31 *
32 * This has a few impacts on the driver
33 * - In pass through mode we do all the work you would expect
34 * - In smart mode the clocking set up is done by the controller generally
35 * but we must watch the other limits and filter.
36 * - There are a few extra vendor commands that actually talk to the
37 * controller but only work PIO with no IRQ.
38 *
39 * Vendor areas of the identify block in smart mode are used for the
40 * timing and policy set up. Each HDD in raid mode also has a serial
41 * block on the disk. The hardware extra commands are get/set chip status,
42 * rebuild, get rebuild status.
43 *
44 * In Linux the driver supports pass through mode as if the device was
45 * just another IDE controller. If the smart mode is running then
46 * volumes are managed by the controller firmware and each IDE "disk"
47 * is a raid volume. Even more cute - the controller can do automated
48 * hotplug and rebuild.
49 *
50 * The pass through controller itself is a little demented. It has a
51 * flaw that it has a single set of PIO/MWDMA timings per channel so
52 * non UDMA devices restrict each others performance. It also has a
53 * single clock source per channel so mixed UDMA100/133 performance
54 * isn't perfect and we have to pick a clock. Thankfully none of this
55 * matters in smart mode. ATAPI DMA is not currently supported.
56 *
57 * It seems the smart mode is a win for RAID1/RAID10 but otherwise not.
58 *
59 * TODO
60 * - ATAPI UDMA is ok but not MWDMA it seems
61 * - RAID configuration ioctls
62 * - Move to libata once it grows up
63 */
64
65#include <linux/config.h>
66#include <linux/types.h>
67#include <linux/module.h>
68#include <linux/pci.h>
69#include <linux/delay.h>
70#include <linux/hdreg.h>
71#include <linux/ide.h>
72#include <linux/init.h>
73
74#include <asm/io.h>
75
76struct it821x_dev
77{
78 unsigned int smart:1, /* Are we in smart raid mode */
79 timing10:1; /* Rev 0x10 */
80 u8 clock_mode; /* 0, ATA_50 or ATA_66 */
81 u8 want[2][2]; /* Mode/Pri log for master slave */
82 /* We need these for switching the clock when DMA goes on/off
83 The high byte is the 66Mhz timing */
84 u16 pio[2]; /* Cached PIO values */
85 u16 mwdma[2]; /* Cached MWDMA values */
86 u16 udma[2]; /* Cached UDMA values (per drive) */
87};
88
89#define ATA_66 0
90#define ATA_50 1
91#define ATA_ANY 2
92
93#define UDMA_OFF 0
94#define MWDMA_OFF 0
95
96/*
97 * We allow users to force the card into non raid mode without
98 * flashing the alternative BIOS. This is also neccessary right now
99 * for embedded platforms that cannot run a PC BIOS but are using this
100 * device.
101 */
102
103static int it8212_noraid;
104
105/**
106 * it821x_program - program the PIO/MWDMA registers
107 * @drive: drive to tune
108 *
109 * Program the PIO/MWDMA timing for this channel according to the
110 * current clock.
111 */
112
113static void it821x_program(ide_drive_t *drive, u16 timing)
114{
115 ide_hwif_t *hwif = drive->hwif;
116 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
117 int channel = hwif->channel;
118 u8 conf;
119
120 /* Program PIO/MWDMA timing bits */
121 if(itdev->clock_mode == ATA_66)
122 conf = timing >> 8;
123 else
124 conf = timing & 0xFF;
125 pci_write_config_byte(hwif->pci_dev, 0x54 + 4 * channel, conf);
126}
127
128/**
129 * it821x_program_udma - program the UDMA registers
130 * @drive: drive to tune
131 *
132 * Program the UDMA timing for this drive according to the
133 * current clock.
134 */
135
136static void it821x_program_udma(ide_drive_t *drive, u16 timing)
137{
138 ide_hwif_t *hwif = drive->hwif;
139 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
140 int channel = hwif->channel;
141 int unit = drive->select.b.unit;
142 u8 conf;
143
144 /* Program UDMA timing bits */
145 if(itdev->clock_mode == ATA_66)
146 conf = timing >> 8;
147 else
148 conf = timing & 0xFF;
149 if(itdev->timing10 == 0)
150 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + unit, conf);
151 else {
152 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel, conf);
153 pci_write_config_byte(hwif->pci_dev, 0x56 + 4 * channel + 1, conf);
154 }
155}
156
157
158/**
159 * it821x_clock_strategy
160 * @hwif: hardware interface
161 *
162 * Select between the 50 and 66Mhz base clocks to get the best
163 * results for this interface.
164 */
165
166static void it821x_clock_strategy(ide_drive_t *drive)
167{
168 ide_hwif_t *hwif = drive->hwif;
169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170
171 u8 unit = drive->select.b.unit;
172 ide_drive_t *pair = &hwif->drives[1-unit];
173
174 int clock, altclock;
175 u8 v;
176 int sel = 0;
177
178 if(itdev->want[0][0] > itdev->want[1][0]) {
179 clock = itdev->want[0][1];
180 altclock = itdev->want[1][1];
181 } else {
182 clock = itdev->want[1][1];
183 altclock = itdev->want[0][1];
184 }
185
186 /* Master doesn't care does the slave ? */
187 if(clock == ATA_ANY)
188 clock = altclock;
189
190 /* Nobody cares - keep the same clock */
191 if(clock == ATA_ANY)
192 return;
193 /* No change */
194 if(clock == itdev->clock_mode)
195 return;
196
197 /* Load this into the controller ? */
198 if(clock == ATA_66)
199 itdev->clock_mode = ATA_66;
200 else {
201 itdev->clock_mode = ATA_50;
202 sel = 1;
203 }
204 pci_read_config_byte(hwif->pci_dev, 0x50, &v);
205 v &= ~(1 << (1 + hwif->channel));
206 v |= sel << (1 + hwif->channel);
207 pci_write_config_byte(hwif->pci_dev, 0x50, v);
208
209 /*
210 * Reprogram the UDMA/PIO of the pair drive for the switch
211 * MWDMA will be dealt with by the dma switcher
212 */
213 if(pair && itdev->udma[1-unit] != UDMA_OFF) {
214 it821x_program_udma(pair, itdev->udma[1-unit]);
215 it821x_program(pair, itdev->pio[1-unit]);
216 }
217 /*
218 * Reprogram the UDMA/PIO of our drive for the switch.
219 * MWDMA will be dealt with by the dma switcher
220 */
221 if(itdev->udma[unit] != UDMA_OFF) {
222 it821x_program_udma(drive, itdev->udma[unit]);
223 it821x_program(drive, itdev->pio[unit]);
224 }
225}
226
227/**
228 * it821x_ratemask - Compute available modes
229 * @drive: IDE drive
230 *
231 * Compute the available speeds for the devices on the interface. This
232 * is all modes to ATA133 clipped by drive cable setup.
233 */
234
235static u8 it821x_ratemask (ide_drive_t *drive)
236{
237 u8 mode = 4;
238 if (!eighty_ninty_three(drive))
239 mode = min(mode, (u8)1);
240 return mode;
241}
242
243/**
244 * it821x_tuneproc - tune a drive
245 * @drive: drive to tune
246 * @mode_wanted: the target operating mode
247 *
248 * Load the timing settings for this device mode into the
249 * controller. By the time we are called the mode has been
250 * modified as neccessary to handle the absence of seperate
251 * master/slave timers for MWDMA/PIO.
252 *
253 * This code is only used in pass through mode.
254 */
255
256static void it821x_tuneproc (ide_drive_t *drive, byte mode_wanted)
257{
258 ide_hwif_t *hwif = drive->hwif;
259 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
260 int unit = drive->select.b.unit;
261
262 /* Spec says 89 ref driver uses 88 */
263 static u16 pio[] = { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
264 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
265
266 if(itdev->smart)
267 return;
268
269 /* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */
270 itdev->want[unit][1] = pio_want[mode_wanted];
271 itdev->want[unit][0] = 1; /* PIO is lowest priority */
272 itdev->pio[unit] = pio[mode_wanted];
273 it821x_clock_strategy(drive);
274 it821x_program(drive, itdev->pio[unit]);
275}
276
277/**
278 * it821x_tune_mwdma - tune a channel for MWDMA
279 * @drive: drive to set up
280 * @mode_wanted: the target operating mode
281 *
282 * Load the timing settings for this device mode into the
283 * controller when doing MWDMA in pass through mode. The caller
284 * must manage the whole lack of per device MWDMA/PIO timings and
285 * the shared MWDMA/PIO timing register.
286 */
287
288static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
289{
290 ide_hwif_t *hwif = drive->hwif;
291 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
292 int unit = drive->select.b.unit;
293 int channel = hwif->channel;
294 u8 conf;
295
296 static u16 dma[] = { 0x8866, 0x3222, 0x3121 };
297 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
298
299 itdev->want[unit][1] = mwdma_want[mode_wanted];
300 itdev->want[unit][0] = 2; /* MWDMA is low priority */
301 itdev->mwdma[unit] = dma[mode_wanted];
302 itdev->udma[unit] = UDMA_OFF;
303
304 /* UDMA bits off - Revision 0x10 do them in pairs */
305 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
306 if(itdev->timing10)
307 conf |= channel ? 0x60: 0x18;
308 else
309 conf |= 1 << (3 + 2 * channel + unit);
310 pci_write_config_byte(hwif->pci_dev, 0x50, conf);
311
312 it821x_clock_strategy(drive);
313 /* FIXME: do we need to program this ? */
314 /* it821x_program(drive, itdev->mwdma[unit]); */
315}
316
317/**
318 * it821x_tune_udma - tune a channel for UDMA
319 * @drive: drive to set up
320 * @mode_wanted: the target operating mode
321 *
322 * Load the timing settings for this device mode into the
323 * controller when doing UDMA modes in pass through.
324 */
325
326static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
327{
328 ide_hwif_t *hwif = drive->hwif;
329 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
330 int unit = drive->select.b.unit;
331 int channel = hwif->channel;
332 u8 conf;
333
334 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
335 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
336
337 itdev->want[unit][1] = udma_want[mode_wanted];
338 itdev->want[unit][0] = 3; /* UDMA is high priority */
339 itdev->mwdma[unit] = MWDMA_OFF;
340 itdev->udma[unit] = udma[mode_wanted];
341 if(mode_wanted >= 5)
342 itdev->udma[unit] |= 0x8080; /* UDMA 5/6 select on */
343
344 /* UDMA on. Again revision 0x10 must do the pair */
345 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
346 if(itdev->timing10)
347 conf &= channel ? 0x9F: 0xE7;
348 else
349 conf &= ~ (1 << (3 + 2 * channel + unit));
350 pci_write_config_byte(hwif->pci_dev, 0x50, conf);
351
352 it821x_clock_strategy(drive);
353 it821x_program_udma(drive, itdev->udma[unit]);
354
355}
356
357/**
358 * config_it821x_chipset_for_pio - set drive timings
359 * @drive: drive to tune
360 * @speed we want
361 *
362 * Compute the best pio mode we can for a given device. We must
363 * pick a speed that does not cause problems with the other device
364 * on the cable.
365 */
366
367static void config_it821x_chipset_for_pio (ide_drive_t *drive, byte set_speed)
368{
369 u8 unit = drive->select.b.unit;
370 ide_hwif_t *hwif = drive->hwif;
371 ide_drive_t *pair = &hwif->drives[1-unit];
372 u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
373 u8 pair_pio;
374
375 /* We have to deal with this mess in pairs */
376 if(pair != NULL) {
377 pair_pio = ide_get_best_pio_mode(pair, 255, 5, NULL);
378 /* Trim PIO to the slowest of the master/slave */
379 if(pair_pio < set_pio)
380 set_pio = pair_pio;
381 }
382 it821x_tuneproc(drive, set_pio);
383 speed = XFER_PIO_0 + set_pio;
384 /* XXX - We trim to the lowest of the pair so the other drive
385 will always be fine at this point until we do hotplug passthru */
386
387 if (set_speed)
388 (void) ide_config_drive_speed(drive, speed);
389}
390
391/**
392 * it821x_dma_read - DMA hook
393 * @drive: drive for DMA
394 *
395 * The IT821x has a single timing register for MWDMA and for PIO
396 * operations. As we flip back and forth we have to reload the
397 * clock. In addition the rev 0x10 device only works if the same
398 * timing value is loaded into the master and slave UDMA clock
399 * so we must also reload that.
400 *
401 * FIXME: we could figure out in advance if we need to do reloads
402 */
403
404static void it821x_dma_start(ide_drive_t *drive)
405{
406 ide_hwif_t *hwif = drive->hwif;
407 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
408 int unit = drive->select.b.unit;
409 if(itdev->mwdma[unit] != MWDMA_OFF)
410 it821x_program(drive, itdev->mwdma[unit]);
411 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
412 it821x_program_udma(drive, itdev->udma[unit]);
413 ide_dma_start(drive);
414}
415
416/**
417 * it821x_dma_write - DMA hook
418 * @drive: drive for DMA stop
419 *
420 * The IT821x has a single timing register for MWDMA and for PIO
421 * operations. As we flip back and forth we have to reload the
422 * clock.
423 */
424
425static int it821x_dma_end(ide_drive_t *drive)
426{
427 ide_hwif_t *hwif = drive->hwif;
428 int unit = drive->select.b.unit;
429 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
430 int ret = __ide_dma_end(drive);
431 if(itdev->mwdma[unit] != MWDMA_OFF)
432 it821x_program(drive, itdev->pio[unit]);
433 return ret;
434}
435
436
437/**
438 * it821x_tune_chipset - set controller timings
439 * @drive: Drive to set up
440 * @xferspeed: speed we want to achieve
441 *
442 * Tune the ITE chipset for the desired mode. If we can't achieve
443 * the desired mode then tune for a lower one, but ultimately
444 * make the thing work.
445 */
446
447static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
448{
449
450 ide_hwif_t *hwif = drive->hwif;
451 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
452 u8 speed = ide_rate_filter(it821x_ratemask(drive), xferspeed);
453
454 if(!itdev->smart) {
455 switch(speed) {
456 case XFER_PIO_4:
457 case XFER_PIO_3:
458 case XFER_PIO_2:
459 case XFER_PIO_1:
460 case XFER_PIO_0:
461 it821x_tuneproc(drive, (speed - XFER_PIO_0));
462 break;
463 /* MWDMA tuning is really hard because our MWDMA and PIO
464 timings are kept in the same place. We can switch in the
465 host dma on/off callbacks */
466 case XFER_MW_DMA_2:
467 case XFER_MW_DMA_1:
468 case XFER_MW_DMA_0:
469 it821x_tune_mwdma(drive, (speed - XFER_MW_DMA_0));
470 break;
471 case XFER_UDMA_6:
472 case XFER_UDMA_5:
473 case XFER_UDMA_4:
474 case XFER_UDMA_3:
475 case XFER_UDMA_2:
476 case XFER_UDMA_1:
477 case XFER_UDMA_0:
478 it821x_tune_udma(drive, (speed - XFER_UDMA_0));
479 break;
480 default:
481 return 1;
482 }
483 }
484 /*
485 * In smart mode the clocking is done by the host controller
486 * snooping the mode we picked. The rest of it is not our problem
487 */
488 return ide_config_drive_speed(drive, speed);
489}
490
491/**
492 * config_chipset_for_dma - configure for DMA
493 * @drive: drive to configure
494 *
495 * Called by the IDE layer when it wants the timings set up.
496 */
497
498static int config_chipset_for_dma (ide_drive_t *drive)
499{
500 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive));
501
502 config_it821x_chipset_for_pio(drive, !speed);
503 it821x_tune_chipset(drive, speed);
504 return ide_dma_enable(drive);
505}
506
507/**
508 * it821x_configure_drive_for_dma - set up for DMA transfers
509 * @drive: drive we are going to set up
510 *
511 * Set up the drive for DMA, tune the controller and drive as
512 * required. If the drive isn't suitable for DMA or we hit
513 * other problems then we will drop down to PIO and set up
514 * PIO appropriately
515 */
516
517static int it821x_config_drive_for_dma (ide_drive_t *drive)
518{
519 ide_hwif_t *hwif = drive->hwif;
520
521 if (ide_use_dma(drive)) {
522 if (config_chipset_for_dma(drive))
523 return hwif->ide_dma_on(drive);
524 }
525 config_it821x_chipset_for_pio(drive, 1);
526 return hwif->ide_dma_off_quietly(drive);
527}
528
529/**
530 * ata66_it821x - check for 80 pin cable
531 * @hwif: interface to check
532 *
533 * Check for the presence of an ATA66 capable cable on the
534 * interface. Problematic as it seems some cards don't have
535 * the needed logic onboard.
536 */
537
538static unsigned int __devinit ata66_it821x(ide_hwif_t *hwif)
539{
540 /* The reference driver also only does disk side */
541 return 1;
542}
543
544/**
545 * it821x_fixup - post init callback
546 * @hwif: interface
547 *
548 * This callback is run after the drives have been probed but
549 * before anything gets attached. It allows drivers to do any
550 * final tuning that is needed, or fixups to work around bugs.
551 */
552
553static void __devinit it821x_fixups(ide_hwif_t *hwif)
554{
555 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
556 int i;
557
558 if(!itdev->smart) {
559 /*
560 * If we are in pass through mode then not much
561 * needs to be done, but we do bother to clear the
562 * IRQ mask as we may well be in PIO (eg rev 0x10)
563 * for now and we know unmasking is safe on this chipset.
564 */
565 for (i = 0; i < 2; i++) {
566 ide_drive_t *drive = &hwif->drives[i];
567 if(drive->present)
568 drive->unmask = 1;
569 }
570 return;
571 }
572 /*
573 * Perform fixups on smart mode. We need to "lose" some
574 * capabilities the firmware lacks but does not filter, and
575 * also patch up some capability bits that it forgets to set
576 * in RAID mode.
577 */
578
579 for(i = 0; i < 2; i++) {
580 ide_drive_t *drive = &hwif->drives[i];
581 struct hd_driveid *id;
582 u16 *idbits;
583
584 if(!drive->present)
585 continue;
586 id = drive->id;
587 idbits = (u16 *)drive->id;
588
589 /* Check for RAID v native */
590 if(strstr(id->model, "Integrated Technology Express")) {
591 /* In raid mode the ident block is slightly buggy
592 We need to set the bits so that the IDE layer knows
593 LBA28. LBA48 and DMA ar valid */
594 id->capability |= 3; /* LBA28, DMA */
595 id->command_set_2 |= 0x0400; /* LBA48 valid */
596 id->cfs_enable_2 |= 0x0400; /* LBA48 on */
597 /* Reporting logic */
598 printk(KERN_INFO "%s: IT8212 %sRAID %d volume",
599 drive->name,
600 idbits[147] ? "Bootable ":"",
601 idbits[129]);
602 if(idbits[129] != 1)
603 printk("(%dK stripe)", idbits[146]);
604 printk(".\n");
605 /* Now the core code will have wrongly decided no DMA
606 so we need to fix this */
607 hwif->ide_dma_off_quietly(drive);
608#ifdef CONFIG_IDEDMA_ONLYDISK
609 if (drive->media == ide_disk)
610#endif
611 hwif->ide_dma_check(drive);
612 } else {
613 /* Non RAID volume. Fixups to stop the core code
614 doing unsupported things */
615 id->field_valid &= 1;
616 id->queue_depth = 0;
617 id->command_set_1 = 0;
618 id->command_set_2 &= 0xC400;
619 id->cfsse &= 0xC000;
620 id->cfs_enable_1 = 0;
621 id->cfs_enable_2 &= 0xC400;
622 id->csf_default &= 0xC000;
623 id->word127 = 0;
624 id->dlf = 0;
625 id->csfo = 0;
626 id->cfa_power = 0;
627 printk(KERN_INFO "%s: Performing identify fixups.\n",
628 drive->name);
629 }
630 }
631
632}
633
634/**
635 * init_hwif_it821x - set up hwif structs
636 * @hwif: interface to set up
637 *
638 * We do the basic set up of the interface structure. The IT8212
639 * requires several custom handlers so we override the default
640 * ide DMA handlers appropriately
641 */
642
643static void __devinit init_hwif_it821x(ide_hwif_t *hwif)
644{
645 struct it821x_dev *idev = kmalloc(sizeof(struct it821x_dev), GFP_KERNEL);
646 u8 conf;
647
648 if(idev == NULL) {
649 printk(KERN_ERR "it821x: out of memory, falling back to legacy behaviour.\n");
650 goto fallback;
651 }
652 memset(idev, 0, sizeof(struct it821x_dev));
653 ide_set_hwifdata(hwif, idev);
654
655 pci_read_config_byte(hwif->pci_dev, 0x50, &conf);
656 if(conf & 1) {
657 idev->smart = 1;
658 hwif->atapi_dma = 0;
659 /* Long I/O's although allowed in LBA48 space cause the
660 onboard firmware to enter the twighlight zone */
661 hwif->rqsize = 256;
662 }
663
664 /* Pull the current clocks from 0x50 also */
665 if (conf & (1 << (1 + hwif->channel)))
666 idev->clock_mode = ATA_50;
667 else
668 idev->clock_mode = ATA_66;
669
670 idev->want[0][1] = ATA_ANY;
671 idev->want[1][1] = ATA_ANY;
672
673 /*
674 * Not in the docs but according to the reference driver
675 * this is neccessary.
676 */
677
678 pci_read_config_byte(hwif->pci_dev, 0x08, &conf);
679 if(conf == 0x10) {
680 idev->timing10 = 1;
681 hwif->atapi_dma = 0;
682 if(!idev->smart)
683 printk(KERN_WARNING "it821x: Revision 0x10, workarounds activated.\n");
684 }
685
686 hwif->speedproc = &it821x_tune_chipset;
687 hwif->tuneproc = &it821x_tuneproc;
688
689 /* MWDMA/PIO clock switching for pass through mode */
690 if(!idev->smart) {
691 hwif->dma_start = &it821x_dma_start;
692 hwif->ide_dma_end = &it821x_dma_end;
693 }
694
695 hwif->drives[0].autotune = 1;
696 hwif->drives[1].autotune = 1;
697
698 if (!hwif->dma_base)
699 goto fallback;
700
701 hwif->ultra_mask = 0x7f;
702 hwif->mwdma_mask = 0x07;
703 hwif->swdma_mask = 0x07;
704
705 hwif->ide_dma_check = &it821x_config_drive_for_dma;
706 if (!(hwif->udma_four))
707 hwif->udma_four = ata66_it821x(hwif);
708
709 /*
710 * The BIOS often doesn't set up DMA on this controller
711 * so we always do it.
712 */
713
714 hwif->autodma = 1;
715 hwif->drives[0].autodma = hwif->autodma;
716 hwif->drives[1].autodma = hwif->autodma;
717 return;
718fallback:
719 hwif->autodma = 0;
720 return;
721}
722
723static void __devinit it8212_disable_raid(struct pci_dev *dev)
724{
725 /* Reset local CPU, and set BIOS not ready */
726 pci_write_config_byte(dev, 0x5E, 0x01);
727
728 /* Set to bypass mode, and reset PCI bus */
729 pci_write_config_byte(dev, 0x50, 0x00);
730 pci_write_config_word(dev, PCI_COMMAND,
731 PCI_COMMAND_PARITY | PCI_COMMAND_IO |
732 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
733 pci_write_config_word(dev, 0x40, 0xA0F3);
734
735 pci_write_config_dword(dev,0x4C, 0x02040204);
736 pci_write_config_byte(dev, 0x42, 0x36);
737 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0);
738}
739
740static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const char *name)
741{
742 u8 conf;
743 static char *mode[2] = { "pass through", "smart" };
744
745 /* Force the card into bypass mode if so requested */
746 if (it8212_noraid) {
747 printk(KERN_INFO "it8212: forcing bypass mode.\n");
748 it8212_disable_raid(dev);
749 }
750 pci_read_config_byte(dev, 0x50, &conf);
751 printk(KERN_INFO "it821x: controller in %s mode.\n", mode[conf & 1]);
752 return 0;
753}
754
755
756#define DECLARE_ITE_DEV(name_str) \
757 { \
758 .name = name_str, \
759 .init_chipset = init_chipset_it821x, \
760 .init_hwif = init_hwif_it821x, \
761 .channels = 2, \
762 .autodma = AUTODMA, \
763 .bootable = ON_BOARD, \
764 .fixup = it821x_fixups \
765 }
766
767static ide_pci_device_t it821x_chipsets[] __devinitdata = {
768 /* 0 */ DECLARE_ITE_DEV("IT8212"),
769};
770
771/**
772 * it821x_init_one - pci layer discovery entry
773 * @dev: PCI device
774 * @id: ident table entry
775 *
776 * Called by the PCI code when it finds an ITE821x controller.
777 * We then use the IDE PCI generic helper to do most of the work.
778 */
779
780static int __devinit it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
781{
782 ide_setup_pci_device(dev, &it821x_chipsets[id->driver_data]);
783 return 0;
784}
785
786static struct pci_device_id it821x_pci_tbl[] = {
787 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
788 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8212, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
789 { 0, },
790};
791
792MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
793
794static struct pci_driver driver = {
795 .name = "ITE821x IDE",
796 .id_table = it821x_pci_tbl,
797 .probe = it821x_init_one,
798};
799
800static int __init it821x_ide_init(void)
801{
802 return ide_pci_register_driver(&driver);
803}
804
805module_init(it821x_ide_init);
806
807module_param_named(noraid, it8212_noraid, int, S_IRUGO);
808MODULE_PARM_DESC(it8212_noraid, "Force card into bypass mode");
809
810MODULE_AUTHOR("Alan Cox");
811MODULE_DESCRIPTION("PCI driver module for the ITE 821x");
812MODULE_LICENSE("GPL");
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 205a32fbc2f0..fcd5142f5cfe 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -195,7 +195,7 @@ static int ns87415_ide_dma_check (ide_drive_t *drive)
195 return __ide_dma_check(drive); 195 return __ide_dma_check(drive);
196} 196}
197 197
198static void __init init_hwif_ns87415 (ide_hwif_t *hwif) 198static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
199{ 199{
200 struct pci_dev *dev = hwif->pci_dev; 200 struct pci_dev *dev = hwif->pci_dev;
201 unsigned int ctrl, using_inta; 201 unsigned int ctrl, using_inta;
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index cf4fd91d396a..7a7c2ef78ac2 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -326,7 +326,7 @@ static void opti621_tune_drive (ide_drive_t *drive, u8 pio)
326/* 326/*
327 * init_hwif_opti621() is called once for each hwif found at boot. 327 * init_hwif_opti621() is called once for each hwif found at boot.
328 */ 328 */
329static void __init init_hwif_opti621 (ide_hwif_t *hwif) 329static void __devinit init_hwif_opti621 (ide_hwif_t *hwif)
330{ 330{
331 hwif->autodma = 0; 331 hwif->autodma = 0;
332 hwif->drives[0].drive_data = PIO_DONT_KNOW; 332 hwif->drives[0].drive_data = PIO_DONT_KNOW;
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 3bc3bf1be49b..10592cec6c43 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -459,7 +459,7 @@ printk("%s: SC1200: resume\n", hwif->name);
459 * This gets invoked by the IDE driver once for each channel, 459 * This gets invoked by the IDE driver once for each channel,
460 * and performs channel-specific pre-initialization before drive probing. 460 * and performs channel-specific pre-initialization before drive probing.
461 */ 461 */
462static void __init init_hwif_sc1200 (ide_hwif_t *hwif) 462static void __devinit init_hwif_sc1200 (ide_hwif_t *hwif)
463{ 463{
464 if (hwif->mate) 464 if (hwif->mate)
465 hwif->serialized = hwif->mate->serialized = 1; 465 hwif->serialized = hwif->mate->serialized = 1;
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 82a1103b2413..c6f5fa4b4ca6 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -442,7 +442,7 @@ static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const cha
442 return (dev->irq) ? dev->irq : 0; 442 return (dev->irq) ? dev->irq : 0;
443} 443}
444 444
445static unsigned int __init ata66_svwks_svwks (ide_hwif_t *hwif) 445static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
446{ 446{
447 return 1; 447 return 1;
448} 448}
@@ -454,7 +454,7 @@ static unsigned int __init ata66_svwks_svwks (ide_hwif_t *hwif)
454 * Bit 14 clear = primary IDE channel does not have 80-pin cable. 454 * Bit 14 clear = primary IDE channel does not have 80-pin cable.
455 * Bit 14 set = primary IDE channel has 80-pin cable. 455 * Bit 14 set = primary IDE channel has 80-pin cable.
456 */ 456 */
457static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif) 457static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
458{ 458{
459 struct pci_dev *dev = hwif->pci_dev; 459 struct pci_dev *dev = hwif->pci_dev;
460 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL && 460 if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
@@ -472,7 +472,7 @@ static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif)
472 * 472 *
473 * WARNING: this only works on Alpine hardware! 473 * WARNING: this only works on Alpine hardware!
474 */ 474 */
475static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif) 475static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
476{ 476{
477 struct pci_dev *dev = hwif->pci_dev; 477 struct pci_dev *dev = hwif->pci_dev;
478 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN && 478 if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
@@ -483,7 +483,7 @@ static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif)
483 return 0; 483 return 0;
484} 484}
485 485
486static unsigned int __init ata66_svwks (ide_hwif_t *hwif) 486static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
487{ 487{
488 struct pci_dev *dev = hwif->pci_dev; 488 struct pci_dev *dev = hwif->pci_dev;
489 489
@@ -573,7 +573,7 @@ static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
573 return ide_setup_pci_device(dev, d); 573 return ide_setup_pci_device(dev, d);
574} 574}
575 575
576static int __init init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d) 576static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
577{ 577{
578 if (!(PCI_FUNC(dev->devfn) & 1)) { 578 if (!(PCI_FUNC(dev->devfn) & 1)) {
579 d->bootable = NEVER_BOARD; 579 d->bootable = NEVER_BOARD;
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 1d970a0de21a..ea0806c82be0 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -386,7 +386,7 @@ static unsigned int sl82c105_bridge_revision(struct pci_dev *dev)
386 * channel 0 here at least, but channel 1 has to be enabled by 386 * channel 0 here at least, but channel 1 has to be enabled by
387 * firmware or arch code. We still set both to 16 bits mode. 387 * firmware or arch code. We still set both to 16 bits mode.
388 */ 388 */
389static unsigned int __init init_chipset_sl82c105(struct pci_dev *dev, const char *msg) 389static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const char *msg)
390{ 390{
391 u32 val; 391 u32 val;
392 392
@@ -399,7 +399,7 @@ static unsigned int __init init_chipset_sl82c105(struct pci_dev *dev, const char
399 return dev->irq; 399 return dev->irq;
400} 400}
401 401
402static void __init init_dma_sl82c105(ide_hwif_t *hwif, unsigned long dma_base) 402static void __devinit init_dma_sl82c105(ide_hwif_t *hwif, unsigned long dma_base)
403{ 403{
404 unsigned int rev; 404 unsigned int rev;
405 u8 dma_state; 405 u8 dma_state;
@@ -431,7 +431,7 @@ static void __init init_dma_sl82c105(ide_hwif_t *hwif, unsigned long dma_base)
431 * Initialise the chip 431 * Initialise the chip
432 */ 432 */
433 433
434static void __init init_hwif_sl82c105(ide_hwif_t *hwif) 434static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
435{ 435{
436 struct pci_dev *dev = hwif->pci_dev; 436 struct pci_dev *dev = hwif->pci_dev;
437 u32 val; 437 u32 val;
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 7fbf36342f73..5112c726633b 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -196,7 +196,7 @@ fast_ata_pio:
196} 196}
197#endif /* CONFIG_BLK_DEV_IDEDMA */ 197#endif /* CONFIG_BLK_DEV_IDEDMA */
198 198
199static void __init init_hwif_slc90e66 (ide_hwif_t *hwif) 199static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
200{ 200{
201 u8 reg47 = 0; 201 u8 reg47 = 0;
202 u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */ 202 u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index a1df2bfe3631..f96b56838f33 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -130,7 +130,7 @@ static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
130 return hwif->ide_dma_off_quietly(drive); 130 return hwif->ide_dma_off_quietly(drive);
131} 131}
132 132
133static void __init init_hwif_triflex(ide_hwif_t *hwif) 133static void __devinit init_hwif_triflex(ide_hwif_t *hwif)
134{ 134{
135 hwif->tuneproc = &triflex_tune_drive; 135 hwif->tuneproc = &triflex_tune_drive;
136 hwif->speedproc = &triflex_tune_chipset; 136 hwif->speedproc = &triflex_tune_chipset;
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 069dbffe2116..a4d099c937ff 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -415,7 +415,7 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive)
415 * and initialize its drive independent registers. 415 * and initialize its drive independent registers.
416 */ 416 */
417 417
418static unsigned int __init init_chipset_via82cxxx(struct pci_dev *dev, const char *name) 418static unsigned int __devinit init_chipset_via82cxxx(struct pci_dev *dev, const char *name)
419{ 419{
420 struct pci_dev *isa = NULL; 420 struct pci_dev *isa = NULL;
421 u8 t, v; 421 u8 t, v;
@@ -576,7 +576,7 @@ static unsigned int __init init_chipset_via82cxxx(struct pci_dev *dev, const cha
576 return 0; 576 return 0;
577} 577}
578 578
579static void __init init_hwif_via82cxxx(ide_hwif_t *hwif) 579static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
580{ 580{
581 int i; 581 int i;
582 582
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 569f16767442..be0fcc8f4b15 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1324,9 +1324,9 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1324 /* XXX FIXME: Media bay stuff need re-organizing */ 1324 /* XXX FIXME: Media bay stuff need re-organizing */
1325 if (np->parent && np->parent->name 1325 if (np->parent && np->parent->name
1326 && strcasecmp(np->parent->name, "media-bay") == 0) { 1326 && strcasecmp(np->parent->name, "media-bay") == 0) {
1327#ifdef CONFIG_PMAC_PBOOK 1327#ifdef CONFIG_PMAC_MEDIABAY
1328 media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index); 1328 media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index);
1329#endif /* CONFIG_PMAC_PBOOK */ 1329#endif /* CONFIG_PMAC_MEDIABAY */
1330 pmif->mediabay = 1; 1330 pmif->mediabay = 1;
1331 if (!bidp) 1331 if (!bidp)
1332 pmif->aapl_bus_id = 1; 1332 pmif->aapl_bus_id = 1;
@@ -1382,10 +1382,10 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1382 hwif->index, model_name[pmif->kind], pmif->aapl_bus_id, 1382 hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
1383 pmif->mediabay ? " (mediabay)" : "", hwif->irq); 1383 pmif->mediabay ? " (mediabay)" : "", hwif->irq);
1384 1384
1385#ifdef CONFIG_PMAC_PBOOK 1385#ifdef CONFIG_PMAC_MEDIABAY
1386 if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0) 1386 if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
1387 hwif->noprobe = 0; 1387 hwif->noprobe = 0;
1388#endif /* CONFIG_PMAC_PBOOK */ 1388#endif /* CONFIG_PMAC_MEDIABAY */
1389 1389
1390 hwif->sg_max_nents = MAX_DCMDS; 1390 hwif->sg_max_nents = MAX_DCMDS;
1391 1391
@@ -1419,7 +1419,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1419 * Attach to a macio probed interface 1419 * Attach to a macio probed interface
1420 */ 1420 */
1421static int __devinit 1421static int __devinit
1422pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match) 1422pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1423{ 1423{
1424 void __iomem *base; 1424 void __iomem *base;
1425 unsigned long regbase; 1425 unsigned long regbase;
@@ -1637,27 +1637,19 @@ pmac_ide_pci_resume(struct pci_dev *pdev)
1637 return rc; 1637 return rc;
1638} 1638}
1639 1639
1640static struct of_match pmac_ide_macio_match[] = 1640static struct of_device_id pmac_ide_macio_match[] =
1641{ 1641{
1642 { 1642 {
1643 .name = "IDE", 1643 .name = "IDE",
1644 .type = OF_ANY_MATCH,
1645 .compatible = OF_ANY_MATCH
1646 }, 1644 },
1647 { 1645 {
1648 .name = "ATA", 1646 .name = "ATA",
1649 .type = OF_ANY_MATCH,
1650 .compatible = OF_ANY_MATCH
1651 }, 1647 },
1652 { 1648 {
1653 .name = OF_ANY_MATCH,
1654 .type = "ide", 1649 .type = "ide",
1655 .compatible = OF_ANY_MATCH
1656 }, 1650 },
1657 { 1651 {
1658 .name = OF_ANY_MATCH,
1659 .type = "ata", 1652 .type = "ata",
1660 .compatible = OF_ANY_MATCH
1661 }, 1653 },
1662 {}, 1654 {},
1663}; 1655};
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index e501675ad72e..77da827b2898 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -847,7 +847,7 @@ static int __init ide_scan_pcidev(struct pci_dev *dev)
847 d = list_entry(l, struct pci_driver, node); 847 d = list_entry(l, struct pci_driver, node);
848 if(d->id_table) 848 if(d->id_table)
849 { 849 {
850 const struct pci_device_id *id = pci_match_device(d->id_table, dev); 850 const struct pci_device_id *id = pci_match_id(d->id_table, dev);
851 if(id != NULL) 851 if(id != NULL)
852 { 852 {
853 if(d->probe(dev, id) >= 0) 853 if(d->probe(dev, id) >= 0)
diff --git a/drivers/ieee1394/Kconfig b/drivers/ieee1394/Kconfig
index 7d58af1ae306..25103a0ef9b3 100644
--- a/drivers/ieee1394/Kconfig
+++ b/drivers/ieee1394/Kconfig
@@ -66,6 +66,18 @@ config IEEE1394_CONFIG_ROM_IP1394
66 with MacOSX and WinXP IP-over-1394), enable this option and the 66 with MacOSX and WinXP IP-over-1394), enable this option and the
67 eth1394 option below. 67 eth1394 option below.
68 68
69config IEEE1394_EXPORT_FULL_API
70 bool "Export all symbols of ieee1394's API"
71 depends on IEEE1394
72 default n
73 help
74 Export all symbols of ieee1394's driver programming interface, even
75 those that are not currently used by the standard IEEE 1394 drivers.
76
77 This option does not affect the interface to userspace applications.
78 Say Y here if you want to compile externally developed drivers that
79 make extended use of ieee1394's API. It is otherwise safe to say N.
80
69comment "Device Drivers" 81comment "Device Drivers"
70 depends on IEEE1394 82 depends on IEEE1394
71 83
diff --git a/drivers/ieee1394/csr.c b/drivers/ieee1394/csr.c
index 1b98684aebcd..149573db91c5 100644
--- a/drivers/ieee1394/csr.c
+++ b/drivers/ieee1394/csr.c
@@ -28,6 +28,7 @@
28#include "hosts.h" 28#include "hosts.h"
29#include "ieee1394.h" 29#include "ieee1394.h"
30#include "highlevel.h" 30#include "highlevel.h"
31#include "ieee1394_core.h"
31 32
32/* Module Parameters */ 33/* Module Parameters */
33/* this module parameter can be used to disable mapping of the FCP registers */ 34/* this module parameter can be used to disable mapping of the FCP registers */
@@ -232,7 +233,7 @@ static void add_host(struct hpsb_host *host)
232 host->csr.generation = 2; 233 host->csr.generation = 2;
233 234
234 bus_info[1] = __constant_cpu_to_be32(0x31333934); 235 bus_info[1] = __constant_cpu_to_be32(0x31333934);
235 bus_info[2] = cpu_to_be32((1 << CSR_IRMC_SHIFT) | 236 bus_info[2] = cpu_to_be32((hpsb_disable_irm ? 0 : 1 << CSR_IRMC_SHIFT) |
236 (1 << CSR_CMC_SHIFT) | 237 (1 << CSR_CMC_SHIFT) |
237 (1 << CSR_ISC_SHIFT) | 238 (1 << CSR_ISC_SHIFT) |
238 (0 << CSR_BMC_SHIFT) | 239 (0 << CSR_BMC_SHIFT) |
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index 7c4330e2e875..61ddd5d37eff 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -209,7 +209,15 @@ void csr1212_init_local_csr(struct csr1212_csr *csr,
209{ 209{
210 static const int mr_map[] = { 4, 64, 1024, 0 }; 210 static const int mr_map[] = { 4, 64, 1024, 0 };
211 211
212#ifdef __KERNEL__
213 BUG_ON(max_rom & ~0x3);
212 csr->max_rom = mr_map[max_rom]; 214 csr->max_rom = mr_map[max_rom];
215#else
216 if (max_rom & ~0x3) /* caller supplied invalid argument */
217 csr->max_rom = 0;
218 else
219 csr->max_rom = mr_map[max_rom];
220#endif
213 memcpy(csr->bus_info_data, bus_info_data, csr->bus_info_len); 221 memcpy(csr->bus_info_data, bus_info_data, csr->bus_info_len);
214} 222}
215 223
@@ -533,12 +541,15 @@ struct csr1212_keyval *csr1212_new_icon_descriptor_leaf(u_int32_t version,
533 static const int pd[4] = { 0, 4, 16, 256 }; 541 static const int pd[4] = { 0, 4, 16, 256 };
534 static const int cs[16] = { 4, 2 }; 542 static const int cs[16] = { 4, 2 };
535 struct csr1212_keyval *kv; 543 struct csr1212_keyval *kv;
536 int palette_size = pd[palette_depth] * cs[color_space]; 544 int palette_size;
537 int pixel_size = (hscan * vscan + 3) & ~0x3; 545 int pixel_size = (hscan * vscan + 3) & ~0x3;
538 546
539 if ((palette_depth && !palette) || !pixels) 547 if (!pixels || (!palette && palette_depth) ||
548 (palette_depth & ~0x3) || (color_space & ~0xf))
540 return NULL; 549 return NULL;
541 550
551 palette_size = pd[palette_depth] * cs[color_space];
552
542 kv = csr1212_new_descriptor_leaf(1, 0, NULL, 553 kv = csr1212_new_descriptor_leaf(1, 0, NULL,
543 palette_size + pixel_size + 554 palette_size + pixel_size +
544 CSR1212_ICON_DESCRIPTOR_LEAF_OVERHEAD); 555 CSR1212_ICON_DESCRIPTOR_LEAF_OVERHEAD);
@@ -760,9 +771,9 @@ static int csr1212_append_new_cache(struct csr1212_csr *csr, size_t romsize)
760 struct csr1212_csr_rom_cache *cache; 771 struct csr1212_csr_rom_cache *cache;
761 u_int64_t csr_addr; 772 u_int64_t csr_addr;
762 773
763 if (!csr || !csr->ops->allocate_addr_range || 774 if (!csr || !csr->ops || !csr->ops->allocate_addr_range ||
764 !csr->ops->release_addr) 775 !csr->ops->release_addr || csr->max_rom < 1)
765 return CSR1212_ENOMEM; 776 return CSR1212_EINVAL;
766 777
767 /* ROM size must be a multiple of csr->max_rom */ 778 /* ROM size must be a multiple of csr->max_rom */
768 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1); 779 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
@@ -1145,6 +1156,8 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
1145 1156
1146 /* Make sure the Extended ROM leaf is a multiple of 1157 /* Make sure the Extended ROM leaf is a multiple of
1147 * max_rom in size. */ 1158 * max_rom in size. */
1159 if (csr->max_rom < 1)
1160 return CSR1212_EINVAL;
1148 leaf_size = (cache->len + (csr->max_rom - 1)) & 1161 leaf_size = (cache->len + (csr->max_rom - 1)) &
1149 ~(csr->max_rom - 1); 1162 ~(csr->max_rom - 1);
1150 1163
@@ -1409,7 +1422,7 @@ int _csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
1409 u_int32_t *cache_ptr; 1422 u_int32_t *cache_ptr;
1410 u_int16_t kv_len = 0; 1423 u_int16_t kv_len = 0;
1411 1424
1412 if (!csr || !kv) 1425 if (!csr || !kv || csr->max_rom < 1)
1413 return CSR1212_EINVAL; 1426 return CSR1212_EINVAL;
1414 1427
1415 /* First find which cache the data should be in (or go in if not read 1428 /* First find which cache the data should be in (or go in if not read
@@ -1572,7 +1585,7 @@ int csr1212_parse_csr(struct csr1212_csr *csr)
1572 struct csr1212_dentry *dentry; 1585 struct csr1212_dentry *dentry;
1573 int ret; 1586 int ret;
1574 1587
1575 if (!csr || !csr->ops->bus_read) 1588 if (!csr || !csr->ops || !csr->ops->bus_read)
1576 return CSR1212_EINVAL; 1589 return CSR1212_EINVAL;
1577 1590
1578 ret = csr1212_parse_bus_info_block(csr); 1591 ret = csr1212_parse_bus_info_block(csr);
@@ -1581,9 +1594,13 @@ int csr1212_parse_csr(struct csr1212_csr *csr)
1581 1594
1582 if (!csr->ops->get_max_rom) 1595 if (!csr->ops->get_max_rom)
1583 csr->max_rom = mr_map[0]; /* default value */ 1596 csr->max_rom = mr_map[0]; /* default value */
1584 else 1597 else {
1585 csr->max_rom = mr_map[csr->ops->get_max_rom(csr->bus_info_data, 1598 int i = csr->ops->get_max_rom(csr->bus_info_data,
1586 csr->private)]; 1599 csr->private);
1600 if (i & ~0x3)
1601 return CSR1212_EINVAL;
1602 csr->max_rom = mr_map[i];
1603 }
1587 1604
1588 csr->cache_head->layout_head = csr->root_kv; 1605 csr->cache_head->layout_head = csr->root_kv;
1589 csr->cache_head->layout_tail = csr->root_kv; 1606 csr->cache_head->layout_tail = csr->root_kv;
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index 758819d1999d..b79ddb43e746 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -158,7 +158,7 @@ static inline int dma_region_find(struct dma_region *dma, unsigned long offset,
158 158
159dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset) 159dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset)
160{ 160{
161 unsigned long rem; 161 unsigned long rem = 0;
162 162
163 struct scatterlist *sg = &dma->sglist[dma_region_find(dma, offset, &rem)]; 163 struct scatterlist *sg = &dma->sglist[dma_region_find(dma, offset, &rem)];
164 return sg_dma_address(sg) + rem; 164 return sg_dma_address(sg) + rem;
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index 654da76bf811..cd53c174ced1 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -89,7 +89,7 @@
89#define TRACE() printk(KERN_ERR "%s:%s[%d] ---- TRACE\n", driver_name, __FUNCTION__, __LINE__) 89#define TRACE() printk(KERN_ERR "%s:%s[%d] ---- TRACE\n", driver_name, __FUNCTION__, __LINE__)
90 90
91static char version[] __devinitdata = 91static char version[] __devinitdata =
92 "$Rev: 1247 $ Ben Collins <bcollins@debian.org>"; 92 "$Rev: 1264 $ Ben Collins <bcollins@debian.org>";
93 93
94struct fragment_info { 94struct fragment_info {
95 struct list_head list; 95 struct list_head list;
@@ -706,7 +706,7 @@ static void ether1394_host_reset (struct hpsb_host *host)
706 return; 706 return;
707 707
708 dev = hi->dev; 708 dev = hi->dev;
709 priv = netdev_priv(dev); 709 priv = (struct eth1394_priv *)netdev_priv(dev);
710 710
711 /* Reset our private host data, but not our mtu */ 711 /* Reset our private host data, but not our mtu */
712 netif_stop_queue (dev); 712 netif_stop_queue (dev);
@@ -1770,7 +1770,7 @@ fail:
1770static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 1770static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1771{ 1771{
1772 strcpy (info->driver, driver_name); 1772 strcpy (info->driver, driver_name);
1773 strcpy (info->version, "$Rev: 1247 $"); 1773 strcpy (info->version, "$Rev: 1264 $");
1774 /* FIXME XXX provide sane businfo */ 1774 /* FIXME XXX provide sane businfo */
1775 strcpy (info->bus_info, "ieee1394"); 1775 strcpy (info->bus_info, "ieee1394");
1776} 1776}
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index 629070b83a33..b248d89de8b4 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -52,7 +52,7 @@
52/* 52/*
53 * Disable the nodemgr detection and config rom reading functionality. 53 * Disable the nodemgr detection and config rom reading functionality.
54 */ 54 */
55static int disable_nodemgr = 0; 55static int disable_nodemgr;
56module_param(disable_nodemgr, int, 0444); 56module_param(disable_nodemgr, int, 0444);
57MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality."); 57MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality.");
58 58
@@ -520,6 +520,9 @@ int hpsb_send_packet(struct hpsb_packet *packet)
520 520
521 if (!packet->no_waiter || packet->expect_response) { 521 if (!packet->no_waiter || packet->expect_response) {
522 atomic_inc(&packet->refcnt); 522 atomic_inc(&packet->refcnt);
523 /* Set the initial "sendtime" to 10 seconds from now, to
524 prevent premature expiry. If a packet takes more than
525 10 seconds to hit the wire, we have bigger problems :) */
523 packet->sendtime = jiffies + 10 * HZ; 526 packet->sendtime = jiffies + 10 * HZ;
524 skb_queue_tail(&host->pending_packet_queue, packet->skb); 527 skb_queue_tail(&host->pending_packet_queue, packet->skb);
525 } 528 }
@@ -1223,9 +1226,7 @@ EXPORT_SYMBOL(hpsb_protocol_class);
1223EXPORT_SYMBOL(hpsb_set_packet_complete_task); 1226EXPORT_SYMBOL(hpsb_set_packet_complete_task);
1224EXPORT_SYMBOL(hpsb_alloc_packet); 1227EXPORT_SYMBOL(hpsb_alloc_packet);
1225EXPORT_SYMBOL(hpsb_free_packet); 1228EXPORT_SYMBOL(hpsb_free_packet);
1226EXPORT_SYMBOL(hpsb_send_phy_config);
1227EXPORT_SYMBOL(hpsb_send_packet); 1229EXPORT_SYMBOL(hpsb_send_packet);
1228EXPORT_SYMBOL(hpsb_send_packet_and_wait);
1229EXPORT_SYMBOL(hpsb_reset_bus); 1230EXPORT_SYMBOL(hpsb_reset_bus);
1230EXPORT_SYMBOL(hpsb_bus_reset); 1231EXPORT_SYMBOL(hpsb_bus_reset);
1231EXPORT_SYMBOL(hpsb_selfid_received); 1232EXPORT_SYMBOL(hpsb_selfid_received);
@@ -1233,6 +1234,10 @@ EXPORT_SYMBOL(hpsb_selfid_complete);
1233EXPORT_SYMBOL(hpsb_packet_sent); 1234EXPORT_SYMBOL(hpsb_packet_sent);
1234EXPORT_SYMBOL(hpsb_packet_received); 1235EXPORT_SYMBOL(hpsb_packet_received);
1235EXPORT_SYMBOL_GPL(hpsb_disable_irm); 1236EXPORT_SYMBOL_GPL(hpsb_disable_irm);
1237#ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1238EXPORT_SYMBOL(hpsb_send_phy_config);
1239EXPORT_SYMBOL(hpsb_send_packet_and_wait);
1240#endif
1236 1241
1237/** ieee1394_transactions.c **/ 1242/** ieee1394_transactions.c **/
1238EXPORT_SYMBOL(hpsb_get_tlabel); 1243EXPORT_SYMBOL(hpsb_get_tlabel);
@@ -1262,9 +1267,11 @@ EXPORT_SYMBOL(hpsb_destroy_hostinfo);
1262EXPORT_SYMBOL(hpsb_set_hostinfo_key); 1267EXPORT_SYMBOL(hpsb_set_hostinfo_key);
1263EXPORT_SYMBOL(hpsb_get_hostinfo_bykey); 1268EXPORT_SYMBOL(hpsb_get_hostinfo_bykey);
1264EXPORT_SYMBOL(hpsb_set_hostinfo); 1269EXPORT_SYMBOL(hpsb_set_hostinfo);
1270EXPORT_SYMBOL(highlevel_host_reset);
1271#ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1265EXPORT_SYMBOL(highlevel_add_host); 1272EXPORT_SYMBOL(highlevel_add_host);
1266EXPORT_SYMBOL(highlevel_remove_host); 1273EXPORT_SYMBOL(highlevel_remove_host);
1267EXPORT_SYMBOL(highlevel_host_reset); 1274#endif
1268 1275
1269/** nodemgr.c **/ 1276/** nodemgr.c **/
1270EXPORT_SYMBOL(hpsb_node_fill_packet); 1277EXPORT_SYMBOL(hpsb_node_fill_packet);
@@ -1272,7 +1279,9 @@ EXPORT_SYMBOL(hpsb_node_write);
1272EXPORT_SYMBOL(hpsb_register_protocol); 1279EXPORT_SYMBOL(hpsb_register_protocol);
1273EXPORT_SYMBOL(hpsb_unregister_protocol); 1280EXPORT_SYMBOL(hpsb_unregister_protocol);
1274EXPORT_SYMBOL(ieee1394_bus_type); 1281EXPORT_SYMBOL(ieee1394_bus_type);
1282#ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1275EXPORT_SYMBOL(nodemgr_for_each_host); 1283EXPORT_SYMBOL(nodemgr_for_each_host);
1284#endif
1276 1285
1277/** csr.c **/ 1286/** csr.c **/
1278EXPORT_SYMBOL(hpsb_update_config_rom); 1287EXPORT_SYMBOL(hpsb_update_config_rom);
@@ -1309,19 +1318,21 @@ EXPORT_SYMBOL(hpsb_iso_wake);
1309EXPORT_SYMBOL(hpsb_iso_recv_flush); 1318EXPORT_SYMBOL(hpsb_iso_recv_flush);
1310 1319
1311/** csr1212.c **/ 1320/** csr1212.c **/
1312EXPORT_SYMBOL(csr1212_create_csr);
1313EXPORT_SYMBOL(csr1212_init_local_csr);
1314EXPORT_SYMBOL(csr1212_new_immediate);
1315EXPORT_SYMBOL(csr1212_new_directory); 1321EXPORT_SYMBOL(csr1212_new_directory);
1316EXPORT_SYMBOL(csr1212_associate_keyval);
1317EXPORT_SYMBOL(csr1212_attach_keyval_to_directory); 1322EXPORT_SYMBOL(csr1212_attach_keyval_to_directory);
1318EXPORT_SYMBOL(csr1212_new_string_descriptor_leaf);
1319EXPORT_SYMBOL(csr1212_detach_keyval_from_directory); 1323EXPORT_SYMBOL(csr1212_detach_keyval_from_directory);
1320EXPORT_SYMBOL(csr1212_release_keyval); 1324EXPORT_SYMBOL(csr1212_release_keyval);
1321EXPORT_SYMBOL(csr1212_destroy_csr);
1322EXPORT_SYMBOL(csr1212_read); 1325EXPORT_SYMBOL(csr1212_read);
1323EXPORT_SYMBOL(csr1212_generate_csr_image);
1324EXPORT_SYMBOL(csr1212_parse_keyval); 1326EXPORT_SYMBOL(csr1212_parse_keyval);
1325EXPORT_SYMBOL(csr1212_parse_csr);
1326EXPORT_SYMBOL(_csr1212_read_keyval); 1327EXPORT_SYMBOL(_csr1212_read_keyval);
1327EXPORT_SYMBOL(_csr1212_destroy_keyval); 1328EXPORT_SYMBOL(_csr1212_destroy_keyval);
1329#ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1330EXPORT_SYMBOL(csr1212_create_csr);
1331EXPORT_SYMBOL(csr1212_init_local_csr);
1332EXPORT_SYMBOL(csr1212_new_immediate);
1333EXPORT_SYMBOL(csr1212_associate_keyval);
1334EXPORT_SYMBOL(csr1212_new_string_descriptor_leaf);
1335EXPORT_SYMBOL(csr1212_destroy_csr);
1336EXPORT_SYMBOL(csr1212_generate_csr_image);
1337EXPORT_SYMBOL(csr1212_parse_csr);
1338#endif
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 73bd8efd2b6c..0b31429d0a68 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -38,8 +38,8 @@ struct hpsb_packet {
38 38
39 /* These are core internal. */ 39 /* These are core internal. */
40 signed char tlabel; 40 signed char tlabel;
41 char ack_code; 41 signed char ack_code;
42 char tcode; 42 unsigned char tcode;
43 43
44 unsigned expect_response:1; 44 unsigned expect_response:1;
45 unsigned no_waiter:1; 45 unsigned no_waiter:1;
diff --git a/drivers/ieee1394/iso.c b/drivers/ieee1394/iso.c
index f05759107f7e..615541b8b90f 100644
--- a/drivers/ieee1394/iso.c
+++ b/drivers/ieee1394/iso.c
@@ -62,10 +62,10 @@ static struct hpsb_iso* hpsb_iso_common_init(struct hpsb_host *host, enum hpsb_i
62 if ((dma_mode < HPSB_ISO_DMA_DEFAULT) || (dma_mode > HPSB_ISO_DMA_PACKET_PER_BUFFER)) 62 if ((dma_mode < HPSB_ISO_DMA_DEFAULT) || (dma_mode > HPSB_ISO_DMA_PACKET_PER_BUFFER))
63 dma_mode=HPSB_ISO_DMA_DEFAULT; 63 dma_mode=HPSB_ISO_DMA_DEFAULT;
64 64
65 if ((irq_interval < 0) || (irq_interval > buf_packets / 4))
66 irq_interval = buf_packets / 4;
65 if (irq_interval == 0) /* really interrupt for each packet*/ 67 if (irq_interval == 0) /* really interrupt for each packet*/
66 irq_interval = 1; 68 irq_interval = 1;
67 else if ((irq_interval < 0) || (irq_interval > buf_packets / 4))
68 irq_interval = buf_packets / 4;
69 69
70 if (channel < -1 || channel >= 64) 70 if (channel < -1 || channel >= 64)
71 return NULL; 71 return NULL;
@@ -106,6 +106,7 @@ static struct hpsb_iso* hpsb_iso_common_init(struct hpsb_host *host, enum hpsb_i
106 } 106 }
107 107
108 atomic_set(&iso->overflows, 0); 108 atomic_set(&iso->overflows, 0);
109 iso->bytes_discarded = 0;
109 iso->flags = 0; 110 iso->flags = 0;
110 iso->prebuffer = 0; 111 iso->prebuffer = 0;
111 112
@@ -241,12 +242,12 @@ int hpsb_iso_xmit_start(struct hpsb_iso *iso, int cycle, int prebuffer)
241 iso->xmit_cycle = cycle; 242 iso->xmit_cycle = cycle;
242 243
243 if (prebuffer < 0) 244 if (prebuffer < 0)
244 prebuffer = iso->buf_packets; 245 prebuffer = iso->buf_packets - 1;
245 else if (prebuffer == 0) 246 else if (prebuffer == 0)
246 prebuffer = 1; 247 prebuffer = 1;
247 248
248 if (prebuffer > iso->buf_packets) 249 if (prebuffer >= iso->buf_packets)
249 prebuffer = iso->buf_packets; 250 prebuffer = iso->buf_packets - 1;
250 251
251 iso->prebuffer = prebuffer; 252 iso->prebuffer = prebuffer;
252 253
@@ -395,7 +396,7 @@ void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error)
395} 396}
396 397
397void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, 398void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
398 u16 cycle, u8 channel, u8 tag, u8 sy) 399 u16 total_len, u16 cycle, u8 channel, u8 tag, u8 sy)
399{ 400{
400 unsigned long flags; 401 unsigned long flags;
401 spin_lock_irqsave(&iso->lock, flags); 402 spin_lock_irqsave(&iso->lock, flags);
@@ -403,10 +404,13 @@ void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
403 if (iso->n_ready_packets == iso->buf_packets) { 404 if (iso->n_ready_packets == iso->buf_packets) {
404 /* overflow! */ 405 /* overflow! */
405 atomic_inc(&iso->overflows); 406 atomic_inc(&iso->overflows);
407 /* Record size of this discarded packet */
408 iso->bytes_discarded += total_len;
406 } else { 409 } else {
407 struct hpsb_iso_packet_info *info = &iso->infos[iso->pkt_dma]; 410 struct hpsb_iso_packet_info *info = &iso->infos[iso->pkt_dma];
408 info->offset = offset; 411 info->offset = offset;
409 info->len = len; 412 info->len = len;
413 info->total_len = total_len;
410 info->cycle = cycle; 414 info->cycle = cycle;
411 info->channel = channel; 415 info->channel = channel;
412 info->tag = tag; 416 info->tag = tag;
@@ -437,6 +441,17 @@ int hpsb_iso_recv_release_packets(struct hpsb_iso *iso, unsigned int n_packets)
437 441
438 iso->first_packet = (iso->first_packet+1) % iso->buf_packets; 442 iso->first_packet = (iso->first_packet+1) % iso->buf_packets;
439 iso->n_ready_packets--; 443 iso->n_ready_packets--;
444
445 /* release memory from packets discarded when queue was full */
446 if (iso->n_ready_packets == 0) { /* Release only after all prior packets handled */
447 if (iso->bytes_discarded != 0) {
448 struct hpsb_iso_packet_info inf;
449 inf.total_len = iso->bytes_discarded;
450 iso->host->driver->isoctl(iso, RECV_RELEASE,
451 (unsigned long) &inf);
452 iso->bytes_discarded = 0;
453 }
454 }
440 } 455 }
441 spin_unlock_irqrestore(&iso->lock, flags); 456 spin_unlock_irqrestore(&iso->lock, flags);
442 return rv; 457 return rv;
diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h
index fb654d9639a7..3efc60b33a88 100644
--- a/drivers/ieee1394/iso.h
+++ b/drivers/ieee1394/iso.h
@@ -47,6 +47,14 @@ struct hpsb_iso_packet_info {
47 /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */ 47 /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */
48 __u8 tag; 48 __u8 tag;
49 __u8 sy; 49 __u8 sy;
50
51 /*
52 * length in bytes of the packet including header/trailer.
53 * MUST be at structure end, since the first part of this structure is also
54 * defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is copied to
55 * userspace and is accessed there through libraw1394.
56 */
57 __u16 total_len;
50}; 58};
51 59
52enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 }; 60enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 };
@@ -111,6 +119,9 @@ struct hpsb_iso {
111 /* how many times the buffer has overflowed or underflowed */ 119 /* how many times the buffer has overflowed or underflowed */
112 atomic_t overflows; 120 atomic_t overflows;
113 121
122 /* Current number of bytes lost in discarded packets */
123 int bytes_discarded;
124
114 /* private flags to track initialization progress */ 125 /* private flags to track initialization progress */
115#define HPSB_ISO_DRIVER_INIT (1<<0) 126#define HPSB_ISO_DRIVER_INIT (1<<0)
116#define HPSB_ISO_DRIVER_STARTED (1<<1) 127#define HPSB_ISO_DRIVER_STARTED (1<<1)
@@ -193,7 +204,7 @@ void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
193 204
194/* call after a packet has been received (interrupt context OK) */ 205/* call after a packet has been received (interrupt context OK) */
195void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, 206void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
196 u16 cycle, u8 channel, u8 tag, u8 sy); 207 u16 total_len, u16 cycle, u8 channel, u8 tag, u8 sy);
197 208
198/* call to wake waiting processes after buffer space has opened up. */ 209/* call to wake waiting processes after buffer space has opened up. */
199void hpsb_iso_wake(struct hpsb_iso *iso); 210void hpsb_iso_wake(struct hpsb_iso *iso);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 9a46c3b44bf8..bebcc47ab06c 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -30,7 +30,7 @@
30#include "csr.h" 30#include "csr.h"
31#include "nodemgr.h" 31#include "nodemgr.h"
32 32
33static int ignore_drivers = 0; 33static int ignore_drivers;
34module_param(ignore_drivers, int, 0444); 34module_param(ignore_drivers, int, 0444);
35MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers."); 35MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers.");
36 36
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index 36e25ac823dc..b12a970cc9a3 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -162,7 +162,7 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
162printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args) 162printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
163 163
164static char version[] __devinitdata = 164static char version[] __devinitdata =
165 "$Rev: 1250 $ Ben Collins <bcollins@debian.org>"; 165 "$Rev: 1299 $ Ben Collins <bcollins@debian.org>";
166 166
167/* Module Parameters */ 167/* Module Parameters */
168static int phys_dma = 1; 168static int phys_dma = 1;
@@ -483,7 +483,9 @@ static void ohci_initialize(struct ti_ohci *ohci)
483 /* Put some defaults to these undefined bus options */ 483 /* Put some defaults to these undefined bus options */
484 buf = reg_read(ohci, OHCI1394_BusOptions); 484 buf = reg_read(ohci, OHCI1394_BusOptions);
485 buf |= 0x60000000; /* Enable CMC and ISC */ 485 buf |= 0x60000000; /* Enable CMC and ISC */
486 if (!hpsb_disable_irm) 486 if (hpsb_disable_irm)
487 buf &= ~0x80000000;
488 else
487 buf |= 0x80000000; /* Enable IRMC */ 489 buf |= 0x80000000; /* Enable IRMC */
488 buf &= ~0x00ff0000; /* XXX: Set cyc_clk_acc to zero for now */ 490 buf &= ~0x00ff0000; /* XXX: Set cyc_clk_acc to zero for now */
489 buf &= ~0x18000000; /* Disable PMC and BMC */ 491 buf &= ~0x18000000; /* Disable PMC and BMC */
@@ -503,8 +505,12 @@ static void ohci_initialize(struct ti_ohci *ohci)
503 reg_write(ohci, OHCI1394_LinkControlSet, 505 reg_write(ohci, OHCI1394_LinkControlSet,
504 OHCI1394_LinkControl_CycleTimerEnable | 506 OHCI1394_LinkControl_CycleTimerEnable |
505 OHCI1394_LinkControl_CycleMaster); 507 OHCI1394_LinkControl_CycleMaster);
506 set_phy_reg_mask(ohci, 4, PHY_04_LCTRL | 508 i = get_phy_reg(ohci, 4) | PHY_04_LCTRL;
507 (hpsb_disable_irm ? 0 : PHY_04_CONTENDER)); 509 if (hpsb_disable_irm)
510 i &= ~PHY_04_CONTENDER;
511 else
512 i |= PHY_04_CONTENDER;
513 set_phy_reg(ohci, 4, i);
508 514
509 /* Set up self-id dma buffer */ 515 /* Set up self-id dma buffer */
510 reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->selfid_buf_bus); 516 reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->selfid_buf_bus);
@@ -1078,7 +1084,8 @@ static int ohci_devctl(struct hpsb_host *host, enum devctl_cmd cmd, int arg)
1078 1084
1079 initialize_dma_rcv_ctx(&ohci->ir_legacy_context, 1); 1085 initialize_dma_rcv_ctx(&ohci->ir_legacy_context, 1);
1080 1086
1081 PRINT(KERN_ERR, "IR legacy activated"); 1087 if (printk_ratelimit())
1088 PRINT(KERN_ERR, "IR legacy activated");
1082 } 1089 }
1083 1090
1084 spin_lock_irqsave(&ohci->IR_channel_lock, flags); 1091 spin_lock_irqsave(&ohci->IR_channel_lock, flags);
@@ -1566,6 +1573,10 @@ static void ohci_iso_recv_release_block(struct ohci_iso_recv *recv, int block)
1566 1573
1567 struct dma_cmd *next = &recv->block[next_i]; 1574 struct dma_cmd *next = &recv->block[next_i];
1568 struct dma_cmd *prev = &recv->block[prev_i]; 1575 struct dma_cmd *prev = &recv->block[prev_i];
1576
1577 /* ignore out-of-range requests */
1578 if ((block < 0) || (block > recv->nblocks))
1579 return;
1569 1580
1570 /* 'next' becomes the new end of the DMA chain, 1581 /* 'next' becomes the new end of the DMA chain,
1571 so disable branch and enable interrupt */ 1582 so disable branch and enable interrupt */
@@ -1593,19 +1604,8 @@ static void ohci_iso_recv_release_block(struct ohci_iso_recv *recv, int block)
1593static void ohci_iso_recv_bufferfill_release(struct ohci_iso_recv *recv, 1604static void ohci_iso_recv_bufferfill_release(struct ohci_iso_recv *recv,
1594 struct hpsb_iso_packet_info *info) 1605 struct hpsb_iso_packet_info *info)
1595{ 1606{
1596 int len;
1597
1598 /* release the memory where the packet was */ 1607 /* release the memory where the packet was */
1599 len = info->len; 1608 recv->released_bytes += info->total_len;
1600
1601 /* add the wasted space for padding to 4 bytes */
1602 if (len % 4)
1603 len += 4 - (len % 4);
1604
1605 /* add 8 bytes for the OHCI DMA data format overhead */
1606 len += 8;
1607
1608 recv->released_bytes += len;
1609 1609
1610 /* have we released enough memory for one block? */ 1610 /* have we released enough memory for one block? */
1611 while (recv->released_bytes > recv->buf_stride) { 1611 while (recv->released_bytes > recv->buf_stride) {
@@ -1637,7 +1637,7 @@ static void ohci_iso_recv_bufferfill_parse(struct hpsb_iso *iso, struct ohci_iso
1637 /* note: packet layout is as shown in section 10.6.1.1 of the OHCI spec */ 1637 /* note: packet layout is as shown in section 10.6.1.1 of the OHCI spec */
1638 1638
1639 unsigned int offset; 1639 unsigned int offset;
1640 unsigned short len, cycle; 1640 unsigned short len, cycle, total_len;
1641 unsigned char channel, tag, sy; 1641 unsigned char channel, tag, sy;
1642 1642
1643 unsigned char *p = iso->data_buf.kvirt; 1643 unsigned char *p = iso->data_buf.kvirt;
@@ -1688,9 +1688,11 @@ static void ohci_iso_recv_bufferfill_parse(struct hpsb_iso *iso, struct ohci_iso
1688 /* advance to xferStatus/timeStamp */ 1688 /* advance to xferStatus/timeStamp */
1689 recv->dma_offset += len; 1689 recv->dma_offset += len;
1690 1690
1691 total_len = len + 8; /* 8 bytes header+trailer in OHCI packet */
1691 /* payload is padded to 4 bytes */ 1692 /* payload is padded to 4 bytes */
1692 if (len % 4) { 1693 if (len % 4) {
1693 recv->dma_offset += 4 - (len%4); 1694 recv->dma_offset += 4 - (len%4);
1695 total_len += 4 - (len%4);
1694 } 1696 }
1695 1697
1696 /* check for wrap-around */ 1698 /* check for wrap-around */
@@ -1724,7 +1726,7 @@ static void ohci_iso_recv_bufferfill_parse(struct hpsb_iso *iso, struct ohci_iso
1724 recv->dma_offset -= recv->buf_stride*recv->nblocks; 1726 recv->dma_offset -= recv->buf_stride*recv->nblocks;
1725 } 1727 }
1726 1728
1727 hpsb_iso_packet_received(iso, offset, len, cycle, channel, tag, sy); 1729 hpsb_iso_packet_received(iso, offset, len, total_len, cycle, channel, tag, sy);
1728 } 1730 }
1729 1731
1730 if (wake) 1732 if (wake)
@@ -1850,7 +1852,8 @@ static void ohci_iso_recv_packetperbuf_task(struct hpsb_iso *iso, struct ohci_is
1850 tag = hdr[5] >> 6; 1852 tag = hdr[5] >> 6;
1851 sy = hdr[4] & 0xF; 1853 sy = hdr[4] & 0xF;
1852 1854
1853 hpsb_iso_packet_received(iso, offset, packet_len, cycle, channel, tag, sy); 1855 hpsb_iso_packet_received(iso, offset, packet_len,
1856 recv->buf_stride, cycle, channel, tag, sy);
1854 } 1857 }
1855 1858
1856 /* reset the DMA descriptor */ 1859 /* reset the DMA descriptor */
@@ -3538,8 +3541,8 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3538 3541
3539static int ohci1394_pci_resume (struct pci_dev *pdev) 3542static int ohci1394_pci_resume (struct pci_dev *pdev)
3540{ 3543{
3541#ifdef CONFIG_PMAC_PBOOK 3544#ifdef CONFIG_PPC_PMAC
3542 { 3545 if (_machine == _MACH_Pmac) {
3543 struct device_node *of_node; 3546 struct device_node *of_node;
3544 3547
3545 /* Re-enable 1394 */ 3548 /* Re-enable 1394 */
@@ -3547,7 +3550,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3547 if (of_node) 3550 if (of_node)
3548 pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1); 3551 pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1);
3549 } 3552 }
3550#endif 3553#endif /* CONFIG_PPC_PMAC */
3551 3554
3552 pci_enable_device(pdev); 3555 pci_enable_device(pdev);
3553 3556
@@ -3557,8 +3560,8 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3557 3560
3558static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3561static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3559{ 3562{
3560#ifdef CONFIG_PMAC_PBOOK 3563#ifdef CONFIG_PPC_PMAC
3561 { 3564 if (_machine == _MACH_Pmac) {
3562 struct device_node *of_node; 3565 struct device_node *of_node;
3563 3566
3564 /* Disable 1394 */ 3567 /* Disable 1394 */
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index bdb3a85cafa6..36074e6eeebb 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -76,7 +76,7 @@
76 76
77 77
78/* Module Parameters */ 78/* Module Parameters */
79static int skip_eeprom = 0; 79static int skip_eeprom;
80module_param(skip_eeprom, int, 0444); 80module_param(skip_eeprom, int, 0444);
81MODULE_PARM_DESC(skip_eeprom, "Use generic bus info block instead of serial eeprom (default = 0)."); 81MODULE_PARM_DESC(skip_eeprom, "Use generic bus info block instead of serial eeprom (default = 0).");
82 82
@@ -1422,7 +1422,7 @@ static int __devinit add_card(struct pci_dev *dev,
1422 i = get_phy_reg(lynx, 4); 1422 i = get_phy_reg(lynx, 4);
1423 i |= PHY_04_LCTRL; 1423 i |= PHY_04_LCTRL;
1424 if (hpsb_disable_irm) 1424 if (hpsb_disable_irm)
1425 i &= !PHY_04_CONTENDER; 1425 i &= ~PHY_04_CONTENDER;
1426 else 1426 else
1427 i |= PHY_04_CONTENDER; 1427 i |= PHY_04_CONTENDER;
1428 if (i != -1) set_phy_reg(lynx, 4, i); 1428 if (i != -1) set_phy_reg(lynx, 4, i);
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 7419af450bd1..b4fa14793fe5 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -98,7 +98,7 @@ static struct hpsb_address_ops arm_ops = {
98 98
99static void queue_complete_cb(struct pending_request *req); 99static void queue_complete_cb(struct pending_request *req);
100 100
101static struct pending_request *__alloc_pending_request(int flags) 101static struct pending_request *__alloc_pending_request(unsigned int __nocast flags)
102{ 102{
103 struct pending_request *req; 103 struct pending_request *req;
104 104
@@ -2506,9 +2506,12 @@ static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2506 if (copy_from_user(&upackets, uaddr, sizeof(upackets))) 2506 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2507 return -EFAULT; 2507 return -EFAULT;
2508 2508
2509 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle)) 2509 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2510 return -EINVAL; 2510 return -EINVAL;
2511 2511
2512 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2513 return -EAGAIN;
2514
2512 /* ensure user-supplied buffer is accessible and big enough */ 2515 /* ensure user-supplied buffer is accessible and big enough */
2513 if (!access_ok(VERIFY_READ, upackets.infos, 2516 if (!access_ok(VERIFY_READ, upackets.infos,
2514 upackets.n_packets * 2517 upackets.n_packets *
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 32368f3428ec..fe3e1703fa61 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -81,7 +81,7 @@
81#include "sbp2.h" 81#include "sbp2.h"
82 82
83static char version[] __devinitdata = 83static char version[] __devinitdata =
84 "$Rev: 1219 $ Ben Collins <bcollins@debian.org>"; 84 "$Rev: 1306 $ Ben Collins <bcollins@debian.org>";
85 85
86/* 86/*
87 * Module load parameter definitions 87 * Module load parameter definitions
@@ -104,7 +104,7 @@ MODULE_PARM_DESC(max_speed, "Force max speed (3 = 800mb, 2 = 400mb default, 1 =
104 * down to us at a time (debugging). This might be necessary for very 104 * down to us at a time (debugging). This might be necessary for very
105 * badly behaved sbp2 devices. 105 * badly behaved sbp2 devices.
106 */ 106 */
107static int serialize_io = 0; 107static int serialize_io;
108module_param(serialize_io, int, 0444); 108module_param(serialize_io, int, 0444);
109MODULE_PARM_DESC(serialize_io, "Serialize all I/O coming down from the scsi drivers (default = 0)"); 109MODULE_PARM_DESC(serialize_io, "Serialize all I/O coming down from the scsi drivers (default = 0)");
110 110
@@ -145,7 +145,7 @@ MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device (default = 1)"
145 * please submit the logged sbp2_firmware_revision value of this device to 145 * please submit the logged sbp2_firmware_revision value of this device to
146 * the linux1394-devel mailing list. 146 * the linux1394-devel mailing list.
147 */ 147 */
148static int force_inquiry_hack = 0; 148static int force_inquiry_hack;
149module_param(force_inquiry_hack, int, 0444); 149module_param(force_inquiry_hack, int, 0444);
150MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)"); 150MODULE_PARM_DESC(force_inquiry_hack, "Force SCSI inquiry hack (default = 0)");
151 151
@@ -2112,6 +2112,102 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id,
2112 */ 2112 */
2113static void sbp2_check_sbp2_command(struct scsi_id_instance_data *scsi_id, unchar *cmd) 2113static void sbp2_check_sbp2_command(struct scsi_id_instance_data *scsi_id, unchar *cmd)
2114{ 2114{
2115 unchar new_cmd[16];
2116 u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
2117
2118 SBP2_DEBUG("sbp2_check_sbp2_command");
2119
2120 switch (*cmd) {
2121
2122 case READ_6:
2123
2124 if (sbp2_command_conversion_device_type(device_type)) {
2125
2126 SBP2_DEBUG("Convert READ_6 to READ_10");
2127
2128 /*
2129 * Need to turn read_6 into read_10
2130 */
2131 new_cmd[0] = 0x28;
2132 new_cmd[1] = (cmd[1] & 0xe0);
2133 new_cmd[2] = 0x0;
2134 new_cmd[3] = (cmd[1] & 0x1f);
2135 new_cmd[4] = cmd[2];
2136 new_cmd[5] = cmd[3];
2137 new_cmd[6] = 0x0;
2138 new_cmd[7] = 0x0;
2139 new_cmd[8] = cmd[4];
2140 new_cmd[9] = cmd[5];
2141
2142 memcpy(cmd, new_cmd, 10);
2143
2144 }
2145
2146 break;
2147
2148 case WRITE_6:
2149
2150 if (sbp2_command_conversion_device_type(device_type)) {
2151
2152 SBP2_DEBUG("Convert WRITE_6 to WRITE_10");
2153
2154 /*
2155 * Need to turn write_6 into write_10
2156 */
2157 new_cmd[0] = 0x2a;
2158 new_cmd[1] = (cmd[1] & 0xe0);
2159 new_cmd[2] = 0x0;
2160 new_cmd[3] = (cmd[1] & 0x1f);
2161 new_cmd[4] = cmd[2];
2162 new_cmd[5] = cmd[3];
2163 new_cmd[6] = 0x0;
2164 new_cmd[7] = 0x0;
2165 new_cmd[8] = cmd[4];
2166 new_cmd[9] = cmd[5];
2167
2168 memcpy(cmd, new_cmd, 10);
2169
2170 }
2171
2172 break;
2173
2174 case MODE_SENSE:
2175
2176 if (sbp2_command_conversion_device_type(device_type)) {
2177
2178 SBP2_DEBUG("Convert MODE_SENSE_6 to MODE_SENSE_10");
2179
2180 /*
2181 * Need to turn mode_sense_6 into mode_sense_10
2182 */
2183 new_cmd[0] = 0x5a;
2184 new_cmd[1] = cmd[1];
2185 new_cmd[2] = cmd[2];
2186 new_cmd[3] = 0x0;
2187 new_cmd[4] = 0x0;
2188 new_cmd[5] = 0x0;
2189 new_cmd[6] = 0x0;
2190 new_cmd[7] = 0x0;
2191 new_cmd[8] = cmd[4];
2192 new_cmd[9] = cmd[5];
2193
2194 memcpy(cmd, new_cmd, 10);
2195
2196 }
2197
2198 break;
2199
2200 case MODE_SELECT:
2201
2202 /*
2203 * TODO. Probably need to change mode select to 10 byte version
2204 */
2205
2206 default:
2207 break;
2208 }
2209
2210 return;
2115} 2211}
2116 2212
2117/* 2213/*
@@ -2152,6 +2248,7 @@ static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2152 struct scsi_cmnd *SCpnt) 2248 struct scsi_cmnd *SCpnt)
2153{ 2249{
2154 u8 *scsi_buf = SCpnt->request_buffer; 2250 u8 *scsi_buf = SCpnt->request_buffer;
2251 u8 device_type = SBP2_DEVICE_TYPE (scsi_id->sbp2_device_type_and_lun);
2155 2252
2156 SBP2_DEBUG("sbp2_check_sbp2_response"); 2253 SBP2_DEBUG("sbp2_check_sbp2_response");
2157 2254
@@ -2176,6 +2273,14 @@ static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2176 } 2273 }
2177 2274
2178 /* 2275 /*
2276 * Check for Simple Direct Access Device and change it to TYPE_DISK
2277 */
2278 if ((scsi_buf[0] & 0x1f) == TYPE_RBC) {
2279 SBP2_DEBUG("Changing TYPE_RBC to TYPE_DISK");
2280 scsi_buf[0] &= 0xe0;
2281 }
2282
2283 /*
2179 * Fix ansi revision and response data format 2284 * Fix ansi revision and response data format
2180 */ 2285 */
2181 scsi_buf[2] |= 2; 2286 scsi_buf[2] |= 2;
@@ -2183,6 +2288,27 @@ static void sbp2_check_sbp2_response(struct scsi_id_instance_data *scsi_id,
2183 2288
2184 break; 2289 break;
2185 2290
2291 case MODE_SENSE:
2292
2293 if (sbp2_command_conversion_device_type(device_type)) {
2294
2295 SBP2_DEBUG("Modify mode sense response (10 byte version)");
2296
2297 scsi_buf[0] = scsi_buf[1]; /* Mode data length */
2298 scsi_buf[1] = scsi_buf[2]; /* Medium type */
2299 scsi_buf[2] = scsi_buf[3]; /* Device specific parameter */
2300 scsi_buf[3] = scsi_buf[7]; /* Block descriptor length */
2301 memcpy(scsi_buf + 4, scsi_buf + 8, scsi_buf[0]);
2302 }
2303
2304 break;
2305
2306 case MODE_SELECT:
2307
2308 /*
2309 * TODO. Probably need to change mode select to 10 byte version
2310 */
2311
2186 default: 2312 default:
2187 break; 2313 break;
2188 } 2314 }
@@ -2559,8 +2685,7 @@ static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id,
2559static int sbp2scsi_slave_configure (struct scsi_device *sdev) 2685static int sbp2scsi_slave_configure (struct scsi_device *sdev)
2560{ 2686{
2561 blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); 2687 blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
2562 sdev->use_10_for_rw = 1; 2688
2563 sdev->use_10_for_ms = 1;
2564 return 0; 2689 return 0;
2565} 2690}
2566 2691
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 3cc3ff0cccb1..79c8e2dd9c33 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -7,6 +7,16 @@ config INFINIBAND
7 any protocols you wish to use as well as drivers for your 7 any protocols you wish to use as well as drivers for your
8 InfiniBand hardware. 8 InfiniBand hardware.
9 9
10config INFINIBAND_USER_VERBS
11 tristate "InfiniBand userspace verbs support"
12 depends on INFINIBAND
13 ---help---
14 Userspace InfiniBand verbs support. This is the kernel side
15 of userspace verbs, which allows userspace processes to
16 directly access InfiniBand hardware for fast-path
17 operations. You will also need libibverbs and a hardware
18 driver library from <http://www.openib.org>.
19
10source "drivers/infiniband/hw/mthca/Kconfig" 20source "drivers/infiniband/hw/mthca/Kconfig"
11 21
12source "drivers/infiniband/ulp/ipoib/Kconfig" 22source "drivers/infiniband/ulp/ipoib/Kconfig"
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index d2dbfb52c0a3..e1a7cf3e8636 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -1,6 +1,7 @@
1EXTRA_CFLAGS += -Idrivers/infiniband/include 1EXTRA_CFLAGS += -Idrivers/infiniband/include
2 2
3obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o ib_umad.o 3obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o ib_umad.o
4obj-$(CONFIG_INFINIBAND_USER_VERBS) += ib_uverbs.o
4 5
5ib_core-y := packer.o ud_header.o verbs.o sysfs.o \ 6ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
6 device.o fmr_pool.o cache.o 7 device.o fmr_pool.o cache.o
@@ -10,3 +11,5 @@ ib_mad-y := mad.o smi.o agent.o
10ib_sa-y := sa_query.o 11ib_sa-y := sa_query.o
11 12
12ib_umad-y := user_mad.o 13ib_umad-y := user_mad.o
14
15ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_mem.o
diff --git a/drivers/infiniband/core/packer.c b/drivers/infiniband/core/packer.c
index 5f15feffeae2..eb5ff54c10d7 100644
--- a/drivers/infiniband/core/packer.c
+++ b/drivers/infiniband/core/packer.c
@@ -96,7 +96,7 @@ void ib_pack(const struct ib_field *desc,
96 else 96 else
97 val = 0; 97 val = 0;
98 98
99 mask = cpu_to_be64(((1ull << desc[i].size_bits) - 1) << shift); 99 mask = cpu_to_be64((~0ull >> (64 - desc[i].size_bits)) << shift);
100 addr = (__be64 *) ((__be32 *) buf + desc[i].offset_words); 100 addr = (__be64 *) ((__be32 *) buf + desc[i].offset_words);
101 *addr = (*addr & ~mask) | (cpu_to_be64(val) & mask); 101 *addr = (*addr & ~mask) | (cpu_to_be64(val) & mask);
102 } else { 102 } else {
@@ -176,7 +176,7 @@ void ib_unpack(const struct ib_field *desc,
176 __be64 *addr; 176 __be64 *addr;
177 177
178 shift = 64 - desc[i].offset_bits - desc[i].size_bits; 178 shift = 64 - desc[i].offset_bits - desc[i].size_bits;
179 mask = ((1ull << desc[i].size_bits) - 1) << shift; 179 mask = (~0ull >> (64 - desc[i].size_bits)) << shift;
180 addr = (__be64 *) buf + desc[i].offset_words; 180 addr = (__be64 *) buf + desc[i].offset_words;
181 val = (be64_to_cpup(addr) & mask) >> shift; 181 val = (be64_to_cpup(addr) & mask) >> shift;
182 value_write(desc[i].struct_offset_bytes, 182 value_write(desc[i].struct_offset_bytes,
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 276e1a53010d..5a08e81fa827 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -507,7 +507,13 @@ retry:
507 spin_unlock_irqrestore(&idr_lock, flags); 507 spin_unlock_irqrestore(&idr_lock, flags);
508 } 508 }
509 509
510 return ret; 510 /*
511 * It's not safe to dereference query any more, because the
512 * send may already have completed and freed the query in
513 * another context. So use wr.wr_id, which has a copy of the
514 * query's id.
515 */
516 return ret ? ret : wr.wr_id;
511} 517}
512 518
513static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query, 519static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
@@ -598,14 +604,15 @@ int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
598 rec, query->sa_query.mad->data); 604 rec, query->sa_query.mad->data);
599 605
600 *sa_query = &query->sa_query; 606 *sa_query = &query->sa_query;
607
601 ret = send_mad(&query->sa_query, timeout_ms); 608 ret = send_mad(&query->sa_query, timeout_ms);
602 if (ret) { 609 if (ret < 0) {
603 *sa_query = NULL; 610 *sa_query = NULL;
604 kfree(query->sa_query.mad); 611 kfree(query->sa_query.mad);
605 kfree(query); 612 kfree(query);
606 } 613 }
607 614
608 return ret ? ret : query->sa_query.id; 615 return ret;
609} 616}
610EXPORT_SYMBOL(ib_sa_path_rec_get); 617EXPORT_SYMBOL(ib_sa_path_rec_get);
611 618
@@ -674,14 +681,15 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
674 rec, query->sa_query.mad->data); 681 rec, query->sa_query.mad->data);
675 682
676 *sa_query = &query->sa_query; 683 *sa_query = &query->sa_query;
684
677 ret = send_mad(&query->sa_query, timeout_ms); 685 ret = send_mad(&query->sa_query, timeout_ms);
678 if (ret) { 686 if (ret < 0) {
679 *sa_query = NULL; 687 *sa_query = NULL;
680 kfree(query->sa_query.mad); 688 kfree(query->sa_query.mad);
681 kfree(query); 689 kfree(query);
682 } 690 }
683 691
684 return ret ? ret : query->sa_query.id; 692 return ret;
685} 693}
686EXPORT_SYMBOL(ib_sa_mcmember_rec_query); 694EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
687 695
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
new file mode 100644
index 000000000000..57347f1e82c1
--- /dev/null
+++ b/drivers/infiniband/core/uverbs.h
@@ -0,0 +1,132 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: uverbs.h 2559 2005-06-06 19:43:16Z roland $
34 */
35
36#ifndef UVERBS_H
37#define UVERBS_H
38
39/* Include device.h and fs.h until cdev.h is self-sufficient */
40#include <linux/fs.h>
41#include <linux/device.h>
42#include <linux/cdev.h>
43#include <linux/kref.h>
44#include <linux/idr.h>
45
46#include <ib_verbs.h>
47#include <ib_user_verbs.h>
48
49struct ib_uverbs_device {
50 int devnum;
51 struct cdev dev;
52 struct class_device class_dev;
53 struct ib_device *ib_dev;
54 int num_comp;
55};
56
57struct ib_uverbs_event_file {
58 struct kref ref;
59 struct ib_uverbs_file *uverbs_file;
60 spinlock_t lock;
61 int fd;
62 int is_async;
63 wait_queue_head_t poll_wait;
64 struct list_head event_list;
65};
66
67struct ib_uverbs_file {
68 struct kref ref;
69 struct ib_uverbs_device *device;
70 struct ib_ucontext *ucontext;
71 struct ib_event_handler event_handler;
72 struct ib_uverbs_event_file async_file;
73 struct ib_uverbs_event_file comp_file[1];
74};
75
76struct ib_uverbs_async_event {
77 struct ib_uverbs_async_event_desc desc;
78 struct list_head list;
79};
80
81struct ib_uverbs_comp_event {
82 struct ib_uverbs_comp_event_desc desc;
83 struct list_head list;
84};
85
86struct ib_uobject_mr {
87 struct ib_uobject uobj;
88 struct page *page_list;
89 struct scatterlist *sg_list;
90};
91
92extern struct semaphore ib_uverbs_idr_mutex;
93extern struct idr ib_uverbs_pd_idr;
94extern struct idr ib_uverbs_mr_idr;
95extern struct idr ib_uverbs_mw_idr;
96extern struct idr ib_uverbs_ah_idr;
97extern struct idr ib_uverbs_cq_idr;
98extern struct idr ib_uverbs_qp_idr;
99
100void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
101void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
102void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
103
104int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
105 void *addr, size_t size, int write);
106void ib_umem_release(struct ib_device *dev, struct ib_umem *umem);
107void ib_umem_release_on_close(struct ib_device *dev, struct ib_umem *umem);
108
109#define IB_UVERBS_DECLARE_CMD(name) \
110 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
111 const char __user *buf, int in_len, \
112 int out_len)
113
114IB_UVERBS_DECLARE_CMD(query_params);
115IB_UVERBS_DECLARE_CMD(get_context);
116IB_UVERBS_DECLARE_CMD(query_device);
117IB_UVERBS_DECLARE_CMD(query_port);
118IB_UVERBS_DECLARE_CMD(query_gid);
119IB_UVERBS_DECLARE_CMD(query_pkey);
120IB_UVERBS_DECLARE_CMD(alloc_pd);
121IB_UVERBS_DECLARE_CMD(dealloc_pd);
122IB_UVERBS_DECLARE_CMD(reg_mr);
123IB_UVERBS_DECLARE_CMD(dereg_mr);
124IB_UVERBS_DECLARE_CMD(create_cq);
125IB_UVERBS_DECLARE_CMD(destroy_cq);
126IB_UVERBS_DECLARE_CMD(create_qp);
127IB_UVERBS_DECLARE_CMD(modify_qp);
128IB_UVERBS_DECLARE_CMD(destroy_qp);
129IB_UVERBS_DECLARE_CMD(attach_mcast);
130IB_UVERBS_DECLARE_CMD(detach_mcast);
131
132#endif /* UVERBS_H */
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
new file mode 100644
index 000000000000..5f2bbcda4c73
--- /dev/null
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -0,0 +1,1006 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: uverbs_cmd.c 2708 2005-06-24 17:27:21Z roland $
34 */
35
36#include <asm/uaccess.h>
37
38#include "uverbs.h"
39
40#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
41 do { \
42 (udata)->inbuf = (void __user *) (ibuf); \
43 (udata)->outbuf = (void __user *) (obuf); \
44 (udata)->inlen = (ilen); \
45 (udata)->outlen = (olen); \
46 } while (0)
47
48ssize_t ib_uverbs_query_params(struct ib_uverbs_file *file,
49 const char __user *buf,
50 int in_len, int out_len)
51{
52 struct ib_uverbs_query_params cmd;
53 struct ib_uverbs_query_params_resp resp;
54
55 if (out_len < sizeof resp)
56 return -ENOSPC;
57
58 if (copy_from_user(&cmd, buf, sizeof cmd))
59 return -EFAULT;
60
61 memset(&resp, 0, sizeof resp);
62
63 resp.num_cq_events = file->device->num_comp;
64
65 if (copy_to_user((void __user *) (unsigned long) cmd.response, &resp, sizeof resp))
66 return -EFAULT;
67
68 return in_len;
69}
70
71ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
72 const char __user *buf,
73 int in_len, int out_len)
74{
75 struct ib_uverbs_get_context cmd;
76 struct ib_uverbs_get_context_resp resp;
77 struct ib_udata udata;
78 struct ib_device *ibdev = file->device->ib_dev;
79 int i;
80 int ret = in_len;
81
82 if (out_len < sizeof resp)
83 return -ENOSPC;
84
85 if (copy_from_user(&cmd, buf, sizeof cmd))
86 return -EFAULT;
87
88 INIT_UDATA(&udata, buf + sizeof cmd,
89 (unsigned long) cmd.response + sizeof resp,
90 in_len - sizeof cmd, out_len - sizeof resp);
91
92 file->ucontext = ibdev->alloc_ucontext(ibdev, &udata);
93 if (IS_ERR(file->ucontext)) {
94 ret = PTR_ERR(file->ucontext);
95 file->ucontext = NULL;
96 return ret;
97 }
98
99 file->ucontext->device = ibdev;
100 INIT_LIST_HEAD(&file->ucontext->pd_list);
101 INIT_LIST_HEAD(&file->ucontext->mr_list);
102 INIT_LIST_HEAD(&file->ucontext->mw_list);
103 INIT_LIST_HEAD(&file->ucontext->cq_list);
104 INIT_LIST_HEAD(&file->ucontext->qp_list);
105 INIT_LIST_HEAD(&file->ucontext->srq_list);
106 INIT_LIST_HEAD(&file->ucontext->ah_list);
107 spin_lock_init(&file->ucontext->lock);
108
109 resp.async_fd = file->async_file.fd;
110 for (i = 0; i < file->device->num_comp; ++i)
111 if (copy_to_user((void __user *) (unsigned long) cmd.cq_fd_tab +
112 i * sizeof (__u32),
113 &file->comp_file[i].fd, sizeof (__u32)))
114 goto err;
115
116 if (copy_to_user((void __user *) (unsigned long) cmd.response,
117 &resp, sizeof resp))
118 goto err;
119
120 return in_len;
121
122err:
123 ibdev->dealloc_ucontext(file->ucontext);
124 file->ucontext = NULL;
125
126 return -EFAULT;
127}
128
129ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
130 const char __user *buf,
131 int in_len, int out_len)
132{
133 struct ib_uverbs_query_device cmd;
134 struct ib_uverbs_query_device_resp resp;
135 struct ib_device_attr attr;
136 int ret;
137
138 if (out_len < sizeof resp)
139 return -ENOSPC;
140
141 if (copy_from_user(&cmd, buf, sizeof cmd))
142 return -EFAULT;
143
144 ret = ib_query_device(file->device->ib_dev, &attr);
145 if (ret)
146 return ret;
147
148 memset(&resp, 0, sizeof resp);
149
150 resp.fw_ver = attr.fw_ver;
151 resp.node_guid = attr.node_guid;
152 resp.sys_image_guid = attr.sys_image_guid;
153 resp.max_mr_size = attr.max_mr_size;
154 resp.page_size_cap = attr.page_size_cap;
155 resp.vendor_id = attr.vendor_id;
156 resp.vendor_part_id = attr.vendor_part_id;
157 resp.hw_ver = attr.hw_ver;
158 resp.max_qp = attr.max_qp;
159 resp.max_qp_wr = attr.max_qp_wr;
160 resp.device_cap_flags = attr.device_cap_flags;
161 resp.max_sge = attr.max_sge;
162 resp.max_sge_rd = attr.max_sge_rd;
163 resp.max_cq = attr.max_cq;
164 resp.max_cqe = attr.max_cqe;
165 resp.max_mr = attr.max_mr;
166 resp.max_pd = attr.max_pd;
167 resp.max_qp_rd_atom = attr.max_qp_rd_atom;
168 resp.max_ee_rd_atom = attr.max_ee_rd_atom;
169 resp.max_res_rd_atom = attr.max_res_rd_atom;
170 resp.max_qp_init_rd_atom = attr.max_qp_init_rd_atom;
171 resp.max_ee_init_rd_atom = attr.max_ee_init_rd_atom;
172 resp.atomic_cap = attr.atomic_cap;
173 resp.max_ee = attr.max_ee;
174 resp.max_rdd = attr.max_rdd;
175 resp.max_mw = attr.max_mw;
176 resp.max_raw_ipv6_qp = attr.max_raw_ipv6_qp;
177 resp.max_raw_ethy_qp = attr.max_raw_ethy_qp;
178 resp.max_mcast_grp = attr.max_mcast_grp;
179 resp.max_mcast_qp_attach = attr.max_mcast_qp_attach;
180 resp.max_total_mcast_qp_attach = attr.max_total_mcast_qp_attach;
181 resp.max_ah = attr.max_ah;
182 resp.max_fmr = attr.max_fmr;
183 resp.max_map_per_fmr = attr.max_map_per_fmr;
184 resp.max_srq = attr.max_srq;
185 resp.max_srq_wr = attr.max_srq_wr;
186 resp.max_srq_sge = attr.max_srq_sge;
187 resp.max_pkeys = attr.max_pkeys;
188 resp.local_ca_ack_delay = attr.local_ca_ack_delay;
189 resp.phys_port_cnt = file->device->ib_dev->phys_port_cnt;
190
191 if (copy_to_user((void __user *) (unsigned long) cmd.response,
192 &resp, sizeof resp))
193 return -EFAULT;
194
195 return in_len;
196}
197
198ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
199 const char __user *buf,
200 int in_len, int out_len)
201{
202 struct ib_uverbs_query_port cmd;
203 struct ib_uverbs_query_port_resp resp;
204 struct ib_port_attr attr;
205 int ret;
206
207 if (out_len < sizeof resp)
208 return -ENOSPC;
209
210 if (copy_from_user(&cmd, buf, sizeof cmd))
211 return -EFAULT;
212
213 ret = ib_query_port(file->device->ib_dev, cmd.port_num, &attr);
214 if (ret)
215 return ret;
216
217 memset(&resp, 0, sizeof resp);
218
219 resp.state = attr.state;
220 resp.max_mtu = attr.max_mtu;
221 resp.active_mtu = attr.active_mtu;
222 resp.gid_tbl_len = attr.gid_tbl_len;
223 resp.port_cap_flags = attr.port_cap_flags;
224 resp.max_msg_sz = attr.max_msg_sz;
225 resp.bad_pkey_cntr = attr.bad_pkey_cntr;
226 resp.qkey_viol_cntr = attr.qkey_viol_cntr;
227 resp.pkey_tbl_len = attr.pkey_tbl_len;
228 resp.lid = attr.lid;
229 resp.sm_lid = attr.sm_lid;
230 resp.lmc = attr.lmc;
231 resp.max_vl_num = attr.max_vl_num;
232 resp.sm_sl = attr.sm_sl;
233 resp.subnet_timeout = attr.subnet_timeout;
234 resp.init_type_reply = attr.init_type_reply;
235 resp.active_width = attr.active_width;
236 resp.active_speed = attr.active_speed;
237 resp.phys_state = attr.phys_state;
238
239 if (copy_to_user((void __user *) (unsigned long) cmd.response,
240 &resp, sizeof resp))
241 return -EFAULT;
242
243 return in_len;
244}
245
246ssize_t ib_uverbs_query_gid(struct ib_uverbs_file *file,
247 const char __user *buf,
248 int in_len, int out_len)
249{
250 struct ib_uverbs_query_gid cmd;
251 struct ib_uverbs_query_gid_resp resp;
252 int ret;
253
254 if (out_len < sizeof resp)
255 return -ENOSPC;
256
257 if (copy_from_user(&cmd, buf, sizeof cmd))
258 return -EFAULT;
259
260 memset(&resp, 0, sizeof resp);
261
262 ret = ib_query_gid(file->device->ib_dev, cmd.port_num, cmd.index,
263 (union ib_gid *) resp.gid);
264 if (ret)
265 return ret;
266
267 if (copy_to_user((void __user *) (unsigned long) cmd.response,
268 &resp, sizeof resp))
269 return -EFAULT;
270
271 return in_len;
272}
273
274ssize_t ib_uverbs_query_pkey(struct ib_uverbs_file *file,
275 const char __user *buf,
276 int in_len, int out_len)
277{
278 struct ib_uverbs_query_pkey cmd;
279 struct ib_uverbs_query_pkey_resp resp;
280 int ret;
281
282 if (out_len < sizeof resp)
283 return -ENOSPC;
284
285 if (copy_from_user(&cmd, buf, sizeof cmd))
286 return -EFAULT;
287
288 memset(&resp, 0, sizeof resp);
289
290 ret = ib_query_pkey(file->device->ib_dev, cmd.port_num, cmd.index,
291 &resp.pkey);
292 if (ret)
293 return ret;
294
295 if (copy_to_user((void __user *) (unsigned long) cmd.response,
296 &resp, sizeof resp))
297 return -EFAULT;
298
299 return in_len;
300}
301
302ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
303 const char __user *buf,
304 int in_len, int out_len)
305{
306 struct ib_uverbs_alloc_pd cmd;
307 struct ib_uverbs_alloc_pd_resp resp;
308 struct ib_udata udata;
309 struct ib_uobject *uobj;
310 struct ib_pd *pd;
311 int ret;
312
313 if (out_len < sizeof resp)
314 return -ENOSPC;
315
316 if (copy_from_user(&cmd, buf, sizeof cmd))
317 return -EFAULT;
318
319 INIT_UDATA(&udata, buf + sizeof cmd,
320 (unsigned long) cmd.response + sizeof resp,
321 in_len - sizeof cmd, out_len - sizeof resp);
322
323 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
324 if (!uobj)
325 return -ENOMEM;
326
327 uobj->context = file->ucontext;
328
329 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev,
330 file->ucontext, &udata);
331 if (IS_ERR(pd)) {
332 ret = PTR_ERR(pd);
333 goto err;
334 }
335
336 pd->device = file->device->ib_dev;
337 pd->uobject = uobj;
338 atomic_set(&pd->usecnt, 0);
339
340retry:
341 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) {
342 ret = -ENOMEM;
343 goto err_pd;
344 }
345
346 down(&ib_uverbs_idr_mutex);
347 ret = idr_get_new(&ib_uverbs_pd_idr, pd, &uobj->id);
348 up(&ib_uverbs_idr_mutex);
349
350 if (ret == -EAGAIN)
351 goto retry;
352 if (ret)
353 goto err_pd;
354
355 spin_lock_irq(&file->ucontext->lock);
356 list_add_tail(&uobj->list, &file->ucontext->pd_list);
357 spin_unlock_irq(&file->ucontext->lock);
358
359 memset(&resp, 0, sizeof resp);
360 resp.pd_handle = uobj->id;
361
362 if (copy_to_user((void __user *) (unsigned long) cmd.response,
363 &resp, sizeof resp)) {
364 ret = -EFAULT;
365 goto err_list;
366 }
367
368 return in_len;
369
370err_list:
371 spin_lock_irq(&file->ucontext->lock);
372 list_del(&uobj->list);
373 spin_unlock_irq(&file->ucontext->lock);
374
375 down(&ib_uverbs_idr_mutex);
376 idr_remove(&ib_uverbs_pd_idr, uobj->id);
377 up(&ib_uverbs_idr_mutex);
378
379err_pd:
380 ib_dealloc_pd(pd);
381
382err:
383 kfree(uobj);
384 return ret;
385}
386
387ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
388 const char __user *buf,
389 int in_len, int out_len)
390{
391 struct ib_uverbs_dealloc_pd cmd;
392 struct ib_pd *pd;
393 struct ib_uobject *uobj;
394 int ret = -EINVAL;
395
396 if (copy_from_user(&cmd, buf, sizeof cmd))
397 return -EFAULT;
398
399 down(&ib_uverbs_idr_mutex);
400
401 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
402 if (!pd || pd->uobject->context != file->ucontext)
403 goto out;
404
405 uobj = pd->uobject;
406
407 ret = ib_dealloc_pd(pd);
408 if (ret)
409 goto out;
410
411 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle);
412
413 spin_lock_irq(&file->ucontext->lock);
414 list_del(&uobj->list);
415 spin_unlock_irq(&file->ucontext->lock);
416
417 kfree(uobj);
418
419out:
420 up(&ib_uverbs_idr_mutex);
421
422 return ret ? ret : in_len;
423}
424
425ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
426 const char __user *buf, int in_len,
427 int out_len)
428{
429 struct ib_uverbs_reg_mr cmd;
430 struct ib_uverbs_reg_mr_resp resp;
431 struct ib_udata udata;
432 struct ib_umem_object *obj;
433 struct ib_pd *pd;
434 struct ib_mr *mr;
435 int ret;
436
437 if (out_len < sizeof resp)
438 return -ENOSPC;
439
440 if (copy_from_user(&cmd, buf, sizeof cmd))
441 return -EFAULT;
442
443 INIT_UDATA(&udata, buf + sizeof cmd,
444 (unsigned long) cmd.response + sizeof resp,
445 in_len - sizeof cmd, out_len - sizeof resp);
446
447 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
448 return -EINVAL;
449
450 obj = kmalloc(sizeof *obj, GFP_KERNEL);
451 if (!obj)
452 return -ENOMEM;
453
454 obj->uobject.context = file->ucontext;
455
456 /*
457 * We ask for writable memory if any access flags other than
458 * "remote read" are set. "Local write" and "remote write"
459 * obviously require write access. "Remote atomic" can do
460 * things like fetch and add, which will modify memory, and
461 * "MW bind" can change permissions by binding a window.
462 */
463 ret = ib_umem_get(file->device->ib_dev, &obj->umem,
464 (void *) (unsigned long) cmd.start, cmd.length,
465 !!(cmd.access_flags & ~IB_ACCESS_REMOTE_READ));
466 if (ret)
467 goto err_free;
468
469 obj->umem.virt_base = cmd.hca_va;
470
471 down(&ib_uverbs_idr_mutex);
472
473 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
474 if (!pd || pd->uobject->context != file->ucontext) {
475 ret = -EINVAL;
476 goto err_up;
477 }
478
479 if (!pd->device->reg_user_mr) {
480 ret = -ENOSYS;
481 goto err_up;
482 }
483
484 mr = pd->device->reg_user_mr(pd, &obj->umem, cmd.access_flags, &udata);
485 if (IS_ERR(mr)) {
486 ret = PTR_ERR(mr);
487 goto err_up;
488 }
489
490 mr->device = pd->device;
491 mr->pd = pd;
492 mr->uobject = &obj->uobject;
493 atomic_inc(&pd->usecnt);
494 atomic_set(&mr->usecnt, 0);
495
496 memset(&resp, 0, sizeof resp);
497 resp.lkey = mr->lkey;
498 resp.rkey = mr->rkey;
499
500retry:
501 if (!idr_pre_get(&ib_uverbs_mr_idr, GFP_KERNEL)) {
502 ret = -ENOMEM;
503 goto err_unreg;
504 }
505
506 ret = idr_get_new(&ib_uverbs_mr_idr, mr, &obj->uobject.id);
507
508 if (ret == -EAGAIN)
509 goto retry;
510 if (ret)
511 goto err_unreg;
512
513 resp.mr_handle = obj->uobject.id;
514
515 spin_lock_irq(&file->ucontext->lock);
516 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
517 spin_unlock_irq(&file->ucontext->lock);
518
519 if (copy_to_user((void __user *) (unsigned long) cmd.response,
520 &resp, sizeof resp)) {
521 ret = -EFAULT;
522 goto err_list;
523 }
524
525 up(&ib_uverbs_idr_mutex);
526
527 return in_len;
528
529err_list:
530 spin_lock_irq(&file->ucontext->lock);
531 list_del(&obj->uobject.list);
532 spin_unlock_irq(&file->ucontext->lock);
533
534err_unreg:
535 ib_dereg_mr(mr);
536
537err_up:
538 up(&ib_uverbs_idr_mutex);
539
540 ib_umem_release(file->device->ib_dev, &obj->umem);
541
542err_free:
543 kfree(obj);
544 return ret;
545}
546
547ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
548 const char __user *buf, int in_len,
549 int out_len)
550{
551 struct ib_uverbs_dereg_mr cmd;
552 struct ib_mr *mr;
553 struct ib_umem_object *memobj;
554 int ret = -EINVAL;
555
556 if (copy_from_user(&cmd, buf, sizeof cmd))
557 return -EFAULT;
558
559 down(&ib_uverbs_idr_mutex);
560
561 mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle);
562 if (!mr || mr->uobject->context != file->ucontext)
563 goto out;
564
565 memobj = container_of(mr->uobject, struct ib_umem_object, uobject);
566
567 ret = ib_dereg_mr(mr);
568 if (ret)
569 goto out;
570
571 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle);
572
573 spin_lock_irq(&file->ucontext->lock);
574 list_del(&memobj->uobject.list);
575 spin_unlock_irq(&file->ucontext->lock);
576
577 ib_umem_release(file->device->ib_dev, &memobj->umem);
578 kfree(memobj);
579
580out:
581 up(&ib_uverbs_idr_mutex);
582
583 return ret ? ret : in_len;
584}
585
586ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
587 const char __user *buf, int in_len,
588 int out_len)
589{
590 struct ib_uverbs_create_cq cmd;
591 struct ib_uverbs_create_cq_resp resp;
592 struct ib_udata udata;
593 struct ib_uobject *uobj;
594 struct ib_cq *cq;
595 int ret;
596
597 if (out_len < sizeof resp)
598 return -ENOSPC;
599
600 if (copy_from_user(&cmd, buf, sizeof cmd))
601 return -EFAULT;
602
603 INIT_UDATA(&udata, buf + sizeof cmd,
604 (unsigned long) cmd.response + sizeof resp,
605 in_len - sizeof cmd, out_len - sizeof resp);
606
607 if (cmd.event_handler >= file->device->num_comp)
608 return -EINVAL;
609
610 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
611 if (!uobj)
612 return -ENOMEM;
613
614 uobj->user_handle = cmd.user_handle;
615 uobj->context = file->ucontext;
616
617 cq = file->device->ib_dev->create_cq(file->device->ib_dev, cmd.cqe,
618 file->ucontext, &udata);
619 if (IS_ERR(cq)) {
620 ret = PTR_ERR(cq);
621 goto err;
622 }
623
624 cq->device = file->device->ib_dev;
625 cq->uobject = uobj;
626 cq->comp_handler = ib_uverbs_comp_handler;
627 cq->event_handler = ib_uverbs_cq_event_handler;
628 cq->cq_context = file;
629 atomic_set(&cq->usecnt, 0);
630
631retry:
632 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) {
633 ret = -ENOMEM;
634 goto err_cq;
635 }
636
637 down(&ib_uverbs_idr_mutex);
638 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->id);
639 up(&ib_uverbs_idr_mutex);
640
641 if (ret == -EAGAIN)
642 goto retry;
643 if (ret)
644 goto err_cq;
645
646 spin_lock_irq(&file->ucontext->lock);
647 list_add_tail(&uobj->list, &file->ucontext->cq_list);
648 spin_unlock_irq(&file->ucontext->lock);
649
650 memset(&resp, 0, sizeof resp);
651 resp.cq_handle = uobj->id;
652 resp.cqe = cq->cqe;
653
654 if (copy_to_user((void __user *) (unsigned long) cmd.response,
655 &resp, sizeof resp)) {
656 ret = -EFAULT;
657 goto err_list;
658 }
659
660 return in_len;
661
662err_list:
663 spin_lock_irq(&file->ucontext->lock);
664 list_del(&uobj->list);
665 spin_unlock_irq(&file->ucontext->lock);
666
667 down(&ib_uverbs_idr_mutex);
668 idr_remove(&ib_uverbs_cq_idr, uobj->id);
669 up(&ib_uverbs_idr_mutex);
670
671err_cq:
672 ib_destroy_cq(cq);
673
674err:
675 kfree(uobj);
676 return ret;
677}
678
679ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
680 const char __user *buf, int in_len,
681 int out_len)
682{
683 struct ib_uverbs_destroy_cq cmd;
684 struct ib_cq *cq;
685 struct ib_uobject *uobj;
686 int ret = -EINVAL;
687
688 if (copy_from_user(&cmd, buf, sizeof cmd))
689 return -EFAULT;
690
691 down(&ib_uverbs_idr_mutex);
692
693 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
694 if (!cq || cq->uobject->context != file->ucontext)
695 goto out;
696
697 uobj = cq->uobject;
698
699 ret = ib_destroy_cq(cq);
700 if (ret)
701 goto out;
702
703 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle);
704
705 spin_lock_irq(&file->ucontext->lock);
706 list_del(&uobj->list);
707 spin_unlock_irq(&file->ucontext->lock);
708
709 kfree(uobj);
710
711out:
712 up(&ib_uverbs_idr_mutex);
713
714 return ret ? ret : in_len;
715}
716
717ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
718 const char __user *buf, int in_len,
719 int out_len)
720{
721 struct ib_uverbs_create_qp cmd;
722 struct ib_uverbs_create_qp_resp resp;
723 struct ib_udata udata;
724 struct ib_uobject *uobj;
725 struct ib_pd *pd;
726 struct ib_cq *scq, *rcq;
727 struct ib_qp *qp;
728 struct ib_qp_init_attr attr;
729 int ret;
730
731 if (out_len < sizeof resp)
732 return -ENOSPC;
733
734 if (copy_from_user(&cmd, buf, sizeof cmd))
735 return -EFAULT;
736
737 INIT_UDATA(&udata, buf + sizeof cmd,
738 (unsigned long) cmd.response + sizeof resp,
739 in_len - sizeof cmd, out_len - sizeof resp);
740
741 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
742 if (!uobj)
743 return -ENOMEM;
744
745 down(&ib_uverbs_idr_mutex);
746
747 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
748 scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle);
749 rcq = idr_find(&ib_uverbs_cq_idr, cmd.recv_cq_handle);
750
751 if (!pd || pd->uobject->context != file->ucontext ||
752 !scq || scq->uobject->context != file->ucontext ||
753 !rcq || rcq->uobject->context != file->ucontext) {
754 ret = -EINVAL;
755 goto err_up;
756 }
757
758 attr.event_handler = ib_uverbs_qp_event_handler;
759 attr.qp_context = file;
760 attr.send_cq = scq;
761 attr.recv_cq = rcq;
762 attr.srq = NULL;
763 attr.sq_sig_type = cmd.sq_sig_all ? IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR;
764 attr.qp_type = cmd.qp_type;
765
766 attr.cap.max_send_wr = cmd.max_send_wr;
767 attr.cap.max_recv_wr = cmd.max_recv_wr;
768 attr.cap.max_send_sge = cmd.max_send_sge;
769 attr.cap.max_recv_sge = cmd.max_recv_sge;
770 attr.cap.max_inline_data = cmd.max_inline_data;
771
772 uobj->user_handle = cmd.user_handle;
773 uobj->context = file->ucontext;
774
775 qp = pd->device->create_qp(pd, &attr, &udata);
776 if (IS_ERR(qp)) {
777 ret = PTR_ERR(qp);
778 goto err_up;
779 }
780
781 qp->device = pd->device;
782 qp->pd = pd;
783 qp->send_cq = attr.send_cq;
784 qp->recv_cq = attr.recv_cq;
785 qp->srq = attr.srq;
786 qp->uobject = uobj;
787 qp->event_handler = attr.event_handler;
788 qp->qp_context = attr.qp_context;
789 qp->qp_type = attr.qp_type;
790 atomic_inc(&pd->usecnt);
791 atomic_inc(&attr.send_cq->usecnt);
792 atomic_inc(&attr.recv_cq->usecnt);
793 if (attr.srq)
794 atomic_inc(&attr.srq->usecnt);
795
796 memset(&resp, 0, sizeof resp);
797 resp.qpn = qp->qp_num;
798
799retry:
800 if (!idr_pre_get(&ib_uverbs_qp_idr, GFP_KERNEL)) {
801 ret = -ENOMEM;
802 goto err_destroy;
803 }
804
805 ret = idr_get_new(&ib_uverbs_qp_idr, qp, &uobj->id);
806
807 if (ret == -EAGAIN)
808 goto retry;
809 if (ret)
810 goto err_destroy;
811
812 resp.qp_handle = uobj->id;
813
814 spin_lock_irq(&file->ucontext->lock);
815 list_add_tail(&uobj->list, &file->ucontext->qp_list);
816 spin_unlock_irq(&file->ucontext->lock);
817
818 if (copy_to_user((void __user *) (unsigned long) cmd.response,
819 &resp, sizeof resp)) {
820 ret = -EFAULT;
821 goto err_list;
822 }
823
824 up(&ib_uverbs_idr_mutex);
825
826 return in_len;
827
828err_list:
829 spin_lock_irq(&file->ucontext->lock);
830 list_del(&uobj->list);
831 spin_unlock_irq(&file->ucontext->lock);
832
833err_destroy:
834 ib_destroy_qp(qp);
835
836err_up:
837 up(&ib_uverbs_idr_mutex);
838
839 kfree(uobj);
840 return ret;
841}
842
843ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
844 const char __user *buf, int in_len,
845 int out_len)
846{
847 struct ib_uverbs_modify_qp cmd;
848 struct ib_qp *qp;
849 struct ib_qp_attr *attr;
850 int ret;
851
852 if (copy_from_user(&cmd, buf, sizeof cmd))
853 return -EFAULT;
854
855 attr = kmalloc(sizeof *attr, GFP_KERNEL);
856 if (!attr)
857 return -ENOMEM;
858
859 down(&ib_uverbs_idr_mutex);
860
861 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
862 if (!qp || qp->uobject->context != file->ucontext) {
863 ret = -EINVAL;
864 goto out;
865 }
866
867 attr->qp_state = cmd.qp_state;
868 attr->cur_qp_state = cmd.cur_qp_state;
869 attr->path_mtu = cmd.path_mtu;
870 attr->path_mig_state = cmd.path_mig_state;
871 attr->qkey = cmd.qkey;
872 attr->rq_psn = cmd.rq_psn;
873 attr->sq_psn = cmd.sq_psn;
874 attr->dest_qp_num = cmd.dest_qp_num;
875 attr->qp_access_flags = cmd.qp_access_flags;
876 attr->pkey_index = cmd.pkey_index;
877 attr->alt_pkey_index = cmd.pkey_index;
878 attr->en_sqd_async_notify = cmd.en_sqd_async_notify;
879 attr->max_rd_atomic = cmd.max_rd_atomic;
880 attr->max_dest_rd_atomic = cmd.max_dest_rd_atomic;
881 attr->min_rnr_timer = cmd.min_rnr_timer;
882 attr->port_num = cmd.port_num;
883 attr->timeout = cmd.timeout;
884 attr->retry_cnt = cmd.retry_cnt;
885 attr->rnr_retry = cmd.rnr_retry;
886 attr->alt_port_num = cmd.alt_port_num;
887 attr->alt_timeout = cmd.alt_timeout;
888
889 memcpy(attr->ah_attr.grh.dgid.raw, cmd.dest.dgid, 16);
890 attr->ah_attr.grh.flow_label = cmd.dest.flow_label;
891 attr->ah_attr.grh.sgid_index = cmd.dest.sgid_index;
892 attr->ah_attr.grh.hop_limit = cmd.dest.hop_limit;
893 attr->ah_attr.grh.traffic_class = cmd.dest.traffic_class;
894 attr->ah_attr.dlid = cmd.dest.dlid;
895 attr->ah_attr.sl = cmd.dest.sl;
896 attr->ah_attr.src_path_bits = cmd.dest.src_path_bits;
897 attr->ah_attr.static_rate = cmd.dest.static_rate;
898 attr->ah_attr.ah_flags = cmd.dest.is_global ? IB_AH_GRH : 0;
899 attr->ah_attr.port_num = cmd.dest.port_num;
900
901 memcpy(attr->alt_ah_attr.grh.dgid.raw, cmd.alt_dest.dgid, 16);
902 attr->alt_ah_attr.grh.flow_label = cmd.alt_dest.flow_label;
903 attr->alt_ah_attr.grh.sgid_index = cmd.alt_dest.sgid_index;
904 attr->alt_ah_attr.grh.hop_limit = cmd.alt_dest.hop_limit;
905 attr->alt_ah_attr.grh.traffic_class = cmd.alt_dest.traffic_class;
906 attr->alt_ah_attr.dlid = cmd.alt_dest.dlid;
907 attr->alt_ah_attr.sl = cmd.alt_dest.sl;
908 attr->alt_ah_attr.src_path_bits = cmd.alt_dest.src_path_bits;
909 attr->alt_ah_attr.static_rate = cmd.alt_dest.static_rate;
910 attr->alt_ah_attr.ah_flags = cmd.alt_dest.is_global ? IB_AH_GRH : 0;
911 attr->alt_ah_attr.port_num = cmd.alt_dest.port_num;
912
913 ret = ib_modify_qp(qp, attr, cmd.attr_mask);
914 if (ret)
915 goto out;
916
917 ret = in_len;
918
919out:
920 up(&ib_uverbs_idr_mutex);
921 kfree(attr);
922
923 return ret;
924}
925
926ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
927 const char __user *buf, int in_len,
928 int out_len)
929{
930 struct ib_uverbs_destroy_qp cmd;
931 struct ib_qp *qp;
932 struct ib_uobject *uobj;
933 int ret = -EINVAL;
934
935 if (copy_from_user(&cmd, buf, sizeof cmd))
936 return -EFAULT;
937
938 down(&ib_uverbs_idr_mutex);
939
940 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
941 if (!qp || qp->uobject->context != file->ucontext)
942 goto out;
943
944 uobj = qp->uobject;
945
946 ret = ib_destroy_qp(qp);
947 if (ret)
948 goto out;
949
950 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle);
951
952 spin_lock_irq(&file->ucontext->lock);
953 list_del(&uobj->list);
954 spin_unlock_irq(&file->ucontext->lock);
955
956 kfree(uobj);
957
958out:
959 up(&ib_uverbs_idr_mutex);
960
961 return ret ? ret : in_len;
962}
963
964ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
965 const char __user *buf, int in_len,
966 int out_len)
967{
968 struct ib_uverbs_attach_mcast cmd;
969 struct ib_qp *qp;
970 int ret = -EINVAL;
971
972 if (copy_from_user(&cmd, buf, sizeof cmd))
973 return -EFAULT;
974
975 down(&ib_uverbs_idr_mutex);
976
977 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
978 if (qp && qp->uobject->context == file->ucontext)
979 ret = ib_attach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
980
981 up(&ib_uverbs_idr_mutex);
982
983 return ret ? ret : in_len;
984}
985
986ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
987 const char __user *buf, int in_len,
988 int out_len)
989{
990 struct ib_uverbs_detach_mcast cmd;
991 struct ib_qp *qp;
992 int ret = -EINVAL;
993
994 if (copy_from_user(&cmd, buf, sizeof cmd))
995 return -EFAULT;
996
997 down(&ib_uverbs_idr_mutex);
998
999 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1000 if (qp && qp->uobject->context == file->ucontext)
1001 ret = ib_detach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
1002
1003 up(&ib_uverbs_idr_mutex);
1004
1005 return ret ? ret : in_len;
1006}
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
new file mode 100644
index 000000000000..fbbe03d8c901
--- /dev/null
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -0,0 +1,698 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: uverbs_main.c 2733 2005-06-28 19:14:34Z roland $
34 */
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/device.h>
39#include <linux/err.h>
40#include <linux/fs.h>
41#include <linux/poll.h>
42#include <linux/file.h>
43#include <linux/mount.h>
44
45#include <asm/uaccess.h>
46
47#include "uverbs.h"
48
49MODULE_AUTHOR("Roland Dreier");
50MODULE_DESCRIPTION("InfiniBand userspace verbs access");
51MODULE_LICENSE("Dual BSD/GPL");
52
53#define INFINIBANDEVENTFS_MAGIC 0x49426576 /* "IBev" */
54
55enum {
56 IB_UVERBS_MAJOR = 231,
57 IB_UVERBS_BASE_MINOR = 192,
58 IB_UVERBS_MAX_DEVICES = 32
59};
60
61#define IB_UVERBS_BASE_DEV MKDEV(IB_UVERBS_MAJOR, IB_UVERBS_BASE_MINOR)
62
63DECLARE_MUTEX(ib_uverbs_idr_mutex);
64DEFINE_IDR(ib_uverbs_pd_idr);
65DEFINE_IDR(ib_uverbs_mr_idr);
66DEFINE_IDR(ib_uverbs_mw_idr);
67DEFINE_IDR(ib_uverbs_ah_idr);
68DEFINE_IDR(ib_uverbs_cq_idr);
69DEFINE_IDR(ib_uverbs_qp_idr);
70
71static spinlock_t map_lock;
72static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
73
74static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
75 const char __user *buf, int in_len,
76 int out_len) = {
77 [IB_USER_VERBS_CMD_QUERY_PARAMS] = ib_uverbs_query_params,
78 [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context,
79 [IB_USER_VERBS_CMD_QUERY_DEVICE] = ib_uverbs_query_device,
80 [IB_USER_VERBS_CMD_QUERY_PORT] = ib_uverbs_query_port,
81 [IB_USER_VERBS_CMD_QUERY_GID] = ib_uverbs_query_gid,
82 [IB_USER_VERBS_CMD_QUERY_PKEY] = ib_uverbs_query_pkey,
83 [IB_USER_VERBS_CMD_ALLOC_PD] = ib_uverbs_alloc_pd,
84 [IB_USER_VERBS_CMD_DEALLOC_PD] = ib_uverbs_dealloc_pd,
85 [IB_USER_VERBS_CMD_REG_MR] = ib_uverbs_reg_mr,
86 [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr,
87 [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq,
88 [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq,
89 [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp,
90 [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp,
91 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,
92 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast,
93 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,
94};
95
96static struct vfsmount *uverbs_event_mnt;
97
98static void ib_uverbs_add_one(struct ib_device *device);
99static void ib_uverbs_remove_one(struct ib_device *device);
100
101static int ib_dealloc_ucontext(struct ib_ucontext *context)
102{
103 struct ib_uobject *uobj, *tmp;
104
105 if (!context)
106 return 0;
107
108 down(&ib_uverbs_idr_mutex);
109
110 /* XXX Free AHs */
111
112 list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) {
113 struct ib_qp *qp = idr_find(&ib_uverbs_qp_idr, uobj->id);
114 idr_remove(&ib_uverbs_qp_idr, uobj->id);
115 ib_destroy_qp(qp);
116 list_del(&uobj->list);
117 kfree(uobj);
118 }
119
120 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) {
121 struct ib_cq *cq = idr_find(&ib_uverbs_cq_idr, uobj->id);
122 idr_remove(&ib_uverbs_cq_idr, uobj->id);
123 ib_destroy_cq(cq);
124 list_del(&uobj->list);
125 kfree(uobj);
126 }
127
128 /* XXX Free SRQs */
129 /* XXX Free MWs */
130
131 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {
132 struct ib_mr *mr = idr_find(&ib_uverbs_mr_idr, uobj->id);
133 struct ib_umem_object *memobj;
134
135 idr_remove(&ib_uverbs_mr_idr, uobj->id);
136 ib_dereg_mr(mr);
137
138 memobj = container_of(uobj, struct ib_umem_object, uobject);
139 ib_umem_release_on_close(mr->device, &memobj->umem);
140
141 list_del(&uobj->list);
142 kfree(memobj);
143 }
144
145 list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) {
146 struct ib_pd *pd = idr_find(&ib_uverbs_pd_idr, uobj->id);
147 idr_remove(&ib_uverbs_pd_idr, uobj->id);
148 ib_dealloc_pd(pd);
149 list_del(&uobj->list);
150 kfree(uobj);
151 }
152
153 up(&ib_uverbs_idr_mutex);
154
155 return context->device->dealloc_ucontext(context);
156}
157
158static void ib_uverbs_release_file(struct kref *ref)
159{
160 struct ib_uverbs_file *file =
161 container_of(ref, struct ib_uverbs_file, ref);
162
163 module_put(file->device->ib_dev->owner);
164 kfree(file);
165}
166
167static ssize_t ib_uverbs_event_read(struct file *filp, char __user *buf,
168 size_t count, loff_t *pos)
169{
170 struct ib_uverbs_event_file *file = filp->private_data;
171 void *event;
172 int eventsz;
173 int ret = 0;
174
175 spin_lock_irq(&file->lock);
176
177 while (list_empty(&file->event_list) && file->fd >= 0) {
178 spin_unlock_irq(&file->lock);
179
180 if (filp->f_flags & O_NONBLOCK)
181 return -EAGAIN;
182
183 if (wait_event_interruptible(file->poll_wait,
184 !list_empty(&file->event_list) ||
185 file->fd < 0))
186 return -ERESTARTSYS;
187
188 spin_lock_irq(&file->lock);
189 }
190
191 if (file->fd < 0) {
192 spin_unlock_irq(&file->lock);
193 return -ENODEV;
194 }
195
196 if (file->is_async) {
197 event = list_entry(file->event_list.next,
198 struct ib_uverbs_async_event, list);
199 eventsz = sizeof (struct ib_uverbs_async_event_desc);
200 } else {
201 event = list_entry(file->event_list.next,
202 struct ib_uverbs_comp_event, list);
203 eventsz = sizeof (struct ib_uverbs_comp_event_desc);
204 }
205
206 if (eventsz > count) {
207 ret = -EINVAL;
208 event = NULL;
209 } else
210 list_del(file->event_list.next);
211
212 spin_unlock_irq(&file->lock);
213
214 if (event) {
215 if (copy_to_user(buf, event, eventsz))
216 ret = -EFAULT;
217 else
218 ret = eventsz;
219 }
220
221 kfree(event);
222
223 return ret;
224}
225
226static unsigned int ib_uverbs_event_poll(struct file *filp,
227 struct poll_table_struct *wait)
228{
229 unsigned int pollflags = 0;
230 struct ib_uverbs_event_file *file = filp->private_data;
231
232 poll_wait(filp, &file->poll_wait, wait);
233
234 spin_lock_irq(&file->lock);
235 if (file->fd < 0)
236 pollflags = POLLERR;
237 else if (!list_empty(&file->event_list))
238 pollflags = POLLIN | POLLRDNORM;
239 spin_unlock_irq(&file->lock);
240
241 return pollflags;
242}
243
244static void ib_uverbs_event_release(struct ib_uverbs_event_file *file)
245{
246 struct list_head *entry, *tmp;
247
248 spin_lock_irq(&file->lock);
249 if (file->fd != -1) {
250 file->fd = -1;
251 list_for_each_safe(entry, tmp, &file->event_list)
252 if (file->is_async)
253 kfree(list_entry(entry, struct ib_uverbs_async_event, list));
254 else
255 kfree(list_entry(entry, struct ib_uverbs_comp_event, list));
256 }
257 spin_unlock_irq(&file->lock);
258}
259
260static int ib_uverbs_event_close(struct inode *inode, struct file *filp)
261{
262 struct ib_uverbs_event_file *file = filp->private_data;
263
264 ib_uverbs_event_release(file);
265 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file);
266
267 return 0;
268}
269
270static struct file_operations uverbs_event_fops = {
271 /*
272 * No .owner field since we artificially create event files,
273 * so there is no increment to the module reference count in
274 * the open path. All event files come from a uverbs command
275 * file, which already takes a module reference, so this is OK.
276 */
277 .read = ib_uverbs_event_read,
278 .poll = ib_uverbs_event_poll,
279 .release = ib_uverbs_event_close
280};
281
282void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
283{
284 struct ib_uverbs_file *file = cq_context;
285 struct ib_uverbs_comp_event *entry;
286 unsigned long flags;
287
288 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
289 if (!entry)
290 return;
291
292 entry->desc.cq_handle = cq->uobject->user_handle;
293
294 spin_lock_irqsave(&file->comp_file[0].lock, flags);
295 list_add_tail(&entry->list, &file->comp_file[0].event_list);
296 spin_unlock_irqrestore(&file->comp_file[0].lock, flags);
297
298 wake_up_interruptible(&file->comp_file[0].poll_wait);
299}
300
301static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
302 __u64 element, __u64 event)
303{
304 struct ib_uverbs_async_event *entry;
305 unsigned long flags;
306
307 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
308 if (!entry)
309 return;
310
311 entry->desc.element = element;
312 entry->desc.event_type = event;
313
314 spin_lock_irqsave(&file->async_file.lock, flags);
315 list_add_tail(&entry->list, &file->async_file.event_list);
316 spin_unlock_irqrestore(&file->async_file.lock, flags);
317
318 wake_up_interruptible(&file->async_file.poll_wait);
319}
320
321void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
322{
323 ib_uverbs_async_handler(context_ptr,
324 event->element.cq->uobject->user_handle,
325 event->event);
326}
327
328void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr)
329{
330 ib_uverbs_async_handler(context_ptr,
331 event->element.qp->uobject->user_handle,
332 event->event);
333}
334
335static void ib_uverbs_event_handler(struct ib_event_handler *handler,
336 struct ib_event *event)
337{
338 struct ib_uverbs_file *file =
339 container_of(handler, struct ib_uverbs_file, event_handler);
340
341 ib_uverbs_async_handler(file, event->element.port_num, event->event);
342}
343
344static int ib_uverbs_event_init(struct ib_uverbs_event_file *file,
345 struct ib_uverbs_file *uverbs_file)
346{
347 struct file *filp;
348
349 spin_lock_init(&file->lock);
350 INIT_LIST_HEAD(&file->event_list);
351 init_waitqueue_head(&file->poll_wait);
352 file->uverbs_file = uverbs_file;
353
354 file->fd = get_unused_fd();
355 if (file->fd < 0)
356 return file->fd;
357
358 filp = get_empty_filp();
359 if (!filp) {
360 put_unused_fd(file->fd);
361 return -ENFILE;
362 }
363
364 filp->f_op = &uverbs_event_fops;
365 filp->f_vfsmnt = mntget(uverbs_event_mnt);
366 filp->f_dentry = dget(uverbs_event_mnt->mnt_root);
367 filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
368 filp->f_flags = O_RDONLY;
369 filp->f_mode = FMODE_READ;
370 filp->private_data = file;
371
372 fd_install(file->fd, filp);
373
374 return 0;
375}
376
377static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
378 size_t count, loff_t *pos)
379{
380 struct ib_uverbs_file *file = filp->private_data;
381 struct ib_uverbs_cmd_hdr hdr;
382
383 if (count < sizeof hdr)
384 return -EINVAL;
385
386 if (copy_from_user(&hdr, buf, sizeof hdr))
387 return -EFAULT;
388
389 if (hdr.in_words * 4 != count)
390 return -EINVAL;
391
392 if (hdr.command < 0 || hdr.command >= ARRAY_SIZE(uverbs_cmd_table))
393 return -EINVAL;
394
395 if (!file->ucontext &&
396 hdr.command != IB_USER_VERBS_CMD_QUERY_PARAMS &&
397 hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT)
398 return -EINVAL;
399
400 return uverbs_cmd_table[hdr.command](file, buf + sizeof hdr,
401 hdr.in_words * 4, hdr.out_words * 4);
402}
403
404static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
405{
406 struct ib_uverbs_file *file = filp->private_data;
407
408 if (!file->ucontext)
409 return -ENODEV;
410 else
411 return file->device->ib_dev->mmap(file->ucontext, vma);
412}
413
414static int ib_uverbs_open(struct inode *inode, struct file *filp)
415{
416 struct ib_uverbs_device *dev =
417 container_of(inode->i_cdev, struct ib_uverbs_device, dev);
418 struct ib_uverbs_file *file;
419 int i = 0;
420 int ret;
421
422 if (!try_module_get(dev->ib_dev->owner))
423 return -ENODEV;
424
425 file = kmalloc(sizeof *file +
426 (dev->num_comp - 1) * sizeof (struct ib_uverbs_event_file),
427 GFP_KERNEL);
428 if (!file)
429 return -ENOMEM;
430
431 file->device = dev;
432 kref_init(&file->ref);
433
434 file->ucontext = NULL;
435
436 ret = ib_uverbs_event_init(&file->async_file, file);
437 if (ret)
438 goto err;
439
440 file->async_file.is_async = 1;
441
442 kref_get(&file->ref);
443
444 for (i = 0; i < dev->num_comp; ++i) {
445 ret = ib_uverbs_event_init(&file->comp_file[i], file);
446 if (ret)
447 goto err_async;
448 kref_get(&file->ref);
449 file->comp_file[i].is_async = 0;
450 }
451
452
453 filp->private_data = file;
454
455 INIT_IB_EVENT_HANDLER(&file->event_handler, dev->ib_dev,
456 ib_uverbs_event_handler);
457 if (ib_register_event_handler(&file->event_handler))
458 goto err_async;
459
460 return 0;
461
462err_async:
463 while (i--)
464 ib_uverbs_event_release(&file->comp_file[i]);
465
466 ib_uverbs_event_release(&file->async_file);
467
468err:
469 kref_put(&file->ref, ib_uverbs_release_file);
470
471 return ret;
472}
473
474static int ib_uverbs_close(struct inode *inode, struct file *filp)
475{
476 struct ib_uverbs_file *file = filp->private_data;
477 int i;
478
479 ib_unregister_event_handler(&file->event_handler);
480 ib_uverbs_event_release(&file->async_file);
481 ib_dealloc_ucontext(file->ucontext);
482
483 for (i = 0; i < file->device->num_comp; ++i)
484 ib_uverbs_event_release(&file->comp_file[i]);
485
486 kref_put(&file->ref, ib_uverbs_release_file);
487
488 return 0;
489}
490
491static struct file_operations uverbs_fops = {
492 .owner = THIS_MODULE,
493 .write = ib_uverbs_write,
494 .open = ib_uverbs_open,
495 .release = ib_uverbs_close
496};
497
498static struct file_operations uverbs_mmap_fops = {
499 .owner = THIS_MODULE,
500 .write = ib_uverbs_write,
501 .mmap = ib_uverbs_mmap,
502 .open = ib_uverbs_open,
503 .release = ib_uverbs_close
504};
505
506static struct ib_client uverbs_client = {
507 .name = "uverbs",
508 .add = ib_uverbs_add_one,
509 .remove = ib_uverbs_remove_one
510};
511
512static ssize_t show_ibdev(struct class_device *class_dev, char *buf)
513{
514 struct ib_uverbs_device *dev =
515 container_of(class_dev, struct ib_uverbs_device, class_dev);
516
517 return sprintf(buf, "%s\n", dev->ib_dev->name);
518}
519static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
520
521static void ib_uverbs_release_class_dev(struct class_device *class_dev)
522{
523 struct ib_uverbs_device *dev =
524 container_of(class_dev, struct ib_uverbs_device, class_dev);
525
526 cdev_del(&dev->dev);
527 clear_bit(dev->devnum, dev_map);
528 kfree(dev);
529}
530
531static struct class uverbs_class = {
532 .name = "infiniband_verbs",
533 .release = ib_uverbs_release_class_dev
534};
535
536static ssize_t show_abi_version(struct class *class, char *buf)
537{
538 return sprintf(buf, "%d\n", IB_USER_VERBS_ABI_VERSION);
539}
540static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
541
542static void ib_uverbs_add_one(struct ib_device *device)
543{
544 struct ib_uverbs_device *uverbs_dev;
545
546 if (!device->alloc_ucontext)
547 return;
548
549 uverbs_dev = kmalloc(sizeof *uverbs_dev, GFP_KERNEL);
550 if (!uverbs_dev)
551 return;
552
553 memset(uverbs_dev, 0, sizeof *uverbs_dev);
554
555 spin_lock(&map_lock);
556 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
557 if (uverbs_dev->devnum >= IB_UVERBS_MAX_DEVICES) {
558 spin_unlock(&map_lock);
559 goto err;
560 }
561 set_bit(uverbs_dev->devnum, dev_map);
562 spin_unlock(&map_lock);
563
564 uverbs_dev->ib_dev = device;
565 uverbs_dev->num_comp = 1;
566
567 if (device->mmap)
568 cdev_init(&uverbs_dev->dev, &uverbs_mmap_fops);
569 else
570 cdev_init(&uverbs_dev->dev, &uverbs_fops);
571 uverbs_dev->dev.owner = THIS_MODULE;
572 kobject_set_name(&uverbs_dev->dev.kobj, "uverbs%d", uverbs_dev->devnum);
573 if (cdev_add(&uverbs_dev->dev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
574 goto err;
575
576 uverbs_dev->class_dev.class = &uverbs_class;
577 uverbs_dev->class_dev.dev = device->dma_device;
578 uverbs_dev->class_dev.devt = uverbs_dev->dev.dev;
579 snprintf(uverbs_dev->class_dev.class_id, BUS_ID_SIZE, "uverbs%d", uverbs_dev->devnum);
580 if (class_device_register(&uverbs_dev->class_dev))
581 goto err_cdev;
582
583 if (class_device_create_file(&uverbs_dev->class_dev, &class_device_attr_ibdev))
584 goto err_class;
585
586 ib_set_client_data(device, &uverbs_client, uverbs_dev);
587
588 return;
589
590err_class:
591 class_device_unregister(&uverbs_dev->class_dev);
592
593err_cdev:
594 cdev_del(&uverbs_dev->dev);
595 clear_bit(uverbs_dev->devnum, dev_map);
596
597err:
598 kfree(uverbs_dev);
599 return;
600}
601
602static void ib_uverbs_remove_one(struct ib_device *device)
603{
604 struct ib_uverbs_device *uverbs_dev = ib_get_client_data(device, &uverbs_client);
605
606 if (!uverbs_dev)
607 return;
608
609 class_device_unregister(&uverbs_dev->class_dev);
610}
611
612static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
613 const char *dev_name, void *data)
614{
615 return get_sb_pseudo(fs_type, "infinibandevent:", NULL,
616 INFINIBANDEVENTFS_MAGIC);
617}
618
619static struct file_system_type uverbs_event_fs = {
620 /* No owner field so module can be unloaded */
621 .name = "infinibandeventfs",
622 .get_sb = uverbs_event_get_sb,
623 .kill_sb = kill_litter_super
624};
625
626static int __init ib_uverbs_init(void)
627{
628 int ret;
629
630 spin_lock_init(&map_lock);
631
632 ret = register_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES,
633 "infiniband_verbs");
634 if (ret) {
635 printk(KERN_ERR "user_verbs: couldn't register device number\n");
636 goto out;
637 }
638
639 ret = class_register(&uverbs_class);
640 if (ret) {
641 printk(KERN_ERR "user_verbs: couldn't create class infiniband_verbs\n");
642 goto out_chrdev;
643 }
644
645 ret = class_create_file(&uverbs_class, &class_attr_abi_version);
646 if (ret) {
647 printk(KERN_ERR "user_verbs: couldn't create abi_version attribute\n");
648 goto out_class;
649 }
650
651 ret = register_filesystem(&uverbs_event_fs);
652 if (ret) {
653 printk(KERN_ERR "user_verbs: couldn't register infinibandeventfs\n");
654 goto out_class;
655 }
656
657 uverbs_event_mnt = kern_mount(&uverbs_event_fs);
658 if (IS_ERR(uverbs_event_mnt)) {
659 ret = PTR_ERR(uverbs_event_mnt);
660 printk(KERN_ERR "user_verbs: couldn't mount infinibandeventfs\n");
661 goto out_fs;
662 }
663
664 ret = ib_register_client(&uverbs_client);
665 if (ret) {
666 printk(KERN_ERR "user_verbs: couldn't register client\n");
667 goto out_mnt;
668 }
669
670 return 0;
671
672out_mnt:
673 mntput(uverbs_event_mnt);
674
675out_fs:
676 unregister_filesystem(&uverbs_event_fs);
677
678out_class:
679 class_unregister(&uverbs_class);
680
681out_chrdev:
682 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
683
684out:
685 return ret;
686}
687
688static void __exit ib_uverbs_cleanup(void)
689{
690 ib_unregister_client(&uverbs_client);
691 mntput(uverbs_event_mnt);
692 unregister_filesystem(&uverbs_event_fs);
693 class_unregister(&uverbs_class);
694 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
695}
696
697module_init(ib_uverbs_init);
698module_exit(ib_uverbs_cleanup);
diff --git a/drivers/infiniband/core/uverbs_mem.c b/drivers/infiniband/core/uverbs_mem.c
new file mode 100644
index 000000000000..ed550f6595bd
--- /dev/null
+++ b/drivers/infiniband/core/uverbs_mem.c
@@ -0,0 +1,221 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: uverbs_mem.c 2743 2005-06-28 22:27:59Z roland $
34 */
35
36#include <linux/mm.h>
37#include <linux/dma-mapping.h>
38
39#include "uverbs.h"
40
41struct ib_umem_account_work {
42 struct work_struct work;
43 struct mm_struct *mm;
44 unsigned long diff;
45};
46
47
48static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty)
49{
50 struct ib_umem_chunk *chunk, *tmp;
51 int i;
52
53 list_for_each_entry_safe(chunk, tmp, &umem->chunk_list, list) {
54 dma_unmap_sg(dev->dma_device, chunk->page_list,
55 chunk->nents, DMA_BIDIRECTIONAL);
56 for (i = 0; i < chunk->nents; ++i) {
57 if (umem->writable && dirty)
58 set_page_dirty_lock(chunk->page_list[i].page);
59 put_page(chunk->page_list[i].page);
60 }
61
62 kfree(chunk);
63 }
64}
65
66int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
67 void *addr, size_t size, int write)
68{
69 struct page **page_list;
70 struct ib_umem_chunk *chunk;
71 unsigned long locked;
72 unsigned long lock_limit;
73 unsigned long cur_base;
74 unsigned long npages;
75 int ret = 0;
76 int off;
77 int i;
78
79 if (!can_do_mlock())
80 return -EPERM;
81
82 page_list = (struct page **) __get_free_page(GFP_KERNEL);
83 if (!page_list)
84 return -ENOMEM;
85
86 mem->user_base = (unsigned long) addr;
87 mem->length = size;
88 mem->offset = (unsigned long) addr & ~PAGE_MASK;
89 mem->page_size = PAGE_SIZE;
90 mem->writable = write;
91
92 INIT_LIST_HEAD(&mem->chunk_list);
93
94 npages = PAGE_ALIGN(size + mem->offset) >> PAGE_SHIFT;
95
96 down_write(&current->mm->mmap_sem);
97
98 locked = npages + current->mm->locked_vm;
99 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
100
101 if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) {
102 ret = -ENOMEM;
103 goto out;
104 }
105
106 cur_base = (unsigned long) addr & PAGE_MASK;
107
108 while (npages) {
109 ret = get_user_pages(current, current->mm, cur_base,
110 min_t(int, npages,
111 PAGE_SIZE / sizeof (struct page *)),
112 1, !write, page_list, NULL);
113
114 if (ret < 0)
115 goto out;
116
117 cur_base += ret * PAGE_SIZE;
118 npages -= ret;
119
120 off = 0;
121
122 while (ret) {
123 chunk = kmalloc(sizeof *chunk + sizeof (struct scatterlist) *
124 min_t(int, ret, IB_UMEM_MAX_PAGE_CHUNK),
125 GFP_KERNEL);
126 if (!chunk) {
127 ret = -ENOMEM;
128 goto out;
129 }
130
131 chunk->nents = min_t(int, ret, IB_UMEM_MAX_PAGE_CHUNK);
132 for (i = 0; i < chunk->nents; ++i) {
133 chunk->page_list[i].page = page_list[i + off];
134 chunk->page_list[i].offset = 0;
135 chunk->page_list[i].length = PAGE_SIZE;
136 }
137
138 chunk->nmap = dma_map_sg(dev->dma_device,
139 &chunk->page_list[0],
140 chunk->nents,
141 DMA_BIDIRECTIONAL);
142 if (chunk->nmap <= 0) {
143 for (i = 0; i < chunk->nents; ++i)
144 put_page(chunk->page_list[i].page);
145 kfree(chunk);
146
147 ret = -ENOMEM;
148 goto out;
149 }
150
151 ret -= chunk->nents;
152 off += chunk->nents;
153 list_add_tail(&chunk->list, &mem->chunk_list);
154 }
155
156 ret = 0;
157 }
158
159out:
160 if (ret < 0)
161 __ib_umem_release(dev, mem, 0);
162 else
163 current->mm->locked_vm = locked;
164
165 up_write(&current->mm->mmap_sem);
166 free_page((unsigned long) page_list);
167
168 return ret;
169}
170
171void ib_umem_release(struct ib_device *dev, struct ib_umem *umem)
172{
173 __ib_umem_release(dev, umem, 1);
174
175 down_write(&current->mm->mmap_sem);
176 current->mm->locked_vm -=
177 PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT;
178 up_write(&current->mm->mmap_sem);
179}
180
181static void ib_umem_account(void *work_ptr)
182{
183 struct ib_umem_account_work *work = work_ptr;
184
185 down_write(&work->mm->mmap_sem);
186 work->mm->locked_vm -= work->diff;
187 up_write(&work->mm->mmap_sem);
188 mmput(work->mm);
189 kfree(work);
190}
191
192void ib_umem_release_on_close(struct ib_device *dev, struct ib_umem *umem)
193{
194 struct ib_umem_account_work *work;
195 struct mm_struct *mm;
196
197 __ib_umem_release(dev, umem, 1);
198
199 mm = get_task_mm(current);
200 if (!mm)
201 return;
202
203 /*
204 * We may be called with the mm's mmap_sem already held. This
205 * can happen when a userspace munmap() is the call that drops
206 * the last reference to our file and calls our release
207 * method. If there are memory regions to destroy, we'll end
208 * up here and not be able to take the mmap_sem. Therefore we
209 * defer the vm_locked accounting to the system workqueue.
210 */
211
212 work = kmalloc(sizeof *work, GFP_KERNEL);
213 if (!work)
214 return;
215
216 INIT_WORK(&work->work, ib_umem_account, work);
217 work->mm = mm;
218 work->diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT;
219
220 schedule_work(&work->work);
221}
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 7c08ed0cd7dd..2516f9646515 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -4,6 +4,7 @@
4 * Copyright (c) 2004 Intel Corporation. All rights reserved. 4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
7 * Copyright (c) 2005 Cisco Systems. All rights reserved.
7 * 8 *
8 * This software is available to you under a choice of one of two 9 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU 10 * licenses. You may choose to be licensed under the terms of the GNU
@@ -47,10 +48,11 @@ struct ib_pd *ib_alloc_pd(struct ib_device *device)
47{ 48{
48 struct ib_pd *pd; 49 struct ib_pd *pd;
49 50
50 pd = device->alloc_pd(device); 51 pd = device->alloc_pd(device, NULL, NULL);
51 52
52 if (!IS_ERR(pd)) { 53 if (!IS_ERR(pd)) {
53 pd->device = device; 54 pd->device = device;
55 pd->uobject = NULL;
54 atomic_set(&pd->usecnt, 0); 56 atomic_set(&pd->usecnt, 0);
55 } 57 }
56 58
@@ -76,8 +78,9 @@ struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
76 ah = pd->device->create_ah(pd, ah_attr); 78 ah = pd->device->create_ah(pd, ah_attr);
77 79
78 if (!IS_ERR(ah)) { 80 if (!IS_ERR(ah)) {
79 ah->device = pd->device; 81 ah->device = pd->device;
80 ah->pd = pd; 82 ah->pd = pd;
83 ah->uobject = NULL;
81 atomic_inc(&pd->usecnt); 84 atomic_inc(&pd->usecnt);
82 } 85 }
83 86
@@ -122,7 +125,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
122{ 125{
123 struct ib_qp *qp; 126 struct ib_qp *qp;
124 127
125 qp = pd->device->create_qp(pd, qp_init_attr); 128 qp = pd->device->create_qp(pd, qp_init_attr, NULL);
126 129
127 if (!IS_ERR(qp)) { 130 if (!IS_ERR(qp)) {
128 qp->device = pd->device; 131 qp->device = pd->device;
@@ -130,6 +133,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
130 qp->send_cq = qp_init_attr->send_cq; 133 qp->send_cq = qp_init_attr->send_cq;
131 qp->recv_cq = qp_init_attr->recv_cq; 134 qp->recv_cq = qp_init_attr->recv_cq;
132 qp->srq = qp_init_attr->srq; 135 qp->srq = qp_init_attr->srq;
136 qp->uobject = NULL;
133 qp->event_handler = qp_init_attr->event_handler; 137 qp->event_handler = qp_init_attr->event_handler;
134 qp->qp_context = qp_init_attr->qp_context; 138 qp->qp_context = qp_init_attr->qp_context;
135 qp->qp_type = qp_init_attr->qp_type; 139 qp->qp_type = qp_init_attr->qp_type;
@@ -197,10 +201,11 @@ struct ib_cq *ib_create_cq(struct ib_device *device,
197{ 201{
198 struct ib_cq *cq; 202 struct ib_cq *cq;
199 203
200 cq = device->create_cq(device, cqe); 204 cq = device->create_cq(device, cqe, NULL, NULL);
201 205
202 if (!IS_ERR(cq)) { 206 if (!IS_ERR(cq)) {
203 cq->device = device; 207 cq->device = device;
208 cq->uobject = NULL;
204 cq->comp_handler = comp_handler; 209 cq->comp_handler = comp_handler;
205 cq->event_handler = event_handler; 210 cq->event_handler = event_handler;
206 cq->cq_context = cq_context; 211 cq->cq_context = cq_context;
@@ -245,8 +250,9 @@ struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags)
245 mr = pd->device->get_dma_mr(pd, mr_access_flags); 250 mr = pd->device->get_dma_mr(pd, mr_access_flags);
246 251
247 if (!IS_ERR(mr)) { 252 if (!IS_ERR(mr)) {
248 mr->device = pd->device; 253 mr->device = pd->device;
249 mr->pd = pd; 254 mr->pd = pd;
255 mr->uobject = NULL;
250 atomic_inc(&pd->usecnt); 256 atomic_inc(&pd->usecnt);
251 atomic_set(&mr->usecnt, 0); 257 atomic_set(&mr->usecnt, 0);
252 } 258 }
@@ -267,8 +273,9 @@ struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
267 mr_access_flags, iova_start); 273 mr_access_flags, iova_start);
268 274
269 if (!IS_ERR(mr)) { 275 if (!IS_ERR(mr)) {
270 mr->device = pd->device; 276 mr->device = pd->device;
271 mr->pd = pd; 277 mr->pd = pd;
278 mr->uobject = NULL;
272 atomic_inc(&pd->usecnt); 279 atomic_inc(&pd->usecnt);
273 atomic_set(&mr->usecnt, 0); 280 atomic_set(&mr->usecnt, 0);
274 } 281 }
@@ -344,8 +351,9 @@ struct ib_mw *ib_alloc_mw(struct ib_pd *pd)
344 351
345 mw = pd->device->alloc_mw(pd); 352 mw = pd->device->alloc_mw(pd);
346 if (!IS_ERR(mw)) { 353 if (!IS_ERR(mw)) {
347 mw->device = pd->device; 354 mw->device = pd->device;
348 mw->pd = pd; 355 mw->pd = pd;
356 mw->uobject = NULL;
349 atomic_inc(&pd->usecnt); 357 atomic_inc(&pd->usecnt);
350 } 358 }
351 359
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index 085baf393ca4..d58dcbe66488 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index cd9ed958d92f..1557a522d831 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -431,6 +431,36 @@ static int mthca_cmd_imm(struct mthca_dev *dev,
431 timeout, status); 431 timeout, status);
432} 432}
433 433
434int mthca_cmd_init(struct mthca_dev *dev)
435{
436 sema_init(&dev->cmd.hcr_sem, 1);
437 sema_init(&dev->cmd.poll_sem, 1);
438 dev->cmd.use_events = 0;
439
440 dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
441 MTHCA_HCR_SIZE);
442 if (!dev->hcr) {
443 mthca_err(dev, "Couldn't map command register.");
444 return -ENOMEM;
445 }
446
447 dev->cmd.pool = pci_pool_create("mthca_cmd", dev->pdev,
448 MTHCA_MAILBOX_SIZE,
449 MTHCA_MAILBOX_SIZE, 0);
450 if (!dev->cmd.pool) {
451 iounmap(dev->hcr);
452 return -ENOMEM;
453 }
454
455 return 0;
456}
457
458void mthca_cmd_cleanup(struct mthca_dev *dev)
459{
460 pci_pool_destroy(dev->cmd.pool);
461 iounmap(dev->hcr);
462}
463
434/* 464/*
435 * Switch to using events to issue FW commands (should be called after 465 * Switch to using events to issue FW commands (should be called after
436 * event queue to command events has been initialized). 466 * event queue to command events has been initialized).
@@ -489,6 +519,33 @@ void mthca_cmd_use_polling(struct mthca_dev *dev)
489 up(&dev->cmd.poll_sem); 519 up(&dev->cmd.poll_sem);
490} 520}
491 521
522struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
523 unsigned int gfp_mask)
524{
525 struct mthca_mailbox *mailbox;
526
527 mailbox = kmalloc(sizeof *mailbox, gfp_mask);
528 if (!mailbox)
529 return ERR_PTR(-ENOMEM);
530
531 mailbox->buf = pci_pool_alloc(dev->cmd.pool, gfp_mask, &mailbox->dma);
532 if (!mailbox->buf) {
533 kfree(mailbox);
534 return ERR_PTR(-ENOMEM);
535 }
536
537 return mailbox;
538}
539
540void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
541{
542 if (!mailbox)
543 return;
544
545 pci_pool_free(dev->cmd.pool, mailbox->buf, mailbox->dma);
546 kfree(mailbox);
547}
548
492int mthca_SYS_EN(struct mthca_dev *dev, u8 *status) 549int mthca_SYS_EN(struct mthca_dev *dev, u8 *status)
493{ 550{
494 u64 out; 551 u64 out;
@@ -513,20 +570,20 @@ int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status)
513static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm, 570static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
514 u64 virt, u8 *status) 571 u64 virt, u8 *status)
515{ 572{
516 u32 *inbox; 573 struct mthca_mailbox *mailbox;
517 dma_addr_t indma;
518 struct mthca_icm_iter iter; 574 struct mthca_icm_iter iter;
575 __be64 *pages;
519 int lg; 576 int lg;
520 int nent = 0; 577 int nent = 0;
521 int i; 578 int i;
522 int err = 0; 579 int err = 0;
523 int ts = 0, tc = 0; 580 int ts = 0, tc = 0;
524 581
525 inbox = pci_alloc_consistent(dev->pdev, PAGE_SIZE, &indma); 582 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
526 if (!inbox) 583 if (IS_ERR(mailbox))
527 return -ENOMEM; 584 return PTR_ERR(mailbox);
528 585 memset(mailbox->buf, 0, MTHCA_MAILBOX_SIZE);
529 memset(inbox, 0, PAGE_SIZE); 586 pages = mailbox->buf;
530 587
531 for (mthca_icm_first(icm, &iter); 588 for (mthca_icm_first(icm, &iter);
532 !mthca_icm_last(&iter); 589 !mthca_icm_last(&iter);
@@ -546,19 +603,17 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
546 } 603 }
547 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) { 604 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) {
548 if (virt != -1) { 605 if (virt != -1) {
549 *((__be64 *) (inbox + nent * 4)) = 606 pages[nent * 2] = cpu_to_be64(virt);
550 cpu_to_be64(virt);
551 virt += 1 << lg; 607 virt += 1 << lg;
552 } 608 }
553 609
554 *((__be64 *) (inbox + nent * 4 + 2)) = 610 pages[nent * 2 + 1] = cpu_to_be64((mthca_icm_addr(&iter) +
555 cpu_to_be64((mthca_icm_addr(&iter) + 611 (i << lg)) | (lg - 12));
556 (i << lg)) | (lg - 12));
557 ts += 1 << (lg - 10); 612 ts += 1 << (lg - 10);
558 ++tc; 613 ++tc;
559 614
560 if (nent == PAGE_SIZE / 16) { 615 if (nent == MTHCA_MAILBOX_SIZE / 16) {
561 err = mthca_cmd(dev, indma, nent, 0, op, 616 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
562 CMD_TIME_CLASS_B, status); 617 CMD_TIME_CLASS_B, status);
563 if (err || *status) 618 if (err || *status)
564 goto out; 619 goto out;
@@ -568,7 +623,7 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
568 } 623 }
569 624
570 if (nent) 625 if (nent)
571 err = mthca_cmd(dev, indma, nent, 0, op, 626 err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
572 CMD_TIME_CLASS_B, status); 627 CMD_TIME_CLASS_B, status);
573 628
574 switch (op) { 629 switch (op) {
@@ -585,7 +640,7 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
585 } 640 }
586 641
587out: 642out:
588 pci_free_consistent(dev->pdev, PAGE_SIZE, inbox, indma); 643 mthca_free_mailbox(dev, mailbox);
589 return err; 644 return err;
590} 645}
591 646
@@ -606,8 +661,8 @@ int mthca_RUN_FW(struct mthca_dev *dev, u8 *status)
606 661
607int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status) 662int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
608{ 663{
664 struct mthca_mailbox *mailbox;
609 u32 *outbox; 665 u32 *outbox;
610 dma_addr_t outdma;
611 int err = 0; 666 int err = 0;
612 u8 lg; 667 u8 lg;
613 668
@@ -625,12 +680,12 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
625#define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40 680#define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40
626#define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48 681#define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48
627 682
628 outbox = pci_alloc_consistent(dev->pdev, QUERY_FW_OUT_SIZE, &outdma); 683 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
629 if (!outbox) { 684 if (IS_ERR(mailbox))
630 return -ENOMEM; 685 return PTR_ERR(mailbox);
631 } 686 outbox = mailbox->buf;
632 687
633 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_FW, 688 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_FW,
634 CMD_TIME_CLASS_A, status); 689 CMD_TIME_CLASS_A, status);
635 690
636 if (err) 691 if (err)
@@ -681,15 +736,15 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
681 } 736 }
682 737
683out: 738out:
684 pci_free_consistent(dev->pdev, QUERY_FW_OUT_SIZE, outbox, outdma); 739 mthca_free_mailbox(dev, mailbox);
685 return err; 740 return err;
686} 741}
687 742
688int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status) 743int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
689{ 744{
745 struct mthca_mailbox *mailbox;
690 u8 info; 746 u8 info;
691 u32 *outbox; 747 u32 *outbox;
692 dma_addr_t outdma;
693 int err = 0; 748 int err = 0;
694 749
695#define ENABLE_LAM_OUT_SIZE 0x100 750#define ENABLE_LAM_OUT_SIZE 0x100
@@ -700,11 +755,12 @@ int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
700#define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4) 755#define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4)
701#define ENABLE_LAM_INFO_ECC_MASK 0x3 756#define ENABLE_LAM_INFO_ECC_MASK 0x3
702 757
703 outbox = pci_alloc_consistent(dev->pdev, ENABLE_LAM_OUT_SIZE, &outdma); 758 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
704 if (!outbox) 759 if (IS_ERR(mailbox))
705 return -ENOMEM; 760 return PTR_ERR(mailbox);
761 outbox = mailbox->buf;
706 762
707 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_ENABLE_LAM, 763 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_ENABLE_LAM,
708 CMD_TIME_CLASS_C, status); 764 CMD_TIME_CLASS_C, status);
709 765
710 if (err) 766 if (err)
@@ -733,7 +789,7 @@ int mthca_ENABLE_LAM(struct mthca_dev *dev, u8 *status)
733 (unsigned long long) dev->ddr_end); 789 (unsigned long long) dev->ddr_end);
734 790
735out: 791out:
736 pci_free_consistent(dev->pdev, ENABLE_LAM_OUT_SIZE, outbox, outdma); 792 mthca_free_mailbox(dev, mailbox);
737 return err; 793 return err;
738} 794}
739 795
@@ -744,9 +800,9 @@ int mthca_DISABLE_LAM(struct mthca_dev *dev, u8 *status)
744 800
745int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status) 801int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
746{ 802{
803 struct mthca_mailbox *mailbox;
747 u8 info; 804 u8 info;
748 u32 *outbox; 805 u32 *outbox;
749 dma_addr_t outdma;
750 int err = 0; 806 int err = 0;
751 807
752#define QUERY_DDR_OUT_SIZE 0x100 808#define QUERY_DDR_OUT_SIZE 0x100
@@ -757,11 +813,12 @@ int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
757#define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4) 813#define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4)
758#define QUERY_DDR_INFO_ECC_MASK 0x3 814#define QUERY_DDR_INFO_ECC_MASK 0x3
759 815
760 outbox = pci_alloc_consistent(dev->pdev, QUERY_DDR_OUT_SIZE, &outdma); 816 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
761 if (!outbox) 817 if (IS_ERR(mailbox))
762 return -ENOMEM; 818 return PTR_ERR(mailbox);
819 outbox = mailbox->buf;
763 820
764 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_DDR, 821 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DDR,
765 CMD_TIME_CLASS_A, status); 822 CMD_TIME_CLASS_A, status);
766 823
767 if (err) 824 if (err)
@@ -787,15 +844,15 @@ int mthca_QUERY_DDR(struct mthca_dev *dev, u8 *status)
787 (unsigned long long) dev->ddr_end); 844 (unsigned long long) dev->ddr_end);
788 845
789out: 846out:
790 pci_free_consistent(dev->pdev, QUERY_DDR_OUT_SIZE, outbox, outdma); 847 mthca_free_mailbox(dev, mailbox);
791 return err; 848 return err;
792} 849}
793 850
794int mthca_QUERY_DEV_LIM(struct mthca_dev *dev, 851int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
795 struct mthca_dev_lim *dev_lim, u8 *status) 852 struct mthca_dev_lim *dev_lim, u8 *status)
796{ 853{
854 struct mthca_mailbox *mailbox;
797 u32 *outbox; 855 u32 *outbox;
798 dma_addr_t outdma;
799 u8 field; 856 u8 field;
800 u16 size; 857 u16 size;
801 int err; 858 int err;
@@ -860,11 +917,12 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
860#define QUERY_DEV_LIM_LAMR_OFFSET 0x9f 917#define QUERY_DEV_LIM_LAMR_OFFSET 0x9f
861#define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0 918#define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0
862 919
863 outbox = pci_alloc_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, &outdma); 920 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
864 if (!outbox) 921 if (IS_ERR(mailbox))
865 return -ENOMEM; 922 return PTR_ERR(mailbox);
923 outbox = mailbox->buf;
866 924
867 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_DEV_LIM, 925 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DEV_LIM,
868 CMD_TIME_CLASS_A, status); 926 CMD_TIME_CLASS_A, status);
869 927
870 if (err) 928 if (err)
@@ -1020,15 +1078,15 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
1020 } 1078 }
1021 1079
1022out: 1080out:
1023 pci_free_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, outbox, outdma); 1081 mthca_free_mailbox(dev, mailbox);
1024 return err; 1082 return err;
1025} 1083}
1026 1084
1027int mthca_QUERY_ADAPTER(struct mthca_dev *dev, 1085int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
1028 struct mthca_adapter *adapter, u8 *status) 1086 struct mthca_adapter *adapter, u8 *status)
1029{ 1087{
1088 struct mthca_mailbox *mailbox;
1030 u32 *outbox; 1089 u32 *outbox;
1031 dma_addr_t outdma;
1032 int err; 1090 int err;
1033 1091
1034#define QUERY_ADAPTER_OUT_SIZE 0x100 1092#define QUERY_ADAPTER_OUT_SIZE 0x100
@@ -1037,23 +1095,24 @@ int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
1037#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08 1095#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08
1038#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10 1096#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
1039 1097
1040 outbox = pci_alloc_consistent(dev->pdev, QUERY_ADAPTER_OUT_SIZE, &outdma); 1098 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1041 if (!outbox) 1099 if (IS_ERR(mailbox))
1042 return -ENOMEM; 1100 return PTR_ERR(mailbox);
1101 outbox = mailbox->buf;
1043 1102
1044 err = mthca_cmd_box(dev, 0, outdma, 0, 0, CMD_QUERY_ADAPTER, 1103 err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_ADAPTER,
1045 CMD_TIME_CLASS_A, status); 1104 CMD_TIME_CLASS_A, status);
1046 1105
1047 if (err) 1106 if (err)
1048 goto out; 1107 goto out;
1049 1108
1050 MTHCA_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET); 1109 MTHCA_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET);
1051 MTHCA_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET); 1110 MTHCA_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET);
1052 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET); 1111 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
1053 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET); 1112 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
1054 1113
1055out: 1114out:
1056 pci_free_consistent(dev->pdev, QUERY_DEV_LIM_OUT_SIZE, outbox, outdma); 1115 mthca_free_mailbox(dev, mailbox);
1057 return err; 1116 return err;
1058} 1117}
1059 1118
@@ -1061,8 +1120,8 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1061 struct mthca_init_hca_param *param, 1120 struct mthca_init_hca_param *param,
1062 u8 *status) 1121 u8 *status)
1063{ 1122{
1123 struct mthca_mailbox *mailbox;
1064 u32 *inbox; 1124 u32 *inbox;
1065 dma_addr_t indma;
1066 int err; 1125 int err;
1067 1126
1068#define INIT_HCA_IN_SIZE 0x200 1127#define INIT_HCA_IN_SIZE 0x200
@@ -1102,9 +1161,10 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1102#define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10) 1161#define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10)
1103#define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18) 1162#define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18)
1104 1163
1105 inbox = pci_alloc_consistent(dev->pdev, INIT_HCA_IN_SIZE, &indma); 1164 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1106 if (!inbox) 1165 if (IS_ERR(mailbox))
1107 return -ENOMEM; 1166 return PTR_ERR(mailbox);
1167 inbox = mailbox->buf;
1108 1168
1109 memset(inbox, 0, INIT_HCA_IN_SIZE); 1169 memset(inbox, 0, INIT_HCA_IN_SIZE);
1110 1170
@@ -1167,10 +1227,9 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
1167 MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET); 1227 MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET);
1168 } 1228 }
1169 1229
1170 err = mthca_cmd(dev, indma, 0, 0, CMD_INIT_HCA, 1230 err = mthca_cmd(dev, mailbox->dma, 0, 0, CMD_INIT_HCA, HZ, status);
1171 HZ, status);
1172 1231
1173 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1232 mthca_free_mailbox(dev, mailbox);
1174 return err; 1233 return err;
1175} 1234}
1176 1235
@@ -1178,8 +1237,8 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1178 struct mthca_init_ib_param *param, 1237 struct mthca_init_ib_param *param,
1179 int port, u8 *status) 1238 int port, u8 *status)
1180{ 1239{
1240 struct mthca_mailbox *mailbox;
1181 u32 *inbox; 1241 u32 *inbox;
1182 dma_addr_t indma;
1183 int err; 1242 int err;
1184 u32 flags; 1243 u32 flags;
1185 1244
@@ -1199,9 +1258,10 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1199#define INIT_IB_NODE_GUID_OFFSET 0x18 1258#define INIT_IB_NODE_GUID_OFFSET 0x18
1200#define INIT_IB_SI_GUID_OFFSET 0x20 1259#define INIT_IB_SI_GUID_OFFSET 0x20
1201 1260
1202 inbox = pci_alloc_consistent(dev->pdev, INIT_IB_IN_SIZE, &indma); 1261 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1203 if (!inbox) 1262 if (IS_ERR(mailbox))
1204 return -ENOMEM; 1263 return PTR_ERR(mailbox);
1264 inbox = mailbox->buf;
1205 1265
1206 memset(inbox, 0, INIT_IB_IN_SIZE); 1266 memset(inbox, 0, INIT_IB_IN_SIZE);
1207 1267
@@ -1221,10 +1281,10 @@ int mthca_INIT_IB(struct mthca_dev *dev,
1221 MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET); 1281 MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET);
1222 MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET); 1282 MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET);
1223 1283
1224 err = mthca_cmd(dev, indma, port, 0, CMD_INIT_IB, 1284 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_INIT_IB,
1225 CMD_TIME_CLASS_A, status); 1285 CMD_TIME_CLASS_A, status);
1226 1286
1227 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1287 mthca_free_mailbox(dev, mailbox);
1228 return err; 1288 return err;
1229} 1289}
1230 1290
@@ -1241,8 +1301,8 @@ int mthca_CLOSE_HCA(struct mthca_dev *dev, int panic, u8 *status)
1241int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param, 1301int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1242 int port, u8 *status) 1302 int port, u8 *status)
1243{ 1303{
1304 struct mthca_mailbox *mailbox;
1244 u32 *inbox; 1305 u32 *inbox;
1245 dma_addr_t indma;
1246 int err; 1306 int err;
1247 u32 flags = 0; 1307 u32 flags = 0;
1248 1308
@@ -1253,9 +1313,10 @@ int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1253#define SET_IB_CAP_MASK_OFFSET 0x04 1313#define SET_IB_CAP_MASK_OFFSET 0x04
1254#define SET_IB_SI_GUID_OFFSET 0x08 1314#define SET_IB_SI_GUID_OFFSET 0x08
1255 1315
1256 inbox = pci_alloc_consistent(dev->pdev, SET_IB_IN_SIZE, &indma); 1316 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1257 if (!inbox) 1317 if (IS_ERR(mailbox))
1258 return -ENOMEM; 1318 return PTR_ERR(mailbox);
1319 inbox = mailbox->buf;
1259 1320
1260 memset(inbox, 0, SET_IB_IN_SIZE); 1321 memset(inbox, 0, SET_IB_IN_SIZE);
1261 1322
@@ -1266,10 +1327,10 @@ int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
1266 MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET); 1327 MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET);
1267 MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET); 1328 MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET);
1268 1329
1269 err = mthca_cmd(dev, indma, port, 0, CMD_SET_IB, 1330 err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_SET_IB,
1270 CMD_TIME_CLASS_B, status); 1331 CMD_TIME_CLASS_B, status);
1271 1332
1272 pci_free_consistent(dev->pdev, INIT_HCA_IN_SIZE, inbox, indma); 1333 mthca_free_mailbox(dev, mailbox);
1273 return err; 1334 return err;
1274} 1335}
1275 1336
@@ -1280,20 +1341,22 @@ int mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt, u8 *st
1280 1341
1281int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status) 1342int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status)
1282{ 1343{
1344 struct mthca_mailbox *mailbox;
1283 u64 *inbox; 1345 u64 *inbox;
1284 dma_addr_t indma;
1285 int err; 1346 int err;
1286 1347
1287 inbox = pci_alloc_consistent(dev->pdev, 16, &indma); 1348 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1288 if (!inbox) 1349 if (IS_ERR(mailbox))
1289 return -ENOMEM; 1350 return PTR_ERR(mailbox);
1351 inbox = mailbox->buf;
1290 1352
1291 inbox[0] = cpu_to_be64(virt); 1353 inbox[0] = cpu_to_be64(virt);
1292 inbox[1] = cpu_to_be64(dma_addr); 1354 inbox[1] = cpu_to_be64(dma_addr);
1293 1355
1294 err = mthca_cmd(dev, indma, 1, 0, CMD_MAP_ICM, CMD_TIME_CLASS_B, status); 1356 err = mthca_cmd(dev, mailbox->dma, 1, 0, CMD_MAP_ICM,
1357 CMD_TIME_CLASS_B, status);
1295 1358
1296 pci_free_consistent(dev->pdev, 16, inbox, indma); 1359 mthca_free_mailbox(dev, mailbox);
1297 1360
1298 if (!err) 1361 if (!err)
1299 mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n", 1362 mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
@@ -1338,69 +1401,26 @@ int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
1338 return 0; 1401 return 0;
1339} 1402}
1340 1403
1341int mthca_SW2HW_MPT(struct mthca_dev *dev, void *mpt_entry, 1404int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1342 int mpt_index, u8 *status) 1405 int mpt_index, u8 *status)
1343{ 1406{
1344 dma_addr_t indma; 1407 return mthca_cmd(dev, mailbox->dma, mpt_index, 0, CMD_SW2HW_MPT,
1345 int err; 1408 CMD_TIME_CLASS_B, status);
1346
1347 indma = pci_map_single(dev->pdev, mpt_entry,
1348 MTHCA_MPT_ENTRY_SIZE,
1349 PCI_DMA_TODEVICE);
1350 if (pci_dma_mapping_error(indma))
1351 return -ENOMEM;
1352
1353 err = mthca_cmd(dev, indma, mpt_index, 0, CMD_SW2HW_MPT,
1354 CMD_TIME_CLASS_B, status);
1355
1356 pci_unmap_single(dev->pdev, indma,
1357 MTHCA_MPT_ENTRY_SIZE, PCI_DMA_TODEVICE);
1358 return err;
1359} 1409}
1360 1410
1361int mthca_HW2SW_MPT(struct mthca_dev *dev, void *mpt_entry, 1411int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1362 int mpt_index, u8 *status) 1412 int mpt_index, u8 *status)
1363{ 1413{
1364 dma_addr_t outdma = 0; 1414 return mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
1365 int err; 1415 !mailbox, CMD_HW2SW_MPT,
1366 1416 CMD_TIME_CLASS_B, status);
1367 if (mpt_entry) {
1368 outdma = pci_map_single(dev->pdev, mpt_entry,
1369 MTHCA_MPT_ENTRY_SIZE,
1370 PCI_DMA_FROMDEVICE);
1371 if (pci_dma_mapping_error(outdma))
1372 return -ENOMEM;
1373 }
1374
1375 err = mthca_cmd_box(dev, 0, outdma, mpt_index, !mpt_entry,
1376 CMD_HW2SW_MPT,
1377 CMD_TIME_CLASS_B, status);
1378
1379 if (mpt_entry)
1380 pci_unmap_single(dev->pdev, outdma,
1381 MTHCA_MPT_ENTRY_SIZE,
1382 PCI_DMA_FROMDEVICE);
1383 return err;
1384} 1417}
1385 1418
1386int mthca_WRITE_MTT(struct mthca_dev *dev, u64 *mtt_entry, 1419int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1387 int num_mtt, u8 *status) 1420 int num_mtt, u8 *status)
1388{ 1421{
1389 dma_addr_t indma; 1422 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
1390 int err; 1423 CMD_TIME_CLASS_B, status);
1391
1392 indma = pci_map_single(dev->pdev, mtt_entry,
1393 (num_mtt + 2) * 8,
1394 PCI_DMA_TODEVICE);
1395 if (pci_dma_mapping_error(indma))
1396 return -ENOMEM;
1397
1398 err = mthca_cmd(dev, indma, num_mtt, 0, CMD_WRITE_MTT,
1399 CMD_TIME_CLASS_B, status);
1400
1401 pci_unmap_single(dev->pdev, indma,
1402 (num_mtt + 2) * 8, PCI_DMA_TODEVICE);
1403 return err;
1404} 1424}
1405 1425
1406int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status) 1426int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status)
@@ -1418,92 +1438,38 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
1418 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status); 1438 0, CMD_MAP_EQ, CMD_TIME_CLASS_B, status);
1419} 1439}
1420 1440
1421int mthca_SW2HW_EQ(struct mthca_dev *dev, void *eq_context, 1441int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1422 int eq_num, u8 *status) 1442 int eq_num, u8 *status)
1423{ 1443{
1424 dma_addr_t indma; 1444 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
1425 int err; 1445 CMD_TIME_CLASS_A, status);
1426
1427 indma = pci_map_single(dev->pdev, eq_context,
1428 MTHCA_EQ_CONTEXT_SIZE,
1429 PCI_DMA_TODEVICE);
1430 if (pci_dma_mapping_error(indma))
1431 return -ENOMEM;
1432
1433 err = mthca_cmd(dev, indma, eq_num, 0, CMD_SW2HW_EQ,
1434 CMD_TIME_CLASS_A, status);
1435
1436 pci_unmap_single(dev->pdev, indma,
1437 MTHCA_EQ_CONTEXT_SIZE, PCI_DMA_TODEVICE);
1438 return err;
1439} 1446}
1440 1447
1441int mthca_HW2SW_EQ(struct mthca_dev *dev, void *eq_context, 1448int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1442 int eq_num, u8 *status) 1449 int eq_num, u8 *status)
1443{ 1450{
1444 dma_addr_t outdma = 0; 1451 return mthca_cmd_box(dev, 0, mailbox->dma, eq_num, 0,
1445 int err; 1452 CMD_HW2SW_EQ,
1446 1453 CMD_TIME_CLASS_A, status);
1447 outdma = pci_map_single(dev->pdev, eq_context,
1448 MTHCA_EQ_CONTEXT_SIZE,
1449 PCI_DMA_FROMDEVICE);
1450 if (pci_dma_mapping_error(outdma))
1451 return -ENOMEM;
1452
1453 err = mthca_cmd_box(dev, 0, outdma, eq_num, 0,
1454 CMD_HW2SW_EQ,
1455 CMD_TIME_CLASS_A, status);
1456
1457 pci_unmap_single(dev->pdev, outdma,
1458 MTHCA_EQ_CONTEXT_SIZE,
1459 PCI_DMA_FROMDEVICE);
1460 return err;
1461} 1454}
1462 1455
1463int mthca_SW2HW_CQ(struct mthca_dev *dev, void *cq_context, 1456int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1464 int cq_num, u8 *status) 1457 int cq_num, u8 *status)
1465{ 1458{
1466 dma_addr_t indma; 1459 return mthca_cmd(dev, mailbox->dma, cq_num, 0, CMD_SW2HW_CQ,
1467 int err;
1468
1469 indma = pci_map_single(dev->pdev, cq_context,
1470 MTHCA_CQ_CONTEXT_SIZE,
1471 PCI_DMA_TODEVICE);
1472 if (pci_dma_mapping_error(indma))
1473 return -ENOMEM;
1474
1475 err = mthca_cmd(dev, indma, cq_num, 0, CMD_SW2HW_CQ,
1476 CMD_TIME_CLASS_A, status); 1460 CMD_TIME_CLASS_A, status);
1477
1478 pci_unmap_single(dev->pdev, indma,
1479 MTHCA_CQ_CONTEXT_SIZE, PCI_DMA_TODEVICE);
1480 return err;
1481} 1461}
1482 1462
1483int mthca_HW2SW_CQ(struct mthca_dev *dev, void *cq_context, 1463int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1484 int cq_num, u8 *status) 1464 int cq_num, u8 *status)
1485{ 1465{
1486 dma_addr_t outdma = 0; 1466 return mthca_cmd_box(dev, 0, mailbox->dma, cq_num, 0,
1487 int err; 1467 CMD_HW2SW_CQ,
1488 1468 CMD_TIME_CLASS_A, status);
1489 outdma = pci_map_single(dev->pdev, cq_context,
1490 MTHCA_CQ_CONTEXT_SIZE,
1491 PCI_DMA_FROMDEVICE);
1492 if (pci_dma_mapping_error(outdma))
1493 return -ENOMEM;
1494
1495 err = mthca_cmd_box(dev, 0, outdma, cq_num, 0,
1496 CMD_HW2SW_CQ,
1497 CMD_TIME_CLASS_A, status);
1498
1499 pci_unmap_single(dev->pdev, outdma,
1500 MTHCA_CQ_CONTEXT_SIZE,
1501 PCI_DMA_FROMDEVICE);
1502 return err;
1503} 1469}
1504 1470
1505int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 1471int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1506 int is_ee, void *qp_context, u32 optmask, 1472 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
1507 u8 *status) 1473 u8 *status)
1508{ 1474{
1509 static const u16 op[] = { 1475 static const u16 op[] = {
@@ -1520,36 +1486,34 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1520 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE 1486 [MTHCA_TRANS_ANY2RST] = CMD_ERR2RST_QPEE
1521 }; 1487 };
1522 u8 op_mod = 0; 1488 u8 op_mod = 0;
1523 1489 int my_mailbox = 0;
1524 dma_addr_t indma;
1525 int err; 1490 int err;
1526 1491
1527 if (trans < 0 || trans >= ARRAY_SIZE(op)) 1492 if (trans < 0 || trans >= ARRAY_SIZE(op))
1528 return -EINVAL; 1493 return -EINVAL;
1529 1494
1530 if (trans == MTHCA_TRANS_ANY2RST) { 1495 if (trans == MTHCA_TRANS_ANY2RST) {
1531 indma = 0;
1532 op_mod = 3; /* don't write outbox, any->reset */ 1496 op_mod = 3; /* don't write outbox, any->reset */
1533 1497
1534 /* For debugging */ 1498 /* For debugging */
1535 qp_context = pci_alloc_consistent(dev->pdev, MTHCA_QP_CONTEXT_SIZE, 1499 if (!mailbox) {
1536 &indma); 1500 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1537 op_mod = 2; /* write outbox, any->reset */ 1501 if (!IS_ERR(mailbox)) {
1502 my_mailbox = 1;
1503 op_mod = 2; /* write outbox, any->reset */
1504 } else
1505 mailbox = NULL;
1506 }
1538 } else { 1507 } else {
1539 indma = pci_map_single(dev->pdev, qp_context,
1540 MTHCA_QP_CONTEXT_SIZE,
1541 PCI_DMA_TODEVICE);
1542 if (pci_dma_mapping_error(indma))
1543 return -ENOMEM;
1544
1545 if (0) { 1508 if (0) {
1546 int i; 1509 int i;
1547 mthca_dbg(dev, "Dumping QP context:\n"); 1510 mthca_dbg(dev, "Dumping QP context:\n");
1548 printk(" opt param mask: %08x\n", be32_to_cpup(qp_context)); 1511 printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf));
1549 for (i = 0; i < 0x100 / 4; ++i) { 1512 for (i = 0; i < 0x100 / 4; ++i) {
1550 if (i % 8 == 0) 1513 if (i % 8 == 0)
1551 printk(" [%02x] ", i * 4); 1514 printk(" [%02x] ", i * 4);
1552 printk(" %08x", be32_to_cpu(((u32 *) qp_context)[i + 2])); 1515 printk(" %08x",
1516 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1553 if ((i + 1) % 8 == 0) 1517 if ((i + 1) % 8 == 0)
1554 printk("\n"); 1518 printk("\n");
1555 } 1519 }
@@ -1557,55 +1521,39 @@ int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
1557 } 1521 }
1558 1522
1559 if (trans == MTHCA_TRANS_ANY2RST) { 1523 if (trans == MTHCA_TRANS_ANY2RST) {
1560 err = mthca_cmd_box(dev, 0, indma, (!!is_ee << 24) | num, 1524 err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
1561 op_mod, op[trans], CMD_TIME_CLASS_C, status); 1525 (!!is_ee << 24) | num, op_mod,
1526 op[trans], CMD_TIME_CLASS_C, status);
1562 1527
1563 if (0) { 1528 if (0 && mailbox) {
1564 int i; 1529 int i;
1565 mthca_dbg(dev, "Dumping QP context:\n"); 1530 mthca_dbg(dev, "Dumping QP context:\n");
1566 printk(" %08x\n", be32_to_cpup(qp_context)); 1531 printk(" %08x\n", be32_to_cpup(mailbox->buf));
1567 for (i = 0; i < 0x100 / 4; ++i) { 1532 for (i = 0; i < 0x100 / 4; ++i) {
1568 if (i % 8 == 0) 1533 if (i % 8 == 0)
1569 printk("[%02x] ", i * 4); 1534 printk("[%02x] ", i * 4);
1570 printk(" %08x", be32_to_cpu(((u32 *) qp_context)[i + 2])); 1535 printk(" %08x",
1536 be32_to_cpu(((u32 *) mailbox->buf)[i + 2]));
1571 if ((i + 1) % 8 == 0) 1537 if ((i + 1) % 8 == 0)
1572 printk("\n"); 1538 printk("\n");
1573 } 1539 }
1574 } 1540 }
1575 1541
1576 } else 1542 } else
1577 err = mthca_cmd(dev, indma, (!!is_ee << 24) | num, 1543 err = mthca_cmd(dev, mailbox->dma, (!!is_ee << 24) | num,
1578 op_mod, op[trans], CMD_TIME_CLASS_C, status); 1544 op_mod, op[trans], CMD_TIME_CLASS_C, status);
1579 1545
1580 if (trans != MTHCA_TRANS_ANY2RST) 1546 if (my_mailbox)
1581 pci_unmap_single(dev->pdev, indma, 1547 mthca_free_mailbox(dev, mailbox);
1582 MTHCA_QP_CONTEXT_SIZE, PCI_DMA_TODEVICE); 1548
1583 else
1584 pci_free_consistent(dev->pdev, MTHCA_QP_CONTEXT_SIZE,
1585 qp_context, indma);
1586 return err; 1549 return err;
1587} 1550}
1588 1551
1589int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 1552int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
1590 void *qp_context, u8 *status) 1553 struct mthca_mailbox *mailbox, u8 *status)
1591{ 1554{
1592 dma_addr_t outdma = 0; 1555 return mthca_cmd_box(dev, 0, mailbox->dma, (!!is_ee << 24) | num, 0,
1593 int err; 1556 CMD_QUERY_QPEE, CMD_TIME_CLASS_A, status);
1594
1595 outdma = pci_map_single(dev->pdev, qp_context,
1596 MTHCA_QP_CONTEXT_SIZE,
1597 PCI_DMA_FROMDEVICE);
1598 if (pci_dma_mapping_error(outdma))
1599 return -ENOMEM;
1600
1601 err = mthca_cmd_box(dev, 0, outdma, (!!is_ee << 24) | num, 0,
1602 CMD_QUERY_QPEE,
1603 CMD_TIME_CLASS_A, status);
1604
1605 pci_unmap_single(dev->pdev, outdma,
1606 MTHCA_QP_CONTEXT_SIZE,
1607 PCI_DMA_FROMDEVICE);
1608 return err;
1609} 1557}
1610 1558
1611int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, 1559int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
@@ -1635,11 +1583,11 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
1635} 1583}
1636 1584
1637int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, 1585int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1638 int port, struct ib_wc* in_wc, struct ib_grh* in_grh, 1586 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
1639 void *in_mad, void *response_mad, u8 *status) 1587 void *in_mad, void *response_mad, u8 *status)
1640{ 1588{
1641 void *box; 1589 struct mthca_mailbox *inmailbox, *outmailbox;
1642 dma_addr_t dma; 1590 void *inbox;
1643 int err; 1591 int err;
1644 u32 in_modifier = port; 1592 u32 in_modifier = port;
1645 u8 op_modifier = 0; 1593 u8 op_modifier = 0;
@@ -1653,11 +1601,18 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1653#define MAD_IFC_PKEY_OFFSET 0x10e 1601#define MAD_IFC_PKEY_OFFSET 0x10e
1654#define MAD_IFC_GRH_OFFSET 0x140 1602#define MAD_IFC_GRH_OFFSET 0x140
1655 1603
1656 box = pci_alloc_consistent(dev->pdev, MAD_IFC_BOX_SIZE, &dma); 1604 inmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1657 if (!box) 1605 if (IS_ERR(inmailbox))
1658 return -ENOMEM; 1606 return PTR_ERR(inmailbox);
1607 inbox = inmailbox->buf;
1659 1608
1660 memcpy(box, in_mad, 256); 1609 outmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
1610 if (IS_ERR(outmailbox)) {
1611 mthca_free_mailbox(dev, inmailbox);
1612 return PTR_ERR(outmailbox);
1613 }
1614
1615 memcpy(inbox, in_mad, 256);
1661 1616
1662 /* 1617 /*
1663 * Key check traps can't be generated unless we have in_wc to 1618 * Key check traps can't be generated unless we have in_wc to
@@ -1671,97 +1626,65 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
1671 if (in_wc) { 1626 if (in_wc) {
1672 u8 val; 1627 u8 val;
1673 1628
1674 memset(box + 256, 0, 256); 1629 memset(inbox + 256, 0, 256);
1675 1630
1676 MTHCA_PUT(box, in_wc->qp_num, MAD_IFC_MY_QPN_OFFSET); 1631 MTHCA_PUT(inbox, in_wc->qp_num, MAD_IFC_MY_QPN_OFFSET);
1677 MTHCA_PUT(box, in_wc->src_qp, MAD_IFC_RQPN_OFFSET); 1632 MTHCA_PUT(inbox, in_wc->src_qp, MAD_IFC_RQPN_OFFSET);
1678 1633
1679 val = in_wc->sl << 4; 1634 val = in_wc->sl << 4;
1680 MTHCA_PUT(box, val, MAD_IFC_SL_OFFSET); 1635 MTHCA_PUT(inbox, val, MAD_IFC_SL_OFFSET);
1681 1636
1682 val = in_wc->dlid_path_bits | 1637 val = in_wc->dlid_path_bits |
1683 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0); 1638 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
1684 MTHCA_PUT(box, val, MAD_IFC_GRH_OFFSET); 1639 MTHCA_PUT(inbox, val, MAD_IFC_GRH_OFFSET);
1685 1640
1686 MTHCA_PUT(box, in_wc->slid, MAD_IFC_RLID_OFFSET); 1641 MTHCA_PUT(inbox, in_wc->slid, MAD_IFC_RLID_OFFSET);
1687 MTHCA_PUT(box, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET); 1642 MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET);
1688 1643
1689 if (in_grh) 1644 if (in_grh)
1690 memcpy((u8 *) box + MAD_IFC_GRH_OFFSET, in_grh, 40); 1645 memcpy(inbox + MAD_IFC_GRH_OFFSET, in_grh, 40);
1691 1646
1692 op_modifier |= 0x10; 1647 op_modifier |= 0x10;
1693 1648
1694 in_modifier |= in_wc->slid << 16; 1649 in_modifier |= in_wc->slid << 16;
1695 } 1650 }
1696 1651
1697 err = mthca_cmd_box(dev, dma, dma + 512, in_modifier, op_modifier, 1652 err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma,
1653 in_modifier, op_modifier,
1698 CMD_MAD_IFC, CMD_TIME_CLASS_C, status); 1654 CMD_MAD_IFC, CMD_TIME_CLASS_C, status);
1699 1655
1700 if (!err && !*status) 1656 if (!err && !*status)
1701 memcpy(response_mad, box + 512, 256); 1657 memcpy(response_mad, outmailbox->buf, 256);
1702 1658
1703 pci_free_consistent(dev->pdev, MAD_IFC_BOX_SIZE, box, dma); 1659 mthca_free_mailbox(dev, inmailbox);
1660 mthca_free_mailbox(dev, outmailbox);
1704 return err; 1661 return err;
1705} 1662}
1706 1663
1707int mthca_READ_MGM(struct mthca_dev *dev, int index, void *mgm, 1664int mthca_READ_MGM(struct mthca_dev *dev, int index,
1708 u8 *status) 1665 struct mthca_mailbox *mailbox, u8 *status)
1709{ 1666{
1710 dma_addr_t outdma = 0; 1667 return mthca_cmd_box(dev, 0, mailbox->dma, index, 0,
1711 int err; 1668 CMD_READ_MGM, CMD_TIME_CLASS_A, status);
1712
1713 outdma = pci_map_single(dev->pdev, mgm,
1714 MTHCA_MGM_ENTRY_SIZE,
1715 PCI_DMA_FROMDEVICE);
1716 if (pci_dma_mapping_error(outdma))
1717 return -ENOMEM;
1718
1719 err = mthca_cmd_box(dev, 0, outdma, index, 0,
1720 CMD_READ_MGM,
1721 CMD_TIME_CLASS_A, status);
1722
1723 pci_unmap_single(dev->pdev, outdma,
1724 MTHCA_MGM_ENTRY_SIZE,
1725 PCI_DMA_FROMDEVICE);
1726 return err;
1727} 1669}
1728 1670
1729int mthca_WRITE_MGM(struct mthca_dev *dev, int index, void *mgm, 1671int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
1730 u8 *status) 1672 struct mthca_mailbox *mailbox, u8 *status)
1731{ 1673{
1732 dma_addr_t indma; 1674 return mthca_cmd(dev, mailbox->dma, index, 0, CMD_WRITE_MGM,
1733 int err; 1675 CMD_TIME_CLASS_A, status);
1734
1735 indma = pci_map_single(dev->pdev, mgm,
1736 MTHCA_MGM_ENTRY_SIZE,
1737 PCI_DMA_TODEVICE);
1738 if (pci_dma_mapping_error(indma))
1739 return -ENOMEM;
1740
1741 err = mthca_cmd(dev, indma, index, 0, CMD_WRITE_MGM,
1742 CMD_TIME_CLASS_A, status);
1743
1744 pci_unmap_single(dev->pdev, indma,
1745 MTHCA_MGM_ENTRY_SIZE, PCI_DMA_TODEVICE);
1746 return err;
1747} 1676}
1748 1677
1749int mthca_MGID_HASH(struct mthca_dev *dev, void *gid, u16 *hash, 1678int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
1750 u8 *status) 1679 u16 *hash, u8 *status)
1751{ 1680{
1752 dma_addr_t indma;
1753 u64 imm; 1681 u64 imm;
1754 int err; 1682 int err;
1755 1683
1756 indma = pci_map_single(dev->pdev, gid, 16, PCI_DMA_TODEVICE); 1684 err = mthca_cmd_imm(dev, mailbox->dma, &imm, 0, 0, CMD_MGID_HASH,
1757 if (pci_dma_mapping_error(indma))
1758 return -ENOMEM;
1759
1760 err = mthca_cmd_imm(dev, indma, &imm, 0, 0, CMD_MGID_HASH,
1761 CMD_TIME_CLASS_A, status); 1685 CMD_TIME_CLASS_A, status);
1762 *hash = imm;
1763 1686
1764 pci_unmap_single(dev->pdev, indma, 16, PCI_DMA_TODEVICE); 1687 *hash = imm;
1765 return err; 1688 return err;
1766} 1689}
1767 1690
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.h b/drivers/infiniband/hw/mthca/mthca_cmd.h
index adf039b3c540..ed517f175dd6 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.h
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.h
@@ -37,8 +37,7 @@
37 37
38#include <ib_verbs.h> 38#include <ib_verbs.h>
39 39
40#define MTHCA_CMD_MAILBOX_ALIGN 16UL 40#define MTHCA_MAILBOX_SIZE 4096
41#define MTHCA_CMD_MAILBOX_EXTRA (MTHCA_CMD_MAILBOX_ALIGN - 1)
42 41
43enum { 42enum {
44 /* command completed successfully: */ 43 /* command completed successfully: */
@@ -112,6 +111,11 @@ enum {
112 DEV_LIM_FLAG_UD_MULTI = 1 << 21, 111 DEV_LIM_FLAG_UD_MULTI = 1 << 21,
113}; 112};
114 113
114struct mthca_mailbox {
115 dma_addr_t dma;
116 void *buf;
117};
118
115struct mthca_dev_lim { 119struct mthca_dev_lim {
116 int max_srq_sz; 120 int max_srq_sz;
117 int max_qp_sz; 121 int max_qp_sz;
@@ -235,11 +239,17 @@ struct mthca_set_ib_param {
235 u32 cap_mask; 239 u32 cap_mask;
236}; 240};
237 241
242int mthca_cmd_init(struct mthca_dev *dev);
243void mthca_cmd_cleanup(struct mthca_dev *dev);
238int mthca_cmd_use_events(struct mthca_dev *dev); 244int mthca_cmd_use_events(struct mthca_dev *dev);
239void mthca_cmd_use_polling(struct mthca_dev *dev); 245void mthca_cmd_use_polling(struct mthca_dev *dev);
240void mthca_cmd_event(struct mthca_dev *dev, u16 token, 246void mthca_cmd_event(struct mthca_dev *dev, u16 token,
241 u8 status, u64 out_param); 247 u8 status, u64 out_param);
242 248
249struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
250 unsigned int gfp_mask);
251void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox);
252
243int mthca_SYS_EN(struct mthca_dev *dev, u8 *status); 253int mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
244int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status); 254int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status);
245int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status); 255int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
@@ -270,41 +280,39 @@ int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
270int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status); 280int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status);
271int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages, 281int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
272 u8 *status); 282 u8 *status);
273int mthca_SW2HW_MPT(struct mthca_dev *dev, void *mpt_entry, 283int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
274 int mpt_index, u8 *status); 284 int mpt_index, u8 *status);
275int mthca_HW2SW_MPT(struct mthca_dev *dev, void *mpt_entry, 285int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
276 int mpt_index, u8 *status); 286 int mpt_index, u8 *status);
277int mthca_WRITE_MTT(struct mthca_dev *dev, u64 *mtt_entry, 287int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
278 int num_mtt, u8 *status); 288 int num_mtt, u8 *status);
279int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status); 289int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status);
280int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap, 290int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
281 int eq_num, u8 *status); 291 int eq_num, u8 *status);
282int mthca_SW2HW_EQ(struct mthca_dev *dev, void *eq_context, 292int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
283 int eq_num, u8 *status); 293 int eq_num, u8 *status);
284int mthca_HW2SW_EQ(struct mthca_dev *dev, void *eq_context, 294int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
285 int eq_num, u8 *status); 295 int eq_num, u8 *status);
286int mthca_SW2HW_CQ(struct mthca_dev *dev, void *cq_context, 296int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
287 int cq_num, u8 *status); 297 int cq_num, u8 *status);
288int mthca_HW2SW_CQ(struct mthca_dev *dev, void *cq_context, 298int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
289 int cq_num, u8 *status); 299 int cq_num, u8 *status);
290int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, 300int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
291 int is_ee, void *qp_context, u32 optmask, 301 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
292 u8 *status); 302 u8 *status);
293int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, 303int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
294 void *qp_context, u8 *status); 304 struct mthca_mailbox *mailbox, u8 *status);
295int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, 305int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
296 u8 *status); 306 u8 *status);
297int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, 307int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
298 int port, struct ib_wc* in_wc, struct ib_grh* in_grh, 308 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
299 void *in_mad, void *response_mad, u8 *status); 309 void *in_mad, void *response_mad, u8 *status);
300int mthca_READ_MGM(struct mthca_dev *dev, int index, void *mgm, 310int mthca_READ_MGM(struct mthca_dev *dev, int index,
301 u8 *status); 311 struct mthca_mailbox *mailbox, u8 *status);
302int mthca_WRITE_MGM(struct mthca_dev *dev, int index, void *mgm, 312int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
303 u8 *status); 313 struct mthca_mailbox *mailbox, u8 *status);
304int mthca_MGID_HASH(struct mthca_dev *dev, void *gid, u16 *hash, 314int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
305 u8 *status); 315 u16 *hash, u8 *status);
306int mthca_NOP(struct mthca_dev *dev, u8 *status); 316int mthca_NOP(struct mthca_dev *dev, u8 *status);
307 317
308#define MAILBOX_ALIGN(x) ((void *) ALIGN((unsigned long) (x), MTHCA_CMD_MAILBOX_ALIGN))
309
310#endif /* MTHCA_CMD_H */ 318#endif /* MTHCA_CMD_H */
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 2bf347b84c31..b5aea7b869f6 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved.
3 * 5 *
4 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -171,6 +173,17 @@ static inline void set_cqe_hw(struct mthca_cqe *cqe)
171 cqe->owner = MTHCA_CQ_ENTRY_OWNER_HW; 173 cqe->owner = MTHCA_CQ_ENTRY_OWNER_HW;
172} 174}
173 175
176static void dump_cqe(struct mthca_dev *dev, void *cqe_ptr)
177{
178 __be32 *cqe = cqe_ptr;
179
180 (void) cqe; /* avoid warning if mthca_dbg compiled away... */
181 mthca_dbg(dev, "CQE contents %08x %08x %08x %08x %08x %08x %08x %08x\n",
182 be32_to_cpu(cqe[0]), be32_to_cpu(cqe[1]), be32_to_cpu(cqe[2]),
183 be32_to_cpu(cqe[3]), be32_to_cpu(cqe[4]), be32_to_cpu(cqe[5]),
184 be32_to_cpu(cqe[6]), be32_to_cpu(cqe[7]));
185}
186
174/* 187/*
175 * incr is ignored in native Arbel (mem-free) mode, so cq->cons_index 188 * incr is ignored in native Arbel (mem-free) mode, so cq->cons_index
176 * should be correct before calling update_cons_index(). 189 * should be correct before calling update_cons_index().
@@ -280,16 +293,12 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
280 int dbd; 293 int dbd;
281 u32 new_wqe; 294 u32 new_wqe;
282 295
283 if (1 && cqe->syndrome != SYNDROME_WR_FLUSH_ERR) { 296 if (cqe->syndrome == SYNDROME_LOCAL_QP_OP_ERR) {
284 int j; 297 mthca_dbg(dev, "local QP operation err "
285 298 "(QPN %06x, WQE @ %08x, CQN %06x, index %d)\n",
286 mthca_dbg(dev, "%x/%d: error CQE -> QPN %06x, WQE @ %08x\n", 299 be32_to_cpu(cqe->my_qpn), be32_to_cpu(cqe->wqe),
287 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn), 300 cq->cqn, cq->cons_index);
288 be32_to_cpu(cqe->wqe)); 301 dump_cqe(dev, cqe);
289
290 for (j = 0; j < 8; ++j)
291 printk(KERN_DEBUG " [%2x] %08x\n",
292 j * 4, be32_to_cpu(((u32 *) cqe)[j]));
293 } 302 }
294 303
295 /* 304 /*
@@ -377,15 +386,6 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
377 return 0; 386 return 0;
378} 387}
379 388
380static void dump_cqe(struct mthca_cqe *cqe)
381{
382 int j;
383
384 for (j = 0; j < 8; ++j)
385 printk(KERN_DEBUG " [%2x] %08x\n",
386 j * 4, be32_to_cpu(((u32 *) cqe)[j]));
387}
388
389static inline int mthca_poll_one(struct mthca_dev *dev, 389static inline int mthca_poll_one(struct mthca_dev *dev,
390 struct mthca_cq *cq, 390 struct mthca_cq *cq,
391 struct mthca_qp **cur_qp, 391 struct mthca_qp **cur_qp,
@@ -414,8 +414,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
414 mthca_dbg(dev, "%x/%d: CQE -> QPN %06x, WQE @ %08x\n", 414 mthca_dbg(dev, "%x/%d: CQE -> QPN %06x, WQE @ %08x\n",
415 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn), 415 cq->cqn, cq->cons_index, be32_to_cpu(cqe->my_qpn),
416 be32_to_cpu(cqe->wqe)); 416 be32_to_cpu(cqe->wqe));
417 417 dump_cqe(dev, cqe);
418 dump_cqe(cqe);
419 } 418 }
420 419
421 is_error = (cqe->opcode & MTHCA_ERROR_CQE_OPCODE_MASK) == 420 is_error = (cqe->opcode & MTHCA_ERROR_CQE_OPCODE_MASK) ==
@@ -638,19 +637,19 @@ static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)
638 int size; 637 int size;
639 638
640 if (cq->is_direct) 639 if (cq->is_direct)
641 pci_free_consistent(dev->pdev, 640 dma_free_coherent(&dev->pdev->dev,
642 (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE, 641 (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,
643 cq->queue.direct.buf, 642 cq->queue.direct.buf,
644 pci_unmap_addr(&cq->queue.direct, 643 pci_unmap_addr(&cq->queue.direct,
645 mapping)); 644 mapping));
646 else { 645 else {
647 size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE; 646 size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE;
648 for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i) 647 for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i)
649 if (cq->queue.page_list[i].buf) 648 if (cq->queue.page_list[i].buf)
650 pci_free_consistent(dev->pdev, PAGE_SIZE, 649 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
651 cq->queue.page_list[i].buf, 650 cq->queue.page_list[i].buf,
652 pci_unmap_addr(&cq->queue.page_list[i], 651 pci_unmap_addr(&cq->queue.page_list[i],
653 mapping)); 652 mapping));
654 653
655 kfree(cq->queue.page_list); 654 kfree(cq->queue.page_list);
656 } 655 }
@@ -670,8 +669,8 @@ static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,
670 npages = 1; 669 npages = 1;
671 shift = get_order(size) + PAGE_SHIFT; 670 shift = get_order(size) + PAGE_SHIFT;
672 671
673 cq->queue.direct.buf = pci_alloc_consistent(dev->pdev, 672 cq->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev,
674 size, &t); 673 size, &t, GFP_KERNEL);
675 if (!cq->queue.direct.buf) 674 if (!cq->queue.direct.buf)
676 return -ENOMEM; 675 return -ENOMEM;
677 676
@@ -709,7 +708,8 @@ static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,
709 708
710 for (i = 0; i < npages; ++i) { 709 for (i = 0; i < npages; ++i) {
711 cq->queue.page_list[i].buf = 710 cq->queue.page_list[i].buf =
712 pci_alloc_consistent(dev->pdev, PAGE_SIZE, &t); 711 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
712 &t, GFP_KERNEL);
713 if (!cq->queue.page_list[i].buf) 713 if (!cq->queue.page_list[i].buf)
714 goto err_free; 714 goto err_free;
715 715
@@ -743,10 +743,11 @@ err_out:
743} 743}
744 744
745int mthca_init_cq(struct mthca_dev *dev, int nent, 745int mthca_init_cq(struct mthca_dev *dev, int nent,
746 struct mthca_ucontext *ctx, u32 pdn,
746 struct mthca_cq *cq) 747 struct mthca_cq *cq)
747{ 748{
748 int size = nent * MTHCA_CQ_ENTRY_SIZE; 749 int size = nent * MTHCA_CQ_ENTRY_SIZE;
749 void *mailbox = NULL; 750 struct mthca_mailbox *mailbox;
750 struct mthca_cq_context *cq_context; 751 struct mthca_cq_context *cq_context;
751 int err = -ENOMEM; 752 int err = -ENOMEM;
752 u8 status; 753 u8 status;
@@ -754,45 +755,49 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
754 755
755 might_sleep(); 756 might_sleep();
756 757
757 cq->ibcq.cqe = nent - 1; 758 cq->ibcq.cqe = nent - 1;
759 cq->is_kernel = !ctx;
758 760
759 cq->cqn = mthca_alloc(&dev->cq_table.alloc); 761 cq->cqn = mthca_alloc(&dev->cq_table.alloc);
760 if (cq->cqn == -1) 762 if (cq->cqn == -1)
761 return -ENOMEM; 763 return -ENOMEM;
762 764
763 if (mthca_is_memfree(dev)) { 765 if (mthca_is_memfree(dev)) {
764 cq->arm_sn = 1;
765
766 err = mthca_table_get(dev, dev->cq_table.table, cq->cqn); 766 err = mthca_table_get(dev, dev->cq_table.table, cq->cqn);
767 if (err) 767 if (err)
768 goto err_out; 768 goto err_out;
769 769
770 err = -ENOMEM; 770 if (cq->is_kernel) {
771 cq->arm_sn = 1;
771 772
772 cq->set_ci_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, 773 err = -ENOMEM;
773 cq->cqn, &cq->set_ci_db);
774 if (cq->set_ci_db_index < 0)
775 goto err_out_icm;
776 774
777 cq->arm_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_ARM, 775 cq->set_ci_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_SET_CI,
778 cq->cqn, &cq->arm_db); 776 cq->cqn, &cq->set_ci_db);
779 if (cq->arm_db_index < 0) 777 if (cq->set_ci_db_index < 0)
780 goto err_out_ci; 778 goto err_out_icm;
779
780 cq->arm_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_ARM,
781 cq->cqn, &cq->arm_db);
782 if (cq->arm_db_index < 0)
783 goto err_out_ci;
784 }
781 } 785 }
782 786
783 mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, 787 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
784 GFP_KERNEL); 788 if (IS_ERR(mailbox))
785 if (!mailbox) 789 goto err_out_arm;
786 goto err_out_mailbox;
787 790
788 cq_context = MAILBOX_ALIGN(mailbox); 791 cq_context = mailbox->buf;
789 792
790 err = mthca_alloc_cq_buf(dev, size, cq); 793 if (cq->is_kernel) {
791 if (err) 794 err = mthca_alloc_cq_buf(dev, size, cq);
792 goto err_out_mailbox; 795 if (err)
796 goto err_out_mailbox;
793 797
794 for (i = 0; i < nent; ++i) 798 for (i = 0; i < nent; ++i)
795 set_cqe_hw(get_cqe(cq, i)); 799 set_cqe_hw(get_cqe(cq, i));
800 }
796 801
797 spin_lock_init(&cq->lock); 802 spin_lock_init(&cq->lock);
798 atomic_set(&cq->refcount, 1); 803 atomic_set(&cq->refcount, 1);
@@ -803,11 +808,14 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
803 MTHCA_CQ_STATE_DISARMED | 808 MTHCA_CQ_STATE_DISARMED |
804 MTHCA_CQ_FLAG_TR); 809 MTHCA_CQ_FLAG_TR);
805 cq_context->start = cpu_to_be64(0); 810 cq_context->start = cpu_to_be64(0);
806 cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24 | 811 cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24);
807 dev->driver_uar.index); 812 if (ctx)
813 cq_context->logsize_usrpage |= cpu_to_be32(ctx->uar.index);
814 else
815 cq_context->logsize_usrpage |= cpu_to_be32(dev->driver_uar.index);
808 cq_context->error_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn); 816 cq_context->error_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn);
809 cq_context->comp_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_COMP].eqn); 817 cq_context->comp_eqn = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_COMP].eqn);
810 cq_context->pd = cpu_to_be32(dev->driver_pd.pd_num); 818 cq_context->pd = cpu_to_be32(pdn);
811 cq_context->lkey = cpu_to_be32(cq->mr.ibmr.lkey); 819 cq_context->lkey = cpu_to_be32(cq->mr.ibmr.lkey);
812 cq_context->cqn = cpu_to_be32(cq->cqn); 820 cq_context->cqn = cpu_to_be32(cq->cqn);
813 821
@@ -816,7 +824,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
816 cq_context->state_db = cpu_to_be32(cq->arm_db_index); 824 cq_context->state_db = cpu_to_be32(cq->arm_db_index);
817 } 825 }
818 826
819 err = mthca_SW2HW_CQ(dev, cq_context, cq->cqn, &status); 827 err = mthca_SW2HW_CQ(dev, mailbox, cq->cqn, &status);
820 if (err) { 828 if (err) {
821 mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err); 829 mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err);
822 goto err_out_free_mr; 830 goto err_out_free_mr;
@@ -840,22 +848,25 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
840 848
841 cq->cons_index = 0; 849 cq->cons_index = 0;
842 850
843 kfree(mailbox); 851 mthca_free_mailbox(dev, mailbox);
844 852
845 return 0; 853 return 0;
846 854
847err_out_free_mr: 855err_out_free_mr:
848 mthca_free_mr(dev, &cq->mr); 856 if (cq->is_kernel) {
849 mthca_free_cq_buf(dev, cq); 857 mthca_free_mr(dev, &cq->mr);
858 mthca_free_cq_buf(dev, cq);
859 }
850 860
851err_out_mailbox: 861err_out_mailbox:
852 kfree(mailbox); 862 mthca_free_mailbox(dev, mailbox);
853 863
854 if (mthca_is_memfree(dev)) 864err_out_arm:
865 if (cq->is_kernel && mthca_is_memfree(dev))
855 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 866 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
856 867
857err_out_ci: 868err_out_ci:
858 if (mthca_is_memfree(dev)) 869 if (cq->is_kernel && mthca_is_memfree(dev))
859 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index); 870 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);
860 871
861err_out_icm: 872err_out_icm:
@@ -870,32 +881,31 @@ err_out:
870void mthca_free_cq(struct mthca_dev *dev, 881void mthca_free_cq(struct mthca_dev *dev,
871 struct mthca_cq *cq) 882 struct mthca_cq *cq)
872{ 883{
873 void *mailbox; 884 struct mthca_mailbox *mailbox;
874 int err; 885 int err;
875 u8 status; 886 u8 status;
876 887
877 might_sleep(); 888 might_sleep();
878 889
879 mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, 890 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
880 GFP_KERNEL); 891 if (IS_ERR(mailbox)) {
881 if (!mailbox) {
882 mthca_warn(dev, "No memory for mailbox to free CQ.\n"); 892 mthca_warn(dev, "No memory for mailbox to free CQ.\n");
883 return; 893 return;
884 } 894 }
885 895
886 err = mthca_HW2SW_CQ(dev, MAILBOX_ALIGN(mailbox), cq->cqn, &status); 896 err = mthca_HW2SW_CQ(dev, mailbox, cq->cqn, &status);
887 if (err) 897 if (err)
888 mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err); 898 mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err);
889 else if (status) 899 else if (status)
890 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", 900 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);
891 status);
892 901
893 if (0) { 902 if (0) {
894 u32 *ctx = MAILBOX_ALIGN(mailbox); 903 u32 *ctx = mailbox->buf;
895 int j; 904 int j;
896 905
897 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n", 906 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",
898 cq->cqn, cq->cons_index, !!next_cqe_sw(cq)); 907 cq->cqn, cq->cons_index,
908 cq->is_kernel ? !!next_cqe_sw(cq) : 0);
899 for (j = 0; j < 16; ++j) 909 for (j = 0; j < 16; ++j)
900 printk(KERN_ERR "[%2x] %08x\n", j * 4, be32_to_cpu(ctx[j])); 910 printk(KERN_ERR "[%2x] %08x\n", j * 4, be32_to_cpu(ctx[j]));
901 } 911 }
@@ -913,17 +923,18 @@ void mthca_free_cq(struct mthca_dev *dev,
913 atomic_dec(&cq->refcount); 923 atomic_dec(&cq->refcount);
914 wait_event(cq->wait, !atomic_read(&cq->refcount)); 924 wait_event(cq->wait, !atomic_read(&cq->refcount));
915 925
916 mthca_free_mr(dev, &cq->mr); 926 if (cq->is_kernel) {
917 mthca_free_cq_buf(dev, cq); 927 mthca_free_mr(dev, &cq->mr);
918 928 mthca_free_cq_buf(dev, cq);
919 if (mthca_is_memfree(dev)) { 929 if (mthca_is_memfree(dev)) {
920 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 930 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
921 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index); 931 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);
922 mthca_table_put(dev, dev->cq_table.table, cq->cqn); 932 }
923 } 933 }
924 934
935 mthca_table_put(dev, dev->cq_table.table, cq->cqn);
925 mthca_free(&dev->cq_table.alloc, cq->cqn); 936 mthca_free(&dev->cq_table.alloc, cq->cqn);
926 kfree(mailbox); 937 mthca_free_mailbox(dev, mailbox);
927} 938}
928 939
929int __devinit mthca_init_cq_table(struct mthca_dev *dev) 940int __devinit mthca_init_cq_table(struct mthca_dev *dev)
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index e3d79e267dc9..5ecdd2eeeb0f 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 5 *
4 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -46,8 +48,8 @@
46 48
47#define DRV_NAME "ib_mthca" 49#define DRV_NAME "ib_mthca"
48#define PFX DRV_NAME ": " 50#define PFX DRV_NAME ": "
49#define DRV_VERSION "0.06-pre" 51#define DRV_VERSION "0.06"
50#define DRV_RELDATE "November 8, 2004" 52#define DRV_RELDATE "June 23, 2005"
51 53
52enum { 54enum {
53 MTHCA_FLAG_DDR_HIDDEN = 1 << 1, 55 MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
@@ -98,6 +100,7 @@ enum {
98}; 100};
99 101
100struct mthca_cmd { 102struct mthca_cmd {
103 struct pci_pool *pool;
101 int use_events; 104 int use_events;
102 struct semaphore hcr_sem; 105 struct semaphore hcr_sem;
103 struct semaphore poll_sem; 106 struct semaphore poll_sem;
@@ -376,9 +379,15 @@ void mthca_unregister_device(struct mthca_dev *dev);
376int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar); 379int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
377void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar); 380void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
378 381
379int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd); 382int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);
380void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd); 383void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
381 384
385struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
386void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);
387int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
388 int start_index, u64 *buffer_list, int list_len);
389int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
390 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr);
382int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd, 391int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
383 u32 access, struct mthca_mr *mr); 392 u32 access, struct mthca_mr *mr);
384int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd, 393int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
@@ -405,6 +414,7 @@ int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
405int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify); 414int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
406int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify); 415int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
407int mthca_init_cq(struct mthca_dev *dev, int nent, 416int mthca_init_cq(struct mthca_dev *dev, int nent,
417 struct mthca_ucontext *ctx, u32 pdn,
408 struct mthca_cq *cq); 418 struct mthca_cq *cq);
409void mthca_free_cq(struct mthca_dev *dev, 419void mthca_free_cq(struct mthca_dev *dev,
410 struct mthca_cq *cq); 420 struct mthca_cq *cq);
@@ -430,12 +440,14 @@ int mthca_alloc_qp(struct mthca_dev *dev,
430 struct mthca_cq *recv_cq, 440 struct mthca_cq *recv_cq,
431 enum ib_qp_type type, 441 enum ib_qp_type type,
432 enum ib_sig_type send_policy, 442 enum ib_sig_type send_policy,
443 struct ib_qp_cap *cap,
433 struct mthca_qp *qp); 444 struct mthca_qp *qp);
434int mthca_alloc_sqp(struct mthca_dev *dev, 445int mthca_alloc_sqp(struct mthca_dev *dev,
435 struct mthca_pd *pd, 446 struct mthca_pd *pd,
436 struct mthca_cq *send_cq, 447 struct mthca_cq *send_cq,
437 struct mthca_cq *recv_cq, 448 struct mthca_cq *recv_cq,
438 enum ib_sig_type send_policy, 449 enum ib_sig_type send_policy,
450 struct ib_qp_cap *cap,
439 int qpn, 451 int qpn,
440 int port, 452 int port,
441 struct mthca_sqp *sqp); 453 struct mthca_sqp *sqp);
diff --git a/drivers/infiniband/hw/mthca/mthca_doorbell.h b/drivers/infiniband/hw/mthca/mthca_doorbell.h
index 821039a49049..535fad7710fb 100644
--- a/drivers/infiniband/hw/mthca/mthca_doorbell.h
+++ b/drivers/infiniband/hw/mthca/mthca_doorbell.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index f46d615d396f..cbcf2b4722e4 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -469,7 +469,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
469 PAGE_SIZE; 469 PAGE_SIZE;
470 u64 *dma_list = NULL; 470 u64 *dma_list = NULL;
471 dma_addr_t t; 471 dma_addr_t t;
472 void *mailbox = NULL; 472 struct mthca_mailbox *mailbox;
473 struct mthca_eq_context *eq_context; 473 struct mthca_eq_context *eq_context;
474 int err = -ENOMEM; 474 int err = -ENOMEM;
475 int i; 475 int i;
@@ -494,17 +494,16 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
494 if (!dma_list) 494 if (!dma_list)
495 goto err_out_free; 495 goto err_out_free;
496 496
497 mailbox = kmalloc(sizeof *eq_context + MTHCA_CMD_MAILBOX_EXTRA, 497 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
498 GFP_KERNEL); 498 if (IS_ERR(mailbox))
499 if (!mailbox)
500 goto err_out_free; 499 goto err_out_free;
501 eq_context = MAILBOX_ALIGN(mailbox); 500 eq_context = mailbox->buf;
502 501
503 for (i = 0; i < npages; ++i) { 502 for (i = 0; i < npages; ++i) {
504 eq->page_list[i].buf = pci_alloc_consistent(dev->pdev, 503 eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
505 PAGE_SIZE, &t); 504 PAGE_SIZE, &t, GFP_KERNEL);
506 if (!eq->page_list[i].buf) 505 if (!eq->page_list[i].buf)
507 goto err_out_free; 506 goto err_out_free_pages;
508 507
509 dma_list[i] = t; 508 dma_list[i] = t;
510 pci_unmap_addr_set(&eq->page_list[i], mapping, t); 509 pci_unmap_addr_set(&eq->page_list[i], mapping, t);
@@ -517,7 +516,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
517 516
518 eq->eqn = mthca_alloc(&dev->eq_table.alloc); 517 eq->eqn = mthca_alloc(&dev->eq_table.alloc);
519 if (eq->eqn == -1) 518 if (eq->eqn == -1)
520 goto err_out_free; 519 goto err_out_free_pages;
521 520
522 err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num, 521 err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,
523 dma_list, PAGE_SHIFT, npages, 522 dma_list, PAGE_SHIFT, npages,
@@ -548,7 +547,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
548 eq_context->intr = intr; 547 eq_context->intr = intr;
549 eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey); 548 eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey);
550 549
551 err = mthca_SW2HW_EQ(dev, eq_context, eq->eqn, &status); 550 err = mthca_SW2HW_EQ(dev, mailbox, eq->eqn, &status);
552 if (err) { 551 if (err) {
553 mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err); 552 mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err);
554 goto err_out_free_mr; 553 goto err_out_free_mr;
@@ -561,7 +560,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
561 } 560 }
562 561
563 kfree(dma_list); 562 kfree(dma_list);
564 kfree(mailbox); 563 mthca_free_mailbox(dev, mailbox);
565 564
566 eq->eqn_mask = swab32(1 << eq->eqn); 565 eq->eqn_mask = swab32(1 << eq->eqn);
567 eq->cons_index = 0; 566 eq->cons_index = 0;
@@ -579,17 +578,19 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
579 err_out_free_eq: 578 err_out_free_eq:
580 mthca_free(&dev->eq_table.alloc, eq->eqn); 579 mthca_free(&dev->eq_table.alloc, eq->eqn);
581 580
582 err_out_free: 581 err_out_free_pages:
583 for (i = 0; i < npages; ++i) 582 for (i = 0; i < npages; ++i)
584 if (eq->page_list[i].buf) 583 if (eq->page_list[i].buf)
585 pci_free_consistent(dev->pdev, PAGE_SIZE, 584 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
586 eq->page_list[i].buf, 585 eq->page_list[i].buf,
587 pci_unmap_addr(&eq->page_list[i], 586 pci_unmap_addr(&eq->page_list[i],
588 mapping)); 587 mapping));
588
589 mthca_free_mailbox(dev, mailbox);
589 590
591 err_out_free:
590 kfree(eq->page_list); 592 kfree(eq->page_list);
591 kfree(dma_list); 593 kfree(dma_list);
592 kfree(mailbox);
593 594
594 err_out: 595 err_out:
595 return err; 596 return err;
@@ -598,25 +599,22 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
598static void mthca_free_eq(struct mthca_dev *dev, 599static void mthca_free_eq(struct mthca_dev *dev,
599 struct mthca_eq *eq) 600 struct mthca_eq *eq)
600{ 601{
601 void *mailbox = NULL; 602 struct mthca_mailbox *mailbox;
602 int err; 603 int err;
603 u8 status; 604 u8 status;
604 int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) / 605 int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) /
605 PAGE_SIZE; 606 PAGE_SIZE;
606 int i; 607 int i;
607 608
608 mailbox = kmalloc(sizeof (struct mthca_eq_context) + MTHCA_CMD_MAILBOX_EXTRA, 609 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
609 GFP_KERNEL); 610 if (IS_ERR(mailbox))
610 if (!mailbox)
611 return; 611 return;
612 612
613 err = mthca_HW2SW_EQ(dev, MAILBOX_ALIGN(mailbox), 613 err = mthca_HW2SW_EQ(dev, mailbox, eq->eqn, &status);
614 eq->eqn, &status);
615 if (err) 614 if (err)
616 mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err); 615 mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err);
617 if (status) 616 if (status)
618 mthca_warn(dev, "HW2SW_EQ returned status 0x%02x\n", 617 mthca_warn(dev, "HW2SW_EQ returned status 0x%02x\n", status);
619 status);
620 618
621 dev->eq_table.arm_mask &= ~eq->eqn_mask; 619 dev->eq_table.arm_mask &= ~eq->eqn_mask;
622 620
@@ -625,7 +623,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
625 for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) { 623 for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) {
626 if (i % 4 == 0) 624 if (i % 4 == 0)
627 printk("[%02x] ", i * 4); 625 printk("[%02x] ", i * 4);
628 printk(" %08x", be32_to_cpup(MAILBOX_ALIGN(mailbox) + i * 4)); 626 printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
629 if ((i + 1) % 4 == 0) 627 if ((i + 1) % 4 == 0)
630 printk("\n"); 628 printk("\n");
631 } 629 }
@@ -638,7 +636,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
638 pci_unmap_addr(&eq->page_list[i], mapping)); 636 pci_unmap_addr(&eq->page_list[i], mapping));
639 637
640 kfree(eq->page_list); 638 kfree(eq->page_list);
641 kfree(mailbox); 639 mthca_free_mailbox(dev, mailbox);
642} 640}
643 641
644static void mthca_free_irqs(struct mthca_dev *dev) 642static void mthca_free_irqs(struct mthca_dev *dev)
@@ -709,8 +707,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)
709 if (mthca_map_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) & 707 if (mthca_map_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
710 dev->fw.arbel.eq_arm_base) + 4, 4, 708 dev->fw.arbel.eq_arm_base) + 4, 4,
711 &dev->eq_regs.arbel.eq_arm)) { 709 &dev->eq_regs.arbel.eq_arm)) {
712 mthca_err(dev, "Couldn't map interrupt clear register, " 710 mthca_err(dev, "Couldn't map EQ arm register, aborting.\n");
713 "aborting.\n");
714 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) & 711 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
715 dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE, 712 dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
716 dev->clr_base); 713 dev->clr_base);
@@ -721,8 +718,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)
721 dev->fw.arbel.eq_set_ci_base, 718 dev->fw.arbel.eq_set_ci_base,
722 MTHCA_EQ_SET_CI_SIZE, 719 MTHCA_EQ_SET_CI_SIZE,
723 &dev->eq_regs.arbel.eq_set_ci_base)) { 720 &dev->eq_regs.arbel.eq_set_ci_base)) {
724 mthca_err(dev, "Couldn't map interrupt clear register, " 721 mthca_err(dev, "Couldn't map EQ CI register, aborting.\n");
725 "aborting.\n");
726 mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) & 722 mthca_unmap_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
727 dev->fw.arbel.eq_arm_base) + 4, 4, 723 dev->fw.arbel.eq_arm_base) + 4, 4,
728 dev->eq_regs.arbel.eq_arm); 724 dev->eq_regs.arbel.eq_arm);
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index d40590356df8..2ef916859e17 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -69,7 +70,7 @@ MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero");
69#endif /* CONFIG_PCI_MSI */ 70#endif /* CONFIG_PCI_MSI */
70 71
71static const char mthca_version[] __devinitdata = 72static const char mthca_version[] __devinitdata =
72 "ib_mthca: Mellanox InfiniBand HCA driver v" 73 DRV_NAME ": Mellanox InfiniBand HCA driver v"
73 DRV_VERSION " (" DRV_RELDATE ")\n"; 74 DRV_VERSION " (" DRV_RELDATE ")\n";
74 75
75static struct mthca_profile default_profile = { 76static struct mthca_profile default_profile = {
@@ -664,7 +665,7 @@ static int __devinit mthca_setup_hca(struct mthca_dev *dev)
664 goto err_pd_table_free; 665 goto err_pd_table_free;
665 } 666 }
666 667
667 err = mthca_pd_alloc(dev, &dev->driver_pd); 668 err = mthca_pd_alloc(dev, 1, &dev->driver_pd);
668 if (err) { 669 if (err) {
669 mthca_err(dev, "Failed to create driver PD, " 670 mthca_err(dev, "Failed to create driver PD, "
670 "aborting.\n"); 671 "aborting.\n");
@@ -927,13 +928,13 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
927 */ 928 */
928 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) || 929 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
929 pci_resource_len(pdev, 0) != 1 << 20) { 930 pci_resource_len(pdev, 0) != 1 << 20) {
930 dev_err(&pdev->dev, "Missing DCS, aborting."); 931 dev_err(&pdev->dev, "Missing DCS, aborting.\n");
931 err = -ENODEV; 932 err = -ENODEV;
932 goto err_disable_pdev; 933 goto err_disable_pdev;
933 } 934 }
934 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM) || 935 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM) ||
935 pci_resource_len(pdev, 2) != 1 << 23) { 936 pci_resource_len(pdev, 2) != 1 << 23) {
936 dev_err(&pdev->dev, "Missing UAR, aborting."); 937 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
937 err = -ENODEV; 938 err = -ENODEV;
938 goto err_disable_pdev; 939 goto err_disable_pdev;
939 } 940 }
@@ -1004,25 +1005,18 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
1004 !pci_enable_msi(pdev)) 1005 !pci_enable_msi(pdev))
1005 mdev->mthca_flags |= MTHCA_FLAG_MSI; 1006 mdev->mthca_flags |= MTHCA_FLAG_MSI;
1006 1007
1007 sema_init(&mdev->cmd.hcr_sem, 1); 1008 if (mthca_cmd_init(mdev)) {
1008 sema_init(&mdev->cmd.poll_sem, 1); 1009 mthca_err(mdev, "Failed to init command interface, aborting.\n");
1009 mdev->cmd.use_events = 0;
1010
1011 mdev->hcr = ioremap(pci_resource_start(pdev, 0) + MTHCA_HCR_BASE, MTHCA_HCR_SIZE);
1012 if (!mdev->hcr) {
1013 mthca_err(mdev, "Couldn't map command register, "
1014 "aborting.\n");
1015 err = -ENOMEM;
1016 goto err_free_dev; 1010 goto err_free_dev;
1017 } 1011 }
1018 1012
1019 err = mthca_tune_pci(mdev); 1013 err = mthca_tune_pci(mdev);
1020 if (err) 1014 if (err)
1021 goto err_iounmap; 1015 goto err_cmd;
1022 1016
1023 err = mthca_init_hca(mdev); 1017 err = mthca_init_hca(mdev);
1024 if (err) 1018 if (err)
1025 goto err_iounmap; 1019 goto err_cmd;
1026 1020
1027 if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) { 1021 if (mdev->fw_ver < mthca_hca_table[id->driver_data].latest_fw) {
1028 mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n", 1022 mthca_warn(mdev, "HCA FW version %x.%x.%x is old (%x.%x.%x is current).\n",
@@ -1070,8 +1064,8 @@ err_cleanup:
1070err_close: 1064err_close:
1071 mthca_close_hca(mdev); 1065 mthca_close_hca(mdev);
1072 1066
1073err_iounmap: 1067err_cmd:
1074 iounmap(mdev->hcr); 1068 mthca_cmd_cleanup(mdev);
1075 1069
1076err_free_dev: 1070err_free_dev:
1077 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) 1071 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
@@ -1118,10 +1112,8 @@ static void __devexit mthca_remove_one(struct pci_dev *pdev)
1118 iounmap(mdev->kar); 1112 iounmap(mdev->kar);
1119 mthca_uar_free(mdev, &mdev->driver_uar); 1113 mthca_uar_free(mdev, &mdev->driver_uar);
1120 mthca_cleanup_uar_table(mdev); 1114 mthca_cleanup_uar_table(mdev);
1121
1122 mthca_close_hca(mdev); 1115 mthca_close_hca(mdev);
1123 1116 mthca_cmd_cleanup(mdev);
1124 iounmap(mdev->hcr);
1125 1117
1126 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X) 1118 if (mdev->mthca_flags & MTHCA_FLAG_MSI_X)
1127 pci_disable_msix(pdev); 1119 pci_disable_msix(pdev);
@@ -1163,7 +1155,7 @@ static struct pci_device_id mthca_pci_table[] = {
1163MODULE_DEVICE_TABLE(pci, mthca_pci_table); 1155MODULE_DEVICE_TABLE(pci, mthca_pci_table);
1164 1156
1165static struct pci_driver mthca_driver = { 1157static struct pci_driver mthca_driver = {
1166 .name = "ib_mthca", 1158 .name = DRV_NAME,
1167 .id_table = mthca_pci_table, 1159 .id_table = mthca_pci_table,
1168 .probe = mthca_init_one, 1160 .probe = mthca_init_one,
1169 .remove = __devexit_p(mthca_remove_one) 1161 .remove = __devexit_p(mthca_remove_one)
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c
index 70a6553a588e..5be7d949dbf6 100644
--- a/drivers/infiniband/hw/mthca/mthca_mcg.c
+++ b/drivers/infiniband/hw/mthca/mthca_mcg.c
@@ -66,22 +66,23 @@ static const u8 zero_gid[16]; /* automatically initialized to 0 */
66 * entry in hash chain and *mgm holds end of hash chain. 66 * entry in hash chain and *mgm holds end of hash chain.
67 */ 67 */
68static int find_mgm(struct mthca_dev *dev, 68static int find_mgm(struct mthca_dev *dev,
69 u8 *gid, struct mthca_mgm *mgm, 69 u8 *gid, struct mthca_mailbox *mgm_mailbox,
70 u16 *hash, int *prev, int *index) 70 u16 *hash, int *prev, int *index)
71{ 71{
72 void *mailbox; 72 struct mthca_mailbox *mailbox;
73 struct mthca_mgm *mgm = mgm_mailbox->buf;
73 u8 *mgid; 74 u8 *mgid;
74 int err; 75 int err;
75 u8 status; 76 u8 status;
76 77
77 mailbox = kmalloc(16 + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 78 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
78 if (!mailbox) 79 if (IS_ERR(mailbox))
79 return -ENOMEM; 80 return -ENOMEM;
80 mgid = MAILBOX_ALIGN(mailbox); 81 mgid = mailbox->buf;
81 82
82 memcpy(mgid, gid, 16); 83 memcpy(mgid, gid, 16);
83 84
84 err = mthca_MGID_HASH(dev, mgid, hash, &status); 85 err = mthca_MGID_HASH(dev, mailbox, hash, &status);
85 if (err) 86 if (err)
86 goto out; 87 goto out;
87 if (status) { 88 if (status) {
@@ -103,7 +104,7 @@ static int find_mgm(struct mthca_dev *dev,
103 *prev = -1; 104 *prev = -1;
104 105
105 do { 106 do {
106 err = mthca_READ_MGM(dev, *index, mgm, &status); 107 err = mthca_READ_MGM(dev, *index, mgm_mailbox, &status);
107 if (err) 108 if (err)
108 goto out; 109 goto out;
109 if (status) { 110 if (status) {
@@ -129,14 +130,14 @@ static int find_mgm(struct mthca_dev *dev,
129 *index = -1; 130 *index = -1;
130 131
131 out: 132 out:
132 kfree(mailbox); 133 mthca_free_mailbox(dev, mailbox);
133 return err; 134 return err;
134} 135}
135 136
136int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 137int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
137{ 138{
138 struct mthca_dev *dev = to_mdev(ibqp->device); 139 struct mthca_dev *dev = to_mdev(ibqp->device);
139 void *mailbox; 140 struct mthca_mailbox *mailbox;
140 struct mthca_mgm *mgm; 141 struct mthca_mgm *mgm;
141 u16 hash; 142 u16 hash;
142 int index, prev; 143 int index, prev;
@@ -145,15 +146,15 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
145 int err; 146 int err;
146 u8 status; 147 u8 status;
147 148
148 mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 149 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
149 if (!mailbox) 150 if (IS_ERR(mailbox))
150 return -ENOMEM; 151 return PTR_ERR(mailbox);
151 mgm = MAILBOX_ALIGN(mailbox); 152 mgm = mailbox->buf;
152 153
153 if (down_interruptible(&dev->mcg_table.sem)) 154 if (down_interruptible(&dev->mcg_table.sem))
154 return -EINTR; 155 return -EINTR;
155 156
156 err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); 157 err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
157 if (err) 158 if (err)
158 goto out; 159 goto out;
159 160
@@ -170,7 +171,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
170 goto out; 171 goto out;
171 } 172 }
172 173
173 err = mthca_READ_MGM(dev, index, mgm, &status); 174 err = mthca_READ_MGM(dev, index, mailbox, &status);
174 if (err) 175 if (err)
175 goto out; 176 goto out;
176 if (status) { 177 if (status) {
@@ -195,7 +196,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
195 goto out; 196 goto out;
196 } 197 }
197 198
198 err = mthca_WRITE_MGM(dev, index, mgm, &status); 199 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
199 if (err) 200 if (err)
200 goto out; 201 goto out;
201 if (status) { 202 if (status) {
@@ -206,7 +207,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
206 if (!link) 207 if (!link)
207 goto out; 208 goto out;
208 209
209 err = mthca_READ_MGM(dev, prev, mgm, &status); 210 err = mthca_READ_MGM(dev, prev, mailbox, &status);
210 if (err) 211 if (err)
211 goto out; 212 goto out;
212 if (status) { 213 if (status) {
@@ -217,7 +218,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
217 218
218 mgm->next_gid_index = cpu_to_be32(index << 5); 219 mgm->next_gid_index = cpu_to_be32(index << 5);
219 220
220 err = mthca_WRITE_MGM(dev, prev, mgm, &status); 221 err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
221 if (err) 222 if (err)
222 goto out; 223 goto out;
223 if (status) { 224 if (status) {
@@ -227,14 +228,14 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
227 228
228 out: 229 out:
229 up(&dev->mcg_table.sem); 230 up(&dev->mcg_table.sem);
230 kfree(mailbox); 231 mthca_free_mailbox(dev, mailbox);
231 return err; 232 return err;
232} 233}
233 234
234int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 235int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
235{ 236{
236 struct mthca_dev *dev = to_mdev(ibqp->device); 237 struct mthca_dev *dev = to_mdev(ibqp->device);
237 void *mailbox; 238 struct mthca_mailbox *mailbox;
238 struct mthca_mgm *mgm; 239 struct mthca_mgm *mgm;
239 u16 hash; 240 u16 hash;
240 int prev, index; 241 int prev, index;
@@ -242,15 +243,15 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
242 int err; 243 int err;
243 u8 status; 244 u8 status;
244 245
245 mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 246 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
246 if (!mailbox) 247 if (IS_ERR(mailbox))
247 return -ENOMEM; 248 return PTR_ERR(mailbox);
248 mgm = MAILBOX_ALIGN(mailbox); 249 mgm = mailbox->buf;
249 250
250 if (down_interruptible(&dev->mcg_table.sem)) 251 if (down_interruptible(&dev->mcg_table.sem))
251 return -EINTR; 252 return -EINTR;
252 253
253 err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); 254 err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
254 if (err) 255 if (err)
255 goto out; 256 goto out;
256 257
@@ -285,7 +286,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
285 mgm->qp[loc] = mgm->qp[i - 1]; 286 mgm->qp[loc] = mgm->qp[i - 1];
286 mgm->qp[i - 1] = 0; 287 mgm->qp[i - 1] = 0;
287 288
288 err = mthca_WRITE_MGM(dev, index, mgm, &status); 289 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
289 if (err) 290 if (err)
290 goto out; 291 goto out;
291 if (status) { 292 if (status) {
@@ -304,7 +305,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
304 if (be32_to_cpu(mgm->next_gid_index) >> 5) { 305 if (be32_to_cpu(mgm->next_gid_index) >> 5) {
305 err = mthca_READ_MGM(dev, 306 err = mthca_READ_MGM(dev,
306 be32_to_cpu(mgm->next_gid_index) >> 5, 307 be32_to_cpu(mgm->next_gid_index) >> 5,
307 mgm, &status); 308 mailbox, &status);
308 if (err) 309 if (err)
309 goto out; 310 goto out;
310 if (status) { 311 if (status) {
@@ -316,7 +317,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
316 } else 317 } else
317 memset(mgm->gid, 0, 16); 318 memset(mgm->gid, 0, 16);
318 319
319 err = mthca_WRITE_MGM(dev, index, mgm, &status); 320 err = mthca_WRITE_MGM(dev, index, mailbox, &status);
320 if (err) 321 if (err)
321 goto out; 322 goto out;
322 if (status) { 323 if (status) {
@@ -327,7 +328,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
327 } else { 328 } else {
328 /* Remove entry from AMGM */ 329 /* Remove entry from AMGM */
329 index = be32_to_cpu(mgm->next_gid_index) >> 5; 330 index = be32_to_cpu(mgm->next_gid_index) >> 5;
330 err = mthca_READ_MGM(dev, prev, mgm, &status); 331 err = mthca_READ_MGM(dev, prev, mailbox, &status);
331 if (err) 332 if (err)
332 goto out; 333 goto out;
333 if (status) { 334 if (status) {
@@ -338,7 +339,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
338 339
339 mgm->next_gid_index = cpu_to_be32(index << 5); 340 mgm->next_gid_index = cpu_to_be32(index << 5);
340 341
341 err = mthca_WRITE_MGM(dev, prev, mgm, &status); 342 err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
342 if (err) 343 if (err)
343 goto out; 344 goto out;
344 if (status) { 345 if (status) {
@@ -350,7 +351,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
350 351
351 out: 352 out:
352 up(&dev->mcg_table.sem); 353 up(&dev->mcg_table.sem);
353 kfree(mailbox); 354 mthca_free_mailbox(dev, mailbox);
354 return err; 355 return err;
355} 356}
356 357
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 637b30e35592..2a8646150355 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -47,6 +48,15 @@ enum {
47 MTHCA_TABLE_CHUNK_SIZE = 1 << 18 48 MTHCA_TABLE_CHUNK_SIZE = 1 << 18
48}; 49};
49 50
51struct mthca_user_db_table {
52 struct semaphore mutex;
53 struct {
54 u64 uvirt;
55 struct scatterlist mem;
56 int refcount;
57 } page[0];
58};
59
50void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm) 60void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm)
51{ 61{
52 struct mthca_icm_chunk *chunk, *tmp; 62 struct mthca_icm_chunk *chunk, *tmp;
@@ -179,9 +189,14 @@ out:
179 189
180void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj) 190void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)
181{ 191{
182 int i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; 192 int i;
183 u8 status; 193 u8 status;
184 194
195 if (!mthca_is_memfree(dev))
196 return;
197
198 i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
199
185 down(&table->mutex); 200 down(&table->mutex);
186 201
187 if (--table->icm[i]->refcount == 0) { 202 if (--table->icm[i]->refcount == 0) {
@@ -256,6 +271,9 @@ void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table,
256{ 271{
257 int i; 272 int i;
258 273
274 if (!mthca_is_memfree(dev))
275 return;
276
259 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size) 277 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size)
260 mthca_table_put(dev, table, i); 278 mthca_table_put(dev, table, i);
261} 279}
@@ -336,13 +354,133 @@ void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table)
336 kfree(table); 354 kfree(table);
337} 355}
338 356
339static u64 mthca_uarc_virt(struct mthca_dev *dev, int page) 357static u64 mthca_uarc_virt(struct mthca_dev *dev, struct mthca_uar *uar, int page)
340{ 358{
341 return dev->uar_table.uarc_base + 359 return dev->uar_table.uarc_base +
342 dev->driver_uar.index * dev->uar_table.uarc_size + 360 uar->index * dev->uar_table.uarc_size +
343 page * 4096; 361 page * 4096;
344} 362}
345 363
364int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
365 struct mthca_user_db_table *db_tab, int index, u64 uaddr)
366{
367 int ret = 0;
368 u8 status;
369 int i;
370
371 if (!mthca_is_memfree(dev))
372 return 0;
373
374 if (index < 0 || index > dev->uar_table.uarc_size / 8)
375 return -EINVAL;
376
377 down(&db_tab->mutex);
378
379 i = index / MTHCA_DB_REC_PER_PAGE;
380
381 if ((db_tab->page[i].refcount >= MTHCA_DB_REC_PER_PAGE) ||
382 (db_tab->page[i].uvirt && db_tab->page[i].uvirt != uaddr) ||
383 (uaddr & 4095)) {
384 ret = -EINVAL;
385 goto out;
386 }
387
388 if (db_tab->page[i].refcount) {
389 ++db_tab->page[i].refcount;
390 goto out;
391 }
392
393 ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0,
394 &db_tab->page[i].mem.page, NULL);
395 if (ret < 0)
396 goto out;
397
398 db_tab->page[i].mem.length = 4096;
399 db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
400
401 ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
402 if (ret < 0) {
403 put_page(db_tab->page[i].mem.page);
404 goto out;
405 }
406
407 ret = mthca_MAP_ICM_page(dev, sg_dma_address(&db_tab->page[i].mem),
408 mthca_uarc_virt(dev, uar, i), &status);
409 if (!ret && status)
410 ret = -EINVAL;
411 if (ret) {
412 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
413 put_page(db_tab->page[i].mem.page);
414 goto out;
415 }
416
417 db_tab->page[i].uvirt = uaddr;
418 db_tab->page[i].refcount = 1;
419
420out:
421 up(&db_tab->mutex);
422 return ret;
423}
424
425void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
426 struct mthca_user_db_table *db_tab, int index)
427{
428 if (!mthca_is_memfree(dev))
429 return;
430
431 /*
432 * To make our bookkeeping simpler, we don't unmap DB
433 * pages until we clean up the whole db table.
434 */
435
436 down(&db_tab->mutex);
437
438 --db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount;
439
440 up(&db_tab->mutex);
441}
442
443struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
444{
445 struct mthca_user_db_table *db_tab;
446 int npages;
447 int i;
448
449 if (!mthca_is_memfree(dev))
450 return NULL;
451
452 npages = dev->uar_table.uarc_size / 4096;
453 db_tab = kmalloc(sizeof *db_tab + npages * sizeof *db_tab->page, GFP_KERNEL);
454 if (!db_tab)
455 return ERR_PTR(-ENOMEM);
456
457 init_MUTEX(&db_tab->mutex);
458 for (i = 0; i < npages; ++i) {
459 db_tab->page[i].refcount = 0;
460 db_tab->page[i].uvirt = 0;
461 }
462
463 return db_tab;
464}
465
466void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
467 struct mthca_user_db_table *db_tab)
468{
469 int i;
470 u8 status;
471
472 if (!mthca_is_memfree(dev))
473 return;
474
475 for (i = 0; i < dev->uar_table.uarc_size / 4096; ++i) {
476 if (db_tab->page[i].uvirt) {
477 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status);
478 pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
479 put_page(db_tab->page[i].mem.page);
480 }
481 }
482}
483
346int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db) 484int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db)
347{ 485{
348 int group; 486 int group;
@@ -399,7 +537,8 @@ int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db)
399 } 537 }
400 memset(page->db_rec, 0, 4096); 538 memset(page->db_rec, 0, 4096);
401 539
402 ret = mthca_MAP_ICM_page(dev, page->mapping, mthca_uarc_virt(dev, i), &status); 540 ret = mthca_MAP_ICM_page(dev, page->mapping,
541 mthca_uarc_virt(dev, &dev->driver_uar, i), &status);
403 if (!ret && status) 542 if (!ret && status)
404 ret = -EINVAL; 543 ret = -EINVAL;
405 if (ret) { 544 if (ret) {
@@ -453,7 +592,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index)
453 592
454 if (bitmap_empty(page->used, MTHCA_DB_REC_PER_PAGE) && 593 if (bitmap_empty(page->used, MTHCA_DB_REC_PER_PAGE) &&
455 i >= dev->db_tab->max_group1 - 1) { 594 i >= dev->db_tab->max_group1 - 1) {
456 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, i), 1, &status); 595 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
457 596
458 dma_free_coherent(&dev->pdev->dev, 4096, 597 dma_free_coherent(&dev->pdev->dev, 4096,
459 page->db_rec, page->mapping); 598 page->db_rec, page->mapping);
@@ -522,7 +661,7 @@ void mthca_cleanup_db_tab(struct mthca_dev *dev)
522 if (!bitmap_empty(dev->db_tab->page[i].used, MTHCA_DB_REC_PER_PAGE)) 661 if (!bitmap_empty(dev->db_tab->page[i].used, MTHCA_DB_REC_PER_PAGE))
523 mthca_warn(dev, "Kernel UARC page %d not empty\n", i); 662 mthca_warn(dev, "Kernel UARC page %d not empty\n", i);
524 663
525 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, i), 1, &status); 664 mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
526 665
527 dma_free_coherent(&dev->pdev->dev, 4096, 666 dma_free_coherent(&dev->pdev->dev, 4096,
528 dev->db_tab->page[i].db_rec, 667 dev->db_tab->page[i].db_rec,
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.h b/drivers/infiniband/hw/mthca/mthca_memfree.h
index fe7be2a6bc4a..4761d844cb5f 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.h
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -148,7 +149,7 @@ struct mthca_db_table {
148 struct semaphore mutex; 149 struct semaphore mutex;
149}; 150};
150 151
151enum { 152enum mthca_db_type {
152 MTHCA_DB_TYPE_INVALID = 0x0, 153 MTHCA_DB_TYPE_INVALID = 0x0,
153 MTHCA_DB_TYPE_CQ_SET_CI = 0x1, 154 MTHCA_DB_TYPE_CQ_SET_CI = 0x1,
154 MTHCA_DB_TYPE_CQ_ARM = 0x2, 155 MTHCA_DB_TYPE_CQ_ARM = 0x2,
@@ -158,6 +159,17 @@ enum {
158 MTHCA_DB_TYPE_GROUP_SEP = 0x7 159 MTHCA_DB_TYPE_GROUP_SEP = 0x7
159}; 160};
160 161
162struct mthca_user_db_table;
163struct mthca_uar;
164
165int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
166 struct mthca_user_db_table *db_tab, int index, u64 uaddr);
167void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
168 struct mthca_user_db_table *db_tab, int index);
169struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev);
170void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
171 struct mthca_user_db_table *db_tab);
172
161int mthca_init_db_tab(struct mthca_dev *dev); 173int mthca_init_db_tab(struct mthca_dev *dev);
162void mthca_cleanup_db_tab(struct mthca_dev *dev); 174void mthca_cleanup_db_tab(struct mthca_dev *dev);
163int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db); 175int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db);
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index 8960fc2306be..cbe50feaf680 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -40,6 +40,12 @@
40#include "mthca_cmd.h" 40#include "mthca_cmd.h"
41#include "mthca_memfree.h" 41#include "mthca_memfree.h"
42 42
43struct mthca_mtt {
44 struct mthca_buddy *buddy;
45 int order;
46 u32 first_seg;
47};
48
43/* 49/*
44 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits. 50 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
45 */ 51 */
@@ -173,8 +179,8 @@ static void __devexit mthca_buddy_cleanup(struct mthca_buddy *buddy)
173 kfree(buddy->bits); 179 kfree(buddy->bits);
174} 180}
175 181
176static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order, 182static u32 mthca_alloc_mtt_range(struct mthca_dev *dev, int order,
177 struct mthca_buddy *buddy) 183 struct mthca_buddy *buddy)
178{ 184{
179 u32 seg = mthca_buddy_alloc(buddy, order); 185 u32 seg = mthca_buddy_alloc(buddy, order);
180 186
@@ -191,14 +197,102 @@ static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order,
191 return seg; 197 return seg;
192} 198}
193 199
194static void mthca_free_mtt(struct mthca_dev *dev, u32 seg, int order, 200static struct mthca_mtt *__mthca_alloc_mtt(struct mthca_dev *dev, int size,
195 struct mthca_buddy* buddy) 201 struct mthca_buddy *buddy)
196{ 202{
197 mthca_buddy_free(buddy, seg, order); 203 struct mthca_mtt *mtt;
204 int i;
198 205
199 if (mthca_is_memfree(dev)) 206 if (size <= 0)
200 mthca_table_put_range(dev, dev->mr_table.mtt_table, seg, 207 return ERR_PTR(-EINVAL);
201 seg + (1 << order) - 1); 208
209 mtt = kmalloc(sizeof *mtt, GFP_KERNEL);
210 if (!mtt)
211 return ERR_PTR(-ENOMEM);
212
213 mtt->buddy = buddy;
214 mtt->order = 0;
215 for (i = MTHCA_MTT_SEG_SIZE / 8; i < size; i <<= 1)
216 ++mtt->order;
217
218 mtt->first_seg = mthca_alloc_mtt_range(dev, mtt->order, buddy);
219 if (mtt->first_seg == -1) {
220 kfree(mtt);
221 return ERR_PTR(-ENOMEM);
222 }
223
224 return mtt;
225}
226
227struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size)
228{
229 return __mthca_alloc_mtt(dev, size, &dev->mr_table.mtt_buddy);
230}
231
232void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt)
233{
234 if (!mtt)
235 return;
236
237 mthca_buddy_free(mtt->buddy, mtt->first_seg, mtt->order);
238
239 mthca_table_put_range(dev, dev->mr_table.mtt_table,
240 mtt->first_seg,
241 mtt->first_seg + (1 << mtt->order) - 1);
242
243 kfree(mtt);
244}
245
246int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
247 int start_index, u64 *buffer_list, int list_len)
248{
249 struct mthca_mailbox *mailbox;
250 u64 *mtt_entry;
251 int err = 0;
252 u8 status;
253 int i;
254
255 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
256 if (IS_ERR(mailbox))
257 return PTR_ERR(mailbox);
258 mtt_entry = mailbox->buf;
259
260 while (list_len > 0) {
261 mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
262 mtt->first_seg * MTHCA_MTT_SEG_SIZE +
263 start_index * 8);
264 mtt_entry[1] = 0;
265 for (i = 0; i < list_len && i < MTHCA_MAILBOX_SIZE / 8 - 2; ++i)
266 mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
267 MTHCA_MTT_FLAG_PRESENT);
268
269 /*
270 * If we have an odd number of entries to write, add
271 * one more dummy entry for firmware efficiency.
272 */
273 if (i & 1)
274 mtt_entry[i + 2] = 0;
275
276 err = mthca_WRITE_MTT(dev, mailbox, (i + 1) & ~1, &status);
277 if (err) {
278 mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
279 goto out;
280 }
281 if (status) {
282 mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",
283 status);
284 err = -EINVAL;
285 goto out;
286 }
287
288 list_len -= i;
289 start_index += i;
290 buffer_list += i;
291 }
292
293out:
294 mthca_free_mailbox(dev, mailbox);
295 return err;
202} 296}
203 297
204static inline u32 tavor_hw_index_to_key(u32 ind) 298static inline u32 tavor_hw_index_to_key(u32 ind)
@@ -237,91 +331,18 @@ static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
237 return tavor_key_to_hw_index(key); 331 return tavor_key_to_hw_index(key);
238} 332}
239 333
240int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd, 334int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
241 u32 access, struct mthca_mr *mr) 335 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
242{ 336{
243 void *mailbox = NULL; 337 struct mthca_mailbox *mailbox;
244 struct mthca_mpt_entry *mpt_entry; 338 struct mthca_mpt_entry *mpt_entry;
245 u32 key; 339 u32 key;
340 int i;
246 int err; 341 int err;
247 u8 status; 342 u8 status;
248 343
249 might_sleep(); 344 might_sleep();
250 345
251 mr->order = -1;
252 key = mthca_alloc(&dev->mr_table.mpt_alloc);
253 if (key == -1)
254 return -ENOMEM;
255 mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);
256
257 if (mthca_is_memfree(dev)) {
258 err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
259 if (err)
260 goto err_out_mpt_free;
261 }
262
263 mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA,
264 GFP_KERNEL);
265 if (!mailbox) {
266 err = -ENOMEM;
267 goto err_out_table;
268 }
269 mpt_entry = MAILBOX_ALIGN(mailbox);
270
271 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
272 MTHCA_MPT_FLAG_MIO |
273 MTHCA_MPT_FLAG_PHYSICAL |
274 MTHCA_MPT_FLAG_REGION |
275 access);
276 mpt_entry->page_size = 0;
277 mpt_entry->key = cpu_to_be32(key);
278 mpt_entry->pd = cpu_to_be32(pd);
279 mpt_entry->start = 0;
280 mpt_entry->length = ~0ULL;
281
282 memset(&mpt_entry->lkey, 0,
283 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
284
285 err = mthca_SW2HW_MPT(dev, mpt_entry,
286 key & (dev->limits.num_mpts - 1),
287 &status);
288 if (err) {
289 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
290 goto err_out_table;
291 } else if (status) {
292 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
293 status);
294 err = -EINVAL;
295 goto err_out_table;
296 }
297
298 kfree(mailbox);
299 return err;
300
301err_out_table:
302 if (mthca_is_memfree(dev))
303 mthca_table_put(dev, dev->mr_table.mpt_table, key);
304
305err_out_mpt_free:
306 mthca_free(&dev->mr_table.mpt_alloc, key);
307 kfree(mailbox);
308 return err;
309}
310
311int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
312 u64 *buffer_list, int buffer_size_shift,
313 int list_len, u64 iova, u64 total_size,
314 u32 access, struct mthca_mr *mr)
315{
316 void *mailbox;
317 u64 *mtt_entry;
318 struct mthca_mpt_entry *mpt_entry;
319 u32 key;
320 int err = -ENOMEM;
321 u8 status;
322 int i;
323
324 might_sleep();
325 WARN_ON(buffer_size_shift >= 32); 346 WARN_ON(buffer_size_shift >= 32);
326 347
327 key = mthca_alloc(&dev->mr_table.mpt_alloc); 348 key = mthca_alloc(&dev->mr_table.mpt_alloc);
@@ -335,75 +356,33 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
335 goto err_out_mpt_free; 356 goto err_out_mpt_free;
336 } 357 }
337 358
338 for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0; 359 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
339 i < list_len; 360 if (IS_ERR(mailbox)) {
340 i <<= 1, ++mr->order) 361 err = PTR_ERR(mailbox);
341 ; /* nothing */
342
343 mr->first_seg = mthca_alloc_mtt(dev, mr->order,
344 &dev->mr_table.mtt_buddy);
345 if (mr->first_seg == -1)
346 goto err_out_table; 362 goto err_out_table;
347
348 /*
349 * If list_len is odd, we add one more dummy entry for
350 * firmware efficiency.
351 */
352 mailbox = kmalloc(max(sizeof *mpt_entry,
353 (size_t) 8 * (list_len + (list_len & 1) + 2)) +
354 MTHCA_CMD_MAILBOX_EXTRA,
355 GFP_KERNEL);
356 if (!mailbox)
357 goto err_out_free_mtt;
358
359 mtt_entry = MAILBOX_ALIGN(mailbox);
360
361 mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
362 mr->first_seg * MTHCA_MTT_SEG_SIZE);
363 mtt_entry[1] = 0;
364 for (i = 0; i < list_len; ++i)
365 mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
366 MTHCA_MTT_FLAG_PRESENT);
367 if (list_len & 1) {
368 mtt_entry[i + 2] = 0;
369 ++list_len;
370 }
371
372 if (0) {
373 mthca_dbg(dev, "Dumping MPT entry\n");
374 for (i = 0; i < list_len + 2; ++i)
375 printk(KERN_ERR "[%2d] %016llx\n",
376 i, (unsigned long long) be64_to_cpu(mtt_entry[i]));
377 }
378
379 err = mthca_WRITE_MTT(dev, mtt_entry, list_len, &status);
380 if (err) {
381 mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
382 goto err_out_mailbox_free;
383 }
384 if (status) {
385 mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",
386 status);
387 err = -EINVAL;
388 goto err_out_mailbox_free;
389 } 363 }
390 364 mpt_entry = mailbox->buf;
391 mpt_entry = MAILBOX_ALIGN(mailbox);
392 365
393 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | 366 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
394 MTHCA_MPT_FLAG_MIO | 367 MTHCA_MPT_FLAG_MIO |
395 MTHCA_MPT_FLAG_REGION | 368 MTHCA_MPT_FLAG_REGION |
396 access); 369 access);
370 if (!mr->mtt)
371 mpt_entry->flags |= cpu_to_be32(MTHCA_MPT_FLAG_PHYSICAL);
397 372
398 mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12); 373 mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12);
399 mpt_entry->key = cpu_to_be32(key); 374 mpt_entry->key = cpu_to_be32(key);
400 mpt_entry->pd = cpu_to_be32(pd); 375 mpt_entry->pd = cpu_to_be32(pd);
401 mpt_entry->start = cpu_to_be64(iova); 376 mpt_entry->start = cpu_to_be64(iova);
402 mpt_entry->length = cpu_to_be64(total_size); 377 mpt_entry->length = cpu_to_be64(total_size);
378
403 memset(&mpt_entry->lkey, 0, 379 memset(&mpt_entry->lkey, 0,
404 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey)); 380 sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
405 mpt_entry->mtt_seg = cpu_to_be64(dev->mr_table.mtt_base + 381
406 mr->first_seg * MTHCA_MTT_SEG_SIZE); 382 if (mr->mtt)
383 mpt_entry->mtt_seg =
384 cpu_to_be64(dev->mr_table.mtt_base +
385 mr->mtt->first_seg * MTHCA_MTT_SEG_SIZE);
407 386
408 if (0) { 387 if (0) {
409 mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey); 388 mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey);
@@ -416,45 +395,70 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
416 } 395 }
417 } 396 }
418 397
419 err = mthca_SW2HW_MPT(dev, mpt_entry, 398 err = mthca_SW2HW_MPT(dev, mailbox,
420 key & (dev->limits.num_mpts - 1), 399 key & (dev->limits.num_mpts - 1),
421 &status); 400 &status);
422 if (err) 401 if (err) {
423 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err); 402 mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);
424 else if (status) { 403 goto err_out_mailbox;
404 } else if (status) {
425 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n", 405 mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",
426 status); 406 status);
427 err = -EINVAL; 407 err = -EINVAL;
408 goto err_out_mailbox;
428 } 409 }
429 410
430 kfree(mailbox); 411 mthca_free_mailbox(dev, mailbox);
431 return err; 412 return err;
432 413
433err_out_mailbox_free: 414err_out_mailbox:
434 kfree(mailbox); 415 mthca_free_mailbox(dev, mailbox);
435
436err_out_free_mtt:
437 mthca_free_mtt(dev, mr->first_seg, mr->order, &dev->mr_table.mtt_buddy);
438 416
439err_out_table: 417err_out_table:
440 if (mthca_is_memfree(dev)) 418 mthca_table_put(dev, dev->mr_table.mpt_table, key);
441 mthca_table_put(dev, dev->mr_table.mpt_table, key);
442 419
443err_out_mpt_free: 420err_out_mpt_free:
444 mthca_free(&dev->mr_table.mpt_alloc, key); 421 mthca_free(&dev->mr_table.mpt_alloc, key);
445 return err; 422 return err;
446} 423}
447 424
448/* Free mr or fmr */ 425int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
449static void mthca_free_region(struct mthca_dev *dev, u32 lkey, int order, 426 u32 access, struct mthca_mr *mr)
450 u32 first_seg, struct mthca_buddy *buddy)
451{ 427{
452 if (order >= 0) 428 mr->mtt = NULL;
453 mthca_free_mtt(dev, first_seg, order, buddy); 429 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
430}
454 431
455 if (mthca_is_memfree(dev)) 432int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
456 mthca_table_put(dev, dev->mr_table.mpt_table, 433 u64 *buffer_list, int buffer_size_shift,
457 arbel_key_to_hw_index(lkey)); 434 int list_len, u64 iova, u64 total_size,
435 u32 access, struct mthca_mr *mr)
436{
437 int err;
438
439 mr->mtt = mthca_alloc_mtt(dev, list_len);
440 if (IS_ERR(mr->mtt))
441 return PTR_ERR(mr->mtt);
442
443 err = mthca_write_mtt(dev, mr->mtt, 0, buffer_list, list_len);
444 if (err) {
445 mthca_free_mtt(dev, mr->mtt);
446 return err;
447 }
448
449 err = mthca_mr_alloc(dev, pd, buffer_size_shift, iova,
450 total_size, access, mr);
451 if (err)
452 mthca_free_mtt(dev, mr->mtt);
453
454 return err;
455}
456
457/* Free mr or fmr */
458static void mthca_free_region(struct mthca_dev *dev, u32 lkey)
459{
460 mthca_table_put(dev, dev->mr_table.mpt_table,
461 arbel_key_to_hw_index(lkey));
458 462
459 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey)); 463 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey));
460} 464}
@@ -476,15 +480,15 @@ void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr)
476 mthca_warn(dev, "HW2SW_MPT returned status 0x%02x\n", 480 mthca_warn(dev, "HW2SW_MPT returned status 0x%02x\n",
477 status); 481 status);
478 482
479 mthca_free_region(dev, mr->ibmr.lkey, mr->order, mr->first_seg, 483 mthca_free_region(dev, mr->ibmr.lkey);
480 &dev->mr_table.mtt_buddy); 484 mthca_free_mtt(dev, mr->mtt);
481} 485}
482 486
483int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, 487int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
484 u32 access, struct mthca_fmr *mr) 488 u32 access, struct mthca_fmr *mr)
485{ 489{
486 struct mthca_mpt_entry *mpt_entry; 490 struct mthca_mpt_entry *mpt_entry;
487 void *mailbox; 491 struct mthca_mailbox *mailbox;
488 u64 mtt_seg; 492 u64 mtt_seg;
489 u32 key, idx; 493 u32 key, idx;
490 u8 status; 494 u8 status;
@@ -522,31 +526,24 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
522 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base + 526 mr->mem.tavor.mpt = dev->mr_table.tavor_fmr.mpt_base +
523 sizeof *(mr->mem.tavor.mpt) * idx; 527 sizeof *(mr->mem.tavor.mpt) * idx;
524 528
525 for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0; 529 mr->mtt = __mthca_alloc_mtt(dev, list_len, dev->mr_table.fmr_mtt_buddy);
526 i < list_len; 530 if (IS_ERR(mr->mtt))
527 i <<= 1, ++mr->order)
528 ; /* nothing */
529
530 mr->first_seg = mthca_alloc_mtt(dev, mr->order,
531 dev->mr_table.fmr_mtt_buddy);
532 if (mr->first_seg == -1)
533 goto err_out_table; 531 goto err_out_table;
534 532
535 mtt_seg = mr->first_seg * MTHCA_MTT_SEG_SIZE; 533 mtt_seg = mr->mtt->first_seg * MTHCA_MTT_SEG_SIZE;
536 534
537 if (mthca_is_memfree(dev)) { 535 if (mthca_is_memfree(dev)) {
538 mr->mem.arbel.mtts = mthca_table_find(dev->mr_table.mtt_table, 536 mr->mem.arbel.mtts = mthca_table_find(dev->mr_table.mtt_table,
539 mr->first_seg); 537 mr->mtt->first_seg);
540 BUG_ON(!mr->mem.arbel.mtts); 538 BUG_ON(!mr->mem.arbel.mtts);
541 } else 539 } else
542 mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg; 540 mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg;
543 541
544 mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA, 542 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
545 GFP_KERNEL); 543 if (IS_ERR(mailbox))
546 if (!mailbox)
547 goto err_out_free_mtt; 544 goto err_out_free_mtt;
548 545
549 mpt_entry = MAILBOX_ALIGN(mailbox); 546 mpt_entry = mailbox->buf;
550 547
551 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | 548 mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
552 MTHCA_MPT_FLAG_MIO | 549 MTHCA_MPT_FLAG_MIO |
@@ -571,7 +568,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
571 } 568 }
572 } 569 }
573 570
574 err = mthca_SW2HW_MPT(dev, mpt_entry, 571 err = mthca_SW2HW_MPT(dev, mailbox,
575 key & (dev->limits.num_mpts - 1), 572 key & (dev->limits.num_mpts - 1),
576 &status); 573 &status);
577 if (err) { 574 if (err) {
@@ -585,19 +582,17 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
585 goto err_out_mailbox_free; 582 goto err_out_mailbox_free;
586 } 583 }
587 584
588 kfree(mailbox); 585 mthca_free_mailbox(dev, mailbox);
589 return 0; 586 return 0;
590 587
591err_out_mailbox_free: 588err_out_mailbox_free:
592 kfree(mailbox); 589 mthca_free_mailbox(dev, mailbox);
593 590
594err_out_free_mtt: 591err_out_free_mtt:
595 mthca_free_mtt(dev, mr->first_seg, mr->order, 592 mthca_free_mtt(dev, mr->mtt);
596 dev->mr_table.fmr_mtt_buddy);
597 593
598err_out_table: 594err_out_table:
599 if (mthca_is_memfree(dev)) 595 mthca_table_put(dev, dev->mr_table.mpt_table, key);
600 mthca_table_put(dev, dev->mr_table.mpt_table, key);
601 596
602err_out_mpt_free: 597err_out_mpt_free:
603 mthca_free(&dev->mr_table.mpt_alloc, mr->ibmr.lkey); 598 mthca_free(&dev->mr_table.mpt_alloc, mr->ibmr.lkey);
@@ -609,8 +604,9 @@ int mthca_free_fmr(struct mthca_dev *dev, struct mthca_fmr *fmr)
609 if (fmr->maps) 604 if (fmr->maps)
610 return -EBUSY; 605 return -EBUSY;
611 606
612 mthca_free_region(dev, fmr->ibmr.lkey, fmr->order, fmr->first_seg, 607 mthca_free_region(dev, fmr->ibmr.lkey);
613 dev->mr_table.fmr_mtt_buddy); 608 mthca_free_mtt(dev, fmr->mtt);
609
614 return 0; 610 return 0;
615} 611}
616 612
@@ -826,7 +822,8 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
826 if (dev->limits.reserved_mtts) { 822 if (dev->limits.reserved_mtts) {
827 i = fls(dev->limits.reserved_mtts - 1); 823 i = fls(dev->limits.reserved_mtts - 1);
828 824
829 if (mthca_alloc_mtt(dev, i, dev->mr_table.fmr_mtt_buddy) == -1) { 825 if (mthca_alloc_mtt_range(dev, i,
826 dev->mr_table.fmr_mtt_buddy) == -1) {
830 mthca_warn(dev, "MTT table of order %d is too small.\n", 827 mthca_warn(dev, "MTT table of order %d is too small.\n",
831 dev->mr_table.fmr_mtt_buddy->max_order); 828 dev->mr_table.fmr_mtt_buddy->max_order);
832 err = -ENOMEM; 829 err = -ENOMEM;
diff --git a/drivers/infiniband/hw/mthca/mthca_pd.c b/drivers/infiniband/hw/mthca/mthca_pd.c
index ea66847e4ea3..c2c899844e98 100644
--- a/drivers/infiniband/hw/mthca/mthca_pd.c
+++ b/drivers/infiniband/hw/mthca/mthca_pd.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -37,23 +38,27 @@
37 38
38#include "mthca_dev.h" 39#include "mthca_dev.h"
39 40
40int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd) 41int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd)
41{ 42{
42 int err; 43 int err = 0;
43 44
44 might_sleep(); 45 might_sleep();
45 46
47 pd->privileged = privileged;
48
46 atomic_set(&pd->sqp_count, 0); 49 atomic_set(&pd->sqp_count, 0);
47 pd->pd_num = mthca_alloc(&dev->pd_table.alloc); 50 pd->pd_num = mthca_alloc(&dev->pd_table.alloc);
48 if (pd->pd_num == -1) 51 if (pd->pd_num == -1)
49 return -ENOMEM; 52 return -ENOMEM;
50 53
51 err = mthca_mr_alloc_notrans(dev, pd->pd_num, 54 if (privileged) {
52 MTHCA_MPT_FLAG_LOCAL_READ | 55 err = mthca_mr_alloc_notrans(dev, pd->pd_num,
53 MTHCA_MPT_FLAG_LOCAL_WRITE, 56 MTHCA_MPT_FLAG_LOCAL_READ |
54 &pd->ntmr); 57 MTHCA_MPT_FLAG_LOCAL_WRITE,
55 if (err) 58 &pd->ntmr);
56 mthca_free(&dev->pd_table.alloc, pd->pd_num); 59 if (err)
60 mthca_free(&dev->pd_table.alloc, pd->pd_num);
61 }
57 62
58 return err; 63 return err;
59} 64}
@@ -61,7 +66,8 @@ int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd)
61void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd) 66void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd)
62{ 67{
63 might_sleep(); 68 might_sleep();
64 mthca_free_mr(dev, &pd->ntmr); 69 if (pd->privileged)
70 mthca_free_mr(dev, &pd->ntmr);
65 mthca_free(&dev->pd_table.alloc, pd->pd_num); 71 mthca_free(&dev->pd_table.alloc, pd->pd_num);
66} 72}
67 73
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 159f4e6c312d..7a58ce90e179 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 5 *
4 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -33,9 +35,12 @@
33 */ 35 */
34 36
35#include <ib_smi.h> 37#include <ib_smi.h>
38#include <linux/mm.h>
36 39
37#include "mthca_dev.h" 40#include "mthca_dev.h"
38#include "mthca_cmd.h" 41#include "mthca_cmd.h"
42#include "mthca_user.h"
43#include "mthca_memfree.h"
39 44
40static int mthca_query_device(struct ib_device *ibdev, 45static int mthca_query_device(struct ib_device *ibdev,
41 struct ib_device_attr *props) 46 struct ib_device_attr *props)
@@ -52,7 +57,7 @@ static int mthca_query_device(struct ib_device *ibdev,
52 if (!in_mad || !out_mad) 57 if (!in_mad || !out_mad)
53 goto out; 58 goto out;
54 59
55 memset(props, 0, sizeof props); 60 memset(props, 0, sizeof *props);
56 61
57 props->fw_ver = mdev->fw_ver; 62 props->fw_ver = mdev->fw_ver;
58 63
@@ -283,7 +288,78 @@ static int mthca_query_gid(struct ib_device *ibdev, u8 port,
283 return err; 288 return err;
284} 289}
285 290
286static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev) 291static struct ib_ucontext *mthca_alloc_ucontext(struct ib_device *ibdev,
292 struct ib_udata *udata)
293{
294 struct mthca_alloc_ucontext_resp uresp;
295 struct mthca_ucontext *context;
296 int err;
297
298 memset(&uresp, 0, sizeof uresp);
299
300 uresp.qp_tab_size = to_mdev(ibdev)->limits.num_qps;
301 if (mthca_is_memfree(to_mdev(ibdev)))
302 uresp.uarc_size = to_mdev(ibdev)->uar_table.uarc_size;
303 else
304 uresp.uarc_size = 0;
305
306 context = kmalloc(sizeof *context, GFP_KERNEL);
307 if (!context)
308 return ERR_PTR(-ENOMEM);
309
310 err = mthca_uar_alloc(to_mdev(ibdev), &context->uar);
311 if (err) {
312 kfree(context);
313 return ERR_PTR(err);
314 }
315
316 context->db_tab = mthca_init_user_db_tab(to_mdev(ibdev));
317 if (IS_ERR(context->db_tab)) {
318 err = PTR_ERR(context->db_tab);
319 mthca_uar_free(to_mdev(ibdev), &context->uar);
320 kfree(context);
321 return ERR_PTR(err);
322 }
323
324 if (ib_copy_to_udata(udata, &uresp, sizeof uresp)) {
325 mthca_cleanup_user_db_tab(to_mdev(ibdev), &context->uar, context->db_tab);
326 mthca_uar_free(to_mdev(ibdev), &context->uar);
327 kfree(context);
328 return ERR_PTR(-EFAULT);
329 }
330
331 return &context->ibucontext;
332}
333
334static int mthca_dealloc_ucontext(struct ib_ucontext *context)
335{
336 mthca_cleanup_user_db_tab(to_mdev(context->device), &to_mucontext(context)->uar,
337 to_mucontext(context)->db_tab);
338 mthca_uar_free(to_mdev(context->device), &to_mucontext(context)->uar);
339 kfree(to_mucontext(context));
340
341 return 0;
342}
343
344static int mthca_mmap_uar(struct ib_ucontext *context,
345 struct vm_area_struct *vma)
346{
347 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
348 return -EINVAL;
349
350 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
351
352 if (remap_pfn_range(vma, vma->vm_start,
353 to_mucontext(context)->uar.pfn,
354 PAGE_SIZE, vma->vm_page_prot))
355 return -EAGAIN;
356
357 return 0;
358}
359
360static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev,
361 struct ib_ucontext *context,
362 struct ib_udata *udata)
287{ 363{
288 struct mthca_pd *pd; 364 struct mthca_pd *pd;
289 int err; 365 int err;
@@ -292,12 +368,20 @@ static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev)
292 if (!pd) 368 if (!pd)
293 return ERR_PTR(-ENOMEM); 369 return ERR_PTR(-ENOMEM);
294 370
295 err = mthca_pd_alloc(to_mdev(ibdev), pd); 371 err = mthca_pd_alloc(to_mdev(ibdev), !context, pd);
296 if (err) { 372 if (err) {
297 kfree(pd); 373 kfree(pd);
298 return ERR_PTR(err); 374 return ERR_PTR(err);
299 } 375 }
300 376
377 if (context) {
378 if (ib_copy_to_udata(udata, &pd->pd_num, sizeof (__u32))) {
379 mthca_pd_free(to_mdev(ibdev), pd);
380 kfree(pd);
381 return ERR_PTR(-EFAULT);
382 }
383 }
384
301 return &pd->ibpd; 385 return &pd->ibpd;
302} 386}
303 387
@@ -337,8 +421,10 @@ static int mthca_ah_destroy(struct ib_ah *ah)
337} 421}
338 422
339static struct ib_qp *mthca_create_qp(struct ib_pd *pd, 423static struct ib_qp *mthca_create_qp(struct ib_pd *pd,
340 struct ib_qp_init_attr *init_attr) 424 struct ib_qp_init_attr *init_attr,
425 struct ib_udata *udata)
341{ 426{
427 struct mthca_create_qp ucmd;
342 struct mthca_qp *qp; 428 struct mthca_qp *qp;
343 int err; 429 int err;
344 430
@@ -347,41 +433,82 @@ static struct ib_qp *mthca_create_qp(struct ib_pd *pd,
347 case IB_QPT_UC: 433 case IB_QPT_UC:
348 case IB_QPT_UD: 434 case IB_QPT_UD:
349 { 435 {
436 struct mthca_ucontext *context;
437
350 qp = kmalloc(sizeof *qp, GFP_KERNEL); 438 qp = kmalloc(sizeof *qp, GFP_KERNEL);
351 if (!qp) 439 if (!qp)
352 return ERR_PTR(-ENOMEM); 440 return ERR_PTR(-ENOMEM);
353 441
354 qp->sq.max = init_attr->cap.max_send_wr; 442 if (pd->uobject) {
355 qp->rq.max = init_attr->cap.max_recv_wr; 443 context = to_mucontext(pd->uobject->context);
356 qp->sq.max_gs = init_attr->cap.max_send_sge; 444
357 qp->rq.max_gs = init_attr->cap.max_recv_sge; 445 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
446 return ERR_PTR(-EFAULT);
447
448 err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
449 context->db_tab,
450 ucmd.sq_db_index, ucmd.sq_db_page);
451 if (err) {
452 kfree(qp);
453 return ERR_PTR(err);
454 }
455
456 err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
457 context->db_tab,
458 ucmd.rq_db_index, ucmd.rq_db_page);
459 if (err) {
460 mthca_unmap_user_db(to_mdev(pd->device),
461 &context->uar,
462 context->db_tab,
463 ucmd.sq_db_index);
464 kfree(qp);
465 return ERR_PTR(err);
466 }
467
468 qp->mr.ibmr.lkey = ucmd.lkey;
469 qp->sq.db_index = ucmd.sq_db_index;
470 qp->rq.db_index = ucmd.rq_db_index;
471 }
358 472
359 err = mthca_alloc_qp(to_mdev(pd->device), to_mpd(pd), 473 err = mthca_alloc_qp(to_mdev(pd->device), to_mpd(pd),
360 to_mcq(init_attr->send_cq), 474 to_mcq(init_attr->send_cq),
361 to_mcq(init_attr->recv_cq), 475 to_mcq(init_attr->recv_cq),
362 init_attr->qp_type, init_attr->sq_sig_type, 476 init_attr->qp_type, init_attr->sq_sig_type,
363 qp); 477 &init_attr->cap, qp);
478
479 if (err && pd->uobject) {
480 context = to_mucontext(pd->uobject->context);
481
482 mthca_unmap_user_db(to_mdev(pd->device),
483 &context->uar,
484 context->db_tab,
485 ucmd.sq_db_index);
486 mthca_unmap_user_db(to_mdev(pd->device),
487 &context->uar,
488 context->db_tab,
489 ucmd.rq_db_index);
490 }
491
364 qp->ibqp.qp_num = qp->qpn; 492 qp->ibqp.qp_num = qp->qpn;
365 break; 493 break;
366 } 494 }
367 case IB_QPT_SMI: 495 case IB_QPT_SMI:
368 case IB_QPT_GSI: 496 case IB_QPT_GSI:
369 { 497 {
498 /* Don't allow userspace to create special QPs */
499 if (pd->uobject)
500 return ERR_PTR(-EINVAL);
501
370 qp = kmalloc(sizeof (struct mthca_sqp), GFP_KERNEL); 502 qp = kmalloc(sizeof (struct mthca_sqp), GFP_KERNEL);
371 if (!qp) 503 if (!qp)
372 return ERR_PTR(-ENOMEM); 504 return ERR_PTR(-ENOMEM);
373 505
374 qp->sq.max = init_attr->cap.max_send_wr;
375 qp->rq.max = init_attr->cap.max_recv_wr;
376 qp->sq.max_gs = init_attr->cap.max_send_sge;
377 qp->rq.max_gs = init_attr->cap.max_recv_sge;
378
379 qp->ibqp.qp_num = init_attr->qp_type == IB_QPT_SMI ? 0 : 1; 506 qp->ibqp.qp_num = init_attr->qp_type == IB_QPT_SMI ? 0 : 1;
380 507
381 err = mthca_alloc_sqp(to_mdev(pd->device), to_mpd(pd), 508 err = mthca_alloc_sqp(to_mdev(pd->device), to_mpd(pd),
382 to_mcq(init_attr->send_cq), 509 to_mcq(init_attr->send_cq),
383 to_mcq(init_attr->recv_cq), 510 to_mcq(init_attr->recv_cq),
384 init_attr->sq_sig_type, 511 init_attr->sq_sig_type, &init_attr->cap,
385 qp->ibqp.qp_num, init_attr->port_num, 512 qp->ibqp.qp_num, init_attr->port_num,
386 to_msqp(qp)); 513 to_msqp(qp));
387 break; 514 break;
@@ -396,42 +523,115 @@ static struct ib_qp *mthca_create_qp(struct ib_pd *pd,
396 return ERR_PTR(err); 523 return ERR_PTR(err);
397 } 524 }
398 525
399 init_attr->cap.max_inline_data = 0; 526 init_attr->cap.max_inline_data = 0;
527 init_attr->cap.max_send_wr = qp->sq.max;
528 init_attr->cap.max_recv_wr = qp->rq.max;
529 init_attr->cap.max_send_sge = qp->sq.max_gs;
530 init_attr->cap.max_recv_sge = qp->rq.max_gs;
400 531
401 return &qp->ibqp; 532 return &qp->ibqp;
402} 533}
403 534
404static int mthca_destroy_qp(struct ib_qp *qp) 535static int mthca_destroy_qp(struct ib_qp *qp)
405{ 536{
537 if (qp->uobject) {
538 mthca_unmap_user_db(to_mdev(qp->device),
539 &to_mucontext(qp->uobject->context)->uar,
540 to_mucontext(qp->uobject->context)->db_tab,
541 to_mqp(qp)->sq.db_index);
542 mthca_unmap_user_db(to_mdev(qp->device),
543 &to_mucontext(qp->uobject->context)->uar,
544 to_mucontext(qp->uobject->context)->db_tab,
545 to_mqp(qp)->rq.db_index);
546 }
406 mthca_free_qp(to_mdev(qp->device), to_mqp(qp)); 547 mthca_free_qp(to_mdev(qp->device), to_mqp(qp));
407 kfree(qp); 548 kfree(qp);
408 return 0; 549 return 0;
409} 550}
410 551
411static struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries) 552static struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries,
553 struct ib_ucontext *context,
554 struct ib_udata *udata)
412{ 555{
556 struct mthca_create_cq ucmd;
413 struct mthca_cq *cq; 557 struct mthca_cq *cq;
414 int nent; 558 int nent;
415 int err; 559 int err;
416 560
561 if (context) {
562 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
563 return ERR_PTR(-EFAULT);
564
565 err = mthca_map_user_db(to_mdev(ibdev), &to_mucontext(context)->uar,
566 to_mucontext(context)->db_tab,
567 ucmd.set_db_index, ucmd.set_db_page);
568 if (err)
569 return ERR_PTR(err);
570
571 err = mthca_map_user_db(to_mdev(ibdev), &to_mucontext(context)->uar,
572 to_mucontext(context)->db_tab,
573 ucmd.arm_db_index, ucmd.arm_db_page);
574 if (err)
575 goto err_unmap_set;
576 }
577
417 cq = kmalloc(sizeof *cq, GFP_KERNEL); 578 cq = kmalloc(sizeof *cq, GFP_KERNEL);
418 if (!cq) 579 if (!cq) {
419 return ERR_PTR(-ENOMEM); 580 err = -ENOMEM;
581 goto err_unmap_arm;
582 }
583
584 if (context) {
585 cq->mr.ibmr.lkey = ucmd.lkey;
586 cq->set_ci_db_index = ucmd.set_db_index;
587 cq->arm_db_index = ucmd.arm_db_index;
588 }
420 589
421 for (nent = 1; nent <= entries; nent <<= 1) 590 for (nent = 1; nent <= entries; nent <<= 1)
422 ; /* nothing */ 591 ; /* nothing */
423 592
424 err = mthca_init_cq(to_mdev(ibdev), nent, cq); 593 err = mthca_init_cq(to_mdev(ibdev), nent,
425 if (err) { 594 context ? to_mucontext(context) : NULL,
426 kfree(cq); 595 context ? ucmd.pdn : to_mdev(ibdev)->driver_pd.pd_num,
427 cq = ERR_PTR(err); 596 cq);
597 if (err)
598 goto err_free;
599
600 if (context && ib_copy_to_udata(udata, &cq->cqn, sizeof (__u32))) {
601 mthca_free_cq(to_mdev(ibdev), cq);
602 goto err_free;
428 } 603 }
429 604
430 return &cq->ibcq; 605 return &cq->ibcq;
606
607err_free:
608 kfree(cq);
609
610err_unmap_arm:
611 if (context)
612 mthca_unmap_user_db(to_mdev(ibdev), &to_mucontext(context)->uar,
613 to_mucontext(context)->db_tab, ucmd.arm_db_index);
614
615err_unmap_set:
616 if (context)
617 mthca_unmap_user_db(to_mdev(ibdev), &to_mucontext(context)->uar,
618 to_mucontext(context)->db_tab, ucmd.set_db_index);
619
620 return ERR_PTR(err);
431} 621}
432 622
433static int mthca_destroy_cq(struct ib_cq *cq) 623static int mthca_destroy_cq(struct ib_cq *cq)
434{ 624{
625 if (cq->uobject) {
626 mthca_unmap_user_db(to_mdev(cq->device),
627 &to_mucontext(cq->uobject->context)->uar,
628 to_mucontext(cq->uobject->context)->db_tab,
629 to_mcq(cq)->arm_db_index);
630 mthca_unmap_user_db(to_mdev(cq->device),
631 &to_mucontext(cq->uobject->context)->uar,
632 to_mucontext(cq->uobject->context)->db_tab,
633 to_mcq(cq)->set_ci_db_index);
634 }
435 mthca_free_cq(to_mdev(cq->device), to_mcq(cq)); 635 mthca_free_cq(to_mdev(cq->device), to_mcq(cq));
436 kfree(cq); 636 kfree(cq);
437 637
@@ -558,6 +758,7 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
558 convert_access(acc), mr); 758 convert_access(acc), mr);
559 759
560 if (err) { 760 if (err) {
761 kfree(page_list);
561 kfree(mr); 762 kfree(mr);
562 return ERR_PTR(err); 763 return ERR_PTR(err);
563 } 764 }
@@ -566,6 +767,87 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
566 return &mr->ibmr; 767 return &mr->ibmr;
567} 768}
568 769
770static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
771 int acc, struct ib_udata *udata)
772{
773 struct mthca_dev *dev = to_mdev(pd->device);
774 struct ib_umem_chunk *chunk;
775 struct mthca_mr *mr;
776 u64 *pages;
777 int shift, n, len;
778 int i, j, k;
779 int err = 0;
780
781 shift = ffs(region->page_size) - 1;
782
783 mr = kmalloc(sizeof *mr, GFP_KERNEL);
784 if (!mr)
785 return ERR_PTR(-ENOMEM);
786
787 n = 0;
788 list_for_each_entry(chunk, &region->chunk_list, list)
789 n += chunk->nents;
790
791 mr->mtt = mthca_alloc_mtt(dev, n);
792 if (IS_ERR(mr->mtt)) {
793 err = PTR_ERR(mr->mtt);
794 goto err;
795 }
796
797 pages = (u64 *) __get_free_page(GFP_KERNEL);
798 if (!pages) {
799 err = -ENOMEM;
800 goto err_mtt;
801 }
802
803 i = n = 0;
804
805 list_for_each_entry(chunk, &region->chunk_list, list)
806 for (j = 0; j < chunk->nmap; ++j) {
807 len = sg_dma_len(&chunk->page_list[j]) >> shift;
808 for (k = 0; k < len; ++k) {
809 pages[i++] = sg_dma_address(&chunk->page_list[j]) +
810 region->page_size * k;
811 /*
812 * Be friendly to WRITE_MTT command
813 * and leave two empty slots for the
814 * index and reserved fields of the
815 * mailbox.
816 */
817 if (i == PAGE_SIZE / sizeof (u64) - 2) {
818 err = mthca_write_mtt(dev, mr->mtt,
819 n, pages, i);
820 if (err)
821 goto mtt_done;
822 n += i;
823 i = 0;
824 }
825 }
826 }
827
828 if (i)
829 err = mthca_write_mtt(dev, mr->mtt, n, pages, i);
830mtt_done:
831 free_page((unsigned long) pages);
832 if (err)
833 goto err_mtt;
834
835 err = mthca_mr_alloc(dev, to_mpd(pd)->pd_num, shift, region->virt_base,
836 region->length, convert_access(acc), mr);
837
838 if (err)
839 goto err_mtt;
840
841 return &mr->ibmr;
842
843err_mtt:
844 mthca_free_mtt(dev, mr->mtt);
845
846err:
847 kfree(mr);
848 return ERR_PTR(err);
849}
850
569static int mthca_dereg_mr(struct ib_mr *mr) 851static int mthca_dereg_mr(struct ib_mr *mr)
570{ 852{
571 struct mthca_mr *mmr = to_mmr(mr); 853 struct mthca_mr *mmr = to_mmr(mr);
@@ -690,6 +972,8 @@ int mthca_register_device(struct mthca_dev *dev)
690 int i; 972 int i;
691 973
692 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 974 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
975 dev->ib_dev.owner = THIS_MODULE;
976
693 dev->ib_dev.node_type = IB_NODE_CA; 977 dev->ib_dev.node_type = IB_NODE_CA;
694 dev->ib_dev.phys_port_cnt = dev->limits.num_ports; 978 dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
695 dev->ib_dev.dma_device = &dev->pdev->dev; 979 dev->ib_dev.dma_device = &dev->pdev->dev;
@@ -699,6 +983,9 @@ int mthca_register_device(struct mthca_dev *dev)
699 dev->ib_dev.modify_port = mthca_modify_port; 983 dev->ib_dev.modify_port = mthca_modify_port;
700 dev->ib_dev.query_pkey = mthca_query_pkey; 984 dev->ib_dev.query_pkey = mthca_query_pkey;
701 dev->ib_dev.query_gid = mthca_query_gid; 985 dev->ib_dev.query_gid = mthca_query_gid;
986 dev->ib_dev.alloc_ucontext = mthca_alloc_ucontext;
987 dev->ib_dev.dealloc_ucontext = mthca_dealloc_ucontext;
988 dev->ib_dev.mmap = mthca_mmap_uar;
702 dev->ib_dev.alloc_pd = mthca_alloc_pd; 989 dev->ib_dev.alloc_pd = mthca_alloc_pd;
703 dev->ib_dev.dealloc_pd = mthca_dealloc_pd; 990 dev->ib_dev.dealloc_pd = mthca_dealloc_pd;
704 dev->ib_dev.create_ah = mthca_ah_create; 991 dev->ib_dev.create_ah = mthca_ah_create;
@@ -711,6 +998,7 @@ int mthca_register_device(struct mthca_dev *dev)
711 dev->ib_dev.poll_cq = mthca_poll_cq; 998 dev->ib_dev.poll_cq = mthca_poll_cq;
712 dev->ib_dev.get_dma_mr = mthca_get_dma_mr; 999 dev->ib_dev.get_dma_mr = mthca_get_dma_mr;
713 dev->ib_dev.reg_phys_mr = mthca_reg_phys_mr; 1000 dev->ib_dev.reg_phys_mr = mthca_reg_phys_mr;
1001 dev->ib_dev.reg_user_mr = mthca_reg_user_mr;
714 dev->ib_dev.dereg_mr = mthca_dereg_mr; 1002 dev->ib_dev.dereg_mr = mthca_dereg_mr;
715 1003
716 if (dev->mthca_flags & MTHCA_FLAG_FMR) { 1004 if (dev->mthca_flags & MTHCA_FLAG_FMR) {
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 619710f95a87..1d032791cc8b 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -54,18 +55,26 @@ struct mthca_uar {
54 int index; 55 int index;
55}; 56};
56 57
58struct mthca_user_db_table;
59
60struct mthca_ucontext {
61 struct ib_ucontext ibucontext;
62 struct mthca_uar uar;
63 struct mthca_user_db_table *db_tab;
64};
65
66struct mthca_mtt;
67
57struct mthca_mr { 68struct mthca_mr {
58 struct ib_mr ibmr; 69 struct ib_mr ibmr;
59 int order; 70 struct mthca_mtt *mtt;
60 u32 first_seg;
61}; 71};
62 72
63struct mthca_fmr { 73struct mthca_fmr {
64 struct ib_fmr ibmr; 74 struct ib_fmr ibmr;
65 struct ib_fmr_attr attr; 75 struct ib_fmr_attr attr;
66 int order; 76 struct mthca_mtt *mtt;
67 u32 first_seg; 77 int maps;
68 int maps;
69 union { 78 union {
70 struct { 79 struct {
71 struct mthca_mpt_entry __iomem *mpt; 80 struct mthca_mpt_entry __iomem *mpt;
@@ -83,6 +92,7 @@ struct mthca_pd {
83 u32 pd_num; 92 u32 pd_num;
84 atomic_t sqp_count; 93 atomic_t sqp_count;
85 struct mthca_mr ntmr; 94 struct mthca_mr ntmr;
95 int privileged;
86}; 96};
87 97
88struct mthca_eq { 98struct mthca_eq {
@@ -167,6 +177,7 @@ struct mthca_cq {
167 int cqn; 177 int cqn;
168 u32 cons_index; 178 u32 cons_index;
169 int is_direct; 179 int is_direct;
180 int is_kernel;
170 181
171 /* Next fields are Arbel only */ 182 /* Next fields are Arbel only */
172 int set_ci_db_index; 183 int set_ci_db_index;
@@ -236,6 +247,11 @@ struct mthca_sqp {
236 dma_addr_t header_dma; 247 dma_addr_t header_dma;
237}; 248};
238 249
250static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
251{
252 return container_of(ibucontext, struct mthca_ucontext, ibucontext);
253}
254
239static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr) 255static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr)
240{ 256{
241 return container_of(ibmr, struct mthca_fmr, ibmr); 257 return container_of(ibmr, struct mthca_fmr, ibmr);
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index ca73bab11a02..f7126b14d5ae 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -46,7 +47,9 @@ enum {
46 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE, 47 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,
47 MTHCA_ACK_REQ_FREQ = 10, 48 MTHCA_ACK_REQ_FREQ = 10,
48 MTHCA_FLIGHT_LIMIT = 9, 49 MTHCA_FLIGHT_LIMIT = 9,
49 MTHCA_UD_HEADER_SIZE = 72 /* largest UD header possible */ 50 MTHCA_UD_HEADER_SIZE = 72, /* largest UD header possible */
51 MTHCA_INLINE_HEADER_SIZE = 4, /* data segment overhead for inline */
52 MTHCA_INLINE_CHUNK_SIZE = 16 /* inline data segment chunk */
50}; 53};
51 54
52enum { 55enum {
@@ -357,6 +360,9 @@ static const struct {
357 [UD] = (IB_QP_PKEY_INDEX | 360 [UD] = (IB_QP_PKEY_INDEX |
358 IB_QP_PORT | 361 IB_QP_PORT |
359 IB_QP_QKEY), 362 IB_QP_QKEY),
363 [UC] = (IB_QP_PKEY_INDEX |
364 IB_QP_PORT |
365 IB_QP_ACCESS_FLAGS),
360 [RC] = (IB_QP_PKEY_INDEX | 366 [RC] = (IB_QP_PKEY_INDEX |
361 IB_QP_PORT | 367 IB_QP_PORT |
362 IB_QP_ACCESS_FLAGS), 368 IB_QP_ACCESS_FLAGS),
@@ -378,6 +384,9 @@ static const struct {
378 [UD] = (IB_QP_PKEY_INDEX | 384 [UD] = (IB_QP_PKEY_INDEX |
379 IB_QP_PORT | 385 IB_QP_PORT |
380 IB_QP_QKEY), 386 IB_QP_QKEY),
387 [UC] = (IB_QP_PKEY_INDEX |
388 IB_QP_PORT |
389 IB_QP_ACCESS_FLAGS),
381 [RC] = (IB_QP_PKEY_INDEX | 390 [RC] = (IB_QP_PKEY_INDEX |
382 IB_QP_PORT | 391 IB_QP_PORT |
383 IB_QP_ACCESS_FLAGS), 392 IB_QP_ACCESS_FLAGS),
@@ -388,6 +397,11 @@ static const struct {
388 [IB_QPS_RTR] = { 397 [IB_QPS_RTR] = {
389 .trans = MTHCA_TRANS_INIT2RTR, 398 .trans = MTHCA_TRANS_INIT2RTR,
390 .req_param = { 399 .req_param = {
400 [UC] = (IB_QP_AV |
401 IB_QP_PATH_MTU |
402 IB_QP_DEST_QPN |
403 IB_QP_RQ_PSN |
404 IB_QP_MAX_DEST_RD_ATOMIC),
391 [RC] = (IB_QP_AV | 405 [RC] = (IB_QP_AV |
392 IB_QP_PATH_MTU | 406 IB_QP_PATH_MTU |
393 IB_QP_DEST_QPN | 407 IB_QP_DEST_QPN |
@@ -398,6 +412,9 @@ static const struct {
398 .opt_param = { 412 .opt_param = {
399 [UD] = (IB_QP_PKEY_INDEX | 413 [UD] = (IB_QP_PKEY_INDEX |
400 IB_QP_QKEY), 414 IB_QP_QKEY),
415 [UC] = (IB_QP_ALT_PATH |
416 IB_QP_ACCESS_FLAGS |
417 IB_QP_PKEY_INDEX),
401 [RC] = (IB_QP_ALT_PATH | 418 [RC] = (IB_QP_ALT_PATH |
402 IB_QP_ACCESS_FLAGS | 419 IB_QP_ACCESS_FLAGS |
403 IB_QP_PKEY_INDEX), 420 IB_QP_PKEY_INDEX),
@@ -413,6 +430,8 @@ static const struct {
413 .trans = MTHCA_TRANS_RTR2RTS, 430 .trans = MTHCA_TRANS_RTR2RTS,
414 .req_param = { 431 .req_param = {
415 [UD] = IB_QP_SQ_PSN, 432 [UD] = IB_QP_SQ_PSN,
433 [UC] = (IB_QP_SQ_PSN |
434 IB_QP_MAX_QP_RD_ATOMIC),
416 [RC] = (IB_QP_TIMEOUT | 435 [RC] = (IB_QP_TIMEOUT |
417 IB_QP_RETRY_CNT | 436 IB_QP_RETRY_CNT |
418 IB_QP_RNR_RETRY | 437 IB_QP_RNR_RETRY |
@@ -423,6 +442,11 @@ static const struct {
423 .opt_param = { 442 .opt_param = {
424 [UD] = (IB_QP_CUR_STATE | 443 [UD] = (IB_QP_CUR_STATE |
425 IB_QP_QKEY), 444 IB_QP_QKEY),
445 [UC] = (IB_QP_CUR_STATE |
446 IB_QP_ALT_PATH |
447 IB_QP_ACCESS_FLAGS |
448 IB_QP_PKEY_INDEX |
449 IB_QP_PATH_MIG_STATE),
426 [RC] = (IB_QP_CUR_STATE | 450 [RC] = (IB_QP_CUR_STATE |
427 IB_QP_ALT_PATH | 451 IB_QP_ALT_PATH |
428 IB_QP_ACCESS_FLAGS | 452 IB_QP_ACCESS_FLAGS |
@@ -442,6 +466,9 @@ static const struct {
442 .opt_param = { 466 .opt_param = {
443 [UD] = (IB_QP_CUR_STATE | 467 [UD] = (IB_QP_CUR_STATE |
444 IB_QP_QKEY), 468 IB_QP_QKEY),
469 [UC] = (IB_QP_ACCESS_FLAGS |
470 IB_QP_ALT_PATH |
471 IB_QP_PATH_MIG_STATE),
445 [RC] = (IB_QP_ACCESS_FLAGS | 472 [RC] = (IB_QP_ACCESS_FLAGS |
446 IB_QP_ALT_PATH | 473 IB_QP_ALT_PATH |
447 IB_QP_PATH_MIG_STATE | 474 IB_QP_PATH_MIG_STATE |
@@ -462,6 +489,10 @@ static const struct {
462 .opt_param = { 489 .opt_param = {
463 [UD] = (IB_QP_CUR_STATE | 490 [UD] = (IB_QP_CUR_STATE |
464 IB_QP_QKEY), 491 IB_QP_QKEY),
492 [UC] = (IB_QP_CUR_STATE |
493 IB_QP_ALT_PATH |
494 IB_QP_ACCESS_FLAGS |
495 IB_QP_PATH_MIG_STATE),
465 [RC] = (IB_QP_CUR_STATE | 496 [RC] = (IB_QP_CUR_STATE |
466 IB_QP_ALT_PATH | 497 IB_QP_ALT_PATH |
467 IB_QP_ACCESS_FLAGS | 498 IB_QP_ACCESS_FLAGS |
@@ -476,6 +507,14 @@ static const struct {
476 .opt_param = { 507 .opt_param = {
477 [UD] = (IB_QP_PKEY_INDEX | 508 [UD] = (IB_QP_PKEY_INDEX |
478 IB_QP_QKEY), 509 IB_QP_QKEY),
510 [UC] = (IB_QP_AV |
511 IB_QP_MAX_QP_RD_ATOMIC |
512 IB_QP_MAX_DEST_RD_ATOMIC |
513 IB_QP_CUR_STATE |
514 IB_QP_ALT_PATH |
515 IB_QP_ACCESS_FLAGS |
516 IB_QP_PKEY_INDEX |
517 IB_QP_PATH_MIG_STATE),
479 [RC] = (IB_QP_AV | 518 [RC] = (IB_QP_AV |
480 IB_QP_TIMEOUT | 519 IB_QP_TIMEOUT |
481 IB_QP_RETRY_CNT | 520 IB_QP_RETRY_CNT |
@@ -501,6 +540,7 @@ static const struct {
501 .opt_param = { 540 .opt_param = {
502 [UD] = (IB_QP_CUR_STATE | 541 [UD] = (IB_QP_CUR_STATE |
503 IB_QP_QKEY), 542 IB_QP_QKEY),
543 [UC] = (IB_QP_CUR_STATE),
504 [RC] = (IB_QP_CUR_STATE | 544 [RC] = (IB_QP_CUR_STATE |
505 IB_QP_MIN_RNR_TIMER), 545 IB_QP_MIN_RNR_TIMER),
506 [MLX] = (IB_QP_CUR_STATE | 546 [MLX] = (IB_QP_CUR_STATE |
@@ -552,7 +592,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
552 struct mthca_dev *dev = to_mdev(ibqp->device); 592 struct mthca_dev *dev = to_mdev(ibqp->device);
553 struct mthca_qp *qp = to_mqp(ibqp); 593 struct mthca_qp *qp = to_mqp(ibqp);
554 enum ib_qp_state cur_state, new_state; 594 enum ib_qp_state cur_state, new_state;
555 void *mailbox = NULL; 595 struct mthca_mailbox *mailbox;
556 struct mthca_qp_param *qp_param; 596 struct mthca_qp_param *qp_param;
557 struct mthca_qp_context *qp_context; 597 struct mthca_qp_context *qp_context;
558 u32 req_param, opt_param; 598 u32 req_param, opt_param;
@@ -609,10 +649,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
609 return -EINVAL; 649 return -EINVAL;
610 } 650 }
611 651
612 mailbox = kmalloc(sizeof (*qp_param) + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); 652 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
613 if (!mailbox) 653 if (IS_ERR(mailbox))
614 return -ENOMEM; 654 return PTR_ERR(mailbox);
615 qp_param = MAILBOX_ALIGN(mailbox); 655 qp_param = mailbox->buf;
616 qp_context = &qp_param->context; 656 qp_context = &qp_param->context;
617 memset(qp_param, 0, sizeof *qp_param); 657 memset(qp_param, 0, sizeof *qp_param);
618 658
@@ -652,7 +692,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
652 692
653 /* leave arbel_sched_queue as 0 */ 693 /* leave arbel_sched_queue as 0 */
654 694
655 qp_context->usr_page = cpu_to_be32(dev->driver_uar.index); 695 if (qp->ibqp.uobject)
696 qp_context->usr_page =
697 cpu_to_be32(to_mucontext(qp->ibqp.uobject->context)->uar.index);
698 else
699 qp_context->usr_page = cpu_to_be32(dev->driver_uar.index);
656 qp_context->local_qpn = cpu_to_be32(qp->qpn); 700 qp_context->local_qpn = cpu_to_be32(qp->qpn);
657 if (attr_mask & IB_QP_DEST_QPN) { 701 if (attr_mask & IB_QP_DEST_QPN) {
658 qp_context->remote_qpn = cpu_to_be32(attr->dest_qp_num); 702 qp_context->remote_qpn = cpu_to_be32(attr->dest_qp_num);
@@ -683,7 +727,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
683 if (attr_mask & IB_QP_AV) { 727 if (attr_mask & IB_QP_AV) {
684 qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f; 728 qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f;
685 qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid); 729 qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid);
686 qp_context->pri_path.static_rate = (!!attr->ah_attr.static_rate) << 3; 730 qp_context->pri_path.static_rate = !!attr->ah_attr.static_rate;
687 if (attr->ah_attr.ah_flags & IB_AH_GRH) { 731 if (attr->ah_attr.ah_flags & IB_AH_GRH) {
688 qp_context->pri_path.g_mylmc |= 1 << 7; 732 qp_context->pri_path.g_mylmc |= 1 << 7;
689 qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index; 733 qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index;
@@ -724,9 +768,9 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
724 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT); 768 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT);
725 } 769 }
726 770
727 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { 771 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
728 qp_context->params1 |= cpu_to_be32(min(attr->max_dest_rd_atomic ? 772 qp_context->params1 |= cpu_to_be32(min(attr->max_rd_atomic ?
729 ffs(attr->max_dest_rd_atomic) - 1 : 0, 773 ffs(attr->max_rd_atomic) - 1 : 0,
730 7) << 21); 774 7) << 21);
731 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX); 775 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX);
732 } 776 }
@@ -764,10 +808,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
764 qp->atomic_rd_en = attr->qp_access_flags; 808 qp->atomic_rd_en = attr->qp_access_flags;
765 } 809 }
766 810
767 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { 811 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
768 u8 rra_max; 812 u8 rra_max;
769 813
770 if (qp->resp_depth && !attr->max_rd_atomic) { 814 if (qp->resp_depth && !attr->max_dest_rd_atomic) {
771 /* 815 /*
772 * Lowering our responder resources to zero. 816 * Lowering our responder resources to zero.
773 * Turn off RDMA/atomics as responder. 817 * Turn off RDMA/atomics as responder.
@@ -778,7 +822,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
778 MTHCA_QP_OPTPAR_RAE); 822 MTHCA_QP_OPTPAR_RAE);
779 } 823 }
780 824
781 if (!qp->resp_depth && attr->max_rd_atomic) { 825 if (!qp->resp_depth && attr->max_dest_rd_atomic) {
782 /* 826 /*
783 * Increasing our responder resources from 827 * Increasing our responder resources from
784 * zero. Turn on RDMA/atomics as appropriate. 828 * zero. Turn on RDMA/atomics as appropriate.
@@ -799,7 +843,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
799 } 843 }
800 844
801 for (rra_max = 0; 845 for (rra_max = 0;
802 1 << rra_max < attr->max_rd_atomic && 846 1 << rra_max < attr->max_dest_rd_atomic &&
803 rra_max < dev->qp_table.rdb_shift; 847 rra_max < dev->qp_table.rdb_shift;
804 ++rra_max) 848 ++rra_max)
805 ; /* nothing */ 849 ; /* nothing */
@@ -807,7 +851,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
807 qp_context->params2 |= cpu_to_be32(rra_max << 21); 851 qp_context->params2 |= cpu_to_be32(rra_max << 21);
808 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX); 852 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX);
809 853
810 qp->resp_depth = attr->max_rd_atomic; 854 qp->resp_depth = attr->max_dest_rd_atomic;
811 } 855 }
812 856
813 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC); 857 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);
@@ -835,7 +879,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
835 } 879 }
836 880
837 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans, 881 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,
838 qp->qpn, 0, qp_param, 0, &status); 882 qp->qpn, 0, mailbox, 0, &status);
839 if (status) { 883 if (status) {
840 mthca_warn(dev, "modify QP %d returned status %02x.\n", 884 mthca_warn(dev, "modify QP %d returned status %02x.\n",
841 state_table[cur_state][new_state].trans, status); 885 state_table[cur_state][new_state].trans, status);
@@ -845,7 +889,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
845 if (!err) 889 if (!err)
846 qp->state = new_state; 890 qp->state = new_state;
847 891
848 kfree(mailbox); 892 mthca_free_mailbox(dev, mailbox);
849 893
850 if (is_sqp(dev, qp)) 894 if (is_sqp(dev, qp))
851 store_attrs(to_msqp(qp), attr, attr_mask); 895 store_attrs(to_msqp(qp), attr, attr_mask);
@@ -917,6 +961,15 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
917 961
918 qp->send_wqe_offset = ALIGN(qp->rq.max << qp->rq.wqe_shift, 962 qp->send_wqe_offset = ALIGN(qp->rq.max << qp->rq.wqe_shift,
919 1 << qp->sq.wqe_shift); 963 1 << qp->sq.wqe_shift);
964
965 /*
966 * If this is a userspace QP, we don't actually have to
967 * allocate anything. All we need is to calculate the WQE
968 * sizes and the send_wqe_offset, so we're done now.
969 */
970 if (pd->ibpd.uobject)
971 return 0;
972
920 size = PAGE_ALIGN(qp->send_wqe_offset + 973 size = PAGE_ALIGN(qp->send_wqe_offset +
921 (qp->sq.max << qp->sq.wqe_shift)); 974 (qp->sq.max << qp->sq.wqe_shift));
922 975
@@ -934,7 +987,8 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
934 mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n", 987 mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n",
935 size, shift); 988 size, shift);
936 989
937 qp->queue.direct.buf = pci_alloc_consistent(dev->pdev, size, &t); 990 qp->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev, size,
991 &t, GFP_KERNEL);
938 if (!qp->queue.direct.buf) 992 if (!qp->queue.direct.buf)
939 goto err_out; 993 goto err_out;
940 994
@@ -973,7 +1027,8 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
973 1027
974 for (i = 0; i < npages; ++i) { 1028 for (i = 0; i < npages; ++i) {
975 qp->queue.page_list[i].buf = 1029 qp->queue.page_list[i].buf =
976 pci_alloc_consistent(dev->pdev, PAGE_SIZE, &t); 1030 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
1031 &t, GFP_KERNEL);
977 if (!qp->queue.page_list[i].buf) 1032 if (!qp->queue.page_list[i].buf)
978 goto err_out_free; 1033 goto err_out_free;
979 1034
@@ -996,16 +1051,15 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
996 1051
997 err_out_free: 1052 err_out_free:
998 if (qp->is_direct) { 1053 if (qp->is_direct) {
999 pci_free_consistent(dev->pdev, size, 1054 dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,
1000 qp->queue.direct.buf, 1055 pci_unmap_addr(&qp->queue.direct, mapping));
1001 pci_unmap_addr(&qp->queue.direct, mapping));
1002 } else 1056 } else
1003 for (i = 0; i < npages; ++i) { 1057 for (i = 0; i < npages; ++i) {
1004 if (qp->queue.page_list[i].buf) 1058 if (qp->queue.page_list[i].buf)
1005 pci_free_consistent(dev->pdev, PAGE_SIZE, 1059 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
1006 qp->queue.page_list[i].buf, 1060 qp->queue.page_list[i].buf,
1007 pci_unmap_addr(&qp->queue.page_list[i], 1061 pci_unmap_addr(&qp->queue.page_list[i],
1008 mapping)); 1062 mapping));
1009 1063
1010 } 1064 }
1011 1065
@@ -1015,10 +1069,32 @@ static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
1015 return err; 1069 return err;
1016} 1070}
1017 1071
1018static int mthca_alloc_memfree(struct mthca_dev *dev, 1072static void mthca_free_wqe_buf(struct mthca_dev *dev,
1019 struct mthca_qp *qp) 1073 struct mthca_qp *qp)
1020{ 1074{
1021 int ret = 0; 1075 int i;
1076 int size = PAGE_ALIGN(qp->send_wqe_offset +
1077 (qp->sq.max << qp->sq.wqe_shift));
1078
1079 if (qp->is_direct) {
1080 dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,
1081 pci_unmap_addr(&qp->queue.direct, mapping));
1082 } else {
1083 for (i = 0; i < size / PAGE_SIZE; ++i) {
1084 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
1085 qp->queue.page_list[i].buf,
1086 pci_unmap_addr(&qp->queue.page_list[i],
1087 mapping));
1088 }
1089 }
1090
1091 kfree(qp->wrid);
1092}
1093
1094static int mthca_map_memfree(struct mthca_dev *dev,
1095 struct mthca_qp *qp)
1096{
1097 int ret;
1022 1098
1023 if (mthca_is_memfree(dev)) { 1099 if (mthca_is_memfree(dev)) {
1024 ret = mthca_table_get(dev, dev->qp_table.qp_table, qp->qpn); 1100 ret = mthca_table_get(dev, dev->qp_table.qp_table, qp->qpn);
@@ -1029,35 +1105,15 @@ static int mthca_alloc_memfree(struct mthca_dev *dev,
1029 if (ret) 1105 if (ret)
1030 goto err_qpc; 1106 goto err_qpc;
1031 1107
1032 ret = mthca_table_get(dev, dev->qp_table.rdb_table, 1108 ret = mthca_table_get(dev, dev->qp_table.rdb_table,
1033 qp->qpn << dev->qp_table.rdb_shift); 1109 qp->qpn << dev->qp_table.rdb_shift);
1034 if (ret) 1110 if (ret)
1035 goto err_eqpc; 1111 goto err_eqpc;
1036
1037 qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ,
1038 qp->qpn, &qp->rq.db);
1039 if (qp->rq.db_index < 0) {
1040 ret = -ENOMEM;
1041 goto err_rdb;
1042 }
1043 1112
1044 qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ,
1045 qp->qpn, &qp->sq.db);
1046 if (qp->sq.db_index < 0) {
1047 ret = -ENOMEM;
1048 goto err_rq_db;
1049 }
1050 } 1113 }
1051 1114
1052 return 0; 1115 return 0;
1053 1116
1054err_rq_db:
1055 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1056
1057err_rdb:
1058 mthca_table_put(dev, dev->qp_table.rdb_table,
1059 qp->qpn << dev->qp_table.rdb_shift);
1060
1061err_eqpc: 1117err_eqpc:
1062 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn); 1118 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1063 1119
@@ -1067,16 +1123,41 @@ err_qpc:
1067 return ret; 1123 return ret;
1068} 1124}
1069 1125
1126static void mthca_unmap_memfree(struct mthca_dev *dev,
1127 struct mthca_qp *qp)
1128{
1129 mthca_table_put(dev, dev->qp_table.rdb_table,
1130 qp->qpn << dev->qp_table.rdb_shift);
1131 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1132 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1133}
1134
1135static int mthca_alloc_memfree(struct mthca_dev *dev,
1136 struct mthca_qp *qp)
1137{
1138 int ret = 0;
1139
1140 if (mthca_is_memfree(dev)) {
1141 qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ,
1142 qp->qpn, &qp->rq.db);
1143 if (qp->rq.db_index < 0)
1144 return ret;
1145
1146 qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ,
1147 qp->qpn, &qp->sq.db);
1148 if (qp->sq.db_index < 0)
1149 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1150 }
1151
1152 return ret;
1153}
1154
1070static void mthca_free_memfree(struct mthca_dev *dev, 1155static void mthca_free_memfree(struct mthca_dev *dev,
1071 struct mthca_qp *qp) 1156 struct mthca_qp *qp)
1072{ 1157{
1073 if (mthca_is_memfree(dev)) { 1158 if (mthca_is_memfree(dev)) {
1074 mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index); 1159 mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index);
1075 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index); 1160 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1076 mthca_table_put(dev, dev->qp_table.rdb_table,
1077 qp->qpn << dev->qp_table.rdb_shift);
1078 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1079 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1080 } 1161 }
1081} 1162}
1082 1163
@@ -1108,13 +1189,28 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
1108 mthca_wq_init(&qp->sq); 1189 mthca_wq_init(&qp->sq);
1109 mthca_wq_init(&qp->rq); 1190 mthca_wq_init(&qp->rq);
1110 1191
1111 ret = mthca_alloc_memfree(dev, qp); 1192 ret = mthca_map_memfree(dev, qp);
1112 if (ret) 1193 if (ret)
1113 return ret; 1194 return ret;
1114 1195
1115 ret = mthca_alloc_wqe_buf(dev, pd, qp); 1196 ret = mthca_alloc_wqe_buf(dev, pd, qp);
1116 if (ret) { 1197 if (ret) {
1117 mthca_free_memfree(dev, qp); 1198 mthca_unmap_memfree(dev, qp);
1199 return ret;
1200 }
1201
1202 /*
1203 * If this is a userspace QP, we're done now. The doorbells
1204 * will be allocated and buffers will be initialized in
1205 * userspace.
1206 */
1207 if (pd->ibpd.uobject)
1208 return 0;
1209
1210 ret = mthca_alloc_memfree(dev, qp);
1211 if (ret) {
1212 mthca_free_wqe_buf(dev, qp);
1213 mthca_unmap_memfree(dev, qp);
1118 return ret; 1214 return ret;
1119 } 1215 }
1120 1216
@@ -1147,22 +1243,39 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
1147 return 0; 1243 return 0;
1148} 1244}
1149 1245
1150static void mthca_align_qp_size(struct mthca_dev *dev, struct mthca_qp *qp) 1246static int mthca_set_qp_size(struct mthca_dev *dev, struct ib_qp_cap *cap,
1247 struct mthca_qp *qp)
1151{ 1248{
1152 int i; 1249 /* Sanity check QP size before proceeding */
1153 1250 if (cap->max_send_wr > 65536 || cap->max_recv_wr > 65536 ||
1154 if (!mthca_is_memfree(dev)) 1251 cap->max_send_sge > 64 || cap->max_recv_sge > 64)
1155 return; 1252 return -EINVAL;
1156 1253
1157 for (i = 0; 1 << i < qp->rq.max; ++i) 1254 if (mthca_is_memfree(dev)) {
1158 ; /* nothing */ 1255 qp->rq.max = cap->max_recv_wr ?
1256 roundup_pow_of_two(cap->max_recv_wr) : 0;
1257 qp->sq.max = cap->max_send_wr ?
1258 roundup_pow_of_two(cap->max_send_wr) : 0;
1259 } else {
1260 qp->rq.max = cap->max_recv_wr;
1261 qp->sq.max = cap->max_send_wr;
1262 }
1159 1263
1160 qp->rq.max = 1 << i; 1264 qp->rq.max_gs = cap->max_recv_sge;
1265 qp->sq.max_gs = max_t(int, cap->max_send_sge,
1266 ALIGN(cap->max_inline_data + MTHCA_INLINE_HEADER_SIZE,
1267 MTHCA_INLINE_CHUNK_SIZE) /
1268 sizeof (struct mthca_data_seg));
1161 1269
1162 for (i = 0; 1 << i < qp->sq.max; ++i) 1270 /*
1163 ; /* nothing */ 1271 * For MLX transport we need 2 extra S/G entries:
1272 * one for the header and one for the checksum at the end
1273 */
1274 if ((qp->transport == MLX && qp->sq.max_gs + 2 > dev->limits.max_sg) ||
1275 qp->sq.max_gs > dev->limits.max_sg || qp->rq.max_gs > dev->limits.max_sg)
1276 return -EINVAL;
1164 1277
1165 qp->sq.max = 1 << i; 1278 return 0;
1166} 1279}
1167 1280
1168int mthca_alloc_qp(struct mthca_dev *dev, 1281int mthca_alloc_qp(struct mthca_dev *dev,
@@ -1171,11 +1284,14 @@ int mthca_alloc_qp(struct mthca_dev *dev,
1171 struct mthca_cq *recv_cq, 1284 struct mthca_cq *recv_cq,
1172 enum ib_qp_type type, 1285 enum ib_qp_type type,
1173 enum ib_sig_type send_policy, 1286 enum ib_sig_type send_policy,
1287 struct ib_qp_cap *cap,
1174 struct mthca_qp *qp) 1288 struct mthca_qp *qp)
1175{ 1289{
1176 int err; 1290 int err;
1177 1291
1178 mthca_align_qp_size(dev, qp); 1292 err = mthca_set_qp_size(dev, cap, qp);
1293 if (err)
1294 return err;
1179 1295
1180 switch (type) { 1296 switch (type) {
1181 case IB_QPT_RC: qp->transport = RC; break; 1297 case IB_QPT_RC: qp->transport = RC; break;
@@ -1208,14 +1324,17 @@ int mthca_alloc_sqp(struct mthca_dev *dev,
1208 struct mthca_cq *send_cq, 1324 struct mthca_cq *send_cq,
1209 struct mthca_cq *recv_cq, 1325 struct mthca_cq *recv_cq,
1210 enum ib_sig_type send_policy, 1326 enum ib_sig_type send_policy,
1327 struct ib_qp_cap *cap,
1211 int qpn, 1328 int qpn,
1212 int port, 1329 int port,
1213 struct mthca_sqp *sqp) 1330 struct mthca_sqp *sqp)
1214{ 1331{
1215 int err = 0;
1216 u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1; 1332 u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1;
1333 int err;
1217 1334
1218 mthca_align_qp_size(dev, &sqp->qp); 1335 err = mthca_set_qp_size(dev, cap, &sqp->qp);
1336 if (err)
1337 return err;
1219 1338
1220 sqp->header_buf_size = sqp->qp.sq.max * MTHCA_UD_HEADER_SIZE; 1339 sqp->header_buf_size = sqp->qp.sq.max * MTHCA_UD_HEADER_SIZE;
1221 sqp->header_buf = dma_alloc_coherent(&dev->pdev->dev, sqp->header_buf_size, 1340 sqp->header_buf = dma_alloc_coherent(&dev->pdev->dev, sqp->header_buf_size,
@@ -1274,8 +1393,6 @@ void mthca_free_qp(struct mthca_dev *dev,
1274 struct mthca_qp *qp) 1393 struct mthca_qp *qp)
1275{ 1394{
1276 u8 status; 1395 u8 status;
1277 int size;
1278 int i;
1279 struct mthca_cq *send_cq; 1396 struct mthca_cq *send_cq;
1280 struct mthca_cq *recv_cq; 1397 struct mthca_cq *recv_cq;
1281 1398
@@ -1305,31 +1422,22 @@ void mthca_free_qp(struct mthca_dev *dev,
1305 if (qp->state != IB_QPS_RESET) 1422 if (qp->state != IB_QPS_RESET)
1306 mthca_MODIFY_QP(dev, MTHCA_TRANS_ANY2RST, qp->qpn, 0, NULL, 0, &status); 1423 mthca_MODIFY_QP(dev, MTHCA_TRANS_ANY2RST, qp->qpn, 0, NULL, 0, &status);
1307 1424
1308 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn); 1425 /*
1309 if (qp->ibqp.send_cq != qp->ibqp.recv_cq) 1426 * If this is a userspace QP, the buffers, MR, CQs and so on
1310 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn); 1427 * will be cleaned up in userspace, so all we have to do is
1311 1428 * unref the mem-free tables and free the QPN in our table.
1312 mthca_free_mr(dev, &qp->mr); 1429 */
1313 1430 if (!qp->ibqp.uobject) {
1314 size = PAGE_ALIGN(qp->send_wqe_offset + 1431 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn);
1315 (qp->sq.max << qp->sq.wqe_shift)); 1432 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
1433 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn);
1316 1434
1317 if (qp->is_direct) { 1435 mthca_free_mr(dev, &qp->mr);
1318 pci_free_consistent(dev->pdev, size, 1436 mthca_free_memfree(dev, qp);
1319 qp->queue.direct.buf, 1437 mthca_free_wqe_buf(dev, qp);
1320 pci_unmap_addr(&qp->queue.direct, mapping));
1321 } else {
1322 for (i = 0; i < size / PAGE_SIZE; ++i) {
1323 pci_free_consistent(dev->pdev, PAGE_SIZE,
1324 qp->queue.page_list[i].buf,
1325 pci_unmap_addr(&qp->queue.page_list[i],
1326 mapping));
1327 }
1328 } 1438 }
1329 1439
1330 kfree(qp->wrid); 1440 mthca_unmap_memfree(dev, qp);
1331
1332 mthca_free_memfree(dev, qp);
1333 1441
1334 if (is_sqp(dev, qp)) { 1442 if (is_sqp(dev, qp)) {
1335 atomic_dec(&(to_mpd(qp->ibqp.pd)->sqp_count)); 1443 atomic_dec(&(to_mpd(qp->ibqp.pd)->sqp_count));
@@ -1529,6 +1637,26 @@ int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1529 1637
1530 break; 1638 break;
1531 1639
1640 case UC:
1641 switch (wr->opcode) {
1642 case IB_WR_RDMA_WRITE:
1643 case IB_WR_RDMA_WRITE_WITH_IMM:
1644 ((struct mthca_raddr_seg *) wqe)->raddr =
1645 cpu_to_be64(wr->wr.rdma.remote_addr);
1646 ((struct mthca_raddr_seg *) wqe)->rkey =
1647 cpu_to_be32(wr->wr.rdma.rkey);
1648 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1649 wqe += sizeof (struct mthca_raddr_seg);
1650 size += sizeof (struct mthca_raddr_seg) / 16;
1651 break;
1652
1653 default:
1654 /* No extra segments required for sends */
1655 break;
1656 }
1657
1658 break;
1659
1532 case UD: 1660 case UD:
1533 ((struct mthca_tavor_ud_seg *) wqe)->lkey = 1661 ((struct mthca_tavor_ud_seg *) wqe)->lkey =
1534 cpu_to_be32(to_mah(wr->wr.ud.ah)->key); 1662 cpu_to_be32(to_mah(wr->wr.ud.ah)->key);
@@ -1814,9 +1942,29 @@ int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1814 sizeof (struct mthca_atomic_seg); 1942 sizeof (struct mthca_atomic_seg);
1815 break; 1943 break;
1816 1944
1945 case IB_WR_RDMA_READ:
1946 case IB_WR_RDMA_WRITE:
1947 case IB_WR_RDMA_WRITE_WITH_IMM:
1948 ((struct mthca_raddr_seg *) wqe)->raddr =
1949 cpu_to_be64(wr->wr.rdma.remote_addr);
1950 ((struct mthca_raddr_seg *) wqe)->rkey =
1951 cpu_to_be32(wr->wr.rdma.rkey);
1952 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1953 wqe += sizeof (struct mthca_raddr_seg);
1954 size += sizeof (struct mthca_raddr_seg) / 16;
1955 break;
1956
1957 default:
1958 /* No extra segments required for sends */
1959 break;
1960 }
1961
1962 break;
1963
1964 case UC:
1965 switch (wr->opcode) {
1817 case IB_WR_RDMA_WRITE: 1966 case IB_WR_RDMA_WRITE:
1818 case IB_WR_RDMA_WRITE_WITH_IMM: 1967 case IB_WR_RDMA_WRITE_WITH_IMM:
1819 case IB_WR_RDMA_READ:
1820 ((struct mthca_raddr_seg *) wqe)->raddr = 1968 ((struct mthca_raddr_seg *) wqe)->raddr =
1821 cpu_to_be64(wr->wr.rdma.remote_addr); 1969 cpu_to_be64(wr->wr.rdma.remote_addr);
1822 ((struct mthca_raddr_seg *) wqe)->rkey = 1970 ((struct mthca_raddr_seg *) wqe)->rkey =
diff --git a/drivers/infiniband/hw/mthca/mthca_user.h b/drivers/infiniband/hw/mthca/mthca_user.h
new file mode 100644
index 000000000000..3024c1b4547d
--- /dev/null
+++ b/drivers/infiniband/hw/mthca/mthca_user.h
@@ -0,0 +1,81 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 */
34
35#ifndef MTHCA_USER_H
36#define MTHCA_USER_H
37
38#include <linux/types.h>
39
40/*
41 * Make sure that all structs defined in this file remain laid out so
42 * that they pack the same way on 32-bit and 64-bit architectures (to
43 * avoid incompatibility between 32-bit userspace and 64-bit kernels).
44 * In particular do not use pointer types -- pass pointers in __u64
45 * instead.
46 */
47
48struct mthca_alloc_ucontext_resp {
49 __u32 qp_tab_size;
50 __u32 uarc_size;
51};
52
53struct mthca_alloc_pd_resp {
54 __u32 pdn;
55 __u32 reserved;
56};
57
58struct mthca_create_cq {
59 __u32 lkey;
60 __u32 pdn;
61 __u64 arm_db_page;
62 __u64 set_db_page;
63 __u32 arm_db_index;
64 __u32 set_db_index;
65};
66
67struct mthca_create_cq_resp {
68 __u32 cqn;
69 __u32 reserved;
70};
71
72struct mthca_create_qp {
73 __u32 lkey;
74 __u32 reserved;
75 __u64 sq_db_page;
76 __u64 rq_db_page;
77 __u32 sq_db_index;
78 __u32 rq_db_index;
79};
80
81#endif /* MTHCA_USER_H */
diff --git a/drivers/infiniband/include/ib_user_verbs.h b/drivers/infiniband/include/ib_user_verbs.h
new file mode 100644
index 000000000000..7c613706af72
--- /dev/null
+++ b/drivers/infiniband/include/ib_user_verbs.h
@@ -0,0 +1,389 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: ib_user_verbs.h 2708 2005-06-24 17:27:21Z roland $
34 */
35
36#ifndef IB_USER_VERBS_H
37#define IB_USER_VERBS_H
38
39#include <linux/types.h>
40
41/*
42 * Increment this value if any changes that break userspace ABI
43 * compatibility are made.
44 */
45#define IB_USER_VERBS_ABI_VERSION 1
46
47enum {
48 IB_USER_VERBS_CMD_QUERY_PARAMS,
49 IB_USER_VERBS_CMD_GET_CONTEXT,
50 IB_USER_VERBS_CMD_QUERY_DEVICE,
51 IB_USER_VERBS_CMD_QUERY_PORT,
52 IB_USER_VERBS_CMD_QUERY_GID,
53 IB_USER_VERBS_CMD_QUERY_PKEY,
54 IB_USER_VERBS_CMD_ALLOC_PD,
55 IB_USER_VERBS_CMD_DEALLOC_PD,
56 IB_USER_VERBS_CMD_CREATE_AH,
57 IB_USER_VERBS_CMD_MODIFY_AH,
58 IB_USER_VERBS_CMD_QUERY_AH,
59 IB_USER_VERBS_CMD_DESTROY_AH,
60 IB_USER_VERBS_CMD_REG_MR,
61 IB_USER_VERBS_CMD_REG_SMR,
62 IB_USER_VERBS_CMD_REREG_MR,
63 IB_USER_VERBS_CMD_QUERY_MR,
64 IB_USER_VERBS_CMD_DEREG_MR,
65 IB_USER_VERBS_CMD_ALLOC_MW,
66 IB_USER_VERBS_CMD_BIND_MW,
67 IB_USER_VERBS_CMD_DEALLOC_MW,
68 IB_USER_VERBS_CMD_CREATE_CQ,
69 IB_USER_VERBS_CMD_RESIZE_CQ,
70 IB_USER_VERBS_CMD_DESTROY_CQ,
71 IB_USER_VERBS_CMD_POLL_CQ,
72 IB_USER_VERBS_CMD_PEEK_CQ,
73 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
74 IB_USER_VERBS_CMD_CREATE_QP,
75 IB_USER_VERBS_CMD_QUERY_QP,
76 IB_USER_VERBS_CMD_MODIFY_QP,
77 IB_USER_VERBS_CMD_DESTROY_QP,
78 IB_USER_VERBS_CMD_POST_SEND,
79 IB_USER_VERBS_CMD_POST_RECV,
80 IB_USER_VERBS_CMD_ATTACH_MCAST,
81 IB_USER_VERBS_CMD_DETACH_MCAST
82};
83
84/*
85 * Make sure that all structs defined in this file remain laid out so
86 * that they pack the same way on 32-bit and 64-bit architectures (to
87 * avoid incompatibility between 32-bit userspace and 64-bit kernels).
88 * In particular do not use pointer types -- pass pointers in __u64
89 * instead.
90 */
91
92struct ib_uverbs_async_event_desc {
93 __u64 element;
94 __u32 event_type; /* enum ib_event_type */
95 __u32 reserved;
96};
97
98struct ib_uverbs_comp_event_desc {
99 __u64 cq_handle;
100};
101
102/*
103 * All commands from userspace should start with a __u32 command field
104 * followed by __u16 in_words and out_words fields (which give the
105 * length of the command block and response buffer if any in 32-bit
106 * words). The kernel driver will read these fields first and read
107 * the rest of the command struct based on these value.
108 */
109
110struct ib_uverbs_cmd_hdr {
111 __u32 command;
112 __u16 in_words;
113 __u16 out_words;
114};
115
116/*
117 * No driver_data for "query params" command, since this is intended
118 * to be a core function with no possible device dependence.
119 */
120struct ib_uverbs_query_params {
121 __u64 response;
122};
123
124struct ib_uverbs_query_params_resp {
125 __u32 num_cq_events;
126};
127
128struct ib_uverbs_get_context {
129 __u64 response;
130 __u64 cq_fd_tab;
131 __u64 driver_data[0];
132};
133
134struct ib_uverbs_get_context_resp {
135 __u32 async_fd;
136 __u32 reserved;
137};
138
139struct ib_uverbs_query_device {
140 __u64 response;
141 __u64 driver_data[0];
142};
143
144struct ib_uverbs_query_device_resp {
145 __u64 fw_ver;
146 __u64 node_guid;
147 __u64 sys_image_guid;
148 __u64 max_mr_size;
149 __u64 page_size_cap;
150 __u32 vendor_id;
151 __u32 vendor_part_id;
152 __u32 hw_ver;
153 __u32 max_qp;
154 __u32 max_qp_wr;
155 __u32 device_cap_flags;
156 __u32 max_sge;
157 __u32 max_sge_rd;
158 __u32 max_cq;
159 __u32 max_cqe;
160 __u32 max_mr;
161 __u32 max_pd;
162 __u32 max_qp_rd_atom;
163 __u32 max_ee_rd_atom;
164 __u32 max_res_rd_atom;
165 __u32 max_qp_init_rd_atom;
166 __u32 max_ee_init_rd_atom;
167 __u32 atomic_cap;
168 __u32 max_ee;
169 __u32 max_rdd;
170 __u32 max_mw;
171 __u32 max_raw_ipv6_qp;
172 __u32 max_raw_ethy_qp;
173 __u32 max_mcast_grp;
174 __u32 max_mcast_qp_attach;
175 __u32 max_total_mcast_qp_attach;
176 __u32 max_ah;
177 __u32 max_fmr;
178 __u32 max_map_per_fmr;
179 __u32 max_srq;
180 __u32 max_srq_wr;
181 __u32 max_srq_sge;
182 __u16 max_pkeys;
183 __u8 local_ca_ack_delay;
184 __u8 phys_port_cnt;
185 __u8 reserved[4];
186};
187
188struct ib_uverbs_query_port {
189 __u64 response;
190 __u8 port_num;
191 __u8 reserved[7];
192 __u64 driver_data[0];
193};
194
195struct ib_uverbs_query_port_resp {
196 __u32 port_cap_flags;
197 __u32 max_msg_sz;
198 __u32 bad_pkey_cntr;
199 __u32 qkey_viol_cntr;
200 __u32 gid_tbl_len;
201 __u16 pkey_tbl_len;
202 __u16 lid;
203 __u16 sm_lid;
204 __u8 state;
205 __u8 max_mtu;
206 __u8 active_mtu;
207 __u8 lmc;
208 __u8 max_vl_num;
209 __u8 sm_sl;
210 __u8 subnet_timeout;
211 __u8 init_type_reply;
212 __u8 active_width;
213 __u8 active_speed;
214 __u8 phys_state;
215 __u8 reserved[3];
216};
217
218struct ib_uverbs_query_gid {
219 __u64 response;
220 __u8 port_num;
221 __u8 index;
222 __u8 reserved[6];
223 __u64 driver_data[0];
224};
225
226struct ib_uverbs_query_gid_resp {
227 __u8 gid[16];
228};
229
230struct ib_uverbs_query_pkey {
231 __u64 response;
232 __u8 port_num;
233 __u8 index;
234 __u8 reserved[6];
235 __u64 driver_data[0];
236};
237
238struct ib_uverbs_query_pkey_resp {
239 __u16 pkey;
240 __u16 reserved;
241};
242
243struct ib_uverbs_alloc_pd {
244 __u64 response;
245 __u64 driver_data[0];
246};
247
248struct ib_uverbs_alloc_pd_resp {
249 __u32 pd_handle;
250};
251
252struct ib_uverbs_dealloc_pd {
253 __u32 pd_handle;
254};
255
256struct ib_uverbs_reg_mr {
257 __u64 response;
258 __u64 start;
259 __u64 length;
260 __u64 hca_va;
261 __u32 pd_handle;
262 __u32 access_flags;
263 __u64 driver_data[0];
264};
265
266struct ib_uverbs_reg_mr_resp {
267 __u32 mr_handle;
268 __u32 lkey;
269 __u32 rkey;
270};
271
272struct ib_uverbs_dereg_mr {
273 __u32 mr_handle;
274};
275
276struct ib_uverbs_create_cq {
277 __u64 response;
278 __u64 user_handle;
279 __u32 cqe;
280 __u32 event_handler;
281 __u64 driver_data[0];
282};
283
284struct ib_uverbs_create_cq_resp {
285 __u32 cq_handle;
286 __u32 cqe;
287};
288
289struct ib_uverbs_destroy_cq {
290 __u32 cq_handle;
291};
292
293struct ib_uverbs_create_qp {
294 __u64 response;
295 __u64 user_handle;
296 __u32 pd_handle;
297 __u32 send_cq_handle;
298 __u32 recv_cq_handle;
299 __u32 srq_handle;
300 __u32 max_send_wr;
301 __u32 max_recv_wr;
302 __u32 max_send_sge;
303 __u32 max_recv_sge;
304 __u32 max_inline_data;
305 __u8 sq_sig_all;
306 __u8 qp_type;
307 __u8 is_srq;
308 __u8 reserved;
309 __u64 driver_data[0];
310};
311
312struct ib_uverbs_create_qp_resp {
313 __u32 qp_handle;
314 __u32 qpn;
315};
316
317/*
318 * This struct needs to remain a multiple of 8 bytes to keep the
319 * alignment of the modify QP parameters.
320 */
321struct ib_uverbs_qp_dest {
322 __u8 dgid[16];
323 __u32 flow_label;
324 __u16 dlid;
325 __u16 reserved;
326 __u8 sgid_index;
327 __u8 hop_limit;
328 __u8 traffic_class;
329 __u8 sl;
330 __u8 src_path_bits;
331 __u8 static_rate;
332 __u8 is_global;
333 __u8 port_num;
334};
335
336struct ib_uverbs_modify_qp {
337 struct ib_uverbs_qp_dest dest;
338 struct ib_uverbs_qp_dest alt_dest;
339 __u32 qp_handle;
340 __u32 attr_mask;
341 __u32 qkey;
342 __u32 rq_psn;
343 __u32 sq_psn;
344 __u32 dest_qp_num;
345 __u32 qp_access_flags;
346 __u16 pkey_index;
347 __u16 alt_pkey_index;
348 __u8 qp_state;
349 __u8 cur_qp_state;
350 __u8 path_mtu;
351 __u8 path_mig_state;
352 __u8 en_sqd_async_notify;
353 __u8 max_rd_atomic;
354 __u8 max_dest_rd_atomic;
355 __u8 min_rnr_timer;
356 __u8 port_num;
357 __u8 timeout;
358 __u8 retry_cnt;
359 __u8 rnr_retry;
360 __u8 alt_port_num;
361 __u8 alt_timeout;
362 __u8 reserved[2];
363 __u64 driver_data[0];
364};
365
366struct ib_uverbs_modify_qp_resp {
367};
368
369struct ib_uverbs_destroy_qp {
370 __u32 qp_handle;
371};
372
373struct ib_uverbs_attach_mcast {
374 __u8 gid[16];
375 __u32 qp_handle;
376 __u16 mlid;
377 __u16 reserved;
378 __u64 driver_data[0];
379};
380
381struct ib_uverbs_detach_mcast {
382 __u8 gid[16];
383 __u32 qp_handle;
384 __u16 mlid;
385 __u16 reserved;
386 __u64 driver_data[0];
387};
388
389#endif /* IB_USER_VERBS_H */
diff --git a/drivers/infiniband/include/ib_verbs.h b/drivers/infiniband/include/ib_verbs.h
index cf01f044a223..e5bd9a10c201 100644
--- a/drivers/infiniband/include/ib_verbs.h
+++ b/drivers/infiniband/include/ib_verbs.h
@@ -4,6 +4,7 @@
4 * Copyright (c) 2004 Intel Corporation. All rights reserved. 4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
7 * Copyright (c) 2005 Cisco Systems. All rights reserved.
7 * 8 *
8 * This software is available to you under a choice of one of two 9 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU 10 * licenses. You may choose to be licensed under the terms of the GNU
@@ -41,7 +42,10 @@
41 42
42#include <linux/types.h> 43#include <linux/types.h>
43#include <linux/device.h> 44#include <linux/device.h>
45
44#include <asm/atomic.h> 46#include <asm/atomic.h>
47#include <asm/scatterlist.h>
48#include <asm/uaccess.h>
45 49
46union ib_gid { 50union ib_gid {
47 u8 raw[16]; 51 u8 raw[16];
@@ -544,7 +548,7 @@ struct ib_send_wr {
544 int num_sge; 548 int num_sge;
545 enum ib_wr_opcode opcode; 549 enum ib_wr_opcode opcode;
546 int send_flags; 550 int send_flags;
547 u32 imm_data; 551 __be32 imm_data;
548 union { 552 union {
549 struct { 553 struct {
550 u64 remote_addr; 554 u64 remote_addr;
@@ -618,29 +622,86 @@ struct ib_fmr_attr {
618 u8 page_size; 622 u8 page_size;
619}; 623};
620 624
625struct ib_ucontext {
626 struct ib_device *device;
627 struct list_head pd_list;
628 struct list_head mr_list;
629 struct list_head mw_list;
630 struct list_head cq_list;
631 struct list_head qp_list;
632 struct list_head srq_list;
633 struct list_head ah_list;
634 spinlock_t lock;
635};
636
637struct ib_uobject {
638 u64 user_handle; /* handle given to us by userspace */
639 struct ib_ucontext *context; /* associated user context */
640 struct list_head list; /* link to context's list */
641 u32 id; /* index into kernel idr */
642};
643
644struct ib_umem {
645 unsigned long user_base;
646 unsigned long virt_base;
647 size_t length;
648 int offset;
649 int page_size;
650 int writable;
651 struct list_head chunk_list;
652};
653
654struct ib_umem_chunk {
655 struct list_head list;
656 int nents;
657 int nmap;
658 struct scatterlist page_list[0];
659};
660
661struct ib_udata {
662 void __user *inbuf;
663 void __user *outbuf;
664 size_t inlen;
665 size_t outlen;
666};
667
668#define IB_UMEM_MAX_PAGE_CHUNK \
669 ((PAGE_SIZE - offsetof(struct ib_umem_chunk, page_list)) / \
670 ((void *) &((struct ib_umem_chunk *) 0)->page_list[1] - \
671 (void *) &((struct ib_umem_chunk *) 0)->page_list[0]))
672
673struct ib_umem_object {
674 struct ib_uobject uobject;
675 struct ib_umem umem;
676};
677
621struct ib_pd { 678struct ib_pd {
622 struct ib_device *device; 679 struct ib_device *device;
623 atomic_t usecnt; /* count all resources */ 680 struct ib_uobject *uobject;
681 atomic_t usecnt; /* count all resources */
624}; 682};
625 683
626struct ib_ah { 684struct ib_ah {
627 struct ib_device *device; 685 struct ib_device *device;
628 struct ib_pd *pd; 686 struct ib_pd *pd;
687 struct ib_uobject *uobject;
629}; 688};
630 689
631typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); 690typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
632 691
633struct ib_cq { 692struct ib_cq {
634 struct ib_device *device; 693 struct ib_device *device;
635 ib_comp_handler comp_handler; 694 struct ib_uobject *uobject;
636 void (*event_handler)(struct ib_event *, void *); 695 ib_comp_handler comp_handler;
637 void * cq_context; 696 void (*event_handler)(struct ib_event *, void *);
638 int cqe; 697 void * cq_context;
639 atomic_t usecnt; /* count number of work queues */ 698 int cqe;
699 atomic_t usecnt; /* count number of work queues */
640}; 700};
641 701
642struct ib_srq { 702struct ib_srq {
643 struct ib_device *device; 703 struct ib_device *device;
704 struct ib_uobject *uobject;
644 struct ib_pd *pd; 705 struct ib_pd *pd;
645 void *srq_context; 706 void *srq_context;
646 atomic_t usecnt; 707 atomic_t usecnt;
@@ -652,6 +713,7 @@ struct ib_qp {
652 struct ib_cq *send_cq; 713 struct ib_cq *send_cq;
653 struct ib_cq *recv_cq; 714 struct ib_cq *recv_cq;
654 struct ib_srq *srq; 715 struct ib_srq *srq;
716 struct ib_uobject *uobject;
655 void (*event_handler)(struct ib_event *, void *); 717 void (*event_handler)(struct ib_event *, void *);
656 void *qp_context; 718 void *qp_context;
657 u32 qp_num; 719 u32 qp_num;
@@ -659,16 +721,18 @@ struct ib_qp {
659}; 721};
660 722
661struct ib_mr { 723struct ib_mr {
662 struct ib_device *device; 724 struct ib_device *device;
663 struct ib_pd *pd; 725 struct ib_pd *pd;
664 u32 lkey; 726 struct ib_uobject *uobject;
665 u32 rkey; 727 u32 lkey;
666 atomic_t usecnt; /* count number of MWs */ 728 u32 rkey;
729 atomic_t usecnt; /* count number of MWs */
667}; 730};
668 731
669struct ib_mw { 732struct ib_mw {
670 struct ib_device *device; 733 struct ib_device *device;
671 struct ib_pd *pd; 734 struct ib_pd *pd;
735 struct ib_uobject *uobject;
672 u32 rkey; 736 u32 rkey;
673}; 737};
674 738
@@ -737,7 +801,14 @@ struct ib_device {
737 int (*modify_port)(struct ib_device *device, 801 int (*modify_port)(struct ib_device *device,
738 u8 port_num, int port_modify_mask, 802 u8 port_num, int port_modify_mask,
739 struct ib_port_modify *port_modify); 803 struct ib_port_modify *port_modify);
740 struct ib_pd * (*alloc_pd)(struct ib_device *device); 804 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
805 struct ib_udata *udata);
806 int (*dealloc_ucontext)(struct ib_ucontext *context);
807 int (*mmap)(struct ib_ucontext *context,
808 struct vm_area_struct *vma);
809 struct ib_pd * (*alloc_pd)(struct ib_device *device,
810 struct ib_ucontext *context,
811 struct ib_udata *udata);
741 int (*dealloc_pd)(struct ib_pd *pd); 812 int (*dealloc_pd)(struct ib_pd *pd);
742 struct ib_ah * (*create_ah)(struct ib_pd *pd, 813 struct ib_ah * (*create_ah)(struct ib_pd *pd,
743 struct ib_ah_attr *ah_attr); 814 struct ib_ah_attr *ah_attr);
@@ -747,7 +818,8 @@ struct ib_device {
747 struct ib_ah_attr *ah_attr); 818 struct ib_ah_attr *ah_attr);
748 int (*destroy_ah)(struct ib_ah *ah); 819 int (*destroy_ah)(struct ib_ah *ah);
749 struct ib_qp * (*create_qp)(struct ib_pd *pd, 820 struct ib_qp * (*create_qp)(struct ib_pd *pd,
750 struct ib_qp_init_attr *qp_init_attr); 821 struct ib_qp_init_attr *qp_init_attr,
822 struct ib_udata *udata);
751 int (*modify_qp)(struct ib_qp *qp, 823 int (*modify_qp)(struct ib_qp *qp,
752 struct ib_qp_attr *qp_attr, 824 struct ib_qp_attr *qp_attr,
753 int qp_attr_mask); 825 int qp_attr_mask);
@@ -762,8 +834,9 @@ struct ib_device {
762 int (*post_recv)(struct ib_qp *qp, 834 int (*post_recv)(struct ib_qp *qp,
763 struct ib_recv_wr *recv_wr, 835 struct ib_recv_wr *recv_wr,
764 struct ib_recv_wr **bad_recv_wr); 836 struct ib_recv_wr **bad_recv_wr);
765 struct ib_cq * (*create_cq)(struct ib_device *device, 837 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
766 int cqe); 838 struct ib_ucontext *context,
839 struct ib_udata *udata);
767 int (*destroy_cq)(struct ib_cq *cq); 840 int (*destroy_cq)(struct ib_cq *cq);
768 int (*resize_cq)(struct ib_cq *cq, int *cqe); 841 int (*resize_cq)(struct ib_cq *cq, int *cqe);
769 int (*poll_cq)(struct ib_cq *cq, int num_entries, 842 int (*poll_cq)(struct ib_cq *cq, int num_entries,
@@ -780,6 +853,10 @@ struct ib_device {
780 int num_phys_buf, 853 int num_phys_buf,
781 int mr_access_flags, 854 int mr_access_flags,
782 u64 *iova_start); 855 u64 *iova_start);
856 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
857 struct ib_umem *region,
858 int mr_access_flags,
859 struct ib_udata *udata);
783 int (*query_mr)(struct ib_mr *mr, 860 int (*query_mr)(struct ib_mr *mr,
784 struct ib_mr_attr *mr_attr); 861 struct ib_mr_attr *mr_attr);
785 int (*dereg_mr)(struct ib_mr *mr); 862 int (*dereg_mr)(struct ib_mr *mr);
@@ -817,6 +894,7 @@ struct ib_device {
817 struct ib_mad *in_mad, 894 struct ib_mad *in_mad,
818 struct ib_mad *out_mad); 895 struct ib_mad *out_mad);
819 896
897 struct module *owner;
820 struct class_device class_dev; 898 struct class_device class_dev;
821 struct kobject ports_parent; 899 struct kobject ports_parent;
822 struct list_head port_list; 900 struct list_head port_list;
@@ -852,6 +930,16 @@ void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
852void ib_set_client_data(struct ib_device *device, struct ib_client *client, 930void ib_set_client_data(struct ib_device *device, struct ib_client *client,
853 void *data); 931 void *data);
854 932
933static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
934{
935 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
936}
937
938static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
939{
940 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
941}
942
855int ib_register_event_handler (struct ib_event_handler *event_handler); 943int ib_register_event_handler (struct ib_event_handler *event_handler);
856int ib_unregister_event_handler(struct ib_event_handler *event_handler); 944int ib_unregister_event_handler(struct ib_event_handler *event_handler);
857void ib_dispatch_event(struct ib_event *event); 945void ib_dispatch_event(struct ib_event *event);
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 556264b43425..374f404e81da 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -21,6 +21,7 @@
21#include <linux/smp_lock.h> 21#include <linux/smp_lock.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/devfs_fs_kernel.h> 23#include <linux/devfs_fs_kernel.h>
24#include <linux/compat.h>
24 25
25struct evdev { 26struct evdev {
26 int exist; 27 int exist;
@@ -145,6 +146,41 @@ static int evdev_open(struct inode * inode, struct file * file)
145 return 0; 146 return 0;
146} 147}
147 148
149#ifdef CONFIG_COMPAT
150struct input_event_compat {
151 struct compat_timeval time;
152 __u16 type;
153 __u16 code;
154 __s32 value;
155};
156
157#ifdef CONFIG_X86_64
158# define COMPAT_TEST test_thread_flag(TIF_IA32)
159#elif defined(CONFIG_IA64)
160# define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current))
161#elif defined(CONFIG_ARCH_S390)
162# define COMPAT_TEST test_thread_flag(TIF_31BIT)
163#else
164# define COMPAT_TEST test_thread_flag(TIF_32BIT)
165#endif
166
167static ssize_t evdev_write_compat(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
168{
169 struct evdev_list *list = file->private_data;
170 struct input_event_compat event;
171 int retval = 0;
172
173 while (retval < count) {
174 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event_compat)))
175 return -EFAULT;
176 input_event(list->evdev->handle.dev, event.type, event.code, event.value);
177 retval += sizeof(struct input_event_compat);
178 }
179
180 return retval;
181}
182#endif
183
148static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) 184static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
149{ 185{
150 struct evdev_list *list = file->private_data; 186 struct evdev_list *list = file->private_data;
@@ -153,6 +189,11 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_
153 189
154 if (!list->evdev->exist) return -ENODEV; 190 if (!list->evdev->exist) return -ENODEV;
155 191
192#ifdef CONFIG_COMPAT
193 if (COMPAT_TEST)
194 return evdev_write_compat(file, buffer, count, ppos);
195#endif
196
156 while (retval < count) { 197 while (retval < count) {
157 198
158 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event))) 199 if (copy_from_user(&event, buffer + retval, sizeof(struct input_event)))
@@ -164,11 +205,56 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_
164 return retval; 205 return retval;
165} 206}
166 207
208#ifdef CONFIG_COMPAT
209static ssize_t evdev_read_compat(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
210{
211 struct evdev_list *list = file->private_data;
212 int retval;
213
214 if (count < sizeof(struct input_event_compat))
215 return -EINVAL;
216
217 if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
218 return -EAGAIN;
219
220 retval = wait_event_interruptible(list->evdev->wait,
221 list->head != list->tail || (!list->evdev->exist));
222
223 if (retval)
224 return retval;
225
226 if (!list->evdev->exist)
227 return -ENODEV;
228
229 while (list->head != list->tail && retval + sizeof(struct input_event_compat) <= count) {
230 struct input_event *event = (struct input_event *) list->buffer + list->tail;
231 struct input_event_compat event_compat;
232 event_compat.time.tv_sec = event->time.tv_sec;
233 event_compat.time.tv_usec = event->time.tv_usec;
234 event_compat.type = event->type;
235 event_compat.code = event->code;
236 event_compat.value = event->value;
237
238 if (copy_to_user(buffer + retval, &event_compat,
239 sizeof(struct input_event_compat))) return -EFAULT;
240 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
241 retval += sizeof(struct input_event_compat);
242 }
243
244 return retval;
245}
246#endif
247
167static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) 248static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
168{ 249{
169 struct evdev_list *list = file->private_data; 250 struct evdev_list *list = file->private_data;
170 int retval; 251 int retval;
171 252
253#ifdef CONFIG_COMPAT
254 if (COMPAT_TEST)
255 return evdev_read_compat(file, buffer, count, ppos);
256#endif
257
172 if (count < sizeof(struct input_event)) 258 if (count < sizeof(struct input_event))
173 return -EINVAL; 259 return -EINVAL;
174 260
@@ -186,7 +272,7 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count
186 272
187 while (list->head != list->tail && retval + sizeof(struct input_event) <= count) { 273 while (list->head != list->tail && retval + sizeof(struct input_event) <= count) {
188 if (copy_to_user(buffer + retval, list->buffer + list->tail, 274 if (copy_to_user(buffer + retval, list->buffer + list->tail,
189 sizeof(struct input_event))) return -EFAULT; 275 sizeof(struct input_event))) return -EFAULT;
190 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); 276 list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
191 retval += sizeof(struct input_event); 277 retval += sizeof(struct input_event);
192 } 278 }
@@ -203,7 +289,7 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait)
203 (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); 289 (list->evdev->exist ? 0 : (POLLHUP | POLLERR));
204} 290}
205 291
206static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 292static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
207{ 293{
208 struct evdev_list *list = file->private_data; 294 struct evdev_list *list = file->private_data;
209 struct evdev *evdev = list->evdev; 295 struct evdev *evdev = list->evdev;
@@ -285,109 +371,267 @@ static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
285 371
286 default: 372 default:
287 373
288 if (_IOC_TYPE(cmd) != 'E' || _IOC_DIR(cmd) != _IOC_READ) 374 if (_IOC_TYPE(cmd) != 'E')
289 return -EINVAL; 375 return -EINVAL;
290 376
291 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) { 377 if (_IOC_DIR(cmd) == _IOC_READ) {
292 378
293 long *bits; 379 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
294 int len; 380
295 381 long *bits;
296 switch (_IOC_NR(cmd) & EV_MAX) { 382 int len;
297 case 0: bits = dev->evbit; len = EV_MAX; break; 383
298 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 384 switch (_IOC_NR(cmd) & EV_MAX) {
299 case EV_REL: bits = dev->relbit; len = REL_MAX; break; 385 case 0: bits = dev->evbit; len = EV_MAX; break;
300 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; 386 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
301 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; 387 case EV_REL: bits = dev->relbit; len = REL_MAX; break;
302 case EV_LED: bits = dev->ledbit; len = LED_MAX; break; 388 case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
303 case EV_SND: bits = dev->sndbit; len = SND_MAX; break; 389 case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
304 case EV_FF: bits = dev->ffbit; len = FF_MAX; break; 390 case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
305 default: return -EINVAL; 391 case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
392 case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
393 default: return -EINVAL;
394 }
395 len = NBITS(len) * sizeof(long);
396 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
397 return copy_to_user(p, bits, len) ? -EFAULT : len;
306 } 398 }
307 len = NBITS(len) * sizeof(long);
308 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
309 return copy_to_user(p, bits, len) ? -EFAULT : len;
310 }
311 399
312 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) { 400 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) {
313 int len; 401 int len;
314 len = NBITS(KEY_MAX) * sizeof(long); 402 len = NBITS(KEY_MAX) * sizeof(long);
315 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 403 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
316 return copy_to_user(p, dev->key, len) ? -EFAULT : len; 404 return copy_to_user(p, dev->key, len) ? -EFAULT : len;
317 } 405 }
318 406
319 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) { 407 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) {
320 int len; 408 int len;
321 len = NBITS(LED_MAX) * sizeof(long); 409 len = NBITS(LED_MAX) * sizeof(long);
322 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 410 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
323 return copy_to_user(p, dev->led, len) ? -EFAULT : len; 411 return copy_to_user(p, dev->led, len) ? -EFAULT : len;
324 } 412 }
325 413
326 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) { 414 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) {
327 int len; 415 int len;
328 len = NBITS(SND_MAX) * sizeof(long); 416 len = NBITS(SND_MAX) * sizeof(long);
329 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 417 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
330 return copy_to_user(p, dev->snd, len) ? -EFAULT : len; 418 return copy_to_user(p, dev->snd, len) ? -EFAULT : len;
331 } 419 }
332 420
333 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { 421 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) {
334 int len; 422 int len;
335 if (!dev->name) return -ENOENT; 423 if (!dev->name) return -ENOENT;
336 len = strlen(dev->name) + 1; 424 len = strlen(dev->name) + 1;
337 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 425 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
338 return copy_to_user(p, dev->name, len) ? -EFAULT : len; 426 return copy_to_user(p, dev->name, len) ? -EFAULT : len;
339 } 427 }
428
429 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
430 int len;
431 if (!dev->phys) return -ENOENT;
432 len = strlen(dev->phys) + 1;
433 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
434 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
435 }
436
437 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) {
438 int len;
439 if (!dev->uniq) return -ENOENT;
440 len = strlen(dev->uniq) + 1;
441 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
442 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len;
443 }
444
445 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
446
447 int t = _IOC_NR(cmd) & ABS_MAX;
448
449 abs.value = dev->abs[t];
450 abs.minimum = dev->absmin[t];
451 abs.maximum = dev->absmax[t];
452 abs.fuzz = dev->absfuzz[t];
453 abs.flat = dev->absflat[t];
454
455 if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
456 return -EFAULT;
457
458 return 0;
459 }
340 460
341 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
342 int len;
343 if (!dev->phys) return -ENOENT;
344 len = strlen(dev->phys) + 1;
345 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
346 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
347 } 461 }
348 462
349 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) { 463 if (_IOC_DIR(cmd) == _IOC_WRITE) {
350 int len; 464
351 if (!dev->uniq) return -ENOENT; 465 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
352 len = strlen(dev->uniq) + 1; 466
353 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); 467 int t = _IOC_NR(cmd) & ABS_MAX;
354 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len; 468
469 if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
470 return -EFAULT;
471
472 dev->abs[t] = abs.value;
473 dev->absmin[t] = abs.minimum;
474 dev->absmax[t] = abs.maximum;
475 dev->absfuzz[t] = abs.fuzz;
476 dev->absflat[t] = abs.flat;
477
478 return 0;
479 }
355 } 480 }
481 }
482 return -EINVAL;
483}
356 484
357 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 485#ifdef CONFIG_COMPAT
486
487#define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8)
488#define NBITS_COMPAT(x) ((((x)-1)/BITS_PER_LONG_COMPAT)+1)
489#define OFF_COMPAT(x) ((x)%BITS_PER_LONG_COMPAT)
490#define BIT_COMPAT(x) (1UL<<OFF_COMPAT(x))
491#define LONG_COMPAT(x) ((x)/BITS_PER_LONG_COMPAT)
492#define test_bit_compat(bit, array) ((array[LONG_COMPAT(bit)] >> OFF_COMPAT(bit)) & 1)
493
494#ifdef __BIG_ENDIAN
495#define bit_to_user(bit, max) \
496do { \
497 int i; \
498 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \
499 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \
500 for (i = 0; i < len / sizeof(compat_long_t); i++) \
501 if (copy_to_user((compat_long_t*) p + i, \
502 (compat_long_t*) (bit) + i + 1 - ((i % 2) << 1), \
503 sizeof(compat_long_t))) \
504 return -EFAULT; \
505 return len; \
506} while (0)
507#else
508#define bit_to_user(bit, max) \
509do { \
510 int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \
511 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \
512 return copy_to_user(p, (bit), len) ? -EFAULT : len; \
513} while (0)
514#endif
515
516static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
517{
518 struct evdev_list *list = file->private_data;
519 struct evdev *evdev = list->evdev;
520 struct input_dev *dev = evdev->handle.dev;
521 struct input_absinfo abs;
522 void __user *p = compat_ptr(arg);
358 523
359 int t = _IOC_NR(cmd) & ABS_MAX; 524 if (!evdev->exist) return -ENODEV;
360 525
361 abs.value = dev->abs[t]; 526 switch (cmd) {
362 abs.minimum = dev->absmin[t];
363 abs.maximum = dev->absmax[t];
364 abs.fuzz = dev->absfuzz[t];
365 abs.flat = dev->absflat[t];
366 527
367 if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) 528 case EVIOCGVERSION:
368 return -EFAULT; 529 case EVIOCGID:
530 case EVIOCGKEYCODE:
531 case EVIOCSKEYCODE:
532 case EVIOCSFF:
533 case EVIOCRMFF:
534 case EVIOCGEFFECTS:
535 case EVIOCGRAB:
536 return evdev_ioctl(file, cmd, (unsigned long) p);
369 537
370 return 0; 538 default:
539
540 if (_IOC_TYPE(cmd) != 'E')
541 return -EINVAL;
542
543 if (_IOC_DIR(cmd) == _IOC_READ) {
544
545 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
546 long *bits;
547 int max;
548
549 switch (_IOC_NR(cmd) & EV_MAX) {
550 case 0: bits = dev->evbit; max = EV_MAX; break;
551 case EV_KEY: bits = dev->keybit; max = KEY_MAX; break;
552 case EV_REL: bits = dev->relbit; max = REL_MAX; break;
553 case EV_ABS: bits = dev->absbit; max = ABS_MAX; break;
554 case EV_MSC: bits = dev->mscbit; max = MSC_MAX; break;
555 case EV_LED: bits = dev->ledbit; max = LED_MAX; break;
556 case EV_SND: bits = dev->sndbit; max = SND_MAX; break;
557 case EV_FF: bits = dev->ffbit; max = FF_MAX; break;
558 default: return -EINVAL;
559 }
560 bit_to_user(bits, max);
561 }
562
563 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0)))
564 bit_to_user(dev->key, KEY_MAX);
565
566 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0)))
567 bit_to_user(dev->led, LED_MAX);
568
569 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0)))
570 bit_to_user(dev->snd, SND_MAX);
571
572 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) {
573 int len;
574 if (!dev->name) return -ENOENT;
575 len = strlen(dev->name) + 1;
576 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
577 return copy_to_user(p, dev->name, len) ? -EFAULT : len;
578 }
579
580 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) {
581 int len;
582 if (!dev->phys) return -ENOENT;
583 len = strlen(dev->phys) + 1;
584 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
585 return copy_to_user(p, dev->phys, len) ? -EFAULT : len;
586 }
587
588 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) {
589 int len;
590 if (!dev->uniq) return -ENOENT;
591 len = strlen(dev->uniq) + 1;
592 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
593 return copy_to_user(p, dev->uniq, len) ? -EFAULT : len;
594 }
595
596 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
597
598 int t = _IOC_NR(cmd) & ABS_MAX;
599
600 abs.value = dev->abs[t];
601 abs.minimum = dev->absmin[t];
602 abs.maximum = dev->absmax[t];
603 abs.fuzz = dev->absfuzz[t];
604 abs.flat = dev->absflat[t];
605
606 if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
607 return -EFAULT;
608
609 return 0;
610 }
371 } 611 }
372 612
373 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 613 if (_IOC_DIR(cmd) == _IOC_WRITE) {
374 614
375 int t = _IOC_NR(cmd) & ABS_MAX; 615 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
376 616
377 if (copy_from_user(&abs, p, sizeof(struct input_absinfo))) 617 int t = _IOC_NR(cmd) & ABS_MAX;
378 return -EFAULT;
379 618
380 dev->abs[t] = abs.value; 619 if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
381 dev->absmin[t] = abs.minimum; 620 return -EFAULT;
382 dev->absmax[t] = abs.maximum;
383 dev->absfuzz[t] = abs.fuzz;
384 dev->absflat[t] = abs.flat;
385 621
386 return 0; 622 dev->abs[t] = abs.value;
623 dev->absmin[t] = abs.minimum;
624 dev->absmax[t] = abs.maximum;
625 dev->absfuzz[t] = abs.fuzz;
626 dev->absflat[t] = abs.flat;
627
628 return 0;
629 }
387 } 630 }
388 } 631 }
389 return -EINVAL; 632 return -EINVAL;
390} 633}
634#endif
391 635
392static struct file_operations evdev_fops = { 636static struct file_operations evdev_fops = {
393 .owner = THIS_MODULE, 637 .owner = THIS_MODULE,
@@ -396,7 +640,10 @@ static struct file_operations evdev_fops = {
396 .poll = evdev_poll, 640 .poll = evdev_poll,
397 .open = evdev_open, 641 .open = evdev_open,
398 .release = evdev_release, 642 .release = evdev_release,
399 .ioctl = evdev_ioctl, 643 .unlocked_ioctl = evdev_ioctl,
644#ifdef CONFIG_COMPAT
645 .compat_ioctl = evdev_ioctl_compat,
646#endif
400 .fasync = evdev_fasync, 647 .fasync = evdev_fasync,
401 .flush = evdev_flush 648 .flush = evdev_flush
402}; 649};
diff --git a/drivers/input/gameport/Kconfig b/drivers/input/gameport/Kconfig
index 1d93f5092904..7524bd7d8b8f 100644
--- a/drivers/input/gameport/Kconfig
+++ b/drivers/input/gameport/Kconfig
@@ -49,22 +49,8 @@ config GAMEPORT_EMU10K1
49 To compile this driver as a module, choose M here: the 49 To compile this driver as a module, choose M here: the
50 module will be called emu10k1-gp. 50 module will be called emu10k1-gp.
51 51
52config GAMEPORT_VORTEX
53 tristate "Aureal Vortex, Vortex 2 gameport support"
54 depends on PCI
55 help
56 Say Y here if you have an Aureal Vortex 1 or 2 card and want
57 to use its gameport.
58
59 To compile this driver as a module, choose M here: the
60 module will be called vortex.
61
62config GAMEPORT_FM801 52config GAMEPORT_FM801
63 tristate "ForteMedia FM801 gameport support" 53 tristate "ForteMedia FM801 gameport support"
64 depends on PCI 54 depends on PCI
65 55
66config GAMEPORT_CS461X
67 tristate "Crystal SoundFusion gameport support"
68 depends on PCI
69
70endif 56endif
diff --git a/drivers/input/gameport/Makefile b/drivers/input/gameport/Makefile
index 5367b4267adf..b6f6097bd8c4 100644
--- a/drivers/input/gameport/Makefile
+++ b/drivers/input/gameport/Makefile
@@ -5,9 +5,7 @@
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_GAMEPORT) += gameport.o 7obj-$(CONFIG_GAMEPORT) += gameport.o
8obj-$(CONFIG_GAMEPORT_CS461X) += cs461x.o
9obj-$(CONFIG_GAMEPORT_EMU10K1) += emu10k1-gp.o 8obj-$(CONFIG_GAMEPORT_EMU10K1) += emu10k1-gp.o
10obj-$(CONFIG_GAMEPORT_FM801) += fm801-gp.o 9obj-$(CONFIG_GAMEPORT_FM801) += fm801-gp.o
11obj-$(CONFIG_GAMEPORT_L4) += lightning.o 10obj-$(CONFIG_GAMEPORT_L4) += lightning.o
12obj-$(CONFIG_GAMEPORT_NS558) += ns558.o 11obj-$(CONFIG_GAMEPORT_NS558) += ns558.o
13obj-$(CONFIG_GAMEPORT_VORTEX) += vortex.o
diff --git a/drivers/input/gameport/cs461x.c b/drivers/input/gameport/cs461x.c
deleted file mode 100644
index d4013ff98623..000000000000
--- a/drivers/input/gameport/cs461x.c
+++ /dev/null
@@ -1,322 +0,0 @@
1/*
2 The all defines and part of code (such as cs461x_*) are
3 contributed from ALSA 0.5.8 sources.
4 See http://www.alsa-project.org/ for sources
5
6 Tested on Linux 686 2.4.0-test9, ALSA 0.5.8a and CS4610
7*/
8
9#include <asm/io.h>
10
11#include <linux/module.h>
12#include <linux/ioport.h>
13#include <linux/config.h>
14#include <linux/init.h>
15#include <linux/gameport.h>
16#include <linux/slab.h>
17#include <linux/pci.h>
18
19MODULE_AUTHOR("Victor Krapivin");
20MODULE_LICENSE("GPL");
21
22/*
23 These options are experimental
24
25#define CS461X_FULL_MAP
26*/
27
28
29#ifndef PCI_VENDOR_ID_CIRRUS
30#define PCI_VENDOR_ID_CIRRUS 0x1013
31#endif
32#ifndef PCI_DEVICE_ID_CIRRUS_4610
33#define PCI_DEVICE_ID_CIRRUS_4610 0x6001
34#endif
35#ifndef PCI_DEVICE_ID_CIRRUS_4612
36#define PCI_DEVICE_ID_CIRRUS_4612 0x6003
37#endif
38#ifndef PCI_DEVICE_ID_CIRRUS_4615
39#define PCI_DEVICE_ID_CIRRUS_4615 0x6004
40#endif
41
42/* Registers */
43
44#define BA0_JSPT 0x00000480
45#define BA0_JSCTL 0x00000484
46#define BA0_JSC1 0x00000488
47#define BA0_JSC2 0x0000048C
48#define BA0_JSIO 0x000004A0
49
50/* Bits for JSPT */
51
52#define JSPT_CAX 0x00000001
53#define JSPT_CAY 0x00000002
54#define JSPT_CBX 0x00000004
55#define JSPT_CBY 0x00000008
56#define JSPT_BA1 0x00000010
57#define JSPT_BA2 0x00000020
58#define JSPT_BB1 0x00000040
59#define JSPT_BB2 0x00000080
60
61/* Bits for JSCTL */
62
63#define JSCTL_SP_MASK 0x00000003
64#define JSCTL_SP_SLOW 0x00000000
65#define JSCTL_SP_MEDIUM_SLOW 0x00000001
66#define JSCTL_SP_MEDIUM_FAST 0x00000002
67#define JSCTL_SP_FAST 0x00000003
68#define JSCTL_ARE 0x00000004
69
70/* Data register pairs masks */
71
72#define JSC1_Y1V_MASK 0x0000FFFF
73#define JSC1_X1V_MASK 0xFFFF0000
74#define JSC1_Y1V_SHIFT 0
75#define JSC1_X1V_SHIFT 16
76#define JSC2_Y2V_MASK 0x0000FFFF
77#define JSC2_X2V_MASK 0xFFFF0000
78#define JSC2_Y2V_SHIFT 0
79#define JSC2_X2V_SHIFT 16
80
81/* JS GPIO */
82
83#define JSIO_DAX 0x00000001
84#define JSIO_DAY 0x00000002
85#define JSIO_DBX 0x00000004
86#define JSIO_DBY 0x00000008
87#define JSIO_AXOE 0x00000010
88#define JSIO_AYOE 0x00000020
89#define JSIO_BXOE 0x00000040
90#define JSIO_BYOE 0x00000080
91
92/*
93 The card initialization code is obfuscated; the module cs461x
94 need to be loaded after ALSA modules initialized and something
95 played on the CS 4610 chip (see sources for details of CS4610
96 initialization code from ALSA)
97*/
98
99/* Card specific definitions */
100
101#define CS461X_BA0_SIZE 0x2000
102#define CS461X_BA1_DATA0_SIZE 0x3000
103#define CS461X_BA1_DATA1_SIZE 0x3800
104#define CS461X_BA1_PRG_SIZE 0x7000
105#define CS461X_BA1_REG_SIZE 0x0100
106
107#define BA1_SP_DMEM0 0x00000000
108#define BA1_SP_DMEM1 0x00010000
109#define BA1_SP_PMEM 0x00020000
110#define BA1_SP_REG 0x00030000
111
112#define BA1_DWORD_SIZE (13 * 1024 + 512)
113#define BA1_MEMORY_COUNT 3
114
115/*
116 Only one CS461x card is still suppoted; the code requires
117 redesign to avoid this limitatuion.
118*/
119
120static unsigned long ba0_addr;
121static unsigned int __iomem *ba0;
122
123#ifdef CS461X_FULL_MAP
124static unsigned long ba1_addr;
125static union ba1_t {
126 struct {
127 unsigned int __iomem *data0;
128 unsigned int __iomem *data1;
129 unsigned int __iomem *pmem;
130 unsigned int __iomem *reg;
131 } name;
132 unsigned int __iomem *idx[4];
133} ba1;
134
135static void cs461x_poke(unsigned long reg, unsigned int val)
136{
137 writel(val, &ba1.idx[(reg >> 16) & 3][(reg >> 2) & 0x3fff]);
138}
139
140static unsigned int cs461x_peek(unsigned long reg)
141{
142 return readl(&ba1.idx[(reg >> 16) & 3][(reg >> 2) & 0x3fff]);
143}
144
145#endif
146
147static void cs461x_pokeBA0(unsigned long reg, unsigned int val)
148{
149 writel(val, &ba0[reg >> 2]);
150}
151
152static unsigned int cs461x_peekBA0(unsigned long reg)
153{
154 return readl(&ba0[reg >> 2]);
155}
156
157static int cs461x_free(struct pci_dev *pdev)
158{
159 struct gameport *port = pci_get_drvdata(pdev);
160
161 if (port)
162 gameport_unregister_port(port);
163
164 if (ba0) iounmap(ba0);
165#ifdef CS461X_FULL_MAP
166 if (ba1.name.data0) iounmap(ba1.name.data0);
167 if (ba1.name.data1) iounmap(ba1.name.data1);
168 if (ba1.name.pmem) iounmap(ba1.name.pmem);
169 if (ba1.name.reg) iounmap(ba1.name.reg);
170#endif
171 return 0;
172}
173
174static void cs461x_gameport_trigger(struct gameport *gameport)
175{
176 cs461x_pokeBA0(BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF);
177}
178
179static unsigned char cs461x_gameport_read(struct gameport *gameport)
180{
181 return cs461x_peekBA0(BA0_JSPT); //inb(gameport->io);
182}
183
184static int cs461x_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
185{
186 unsigned js1, js2, jst;
187
188 js1 = cs461x_peekBA0(BA0_JSC1);
189 js2 = cs461x_peekBA0(BA0_JSC2);
190 jst = cs461x_peekBA0(BA0_JSPT);
191
192 *buttons = (~jst >> 4) & 0x0F;
193
194 axes[0] = ((js1 & JSC1_Y1V_MASK) >> JSC1_Y1V_SHIFT) & 0xFFFF;
195 axes[1] = ((js1 & JSC1_X1V_MASK) >> JSC1_X1V_SHIFT) & 0xFFFF;
196 axes[2] = ((js2 & JSC2_Y2V_MASK) >> JSC2_Y2V_SHIFT) & 0xFFFF;
197 axes[3] = ((js2 & JSC2_X2V_MASK) >> JSC2_X2V_SHIFT) & 0xFFFF;
198
199 for(jst=0;jst<4;++jst)
200 if(axes[jst]==0xFFFF) axes[jst] = -1;
201 return 0;
202}
203
204static int cs461x_gameport_open(struct gameport *gameport, int mode)
205{
206 switch (mode) {
207 case GAMEPORT_MODE_COOKED:
208 case GAMEPORT_MODE_RAW:
209 return 0;
210 default:
211 return -1;
212 }
213 return 0;
214}
215
216static struct pci_device_id cs461x_pci_tbl[] = {
217 { PCI_VENDOR_ID_CIRRUS, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4610 */
218 { PCI_VENDOR_ID_CIRRUS, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4612 */
219 { PCI_VENDOR_ID_CIRRUS, 0x6005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Cirrus CS4615 */
220 { 0, }
221};
222MODULE_DEVICE_TABLE(pci, cs461x_pci_tbl);
223
224static int __devinit cs461x_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
225{
226 int rc;
227 struct gameport* port;
228
229 rc = pci_enable_device(pdev);
230 if (rc) {
231 printk(KERN_ERR "cs461x: Cannot enable PCI gameport (bus %d, devfn %d) error=%d\n",
232 pdev->bus->number, pdev->devfn, rc);
233 return rc;
234 }
235
236 ba0_addr = pci_resource_start(pdev, 0);
237#ifdef CS461X_FULL_MAP
238 ba1_addr = pci_resource_start(pdev, 1);
239#endif
240 if (ba0_addr == 0 || ba0_addr == ~0
241#ifdef CS461X_FULL_MAP
242 || ba1_addr == 0 || ba1_addr == ~0
243#endif
244 ) {
245 printk(KERN_ERR "cs461x: wrong address - ba0 = 0x%lx\n", ba0_addr);
246#ifdef CS461X_FULL_MAP
247 printk(KERN_ERR "cs461x: wrong address - ba1 = 0x%lx\n", ba1_addr);
248#endif
249 cs461x_free(pdev);
250 return -ENOMEM;
251 }
252
253 ba0 = ioremap(ba0_addr, CS461X_BA0_SIZE);
254#ifdef CS461X_FULL_MAP
255 ba1.name.data0 = ioremap(ba1_addr + BA1_SP_DMEM0, CS461X_BA1_DATA0_SIZE);
256 ba1.name.data1 = ioremap(ba1_addr + BA1_SP_DMEM1, CS461X_BA1_DATA1_SIZE);
257 ba1.name.pmem = ioremap(ba1_addr + BA1_SP_PMEM, CS461X_BA1_PRG_SIZE);
258 ba1.name.reg = ioremap(ba1_addr + BA1_SP_REG, CS461X_BA1_REG_SIZE);
259
260 if (ba0 == NULL || ba1.name.data0 == NULL ||
261 ba1.name.data1 == NULL || ba1.name.pmem == NULL ||
262 ba1.name.reg == NULL) {
263 cs461x_free(pdev);
264 return -ENOMEM;
265 }
266#else
267 if (ba0 == NULL) {
268 cs461x_free(pdev);
269 return -ENOMEM;
270 }
271#endif
272
273 if (!(port = gameport_allocate_port())) {
274 printk(KERN_ERR "cs461x: Memory allocation failed\n");
275 cs461x_free(pdev);
276 return -ENOMEM;
277 }
278
279 pci_set_drvdata(pdev, port);
280
281 port->open = cs461x_gameport_open;
282 port->trigger = cs461x_gameport_trigger;
283 port->read = cs461x_gameport_read;
284 port->cooked_read = cs461x_gameport_cooked_read;
285
286 gameport_set_name(port, "CS416x");
287 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
288 port->dev.parent = &pdev->dev;
289
290 cs461x_pokeBA0(BA0_JSIO, 0xFF); // ?
291 cs461x_pokeBA0(BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW);
292
293 gameport_register_port(port);
294
295 return 0;
296}
297
298static void __devexit cs461x_pci_remove(struct pci_dev *pdev)
299{
300 cs461x_free(pdev);
301}
302
303static struct pci_driver cs461x_pci_driver = {
304 .name = "CS461x_gameport",
305 .id_table = cs461x_pci_tbl,
306 .probe = cs461x_pci_probe,
307 .remove = __devexit_p(cs461x_pci_remove),
308};
309
310static int __init cs461x_init(void)
311{
312 return pci_register_driver(&cs461x_pci_driver);
313}
314
315static void __exit cs461x_exit(void)
316{
317 pci_unregister_driver(&cs461x_pci_driver);
318}
319
320module_init(cs461x_init);
321module_exit(cs461x_exit);
322
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index c77a82e46055..ab09cf4093e3 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -17,11 +17,10 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/gameport.h> 18#include <linux/gameport.h>
19#include <linux/wait.h> 19#include <linux/wait.h>
20#include <linux/completion.h>
21#include <linux/sched.h> 20#include <linux/sched.h>
22#include <linux/smp_lock.h>
23#include <linux/slab.h> 21#include <linux/slab.h>
24#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/kthread.h>
25 24
26/*#include <asm/io.h>*/ 25/*#include <asm/io.h>*/
27 26
@@ -61,12 +60,13 @@ static void gameport_disconnect_port(struct gameport *gameport);
61 60
62#if defined(__i386__) 61#if defined(__i386__)
63 62
63#include <asm/i8253.h>
64
64#define DELTA(x,y) ((y)-(x)+((y)<(x)?1193182/HZ:0)) 65#define DELTA(x,y) ((y)-(x)+((y)<(x)?1193182/HZ:0))
65#define GET_TIME(x) do { x = get_time_pit(); } while (0) 66#define GET_TIME(x) do { x = get_time_pit(); } while (0)
66 67
67static unsigned int get_time_pit(void) 68static unsigned int get_time_pit(void)
68{ 69{
69 extern spinlock_t i8253_lock;
70 unsigned long flags; 70 unsigned long flags;
71 unsigned int count; 71 unsigned int count;
72 72
@@ -238,8 +238,7 @@ struct gameport_event {
238static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */ 238static DEFINE_SPINLOCK(gameport_event_lock); /* protects gameport_event_list */
239static LIST_HEAD(gameport_event_list); 239static LIST_HEAD(gameport_event_list);
240static DECLARE_WAIT_QUEUE_HEAD(gameport_wait); 240static DECLARE_WAIT_QUEUE_HEAD(gameport_wait);
241static DECLARE_COMPLETION(gameport_exited); 241static struct task_struct *gameport_task;
242static int gameport_pid;
243 242
244static void gameport_queue_event(void *object, struct module *owner, 243static void gameport_queue_event(void *object, struct module *owner,
245 enum gameport_event_type event_type) 244 enum gameport_event_type event_type)
@@ -250,12 +249,12 @@ static void gameport_queue_event(void *object, struct module *owner,
250 spin_lock_irqsave(&gameport_event_lock, flags); 249 spin_lock_irqsave(&gameport_event_lock, flags);
251 250
252 /* 251 /*
253 * Scan event list for the other events for the same gameport port, 252 * Scan event list for the other events for the same gameport port,
254 * starting with the most recent one. If event is the same we 253 * starting with the most recent one. If event is the same we
255 * do not need add new one. If event is of different type we 254 * do not need add new one. If event is of different type we
256 * need to add this event and should not look further because 255 * need to add this event and should not look further because
257 * we need to preseve sequence of distinct events. 256 * we need to preseve sequence of distinct events.
258 */ 257 */
259 list_for_each_entry_reverse(event, &gameport_event_list, node) { 258 list_for_each_entry_reverse(event, &gameport_event_list, node) {
260 if (event->object == object) { 259 if (event->object == object) {
261 if (event->type == event_type) 260 if (event->type == event_type)
@@ -432,20 +431,15 @@ static struct gameport *gameport_get_pending_child(struct gameport *parent)
432 431
433static int gameport_thread(void *nothing) 432static int gameport_thread(void *nothing)
434{ 433{
435 lock_kernel();
436 daemonize("kgameportd");
437 allow_signal(SIGTERM);
438
439 do { 434 do {
440 gameport_handle_events(); 435 gameport_handle_events();
441 wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list)); 436 wait_event_interruptible(gameport_wait,
437 kthread_should_stop() || !list_empty(&gameport_event_list));
442 try_to_freeze(); 438 try_to_freeze();
443 } while (!signal_pending(current)); 439 } while (!kthread_should_stop());
444 440
445 printk(KERN_DEBUG "gameport: kgameportd exiting\n"); 441 printk(KERN_DEBUG "gameport: kgameportd exiting\n");
446 442 return 0;
447 unlock_kernel();
448 complete_and_exit(&gameport_exited, 0);
449} 443}
450 444
451 445
@@ -773,9 +767,10 @@ void gameport_close(struct gameport *gameport)
773 767
774static int __init gameport_init(void) 768static int __init gameport_init(void)
775{ 769{
776 if (!(gameport_pid = kernel_thread(gameport_thread, NULL, CLONE_KERNEL))) { 770 gameport_task = kthread_run(gameport_thread, NULL, "kgameportd");
771 if (IS_ERR(gameport_task)) {
777 printk(KERN_ERR "gameport: Failed to start kgameportd\n"); 772 printk(KERN_ERR "gameport: Failed to start kgameportd\n");
778 return -1; 773 return PTR_ERR(gameport_task);
779 } 774 }
780 775
781 gameport_bus.dev_attrs = gameport_device_attrs; 776 gameport_bus.dev_attrs = gameport_device_attrs;
@@ -789,8 +784,7 @@ static int __init gameport_init(void)
789static void __exit gameport_exit(void) 784static void __exit gameport_exit(void)
790{ 785{
791 bus_unregister(&gameport_bus); 786 bus_unregister(&gameport_bus);
792 kill_proc(gameport_pid, SIGTERM, 1); 787 kthread_stop(gameport_task);
793 wait_for_completion(&gameport_exited);
794} 788}
795 789
796module_init(gameport_init); 790module_init(gameport_init);
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index 7c5c6318eeb9..1ab5f2dc8a2a 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -258,18 +258,18 @@ static int __init ns558_init(void)
258{ 258{
259 int i = 0; 259 int i = 0;
260 260
261 if (pnp_register_driver(&ns558_pnp_driver) >= 0)
262 pnp_registered = 1;
263
261/* 264/*
262 * Probe ISA ports first so that PnP gets to choose free port addresses 265 * Probe ISA ports after PnP, so that PnP ports that are already
263 * not occupied by the ISA ports. 266 * enabled get detected as PnP. This may be suboptimal in multi-device
267 * configurations, but saves hassle with simple setups.
264 */ 268 */
265 269
266 while (ns558_isa_portlist[i]) 270 while (ns558_isa_portlist[i])
267 ns558_isa_probe(ns558_isa_portlist[i++]); 271 ns558_isa_probe(ns558_isa_portlist[i++]);
268 272
269 if (pnp_register_driver(&ns558_pnp_driver) >= 0)
270 pnp_registered = 1;
271
272
273 return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0; 273 return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0;
274} 274}
275 275
diff --git a/drivers/input/gameport/vortex.c b/drivers/input/gameport/vortex.c
deleted file mode 100644
index 36b0309c8bf6..000000000000
--- a/drivers/input/gameport/vortex.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * $Id: vortex.c,v 1.5 2002/07/01 15:39:30 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 *
6 * Based on the work of:
7 * Raymond Ingles
8 */
9
10/*
11 * Trident 4DWave and Aureal Vortex gameport driver for Linux
12 */
13
14/*
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 */
33
34#include <asm/io.h>
35#include <linux/delay.h>
36#include <linux/errno.h>
37#include <linux/ioport.h>
38#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/pci.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/delay.h>
44#include <linux/gameport.h>
45
46MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
47MODULE_DESCRIPTION("Aureal Vortex and Vortex2 gameport driver");
48MODULE_LICENSE("GPL");
49
50#define VORTEX_GCR 0x0c /* Gameport control register */
51#define VORTEX_LEG 0x08 /* Legacy port location */
52#define VORTEX_AXD 0x10 /* Axes start */
53#define VORTEX_DATA_WAIT 20 /* 20 ms */
54
55struct vortex {
56 struct gameport *gameport;
57 struct pci_dev *dev;
58 unsigned char __iomem *base;
59 unsigned char __iomem *io;
60};
61
62static unsigned char vortex_read(struct gameport *gameport)
63{
64 struct vortex *vortex = gameport->port_data;
65 return readb(vortex->io + VORTEX_LEG);
66}
67
68static void vortex_trigger(struct gameport *gameport)
69{
70 struct vortex *vortex = gameport->port_data;
71 writeb(0xff, vortex->io + VORTEX_LEG);
72}
73
74static int vortex_cooked_read(struct gameport *gameport, int *axes, int *buttons)
75{
76 struct vortex *vortex = gameport->port_data;
77 int i;
78
79 *buttons = (~readb(vortex->base + VORTEX_LEG) >> 4) & 0xf;
80
81 for (i = 0; i < 4; i++) {
82 axes[i] = readw(vortex->io + VORTEX_AXD + i * sizeof(u32));
83 if (axes[i] == 0x1fff) axes[i] = -1;
84 }
85
86 return 0;
87}
88
89static int vortex_open(struct gameport *gameport, int mode)
90{
91 struct vortex *vortex = gameport->port_data;
92
93 switch (mode) {
94 case GAMEPORT_MODE_COOKED:
95 writeb(0x40, vortex->io + VORTEX_GCR);
96 msleep(VORTEX_DATA_WAIT);
97 return 0;
98 case GAMEPORT_MODE_RAW:
99 writeb(0x00, vortex->io + VORTEX_GCR);
100 return 0;
101 default:
102 return -1;
103 }
104
105 return 0;
106}
107
108static int __devinit vortex_probe(struct pci_dev *dev, const struct pci_device_id *id)
109{
110 struct vortex *vortex;
111 struct gameport *port;
112 int i;
113
114 vortex = kcalloc(1, sizeof(struct vortex), GFP_KERNEL);
115 port = gameport_allocate_port();
116 if (!vortex || !port) {
117 printk(KERN_ERR "vortex: Memory allocation failed.\n");
118 kfree(vortex);
119 gameport_free_port(port);
120 return -ENOMEM;
121 }
122
123 for (i = 0; i < 6; i++)
124 if (~pci_resource_flags(dev, i) & IORESOURCE_IO)
125 break;
126
127 pci_enable_device(dev);
128
129 vortex->dev = dev;
130 vortex->gameport = port;
131 vortex->base = ioremap(pci_resource_start(vortex->dev, i),
132 pci_resource_len(vortex->dev, i));
133 vortex->io = vortex->base + id->driver_data;
134
135 pci_set_drvdata(dev, vortex);
136
137 port->port_data = vortex;
138 port->fuzz = 64;
139
140 gameport_set_name(port, "AU88x0");
141 gameport_set_phys(port, "pci%s/gameport0", pci_name(dev));
142 port->dev.parent = &dev->dev;
143 port->read = vortex_read;
144 port->trigger = vortex_trigger;
145 port->cooked_read = vortex_cooked_read;
146 port->open = vortex_open;
147
148 gameport_register_port(port);
149
150 return 0;
151}
152
153static void __devexit vortex_remove(struct pci_dev *dev)
154{
155 struct vortex *vortex = pci_get_drvdata(dev);
156
157 gameport_unregister_port(vortex->gameport);
158 iounmap(vortex->base);
159 kfree(vortex);
160}
161
162static struct pci_device_id vortex_id_table[] = {
163 { 0x12eb, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x11000 },
164 { 0x12eb, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x28800 },
165 { 0 }
166};
167
168static struct pci_driver vortex_driver = {
169 .name = "vortex_gameport",
170 .id_table = vortex_id_table,
171 .probe = vortex_probe,
172 .remove = __devexit_p(vortex_remove),
173};
174
175static int __init vortex_init(void)
176{
177 return pci_register_driver(&vortex_driver);
178}
179
180static void __exit vortex_exit(void)
181{
182 pci_unregister_driver(&vortex_driver);
183}
184
185module_init(vortex_init);
186module_exit(vortex_exit);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 83c77c990dda..7c4b4d37b3e6 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -219,10 +219,24 @@ void input_release_device(struct input_handle *handle)
219 219
220int input_open_device(struct input_handle *handle) 220int input_open_device(struct input_handle *handle)
221{ 221{
222 struct input_dev *dev = handle->dev;
223 int err;
224
225 err = down_interruptible(&dev->sem);
226 if (err)
227 return err;
228
222 handle->open++; 229 handle->open++;
223 if (handle->dev->open) 230
224 return handle->dev->open(handle->dev); 231 if (!dev->users++ && dev->open)
225 return 0; 232 err = dev->open(dev);
233
234 if (err)
235 handle->open--;
236
237 up(&dev->sem);
238
239 return err;
226} 240}
227 241
228int input_flush_device(struct input_handle* handle, struct file* file) 242int input_flush_device(struct input_handle* handle, struct file* file)
@@ -235,10 +249,17 @@ int input_flush_device(struct input_handle* handle, struct file* file)
235 249
236void input_close_device(struct input_handle *handle) 250void input_close_device(struct input_handle *handle)
237{ 251{
252 struct input_dev *dev = handle->dev;
253
238 input_release_device(handle); 254 input_release_device(handle);
239 if (handle->dev->close) 255
240 handle->dev->close(handle->dev); 256 down(&dev->sem);
257
258 if (!--dev->users && dev->close)
259 dev->close(dev);
241 handle->open--; 260 handle->open--;
261
262 up(&dev->sem);
242} 263}
243 264
244static void input_link_handle(struct input_handle *handle) 265static void input_link_handle(struct input_handle *handle)
@@ -415,6 +436,8 @@ void input_register_device(struct input_dev *dev)
415 436
416 set_bit(EV_SYN, dev->evbit); 437 set_bit(EV_SYN, dev->evbit);
417 438
439 init_MUTEX(&dev->sem);
440
418 /* 441 /*
419 * If delay and period are pre-set by the driver, then autorepeating 442 * If delay and period are pre-set by the driver, then autorepeating
420 * is handled by the driver itself and we don't do it in input.c. 443 * is handled by the driver itself and we don't do it in input.c.
@@ -674,6 +697,8 @@ static int input_handlers_read(char *buf, char **start, off_t pos, int count, in
674 return (count > cnt) ? cnt : count; 697 return (count > cnt) ? cnt : count;
675} 698}
676 699
700static struct file_operations input_fileops;
701
677static int __init input_proc_init(void) 702static int __init input_proc_init(void)
678{ 703{
679 struct proc_dir_entry *entry; 704 struct proc_dir_entry *entry;
@@ -688,6 +713,8 @@ static int __init input_proc_init(void)
688 return -ENOMEM; 713 return -ENOMEM;
689 } 714 }
690 entry->owner = THIS_MODULE; 715 entry->owner = THIS_MODULE;
716 input_fileops = *entry->proc_fops;
717 entry->proc_fops = &input_fileops;
691 entry->proc_fops->poll = input_devices_poll; 718 entry->proc_fops->poll = input_devices_poll;
692 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL); 719 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
693 if (entry == NULL) { 720 if (entry == NULL) {
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 39775fc380c7..ff8e1bbd0e13 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -285,48 +285,33 @@ static unsigned int joydev_poll(struct file *file, poll_table *wait)
285 (POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR)); 285 (POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR));
286} 286}
287 287
288static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 288static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp)
289{ 289{
290 struct joydev_list *list = file->private_data;
291 struct joydev *joydev = list->joydev;
292 struct input_dev *dev = joydev->handle.dev; 290 struct input_dev *dev = joydev->handle.dev;
293 void __user *argp = (void __user *)arg;
294 int i, j; 291 int i, j;
295 292
296 if (!joydev->exist) return -ENODEV;
297
298 switch (cmd) { 293 switch (cmd) {
299 294
300 case JS_SET_CAL: 295 case JS_SET_CAL:
301 return copy_from_user(&joydev->glue.JS_CORR, argp, 296 return copy_from_user(&joydev->glue.JS_CORR, argp,
302 sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0; 297 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
303 case JS_GET_CAL: 298 case JS_GET_CAL:
304 return copy_to_user(argp, &joydev->glue.JS_CORR, 299 return copy_to_user(argp, &joydev->glue.JS_CORR,
305 sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0; 300 sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
306 case JS_SET_TIMEOUT: 301 case JS_SET_TIMEOUT:
307 return get_user(joydev->glue.JS_TIMEOUT, (int __user *) arg); 302 return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
308 case JS_GET_TIMEOUT: 303 case JS_GET_TIMEOUT:
309 return put_user(joydev->glue.JS_TIMEOUT, (int __user *) arg); 304 return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
310 case JS_SET_TIMELIMIT:
311 return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
312 case JS_GET_TIMELIMIT:
313 return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
314 case JS_SET_ALL:
315 return copy_from_user(&joydev->glue, argp,
316 sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
317 case JS_GET_ALL:
318 return copy_to_user(argp, &joydev->glue,
319 sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
320 305
321 case JSIOCGVERSION: 306 case JSIOCGVERSION:
322 return put_user(JS_VERSION, (__u32 __user *) arg); 307 return put_user(JS_VERSION, (__u32 __user *) argp);
323 case JSIOCGAXES: 308 case JSIOCGAXES:
324 return put_user(joydev->nabs, (__u8 __user *) arg); 309 return put_user(joydev->nabs, (__u8 __user *) argp);
325 case JSIOCGBUTTONS: 310 case JSIOCGBUTTONS:
326 return put_user(joydev->nkey, (__u8 __user *) arg); 311 return put_user(joydev->nkey, (__u8 __user *) argp);
327 case JSIOCSCORR: 312 case JSIOCSCORR:
328 if (copy_from_user(joydev->corr, argp, 313 if (copy_from_user(joydev->corr, argp,
329 sizeof(struct js_corr) * joydev->nabs)) 314 sizeof(joydev->corr[0]) * joydev->nabs))
330 return -EFAULT; 315 return -EFAULT;
331 for (i = 0; i < joydev->nabs; i++) { 316 for (i = 0; i < joydev->nabs; i++) {
332 j = joydev->abspam[i]; 317 j = joydev->abspam[i];
@@ -335,7 +320,7 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
335 return 0; 320 return 0;
336 case JSIOCGCORR: 321 case JSIOCGCORR:
337 return copy_to_user(argp, joydev->corr, 322 return copy_to_user(argp, joydev->corr,
338 sizeof(struct js_corr) * joydev->nabs) ? -EFAULT : 0; 323 sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0;
339 case JSIOCSAXMAP: 324 case JSIOCSAXMAP:
340 if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1))) 325 if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1)))
341 return -EFAULT; 326 return -EFAULT;
@@ -371,6 +356,84 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
371 return -EINVAL; 356 return -EINVAL;
372} 357}
373 358
359#ifdef CONFIG_COMPAT
360static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
361{
362 struct joydev_list *list = file->private_data;
363 struct joydev *joydev = list->joydev;
364 void __user *argp = (void __user *)arg;
365 s32 tmp32;
366 struct JS_DATA_SAVE_TYPE_32 ds32;
367 int err;
368
369 if (!joydev->exist) return -ENODEV;
370 switch(cmd) {
371 case JS_SET_TIMELIMIT:
372 err = get_user(tmp32, (s32 __user *) arg);
373 if (err == 0)
374 joydev->glue.JS_TIMELIMIT = tmp32;
375 break;
376 case JS_GET_TIMELIMIT:
377 tmp32 = joydev->glue.JS_TIMELIMIT;
378 err = put_user(tmp32, (s32 __user *) arg);
379 break;
380
381 case JS_SET_ALL:
382 err = copy_from_user(&ds32, argp,
383 sizeof(ds32)) ? -EFAULT : 0;
384 if (err == 0) {
385 joydev->glue.JS_TIMEOUT = ds32.JS_TIMEOUT;
386 joydev->glue.BUSY = ds32.BUSY;
387 joydev->glue.JS_EXPIRETIME = ds32.JS_EXPIRETIME;
388 joydev->glue.JS_TIMELIMIT = ds32.JS_TIMELIMIT;
389 joydev->glue.JS_SAVE = ds32.JS_SAVE;
390 joydev->glue.JS_CORR = ds32.JS_CORR;
391 }
392 break;
393
394 case JS_GET_ALL:
395 ds32.JS_TIMEOUT = joydev->glue.JS_TIMEOUT;
396 ds32.BUSY = joydev->glue.BUSY;
397 ds32.JS_EXPIRETIME = joydev->glue.JS_EXPIRETIME;
398 ds32.JS_TIMELIMIT = joydev->glue.JS_TIMELIMIT;
399 ds32.JS_SAVE = joydev->glue.JS_SAVE;
400 ds32.JS_CORR = joydev->glue.JS_CORR;
401
402 err = copy_to_user(argp, &ds32,
403 sizeof(ds32)) ? -EFAULT : 0;
404 break;
405
406 default:
407 err = joydev_ioctl_common(joydev, cmd, argp);
408 }
409 return err;
410}
411#endif /* CONFIG_COMPAT */
412
413static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
414{
415 struct joydev_list *list = file->private_data;
416 struct joydev *joydev = list->joydev;
417 void __user *argp = (void __user *)arg;
418
419 if (!joydev->exist) return -ENODEV;
420
421 switch(cmd) {
422 case JS_SET_TIMELIMIT:
423 return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
424 case JS_GET_TIMELIMIT:
425 return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
426 case JS_SET_ALL:
427 return copy_from_user(&joydev->glue, argp,
428 sizeof(joydev->glue)) ? -EFAULT : 0;
429 case JS_GET_ALL:
430 return copy_to_user(argp, &joydev->glue,
431 sizeof(joydev->glue)) ? -EFAULT : 0;
432 default:
433 return joydev_ioctl_common(joydev, cmd, argp);
434 }
435}
436
374static struct file_operations joydev_fops = { 437static struct file_operations joydev_fops = {
375 .owner = THIS_MODULE, 438 .owner = THIS_MODULE,
376 .read = joydev_read, 439 .read = joydev_read,
@@ -379,6 +442,9 @@ static struct file_operations joydev_fops = {
379 .open = joydev_open, 442 .open = joydev_open,
380 .release = joydev_release, 443 .release = joydev_release,
381 .ioctl = joydev_ioctl, 444 .ioctl = joydev_ioctl,
445#ifdef CONFIG_COMPAT
446 .compat_ioctl = joydev_compat_ioctl,
447#endif
382 .fasync = joydev_fasync, 448 .fasync = joydev_fasync,
383}; 449};
384 450
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index ad39fe4bf35f..bf34f75b9467 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -185,7 +185,7 @@ static void a3d_poll(struct gameport *gameport)
185 a3d->reads++; 185 a3d->reads++;
186 if (a3d_read_packet(a3d->gameport, a3d->length, data) != a3d->length || 186 if (a3d_read_packet(a3d->gameport, a3d->length, data) != a3d->length ||
187 data[0] != a3d->mode || a3d_csum(data, a3d->length)) 187 data[0] != a3d->mode || a3d_csum(data, a3d->length))
188 a3d->bads++; 188 a3d->bads++;
189 else 189 else
190 a3d_read(a3d, data); 190 a3d_read(a3d, data);
191} 191}
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 83f6dafc1716..265962956c63 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -82,7 +82,7 @@ static char adi_cm2_abs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
82static char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y }; 82static char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
83 83
84static short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT }; 84static short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
85static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA }; 85static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
86static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 }; 86static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
87static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; 87static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
88 88
@@ -183,7 +183,7 @@ static void adi_move_bits(struct adi_port *port, int length)
183 int i; 183 int i;
184 struct adi *adi = port->adi; 184 struct adi *adi = port->adi;
185 185
186 adi[0].idx = adi[1].idx = 0; 186 adi[0].idx = adi[1].idx = 0;
187 187
188 if (adi[0].ret <= 0 || adi[1].ret <= 0) return; 188 if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
189 if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return; 189 if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return;
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index cf36ca9b92f3..e996183c5b06 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -51,7 +51,8 @@ MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is
51 51
52__obsolete_setup("amijoy="); 52__obsolete_setup("amijoy=");
53 53
54static int amijoy_used[2] = { 0, 0 }; 54static int amijoy_used;
55static DECLARE_MUTEX(amijoy_sem);
55static struct input_dev amijoy_dev[2]; 56static struct input_dev amijoy_dev[2];
56static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; 57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
57 58
@@ -84,26 +85,30 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
84 85
85static int amijoy_open(struct input_dev *dev) 86static int amijoy_open(struct input_dev *dev)
86{ 87{
87 int *used = dev->private; 88 int err;
88 89
89 if ((*used)++) 90 err = down_interruptible(&amijoy_sem);
90 return 0; 91 if (err)
92 return err;
91 93
92 if (request_irq(IRQ_AMIGA_VERTB, amijoy_interrupt, 0, "amijoy", amijoy_interrupt)) { 94 if (!amijoy_used && request_irq(IRQ_AMIGA_VERTB, amijoy_interrupt, 0, "amijoy", amijoy_interrupt)) {
93 (*used)--;
94 printk(KERN_ERR "amijoy.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB); 95 printk(KERN_ERR "amijoy.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
95 return -EBUSY; 96 err = -EBUSY;
97 goto out;
96 } 98 }
97 99
98 return 0; 100 amijoy_used++;
101out:
102 up(&amijoy_sem);
103 return err;
99} 104}
100 105
101static void amijoy_close(struct input_dev *dev) 106static void amijoy_close(struct input_dev *dev)
102{ 107{
103 int *used = dev->private; 108 down(&amijoy_sem);
104 109 if (!--amijoy_used)
105 if (!--(*used))
106 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt); 110 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt);
111 up(&amijoy_sem);
107} 112}
108 113
109static int __init amijoy_init(void) 114static int __init amijoy_init(void)
@@ -138,8 +143,6 @@ static int __init amijoy_init(void)
138 amijoy_dev[i].id.product = 0x0003; 143 amijoy_dev[i].id.product = 0x0003;
139 amijoy_dev[i].id.version = 0x0100; 144 amijoy_dev[i].id.version = 0x0100;
140 145
141 amijoy_dev[i].private = amijoy_used + i;
142
143 input_register_device(amijoy_dev + i); 146 input_register_device(amijoy_dev + i);
144 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i); 147 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i);
145 } 148 }
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 504b7d550567..c3a5739030c3 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -140,12 +140,14 @@ struct analog_port {
140 */ 140 */
141 141
142#ifdef __i386__ 142#ifdef __i386__
143
144#include <asm/i8253.h>
145
143#define GET_TIME(x) do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0) 146#define GET_TIME(x) do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0)
144#define DELTA(x,y) (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? CLOCK_TICK_RATE / HZ : 0))) 147#define DELTA(x,y) (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? CLOCK_TICK_RATE / HZ : 0)))
145#define TIME_NAME (cpu_has_tsc?"TSC":"PIT") 148#define TIME_NAME (cpu_has_tsc?"TSC":"PIT")
146static unsigned int get_time_pit(void) 149static unsigned int get_time_pit(void)
147{ 150{
148 extern spinlock_t i8253_lock;
149 unsigned long flags; 151 unsigned long flags;
150 unsigned int count; 152 unsigned int count;
151 153
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index cfdd3acf06a1..fbd3eed07f90 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -87,7 +87,7 @@ __obsolete_setup("db9_3=");
87#define DB9_NORMAL 0x0a 87#define DB9_NORMAL 0x0a
88#define DB9_NOSELECT 0x08 88#define DB9_NOSELECT 0x08
89 89
90#define DB9_MAX_DEVICES 2 90#define DB9_MAX_DEVICES 2
91 91
92#define DB9_GENESIS6_DELAY 14 92#define DB9_GENESIS6_DELAY 14
93#define DB9_REFRESH_TIME HZ/100 93#define DB9_REFRESH_TIME HZ/100
@@ -98,6 +98,7 @@ struct db9 {
98 struct pardevice *pd; 98 struct pardevice *pd;
99 int mode; 99 int mode;
100 int used; 100 int used;
101 struct semaphore sem;
101 char phys[2][32]; 102 char phys[2][32];
102}; 103};
103 104
@@ -503,6 +504,11 @@ static int db9_open(struct input_dev *dev)
503{ 504{
504 struct db9 *db9 = dev->private; 505 struct db9 *db9 = dev->private;
505 struct parport *port = db9->pd->port; 506 struct parport *port = db9->pd->port;
507 int err;
508
509 err = down_interruptible(&db9->sem);
510 if (err)
511 return err;
506 512
507 if (!db9->used++) { 513 if (!db9->used++) {
508 parport_claim(db9->pd); 514 parport_claim(db9->pd);
@@ -514,6 +520,7 @@ static int db9_open(struct input_dev *dev)
514 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); 520 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME);
515 } 521 }
516 522
523 up(&db9->sem);
517 return 0; 524 return 0;
518} 525}
519 526
@@ -522,12 +529,14 @@ static void db9_close(struct input_dev *dev)
522 struct db9 *db9 = dev->private; 529 struct db9 *db9 = dev->private;
523 struct parport *port = db9->pd->port; 530 struct parport *port = db9->pd->port;
524 531
532 down(&db9->sem);
525 if (!--db9->used) { 533 if (!--db9->used) {
526 del_timer(&db9->timer); 534 del_timer_sync(&db9->timer);
527 parport_write_control(port, 0x00); 535 parport_write_control(port, 0x00);
528 parport_data_forward(port); 536 parport_data_forward(port);
529 parport_release(db9->pd); 537 parport_release(db9->pd);
530 } 538 }
539 up(&db9->sem);
531} 540}
532 541
533static struct db9 __init *db9_probe(int *config, int nargs) 542static struct db9 __init *db9_probe(int *config, int nargs)
@@ -563,12 +572,12 @@ static struct db9 __init *db9_probe(int *config, int nargs)
563 } 572 }
564 } 573 }
565 574
566 if (!(db9 = kmalloc(sizeof(struct db9), GFP_KERNEL))) { 575 if (!(db9 = kcalloc(1, sizeof(struct db9), GFP_KERNEL))) {
567 parport_put_port(pp); 576 parport_put_port(pp);
568 return NULL; 577 return NULL;
569 } 578 }
570 memset(db9, 0, sizeof(struct db9));
571 579
580 init_MUTEX(&db9->sem);
572 db9->mode = config[1]; 581 db9->mode = config[1];
573 init_timer(&db9->timer); 582 init_timer(&db9->timer);
574 db9->timer.data = (long) db9; 583 db9->timer.data = (long) db9;
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 8732f52bdd08..95bbdd302aad 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux 2 * NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux
3 * 3 *
4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz> 4 * Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org> 5 * Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org>
6 * 6 *
7 * Based on the work of: 7 * Based on the work of:
8 * Andree Borrmann John Dahlstrom 8 * Andree Borrmann John Dahlstrom
9 * David Kuder Nathan Hand 9 * David Kuder Nathan Hand
10 */ 10 */
11 11
12/* 12/*
@@ -81,6 +81,7 @@ struct gc {
81 struct timer_list timer; 81 struct timer_list timer;
82 unsigned char pads[GC_MAX + 1]; 82 unsigned char pads[GC_MAX + 1];
83 int used; 83 int used;
84 struct semaphore sem;
84 char phys[5][32]; 85 char phys[5][32];
85}; 86};
86 87
@@ -433,7 +434,7 @@ static void gc_timer(unsigned long private)
433 gc_psx_read_packet(gc, data_psx, data); 434 gc_psx_read_packet(gc, data_psx, data);
434 435
435 for (i = 0; i < 5; i++) { 436 for (i = 0; i < 5; i++) {
436 switch (data[i]) { 437 switch (data[i]) {
437 438
438 case GC_PSX_RUMBLE: 439 case GC_PSX_RUMBLE:
439 440
@@ -503,22 +504,33 @@ static void gc_timer(unsigned long private)
503static int gc_open(struct input_dev *dev) 504static int gc_open(struct input_dev *dev)
504{ 505{
505 struct gc *gc = dev->private; 506 struct gc *gc = dev->private;
507 int err;
508
509 err = down_interruptible(&gc->sem);
510 if (err)
511 return err;
512
506 if (!gc->used++) { 513 if (!gc->used++) {
507 parport_claim(gc->pd); 514 parport_claim(gc->pd);
508 parport_write_control(gc->pd->port, 0x04); 515 parport_write_control(gc->pd->port, 0x04);
509 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 516 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
510 } 517 }
518
519 up(&gc->sem);
511 return 0; 520 return 0;
512} 521}
513 522
514static void gc_close(struct input_dev *dev) 523static void gc_close(struct input_dev *dev)
515{ 524{
516 struct gc *gc = dev->private; 525 struct gc *gc = dev->private;
526
527 down(&gc->sem);
517 if (!--gc->used) { 528 if (!--gc->used) {
518 del_timer(&gc->timer); 529 del_timer_sync(&gc->timer);
519 parport_write_control(gc->pd->port, 0x00); 530 parport_write_control(gc->pd->port, 0x00);
520 parport_release(gc->pd); 531 parport_release(gc->pd);
521 } 532 }
533 up(&gc->sem);
522} 534}
523 535
524static struct gc __init *gc_probe(int *config, int nargs) 536static struct gc __init *gc_probe(int *config, int nargs)
@@ -542,11 +554,12 @@ static struct gc __init *gc_probe(int *config, int nargs)
542 return NULL; 554 return NULL;
543 } 555 }
544 556
545 if (!(gc = kmalloc(sizeof(struct gc), GFP_KERNEL))) { 557 if (!(gc = kcalloc(1, sizeof(struct gc), GFP_KERNEL))) {
546 parport_put_port(pp); 558 parport_put_port(pp);
547 return NULL; 559 return NULL;
548 } 560 }
549 memset(gc, 0, sizeof(struct gc)); 561
562 init_MUTEX(&gc->sem);
550 563
551 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 564 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
552 565
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index ad13f09a4e71..7d969420066c 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -329,7 +329,7 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
329 329
330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : 331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 :
332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; 332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32;
333 gf2k->dev.absmin[gf2k_abs[i]] = 32; 333 gf2k->dev.absmin[gf2k_abs[i]] = 32;
334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8; 334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8;
335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 42e5005d621f..0da7bd133ccf 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -171,7 +171,7 @@ static int mp_io(struct gameport* gameport, int sendflags, int sendcode, u32 *pa
171 *packet = 0; 171 *packet = 0;
172 raw_data = gameport_read(gameport); 172 raw_data = gameport_read(gameport);
173 if (raw_data & 1) 173 if (raw_data & 1)
174 return IO_RETRY; 174 return IO_RETRY;
175 175
176 for (i = 0; i < 64; i++) { 176 for (i = 0; i < 64; i++) {
177 raw_data = gameport_read(gameport); 177 raw_data = gameport_read(gameport);
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index 028f3513629a..e31b7b93fde2 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -78,6 +78,7 @@ static struct iforce_device iforce_device[] = {
78 { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? 78 { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //?
79 { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? 79 { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //?
80 { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? 80 { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //?
81 { 0x06f8, 0x0004, "Gullemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //?
81 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } 82 { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce }
82}; 83};
83 84
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 617c0b0e5a39..6369a24684fe 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -229,6 +229,7 @@ static struct usb_device_id iforce_usb_ids [] = {
229 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ 229 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */
230 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ 230 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */
231 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ 231 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */
232 { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */
232 { } /* Terminating entry */ 233 { } /* Terminating entry */
233}; 234};
234 235
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index ec0a2a64d49c..a436f2220856 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -4,8 +4,8 @@
4 * Copyright (c) 1999-2001 Vojtech Pavlik 4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * David Thompson 7 * David Thompson
8 * Joseph Krahn 8 * Joseph Krahn
9 */ 9 */
10 10
11/* 11/*
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index 874367bfab08..01fd2e4791ae 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 1999-2001 Vojtech Pavlik 4 * Copyright (c) 1999-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * David Thompson 7 * David Thompson
8 */ 8 */
9 9
10/* 10/*
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index aaee52ceb920..9eb9954cac6e 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -79,7 +79,7 @@ static short tmdc_btn_pad[TMDC_BTN] =
79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; 79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR };
80static short tmdc_btn_joy[TMDC_BTN] = 80static short tmdc_btn_joy[TMDC_BTN] =
81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, 81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE,
82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; 82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z };
83static short tmdc_btn_fm[TMDC_BTN] = 83static short tmdc_btn_fm[TMDC_BTN] =
84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; 84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 };
85static short tmdc_btn_at[TMDC_BTN] = 85static short tmdc_btn_at[TMDC_BTN] =
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index dd88b9cb49fa..28100d461cb7 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -84,6 +84,7 @@ static struct tgfx {
84 char phys[7][32]; 84 char phys[7][32];
85 int sticks; 85 int sticks;
86 int used; 86 int used;
87 struct semaphore sem;
87} *tgfx_base[3]; 88} *tgfx_base[3];
88 89
89/* 90/*
@@ -99,7 +100,7 @@ static void tgfx_timer(unsigned long private)
99 for (i = 0; i < 7; i++) 100 for (i = 0; i < 7; i++)
100 if (tgfx->sticks & (1 << i)) { 101 if (tgfx->sticks & (1 << i)) {
101 102
102 dev = tgfx->dev + i; 103 dev = tgfx->dev + i;
103 104
104 parport_write_data(tgfx->pd->port, ~(1 << i)); 105 parport_write_data(tgfx->pd->port, ~(1 << i));
105 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f; 106 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
@@ -122,23 +123,34 @@ static void tgfx_timer(unsigned long private)
122 123
123static int tgfx_open(struct input_dev *dev) 124static int tgfx_open(struct input_dev *dev)
124{ 125{
125 struct tgfx *tgfx = dev->private; 126 struct tgfx *tgfx = dev->private;
126 if (!tgfx->used++) { 127 int err;
128
129 err = down_interruptible(&tgfx->sem);
130 if (err)
131 return err;
132
133 if (!tgfx->used++) {
127 parport_claim(tgfx->pd); 134 parport_claim(tgfx->pd);
128 parport_write_control(tgfx->pd->port, 0x04); 135 parport_write_control(tgfx->pd->port, 0x04);
129 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME); 136 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
130 } 137 }
131 return 0; 138
139 up(&tgfx->sem);
140 return 0;
132} 141}
133 142
134static void tgfx_close(struct input_dev *dev) 143static void tgfx_close(struct input_dev *dev)
135{ 144{
136 struct tgfx *tgfx = dev->private; 145 struct tgfx *tgfx = dev->private;
137 if (!--tgfx->used) { 146
138 del_timer(&tgfx->timer); 147 down(&tgfx->sem);
148 if (!--tgfx->used) {
149 del_timer_sync(&tgfx->timer);
139 parport_write_control(tgfx->pd->port, 0x00); 150 parport_write_control(tgfx->pd->port, 0x00);
140 parport_release(tgfx->pd); 151 parport_release(tgfx->pd);
141 } 152 }
153 up(&tgfx->sem);
142} 154}
143 155
144/* 156/*
@@ -166,11 +178,12 @@ static struct tgfx __init *tgfx_probe(int *config, int nargs)
166 return NULL; 178 return NULL;
167 } 179 }
168 180
169 if (!(tgfx = kmalloc(sizeof(struct tgfx), GFP_KERNEL))) { 181 if (!(tgfx = kcalloc(1, sizeof(struct tgfx), GFP_KERNEL))) {
170 parport_put_port(pp); 182 parport_put_port(pp);
171 return NULL; 183 return NULL;
172 } 184 }
173 memset(tgfx, 0, sizeof(struct tgfx)); 185
186 init_MUTEX(&tgfx->sem);
174 187
175 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 188 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
176 189
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 82fad9a23ace..4d4985b59abf 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -227,7 +227,7 @@ static ssize_t atkbd_do_set_##_name(struct device *d, struct device_attribute *a
227{ \ 227{ \
228 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \ 228 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
229} \ 229} \
230static struct device_attribute atkbd_attr_##_name = \ 230static struct device_attribute atkbd_attr_##_name = \
231 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name); 231 __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
232 232
233ATKBD_DEFINE_ATTR(extra); 233ATKBD_DEFINE_ATTR(extra);
@@ -388,7 +388,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
388 value = atkbd->release ? 0 : 388 value = atkbd->release ? 0 :
389 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key))); 389 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key)));
390 390
391 switch (value) { /* Workaround Toshiba laptop multiple keypress */ 391 switch (value) { /* Workaround Toshiba laptop multiple keypress */
392 case 0: 392 case 0:
393 atkbd->last = 0; 393 atkbd->last = 0;
394 break; 394 break;
@@ -894,7 +894,7 @@ static int atkbd_reconnect(struct serio *serio)
894 if (atkbd->write) { 894 if (atkbd->write) {
895 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0) 895 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0)
896 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0) 896 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0)
897 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0); 897 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0);
898 898
899 if (atkbd_probe(atkbd)) 899 if (atkbd_probe(atkbd))
900 return -1; 900 return -1;
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index 0f1220a0ceb5..a8551711e8d6 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -39,6 +39,7 @@
39#define CORGI_KEY_CALENDER KEY_F1 39#define CORGI_KEY_CALENDER KEY_F1
40#define CORGI_KEY_ADDRESS KEY_F2 40#define CORGI_KEY_ADDRESS KEY_F2
41#define CORGI_KEY_FN KEY_F3 41#define CORGI_KEY_FN KEY_F3
42#define CORGI_KEY_CANCEL KEY_F4
42#define CORGI_KEY_OFF KEY_SUSPEND 43#define CORGI_KEY_OFF KEY_SUSPEND
43#define CORGI_KEY_EXOK KEY_F5 44#define CORGI_KEY_EXOK KEY_F5
44#define CORGI_KEY_EXCANCEL KEY_F6 45#define CORGI_KEY_EXCANCEL KEY_F6
@@ -46,6 +47,7 @@
46#define CORGI_KEY_EXJOGUP KEY_F8 47#define CORGI_KEY_EXJOGUP KEY_F8
47#define CORGI_KEY_JAP1 KEY_LEFTCTRL 48#define CORGI_KEY_JAP1 KEY_LEFTCTRL
48#define CORGI_KEY_JAP2 KEY_LEFTALT 49#define CORGI_KEY_JAP2 KEY_LEFTALT
50#define CORGI_KEY_MAIL KEY_F10
49#define CORGI_KEY_OK KEY_F11 51#define CORGI_KEY_OK KEY_F11
50#define CORGI_KEY_MENU KEY_F12 52#define CORGI_KEY_MENU KEY_F12
51#define CORGI_HINGE_0 KEY_KP0 53#define CORGI_HINGE_0 KEY_KP0
@@ -59,8 +61,8 @@ static unsigned char corgikbd_keycode[NR_SCANCODES] = {
59 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */ 61 KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */
60 CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */ 62 CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */
61 CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */ 63 CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */
62 KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */ 64 CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */
63 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */ 65 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */
64 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */ 66 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */
65 CORGI_HINGE_0, CORGI_HINGE_1, CORGI_HINGE_2 /* 125-127 */ 67 CORGI_HINGE_0, CORGI_HINGE_1, CORGI_HINGE_2 /* 125-127 */
66}; 68};
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 2694ff2b5beb..098963c7cdd6 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -15,10 +15,10 @@
15 * information given below, I will _not_ be liable! 15 * information given below, I will _not_ be liable!
16 * 16 *
17 * RJ10 pinout: To DE9: Or DB25: 17 * RJ10 pinout: To DE9: Or DB25:
18 * 1 - RxD <----> Pin 3 (TxD) <-> Pin 2 (TxD) 18 * 1 - RxD <----> Pin 3 (TxD) <-> Pin 2 (TxD)
19 * 2 - GND <----> Pin 5 (GND) <-> Pin 7 (GND) 19 * 2 - GND <----> Pin 5 (GND) <-> Pin 7 (GND)
20 * 4 - TxD <----> Pin 2 (RxD) <-> Pin 3 (RxD) 20 * 4 - TxD <----> Pin 2 (RxD) <-> Pin 3 (RxD)
21 * 3 - +12V (from HDD drive connector), DON'T connect to DE9 or DB25!!! 21 * 3 - +12V (from HDD drive connector), DON'T connect to DE9 or DB25!!!
22 * 22 *
23 * Pin numbers for DE9 and DB25 are noted on the plug (quite small:). For 23 * Pin numbers for DE9 and DB25 are noted on the plug (quite small:). For
24 * RJ10, it's like this: 24 * RJ10, it's like this:
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index d3e9dd6a13cd..8935290256b3 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -42,7 +42,7 @@ MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
42MODULE_DESCRIPTION("LoCoMo keyboard driver"); 42MODULE_DESCRIPTION("LoCoMo keyboard driver");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45#define LOCOMOKBD_NUMKEYS 128 45#define LOCOMOKBD_NUMKEYS 128
46 46
47#define KEY_ACTIVITY KEY_F16 47#define KEY_ACTIVITY KEY_F16
48#define KEY_CONTACT KEY_F18 48#define KEY_CONTACT KEY_F18
@@ -61,7 +61,7 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
61 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */ 61 KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */
62 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */ 62 0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A, /* 100 - 109 */
63 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */ 63 KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0, /* 110 - 119 */
64 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */ 64 KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */
65}; 65};
66 66
67#define KB_ROWS 16 67#define KB_ROWS 16
@@ -82,7 +82,7 @@ struct locomokbd {
82 struct locomo_dev *ldev; 82 struct locomo_dev *ldev;
83 unsigned long base; 83 unsigned long base;
84 spinlock_t lock; 84 spinlock_t lock;
85 85
86 struct timer_list timer; 86 struct timer_list timer;
87}; 87};
88 88
@@ -95,7 +95,7 @@ static inline void locomokbd_charge_all(unsigned long membase)
95static inline void locomokbd_activate_all(unsigned long membase) 95static inline void locomokbd_activate_all(unsigned long membase)
96{ 96{
97 unsigned long r; 97 unsigned long r;
98 98
99 locomo_writel(0, membase + LOCOMO_KSC); 99 locomo_writel(0, membase + LOCOMO_KSC);
100 r = locomo_readl(membase + LOCOMO_KIC); 100 r = locomo_readl(membase + LOCOMO_KIC);
101 r &= 0xFEFF; 101 r &= 0xFEFF;
@@ -127,7 +127,7 @@ static inline void locomokbd_reset_col(unsigned long membase, int col)
127 */ 127 */
128 128
129/* Scan the hardware keyboard and push any changes up through the input layer */ 129/* Scan the hardware keyboard and push any changes up through the input layer */
130static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs) 130static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs)
131{ 131{
132 unsigned int row, col, rowd, scancode; 132 unsigned int row, col, rowd, scancode;
133 unsigned long flags; 133 unsigned long flags;
@@ -138,7 +138,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
138 138
139 if (regs) 139 if (regs)
140 input_regs(&locomokbd->input, regs); 140 input_regs(&locomokbd->input, regs);
141 141
142 locomokbd_charge_all(membase); 142 locomokbd_charge_all(membase);
143 143
144 num_pressed = 0; 144 num_pressed = 0;
@@ -146,9 +146,9 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
146 146
147 locomokbd_activate_col(membase, col); 147 locomokbd_activate_col(membase, col);
148 udelay(KB_DELAY); 148 udelay(KB_DELAY);
149 149
150 rowd = ~locomo_readl(membase + LOCOMO_KIB); 150 rowd = ~locomo_readl(membase + LOCOMO_KIB);
151 for (row = 0; row < KB_ROWS; row++ ) { 151 for (row = 0; row < KB_ROWS; row++) {
152 scancode = SCANCODE(col, row); 152 scancode = SCANCODE(col, row);
153 if (rowd & KB_ROWMASK(row)) { 153 if (rowd & KB_ROWMASK(row)) {
154 num_pressed += 1; 154 num_pressed += 1;
@@ -170,7 +170,7 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *
170 spin_unlock_irqrestore(&locomokbd->lock, flags); 170 spin_unlock_irqrestore(&locomokbd->lock, flags);
171} 171}
172 172
173/* 173/*
174 * LoCoMo keyboard interrupt handler. 174 * LoCoMo keyboard interrupt handler.
175 */ 175 */
176static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) 176static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -205,8 +205,8 @@ static int locomokbd_probe(struct locomo_dev *dev)
205 memset(locomokbd, 0, sizeof(struct locomokbd)); 205 memset(locomokbd, 0, sizeof(struct locomokbd));
206 206
207 /* try and claim memory region */ 207 /* try and claim memory region */
208 if (!request_mem_region((unsigned long) dev->mapbase, 208 if (!request_mem_region((unsigned long) dev->mapbase,
209 dev->length, 209 dev->length,
210 LOCOMO_DRIVER_NAME(dev))) { 210 LOCOMO_DRIVER_NAME(dev))) {
211 ret = -EBUSY; 211 ret = -EBUSY;
212 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); 212 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
@@ -225,7 +225,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
225 locomokbd->timer.data = (unsigned long) locomokbd; 225 locomokbd->timer.data = (unsigned long) locomokbd;
226 226
227 locomokbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 227 locomokbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
228 228
229 init_input_dev(&locomokbd->input); 229 init_input_dev(&locomokbd->input);
230 locomokbd->input.keycode = locomokbd->keycode; 230 locomokbd->input.keycode = locomokbd->keycode;
231 locomokbd->input.keycodesize = sizeof(unsigned char); 231 locomokbd->input.keycodesize = sizeof(unsigned char);
@@ -271,11 +271,11 @@ free:
271static int locomokbd_remove(struct locomo_dev *dev) 271static int locomokbd_remove(struct locomo_dev *dev)
272{ 272{
273 struct locomokbd *locomokbd = locomo_get_drvdata(dev); 273 struct locomokbd *locomokbd = locomo_get_drvdata(dev);
274 274
275 free_irq(dev->irq[0], locomokbd); 275 free_irq(dev->irq[0], locomokbd);
276 276
277 del_timer_sync(&locomokbd->timer); 277 del_timer_sync(&locomokbd->timer);
278 278
279 input_unregister_device(&locomokbd->input); 279 input_unregister_device(&locomokbd->input);
280 locomo_set_drvdata(dev, NULL); 280 locomo_set_drvdata(dev, NULL);
281 281
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index 859ed771ee0a..eecbde294f1f 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $ 2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast keyboard driver 3 * SEGA Dreamcast keyboard driver
4 * Based on drivers/usb/usbkbd.c 4 * Based on drivers/usb/usbkbd.c
5 */ 5 */
6 6
@@ -40,7 +40,6 @@ struct dc_kbd {
40 struct input_dev dev; 40 struct input_dev dev;
41 unsigned char new[8]; 41 unsigned char new[8];
42 unsigned char old[8]; 42 unsigned char old[8];
43 int open;
44}; 43};
45 44
46 45
@@ -95,22 +94,6 @@ static void dc_kbd_callback(struct mapleq *mq)
95 } 94 }
96} 95}
97 96
98
99static int dc_kbd_open(struct input_dev *dev)
100{
101 struct dc_kbd *kbd = dev->private;
102 kbd->open++;
103 return 0;
104}
105
106
107static void dc_kbd_close(struct input_dev *dev)
108{
109 struct dc_kbd *kbd = dev->private;
110 kbd->open--;
111}
112
113
114static int dc_kbd_connect(struct maple_device *dev) 97static int dc_kbd_connect(struct maple_device *dev)
115{ 98{
116 int i; 99 int i;
@@ -133,9 +116,6 @@ static int dc_kbd_connect(struct maple_device *dev)
133 clear_bit(0, kbd->dev.keybit); 116 clear_bit(0, kbd->dev.keybit);
134 117
135 kbd->dev.private = kbd; 118 kbd->dev.private = kbd;
136 kbd->dev.open = dc_kbd_open;
137 kbd->dev.close = dc_kbd_close;
138 kbd->dev.event = NULL;
139 119
140 kbd->dev.name = dev->product_name; 120 kbd->dev.name = dev->product_name;
141 kbd->dev.id.bustype = BUS_MAPLE; 121 kbd->dev.id.bustype = BUS_MAPLE;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 158c8e845ff9..98710997aaaa 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -298,9 +298,11 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
298 /* check if absmin/absmax/absfuzz/absflat are filled as 298 /* check if absmin/absmax/absfuzz/absflat are filled as
299 * told in Documentation/input/input-programming.txt */ 299 * told in Documentation/input/input-programming.txt */
300 if (test_bit(EV_ABS, dev->evbit)) { 300 if (test_bit(EV_ABS, dev->evbit)) {
301 retval = uinput_validate_absbits(dev); 301 int err = uinput_validate_absbits(dev);
302 if (retval < 0) 302 if (err < 0) {
303 retval = err;
303 kfree(dev->name); 304 kfree(dev->name);
305 }
304 } 306 }
305 307
306exit: 308exit:
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index a7864195806a..c4909b49337d 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -15,4 +15,4 @@ obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o 15obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o 16obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
17 17
18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o 18psmouse-objs := psmouse-base.o alps.o logips2pp.o synaptics.o lifebook.o
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 7bf4be733e9a..a12e98158a75 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -30,10 +30,11 @@
30 30
31#define ALPS_DUALPOINT 0x01 31#define ALPS_DUALPOINT 0x01
32#define ALPS_WHEEL 0x02 32#define ALPS_WHEEL 0x02
33#define ALPS_FW_BK 0x04 33#define ALPS_FW_BK_1 0x04
34#define ALPS_4BTN 0x08 34#define ALPS_4BTN 0x08
35#define ALPS_OLDPROTO 0x10 35#define ALPS_OLDPROTO 0x10
36#define ALPS_PASS 0x20 36#define ALPS_PASS 0x20
37#define ALPS_FW_BK_2 0x40
37 38
38static struct alps_model_info alps_model_data[] = { 39static struct alps_model_info alps_model_data[] = {
39 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ 40 { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */
@@ -43,11 +44,11 @@ static struct alps_model_info alps_model_data[] = {
43 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 44 { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 },
44 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, 0 }, 45 { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, 0 },
45 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */ 46 { { 0x63, 0x02, 0x3c }, 0x8f, 0x8f, ALPS_WHEEL }, /* Toshiba Satellite S2400-103 */
46 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK }, /* NEC Versa L320 */ 47 { { 0x63, 0x02, 0x50 }, 0xef, 0xef, ALPS_FW_BK_1 }, /* NEC Versa L320 */
47 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 }, 48 { { 0x63, 0x02, 0x64 }, 0xf8, 0xf8, 0 },
48 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */ 49 { { 0x63, 0x03, 0xc8 }, 0xf8, 0xf8, ALPS_PASS }, /* Dell Latitude D800 */
49 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, 50 { { 0x73, 0x02, 0x0a }, 0xf8, 0xf8, 0 },
50 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, 51 { { 0x73, 0x02, 0x14 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Ahtec Laptop */
51 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ 52 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
52 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, 53 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
53 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ 54 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
@@ -61,11 +62,11 @@ static struct alps_model_info alps_model_data[] = {
61 62
62/* 63/*
63 * ALPS abolute Mode - new format 64 * ALPS abolute Mode - new format
64 * 65 *
65 * byte 0: 1 ? ? ? 1 ? ? ? 66 * byte 0: 1 ? ? ? 1 ? ? ?
66 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 67 * byte 1: 0 x6 x5 x4 x3 x2 x1 x0
67 * byte 2: 0 x10 x9 x8 x7 ? fin ges 68 * byte 2: 0 x10 x9 x8 x7 ? fin ges
68 * byte 3: 0 y9 y8 y7 1 M R L 69 * byte 3: 0 y9 y8 y7 1 M R L
69 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 70 * byte 4: 0 y6 y5 y4 y3 y2 y1 y0
70 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 71 * byte 5: 0 z6 z5 z4 z3 z2 z1 z0
71 * 72 *
@@ -81,11 +82,12 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
81 struct input_dev *dev = &psmouse->dev; 82 struct input_dev *dev = &psmouse->dev;
82 struct input_dev *dev2 = &priv->dev2; 83 struct input_dev *dev2 = &priv->dev2;
83 int x, y, z, ges, fin, left, right, middle; 84 int x, y, z, ges, fin, left, right, middle;
85 int back = 0, forward = 0;
84 86
85 input_regs(dev, regs); 87 input_regs(dev, regs);
86 88
87 if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */ 89 if ((packet[0] & 0xc8) == 0x08) { /* 3-byte PS/2 packet */
88 input_report_key(dev2, BTN_LEFT, packet[0] & 1); 90 input_report_key(dev2, BTN_LEFT, packet[0] & 1);
89 input_report_key(dev2, BTN_RIGHT, packet[0] & 2); 91 input_report_key(dev2, BTN_RIGHT, packet[0] & 2);
90 input_report_key(dev2, BTN_MIDDLE, packet[0] & 4); 92 input_report_key(dev2, BTN_MIDDLE, packet[0] & 4);
91 input_report_rel(dev2, REL_X, 93 input_report_rel(dev2, REL_X,
@@ -112,6 +114,18 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
112 z = packet[5]; 114 z = packet[5];
113 } 115 }
114 116
117 if (priv->i->flags & ALPS_FW_BK_1) {
118 back = packet[2] & 4;
119 forward = packet[0] & 0x10;
120 }
121
122 if (priv->i->flags & ALPS_FW_BK_2) {
123 back = packet[3] & 4;
124 forward = packet[2] & 4;
125 if ((middle = forward && back))
126 forward = back = 0;
127 }
128
115 ges = packet[2] & 1; 129 ges = packet[2] & 1;
116 fin = packet[2] & 2; 130 fin = packet[2] & 2;
117 131
@@ -155,13 +169,12 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
155 input_report_abs(dev, ABS_PRESSURE, z); 169 input_report_abs(dev, ABS_PRESSURE, z);
156 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 170 input_report_key(dev, BTN_TOOL_FINGER, z > 0);
157 171
158
159 if (priv->i->flags & ALPS_WHEEL) 172 if (priv->i->flags & ALPS_WHEEL)
160 input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08)); 173 input_report_rel(dev, REL_WHEEL, ((packet[0] >> 4) & 0x07) | ((packet[2] >> 2) & 0x08));
161 174
162 if (priv->i->flags & ALPS_FW_BK) { 175 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
163 input_report_key(dev, BTN_FORWARD, packet[0] & 0x10); 176 input_report_key(dev, BTN_FORWARD, forward);
164 input_report_key(dev, BTN_BACK, packet[2] & 0x04); 177 input_report_key(dev, BTN_BACK, back);
165 } 178 }
166 179
167 input_sync(dev); 180 input_sync(dev);
@@ -257,7 +270,6 @@ static struct alps_model_info *alps_get_model(struct psmouse *psmouse, int *vers
257static int alps_passthrough_mode(struct psmouse *psmouse, int enable) 270static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
258{ 271{
259 struct ps2dev *ps2dev = &psmouse->ps2dev; 272 struct ps2dev *ps2dev = &psmouse->ps2dev;
260 unsigned char param[3];
261 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11; 273 int cmd = enable ? PSMOUSE_CMD_SETSCALE21 : PSMOUSE_CMD_SETSCALE11;
262 274
263 if (ps2_command(ps2dev, NULL, cmd) || 275 if (ps2_command(ps2dev, NULL, cmd) ||
@@ -267,7 +279,7 @@ static int alps_passthrough_mode(struct psmouse *psmouse, int enable)
267 return -1; 279 return -1;
268 280
269 /* we may get 3 more bytes, just ignore them */ 281 /* we may get 3 more bytes, just ignore them */
270 ps2_command(ps2dev, param, 0x0300); 282 ps2_drain(ps2dev, 3, 100);
271 283
272 return 0; 284 return 0;
273} 285}
@@ -425,7 +437,7 @@ int alps_init(struct psmouse *psmouse)
425 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL); 437 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
426 } 438 }
427 439
428 if (priv->i->flags & ALPS_FW_BK) { 440 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
429 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD); 441 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
430 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK); 442 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
431 } 443 }
@@ -436,8 +448,8 @@ int alps_init(struct psmouse *psmouse)
436 priv->dev2.id.bustype = BUS_I8042; 448 priv->dev2.id.bustype = BUS_I8042;
437 priv->dev2.id.vendor = 0x0002; 449 priv->dev2.id.vendor = 0x0002;
438 priv->dev2.id.product = PSMOUSE_ALPS; 450 priv->dev2.id.product = PSMOUSE_ALPS;
439 priv->dev2.id.version = 0x0000; 451 priv->dev2.id.version = 0x0000;
440 452
441 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 453 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
442 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y); 454 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
443 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 455 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
@@ -461,17 +473,15 @@ init_fail:
461int alps_detect(struct psmouse *psmouse, int set_properties) 473int alps_detect(struct psmouse *psmouse, int set_properties)
462{ 474{
463 int version; 475 int version;
464 struct alps_model_info *model; 476 struct alps_model_info *model;
465 477
466 if (!(model = alps_get_model(psmouse, &version))) 478 if (!(model = alps_get_model(psmouse, &version)))
467 return -1; 479 return -1;
468 480
469 if (set_properties) { 481 if (set_properties) {
470 psmouse->vendor = "ALPS"; 482 psmouse->vendor = "ALPS";
471 if (model->flags & ALPS_DUALPOINT) 483 psmouse->name = model->flags & ALPS_DUALPOINT ?
472 psmouse->name = "DualPoint TouchPad"; 484 "DualPoint TouchPad" : "GlidePoint";
473 else
474 psmouse->name = "GlidePoint";
475 psmouse->model = version; 485 psmouse->model = version;
476 } 486 }
477 return 0; 487 return 0;
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index 7baa09cca7c5..e994849efb8f 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -33,7 +33,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
33MODULE_DESCRIPTION("Amiga mouse driver"); 33MODULE_DESCRIPTION("Amiga mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static int amimouse_used = 0;
37static int amimouse_lastx, amimouse_lasty; 36static int amimouse_lastx, amimouse_lasty;
38static struct input_dev amimouse_dev; 37static struct input_dev amimouse_dev;
39 38
@@ -81,16 +80,12 @@ static int amimouse_open(struct input_dev *dev)
81{ 80{
82 unsigned short joy0dat; 81 unsigned short joy0dat;
83 82
84 if (amimouse_used++)
85 return 0;
86
87 joy0dat = custom.joy0dat; 83 joy0dat = custom.joy0dat;
88 84
89 amimouse_lastx = joy0dat & 0xff; 85 amimouse_lastx = joy0dat & 0xff;
90 amimouse_lasty = joy0dat >> 8; 86 amimouse_lasty = joy0dat >> 8;
91 87
92 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) { 88 if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) {
93 amimouse_used--;
94 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB); 89 printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
95 return -EBUSY; 90 return -EBUSY;
96 } 91 }
@@ -100,8 +95,7 @@ static int amimouse_open(struct input_dev *dev)
100 95
101static void amimouse_close(struct input_dev *dev) 96static void amimouse_close(struct input_dev *dev)
102{ 97{
103 if (!--amimouse_used) 98 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
104 free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt);
105} 99}
106 100
107static int __init amimouse_init(void) 101static int __init amimouse_init(void)
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index ca4e96886627..1f62c0134010 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -17,18 +17,18 @@
17/* 17/*
18 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version. 21 * (at your option) any later version.
22 * 22 *
23 * This program is distributed in the hope that it will be useful, 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details. 26 * GNU General Public License for more details.
27 * 27 *
28 * You should have received a copy of the GNU General Public License 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software 29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * 31 *
32 * Should you need to contact me, the author, you can do so either by 32 * Should you need to contact me, the author, you can do so either by
33 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 33 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
34 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 34 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -87,29 +87,23 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
87 87
88__obsolete_setup("inport_irq="); 88__obsolete_setup("inport_irq=");
89 89
90static int inport_used;
91
92static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs); 90static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs);
93 91
94static int inport_open(struct input_dev *dev) 92static int inport_open(struct input_dev *dev)
95{ 93{
96 if (!inport_used++) { 94 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
97 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) 95 return -EBUSY;
98 return -EBUSY; 96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
99 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 97 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
100 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
101 }
102 98
103 return 0; 99 return 0;
104} 100}
105 101
106static void inport_close(struct input_dev *dev) 102static void inport_close(struct input_dev *dev)
107{ 103{
108 if (!--inport_used) { 104 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
109 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 105 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
110 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 106 free_irq(inport_irq, NULL);
111 free_irq(inport_irq, NULL);
112 }
113} 107}
114 108
115static struct input_dev inport_dev = { 109static struct input_dev inport_dev = {
@@ -120,11 +114,11 @@ static struct input_dev inport_dev = {
120 .close = inport_close, 114 .close = inport_close,
121 .name = INPORT_NAME, 115 .name = INPORT_NAME,
122 .phys = "isa023c/input0", 116 .phys = "isa023c/input0",
123 .id = { 117 .id = {
124 .bustype = BUS_ISA, 118 .bustype = BUS_ISA,
125 .vendor = INPORT_VENDOR, 119 .vendor = INPORT_VENDOR,
126 .product = 0x0001, 120 .product = 0x0001,
127 .version = 0x0100, 121 .version = 0x0100,
128 }, 122 },
129}; 123};
130 124
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
new file mode 100644
index 000000000000..bd9df9b28325
--- /dev/null
+++ b/drivers/input/mouse/lifebook.c
@@ -0,0 +1,134 @@
1/*
2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
3 *
4 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
6 *
7 * TouchScreen detection, absolute mode setting and packet layout is taken from
8 * Harald Hoyer's description of the device.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 */
14
15#include <linux/input.h>
16#include <linux/serio.h>
17#include <linux/libps2.h>
18#include <linux/dmi.h>
19
20#include "psmouse.h"
21#include "lifebook.h"
22
23static struct dmi_system_id lifebook_dmi_table[] = {
24 {
25 .ident = "Lifebook B",
26 .matches = {
27 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
28 },
29 },
30 { }
31};
32
33
34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
35{
36 unsigned char *packet = psmouse->packet;
37 struct input_dev *dev = &psmouse->dev;
38
39 if (psmouse->pktcnt != 3)
40 return PSMOUSE_GOOD_DATA;
41
42 input_regs(dev, regs);
43
44 /* calculate X and Y */
45 if ((packet[0] & 0x08) == 0x00) {
46 input_report_abs(dev, ABS_X,
47 (packet[1] | ((packet[0] & 0x30) << 4)));
48 input_report_abs(dev, ABS_Y,
49 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
50 } else {
51 input_report_rel(dev, REL_X,
52 ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
53 input_report_rel(dev, REL_Y,
54 -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
55 }
56
57 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
58 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
59 input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
60
61 input_sync(dev);
62
63 return PSMOUSE_FULL_PACKET;
64}
65
66static int lifebook_absolute_mode(struct psmouse *psmouse)
67{
68 struct ps2dev *ps2dev = &psmouse->ps2dev;
69 unsigned char param;
70
71 if (psmouse_reset(psmouse))
72 return -1;
73
74 /*
75 Enable absolute output -- ps2_command fails always but if
76 you leave this call out the touchsreen will never send
77 absolute coordinates
78 */
79 param = 0x07;
80 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
81
82 return 0;
83}
84
85static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
86{
87 unsigned char params[] = { 0, 1, 2, 2, 3 };
88
89 if (resolution == 0 || resolution > 400)
90 resolution = 400;
91
92 ps2_command(&psmouse->ps2dev, &params[resolution / 100], PSMOUSE_CMD_SETRES);
93 psmouse->resolution = 50 << params[resolution / 100];
94}
95
96static void lifebook_disconnect(struct psmouse *psmouse)
97{
98 psmouse_reset(psmouse);
99}
100
101int lifebook_detect(struct psmouse *psmouse, int set_properties)
102{
103 if (!dmi_check_system(lifebook_dmi_table))
104 return -1;
105
106 if (set_properties) {
107 psmouse->vendor = "Fujitsu";
108 psmouse->name = "Lifebook TouchScreen";
109 }
110
111 return 0;
112}
113
114int lifebook_init(struct psmouse *psmouse)
115{
116 if (lifebook_absolute_mode(psmouse))
117 return -1;
118
119 psmouse->dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
120 psmouse->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
121 psmouse->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
122 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
123 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1024, 0, 0);
124 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 1024, 0, 0);
125
126 psmouse->protocol_handler = lifebook_process_byte;
127 psmouse->set_resolution = lifebook_set_resolution;
128 psmouse->disconnect = lifebook_disconnect;
129 psmouse->reconnect = lifebook_absolute_mode;
130 psmouse->pktsize = 3;
131
132 return 0;
133}
134
diff --git a/drivers/input/mouse/lifebook.h b/drivers/input/mouse/lifebook.h
new file mode 100644
index 000000000000..be1c0943825d
--- /dev/null
+++ b/drivers/input/mouse/lifebook.h
@@ -0,0 +1,17 @@
1/*
2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
3 *
4 * Copyright (c) 2005 Vojtech Pavlik
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 by
8 * the Free Software Foundation.
9 */
10
11#ifndef _LIFEBOOK_H
12#define _LIFEBOOK_H
13
14int lifebook_detect(struct psmouse *psmouse, int set_properties);
15int lifebook_init(struct psmouse *psmouse);
16
17#endif
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 77eb83e87f61..8b5243167227 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -18,18 +18,18 @@
18/* 18/*
19 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or 21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version. 22 * (at your option) any later version.
23 * 23 *
24 * This program is distributed in the hope that it will be useful, 24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details. 27 * GNU General Public License for more details.
28 * 28 *
29 * You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software 30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 * 32 *
33 * Should you need to contact me, the author, you can do so either by 33 * Should you need to contact me, the author, you can do so either by
34 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 34 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
35 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 35 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -77,16 +77,11 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq="); 78__obsolete_setup("logibm_irq=");
79 79
80static int logibm_used = 0;
81
82static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs); 80static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs);
83 81
84static int logibm_open(struct input_dev *dev) 82static int logibm_open(struct input_dev *dev)
85{ 83{
86 if (logibm_used++)
87 return 0;
88 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) { 84 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
89 logibm_used--;
90 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq); 85 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
91 return -EBUSY; 86 return -EBUSY;
92 } 87 }
@@ -96,8 +91,6 @@ static int logibm_open(struct input_dev *dev)
96 91
97static void logibm_close(struct input_dev *dev) 92static void logibm_close(struct input_dev *dev)
98{ 93{
99 if (--logibm_used)
100 return;
101 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 94 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
102 free_irq(logibm_irq, NULL); 95 free_irq(logibm_irq, NULL);
103} 96}
@@ -167,7 +160,7 @@ static int __init logibm_init(void)
167 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 160 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
168 161
169 input_register_device(&logibm_dev); 162 input_register_device(&logibm_dev);
170 163
171 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq); 164 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq);
172 165
173 return 0; 166 return 0;
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
index 12dc0ef5020f..e90c60cbbf05 100644
--- a/drivers/input/mouse/maplemouse.c
+++ b/drivers/input/mouse/maplemouse.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $ 2 * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast mouse driver 3 * SEGA Dreamcast mouse driver
4 * Based on drivers/usb/usbmouse.c 4 * Based on drivers/usb/usbmouse.c
5 */ 5 */
6 6
@@ -15,80 +15,51 @@
15MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>"); 15MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
16MODULE_DESCRIPTION("SEGA Dreamcast mouse driver"); 16MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
17 17
18struct dc_mouse {
19 struct input_dev dev;
20 int open;
21};
22
23
24static void dc_mouse_callback(struct mapleq *mq) 18static void dc_mouse_callback(struct mapleq *mq)
25{ 19{
26 int buttons, relx, rely, relz; 20 int buttons, relx, rely, relz;
27 struct maple_device *mapledev = mq->dev; 21 struct maple_device *mapledev = mq->dev;
28 struct dc_mouse *mouse = mapledev->private_data; 22 struct input_dev *dev = mapledev->private_data;
29 struct input_dev *dev = &mouse->dev;
30 unsigned char *res = mq->recvbuf; 23 unsigned char *res = mq->recvbuf;
31 24
32 buttons = ~res[8]; 25 buttons = ~res[8];
33 relx=*(unsigned short *)(res+12)-512; 26 relx = *(unsigned short *)(res + 12) - 512;
34 rely=*(unsigned short *)(res+14)-512; 27 rely = *(unsigned short *)(res + 14) - 512;
35 relz=*(unsigned short *)(res+16)-512; 28 relz = *(unsigned short *)(res + 16) - 512;
36 29
37 input_report_key(dev, BTN_LEFT, buttons&4); 30 input_report_key(dev, BTN_LEFT, buttons & 4);
38 input_report_key(dev, BTN_MIDDLE, buttons&9); 31 input_report_key(dev, BTN_MIDDLE, buttons & 9);
39 input_report_key(dev, BTN_RIGHT, buttons&2); 32 input_report_key(dev, BTN_RIGHT, buttons & 2);
40 input_report_rel(dev, REL_X, relx); 33 input_report_rel(dev, REL_X, relx);
41 input_report_rel(dev, REL_Y, rely); 34 input_report_rel(dev, REL_Y, rely);
42 input_report_rel(dev, REL_WHEEL, relz); 35 input_report_rel(dev, REL_WHEEL, relz);
43 input_sync(dev); 36 input_sync(dev);
44} 37}
45 38
46
47static int dc_mouse_open(struct input_dev *dev)
48{
49 struct dc_mouse *mouse = dev->private;
50 mouse->open++;
51 return 0;
52}
53
54
55static void dc_mouse_close(struct input_dev *dev)
56{
57 struct dc_mouse *mouse = dev->private;
58 mouse->open--;
59}
60
61
62static int dc_mouse_connect(struct maple_device *dev) 39static int dc_mouse_connect(struct maple_device *dev)
63{ 40{
64 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); 41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
65 struct dc_mouse *mouse; 42 struct input_dev *input_dev;
66 43
67 if (!(mouse = kmalloc(sizeof(struct dc_mouse), GFP_KERNEL))) 44 if (!(input_dev = kmalloc(sizeof(struct input_dev), GFP_KERNEL)))
68 return -1; 45 return -1;
69 memset(mouse, 0, sizeof(struct dc_mouse));
70
71 dev->private_data = mouse;
72 46
73 mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 47 dev->private_data = input_dev;
74 mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
75 mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
76 48
77 init_input_dev(&mouse->dev); 49 memset(input_dev, 0, sizeof(struct dc_mouse));
50 init_input_dev(input_dev);
51 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
52 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
53 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
78 54
79 mouse->dev.private = mouse; 55 input_dev->name = dev->product_name;
80 mouse->dev.open = dc_mouse_open; 56 input_dev->id.bustype = BUS_MAPLE;
81 mouse->dev.close = dc_mouse_close;
82 mouse->dev.event = NULL;
83 57
84 mouse->dev.name = dev->product_name; 58 input_register_device(input_dev);
85 mouse->dev.id.bustype = BUS_MAPLE;
86
87 input_register_device(&mouse->dev);
88 59
89 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); 60 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
90 61
91 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, mouse->dev.name); 62 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, input_dev->name);
92 63
93 return 0; 64 return 0;
94} 65}
@@ -96,10 +67,10 @@ static int dc_mouse_connect(struct maple_device *dev)
96 67
97static void dc_mouse_disconnect(struct maple_device *dev) 68static void dc_mouse_disconnect(struct maple_device *dev)
98{ 69{
99 struct dc_mouse *mouse = dev->private_data; 70 struct input_dev *input_dev = dev->private_data;
100 71
101 input_unregister_device(&mouse->dev); 72 input_unregister_device(input_dev);
102 kfree(mouse); 73 kfree(input_dev);
103} 74}
104 75
105 76
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 0c74918fe254..93393d5c0078 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 2000-2001 Vojtech Pavlik 4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * 5 *
6 * Based on the work of: 6 * Based on the work of:
7 * Alan Cox Robin O'Leary 7 * Alan Cox Robin O'Leary
8 */ 8 */
9 9
10/* 10/*
@@ -56,7 +56,6 @@ static int pc110pad_io = 0x15e0;
56static struct input_dev pc110pad_dev; 56static struct input_dev pc110pad_dev;
57static int pc110pad_data[3]; 57static int pc110pad_data[3];
58static int pc110pad_count; 58static int pc110pad_count;
59static int pc110pad_used;
60 59
61static char *pc110pad_name = "IBM PC110 TouchPad"; 60static char *pc110pad_name = "IBM PC110 TouchPad";
62static char *pc110pad_phys = "isa15e0/input0"; 61static char *pc110pad_phys = "isa15e0/input0";
@@ -74,7 +73,7 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
74 73
75 if (pc110pad_count < 3) 74 if (pc110pad_count < 3)
76 return IRQ_HANDLED; 75 return IRQ_HANDLED;
77 76
78 input_regs(&pc110pad_dev, regs); 77 input_regs(&pc110pad_dev, regs);
79 input_report_key(&pc110pad_dev, BTN_TOUCH, 78 input_report_key(&pc110pad_dev, BTN_TOUCH,
80 pc110pad_data[0] & 0x01); 79 pc110pad_data[0] & 0x01);
@@ -90,15 +89,11 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
90 89
91static void pc110pad_close(struct input_dev *dev) 90static void pc110pad_close(struct input_dev *dev)
92{ 91{
93 if (!--pc110pad_used) 92 outb(PC110PAD_OFF, pc110pad_io + 2);
94 outb(PC110PAD_OFF, pc110pad_io + 2);
95} 93}
96 94
97static int pc110pad_open(struct input_dev *dev) 95static int pc110pad_open(struct input_dev *dev)
98{ 96{
99 if (pc110pad_used++)
100 return 0;
101
102 pc110pad_interrupt(0,NULL,NULL); 97 pc110pad_interrupt(0,NULL,NULL);
103 pc110pad_interrupt(0,NULL,NULL); 98 pc110pad_interrupt(0,NULL,NULL);
104 pc110pad_interrupt(0,NULL,NULL); 99 pc110pad_interrupt(0,NULL,NULL);
@@ -145,7 +140,7 @@ static int __init pc110pad_init(void)
145 140
146 pc110pad_dev.absmax[ABS_X] = 0x1ff; 141 pc110pad_dev.absmax[ABS_X] = 0x1ff;
147 pc110pad_dev.absmax[ABS_Y] = 0x0ff; 142 pc110pad_dev.absmax[ABS_Y] = 0x0ff;
148 143
149 pc110pad_dev.open = pc110pad_open; 144 pc110pad_dev.open = pc110pad_open;
150 pc110pad_dev.close = pc110pad_close; 145 pc110pad_dev.close = pc110pad_close;
151 146
@@ -156,17 +151,17 @@ static int __init pc110pad_init(void)
156 pc110pad_dev.id.product = 0x0001; 151 pc110pad_dev.id.product = 0x0001;
157 pc110pad_dev.id.version = 0x0100; 152 pc110pad_dev.id.version = 0x0100;
158 153
159 input_register_device(&pc110pad_dev); 154 input_register_device(&pc110pad_dev);
160 155
161 printk(KERN_INFO "input: %s at %#x irq %d\n", 156 printk(KERN_INFO "input: %s at %#x irq %d\n",
162 pc110pad_name, pc110pad_io, pc110pad_irq); 157 pc110pad_name, pc110pad_io, pc110pad_irq);
163 158
164 return 0; 159 return 0;
165} 160}
166 161
167static void __exit pc110pad_exit(void) 162static void __exit pc110pad_exit(void)
168{ 163{
169 input_unregister_device(&pc110pad_dev); 164 input_unregister_device(&pc110pad_dev);
170 165
171 outb(PC110PAD_OFF, pc110pad_io + 2); 166 outb(PC110PAD_OFF, pc110pad_io + 2);
172 167
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 019034b21a0b..19785a6c5abd 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -24,6 +24,7 @@
24#include "synaptics.h" 24#include "synaptics.h"
25#include "logips2pp.h" 25#include "logips2pp.h"
26#include "alps.h" 26#include "alps.h"
27#include "lifebook.h"
27 28
28#define DRIVER_DESC "PS/2 mouse driver" 29#define DRIVER_DESC "PS/2 mouse driver"
29 30
@@ -31,10 +32,9 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
31MODULE_DESCRIPTION(DRIVER_DESC); 32MODULE_DESCRIPTION(DRIVER_DESC);
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33 34
34static unsigned int psmouse_max_proto = -1U; 35static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
35static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 36static int psmouse_set_maxproto(const char *val, struct kernel_param *kp);
36static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 37static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp);
37static char *psmouse_proto_abbrev[] = { NULL, "bare", NULL, NULL, NULL, "imps", "exps", NULL, NULL, NULL };
38#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 38#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
39#define param_set_proto_abbrev psmouse_set_maxproto 39#define param_set_proto_abbrev psmouse_set_maxproto
40#define param_get_proto_abbrev psmouse_get_maxproto 40#define param_get_proto_abbrev psmouse_get_maxproto
@@ -57,6 +57,7 @@ static unsigned int psmouse_resetafter;
57module_param_named(resetafter, psmouse_resetafter, uint, 0644); 57module_param_named(resetafter, psmouse_resetafter, uint, 0644);
58MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); 58MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
59 59
60PSMOUSE_DEFINE_ATTR(protocol);
60PSMOUSE_DEFINE_ATTR(rate); 61PSMOUSE_DEFINE_ATTR(rate);
61PSMOUSE_DEFINE_ATTR(resolution); 62PSMOUSE_DEFINE_ATTR(resolution);
62PSMOUSE_DEFINE_ATTR(resetafter); 63PSMOUSE_DEFINE_ATTR(resetafter);
@@ -67,7 +68,23 @@ __obsolete_setup("psmouse_smartscroll=");
67__obsolete_setup("psmouse_resetafter="); 68__obsolete_setup("psmouse_resetafter=");
68__obsolete_setup("psmouse_rate="); 69__obsolete_setup("psmouse_rate=");
69 70
70static char *psmouse_protocols[] = { "None", "PS/2", "PS2++", "ThinkPS/2", "GenPS/2", "ImPS/2", "ImExPS/2", "SynPS/2", "AlpsPS/2" }; 71/*
72 * psmouse_sem protects all operations changing state of mouse
73 * (connecting, disconnecting, changing rate or resolution via
74 * sysfs). We could use a per-device semaphore but since there
75 * rarely more than one PS/2 mouse connected and since semaphore
76 * is taken in "slow" paths it is not worth it.
77 */
78static DECLARE_MUTEX(psmouse_sem);
79
80struct psmouse_protocol {
81 enum psmouse_type type;
82 char *name;
83 char *alias;
84 int maxproto;
85 int (*detect)(struct psmouse *, int);
86 int (*init)(struct psmouse *);
87};
71 88
72/* 89/*
73 * psmouse_process_byte() analyzes the PS/2 data stream and reports 90 * psmouse_process_byte() analyzes the PS/2 data stream and reports
@@ -407,12 +424,15 @@ static int thinking_detect(struct psmouse *psmouse, int set_properties)
407 */ 424 */
408static int ps2bare_detect(struct psmouse *psmouse, int set_properties) 425static int ps2bare_detect(struct psmouse *psmouse, int set_properties)
409{ 426{
410 if (!psmouse->vendor) psmouse->vendor = "Generic"; 427 if (set_properties) {
411 if (!psmouse->name) psmouse->name = "Mouse"; 428 if (!psmouse->vendor) psmouse->vendor = "Generic";
429 if (!psmouse->name) psmouse->name = "Mouse";
430 }
412 431
413 return 0; 432 return 0;
414} 433}
415 434
435
416/* 436/*
417 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol 437 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
418 * the mouse may have. 438 * the mouse may have.
@@ -424,6 +444,17 @@ static int psmouse_extensions(struct psmouse *psmouse,
424 int synaptics_hardware = 0; 444 int synaptics_hardware = 0;
425 445
426/* 446/*
447 * We always check for lifebook because it does not disturb mouse
448 * (it only checks DMI information).
449 */
450 if (lifebook_detect(psmouse, set_properties) == 0) {
451 if (max_proto > PSMOUSE_IMEX) {
452 if (!set_properties || lifebook_init(psmouse) == 0)
453 return PSMOUSE_LIFEBOOK;
454 }
455 }
456
457/*
427 * Try Kensington ThinkingMouse (we try first, because synaptics probe 458 * Try Kensington ThinkingMouse (we try first, because synaptics probe
428 * upsets the thinkingmouse). 459 * upsets the thinkingmouse).
429 */ 460 */
@@ -506,6 +537,103 @@ static int psmouse_extensions(struct psmouse *psmouse,
506 return PSMOUSE_PS2; 537 return PSMOUSE_PS2;
507} 538}
508 539
540static struct psmouse_protocol psmouse_protocols[] = {
541 {
542 .type = PSMOUSE_PS2,
543 .name = "PS/2",
544 .alias = "bare",
545 .maxproto = 1,
546 .detect = ps2bare_detect,
547 },
548 {
549 .type = PSMOUSE_PS2PP,
550 .name = "PS2++",
551 .alias = "logitech",
552 .detect = ps2pp_init,
553 },
554 {
555 .type = PSMOUSE_THINKPS,
556 .name = "ThinkPS/2",
557 .alias = "thinkps",
558 .detect = thinking_detect,
559 },
560 {
561 .type = PSMOUSE_GENPS,
562 .name = "GenPS/2",
563 .alias = "genius",
564 .detect = genius_detect,
565 },
566 {
567 .type = PSMOUSE_IMPS,
568 .name = "ImPS/2",
569 .alias = "imps",
570 .maxproto = 1,
571 .detect = intellimouse_detect,
572 },
573 {
574 .type = PSMOUSE_IMEX,
575 .name = "ImExPS/2",
576 .alias = "exps",
577 .maxproto = 1,
578 .detect = im_explorer_detect,
579 },
580 {
581 .type = PSMOUSE_SYNAPTICS,
582 .name = "SynPS/2",
583 .alias = "synaptics",
584 .detect = synaptics_detect,
585 .init = synaptics_init,
586 },
587 {
588 .type = PSMOUSE_ALPS,
589 .name = "AlpsPS/2",
590 .alias = "alps",
591 .detect = alps_detect,
592 .init = alps_init,
593 },
594 {
595 .type = PSMOUSE_LIFEBOOK,
596 .name = "LBPS/2",
597 .alias = "lifebook",
598 .init = lifebook_init,
599 },
600 {
601 .type = PSMOUSE_AUTO,
602 .name = "auto",
603 .alias = "any",
604 .maxproto = 1,
605 },
606};
607
608static struct psmouse_protocol *psmouse_protocol_by_type(enum psmouse_type type)
609{
610 int i;
611
612 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++)
613 if (psmouse_protocols[i].type == type)
614 return &psmouse_protocols[i];
615
616 WARN_ON(1);
617 return &psmouse_protocols[0];
618}
619
620static struct psmouse_protocol *psmouse_protocol_by_name(const char *name, size_t len)
621{
622 struct psmouse_protocol *p;
623 int i;
624
625 for (i = 0; i < ARRAY_SIZE(psmouse_protocols); i++) {
626 p = &psmouse_protocols[i];
627
628 if ((strlen(p->name) == len && !strncmp(p->name, name, len)) ||
629 (strlen(p->alias) == len && !strncmp(p->alias, name, len)))
630 return &psmouse_protocols[i];
631 }
632
633 return NULL;
634}
635
636
509/* 637/*
510 * psmouse_probe() probes for a PS/2 mouse. 638 * psmouse_probe() probes for a PS/2 mouse.
511 */ 639 */
@@ -653,30 +781,84 @@ static void psmouse_cleanup(struct serio *serio)
653 781
654static void psmouse_disconnect(struct serio *serio) 782static void psmouse_disconnect(struct serio *serio)
655{ 783{
656 struct psmouse *psmouse, *parent; 784 struct psmouse *psmouse, *parent = NULL;
657 785
786 psmouse = serio_get_drvdata(serio);
787
788 device_remove_file(&serio->dev, &psmouse_attr_protocol);
658 device_remove_file(&serio->dev, &psmouse_attr_rate); 789 device_remove_file(&serio->dev, &psmouse_attr_rate);
659 device_remove_file(&serio->dev, &psmouse_attr_resolution); 790 device_remove_file(&serio->dev, &psmouse_attr_resolution);
660 device_remove_file(&serio->dev, &psmouse_attr_resetafter); 791 device_remove_file(&serio->dev, &psmouse_attr_resetafter);
661 792
662 psmouse = serio_get_drvdata(serio); 793 down(&psmouse_sem);
794
663 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 795 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
664 796
665 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 797 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
666 parent = serio_get_drvdata(serio->parent); 798 parent = serio_get_drvdata(serio->parent);
667 if (parent->pt_deactivate) 799 psmouse_deactivate(parent);
668 parent->pt_deactivate(parent);
669 } 800 }
670 801
671 if (psmouse->disconnect) 802 if (psmouse->disconnect)
672 psmouse->disconnect(psmouse); 803 psmouse->disconnect(psmouse);
673 804
805 if (parent && parent->pt_deactivate)
806 parent->pt_deactivate(parent);
807
674 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 808 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
675 809
676 input_unregister_device(&psmouse->dev); 810 input_unregister_device(&psmouse->dev);
677 serio_close(serio); 811 serio_close(serio);
678 serio_set_drvdata(serio, NULL); 812 serio_set_drvdata(serio, NULL);
679 kfree(psmouse); 813 kfree(psmouse);
814
815 if (parent)
816 psmouse_activate(parent);
817
818 up(&psmouse_sem);
819}
820
821static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto)
822{
823 memset(&psmouse->dev, 0, sizeof(struct input_dev));
824
825 init_input_dev(&psmouse->dev);
826
827 psmouse->dev.private = psmouse;
828 psmouse->dev.dev = &psmouse->ps2dev.serio->dev;
829
830 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
831 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
832 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
833
834 psmouse->set_rate = psmouse_set_rate;
835 psmouse->set_resolution = psmouse_set_resolution;
836 psmouse->protocol_handler = psmouse_process_byte;
837 psmouse->pktsize = 3;
838
839 if (proto && (proto->detect || proto->init)) {
840 if (proto->detect && proto->detect(psmouse, 1) < 0)
841 return -1;
842
843 if (proto->init && proto->init(psmouse) < 0)
844 return -1;
845
846 psmouse->type = proto->type;
847 }
848 else
849 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
850
851 sprintf(psmouse->devname, "%s %s %s",
852 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
853
854 psmouse->dev.name = psmouse->devname;
855 psmouse->dev.phys = psmouse->phys;
856 psmouse->dev.id.bustype = BUS_I8042;
857 psmouse->dev.id.vendor = 0x0002;
858 psmouse->dev.id.product = psmouse->type;
859 psmouse->dev.id.version = psmouse->model;
860
861 return 0;
680} 862}
681 863
682/* 864/*
@@ -688,6 +870,8 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
688 struct psmouse *psmouse, *parent = NULL; 870 struct psmouse *psmouse, *parent = NULL;
689 int retval; 871 int retval;
690 872
873 down(&psmouse_sem);
874
691 /* 875 /*
692 * If this is a pass-through port deactivate parent so the device 876 * If this is a pass-through port deactivate parent so the device
693 * connected to this port can be successfully identified 877 * connected to this port can be successfully identified
@@ -697,20 +881,14 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
697 psmouse_deactivate(parent); 881 psmouse_deactivate(parent);
698 } 882 }
699 883
700 if (!(psmouse = kmalloc(sizeof(struct psmouse), GFP_KERNEL))) { 884 if (!(psmouse = kcalloc(1, sizeof(struct psmouse), GFP_KERNEL))) {
701 retval = -ENOMEM; 885 retval = -ENOMEM;
702 goto out; 886 goto out;
703 } 887 }
704 888
705 memset(psmouse, 0, sizeof(struct psmouse));
706
707 ps2_init(&psmouse->ps2dev, serio); 889 ps2_init(&psmouse->ps2dev, serio);
708 sprintf(psmouse->phys, "%s/input0", serio->phys); 890 sprintf(psmouse->phys, "%s/input0", serio->phys);
709 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 891
710 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
711 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
712 psmouse->dev.private = psmouse;
713 psmouse->dev.dev = &serio->dev;
714 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 892 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
715 893
716 serio_set_drvdata(serio, psmouse); 894 serio_set_drvdata(serio, psmouse);
@@ -734,25 +912,10 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
734 psmouse->resolution = psmouse_resolution; 912 psmouse->resolution = psmouse_resolution;
735 psmouse->resetafter = psmouse_resetafter; 913 psmouse->resetafter = psmouse_resetafter;
736 psmouse->smartscroll = psmouse_smartscroll; 914 psmouse->smartscroll = psmouse_smartscroll;
737 psmouse->set_rate = psmouse_set_rate;
738 psmouse->set_resolution = psmouse_set_resolution;
739 psmouse->protocol_handler = psmouse_process_byte;
740 psmouse->pktsize = 3;
741 915
742 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1); 916 psmouse_switch_protocol(psmouse, NULL);
743
744 sprintf(psmouse->devname, "%s %s %s",
745 psmouse_protocols[psmouse->type], psmouse->vendor, psmouse->name);
746
747 psmouse->dev.name = psmouse->devname;
748 psmouse->dev.phys = psmouse->phys;
749 psmouse->dev.id.bustype = BUS_I8042;
750 psmouse->dev.id.vendor = 0x0002;
751 psmouse->dev.id.product = psmouse->type;
752 psmouse->dev.id.version = psmouse->model;
753 917
754 input_register_device(&psmouse->dev); 918 input_register_device(&psmouse->dev);
755
756 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys); 919 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
757 920
758 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 921 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
@@ -762,6 +925,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
762 if (parent && parent->pt_activate) 925 if (parent && parent->pt_activate)
763 parent->pt_activate(parent); 926 parent->pt_activate(parent);
764 927
928 device_create_file(&serio->dev, &psmouse_attr_protocol);
765 device_create_file(&serio->dev, &psmouse_attr_rate); 929 device_create_file(&serio->dev, &psmouse_attr_rate);
766 device_create_file(&serio->dev, &psmouse_attr_resolution); 930 device_create_file(&serio->dev, &psmouse_attr_resolution);
767 device_create_file(&serio->dev, &psmouse_attr_resetafter); 931 device_create_file(&serio->dev, &psmouse_attr_resetafter);
@@ -771,10 +935,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
771 retval = 0; 935 retval = 0;
772 936
773out: 937out:
774 /* If this is a pass-through port the parent awaits to be activated */ 938 /* If this is a pass-through port the parent needs to be re-activated */
775 if (parent) 939 if (parent)
776 psmouse_activate(parent); 940 psmouse_activate(parent);
777 941
942 up(&psmouse_sem);
778 return retval; 943 return retval;
779} 944}
780 945
@@ -791,6 +956,8 @@ static int psmouse_reconnect(struct serio *serio)
791 return -1; 956 return -1;
792 } 957 }
793 958
959 down(&psmouse_sem);
960
794 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 961 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
795 parent = serio_get_drvdata(serio->parent); 962 parent = serio_get_drvdata(serio->parent);
796 psmouse_deactivate(parent); 963 psmouse_deactivate(parent);
@@ -823,6 +990,7 @@ out:
823 if (parent) 990 if (parent)
824 psmouse_activate(parent); 991 psmouse_activate(parent);
825 992
993 up(&psmouse_sem);
826 return rc; 994 return rc;
827} 995}
828 996
@@ -893,26 +1061,109 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
893 1061
894 if (serio->drv != &psmouse_drv) { 1062 if (serio->drv != &psmouse_drv) {
895 retval = -ENODEV; 1063 retval = -ENODEV;
896 goto out; 1064 goto out_unpin;
1065 }
1066
1067 retval = down_interruptible(&psmouse_sem);
1068 if (retval)
1069 goto out_unpin;
1070
1071 if (psmouse->state == PSMOUSE_IGNORE) {
1072 retval = -ENODEV;
1073 goto out_up;
897 } 1074 }
898 1075
899 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1076 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
900 parent = serio_get_drvdata(serio->parent); 1077 parent = serio_get_drvdata(serio->parent);
901 psmouse_deactivate(parent); 1078 psmouse_deactivate(parent);
902 } 1079 }
1080
903 psmouse_deactivate(psmouse); 1081 psmouse_deactivate(psmouse);
904 1082
905 retval = handler(psmouse, buf, count); 1083 retval = handler(psmouse, buf, count);
906 1084
907 psmouse_activate(psmouse); 1085 if (retval != -ENODEV)
1086 psmouse_activate(psmouse);
1087
908 if (parent) 1088 if (parent)
909 psmouse_activate(parent); 1089 psmouse_activate(parent);
910 1090
911out: 1091 out_up:
1092 up(&psmouse_sem);
1093 out_unpin:
912 serio_unpin_driver(serio); 1094 serio_unpin_driver(serio);
913 return retval; 1095 return retval;
914} 1096}
915 1097
1098static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, char *buf)
1099{
1100 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1101}
1102
1103static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *buf, size_t count)
1104{
1105 struct serio *serio = psmouse->ps2dev.serio;
1106 struct psmouse *parent = NULL;
1107 struct psmouse_protocol *proto;
1108 int retry = 0;
1109
1110 if (!(proto = psmouse_protocol_by_name(buf, count)))
1111 return -EINVAL;
1112
1113 if (psmouse->type == proto->type)
1114 return count;
1115
1116 while (serio->child) {
1117 if (++retry > 3) {
1118 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
1119 return -EIO;
1120 }
1121
1122 up(&psmouse_sem);
1123 serio_unpin_driver(serio);
1124 serio_unregister_child_port(serio);
1125 serio_pin_driver_uninterruptible(serio);
1126 down(&psmouse_sem);
1127
1128 if (serio->drv != &psmouse_drv)
1129 return -ENODEV;
1130
1131 if (psmouse->type == proto->type)
1132 return count; /* switched by other thread */
1133 }
1134
1135 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1136 parent = serio_get_drvdata(serio->parent);
1137 if (parent->pt_deactivate)
1138 parent->pt_deactivate(parent);
1139 }
1140
1141 if (psmouse->disconnect)
1142 psmouse->disconnect(psmouse);
1143
1144 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1145 input_unregister_device(&psmouse->dev);
1146
1147 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1148
1149 if (psmouse_switch_protocol(psmouse, proto) < 0) {
1150 psmouse_reset(psmouse);
1151 /* default to PSMOUSE_PS2 */
1152 psmouse_switch_protocol(psmouse, &psmouse_protocols[0]);
1153 }
1154
1155 psmouse_initialize(psmouse);
1156 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1157
1158 input_register_device(&psmouse->dev);
1159 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
1160
1161 if (parent && parent->pt_activate)
1162 parent->pt_activate(parent);
1163
1164 return count;
1165}
1166
916static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf) 1167static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf)
917{ 1168{
918 return sprintf(buf, "%d\n", psmouse->rate); 1169 return sprintf(buf, "%d\n", psmouse->rate);
@@ -969,34 +1220,26 @@ static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *
969 1220
970static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1221static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
971{ 1222{
972 int i; 1223 struct psmouse_protocol *proto;
973 1224
974 if (!val) 1225 if (!val)
975 return -EINVAL; 1226 return -EINVAL;
976 1227
977 if (!strncmp(val, "any", 3)) { 1228 proto = psmouse_protocol_by_name(val, strlen(val));
978 *((unsigned int *)kp->arg) = -1U;
979 return 0;
980 }
981 1229
982 for (i = 0; i < ARRAY_SIZE(psmouse_proto_abbrev); i++) { 1230 if (!proto || !proto->maxproto)
983 if (!psmouse_proto_abbrev[i]) 1231 return -EINVAL;
984 continue;
985 1232
986 if (!strncmp(val, psmouse_proto_abbrev[i], strlen(psmouse_proto_abbrev[i]))) { 1233 *((unsigned int *)kp->arg) = proto->type;
987 *((unsigned int *)kp->arg) = i;
988 return 0;
989 }
990 }
991 1234
992 return -EINVAL; \ 1235 return 0; \
993} 1236}
994 1237
995static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1238static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
996{ 1239{
997 return sprintf(buffer, "%s\n", 1240 int type = *((unsigned int *)kp->arg);
998 psmouse_max_proto < ARRAY_SIZE(psmouse_proto_abbrev) ? 1241
999 psmouse_proto_abbrev[psmouse_max_proto] : "any"); 1242 return sprintf(buffer, "%s\n", psmouse_protocol_by_type(type)->name);
1000} 1243}
1001 1244
1002static int __init psmouse_init(void) 1245static int __init psmouse_init(void)
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 79e17a0c4664..86691cf43433 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -77,6 +77,8 @@ enum psmouse_type {
77 PSMOUSE_IMEX, 77 PSMOUSE_IMEX,
78 PSMOUSE_SYNAPTICS, 78 PSMOUSE_SYNAPTICS,
79 PSMOUSE_ALPS, 79 PSMOUSE_ALPS,
80 PSMOUSE_LIFEBOOK,
81 PSMOUSE_AUTO /* This one should always be last */
80}; 82};
81 83
82int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command); 84int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
@@ -99,7 +101,7 @@ static ssize_t psmouse_do_set_##_name(struct device *d, struct device_attribute
99{ \ 101{ \
100 return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \ 102 return psmouse_attr_set_helper(d, b, s, psmouse_attr_set_##_name); \
101} \ 103} \
102static struct device_attribute psmouse_attr_##_name = \ 104static struct device_attribute psmouse_attr_##_name = \
103 __ATTR(_name, S_IWUSR | S_IRUGO, \ 105 __ATTR(_name, S_IWUSR | S_IRUGO, \
104 psmouse_do_show_##_name, psmouse_do_set_##_name); 106 psmouse_do_show_##_name, psmouse_do_set_##_name);
105 107
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index 7280f68afcee..8fe1212b8fd7 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -59,7 +59,7 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
59 b = (short) (__raw_readl(0xe0310000) ^ 0x70); 59 b = (short) (__raw_readl(0xe0310000) ^ 0x70);
60 60
61 dx = x - rpcmouse_lastx; 61 dx = x - rpcmouse_lastx;
62 dy = y - rpcmouse_lasty; 62 dy = y - rpcmouse_lasty;
63 63
64 rpcmouse_lastx = x; 64 rpcmouse_lastx = x;
65 rpcmouse_lasty = y; 65 rpcmouse_lasty = y;
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index b2cb101c8110..f024be9b44d2 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for DEC VSXXX-AA mouse (hockey-puck mouse, ball or two rollers) 2 * Driver for DEC VSXXX-AA mouse (hockey-puck mouse, ball or two rollers)
3 * DEC VSXXX-GA mouse (rectangular mouse, with ball) 3 * DEC VSXXX-GA mouse (rectangular mouse, with ball)
4 * DEC VSXXX-AB tablet (digitizer with hair cross or stylus) 4 * DEC VSXXX-AB tablet (digitizer with hair cross or stylus)
5 * 5 *
6 * Copyright (C) 2003-2004 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 6 * Copyright (C) 2003-2004 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
7 * 7 *
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 062848ac7e6b..c6194a9dd174 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -220,6 +220,7 @@ static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_h
220 struct mousedev_list *list; 220 struct mousedev_list *list;
221 struct mousedev_motion *p; 221 struct mousedev_motion *p;
222 unsigned long flags; 222 unsigned long flags;
223 int wake_readers = 0;
223 224
224 list_for_each_entry(list, &mousedev->list, node) { 225 list_for_each_entry(list, &mousedev->list, node) {
225 spin_lock_irqsave(&list->packet_lock, flags); 226 spin_lock_irqsave(&list->packet_lock, flags);
@@ -255,11 +256,14 @@ static void mousedev_notify_readers(struct mousedev *mousedev, struct mousedev_h
255 256
256 spin_unlock_irqrestore(&list->packet_lock, flags); 257 spin_unlock_irqrestore(&list->packet_lock, flags);
257 258
258 if (list->ready) 259 if (list->ready) {
259 kill_fasync(&list->fasync, SIGIO, POLL_IN); 260 kill_fasync(&list->fasync, SIGIO, POLL_IN);
261 wake_readers = 1;
262 }
260 } 263 }
261 264
262 wake_up_interruptible(&mousedev->wait); 265 if (wake_readers)
266 wake_up_interruptible(&mousedev->wait);
263} 267}
264 268
265static void mousedev_touchpad_touch(struct mousedev *mousedev, int value) 269static void mousedev_touchpad_touch(struct mousedev *mousedev, int value)
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index c978657068c5..d4c990f7c85e 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -29,6 +29,7 @@ MODULE_LICENSE("GPL");
29 29
30EXPORT_SYMBOL(ps2_init); 30EXPORT_SYMBOL(ps2_init);
31EXPORT_SYMBOL(ps2_sendbyte); 31EXPORT_SYMBOL(ps2_sendbyte);
32EXPORT_SYMBOL(ps2_drain);
32EXPORT_SYMBOL(ps2_command); 33EXPORT_SYMBOL(ps2_command);
33EXPORT_SYMBOL(ps2_schedule_command); 34EXPORT_SYMBOL(ps2_schedule_command);
34EXPORT_SYMBOL(ps2_handle_ack); 35EXPORT_SYMBOL(ps2_handle_ack);
@@ -45,11 +46,11 @@ struct ps2work {
45 46
46 47
47/* 48/*
48 * ps2_sendbyte() sends a byte to the mouse, and waits for acknowledge. 49 * ps2_sendbyte() sends a byte to the device and waits for acknowledge.
49 * It doesn't handle retransmission, though it could - because when there would 50 * It doesn't handle retransmission, though it could - because if there
50 * be need for retransmissions, the mouse has to be replaced anyway. 51 * is a need for retransmissions device has to be replaced anyway.
51 * 52 *
52 * ps2_sendbyte() can only be called from a process context 53 * ps2_sendbyte() can only be called from a process context.
53 */ 54 */
54 55
55int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout) 56int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout)
@@ -72,6 +73,91 @@ int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout)
72} 73}
73 74
74/* 75/*
76 * ps2_drain() waits for device to transmit requested number of bytes
77 * and discards them.
78 */
79
80void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
81{
82 if (maxbytes > sizeof(ps2dev->cmdbuf)) {
83 WARN_ON(1);
84 maxbytes = sizeof(ps2dev->cmdbuf);
85 }
86
87 down(&ps2dev->cmd_sem);
88
89 serio_pause_rx(ps2dev->serio);
90 ps2dev->flags = PS2_FLAG_CMD;
91 ps2dev->cmdcnt = maxbytes;
92 serio_continue_rx(ps2dev->serio);
93
94 wait_event_timeout(ps2dev->wait,
95 !(ps2dev->flags & PS2_FLAG_CMD),
96 msecs_to_jiffies(timeout));
97 up(&ps2dev->cmd_sem);
98}
99
100/*
101 * ps2_is_keyboard_id() checks received ID byte against the list of
102 * known keyboard IDs.
103 */
104
105static inline int ps2_is_keyboard_id(char id_byte)
106{
107 static char keyboard_ids[] = {
108 0xab, /* Regular keyboards */
109 0xac, /* NCD Sun keyboard */
110 0x2b, /* Trust keyboard, translated */
111 0x5d, /* Trust keyboard */
112 0x60, /* NMB SGI keyboard, translated */
113 0x47, /* NMB SGI keyboard */
114 };
115
116 return memchr(keyboard_ids, id_byte, sizeof(keyboard_ids)) != NULL;
117}
118
119/*
120 * ps2_adjust_timeout() is called after receiving 1st byte of command
121 * response and tries to reduce remaining timeout to speed up command
122 * completion.
123 */
124
125static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout)
126{
127 switch (command) {
128 case PS2_CMD_RESET_BAT:
129 /*
130 * Device has sent the first response byte after
131 * reset command, reset is thus done, so we can
132 * shorten the timeout.
133 * The next byte will come soon (keyboard) or not
134 * at all (mouse).
135 */
136 if (timeout > msecs_to_jiffies(100))
137 timeout = msecs_to_jiffies(100);
138 break;
139
140 case PS2_CMD_GETID:
141 /*
142 * If device behind the port is not a keyboard there
143 * won't be 2nd byte of ID response.
144 */
145 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) {
146 serio_pause_rx(ps2dev->serio);
147 ps2dev->flags = ps2dev->cmdcnt = 0;
148 serio_continue_rx(ps2dev->serio);
149 timeout = 0;
150 }
151 break;
152
153 default:
154 break;
155 }
156
157 return timeout;
158}
159
160/*
75 * ps2_command() sends a command and its parameters to the mouse, 161 * ps2_command() sends a command and its parameters to the mouse,
76 * then waits for the response and puts it in the param array. 162 * then waits for the response and puts it in the param array.
77 * 163 *
@@ -86,6 +172,11 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
86 int rc = -1; 172 int rc = -1;
87 int i; 173 int i;
88 174
175 if (receive > sizeof(ps2dev->cmdbuf)) {
176 WARN_ON(1);
177 return -1;
178 }
179
89 down(&ps2dev->cmd_sem); 180 down(&ps2dev->cmd_sem);
90 181
91 serio_pause_rx(ps2dev->serio); 182 serio_pause_rx(ps2dev->serio);
@@ -101,10 +192,9 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
101 * ACKing the reset command, and so it can take a long 192 * ACKing the reset command, and so it can take a long
102 * time before the ACK arrrives. 193 * time before the ACK arrrives.
103 */ 194 */
104 if (command & 0xff) 195 if (ps2_sendbyte(ps2dev, command & 0xff,
105 if (ps2_sendbyte(ps2dev, command & 0xff, 196 command == PS2_CMD_RESET_BAT ? 1000 : 200))
106 command == PS2_CMD_RESET_BAT ? 1000 : 200)) 197 goto out;
107 goto out;
108 198
109 for (i = 0; i < send; i++) 199 for (i = 0; i < send; i++)
110 if (ps2_sendbyte(ps2dev, param[i], 200)) 200 if (ps2_sendbyte(ps2dev, param[i], 200))
@@ -120,33 +210,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
120 210
121 if (ps2dev->cmdcnt && timeout > 0) { 211 if (ps2dev->cmdcnt && timeout > 0) {
122 212
123 if (command == PS2_CMD_RESET_BAT && timeout > msecs_to_jiffies(100)) { 213 timeout = ps2_adjust_timeout(ps2dev, command, timeout);
124 /*
125 * Device has sent the first response byte
126 * after a reset command, reset is thus done,
127 * shorten the timeout. The next byte will come
128 * soon (keyboard) or not at all (mouse).
129 */
130 timeout = msecs_to_jiffies(100);
131 }
132
133 if (command == PS2_CMD_GETID &&
134 ps2dev->cmdbuf[receive - 1] != 0xab && /* Regular keyboards */
135 ps2dev->cmdbuf[receive - 1] != 0xac && /* NCD Sun keyboard */
136 ps2dev->cmdbuf[receive - 1] != 0x2b && /* Trust keyboard, translated */
137 ps2dev->cmdbuf[receive - 1] != 0x5d && /* Trust keyboard */
138 ps2dev->cmdbuf[receive - 1] != 0x60 && /* NMB SGI keyboard, translated */
139 ps2dev->cmdbuf[receive - 1] != 0x47) { /* NMB SGI keyboard */
140 /*
141 * Device behind the port is not a keyboard
142 * so we don't need to wait for the 2nd byte
143 * of ID response.
144 */
145 serio_pause_rx(ps2dev->serio);
146 ps2dev->flags = ps2dev->cmdcnt = 0;
147 serio_continue_rx(ps2dev->serio);
148 }
149
150 wait_event_timeout(ps2dev->wait, 214 wait_event_timeout(ps2dev->wait,
151 !(ps2dev->flags & PS2_FLAG_CMD), timeout); 215 !(ps2dev->flags & PS2_FLAG_CMD), timeout);
152 } 216 }
@@ -160,7 +224,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
160 224
161 rc = 0; 225 rc = 0;
162 226
163out: 227 out:
164 serio_pause_rx(ps2dev->serio); 228 serio_pause_rx(ps2dev->serio);
165 ps2dev->flags = 0; 229 ps2dev->flags = 0;
166 serio_continue_rx(ps2dev->serio); 230 serio_continue_rx(ps2dev->serio);
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 341824c48529..f367695e69b5 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -31,10 +31,9 @@
31#include <linux/serio.h> 31#include <linux/serio.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/wait.h> 33#include <linux/wait.h>
34#include <linux/completion.h>
35#include <linux/sched.h> 34#include <linux/sched.h>
36#include <linux/smp_lock.h>
37#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/kthread.h>
38 37
39MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 38MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40MODULE_DESCRIPTION("Serio abstraction core"); 39MODULE_DESCRIPTION("Serio abstraction core");
@@ -43,6 +42,7 @@ MODULE_LICENSE("GPL");
43EXPORT_SYMBOL(serio_interrupt); 42EXPORT_SYMBOL(serio_interrupt);
44EXPORT_SYMBOL(__serio_register_port); 43EXPORT_SYMBOL(__serio_register_port);
45EXPORT_SYMBOL(serio_unregister_port); 44EXPORT_SYMBOL(serio_unregister_port);
45EXPORT_SYMBOL(serio_unregister_child_port);
46EXPORT_SYMBOL(__serio_unregister_port_delayed); 46EXPORT_SYMBOL(__serio_unregister_port_delayed);
47EXPORT_SYMBOL(__serio_register_driver); 47EXPORT_SYMBOL(__serio_register_driver);
48EXPORT_SYMBOL(serio_unregister_driver); 48EXPORT_SYMBOL(serio_unregister_driver);
@@ -68,6 +68,37 @@ static void serio_destroy_port(struct serio *serio);
68static void serio_reconnect_port(struct serio *serio); 68static void serio_reconnect_port(struct serio *serio);
69static void serio_disconnect_port(struct serio *serio); 69static void serio_disconnect_port(struct serio *serio);
70 70
71static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
72{
73 int retval;
74
75 down(&serio->drv_sem);
76 retval = drv->connect(serio, drv);
77 up(&serio->drv_sem);
78
79 return retval;
80}
81
82static int serio_reconnect_driver(struct serio *serio)
83{
84 int retval = -1;
85
86 down(&serio->drv_sem);
87 if (serio->drv && serio->drv->reconnect)
88 retval = serio->drv->reconnect(serio);
89 up(&serio->drv_sem);
90
91 return retval;
92}
93
94static void serio_disconnect_driver(struct serio *serio)
95{
96 down(&serio->drv_sem);
97 if (serio->drv)
98 serio->drv->disconnect(serio);
99 up(&serio->drv_sem);
100}
101
71static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) 102static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
72{ 103{
73 while (ids->type || ids->proto) { 104 while (ids->type || ids->proto) {
@@ -91,7 +122,7 @@ static void serio_bind_driver(struct serio *serio, struct serio_driver *drv)
91 122
92 if (serio_match_port(drv->id_table, serio)) { 123 if (serio_match_port(drv->id_table, serio)) {
93 serio->dev.driver = &drv->driver; 124 serio->dev.driver = &drv->driver;
94 if (drv->connect(serio, drv)) { 125 if (serio_connect_driver(serio, drv)) {
95 serio->dev.driver = NULL; 126 serio->dev.driver = NULL;
96 goto out; 127 goto out;
97 } 128 }
@@ -138,8 +169,7 @@ struct serio_event {
138static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */ 169static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */
139static LIST_HEAD(serio_event_list); 170static LIST_HEAD(serio_event_list);
140static DECLARE_WAIT_QUEUE_HEAD(serio_wait); 171static DECLARE_WAIT_QUEUE_HEAD(serio_wait);
141static DECLARE_COMPLETION(serio_exited); 172static struct task_struct *serio_task;
142static int serio_pid;
143 173
144static void serio_queue_event(void *object, struct module *owner, 174static void serio_queue_event(void *object, struct module *owner,
145 enum serio_event_type event_type) 175 enum serio_event_type event_type)
@@ -150,12 +180,12 @@ static void serio_queue_event(void *object, struct module *owner,
150 spin_lock_irqsave(&serio_event_lock, flags); 180 spin_lock_irqsave(&serio_event_lock, flags);
151 181
152 /* 182 /*
153 * Scan event list for the other events for the same serio port, 183 * Scan event list for the other events for the same serio port,
154 * starting with the most recent one. If event is the same we 184 * starting with the most recent one. If event is the same we
155 * do not need add new one. If event is of different type we 185 * do not need add new one. If event is of different type we
156 * need to add this event and should not look further because 186 * need to add this event and should not look further because
157 * we need to preseve sequence of distinct events. 187 * we need to preseve sequence of distinct events.
158 */ 188 */
159 list_for_each_entry_reverse(event, &serio_event_list, node) { 189 list_for_each_entry_reverse(event, &serio_event_list, node) {
160 if (event->object == object) { 190 if (event->object == object) {
161 if (event->type == event_type) 191 if (event->type == event_type)
@@ -337,20 +367,15 @@ static struct serio *serio_get_pending_child(struct serio *parent)
337 367
338static int serio_thread(void *nothing) 368static int serio_thread(void *nothing)
339{ 369{
340 lock_kernel();
341 daemonize("kseriod");
342 allow_signal(SIGTERM);
343
344 do { 370 do {
345 serio_handle_events(); 371 serio_handle_events();
346 wait_event_interruptible(serio_wait, !list_empty(&serio_event_list)); 372 wait_event_interruptible(serio_wait,
373 kthread_should_stop() || !list_empty(&serio_event_list));
347 try_to_freeze(); 374 try_to_freeze();
348 } while (!signal_pending(current)); 375 } while (!kthread_should_stop());
349 376
350 printk(KERN_DEBUG "serio: kseriod exiting\n"); 377 printk(KERN_DEBUG "serio: kseriod exiting\n");
351 378 return 0;
352 unlock_kernel();
353 complete_and_exit(&serio_exited, 0);
354} 379}
355 380
356 381
@@ -557,7 +582,7 @@ static void serio_destroy_port(struct serio *serio)
557static void serio_reconnect_port(struct serio *serio) 582static void serio_reconnect_port(struct serio *serio)
558{ 583{
559 do { 584 do {
560 if (!serio->drv || !serio->drv->reconnect || serio->drv->reconnect(serio)) { 585 if (serio_reconnect_driver(serio)) {
561 serio_disconnect_port(serio); 586 serio_disconnect_port(serio);
562 serio_find_driver(serio); 587 serio_find_driver(serio);
563 /* Ok, old children are now gone, we are done */ 588 /* Ok, old children are now gone, we are done */
@@ -630,6 +655,19 @@ void serio_unregister_port(struct serio *serio)
630} 655}
631 656
632/* 657/*
658 * Safely unregisters child port if one is present.
659 */
660void serio_unregister_child_port(struct serio *serio)
661{
662 down(&serio_sem);
663 if (serio->child) {
664 serio_disconnect_port(serio->child);
665 serio_destroy_port(serio->child);
666 }
667 up(&serio_sem);
668}
669
670/*
633 * Submits register request to kseriod for subsequent execution. 671 * Submits register request to kseriod for subsequent execution.
634 * Can be used when it is not obvious whether the serio_sem is 672 * Can be used when it is not obvious whether the serio_sem is
635 * taken or not and when delayed execution is feasible. 673 * taken or not and when delayed execution is feasible.
@@ -686,15 +724,14 @@ static int serio_driver_probe(struct device *dev)
686 struct serio *serio = to_serio_port(dev); 724 struct serio *serio = to_serio_port(dev);
687 struct serio_driver *drv = to_serio_driver(dev->driver); 725 struct serio_driver *drv = to_serio_driver(dev->driver);
688 726
689 return drv->connect(serio, drv); 727 return serio_connect_driver(serio, drv);
690} 728}
691 729
692static int serio_driver_remove(struct device *dev) 730static int serio_driver_remove(struct device *dev)
693{ 731{
694 struct serio *serio = to_serio_port(dev); 732 struct serio *serio = to_serio_port(dev);
695 struct serio_driver *drv = to_serio_driver(dev->driver);
696 733
697 drv->disconnect(serio); 734 serio_disconnect_driver(serio);
698 return 0; 735 return 0;
699} 736}
700 737
@@ -730,11 +767,9 @@ start_over:
730 767
731static void serio_set_drv(struct serio *serio, struct serio_driver *drv) 768static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
732{ 769{
733 down(&serio->drv_sem);
734 serio_pause_rx(serio); 770 serio_pause_rx(serio);
735 serio->drv = drv; 771 serio->drv = drv;
736 serio_continue_rx(serio); 772 serio_continue_rx(serio);
737 up(&serio->drv_sem);
738} 773}
739 774
740static int serio_bus_match(struct device *dev, struct device_driver *drv) 775static int serio_bus_match(struct device *dev, struct device_driver *drv)
@@ -794,7 +829,7 @@ static int serio_resume(struct device *dev)
794{ 829{
795 struct serio *serio = to_serio_port(dev); 830 struct serio *serio = to_serio_port(dev);
796 831
797 if (!serio->drv || !serio->drv->reconnect || serio->drv->reconnect(serio)) { 832 if (serio_reconnect_driver(serio)) {
798 /* 833 /*
799 * Driver re-probing can take a while, so better let kseriod 834 * Driver re-probing can take a while, so better let kseriod
800 * deal with it. 835 * deal with it.
@@ -848,9 +883,10 @@ irqreturn_t serio_interrupt(struct serio *serio,
848 883
849static int __init serio_init(void) 884static int __init serio_init(void)
850{ 885{
851 if (!(serio_pid = kernel_thread(serio_thread, NULL, CLONE_KERNEL))) { 886 serio_task = kthread_run(serio_thread, NULL, "kseriod");
887 if (IS_ERR(serio_task)) {
852 printk(KERN_ERR "serio: Failed to start kseriod\n"); 888 printk(KERN_ERR "serio: Failed to start kseriod\n");
853 return -1; 889 return PTR_ERR(serio_task);
854 } 890 }
855 891
856 serio_bus.dev_attrs = serio_device_attrs; 892 serio_bus.dev_attrs = serio_device_attrs;
@@ -866,8 +902,7 @@ static int __init serio_init(void)
866static void __exit serio_exit(void) 902static void __exit serio_exit(void)
867{ 903{
868 bus_unregister(&serio_bus); 904 bus_unregister(&serio_bus);
869 kill_proc(serio_pid, SIGTERM, 1); 905 kthread_stop(serio_task);
870 wait_for_completion(&serio_exited);
871} 906}
872 907
873module_init(serio_init); 908module_init(serio_init);
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 546ce599334e..3cdc9cab688d 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -226,7 +226,7 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0);
227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0); 227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0);
228 break; 228 break;
229 229
230 case 1: /* 6-byte protocol */ 230 case 1: /* 6-byte protocol */
231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0); 231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0);
232 232
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index acb9137a0226..bcfa1e36f957 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -89,9 +89,9 @@ MODULE_LICENSE("GPL");
89#define H3600_SCANCODE_Q 4 /* 4 -> Q button */ 89#define H3600_SCANCODE_Q 4 /* 4 -> Q button */
90#define H3600_SCANCODE_START 5 /* 5 -> start menu */ 90#define H3600_SCANCODE_START 5 /* 5 -> start menu */
91#define H3600_SCANCODE_UP 6 /* 6 -> up */ 91#define H3600_SCANCODE_UP 6 /* 6 -> up */
92#define H3600_SCANCODE_RIGHT 7 /* 7 -> right */ 92#define H3600_SCANCODE_RIGHT 7 /* 7 -> right */
93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */ 93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */
94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */ 94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */
95 95
96static char *h3600_name = "H3600 TouchScreen"; 96static char *h3600_name = "H3600 TouchScreen";
97 97
@@ -113,7 +113,7 @@ struct h3600_dev {
113 113
114static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *regs) 114static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *regs)
115{ 115{
116 int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1; 116 int down = (GPLR & GPIO_BITSY_ACTION_BUTTON) ? 0 : 1;
117 struct input_dev *dev = (struct input_dev *) dev_id; 117 struct input_dev *dev = (struct input_dev *) dev_id;
118 118
119 input_regs(dev, regs); 119 input_regs(dev, regs);
@@ -125,7 +125,7 @@ static irqreturn_t action_button_handler(int irq, void *dev_id, struct pt_regs *
125 125
126static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *regs) 126static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *regs)
127{ 127{
128 int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1; 128 int down = (GPLR & GPIO_BITSY_NPOWER_BUTTON) ? 0 : 1;
129 struct input_dev *dev = (struct input_dev *) dev_id; 129 struct input_dev *dev = (struct input_dev *) dev_id;
130 130
131 /* 131 /*
@@ -145,8 +145,8 @@ static irqreturn_t npower_button_handler(int irq, void *dev_id, struct pt_regs *
145static int flite_brightness = 25; 145static int flite_brightness = 25;
146 146
147enum flite_pwr { 147enum flite_pwr {
148 FLITE_PWR_OFF = 0, 148 FLITE_PWR_OFF = 0,
149 FLITE_PWR_ON = 1 149 FLITE_PWR_ON = 1
150}; 150};
151 151
152/* 152/*
@@ -157,9 +157,9 @@ unsigned int h3600_flite_power(struct input_dev *dev, enum flite_pwr pwr)
157 struct h3600_dev *ts = dev->private; 157 struct h3600_dev *ts = dev->private;
158 158
159 /* Must be in this order */ 159 /* Must be in this order */
160 ts->serio->write(ts->serio, 1); 160 ts->serio->write(ts->serio, 1);
161 ts->serio->write(ts->serio, pwr); 161 ts->serio->write(ts->serio, pwr);
162 ts->serio->write(ts->serio, brightness); 162 ts->serio->write(ts->serio, brightness);
163 return 0; 163 return 0;
164} 164}
165 165
@@ -169,26 +169,26 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
169{ 169{
170 struct input_dev *dev = (struct input_dev *) data; 170 struct input_dev *dev = (struct input_dev *) data;
171 171
172 switch (req) { 172 switch (req) {
173 case PM_SUSPEND: /* enter D1-D3 */ 173 case PM_SUSPEND: /* enter D1-D3 */
174 suspended = 1; 174 suspended = 1;
175 h3600_flite_power(dev, FLITE_PWR_OFF); 175 h3600_flite_power(dev, FLITE_PWR_OFF);
176 break; 176 break;
177 case PM_BLANK: 177 case PM_BLANK:
178 if (!suspended) 178 if (!suspended)
179 h3600_flite_power(dev, FLITE_PWR_OFF); 179 h3600_flite_power(dev, FLITE_PWR_OFF);
180 break; 180 break;
181 case PM_RESUME: /* enter D0 */ 181 case PM_RESUME: /* enter D0 */
182 /* same as unblank */ 182 /* same as unblank */
183 case PM_UNBLANK: 183 case PM_UNBLANK:
184 if (suspended) { 184 if (suspended) {
185 //initSerial(); 185 //initSerial();
186 suspended = 0; 186 suspended = 0;
187 } 187 }
188 h3600_flite_power(dev, FLITE_PWR_ON); 188 h3600_flite_power(dev, FLITE_PWR_ON);
189 break; 189 break;
190 } 190 }
191 return 0; 191 return 0;
192} 192}
193#endif 193#endif
194 194
@@ -199,25 +199,25 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
199 */ 199 */
200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs) 200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
201{ 201{
202 struct input_dev *dev = &ts->dev; 202 struct input_dev *dev = &ts->dev;
203 static int touched = 0; 203 static int touched = 0;
204 int key, down = 0; 204 int key, down = 0;
205 205
206 input_regs(dev, regs); 206 input_regs(dev, regs);
207 207
208 switch (ts->event) { 208 switch (ts->event) {
209 /* 209 /*
210 Buttons - returned as a single byte 210 Buttons - returned as a single byte
211 7 6 5 4 3 2 1 0 211 7 6 5 4 3 2 1 0
212 S x x x N N N N 212 S x x x N N N N
213 213
214 S switch state ( 0=pressed 1=released) 214 S switch state ( 0=pressed 1=released)
215 x Unused. 215 x Unused.
216 NNNN switch number 0-15 216 NNNN switch number 0-15
217 217
218 Note: This is true for non interrupt generated key events. 218 Note: This is true for non interrupt generated key events.
219 */ 219 */
220 case KEYBD_ID: 220 case KEYBD_ID:
221 down = (ts->buf[0] & 0x80) ? 0 : 1; 221 down = (ts->buf[0] & 0x80) ? 0 : 1;
222 222
223 switch (ts->buf[0] & 0x7f) { 223 switch (ts->buf[0] & 0x7f) {
@@ -229,40 +229,40 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
229 break; 229 break;
230 case H3600_SCANCODE_CONTACTS: 230 case H3600_SCANCODE_CONTACTS:
231 key = KEY_PROG2; 231 key = KEY_PROG2;
232 break; 232 break;
233 case H3600_SCANCODE_Q: 233 case H3600_SCANCODE_Q:
234 key = KEY_Q; 234 key = KEY_Q;
235 break; 235 break;
236 case H3600_SCANCODE_START: 236 case H3600_SCANCODE_START:
237 key = KEY_PROG3; 237 key = KEY_PROG3;
238 break; 238 break;
239 case H3600_SCANCODE_UP: 239 case H3600_SCANCODE_UP:
240 key = KEY_UP; 240 key = KEY_UP;
241 break; 241 break;
242 case H3600_SCANCODE_RIGHT: 242 case H3600_SCANCODE_RIGHT:
243 key = KEY_RIGHT; 243 key = KEY_RIGHT;
244 break; 244 break;
245 case H3600_SCANCODE_LEFT: 245 case H3600_SCANCODE_LEFT:
246 key = KEY_LEFT; 246 key = KEY_LEFT;
247 break; 247 break;
248 case H3600_SCANCODE_DOWN: 248 case H3600_SCANCODE_DOWN:
249 key = KEY_DOWN; 249 key = KEY_DOWN;
250 break; 250 break;
251 default: 251 default:
252 key = 0; 252 key = 0;
253 } 253 }
254 if (key) 254 if (key)
255 input_report_key(dev, key, down); 255 input_report_key(dev, key, down);
256 break; 256 break;
257 /* 257 /*
258 * Native touchscreen event data is formatted as shown below:- 258 * Native touchscreen event data is formatted as shown below:-
259 * 259 *
260 * +-------+-------+-------+-------+ 260 * +-------+-------+-------+-------+
261 * | Xmsb | Xlsb | Ymsb | Ylsb | 261 * | Xmsb | Xlsb | Ymsb | Ylsb |
262 * +-------+-------+-------+-------+ 262 * +-------+-------+-------+-------+
263 * byte 0 1 2 3 263 * byte 0 1 2 3
264 */ 264 */
265 case TOUCHS_ID: 265 case TOUCHS_ID:
266 if (!touched) { 266 if (!touched) {
267 input_report_key(dev, BTN_TOUCH, 1); 267 input_report_key(dev, BTN_TOUCH, 1);
268 touched = 1; 268 touched = 1;
@@ -272,19 +272,19 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
272 unsigned short x, y; 272 unsigned short x, y;
273 273
274 x = ts->buf[0]; x <<= 8; x += ts->buf[1]; 274 x = ts->buf[0]; x <<= 8; x += ts->buf[1];
275 y = ts->buf[2]; y <<= 8; y += ts->buf[3]; 275 y = ts->buf[2]; y <<= 8; y += ts->buf[3];
276 276
277 input_report_abs(dev, ABS_X, x); 277 input_report_abs(dev, ABS_X, x);
278 input_report_abs(dev, ABS_Y, y); 278 input_report_abs(dev, ABS_Y, y);
279 } else { 279 } else {
280 input_report_key(dev, BTN_TOUCH, 0); 280 input_report_key(dev, BTN_TOUCH, 0);
281 touched = 0; 281 touched = 0;
282 } 282 }
283 break; 283 break;
284 default: 284 default:
285 /* Send a non input event elsewhere */ 285 /* Send a non input event elsewhere */
286 break; 286 break;
287 } 287 }
288 288
289 input_sync(dev); 289 input_sync(dev);
290} 290}
@@ -293,7 +293,7 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
293 * h3600ts_event() handles events from the input module. 293 * h3600ts_event() handles events from the input module.
294 */ 294 */
295static int h3600ts_event(struct input_dev *dev, unsigned int type, 295static int h3600ts_event(struct input_dev *dev, unsigned int type,
296 unsigned int code, int value) 296 unsigned int code, int value)
297{ 297{
298 struct h3600_dev *ts = dev->private; 298 struct h3600_dev *ts = dev->private;
299 299
@@ -332,41 +332,41 @@ static int state;
332static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data, 332static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data,
333 unsigned int flags, struct pt_regs *regs) 333 unsigned int flags, struct pt_regs *regs)
334{ 334{
335 struct h3600_dev *ts = serio_get_drvdata(serio); 335 struct h3600_dev *ts = serio_get_drvdata(serio);
336 336
337 /* 337 /*
338 * We have a new frame coming in. 338 * We have a new frame coming in.
339 */ 339 */
340 switch (state) { 340 switch (state) {
341 case STATE_SOF: 341 case STATE_SOF:
342 if (data == CHAR_SOF) 342 if (data == CHAR_SOF)
343 state = STATE_ID; 343 state = STATE_ID;
344 break; 344 break;
345 case STATE_ID: 345 case STATE_ID:
346 ts->event = (data & 0xf0) >> 4; 346 ts->event = (data & 0xf0) >> 4;
347 ts->len = (data & 0xf); 347 ts->len = (data & 0xf);
348 ts->idx = 0; 348 ts->idx = 0;
349 if (ts->event >= MAX_ID) { 349 if (ts->event >= MAX_ID) {
350 state = STATE_SOF; 350 state = STATE_SOF;
351 break; 351 break;
352 } 352 }
353 ts->chksum = data; 353 ts->chksum = data;
354 state = (ts->len > 0) ? STATE_DATA : STATE_EOF; 354 state = (ts->len > 0) ? STATE_DATA : STATE_EOF;
355 break; 355 break;
356 case STATE_DATA: 356 case STATE_DATA:
357 ts->chksum += data; 357 ts->chksum += data;
358 ts->buf[ts->idx]= data; 358 ts->buf[ts->idx]= data;
359 if(++ts->idx == ts->len) 359 if (++ts->idx == ts->len)
360 state = STATE_EOF; 360 state = STATE_EOF;
361 break; 361 break;
362 case STATE_EOF: 362 case STATE_EOF:
363 state = STATE_SOF; 363 state = STATE_SOF;
364 if (data == CHAR_EOF || data == ts->chksum) 364 if (data == CHAR_EOF || data == ts->chksum)
365 h3600ts_process_packet(ts, regs); 365 h3600ts_process_packet(ts, regs);
366 break; 366 break;
367 default: 367 default:
368 printk("Error3\n"); 368 printk("Error3\n");
369 break; 369 break;
370 } 370 }
371 371
372 return IRQ_HANDLED; 372 return IRQ_HANDLED;
@@ -390,10 +390,10 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
390 init_input_dev(&ts->dev); 390 init_input_dev(&ts->dev);
391 391
392 /* Device specific stuff */ 392 /* Device specific stuff */
393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); 393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES);
394 set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE); 394 set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE);
395 395
396 if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler, 396 if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler,
397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
398 "h3600_action", &ts->dev)) { 398 "h3600_action", &ts->dev)) {
399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); 399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n");
@@ -401,7 +401,7 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
401 return -EBUSY; 401 return -EBUSY;
402 } 402 }
403 403
404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, 404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler,
405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
406 "h3600_suspend", &ts->dev)) { 406 "h3600_suspend", &ts->dev)) {
407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev); 407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
@@ -433,7 +433,7 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
433 433
434 sprintf(ts->phys, "%s/input0", serio->phys); 434 sprintf(ts->phys, "%s/input0", serio->phys);
435 435
436 ts->dev.event = h3600ts_event; 436 ts->dev.event = h3600ts_event;
437 ts->dev.private = ts; 437 ts->dev.private = ts;
438 ts->dev.name = h3600_name; 438 ts->dev.name = h3600_name;
439 ts->dev.phys = ts->phys; 439 ts->dev.phys = ts->phys;
@@ -446,8 +446,8 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
446 446
447 err = serio_open(serio, drv); 447 err = serio_open(serio, drv);
448 if (err) { 448 if (err) {
449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts); 449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts);
450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts); 450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts);
451 serio_set_drvdata(serio, NULL); 451 serio_set_drvdata(serio, NULL);
452 kfree(ts); 452 kfree(ts);
453 return err; 453 return err;
diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
index 2d14a57a05e5..afaaebe5225b 100644
--- a/drivers/input/touchscreen/mk712.c
+++ b/drivers/input/touchscreen/mk712.c
@@ -17,7 +17,7 @@
17 * found in Gateway AOL Connected Touchpad computers. 17 * found in Gateway AOL Connected Touchpad computers.
18 * 18 *
19 * Documentation for ICS MK712 can be found at: 19 * Documentation for ICS MK712 can be found at:
20 * http://www.icst.com/pdf/mk712.pdf 20 * http://www.icst.com/pdf/mk712.pdf
21 */ 21 */
22 22
23/* 23/*
@@ -77,7 +77,6 @@ MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
77#define MK712_READ_ONE_POINT 0x20 77#define MK712_READ_ONE_POINT 0x20
78#define MK712_POWERUP 0x40 78#define MK712_POWERUP 0x40
79 79
80static int mk712_used = 0;
81static struct input_dev mk712_dev; 80static struct input_dev mk712_dev;
82static DEFINE_SPINLOCK(mk712_lock); 81static DEFINE_SPINLOCK(mk712_lock);
83 82
@@ -130,17 +129,14 @@ static int mk712_open(struct input_dev *dev)
130 129
131 spin_lock_irqsave(&mk712_lock, flags); 130 spin_lock_irqsave(&mk712_lock, flags);
132 131
133 if (!mk712_used++) { 132 outb(0, mk712_io + MK712_CONTROL); /* Reset */
134 133
135 outb(0, mk712_io + MK712_CONTROL); /* Reset */ 134 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
135 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
136 MK712_ENABLE_PERIODIC_CONVERSIONS |
137 MK712_POWERUP, mk712_io + MK712_CONTROL);
136 138
137 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE | 139 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
138 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
139 MK712_ENABLE_PERIODIC_CONVERSIONS |
140 MK712_POWERUP, mk712_io + MK712_CONTROL);
141
142 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
143 }
144 140
145 spin_unlock_irqrestore(&mk712_lock, flags); 141 spin_unlock_irqrestore(&mk712_lock, flags);
146 142
@@ -153,8 +149,7 @@ static void mk712_close(struct input_dev *dev)
153 149
154 spin_lock_irqsave(&mk712_lock, flags); 150 spin_lock_irqsave(&mk712_lock, flags);
155 151
156 if (!--mk712_used) 152 outb(0, mk712_io + MK712_CONTROL);
157 outb(0, mk712_io + MK712_CONTROL);
158 153
159 spin_unlock_irqrestore(&mk712_lock, flags); 154 spin_unlock_irqrestore(&mk712_lock, flags);
160} 155}
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index dc00c85e3e35..db9bad2b3d16 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -22,7 +22,6 @@
22#include <asm/io.h> 22#include <asm/io.h>
23#include <asm/system.h> 23#include <asm/system.h>
24 24
25#include <pcmcia/version.h>
26#include <pcmcia/cs_types.h> 25#include <pcmcia/cs_types.h>
27#include <pcmcia/cs.h> 26#include <pcmcia/cs.h>
28#include <pcmcia/cistpl.h> 27#include <pcmcia/cistpl.h>
@@ -161,11 +160,6 @@ static dev_link_t *avmcs_attach(void)
161 link->next = dev_list; 160 link->next = dev_list;
162 dev_list = link; 161 dev_list = link;
163 client_reg.dev_info = &dev_info; 162 client_reg.dev_info = &dev_info;
164 client_reg.EventMask =
165 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
166 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
167 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
168 client_reg.event_handler = &avmcs_event;
169 client_reg.Version = 0x0210; 163 client_reg.Version = 0x0210;
170 client_reg.event_callback_args.client_data = link; 164 client_reg.event_callback_args.client_data = link;
171 ret = pcmcia_register_client(&link->handle, &client_reg); 165 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -486,13 +480,23 @@ static int avmcs_event(event_t event, int priority,
486 return 0; 480 return 0;
487} /* avmcs_event */ 481} /* avmcs_event */
488 482
483static struct pcmcia_device_id avmcs_ids[] = {
484 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
485 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
486 PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
487 PCMCIA_DEVICE_NULL
488};
489MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
490
489static struct pcmcia_driver avmcs_driver = { 491static struct pcmcia_driver avmcs_driver = {
490 .owner = THIS_MODULE, 492 .owner = THIS_MODULE,
491 .drv = { 493 .drv = {
492 .name = "avm_cs", 494 .name = "avm_cs",
493 }, 495 },
494 .attach = avmcs_attach, 496 .attach = avmcs_attach,
497 .event = avmcs_event,
495 .detach = avmcs_detach, 498 .detach = avmcs_detach,
499 .id_table = avmcs_ids,
496}; 500};
497 501
498static int __init avmcs_init(void) 502static int __init avmcs_init(void)
diff --git a/drivers/isdn/hardware/eicon/dadapter.c b/drivers/isdn/hardware/eicon/dadapter.c
index 6e548a222ef1..89497890158d 100644
--- a/drivers/isdn/hardware/eicon/dadapter.c
+++ b/drivers/isdn/hardware/eicon/dadapter.c
@@ -44,7 +44,7 @@ static didd_adapter_change_notification_t\
44 Array to held adapter information 44 Array to held adapter information
45 -------------------------------------------------------------------------- */ 45 -------------------------------------------------------------------------- */
46static DESCRIPTOR HandleTable[NEW_MAX_DESCRIPTORS]; 46static DESCRIPTOR HandleTable[NEW_MAX_DESCRIPTORS];
47dword Adapters = 0; /* Number of adapters */ 47static dword Adapters = 0; /* Number of adapters */
48/* -------------------------------------------------------------------------- 48/* --------------------------------------------------------------------------
49 Shadow IDI_DIMAINT 49 Shadow IDI_DIMAINT
50 and 'shadow' debug stuff 50 and 'shadow' debug stuff
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 663a0bf703b7..0e22991635e7 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -21,7 +21,6 @@
21#include <asm/io.h> 21#include <asm/io.h>
22#include <asm/system.h> 22#include <asm/system.h>
23 23
24#include <pcmcia/version.h>
25#include <pcmcia/cs_types.h> 24#include <pcmcia/cs_types.h>
26#include <pcmcia/cs.h> 25#include <pcmcia/cs.h>
27#include <pcmcia/cistpl.h> 26#include <pcmcia/cistpl.h>
@@ -183,11 +182,6 @@ static dev_link_t *avma1cs_attach(void)
183 link->next = dev_list; 182 link->next = dev_list;
184 dev_list = link; 183 dev_list = link;
185 client_reg.dev_info = &dev_info; 184 client_reg.dev_info = &dev_info;
186 client_reg.EventMask =
187 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
188 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
189 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
190 client_reg.event_handler = &avma1cs_event;
191 client_reg.Version = 0x0210; 185 client_reg.Version = 0x0210;
192 client_reg.event_callback_args.client_data = link; 186 client_reg.event_callback_args.client_data = link;
193 ret = pcmcia_register_client(&link->handle, &client_reg); 187 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -501,13 +495,22 @@ static int avma1cs_event(event_t event, int priority,
501 return 0; 495 return 0;
502} /* avma1cs_event */ 496} /* avma1cs_event */
503 497
498static struct pcmcia_device_id avma1cs_ids[] = {
499 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
500 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
501 PCMCIA_DEVICE_NULL
502};
503MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
504
504static struct pcmcia_driver avma1cs_driver = { 505static struct pcmcia_driver avma1cs_driver = {
505 .owner = THIS_MODULE, 506 .owner = THIS_MODULE,
506 .drv = { 507 .drv = {
507 .name = "avma1_cs", 508 .name = "avma1_cs",
508 }, 509 },
509 .attach = avma1cs_attach, 510 .attach = avma1cs_attach,
511 .event = avma1cs_event,
510 .detach = avma1cs_detach, 512 .detach = avma1cs_detach,
513 .id_table = avma1cs_ids,
511}; 514};
512 515
513/*====================================================================*/ 516/*====================================================================*/
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index bfc013225f46..6fc6868de0b0 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -47,7 +47,6 @@
47#include <asm/io.h> 47#include <asm/io.h>
48#include <asm/system.h> 48#include <asm/system.h>
49 49
50#include <pcmcia/version.h>
51#include <pcmcia/cs_types.h> 50#include <pcmcia/cs_types.h>
52#include <pcmcia/cs.h> 51#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
@@ -212,11 +211,6 @@ static dev_link_t *elsa_cs_attach(void)
212 link->next = dev_list; 211 link->next = dev_list;
213 dev_list = link; 212 dev_list = link;
214 client_reg.dev_info = &dev_info; 213 client_reg.dev_info = &dev_info;
215 client_reg.EventMask =
216 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
217 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
218 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
219 client_reg.event_handler = &elsa_cs_event;
220 client_reg.Version = 0x0210; 214 client_reg.Version = 0x0210;
221 client_reg.event_callback_args.client_data = link; 215 client_reg.event_callback_args.client_data = link;
222 ret = pcmcia_register_client(&link->handle, &client_reg); 216 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -508,13 +502,22 @@ static int elsa_cs_event(event_t event, int priority,
508 return 0; 502 return 0;
509} /* elsa_cs_event */ 503} /* elsa_cs_event */
510 504
505static struct pcmcia_device_id elsa_ids[] = {
506 PCMCIA_DEVICE_PROD_ID12("ELSA AG (Aachen, Germany)", "MicroLink ISDN/MC ", 0x983de2c4, 0x333ba257),
507 PCMCIA_DEVICE_PROD_ID12("ELSA GmbH, Aachen", "MicroLink ISDN/MC ", 0x639e5718, 0x333ba257),
508 PCMCIA_DEVICE_NULL
509};
510MODULE_DEVICE_TABLE(pcmcia, elsa_ids);
511
511static struct pcmcia_driver elsa_cs_driver = { 512static struct pcmcia_driver elsa_cs_driver = {
512 .owner = THIS_MODULE, 513 .owner = THIS_MODULE,
513 .drv = { 514 .drv = {
514 .name = "elsa_cs", 515 .name = "elsa_cs",
515 }, 516 },
516 .attach = elsa_cs_attach, 517 .attach = elsa_cs_attach,
518 .event = elsa_cs_event,
517 .detach = elsa_cs_detach, 519 .detach = elsa_cs_detach,
520 .id_table = elsa_ids,
518}; 521};
519 522
520static int __init init_elsa_cs(void) 523static int __init init_elsa_cs(void)
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 6e7e060716b7..7333377ab31d 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -312,7 +312,7 @@ wait_busy(hfc4s8s_hw * a)
312/* function to read critical counter registers that */ 312/* function to read critical counter registers that */
313/* may be udpated by the chip during read */ 313/* may be udpated by the chip during read */
314/******************************************************/ 314/******************************************************/
315static volatile u_char 315static u_char
316Read_hfc8_stable(hfc4s8s_hw * hw, int reg) 316Read_hfc8_stable(hfc4s8s_hw * hw, int reg)
317{ 317{
318 u_char ref8; 318 u_char ref8;
@@ -324,7 +324,7 @@ Read_hfc8_stable(hfc4s8s_hw * hw, int reg)
324 return in8; 324 return in8;
325} 325}
326 326
327static volatile int 327static int
328Read_hfc16_stable(hfc4s8s_hw * hw, int reg) 328Read_hfc16_stable(hfc4s8s_hw * hw, int reg)
329{ 329{
330 int ref16; 330 int ref16;
@@ -1465,7 +1465,7 @@ hfc_hardware_enable(hfc4s8s_hw * hw, int enable, int nt_mode)
1465/******************************************/ 1465/******************************************/
1466/* disable memory mapped ports / io ports */ 1466/* disable memory mapped ports / io ports */
1467/******************************************/ 1467/******************************************/
1468void 1468static void
1469release_pci_ports(hfc4s8s_hw * hw) 1469release_pci_ports(hfc4s8s_hw * hw)
1470{ 1470{
1471 pci_write_config_word(hw->pdev, PCI_COMMAND, 0); 1471 pci_write_config_word(hw->pdev, PCI_COMMAND, 0);
@@ -1481,7 +1481,7 @@ release_pci_ports(hfc4s8s_hw * hw)
1481/*****************************************/ 1481/*****************************************/
1482/* enable memory mapped ports / io ports */ 1482/* enable memory mapped ports / io ports */
1483/*****************************************/ 1483/*****************************************/
1484void 1484static void
1485enable_pci_ports(hfc4s8s_hw * hw) 1485enable_pci_ports(hfc4s8s_hw * hw)
1486{ 1486{
1487#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1487#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM
diff --git a/drivers/isdn/hisax/isdnl1.c b/drivers/isdn/hisax/isdnl1.c
index ac899503a74f..bab356886483 100644
--- a/drivers/isdn/hisax/isdnl1.c
+++ b/drivers/isdn/hisax/isdnl1.c
@@ -279,7 +279,8 @@ BChannel_proc_xmt(struct BCState *bcs)
279 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags)) 279 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
280 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL); 280 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
281 if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) { 281 if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
282 if (!test_bit(BC_FLG_BUSY, &bcs->Flag) && (!skb_queue_len(&bcs->squeue))) { 282 if (!test_bit(BC_FLG_BUSY, &bcs->Flag) &&
283 skb_queue_empty(&bcs->squeue)) {
283 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL); 284 st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
284 } 285 }
285 } 286 }
diff --git a/drivers/isdn/hisax/isdnl2.c b/drivers/isdn/hisax/isdnl2.c
index 9022583fd6a0..1615c1a76ab8 100644
--- a/drivers/isdn/hisax/isdnl2.c
+++ b/drivers/isdn/hisax/isdnl2.c
@@ -108,7 +108,8 @@ static int l2addrsize(struct Layer2 *l2);
108static void 108static void
109set_peer_busy(struct Layer2 *l2) { 109set_peer_busy(struct Layer2 *l2) {
110 test_and_set_bit(FLG_PEER_BUSY, &l2->flag); 110 test_and_set_bit(FLG_PEER_BUSY, &l2->flag);
111 if (skb_queue_len(&l2->i_queue) || skb_queue_len(&l2->ui_queue)) 111 if (!skb_queue_empty(&l2->i_queue) ||
112 !skb_queue_empty(&l2->ui_queue))
112 test_and_set_bit(FLG_L2BLOCK, &l2->flag); 113 test_and_set_bit(FLG_L2BLOCK, &l2->flag);
113} 114}
114 115
@@ -754,7 +755,7 @@ l2_restart_multi(struct FsmInst *fi, int event, void *arg)
754 st->l2.l2l3(st, DL_ESTABLISH | INDICATION, NULL); 755 st->l2.l2l3(st, DL_ESTABLISH | INDICATION, NULL);
755 756
756 if ((ST_L2_7==state) || (ST_L2_8 == state)) 757 if ((ST_L2_7==state) || (ST_L2_8 == state))
757 if (skb_queue_len(&st->l2.i_queue) && cansend(st)) 758 if (!skb_queue_empty(&st->l2.i_queue) && cansend(st))
758 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 759 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
759} 760}
760 761
@@ -810,7 +811,7 @@ l2_connected(struct FsmInst *fi, int event, void *arg)
810 if (pr != -1) 811 if (pr != -1)
811 st->l2.l2l3(st, pr, NULL); 812 st->l2.l2l3(st, pr, NULL);
812 813
813 if (skb_queue_len(&st->l2.i_queue) && cansend(st)) 814 if (!skb_queue_empty(&st->l2.i_queue) && cansend(st))
814 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 815 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
815} 816}
816 817
@@ -1014,7 +1015,7 @@ l2_st7_got_super(struct FsmInst *fi, int event, void *arg)
1014 if(typ != RR) FsmDelTimer(&st->l2.t203, 9); 1015 if(typ != RR) FsmDelTimer(&st->l2.t203, 9);
1015 restart_t200(st, 12); 1016 restart_t200(st, 12);
1016 } 1017 }
1017 if (skb_queue_len(&st->l2.i_queue) && (typ == RR)) 1018 if (!skb_queue_empty(&st->l2.i_queue) && (typ == RR))
1018 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 1019 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
1019 } else 1020 } else
1020 nrerrorrecovery(fi); 1021 nrerrorrecovery(fi);
@@ -1120,7 +1121,7 @@ l2_got_iframe(struct FsmInst *fi, int event, void *arg)
1120 return; 1121 return;
1121 } 1122 }
1122 1123
1123 if (skb_queue_len(&st->l2.i_queue) && (fi->state == ST_L2_7)) 1124 if (!skb_queue_empty(&st->l2.i_queue) && (fi->state == ST_L2_7))
1124 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 1125 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
1125 if (test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag)) 1126 if (test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag))
1126 enquiry_cr(st, RR, RSP, 0); 1127 enquiry_cr(st, RR, RSP, 0);
@@ -1138,7 +1139,7 @@ l2_got_tei(struct FsmInst *fi, int event, void *arg)
1138 test_and_set_bit(FLG_L3_INIT, &st->l2.flag); 1139 test_and_set_bit(FLG_L3_INIT, &st->l2.flag);
1139 } else 1140 } else
1140 FsmChangeState(fi, ST_L2_4); 1141 FsmChangeState(fi, ST_L2_4);
1141 if (skb_queue_len(&st->l2.ui_queue)) 1142 if (!skb_queue_empty(&st->l2.ui_queue))
1142 tx_ui(st); 1143 tx_ui(st);
1143} 1144}
1144 1145
@@ -1301,7 +1302,7 @@ l2_pull_iqueue(struct FsmInst *fi, int event, void *arg)
1301 FsmDelTimer(&st->l2.t203, 13); 1302 FsmDelTimer(&st->l2.t203, 13);
1302 FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 11); 1303 FsmAddTimer(&st->l2.t200, st->l2.T200, EV_L2_T200, NULL, 11);
1303 } 1304 }
1304 if (skb_queue_len(&l2->i_queue) && cansend(st)) 1305 if (!skb_queue_empty(&l2->i_queue) && cansend(st))
1305 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 1306 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
1306} 1307}
1307 1308
@@ -1347,7 +1348,7 @@ l2_st8_got_super(struct FsmInst *fi, int event, void *arg)
1347 } 1348 }
1348 invoke_retransmission(st, nr); 1349 invoke_retransmission(st, nr);
1349 FsmChangeState(fi, ST_L2_7); 1350 FsmChangeState(fi, ST_L2_7);
1350 if (skb_queue_len(&l2->i_queue) && cansend(st)) 1351 if (!skb_queue_empty(&l2->i_queue) && cansend(st))
1351 st->l2.l2l1(st, PH_PULL | REQUEST, NULL); 1352 st->l2.l2l1(st, PH_PULL | REQUEST, NULL);
1352 } else 1353 } else
1353 nrerrorrecovery(fi); 1354 nrerrorrecovery(fi);
diff --git a/drivers/isdn/hisax/isdnl3.c b/drivers/isdn/hisax/isdnl3.c
index abcc9530eb34..c9917cd2132b 100644
--- a/drivers/isdn/hisax/isdnl3.c
+++ b/drivers/isdn/hisax/isdnl3.c
@@ -302,7 +302,7 @@ release_l3_process(struct l3_process *p)
302 !test_bit(FLG_PTP, &p->st->l2.flag)) { 302 !test_bit(FLG_PTP, &p->st->l2.flag)) {
303 if (p->debug) 303 if (p->debug)
304 l3_debug(p->st, "release_l3_process: last process"); 304 l3_debug(p->st, "release_l3_process: last process");
305 if (!skb_queue_len(&p->st->l3.squeue)) { 305 if (skb_queue_empty(&p->st->l3.squeue)) {
306 if (p->debug) 306 if (p->debug)
307 l3_debug(p->st, "release_l3_process: release link"); 307 l3_debug(p->st, "release_l3_process: release link");
308 if (p->st->protocol != ISDN_PTYPE_NI1) 308 if (p->st->protocol != ISDN_PTYPE_NI1)
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 449651241477..c6b5bf7d2aca 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -47,7 +47,6 @@
47#include <asm/io.h> 47#include <asm/io.h>
48#include <asm/system.h> 48#include <asm/system.h>
49 49
50#include <pcmcia/version.h>
51#include <pcmcia/cs_types.h> 50#include <pcmcia/cs_types.h>
52#include <pcmcia/cs.h> 51#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
@@ -226,11 +225,6 @@ static dev_link_t *sedlbauer_attach(void)
226 link->next = dev_list; 225 link->next = dev_list;
227 dev_list = link; 226 dev_list = link;
228 client_reg.dev_info = &dev_info; 227 client_reg.dev_info = &dev_info;
229 client_reg.EventMask =
230 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
231 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
232 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
233 client_reg.event_handler = &sedlbauer_event;
234 client_reg.Version = 0x0210; 228 client_reg.Version = 0x0210;
235 client_reg.event_callback_args.client_data = link; 229 client_reg.event_callback_args.client_data = link;
236 ret = pcmcia_register_client(&link->handle, &client_reg); 230 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -616,13 +610,27 @@ static int sedlbauer_event(event_t event, int priority,
616 return 0; 610 return 0;
617} /* sedlbauer_event */ 611} /* sedlbauer_event */
618 612
613static struct pcmcia_device_id sedlbauer_ids[] = {
614 PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", "speed star II", "V 3.1", "(c) 93 - 98 cb ", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a, 0x50d4149c),
615 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
616 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
617 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
618 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
619 PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
620/* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
621 PCMCIA_DEVICE_NULL
622};
623MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
624
619static struct pcmcia_driver sedlbauer_driver = { 625static struct pcmcia_driver sedlbauer_driver = {
620 .owner = THIS_MODULE, 626 .owner = THIS_MODULE,
621 .drv = { 627 .drv = {
622 .name = "sedlbauer_cs", 628 .name = "sedlbauer_cs",
623 }, 629 },
624 .attach = sedlbauer_attach, 630 .attach = sedlbauer_attach,
631 .event = sedlbauer_event,
625 .detach = sedlbauer_detach, 632 .detach = sedlbauer_detach,
633 .id_table = sedlbauer_ids,
626}; 634};
627 635
628static int __init init_sedlbauer_cs(void) 636static int __init init_sedlbauer_cs(void)
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 63e8e20c17a8..0ddef1bf778b 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -28,7 +28,6 @@
28#include <asm/io.h> 28#include <asm/io.h>
29#include <asm/system.h> 29#include <asm/system.h>
30 30
31#include <pcmcia/version.h>
32#include <pcmcia/cs_types.h> 31#include <pcmcia/cs_types.h>
33#include <pcmcia/cs.h> 32#include <pcmcia/cs.h>
34#include <pcmcia/cistpl.h> 33#include <pcmcia/cistpl.h>
@@ -193,11 +192,6 @@ static dev_link_t *teles_attach(void)
193 link->next = dev_list; 192 link->next = dev_list;
194 dev_list = link; 193 dev_list = link;
195 client_reg.dev_info = &dev_info; 194 client_reg.dev_info = &dev_info;
196 client_reg.EventMask =
197 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
198 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
199 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
200 client_reg.event_handler = &teles_cs_event;
201 client_reg.Version = 0x0210; 195 client_reg.Version = 0x0210;
202 client_reg.event_callback_args.client_data = link; 196 client_reg.event_callback_args.client_data = link;
203 ret = pcmcia_register_client(&link->handle, &client_reg); 197 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -489,13 +483,21 @@ static int teles_cs_event(event_t event, int priority,
489 return 0; 483 return 0;
490} /* teles_cs_event */ 484} /* teles_cs_event */
491 485
486static struct pcmcia_device_id teles_ids[] = {
487 PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
488 PCMCIA_DEVICE_NULL,
489};
490MODULE_DEVICE_TABLE(pcmcia, teles_ids);
491
492static struct pcmcia_driver teles_cs_driver = { 492static struct pcmcia_driver teles_cs_driver = {
493 .owner = THIS_MODULE, 493 .owner = THIS_MODULE,
494 .drv = { 494 .drv = {
495 .name = "teles_cs", 495 .name = "teles_cs",
496 }, 496 },
497 .attach = teles_attach, 497 .attach = teles_attach,
498 .event = teles_cs_event,
498 .detach = teles_detach, 499 .detach = teles_detach,
500 .id_table = teles_ids,
499}; 501};
500 502
501static int __init init_teles_cs(void) 503static int __init init_teles_cs(void)
diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c
index 8ee25b2ccce1..1fd3d4e5f284 100644
--- a/drivers/isdn/hysdn/hycapi.c
+++ b/drivers/isdn/hysdn/hycapi.c
@@ -42,6 +42,8 @@ typedef struct _hycapi_appl {
42 42
43static hycapi_appl hycapi_applications[CAPI_MAXAPPL]; 43static hycapi_appl hycapi_applications[CAPI_MAXAPPL];
44 44
45static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
46
45static inline int _hycapi_appCheck(int app_id, int ctrl_no) 47static inline int _hycapi_appCheck(int app_id, int ctrl_no)
46{ 48{
47 if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) || 49 if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||
@@ -57,7 +59,7 @@ static inline int _hycapi_appCheck(int app_id, int ctrl_no)
57Kernel-Capi callback reset_ctr 59Kernel-Capi callback reset_ctr
58******************************/ 60******************************/
59 61
60void 62static void
61hycapi_reset_ctr(struct capi_ctr *ctrl) 63hycapi_reset_ctr(struct capi_ctr *ctrl)
62{ 64{
63 hycapictrl_info *cinfo = ctrl->driverdata; 65 hycapictrl_info *cinfo = ctrl->driverdata;
@@ -73,7 +75,7 @@ hycapi_reset_ctr(struct capi_ctr *ctrl)
73Kernel-Capi callback remove_ctr 75Kernel-Capi callback remove_ctr
74******************************/ 76******************************/
75 77
76void 78static void
77hycapi_remove_ctr(struct capi_ctr *ctrl) 79hycapi_remove_ctr(struct capi_ctr *ctrl)
78{ 80{
79 int i; 81 int i;
@@ -215,7 +217,7 @@ Error-checking is done for CAPI-compliance.
215The application is recorded in the internal list. 217The application is recorded in the internal list.
216*************************************************************/ 218*************************************************************/
217 219
218void 220static void
219hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl, 221hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
220 capi_register_params *rp) 222 capi_register_params *rp)
221{ 223{
@@ -291,7 +293,7 @@ Release the application from the internal list an remove it's
291registration at controller-level 293registration at controller-level
292******************************************************************/ 294******************************************************************/
293 295
294void 296static void
295hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl) 297hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
296{ 298{
297 int chk; 299 int chk;
@@ -364,7 +366,7 @@ firmware-releases that do not check the MsgLen-Indication!
364 366
365***************************************************************/ 367***************************************************************/
366 368
367u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) 369static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
368{ 370{
369 __u16 appl_id; 371 __u16 appl_id;
370 int _len, _len2; 372 int _len, _len2;
@@ -437,8 +439,8 @@ Informations provided in the /proc/capi-entries.
437 439
438*********************************************************************/ 440*********************************************************************/
439 441
440int hycapi_read_proc(char *page, char **start, off_t off, 442static int hycapi_read_proc(char *page, char **start, off_t off,
441 int count, int *eof, struct capi_ctr *ctrl) 443 int count, int *eof, struct capi_ctr *ctrl)
442{ 444{
443 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata); 445 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
444 hysdn_card *card = cinfo->card; 446 hysdn_card *card = cinfo->card;
@@ -485,7 +487,7 @@ on capi-interface registration.
485 487
486**************************************************************/ 488**************************************************************/
487 489
488int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) 490static int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
489{ 491{
490#ifdef HYCAPI_PRINTFNAMES 492#ifdef HYCAPI_PRINTFNAMES
491 printk(KERN_NOTICE "hycapi_load_firmware\n"); 493 printk(KERN_NOTICE "hycapi_load_firmware\n");
@@ -494,7 +496,7 @@ int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
494} 496}
495 497
496 498
497char *hycapi_procinfo(struct capi_ctr *ctrl) 499static char *hycapi_procinfo(struct capi_ctr *ctrl)
498{ 500{
499 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata); 501 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
500#ifdef HYCAPI_PRINTFNAMES 502#ifdef HYCAPI_PRINTFNAMES
diff --git a/drivers/isdn/hysdn/hysdn_boot.c b/drivers/isdn/hysdn/hysdn_boot.c
index 6c04281e57b8..7bfba196f315 100644
--- a/drivers/isdn/hysdn/hysdn_boot.c
+++ b/drivers/isdn/hysdn/hysdn_boot.c
@@ -53,7 +53,7 @@ struct boot_data {
53/* to be called at start of POF file reading, */ 53/* to be called at start of POF file reading, */
54/* before starting any decryption on any POF record. */ 54/* before starting any decryption on any POF record. */
55/*****************************************************/ 55/*****************************************************/
56void 56static void
57StartDecryption(struct boot_data *boot) 57StartDecryption(struct boot_data *boot)
58{ 58{
59 boot->Cryptor = CRYPT_STARTTERM; 59 boot->Cryptor = CRYPT_STARTTERM;
@@ -66,7 +66,7 @@ StartDecryption(struct boot_data *boot)
66/* to HI and LO boot loader and (all) seq tags, because */ 66/* to HI and LO boot loader and (all) seq tags, because */
67/* global Cryptor is started for whole POF. */ 67/* global Cryptor is started for whole POF. */
68/***************************************************************/ 68/***************************************************************/
69void 69static void
70DecryptBuf(struct boot_data *boot, int cnt) 70DecryptBuf(struct boot_data *boot, int cnt)
71{ 71{
72 uchar *bufp = boot->buf.BootBuf; 72 uchar *bufp = boot->buf.BootBuf;
diff --git a/drivers/isdn/hysdn/hysdn_defs.h b/drivers/isdn/hysdn/hysdn_defs.h
index 4cee26e558ee..432f6f99089e 100644
--- a/drivers/isdn/hysdn/hysdn_defs.h
+++ b/drivers/isdn/hysdn/hysdn_defs.h
@@ -227,7 +227,6 @@ typedef struct hycapictrl_info hycapictrl_info;
227/*****************/ 227/*****************/
228/* exported vars */ 228/* exported vars */
229/*****************/ 229/*****************/
230extern int cardmax; /* number of found cards */
231extern hysdn_card *card_root; /* pointer to first card */ 230extern hysdn_card *card_root; /* pointer to first card */
232 231
233 232
@@ -244,7 +243,6 @@ extern void hysdn_procconf_release(void); /* deinit proc config filesys */
244/* hysdn_proclog.c */ 243/* hysdn_proclog.c */
245extern int hysdn_proclog_init(hysdn_card *); /* init proc log entry */ 244extern int hysdn_proclog_init(hysdn_card *); /* init proc log entry */
246extern void hysdn_proclog_release(hysdn_card *); /* deinit proc log entry */ 245extern void hysdn_proclog_release(hysdn_card *); /* deinit proc log entry */
247extern void put_log_buffer(hysdn_card *, char *); /* output log data */
248extern void hysdn_addlog(hysdn_card *, char *,...); /* output data to log */ 246extern void hysdn_addlog(hysdn_card *, char *,...); /* output data to log */
249extern void hysdn_card_errlog(hysdn_card *, tErrLogEntry *, int); /* output card log */ 247extern void hysdn_card_errlog(hysdn_card *, tErrLogEntry *, int); /* output card log */
250 248
@@ -278,16 +276,6 @@ extern unsigned int hycapi_enable;
278extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */ 276extern int hycapi_capi_create(hysdn_card *); /* create a new capi device */
279extern int hycapi_capi_release(hysdn_card *); /* delete the device */ 277extern int hycapi_capi_release(hysdn_card *); /* delete the device */
280extern int hycapi_capi_stop(hysdn_card *card); /* suspend */ 278extern int hycapi_capi_stop(hysdn_card *card); /* suspend */
281extern int hycapi_load_firmware(struct capi_ctr *, capiloaddata *);
282extern void hycapi_reset_ctr(struct capi_ctr *);
283extern void hycapi_remove_ctr(struct capi_ctr *);
284extern void hycapi_register_appl(struct capi_ctr *, __u16 appl,
285 capi_register_params *);
286extern void hycapi_release_appl(struct capi_ctr *, __u16 appl);
287extern u16 hycapi_send_message(struct capi_ctr *, struct sk_buff *skb);
288extern char *hycapi_procinfo(struct capi_ctr *);
289extern int hycapi_read_proc(char *page, char **start, off_t off,
290 int count, int *eof, struct capi_ctr *card);
291extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len); 279extern void hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len);
292extern void hycapi_tx_capiack(hysdn_card * card); 280extern void hycapi_tx_capiack(hysdn_card * card);
293extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card); 281extern struct sk_buff *hycapi_tx_capiget(hysdn_card *card);
diff --git a/drivers/isdn/hysdn/hysdn_init.c b/drivers/isdn/hysdn/hysdn_init.c
index 5cac2bf5f4b0..12c8137b5161 100644
--- a/drivers/isdn/hysdn/hysdn_init.c
+++ b/drivers/isdn/hysdn/hysdn_init.c
@@ -34,7 +34,7 @@ MODULE_AUTHOR("Werner Cornelius");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static char *hysdn_init_revision = "$Revision: 1.6.6.6 $"; 36static char *hysdn_init_revision = "$Revision: 1.6.6.6 $";
37int cardmax; /* number of found cards */ 37static int cardmax; /* number of found cards */
38hysdn_card *card_root = NULL; /* pointer to first card */ 38hysdn_card *card_root = NULL; /* pointer to first card */
39 39
40/**********************************************/ 40/**********************************************/
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 8ef2b7c952a6..4d57011c5737 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -22,6 +22,8 @@
22/* the proc subdir for the interface is defined in the procconf module */ 22/* the proc subdir for the interface is defined in the procconf module */
23extern struct proc_dir_entry *hysdn_proc_entry; 23extern struct proc_dir_entry *hysdn_proc_entry;
24 24
25static void put_log_buffer(hysdn_card * card, char *cp);
26
25/*************************************************/ 27/*************************************************/
26/* structure keeping ascii log for device output */ 28/* structure keeping ascii log for device output */
27/*************************************************/ 29/*************************************************/
@@ -93,7 +95,7 @@ hysdn_addlog(hysdn_card * card, char *fmt,...)
93/* opened for read got the contents. */ 95/* opened for read got the contents. */
94/* Flushes buffers not longer in use. */ 96/* Flushes buffers not longer in use. */
95/********************************************/ 97/********************************************/
96void 98static void
97put_log_buffer(hysdn_card * card, char *cp) 99put_log_buffer(hysdn_card * card, char *cp)
98{ 100{
99 struct log_data *ib; 101 struct log_data *ib;
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index ad5aa38fb5a6..b37ef1f06b3d 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1223,7 +1223,7 @@ isdn_tty_write(struct tty_struct *tty, const u_char * buf, int count)
1223 total += c; 1223 total += c;
1224 } 1224 }
1225 atomic_dec(&info->xmit_lock); 1225 atomic_dec(&info->xmit_lock);
1226 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue))) { 1226 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) {
1227 if (m->mdmreg[REG_DXMT] & BIT_DXMT) { 1227 if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
1228 isdn_tty_senddown(info); 1228 isdn_tty_senddown(info);
1229 isdn_tty_tint(info); 1229 isdn_tty_tint(info);
@@ -1284,7 +1284,7 @@ isdn_tty_flush_chars(struct tty_struct *tty)
1284 1284
1285 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars")) 1285 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
1286 return; 1286 return;
1287 if ((info->xmit_count) || (skb_queue_len(&info->xmit_queue))) 1287 if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue))
1288 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1); 1288 isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
1289} 1289}
1290 1290
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index 9fc0c1e03732..e0d1b01cc74c 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -304,12 +304,12 @@ icn_pollbchan_send(int channel, icn_card * card)
304 isdn_ctrl cmd; 304 isdn_ctrl cmd;
305 305
306 if (!(card->sndcount[channel] || card->xskb[channel] || 306 if (!(card->sndcount[channel] || card->xskb[channel] ||
307 skb_queue_len(&card->spqueue[channel]))) 307 !skb_queue_empty(&card->spqueue[channel])))
308 return; 308 return;
309 if (icn_trymaplock_channel(card, mch)) { 309 if (icn_trymaplock_channel(card, mch)) {
310 while (sbfree && 310 while (sbfree &&
311 (card->sndcount[channel] || 311 (card->sndcount[channel] ||
312 skb_queue_len(&card->spqueue[channel]) || 312 !skb_queue_empty(&card->spqueue[channel]) ||
313 card->xskb[channel])) { 313 card->xskb[channel])) {
314 spin_lock_irqsave(&card->lock, flags); 314 spin_lock_irqsave(&card->lock, flags);
315 if (card->xmit_lock[channel]) { 315 if (card->xmit_lock[channel]) {
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 8a7117a08cf0..91691a6c004e 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -86,33 +86,18 @@ config PMAC_SMU
86 on the "SMU" system control chip which replaces the old PMU. 86 on the "SMU" system control chip which replaces the old PMU.
87 If you don't know, say Y. 87 If you don't know, say Y.
88 88
89config PMAC_PBOOK
90 bool "Power management support for PowerBooks"
91 depends on ADB_PMU
92 ---help---
93 This provides support for putting a PowerBook to sleep; it also
94 enables media bay support. Power management works on the
95 PB2400/3400/3500, Wallstreet, Lombard, and Bronze PowerBook G3 and
96 the Titanium Powerbook G4, as well as the iBooks. You should get
97 the power management daemon, pmud, to make it work and you must have
98 the /dev/pmu device (see the pmud README).
99
100 Get pmud from <ftp://ftp.samba.org/pub/ppclinux/pmud/>.
101
102 If you have a PowerBook, you should say Y here.
103
104 You may also want to compile the dma sound driver as a module and
105 have it autoloaded. The act of removing the module shuts down the
106 sound hardware for more power savings.
107
108config PM
109 bool
110 depends on PPC_PMAC && ADB_PMU && PMAC_PBOOK
111 default y
112
113config PMAC_APM_EMU 89config PMAC_APM_EMU
114 tristate "APM emulation" 90 tristate "APM emulation"
115 depends on PMAC_PBOOK 91 depends on PPC_PMAC && PPC32 && PM
92
93config PMAC_MEDIABAY
94 bool "Support PowerBook hotswap media bay"
95 depends on PPC_PMAC && PPC32
96 help
97 This option adds support for older PowerBook's hotswap media bay
98 that can contains batteries, floppy drives, or IDE devices. PCI
99 devices are not fully supported in the bay as I never had one to
100 try with
116 101
117# made a separate option since backlight may end up beeing used 102# made a separate option since backlight may end up beeing used
118# on non-powerbook machines (but only on PMU based ones AFAIK) 103# on non-powerbook machines (but only on PMU based ones AFAIK)
@@ -126,13 +111,6 @@ config PMAC_BACKLIGHT
126 events; also, the PowerBook button device will be enabled so you can 111 events; also, the PowerBook button device will be enabled so you can
127 change the screen brightness. 112 change the screen brightness.
128 113
129config MAC_SERIAL
130 tristate "Support for PowerMac serial ports (OBSOLETE DRIVER)"
131 depends on PPC_PMAC && BROKEN
132 help
133 This driver is obsolete. Use CONFIG_SERIAL_PMACZILOG in
134 "Character devices --> Serial drivers --> PowerMac z85c30" option.
135
136config ADB_MACIO 114config ADB_MACIO
137 bool "Include MacIO (CHRP) ADB driver" 115 bool "Include MacIO (CHRP) ADB driver"
138 depends on ADB && PPC_CHRP && !PPC_PMAC64 116 depends on ADB && PPC_CHRP && !PPC_PMAC64
diff --git a/drivers/macintosh/Makefile b/drivers/macintosh/Makefile
index c3a4705a8295..236291bd48a4 100644
--- a/drivers/macintosh/Makefile
+++ b/drivers/macintosh/Makefile
@@ -4,10 +4,9 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_PPC_PMAC) += macio_asic.o 7obj-$(CONFIG_PPC_PMAC) += macio_asic.o macio_sysfs.o
8 8
9obj-$(CONFIG_PMAC_PBOOK) += mediabay.o 9obj-$(CONFIG_PMAC_MEDIABAY) += mediabay.o
10obj-$(CONFIG_MAC_SERIAL) += macserial.o
11obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o 10obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o
12obj-$(CONFIG_INPUT_ADBHID) += adbhid.o 11obj-$(CONFIG_INPUT_ADBHID) += adbhid.o
13obj-$(CONFIG_ANSLCD) += ans-lcd.o 12obj-$(CONFIG_ANSLCD) += ans-lcd.o
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 493e2afa191c..c0dc1e3fa58b 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -90,7 +90,7 @@ static int sleepy_trackpad;
90static int autopoll_devs; 90static int autopoll_devs;
91int __adb_probe_sync; 91int __adb_probe_sync;
92 92
93#ifdef CONFIG_PMAC_PBOOK 93#ifdef CONFIG_PM
94static int adb_notify_sleep(struct pmu_sleep_notifier *self, int when); 94static int adb_notify_sleep(struct pmu_sleep_notifier *self, int when);
95static struct pmu_sleep_notifier adb_sleep_notifier = { 95static struct pmu_sleep_notifier adb_sleep_notifier = {
96 adb_notify_sleep, 96 adb_notify_sleep,
@@ -320,9 +320,9 @@ int __init adb_init(void)
320 printk(KERN_WARNING "Warning: no ADB interface detected\n"); 320 printk(KERN_WARNING "Warning: no ADB interface detected\n");
321 adb_controller = NULL; 321 adb_controller = NULL;
322 } else { 322 } else {
323#ifdef CONFIG_PMAC_PBOOK 323#ifdef CONFIG_PM
324 pmu_register_sleep_notifier(&adb_sleep_notifier); 324 pmu_register_sleep_notifier(&adb_sleep_notifier);
325#endif /* CONFIG_PMAC_PBOOK */ 325#endif /* CONFIG_PM */
326#ifdef CONFIG_PPC 326#ifdef CONFIG_PPC
327 if (machine_is_compatible("AAPL,PowerBook1998") || 327 if (machine_is_compatible("AAPL,PowerBook1998") ||
328 machine_is_compatible("PowerBook1,1")) 328 machine_is_compatible("PowerBook1,1"))
@@ -337,7 +337,7 @@ int __init adb_init(void)
337 337
338__initcall(adb_init); 338__initcall(adb_init);
339 339
340#ifdef CONFIG_PMAC_PBOOK 340#ifdef CONFIG_PM
341/* 341/*
342 * notify clients before sleep and reset bus afterwards 342 * notify clients before sleep and reset bus afterwards
343 */ 343 */
@@ -378,7 +378,7 @@ adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
378 } 378 }
379 return PBOOK_SLEEP_OK; 379 return PBOOK_SLEEP_OK;
380} 380}
381#endif /* CONFIG_PMAC_PBOOK */ 381#endif /* CONFIG_PM */
382 382
383static int 383static int
384do_adb_reset_bus(void) 384do_adb_reset_bus(void)
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index d0bda7e3e6aa..1ee003346923 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -33,7 +33,7 @@ static int macio_bus_match(struct device *dev, struct device_driver *drv)
33{ 33{
34 struct macio_dev * macio_dev = to_macio_device(dev); 34 struct macio_dev * macio_dev = to_macio_device(dev);
35 struct macio_driver * macio_drv = to_macio_driver(drv); 35 struct macio_driver * macio_drv = to_macio_driver(drv);
36 const struct of_match * matches = macio_drv->match_table; 36 const struct of_device_id * matches = macio_drv->match_table;
37 37
38 if (!matches) 38 if (!matches)
39 return 0; 39 return 0;
@@ -66,7 +66,7 @@ static int macio_device_probe(struct device *dev)
66 int error = -ENODEV; 66 int error = -ENODEV;
67 struct macio_driver *drv; 67 struct macio_driver *drv;
68 struct macio_dev *macio_dev; 68 struct macio_dev *macio_dev;
69 const struct of_match *match; 69 const struct of_device_id *match;
70 70
71 drv = to_macio_driver(dev->driver); 71 drv = to_macio_driver(dev->driver);
72 macio_dev = to_macio_device(dev); 72 macio_dev = to_macio_device(dev);
@@ -126,11 +126,85 @@ static int macio_device_resume(struct device * dev)
126 return 0; 126 return 0;
127} 127}
128 128
129static int macio_hotplug (struct device *dev, char **envp, int num_envp,
130 char *buffer, int buffer_size)
131{
132 struct macio_dev * macio_dev;
133 struct of_device * of;
134 char *scratch, *compat;
135 int i = 0;
136 int length = 0;
137 int cplen, seen = 0;
138
139 if (!dev)
140 return -ENODEV;
141
142 macio_dev = to_macio_device(dev);
143 if (!macio_dev)
144 return -ENODEV;
145
146 of = &macio_dev->ofdev;
147 scratch = buffer;
148
149 /* stuff we want to pass to /sbin/hotplug */
150 envp[i++] = scratch;
151 length += scnprintf (scratch, buffer_size - length, "OF_NAME=%s",
152 of->node->name);
153 if ((buffer_size - length <= 0) || (i >= num_envp))
154 return -ENOMEM;
155 ++length;
156 scratch += length;
157
158 envp[i++] = scratch;
159 length += scnprintf (scratch, buffer_size - length, "OF_TYPE=%s",
160 of->node->type);
161 if ((buffer_size - length <= 0) || (i >= num_envp))
162 return -ENOMEM;
163 ++length;
164 scratch += length;
165
166 /* Since the compatible field can contain pretty much anything
167 * it's not really legal to split it out with commas. We split it
168 * up using a number of environment variables instead. */
169
170 compat = (char *) get_property(of->node, "compatible", &cplen);
171 while (compat && cplen > 0) {
172 int l;
173 envp[i++] = scratch;
174 length += scnprintf (scratch, buffer_size - length,
175 "OF_COMPATIBLE_%d=%s", seen, compat);
176 if ((buffer_size - length <= 0) || (i >= num_envp))
177 return -ENOMEM;
178 length++;
179 scratch += length;
180 l = strlen (compat) + 1;
181 compat += l;
182 cplen -= l;
183 seen++;
184 }
185
186 envp[i++] = scratch;
187 length += scnprintf (scratch, buffer_size - length,
188 "OF_COMPATIBLE_N=%d", seen);
189 if ((buffer_size - length <= 0) || (i >= num_envp))
190 return -ENOMEM;
191 ++length;
192 scratch += length;
193
194 envp[i] = NULL;
195
196 return 0;
197}
198
199extern struct device_attribute macio_dev_attrs[];
200
129struct bus_type macio_bus_type = { 201struct bus_type macio_bus_type = {
130 .name = "macio", 202 .name = "macio",
131 .match = macio_bus_match, 203 .match = macio_bus_match,
204 .hotplug = macio_hotplug,
132 .suspend = macio_device_suspend, 205 .suspend = macio_device_suspend,
133 .resume = macio_device_resume, 206 .resume = macio_device_resume,
207 .dev_attrs = macio_dev_attrs,
134}; 208};
135 209
136static int __init macio_bus_driver_init(void) 210static int __init macio_bus_driver_init(void)
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
new file mode 100644
index 000000000000..97d22bb4516a
--- /dev/null
+++ b/drivers/macintosh/macio_sysfs.c
@@ -0,0 +1,50 @@
1#include <linux/config.h>
2#include <linux/kernel.h>
3#include <linux/stat.h>
4#include <asm/macio.h>
5
6
7#define macio_config_of_attr(field, format_string) \
8static ssize_t \
9field##_show (struct device *dev, struct device_attribute *attr, \
10 char *buf) \
11{ \
12 struct macio_dev *mdev = to_macio_device (dev); \
13 return sprintf (buf, format_string, mdev->ofdev.node->field); \
14}
15
16static ssize_t
17compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
18{
19 struct of_device *of;
20 char *compat;
21 int cplen;
22 int length = 0;
23
24 of = &to_macio_device (dev)->ofdev;
25 compat = (char *) get_property(of->node, "compatible", &cplen);
26 if (!compat) {
27 *buf = '\0';
28 return 0;
29 }
30 while (cplen > 0) {
31 int l;
32 length += sprintf (buf, "%s\n", compat);
33 buf += length;
34 l = strlen (compat) + 1;
35 compat += l;
36 cplen -= l;
37 }
38
39 return length;
40}
41
42macio_config_of_attr (name, "%s\n");
43macio_config_of_attr (type, "%s\n");
44
45struct device_attribute macio_dev_attrs[] = {
46 __ATTR_RO(name),
47 __ATTR_RO(type),
48 __ATTR_RO(compatible),
49 __ATTR_NULL
50};
diff --git a/drivers/macintosh/macserial.c b/drivers/macintosh/macserial.c
deleted file mode 100644
index 0be3ac6cc169..000000000000
--- a/drivers/macintosh/macserial.c
+++ /dev/null
@@ -1,3036 +0,0 @@
1/*
2 * macserial.c: Serial port driver for Power Macintoshes.
3 *
4 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
5 *
6 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 *
9 * Receive DMA code by Takashi Oe <toe@unlserve.unl.edu>.
10 *
11 * $Id: macserial.c,v 1.24.2.4 1999/10/19 04:36:42 paulus Exp $
12 */
13
14#include <linux/config.h>
15#include <linux/errno.h>
16#include <linux/module.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/timer.h>
20#include <linux/interrupt.h>
21#include <linux/workqueue.h>
22#include <linux/tty.h>
23#include <linux/tty_flip.h>
24#include <linux/major.h>
25#include <linux/string.h>
26#include <linux/fcntl.h>
27#include <linux/mm.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/init.h>
31#ifdef CONFIG_SERIAL_CONSOLE
32#include <linux/console.h>
33#endif
34#include <linux/slab.h>
35#include <linux/bitops.h>
36
37#include <asm/sections.h>
38#include <asm/io.h>
39#include <asm/pgtable.h>
40#include <asm/irq.h>
41#include <asm/prom.h>
42#include <asm/system.h>
43#include <asm/segment.h>
44#include <asm/machdep.h>
45#include <asm/pmac_feature.h>
46#include <linux/adb.h>
47#include <linux/pmu.h>
48#ifdef CONFIG_KGDB
49#include <asm/kgdb.h>
50#endif
51#include <asm/dbdma.h>
52
53#include "macserial.h"
54
55#ifdef CONFIG_PMAC_PBOOK
56static int serial_notify_sleep(struct pmu_sleep_notifier *self, int when);
57static struct pmu_sleep_notifier serial_sleep_notifier = {
58 serial_notify_sleep,
59 SLEEP_LEVEL_MISC,
60};
61#endif
62
63#define SUPPORT_SERIAL_DMA
64#define MACSERIAL_VERSION "2.0"
65
66/*
67 * It would be nice to dynamically allocate everything that
68 * depends on NUM_SERIAL, so we could support any number of
69 * Z8530s, but for now...
70 */
71#define NUM_SERIAL 2 /* Max number of ZS chips supported */
72#define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
73
74/* On PowerMacs, the hardware takes care of the SCC recovery time,
75 but we need the eieio to make sure that the accesses occur
76 in the order we want. */
77#define RECOVERY_DELAY eieio()
78
79static struct tty_driver *serial_driver;
80
81struct mac_zschannel zs_channels[NUM_CHANNELS];
82
83struct mac_serial zs_soft[NUM_CHANNELS];
84int zs_channels_found;
85struct mac_serial *zs_chain; /* list of all channels */
86
87struct tty_struct zs_ttys[NUM_CHANNELS];
88
89static int is_powerbook;
90
91#ifdef CONFIG_SERIAL_CONSOLE
92static struct console sercons;
93#endif
94
95#ifdef CONFIG_KGDB
96struct mac_zschannel *zs_kgdbchan;
97static unsigned char scc_inittab[] = {
98 9, 0x80, /* reset A side (CHRA) */
99 13, 0, /* set baud rate divisor */
100 12, 1,
101 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
102 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
103 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
104 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
105 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
106};
107#endif
108#define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
109
110/* serial subtype definitions */
111#define SERIAL_TYPE_NORMAL 1
112
113/* number of characters left in xmit buffer before we ask for more */
114#define WAKEUP_CHARS 256
115
116/*
117 * Debugging.
118 */
119#undef SERIAL_DEBUG_INTR
120#undef SERIAL_DEBUG_OPEN
121#undef SERIAL_DEBUG_FLOW
122#undef SERIAL_DEBUG_POWER
123#undef SERIAL_DEBUG_THROTTLE
124#undef SERIAL_DEBUG_STOP
125#undef SERIAL_DEBUG_BAUDS
126
127#define RS_STROBE_TIME 10
128#define RS_ISR_PASS_LIMIT 256
129
130#define _INLINE_ inline
131
132#ifdef SERIAL_DEBUG_OPEN
133#define OPNDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
134#else
135#define OPNDBG(fmt, arg...) do { } while (0)
136#endif
137#ifdef SERIAL_DEBUG_POWER
138#define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
139#else
140#define PWRDBG(fmt, arg...) do { } while (0)
141#endif
142#ifdef SERIAL_DEBUG_BAUDS
143#define BAUDBG(fmt, arg...) printk(fmt , ## arg)
144#else
145#define BAUDBG(fmt, arg...) do { } while (0)
146#endif
147
148static void probe_sccs(void);
149static void change_speed(struct mac_serial *info, struct termios *old);
150static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
151static int set_scc_power(struct mac_serial * info, int state);
152static int setup_scc(struct mac_serial * info);
153static void dbdma_reset(volatile struct dbdma_regs *dma);
154static void dbdma_flush(volatile struct dbdma_regs *dma);
155static irqreturn_t rs_txdma_irq(int irq, void *dev_id, struct pt_regs *regs);
156static irqreturn_t rs_rxdma_irq(int irq, void *dev_id, struct pt_regs *regs);
157static void dma_init(struct mac_serial * info);
158static void rxdma_start(struct mac_serial * info, int curr);
159static void rxdma_to_tty(struct mac_serial * info);
160
161/*
162 * tmp_buf is used as a temporary buffer by serial_write. We need to
163 * lock it in case the copy_from_user blocks while swapping in a page,
164 * and some other program tries to do a serial write at the same time.
165 * Since the lock will only come under contention when the system is
166 * swapping and available memory is low, it makes sense to share one
167 * buffer across all the serial ports, since it significantly saves
168 * memory if large numbers of serial ports are open.
169 */
170static unsigned char *tmp_buf;
171static DECLARE_MUTEX(tmp_buf_sem);
172
173
174static inline int __pmac
175serial_paranoia_check(struct mac_serial *info,
176 char *name, const char *routine)
177{
178#ifdef SERIAL_PARANOIA_CHECK
179 static const char badmagic[] = KERN_WARNING
180 "Warning: bad magic number for serial struct %s in %s\n";
181 static const char badinfo[] = KERN_WARNING
182 "Warning: null mac_serial for %s in %s\n";
183
184 if (!info) {
185 printk(badinfo, name, routine);
186 return 1;
187 }
188 if (info->magic != SERIAL_MAGIC) {
189 printk(badmagic, name, routine);
190 return 1;
191 }
192#endif
193 return 0;
194}
195
196/*
197 * Reading and writing Z8530 registers.
198 */
199static inline unsigned char __pmac read_zsreg(struct mac_zschannel *channel,
200 unsigned char reg)
201{
202 unsigned char retval;
203 unsigned long flags;
204
205 /*
206 * We have to make this atomic.
207 */
208 spin_lock_irqsave(&channel->lock, flags);
209 if (reg != 0) {
210 *channel->control = reg;
211 RECOVERY_DELAY;
212 }
213 retval = *channel->control;
214 RECOVERY_DELAY;
215 spin_unlock_irqrestore(&channel->lock, flags);
216 return retval;
217}
218
219static inline void __pmac write_zsreg(struct mac_zschannel *channel,
220 unsigned char reg, unsigned char value)
221{
222 unsigned long flags;
223
224 spin_lock_irqsave(&channel->lock, flags);
225 if (reg != 0) {
226 *channel->control = reg;
227 RECOVERY_DELAY;
228 }
229 *channel->control = value;
230 RECOVERY_DELAY;
231 spin_unlock_irqrestore(&channel->lock, flags);
232 return;
233}
234
235static inline unsigned char __pmac read_zsdata(struct mac_zschannel *channel)
236{
237 unsigned char retval;
238
239 retval = *channel->data;
240 RECOVERY_DELAY;
241 return retval;
242}
243
244static inline void write_zsdata(struct mac_zschannel *channel,
245 unsigned char value)
246{
247 *channel->data = value;
248 RECOVERY_DELAY;
249 return;
250}
251
252static inline void load_zsregs(struct mac_zschannel *channel,
253 unsigned char *regs)
254{
255 ZS_CLEARERR(channel);
256 ZS_CLEARFIFO(channel);
257 /* Load 'em up */
258 write_zsreg(channel, R4, regs[R4]);
259 write_zsreg(channel, R10, regs[R10]);
260 write_zsreg(channel, R3, regs[R3] & ~RxENABLE);
261 write_zsreg(channel, R5, regs[R5] & ~TxENAB);
262 write_zsreg(channel, R1, regs[R1]);
263 write_zsreg(channel, R9, regs[R9]);
264 write_zsreg(channel, R11, regs[R11]);
265 write_zsreg(channel, R12, regs[R12]);
266 write_zsreg(channel, R13, regs[R13]);
267 write_zsreg(channel, R14, regs[R14]);
268 write_zsreg(channel, R15, regs[R15]);
269 write_zsreg(channel, R3, regs[R3]);
270 write_zsreg(channel, R5, regs[R5]);
271 return;
272}
273
274/* Sets or clears DTR/RTS on the requested line */
275static inline void zs_rtsdtr(struct mac_serial *ss, int set)
276{
277 if (set)
278 ss->curregs[5] |= (RTS | DTR);
279 else
280 ss->curregs[5] &= ~(RTS | DTR);
281 write_zsreg(ss->zs_channel, 5, ss->curregs[5]);
282 return;
283}
284
285/* Utility routines for the Zilog */
286static inline int get_zsbaud(struct mac_serial *ss)
287{
288 struct mac_zschannel *channel = ss->zs_channel;
289 int brg;
290
291 if ((ss->curregs[R11] & TCBR) == 0) {
292 /* higher rates don't use the baud rate generator */
293 return (ss->curregs[R4] & X32CLK)? ZS_CLOCK/32: ZS_CLOCK/16;
294 }
295 /* The baud rate is split up between two 8-bit registers in
296 * what is termed 'BRG time constant' format in my docs for
297 * the chip, it is a function of the clk rate the chip is
298 * receiving which happens to be constant.
299 */
300 brg = (read_zsreg(channel, 13) << 8);
301 brg |= read_zsreg(channel, 12);
302 return BRG_TO_BPS(brg, (ZS_CLOCK/(ss->clk_divisor)));
303}
304
305/* On receive, this clears errors and the receiver interrupts */
306static inline void rs_recv_clear(struct mac_zschannel *zsc)
307{
308 write_zsreg(zsc, 0, ERR_RES);
309 write_zsreg(zsc, 0, RES_H_IUS); /* XXX this is unnecessary */
310}
311
312/*
313 * Reset a Descriptor-Based DMA channel.
314 */
315static void dbdma_reset(volatile struct dbdma_regs *dma)
316{
317 int i;
318
319 out_le32(&dma->control, (WAKE|FLUSH|PAUSE|RUN) << 16);
320
321 /*
322 * Yes this looks peculiar, but apparently it needs to be this
323 * way on some machines. (We need to make sure the DBDMA
324 * engine has actually got the write above and responded
325 * to it. - paulus)
326 */
327 for (i = 200; i > 0; --i)
328 if (ld_le32(&dma->status) & RUN)
329 udelay(1);
330}
331
332/*
333 * Tells a DBDMA channel to stop and write any buffered data
334 * it might have to memory.
335 */
336static _INLINE_ void dbdma_flush(volatile struct dbdma_regs *dma)
337{
338 int i = 0;
339
340 out_le32(&dma->control, (FLUSH << 16) | FLUSH);
341 while (((in_le32(&dma->status) & FLUSH) != 0) && (i++ < 100))
342 udelay(1);
343}
344
345/*
346 * ----------------------------------------------------------------------
347 *
348 * Here starts the interrupt handling routines. All of the following
349 * subroutines are declared as inline and are folded into
350 * rs_interrupt(). They were separated out for readability's sake.
351 *
352 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
353 * -----------------------------------------------------------------------
354 */
355
356/*
357 * This routine is used by the interrupt handler to schedule
358 * processing in the software interrupt portion of the driver.
359 */
360static _INLINE_ void rs_sched_event(struct mac_serial *info,
361 int event)
362{
363 info->event |= 1 << event;
364 schedule_work(&info->tqueue);
365}
366
367/* Work out the flag value for a z8530 status value. */
368static _INLINE_ int stat_to_flag(int stat)
369{
370 int flag;
371
372 if (stat & Rx_OVR) {
373 flag = TTY_OVERRUN;
374 } else if (stat & FRM_ERR) {
375 flag = TTY_FRAME;
376 } else if (stat & PAR_ERR) {
377 flag = TTY_PARITY;
378 } else
379 flag = 0;
380 return flag;
381}
382
383static _INLINE_ void receive_chars(struct mac_serial *info,
384 struct pt_regs *regs)
385{
386 struct tty_struct *tty = info->tty;
387 unsigned char ch, stat, flag;
388
389 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) != 0) {
390
391 stat = read_zsreg(info->zs_channel, R1);
392 ch = read_zsdata(info->zs_channel);
393
394#ifdef CONFIG_KGDB
395 if (info->kgdb_channel) {
396 if (ch == 0x03 || ch == '$')
397 breakpoint();
398 if (stat & (Rx_OVR|FRM_ERR|PAR_ERR))
399 write_zsreg(info->zs_channel, 0, ERR_RES);
400 return;
401 }
402#endif
403 if (!tty)
404 continue;
405 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
406 tty_flip_buffer_push(tty);
407
408 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
409 static int flip_buf_ovf;
410 if (++flip_buf_ovf <= 1)
411 printk(KERN_WARNING "FB. overflow: %d\n",
412 flip_buf_ovf);
413 break;
414 }
415 tty->flip.count++;
416 {
417 static int flip_max_cnt;
418 if (flip_max_cnt < tty->flip.count)
419 flip_max_cnt = tty->flip.count;
420 }
421 flag = stat_to_flag(stat);
422 if (flag)
423 /* reset the error indication */
424 write_zsreg(info->zs_channel, 0, ERR_RES);
425 *tty->flip.flag_buf_ptr++ = flag;
426 *tty->flip.char_buf_ptr++ = ch;
427 }
428 if (tty)
429 tty_flip_buffer_push(tty);
430}
431
432static void transmit_chars(struct mac_serial *info)
433{
434 if ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0)
435 return;
436 info->tx_active = 0;
437
438 if (info->x_char && !info->power_wait) {
439 /* Send next char */
440 write_zsdata(info->zs_channel, info->x_char);
441 info->x_char = 0;
442 info->tx_active = 1;
443 return;
444 }
445
446 if ((info->xmit_cnt <= 0) || info->tty->stopped || info->tx_stopped
447 || info->power_wait) {
448 write_zsreg(info->zs_channel, 0, RES_Tx_P);
449 return;
450 }
451
452 /* Send char */
453 write_zsdata(info->zs_channel, info->xmit_buf[info->xmit_tail++]);
454 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
455 info->xmit_cnt--;
456 info->tx_active = 1;
457
458 if (info->xmit_cnt < WAKEUP_CHARS)
459 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
460}
461
462static void powerup_done(unsigned long data)
463{
464 struct mac_serial *info = (struct mac_serial *) data;
465 unsigned long flags;
466
467 spin_lock_irqsave(&info->lock, flags);
468 info->power_wait = 0;
469 transmit_chars(info);
470 spin_unlock_irqrestore(&info->lock, flags);
471}
472
473static _INLINE_ void status_handle(struct mac_serial *info)
474{
475 unsigned char status;
476
477 /* Get status from Read Register 0 */
478 status = read_zsreg(info->zs_channel, 0);
479
480 /* Check for DCD transitions */
481 if (((status ^ info->read_reg_zero) & DCD) != 0
482 && info->tty && !C_CLOCAL(info->tty)) {
483 if (status & DCD) {
484 wake_up_interruptible(&info->open_wait);
485 } else {
486 if (info->tty)
487 tty_hangup(info->tty);
488 }
489 }
490
491 /* Check for CTS transitions */
492 if (info->tty && C_CRTSCTS(info->tty)) {
493 /*
494 * For some reason, on the Power Macintosh,
495 * it seems that the CTS bit is 1 when CTS is
496 * *negated* and 0 when it is asserted.
497 * The DCD bit doesn't seem to be inverted
498 * like this.
499 */
500 if ((status & CTS) == 0) {
501 if (info->tx_stopped) {
502#ifdef SERIAL_DEBUG_FLOW
503 printk(KERN_DEBUG "CTS up\n");
504#endif
505 info->tx_stopped = 0;
506 if (!info->tx_active)
507 transmit_chars(info);
508 }
509 } else {
510#ifdef SERIAL_DEBUG_FLOW
511 printk(KERN_DEBUG "CTS down\n");
512#endif
513 info->tx_stopped = 1;
514 }
515 }
516
517 /* Clear status condition... */
518 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
519 info->read_reg_zero = status;
520}
521
522static _INLINE_ void receive_special_dma(struct mac_serial *info)
523{
524 unsigned char stat, flag;
525 volatile struct dbdma_regs *rd = &info->rx->dma;
526 int where = RX_BUF_SIZE;
527
528 spin_lock(&info->rx_dma_lock);
529 if ((ld_le32(&rd->status) & ACTIVE) != 0)
530 dbdma_flush(rd);
531 if (in_le32(&rd->cmdptr)
532 == virt_to_bus(info->rx_cmds[info->rx_cbuf] + 1))
533 where -= in_le16(&info->rx->res_count);
534 where--;
535
536 stat = read_zsreg(info->zs_channel, R1);
537
538 flag = stat_to_flag(stat);
539 if (flag) {
540 info->rx_flag_buf[info->rx_cbuf][where] = flag;
541 /* reset the error indication */
542 write_zsreg(info->zs_channel, 0, ERR_RES);
543 }
544
545 spin_unlock(&info->rx_dma_lock);
546}
547
548/*
549 * This is the serial driver's generic interrupt routine
550 */
551static irqreturn_t rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
552{
553 struct mac_serial *info = (struct mac_serial *) dev_id;
554 unsigned char zs_intreg;
555 int shift;
556 unsigned long flags;
557 int handled = 0;
558
559 if (!(info->flags & ZILOG_INITIALIZED)) {
560 printk(KERN_WARNING "rs_interrupt: irq %d, port not "
561 "initialized\n", irq);
562 disable_irq(irq);
563 return IRQ_NONE;
564 }
565
566 /* NOTE: The read register 3, which holds the irq status,
567 * does so for both channels on each chip. Although
568 * the status value itself must be read from the A
569 * channel and is only valid when read from channel A.
570 * Yes... broken hardware...
571 */
572#define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
573
574 if (info->zs_chan_a == info->zs_channel)
575 shift = 3; /* Channel A */
576 else
577 shift = 0; /* Channel B */
578
579 spin_lock_irqsave(&info->lock, flags);
580 for (;;) {
581 zs_intreg = read_zsreg(info->zs_chan_a, 3) >> shift;
582#ifdef SERIAL_DEBUG_INTR
583 printk(KERN_DEBUG "rs_interrupt: irq %d, zs_intreg 0x%x\n",
584 irq, (int)zs_intreg);
585#endif
586
587 if ((zs_intreg & CHAN_IRQMASK) == 0)
588 break;
589 handled = 1;
590
591 if (zs_intreg & CHBRxIP) {
592 /* If we are doing DMA, we only ask for interrupts
593 on characters with errors or special conditions. */
594 if (info->dma_initted)
595 receive_special_dma(info);
596 else
597 receive_chars(info, regs);
598 }
599 if (zs_intreg & CHBTxIP)
600 transmit_chars(info);
601 if (zs_intreg & CHBEXT)
602 status_handle(info);
603 }
604 spin_unlock_irqrestore(&info->lock, flags);
605 return IRQ_RETVAL(handled);
606}
607
608/* Transmit DMA interrupt - not used at present */
609static irqreturn_t rs_txdma_irq(int irq, void *dev_id, struct pt_regs *regs)
610{
611 return IRQ_HANDLED;
612}
613
614/*
615 * Receive DMA interrupt.
616 */
617static irqreturn_t rs_rxdma_irq(int irq, void *dev_id, struct pt_regs *regs)
618{
619 struct mac_serial *info = (struct mac_serial *) dev_id;
620 volatile struct dbdma_cmd *cd;
621
622 if (!info->dma_initted)
623 return IRQ_NONE;
624 spin_lock(&info->rx_dma_lock);
625 /* First, confirm that this interrupt is, indeed, coming */
626 /* from Rx DMA */
627 cd = info->rx_cmds[info->rx_cbuf] + 2;
628 if ((in_le16(&cd->xfer_status) & (RUN | ACTIVE)) != (RUN | ACTIVE)) {
629 spin_unlock(&info->rx_dma_lock);
630 return IRQ_NONE;
631 }
632 if (info->rx_fbuf != RX_NO_FBUF) {
633 info->rx_cbuf = info->rx_fbuf;
634 if (++info->rx_fbuf == info->rx_nbuf)
635 info->rx_fbuf = 0;
636 if (info->rx_fbuf == info->rx_ubuf)
637 info->rx_fbuf = RX_NO_FBUF;
638 }
639 spin_unlock(&info->rx_dma_lock);
640 return IRQ_HANDLED;
641}
642
643/*
644 * -------------------------------------------------------------------
645 * Here ends the serial interrupt routines.
646 * -------------------------------------------------------------------
647 */
648
649/*
650 * ------------------------------------------------------------
651 * rs_stop() and rs_start()
652 *
653 * This routines are called before setting or resetting tty->stopped.
654 * ------------------------------------------------------------
655 */
656static void rs_stop(struct tty_struct *tty)
657{
658 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
659
660#ifdef SERIAL_DEBUG_STOP
661 printk(KERN_DEBUG "rs_stop %ld....\n",
662 tty->ldisc.chars_in_buffer(tty));
663#endif
664
665 if (serial_paranoia_check(info, tty->name, "rs_stop"))
666 return;
667
668#if 0
669 spin_lock_irqsave(&info->lock, flags);
670 if (info->curregs[5] & TxENAB) {
671 info->curregs[5] &= ~TxENAB;
672 info->pendregs[5] &= ~TxENAB;
673 write_zsreg(info->zs_channel, 5, info->curregs[5]);
674 }
675 spin_unlock_irqrestore(&info->lock, flags);
676#endif
677}
678
679static void rs_start(struct tty_struct *tty)
680{
681 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
682 unsigned long flags;
683
684#ifdef SERIAL_DEBUG_STOP
685 printk(KERN_DEBUG "rs_start %ld....\n",
686 tty->ldisc.chars_in_buffer(tty));
687#endif
688
689 if (serial_paranoia_check(info, tty->name, "rs_start"))
690 return;
691
692 spin_lock_irqsave(&info->lock, flags);
693#if 0
694 if (info->xmit_cnt && info->xmit_buf && !(info->curregs[5] & TxENAB)) {
695 info->curregs[5] |= TxENAB;
696 info->pendregs[5] = info->curregs[5];
697 write_zsreg(info->zs_channel, 5, info->curregs[5]);
698 }
699#else
700 if (info->xmit_cnt && info->xmit_buf && !info->tx_active) {
701 transmit_chars(info);
702 }
703#endif
704 spin_unlock_irqrestore(&info->lock, flags);
705}
706
707static void do_softint(void *private_)
708{
709 struct mac_serial *info = (struct mac_serial *) private_;
710 struct tty_struct *tty;
711
712 tty = info->tty;
713 if (!tty)
714 return;
715
716 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
717 tty_wakeup(tty);
718}
719
720static int startup(struct mac_serial * info)
721{
722 int delay;
723
724 OPNDBG("startup() (ttyS%d, irq %d)\n", info->line, info->irq);
725
726 if (info->flags & ZILOG_INITIALIZED) {
727 OPNDBG(" -> already inited\n");
728 return 0;
729 }
730
731 if (!info->xmit_buf) {
732 info->xmit_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
733 if (!info->xmit_buf)
734 return -ENOMEM;
735 }
736
737 OPNDBG("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
738
739 delay = set_scc_power(info, 1);
740
741 setup_scc(info);
742
743 if (delay) {
744 unsigned long flags;
745
746 /* delay is in ms */
747 spin_lock_irqsave(&info->lock, flags);
748 info->power_wait = 1;
749 mod_timer(&info->powerup_timer,
750 jiffies + (delay * HZ + 999) / 1000);
751 spin_unlock_irqrestore(&info->lock, flags);
752 }
753
754 OPNDBG("enabling IRQ on ttyS%d (irq %d)...\n", info->line, info->irq);
755
756 info->flags |= ZILOG_INITIALIZED;
757 enable_irq(info->irq);
758 if (info->dma_initted) {
759 enable_irq(info->rx_dma_irq);
760 }
761
762 return 0;
763}
764
765static _INLINE_ void rxdma_start(struct mac_serial * info, int curr)
766{
767 volatile struct dbdma_regs *rd = &info->rx->dma;
768 volatile struct dbdma_cmd *cd = info->rx_cmds[curr];
769
770//printk(KERN_DEBUG "SCC: rxdma_start\n");
771
772 st_le32(&rd->cmdptr, virt_to_bus(cd));
773 out_le32(&rd->control, (RUN << 16) | RUN);
774}
775
776static void rxdma_to_tty(struct mac_serial *info)
777{
778 struct tty_struct *tty = info->tty;
779 volatile struct dbdma_regs *rd = &info->rx->dma;
780 unsigned long flags;
781 int residue, available, space, do_queue;
782
783 if (!tty)
784 return;
785
786 do_queue = 0;
787 spin_lock_irqsave(&info->rx_dma_lock, flags);
788more:
789 space = TTY_FLIPBUF_SIZE - tty->flip.count;
790 if (!space) {
791 do_queue++;
792 goto out;
793 }
794 residue = 0;
795 if (info->rx_ubuf == info->rx_cbuf) {
796 if ((ld_le32(&rd->status) & ACTIVE) != 0) {
797 dbdma_flush(rd);
798 if (in_le32(&rd->cmdptr)
799 == virt_to_bus(info->rx_cmds[info->rx_cbuf]+1))
800 residue = in_le16(&info->rx->res_count);
801 }
802 }
803 available = RX_BUF_SIZE - residue - info->rx_done_bytes;
804 if (available > space)
805 available = space;
806 if (available) {
807 memcpy(tty->flip.char_buf_ptr,
808 info->rx_char_buf[info->rx_ubuf] + info->rx_done_bytes,
809 available);
810 memcpy(tty->flip.flag_buf_ptr,
811 info->rx_flag_buf[info->rx_ubuf] + info->rx_done_bytes,
812 available);
813 tty->flip.char_buf_ptr += available;
814 tty->flip.count += available;
815 tty->flip.flag_buf_ptr += available;
816 memset(info->rx_flag_buf[info->rx_ubuf] + info->rx_done_bytes,
817 0, available);
818 info->rx_done_bytes += available;
819 do_queue++;
820 }
821 if (info->rx_done_bytes == RX_BUF_SIZE) {
822 volatile struct dbdma_cmd *cd = info->rx_cmds[info->rx_ubuf];
823
824 if (info->rx_ubuf == info->rx_cbuf)
825 goto out;
826 /* mark rx_char_buf[rx_ubuf] free */
827 st_le16(&cd->command, DBDMA_NOP);
828 cd++;
829 st_le32(&cd->cmd_dep, 0);
830 st_le32((unsigned int *)&cd->res_count, 0);
831 cd++;
832 st_le16(&cd->xfer_status, 0);
833
834 if (info->rx_fbuf == RX_NO_FBUF) {
835 info->rx_fbuf = info->rx_ubuf;
836 if (!(ld_le32(&rd->status) & ACTIVE)) {
837 dbdma_reset(&info->rx->dma);
838 rxdma_start(info, info->rx_ubuf);
839 info->rx_cbuf = info->rx_ubuf;
840 }
841 }
842 info->rx_done_bytes = 0;
843 if (++info->rx_ubuf == info->rx_nbuf)
844 info->rx_ubuf = 0;
845 if (info->rx_fbuf == info->rx_ubuf)
846 info->rx_fbuf = RX_NO_FBUF;
847 goto more;
848 }
849out:
850 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
851 if (do_queue)
852 tty_flip_buffer_push(tty);
853}
854
855static void poll_rxdma(unsigned long private_)
856{
857 struct mac_serial *info = (struct mac_serial *) private_;
858 unsigned long flags;
859
860 rxdma_to_tty(info);
861 spin_lock_irqsave(&info->rx_dma_lock, flags);
862 mod_timer(&info->poll_dma_timer, RX_DMA_TIMER);
863 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
864}
865
866static void dma_init(struct mac_serial * info)
867{
868 int i, size;
869 volatile struct dbdma_cmd *cd;
870 unsigned char *p;
871
872 info->rx_nbuf = 8;
873
874 /* various mem set up */
875 size = sizeof(struct dbdma_cmd) * (3 * info->rx_nbuf + 2)
876 + (RX_BUF_SIZE * 2 + sizeof(*info->rx_cmds)
877 + sizeof(*info->rx_char_buf) + sizeof(*info->rx_flag_buf))
878 * info->rx_nbuf;
879 info->dma_priv = kmalloc(size, GFP_KERNEL | GFP_DMA);
880 if (info->dma_priv == NULL)
881 return;
882 memset(info->dma_priv, 0, size);
883
884 info->rx_cmds = (volatile struct dbdma_cmd **)info->dma_priv;
885 info->rx_char_buf = (unsigned char **) (info->rx_cmds + info->rx_nbuf);
886 info->rx_flag_buf = info->rx_char_buf + info->rx_nbuf;
887 p = (unsigned char *) (info->rx_flag_buf + info->rx_nbuf);
888 for (i = 0; i < info->rx_nbuf; i++, p += RX_BUF_SIZE)
889 info->rx_char_buf[i] = p;
890 for (i = 0; i < info->rx_nbuf; i++, p += RX_BUF_SIZE)
891 info->rx_flag_buf[i] = p;
892
893 /* a bit of DMA programming */
894 cd = info->rx_cmds[0] = (volatile struct dbdma_cmd *) DBDMA_ALIGN(p);
895 st_le16(&cd->command, DBDMA_NOP);
896 cd++;
897 st_le16(&cd->req_count, RX_BUF_SIZE);
898 st_le16(&cd->command, INPUT_MORE);
899 st_le32(&cd->phy_addr, virt_to_bus(info->rx_char_buf[0]));
900 cd++;
901 st_le16(&cd->req_count, 4);
902 st_le16(&cd->command, STORE_WORD | INTR_ALWAYS);
903 st_le32(&cd->phy_addr, virt_to_bus(cd-2));
904 st_le32(&cd->cmd_dep, DBDMA_STOP);
905 for (i = 1; i < info->rx_nbuf; i++) {
906 info->rx_cmds[i] = ++cd;
907 st_le16(&cd->command, DBDMA_NOP);
908 cd++;
909 st_le16(&cd->req_count, RX_BUF_SIZE);
910 st_le16(&cd->command, INPUT_MORE);
911 st_le32(&cd->phy_addr, virt_to_bus(info->rx_char_buf[i]));
912 cd++;
913 st_le16(&cd->req_count, 4);
914 st_le16(&cd->command, STORE_WORD | INTR_ALWAYS);
915 st_le32(&cd->phy_addr, virt_to_bus(cd-2));
916 st_le32(&cd->cmd_dep, DBDMA_STOP);
917 }
918 cd++;
919 st_le16(&cd->command, DBDMA_NOP | BR_ALWAYS);
920 st_le32(&cd->cmd_dep, virt_to_bus(info->rx_cmds[0]));
921
922 /* setup DMA to our liking */
923 dbdma_reset(&info->rx->dma);
924 st_le32(&info->rx->dma.intr_sel, 0x10001);
925 st_le32(&info->rx->dma.br_sel, 0x10001);
926 out_le32(&info->rx->dma.wait_sel, 0x10001);
927
928 /* set various flags */
929 info->rx_ubuf = 0;
930 info->rx_cbuf = 0;
931 info->rx_fbuf = info->rx_ubuf + 1;
932 if (info->rx_fbuf == info->rx_nbuf)
933 info->rx_fbuf = RX_NO_FBUF;
934 info->rx_done_bytes = 0;
935
936 /* setup polling */
937 init_timer(&info->poll_dma_timer);
938 info->poll_dma_timer.function = (void *)&poll_rxdma;
939 info->poll_dma_timer.data = (unsigned long)info;
940
941 info->dma_initted = 1;
942}
943
944/*
945 * FixZeroBug....Works around a bug in the SCC receving channel.
946 * Taken from Darwin code, 15 Sept. 2000 -DanM
947 *
948 * The following sequence prevents a problem that is seen with O'Hare ASICs
949 * (most versions -- also with some Heathrow and Hydra ASICs) where a zero
950 * at the input to the receiver becomes 'stuck' and locks up the receiver.
951 * This problem can occur as a result of a zero bit at the receiver input
952 * coincident with any of the following events:
953 *
954 * The SCC is initialized (hardware or software).
955 * A framing error is detected.
956 * The clocking option changes from synchronous or X1 asynchronous
957 * clocking to X16, X32, or X64 asynchronous clocking.
958 * The decoding mode is changed among NRZ, NRZI, FM0, or FM1.
959 *
960 * This workaround attempts to recover from the lockup condition by placing
961 * the SCC in synchronous loopback mode with a fast clock before programming
962 * any of the asynchronous modes.
963 */
964static void fix_zero_bug_scc(struct mac_serial * info)
965{
966 write_zsreg(info->zs_channel, 9,
967 (info->zs_channel == info->zs_chan_a? CHRA: CHRB));
968 udelay(10);
969 write_zsreg(info->zs_channel, 9,
970 ((info->zs_channel == info->zs_chan_a? CHRA: CHRB) | NV));
971
972 write_zsreg(info->zs_channel, 4, (X1CLK | EXTSYNC));
973
974 /* I think this is wrong....but, I just copying code....
975 */
976 write_zsreg(info->zs_channel, 3, (8 & ~RxENABLE));
977
978 write_zsreg(info->zs_channel, 5, (8 & ~TxENAB));
979 write_zsreg(info->zs_channel, 9, NV); /* Didn't we already do this? */
980 write_zsreg(info->zs_channel, 11, (RCBR | TCBR));
981 write_zsreg(info->zs_channel, 12, 0);
982 write_zsreg(info->zs_channel, 13, 0);
983 write_zsreg(info->zs_channel, 14, (LOOPBAK | SSBR));
984 write_zsreg(info->zs_channel, 14, (LOOPBAK | SSBR | BRENABL));
985 write_zsreg(info->zs_channel, 3, (8 | RxENABLE));
986 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
987 write_zsreg(info->zs_channel, 0, RES_EXT_INT); /* to kill some time */
988
989 /* The channel should be OK now, but it is probably receiving
990 * loopback garbage.
991 * Switch to asynchronous mode, disable the receiver,
992 * and discard everything in the receive buffer.
993 */
994 write_zsreg(info->zs_channel, 9, NV);
995 write_zsreg(info->zs_channel, 4, PAR_ENA);
996 write_zsreg(info->zs_channel, 3, (8 & ~RxENABLE));
997
998 while (read_zsreg(info->zs_channel, 0) & Rx_CH_AV) {
999 (void)read_zsreg(info->zs_channel, 8);
1000 write_zsreg(info->zs_channel, 0, RES_EXT_INT);
1001 write_zsreg(info->zs_channel, 0, ERR_RES);
1002 }
1003}
1004
1005static int setup_scc(struct mac_serial * info)
1006{
1007 unsigned long flags;
1008
1009 OPNDBG("setting up ttyS%d SCC...\n", info->line);
1010
1011 spin_lock_irqsave(&info->lock, flags);
1012
1013 /* Nice buggy HW ... */
1014 fix_zero_bug_scc(info);
1015
1016 /*
1017 * Reset the chip.
1018 */
1019 write_zsreg(info->zs_channel, 9,
1020 (info->zs_channel == info->zs_chan_a? CHRA: CHRB));
1021 udelay(10);
1022 write_zsreg(info->zs_channel, 9, 0);
1023
1024 /*
1025 * Clear the receive FIFO.
1026 */
1027 ZS_CLEARFIFO(info->zs_channel);
1028 info->xmit_fifo_size = 1;
1029
1030 /*
1031 * Reset DMAs
1032 */
1033 if (info->has_dma)
1034 dma_init(info);
1035
1036 /*
1037 * Clear the interrupt registers.
1038 */
1039 write_zsreg(info->zs_channel, 0, ERR_RES);
1040 write_zsreg(info->zs_channel, 0, RES_H_IUS);
1041
1042 /*
1043 * Turn on RTS and DTR.
1044 */
1045 if (!info->is_irda)
1046 zs_rtsdtr(info, 1);
1047
1048 /*
1049 * Finally, enable sequencing and interrupts
1050 */
1051 if (!info->dma_initted) {
1052 /* interrupt on ext/status changes, all received chars,
1053 transmit ready */
1054 info->curregs[1] = (info->curregs[1] & ~0x18)
1055 | (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB);
1056 } else {
1057 /* interrupt on ext/status changes, W/Req pin is
1058 receive DMA request */
1059 info->curregs[1] = (info->curregs[1] & ~(0x18 | TxINT_ENAB))
1060 | (EXT_INT_ENAB | WT_RDY_RT | WT_FN_RDYFN);
1061 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1062 /* enable W/Req pin */
1063 info->curregs[1] |= WT_RDY_ENAB;
1064 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1065 /* enable interrupts on transmit ready and receive errors */
1066 info->curregs[1] |= INT_ERR_Rx | TxINT_ENAB;
1067 }
1068 info->pendregs[1] = info->curregs[1];
1069 info->curregs[3] |= (RxENABLE | Rx8);
1070 info->pendregs[3] = info->curregs[3];
1071 info->curregs[5] |= (TxENAB | Tx8);
1072 info->pendregs[5] = info->curregs[5];
1073 info->curregs[9] |= (NV | MIE);
1074 info->pendregs[9] = info->curregs[9];
1075 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1076 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1077 write_zsreg(info->zs_channel, 9, info->curregs[9]);
1078
1079 if (info->tty)
1080 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1081 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1082
1083 spin_unlock_irqrestore(&info->lock, flags);
1084
1085 /*
1086 * Set the speed of the serial port
1087 */
1088 change_speed(info, 0);
1089
1090 /* Save the current value of RR0 */
1091 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
1092
1093 if (info->dma_initted) {
1094 spin_lock_irqsave(&info->rx_dma_lock, flags);
1095 rxdma_start(info, 0);
1096 info->poll_dma_timer.expires = RX_DMA_TIMER;
1097 add_timer(&info->poll_dma_timer);
1098 spin_unlock_irqrestore(&info->rx_dma_lock, flags);
1099 }
1100
1101 return 0;
1102}
1103
1104/*
1105 * This routine will shutdown a serial port; interrupts are disabled, and
1106 * DTR is dropped if the hangup on close termio flag is on.
1107 */
1108static void shutdown(struct mac_serial * info)
1109{
1110 OPNDBG("Shutting down serial port %d (irq %d)....\n", info->line,
1111 info->irq);
1112
1113 if (!(info->flags & ZILOG_INITIALIZED)) {
1114 OPNDBG("(already shutdown)\n");
1115 return;
1116 }
1117
1118 if (info->has_dma) {
1119 del_timer(&info->poll_dma_timer);
1120 dbdma_reset(info->tx_dma);
1121 dbdma_reset(&info->rx->dma);
1122 disable_irq(info->tx_dma_irq);
1123 disable_irq(info->rx_dma_irq);
1124 }
1125 disable_irq(info->irq);
1126
1127 info->pendregs[1] = info->curregs[1] = 0;
1128 write_zsreg(info->zs_channel, 1, 0); /* no interrupts */
1129
1130 info->curregs[3] &= ~RxENABLE;
1131 info->pendregs[3] = info->curregs[3];
1132 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1133
1134 info->curregs[5] &= ~TxENAB;
1135 if (!info->tty || C_HUPCL(info->tty))
1136 info->curregs[5] &= ~DTR;
1137 info->pendregs[5] = info->curregs[5];
1138 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1139
1140 if (info->tty)
1141 set_bit(TTY_IO_ERROR, &info->tty->flags);
1142
1143 set_scc_power(info, 0);
1144
1145 if (info->xmit_buf) {
1146 free_page((unsigned long) info->xmit_buf);
1147 info->xmit_buf = 0;
1148 }
1149
1150 if (info->has_dma && info->dma_priv) {
1151 kfree(info->dma_priv);
1152 info->dma_priv = NULL;
1153 info->dma_initted = 0;
1154 }
1155
1156 memset(info->curregs, 0, sizeof(info->curregs));
1157 memset(info->pendregs, 0, sizeof(info->pendregs));
1158
1159 info->flags &= ~ZILOG_INITIALIZED;
1160}
1161
1162/*
1163 * Turn power on or off to the SCC and associated stuff
1164 * (port drivers, modem, IR port, etc.)
1165 * Returns the number of milliseconds we should wait before
1166 * trying to use the port.
1167 */
1168static int set_scc_power(struct mac_serial * info, int state)
1169{
1170 int delay = 0;
1171
1172 if (state) {
1173 PWRDBG("ttyS%d: powering up hardware\n", info->line);
1174 pmac_call_feature(
1175 PMAC_FTR_SCC_ENABLE,
1176 info->dev_node, info->port_type, 1);
1177 if (info->is_internal_modem) {
1178 pmac_call_feature(
1179 PMAC_FTR_MODEM_ENABLE,
1180 info->dev_node, 0, 1);
1181 delay = 2500; /* wait for 2.5s before using */
1182 } else if (info->is_irda)
1183 mdelay(50); /* Do better here once the problems
1184 * with blocking have been ironed out
1185 */
1186 } else {
1187 /* TODO: Make that depend on a timer, don't power down
1188 * immediately
1189 */
1190 PWRDBG("ttyS%d: shutting down hardware\n", info->line);
1191 if (info->is_internal_modem) {
1192 PWRDBG("ttyS%d: shutting down modem\n", info->line);
1193 pmac_call_feature(
1194 PMAC_FTR_MODEM_ENABLE,
1195 info->dev_node, 0, 0);
1196 }
1197 pmac_call_feature(
1198 PMAC_FTR_SCC_ENABLE,
1199 info->dev_node, info->port_type, 0);
1200 }
1201 return delay;
1202}
1203
1204static void irda_rts_pulses(struct mac_serial *info, int w)
1205{
1206 udelay(w);
1207 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB);
1208 udelay(2);
1209 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1210 udelay(8);
1211 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB);
1212 udelay(4);
1213 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1214}
1215
1216/*
1217 * Set the irda codec on the imac to the specified baud rate.
1218 */
1219static void irda_setup(struct mac_serial *info)
1220{
1221 int code, speed, t;
1222
1223 speed = info->tty->termios->c_cflag & CBAUD;
1224 if (speed < B2400 || speed > B115200)
1225 return;
1226 code = 0x4d + B115200 - speed;
1227
1228 /* disable serial interrupts and receive DMA */
1229 write_zsreg(info->zs_channel, 1, info->curregs[1] & ~0x9f);
1230
1231 /* wait for transmitter to drain */
1232 t = 10000;
1233 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0
1234 || (read_zsreg(info->zs_channel, 1) & ALL_SNT) == 0) {
1235 if (--t <= 0) {
1236 printk(KERN_ERR "transmitter didn't drain\n");
1237 return;
1238 }
1239 udelay(10);
1240 }
1241 udelay(100);
1242
1243 /* set to 8 bits, no parity, 19200 baud, RTS on, DTR off */
1244 write_zsreg(info->zs_channel, 4, X16CLK | SB1);
1245 write_zsreg(info->zs_channel, 11, TCBR | RCBR);
1246 t = BPS_TO_BRG(19200, ZS_CLOCK/16);
1247 write_zsreg(info->zs_channel, 12, t);
1248 write_zsreg(info->zs_channel, 13, t >> 8);
1249 write_zsreg(info->zs_channel, 14, BRENABL);
1250 write_zsreg(info->zs_channel, 3, Rx8 | RxENABLE);
1251 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1252
1253 /* set TxD low for ~104us and pulse RTS */
1254 udelay(1000);
1255 write_zsdata(info->zs_channel, 0xfe);
1256 irda_rts_pulses(info, 150);
1257 irda_rts_pulses(info, 180);
1258 irda_rts_pulses(info, 50);
1259 udelay(100);
1260
1261 /* assert DTR, wait 30ms, talk to the chip */
1262 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS | DTR);
1263 mdelay(30);
1264 while (read_zsreg(info->zs_channel, 0) & Rx_CH_AV)
1265 read_zsdata(info->zs_channel);
1266
1267 write_zsdata(info->zs_channel, 1);
1268 t = 1000;
1269 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) == 0) {
1270 if (--t <= 0) {
1271 printk(KERN_ERR "irda_setup timed out on 1st byte\n");
1272 goto out;
1273 }
1274 udelay(10);
1275 }
1276 t = read_zsdata(info->zs_channel);
1277 if (t != 4)
1278 printk(KERN_ERR "irda_setup 1st byte = %x\n", t);
1279
1280 write_zsdata(info->zs_channel, code);
1281 t = 1000;
1282 while ((read_zsreg(info->zs_channel, 0) & Rx_CH_AV) == 0) {
1283 if (--t <= 0) {
1284 printk(KERN_ERR "irda_setup timed out on 2nd byte\n");
1285 goto out;
1286 }
1287 udelay(10);
1288 }
1289 t = read_zsdata(info->zs_channel);
1290 if (t != code)
1291 printk(KERN_ERR "irda_setup 2nd byte = %x (%x)\n", t, code);
1292
1293 /* Drop DTR again and do some more RTS pulses */
1294 out:
1295 udelay(100);
1296 write_zsreg(info->zs_channel, 5, Tx8 | TxENAB | RTS);
1297 irda_rts_pulses(info, 80);
1298
1299 /* We should be right to go now. We assume that load_zsregs
1300 will get called soon to load up the correct baud rate etc. */
1301 info->curregs[5] = (info->curregs[5] | RTS) & ~DTR;
1302 info->pendregs[5] = info->curregs[5];
1303}
1304
1305/*
1306 * This routine is called to set the UART divisor registers to match
1307 * the specified baud rate for a serial port.
1308 */
1309static void change_speed(struct mac_serial *info, struct termios *old_termios)
1310{
1311 unsigned cflag;
1312 int bits;
1313 int brg, baud;
1314 unsigned long flags;
1315
1316 if (!info->tty || !info->tty->termios)
1317 return;
1318
1319 cflag = info->tty->termios->c_cflag;
1320 baud = tty_get_baud_rate(info->tty);
1321 if (baud == 0) {
1322 if (old_termios) {
1323 info->tty->termios->c_cflag &= ~CBAUD;
1324 info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
1325 cflag = info->tty->termios->c_cflag;
1326 baud = tty_get_baud_rate(info->tty);
1327 }
1328 else
1329 baud = info->zs_baud;
1330 }
1331 if (baud > 230400)
1332 baud = 230400;
1333 else if (baud == 0)
1334 baud = 38400;
1335
1336 spin_lock_irqsave(&info->lock, flags);
1337 info->zs_baud = baud;
1338 info->clk_divisor = 16;
1339
1340 BAUDBG(KERN_DEBUG "set speed to %d bds, ", baud);
1341
1342 switch (baud) {
1343 case ZS_CLOCK/16: /* 230400 */
1344 info->curregs[4] = X16CLK;
1345 info->curregs[11] = 0;
1346 break;
1347 case ZS_CLOCK/32: /* 115200 */
1348 info->curregs[4] = X32CLK;
1349 info->curregs[11] = 0;
1350 break;
1351 default:
1352 info->curregs[4] = X16CLK;
1353 info->curregs[11] = TCBR | RCBR;
1354 brg = BPS_TO_BRG(baud, ZS_CLOCK/info->clk_divisor);
1355 info->curregs[12] = (brg & 255);
1356 info->curregs[13] = ((brg >> 8) & 255);
1357 info->curregs[14] = BRENABL;
1358 }
1359
1360 /* byte size and parity */
1361 info->curregs[3] &= ~RxNBITS_MASK;
1362 info->curregs[5] &= ~TxNBITS_MASK;
1363 switch (cflag & CSIZE) {
1364 case CS5:
1365 info->curregs[3] |= Rx5;
1366 info->curregs[5] |= Tx5;
1367 BAUDBG("5 bits, ");
1368 bits = 7;
1369 break;
1370 case CS6:
1371 info->curregs[3] |= Rx6;
1372 info->curregs[5] |= Tx6;
1373 BAUDBG("6 bits, ");
1374 bits = 8;
1375 break;
1376 case CS7:
1377 info->curregs[3] |= Rx7;
1378 info->curregs[5] |= Tx7;
1379 BAUDBG("7 bits, ");
1380 bits = 9;
1381 break;
1382 case CS8:
1383 default: /* defaults to 8 bits */
1384 info->curregs[3] |= Rx8;
1385 info->curregs[5] |= Tx8;
1386 BAUDBG("8 bits, ");
1387 bits = 10;
1388 break;
1389 }
1390 info->pendregs[3] = info->curregs[3];
1391 info->pendregs[5] = info->curregs[5];
1392
1393 info->curregs[4] &= ~(SB_MASK | PAR_ENA | PAR_EVEN);
1394 if (cflag & CSTOPB) {
1395 info->curregs[4] |= SB2;
1396 bits++;
1397 BAUDBG("2 stop, ");
1398 } else {
1399 info->curregs[4] |= SB1;
1400 BAUDBG("1 stop, ");
1401 }
1402 if (cflag & PARENB) {
1403 bits++;
1404 info->curregs[4] |= PAR_ENA;
1405 BAUDBG("parity, ");
1406 }
1407 if (!(cflag & PARODD)) {
1408 info->curregs[4] |= PAR_EVEN;
1409 }
1410 info->pendregs[4] = info->curregs[4];
1411
1412 if (!(cflag & CLOCAL)) {
1413 if (!(info->curregs[15] & DCDIE))
1414 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
1415 info->curregs[15] |= DCDIE;
1416 } else
1417 info->curregs[15] &= ~DCDIE;
1418 if (cflag & CRTSCTS) {
1419 info->curregs[15] |= CTSIE;
1420 if ((read_zsreg(info->zs_channel, 0) & CTS) != 0)
1421 info->tx_stopped = 1;
1422 } else {
1423 info->curregs[15] &= ~CTSIE;
1424 info->tx_stopped = 0;
1425 }
1426 info->pendregs[15] = info->curregs[15];
1427
1428 /* Calc timeout value. This is pretty broken with high baud rates with HZ=100.
1429 This code would love a larger HZ and a >1 fifo size, but this is not
1430 a priority. The resulting value must be >HZ/2
1431 */
1432 info->timeout = ((info->xmit_fifo_size*HZ*bits) / baud);
1433 info->timeout += HZ/50+1; /* Add .02 seconds of slop */
1434
1435 BAUDBG("timeout=%d/%ds, base:%d\n", (int)info->timeout, (int)HZ,
1436 (int)info->baud_base);
1437
1438 /* set the irda codec to the right rate */
1439 if (info->is_irda)
1440 irda_setup(info);
1441
1442 /* Load up the new values */
1443 load_zsregs(info->zs_channel, info->curregs);
1444
1445 spin_unlock_irqrestore(&info->lock, flags);
1446}
1447
1448static void rs_flush_chars(struct tty_struct *tty)
1449{
1450 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1451 unsigned long flags;
1452
1453 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1454 return;
1455
1456 spin_lock_irqsave(&info->lock, flags);
1457 if (!(info->xmit_cnt <= 0 || tty->stopped || info->tx_stopped ||
1458 !info->xmit_buf))
1459 /* Enable transmitter */
1460 transmit_chars(info);
1461 spin_unlock_irqrestore(&info->lock, flags);
1462}
1463
1464static int rs_write(struct tty_struct * tty,
1465 const unsigned char *buf, int count)
1466{
1467 int c, ret = 0;
1468 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1469 unsigned long flags;
1470
1471 if (serial_paranoia_check(info, tty->name, "rs_write"))
1472 return 0;
1473
1474 if (!tty || !info->xmit_buf || !tmp_buf)
1475 return 0;
1476
1477 while (1) {
1478 spin_lock_irqsave(&info->lock, flags);
1479 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1480 SERIAL_XMIT_SIZE - info->xmit_head));
1481 if (c <= 0) {
1482 spin_unlock_irqrestore(&info->lock, flags);
1483 break;
1484 }
1485 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1486 info->xmit_head = ((info->xmit_head + c) &
1487 (SERIAL_XMIT_SIZE-1));
1488 info->xmit_cnt += c;
1489 spin_unlock_irqrestore(&info->lock, flags);
1490 buf += c;
1491 count -= c;
1492 ret += c;
1493 }
1494 spin_lock_irqsave(&info->lock, flags);
1495 if (info->xmit_cnt && !tty->stopped && !info->tx_stopped
1496 && !info->tx_active)
1497 transmit_chars(info);
1498 spin_unlock_irqrestore(&info->lock, flags);
1499 return ret;
1500}
1501
1502static int rs_write_room(struct tty_struct *tty)
1503{
1504 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1505 int ret;
1506
1507 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1508 return 0;
1509 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1510 if (ret < 0)
1511 ret = 0;
1512 return ret;
1513}
1514
1515static int rs_chars_in_buffer(struct tty_struct *tty)
1516{
1517 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1518
1519 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1520 return 0;
1521 return info->xmit_cnt;
1522}
1523
1524static void rs_flush_buffer(struct tty_struct *tty)
1525{
1526 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1527 unsigned long flags;
1528
1529 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1530 return;
1531 spin_lock_irqsave(&info->lock, flags);
1532 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1533 spin_unlock_irqrestore(&info->lock, flags);
1534 tty_wakeup(tty);
1535}
1536
1537/*
1538 * ------------------------------------------------------------
1539 * rs_throttle()
1540 *
1541 * This routine is called by the upper-layer tty layer to signal that
1542 * incoming characters should be throttled.
1543 * ------------------------------------------------------------
1544 */
1545static void rs_throttle(struct tty_struct * tty)
1546{
1547 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1548 unsigned long flags;
1549#ifdef SERIAL_DEBUG_THROTTLE
1550 printk(KERN_DEBUG "throttle %ld....\n",tty->ldisc.chars_in_buffer(tty));
1551#endif
1552
1553 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1554 return;
1555
1556 if (I_IXOFF(tty)) {
1557 spin_lock_irqsave(&info->lock, flags);
1558 info->x_char = STOP_CHAR(tty);
1559 if (!info->tx_active)
1560 transmit_chars(info);
1561 spin_unlock_irqrestore(&info->lock, flags);
1562 }
1563
1564 if (C_CRTSCTS(tty)) {
1565 /*
1566 * Here we want to turn off the RTS line. On Macintoshes,
1567 * the external serial ports using a DIN-8 or DIN-9
1568 * connector only have the DTR line (which is usually
1569 * wired to both RTS and DTR on an external modem in
1570 * the cable). RTS doesn't go out to the serial port
1571 * socket, it acts as an output enable for the transmit
1572 * data line. So in this case we don't drop RTS.
1573 *
1574 * Macs with internal modems generally do have both RTS
1575 * and DTR wired to the modem, so in that case we do
1576 * drop RTS.
1577 */
1578 if (info->is_internal_modem) {
1579 spin_lock_irqsave(&info->lock, flags);
1580 info->curregs[5] &= ~RTS;
1581 info->pendregs[5] &= ~RTS;
1582 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1583 spin_unlock_irqrestore(&info->lock, flags);
1584 }
1585 }
1586
1587#ifdef CDTRCTS
1588 if (tty->termios->c_cflag & CDTRCTS) {
1589 spin_lock_irqsave(&info->lock, flags);
1590 info->curregs[5] &= ~DTR;
1591 info->pendregs[5] &= ~DTR;
1592 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1593 spin_unlock_irqrestore(&info->lock, flags);
1594 }
1595#endif /* CDTRCTS */
1596}
1597
1598static void rs_unthrottle(struct tty_struct * tty)
1599{
1600 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1601 unsigned long flags;
1602#ifdef SERIAL_DEBUG_THROTTLE
1603 printk(KERN_DEBUG "unthrottle %s: %d....\n",
1604 tty->ldisc.chars_in_buffer(tty));
1605#endif
1606
1607 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1608 return;
1609
1610 if (I_IXOFF(tty)) {
1611 spin_lock_irqsave(&info->lock, flags);
1612 if (info->x_char)
1613 info->x_char = 0;
1614 else {
1615 info->x_char = START_CHAR(tty);
1616 if (!info->tx_active)
1617 transmit_chars(info);
1618 }
1619 spin_unlock_irqrestore(&info->lock, flags);
1620 }
1621
1622 if (C_CRTSCTS(tty) && info->is_internal_modem) {
1623 /* Assert RTS line */
1624 spin_lock_irqsave(&info->lock, flags);
1625 info->curregs[5] |= RTS;
1626 info->pendregs[5] |= RTS;
1627 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1628 spin_unlock_irqrestore(&info->lock, flags);
1629 }
1630
1631#ifdef CDTRCTS
1632 if (tty->termios->c_cflag & CDTRCTS) {
1633 /* Assert DTR line */
1634 spin_lock_irqsave(&info->lock, flags);
1635 info->curregs[5] |= DTR;
1636 info->pendregs[5] |= DTR;
1637 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1638 spin_unlock_irqrestore(&info->lock, flags);
1639 }
1640#endif
1641}
1642
1643/*
1644 * ------------------------------------------------------------
1645 * rs_ioctl() and friends
1646 * ------------------------------------------------------------
1647 */
1648
1649static int get_serial_info(struct mac_serial * info,
1650 struct serial_struct __user * retinfo)
1651{
1652 struct serial_struct tmp;
1653
1654 if (!retinfo)
1655 return -EFAULT;
1656 memset(&tmp, 0, sizeof(tmp));
1657 tmp.type = info->type;
1658 tmp.line = info->line;
1659 tmp.port = info->port;
1660 tmp.irq = info->irq;
1661 tmp.flags = info->flags;
1662 tmp.baud_base = info->baud_base;
1663 tmp.close_delay = info->close_delay;
1664 tmp.closing_wait = info->closing_wait;
1665 tmp.custom_divisor = info->custom_divisor;
1666 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1667 return -EFAULT;
1668 return 0;
1669}
1670
1671static int set_serial_info(struct mac_serial * info,
1672 struct serial_struct __user * new_info)
1673{
1674 struct serial_struct new_serial;
1675 struct mac_serial old_info;
1676 int retval = 0;
1677
1678 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1679 return -EFAULT;
1680 old_info = *info;
1681
1682 if (!capable(CAP_SYS_ADMIN)) {
1683 if ((new_serial.baud_base != info->baud_base) ||
1684 (new_serial.type != info->type) ||
1685 (new_serial.close_delay != info->close_delay) ||
1686 ((new_serial.flags & ~ZILOG_USR_MASK) !=
1687 (info->flags & ~ZILOG_USR_MASK)))
1688 return -EPERM;
1689 info->flags = ((info->flags & ~ZILOG_USR_MASK) |
1690 (new_serial.flags & ZILOG_USR_MASK));
1691 info->custom_divisor = new_serial.custom_divisor;
1692 goto check_and_exit;
1693 }
1694
1695 if (info->count > 1)
1696 return -EBUSY;
1697
1698 /*
1699 * OK, past this point, all the error checking has been done.
1700 * At this point, we start making changes.....
1701 */
1702
1703 info->baud_base = new_serial.baud_base;
1704 info->flags = ((info->flags & ~ZILOG_FLAGS) |
1705 (new_serial.flags & ZILOG_FLAGS));
1706 info->type = new_serial.type;
1707 info->close_delay = new_serial.close_delay;
1708 info->closing_wait = new_serial.closing_wait;
1709
1710check_and_exit:
1711 if (info->flags & ZILOG_INITIALIZED)
1712 retval = setup_scc(info);
1713 return retval;
1714}
1715
1716/*
1717 * get_lsr_info - get line status register info
1718 *
1719 * Purpose: Let user call ioctl() to get info when the UART physically
1720 * is emptied. On bus types like RS485, the transmitter must
1721 * release the bus after transmitting. This must be done when
1722 * the transmit shift register is empty, not be done when the
1723 * transmit holding register is empty. This functionality
1724 * allows an RS485 driver to be written in user space.
1725 */
1726static int get_lsr_info(struct mac_serial * info, unsigned int *value)
1727{
1728 unsigned char status;
1729 unsigned long flags;
1730
1731 spin_lock_irqsave(&info->lock, flags);
1732 status = read_zsreg(info->zs_channel, 0);
1733 spin_unlock_irqrestore(&info->lock, flags);
1734 status = (status & Tx_BUF_EMP)? TIOCSER_TEMT: 0;
1735 return put_user(status,value);
1736}
1737
1738static int rs_tiocmget(struct tty_struct *tty, struct file *file)
1739{
1740 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1741 unsigned char control, status;
1742 unsigned long flags;
1743
1744#ifdef CONFIG_KGDB
1745 if (info->kgdb_channel)
1746 return -ENODEV;
1747#endif
1748 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1749 return -ENODEV;
1750
1751 if (tty->flags & (1 << TTY_IO_ERROR))
1752 return -EIO;
1753
1754 spin_lock_irqsave(&info->lock, flags);
1755 control = info->curregs[5];
1756 status = read_zsreg(info->zs_channel, 0);
1757 spin_unlock_irqrestore(&info->lock, flags);
1758 return ((control & RTS) ? TIOCM_RTS: 0)
1759 | ((control & DTR) ? TIOCM_DTR: 0)
1760 | ((status & DCD) ? TIOCM_CAR: 0)
1761 | ((status & CTS) ? 0: TIOCM_CTS);
1762}
1763
1764static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1765 unsigned int set, unsigned int clear)
1766{
1767 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1768 unsigned int arg, bits;
1769 unsigned long flags;
1770
1771#ifdef CONFIG_KGDB
1772 if (info->kgdb_channel)
1773 return -ENODEV;
1774#endif
1775 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1776 return -ENODEV;
1777
1778 if (tty->flags & (1 << TTY_IO_ERROR))
1779 return -EIO;
1780
1781 spin_lock_irqsave(&info->lock, flags);
1782 if (set & TIOCM_RTS)
1783 info->curregs[5] |= RTS;
1784 if (set & TIOCM_DTR)
1785 info->curregs[5] |= DTR;
1786 if (clear & TIOCM_RTS)
1787 info->curregs[5] &= ~RTS;
1788 if (clear & TIOCM_DTR)
1789 info->curregs[5] &= ~DTR;
1790
1791 info->pendregs[5] = info->curregs[5];
1792 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1793 spin_unlock_irqrestore(&info->lock, flags);
1794 return 0;
1795}
1796
1797/*
1798 * rs_break - turn transmit break condition on/off
1799 */
1800static void rs_break(struct tty_struct *tty, int break_state)
1801{
1802 struct mac_serial *info = (struct mac_serial *) tty->driver_data;
1803 unsigned long flags;
1804
1805 if (serial_paranoia_check(info, tty->name, "rs_break"))
1806 return;
1807
1808 spin_lock_irqsave(&info->lock, flags);
1809 if (break_state == -1)
1810 info->curregs[5] |= SND_BRK;
1811 else
1812 info->curregs[5] &= ~SND_BRK;
1813 write_zsreg(info->zs_channel, 5, info->curregs[5]);
1814 spin_unlock_irqrestore(&info->lock, flags);
1815}
1816
1817static int rs_ioctl(struct tty_struct *tty, struct file * file,
1818 unsigned int cmd, unsigned long arg)
1819{
1820 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1821
1822#ifdef CONFIG_KGDB
1823 if (info->kgdb_channel)
1824 return -ENODEV;
1825#endif
1826 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1827 return -ENODEV;
1828
1829 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1830 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT)) {
1831 if (tty->flags & (1 << TTY_IO_ERROR))
1832 return -EIO;
1833 }
1834
1835 switch (cmd) {
1836 case TIOCGSERIAL:
1837 return get_serial_info(info,
1838 (struct serial_struct __user *) arg);
1839 case TIOCSSERIAL:
1840 return set_serial_info(info,
1841 (struct serial_struct __user *) arg);
1842 case TIOCSERGETLSR: /* Get line status register */
1843 return get_lsr_info(info, (unsigned int *) arg);
1844
1845 case TIOCSERGSTRUCT:
1846 if (copy_to_user((struct mac_serial __user *) arg,
1847 info, sizeof(struct mac_serial)))
1848 return -EFAULT;
1849 return 0;
1850
1851 default:
1852 return -ENOIOCTLCMD;
1853 }
1854 return 0;
1855}
1856
1857static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1858{
1859 struct mac_serial *info = (struct mac_serial *)tty->driver_data;
1860 int was_stopped;
1861
1862 if (tty->termios->c_cflag == old_termios->c_cflag)
1863 return;
1864 was_stopped = info->tx_stopped;
1865
1866 change_speed(info, old_termios);
1867
1868 if (was_stopped && !info->tx_stopped) {
1869 tty->hw_stopped = 0;
1870 rs_start(tty);
1871 }
1872}
1873
1874/*
1875 * ------------------------------------------------------------
1876 * rs_close()
1877 *
1878 * This routine is called when the serial port gets closed.
1879 * Wait for the last remaining data to be sent.
1880 * ------------------------------------------------------------
1881 */
1882static void rs_close(struct tty_struct *tty, struct file * filp)
1883{
1884 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
1885 unsigned long flags;
1886
1887 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1888 return;
1889
1890 spin_lock_irqsave(&info->lock, flags);
1891
1892 if (tty_hung_up_p(filp)) {
1893 spin_unlock_irqrestore(&info->lock, flags);
1894 return;
1895 }
1896
1897 OPNDBG("rs_close ttyS%d, count = %d\n", info->line, info->count);
1898 if ((tty->count == 1) && (info->count != 1)) {
1899 /*
1900 * Uh, oh. tty->count is 1, which means that the tty
1901 * structure will be freed. Info->count should always
1902 * be one in these conditions. If it's greater than
1903 * one, we've got real problems, since it means the
1904 * serial port won't be shutdown.
1905 */
1906 printk(KERN_ERR "rs_close: bad serial port count; tty->count "
1907 "is 1, info->count is %d\n", info->count);
1908 info->count = 1;
1909 }
1910 if (--info->count < 0) {
1911 printk(KERN_ERR "rs_close: bad serial port count for "
1912 "ttyS%d: %d\n", info->line, info->count);
1913 info->count = 0;
1914 }
1915 if (info->count) {
1916 spin_unlock_irqrestore(&info->lock, flags);
1917 return;
1918 }
1919 info->flags |= ZILOG_CLOSING;
1920 /*
1921 * Now we wait for the transmit buffer to clear; and we notify
1922 * the line discipline to only process XON/XOFF characters.
1923 */
1924 OPNDBG("waiting end of Tx... (timeout:%d)\n", info->closing_wait);
1925 tty->closing = 1;
1926 if (info->closing_wait != ZILOG_CLOSING_WAIT_NONE) {
1927 spin_unlock_irqrestore(&info->lock, flags);
1928 tty_wait_until_sent(tty, info->closing_wait);
1929 spin_lock_irqsave(&info->lock, flags);
1930 }
1931
1932 /*
1933 * At this point we stop accepting input. To do this, we
1934 * disable the receiver and receive interrupts.
1935 */
1936 info->curregs[3] &= ~RxENABLE;
1937 info->pendregs[3] = info->curregs[3];
1938 write_zsreg(info->zs_channel, 3, info->curregs[3]);
1939 info->curregs[1] &= ~(0x18); /* disable any rx ints */
1940 info->pendregs[1] = info->curregs[1];
1941 write_zsreg(info->zs_channel, 1, info->curregs[1]);
1942 ZS_CLEARFIFO(info->zs_channel);
1943 if (info->flags & ZILOG_INITIALIZED) {
1944 /*
1945 * Before we drop DTR, make sure the SCC transmitter
1946 * has completely drained.
1947 */
1948 OPNDBG("waiting end of Rx...\n");
1949 spin_unlock_irqrestore(&info->lock, flags);
1950 rs_wait_until_sent(tty, info->timeout);
1951 spin_lock_irqsave(&info->lock, flags);
1952 }
1953
1954 shutdown(info);
1955 /* restore flags now since shutdown() will have disabled this port's
1956 specific irqs */
1957 spin_unlock_irqrestore(&info->lock, flags);
1958
1959 if (tty->driver->flush_buffer)
1960 tty->driver->flush_buffer(tty);
1961 tty_ldisc_flush(tty);
1962 tty->closing = 0;
1963 info->event = 0;
1964 info->tty = 0;
1965
1966 if (info->blocked_open) {
1967 if (info->close_delay) {
1968 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1969 }
1970 wake_up_interruptible(&info->open_wait);
1971 }
1972 info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CLOSING);
1973 wake_up_interruptible(&info->close_wait);
1974}
1975
1976/*
1977 * rs_wait_until_sent() --- wait until the transmitter is empty
1978 */
1979static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1980{
1981 struct mac_serial *info = (struct mac_serial *) tty->driver_data;
1982 unsigned long orig_jiffies, char_time;
1983
1984 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1985 return;
1986
1987/* printk("rs_wait_until_sent, timeout:%d, tty_stopped:%d, tx_stopped:%d\n",
1988 timeout, tty->stopped, info->tx_stopped);
1989*/
1990 orig_jiffies = jiffies;
1991 /*
1992 * Set the check interval to be 1/5 of the estimated time to
1993 * send a single character, and make it at least 1. The check
1994 * interval should also be less than the timeout.
1995 */
1996 if (info->timeout <= HZ/50) {
1997 printk(KERN_INFO "macserial: invalid info->timeout=%d\n",
1998 info->timeout);
1999 info->timeout = HZ/50+1;
2000 }
2001
2002 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
2003 char_time = char_time / 5;
2004 if (char_time > HZ) {
2005 printk(KERN_WARNING "macserial: char_time %ld >HZ !!!\n",
2006 char_time);
2007 char_time = 1;
2008 } else if (char_time == 0)
2009 char_time = 1;
2010 if (timeout)
2011 char_time = min_t(unsigned long, char_time, timeout);
2012 while ((read_zsreg(info->zs_channel, 1) & ALL_SNT) == 0) {
2013 msleep_interruptible(jiffies_to_msecs(char_time));
2014 if (signal_pending(current))
2015 break;
2016 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2017 break;
2018 }
2019 current->state = TASK_RUNNING;
2020}
2021
2022/*
2023 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2024 */
2025static void rs_hangup(struct tty_struct *tty)
2026{
2027 struct mac_serial * info = (struct mac_serial *)tty->driver_data;
2028
2029 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
2030 return;
2031
2032 rs_flush_buffer(tty);
2033 shutdown(info);
2034 info->event = 0;
2035 info->count = 0;
2036 info->flags &= ~ZILOG_NORMAL_ACTIVE;
2037 info->tty = 0;
2038 wake_up_interruptible(&info->open_wait);
2039}
2040
2041/*
2042 * ------------------------------------------------------------
2043 * rs_open() and friends
2044 * ------------------------------------------------------------
2045 */
2046static int block_til_ready(struct tty_struct *tty, struct file * filp,
2047 struct mac_serial *info)
2048{
2049 DECLARE_WAITQUEUE(wait,current);
2050 int retval;
2051 int do_clocal = 0;
2052
2053 /*
2054 * If the device is in the middle of being closed, then block
2055 * until it's done, and then try again.
2056 */
2057 if (info->flags & ZILOG_CLOSING) {
2058 interruptible_sleep_on(&info->close_wait);
2059 return -EAGAIN;
2060 }
2061
2062 /*
2063 * If non-blocking mode is set, or the port is not enabled,
2064 * then make the check up front and then exit.
2065 */
2066 if ((filp->f_flags & O_NONBLOCK) ||
2067 (tty->flags & (1 << TTY_IO_ERROR))) {
2068 info->flags |= ZILOG_NORMAL_ACTIVE;
2069 return 0;
2070 }
2071
2072 if (tty->termios->c_cflag & CLOCAL)
2073 do_clocal = 1;
2074
2075 /*
2076 * Block waiting for the carrier detect and the line to become
2077 * free (i.e., not in use by the callout). While we are in
2078 * this loop, info->count is dropped by one, so that
2079 * rs_close() knows when to free things. We restore it upon
2080 * exit, either normal or abnormal.
2081 */
2082 retval = 0;
2083 add_wait_queue(&info->open_wait, &wait);
2084 OPNDBG("block_til_ready before block: ttyS%d, count = %d\n",
2085 info->line, info->count);
2086 spin_lock_irq(&info->lock);
2087 if (!tty_hung_up_p(filp))
2088 info->count--;
2089 spin_unlock_irq(&info->lock);
2090 info->blocked_open++;
2091 while (1) {
2092 spin_lock_irq(&info->lock);
2093 if ((tty->termios->c_cflag & CBAUD) &&
2094 !info->is_irda)
2095 zs_rtsdtr(info, 1);
2096 spin_unlock_irq(&info->lock);
2097 set_current_state(TASK_INTERRUPTIBLE);
2098 if (tty_hung_up_p(filp) ||
2099 !(info->flags & ZILOG_INITIALIZED)) {
2100 retval = -EAGAIN;
2101 break;
2102 }
2103 if (!(info->flags & ZILOG_CLOSING) &&
2104 (do_clocal || (read_zsreg(info->zs_channel, 0) & DCD)))
2105 break;
2106 if (signal_pending(current)) {
2107 retval = -ERESTARTSYS;
2108 break;
2109 }
2110 OPNDBG("block_til_ready blocking: ttyS%d, count = %d\n",
2111 info->line, info->count);
2112 schedule();
2113 }
2114 current->state = TASK_RUNNING;
2115 remove_wait_queue(&info->open_wait, &wait);
2116 if (!tty_hung_up_p(filp))
2117 info->count++;
2118 info->blocked_open--;
2119 OPNDBG("block_til_ready after blocking: ttyS%d, count = %d\n",
2120 info->line, info->count);
2121 if (retval)
2122 return retval;
2123 info->flags |= ZILOG_NORMAL_ACTIVE;
2124 return 0;
2125}
2126
2127/*
2128 * This routine is called whenever a serial port is opened. It
2129 * enables interrupts for a serial port, linking in its ZILOG structure into
2130 * the IRQ chain. It also performs the serial-specific
2131 * initialization for the tty structure.
2132 */
2133static int rs_open(struct tty_struct *tty, struct file * filp)
2134{
2135 struct mac_serial *info;
2136 int retval, line;
2137 unsigned long page;
2138
2139 line = tty->index;
2140 if ((line < 0) || (line >= zs_channels_found)) {
2141 return -ENODEV;
2142 }
2143 info = zs_soft + line;
2144
2145#ifdef CONFIG_KGDB
2146 if (info->kgdb_channel) {
2147 return -ENODEV;
2148 }
2149#endif
2150 if (serial_paranoia_check(info, tty->name, "rs_open"))
2151 return -ENODEV;
2152 OPNDBG("rs_open %s, count = %d, tty=%p\n", tty->name,
2153 info->count, tty);
2154
2155 info->count++;
2156 tty->driver_data = info;
2157 info->tty = tty;
2158
2159 if (!tmp_buf) {
2160 page = get_zeroed_page(GFP_KERNEL);
2161 if (!page)
2162 return -ENOMEM;
2163 if (tmp_buf)
2164 free_page(page);
2165 else
2166 tmp_buf = (unsigned char *) page;
2167 }
2168
2169 /*
2170 * If the port is the middle of closing, bail out now
2171 */
2172 if (tty_hung_up_p(filp) ||
2173 (info->flags & ZILOG_CLOSING)) {
2174 if (info->flags & ZILOG_CLOSING)
2175 interruptible_sleep_on(&info->close_wait);
2176 return -EAGAIN;
2177 }
2178
2179 /*
2180 * Start up serial port
2181 */
2182
2183 retval = startup(info);
2184 if (retval)
2185 return retval;
2186
2187 retval = block_til_ready(tty, filp, info);
2188 if (retval) {
2189 OPNDBG("rs_open returning after block_til_ready with %d\n",
2190 retval);
2191 return retval;
2192 }
2193
2194#ifdef CONFIG_SERIAL_CONSOLE
2195 if (sercons.cflag && sercons.index == line) {
2196 tty->termios->c_cflag = sercons.cflag;
2197 sercons.cflag = 0;
2198 change_speed(info, 0);
2199 }
2200#endif
2201
2202 OPNDBG("rs_open %s successful...\n", tty->name);
2203 return 0;
2204}
2205
2206/* Finally, routines used to initialize the serial driver. */
2207
2208static void show_serial_version(void)
2209{
2210 printk(KERN_INFO "PowerMac Z8530 serial driver version " MACSERIAL_VERSION "\n");
2211}
2212
2213/*
2214 * Initialize one channel, both the mac_serial and mac_zschannel
2215 * structs. We use the dev_node field of the mac_serial struct.
2216 */
2217static int
2218chan_init(struct mac_serial *zss, struct mac_zschannel *zs_chan,
2219 struct mac_zschannel *zs_chan_a)
2220{
2221 struct device_node *ch = zss->dev_node;
2222 char *conn;
2223 int len;
2224 struct slot_names_prop {
2225 int count;
2226 char name[1];
2227 } *slots;
2228
2229 zss->irq = ch->intrs[0].line;
2230 zss->has_dma = 0;
2231#if !defined(CONFIG_KGDB) && defined(SUPPORT_SERIAL_DMA)
2232 if (ch->n_addrs >= 3 && ch->n_intrs == 3)
2233 zss->has_dma = 1;
2234#endif
2235 zss->dma_initted = 0;
2236
2237 zs_chan->control = (volatile unsigned char *)
2238 ioremap(ch->addrs[0].address, 0x1000);
2239 zs_chan->data = zs_chan->control + 0x10;
2240 spin_lock_init(&zs_chan->lock);
2241 zs_chan->parent = zss;
2242 zss->zs_channel = zs_chan;
2243 zss->zs_chan_a = zs_chan_a;
2244
2245 /* setup misc varariables */
2246 zss->kgdb_channel = 0;
2247
2248 /* For now, we assume you either have a slot-names property
2249 * with "Modem" in it, or your channel is compatible with
2250 * "cobalt". Might need additional fixups
2251 */
2252 zss->is_internal_modem = device_is_compatible(ch, "cobalt");
2253 conn = get_property(ch, "AAPL,connector", &len);
2254 zss->is_irda = conn && (strcmp(conn, "infrared") == 0);
2255 zss->port_type = PMAC_SCC_ASYNC;
2256 /* 1999 Powerbook G3 has slot-names property instead */
2257 slots = (struct slot_names_prop *)get_property(ch, "slot-names", &len);
2258 if (slots && slots->count > 0) {
2259 if (strcmp(slots->name, "IrDA") == 0)
2260 zss->is_irda = 1;
2261 else if (strcmp(slots->name, "Modem") == 0)
2262 zss->is_internal_modem = 1;
2263 }
2264 if (zss->is_irda)
2265 zss->port_type = PMAC_SCC_IRDA;
2266 if (zss->is_internal_modem) {
2267 struct device_node* i2c_modem = find_devices("i2c-modem");
2268 if (i2c_modem) {
2269 char* mid = get_property(i2c_modem, "modem-id", NULL);
2270 if (mid) switch(*mid) {
2271 case 0x04 :
2272 case 0x05 :
2273 case 0x07 :
2274 case 0x08 :
2275 case 0x0b :
2276 case 0x0c :
2277 zss->port_type = PMAC_SCC_I2S1;
2278 }
2279 printk(KERN_INFO "macserial: i2c-modem detected, id: %d\n",
2280 mid ? (*mid) : 0);
2281 } else {
2282 printk(KERN_INFO "macserial: serial modem detected\n");
2283 }
2284 }
2285
2286 while (zss->has_dma) {
2287 zss->dma_priv = NULL;
2288 /* it seems that the last two addresses are the
2289 DMA controllers */
2290 zss->tx_dma = (volatile struct dbdma_regs *)
2291 ioremap(ch->addrs[ch->n_addrs - 2].address, 0x100);
2292 zss->rx = (volatile struct mac_dma *)
2293 ioremap(ch->addrs[ch->n_addrs - 1].address, 0x100);
2294 zss->tx_dma_irq = ch->intrs[1].line;
2295 zss->rx_dma_irq = ch->intrs[2].line;
2296 spin_lock_init(&zss->rx_dma_lock);
2297 break;
2298 }
2299
2300 init_timer(&zss->powerup_timer);
2301 zss->powerup_timer.function = powerup_done;
2302 zss->powerup_timer.data = (unsigned long) zss;
2303 return 0;
2304}
2305
2306/*
2307 * /proc fs routines. TODO: Add status lines & error stats
2308 */
2309static inline int
2310line_info(char *buf, struct mac_serial *info)
2311{
2312 int ret=0;
2313 unsigned char* connector;
2314 int lenp;
2315
2316 ret += sprintf(buf, "%d: port:0x%X irq:%d", info->line, info->port, info->irq);
2317
2318 connector = get_property(info->dev_node, "AAPL,connector", &lenp);
2319 if (connector)
2320 ret+=sprintf(buf+ret," con:%s ", connector);
2321 if (info->is_internal_modem) {
2322 if (!connector)
2323 ret+=sprintf(buf+ret," con:");
2324 ret+=sprintf(buf+ret,"%s", " (internal modem)");
2325 }
2326 if (info->is_irda) {
2327 if (!connector)
2328 ret+=sprintf(buf+ret," con:");
2329 ret+=sprintf(buf+ret,"%s", " (IrDA)");
2330 }
2331 ret+=sprintf(buf+ret,"\n");
2332
2333 return ret;
2334}
2335
2336int macserial_read_proc(char *page, char **start, off_t off, int count,
2337 int *eof, void *data)
2338{
2339 int l, len = 0;
2340 off_t begin = 0;
2341 struct mac_serial *info;
2342
2343 len += sprintf(page, "serinfo:1.0 driver:" MACSERIAL_VERSION "\n");
2344 for (info = zs_chain; info && len < 4000; info = info->zs_next) {
2345 l = line_info(page + len, info);
2346 len += l;
2347 if (len+begin > off+count)
2348 goto done;
2349 if (len+begin < off) {
2350 begin += len;
2351 len = 0;
2352 }
2353 }
2354 *eof = 1;
2355done:
2356 if (off >= len+begin)
2357 return 0;
2358 *start = page + (off-begin);
2359 return ((count < begin+len-off) ? count : begin+len-off);
2360}
2361
2362/* Ask the PROM how many Z8530s we have and initialize their zs_channels */
2363static void
2364probe_sccs(void)
2365{
2366 struct device_node *dev, *ch;
2367 struct mac_serial **pp;
2368 int n, chip, nchan;
2369 struct mac_zschannel *zs_chan;
2370 int chan_a_index;
2371
2372 n = 0;
2373 pp = &zs_chain;
2374 zs_chan = zs_channels;
2375 for (dev = find_devices("escc"); dev != 0; dev = dev->next) {
2376 nchan = 0;
2377 chip = n;
2378 if (n >= NUM_CHANNELS) {
2379 printk(KERN_WARNING "Sorry, can't use %s: no more "
2380 "channels\n", dev->full_name);
2381 continue;
2382 }
2383 chan_a_index = 0;
2384 for (ch = dev->child; ch != 0; ch = ch->sibling) {
2385 if (nchan >= 2) {
2386 printk(KERN_WARNING "SCC: Only 2 channels per "
2387 "chip are supported\n");
2388 break;
2389 }
2390 if (ch->n_addrs < 1 || (ch ->n_intrs < 1)) {
2391 printk("Can't use %s: %d addrs %d intrs\n",
2392 ch->full_name, ch->n_addrs, ch->n_intrs);
2393 continue;
2394 }
2395
2396 /* The channel with the higher address
2397 will be the A side. */
2398 if (nchan > 0 &&
2399 ch->addrs[0].address
2400 > zs_soft[n-1].dev_node->addrs[0].address)
2401 chan_a_index = 1;
2402
2403 /* minimal initialization for now */
2404 zs_soft[n].dev_node = ch;
2405 *pp = &zs_soft[n];
2406 pp = &zs_soft[n].zs_next;
2407 ++nchan;
2408 ++n;
2409 }
2410 if (nchan == 0)
2411 continue;
2412
2413 /* set up A side */
2414 if (chan_init(&zs_soft[chip + chan_a_index], zs_chan, zs_chan))
2415 continue;
2416 ++zs_chan;
2417
2418 /* set up B side, if it exists */
2419 if (nchan > 1)
2420 if (chan_init(&zs_soft[chip + 1 - chan_a_index],
2421 zs_chan, zs_chan - 1))
2422 continue;
2423 ++zs_chan;
2424 }
2425 *pp = 0;
2426
2427 zs_channels_found = n;
2428#ifdef CONFIG_PMAC_PBOOK
2429 if (n)
2430 pmu_register_sleep_notifier(&serial_sleep_notifier);
2431#endif /* CONFIG_PMAC_PBOOK */
2432}
2433
2434static struct tty_operations serial_ops = {
2435 .open = rs_open,
2436 .close = rs_close,
2437 .write = rs_write,
2438 .flush_chars = rs_flush_chars,
2439 .write_room = rs_write_room,
2440 .chars_in_buffer = rs_chars_in_buffer,
2441 .flush_buffer = rs_flush_buffer,
2442 .ioctl = rs_ioctl,
2443 .throttle = rs_throttle,
2444 .unthrottle = rs_unthrottle,
2445 .set_termios = rs_set_termios,
2446 .stop = rs_stop,
2447 .start = rs_start,
2448 .hangup = rs_hangup,
2449 .break_ctl = rs_break,
2450 .wait_until_sent = rs_wait_until_sent,
2451 .read_proc = macserial_read_proc,
2452 .tiocmget = rs_tiocmget,
2453 .tiocmset = rs_tiocmset,
2454};
2455
2456static int macserial_init(void)
2457{
2458 int channel, i;
2459 struct mac_serial *info;
2460
2461 /* Find out how many Z8530 SCCs we have */
2462 if (zs_chain == 0)
2463 probe_sccs();
2464
2465 serial_driver = alloc_tty_driver(zs_channels_found);
2466 if (!serial_driver)
2467 return -ENOMEM;
2468
2469 /* XXX assume it's a powerbook if we have a via-pmu
2470 *
2471 * This is OK for core99 machines as well.
2472 */
2473 is_powerbook = find_devices("via-pmu") != 0;
2474
2475 /* Register the interrupt handler for each one
2476 * We also request the OF resources here as probe_sccs()
2477 * might be called too early for that
2478 */
2479 for (i = 0; i < zs_channels_found; ++i) {
2480 struct device_node* ch = zs_soft[i].dev_node;
2481 if (!request_OF_resource(ch, 0, NULL)) {
2482 printk(KERN_ERR "macserial: can't request IO resource !\n");
2483 put_tty_driver(serial_driver);
2484 return -ENODEV;
2485 }
2486 if (zs_soft[i].has_dma) {
2487 if (!request_OF_resource(ch, ch->n_addrs - 2, " (tx dma)")) {
2488 printk(KERN_ERR "macserial: can't request TX DMA resource !\n");
2489 zs_soft[i].has_dma = 0;
2490 goto no_dma;
2491 }
2492 if (!request_OF_resource(ch, ch->n_addrs - 1, " (rx dma)")) {
2493 release_OF_resource(ch, ch->n_addrs - 2);
2494 printk(KERN_ERR "macserial: can't request RX DMA resource !\n");
2495 zs_soft[i].has_dma = 0;
2496 goto no_dma;
2497 }
2498 if (request_irq(zs_soft[i].tx_dma_irq, rs_txdma_irq, 0,
2499 "SCC-txdma", &zs_soft[i]))
2500 printk(KERN_ERR "macserial: can't get irq %d\n",
2501 zs_soft[i].tx_dma_irq);
2502 disable_irq(zs_soft[i].tx_dma_irq);
2503 if (request_irq(zs_soft[i].rx_dma_irq, rs_rxdma_irq, 0,
2504 "SCC-rxdma", &zs_soft[i]))
2505 printk(KERN_ERR "macserial: can't get irq %d\n",
2506 zs_soft[i].rx_dma_irq);
2507 disable_irq(zs_soft[i].rx_dma_irq);
2508 }
2509no_dma:
2510 if (request_irq(zs_soft[i].irq, rs_interrupt, 0,
2511 "SCC", &zs_soft[i]))
2512 printk(KERN_ERR "macserial: can't get irq %d\n",
2513 zs_soft[i].irq);
2514 disable_irq(zs_soft[i].irq);
2515 }
2516
2517 show_serial_version();
2518
2519 /* Initialize the tty_driver structure */
2520 /* Not all of this is exactly right for us. */
2521
2522 serial_driver->owner = THIS_MODULE;
2523 serial_driver->driver_name = "macserial";
2524 serial_driver->devfs_name = "tts/";
2525 serial_driver->name = "ttyS";
2526 serial_driver->major = TTY_MAJOR;
2527 serial_driver->minor_start = 64;
2528 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2529 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2530 serial_driver->init_termios = tty_std_termios;
2531 serial_driver->init_termios.c_cflag =
2532 B38400 | CS8 | CREAD | HUPCL | CLOCAL;
2533 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2534 tty_set_operations(serial_driver, &serial_ops);
2535
2536 if (tty_register_driver(serial_driver))
2537 printk(KERN_ERR "Error: couldn't register serial driver\n");
2538
2539 for (channel = 0; channel < zs_channels_found; ++channel) {
2540#ifdef CONFIG_KGDB
2541 if (zs_soft[channel].kgdb_channel) {
2542 kgdb_interruptible(1);
2543 continue;
2544 }
2545#endif
2546 zs_soft[channel].clk_divisor = 16;
2547/* -- we are not sure the SCC is powered ON at this point
2548 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
2549*/
2550 zs_soft[channel].zs_baud = 38400;
2551
2552 /* If console serial line, then enable interrupts. */
2553 if (zs_soft[channel].is_cons) {
2554 printk(KERN_INFO "macserial: console line, enabling "
2555 "interrupt %d\n", zs_soft[channel].irq);
2556 panic("macserial: console not supported yet !");
2557 write_zsreg(zs_soft[channel].zs_channel, R1,
2558 (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB));
2559 write_zsreg(zs_soft[channel].zs_channel, R9,
2560 (NV | MIE));
2561 }
2562 }
2563
2564 for (info = zs_chain, i = 0; info; info = info->zs_next, i++)
2565 {
2566 unsigned char* connector;
2567 int lenp;
2568
2569#ifdef CONFIG_KGDB
2570 if (info->kgdb_channel) {
2571 continue;
2572 }
2573#endif
2574 info->magic = SERIAL_MAGIC;
2575 info->port = (int) info->zs_channel->control;
2576 info->line = i;
2577 info->tty = 0;
2578 info->custom_divisor = 16;
2579 info->timeout = 0;
2580 info->close_delay = 50;
2581 info->closing_wait = 3000;
2582 info->x_char = 0;
2583 info->event = 0;
2584 info->count = 0;
2585 info->blocked_open = 0;
2586 INIT_WORK(&info->tqueue, do_softint, info);
2587 spin_lock_init(&info->lock);
2588 init_waitqueue_head(&info->open_wait);
2589 init_waitqueue_head(&info->close_wait);
2590 info->timeout = HZ;
2591 printk(KERN_INFO "tty%02d at 0x%08x (irq = %d)", info->line,
2592 info->port, info->irq);
2593 printk(" is a Z8530 ESCC");
2594 connector = get_property(info->dev_node, "AAPL,connector", &lenp);
2595 if (connector)
2596 printk(", port = %s", connector);
2597 if (info->is_internal_modem)
2598 printk(" (internal modem)");
2599 if (info->is_irda)
2600 printk(" (IrDA)");
2601 printk("\n");
2602 }
2603 tmp_buf = 0;
2604
2605 return 0;
2606}
2607
2608void macserial_cleanup(void)
2609{
2610 int i;
2611 unsigned long flags;
2612 struct mac_serial *info;
2613
2614 for (info = zs_chain, i = 0; info; info = info->zs_next, i++)
2615 set_scc_power(info, 0);
2616 spin_lock_irqsave(&info->lock, flags);
2617 for (i = 0; i < zs_channels_found; ++i) {
2618 free_irq(zs_soft[i].irq, &zs_soft[i]);
2619 if (zs_soft[i].has_dma) {
2620 free_irq(zs_soft[i].tx_dma_irq, &zs_soft[i]);
2621 free_irq(zs_soft[i].rx_dma_irq, &zs_soft[i]);
2622 }
2623 release_OF_resource(zs_soft[i].dev_node, 0);
2624 if (zs_soft[i].has_dma) {
2625 struct device_node* ch = zs_soft[i].dev_node;
2626 release_OF_resource(ch, ch->n_addrs - 2);
2627 release_OF_resource(ch, ch->n_addrs - 1);
2628 }
2629 }
2630 spin_unlock_irqrestore(&info->lock, flags);
2631 tty_unregister_driver(serial_driver);
2632 put_tty_driver(serial_driver);
2633
2634 if (tmp_buf) {
2635 free_page((unsigned long) tmp_buf);
2636 tmp_buf = 0;
2637 }
2638
2639#ifdef CONFIG_PMAC_PBOOK
2640 if (zs_channels_found)
2641 pmu_unregister_sleep_notifier(&serial_sleep_notifier);
2642#endif /* CONFIG_PMAC_PBOOK */
2643}
2644
2645module_init(macserial_init);
2646module_exit(macserial_cleanup);
2647MODULE_LICENSE("GPL");
2648
2649#if 0
2650/*
2651 * register_serial and unregister_serial allows for serial ports to be
2652 * configured at run-time, to support PCMCIA modems.
2653 */
2654/* PowerMac: Unused at this time, just here to make things link. */
2655int register_serial(struct serial_struct *req)
2656{
2657 return -1;
2658}
2659
2660void unregister_serial(int line)
2661{
2662 return;
2663}
2664#endif
2665
2666/*
2667 * ------------------------------------------------------------
2668 * Serial console driver
2669 * ------------------------------------------------------------
2670 */
2671#ifdef CONFIG_SERIAL_CONSOLE
2672
2673/*
2674 * Print a string to the serial port trying not to disturb
2675 * any possible real use of the port...
2676 */
2677static void serial_console_write(struct console *co, const char *s,
2678 unsigned count)
2679{
2680 struct mac_serial *info = zs_soft + co->index;
2681 int i;
2682
2683 /* Turn of interrupts and enable the transmitter. */
2684 write_zsreg(info->zs_channel, R1, info->curregs[1] & ~TxINT_ENAB);
2685 write_zsreg(info->zs_channel, R5, info->curregs[5] | TxENAB | RTS | DTR);
2686
2687 for (i=0; i<count; i++) {
2688 /* Wait for the transmit buffer to empty. */
2689 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP) == 0) {
2690 eieio();
2691 }
2692
2693 write_zsdata(info->zs_channel, s[i]);
2694 if (s[i] == 10) {
2695 while ((read_zsreg(info->zs_channel, 0) & Tx_BUF_EMP)
2696 == 0)
2697 eieio();
2698
2699 write_zsdata(info->zs_channel, 13);
2700 }
2701 }
2702
2703 /* Restore the values in the registers. */
2704 write_zsreg(info->zs_channel, R1, info->curregs[1]);
2705 /* Don't disable the transmitter. */
2706}
2707
2708static struct tty_driver *serial_driver;
2709
2710static struct tty_driver *serial_console_device(struct console *c, int *index)
2711{
2712 *index = c->index;
2713 return serial_driver;
2714}
2715
2716/*
2717 * Setup initial baud/bits/parity. We do two things here:
2718 * - construct a cflag setting for the first rs_open()
2719 * - initialize the serial port
2720 * Return non-zero if we didn't find a serial port.
2721 */
2722static int __init serial_console_setup(struct console *co, char *options)
2723{
2724 struct mac_serial *info;
2725 int baud = 38400;
2726 int bits = 8;
2727 int parity = 'n';
2728 int cflag = CREAD | HUPCL | CLOCAL;
2729 int brg;
2730 char *s;
2731 long flags;
2732
2733 /* Find out how many Z8530 SCCs we have */
2734 if (zs_chain == 0)
2735 probe_sccs();
2736
2737 if (zs_chain == 0)
2738 return -1;
2739
2740 /* Do we have the device asked for? */
2741 if (co->index >= zs_channels_found)
2742 return -1;
2743 info = zs_soft + co->index;
2744
2745 set_scc_power(info, 1);
2746
2747 /* Reset the channel */
2748 write_zsreg(info->zs_channel, R9, CHRA);
2749
2750 if (options) {
2751 baud = simple_strtoul(options, NULL, 10);
2752 s = options;
2753 while(*s >= '0' && *s <= '9')
2754 s++;
2755 if (*s)
2756 parity = *s++;
2757 if (*s)
2758 bits = *s - '0';
2759 }
2760
2761 /*
2762 * Now construct a cflag setting.
2763 */
2764 switch(baud) {
2765 case 1200:
2766 cflag |= B1200;
2767 break;
2768 case 2400:
2769 cflag |= B2400;
2770 break;
2771 case 4800:
2772 cflag |= B4800;
2773 break;
2774 case 9600:
2775 cflag |= B9600;
2776 break;
2777 case 19200:
2778 cflag |= B19200;
2779 break;
2780 case 57600:
2781 cflag |= B57600;
2782 break;
2783 case 115200:
2784 cflag |= B115200;
2785 break;
2786 case 38400:
2787 default:
2788 cflag |= B38400;
2789 break;
2790 }
2791 switch(bits) {
2792 case 7:
2793 cflag |= CS7;
2794 break;
2795 default:
2796 case 8:
2797 cflag |= CS8;
2798 break;
2799 }
2800 switch(parity) {
2801 case 'o': case 'O':
2802 cflag |= PARENB | PARODD;
2803 break;
2804 case 'e': case 'E':
2805 cflag |= PARENB;
2806 break;
2807 }
2808 co->cflag = cflag;
2809
2810 spin_lock_irqsave(&info->lock, flags);
2811 memset(info->curregs, 0, sizeof(info->curregs));
2812
2813 info->zs_baud = baud;
2814 info->clk_divisor = 16;
2815 switch (info->zs_baud) {
2816 case ZS_CLOCK/16: /* 230400 */
2817 info->curregs[4] = X16CLK;
2818 info->curregs[11] = 0;
2819 break;
2820 case ZS_CLOCK/32: /* 115200 */
2821 info->curregs[4] = X32CLK;
2822 info->curregs[11] = 0;
2823 break;
2824 default:
2825 info->curregs[4] = X16CLK;
2826 info->curregs[11] = TCBR | RCBR;
2827 brg = BPS_TO_BRG(info->zs_baud, ZS_CLOCK/info->clk_divisor);
2828 info->curregs[12] = (brg & 255);
2829 info->curregs[13] = ((brg >> 8) & 255);
2830 info->curregs[14] = BRENABL;
2831 }
2832
2833 /* byte size and parity */
2834 info->curregs[3] &= ~RxNBITS_MASK;
2835 info->curregs[5] &= ~TxNBITS_MASK;
2836 switch (cflag & CSIZE) {
2837 case CS5:
2838 info->curregs[3] |= Rx5;
2839 info->curregs[5] |= Tx5;
2840 break;
2841 case CS6:
2842 info->curregs[3] |= Rx6;
2843 info->curregs[5] |= Tx6;
2844 break;
2845 case CS7:
2846 info->curregs[3] |= Rx7;
2847 info->curregs[5] |= Tx7;
2848 break;
2849 case CS8:
2850 default: /* defaults to 8 bits */
2851 info->curregs[3] |= Rx8;
2852 info->curregs[5] |= Tx8;
2853 break;
2854 }
2855 info->curregs[5] |= TxENAB | RTS | DTR;
2856 info->pendregs[3] = info->curregs[3];
2857 info->pendregs[5] = info->curregs[5];
2858
2859 info->curregs[4] &= ~(SB_MASK | PAR_ENA | PAR_EVEN);
2860 if (cflag & CSTOPB) {
2861 info->curregs[4] |= SB2;
2862 } else {
2863 info->curregs[4] |= SB1;
2864 }
2865 if (cflag & PARENB) {
2866 info->curregs[4] |= PAR_ENA;
2867 if (!(cflag & PARODD)) {
2868 info->curregs[4] |= PAR_EVEN;
2869 }
2870 }
2871 info->pendregs[4] = info->curregs[4];
2872
2873 if (!(cflag & CLOCAL)) {
2874 if (!(info->curregs[15] & DCDIE))
2875 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
2876 info->curregs[15] |= DCDIE;
2877 } else
2878 info->curregs[15] &= ~DCDIE;
2879 if (cflag & CRTSCTS) {
2880 info->curregs[15] |= CTSIE;
2881 if ((read_zsreg(info->zs_channel, 0) & CTS) != 0)
2882 info->tx_stopped = 1;
2883 } else {
2884 info->curregs[15] &= ~CTSIE;
2885 info->tx_stopped = 0;
2886 }
2887 info->pendregs[15] = info->curregs[15];
2888
2889 /* Load up the new values */
2890 load_zsregs(info->zs_channel, info->curregs);
2891
2892 spin_unlock_irqrestore(&info->lock, flags);
2893
2894 return 0;
2895}
2896
2897static struct console sercons = {
2898 .name = "ttyS",
2899 .write = serial_console_write,
2900 .device = serial_console_device,
2901 .setup = serial_console_setup,
2902 .flags = CON_PRINTBUFFER,
2903 .index = -1,
2904};
2905
2906/*
2907 * Register console.
2908 */
2909static void __init mac_scc_console_init(void)
2910{
2911 register_console(&sercons);
2912}
2913console_initcall(mac_scc_console_init);
2914
2915#endif /* ifdef CONFIG_SERIAL_CONSOLE */
2916
2917#ifdef CONFIG_KGDB
2918/* These are for receiving and sending characters under the kgdb
2919 * source level kernel debugger.
2920 */
2921void putDebugChar(char kgdb_char)
2922{
2923 struct mac_zschannel *chan = zs_kgdbchan;
2924 while ((read_zsreg(chan, 0) & Tx_BUF_EMP) == 0)
2925 udelay(5);
2926 write_zsdata(chan, kgdb_char);
2927}
2928
2929char getDebugChar(void)
2930{
2931 struct mac_zschannel *chan = zs_kgdbchan;
2932 while((read_zsreg(chan, 0) & Rx_CH_AV) == 0)
2933 eieio(); /*barrier();*/
2934 return read_zsdata(chan);
2935}
2936
2937void kgdb_interruptible(int yes)
2938{
2939 struct mac_zschannel *chan = zs_kgdbchan;
2940 int one, nine;
2941 nine = read_zsreg(chan, 9);
2942 if (yes == 1) {
2943 one = EXT_INT_ENAB|INT_ALL_Rx;
2944 nine |= MIE;
2945 printk("turning serial ints on\n");
2946 } else {
2947 one = RxINT_DISAB;
2948 nine &= ~MIE;
2949 printk("turning serial ints off\n");
2950 }
2951 write_zsreg(chan, 1, one);
2952 write_zsreg(chan, 9, nine);
2953}
2954
2955/* This sets up the serial port we're using, and turns on
2956 * interrupts for that channel, so kgdb is usable once we're done.
2957 */
2958static inline void kgdb_chaninit(struct mac_zschannel *ms, int intson, int bps)
2959{
2960 int brg;
2961 int i, x;
2962 volatile char *sccc = ms->control;
2963 brg = BPS_TO_BRG(bps, ZS_CLOCK/16);
2964 printk("setting bps on kgdb line to %d [brg=%x]\n", bps, brg);
2965 for (i = 20000; i != 0; --i) {
2966 x = *sccc; eieio();
2967 }
2968 for (i = 0; i < sizeof(scc_inittab); ++i) {
2969 write_zsreg(ms, scc_inittab[i], scc_inittab[i+1]);
2970 i++;
2971 }
2972}
2973
2974/* This is called at boot time to prime the kgdb serial debugging
2975 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2976 * for /dev/ttyb which is determined in setup_arch() from the
2977 * boot command line flags.
2978 * XXX at the moment probably only channel A will work
2979 */
2980void __init zs_kgdb_hook(int tty_num)
2981{
2982 /* Find out how many Z8530 SCCs we have */
2983 if (zs_chain == 0)
2984 probe_sccs();
2985
2986 set_scc_power(&zs_soft[tty_num], 1);
2987
2988 zs_kgdbchan = zs_soft[tty_num].zs_channel;
2989 zs_soft[tty_num].change_needed = 0;
2990 zs_soft[tty_num].clk_divisor = 16;
2991 zs_soft[tty_num].zs_baud = 38400;
2992 zs_soft[tty_num].kgdb_channel = 1; /* This runs kgdb */
2993
2994 /* Turn on transmitter/receiver at 8-bits/char */
2995 kgdb_chaninit(zs_soft[tty_num].zs_channel, 1, 38400);
2996 printk("KGDB: on channel %d initialized\n", tty_num);
2997 set_debug_traps(); /* init stub */
2998}
2999#endif /* ifdef CONFIG_KGDB */
3000
3001#ifdef CONFIG_PMAC_PBOOK
3002/*
3003 * notify clients before sleep and reset bus afterwards
3004 */
3005int
3006serial_notify_sleep(struct pmu_sleep_notifier *self, int when)
3007{
3008 int i;
3009
3010 switch (when) {
3011 case PBOOK_SLEEP_REQUEST:
3012 case PBOOK_SLEEP_REJECT:
3013 break;
3014
3015 case PBOOK_SLEEP_NOW:
3016 for (i=0; i<zs_channels_found; i++) {
3017 struct mac_serial *info = &zs_soft[i];
3018 if (info->flags & ZILOG_INITIALIZED) {
3019 shutdown(info);
3020 info->flags |= ZILOG_SLEEPING;
3021 }
3022 }
3023 break;
3024 case PBOOK_WAKE:
3025 for (i=0; i<zs_channels_found; i++) {
3026 struct mac_serial *info = &zs_soft[i];
3027 if (info->flags & ZILOG_SLEEPING) {
3028 info->flags &= ~ZILOG_SLEEPING;
3029 startup(info);
3030 }
3031 }
3032 break;
3033 }
3034 return PBOOK_SLEEP_OK;
3035}
3036#endif /* CONFIG_PMAC_PBOOK */
diff --git a/drivers/macintosh/macserial.h b/drivers/macintosh/macserial.h
deleted file mode 100644
index bade11a7a5c3..000000000000
--- a/drivers/macintosh/macserial.h
+++ /dev/null
@@ -1,461 +0,0 @@
1/*
2 * macserial.h: Definitions for the Macintosh Z8530 serial driver.
3 *
4 * Adapted from drivers/sbus/char/sunserial.h by Paul Mackerras.
5 *
6 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
7 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 */
9#ifndef _MACSERIAL_H
10#define _MACSERIAL_H
11
12#include <linux/spinlock.h>
13
14#define NUM_ZSREGS 16
15
16struct serial_struct {
17 int type;
18 int line;
19 int port;
20 int irq;
21 int flags;
22 int xmit_fifo_size;
23 int custom_divisor;
24 int baud_base;
25 unsigned short close_delay;
26 char reserved_char[2];
27 int hub6;
28 unsigned short closing_wait; /* time to wait before closing */
29 unsigned short closing_wait2; /* no longer used... */
30 int reserved[4];
31};
32
33/*
34 * For the close wait times, 0 means wait forever for serial port to
35 * flush its output. 65535 means don't wait at all.
36 */
37#define ZILOG_CLOSING_WAIT_INF 0
38#define ZILOG_CLOSING_WAIT_NONE 65535
39
40/*
41 * Definitions for ZILOG_struct (and serial_struct) flags field
42 */
43#define ZILOG_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
44 * on the callout port */
45#define ZILOG_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
46#define ZILOG_SAK 0x0004 /* Secure Attention Key (Orange book) */
47#define ZILOG_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
48
49#define ZILOG_SPD_MASK 0x0030
50#define ZILOG_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
51
52#define ZILOG_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
53#define ZILOG_SPD_CUST 0x0030 /* Use user-specified divisor */
54
55#define ZILOG_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
56#define ZILOG_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
57#define ZILOG_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
58#define ZILOG_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
59#define ZILOG_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
60
61#define ZILOG_FLAGS 0x0FFF /* Possible legal ZILOG flags */
62#define ZILOG_USR_MASK 0x0430 /* Legal flags that non-privileged
63 * users can set or reset */
64
65/* Internal flags used only by kernel/chr_drv/serial.c */
66#define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */
67#define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
68#define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
69#define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
70#define ZILOG_CLOSING 0x08000000 /* Serial port is closing */
71#define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */
72#define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */
73#define ZILOG_SLEEPING 0x01000000 /* have shut it down for sleep */
74
75/* Software state per channel */
76
77#ifdef __KERNEL__
78/*
79 * This is our internal structure for each serial port's state.
80 *
81 * Many fields are paralleled by the structure used by the serial_struct
82 * structure.
83 *
84 * For definitions of the flags field, see tty.h
85 */
86
87struct mac_serial;
88
89struct mac_zschannel {
90 volatile unsigned char* control;
91 volatile unsigned char* data;
92 spinlock_t lock;
93 /* Used for debugging */
94 struct mac_serial* parent;
95};
96
97struct mac_dma {
98 volatile struct dbdma_regs dma;
99 volatile unsigned short res_count;
100 volatile unsigned short command;
101 volatile unsigned int buf_addr;
102};
103
104struct mac_serial {
105 struct mac_serial *zs_next; /* For IRQ servicing chain */
106 struct mac_zschannel *zs_channel; /* Channel registers */
107 struct mac_zschannel *zs_chan_a; /* A side registers */
108 unsigned char read_reg_zero;
109 struct device_node* dev_node;
110 spinlock_t lock;
111
112 char soft_carrier; /* Use soft carrier on this channel */
113 char break_abort; /* Is serial console in, so process brk/abrt */
114 char kgdb_channel; /* Kgdb is running on this channel */
115 char is_cons; /* Is this our console. */
116 char is_internal_modem; /* is connected to an internal modem */
117 char is_irda; /* is connected to an IrDA codec */
118 int port_type; /* Port type for pmac_feature */
119 unsigned char tx_active; /* character is being xmitted */
120 unsigned char tx_stopped; /* output is suspended */
121 unsigned char power_wait; /* waiting for power-up delay to expire */
122
123 /* We need to know the current clock divisor
124 * to read the bps rate the chip has currently
125 * loaded.
126 */
127 unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */
128 int zs_baud;
129
130 /* Current write register values */
131 unsigned char curregs[NUM_ZSREGS];
132
133 /* Values we need to set next opportunity */
134 unsigned char pendregs[NUM_ZSREGS];
135
136 char change_needed;
137
138 int magic;
139 int baud_base;
140 int port;
141 int irq;
142 int flags; /* defined in tty.h */
143 int type; /* UART type */
144 struct tty_struct *tty;
145 int read_status_mask;
146 int ignore_status_mask;
147 int timeout;
148 int xmit_fifo_size;
149 int custom_divisor;
150 int x_char; /* xon/xoff character */
151 int close_delay;
152 unsigned short closing_wait;
153 unsigned short closing_wait2;
154 unsigned long event;
155 unsigned long last_active;
156 int line;
157 int count; /* # of fd on device */
158 int blocked_open; /* # of blocked opens */
159 unsigned char *xmit_buf;
160 int xmit_head;
161 int xmit_tail;
162 int xmit_cnt;
163 struct work_struct tqueue;
164 wait_queue_head_t open_wait;
165 wait_queue_head_t close_wait;
166
167 volatile struct dbdma_regs *tx_dma;
168 int tx_dma_irq;
169 volatile struct dbdma_cmd *tx_cmds;
170 volatile struct mac_dma *rx;
171 int rx_dma_irq;
172 volatile struct dbdma_cmd **rx_cmds;
173 unsigned char **rx_char_buf;
174 unsigned char **rx_flag_buf;
175#define RX_BUF_SIZE 256
176 int rx_nbuf;
177 int rx_done_bytes;
178 int rx_ubuf;
179 int rx_fbuf;
180#define RX_NO_FBUF (-1)
181 int rx_cbuf;
182 spinlock_t rx_dma_lock;
183 int has_dma;
184 int dma_initted;
185 void *dma_priv;
186 struct timer_list poll_dma_timer;
187#define RX_DMA_TIMER (jiffies + 10*HZ/1000)
188
189 struct timer_list powerup_timer;
190};
191
192
193#define SERIAL_MAGIC 0x5301
194
195/*
196 * The size of the serial xmit buffer is 1 page, or 4096 bytes
197 */
198#define SERIAL_XMIT_SIZE 4096
199
200/*
201 * Events are used to schedule things to happen at timer-interrupt
202 * time, instead of at rs interrupt time.
203 */
204#define RS_EVENT_WRITE_WAKEUP 0
205
206#endif /* __KERNEL__ */
207
208/* Conversion routines to/from brg time constants from/to bits
209 * per second.
210 */
211#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
212#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
213
214/* The Zilog register set */
215
216#define FLAG 0x7e
217
218/* Write Register 0 */
219#define R0 0 /* Register selects */
220#define R1 1
221#define R2 2
222#define R3 3
223#define R4 4
224#define R5 5
225#define R6 6
226#define R7 7
227#define R8 8
228#define R9 9
229#define R10 10
230#define R11 11
231#define R12 12
232#define R13 13
233#define R14 14
234#define R15 15
235
236#define NULLCODE 0 /* Null Code */
237#define POINT_HIGH 0x8 /* Select upper half of registers */
238#define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
239#define SEND_ABORT 0x18 /* HDLC Abort */
240#define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
241#define RES_Tx_P 0x28 /* Reset TxINT Pending */
242#define ERR_RES 0x30 /* Error Reset */
243#define RES_H_IUS 0x38 /* Reset highest IUS */
244
245#define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
246#define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
247#define RES_EOM_L 0xC0 /* Reset EOM latch */
248
249/* Write Register 1 */
250
251#define EXT_INT_ENAB 0x1 /* Ext Int Enable */
252#define TxINT_ENAB 0x2 /* Tx Int Enable */
253#define PAR_SPEC 0x4 /* Parity is special condition */
254
255#define RxINT_DISAB 0 /* Rx Int Disable */
256#define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
257#define INT_ALL_Rx 0x10 /* Int on all Rx Characters or error */
258#define INT_ERR_Rx 0x18 /* Int on error only */
259
260#define WT_RDY_RT 0x20 /* W/Req reflects recv if 1, xmit if 0 */
261#define WT_FN_RDYFN 0x40 /* W/Req pin is DMA request if 1, wait if 0 */
262#define WT_RDY_ENAB 0x80 /* Enable W/Req pin */
263
264/* Write Register #2 (Interrupt Vector) */
265
266/* Write Register 3 */
267
268#define RxENABLE 0x1 /* Rx Enable */
269#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
270#define ADD_SM 0x4 /* Address Search Mode (SDLC) */
271#define RxCRC_ENAB 0x8 /* Rx CRC Enable */
272#define ENT_HM 0x10 /* Enter Hunt Mode */
273#define AUTO_ENAB 0x20 /* Auto Enables */
274#define Rx5 0x0 /* Rx 5 Bits/Character */
275#define Rx7 0x40 /* Rx 7 Bits/Character */
276#define Rx6 0x80 /* Rx 6 Bits/Character */
277#define Rx8 0xc0 /* Rx 8 Bits/Character */
278#define RxNBITS_MASK 0xc0
279
280/* Write Register 4 */
281
282#define PAR_ENA 0x1 /* Parity Enable */
283#define PAR_EVEN 0x2 /* Parity Even/Odd* */
284
285#define SYNC_ENAB 0 /* Sync Modes Enable */
286#define SB1 0x4 /* 1 stop bit/char */
287#define SB15 0x8 /* 1.5 stop bits/char */
288#define SB2 0xc /* 2 stop bits/char */
289#define SB_MASK 0xc
290
291#define MONSYNC 0 /* 8 Bit Sync character */
292#define BISYNC 0x10 /* 16 bit sync character */
293#define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
294#define EXTSYNC 0x30 /* External Sync Mode */
295
296#define X1CLK 0x0 /* x1 clock mode */
297#define X16CLK 0x40 /* x16 clock mode */
298#define X32CLK 0x80 /* x32 clock mode */
299#define X64CLK 0xC0 /* x64 clock mode */
300#define XCLK_MASK 0xC0
301
302/* Write Register 5 */
303
304#define TxCRC_ENAB 0x1 /* Tx CRC Enable */
305#define RTS 0x2 /* RTS */
306#define SDLC_CRC 0x4 /* SDLC/CRC-16 */
307#define TxENAB 0x8 /* Tx Enable */
308#define SND_BRK 0x10 /* Send Break */
309#define Tx5 0x0 /* Tx 5 bits (or less)/character */
310#define Tx7 0x20 /* Tx 7 bits/character */
311#define Tx6 0x40 /* Tx 6 bits/character */
312#define Tx8 0x60 /* Tx 8 bits/character */
313#define TxNBITS_MASK 0x60
314#define DTR 0x80 /* DTR */
315
316/* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
317
318/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
319
320/* Write Register 7' (Some enhanced feature control) */
321#define ENEXREAD 0x40 /* Enable read of some write registers */
322
323/* Write Register 8 (transmit buffer) */
324
325/* Write Register 9 (Master interrupt control) */
326#define VIS 1 /* Vector Includes Status */
327#define NV 2 /* No Vector */
328#define DLC 4 /* Disable Lower Chain */
329#define MIE 8 /* Master Interrupt Enable */
330#define STATHI 0x10 /* Status high */
331#define NORESET 0 /* No reset on write to R9 */
332#define CHRB 0x40 /* Reset channel B */
333#define CHRA 0x80 /* Reset channel A */
334#define FHWRES 0xc0 /* Force hardware reset */
335
336/* Write Register 10 (misc control bits) */
337#define BIT6 1 /* 6 bit/8bit sync */
338#define LOOPMODE 2 /* SDLC Loop mode */
339#define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
340#define MARKIDLE 8 /* Mark/flag on idle */
341#define GAOP 0x10 /* Go active on poll */
342#define NRZ 0 /* NRZ mode */
343#define NRZI 0x20 /* NRZI mode */
344#define FM1 0x40 /* FM1 (transition = 1) */
345#define FM0 0x60 /* FM0 (transition = 0) */
346#define CRCPS 0x80 /* CRC Preset I/O */
347
348/* Write Register 11 (Clock Mode control) */
349#define TRxCXT 0 /* TRxC = Xtal output */
350#define TRxCTC 1 /* TRxC = Transmit clock */
351#define TRxCBR 2 /* TRxC = BR Generator Output */
352#define TRxCDP 3 /* TRxC = DPLL output */
353#define TRxCOI 4 /* TRxC O/I */
354#define TCRTxCP 0 /* Transmit clock = RTxC pin */
355#define TCTRxCP 8 /* Transmit clock = TRxC pin */
356#define TCBR 0x10 /* Transmit clock = BR Generator output */
357#define TCDPLL 0x18 /* Transmit clock = DPLL output */
358#define RCRTxCP 0 /* Receive clock = RTxC pin */
359#define RCTRxCP 0x20 /* Receive clock = TRxC pin */
360#define RCBR 0x40 /* Receive clock = BR Generator output */
361#define RCDPLL 0x60 /* Receive clock = DPLL output */
362#define RTxCX 0x80 /* RTxC Xtal/No Xtal */
363
364/* Write Register 12 (lower byte of baud rate generator time constant) */
365
366/* Write Register 13 (upper byte of baud rate generator time constant) */
367
368/* Write Register 14 (Misc control bits) */
369#define BRENABL 1 /* Baud rate generator enable */
370#define BRSRC 2 /* Baud rate generator source */
371#define DTRREQ 4 /* DTR/Request function */
372#define AUTOECHO 8 /* Auto Echo */
373#define LOOPBAK 0x10 /* Local loopback */
374#define SEARCH 0x20 /* Enter search mode */
375#define RMC 0x40 /* Reset missing clock */
376#define DISDPLL 0x60 /* Disable DPLL */
377#define SSBR 0x80 /* Set DPLL source = BR generator */
378#define SSRTxC 0xa0 /* Set DPLL source = RTxC */
379#define SFMM 0xc0 /* Set FM mode */
380#define SNRZI 0xe0 /* Set NRZI mode */
381
382/* Write Register 15 (external/status interrupt control) */
383#define EN85C30 1 /* Enable some 85c30-enhanced registers */
384#define ZCIE 2 /* Zero count IE */
385#define ENSTFIFO 4 /* Enable status FIFO (SDLC) */
386#define DCDIE 8 /* DCD IE */
387#define SYNCIE 0x10 /* Sync/hunt IE */
388#define CTSIE 0x20 /* CTS IE */
389#define TxUIE 0x40 /* Tx Underrun/EOM IE */
390#define BRKIE 0x80 /* Break/Abort IE */
391
392
393/* Read Register 0 */
394#define Rx_CH_AV 0x1 /* Rx Character Available */
395#define ZCOUNT 0x2 /* Zero count */
396#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
397#define DCD 0x8 /* DCD */
398#define SYNC_HUNT 0x10 /* Sync/hunt */
399#define CTS 0x20 /* CTS */
400#define TxEOM 0x40 /* Tx underrun */
401#define BRK_ABRT 0x80 /* Break/Abort */
402
403/* Read Register 1 */
404#define ALL_SNT 0x1 /* All sent */
405/* Residue Data for 8 Rx bits/char programmed */
406#define RES3 0x8 /* 0/3 */
407#define RES4 0x4 /* 0/4 */
408#define RES5 0xc /* 0/5 */
409#define RES6 0x2 /* 0/6 */
410#define RES7 0xa /* 0/7 */
411#define RES8 0x6 /* 0/8 */
412#define RES18 0xe /* 1/8 */
413#define RES28 0x0 /* 2/8 */
414/* Special Rx Condition Interrupts */
415#define PAR_ERR 0x10 /* Parity error */
416#define Rx_OVR 0x20 /* Rx Overrun Error */
417#define FRM_ERR 0x40 /* CRC/Framing Error */
418#define END_FR 0x80 /* End of Frame (SDLC) */
419
420/* Read Register 2 (channel b only) - Interrupt vector */
421#define CHB_Tx_EMPTY 0x00
422#define CHB_EXT_STAT 0x02
423#define CHB_Rx_AVAIL 0x04
424#define CHB_SPECIAL 0x06
425#define CHA_Tx_EMPTY 0x08
426#define CHA_EXT_STAT 0x0a
427#define CHA_Rx_AVAIL 0x0c
428#define CHA_SPECIAL 0x0e
429#define STATUS_MASK 0x06
430
431/* Read Register 3 (interrupt pending register) ch a only */
432#define CHBEXT 0x1 /* Channel B Ext/Stat IP */
433#define CHBTxIP 0x2 /* Channel B Tx IP */
434#define CHBRxIP 0x4 /* Channel B Rx IP */
435#define CHAEXT 0x8 /* Channel A Ext/Stat IP */
436#define CHATxIP 0x10 /* Channel A Tx IP */
437#define CHARxIP 0x20 /* Channel A Rx IP */
438
439/* Read Register 8 (receive data register) */
440
441/* Read Register 10 (misc status bits) */
442#define ONLOOP 2 /* On loop */
443#define LOOPSEND 0x10 /* Loop sending */
444#define CLK2MIS 0x40 /* Two clocks missing */
445#define CLK1MIS 0x80 /* One clock missing */
446
447/* Read Register 12 (lower byte of baud rate generator constant) */
448
449/* Read Register 13 (upper byte of baud rate generator constant) */
450
451/* Read Register 15 (value of WR 15) */
452
453/* Misc macros */
454#define ZS_CLEARERR(channel) (write_zsreg(channel, 0, ERR_RES))
455#define ZS_CLEARFIFO(channel) do { volatile unsigned char garbage; \
456 garbage = read_zsdata(channel); \
457 garbage = read_zsdata(channel); \
458 garbage = read_zsdata(channel); \
459 } while(0)
460
461#endif /* !(_MACSERIAL_H) */
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 4be709e13eec..7c16c25fc5d4 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -642,7 +642,7 @@ static int __pmac media_bay_task(void *x)
642 } 642 }
643} 643}
644 644
645static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_match *match) 645static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_device_id *match)
646{ 646{
647 struct media_bay_info* bay; 647 struct media_bay_info* bay;
648 u32 __iomem *regbase; 648 u32 __iomem *regbase;
@@ -797,23 +797,20 @@ static struct mb_ops keylargo_mb_ops __pmacdata = {
797 * Therefore we do it all by polling the media bay once each tick. 797 * Therefore we do it all by polling the media bay once each tick.
798 */ 798 */
799 799
800static struct of_match media_bay_match[] = 800static struct of_device_id media_bay_match[] =
801{ 801{
802 { 802 {
803 .name = "media-bay", 803 .name = "media-bay",
804 .type = OF_ANY_MATCH,
805 .compatible = "keylargo-media-bay", 804 .compatible = "keylargo-media-bay",
806 .data = &keylargo_mb_ops, 805 .data = &keylargo_mb_ops,
807 }, 806 },
808 { 807 {
809 .name = "media-bay", 808 .name = "media-bay",
810 .type = OF_ANY_MATCH,
811 .compatible = "heathrow-media-bay", 809 .compatible = "heathrow-media-bay",
812 .data = &heathrow_mb_ops, 810 .data = &heathrow_mb_ops,
813 }, 811 },
814 { 812 {
815 .name = "media-bay", 813 .name = "media-bay",
816 .type = OF_ANY_MATCH,
817 .compatible = "ohare-media-bay", 814 .compatible = "ohare-media-bay",
818 .data = &ohare_mb_ops, 815 .data = &ohare_mb_ops,
819 }, 816 },
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index feb4e2413858..703e31973314 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -120,6 +120,7 @@
120#include <asm/system.h> 120#include <asm/system.h>
121#include <asm/sections.h> 121#include <asm/sections.h>
122#include <asm/of_device.h> 122#include <asm/of_device.h>
123#include <asm/macio.h>
123 124
124#include "therm_pm72.h" 125#include "therm_pm72.h"
125 126
@@ -1986,7 +1987,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node)
1986 } 1987 }
1987} 1988}
1988 1989
1989static int fcu_of_probe(struct of_device* dev, const struct of_match *match) 1990static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
1990{ 1991{
1991 int rc; 1992 int rc;
1992 1993
@@ -2009,12 +2010,10 @@ static int fcu_of_remove(struct of_device* dev)
2009 return 0; 2010 return 0;
2010} 2011}
2011 2012
2012static struct of_match fcu_of_match[] = 2013static struct of_device_id fcu_match[] =
2013{ 2014{
2014 { 2015 {
2015 .name = OF_ANY_MATCH,
2016 .type = "fcu", 2016 .type = "fcu",
2017 .compatible = OF_ANY_MATCH
2018 }, 2017 },
2019 {}, 2018 {},
2020}; 2019};
@@ -2022,7 +2021,7 @@ static struct of_match fcu_of_match[] =
2022static struct of_platform_driver fcu_of_platform_driver = 2021static struct of_platform_driver fcu_of_platform_driver =
2023{ 2022{
2024 .name = "temperature", 2023 .name = "temperature",
2025 .match_table = fcu_of_match, 2024 .match_table = fcu_match,
2026 .probe = fcu_of_probe, 2025 .probe = fcu_of_probe,
2027 .remove = fcu_of_remove 2026 .remove = fcu_of_remove
2028}; 2027};
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 61400f04015e..cbb72eb0426d 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -43,6 +43,7 @@
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/sections.h> 44#include <asm/sections.h>
45#include <asm/of_device.h> 45#include <asm/of_device.h>
46#include <asm/macio.h>
46 47
47#define LOG_TEMP 0 /* continously log temperature */ 48#define LOG_TEMP 0 /* continously log temperature */
48 49
@@ -450,7 +451,7 @@ do_probe( struct i2c_adapter *adapter, int addr, int kind )
450/************************************************************************/ 451/************************************************************************/
451 452
452static int 453static int
453therm_of_probe( struct of_device *dev, const struct of_match *match ) 454therm_of_probe( struct of_device *dev, const struct of_device_id *match )
454{ 455{
455 return i2c_add_driver( &g4fan_driver ); 456 return i2c_add_driver( &g4fan_driver );
456} 457}
@@ -461,9 +462,8 @@ therm_of_remove( struct of_device *dev )
461 return i2c_del_driver( &g4fan_driver ); 462 return i2c_del_driver( &g4fan_driver );
462} 463}
463 464
464static struct of_match therm_of_match[] = {{ 465static struct of_device_id therm_of_match[] = {{
465 .name = "fan", 466 .name = "fan",
466 .type = OF_ANY_MATCH,
467 .compatible = "adm1030" 467 .compatible = "adm1030"
468 }, {} 468 }, {}
469}; 469};
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index b941ee220997..4a0a0ad2d03c 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -63,6 +63,10 @@
63#include <asm/backlight.h> 63#include <asm/backlight.h>
64#endif 64#endif
65 65
66#ifdef CONFIG_PPC32
67#include <asm/open_pic.h>
68#endif
69
66/* Some compile options */ 70/* Some compile options */
67#undef SUSPEND_USES_PMU 71#undef SUSPEND_USES_PMU
68#define DEBUG_SLEEP 72#define DEBUG_SLEEP
@@ -151,10 +155,10 @@ static spinlock_t pmu_lock;
151static u8 pmu_intr_mask; 155static u8 pmu_intr_mask;
152static int pmu_version; 156static int pmu_version;
153static int drop_interrupts; 157static int drop_interrupts;
154#ifdef CONFIG_PMAC_PBOOK 158#ifdef CONFIG_PM
155static int option_lid_wakeup = 1; 159static int option_lid_wakeup = 1;
156static int sleep_in_progress; 160static int sleep_in_progress;
157#endif /* CONFIG_PMAC_PBOOK */ 161#endif /* CONFIG_PM */
158static unsigned long async_req_locks; 162static unsigned long async_req_locks;
159static unsigned int pmu_irq_stats[11]; 163static unsigned int pmu_irq_stats[11];
160 164
@@ -164,7 +168,6 @@ static struct proc_dir_entry *proc_pmu_irqstats;
164static struct proc_dir_entry *proc_pmu_options; 168static struct proc_dir_entry *proc_pmu_options;
165static int option_server_mode; 169static int option_server_mode;
166 170
167#ifdef CONFIG_PMAC_PBOOK
168int pmu_battery_count; 171int pmu_battery_count;
169int pmu_cur_battery; 172int pmu_cur_battery;
170unsigned int pmu_power_flags; 173unsigned int pmu_power_flags;
@@ -172,7 +175,6 @@ struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
172static int query_batt_timer = BATTERY_POLLING_COUNT; 175static int query_batt_timer = BATTERY_POLLING_COUNT;
173static struct adb_request batt_req; 176static struct adb_request batt_req;
174static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES]; 177static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
175#endif /* CONFIG_PMAC_PBOOK */
176 178
177#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 179#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
178extern int disable_kernel_backlight; 180extern int disable_kernel_backlight;
@@ -206,11 +208,9 @@ static int proc_get_irqstats(char *page, char **start, off_t off,
206static int pmu_set_backlight_level(int level, void* data); 208static int pmu_set_backlight_level(int level, void* data);
207static int pmu_set_backlight_enable(int on, int level, void* data); 209static int pmu_set_backlight_enable(int on, int level, void* data);
208#endif /* CONFIG_PMAC_BACKLIGHT */ 210#endif /* CONFIG_PMAC_BACKLIGHT */
209#ifdef CONFIG_PMAC_PBOOK
210static void pmu_pass_intr(unsigned char *data, int len); 211static void pmu_pass_intr(unsigned char *data, int len);
211static int proc_get_batt(char *page, char **start, off_t off, 212static int proc_get_batt(char *page, char **start, off_t off,
212 int count, int *eof, void *data); 213 int count, int *eof, void *data);
213#endif /* CONFIG_PMAC_PBOOK */
214static int proc_read_options(char *page, char **start, off_t off, 214static int proc_read_options(char *page, char **start, off_t off,
215 int count, int *eof, void *data); 215 int count, int *eof, void *data);
216static int proc_write_options(struct file *file, const char __user *buffer, 216static int proc_write_options(struct file *file, const char __user *buffer,
@@ -403,8 +403,12 @@ static int __init via_pmu_start(void)
403 403
404 bright_req_1.complete = 1; 404 bright_req_1.complete = 1;
405 bright_req_2.complete = 1; 405 bright_req_2.complete = 1;
406#ifdef CONFIG_PMAC_PBOOK
407 batt_req.complete = 1; 406 batt_req.complete = 1;
407
408#ifdef CONFIG_PPC32
409 if (pmu_kind == PMU_KEYLARGO_BASED)
410 openpic_set_irq_priority(vias->intrs[0].line,
411 OPENPIC_PRIORITY_DEFAULT + 1);
408#endif 412#endif
409 413
410 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU", 414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU",
@@ -458,7 +462,7 @@ static int __init via_pmu_dev_init(void)
458 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu"); 462 register_backlight_controller(&pmu_backlight_controller, NULL, "pmu");
459#endif /* CONFIG_PMAC_BACKLIGHT */ 463#endif /* CONFIG_PMAC_BACKLIGHT */
460 464
461#ifdef CONFIG_PMAC_PBOOK 465#ifdef CONFIG_PPC32
462 if (machine_is_compatible("AAPL,3400/2400") || 466 if (machine_is_compatible("AAPL,3400/2400") ||
463 machine_is_compatible("AAPL,3500")) { 467 machine_is_compatible("AAPL,3500")) {
464 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, 468 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
@@ -486,20 +490,19 @@ static int __init via_pmu_dev_init(void)
486 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; 490 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
487 } 491 }
488 } 492 }
489#endif /* CONFIG_PMAC_PBOOK */ 493#endif /* CONFIG_PPC32 */
494
490 /* Create /proc/pmu */ 495 /* Create /proc/pmu */
491 proc_pmu_root = proc_mkdir("pmu", NULL); 496 proc_pmu_root = proc_mkdir("pmu", NULL);
492 if (proc_pmu_root) { 497 if (proc_pmu_root) {
493#ifdef CONFIG_PMAC_PBOOK 498 long i;
494 int i;
495 499
496 for (i=0; i<pmu_battery_count; i++) { 500 for (i=0; i<pmu_battery_count; i++) {
497 char title[16]; 501 char title[16];
498 sprintf(title, "battery_%d", i); 502 sprintf(title, "battery_%ld", i);
499 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root, 503 proc_pmu_batt[i] = create_proc_read_entry(title, 0, proc_pmu_root,
500 proc_get_batt, (void *)i); 504 proc_get_batt, (void *)i);
501 } 505 }
502#endif /* CONFIG_PMAC_PBOOK */
503 506
504 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root, 507 proc_pmu_info = create_proc_read_entry("info", 0, proc_pmu_root,
505 proc_get_info, NULL); 508 proc_get_info, NULL);
@@ -619,8 +622,6 @@ static void pmu_set_server_mode(int server_mode)
619 pmu_wait_complete(&req); 622 pmu_wait_complete(&req);
620} 623}
621 624
622#ifdef CONFIG_PMAC_PBOOK
623
624/* This new version of the code for 2400/3400/3500 powerbooks 625/* This new version of the code for 2400/3400/3500 powerbooks
625 * is inspired from the implementation in gkrellm-pmu 626 * is inspired from the implementation in gkrellm-pmu
626 */ 627 */
@@ -803,8 +804,6 @@ query_battery_state(void)
803 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1); 804 2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1);
804} 805}
805 806
806#endif /* CONFIG_PMAC_PBOOK */
807
808static int __pmac 807static int __pmac
809proc_get_info(char *page, char **start, off_t off, 808proc_get_info(char *page, char **start, off_t off,
810 int count, int *eof, void *data) 809 int count, int *eof, void *data)
@@ -813,11 +812,9 @@ proc_get_info(char *page, char **start, off_t off,
813 812
814 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION); 813 p += sprintf(p, "PMU driver version : %d\n", PMU_DRIVER_VERSION);
815 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version); 814 p += sprintf(p, "PMU firmware version : %02x\n", pmu_version);
816#ifdef CONFIG_PMAC_PBOOK
817 p += sprintf(p, "AC Power : %d\n", 815 p += sprintf(p, "AC Power : %d\n",
818 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0)); 816 ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0));
819 p += sprintf(p, "Battery count : %d\n", pmu_battery_count); 817 p += sprintf(p, "Battery count : %d\n", pmu_battery_count);
820#endif /* CONFIG_PMAC_PBOOK */
821 818
822 return p - page; 819 return p - page;
823} 820}
@@ -849,12 +846,11 @@ proc_get_irqstats(char *page, char **start, off_t off,
849 return p - page; 846 return p - page;
850} 847}
851 848
852#ifdef CONFIG_PMAC_PBOOK
853static int __pmac 849static int __pmac
854proc_get_batt(char *page, char **start, off_t off, 850proc_get_batt(char *page, char **start, off_t off,
855 int count, int *eof, void *data) 851 int count, int *eof, void *data)
856{ 852{
857 int batnum = (int)data; 853 long batnum = (long)data;
858 char *p = page; 854 char *p = page;
859 855
860 p += sprintf(p, "\n"); 856 p += sprintf(p, "\n");
@@ -873,7 +869,6 @@ proc_get_batt(char *page, char **start, off_t off,
873 869
874 return p - page; 870 return p - page;
875} 871}
876#endif /* CONFIG_PMAC_PBOOK */
877 872
878static int __pmac 873static int __pmac
879proc_read_options(char *page, char **start, off_t off, 874proc_read_options(char *page, char **start, off_t off,
@@ -881,11 +876,11 @@ proc_read_options(char *page, char **start, off_t off,
881{ 876{
882 char *p = page; 877 char *p = page;
883 878
884#ifdef CONFIG_PMAC_PBOOK 879#ifdef CONFIG_PM
885 if (pmu_kind == PMU_KEYLARGO_BASED && 880 if (pmu_kind == PMU_KEYLARGO_BASED &&
886 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 881 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
887 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup); 882 p += sprintf(p, "lid_wakeup=%d\n", option_lid_wakeup);
888#endif /* CONFIG_PMAC_PBOOK */ 883#endif
889 if (pmu_kind == PMU_KEYLARGO_BASED) 884 if (pmu_kind == PMU_KEYLARGO_BASED)
890 p += sprintf(p, "server_mode=%d\n", option_server_mode); 885 p += sprintf(p, "server_mode=%d\n", option_server_mode);
891 886
@@ -922,12 +917,12 @@ proc_write_options(struct file *file, const char __user *buffer,
922 *(val++) = 0; 917 *(val++) = 0;
923 while(*val == ' ') 918 while(*val == ' ')
924 val++; 919 val++;
925#ifdef CONFIG_PMAC_PBOOK 920#ifdef CONFIG_PM
926 if (pmu_kind == PMU_KEYLARGO_BASED && 921 if (pmu_kind == PMU_KEYLARGO_BASED &&
927 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) 922 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
928 if (!strcmp(label, "lid_wakeup")) 923 if (!strcmp(label, "lid_wakeup"))
929 option_lid_wakeup = ((*val) == '1'); 924 option_lid_wakeup = ((*val) == '1');
930#endif /* CONFIG_PMAC_PBOOK */ 925#endif
931 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) { 926 if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) {
932 int new_value; 927 int new_value;
933 new_value = ((*val) == '1'); 928 new_value = ((*val) == '1');
@@ -1422,7 +1417,6 @@ next:
1422 } 1417 }
1423 /* Tick interrupt */ 1418 /* Tick interrupt */
1424 else if ((1 << pirq) & PMU_INT_TICK) { 1419 else if ((1 << pirq) & PMU_INT_TICK) {
1425#ifdef CONFIG_PMAC_PBOOK
1426 /* Environement or tick interrupt, query batteries */ 1420 /* Environement or tick interrupt, query batteries */
1427 if (pmu_battery_count) { 1421 if (pmu_battery_count) {
1428 if ((--query_batt_timer) == 0) { 1422 if ((--query_batt_timer) == 0) {
@@ -1437,7 +1431,6 @@ next:
1437 pmu_pass_intr(data, len); 1431 pmu_pass_intr(data, len);
1438 } else { 1432 } else {
1439 pmu_pass_intr(data, len); 1433 pmu_pass_intr(data, len);
1440#endif /* CONFIG_PMAC_PBOOK */
1441 } 1434 }
1442 goto next; 1435 goto next;
1443} 1436}
@@ -2052,7 +2045,7 @@ pmu_i2c_simple_write(int bus, int addr, u8* data, int len)
2052 return -1; 2045 return -1;
2053} 2046}
2054 2047
2055#ifdef CONFIG_PMAC_PBOOK 2048#ifdef CONFIG_PM
2056 2049
2057static LIST_HEAD(sleep_notifiers); 2050static LIST_HEAD(sleep_notifiers);
2058 2051
@@ -2705,6 +2698,8 @@ powerbook_sleep_3400(void)
2705 return 0; 2698 return 0;
2706} 2699}
2707 2700
2701#endif /* CONFIG_PM */
2702
2708/* 2703/*
2709 * Support for /dev/pmu device 2704 * Support for /dev/pmu device
2710 */ 2705 */
@@ -2884,11 +2879,11 @@ static int __pmac
2884pmu_ioctl(struct inode * inode, struct file *filp, 2879pmu_ioctl(struct inode * inode, struct file *filp,
2885 u_int cmd, u_long arg) 2880 u_int cmd, u_long arg)
2886{ 2881{
2887 struct pmu_private *pp = filp->private_data;
2888 __u32 __user *argp = (__u32 __user *)arg; 2882 __u32 __user *argp = (__u32 __user *)arg;
2889 int error; 2883 int error = -EINVAL;
2890 2884
2891 switch (cmd) { 2885 switch (cmd) {
2886#ifdef CONFIG_PM
2892 case PMU_IOC_SLEEP: 2887 case PMU_IOC_SLEEP:
2893 if (!capable(CAP_SYS_ADMIN)) 2888 if (!capable(CAP_SYS_ADMIN))
2894 return -EACCES; 2889 return -EACCES;
@@ -2910,12 +2905,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2910 error = -ENOSYS; 2905 error = -ENOSYS;
2911 } 2906 }
2912 sleep_in_progress = 0; 2907 sleep_in_progress = 0;
2913 return error; 2908 break;
2914 case PMU_IOC_CAN_SLEEP: 2909 case PMU_IOC_CAN_SLEEP:
2915 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) 2910 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0)
2916 return put_user(0, argp); 2911 return put_user(0, argp);
2917 else 2912 else
2918 return put_user(1, argp); 2913 return put_user(1, argp);
2914#endif /* CONFIG_PM */
2919 2915
2920#ifdef CONFIG_PMAC_BACKLIGHT 2916#ifdef CONFIG_PMAC_BACKLIGHT
2921 /* Backlight should have its own device or go via 2917 /* Backlight should have its own device or go via
@@ -2936,11 +2932,13 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2936 error = get_user(value, argp); 2932 error = get_user(value, argp);
2937 if (!error) 2933 if (!error)
2938 error = set_backlight_level(value); 2934 error = set_backlight_level(value);
2939 return error; 2935 break;
2940 } 2936 }
2941#ifdef CONFIG_INPUT_ADBHID 2937#ifdef CONFIG_INPUT_ADBHID
2942 case PMU_IOC_GRAB_BACKLIGHT: { 2938 case PMU_IOC_GRAB_BACKLIGHT: {
2939 struct pmu_private *pp = filp->private_data;
2943 unsigned long flags; 2940 unsigned long flags;
2941
2944 if (pp->backlight_locker) 2942 if (pp->backlight_locker)
2945 return 0; 2943 return 0;
2946 pp->backlight_locker = 1; 2944 pp->backlight_locker = 1;
@@ -2956,7 +2954,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2956 case PMU_IOC_HAS_ADB: 2954 case PMU_IOC_HAS_ADB:
2957 return put_user(pmu_has_adb, argp); 2955 return put_user(pmu_has_adb, argp);
2958 } 2956 }
2959 return -EINVAL; 2957 return error;
2960} 2958}
2961 2959
2962static struct file_operations pmu_device_fops __pmacdata = { 2960static struct file_operations pmu_device_fops __pmacdata = {
@@ -2972,14 +2970,16 @@ static struct miscdevice pmu_device __pmacdata = {
2972 PMU_MINOR, "pmu", &pmu_device_fops 2970 PMU_MINOR, "pmu", &pmu_device_fops
2973}; 2971};
2974 2972
2975void pmu_device_init(void) 2973static int pmu_device_init(void)
2976{ 2974{
2977 if (!via) 2975 if (!via)
2978 return; 2976 return 0;
2979 if (misc_register(&pmu_device) < 0) 2977 if (misc_register(&pmu_device) < 0)
2980 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); 2978 printk(KERN_ERR "via-pmu: cannot register misc device.\n");
2979 return 0;
2981} 2980}
2982#endif /* CONFIG_PMAC_PBOOK */ 2981device_initcall(pmu_device_init);
2982
2983 2983
2984#ifdef DEBUG_SLEEP 2984#ifdef DEBUG_SLEEP
2985static inline void __pmac 2985static inline void __pmac
@@ -3147,12 +3147,12 @@ EXPORT_SYMBOL(pmu_i2c_combined_read);
3147EXPORT_SYMBOL(pmu_i2c_stdsub_write); 3147EXPORT_SYMBOL(pmu_i2c_stdsub_write);
3148EXPORT_SYMBOL(pmu_i2c_simple_read); 3148EXPORT_SYMBOL(pmu_i2c_simple_read);
3149EXPORT_SYMBOL(pmu_i2c_simple_write); 3149EXPORT_SYMBOL(pmu_i2c_simple_write);
3150#ifdef CONFIG_PMAC_PBOOK 3150#ifdef CONFIG_PM
3151EXPORT_SYMBOL(pmu_register_sleep_notifier); 3151EXPORT_SYMBOL(pmu_register_sleep_notifier);
3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier); 3152EXPORT_SYMBOL(pmu_unregister_sleep_notifier);
3153EXPORT_SYMBOL(pmu_enable_irled); 3153EXPORT_SYMBOL(pmu_enable_irled);
3154EXPORT_SYMBOL(pmu_battery_count); 3154EXPORT_SYMBOL(pmu_battery_count);
3155EXPORT_SYMBOL(pmu_batteries); 3155EXPORT_SYMBOL(pmu_batteries);
3156EXPORT_SYMBOL(pmu_power_flags); 3156EXPORT_SYMBOL(pmu_power_flags);
3157#endif /* CONFIG_PMAC_PBOOK */ 3157#endif /* CONFIG_PM */
3158 3158
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 95980ad6b27b..0c2ed99a3832 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1345,7 +1345,8 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1345 } 1345 }
1346} 1346}
1347 1347
1348int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks) 1348int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
1349 int degraded)
1349{ 1350{
1350 bitmap_counter_t *bmc; 1351 bitmap_counter_t *bmc;
1351 int rv; 1352 int rv;
@@ -1362,8 +1363,10 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks)
1362 rv = 1; 1363 rv = 1;
1363 else if (NEEDED(*bmc)) { 1364 else if (NEEDED(*bmc)) {
1364 rv = 1; 1365 rv = 1;
1365 *bmc |= RESYNC_MASK; 1366 if (!degraded) { /* don't set/clear bits if degraded */
1366 *bmc &= ~NEEDED_MASK; 1367 *bmc |= RESYNC_MASK;
1368 *bmc &= ~NEEDED_MASK;
1369 }
1367 } 1370 }
1368 } 1371 }
1369 spin_unlock_irq(&bitmap->lock); 1372 spin_unlock_irq(&bitmap->lock);
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 0c1b8520ef86..785806bdb248 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -63,6 +63,7 @@ struct multipath {
63 unsigned nr_priority_groups; 63 unsigned nr_priority_groups;
64 struct list_head priority_groups; 64 struct list_head priority_groups;
65 unsigned pg_init_required; /* pg_init needs calling? */ 65 unsigned pg_init_required; /* pg_init needs calling? */
66 unsigned pg_init_in_progress; /* Only one pg_init allowed at once */
66 67
67 unsigned nr_valid_paths; /* Total number of usable paths */ 68 unsigned nr_valid_paths; /* Total number of usable paths */
68 struct pgpath *current_pgpath; 69 struct pgpath *current_pgpath;
@@ -72,7 +73,7 @@ struct multipath {
72 73
73 unsigned queue_io; /* Must we queue all I/O? */ 74 unsigned queue_io; /* Must we queue all I/O? */
74 unsigned queue_if_no_path; /* Queue I/O if last path fails? */ 75 unsigned queue_if_no_path; /* Queue I/O if last path fails? */
75 unsigned suspended; /* Has dm core suspended our I/O? */ 76 unsigned saved_queue_if_no_path;/* Saved state during suspension */
76 77
77 struct work_struct process_queued_ios; 78 struct work_struct process_queued_ios;
78 struct bio_list queued_ios; 79 struct bio_list queued_ios;
@@ -304,11 +305,12 @@ static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
304 m->queue_size--; 305 m->queue_size--;
305 306
306 if ((pgpath && m->queue_io) || 307 if ((pgpath && m->queue_io) ||
307 (!pgpath && m->queue_if_no_path && !m->suspended)) { 308 (!pgpath && m->queue_if_no_path)) {
308 /* Queue for the daemon to resubmit */ 309 /* Queue for the daemon to resubmit */
309 bio_list_add(&m->queued_ios, bio); 310 bio_list_add(&m->queued_ios, bio);
310 m->queue_size++; 311 m->queue_size++;
311 if (m->pg_init_required || !m->queue_io) 312 if ((m->pg_init_required && !m->pg_init_in_progress) ||
313 !m->queue_io)
312 queue_work(kmultipathd, &m->process_queued_ios); 314 queue_work(kmultipathd, &m->process_queued_ios);
313 pgpath = NULL; 315 pgpath = NULL;
314 r = 0; 316 r = 0;
@@ -333,8 +335,9 @@ static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path)
333 335
334 spin_lock_irqsave(&m->lock, flags); 336 spin_lock_irqsave(&m->lock, flags);
335 337
338 m->saved_queue_if_no_path = m->queue_if_no_path;
336 m->queue_if_no_path = queue_if_no_path; 339 m->queue_if_no_path = queue_if_no_path;
337 if (!m->queue_if_no_path) 340 if (!m->queue_if_no_path && m->queue_size)
338 queue_work(kmultipathd, &m->process_queued_ios); 341 queue_work(kmultipathd, &m->process_queued_ios);
339 342
340 spin_unlock_irqrestore(&m->lock, flags); 343 spin_unlock_irqrestore(&m->lock, flags);
@@ -379,25 +382,31 @@ static void process_queued_ios(void *data)
379{ 382{
380 struct multipath *m = (struct multipath *) data; 383 struct multipath *m = (struct multipath *) data;
381 struct hw_handler *hwh = &m->hw_handler; 384 struct hw_handler *hwh = &m->hw_handler;
382 struct pgpath *pgpath; 385 struct pgpath *pgpath = NULL;
383 unsigned init_required, must_queue = 0; 386 unsigned init_required = 0, must_queue = 1;
384 unsigned long flags; 387 unsigned long flags;
385 388
386 spin_lock_irqsave(&m->lock, flags); 389 spin_lock_irqsave(&m->lock, flags);
387 390
391 if (!m->queue_size)
392 goto out;
393
388 if (!m->current_pgpath) 394 if (!m->current_pgpath)
389 __choose_pgpath(m); 395 __choose_pgpath(m);
390 396
391 pgpath = m->current_pgpath; 397 pgpath = m->current_pgpath;
392 398
393 if ((pgpath && m->queue_io) || 399 if ((pgpath && !m->queue_io) ||
394 (!pgpath && m->queue_if_no_path && !m->suspended)) 400 (!pgpath && !m->queue_if_no_path))
395 must_queue = 1; 401 must_queue = 0;
396 402
397 init_required = m->pg_init_required; 403 if (m->pg_init_required && !m->pg_init_in_progress) {
398 if (init_required)
399 m->pg_init_required = 0; 404 m->pg_init_required = 0;
405 m->pg_init_in_progress = 1;
406 init_required = 1;
407 }
400 408
409out:
401 spin_unlock_irqrestore(&m->lock, flags); 410 spin_unlock_irqrestore(&m->lock, flags);
402 411
403 if (init_required) 412 if (init_required)
@@ -752,6 +761,8 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
752static void multipath_dtr(struct dm_target *ti) 761static void multipath_dtr(struct dm_target *ti)
753{ 762{
754 struct multipath *m = (struct multipath *) ti->private; 763 struct multipath *m = (struct multipath *) ti->private;
764
765 flush_workqueue(kmultipathd);
755 free_multipath(m); 766 free_multipath(m);
756} 767}
757 768
@@ -765,6 +776,9 @@ static int multipath_map(struct dm_target *ti, struct bio *bio,
765 struct mpath_io *mpio; 776 struct mpath_io *mpio;
766 struct multipath *m = (struct multipath *) ti->private; 777 struct multipath *m = (struct multipath *) ti->private;
767 778
779 if (bio_barrier(bio))
780 return -EOPNOTSUPP;
781
768 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO); 782 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO);
769 dm_bio_record(&mpio->details, bio); 783 dm_bio_record(&mpio->details, bio);
770 784
@@ -837,7 +851,7 @@ static int reinstate_path(struct pgpath *pgpath)
837 pgpath->path.is_active = 1; 851 pgpath->path.is_active = 1;
838 852
839 m->current_pgpath = NULL; 853 m->current_pgpath = NULL;
840 if (!m->nr_valid_paths++) 854 if (!m->nr_valid_paths++ && m->queue_size)
841 queue_work(kmultipathd, &m->process_queued_ios); 855 queue_work(kmultipathd, &m->process_queued_ios);
842 856
843 queue_work(kmultipathd, &m->trigger_event); 857 queue_work(kmultipathd, &m->trigger_event);
@@ -963,12 +977,13 @@ void dm_pg_init_complete(struct path *path, unsigned err_flags)
963 bypass_pg(m, pg, 1); 977 bypass_pg(m, pg, 1);
964 978
965 spin_lock_irqsave(&m->lock, flags); 979 spin_lock_irqsave(&m->lock, flags);
966 if (!err_flags) 980 if (err_flags) {
967 m->queue_io = 0;
968 else {
969 m->current_pgpath = NULL; 981 m->current_pgpath = NULL;
970 m->current_pg = NULL; 982 m->current_pg = NULL;
971 } 983 } else if (!m->pg_init_required)
984 m->queue_io = 0;
985
986 m->pg_init_in_progress = 0;
972 queue_work(kmultipathd, &m->process_queued_ios); 987 queue_work(kmultipathd, &m->process_queued_ios);
973 spin_unlock_irqrestore(&m->lock, flags); 988 spin_unlock_irqrestore(&m->lock, flags);
974} 989}
@@ -988,9 +1003,12 @@ static int do_end_io(struct multipath *m, struct bio *bio,
988 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio)) 1003 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
989 return error; 1004 return error;
990 1005
1006 if (error == -EOPNOTSUPP)
1007 return error;
1008
991 spin_lock(&m->lock); 1009 spin_lock(&m->lock);
992 if (!m->nr_valid_paths) { 1010 if (!m->nr_valid_paths) {
993 if (!m->queue_if_no_path || m->suspended) { 1011 if (!m->queue_if_no_path) {
994 spin_unlock(&m->lock); 1012 spin_unlock(&m->lock);
995 return -EIO; 1013 return -EIO;
996 } else { 1014 } else {
@@ -1051,27 +1069,27 @@ static int multipath_end_io(struct dm_target *ti, struct bio *bio,
1051 1069
1052/* 1070/*
1053 * Suspend can't complete until all the I/O is processed so if 1071 * Suspend can't complete until all the I/O is processed so if
1054 * the last path failed we will now error any queued I/O. 1072 * the last path fails we must error any remaining I/O.
1073 * Note that if the freeze_bdev fails while suspending, the
1074 * queue_if_no_path state is lost - userspace should reset it.
1055 */ 1075 */
1056static void multipath_presuspend(struct dm_target *ti) 1076static void multipath_presuspend(struct dm_target *ti)
1057{ 1077{
1058 struct multipath *m = (struct multipath *) ti->private; 1078 struct multipath *m = (struct multipath *) ti->private;
1059 unsigned long flags;
1060 1079
1061 spin_lock_irqsave(&m->lock, flags); 1080 queue_if_no_path(m, 0);
1062 m->suspended = 1;
1063 if (m->queue_if_no_path)
1064 queue_work(kmultipathd, &m->process_queued_ios);
1065 spin_unlock_irqrestore(&m->lock, flags);
1066} 1081}
1067 1082
1083/*
1084 * Restore the queue_if_no_path setting.
1085 */
1068static void multipath_resume(struct dm_target *ti) 1086static void multipath_resume(struct dm_target *ti)
1069{ 1087{
1070 struct multipath *m = (struct multipath *) ti->private; 1088 struct multipath *m = (struct multipath *) ti->private;
1071 unsigned long flags; 1089 unsigned long flags;
1072 1090
1073 spin_lock_irqsave(&m->lock, flags); 1091 spin_lock_irqsave(&m->lock, flags);
1074 m->suspended = 0; 1092 m->queue_if_no_path = m->saved_queue_if_no_path;
1075 spin_unlock_irqrestore(&m->lock, flags); 1093 spin_unlock_irqrestore(&m->lock, flags);
1076} 1094}
1077 1095
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 6e3cf7e13451..12031c9d3f1e 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1060,6 +1060,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1060 } 1060 }
1061 1061
1062 ti->private = ms; 1062 ti->private = ms;
1063 ti->split_io = ms->rh.region_size;
1063 1064
1064 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); 1065 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client);
1065 if (r) { 1066 if (r) {
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 7e691ab9a748..ab54f99b7c3b 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -777,7 +777,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
777 777
778 /* Full snapshots are not usable */ 778 /* Full snapshots are not usable */
779 if (!s->valid) 779 if (!s->valid)
780 return -1; 780 return -EIO;
781 781
782 /* 782 /*
783 * Write to snapshot - higher level takes care of RW/RO 783 * Write to snapshot - higher level takes care of RW/RO
@@ -931,6 +931,10 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
931 if (!snap->valid) 931 if (!snap->valid)
932 continue; 932 continue;
933 933
934 /* Nothing to do if writing beyond end of snapshot */
935 if (bio->bi_sector >= dm_table_get_size(snap->table))
936 continue;
937
934 down_write(&snap->lock); 938 down_write(&snap->lock);
935 939
936 /* 940 /*
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 18e9b9953fcd..a5a4c0ed8a14 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -943,6 +943,7 @@ EXPORT_SYMBOL(dm_vcalloc);
943EXPORT_SYMBOL(dm_get_device); 943EXPORT_SYMBOL(dm_get_device);
944EXPORT_SYMBOL(dm_put_device); 944EXPORT_SYMBOL(dm_put_device);
945EXPORT_SYMBOL(dm_table_event); 945EXPORT_SYMBOL(dm_table_event);
946EXPORT_SYMBOL(dm_table_get_size);
946EXPORT_SYMBOL(dm_table_get_mode); 947EXPORT_SYMBOL(dm_table_get_mode);
947EXPORT_SYMBOL(dm_table_put); 948EXPORT_SYMBOL(dm_table_put);
948EXPORT_SYMBOL(dm_table_get); 949EXPORT_SYMBOL(dm_table_get);
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f6b03957efc7..54fabbf06678 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -384,7 +384,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
384 /* error the io and bail out */ 384 /* error the io and bail out */
385 struct dm_io *io = tio->io; 385 struct dm_io *io = tio->io;
386 free_tio(tio->io->md, tio); 386 free_tio(tio->io->md, tio);
387 dec_pending(io, -EIO); 387 dec_pending(io, r);
388 bio_put(clone); 388 bio_put(clone);
389 } 389 }
390} 390}
@@ -966,23 +966,20 @@ static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
966 */ 966 */
967int dm_swap_table(struct mapped_device *md, struct dm_table *table) 967int dm_swap_table(struct mapped_device *md, struct dm_table *table)
968{ 968{
969 int r; 969 int r = -EINVAL;
970 970
971 down_write(&md->lock); 971 down_write(&md->lock);
972 972
973 /* device must be suspended */ 973 /* device must be suspended */
974 if (!test_bit(DMF_SUSPENDED, &md->flags)) { 974 if (!test_bit(DMF_SUSPENDED, &md->flags))
975 up_write(&md->lock); 975 goto out;
976 return -EPERM;
977 }
978 976
979 __unbind(md); 977 __unbind(md);
980 r = __bind(md, table); 978 r = __bind(md, table);
981 if (r)
982 return r;
983 979
980out:
984 up_write(&md->lock); 981 up_write(&md->lock);
985 return 0; 982 return r;
986} 983}
987 984
988/* 985/*
@@ -1055,14 +1052,17 @@ int dm_suspend(struct mapped_device *md)
1055 if (test_bit(DMF_BLOCK_IO, &md->flags)) 1052 if (test_bit(DMF_BLOCK_IO, &md->flags))
1056 goto out_read_unlock; 1053 goto out_read_unlock;
1057 1054
1058 error = __lock_fs(md);
1059 if (error)
1060 goto out_read_unlock;
1061
1062 map = dm_get_table(md); 1055 map = dm_get_table(md);
1063 if (map) 1056 if (map)
1057 /* This does not get reverted if there's an error later. */
1064 dm_table_presuspend_targets(map); 1058 dm_table_presuspend_targets(map);
1065 1059
1060 error = __lock_fs(md);
1061 if (error) {
1062 dm_table_put(map);
1063 goto out_read_unlock;
1064 }
1065
1066 up_read(&md->lock); 1066 up_read(&md->lock);
1067 1067
1068 /* 1068 /*
@@ -1121,7 +1121,6 @@ int dm_suspend(struct mapped_device *md)
1121 return 0; 1121 return 0;
1122 1122
1123out_unfreeze: 1123out_unfreeze:
1124 /* FIXME Undo dm_table_presuspend_targets */
1125 __unlock_fs(md); 1124 __unlock_fs(md);
1126 clear_bit(DMF_BLOCK_IO, &md->flags); 1125 clear_bit(DMF_BLOCK_IO, &md->flags);
1127out_write_unlock: 1126out_write_unlock:
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 3802f7a17f16..4a0c57db2b67 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -338,6 +338,7 @@ static int super_written(struct bio *bio, unsigned int bytes_done, int error)
338 338
339 if (atomic_dec_and_test(&rdev->mddev->pending_writes)) 339 if (atomic_dec_and_test(&rdev->mddev->pending_writes))
340 wake_up(&rdev->mddev->sb_wait); 340 wake_up(&rdev->mddev->sb_wait);
341 bio_put(bio);
341 return 0; 342 return 0;
342} 343}
343 344
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index e11dd14d0b43..2120710172c5 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -314,16 +314,16 @@ static int raid0_run (mddev_t *mddev)
314 sector_t space = conf->hash_spacing; 314 sector_t space = conf->hash_spacing;
315 int round; 315 int round;
316 conf->preshift = 0; 316 conf->preshift = 0;
317 if (sizeof(sector_t) > sizeof(unsigned long)) { 317 if (sizeof(sector_t) > sizeof(u32)) {
318 /*shift down space and s so that sector_div will work */ 318 /*shift down space and s so that sector_div will work */
319 while (space > (sector_t) (~(unsigned long)0)) { 319 while (space > (sector_t) (~(u32)0)) {
320 s >>= 1; 320 s >>= 1;
321 space >>= 1; 321 space >>= 1;
322 s += 1; /* force round-up */ 322 s += 1; /* force round-up */
323 conf->preshift++; 323 conf->preshift++;
324 } 324 }
325 } 325 }
326 round = sector_div(s, (unsigned long)space) ? 1 : 0; 326 round = sector_div(s, (u32)space) ? 1 : 0;
327 nb_zone = s + round; 327 nb_zone = s + round;
328 } 328 }
329 printk("raid0 : nb_zone is %d.\n", nb_zone); 329 printk("raid0 : nb_zone is %d.\n", nb_zone);
@@ -443,7 +443,7 @@ static int raid0_make_request (request_queue_t *q, struct bio *bio)
443 volatile 443 volatile
444#endif 444#endif
445 sector_t x = block >> conf->preshift; 445 sector_t x = block >> conf->preshift;
446 sector_div(x, (unsigned long)conf->hash_spacing); 446 sector_div(x, (u32)conf->hash_spacing);
447 zone = conf->hash_table[x]; 447 zone = conf->hash_table[x];
448 } 448 }
449 449
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index ff1dbec864af..5f253ee536bb 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1126,21 +1126,19 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1126 * only be one in raid1 resync. 1126 * only be one in raid1 resync.
1127 * We can find the current addess in mddev->curr_resync 1127 * We can find the current addess in mddev->curr_resync
1128 */ 1128 */
1129 if (!conf->fullsync) { 1129 if (mddev->curr_resync < max_sector) /* aborted */
1130 if (mddev->curr_resync < max_sector) 1130 bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
1131 bitmap_end_sync(mddev->bitmap,
1132 mddev->curr_resync,
1133 &sync_blocks, 1); 1131 &sync_blocks, 1);
1134 bitmap_close_sync(mddev->bitmap); 1132 else /* completed sync */
1135 }
1136 if (mddev->curr_resync >= max_sector)
1137 conf->fullsync = 0; 1133 conf->fullsync = 0;
1134
1135 bitmap_close_sync(mddev->bitmap);
1138 close_sync(conf); 1136 close_sync(conf);
1139 return 0; 1137 return 0;
1140 } 1138 }
1141 1139
1142 if (!conf->fullsync && 1140 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, mddev->degraded) &&
1143 !bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks)) { 1141 !conf->fullsync) {
1144 /* We can skip this block, and probably several more */ 1142 /* We can skip this block, and probably several more */
1145 *skipped = 1; 1143 *skipped = 1;
1146 return sync_blocks; 1144 return sync_blocks;
@@ -1243,15 +1241,15 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1243 len = (max_sector - sector_nr) << 9; 1241 len = (max_sector - sector_nr) << 9;
1244 if (len == 0) 1242 if (len == 0)
1245 break; 1243 break;
1246 if (!conf->fullsync) { 1244 if (sync_blocks == 0) {
1247 if (sync_blocks == 0) { 1245 if (!bitmap_start_sync(mddev->bitmap, sector_nr,
1248 if (!bitmap_start_sync(mddev->bitmap, 1246 &sync_blocks, mddev->degraded) &&
1249 sector_nr, &sync_blocks)) 1247 !conf->fullsync)
1250 break; 1248 break;
1251 if (sync_blocks < (PAGE_SIZE>>9)) 1249 if (sync_blocks < (PAGE_SIZE>>9))
1252 BUG(); 1250 BUG();
1253 if (len > (sync_blocks<<9)) len = sync_blocks<<9; 1251 if (len > (sync_blocks<<9))
1254 } 1252 len = sync_blocks<<9;
1255 } 1253 }
1256 1254
1257 for (i=0 ; i < conf->raid_disks; i++) { 1255 for (i=0 ; i < conf->raid_disks; i++) {
@@ -1264,7 +1262,8 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1264 while (i > 0) { 1262 while (i > 0) {
1265 i--; 1263 i--;
1266 bio = r1_bio->bios[i]; 1264 bio = r1_bio->bios[i];
1267 if (bio->bi_end_io==NULL) continue; 1265 if (bio->bi_end_io==NULL)
1266 continue;
1268 /* remove last page from this bio */ 1267 /* remove last page from this bio */
1269 bio->bi_vcnt--; 1268 bio->bi_vcnt--;
1270 bio->bi_size -= len; 1269 bio->bi_size -= len;
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
index 4adb2843f8be..ab7a1fba4427 100644
--- a/drivers/media/common/ir-common.c
+++ b/drivers/media/common/ir-common.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-common.c,v 1.10 2005/05/22 19:23:39 nsh Exp $ 2 * $Id: ir-common.c,v 1.11 2005/07/07 14:44:43 mchehab Exp $
3 * 3 *
4 * some common structs and functions to handle infrared remotes via 4 * some common structs and functions to handle infrared remotes via
5 * input layer ... 5 * input layer ...
@@ -46,79 +46,49 @@ module_param(debug, int, 0644);
46/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */ 46/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
47/* used by old (black) Hauppauge remotes */ 47/* used by old (black) Hauppauge remotes */
48IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = { 48IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = {
49 [ 0x00 ] = KEY_KP0, // 0 49 /* Keys 0 to 9 */
50 [ 0x01 ] = KEY_KP1, // 1 50 [ 0x00 ] = KEY_KP0,
51 [ 0x02 ] = KEY_KP2, // 2 51 [ 0x01 ] = KEY_KP1,
52 [ 0x03 ] = KEY_KP3, // 3 52 [ 0x02 ] = KEY_KP2,
53 [ 0x04 ] = KEY_KP4, // 4 53 [ 0x03 ] = KEY_KP3,
54 [ 0x05 ] = KEY_KP5, // 5 54 [ 0x04 ] = KEY_KP4,
55 [ 0x06 ] = KEY_KP6, // 6 55 [ 0x05 ] = KEY_KP5,
56 [ 0x07 ] = KEY_KP7, // 7 56 [ 0x06 ] = KEY_KP6,
57 [ 0x08 ] = KEY_KP8, // 8 57 [ 0x07 ] = KEY_KP7,
58 [ 0x09 ] = KEY_KP9, // 9 58 [ 0x08 ] = KEY_KP8,
59 59 [ 0x09 ] = KEY_KP9,
60 [ 0x0b ] = KEY_CHANNEL, // channel / program (japan: 11) 60
61 [ 0x0c ] = KEY_POWER, // standby 61 [ 0x0b ] = KEY_CHANNEL, /* channel / program (japan: 11) */
62 [ 0x0d ] = KEY_MUTE, // mute / demute 62 [ 0x0c ] = KEY_POWER, /* standby */
63 [ 0x0f ] = KEY_TV, // display 63 [ 0x0d ] = KEY_MUTE, /* mute / demute */
64 [ 0x10 ] = KEY_VOLUMEUP, // volume + 64 [ 0x0f ] = KEY_TV, /* display */
65 [ 0x11 ] = KEY_VOLUMEDOWN, // volume - 65 [ 0x10 ] = KEY_VOLUMEUP,
66 [ 0x12 ] = KEY_BRIGHTNESSUP, // brightness + 66 [ 0x11 ] = KEY_VOLUMEDOWN,
67 [ 0x13 ] = KEY_BRIGHTNESSDOWN, // brightness - 67 [ 0x12 ] = KEY_BRIGHTNESSUP,
68 [ 0x1e ] = KEY_SEARCH, // search + 68 [ 0x13 ] = KEY_BRIGHTNESSDOWN,
69 [ 0x20 ] = KEY_CHANNELUP, // channel / program + 69 [ 0x1e ] = KEY_SEARCH, /* search + */
70 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program - 70 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
71 [ 0x22 ] = KEY_CHANNEL, // alt / channel 71 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
72 [ 0x23 ] = KEY_LANGUAGE, // 1st / 2nd language 72 [ 0x22 ] = KEY_CHANNEL, /* alt / channel */
73 [ 0x26 ] = KEY_SLEEP, // sleeptimer 73 [ 0x23 ] = KEY_LANGUAGE, /* 1st / 2nd language */
74 [ 0x2e ] = KEY_MENU, // 2nd controls (USA: menu) 74 [ 0x26 ] = KEY_SLEEP, /* sleeptimer */
75 [ 0x30 ] = KEY_PAUSE, // pause 75 [ 0x2e ] = KEY_MENU, /* 2nd controls (USA: menu) */
76 [ 0x32 ] = KEY_REWIND, // rewind 76 [ 0x30 ] = KEY_PAUSE,
77 [ 0x33 ] = KEY_GOTO, // go to 77 [ 0x32 ] = KEY_REWIND,
78 [ 0x35 ] = KEY_PLAY, // play 78 [ 0x33 ] = KEY_GOTO,
79 [ 0x36 ] = KEY_STOP, // stop 79 [ 0x35 ] = KEY_PLAY,
80 [ 0x37 ] = KEY_RECORD, // recording 80 [ 0x36 ] = KEY_STOP,
81 [ 0x3c ] = KEY_TEXT, // teletext submode (Japan: 12) 81 [ 0x37 ] = KEY_RECORD, /* recording */
82 [ 0x3d ] = KEY_SUSPEND, // system standby 82 [ 0x3c ] = KEY_TEXT, /* teletext submode (Japan: 12) */
83 83 [ 0x3d ] = KEY_SUSPEND, /* system standby */
84#if 0 /* FIXME */ 84
85 [ 0x0a ] = KEY_RESERVED, // 1/2/3 digits (japan: 10)
86 [ 0x0e ] = KEY_RESERVED, // P.P. (personal preference)
87 [ 0x14 ] = KEY_RESERVED, // colour saturation +
88 [ 0x15 ] = KEY_RESERVED, // colour saturation -
89 [ 0x16 ] = KEY_RESERVED, // bass +
90 [ 0x17 ] = KEY_RESERVED, // bass -
91 [ 0x18 ] = KEY_RESERVED, // treble +
92 [ 0x19 ] = KEY_RESERVED, // treble -
93 [ 0x1a ] = KEY_RESERVED, // balance right
94 [ 0x1b ] = KEY_RESERVED, // balance left
95 [ 0x1c ] = KEY_RESERVED, // contrast +
96 [ 0x1d ] = KEY_RESERVED, // contrast -
97 [ 0x1f ] = KEY_RESERVED, // tint/hue +
98 [ 0x24 ] = KEY_RESERVED, // spacial stereo on/off
99 [ 0x25 ] = KEY_RESERVED, // mono / stereo (USA)
100 [ 0x27 ] = KEY_RESERVED, // tint / hue -
101 [ 0x28 ] = KEY_RESERVED, // RF switch/PIP select
102 [ 0x29 ] = KEY_RESERVED, // vote
103 [ 0x2a ] = KEY_RESERVED, // timed page/channel clck
104 [ 0x2b ] = KEY_RESERVED, // increment (USA)
105 [ 0x2c ] = KEY_RESERVED, // decrement (USA)
106 [ 0x2d ] = KEY_RESERVED, //
107 [ 0x2f ] = KEY_RESERVED, // PIP shift
108 [ 0x31 ] = KEY_RESERVED, // erase
109 [ 0x34 ] = KEY_RESERVED, // wind
110 [ 0x38 ] = KEY_RESERVED, // external 1
111 [ 0x39 ] = KEY_RESERVED, // external 2
112 [ 0x3a ] = KEY_RESERVED, // PIP display mode
113 [ 0x3b ] = KEY_RESERVED, // view data mode / advance
114 [ 0x3e ] = KEY_RESERVED, // crispener on/off
115 [ 0x3f ] = KEY_RESERVED, // system select
116#endif
117}; 85};
118EXPORT_SYMBOL_GPL(ir_codes_rc5_tv); 86EXPORT_SYMBOL_GPL(ir_codes_rc5_tv);
119 87
120/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */ 88/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
121IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = { 89IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
90 /* Keys 0 to 9 */
91 [ 18 ] = KEY_KP0,
122 [ 5 ] = KEY_KP1, 92 [ 5 ] = KEY_KP1,
123 [ 6 ] = KEY_KP2, 93 [ 6 ] = KEY_KP2,
124 [ 7 ] = KEY_KP3, 94 [ 7 ] = KEY_KP3,
@@ -128,39 +98,31 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
128 [ 13 ] = KEY_KP7, 98 [ 13 ] = KEY_KP7,
129 [ 14 ] = KEY_KP8, 99 [ 14 ] = KEY_KP8,
130 [ 15 ] = KEY_KP9, 100 [ 15 ] = KEY_KP9,
131 [ 18 ] = KEY_KP0,
132 101
133 [ 0 ] = KEY_POWER, 102 [ 0 ] = KEY_POWER,
134// [ 27 ] = MTS button 103 [ 2 ] = KEY_TUNER, /* TV/FM */
135 [ 2 ] = KEY_TUNER, // TV/FM
136 [ 30 ] = KEY_VIDEO, 104 [ 30 ] = KEY_VIDEO,
137// [ 22 ] = display button
138 [ 4 ] = KEY_VOLUMEUP, 105 [ 4 ] = KEY_VOLUMEUP,
139 [ 8 ] = KEY_VOLUMEDOWN, 106 [ 8 ] = KEY_VOLUMEDOWN,
140 [ 12 ] = KEY_CHANNELUP, 107 [ 12 ] = KEY_CHANNELUP,
141 [ 16 ] = KEY_CHANNELDOWN, 108 [ 16 ] = KEY_CHANNELDOWN,
142 [ 3 ] = KEY_ZOOM, // fullscreen 109 [ 3 ] = KEY_ZOOM, /* fullscreen */
143 [ 31 ] = KEY_SUBTITLE, // closed caption/teletext 110 [ 31 ] = KEY_SUBTITLE, /* closed caption/teletext */
144 [ 32 ] = KEY_SLEEP, 111 [ 32 ] = KEY_SLEEP,
145// [ 41 ] = boss key
146 [ 20 ] = KEY_MUTE, 112 [ 20 ] = KEY_MUTE,
147 [ 43 ] = KEY_RED, 113 [ 43 ] = KEY_RED,
148 [ 44 ] = KEY_GREEN, 114 [ 44 ] = KEY_GREEN,
149 [ 45 ] = KEY_YELLOW, 115 [ 45 ] = KEY_YELLOW,
150 [ 46 ] = KEY_BLUE, 116 [ 46 ] = KEY_BLUE,
151 [ 24 ] = KEY_KPPLUS, //fine tune + 117 [ 24 ] = KEY_KPPLUS, /* fine tune + */
152 [ 25 ] = KEY_KPMINUS, //fine tune - 118 [ 25 ] = KEY_KPMINUS, /* fine tune - */
153// [ 42 ] = picture in picture
154 [ 33 ] = KEY_KPDOT, 119 [ 33 ] = KEY_KPDOT,
155 [ 19 ] = KEY_KPENTER, 120 [ 19 ] = KEY_KPENTER,
156// [ 17 ] = recall
157 [ 34 ] = KEY_BACK, 121 [ 34 ] = KEY_BACK,
158 [ 35 ] = KEY_PLAYPAUSE, 122 [ 35 ] = KEY_PLAYPAUSE,
159 [ 36 ] = KEY_NEXT, 123 [ 36 ] = KEY_NEXT,
160// [ 37 ] = time shifting
161 [ 38 ] = KEY_STOP, 124 [ 38 ] = KEY_STOP,
162 [ 39 ] = KEY_RECORD 125 [ 39 ] = KEY_RECORD
163// [ 40 ] = snapshot
164}; 126};
165EXPORT_SYMBOL_GPL(ir_codes_winfast); 127EXPORT_SYMBOL_GPL(ir_codes_winfast);
166 128
@@ -174,54 +136,61 @@ EXPORT_SYMBOL_GPL(ir_codes_empty);
174 * slightly different versions), shipped with cx88+ivtv cards. 136 * slightly different versions), shipped with cx88+ivtv cards.
175 * almost rc5 coding, but some non-standard keys */ 137 * almost rc5 coding, but some non-standard keys */
176IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = { 138IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
177 [ 0x00 ] = KEY_KP0, // 0 139 /* Keys 0 to 9 */
178 [ 0x01 ] = KEY_KP1, // 1 140 [ 0x00 ] = KEY_KP0,
179 [ 0x02 ] = KEY_KP2, // 2 141 [ 0x01 ] = KEY_KP1,
180 [ 0x03 ] = KEY_KP3, // 3 142 [ 0x02 ] = KEY_KP2,
181 [ 0x04 ] = KEY_KP4, // 4 143 [ 0x03 ] = KEY_KP3,
182 [ 0x05 ] = KEY_KP5, // 5 144 [ 0x04 ] = KEY_KP4,
183 [ 0x06 ] = KEY_KP6, // 6 145 [ 0x05 ] = KEY_KP5,
184 [ 0x07 ] = KEY_KP7, // 7 146 [ 0x06 ] = KEY_KP6,
185 [ 0x08 ] = KEY_KP8, // 8 147 [ 0x07 ] = KEY_KP7,
186 [ 0x09 ] = KEY_KP9, // 9 148 [ 0x08 ] = KEY_KP8,
187 [ 0x0a ] = KEY_TEXT, // keypad asterisk as well 149 [ 0x09 ] = KEY_KP9,
188 [ 0x0b ] = KEY_RED, // red button 150
189 [ 0x0c ] = KEY_RADIO, // radio 151 [ 0x0a ] = KEY_TEXT, /* keypad asterisk as well */
190 [ 0x0d ] = KEY_MENU, // menu 152 [ 0x0b ] = KEY_RED, /* red button */
191 [ 0x0e ] = KEY_SUBTITLE, // also the # key 153 [ 0x0c ] = KEY_RADIO,
192 [ 0x0f ] = KEY_MUTE, // mute 154 [ 0x0d ] = KEY_MENU,
193 [ 0x10 ] = KEY_VOLUMEUP, // volume + 155 [ 0x0e ] = KEY_SUBTITLE, /* also the # key */
194 [ 0x11 ] = KEY_VOLUMEDOWN, // volume - 156 [ 0x0f ] = KEY_MUTE,
195 [ 0x12 ] = KEY_PREVIOUS, // previous channel 157 [ 0x10 ] = KEY_VOLUMEUP,
196 [ 0x14 ] = KEY_UP, // up 158 [ 0x11 ] = KEY_VOLUMEDOWN,
197 [ 0x15 ] = KEY_DOWN, // down 159 [ 0x12 ] = KEY_PREVIOUS, /* previous channel */
198 [ 0x16 ] = KEY_LEFT, // left 160 [ 0x14 ] = KEY_UP,
199 [ 0x17 ] = KEY_RIGHT, // right 161 [ 0x15 ] = KEY_DOWN,
200 [ 0x18 ] = KEY_VIDEO, // Videos 162 [ 0x16 ] = KEY_LEFT,
201 [ 0x19 ] = KEY_AUDIO, // Music 163 [ 0x17 ] = KEY_RIGHT,
202 [ 0x1a ] = KEY_MHP, // Pictures - presume this means "Multimedia Home Platform"- no "PICTURES" key in input.h 164 [ 0x18 ] = KEY_VIDEO, /* Videos */
203 [ 0x1b ] = KEY_EPG, // Guide 165 [ 0x19 ] = KEY_AUDIO, /* Music */
204 [ 0x1c ] = KEY_TV, // TV 166 /* 0x1a: Pictures - presume this means
205 [ 0x1e ] = KEY_NEXTSONG, // skip >| 167 "Multimedia Home Platform" -
206 [ 0x1f ] = KEY_EXIT, // back/exit 168 no "PICTURES" key in input.h
207 [ 0x20 ] = KEY_CHANNELUP, // channel / program + 169 */
208 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program - 170 [ 0x1a ] = KEY_MHP,
209 [ 0x22 ] = KEY_CHANNEL, // source (old black remote) 171
210 [ 0x24 ] = KEY_PREVIOUSSONG, // replay |< 172 [ 0x1b ] = KEY_EPG, /* Guide */
211 [ 0x25 ] = KEY_ENTER, // OK 173 [ 0x1c ] = KEY_TV,
212 [ 0x26 ] = KEY_SLEEP, // minimize (old black remote) 174 [ 0x1e ] = KEY_NEXTSONG, /* skip >| */
213 [ 0x29 ] = KEY_BLUE, // blue key 175 [ 0x1f ] = KEY_EXIT, /* back/exit */
214 [ 0x2e ] = KEY_GREEN, // green button 176 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
215 [ 0x30 ] = KEY_PAUSE, // pause 177 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
216 [ 0x32 ] = KEY_REWIND, // backward << 178 [ 0x22 ] = KEY_CHANNEL, /* source (old black remote) */
217 [ 0x34 ] = KEY_FASTFORWARD, // forward >> 179 [ 0x24 ] = KEY_PREVIOUSSONG, /* replay |< */
218 [ 0x35 ] = KEY_PLAY, // play 180 [ 0x25 ] = KEY_ENTER, /* OK */
219 [ 0x36 ] = KEY_STOP, // stop 181 [ 0x26 ] = KEY_SLEEP, /* minimize (old black remote) */
220 [ 0x37 ] = KEY_RECORD, // recording 182 [ 0x29 ] = KEY_BLUE, /* blue key */
221 [ 0x38 ] = KEY_YELLOW, // yellow key 183 [ 0x2e ] = KEY_GREEN, /* green button */
222 [ 0x3b ] = KEY_SELECT, // top right button 184 [ 0x30 ] = KEY_PAUSE, /* pause */
223 [ 0x3c ] = KEY_ZOOM, // full 185 [ 0x32 ] = KEY_REWIND, /* backward << */
224 [ 0x3d ] = KEY_POWER, // system power (green button) 186 [ 0x34 ] = KEY_FASTFORWARD, /* forward >> */
187 [ 0x35 ] = KEY_PLAY,
188 [ 0x36 ] = KEY_STOP,
189 [ 0x37 ] = KEY_RECORD, /* recording */
190 [ 0x38 ] = KEY_YELLOW, /* yellow key */
191 [ 0x3b ] = KEY_SELECT, /* top right button */
192 [ 0x3c ] = KEY_ZOOM, /* full */
193 [ 0x3d ] = KEY_POWER, /* system power (green button) */
225}; 194};
226EXPORT_SYMBOL(ir_codes_hauppauge_new); 195EXPORT_SYMBOL(ir_codes_hauppauge_new);
227 196
@@ -237,9 +206,9 @@ IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
237 [ 10 ] = KEY_KP8, 206 [ 10 ] = KEY_KP8,
238 [ 18 ] = KEY_KP9, 207 [ 18 ] = KEY_KP9,
239 208
240 [ 3 ] = KEY_TUNER, // TV/FM 209 [ 3 ] = KEY_TUNER, /* TV/FM */
241 [ 7 ] = KEY_SEARCH, // scan 210 [ 7 ] = KEY_SEARCH, /* scan */
242 [ 28 ] = KEY_ZOOM, // full screen 211 [ 28 ] = KEY_ZOOM, /* full screen */
243 [ 30 ] = KEY_POWER, 212 [ 30 ] = KEY_POWER,
244 [ 23 ] = KEY_VOLUMEDOWN, 213 [ 23 ] = KEY_VOLUMEDOWN,
245 [ 31 ] = KEY_VOLUMEUP, 214 [ 31 ] = KEY_VOLUMEUP,
@@ -247,14 +216,14 @@ IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
247 [ 22 ] = KEY_CHANNELUP, 216 [ 22 ] = KEY_CHANNELUP,
248 [ 24 ] = KEY_MUTE, 217 [ 24 ] = KEY_MUTE,
249 218
250 [ 0 ] = KEY_LIST, // source 219 [ 0 ] = KEY_LIST, /* source */
251 [ 19 ] = KEY_INFO, // loop 220 [ 19 ] = KEY_INFO, /* loop */
252 [ 16 ] = KEY_LAST, // +100 221 [ 16 ] = KEY_LAST, /* +100 */
253 [ 13 ] = KEY_CLEAR, // reset 222 [ 13 ] = KEY_CLEAR, /* reset */
254 [ 12 ] = BTN_RIGHT, // fun++ 223 [ 12 ] = BTN_RIGHT, /* fun++ */
255 [ 4 ] = BTN_LEFT, // fun-- 224 [ 4 ] = BTN_LEFT, /* fun-- */
256 [ 14 ] = KEY_GOTO, // function 225 [ 14 ] = KEY_GOTO, /* function */
257 [ 15 ] = KEY_STOP, // freeze 226 [ 15 ] = KEY_STOP, /* freeze */
258}; 227};
259EXPORT_SYMBOL(ir_codes_pixelview); 228EXPORT_SYMBOL(ir_codes_pixelview);
260 229
@@ -321,10 +290,6 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
321 ir->keypressed = 1; 290 ir->keypressed = 1;
322 ir_input_key_event(dev,ir); 291 ir_input_key_event(dev,ir);
323 } 292 }
324#if 0
325 /* maybe do something like this ??? */
326 input_event(a, EV_IR, ir->ir_type, ir->ir_raw);
327#endif
328} 293}
329 294
330/* -------------------------------------------------------------------------- */ 295/* -------------------------------------------------------------------------- */
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 50e8b8654018..cd5828b5e9e3 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -62,13 +62,15 @@ void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data)
62int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop) 62int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop)
63{ 63{
64 unsigned long start; 64 unsigned long start;
65 int err;
65 66
66 /* wait for registers to be programmed */ 67 /* wait for registers to be programmed */
67 start = jiffies; 68 start = jiffies;
68 while (1) { 69 while (1) {
69 if (saa7146_read(dev, MC2) & 2) 70 err = time_after(jiffies, start + HZ/20);
70 break; 71 if (saa7146_read(dev, MC2) & 2)
71 if (time_after(jiffies, start + HZ/20)) { 72 break;
73 if (err) {
72 DEB_S(("timed out while waiting for registers getting programmed\n")); 74 DEB_S(("timed out while waiting for registers getting programmed\n"));
73 return -ETIMEDOUT; 75 return -ETIMEDOUT;
74 } 76 }
@@ -79,10 +81,11 @@ int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop)
79 /* wait for transfer to complete */ 81 /* wait for transfer to complete */
80 start = jiffies; 82 start = jiffies;
81 while (1) { 83 while (1) {
84 err = time_after(jiffies, start + HZ/4);
82 if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S)) 85 if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S))
83 break; 86 break;
84 saa7146_read(dev, MC2); 87 saa7146_read(dev, MC2);
85 if (time_after(jiffies, start + HZ/4)) { 88 if (err) {
86 DEB_S(("timed out while waiting for transfer completion\n")); 89 DEB_S(("timed out while waiting for transfer completion\n"));
87 return -ETIMEDOUT; 90 return -ETIMEDOUT;
88 } 91 }
@@ -512,7 +515,7 @@ int saa7146_register_extension(struct saa7146_extension* ext)
512 ext->driver.remove = saa7146_remove_one; 515 ext->driver.remove = saa7146_remove_one;
513 516
514 printk("saa7146: register extension '%s'.\n",ext->name); 517 printk("saa7146: register extension '%s'.\n",ext->name);
515 return pci_module_init(&ext->driver); 518 return pci_register_driver(&ext->driver);
516} 519}
517 520
518int saa7146_unregister_extension(struct saa7146_extension* ext) 521int saa7146_unregister_extension(struct saa7146_extension* ext)
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index 01387f883cdf..3f0ec6be03ae 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -40,6 +40,10 @@ comment "Supported BT878 Adapters"
40 depends on DVB_CORE && PCI 40 depends on DVB_CORE && PCI
41source "drivers/media/dvb/bt8xx/Kconfig" 41source "drivers/media/dvb/bt8xx/Kconfig"
42 42
43comment "Supported Pluto2 Adapters"
44 depends on DVB_CORE && PCI
45source "drivers/media/dvb/pluto2/Kconfig"
46
43comment "Supported DVB Frontends" 47comment "Supported DVB Frontends"
44 depends on DVB_CORE 48 depends on DVB_CORE
45source "drivers/media/dvb/frontends/Kconfig" 49source "drivers/media/dvb/frontends/Kconfig"
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile
index 3c6ff1619103..a7ad0841e6fc 100644
--- a/drivers/media/dvb/Makefile
+++ b/drivers/media/dvb/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the kernel multimedia device drivers. 2# Makefile for the kernel multimedia device drivers.
3# 3#
4 4
5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ cinergyT2/ dvb-usb/ 5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ cinergyT2/ dvb-usb/ pluto2/
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index fafd0ab3a28f..d7417eac2aba 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -35,17 +35,3 @@ config DVB_B2C2_FLEXCOP_DEBUG
35 help 35 help
36 Say Y if you want to enable the module option to control debug messages 36 Say Y if you want to enable the module option to control debug messages
37 of all B2C2 FlexCop drivers. 37 of all B2C2 FlexCop drivers.
38
39config DVB_B2C2_SKYSTAR
40 tristate "B2C2/Technisat Air/Sky/CableStar 2 PCI"
41 depends on DVB_CORE && PCI
42 select DVB_STV0299
43 select DVB_MT352
44 select DVB_MT312
45 select DVB_NXT2002
46 help
47 Support for the Skystar2 PCI DVB card by Technisat, which
48 is equipped with the FlexCopII chipset by B2C2, and
49 for the B2C2/BBTI Air2PC-ATSC card.
50
51 Say Y if you own such a device and want to use it.
diff --git a/drivers/media/dvb/b2c2/Makefile b/drivers/media/dvb/b2c2/Makefile
index 7703812af34f..1a1c3bca55fa 100644
--- a/drivers/media/dvb/b2c2/Makefile
+++ b/drivers/media/dvb/b2c2/Makefile
@@ -9,6 +9,4 @@ obj-$(CONFIG_DVB_B2C2_FLEXCOP_PCI) += b2c2-flexcop-pci.o
9b2c2-flexcop-usb-objs = flexcop-usb.o 9b2c2-flexcop-usb-objs = flexcop-usb.o
10obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o 10obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o
11 11
12obj-$(CONFIG_DVB_B2C2_SKYSTAR) += skystar2.o
13
14EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 12EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/b2c2/flexcop-common.h b/drivers/media/dvb/b2c2/flexcop-common.h
index 773d158032df..a94912ac1872 100644
--- a/drivers/media/dvb/b2c2/flexcop-common.h
+++ b/drivers/media/dvb/b2c2/flexcop-common.h
@@ -108,6 +108,8 @@ void flexcop_device_kfree(struct flexcop_device*);
108int flexcop_device_initialize(struct flexcop_device*); 108int flexcop_device_initialize(struct flexcop_device*);
109void flexcop_device_exit(struct flexcop_device *fc); 109void flexcop_device_exit(struct flexcop_device *fc);
110 110
111void flexcop_reset_block_300(struct flexcop_device *fc);
112
111/* from flexcop-dma.c */ 113/* from flexcop-dma.c */
112int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size); 114int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size);
113void flexcop_dma_free(struct flexcop_dma *dma); 115void flexcop_dma_free(struct flexcop_dma *dma);
@@ -115,7 +117,8 @@ void flexcop_dma_free(struct flexcop_dma *dma);
115int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff); 117int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
116int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff); 118int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
117int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff); 119int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff);
118int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx,flexcop_dma_addr_index_t index); 120int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx);
121int flexcop_dma_xfer_control(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, flexcop_dma_addr_index_t index, int onoff);
119int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles); 122int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles);
120int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets); 123int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets);
121 124
@@ -151,6 +154,7 @@ int flexcop_sram_init(struct flexcop_device *fc);
151/* from flexcop-misc.c */ 154/* from flexcop-misc.c */
152void flexcop_determine_revision(struct flexcop_device *fc); 155void flexcop_determine_revision(struct flexcop_device *fc);
153void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const char *suffix); 156void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const char *suffix);
157void flexcop_dump_reg(struct flexcop_device *fc, flexcop_ibi_register reg, int num);
154 158
155/* from flexcop-hw-filter.c */ 159/* from flexcop-hw-filter.c */
156int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff); 160int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff);
diff --git a/drivers/media/dvb/b2c2/flexcop-dma.c b/drivers/media/dvb/b2c2/flexcop-dma.c
index 8d2706075360..cf4ed1df6086 100644
--- a/drivers/media/dvb/b2c2/flexcop-dma.c
+++ b/drivers/media/dvb/b2c2/flexcop-dma.c
@@ -37,22 +37,90 @@ void flexcop_dma_free(struct flexcop_dma *dma)
37} 37}
38EXPORT_SYMBOL(flexcop_dma_free); 38EXPORT_SYMBOL(flexcop_dma_free);
39 39
40int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff) 40int flexcop_dma_config(struct flexcop_device *fc,
41 struct flexcop_dma *dma,
42 flexcop_dma_index_t dma_idx)
41{ 43{
42 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208); 44 flexcop_ibi_value v0x0,v0x4,v0xc;
45 v0x0.raw = v0x4.raw = v0xc.raw = 0;
43 46
44 if (no & FC_DMA_1) 47 v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
45 v.ctrl_208.DMA1_Timer_Enable_sig = onoff; 48 v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
49 v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
46 50
47 if (no & FC_DMA_2) 51 if ((dma_idx & FC_DMA_1) == dma_idx) {
48 v.ctrl_208.DMA2_Timer_Enable_sig = onoff; 52 fc->write_ibi_reg(fc,dma1_000,v0x0);
53 fc->write_ibi_reg(fc,dma1_004,v0x4);
54 fc->write_ibi_reg(fc,dma1_00c,v0xc);
55 } else if ((dma_idx & FC_DMA_2) == dma_idx) {
56 fc->write_ibi_reg(fc,dma2_010,v0x0);
57 fc->write_ibi_reg(fc,dma2_014,v0x4);
58 fc->write_ibi_reg(fc,dma2_01c,v0xc);
59 } else {
60 err("either DMA1 or DMA2 can be configured at the within one flexcop_dma_config call.");
61 return -EINVAL;
62 }
49 63
50 fc->write_ibi_reg(fc,ctrl_208,v);
51 return 0; 64 return 0;
52} 65}
53EXPORT_SYMBOL(flexcop_dma_control_timer_irq); 66EXPORT_SYMBOL(flexcop_dma_config);
67
68/* start the DMA transfers, but not the DMA IRQs */
69int flexcop_dma_xfer_control(struct flexcop_device *fc,
70 flexcop_dma_index_t dma_idx,
71 flexcop_dma_addr_index_t index,
72 int onoff)
73{
74 flexcop_ibi_value v0x0,v0xc;
75 flexcop_ibi_register r0x0,r0xc;
76
77 if ((dma_idx & FC_DMA_1) == dma_idx) {
78 r0x0 = dma1_000;
79 r0xc = dma1_00c;
80 } else if ((dma_idx & FC_DMA_2) == dma_idx) {
81 r0x0 = dma2_010;
82 r0xc = dma2_01c;
83 } else {
84 err("either transfer DMA1 or DMA2 can be started within one flexcop_dma_xfer_control call.");
85 return -EINVAL;
86 }
87
88 v0x0 = fc->read_ibi_reg(fc,r0x0);
89 v0xc = fc->read_ibi_reg(fc,r0xc);
90
91 deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
92 deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
93
94 if (index & FC_DMA_SUBADDR_0)
95 v0x0.dma_0x0.dma_0start = onoff;
96
97 if (index & FC_DMA_SUBADDR_1)
98 v0xc.dma_0xc.dma_1start = onoff;
99
100 fc->write_ibi_reg(fc,r0x0,v0x0);
101 fc->write_ibi_reg(fc,r0xc,v0xc);
102
103 deb_rdump("reg: %03x: %x\n",r0x0,v0x0.raw);
104 deb_rdump("reg: %03x: %x\n",r0xc,v0xc.raw);
105 return 0;
106}
107EXPORT_SYMBOL(flexcop_dma_xfer_control);
108
109static int flexcop_dma_remap(struct flexcop_device *fc,
110 flexcop_dma_index_t dma_idx,
111 int onoff)
112{
113 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
114 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
115 deb_info("%s\n",__FUNCTION__);
116 v.dma_0xc.remap_enable = onoff;
117 fc->write_ibi_reg(fc,r,v);
118 return 0;
119}
54 120
55int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff) 121int flexcop_dma_control_size_irq(struct flexcop_device *fc,
122 flexcop_dma_index_t no,
123 int onoff)
56{ 124{
57 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208); 125 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
58 126
@@ -67,75 +135,64 @@ int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t
67} 135}
68EXPORT_SYMBOL(flexcop_dma_control_size_irq); 136EXPORT_SYMBOL(flexcop_dma_control_size_irq);
69 137
70int flexcop_dma_control_packet_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff) 138int flexcop_dma_control_timer_irq(struct flexcop_device *fc,
139 flexcop_dma_index_t no,
140 int onoff)
71{ 141{
72 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208); 142 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
73 143
74 if (no & FC_DMA_1) 144 if (no & FC_DMA_1)
75 v.ctrl_208.DMA1_Size_IRQ_Enable_sig = onoff; 145 v.ctrl_208.DMA1_Timer_Enable_sig = onoff;
76 146
77 if (no & FC_DMA_2) 147 if (no & FC_DMA_2)
78 v.ctrl_208.DMA2_Size_IRQ_Enable_sig = onoff; 148 v.ctrl_208.DMA2_Timer_Enable_sig = onoff;
79 149
80 fc->write_ibi_reg(fc,ctrl_208,v); 150 fc->write_ibi_reg(fc,ctrl_208,v);
81 return 0; 151 return 0;
82} 152}
83EXPORT_SYMBOL(flexcop_dma_control_packet_irq); 153EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
84 154
85int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx,flexcop_dma_addr_index_t index) 155/* 1 cycles = 1.97 msec */
156int flexcop_dma_config_timer(struct flexcop_device *fc,
157 flexcop_dma_index_t dma_idx,
158 u8 cycles)
86{ 159{
160 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
161 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
87 162
88 flexcop_ibi_value v0x0,v0x4,v0xc; 163 flexcop_dma_remap(fc,dma_idx,0);
89 v0x0.raw = v0x4.raw = v0xc.raw = 0;
90
91 v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
92 v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
93 v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
94
95 if (index & FC_DMA_SUBADDR_0)
96 v0x0.dma_0x0.dma_0start = 1;
97
98 if (index & FC_DMA_SUBADDR_1)
99 v0xc.dma_0xc.dma_1start = 1;
100
101 if (dma_idx & FC_DMA_1) {
102 fc->write_ibi_reg(fc,dma1_000,v0x0);
103 fc->write_ibi_reg(fc,dma1_004,v0x4);
104 fc->write_ibi_reg(fc,dma1_00c,v0xc);
105 } else { /* (dma_idx & FC_DMA_2) */
106 fc->write_ibi_reg(fc,dma2_010,v0x0);
107 fc->write_ibi_reg(fc,dma2_014,v0x4);
108 fc->write_ibi_reg(fc,dma2_01c,v0xc);
109 }
110
111 return 0;
112}
113EXPORT_SYMBOL(flexcop_dma_config);
114 164
115static int flexcop_dma_remap(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, int onoff) 165 deb_info("%s\n",__FUNCTION__);
116{ 166 v.dma_0x4_write.dmatimer = cycles;
117 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
118 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
119 v.dma_0xc.remap_enable = onoff;
120 fc->write_ibi_reg(fc,r,v); 167 fc->write_ibi_reg(fc,r,v);
121 return 0; 168 return 0;
122} 169}
170EXPORT_SYMBOL(flexcop_dma_config_timer);
123 171
124/* 1 cycles = 1.97 msec */ 172/* packet IRQ does not exist in FCII or FCIIb - according to data book and tests */
125int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles) 173int flexcop_dma_control_packet_irq(struct flexcop_device *fc,
174 flexcop_dma_index_t no,
175 int onoff)
126{ 176{
127 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014; 177 flexcop_ibi_value v = fc->read_ibi_reg(fc,ctrl_208);
128 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
129 178
130 flexcop_dma_remap(fc,dma_idx,0); 179 deb_rdump("reg: %03x: %x\n",ctrl_208,v.raw);
180 if (no & FC_DMA_1)
181 v.ctrl_208.DMA1_Size_IRQ_Enable_sig = onoff;
182
183 if (no & FC_DMA_2)
184 v.ctrl_208.DMA2_Size_IRQ_Enable_sig = onoff;
185
186 fc->write_ibi_reg(fc,ctrl_208,v);
187 deb_rdump("reg: %03x: %x\n",ctrl_208,v.raw);
131 188
132 v.dma_0x4_write.dmatimer = cycles >> 1;
133 fc->write_ibi_reg(fc,r,v);
134 return 0; 189 return 0;
135} 190}
136EXPORT_SYMBOL(flexcop_dma_config_timer); 191EXPORT_SYMBOL(flexcop_dma_control_packet_irq);
137 192
138int flexcop_dma_config_packet_count(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 packets) 193int flexcop_dma_config_packet_count(struct flexcop_device *fc,
194 flexcop_dma_index_t dma_idx,
195 u8 packets)
139{ 196{
140 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014; 197 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
141 flexcop_ibi_value v = fc->read_ibi_reg(fc,r); 198 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
diff --git a/drivers/media/dvb/b2c2/flexcop-hw-filter.c b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
index 2baf43d3ce8f..75cf237196eb 100644
--- a/drivers/media/dvb/b2c2/flexcop-hw-filter.c
+++ b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
@@ -10,6 +10,8 @@
10static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff) 10static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff)
11{ 11{
12 flexcop_set_ibi_value(ctrl_208,Rcv_Data_sig,onoff); 12 flexcop_set_ibi_value(ctrl_208,Rcv_Data_sig,onoff);
13
14 deb_ts("rcv_data is now: '%s'\n",onoff ? "on" : "off");
13} 15}
14 16
15void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff) 17void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff)
@@ -151,7 +153,7 @@ int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *d
151{ 153{
152 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32; 154 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32;
153 155
154 fc->feedcount += onoff ? 1 : -1; 156 fc->feedcount += onoff ? 1 : -1; /* the number of PIDs/Feed currently requested */
155 if (dvbdmxfeed->index >= max_pid_filter) 157 if (dvbdmxfeed->index >= max_pid_filter)
156 fc->extra_feedcount += onoff ? 1 : -1; 158 fc->extra_feedcount += onoff ? 1 : -1;
157 159
@@ -178,8 +180,14 @@ int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *d
178 /* if it was the first or last feed request change the stream-status */ 180 /* if it was the first or last feed request change the stream-status */
179 if (fc->feedcount == onoff) { 181 if (fc->feedcount == onoff) {
180 flexcop_rcv_data_ctrl(fc,onoff); 182 flexcop_rcv_data_ctrl(fc,onoff);
181 if (fc->stream_control) 183 if (fc->stream_control) /* device specific stream control */
182 fc->stream_control(fc,onoff); 184 fc->stream_control(fc,onoff);
185
186 /* feeding stopped -> reset the flexcop filter*/
187 if (onoff == 0) {
188 flexcop_reset_block_300(fc);
189 flexcop_hw_filter_init(fc);
190 }
183 } 191 }
184 192
185 return 0; 193 return 0;
diff --git a/drivers/media/dvb/b2c2/flexcop-misc.c b/drivers/media/dvb/b2c2/flexcop-misc.c
index 23082545651f..3a08d38b318a 100644
--- a/drivers/media/dvb/b2c2/flexcop-misc.c
+++ b/drivers/media/dvb/b2c2/flexcop-misc.c
@@ -65,3 +65,15 @@ void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const
65 flexcop_device_names[fc->dev_type],flexcop_bus_names[fc->bus_type], 65 flexcop_device_names[fc->dev_type],flexcop_bus_names[fc->bus_type],
66 flexcop_revision_names[fc->rev],suffix); 66 flexcop_revision_names[fc->rev],suffix);
67} 67}
68
69void flexcop_dump_reg(struct flexcop_device *fc, flexcop_ibi_register reg, int num)
70{
71 flexcop_ibi_value v;
72 int i;
73 for (i = 0; i < num; i++) {
74 v = fc->read_ibi_reg(fc,reg+4*i);
75 deb_rdump("0x%03x: %08x, ",reg+4*i, v.raw);
76 }
77 deb_rdump("\n");
78}
79EXPORT_SYMBOL(flexcop_dump_reg);
diff --git a/drivers/media/dvb/b2c2/flexcop-pci.c b/drivers/media/dvb/b2c2/flexcop-pci.c
index ed717c0073d5..2f76eb3fea40 100644
--- a/drivers/media/dvb/b2c2/flexcop-pci.c
+++ b/drivers/media/dvb/b2c2/flexcop-pci.c
@@ -13,6 +13,10 @@ static int enable_pid_filtering = 1;
13module_param(enable_pid_filtering, int, 0444); 13module_param(enable_pid_filtering, int, 0444);
14MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported values: 0 (fullts), 1"); 14MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported values: 0 (fullts), 1");
15 15
16static int irq_chk_intv;
17module_param(irq_chk_intv, int, 0644);
18MODULE_PARM_DESC(irq_chk_intv, "set the interval for IRQ watchdog (currently just debugging).");
19
16#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG 20#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
17#define dprintk(level,args...) \ 21#define dprintk(level,args...) \
18 do { if ((debug & level)) printk(args); } while (0) 22 do { if ((debug & level)) printk(args); } while (0)
@@ -26,6 +30,7 @@ MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported
26#define deb_reg(args...) dprintk(0x02,args) 30#define deb_reg(args...) dprintk(0x02,args)
27#define deb_ts(args...) dprintk(0x04,args) 31#define deb_ts(args...) dprintk(0x04,args)
28#define deb_irq(args...) dprintk(0x08,args) 32#define deb_irq(args...) dprintk(0x08,args)
33#define deb_chk(args...) dprintk(0x10,args)
29 34
30static int debug = 0; 35static int debug = 0;
31module_param(debug, int, 0644); 36module_param(debug, int, 0644);
@@ -56,6 +61,10 @@ struct flexcop_pci {
56 61
57 spinlock_t irq_lock; 62 spinlock_t irq_lock;
58 63
64 unsigned long last_irq;
65
66 struct work_struct irq_check_work;
67
59 struct flexcop_device *fc_dev; 68 struct flexcop_device *fc_dev;
60}; 69};
61 70
@@ -88,18 +97,55 @@ static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_regi
88 return 0; 97 return 0;
89} 98}
90 99
100static void flexcop_pci_irq_check_work(void *data)
101{
102 struct flexcop_pci *fc_pci = data;
103 struct flexcop_device *fc = fc_pci->fc_dev;
104
105 flexcop_ibi_value v = fc->read_ibi_reg(fc,sram_dest_reg_714);
106
107 flexcop_dump_reg(fc_pci->fc_dev,dma1_000,4);
108
109 if (v.sram_dest_reg_714.net_ovflow_error)
110 deb_chk("sram net_ovflow_error\n");
111 if (v.sram_dest_reg_714.media_ovflow_error)
112 deb_chk("sram media_ovflow_error\n");
113 if (v.sram_dest_reg_714.cai_ovflow_error)
114 deb_chk("sram cai_ovflow_error\n");
115 if (v.sram_dest_reg_714.cai_ovflow_error)
116 deb_chk("sram cai_ovflow_error\n");
117
118 schedule_delayed_work(&fc_pci->irq_check_work,
119 msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv));
120}
121
91/* When PID filtering is turned on, we use the timer IRQ, because small amounts 122/* When PID filtering is turned on, we use the timer IRQ, because small amounts
92 * of data need to be passed to the user space instantly as well. When PID 123 * of data need to be passed to the user space instantly as well. When PID
93 * filtering is turned off, we use the page-change-IRQ */ 124 * filtering is turned off, we use the page-change-IRQ */
94static irqreturn_t flexcop_pci_irq(int irq, void *dev_id, struct pt_regs *regs) 125static irqreturn_t flexcop_pci_isr(int irq, void *dev_id, struct pt_regs *regs)
95{ 126{
96 struct flexcop_pci *fc_pci = dev_id; 127 struct flexcop_pci *fc_pci = dev_id;
97 struct flexcop_device *fc = fc_pci->fc_dev; 128 struct flexcop_device *fc = fc_pci->fc_dev;
98 flexcop_ibi_value v = fc->read_ibi_reg(fc,irq_20c); 129 flexcop_ibi_value v;
99 irqreturn_t ret = IRQ_HANDLED; 130 irqreturn_t ret = IRQ_HANDLED;
100 131
101 spin_lock_irq(&fc_pci->irq_lock); 132 spin_lock_irq(&fc_pci->irq_lock);
102 133
134 v = fc->read_ibi_reg(fc,irq_20c);
135
136 /* errors */
137 if (v.irq_20c.Data_receiver_error)
138 deb_chk("data receiver error\n");
139 if (v.irq_20c.Continuity_error_flag)
140 deb_chk("Contunuity error flag is set\n");
141 if (v.irq_20c.LLC_SNAP_FLAG_set)
142 deb_chk("LLC_SNAP_FLAG_set is set\n");
143 if (v.irq_20c.Transport_Error)
144 deb_chk("Transport error\n");
145
146 if ((fc_pci->count % 1000) == 0)
147 deb_chk("%d valid irq took place so far\n",fc_pci->count);
148
103 if (v.irq_20c.DMA1_IRQ_Status == 1) { 149 if (v.irq_20c.DMA1_IRQ_Status == 1) {
104 if (fc_pci->active_dma1_addr == 0) 150 if (fc_pci->active_dma1_addr == 0)
105 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr0,fc_pci->dma[0].size / 188); 151 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr0,fc_pci->dma[0].size / 188);
@@ -115,8 +161,9 @@ static irqreturn_t flexcop_pci_irq(int irq, void *dev_id, struct pt_regs *regs)
115 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2; 161 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2;
116 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0; 162 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0;
117 163
118 deb_irq("irq: %08x cur_addr: %08x: cur_pos: %08x, last_cur_pos: %08x ", 164 deb_irq("%u irq: %08x cur_addr: %08x: cur_pos: %08x, last_cur_pos: %08x ",
119 v.raw,cur_addr,cur_pos,fc_pci->last_dma1_cur_pos); 165 jiffies_to_usecs(jiffies - fc_pci->last_irq),v.raw,cur_addr,cur_pos,fc_pci->last_dma1_cur_pos);
166 fc_pci->last_irq = jiffies;
120 167
121 /* buffer end was reached, restarted from the beginning 168 /* buffer end was reached, restarted from the beginning
122 * pass the data from last_cur_pos to the buffer end to the demux 169 * pass the data from last_cur_pos to the buffer end to the demux
@@ -127,7 +174,6 @@ static irqreturn_t flexcop_pci_irq(int irq, void *dev_id, struct pt_regs *regs)
127 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos, 174 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos,
128 (fc_pci->dma[0].size*2) - fc_pci->last_dma1_cur_pos); 175 (fc_pci->dma[0].size*2) - fc_pci->last_dma1_cur_pos);
129 fc_pci->last_dma1_cur_pos = 0; 176 fc_pci->last_dma1_cur_pos = 0;
130 fc_pci->count = 0;
131 } 177 }
132 178
133 if (cur_pos > fc_pci->last_dma1_cur_pos) { 179 if (cur_pos > fc_pci->last_dma1_cur_pos) {
@@ -139,16 +185,14 @@ static irqreturn_t flexcop_pci_irq(int irq, void *dev_id, struct pt_regs *regs)
139 deb_irq("\n"); 185 deb_irq("\n");
140 186
141 fc_pci->last_dma1_cur_pos = cur_pos; 187 fc_pci->last_dma1_cur_pos = cur_pos;
142 } else 188 fc_pci->count++;
189 } else {
190 deb_irq("isr for flexcop called, apparently without reason (%08x)\n",v.raw);
143 ret = IRQ_NONE; 191 ret = IRQ_NONE;
192 }
144 193
145 spin_unlock_irq(&fc_pci->irq_lock); 194 spin_unlock_irq(&fc_pci->irq_lock);
146 195
147/* packet count would be ideal for hw filtering, but it isn't working. Either
148 * the data book is wrong, or I'm unable to read it correctly */
149
150/* if (v.irq_20c.DMA1_Size_IRQ_Status == 1) { packet counter */
151
152 return ret; 196 return ret;
153} 197}
154 198
@@ -156,30 +200,35 @@ static int flexcop_pci_stream_control(struct flexcop_device *fc, int onoff)
156{ 200{
157 struct flexcop_pci *fc_pci = fc->bus_specific; 201 struct flexcop_pci *fc_pci = fc->bus_specific;
158 if (onoff) { 202 if (onoff) {
159 flexcop_dma_config(fc,&fc_pci->dma[0],FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1); 203 flexcop_dma_config(fc,&fc_pci->dma[0],FC_DMA_1);
160 flexcop_dma_config(fc,&fc_pci->dma[1],FC_DMA_2,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1); 204 flexcop_dma_config(fc,&fc_pci->dma[1],FC_DMA_2);
161 flexcop_dma_config_timer(fc,FC_DMA_1,1);
162 205
163 if (fc_pci->fc_dev->pid_filtering) { 206 flexcop_dma_config_timer(fc,FC_DMA_1,0);
164 fc_pci->last_dma1_cur_pos = 0;
165 flexcop_dma_control_timer_irq(fc,FC_DMA_1,1);
166 } else {
167 fc_pci->active_dma1_addr = 0;
168 flexcop_dma_control_size_irq(fc,FC_DMA_1,1);
169 }
170 207
171/* flexcop_dma_config_packet_count(fc,FC_DMA_1,0xc0); 208 flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,1);
172 flexcop_dma_control_packet_irq(fc,FC_DMA_1,1); */ 209 deb_irq("DMA xfer enabled\n");
173 210
174 deb_irq("irqs enabled\n"); 211 fc_pci->last_dma1_cur_pos = 0;
212 flexcop_dma_control_timer_irq(fc,FC_DMA_1,1);
213 deb_irq("IRQ enabled\n");
214
215// fc_pci->active_dma1_addr = 0;
216// flexcop_dma_control_size_irq(fc,FC_DMA_1,1);
217
218 if (irq_chk_intv > 0)
219 schedule_delayed_work(&fc_pci->irq_check_work,
220 msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv));
175 } else { 221 } else {
176 if (fc_pci->fc_dev->pid_filtering) 222 if (irq_chk_intv > 0)
177 flexcop_dma_control_timer_irq(fc,FC_DMA_1,0); 223 cancel_delayed_work(&fc_pci->irq_check_work);
178 else 224
179 flexcop_dma_control_size_irq(fc,FC_DMA_1,0); 225 flexcop_dma_control_timer_irq(fc,FC_DMA_1,0);
226 deb_irq("IRQ disabled\n");
180 227
181// flexcop_dma_control_packet_irq(fc,FC_DMA_1,0); 228// flexcop_dma_control_size_irq(fc,FC_DMA_1,0);
182 deb_irq("irqs disabled\n"); 229
230 flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,0);
231 deb_irq("DMA xfer disabled\n");
183 } 232 }
184 233
185 return 0; 234 return 0;
@@ -198,6 +247,7 @@ static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci)
198 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2); 247 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2);
199 248
200 fc_pci->init_state |= FC_PCI_DMA_INIT; 249 fc_pci->init_state |= FC_PCI_DMA_INIT;
250
201 goto success; 251 goto success;
202dma1_free: 252dma1_free:
203 flexcop_dma_free(&fc_pci->dma[0]); 253 flexcop_dma_free(&fc_pci->dma[0]);
@@ -244,7 +294,7 @@ static int flexcop_pci_init(struct flexcop_pci *fc_pci)
244 294
245 pci_set_drvdata(fc_pci->pdev, fc_pci); 295 pci_set_drvdata(fc_pci->pdev, fc_pci);
246 296
247 if ((ret = request_irq(fc_pci->pdev->irq, flexcop_pci_irq, 297 if ((ret = request_irq(fc_pci->pdev->irq, flexcop_pci_isr,
248 SA_SHIRQ, DRIVER_NAME, fc_pci)) != 0) 298 SA_SHIRQ, DRIVER_NAME, fc_pci)) != 0)
249 goto err_pci_iounmap; 299 goto err_pci_iounmap;
250 300
@@ -324,6 +374,8 @@ static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
324 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0) 374 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0)
325 goto err_fc_exit; 375 goto err_fc_exit;
326 376
377 INIT_WORK(&fc_pci->irq_check_work, flexcop_pci_irq_check_work, fc_pci);
378
327 goto success; 379 goto success;
328err_fc_exit: 380err_fc_exit:
329 flexcop_device_exit(fc); 381 flexcop_device_exit(fc);
@@ -350,17 +402,17 @@ static void flexcop_pci_remove(struct pci_dev *pdev)
350 402
351static struct pci_device_id flexcop_pci_tbl[] = { 403static struct pci_device_id flexcop_pci_tbl[] = {
352 { PCI_DEVICE(0x13d0, 0x2103) }, 404 { PCI_DEVICE(0x13d0, 0x2103) },
353/* { PCI_DEVICE(0x13d0, 0x2200) }, PCI FlexCopIII ? */ 405/* { PCI_DEVICE(0x13d0, 0x2200) }, ? */
354 { }, 406 { },
355}; 407};
356 408
357MODULE_DEVICE_TABLE(pci, flexcop_pci_tbl); 409MODULE_DEVICE_TABLE(pci, flexcop_pci_tbl);
358 410
359static struct pci_driver flexcop_pci_driver = { 411static struct pci_driver flexcop_pci_driver = {
360 .name = "Technisat/B2C2 FlexCop II/IIb/III PCI", 412 .name = "b2c2_flexcop_pci",
361 .id_table = flexcop_pci_tbl, 413 .id_table = flexcop_pci_tbl,
362 .probe = flexcop_pci_probe, 414 .probe = flexcop_pci_probe,
363 .remove = flexcop_pci_remove, 415 .remove = flexcop_pci_remove,
364}; 416};
365 417
366static int __init flexcop_pci_module_init(void) 418static int __init flexcop_pci_module_init(void)
diff --git a/drivers/media/dvb/b2c2/flexcop-reg.h b/drivers/media/dvb/b2c2/flexcop-reg.h
index 75b50f21afe6..4ae1eb5bfe98 100644
--- a/drivers/media/dvb/b2c2/flexcop-reg.h
+++ b/drivers/media/dvb/b2c2/flexcop-reg.h
@@ -36,555 +36,21 @@ typedef enum {
36extern const char *flexcop_device_names[]; 36extern const char *flexcop_device_names[];
37 37
38/* FlexCop IBI Registers */ 38/* FlexCop IBI Registers */
39#if defined(__LITTLE_ENDIAN)
40 #include "flexcop_ibi_value_le.h"
41#elif defined(__BIG_ENDIAN)
42 #include "flexcop_ibi_value_be.h"
43#else
44 #error no endian defined
45#endif
39 46
40/* flexcop_ibi_reg - a huge union representing the register structure */
41typedef union {
42 u32 raw;
43
44/* DMA 0x000 to 0x01c
45 * DMA1 0x000 to 0x00c
46 * DMA2 0x010 to 0x01c
47 */
48 struct {
49 u32 dma_0start : 1; /* set: data will be delivered to dma1_address0 */
50 u32 dma_0No_update : 1; /* set: dma1_cur_address will be updated, unset: no update */
51 u32 dma_address0 :30; /* physical/virtual host memory address0 DMA */
52 } dma_0x0;
53
54 struct {
55 u32 DMA_maxpackets : 8; /* (remapped) PCI DMA1 Packet Count Interrupt. This variable
56 is able to be read and written while bit(1) of register
57 0x00c (remap_enable) is set. This variable represents
58 the number of packets that will be transmitted to the PCI
59 host using PCI DMA1 before an interrupt to the PCI is
60 asserted. This functionality may be enabled using bit(20)
61 of register 0x208. N=0 disables the IRQ. */
62 u32 dma_addr_size :24; /* size of memory buffer in DWORDs (bytesize / 4) for DMA */
63 } dma_0x4_remap;
64
65 struct {
66 u32 dma1timer : 7; /* reading PCI DMA1 timer ... when remap_enable is 0 */
67 u32 unused : 1;
68 u32 dma_addr_size :24;
69 } dma_0x4_read;
70
71 struct {
72 u32 unused : 1;
73 u32 dmatimer : 7; /* writing PCI DMA1 timer ... when remap_enable is 0 */
74 u32 dma_addr_size :24;
75 } dma_0x4_write;
76
77 struct {
78 u32 unused : 2;
79 u32 dma_cur_addr :30; /* current physical host memory address pointer for DMA */
80 } dma_0x8;
81
82 struct {
83 u32 dma_1start : 1; /* set: data will be delivered to dma_address1, when dma_address0 is full */
84 u32 remap_enable : 1; /* remap enable for 0x0x4(7:0) */
85 u32 dma_address1 :30; /* Physical/virtual address 1 on DMA */
86 } dma_0xc;
87
88/* Two-wire Serial Master and Clock 0x100-0x110 */
89 struct {
90// u32 slave_transmitter : 1; /* ???*/
91 u32 chipaddr : 7; /* two-line serial address of the target slave */
92 u32 reserved1 : 1;
93 u32 baseaddr : 8; /* address of the location of the read/write operation */
94 u32 data1_reg : 8; /* first byte in two-line serial read/write operation */
95 u32 working_start : 1; /* when doing a write operation this indicator is 0 when ready
96 * set to 1 when doing a write operation */
97 u32 twoWS_rw : 1; /* read/write indicator (1 = read, 0 write) */
98 u32 total_bytes : 2; /* number of data bytes in each two-line serial transaction (0 = 1 byte, 11 = 4byte)*/
99 u32 twoWS_port_reg : 2; /* port selection: 01 - Front End/Demod, 10 - EEPROM, 11 - Tuner */
100 u32 no_base_addr_ack_error : 1; /* writing: write-req: frame is produced w/o baseaddr, read-req: read-cycles w/o
101 * preceding address assignment write frame
102 * ACK_ERROR = 1 when no ACK from slave in the last transaction */
103 u32 st_done : 1; /* indicator for transaction is done */
104 } tw_sm_c_100;
105
106 struct {
107 u32 data2_reg : 8; /* 2nd data byte */
108 u32 data3_reg : 8; /* 3rd data byte */
109 u32 data4_reg : 8; /* 4th data byte */
110 u32 exlicit_stops : 1; /* when set, transactions are produced w/o trailing STOP flag, then send isolated STOP flags */
111 u32 force_stop : 1; /* isolated stop flag */
112 u32 unused : 6;
113 } tw_sm_c_104;
114
115/* Clock. The register allows the FCIII to convert an incoming Master clock
116 * (MCLK) signal into a lower frequency clock through the use of a LowCounter
117 * (TLO) and a High- Counter (THI). The time counts for THI and TLO are
118 * measured in MCLK; each count represents 4 MCLK input clock cycles.
119 *
120 * The default output for port #1 is set for Front End Demod communication. (0x108)
121 * The default output for port #2 is set for EEPROM communication. (0x10c)
122 * The default output for port #3 is set for Tuner communication. (0x110)
123 */
124 struct {
125 u32 thi1 : 6; /* Thi for port #1 (def: 100110b; 38) */
126 u32 reserved1 : 2;
127 u32 tlo1 : 5; /* Tlo for port #1 (def: 11100b; 28) */
128 u32 reserved2 :19;
129 } tw_sm_c_108;
130
131 struct {
132 u32 thi1 : 6; /* Thi for port #2 (def: 111001b; 57) */
133 u32 reserved1 : 2;
134 u32 tlo1 : 5; /* Tlo for port #2 (def: 11100b; 28) */
135 u32 reserved2 :19;
136 } tw_sm_c_10c;
137
138 struct {
139 u32 thi1 : 6; /* Thi for port #3 (def: 111001b; 57) */
140 u32 reserved1 : 2;
141 u32 tlo1 : 5; /* Tlo for port #3 (def: 11100b; 28) */
142 u32 reserved2 :19;
143 } tw_sm_c_110;
144
145/* LNB Switch Frequency 0x200
146 * Clock that creates the LNB switch tone. The default is set to have a fixed
147 * low output (not oscillating) to the LNB_CTL line.
148 */
149 struct {
150 u32 LNB_CTLHighCount_sig :15; /* It is the number of pre-scaled clock cycles that will be low. */
151 u32 LNB_CTLLowCount_sig :15; /* For example, to obtain a 22KHz output given a 45 Mhz Master
152 Clock signal (MCLK), set PreScalar=01 and LowCounter value to 0x1ff. */
153 u32 LNB_CTLPrescaler_sig : 2; /* pre-scaler divides MCLK: 00 (no division), 01 by 2, 10 by 4, 11 by 12 */
154 } lnb_switch_freq_200;
155
156/* ACPI, Peripheral Reset, LNB Polarity
157 * ACPI power conservation mode, LNB polarity selection (low or high voltage),
158 * and peripheral reset.
159 */
160 struct {
161 u32 ACPI1_sig : 1; /* turn of the power of tuner and LNB, not implemented in FCIII */
162 u32 ACPI3_sig : 1; /* turn of power of the complete satelite receiver board (except FCIII) */
163 u32 LNB_L_H_sig : 1; /* low or high voltage for LNB. (0 = low, 1 = high) */
164 u32 Per_reset_sig : 1; /* misc. init reset (default: 1), to reset set to low and back to high */
165 u32 reserved :20;
166 u32 Rev_N_sig_revision_hi : 4;/* 0xc in case of FCIII */
167 u32 Rev_N_sig_reserved1 : 2;
168 u32 Rev_N_sig_caps : 1; /* if 1, FCIII has 32 PID- and MAC-filters and is capable of IP multicast */
169 u32 Rev_N_sig_reserved2 : 1;
170 } misc_204;
171
172/* Control and Status 0x208 to 0x21c */
173/* Gross enable and disable control */
174 struct {
175 u32 Stream1_filter_sig : 1; /* Stream1 PID filtering */
176 u32 Stream2_filter_sig : 1; /* Stream2 PID filtering */
177 u32 PCR_filter_sig : 1; /* PCR PID filter */
178 u32 PMT_filter_sig : 1; /* PMT PID filter */
179
180 u32 EMM_filter_sig : 1; /* EMM PID filter */
181 u32 ECM_filter_sig : 1; /* ECM PID filter */
182 u32 Null_filter_sig : 1; /* Filters null packets, PID=0x1fff. */
183 u32 Mask_filter_sig : 1; /* mask PID filter */
184
185 u32 WAN_Enable_sig : 1; /* WAN output line through V8 memory space is activated. */
186 u32 WAN_CA_Enable_sig : 1; /* not in FCIII */
187 u32 CA_Enable_sig : 1; /* not in FCIII */
188 u32 SMC_Enable_sig : 1; /* CI stream data (CAI) goes directly to the smart card intf (opposed IBI 0x600 or SC-cmd buf). */
189
190 u32 Per_CA_Enable_sig : 1; /* not in FCIII */
191 u32 Multi2_Enable_sig : 1; /* ? */
192 u32 MAC_filter_Mode_sig : 1; /* (MAC_filter_enable) Globally enables MAC filters for Net PID filteres. */
193 u32 Rcv_Data_sig : 1; /* PID filtering module enable. When this bit is a one, the PID filter will
194 examine and process packets according to all other (individual) PID
195 filtering controls. If it a zero, no packet processing of any kind will
196 take place. All data from the tuner will be thrown away. */
197
198 u32 DMA1_IRQ_Enable_sig : 1; /* When set, a DWORD counter is enabled on PCI DMA1 that asserts the PCI
199 * interrupt after the specified count for filling the buffer. */
200 u32 DMA1_Timer_Enable_sig : 1; /* When set, a timer is enabled on PCI DMA1 that asserts the PCI interrupt
201 after a specified amount of time. */
202 u32 DMA2_IRQ_Enable_sig : 1; /* same as DMA1_IRQ_Enable_sig but for DMA2 */
203 u32 DMA2_Timer_Enable_sig : 1; /* same as DMA1_Timer_Enable_sig but for DMA2 */
204
205 u32 DMA1_Size_IRQ_Enable_sig : 1; /* When set, a packet count detector is enabled on PCI DMA1 that asserts the PCI interrupt. */
206 u32 DMA2_Size_IRQ_Enable_sig : 1; /* When set, a packet count detector is enabled on PCI DMA2 that asserts the PCI interrupt. */
207 u32 Mailbox_from_V8_Enable_sig: 1; /* When set, writes to the mailbox register produce an interrupt to the
208 PCI host to indicate that mailbox data is available. */
209
210 u32 unused : 9;
211 } ctrl_208;
212
213/* General status. When a PCI interrupt occurs, this register is read to
214 * discover the reason for the interrupt.
215 */
216 struct {
217 u32 DMA1_IRQ_Status : 1; /* When set(1) the DMA1 counter had generated an IRQ. Read Only. */
218 u32 DMA1_Timer_Status : 1; /* When set(1) the DMA1 timer had generated an IRQ. Read Only. */
219 u32 DMA2_IRQ_Status : 1; /* When set(1) the DMA2 counter had generated an IRQ. Read Only. */
220 u32 DMA2_Timer_Status : 1; /* When set(1) the DMA2 timer had generated an IRQ. Read Only. */
221 u32 DMA1_Size_IRQ_Status : 1; /* (Read only). This register is read after an interrupt to */
222 u32 DMA2_Size_IRQ_Status : 1; /* find out why we had an IRQ. Reading this register will clear this bit. Packet count*/
223 u32 Mailbox_from_V8_Status_sig: 1; /* Same as above. Reading this register will clear this bit. */
224 u32 Data_receiver_error : 1; /* 1 indicate an error in the receiver Front End (Tuner module) */
225 u32 Continuity_error_flag : 1; /* 1 indicates a continuity error in the TS stream. */
226 u32 LLC_SNAP_FLAG_set : 1; /* 1 indicates that the LCC_SNAP_FLAG was set. */
227 u32 Transport_Error : 1; /* When set indicates that an unexpected packet was received. */
228 u32 reserved :21;
229 } irq_20c;
230
231
232/* Software reset register */
233 struct {
234 u32 reset_blocks : 8; /* Enabled when Block_reset_enable = 0xB2 and 0x208 bits 15:8 = 0x00.
235 Each bit location represents a 0x100 block of registers. Writing
236 a one in a bit location resets that block of registers and the logic
237 that it controls. */
238 u32 Block_reset_enable : 8; /* This variable is set to 0xB2 when the register is written. */
239 u32 Special_controls :16; /* Asserts Reset_V8 => 0xC258; Turns on pci encryption => 0xC25A;
240 Turns off pci encryption => 0xC259 Note: pci_encryption default
241 at power-up is ON. */
242 } sw_reset_210;
243
244 struct {
245 u32 vuart_oe_sig : 1; /* When clear, the V8 processor has sole control of the serial UART
246 (RS-232 Smart Card interface). When set, the IBI interface
247 defined by register 0x600 controls the serial UART. */
248 u32 v2WS_oe_sig : 1; /* When clear, the V8 processor has direct control of the Two-line
249 Serial Master EEPROM target. When set, the Two-line Serial Master
250 EEPROM target interface is controlled by IBI register 0x100. */
251 u32 halt_V8_sig : 1; /* When set, contiguous wait states are applied to the V8-space
252 bus masters. Once this signal is cleared, normal V8-space
253 operations resume. */
254 u32 section_pkg_enable_sig: 1; /* When set, this signal enables the front end translation circuitry
255 to process section packed transport streams. */
256 u32 s2p_sel_sig : 1; /* Serial to parallel conversion. When set, polarized transport data
257 within the FlexCop3 front end circuitry is converted from a serial
258 stream into parallel data before downstream processing otherwise
259 interprets the data. */
260 u32 unused1 : 3;
261 u32 polarity_PS_CLK_sig: 1; /* This signal is used to invert the input polarity of the tranport
262 stream CLOCK signal before any processing occurs on the transport
263 stream within FlexCop3. */
264 u32 polarity_PS_VALID_sig: 1; /* This signal is used to invert the input polarity of the tranport
265 stream VALID signal before any processing occurs on the transport
266 stream within FlexCop3. */
267 u32 polarity_PS_SYNC_sig: 1; /* This signal is used to invert the input polarity of the tranport
268 stream SYNC signal before any processing occurs on the transport
269 stream within FlexCop3. */
270 u32 polarity_PS_ERR_sig: 1; /* This signal is used to invert the input polarity of the tranport
271 stream ERROR signal before any processing occurs on the transport
272 stream within FlexCop3. */
273 u32 unused2 :20;
274 } misc_214;
275
276/* Mailbox from V8 to host */
277 struct {
278 u32 Mailbox_from_V8 :32; /* When this register is written by either the V8 processor or by an
279 end host, an interrupt is generated to the PCI host to indicate
280 that mailbox data is available. Reading register 20c will clear
281 the IRQ. */
282 } mbox_v8_to_host_218;
283
284/* Mailbox from host to v8 Mailbox_to_V8
285 * Mailbox_to_V8 mailbox storage register
286 * used to send messages from PCI to V8. Writing to this register will send an
287 * IRQ to the V8. Then it can read the data from here. Reading this register
288 * will clear the IRQ. If the V8 is halted and bit 31 of this register is set,
289 * then this register is used instead as a direct interface to access the
290 * V8space memory.
291 */
292 struct {
293 u32 sysramaccess_data : 8; /* Data byte written or read from the specified address in V8 SysRAM. */
294 u32 sysramaccess_addr :15; /* 15 bit address used to access V8 Sys-RAM. */
295 u32 unused : 7;
296 u32 sysramaccess_write: 1; /* Write flag used to latch data into the V8 SysRAM. */
297 u32 sysramaccess_busmuster: 1; /* Setting this bit when the V8 is halted at 0x214 Bit(2) allows
298 this IBI register interface to directly drive the V8-space memory. */
299 } mbox_host_to_v8_21c;
300
301
302/* PIDs, Translation Bit, SMC Filter Select 0x300 to 0x31c */
303 struct {
304 u32 Stream1_PID :13; /* Primary use is receiving Net data, so these 13 bits normally
305 hold the PID value for the desired network stream. */
306 u32 Stream1_trans : 1; /* When set, Net translation will take place for Net data ferried in TS packets. */
307 u32 MAC_Multicast_filter : 1; /* When clear, multicast MAC filtering is not allowed for Stream1 and PID_n filters. */
308 u32 debug_flag_pid_saved : 1;
309 u32 Stream2_PID :13; /* 13 bits for Stream 2 PID filter value. General use. */
310 u32 Stream2_trans : 1; /* When set Tables/CAI translation will take place for the data ferried in
311 Stream2_PID TS packets. */
312 u32 debug_flag_write_status00 : 1;
313 u32 debug_fifo_problem : 1;
314 } pid_filter_300;
315
316 struct {
317 u32 PCR_PID :13; /* PCR stream PID filter value. Primary use is Program Clock Reference stream filtering. */
318 u32 PCR_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
319 u32 debug_overrun3 : 1;
320 u32 debug_overrun2 : 1;
321 u32 PMT_PID :13; /* stream PID filter value. Primary use is Program Management Table segment filtering. */
322 u32 PMT_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
323 u32 reserved : 2;
324 } pid_filter_304;
325
326 struct {
327 u32 EMM_PID :13; /* EMM PID filter value. Primary use is Entitlement Management Messaging for
328 conditional access-related data. */
329 u32 EMM_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
330 u32 EMM_filter_4 : 1; /* When set will pass only EMM data possessing the same ID code as the
331 first four bytes (32 bits) of the end-user s 6-byte Smart Card ID number Select */
332 u32 EMM_filter_6 : 1; /* When set will pass only EMM data possessing the same 6-byte code as the end-users
333 complete 6-byte Smart Card ID number. */
334 u32 ECM_PID :13; /* ECM PID filter value. Primary use is Entitlement Control Messaging for conditional
335 access-related data. */
336 u32 ECM_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
337 u32 reserved : 2;
338 } pid_filter_308;
339
340 struct {
341 u32 Group_PID :13; /* PID value for group filtering. */
342 u32 Group_trans : 1; /* When set, Tables/CAI translation will take place for these packets. */
343 u32 unused1 : 2;
344 u32 Group_mask :13; /* Mask value used in logical "and" equation that defines group filtering */
345 u32 unused2 : 3;
346 } pid_filter_30c_ext_ind_0_7;
347
348 struct {
349 u32 net_master_read :17;
350 u32 unused :15;
351 } pid_filter_30c_ext_ind_1;
352
353 struct {
354 u32 net_master_write :17;
355 u32 unused :15;
356 } pid_filter_30c_ext_ind_2;
357
358 struct {
359 u32 next_net_master_write :17;
360 u32 unused :15;
361 } pid_filter_30c_ext_ind_3;
362
363 struct {
364 u32 unused1 : 1;
365 u32 state_write :10;
366 u32 reserved1 : 6; /* default: 000100 */
367 u32 stack_read :10;
368 u32 reserved2 : 5; /* default: 00100 */
369 } pid_filter_30c_ext_ind_4;
370
371 struct {
372 u32 stack_cnt :10;
373 u32 unused :22;
374 } pid_filter_30c_ext_ind_5;
375
376 struct {
377 u32 pid_fsm_save_reg0 : 2;
378 u32 pid_fsm_save_reg1 : 2;
379 u32 pid_fsm_save_reg2 : 2;
380 u32 pid_fsm_save_reg3 : 2;
381 u32 pid_fsm_save_reg4 : 2;
382 u32 pid_fsm_save_reg300 : 2;
383 u32 write_status1 : 2;
384 u32 write_status4 : 2;
385 u32 data_size_reg :12;
386 u32 unused : 4;
387 } pid_filter_30c_ext_ind_6;
388
389 struct {
390 u32 index_reg : 5; /* (Index pointer) Points at an internal PIDn register. A binary code
391 representing one of 32 internal PIDn registers as well as its
392 corresponding internal MAC_lown register. */
393 u32 extra_index_reg : 3; /* This vector is used to select between sets of debug signals routed to register 0x30c. */
394 u32 AB_select : 1; /* Used in conjunction with 0x31c. read/write to the MAC_highA or MAC_highB register
395 0=MAC_highB register, 1=MAC_highA */
396 u32 pass_alltables : 1; /* 1=Net packets are not filtered against the Network Table ID found in register 0x400.
397 All types of networks (DVB, ATSC, ISDB) are passed. */
398 u32 unused :22;
399 } index_reg_310;
400
401 struct {
402 u32 PID :13; /* PID value */
403 u32 PID_trans : 1; /* translation will take place for packets filtered */
404 u32 PID_enable_bit : 1; /* When set this PID filter is enabled */
405 u32 reserved :17;
406 } pid_n_reg_314;
407
408 struct {
409 u32 A4_byte : 8;
410 u32 A5_byte : 8;
411 u32 A6_byte : 8;
412 u32 Enable_bit : 1; /* enabled (1) or disabled (1) */
413 u32 HighAB_bit : 1; /* use MAC_highA (1) or MAC_highB (0) as MSB */
414 u32 reserved : 6;
415 } mac_low_reg_318;
416
417 struct {
418 u32 A1_byte : 8;
419 u32 A2_byte : 8;
420 u32 A3_byte : 8;
421 u32 reserved : 8;
422 } mac_high_reg_31c;
423
424/* Table, SMCID,MACDestination Filters 0x400 to 0x41c */
425 struct {
426 u32 reserved :16;
427#define fc_data_Tag_ID_DVB 0x3e 47#define fc_data_Tag_ID_DVB 0x3e
428#define fc_data_Tag_ID_ATSC 0x3f 48#define fc_data_Tag_ID_ATSC 0x3f
429#define fc_data_Tag_ID_IDSB 0x8b 49#define fc_data_Tag_ID_IDSB 0x8b
430 u32 data_Tag_ID :16;
431 } data_tag_400;
432
433 struct {
434 u32 Card_IDbyte6 : 8;
435 u32 Card_IDbyte5 : 8;
436 u32 Card_IDbyte4 : 8;
437 u32 Card_IDbyte3 : 8;
438 } card_id_408;
439
440 struct {
441 u32 Card_IDbyte2 : 8;
442 u32 Card_IDbyte1 : 8;
443 } card_id_40c;
444
445 /* holding the unique mac address of the receiver which houses the FlexCopIII */
446 struct {
447 u32 MAC1 : 8;
448 u32 MAC2 : 8;
449 u32 MAC3 : 8;
450 u32 MAC6 : 8;
451 } mac_address_418;
452
453 struct {
454 u32 MAC7 : 8;
455 u32 MAC8 : 8;
456 u32 reserved : 16;
457 } mac_address_41c;
458
459 struct {
460 u32 transmitter_data_byte : 8;
461 u32 ReceiveDataReady : 1;
462 u32 ReceiveByteFrameError: 1;
463 u32 txbuffempty : 1;
464 u32 reserved :21;
465 } ci_600;
466
467 struct {
468 u32 pi_d : 8;
469 u32 pi_ha :20;
470 u32 pi_rw : 1;
471 u32 pi_component_reg : 3;
472 } pi_604;
473
474 struct {
475 u32 serialReset : 1;
476 u32 oncecycle_read : 1;
477 u32 Timer_Read_req : 1;
478 u32 Timer_Load_req : 1;
479 u32 timer_data : 7;
480 u32 unused : 1; /* ??? not mentioned in data book */
481 u32 Timer_addr : 5;
482 u32 reserved : 3;
483 u32 pcmcia_a_mod_pwr_n : 1;
484 u32 pcmcia_b_mod_pwr_n : 1;
485 u32 config_Done_stat : 1;
486 u32 config_Init_stat : 1;
487 u32 config_Prog_n : 1;
488 u32 config_wr_n : 1;
489 u32 config_cs_n : 1;
490 u32 config_cclk : 1;
491 u32 pi_CiMax_IRQ_n : 1;
492 u32 pi_timeout_status : 1;
493 u32 pi_wait_n : 1;
494 u32 pi_busy_n : 1;
495 } pi_608;
496 50
497 struct {
498 u32 PID :13;
499 u32 key_enable : 1;
500#define fc_key_code_default 0x1 51#define fc_key_code_default 0x1
501#define fc_key_code_even 0x2 52#define fc_key_code_even 0x2
502#define fc_key_code_odd 0x3 53#define fc_key_code_odd 0x3
503 u32 key_code : 2;
504 u32 key_array_col : 3;
505 u32 key_array_row : 5;
506 u32 dvb_en : 1; /* 0=TS bypasses the Descrambler */
507 u32 rw_flag : 1;
508 u32 reserved : 6;
509 } dvb_reg_60c;
510
511/* SRAM and Output Destination 0x700 to 0x714 */
512 struct {
513 u32 sram_addr :15;
514 u32 sram_rw : 1; /* 0=write, 1=read */
515 u32 sram_data : 8;
516 u32 sc_xfer_bit : 1;
517 u32 reserved1 : 3;
518 u32 oe_pin_reg : 1;
519 u32 ce_pin_reg : 1;
520 u32 reserved2 : 1;
521 u32 start_sram_ibi : 1;
522 } sram_ctrl_reg_700;
523
524 struct {
525 u32 net_addr_read :16;
526 u32 net_addr_write :16;
527 } net_buf_reg_704;
528
529 struct {
530 u32 cai_read :11;
531 u32 reserved1 : 5;
532 u32 cai_write :11;
533 u32 reserved2 : 6;
534 u32 cai_cnt : 4;
535 } cai_buf_reg_708;
536
537 struct {
538 u32 cao_read :11;
539 u32 reserved1 : 5;
540 u32 cap_write :11;
541 u32 reserved2 : 6;
542 u32 cao_cnt : 4;
543 } cao_buf_reg_70c;
544
545 struct {
546 u32 media_read :11;
547 u32 reserved1 : 5;
548 u32 media_write :11;
549 u32 reserved2 : 6;
550 u32 media_cnt : 4;
551 } media_buf_reg_710;
552
553 struct {
554 u32 NET_Dest : 2;
555 u32 CAI_Dest : 2;
556 u32 CAO_Dest : 2;
557 u32 MEDIA_Dest : 2;
558 u32 net_ovflow_error : 1;
559 u32 media_ovflow_error : 1;
560 u32 cai_ovflow_error : 1;
561 u32 cao_ovflow_error : 1;
562 u32 ctrl_usb_wan : 1;
563 u32 ctrl_sramdma : 1;
564 u32 ctrl_maximumfill : 1;
565 u32 reserved :17;
566 } sram_dest_reg_714;
567
568 struct {
569 u32 net_cnt :12;
570 u32 reserved1 : 4;
571 u32 net_addr_read : 1;
572 u32 reserved2 : 3;
573 u32 net_addr_write : 1;
574 u32 reserved3 :11;
575 } net_buf_reg_718;
576
577 struct {
578 u32 wan_speed_sig : 2;
579 u32 reserved1 : 6;
580 u32 wan_wait_state : 8;
581 u32 sram_chip : 2;
582 u32 sram_memmap : 2;
583 u32 reserved2 : 4;
584 u32 wan_pkt_frame : 4;
585 u32 reserved3 : 4;
586 } wan_ctrl_reg_71c;
587} flexcop_ibi_value;
588 54
589extern flexcop_ibi_value ibi_zero; 55extern flexcop_ibi_value ibi_zero;
590 56
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c
index 0113449abd15..0a78ba3737a5 100644
--- a/drivers/media/dvb/b2c2/flexcop-usb.c
+++ b/drivers/media/dvb/b2c2/flexcop-usb.c
@@ -545,7 +545,7 @@ static struct usb_device_id flexcop_usb_table [] = {
545/* usb specific object needed to register this driver with the usb subsystem */ 545/* usb specific object needed to register this driver with the usb subsystem */
546static struct usb_driver flexcop_usb_driver = { 546static struct usb_driver flexcop_usb_driver = {
547 .owner = THIS_MODULE, 547 .owner = THIS_MODULE,
548 .name = "Technisat/B2C2 FlexCop II/IIb/III USB", 548 .name = "b2c2_flexcop_usb",
549 .probe = flexcop_usb_probe, 549 .probe = flexcop_usb_probe,
550 .disconnect = flexcop_usb_disconnect, 550 .disconnect = flexcop_usb_disconnect,
551 .id_table = flexcop_usb_table, 551 .id_table = flexcop_usb_table,
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
index 8b5d14dd36e3..12873d435406 100644
--- a/drivers/media/dvb/b2c2/flexcop.c
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -46,7 +46,7 @@
46 46
47int b2c2_flexcop_debug; 47int b2c2_flexcop_debug;
48module_param_named(debug, b2c2_flexcop_debug, int, 0644); 48module_param_named(debug, b2c2_flexcop_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram (|-able))." DEBSTATUS); 49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." DEBSTATUS);
50#undef DEBSTATUS 50#undef DEBSTATUS
51 51
52/* global zero for ibi values */ 52/* global zero for ibi values */
@@ -173,9 +173,20 @@ static void flexcop_reset(struct flexcop_device *fc)
173 fc->write_ibi_reg(fc,ctrl_208,ibi_zero); 173 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
174 174
175 v210.raw = 0; 175 v210.raw = 0;
176 v210.sw_reset_210.reset_blocks = 0xff; 176 v210.sw_reset_210.reset_block_000 = 1;
177 v210.sw_reset_210.reset_block_100 = 1;
178 v210.sw_reset_210.reset_block_200 = 1;
179 v210.sw_reset_210.reset_block_300 = 1;
180 v210.sw_reset_210.reset_block_400 = 1;
181 v210.sw_reset_210.reset_block_500 = 1;
182 v210.sw_reset_210.reset_block_600 = 1;
183 v210.sw_reset_210.reset_block_700 = 1;
177 v210.sw_reset_210.Block_reset_enable = 0xb2; 184 v210.sw_reset_210.Block_reset_enable = 0xb2;
185
186 v210.sw_reset_210.Special_controls = 0xc259;
187
178 fc->write_ibi_reg(fc,sw_reset_210,v210); 188 fc->write_ibi_reg(fc,sw_reset_210,v210);
189 msleep(1);
179 190
180/* reset the periphical devices */ 191/* reset the periphical devices */
181 192
@@ -186,6 +197,25 @@ static void flexcop_reset(struct flexcop_device *fc)
186 fc->write_ibi_reg(fc,misc_204,v204); 197 fc->write_ibi_reg(fc,misc_204,v204);
187} 198}
188 199
200void flexcop_reset_block_300(struct flexcop_device *fc)
201{
202 flexcop_ibi_value v208_save = fc->read_ibi_reg(fc,ctrl_208),
203 v210 = fc->read_ibi_reg(fc,sw_reset_210);
204
205 deb_rdump("208: %08x, 210: %08x\n",v208_save.raw,v210.raw);
206
207 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
208
209 v210.sw_reset_210.reset_block_300 = 1;
210 v210.sw_reset_210.Block_reset_enable = 0xb2;
211
212 fc->write_ibi_reg(fc,sw_reset_210,v210);
213 msleep(1);
214
215 fc->write_ibi_reg(fc,ctrl_208,v208_save);
216}
217EXPORT_SYMBOL(flexcop_reset_block_300);
218
189struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len) 219struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
190{ 220{
191 void *bus; 221 void *bus;
diff --git a/drivers/media/dvb/b2c2/flexcop.h b/drivers/media/dvb/b2c2/flexcop.h
index caa343a97bdc..0cebe1d92e0b 100644
--- a/drivers/media/dvb/b2c2/flexcop.h
+++ b/drivers/media/dvb/b2c2/flexcop.h
@@ -26,5 +26,6 @@ extern int b2c2_flexcop_debug;
26#define deb_i2c(args...) dprintk(0x04,args) 26#define deb_i2c(args...) dprintk(0x04,args)
27#define deb_ts(args...) dprintk(0x08,args) 27#define deb_ts(args...) dprintk(0x08,args)
28#define deb_sram(args...) dprintk(0x10,args) 28#define deb_sram(args...) dprintk(0x10,args)
29#define deb_rdump(args...) dprintk(0x20,args)
29 30
30#endif 31#endif
diff --git a/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h b/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h
new file mode 100644
index 000000000000..ed9a6756b194
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h
@@ -0,0 +1,458 @@
1/* This file is part of linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
2 *
3 * register descriptions
4 *
5 * see flexcop.c for copyright information.
6 */
7
8/* This file is automatically generated, do not edit things here. */
9#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__
10#define __FLEXCOP_IBI_VALUE_INCLUDED__
11
12typedef union {
13 u32 raw;
14
15 struct {
16 u32 dma_address0 :30;
17 u32 dma_0No_update : 1;
18 u32 dma_0start : 1;
19 } dma_0x0;
20
21 struct {
22 u32 dma_addr_size :24;
23 u32 DMA_maxpackets : 8;
24 } dma_0x4_remap;
25
26 struct {
27 u32 dma_addr_size :24;
28 u32 unused : 1;
29 u32 dma1timer : 7;
30 } dma_0x4_read;
31
32 struct {
33 u32 dma_addr_size :24;
34 u32 dmatimer : 7;
35 u32 unused : 1;
36 } dma_0x4_write;
37
38 struct {
39 u32 dma_cur_addr :30;
40 u32 unused : 2;
41 } dma_0x8;
42
43 struct {
44 u32 dma_address1 :30;
45 u32 remap_enable : 1;
46 u32 dma_1start : 1;
47 } dma_0xc;
48
49 struct {
50 u32 st_done : 1;
51 u32 no_base_addr_ack_error : 1;
52 u32 twoWS_port_reg : 2;
53 u32 total_bytes : 2;
54 u32 twoWS_rw : 1;
55 u32 working_start : 1;
56 u32 data1_reg : 8;
57 u32 baseaddr : 8;
58 u32 reserved1 : 1;
59 u32 chipaddr : 7;
60 } tw_sm_c_100;
61
62 struct {
63 u32 unused : 6;
64 u32 force_stop : 1;
65 u32 exlicit_stops : 1;
66 u32 data4_reg : 8;
67 u32 data3_reg : 8;
68 u32 data2_reg : 8;
69 } tw_sm_c_104;
70
71 struct {
72 u32 reserved2 :19;
73 u32 tlo1 : 5;
74 u32 reserved1 : 2;
75 u32 thi1 : 6;
76 } tw_sm_c_108;
77
78 struct {
79 u32 reserved2 :19;
80 u32 tlo1 : 5;
81 u32 reserved1 : 2;
82 u32 thi1 : 6;
83 } tw_sm_c_10c;
84
85 struct {
86 u32 reserved2 :19;
87 u32 tlo1 : 5;
88 u32 reserved1 : 2;
89 u32 thi1 : 6;
90 } tw_sm_c_110;
91
92 struct {
93 u32 LNB_CTLPrescaler_sig : 2;
94 u32 LNB_CTLLowCount_sig :15;
95 u32 LNB_CTLHighCount_sig :15;
96 } lnb_switch_freq_200;
97
98 struct {
99 u32 Rev_N_sig_reserved2 : 1;
100 u32 Rev_N_sig_caps : 1;
101 u32 Rev_N_sig_reserved1 : 2;
102 u32 Rev_N_sig_revision_hi : 4;
103 u32 reserved :20;
104 u32 Per_reset_sig : 1;
105 u32 LNB_L_H_sig : 1;
106 u32 ACPI3_sig : 1;
107 u32 ACPI1_sig : 1;
108 } misc_204;
109
110 struct {
111 u32 unused : 9;
112 u32 Mailbox_from_V8_Enable_sig : 1;
113 u32 DMA2_Size_IRQ_Enable_sig : 1;
114 u32 DMA1_Size_IRQ_Enable_sig : 1;
115 u32 DMA2_Timer_Enable_sig : 1;
116 u32 DMA2_IRQ_Enable_sig : 1;
117 u32 DMA1_Timer_Enable_sig : 1;
118 u32 DMA1_IRQ_Enable_sig : 1;
119 u32 Rcv_Data_sig : 1;
120 u32 MAC_filter_Mode_sig : 1;
121 u32 Multi2_Enable_sig : 1;
122 u32 Per_CA_Enable_sig : 1;
123 u32 SMC_Enable_sig : 1;
124 u32 CA_Enable_sig : 1;
125 u32 WAN_CA_Enable_sig : 1;
126 u32 WAN_Enable_sig : 1;
127 u32 Mask_filter_sig : 1;
128 u32 Null_filter_sig : 1;
129 u32 ECM_filter_sig : 1;
130 u32 EMM_filter_sig : 1;
131 u32 PMT_filter_sig : 1;
132 u32 PCR_filter_sig : 1;
133 u32 Stream2_filter_sig : 1;
134 u32 Stream1_filter_sig : 1;
135 } ctrl_208;
136
137 struct {
138 u32 reserved :21;
139 u32 Transport_Error : 1;
140 u32 LLC_SNAP_FLAG_set : 1;
141 u32 Continuity_error_flag : 1;
142 u32 Data_receiver_error : 1;
143 u32 Mailbox_from_V8_Status_sig : 1;
144 u32 DMA2_Size_IRQ_Status : 1;
145 u32 DMA1_Size_IRQ_Status : 1;
146 u32 DMA2_Timer_Status : 1;
147 u32 DMA2_IRQ_Status : 1;
148 u32 DMA1_Timer_Status : 1;
149 u32 DMA1_IRQ_Status : 1;
150 } irq_20c;
151
152 struct {
153 u32 Special_controls :16;
154 u32 Block_reset_enable : 8;
155 u32 reset_block_700 : 1;
156 u32 reset_block_600 : 1;
157 u32 reset_block_500 : 1;
158 u32 reset_block_400 : 1;
159 u32 reset_block_300 : 1;
160 u32 reset_block_200 : 1;
161 u32 reset_block_100 : 1;
162 u32 reset_block_000 : 1;
163 } sw_reset_210;
164
165 struct {
166 u32 unused2 :20;
167 u32 polarity_PS_ERR_sig : 1;
168 u32 polarity_PS_SYNC_sig : 1;
169 u32 polarity_PS_VALID_sig : 1;
170 u32 polarity_PS_CLK_sig : 1;
171 u32 unused1 : 3;
172 u32 s2p_sel_sig : 1;
173 u32 section_pkg_enable_sig : 1;
174 u32 halt_V8_sig : 1;
175 u32 v2WS_oe_sig : 1;
176 u32 vuart_oe_sig : 1;
177 } misc_214;
178
179 struct {
180 u32 Mailbox_from_V8 :32;
181 } mbox_v8_to_host_218;
182
183 struct {
184 u32 sysramaccess_busmuster : 1;
185 u32 sysramaccess_write : 1;
186 u32 unused : 7;
187 u32 sysramaccess_addr :15;
188 u32 sysramaccess_data : 8;
189 } mbox_host_to_v8_21c;
190
191 struct {
192 u32 debug_fifo_problem : 1;
193 u32 debug_flag_write_status00 : 1;
194 u32 Stream2_trans : 1;
195 u32 Stream2_PID :13;
196 u32 debug_flag_pid_saved : 1;
197 u32 MAC_Multicast_filter : 1;
198 u32 Stream1_trans : 1;
199 u32 Stream1_PID :13;
200 } pid_filter_300;
201
202 struct {
203 u32 reserved : 2;
204 u32 PMT_trans : 1;
205 u32 PMT_PID :13;
206 u32 debug_overrun2 : 1;
207 u32 debug_overrun3 : 1;
208 u32 PCR_trans : 1;
209 u32 PCR_PID :13;
210 } pid_filter_304;
211
212 struct {
213 u32 reserved : 2;
214 u32 ECM_trans : 1;
215 u32 ECM_PID :13;
216 u32 EMM_filter_6 : 1;
217 u32 EMM_filter_4 : 1;
218 u32 EMM_trans : 1;
219 u32 EMM_PID :13;
220 } pid_filter_308;
221
222 struct {
223 u32 unused2 : 3;
224 u32 Group_mask :13;
225 u32 unused1 : 2;
226 u32 Group_trans : 1;
227 u32 Group_PID :13;
228 } pid_filter_30c_ext_ind_0_7;
229
230 struct {
231 u32 unused :15;
232 u32 net_master_read :17;
233 } pid_filter_30c_ext_ind_1;
234
235 struct {
236 u32 unused :15;
237 u32 net_master_write :17;
238 } pid_filter_30c_ext_ind_2;
239
240 struct {
241 u32 unused :15;
242 u32 next_net_master_write :17;
243 } pid_filter_30c_ext_ind_3;
244
245 struct {
246 u32 reserved2 : 5;
247 u32 stack_read :10;
248 u32 reserved1 : 6;
249 u32 state_write :10;
250 u32 unused1 : 1;
251 } pid_filter_30c_ext_ind_4;
252
253 struct {
254 u32 unused :22;
255 u32 stack_cnt :10;
256 } pid_filter_30c_ext_ind_5;
257
258 struct {
259 u32 unused : 4;
260 u32 data_size_reg :12;
261 u32 write_status4 : 2;
262 u32 write_status1 : 2;
263 u32 pid_fsm_save_reg300 : 2;
264 u32 pid_fsm_save_reg4 : 2;
265 u32 pid_fsm_save_reg3 : 2;
266 u32 pid_fsm_save_reg2 : 2;
267 u32 pid_fsm_save_reg1 : 2;
268 u32 pid_fsm_save_reg0 : 2;
269 } pid_filter_30c_ext_ind_6;
270
271 struct {
272 u32 unused :22;
273 u32 pass_alltables : 1;
274 u32 AB_select : 1;
275 u32 extra_index_reg : 3;
276 u32 index_reg : 5;
277 } index_reg_310;
278
279 struct {
280 u32 reserved :17;
281 u32 PID_enable_bit : 1;
282 u32 PID_trans : 1;
283 u32 PID :13;
284 } pid_n_reg_314;
285
286 struct {
287 u32 reserved : 6;
288 u32 HighAB_bit : 1;
289 u32 Enable_bit : 1;
290 u32 A6_byte : 8;
291 u32 A5_byte : 8;
292 u32 A4_byte : 8;
293 } mac_low_reg_318;
294
295 struct {
296 u32 reserved : 8;
297 u32 A3_byte : 8;
298 u32 A2_byte : 8;
299 u32 A1_byte : 8;
300 } mac_high_reg_31c;
301
302 struct {
303 u32 data_Tag_ID :16;
304 u32 reserved :16;
305 } data_tag_400;
306
307 struct {
308 u32 Card_IDbyte3 : 8;
309 u32 Card_IDbyte4 : 8;
310 u32 Card_IDbyte5 : 8;
311 u32 Card_IDbyte6 : 8;
312 } card_id_408;
313
314 struct {
315 u32 Card_IDbyte1 : 8;
316 u32 Card_IDbyte2 : 8;
317 } card_id_40c;
318
319 struct {
320 u32 MAC6 : 8;
321 u32 MAC3 : 8;
322 u32 MAC2 : 8;
323 u32 MAC1 : 8;
324 } mac_address_418;
325
326 struct {
327 u32 reserved :16;
328 u32 MAC8 : 8;
329 u32 MAC7 : 8;
330 } mac_address_41c;
331
332 struct {
333 u32 reserved :21;
334 u32 txbuffempty : 1;
335 u32 ReceiveByteFrameError : 1;
336 u32 ReceiveDataReady : 1;
337 u32 transmitter_data_byte : 8;
338 } ci_600;
339
340 struct {
341 u32 pi_component_reg : 3;
342 u32 pi_rw : 1;
343 u32 pi_ha :20;
344 u32 pi_d : 8;
345 } pi_604;
346
347 struct {
348 u32 pi_busy_n : 1;
349 u32 pi_wait_n : 1;
350 u32 pi_timeout_status : 1;
351 u32 pi_CiMax_IRQ_n : 1;
352 u32 config_cclk : 1;
353 u32 config_cs_n : 1;
354 u32 config_wr_n : 1;
355 u32 config_Prog_n : 1;
356 u32 config_Init_stat : 1;
357 u32 config_Done_stat : 1;
358 u32 pcmcia_b_mod_pwr_n : 1;
359 u32 pcmcia_a_mod_pwr_n : 1;
360 u32 reserved : 3;
361 u32 Timer_addr : 5;
362 u32 unused : 1;
363 u32 timer_data : 7;
364 u32 Timer_Load_req : 1;
365 u32 Timer_Read_req : 1;
366 u32 oncecycle_read : 1;
367 u32 serialReset : 1;
368 } pi_608;
369
370 struct {
371 u32 reserved : 6;
372 u32 rw_flag : 1;
373 u32 dvb_en : 1;
374 u32 key_array_row : 5;
375 u32 key_array_col : 3;
376 u32 key_code : 2;
377 u32 key_enable : 1;
378 u32 PID :13;
379 } dvb_reg_60c;
380
381 struct {
382 u32 start_sram_ibi : 1;
383 u32 reserved2 : 1;
384 u32 ce_pin_reg : 1;
385 u32 oe_pin_reg : 1;
386 u32 reserved1 : 3;
387 u32 sc_xfer_bit : 1;
388 u32 sram_data : 8;
389 u32 sram_rw : 1;
390 u32 sram_addr :15;
391 } sram_ctrl_reg_700;
392
393 struct {
394 u32 net_addr_write :16;
395 u32 net_addr_read :16;
396 } net_buf_reg_704;
397
398 struct {
399 u32 cai_cnt : 4;
400 u32 reserved2 : 6;
401 u32 cai_write :11;
402 u32 reserved1 : 5;
403 u32 cai_read :11;
404 } cai_buf_reg_708;
405
406 struct {
407 u32 cao_cnt : 4;
408 u32 reserved2 : 6;
409 u32 cap_write :11;
410 u32 reserved1 : 5;
411 u32 cao_read :11;
412 } cao_buf_reg_70c;
413
414 struct {
415 u32 media_cnt : 4;
416 u32 reserved2 : 6;
417 u32 media_write :11;
418 u32 reserved1 : 5;
419 u32 media_read :11;
420 } media_buf_reg_710;
421
422 struct {
423 u32 reserved :17;
424 u32 ctrl_maximumfill : 1;
425 u32 ctrl_sramdma : 1;
426 u32 ctrl_usb_wan : 1;
427 u32 cao_ovflow_error : 1;
428 u32 cai_ovflow_error : 1;
429 u32 media_ovflow_error : 1;
430 u32 net_ovflow_error : 1;
431 u32 MEDIA_Dest : 2;
432 u32 CAO_Dest : 2;
433 u32 CAI_Dest : 2;
434 u32 NET_Dest : 2;
435 } sram_dest_reg_714;
436
437 struct {
438 u32 reserved3 :11;
439 u32 net_addr_write : 1;
440 u32 reserved2 : 3;
441 u32 net_addr_read : 1;
442 u32 reserved1 : 4;
443 u32 net_cnt :12;
444 } net_buf_reg_718;
445
446 struct {
447 u32 reserved3 : 4;
448 u32 wan_pkt_frame : 4;
449 u32 reserved2 : 4;
450 u32 sram_memmap : 2;
451 u32 sram_chip : 2;
452 u32 wan_wait_state : 8;
453 u32 reserved1 : 6;
454 u32 wan_speed_sig : 2;
455 } wan_ctrl_reg_71c;
456} flexcop_ibi_value;
457
458#endif
diff --git a/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h b/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h
new file mode 100644
index 000000000000..49f2315b6e58
--- /dev/null
+++ b/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h
@@ -0,0 +1,458 @@
1/* This file is part of linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
2 *
3 * register descriptions
4 *
5 * see flexcop.c for copyright information.
6 */
7
8/* This file is automatically generated, do not edit things here. */
9#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__
10#define __FLEXCOP_IBI_VALUE_INCLUDED__
11
12typedef union {
13 u32 raw;
14
15 struct {
16 u32 dma_0start : 1;
17 u32 dma_0No_update : 1;
18 u32 dma_address0 :30;
19 } dma_0x0;
20
21 struct {
22 u32 DMA_maxpackets : 8;
23 u32 dma_addr_size :24;
24 } dma_0x4_remap;
25
26 struct {
27 u32 dma1timer : 7;
28 u32 unused : 1;
29 u32 dma_addr_size :24;
30 } dma_0x4_read;
31
32 struct {
33 u32 unused : 1;
34 u32 dmatimer : 7;
35 u32 dma_addr_size :24;
36 } dma_0x4_write;
37
38 struct {
39 u32 unused : 2;
40 u32 dma_cur_addr :30;
41 } dma_0x8;
42
43 struct {
44 u32 dma_1start : 1;
45 u32 remap_enable : 1;
46 u32 dma_address1 :30;
47 } dma_0xc;
48
49 struct {
50 u32 chipaddr : 7;
51 u32 reserved1 : 1;
52 u32 baseaddr : 8;
53 u32 data1_reg : 8;
54 u32 working_start : 1;
55 u32 twoWS_rw : 1;
56 u32 total_bytes : 2;
57 u32 twoWS_port_reg : 2;
58 u32 no_base_addr_ack_error : 1;
59 u32 st_done : 1;
60 } tw_sm_c_100;
61
62 struct {
63 u32 data2_reg : 8;
64 u32 data3_reg : 8;
65 u32 data4_reg : 8;
66 u32 exlicit_stops : 1;
67 u32 force_stop : 1;
68 u32 unused : 6;
69 } tw_sm_c_104;
70
71 struct {
72 u32 thi1 : 6;
73 u32 reserved1 : 2;
74 u32 tlo1 : 5;
75 u32 reserved2 :19;
76 } tw_sm_c_108;
77
78 struct {
79 u32 thi1 : 6;
80 u32 reserved1 : 2;
81 u32 tlo1 : 5;
82 u32 reserved2 :19;
83 } tw_sm_c_10c;
84
85 struct {
86 u32 thi1 : 6;
87 u32 reserved1 : 2;
88 u32 tlo1 : 5;
89 u32 reserved2 :19;
90 } tw_sm_c_110;
91
92 struct {
93 u32 LNB_CTLHighCount_sig :15;
94 u32 LNB_CTLLowCount_sig :15;
95 u32 LNB_CTLPrescaler_sig : 2;
96 } lnb_switch_freq_200;
97
98 struct {
99 u32 ACPI1_sig : 1;
100 u32 ACPI3_sig : 1;
101 u32 LNB_L_H_sig : 1;
102 u32 Per_reset_sig : 1;
103 u32 reserved :20;
104 u32 Rev_N_sig_revision_hi : 4;
105 u32 Rev_N_sig_reserved1 : 2;
106 u32 Rev_N_sig_caps : 1;
107 u32 Rev_N_sig_reserved2 : 1;
108 } misc_204;
109
110 struct {
111 u32 Stream1_filter_sig : 1;
112 u32 Stream2_filter_sig : 1;
113 u32 PCR_filter_sig : 1;
114 u32 PMT_filter_sig : 1;
115 u32 EMM_filter_sig : 1;
116 u32 ECM_filter_sig : 1;
117 u32 Null_filter_sig : 1;
118 u32 Mask_filter_sig : 1;
119 u32 WAN_Enable_sig : 1;
120 u32 WAN_CA_Enable_sig : 1;
121 u32 CA_Enable_sig : 1;
122 u32 SMC_Enable_sig : 1;
123 u32 Per_CA_Enable_sig : 1;
124 u32 Multi2_Enable_sig : 1;
125 u32 MAC_filter_Mode_sig : 1;
126 u32 Rcv_Data_sig : 1;
127 u32 DMA1_IRQ_Enable_sig : 1;
128 u32 DMA1_Timer_Enable_sig : 1;
129 u32 DMA2_IRQ_Enable_sig : 1;
130 u32 DMA2_Timer_Enable_sig : 1;
131 u32 DMA1_Size_IRQ_Enable_sig : 1;
132 u32 DMA2_Size_IRQ_Enable_sig : 1;
133 u32 Mailbox_from_V8_Enable_sig : 1;
134 u32 unused : 9;
135 } ctrl_208;
136
137 struct {
138 u32 DMA1_IRQ_Status : 1;
139 u32 DMA1_Timer_Status : 1;
140 u32 DMA2_IRQ_Status : 1;
141 u32 DMA2_Timer_Status : 1;
142 u32 DMA1_Size_IRQ_Status : 1;
143 u32 DMA2_Size_IRQ_Status : 1;
144 u32 Mailbox_from_V8_Status_sig : 1;
145 u32 Data_receiver_error : 1;
146 u32 Continuity_error_flag : 1;
147 u32 LLC_SNAP_FLAG_set : 1;
148 u32 Transport_Error : 1;
149 u32 reserved :21;
150 } irq_20c;
151
152 struct {
153 u32 reset_block_000 : 1;
154 u32 reset_block_100 : 1;
155 u32 reset_block_200 : 1;
156 u32 reset_block_300 : 1;
157 u32 reset_block_400 : 1;
158 u32 reset_block_500 : 1;
159 u32 reset_block_600 : 1;
160 u32 reset_block_700 : 1;
161 u32 Block_reset_enable : 8;
162 u32 Special_controls :16;
163 } sw_reset_210;
164
165 struct {
166 u32 vuart_oe_sig : 1;
167 u32 v2WS_oe_sig : 1;
168 u32 halt_V8_sig : 1;
169 u32 section_pkg_enable_sig : 1;
170 u32 s2p_sel_sig : 1;
171 u32 unused1 : 3;
172 u32 polarity_PS_CLK_sig : 1;
173 u32 polarity_PS_VALID_sig : 1;
174 u32 polarity_PS_SYNC_sig : 1;
175 u32 polarity_PS_ERR_sig : 1;
176 u32 unused2 :20;
177 } misc_214;
178
179 struct {
180 u32 Mailbox_from_V8 :32;
181 } mbox_v8_to_host_218;
182
183 struct {
184 u32 sysramaccess_data : 8;
185 u32 sysramaccess_addr :15;
186 u32 unused : 7;
187 u32 sysramaccess_write : 1;
188 u32 sysramaccess_busmuster : 1;
189 } mbox_host_to_v8_21c;
190
191 struct {
192 u32 Stream1_PID :13;
193 u32 Stream1_trans : 1;
194 u32 MAC_Multicast_filter : 1;
195 u32 debug_flag_pid_saved : 1;
196 u32 Stream2_PID :13;
197 u32 Stream2_trans : 1;
198 u32 debug_flag_write_status00 : 1;
199 u32 debug_fifo_problem : 1;
200 } pid_filter_300;
201
202 struct {
203 u32 PCR_PID :13;
204 u32 PCR_trans : 1;
205 u32 debug_overrun3 : 1;
206 u32 debug_overrun2 : 1;
207 u32 PMT_PID :13;
208 u32 PMT_trans : 1;
209 u32 reserved : 2;
210 } pid_filter_304;
211
212 struct {
213 u32 EMM_PID :13;
214 u32 EMM_trans : 1;
215 u32 EMM_filter_4 : 1;
216 u32 EMM_filter_6 : 1;
217 u32 ECM_PID :13;
218 u32 ECM_trans : 1;
219 u32 reserved : 2;
220 } pid_filter_308;
221
222 struct {
223 u32 Group_PID :13;
224 u32 Group_trans : 1;
225 u32 unused1 : 2;
226 u32 Group_mask :13;
227 u32 unused2 : 3;
228 } pid_filter_30c_ext_ind_0_7;
229
230 struct {
231 u32 net_master_read :17;
232 u32 unused :15;
233 } pid_filter_30c_ext_ind_1;
234
235 struct {
236 u32 net_master_write :17;
237 u32 unused :15;
238 } pid_filter_30c_ext_ind_2;
239
240 struct {
241 u32 next_net_master_write :17;
242 u32 unused :15;
243 } pid_filter_30c_ext_ind_3;
244
245 struct {
246 u32 unused1 : 1;
247 u32 state_write :10;
248 u32 reserved1 : 6;
249 u32 stack_read :10;
250 u32 reserved2 : 5;
251 } pid_filter_30c_ext_ind_4;
252
253 struct {
254 u32 stack_cnt :10;
255 u32 unused :22;
256 } pid_filter_30c_ext_ind_5;
257
258 struct {
259 u32 pid_fsm_save_reg0 : 2;
260 u32 pid_fsm_save_reg1 : 2;
261 u32 pid_fsm_save_reg2 : 2;
262 u32 pid_fsm_save_reg3 : 2;
263 u32 pid_fsm_save_reg4 : 2;
264 u32 pid_fsm_save_reg300 : 2;
265 u32 write_status1 : 2;
266 u32 write_status4 : 2;
267 u32 data_size_reg :12;
268 u32 unused : 4;
269 } pid_filter_30c_ext_ind_6;
270
271 struct {
272 u32 index_reg : 5;
273 u32 extra_index_reg : 3;
274 u32 AB_select : 1;
275 u32 pass_alltables : 1;
276 u32 unused :22;
277 } index_reg_310;
278
279 struct {
280 u32 PID :13;
281 u32 PID_trans : 1;
282 u32 PID_enable_bit : 1;
283 u32 reserved :17;
284 } pid_n_reg_314;
285
286 struct {
287 u32 A4_byte : 8;
288 u32 A5_byte : 8;
289 u32 A6_byte : 8;
290 u32 Enable_bit : 1;
291 u32 HighAB_bit : 1;
292 u32 reserved : 6;
293 } mac_low_reg_318;
294
295 struct {
296 u32 A1_byte : 8;
297 u32 A2_byte : 8;
298 u32 A3_byte : 8;
299 u32 reserved : 8;
300 } mac_high_reg_31c;
301
302 struct {
303 u32 reserved :16;
304 u32 data_Tag_ID :16;
305 } data_tag_400;
306
307 struct {
308 u32 Card_IDbyte6 : 8;
309 u32 Card_IDbyte5 : 8;
310 u32 Card_IDbyte4 : 8;
311 u32 Card_IDbyte3 : 8;
312 } card_id_408;
313
314 struct {
315 u32 Card_IDbyte2 : 8;
316 u32 Card_IDbyte1 : 8;
317 } card_id_40c;
318
319 struct {
320 u32 MAC1 : 8;
321 u32 MAC2 : 8;
322 u32 MAC3 : 8;
323 u32 MAC6 : 8;
324 } mac_address_418;
325
326 struct {
327 u32 MAC7 : 8;
328 u32 MAC8 : 8;
329 u32 reserved :16;
330 } mac_address_41c;
331
332 struct {
333 u32 transmitter_data_byte : 8;
334 u32 ReceiveDataReady : 1;
335 u32 ReceiveByteFrameError : 1;
336 u32 txbuffempty : 1;
337 u32 reserved :21;
338 } ci_600;
339
340 struct {
341 u32 pi_d : 8;
342 u32 pi_ha :20;
343 u32 pi_rw : 1;
344 u32 pi_component_reg : 3;
345 } pi_604;
346
347 struct {
348 u32 serialReset : 1;
349 u32 oncecycle_read : 1;
350 u32 Timer_Read_req : 1;
351 u32 Timer_Load_req : 1;
352 u32 timer_data : 7;
353 u32 unused : 1;
354 u32 Timer_addr : 5;
355 u32 reserved : 3;
356 u32 pcmcia_a_mod_pwr_n : 1;
357 u32 pcmcia_b_mod_pwr_n : 1;
358 u32 config_Done_stat : 1;
359 u32 config_Init_stat : 1;
360 u32 config_Prog_n : 1;
361 u32 config_wr_n : 1;
362 u32 config_cs_n : 1;
363 u32 config_cclk : 1;
364 u32 pi_CiMax_IRQ_n : 1;
365 u32 pi_timeout_status : 1;
366 u32 pi_wait_n : 1;
367 u32 pi_busy_n : 1;
368 } pi_608;
369
370 struct {
371 u32 PID :13;
372 u32 key_enable : 1;
373 u32 key_code : 2;
374 u32 key_array_col : 3;
375 u32 key_array_row : 5;
376 u32 dvb_en : 1;
377 u32 rw_flag : 1;
378 u32 reserved : 6;
379 } dvb_reg_60c;
380
381 struct {
382 u32 sram_addr :15;
383 u32 sram_rw : 1;
384 u32 sram_data : 8;
385 u32 sc_xfer_bit : 1;
386 u32 reserved1 : 3;
387 u32 oe_pin_reg : 1;
388 u32 ce_pin_reg : 1;
389 u32 reserved2 : 1;
390 u32 start_sram_ibi : 1;
391 } sram_ctrl_reg_700;
392
393 struct {
394 u32 net_addr_read :16;
395 u32 net_addr_write :16;
396 } net_buf_reg_704;
397
398 struct {
399 u32 cai_read :11;
400 u32 reserved1 : 5;
401 u32 cai_write :11;
402 u32 reserved2 : 6;
403 u32 cai_cnt : 4;
404 } cai_buf_reg_708;
405
406 struct {
407 u32 cao_read :11;
408 u32 reserved1 : 5;
409 u32 cap_write :11;
410 u32 reserved2 : 6;
411 u32 cao_cnt : 4;
412 } cao_buf_reg_70c;
413
414 struct {
415 u32 media_read :11;
416 u32 reserved1 : 5;
417 u32 media_write :11;
418 u32 reserved2 : 6;
419 u32 media_cnt : 4;
420 } media_buf_reg_710;
421
422 struct {
423 u32 NET_Dest : 2;
424 u32 CAI_Dest : 2;
425 u32 CAO_Dest : 2;
426 u32 MEDIA_Dest : 2;
427 u32 net_ovflow_error : 1;
428 u32 media_ovflow_error : 1;
429 u32 cai_ovflow_error : 1;
430 u32 cao_ovflow_error : 1;
431 u32 ctrl_usb_wan : 1;
432 u32 ctrl_sramdma : 1;
433 u32 ctrl_maximumfill : 1;
434 u32 reserved :17;
435 } sram_dest_reg_714;
436
437 struct {
438 u32 net_cnt :12;
439 u32 reserved1 : 4;
440 u32 net_addr_read : 1;
441 u32 reserved2 : 3;
442 u32 net_addr_write : 1;
443 u32 reserved3 :11;
444 } net_buf_reg_718;
445
446 struct {
447 u32 wan_speed_sig : 2;
448 u32 reserved1 : 6;
449 u32 wan_wait_state : 8;
450 u32 sram_chip : 2;
451 u32 sram_memmap : 2;
452 u32 reserved2 : 4;
453 u32 wan_pkt_frame : 4;
454 u32 reserved3 : 4;
455 } wan_ctrl_reg_71c;
456} flexcop_ibi_value;
457
458#endif
diff --git a/drivers/media/dvb/b2c2/skystar2.c b/drivers/media/dvb/b2c2/skystar2.c
deleted file mode 100644
index acbc4c34f72a..000000000000
--- a/drivers/media/dvb/b2c2/skystar2.c
+++ /dev/null
@@ -1,2644 +0,0 @@
1/*
2 * skystar2.c - driver for the Technisat SkyStar2 PCI DVB card
3 * based on the FlexCopII by B2C2,Inc.
4 *
5 * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
6 *
7 * FIX: DISEQC Tone Burst in flexcop_diseqc_ioctl()
8 * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev 130) VP310 equipped
9 * Vincenzo Di Massa, hawk.it at tiscalinet.it
10 *
11 * Converted to Linux coding style
12 * Misc reorganization, polishing, restyling
13 * Roberto Ragusa, skystar2-c5b8 at robertoragusa dot it
14 *
15 * Added hardware filtering support,
16 * Niklas Peinecke, peinecke at gdv.uni-hannover.de
17 *
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU Lesser General Public License
21 * as published by the Free Software Foundation; either version 2.1
22 * of the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 */
33
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/delay.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/version.h>
40
41#include <asm/io.h>
42
43#include "dvb_frontend.h"
44
45#include <linux/dvb/frontend.h>
46#include <linux/dvb/dmx.h>
47#include "dvb_demux.h"
48#include "dmxdev.h"
49#include "dvb_filter.h"
50#include "dvbdev.h"
51#include "demux.h"
52#include "dvb_net.h"
53#include "stv0299.h"
54#include "mt352.h"
55#include "mt312.h"
56#include "nxt2002.h"
57
58static int debug;
59static int enable_hw_filters = 2;
60
61module_param(debug, int, 0644);
62MODULE_PARM_DESC(debug, "Set debugging level (0 = default, 1 = most messages, 2 = all messages).");
63module_param(enable_hw_filters, int, 0444);
64MODULE_PARM_DESC(enable_hw_filters, "enable hardware filters: supported values: 0 (none), 1, 2");
65
66#define dprintk(x...) do { if (debug>=1) printk(x); } while (0)
67#define ddprintk(x...) do { if (debug>=2) printk(x); } while (0)
68
69#define SIZE_OF_BUF_DMA1 0x3ac00
70#define SIZE_OF_BUF_DMA2 0x758
71
72#define MAX_N_HW_FILTERS (6+32)
73#define N_PID_SLOTS 256
74
75struct dmaq {
76 u32 bus_addr;
77 u32 head;
78 u32 tail;
79 u32 buffer_size;
80 u8 *buffer;
81};
82
83#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
84#define __iomem
85#endif
86
87struct adapter {
88 struct pci_dev *pdev;
89
90 u8 card_revision;
91 u32 b2c2_revision;
92 u32 pid_filter_max;
93 u32 mac_filter_max;
94 u32 irq;
95 void __iomem *io_mem;
96 unsigned long io_port;
97 u8 mac_addr[8];
98 u32 dw_sram_type;
99
100 struct dvb_adapter dvb_adapter;
101 struct dvb_demux demux;
102 struct dmxdev dmxdev;
103 struct dmx_frontend hw_frontend;
104 struct dmx_frontend mem_frontend;
105 struct i2c_adapter i2c_adap;
106 struct dvb_net dvbnet;
107
108 struct semaphore i2c_sem;
109
110 struct dmaq dmaq1;
111 struct dmaq dmaq2;
112
113 u32 dma_ctrl;
114 u32 dma_status;
115
116 int capturing;
117
118 spinlock_t lock;
119
120 int useable_hw_filters;
121 u16 hw_pids[MAX_N_HW_FILTERS];
122 u16 pid_list[N_PID_SLOTS];
123 int pid_rc[N_PID_SLOTS]; // ref counters for the pids
124 int pid_count;
125 int whole_bandwidth_count;
126 u32 mac_filter;
127
128 struct dvb_frontend* fe;
129 int (*fe_sleep)(struct dvb_frontend* fe);
130};
131
132#define write_reg_dw(adapter,reg,value) writel(value, adapter->io_mem + reg)
133#define read_reg_dw(adapter,reg) readl(adapter->io_mem + reg)
134
135static void write_reg_bitfield(struct adapter *adapter, u32 reg, u32 zeromask, u32 orvalue)
136{
137 u32 tmp;
138
139 tmp = read_reg_dw(adapter, reg);
140 tmp = (tmp & ~zeromask) | orvalue;
141 write_reg_dw(adapter, reg, tmp);
142}
143
144/* i2c functions */
145static int i2c_main_write_for_flex2(struct adapter *adapter, u32 command, u8 *buf, int retries)
146{
147 int i;
148 u32 value;
149
150 write_reg_dw(adapter, 0x100, 0);
151 write_reg_dw(adapter, 0x100, command);
152
153 for (i = 0; i < retries; i++) {
154 value = read_reg_dw(adapter, 0x100);
155
156 if ((value & 0x40000000) == 0) {
157 if ((value & 0x81000000) == 0x80000000) {
158 if (buf != 0)
159 *buf = (value >> 0x10) & 0xff;
160
161 return 1;
162 }
163 } else {
164 write_reg_dw(adapter, 0x100, 0);
165 write_reg_dw(adapter, 0x100, command);
166 }
167 }
168
169 return 0;
170}
171
172/* device = 0x10000000 for tuner, 0x20000000 for eeprom */
173static void i2c_main_setup(u32 device, u32 chip_addr, u8 op, u8 addr, u32 value, u32 len, u32 *command)
174{
175 *command = device | ((len - 1) << 26) | (value << 16) | (addr << 8) | chip_addr;
176
177 if (op != 0)
178 *command = *command | 0x03000000;
179 else
180 *command = *command | 0x01000000;
181}
182
183static int flex_i2c_read4(struct adapter *adapter, u32 device, u32 chip_addr, u16 addr, u8 *buf, u8 len)
184{
185 u32 command;
186 u32 value;
187
188 int result, i;
189
190 i2c_main_setup(device, chip_addr, 1, addr, 0, len, &command);
191
192 result = i2c_main_write_for_flex2(adapter, command, buf, 100000);
193
194 if ((result & 0xff) != 0) {
195 if (len > 1) {
196 value = read_reg_dw(adapter, 0x104);
197
198 for (i = 1; i < len; i++) {
199 buf[i] = value & 0xff;
200 value = value >> 8;
201 }
202 }
203 }
204
205 return result;
206}
207
208static int flex_i2c_write4(struct adapter *adapter, u32 device, u32 chip_addr, u32 addr, u8 *buf, u8 len)
209{
210 u32 command;
211 u32 value;
212 int i;
213
214 if (len > 1) {
215 value = 0;
216
217 for (i = len; i > 1; i--) {
218 value = value << 8;
219 value = value | buf[i - 1];
220 }
221
222 write_reg_dw(adapter, 0x104, value);
223 }
224
225 i2c_main_setup(device, chip_addr, 0, addr, buf[0], len, &command);
226
227 return i2c_main_write_for_flex2(adapter, command, NULL, 100000);
228}
229
230static void fixchipaddr(u32 device, u32 bus, u32 addr, u32 *ret)
231{
232 if (device == 0x20000000)
233 *ret = bus | ((addr >> 8) & 3);
234 else
235 *ret = bus;
236}
237
238static u32 flex_i2c_read(struct adapter *adapter, u32 device, u32 bus, u32 addr, u8 *buf, u32 len)
239{
240 u32 chipaddr;
241 u32 bytes_to_transfer;
242 u8 *start;
243
244 ddprintk("%s:\n", __FUNCTION__);
245
246 start = buf;
247
248 while (len != 0) {
249 bytes_to_transfer = len;
250
251 if (bytes_to_transfer > 4)
252 bytes_to_transfer = 4;
253
254 fixchipaddr(device, bus, addr, &chipaddr);
255
256 if (flex_i2c_read4(adapter, device, chipaddr, addr, buf, bytes_to_transfer) == 0)
257 return buf - start;
258
259 buf = buf + bytes_to_transfer;
260 addr = addr + bytes_to_transfer;
261 len = len - bytes_to_transfer;
262 };
263
264 return buf - start;
265}
266
267static u32 flex_i2c_write(struct adapter *adapter, u32 device, u32 bus, u32 addr, u8 *buf, u32 len)
268{
269 u32 chipaddr;
270 u32 bytes_to_transfer;
271 u8 *start;
272
273 ddprintk("%s:\n", __FUNCTION__);
274
275 start = buf;
276
277 while (len != 0) {
278 bytes_to_transfer = len;
279
280 if (bytes_to_transfer > 4)
281 bytes_to_transfer = 4;
282
283 fixchipaddr(device, bus, addr, &chipaddr);
284
285 if (flex_i2c_write4(adapter, device, chipaddr, addr, buf, bytes_to_transfer) == 0)
286 return buf - start;
287
288 buf = buf + bytes_to_transfer;
289 addr = addr + bytes_to_transfer;
290 len = len - bytes_to_transfer;
291 }
292
293 return buf - start;
294}
295
296static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msgs, int num)
297{
298 struct adapter *tmp = i2c_get_adapdata(adapter);
299 int i, ret = 0;
300
301 if (down_interruptible(&tmp->i2c_sem))
302 return -ERESTARTSYS;
303
304 ddprintk("%s: %d messages to transfer\n", __FUNCTION__, num);
305
306 for (i = 0; i < num; i++) {
307 ddprintk("message %d: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", i,
308 msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len);
309 }
310
311 // read command
312 if ((num == 2) && (msgs[0].flags == 0) && (msgs[1].flags == I2C_M_RD) && (msgs[0].buf != NULL) && (msgs[1].buf != NULL)) {
313
314 ret = flex_i2c_read(tmp, 0x10000000, msgs[0].addr, msgs[0].buf[0], msgs[1].buf, msgs[1].len);
315
316 up(&tmp->i2c_sem);
317
318 if (ret != msgs[1].len) {
319 dprintk("%s: read error !\n", __FUNCTION__);
320
321 for (i = 0; i < 2; i++) {
322 dprintk("message %d: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", i,
323 msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len);
324 }
325
326 return -EREMOTEIO;
327 }
328
329 return num;
330 }
331 // write command
332 for (i = 0; i < num; i++) {
333
334 if ((msgs[i].flags != 0) || (msgs[i].buf == NULL) || (msgs[i].len < 2))
335 return -EINVAL;
336
337 ret = flex_i2c_write(tmp, 0x10000000, msgs[i].addr, msgs[i].buf[0], &msgs[i].buf[1], msgs[i].len - 1);
338
339 up(&tmp->i2c_sem);
340
341 if (ret != msgs[0].len - 1) {
342 dprintk("%s: write error %i !\n", __FUNCTION__, ret);
343
344 dprintk("message %d: flags=0x%x, addr=0x%x, buf[0]=0x%x, len=%d \n", i,
345 msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len);
346
347 return -EREMOTEIO;
348 }
349
350 return num;
351 }
352
353 printk("%s: unknown command format !\n", __FUNCTION__);
354
355 return -EINVAL;
356}
357
358/* SRAM (Skystar2 rev2.3 has one "ISSI IS61LV256" chip on board,
359 but it seems that FlexCopII can work with more than one chip) */
360static void sram_set_net_dest(struct adapter *adapter, u8 dest)
361{
362 u32 tmp;
363
364 udelay(1000);
365
366 tmp = (read_reg_dw(adapter, 0x714) & 0xfffffffc) | (dest & 3);
367
368 udelay(1000);
369
370 write_reg_dw(adapter, 0x714, tmp);
371 write_reg_dw(adapter, 0x714, tmp);
372
373 udelay(1000);
374
375 /* return value is never used? */
376/* return tmp; */
377}
378
379static void sram_set_cai_dest(struct adapter *adapter, u8 dest)
380{
381 u32 tmp;
382
383 udelay(1000);
384
385 tmp = (read_reg_dw(adapter, 0x714) & 0xfffffff3) | ((dest & 3) << 2);
386
387 udelay(1000);
388 udelay(1000);
389
390 write_reg_dw(adapter, 0x714, tmp);
391 write_reg_dw(adapter, 0x714, tmp);
392
393 udelay(1000);
394
395 /* return value is never used? */
396/* return tmp; */
397}
398
399static void sram_set_cao_dest(struct adapter *adapter, u8 dest)
400{
401 u32 tmp;
402
403 udelay(1000);
404
405 tmp = (read_reg_dw(adapter, 0x714) & 0xffffffcf) | ((dest & 3) << 4);
406
407 udelay(1000);
408 udelay(1000);
409
410 write_reg_dw(adapter, 0x714, tmp);
411 write_reg_dw(adapter, 0x714, tmp);
412
413 udelay(1000);
414
415 /* return value is never used? */
416/* return tmp; */
417}
418
419static void sram_set_media_dest(struct adapter *adapter, u8 dest)
420{
421 u32 tmp;
422
423 udelay(1000);
424
425 tmp = (read_reg_dw(adapter, 0x714) & 0xffffff3f) | ((dest & 3) << 6);
426
427 udelay(1000);
428 udelay(1000);
429
430 write_reg_dw(adapter, 0x714, tmp);
431 write_reg_dw(adapter, 0x714, tmp);
432
433 udelay(1000);
434
435 /* return value is never used? */
436/* return tmp; */
437}
438
439/* SRAM memory is accessed through a buffer register in the FlexCop
440 chip (0x700). This register has the following structure:
441 bits 0-14 : address
442 bit 15 : read/write flag
443 bits 16-23 : 8-bit word to write
444 bits 24-27 : = 4
445 bits 28-29 : memory bank selector
446 bit 31 : busy flag
447*/
448static void flex_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
449{
450 int i, retries;
451 u32 command;
452
453 for (i = 0; i < len; i++) {
454 command = bank | addr | 0x04000000 | (*buf << 0x10);
455
456 retries = 2;
457
458 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
459 mdelay(1);
460 retries--;
461 };
462
463 if (retries == 0)
464 printk("%s: SRAM timeout\n", __FUNCTION__);
465
466 write_reg_dw(adapter, 0x700, command);
467
468 buf++;
469 addr++;
470 }
471}
472
473static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len)
474{
475 int i, retries;
476 u32 command, value;
477
478 for (i = 0; i < len; i++) {
479 command = bank | addr | 0x04008000;
480
481 retries = 10000;
482
483 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
484 mdelay(1);
485 retries--;
486 };
487
488 if (retries == 0)
489 printk("%s: SRAM timeout\n", __FUNCTION__);
490
491 write_reg_dw(adapter, 0x700, command);
492
493 retries = 10000;
494
495 while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
496 mdelay(1);
497 retries--;
498 };
499
500 if (retries == 0)
501 printk("%s: SRAM timeout\n", __FUNCTION__);
502
503 value = read_reg_dw(adapter, 0x700) >> 0x10;
504
505 *buf = (value & 0xff);
506
507 addr++;
508 buf++;
509 }
510}
511
512static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
513{
514 u32 bank;
515
516 bank = 0;
517
518 if (adapter->dw_sram_type == 0x20000) {
519 bank = (addr & 0x18000) << 0x0d;
520 }
521
522 if (adapter->dw_sram_type == 0x00000) {
523 if ((addr >> 0x0f) == 0)
524 bank = 0x20000000;
525 else
526 bank = 0x10000000;
527 }
528
529 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
530}
531
532static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
533{
534 u32 bank;
535
536 bank = 0;
537
538 if (adapter->dw_sram_type == 0x20000) {
539 bank = (addr & 0x18000) << 0x0d;
540 }
541
542 if (adapter->dw_sram_type == 0x00000) {
543 if ((addr >> 0x0f) == 0)
544 bank = 0x20000000;
545 else
546 bank = 0x10000000;
547 }
548
549 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
550}
551
552static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
553{
554 u32 length;
555
556 while (len != 0) {
557 length = len;
558
559 // check if the address range belongs to the same
560 // 32K memory chip. If not, the data is read from
561 // one chip at a time.
562 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
563 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
564 }
565
566 sram_read_chunk(adapter, addr, buf, length);
567
568 addr = addr + length;
569 buf = buf + length;
570 len = len - length;
571 }
572}
573
574static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
575{
576 u32 length;
577
578 while (len != 0) {
579 length = len;
580
581 // check if the address range belongs to the same
582 // 32K memory chip. If not, the data is written to
583 // one chip at a time.
584 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
585 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
586 }
587
588 sram_write_chunk(adapter, addr, buf, length);
589
590 addr = addr + length;
591 buf = buf + length;
592 len = len - length;
593 }
594}
595
596static void sram_set_size(struct adapter *adapter, u32 mask)
597{
598 write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
599}
600
601static void sram_init(struct adapter *adapter)
602{
603 u32 tmp;
604
605 tmp = read_reg_dw(adapter, 0x71c);
606
607 write_reg_dw(adapter, 0x71c, 1);
608
609 if (read_reg_dw(adapter, 0x71c) != 0) {
610 write_reg_dw(adapter, 0x71c, tmp);
611
612 adapter->dw_sram_type = tmp & 0x30000;
613
614 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);
615
616 } else {
617
618 adapter->dw_sram_type = 0x10000;
619
620 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);
621 }
622
623 /* return value is never used? */
624/* return adapter->dw_sram_type; */
625}
626
627static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
628{
629 u8 tmp1, tmp2;
630
631 dprintk("%s: mask = %x, addr = %x\n", __FUNCTION__, mask, addr);
632
633 sram_set_size(adapter, mask);
634 sram_init(adapter);
635
636 tmp2 = 0xa5;
637 tmp1 = 0x4f;
638
639 sram_write(adapter, addr, &tmp2, 1);
640 sram_write(adapter, addr + 4, &tmp1, 1);
641
642 tmp2 = 0;
643
644 mdelay(20);
645
646 sram_read(adapter, addr, &tmp2, 1);
647 sram_read(adapter, addr, &tmp2, 1);
648
649 dprintk("%s: wrote 0xa5, read 0x%2x\n", __FUNCTION__, tmp2);
650
651 if (tmp2 != 0xa5)
652 return 0;
653
654 tmp2 = 0x5a;
655 tmp1 = 0xf4;
656
657 sram_write(adapter, addr, &tmp2, 1);
658 sram_write(adapter, addr + 4, &tmp1, 1);
659
660 tmp2 = 0;
661
662 mdelay(20);
663
664 sram_read(adapter, addr, &tmp2, 1);
665 sram_read(adapter, addr, &tmp2, 1);
666
667 dprintk("%s: wrote 0x5a, read 0x%2x\n", __FUNCTION__, tmp2);
668
669 if (tmp2 != 0x5a)
670 return 0;
671
672 return 1;
673}
674
675static u32 sram_length(struct adapter *adapter)
676{
677 if (adapter->dw_sram_type == 0x10000)
678 return 32768; // 32K
679 if (adapter->dw_sram_type == 0x00000)
680 return 65536; // 64K
681 if (adapter->dw_sram_type == 0x20000)
682 return 131072; // 128K
683
684 return 32768; // 32K
685}
686
687/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
688 - for 128K there are 4x32K chips at bank 0,1,2,3.
689 - for 64K there are 2x32K chips at bank 1,2.
690 - for 32K there is one 32K chip at bank 0.
691
692 FlexCop works only with one bank at a time. The bank is selected
693 by bits 28-29 of the 0x700 register.
694
695 bank 0 covers addresses 0x00000-0x07fff
696 bank 1 covers addresses 0x08000-0x0ffff
697 bank 2 covers addresses 0x10000-0x17fff
698 bank 3 covers addresses 0x18000-0x1ffff
699*/
700static int sram_detect_for_flex2(struct adapter *adapter)
701{
702 u32 tmp, tmp2, tmp3;
703
704 dprintk("%s:\n", __FUNCTION__);
705
706 tmp = read_reg_dw(adapter, 0x208);
707 write_reg_dw(adapter, 0x208, 0);
708
709 tmp2 = read_reg_dw(adapter, 0x71c);
710
711 dprintk("%s: tmp2 = %x\n", __FUNCTION__, tmp2);
712
713 write_reg_dw(adapter, 0x71c, 1);
714
715 tmp3 = read_reg_dw(adapter, 0x71c);
716
717 dprintk("%s: tmp3 = %x\n", __FUNCTION__, tmp3);
718
719 write_reg_dw(adapter, 0x71c, tmp2);
720
721 // check for internal SRAM ???
722 tmp3--;
723 if (tmp3 != 0) {
724 sram_set_size(adapter, 0x10000);
725 sram_init(adapter);
726 write_reg_dw(adapter, 0x208, tmp);
727
728 dprintk("%s: sram size = 32K\n", __FUNCTION__);
729
730 return 32;
731 }
732
733 if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {
734 sram_set_size(adapter, 0x20000);
735 sram_init(adapter);
736 write_reg_dw(adapter, 0x208, tmp);
737
738 dprintk("%s: sram size = 128K\n", __FUNCTION__);
739
740 return 128;
741 }
742
743 if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {
744 sram_set_size(adapter, 0x00000);
745 sram_init(adapter);
746 write_reg_dw(adapter, 0x208, tmp);
747
748 dprintk("%s: sram size = 64K\n", __FUNCTION__);
749
750 return 64;
751 }
752
753 if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {
754 sram_set_size(adapter, 0x10000);
755 sram_init(adapter);
756 write_reg_dw(adapter, 0x208, tmp);
757
758 dprintk("%s: sram size = 32K\n", __FUNCTION__);
759
760 return 32;
761 }
762
763 sram_set_size(adapter, 0x10000);
764 sram_init(adapter);
765 write_reg_dw(adapter, 0x208, tmp);
766
767 dprintk("%s: SRAM detection failed. Set to 32K \n", __FUNCTION__);
768
769 return 0;
770}
771
772static void sll_detect_sram_size(struct adapter *adapter)
773{
774 sram_detect_for_flex2(adapter);
775}
776
777/* EEPROM (Skystar2 has one "24LC08B" chip on board) */
778/*
779static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
780{
781 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
782}
783*/
784
785static int eeprom_read(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
786{
787 return flex_i2c_read(adapter, 0x20000000, 0x50, addr, buf, len);
788}
789
790static u8 calc_lrc(u8 *buf, int len)
791{
792 int i;
793 u8 sum;
794
795 sum = 0;
796
797 for (i = 0; i < len; i++)
798 sum = sum ^ buf[i];
799
800 return sum;
801}
802
803static int eeprom_lrc_read(struct adapter *adapter, u32 addr, u32 len, u8 *buf, int retries)
804{
805 int i;
806
807 for (i = 0; i < retries; i++) {
808 if (eeprom_read(adapter, addr, buf, len) == len) {
809 if (calc_lrc(buf, len - 1) == buf[len - 1])
810 return 1;
811 }
812 }
813
814 return 0;
815}
816
817/*
818static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries)
819{
820 int i;
821
822 for (i = 0; i < retries; i++) {
823 if (eeprom_write(adapter, addr, wbuf, len) == len) {
824 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)
825 return 1;
826 }
827 }
828
829 return 0;
830}
831*/
832
833
834/* These functions could be used to unlock SkyStar2 cards. */
835
836/*
837static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
838{
839 u8 rbuf[20];
840 u8 wbuf[20];
841
842 if (len != 16)
843 return 0;
844
845 memcpy(wbuf, key, len);
846
847 wbuf[16] = 0;
848 wbuf[17] = 0;
849 wbuf[18] = 0;
850 wbuf[19] = calc_lrc(wbuf, 19);
851
852 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
853}
854
855static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
856{
857 u8 buf[20];
858
859 if (len != 16)
860 return 0;
861
862 if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0)
863 return 0;
864
865 memcpy(key, buf, len);
866
867 return 1;
868}
869*/
870
871static int eeprom_get_mac_addr(struct adapter *adapter, char type, u8 *mac)
872{
873 u8 tmp[8];
874
875 if (eeprom_lrc_read(adapter, 0x3f8, 8, tmp, 4) != 0) {
876 if (type != 0) {
877 mac[0] = tmp[0];
878 mac[1] = tmp[1];
879 mac[2] = tmp[2];
880 mac[3] = 0xfe;
881 mac[4] = 0xff;
882 mac[5] = tmp[3];
883 mac[6] = tmp[4];
884 mac[7] = tmp[5];
885
886 } else {
887
888 mac[0] = tmp[0];
889 mac[1] = tmp[1];
890 mac[2] = tmp[2];
891 mac[3] = tmp[3];
892 mac[4] = tmp[4];
893 mac[5] = tmp[5];
894 }
895
896 return 1;
897
898 } else {
899
900 if (type == 0) {
901 memset(mac, 0, 6);
902
903 } else {
904
905 memset(mac, 0, 8);
906 }
907
908 return 0;
909 }
910}
911
912/*
913static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
914{
915 u8 tmp[8];
916
917 if (type != 0) {
918 tmp[0] = mac[0];
919 tmp[1] = mac[1];
920 tmp[2] = mac[2];
921 tmp[3] = mac[5];
922 tmp[4] = mac[6];
923 tmp[5] = mac[7];
924
925 } else {
926
927 tmp[0] = mac[0];
928 tmp[1] = mac[1];
929 tmp[2] = mac[2];
930 tmp[3] = mac[3];
931 tmp[4] = mac[4];
932 tmp[5] = mac[5];
933 }
934
935 tmp[6] = 0;
936 tmp[7] = calc_lrc(tmp, 7);
937
938 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
939 return 1;
940
941 return 0;
942}
943*/
944
945/* PID filter */
946
947/* every flexcop has 6 "lower" hw PID filters */
948/* these are enabled by setting bits 0-5 of 0x208 */
949/* for the 32 additional filters we have to select one */
950/* of them through 0x310 and modify through 0x314 */
951/* op: 0=disable, 1=enable */
952static void filter_enable_hw_filter(struct adapter *adapter, int id, u8 op)
953{
954 dprintk("%s: id=%d op=%d\n", __FUNCTION__, id, op);
955 if (id <= 5) {
956 u32 mask = (0x00000001 << id);
957 write_reg_bitfield(adapter, 0x208, mask, op ? mask : 0);
958 } else {
959 /* select */
960 write_reg_bitfield(adapter, 0x310, 0x1f, (id - 6) & 0x1f);
961 /* modify */
962 write_reg_bitfield(adapter, 0x314, 0x00006000, op ? 0x00004000 : 0);
963 }
964}
965
966/* this sets the PID that should pass the specified filter */
967static void pid_set_hw_pid(struct adapter *adapter, int id, u16 pid)
968{
969 dprintk("%s: id=%d pid=%d\n", __FUNCTION__, id, pid);
970 if (id <= 5) {
971 u32 adr = 0x300 + ((id & 6) << 1);
972 int shift = (id & 1) ? 16 : 0;
973 dprintk("%s: id=%d addr=%x %c pid=%d\n", __FUNCTION__, id, adr, (id & 1) ? 'h' : 'l', pid);
974 write_reg_bitfield(adapter, adr, (0x7fff) << shift, (pid & 0x1fff) << shift);
975 } else {
976 /* select */
977 write_reg_bitfield(adapter, 0x310, 0x1f, (id - 6) & 0x1f);
978 /* modify */
979 write_reg_bitfield(adapter, 0x314, 0x1fff, pid & 0x1fff);
980 }
981}
982
983
984/*
985static void filter_enable_null_filter(struct adapter *adapter, u32 op)
986{
987 dprintk("%s: op=%x\n", __FUNCTION__, op);
988
989 write_reg_bitfield(adapter, 0x208, 0x00000040, op?0x00000040:0);
990}
991*/
992
993static void filter_enable_mask_filter(struct adapter *adapter, u32 op)
994{
995 dprintk("%s: op=%x\n", __FUNCTION__, op);
996
997 write_reg_bitfield(adapter, 0x208, 0x00000080, op ? 0x00000080 : 0);
998}
999
1000
1001static void ctrl_enable_mac(struct adapter *adapter, u32 op)
1002{
1003 write_reg_bitfield(adapter, 0x208, 0x00004000, op ? 0x00004000 : 0);
1004}
1005
1006static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 *mac)
1007{
1008 u32 tmp1, tmp2;
1009
1010 tmp1 = (mac[3] << 0x18) | (mac[2] << 0x10) | (mac[1] << 0x08) | mac[0];
1011 tmp2 = (mac[5] << 0x08) | mac[4];
1012
1013 write_reg_dw(adapter, 0x418, tmp1);
1014 write_reg_dw(adapter, 0x41c, tmp2);
1015
1016 return 0;
1017}
1018
1019/*
1020static void set_ignore_mac_filter(struct adapter *adapter, u8 op)
1021{
1022 if (op != 0) {
1023 write_reg_bitfield(adapter, 0x208, 0x00004000, 0);
1024 adapter->mac_filter = 1;
1025 } else {
1026 if (adapter->mac_filter != 0) {
1027 adapter->mac_filter = 0;
1028 write_reg_bitfield(adapter, 0x208, 0x00004000, 0x00004000);
1029 }
1030 }
1031}
1032*/
1033
1034/*
1035static void check_null_filter_enable(struct adapter *adapter)
1036{
1037 filter_enable_null_filter(adapter, 1);
1038 filter_enable_mask_filter(adapter, 1);
1039}
1040*/
1041
1042static void pid_set_group_pid(struct adapter *adapter, u16 pid)
1043{
1044 u32 value;
1045
1046 dprintk("%s: pid=%x\n", __FUNCTION__, pid);
1047 value = (pid & 0x3fff) | (read_reg_dw(adapter, 0x30c) & 0xffff0000);
1048 write_reg_dw(adapter, 0x30c, value);
1049}
1050
1051static void pid_set_group_mask(struct adapter *adapter, u16 pid)
1052{
1053 u32 value;
1054
1055 dprintk("%s: pid=%x\n", __FUNCTION__, pid);
1056 value = ((pid & 0x3fff) << 0x10) | (read_reg_dw(adapter, 0x30c) & 0xffff);
1057 write_reg_dw(adapter, 0x30c, value);
1058}
1059
1060/*
1061static int pid_get_group_pid(struct adapter *adapter)
1062{
1063 return read_reg_dw(adapter, 0x30c) & 0x00001fff;
1064}
1065
1066static int pid_get_group_mask(struct adapter *adapter)
1067{
1068 return (read_reg_dw(adapter, 0x30c) >> 0x10)& 0x00001fff;
1069}
1070*/
1071
1072/*
1073static void reset_hardware_pid_filter(struct adapter *adapter)
1074{
1075 pid_set_stream1_pid(adapter, 0x1fff);
1076
1077 pid_set_stream2_pid(adapter, 0x1fff);
1078 filter_enable_stream2_filter(adapter, 0);
1079
1080 pid_set_pcr_pid(adapter, 0x1fff);
1081 filter_enable_pcr_filter(adapter, 0);
1082
1083 pid_set_pmt_pid(adapter, 0x1fff);
1084 filter_enable_pmt_filter(adapter, 0);
1085
1086 pid_set_ecm_pid(adapter, 0x1fff);
1087 filter_enable_ecm_filter(adapter, 0);
1088
1089 pid_set_emm_pid(adapter, 0x1fff);
1090 filter_enable_emm_filter(adapter, 0);
1091}
1092*/
1093
1094static void init_pids(struct adapter *adapter)
1095{
1096 int i;
1097
1098 adapter->pid_count = 0;
1099 adapter->whole_bandwidth_count = 0;
1100 for (i = 0; i < adapter->useable_hw_filters; i++) {
1101 dprintk("%s: setting filter %d to 0x1fff\n", __FUNCTION__, i);
1102 adapter->hw_pids[i] = 0x1fff;
1103 pid_set_hw_pid(adapter, i, 0x1fff);
1104}
1105
1106 pid_set_group_pid(adapter, 0);
1107 pid_set_group_mask(adapter, 0x1fe0);
1108}
1109
1110static void open_whole_bandwidth(struct adapter *adapter)
1111{
1112 dprintk("%s:\n", __FUNCTION__);
1113 pid_set_group_pid(adapter, 0);
1114 pid_set_group_mask(adapter, 0);
1115/*
1116 filter_enable_mask_filter(adapter, 1);
1117*/
1118}
1119
1120static void close_whole_bandwidth(struct adapter *adapter)
1121{
1122 dprintk("%s:\n", __FUNCTION__);
1123 pid_set_group_pid(adapter, 0);
1124 pid_set_group_mask(adapter, 0x1fe0);
1125/*
1126 filter_enable_mask_filter(adapter, 1);
1127*/
1128}
1129
1130static void whole_bandwidth_inc(struct adapter *adapter)
1131{
1132 if (adapter->whole_bandwidth_count++ == 0)
1133 open_whole_bandwidth(adapter);
1134}
1135
1136static void whole_bandwidth_dec(struct adapter *adapter)
1137{
1138 if (--adapter->whole_bandwidth_count <= 0)
1139 close_whole_bandwidth(adapter);
1140}
1141
1142/* The specified PID has to be let through the
1143 hw filters.
1144 We try to allocate an hardware filter and open whole
1145 bandwidth when allocation is impossible.
1146 All pids<=0x1f pass through the group filter.
1147 Returns 1 on success, -1 on error */
1148static int add_hw_pid(struct adapter *adapter, u16 pid)
1149{
1150 int i;
1151
1152 dprintk("%s: pid=%d\n", __FUNCTION__, pid);
1153
1154 if (pid <= 0x1f)
1155 return 1;
1156
1157 /* we can't use a filter for 0x2000, so no search */
1158 if (pid != 0x2000) {
1159 /* find an unused hardware filter */
1160 for (i = 0; i < adapter->useable_hw_filters; i++) {
1161 dprintk("%s: pid=%d searching slot=%d\n", __FUNCTION__, pid, i);
1162 if (adapter->hw_pids[i] == 0x1fff) {
1163 dprintk("%s: pid=%d slot=%d\n", __FUNCTION__, pid, i);
1164 adapter->hw_pids[i] = pid;
1165 pid_set_hw_pid(adapter, i, pid);
1166 filter_enable_hw_filter(adapter, i, 1);
1167 return 1;
1168 }
1169 }
1170 }
1171 /* if we have not used a filter, this pid depends on whole bandwidth */
1172 dprintk("%s: pid=%d whole_bandwidth\n", __FUNCTION__, pid);
1173 whole_bandwidth_inc(adapter);
1174 return 1;
1175 }
1176
1177/* returns -1 if the pid was not present in the filters */
1178static int remove_hw_pid(struct adapter *adapter, u16 pid)
1179{
1180 int i;
1181
1182 dprintk("%s: pid=%d\n", __FUNCTION__, pid);
1183
1184 if (pid <= 0x1f)
1185 return 1;
1186
1187 /* we can't use a filter for 0x2000, so no search */
1188 if (pid != 0x2000) {
1189 for (i = 0; i < adapter->useable_hw_filters; i++) {
1190 dprintk("%s: pid=%d searching slot=%d\n", __FUNCTION__, pid, i);
1191 if (adapter->hw_pids[i] == pid) { // find the pid slot
1192 dprintk("%s: pid=%d slot=%d\n", __FUNCTION__, pid, i);
1193 adapter->hw_pids[i] = 0x1fff;
1194 pid_set_hw_pid(adapter, i, 0x1fff);
1195 filter_enable_hw_filter(adapter, i, 0);
1196 return 1;
1197 }
1198 }
1199 }
1200 /* if we have not used a filter, this pid depended on whole bandwith */
1201 dprintk("%s: pid=%d whole_bandwidth\n", __FUNCTION__, pid);
1202 whole_bandwidth_dec(adapter);
1203 return 1;
1204 }
1205
1206/* Adds a PID to the filters.
1207 Adding a pid more than once is possible, we keep reference counts.
1208 Whole stream available through pid==0x2000.
1209 Returns 1 on success, -1 on error */
1210static int add_pid(struct adapter *adapter, u16 pid)
1211{
1212 int i;
1213
1214 dprintk("%s: pid=%d\n", __FUNCTION__, pid);
1215
1216 if (pid > 0x1ffe && pid != 0x2000)
1217 return -1;
1218
1219 // check if the pid is already present
1220 for (i = 0; i < adapter->pid_count; i++)
1221 if (adapter->pid_list[i] == pid) {
1222 adapter->pid_rc[i]++; // increment ref counter
1223 return 1;
1224 }
1225
1226 if (adapter->pid_count == N_PID_SLOTS)
1227 return -1; // no more pids can be added
1228 adapter->pid_list[adapter->pid_count] = pid; // register pid
1229 adapter->pid_rc[adapter->pid_count] = 1;
1230 adapter->pid_count++;
1231 // hardware setting
1232 add_hw_pid(adapter, pid);
1233
1234 return 1;
1235 }
1236
1237/* Removes a PID from the filters. */
1238static int remove_pid(struct adapter *adapter, u16 pid)
1239{
1240 int i;
1241
1242 dprintk("%s: pid=%d\n", __FUNCTION__, pid);
1243
1244 if (pid > 0x1ffe && pid != 0x2000)
1245 return -1;
1246
1247 // check if the pid is present (it must be!)
1248 for (i = 0; i < adapter->pid_count; i++) {
1249 if (adapter->pid_list[i] == pid) {
1250 adapter->pid_rc[i]--;
1251 if (adapter->pid_rc[i] <= 0) {
1252 // remove from the list
1253 adapter->pid_count--;
1254 adapter->pid_list[i]=adapter->pid_list[adapter->pid_count];
1255 adapter->pid_rc[i] = adapter->pid_rc[adapter->pid_count];
1256 // hardware setting
1257 remove_hw_pid(adapter, pid);
1258 }
1259 return 1;
1260 }
1261 }
1262
1263 return -1;
1264}
1265
1266
1267/* dma & irq */
1268static void ctrl_enable_smc(struct adapter *adapter, u32 op)
1269{
1270 write_reg_bitfield(adapter, 0x208, 0x00000800, op ? 0x00000800 : 0);
1271}
1272
1273static void dma_enable_disable_irq(struct adapter *adapter, u32 flag1, u32 flag2, u32 flag3)
1274{
1275 adapter->dma_ctrl = adapter->dma_ctrl & 0x000f0000;
1276
1277 if (flag1 == 0) {
1278 if (flag2 == 0)
1279 adapter->dma_ctrl = adapter->dma_ctrl & ~0x00010000;
1280 else
1281 adapter->dma_ctrl = adapter->dma_ctrl | 0x00010000;
1282
1283 if (flag3 == 0)
1284 adapter->dma_ctrl = adapter->dma_ctrl & ~0x00020000;
1285 else
1286 adapter->dma_ctrl = adapter->dma_ctrl | 0x00020000;
1287
1288 } else {
1289
1290 if (flag2 == 0)
1291 adapter->dma_ctrl = adapter->dma_ctrl & ~0x00040000;
1292 else
1293 adapter->dma_ctrl = adapter->dma_ctrl | 0x00040000;
1294
1295 if (flag3 == 0)
1296 adapter->dma_ctrl = adapter->dma_ctrl & ~0x00080000;
1297 else
1298 adapter->dma_ctrl = adapter->dma_ctrl | 0x00080000;
1299 }
1300}
1301
1302static void irq_dma_enable_disable_irq(struct adapter *adapter, u32 op)
1303{
1304 u32 value;
1305
1306 value = read_reg_dw(adapter, 0x208) & 0xfff0ffff;
1307
1308 if (op != 0)
1309 value = value | (adapter->dma_ctrl & 0x000f0000);
1310
1311 write_reg_dw(adapter, 0x208, value);
1312}
1313
1314/* FlexCopII has 2 dma channels. DMA1 is used to transfer TS data to
1315 system memory.
1316
1317 The DMA1 buffer is divided in 2 subbuffers of equal size.
1318 FlexCopII will transfer TS data to one subbuffer, signal an interrupt
1319 when the subbuffer is full and continue fillig the second subbuffer.
1320
1321 For DMA1:
1322 subbuffer size in 32-bit words is stored in the first 24 bits of
1323 register 0x004. The last 8 bits of register 0x004 contain the number
1324 of subbuffers.
1325
1326 the first 30 bits of register 0x000 contain the address of the first
1327 subbuffer. The last 2 bits contain 0, when dma1 is disabled and 1,
1328 when dma1 is enabled.
1329
1330 the first 30 bits of register 0x00c contain the address of the second
1331 subbuffer. the last 2 bits contain 1.
1332
1333 register 0x008 will contain the address of the subbuffer that was filled
1334 with TS data, when FlexCopII will generate an interrupt.
1335
1336 For DMA2:
1337 subbuffer size in 32-bit words is stored in the first 24 bits of
1338 register 0x014. The last 8 bits of register 0x014 contain the number
1339 of subbuffers.
1340
1341 the first 30 bits of register 0x010 contain the address of the first
1342 subbuffer. The last 2 bits contain 0, when dma1 is disabled and 1,
1343 when dma1 is enabled.
1344
1345 the first 30 bits of register 0x01c contain the address of the second
1346 subbuffer. the last 2 bits contain 1.
1347
1348 register 0x018 contains the address of the subbuffer that was filled
1349 with TS data, when FlexCopII generates an interrupt.
1350*/
1351static int dma_init_dma(struct adapter *adapter, u32 dma_channel)
1352{
1353 u32 subbuffers, subbufsize, subbuf0, subbuf1;
1354
1355 if (dma_channel == 0) {
1356 dprintk("%s: Initializing DMA1 channel\n", __FUNCTION__);
1357
1358 subbuffers = 2;
1359
1360 subbufsize = (((adapter->dmaq1.buffer_size / 2) / 4) << 8) | subbuffers;
1361
1362 subbuf0 = adapter->dmaq1.bus_addr & 0xfffffffc;
1363
1364 subbuf1 = ((adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) & 0xfffffffc) | 1;
1365
1366 dprintk("%s: first subbuffer address = 0x%x\n", __FUNCTION__, subbuf0);
1367 udelay(1000);
1368 write_reg_dw(adapter, 0x000, subbuf0);
1369
1370 dprintk("%s: subbuffer size = 0x%x\n", __FUNCTION__, (subbufsize >> 8) * 4);
1371 udelay(1000);
1372 write_reg_dw(adapter, 0x004, subbufsize);
1373
1374 dprintk("%s: second subbuffer address = 0x%x\n", __FUNCTION__, subbuf1);
1375 udelay(1000);
1376 write_reg_dw(adapter, 0x00c, subbuf1);
1377
1378 dprintk("%s: counter = 0x%x\n", __FUNCTION__, adapter->dmaq1.bus_addr & 0xfffffffc);
1379 write_reg_dw(adapter, 0x008, adapter->dmaq1.bus_addr & 0xfffffffc);
1380 udelay(1000);
1381
1382 dma_enable_disable_irq(adapter, 0, 1, subbuffers ? 1 : 0);
1383
1384 irq_dma_enable_disable_irq(adapter, 1);
1385
1386 sram_set_media_dest(adapter, 1);
1387 sram_set_net_dest(adapter, 1);
1388 sram_set_cai_dest(adapter, 2);
1389 sram_set_cao_dest(adapter, 2);
1390 }
1391
1392 if (dma_channel == 1) {
1393 dprintk("%s: Initializing DMA2 channel\n", __FUNCTION__);
1394
1395 subbuffers = 2;
1396
1397 subbufsize = (((adapter->dmaq2.buffer_size / 2) / 4) << 8) | subbuffers;
1398
1399 subbuf0 = adapter->dmaq2.bus_addr & 0xfffffffc;
1400
1401 subbuf1 = ((adapter->dmaq2.bus_addr + adapter->dmaq2.buffer_size / 2) & 0xfffffffc) | 1;
1402
1403 dprintk("%s: first subbuffer address = 0x%x\n", __FUNCTION__, subbuf0);
1404 udelay(1000);
1405 write_reg_dw(adapter, 0x010, subbuf0);
1406
1407 dprintk("%s: subbuffer size = 0x%x\n", __FUNCTION__, (subbufsize >> 8) * 4);
1408 udelay(1000);
1409 write_reg_dw(adapter, 0x014, subbufsize);
1410
1411 dprintk("%s: second buffer address = 0x%x\n", __FUNCTION__, subbuf1);
1412 udelay(1000);
1413 write_reg_dw(adapter, 0x01c, subbuf1);
1414
1415 sram_set_cai_dest(adapter, 2);
1416 }
1417
1418 return 0;
1419}
1420
1421static void ctrl_enable_receive_data(struct adapter *adapter, u32 op)
1422{
1423 if (op == 0) {
1424 write_reg_bitfield(adapter, 0x208, 0x00008000, 0);
1425 adapter->dma_status = adapter->dma_status & ~0x00000004;
1426 } else {
1427 write_reg_bitfield(adapter, 0x208, 0x00008000, 0x00008000);
1428 adapter->dma_status = adapter->dma_status | 0x00000004;
1429 }
1430}
1431
1432/* bit 0 of dma_mask is set to 1 if dma1 channel has to be enabled/disabled
1433 bit 1 of dma_mask is set to 1 if dma2 channel has to be enabled/disabled
1434*/
1435static void dma_start_stop(struct adapter *adapter, u32 dma_mask, int start_stop)
1436{
1437 u32 dma_enable, dma1_enable, dma2_enable;
1438
1439 dprintk("%s: dma_mask=%x\n", __FUNCTION__, dma_mask);
1440
1441 if (start_stop == 1) {
1442 dprintk("%s: starting dma\n", __FUNCTION__);
1443
1444 dma1_enable = 0;
1445 dma2_enable = 0;
1446
1447 if (((dma_mask & 1) != 0) && ((adapter->dma_status & 1) == 0) && (adapter->dmaq1.bus_addr != 0)) {
1448 adapter->dma_status = adapter->dma_status | 1;
1449 dma1_enable = 1;
1450 }
1451
1452 if (((dma_mask & 2) != 0) && ((adapter->dma_status & 2) == 0) && (adapter->dmaq2.bus_addr != 0)) {
1453 adapter->dma_status = adapter->dma_status | 2;
1454 dma2_enable = 1;
1455 }
1456 // enable dma1 and dma2
1457 if ((dma1_enable == 1) && (dma2_enable == 1)) {
1458 write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr | 1);
1459 write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1);
1460 write_reg_dw(adapter, 0x010, adapter->dmaq2.bus_addr | 1);
1461
1462 ctrl_enable_receive_data(adapter, 1);
1463
1464 return;
1465 }
1466 // enable dma1
1467 if ((dma1_enable == 1) && (dma2_enable == 0)) {
1468 write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr | 1);
1469 write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1);
1470
1471 ctrl_enable_receive_data(adapter, 1);
1472
1473 return;
1474 }
1475 // enable dma2
1476 if ((dma1_enable == 0) && (dma2_enable == 1)) {
1477 write_reg_dw(adapter, 0x010, adapter->dmaq2.bus_addr | 1);
1478
1479 ctrl_enable_receive_data(adapter, 1);
1480
1481 return;
1482 }
1483 // start dma
1484 if ((dma1_enable == 0) && (dma2_enable == 0)) {
1485 ctrl_enable_receive_data(adapter, 1);
1486
1487 return;
1488 }
1489
1490 } else {
1491
1492 dprintk("%s: stopping dma\n", __FUNCTION__);
1493
1494 dma_enable = adapter->dma_status & 0x00000003;
1495
1496 if (((dma_mask & 1) != 0) && ((adapter->dma_status & 1) != 0)) {
1497 dma_enable = dma_enable & 0xfffffffe;
1498 }
1499
1500 if (((dma_mask & 2) != 0) && ((adapter->dma_status & 2) != 0)) {
1501 dma_enable = dma_enable & 0xfffffffd;
1502 }
1503 //stop dma
1504 if ((dma_enable == 0) && ((adapter->dma_status & 4) != 0)) {
1505 ctrl_enable_receive_data(adapter, 0);
1506
1507 udelay(3000);
1508 }
1509 //disable dma1
1510 if (((dma_mask & 1) != 0) && ((adapter->dma_status & 1) != 0) && (adapter->dmaq1.bus_addr != 0)) {
1511 write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr);
1512 write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1);
1513
1514 adapter->dma_status = adapter->dma_status & ~0x00000001;
1515 }
1516 //disable dma2
1517 if (((dma_mask & 2) != 0) && ((adapter->dma_status & 2) != 0) && (adapter->dmaq2.bus_addr != 0)) {
1518 write_reg_dw(adapter, 0x010, adapter->dmaq2.bus_addr);
1519
1520 adapter->dma_status = adapter->dma_status & ~0x00000002;
1521 }
1522 }
1523}
1524
1525static void open_stream(struct adapter *adapter, u16 pid)
1526{
1527 u32 dma_mask;
1528
1529 ++adapter->capturing;
1530
1531 filter_enable_mask_filter(adapter, 1);
1532
1533 add_pid(adapter, pid);
1534
1535 dprintk("%s: adapter->dma_status=%x\n", __FUNCTION__, adapter->dma_status);
1536
1537 if ((adapter->dma_status & 7) != 7) {
1538 dma_mask = 0;
1539
1540 if (((adapter->dma_status & 0x10000000) != 0) && ((adapter->dma_status & 1) == 0)) {
1541 dma_mask = dma_mask | 1;
1542
1543 adapter->dmaq1.head = 0;
1544 adapter->dmaq1.tail = 0;
1545
1546 memset(adapter->dmaq1.buffer, 0, adapter->dmaq1.buffer_size);
1547 }
1548
1549 if (((adapter->dma_status & 0x20000000) != 0) && ((adapter->dma_status & 2) == 0)) {
1550 dma_mask = dma_mask | 2;
1551
1552 adapter->dmaq2.head = 0;
1553 adapter->dmaq2.tail = 0;
1554 }
1555
1556 if (dma_mask != 0) {
1557 irq_dma_enable_disable_irq(adapter, 1);
1558
1559 dma_start_stop(adapter, dma_mask, 1);
1560 }
1561 }
1562}
1563
1564static void close_stream(struct adapter *adapter, u16 pid)
1565{
1566 if (adapter->capturing > 0)
1567 --adapter->capturing;
1568
1569 dprintk("%s: dma_status=%x\n", __FUNCTION__, adapter->dma_status);
1570
1571 if (adapter->capturing == 0) {
1572 u32 dma_mask = 0;
1573
1574 if ((adapter->dma_status & 1) != 0)
1575 dma_mask = dma_mask | 0x00000001;
1576 if ((adapter->dma_status & 2) != 0)
1577 dma_mask = dma_mask | 0x00000002;
1578
1579 if (dma_mask != 0) {
1580 dma_start_stop(adapter, dma_mask, 0);
1581 }
1582 }
1583 remove_pid(adapter, pid);
1584}
1585
1586static void interrupt_service_dma1(struct adapter *adapter)
1587{
1588 struct dvb_demux *dvbdmx = &adapter->demux;
1589
1590 int n_cur_dma_counter;
1591 u32 n_num_bytes_parsed;
1592 u32 n_num_new_bytes_transferred;
1593 u32 dw_default_packet_size = 188;
1594 u8 gb_tmp_buffer[188];
1595 u8 *pb_dma_buf_cur_pos;
1596
1597 n_cur_dma_counter = readl(adapter->io_mem + 0x008) - adapter->dmaq1.bus_addr;
1598 n_cur_dma_counter = (n_cur_dma_counter / dw_default_packet_size) * dw_default_packet_size;
1599
1600 if ((n_cur_dma_counter < 0) || (n_cur_dma_counter > adapter->dmaq1.buffer_size)) {
1601 dprintk("%s: dma counter outside dma buffer\n", __FUNCTION__);
1602 return;
1603 }
1604
1605 adapter->dmaq1.head = n_cur_dma_counter;
1606
1607 if (adapter->dmaq1.tail <= n_cur_dma_counter) {
1608 n_num_new_bytes_transferred = n_cur_dma_counter - adapter->dmaq1.tail;
1609
1610 } else {
1611
1612 n_num_new_bytes_transferred = (adapter->dmaq1.buffer_size - adapter->dmaq1.tail) + n_cur_dma_counter;
1613 }
1614
1615 ddprintk("%s: n_cur_dma_counter = %d\n", __FUNCTION__, n_cur_dma_counter);
1616 ddprintk("%s: dmaq1.tail = %d\n", __FUNCTION__, adapter->dmaq1.tail);
1617 ddprintk("%s: bytes_transferred = %d\n", __FUNCTION__, n_num_new_bytes_transferred);
1618
1619 if (n_num_new_bytes_transferred < dw_default_packet_size)
1620 return;
1621
1622 n_num_bytes_parsed = 0;
1623
1624 while (n_num_bytes_parsed < n_num_new_bytes_transferred) {
1625 pb_dma_buf_cur_pos = adapter->dmaq1.buffer + adapter->dmaq1.tail;
1626
1627 if (adapter->dmaq1.buffer + adapter->dmaq1.buffer_size < adapter->dmaq1.buffer + adapter->dmaq1.tail + 188) {
1628 memcpy(gb_tmp_buffer, adapter->dmaq1.buffer + adapter->dmaq1.tail,
1629 adapter->dmaq1.buffer_size - adapter->dmaq1.tail);
1630 memcpy(gb_tmp_buffer + (adapter->dmaq1.buffer_size - adapter->dmaq1.tail), adapter->dmaq1.buffer,
1631 (188 - (adapter->dmaq1.buffer_size - adapter->dmaq1.tail)));
1632
1633 pb_dma_buf_cur_pos = gb_tmp_buffer;
1634 }
1635
1636 if (adapter->capturing != 0) {
1637 dvb_dmx_swfilter_packets(dvbdmx, pb_dma_buf_cur_pos, dw_default_packet_size / 188);
1638 }
1639
1640 n_num_bytes_parsed = n_num_bytes_parsed + dw_default_packet_size;
1641
1642 adapter->dmaq1.tail = adapter->dmaq1.tail + dw_default_packet_size;
1643
1644 if (adapter->dmaq1.tail >= adapter->dmaq1.buffer_size)
1645 adapter->dmaq1.tail = adapter->dmaq1.tail - adapter->dmaq1.buffer_size;
1646 };
1647}
1648
1649static void interrupt_service_dma2(struct adapter *adapter)
1650{
1651 printk("%s:\n", __FUNCTION__);
1652}
1653
1654static irqreturn_t isr(int irq, void *dev_id, struct pt_regs *regs)
1655{
1656 struct adapter *tmp = dev_id;
1657
1658 u32 value;
1659
1660 ddprintk("%s:\n", __FUNCTION__);
1661
1662 spin_lock_irq(&tmp->lock);
1663
1664 if (0 == ((value = read_reg_dw(tmp, 0x20c)) & 0x0f)) {
1665 spin_unlock_irq(&tmp->lock);
1666 return IRQ_NONE;
1667 }
1668
1669 while (value != 0) {
1670 if ((value & 0x03) != 0)
1671 interrupt_service_dma1(tmp);
1672 if ((value & 0x0c) != 0)
1673 interrupt_service_dma2(tmp);
1674 value = read_reg_dw(tmp, 0x20c) & 0x0f;
1675 }
1676
1677 spin_unlock_irq(&tmp->lock);
1678 return IRQ_HANDLED;
1679}
1680
1681static int init_dma_queue_one(struct adapter *adapter, struct dmaq *dmaq,
1682 int size, int dmaq_offset)
1683{
1684 struct pci_dev *pdev = adapter->pdev;
1685 dma_addr_t dma_addr;
1686
1687 dmaq->head = 0;
1688 dmaq->tail = 0;
1689
1690 dmaq->buffer = pci_alloc_consistent(pdev, size + 0x80, &dma_addr);
1691 if (!dmaq->buffer)
1692 return -ENOMEM;
1693
1694 dmaq->bus_addr = dma_addr;
1695 dmaq->buffer_size = size;
1696
1697 dma_init_dma(adapter, dmaq_offset);
1698
1699 ddprintk("%s: allocated dma buffer at 0x%p, length=%d\n",
1700 __FUNCTION__, dmaq->buffer, size);
1701
1702 return 0;
1703 }
1704
1705static int init_dma_queue(struct adapter *adapter)
1706{
1707 struct {
1708 struct dmaq *dmaq;
1709 u32 dma_status;
1710 int size;
1711 } dmaq_desc[] = {
1712 { &adapter->dmaq1, 0x10000000, SIZE_OF_BUF_DMA1 },
1713 { &adapter->dmaq2, 0x20000000, SIZE_OF_BUF_DMA2 }
1714 }, *p = dmaq_desc;
1715 int i;
1716
1717 for (i = 0; i < 2; i++, p++) {
1718 if (init_dma_queue_one(adapter, p->dmaq, p->size, i) < 0)
1719 adapter->dma_status &= ~p->dma_status;
1720 else
1721 adapter->dma_status |= p->dma_status;
1722 }
1723 return (adapter->dma_status & 0x30000000) ? 0 : -ENOMEM;
1724}
1725
1726static void free_dma_queue_one(struct adapter *adapter, struct dmaq *dmaq)
1727{
1728 if (dmaq->buffer) {
1729 pci_free_consistent(adapter->pdev, dmaq->buffer_size + 0x80,
1730 dmaq->buffer, dmaq->bus_addr);
1731 memset(dmaq, 0, sizeof(*dmaq));
1732 }
1733}
1734
1735static void free_dma_queue(struct adapter *adapter)
1736{
1737 struct dmaq *dmaq[] = {
1738 &adapter->dmaq1,
1739 &adapter->dmaq2,
1740 NULL
1741 }, **p;
1742
1743 for (p = dmaq; *p; p++)
1744 free_dma_queue_one(adapter, *p);
1745 }
1746
1747static void release_adapter(struct adapter *adapter)
1748{
1749 struct pci_dev *pdev = adapter->pdev;
1750
1751 iounmap(adapter->io_mem);
1752 pci_disable_device(pdev);
1753 pci_release_region(pdev, 0);
1754 pci_release_region(pdev, 1);
1755}
1756
1757static void free_adapter_object(struct adapter *adapter)
1758{
1759 dprintk("%s:\n", __FUNCTION__);
1760
1761 close_stream(adapter, 0);
1762 free_irq(adapter->irq, adapter);
1763 free_dma_queue(adapter);
1764 release_adapter(adapter);
1765 kfree(adapter);
1766}
1767
1768static struct pci_driver skystar2_pci_driver;
1769
1770static int claim_adapter(struct adapter *adapter)
1771{
1772 struct pci_dev *pdev = adapter->pdev;
1773 u16 var;
1774 int ret;
1775
1776 ret = pci_request_region(pdev, 1, skystar2_pci_driver.name);
1777 if (ret < 0)
1778 goto out;
1779
1780 ret = pci_request_region(pdev, 0, skystar2_pci_driver.name);
1781 if (ret < 0)
1782 goto err_pci_release_1;
1783
1784 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &adapter->card_revision);
1785
1786 dprintk("%s: card revision %x \n", __FUNCTION__, adapter->card_revision);
1787
1788 ret = pci_enable_device(pdev);
1789 if (ret < 0)
1790 goto err_pci_release_0;
1791
1792 pci_read_config_word(pdev, 4, &var);
1793
1794 if ((var & 4) == 0)
1795 pci_set_master(pdev);
1796
1797 adapter->io_port = pdev->resource[1].start;
1798
1799 adapter->io_mem = ioremap(pdev->resource[0].start, 0x800);
1800
1801 if (!adapter->io_mem) {
1802 dprintk("%s: can not map io memory\n", __FUNCTION__);
1803 ret = -EIO;
1804 goto err_pci_disable;
1805 }
1806
1807 dprintk("%s: io memory maped at %p\n", __FUNCTION__, adapter->io_mem);
1808
1809 ret = 1;
1810out:
1811 return ret;
1812
1813err_pci_disable:
1814 pci_disable_device(pdev);
1815err_pci_release_0:
1816 pci_release_region(pdev, 0);
1817err_pci_release_1:
1818 pci_release_region(pdev, 1);
1819 goto out;
1820}
1821
1822/*
1823static int sll_reset_flexcop(struct adapter *adapter)
1824{
1825 write_reg_dw(adapter, 0x208, 0);
1826 write_reg_dw(adapter, 0x210, 0xb2ff);
1827
1828 return 0;
1829}
1830*/
1831
1832static void decide_how_many_hw_filters(struct adapter *adapter)
1833{
1834 int hw_filters;
1835 int mod_option_hw_filters;
1836
1837 // FlexCop IIb & III have 6+32 hw filters
1838 // FlexCop II has 6 hw filters, every other should have at least 6
1839 switch (adapter->b2c2_revision) {
1840 case 0x82: /* II */
1841 hw_filters = 6;
1842 break;
1843 case 0xc3: /* IIB */
1844 hw_filters = 6 + 32;
1845 break;
1846 case 0xc0: /* III */
1847 hw_filters = 6 + 32;
1848 break;
1849 default:
1850 hw_filters = 6;
1851 break;
1852 }
1853 printk("%s: the chip has %i hardware filters", __FILE__, hw_filters);
1854
1855 mod_option_hw_filters = 0;
1856 if (enable_hw_filters >= 1)
1857 mod_option_hw_filters += 6;
1858 if (enable_hw_filters >= 2)
1859 mod_option_hw_filters += 32;
1860
1861 if (mod_option_hw_filters >= hw_filters) {
1862 adapter->useable_hw_filters = hw_filters;
1863 } else {
1864 adapter->useable_hw_filters = mod_option_hw_filters;
1865 printk(", but only %d will be used because of module option", mod_option_hw_filters);
1866 }
1867 printk("\n");
1868 dprintk("%s: useable_hardware_filters set to %i\n", __FILE__, adapter->useable_hw_filters);
1869}
1870
1871static int driver_initialize(struct pci_dev *pdev)
1872{
1873 struct adapter *adapter;
1874 u32 tmp;
1875 int ret = -ENOMEM;
1876
1877 adapter = kmalloc(sizeof(struct adapter), GFP_KERNEL);
1878 if (!adapter) {
1879 dprintk("%s: out of memory!\n", __FUNCTION__);
1880 goto out;
1881 }
1882
1883 memset(adapter, 0, sizeof(struct adapter));
1884
1885 pci_set_drvdata(pdev,adapter);
1886
1887 adapter->pdev = pdev;
1888 adapter->irq = pdev->irq;
1889
1890 ret = claim_adapter(adapter);
1891 if (ret < 0)
1892 goto err_kfree;
1893
1894 irq_dma_enable_disable_irq(adapter, 0);
1895
1896 ret = request_irq(pdev->irq, isr, 0x4000000, "Skystar2", adapter);
1897 if (ret < 0) {
1898 dprintk("%s: unable to allocate irq=%d !\n", __FUNCTION__, pdev->irq);
1899 goto err_release_adapter;
1900 }
1901
1902 read_reg_dw(adapter, 0x208);
1903 write_reg_dw(adapter, 0x208, 0);
1904 write_reg_dw(adapter, 0x210, 0xb2ff);
1905 write_reg_dw(adapter, 0x208, 0x40);
1906
1907 ret = init_dma_queue(adapter);
1908 if (ret < 0)
1909 goto err_free_irq;
1910
1911 adapter->b2c2_revision = (read_reg_dw(adapter, 0x204) >> 0x18);
1912
1913 switch (adapter->b2c2_revision) {
1914 case 0x82:
1915 printk("%s: FlexCopII(rev.130) chip found\n", __FILE__);
1916 break;
1917 case 0xc3:
1918 printk("%s: FlexCopIIB(rev.195) chip found\n", __FILE__);
1919 break;
1920 case 0xc0:
1921 printk("%s: FlexCopIII(rev.192) chip found\n", __FILE__);
1922 break;
1923 default:
1924 printk("%s: The revision of the FlexCop chip on your card is %d\n", __FILE__, adapter->b2c2_revision);
1925 printk("%s: This driver works only with FlexCopII(rev.130), FlexCopIIB(rev.195) and FlexCopIII(rev.192).\n", __FILE__);
1926 ret = -ENODEV;
1927 goto err_free_dma_queue;
1928 }
1929
1930 decide_how_many_hw_filters(adapter);
1931
1932 init_pids(adapter);
1933
1934 tmp = read_reg_dw(adapter, 0x204);
1935
1936 write_reg_dw(adapter, 0x204, 0);
1937 mdelay(20);
1938
1939 write_reg_dw(adapter, 0x204, tmp);
1940 mdelay(10);
1941
1942 tmp = read_reg_dw(adapter, 0x308);
1943 write_reg_dw(adapter, 0x308, 0x4000 | tmp);
1944
1945 adapter->dw_sram_type = 0x10000;
1946
1947 sll_detect_sram_size(adapter);
1948
1949 dprintk("%s sram length = %d, sram type= %x\n", __FUNCTION__, sram_length(adapter), adapter->dw_sram_type);
1950
1951 sram_set_media_dest(adapter, 1);
1952 sram_set_net_dest(adapter, 1);
1953
1954 ctrl_enable_smc(adapter, 0);
1955
1956 sram_set_cai_dest(adapter, 2);
1957 sram_set_cao_dest(adapter, 2);
1958
1959 dma_enable_disable_irq(adapter, 1, 0, 0);
1960
1961 if (eeprom_get_mac_addr(adapter, 0, adapter->mac_addr) != 0) {
1962 printk("%s MAC address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n", __FUNCTION__, adapter->mac_addr[0],
1963 adapter->mac_addr[1], adapter->mac_addr[2], adapter->mac_addr[3], adapter->mac_addr[4], adapter->mac_addr[5],
1964 adapter->mac_addr[6], adapter->mac_addr[7]
1965 );
1966
1967 ca_set_mac_dst_addr_filter(adapter, adapter->mac_addr);
1968 ctrl_enable_mac(adapter, 1);
1969 }
1970
1971 spin_lock_init(&adapter->lock);
1972
1973out:
1974 return ret;
1975
1976err_free_dma_queue:
1977 free_dma_queue(adapter);
1978err_free_irq:
1979 free_irq(pdev->irq, adapter);
1980err_release_adapter:
1981 release_adapter(adapter);
1982err_kfree:
1983 pci_set_drvdata(pdev, NULL);
1984 kfree(adapter);
1985 goto out;
1986}
1987
1988static void driver_halt(struct pci_dev *pdev)
1989{
1990 struct adapter *adapter = pci_get_drvdata(pdev);
1991
1992 irq_dma_enable_disable_irq(adapter, 0);
1993
1994 ctrl_enable_receive_data(adapter, 0);
1995
1996 free_adapter_object(adapter);
1997
1998 pci_set_drvdata(pdev, NULL);
1999}
2000
2001static int dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
2002{
2003 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
2004 struct adapter *adapter = (struct adapter *) dvbdmx->priv;
2005
2006 dprintk("%s: PID=%d, type=%d\n", __FUNCTION__, dvbdmxfeed->pid, dvbdmxfeed->type);
2007
2008 open_stream(adapter, dvbdmxfeed->pid);
2009
2010 return 0;
2011}
2012
2013static int dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
2014{
2015 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
2016 struct adapter *adapter = (struct adapter *) dvbdmx->priv;
2017
2018 dprintk("%s: PID=%d, type=%d\n", __FUNCTION__, dvbdmxfeed->pid, dvbdmxfeed->type);
2019
2020 close_stream(adapter, dvbdmxfeed->pid);
2021
2022 return 0;
2023}
2024
2025/* lnb control */
2026static void set_tuner_tone(struct adapter *adapter, u8 tone)
2027{
2028 u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc };
2029 u16 ax;
2030
2031 dprintk("%s: %u\n", __FUNCTION__, tone);
2032
2033 switch (tone) {
2034 case 1:
2035 ax = wz_half_period_for_45_mhz[0];
2036 break;
2037 case 2:
2038 ax = wz_half_period_for_45_mhz[1];
2039 break;
2040 case 3:
2041 ax = wz_half_period_for_45_mhz[2];
2042 break;
2043 case 4:
2044 ax = wz_half_period_for_45_mhz[3];
2045 break;
2046
2047 default:
2048 ax = 0;
2049 }
2050
2051 if (ax != 0) {
2052 write_reg_dw(adapter, 0x200, ((ax << 0x0f) + (ax & 0x7fff)) | 0x40000000);
2053
2054 } else {
2055
2056 write_reg_dw(adapter, 0x200, 0x40ff8000);
2057 }
2058}
2059
2060static void set_tuner_polarity(struct adapter *adapter, u8 polarity)
2061{
2062 u32 var;
2063
2064 dprintk("%s : polarity = %u \n", __FUNCTION__, polarity);
2065
2066 var = read_reg_dw(adapter, 0x204);
2067
2068 if (polarity == 0) {
2069 dprintk("%s: LNB power off\n", __FUNCTION__);
2070 var = var | 1;
2071 };
2072
2073 if (polarity == 1) {
2074 var = var & ~1;
2075 var = var & ~4;
2076 };
2077
2078 if (polarity == 2) {
2079 var = var & ~1;
2080 var = var | 4;
2081 }
2082
2083 write_reg_dw(adapter, 0x204, var);
2084}
2085
2086static void diseqc_send_bit(struct adapter *adapter, int data)
2087{
2088 set_tuner_tone(adapter, 1);
2089 udelay(data ? 500 : 1000);
2090 set_tuner_tone(adapter, 0);
2091 udelay(data ? 1000 : 500);
2092}
2093
2094
2095static void diseqc_send_byte(struct adapter *adapter, int data)
2096 {
2097 int i, par = 1, d;
2098
2099 for (i = 7; i >= 0; i--) {
2100 d = (data >> i) & 1;
2101 par ^= d;
2102 diseqc_send_bit(adapter, d);
2103 }
2104
2105 diseqc_send_bit(adapter, par);
2106 }
2107
2108
2109static int send_diseqc_msg(struct adapter *adapter, int len, u8 *msg, unsigned long burst)
2110{
2111 int i;
2112
2113 set_tuner_tone(adapter, 0);
2114 mdelay(16);
2115
2116 for (i = 0; i < len; i++)
2117 diseqc_send_byte(adapter, msg[i]);
2118
2119 mdelay(16);
2120
2121 if (burst != -1) {
2122 if (burst)
2123 diseqc_send_byte(adapter, 0xff);
2124 else {
2125 set_tuner_tone(adapter, 1);
2126 udelay(12500);
2127 set_tuner_tone(adapter, 0);
2128 }
2129 msleep(20);
2130 }
2131
2132 return 0;
2133}
2134
2135static int flexcop_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
2136{
2137 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2138
2139 switch(tone) {
2140 case SEC_TONE_ON:
2141 set_tuner_tone(adapter, 1);
2142 break;
2143 case SEC_TONE_OFF:
2144 set_tuner_tone(adapter, 0);
2145 break;
2146 default:
2147 return -EINVAL;
2148 };
2149
2150 return 0;
2151}
2152
2153static int flexcop_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
2154 {
2155 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2156
2157 send_diseqc_msg(adapter, cmd->msg_len, cmd->msg, 0);
2158
2159 return 0;
2160 }
2161
2162static int flexcop_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
2163{
2164 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2165
2166 send_diseqc_msg(adapter, 0, NULL, minicmd);
2167
2168 return 0;
2169}
2170
2171static int flexcop_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
2172 {
2173 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2174
2175 dprintk("%s: FE_SET_VOLTAGE\n", __FUNCTION__);
2176
2177 switch (voltage) {
2178 case SEC_VOLTAGE_13:
2179 dprintk("%s: SEC_VOLTAGE_13, %x\n", __FUNCTION__, SEC_VOLTAGE_13);
2180 set_tuner_polarity(adapter, 1);
2181 return 0;
2182
2183 case SEC_VOLTAGE_18:
2184 dprintk("%s: SEC_VOLTAGE_18, %x\n", __FUNCTION__, SEC_VOLTAGE_18);
2185 set_tuner_polarity(adapter, 2);
2186 return 0;
2187
2188 default:
2189 return -EINVAL;
2190 }
2191 }
2192
2193static int flexcop_sleep(struct dvb_frontend* fe)
2194 {
2195 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2196
2197 dprintk("%s: FE_SLEEP\n", __FUNCTION__);
2198 set_tuner_polarity(adapter, 0);
2199
2200 if (adapter->fe_sleep) return adapter->fe_sleep(fe);
2201 return 0;
2202 }
2203
2204static u32 flexcop_i2c_func(struct i2c_adapter *adapter)
2205 {
2206 printk("flexcop_i2c_func\n");
2207
2208 return I2C_FUNC_I2C;
2209}
2210
2211static struct i2c_algorithm flexcop_algo = {
2212 .name = "flexcop i2c algorithm",
2213 .id = I2C_ALGO_BIT,
2214 .master_xfer = master_xfer,
2215 .functionality = flexcop_i2c_func,
2216};
2217
2218
2219
2220
2221static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
2222{
2223 u8 aclk = 0;
2224 u8 bclk = 0;
2225
2226 if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; }
2227 else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; }
2228 else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; }
2229 else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; }
2230 else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; }
2231 else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; }
2232
2233 stv0299_writereg (fe, 0x13, aclk);
2234 stv0299_writereg (fe, 0x14, bclk);
2235 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
2236 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
2237 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
2238
2239 return 0;
2240}
2241
2242static int samsung_tbmu24112_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
2243{
2244 u8 buf[4];
2245 u32 div;
2246 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
2247 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2248
2249 div = params->frequency / 125;
2250
2251 buf[0] = (div >> 8) & 0x7f;
2252 buf[1] = div & 0xff;
2253 buf[2] = 0x84; // 0xC4
2254 buf[3] = 0x08;
2255
2256 if (params->frequency < 1500000) buf[3] |= 0x10;
2257
2258 if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
2259 return 0;
2260}
2261
2262static u8 samsung_tbmu24112_inittab[] = {
2263 0x01, 0x15,
2264 0x02, 0x30,
2265 0x03, 0x00,
2266 0x04, 0x7D,
2267 0x05, 0x35,
2268 0x06, 0x02,
2269 0x07, 0x00,
2270 0x08, 0xC3,
2271 0x0C, 0x00,
2272 0x0D, 0x81,
2273 0x0E, 0x23,
2274 0x0F, 0x12,
2275 0x10, 0x7E,
2276 0x11, 0x84,
2277 0x12, 0xB9,
2278 0x13, 0x88,
2279 0x14, 0x89,
2280 0x15, 0xC9,
2281 0x16, 0x00,
2282 0x17, 0x5C,
2283 0x18, 0x00,
2284 0x19, 0x00,
2285 0x1A, 0x00,
2286 0x1C, 0x00,
2287 0x1D, 0x00,
2288 0x1E, 0x00,
2289 0x1F, 0x3A,
2290 0x20, 0x2E,
2291 0x21, 0x80,
2292 0x22, 0xFF,
2293 0x23, 0xC1,
2294 0x28, 0x00,
2295 0x29, 0x1E,
2296 0x2A, 0x14,
2297 0x2B, 0x0F,
2298 0x2C, 0x09,
2299 0x2D, 0x05,
2300 0x31, 0x1F,
2301 0x32, 0x19,
2302 0x33, 0xFE,
2303 0x34, 0x93,
2304 0xff, 0xff,
2305 };
2306
2307static struct stv0299_config samsung_tbmu24112_config = {
2308 .demod_address = 0x68,
2309 .inittab = samsung_tbmu24112_inittab,
2310 .mclk = 88000000UL,
2311 .invert = 0,
2312 .enhanced_tuning = 0,
2313 .skip_reinit = 0,
2314 .lock_output = STV0229_LOCKOUTPUT_LK,
2315 .volt13_op0_op1 = STV0299_VOLT13_OP1,
2316 .min_delay_ms = 100,
2317 .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
2318 .pll_set = samsung_tbmu24112_pll_set,
2319};
2320
2321
2322
2323static int nxt2002_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
2324{
2325 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2326
2327 return request_firmware(fw, name, &adapter->pdev->dev);
2328}
2329
2330
2331static struct nxt2002_config samsung_tbmv_config = {
2332 .demod_address = 0x0A,
2333 .request_firmware = nxt2002_request_firmware,
2334};
2335
2336static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
2337{
2338 static u8 mt352_clock_config [] = { 0x89, 0x18, 0x2d };
2339 static u8 mt352_reset [] = { 0x50, 0x80 };
2340 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
2341 static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0xa1 };
2342 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
2343
2344 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
2345 udelay(2000);
2346 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
2347 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
2348
2349 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
2350 mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
2351
2352 return 0;
2353}
2354
2355static int samsung_tdtc9251dh0_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf)
2356{
2357 u32 div;
2358 unsigned char bs = 0;
2359
2360 #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
2361 div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
2362
2363 if (params->frequency >= 48000000 && params->frequency <= 154000000) bs = 0x09;
2364 if (params->frequency >= 161000000 && params->frequency <= 439000000) bs = 0x0a;
2365 if (params->frequency >= 447000000 && params->frequency <= 863000000) bs = 0x08;
2366
2367 pllbuf[0] = 0xc2; // Note: non-linux standard PLL i2c address
2368 pllbuf[1] = div >> 8;
2369 pllbuf[2] = div & 0xff;
2370 pllbuf[3] = 0xcc;
2371 pllbuf[4] = bs;
2372
2373 return 0;
2374}
2375
2376static struct mt352_config samsung_tdtc9251dh0_config = {
2377
2378 .demod_address = 0x0f,
2379 .demod_init = samsung_tdtc9251dh0_demod_init,
2380 .pll_set = samsung_tdtc9251dh0_pll_set,
2381};
2382
2383static int skystar23_samsung_tbdu18132_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
2384{
2385 u8 buf[4];
2386 u32 div;
2387 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
2388 struct adapter* adapter = (struct adapter*) fe->dvb->priv;
2389
2390 div = (params->frequency + (125/2)) / 125;
2391
2392 buf[0] = (div >> 8) & 0x7f;
2393 buf[1] = (div >> 0) & 0xff;
2394 buf[2] = 0x84 | ((div >> 10) & 0x60);
2395 buf[3] = 0x80;
2396
2397 if (params->frequency < 1550000)
2398 buf[3] |= 0x02;
2399
2400 if (i2c_transfer (&adapter->i2c_adap, &msg, 1) != 1) return -EIO;
2401 return 0;
2402}
2403
2404static struct mt312_config skystar23_samsung_tbdu18132_config = {
2405
2406 .demod_address = 0x0e,
2407 .pll_set = skystar23_samsung_tbdu18132_pll_set,
2408};
2409
2410
2411
2412
2413static void frontend_init(struct adapter *skystar2)
2414{
2415 switch(skystar2->pdev->device) {
2416 case 0x2103: // Technisat Skystar2 OR Technisat Airstar2 (DVB-T or ATSC)
2417
2418 // Attempt to load the Nextwave nxt2002 for ATSC support
2419 skystar2->fe = nxt2002_attach(&samsung_tbmv_config, &skystar2->i2c_adap);
2420 if (skystar2->fe != NULL) {
2421 skystar2->fe_sleep = skystar2->fe->ops->sleep;
2422 skystar2->fe->ops->sleep = flexcop_sleep;
2423 break;
2424 }
2425
2426 // try the skystar2 v2.6 first (stv0299/Samsung tbmu24112(sl1935))
2427 skystar2->fe = stv0299_attach(&samsung_tbmu24112_config, &skystar2->i2c_adap);
2428 if (skystar2->fe != NULL) {
2429 skystar2->fe->ops->set_voltage = flexcop_set_voltage;
2430 skystar2->fe_sleep = skystar2->fe->ops->sleep;
2431 skystar2->fe->ops->sleep = flexcop_sleep;
2432 break;
2433}
2434
2435 // try the airstar2 (mt352/Samsung tdtc9251dh0(??))
2436 skystar2->fe = mt352_attach(&samsung_tdtc9251dh0_config, &skystar2->i2c_adap);
2437 if (skystar2->fe != NULL) {
2438 skystar2->fe->ops->info.frequency_min = 474000000;
2439 skystar2->fe->ops->info.frequency_max = 858000000;
2440 break;
2441 }
2442
2443 // try the skystar2 v2.3 (vp310/Samsung tbdu18132(tsa5059))
2444 skystar2->fe = vp310_attach(&skystar23_samsung_tbdu18132_config, &skystar2->i2c_adap);
2445 if (skystar2->fe != NULL) {
2446 skystar2->fe->ops->diseqc_send_master_cmd = flexcop_diseqc_send_master_cmd;
2447 skystar2->fe->ops->diseqc_send_burst = flexcop_diseqc_send_burst;
2448 skystar2->fe->ops->set_tone = flexcop_set_tone;
2449 skystar2->fe->ops->set_voltage = flexcop_set_voltage;
2450 skystar2->fe_sleep = skystar2->fe->ops->sleep;
2451 skystar2->fe->ops->sleep = flexcop_sleep;
2452 break;
2453 }
2454 break;
2455 }
2456
2457 if (skystar2->fe == NULL) {
2458 printk("skystar2: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
2459 skystar2->pdev->vendor,
2460 skystar2->pdev->device,
2461 skystar2->pdev->subsystem_vendor,
2462 skystar2->pdev->subsystem_device);
2463 } else {
2464 if (dvb_register_frontend(&skystar2->dvb_adapter, skystar2->fe)) {
2465 printk("skystar2: Frontend registration failed!\n");
2466 if (skystar2->fe->ops->release)
2467 skystar2->fe->ops->release(skystar2->fe);
2468 skystar2->fe = NULL;
2469 }
2470 }
2471}
2472
2473
2474static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2475{
2476 struct adapter *adapter;
2477 struct dvb_adapter *dvb_adapter;
2478 struct dvb_demux *dvbdemux;
2479 struct dmx_demux *dmx;
2480 int ret = -ENODEV;
2481
2482 if (!pdev)
2483 goto out;
2484
2485 ret = driver_initialize(pdev);
2486 if (ret < 0)
2487 goto out;
2488
2489 adapter = pci_get_drvdata(pdev);
2490 dvb_adapter = &adapter->dvb_adapter;
2491
2492 ret = dvb_register_adapter(dvb_adapter, skystar2_pci_driver.name,
2493 THIS_MODULE);
2494 if (ret < 0) {
2495 printk("%s: Error registering DVB adapter\n", __FUNCTION__);
2496 goto err_halt;
2497 }
2498
2499 dvb_adapter->priv = adapter;
2500
2501
2502 init_MUTEX(&adapter->i2c_sem);
2503
2504
2505 memset(&adapter->i2c_adap, 0, sizeof(struct i2c_adapter));
2506 strcpy(adapter->i2c_adap.name, "SkyStar2");
2507
2508 i2c_set_adapdata(&adapter->i2c_adap, adapter);
2509
2510#ifdef I2C_ADAP_CLASS_TV_DIGITAL
2511 adapter->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL;
2512#else
2513 adapter->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
2514#endif
2515 adapter->i2c_adap.algo = &flexcop_algo;
2516 adapter->i2c_adap.algo_data = NULL;
2517 adapter->i2c_adap.id = I2C_ALGO_BIT;
2518
2519 ret = i2c_add_adapter(&adapter->i2c_adap);
2520 if (ret < 0)
2521 goto err_dvb_unregister;
2522
2523 dvbdemux = &adapter->demux;
2524
2525 dvbdemux->priv = adapter;
2526 dvbdemux->filternum = N_PID_SLOTS;
2527 dvbdemux->feednum = N_PID_SLOTS;
2528 dvbdemux->start_feed = dvb_start_feed;
2529 dvbdemux->stop_feed = dvb_stop_feed;
2530 dvbdemux->write_to_decoder = NULL;
2531 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
2532
2533 ret = dvb_dmx_init(&adapter->demux);
2534 if (ret < 0)
2535 goto err_i2c_del;
2536
2537 dmx = &dvbdemux->dmx;
2538
2539 adapter->hw_frontend.source = DMX_FRONTEND_0;
2540 adapter->dmxdev.filternum = N_PID_SLOTS;
2541 adapter->dmxdev.demux = dmx;
2542 adapter->dmxdev.capabilities = 0;
2543
2544 ret = dvb_dmxdev_init(&adapter->dmxdev, &adapter->dvb_adapter);
2545 if (ret < 0)
2546 goto err_dmx_release;
2547
2548 ret = dmx->add_frontend(dmx, &adapter->hw_frontend);
2549 if (ret < 0)
2550 goto err_dmxdev_release;
2551
2552 adapter->mem_frontend.source = DMX_MEMORY_FE;
2553
2554 ret = dmx->add_frontend(dmx, &adapter->mem_frontend);
2555 if (ret < 0)
2556 goto err_remove_hw_frontend;
2557
2558 ret = dmx->connect_frontend(dmx, &adapter->hw_frontend);
2559 if (ret < 0)
2560 goto err_remove_mem_frontend;
2561
2562 dvb_net_init(&adapter->dvb_adapter, &adapter->dvbnet, &dvbdemux->dmx);
2563
2564 frontend_init(adapter);
2565out:
2566 return ret;
2567
2568err_remove_mem_frontend:
2569 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &adapter->mem_frontend);
2570err_remove_hw_frontend:
2571 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &adapter->hw_frontend);
2572err_dmxdev_release:
2573 dvb_dmxdev_release(&adapter->dmxdev);
2574err_dmx_release:
2575 dvb_dmx_release(&adapter->demux);
2576err_i2c_del:
2577 i2c_del_adapter(&adapter->i2c_adap);
2578err_dvb_unregister:
2579 dvb_unregister_adapter(&adapter->dvb_adapter);
2580err_halt:
2581 driver_halt(pdev);
2582 goto out;
2583}
2584
2585static void skystar2_remove(struct pci_dev *pdev)
2586{
2587 struct adapter *adapter = pci_get_drvdata(pdev);
2588 struct dvb_demux *dvbdemux;
2589 struct dmx_demux *dmx;
2590
2591 if (!adapter)
2592 return;
2593
2594 dvb_net_release(&adapter->dvbnet);
2595 dvbdemux = &adapter->demux;
2596 dmx = &dvbdemux->dmx;
2597
2598 dmx->close(dmx);
2599 dmx->remove_frontend(dmx, &adapter->hw_frontend);
2600 dmx->remove_frontend(dmx, &adapter->mem_frontend);
2601
2602 dvb_dmxdev_release(&adapter->dmxdev);
2603 dvb_dmx_release(dvbdemux);
2604
2605 if (adapter->fe != NULL)
2606 dvb_unregister_frontend(adapter->fe);
2607
2608 dvb_unregister_adapter(&adapter->dvb_adapter);
2609
2610 i2c_del_adapter(&adapter->i2c_adap);
2611
2612 driver_halt(pdev);
2613 }
2614
2615static struct pci_device_id skystar2_pci_tbl[] = {
2616 {0x000013d0, 0x00002103, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000},
2617/* {0x000013d0, 0x00002200, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000}, UNDEFINED HARDWARE - mail linuxtv.org list */ //FCIII
2618 {0,},
2619};
2620
2621MODULE_DEVICE_TABLE(pci, skystar2_pci_tbl);
2622
2623static struct pci_driver skystar2_pci_driver = {
2624 .name = "SkyStar2",
2625 .id_table = skystar2_pci_tbl,
2626 .probe = skystar2_probe,
2627 .remove = skystar2_remove,
2628};
2629
2630static int skystar2_init(void)
2631{
2632 return pci_register_driver(&skystar2_pci_driver);
2633}
2634
2635static void skystar2_cleanup(void)
2636{
2637 pci_unregister_driver(&skystar2_pci_driver);
2638}
2639
2640module_init(skystar2_init);
2641module_exit(skystar2_cleanup);
2642
2643MODULE_DESCRIPTION("Technisat SkyStar2 DVB PCI Driver");
2644MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 1339912c308b..07a0b0a968a6 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -258,10 +258,10 @@ int write_dst(struct dst_state *state, u8 *data, u8 len)
258 if (debug && (verbose > 4)) { 258 if (debug && (verbose > 4)) {
259 u8 i; 259 u8 i;
260 if (verbose > 4) { 260 if (verbose > 4) {
261 dprintk("%s writing", __FUNCTION__); 261 dprintk("%s writing [ ", __FUNCTION__);
262 for (i = 0; i < len; i++) 262 for (i = 0; i < len; i++)
263 dprintk(" %02x", data[i]); 263 dprintk("%02x ", data[i]);
264 dprintk("\n"); 264 dprintk("]\n");
265 } 265 }
266 } 266 }
267 for (cnt = 0; cnt < 2; cnt++) { 267 for (cnt = 0; cnt < 2; cnt++) {
@@ -320,10 +320,29 @@ int read_dst(struct dst_state *state, u8 * ret, u8 len)
320} 320}
321EXPORT_SYMBOL(read_dst); 321EXPORT_SYMBOL(read_dst);
322 322
323static int dst_set_freq(struct dst_state *state, u32 freq) 323static int dst_set_polarization(struct dst_state *state)
324{ 324{
325 u8 *val; 325 switch (state->voltage) {
326 case SEC_VOLTAGE_13: // vertical
327 printk("%s: Polarization=[Vertical]\n", __FUNCTION__);
328 state->tx_tuna[8] &= ~0x40; //1
329 break;
330
331 case SEC_VOLTAGE_18: // horizontal
332 printk("%s: Polarization=[Horizontal]\n", __FUNCTION__);
333 state->tx_tuna[8] |= 0x40; // 0
334 break;
335
336 case SEC_VOLTAGE_OFF:
337
338 break;
339 }
340
341 return 0;
342}
326 343
344static int dst_set_freq(struct dst_state *state, u32 freq)
345{
327 state->frequency = freq; 346 state->frequency = freq;
328 if (debug > 4) 347 if (debug > 4)
329 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq); 348 dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
@@ -332,46 +351,30 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
332 freq = freq / 1000; 351 freq = freq / 1000;
333 if (freq < 950 || freq > 2150) 352 if (freq < 950 || freq > 2150)
334 return -EINVAL; 353 return -EINVAL;
335 val = &state->tx_tuna[0]; 354
336 val[2] = (freq >> 8) & 0x7f; 355 state->tx_tuna[2] = (freq >> 8);
337 val[3] = (u8) freq; 356 state->tx_tuna[3] = (u8) freq;
338 val[4] = 1; 357 state->tx_tuna[4] = 0x01;
339 val[8] &= ~4; 358 state->tx_tuna[8] &= ~0x04;
340 if (freq < 1531) 359 if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
341 val[8] |= 4; 360 if (freq < 1531)
361 state->tx_tuna[8] |= 0x04;
362 }
363
342 } else if (state->dst_type == DST_TYPE_IS_TERR) { 364 } else if (state->dst_type == DST_TYPE_IS_TERR) {
343 freq = freq / 1000; 365 freq = freq / 1000;
344 if (freq < 137000 || freq > 858000) 366 if (freq < 137000 || freq > 858000)
345 return -EINVAL; 367 return -EINVAL;
346 val = &state->tx_tuna[0];
347 val[2] = (freq >> 16) & 0xff;
348 val[3] = (freq >> 8) & 0xff;
349 val[4] = (u8) freq;
350 val[5] = 0;
351 switch (state->bandwidth) {
352 case BANDWIDTH_6_MHZ:
353 val[6] = 6;
354 break;
355 368
356 case BANDWIDTH_7_MHZ: 369 state->tx_tuna[2] = (freq >> 16) & 0xff;
357 case BANDWIDTH_AUTO: 370 state->tx_tuna[3] = (freq >> 8) & 0xff;
358 val[6] = 7; 371 state->tx_tuna[4] = (u8) freq;
359 break;
360 372
361 case BANDWIDTH_8_MHZ:
362 val[6] = 8;
363 break;
364 }
365
366 val[7] = 0;
367 val[8] = 0;
368 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 373 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
369 /* guess till will get one */ 374 state->tx_tuna[2] = (freq >> 16) & 0xff;
370 freq = freq / 1000; 375 state->tx_tuna[3] = (freq >> 8) & 0xff;
371 val = &state->tx_tuna[0]; 376 state->tx_tuna[4] = (u8) freq;
372 val[2] = (freq >> 16) & 0xff; 377
373 val[3] = (freq >> 8) & 0xff;
374 val[4] = (u8) freq;
375 } else 378 } else
376 return -EINVAL; 379 return -EINVAL;
377 return 0; 380 return 0;
@@ -379,51 +382,58 @@ static int dst_set_freq(struct dst_state *state, u32 freq)
379 382
380static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth) 383static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
381{ 384{
382 u8 *val;
383
384 state->bandwidth = bandwidth; 385 state->bandwidth = bandwidth;
385 386
386 if (state->dst_type != DST_TYPE_IS_TERR) 387 if (state->dst_type != DST_TYPE_IS_TERR)
387 return 0; 388 return 0;
388 389
389 val = &state->tx_tuna[0];
390 switch (bandwidth) { 390 switch (bandwidth) {
391 case BANDWIDTH_6_MHZ: 391 case BANDWIDTH_6_MHZ:
392 val[6] = 6; 392 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
393 break; 393 state->tx_tuna[7] = 0x06;
394 else {
395 state->tx_tuna[6] = 0x06;
396 state->tx_tuna[7] = 0x00;
397 }
398 break;
394 399
395 case BANDWIDTH_7_MHZ: 400 case BANDWIDTH_7_MHZ:
396 val[6] = 7; 401 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
397 break; 402 state->tx_tuna[7] = 0x07;
403 else {
404 state->tx_tuna[6] = 0x07;
405 state->tx_tuna[7] = 0x00;
406 }
407 break;
398 408
399 case BANDWIDTH_8_MHZ: 409 case BANDWIDTH_8_MHZ:
400 val[6] = 8; 410 if (state->dst_hw_cap & DST_TYPE_HAS_CA)
401 break; 411 state->tx_tuna[7] = 0x08;
412 else {
413 state->tx_tuna[6] = 0x08;
414 state->tx_tuna[7] = 0x00;
415 }
416 break;
402 417
403 default: 418 default:
404 return -EINVAL; 419 return -EINVAL;
405 } 420 }
406 return 0; 421 return 0;
407} 422}
408 423
409static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion) 424static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion)
410{ 425{
411 u8 *val;
412
413 state->inversion = inversion; 426 state->inversion = inversion;
414
415 val = &state->tx_tuna[0];
416
417 val[8] &= ~0x80;
418
419 switch (inversion) { 427 switch (inversion) {
420 case INVERSION_OFF: 428 case INVERSION_OFF: // Inversion = Normal
421 break; 429 state->tx_tuna[8] &= ~0x80;
422 case INVERSION_ON: 430 break;
423 val[8] |= 0x80; 431
424 break; 432 case INVERSION_ON:
425 default: 433 state->tx_tuna[8] |= 0x80;
426 return -EINVAL; 434 break;
435 default:
436 return -EINVAL;
427 } 437 }
428 return 0; 438 return 0;
429} 439}
@@ -478,6 +488,52 @@ static int dst_set_symbolrate(struct dst_state* state, u32 srate)
478 return 0; 488 return 0;
479} 489}
480 490
491
492static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
493{
494 if (state->dst_type != DST_TYPE_IS_CABLE)
495 return 0;
496
497 state->modulation = modulation;
498 switch (modulation) {
499 case QAM_16:
500 state->tx_tuna[8] = 0x10;
501 break;
502
503 case QAM_32:
504 state->tx_tuna[8] = 0x20;
505 break;
506
507 case QAM_64:
508 state->tx_tuna[8] = 0x40;
509 break;
510
511 case QAM_128:
512 state->tx_tuna[8] = 0x80;
513 break;
514
515 case QAM_256:
516 state->tx_tuna[8] = 0x00;
517 break;
518
519 case QPSK:
520 case QAM_AUTO:
521 case VSB_8:
522 case VSB_16:
523 default:
524 return -EINVAL;
525
526 }
527
528 return 0;
529}
530
531static fe_modulation_t dst_get_modulation(struct dst_state *state)
532{
533 return state->modulation;
534}
535
536
481u8 dst_check_sum(u8 * buf, u32 len) 537u8 dst_check_sum(u8 * buf, u32 len)
482{ 538{
483 u32 i; 539 u32 i;
@@ -577,7 +633,7 @@ struct dst_types dst_tlist[] = {
577 .device_id = "200103A", 633 .device_id = "200103A",
578 .offset = 0, 634 .offset = 0,
579 .dst_type = DST_TYPE_IS_SAT, 635 .dst_type = DST_TYPE_IS_SAT,
580 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1, 636 .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
581 .dst_feature = 0 637 .dst_feature = 0
582 }, /* obsolete */ 638 }, /* obsolete */
583 639
@@ -626,7 +682,7 @@ struct dst_types dst_tlist[] = {
626 .device_id = "DSTMCI", 682 .device_id = "DSTMCI",
627 .offset = 1, 683 .offset = 1,
628 .dst_type = DST_TYPE_IS_SAT, 684 .dst_type = DST_TYPE_IS_SAT,
629 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD, 685 .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
630 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 686 .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
631 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC 687 | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
632 }, 688 },
@@ -872,7 +928,7 @@ static int dst_get_signal(struct dst_state* state)
872{ 928{
873 int retval; 929 int retval;
874 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; 930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
875 931 dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
876 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { 932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
877 state->decode_lock = state->decode_strength = state->decode_snr = 0; 933 state->decode_lock = state->decode_strength = state->decode_snr = 0;
878 return 0; 934 return 0;
@@ -954,15 +1010,8 @@ static int dst_get_tuna(struct dst_state* state)
954 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3]; 1010 state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
955 1011
956 state->decode_lock = 1; 1012 state->decode_lock = 1;
957 /*
958 dst->decode_n1 = (dst->rx_tuna[4] << 8) +
959 (dst->rx_tuna[5]);
960
961 dst->decode_n2 = (dst->rx_tuna[8] << 8) +
962 (dst->rx_tuna[7]);
963 */
964 state->diseq_flags |= HAS_LOCK; 1013 state->diseq_flags |= HAS_LOCK;
965 /* dst->cur_jiff = jiffies; */ 1014
966 return 1; 1015 return 1;
967} 1016}
968 1017
@@ -1098,7 +1147,11 @@ static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
1098 1147
1099 switch (tone) { 1148 switch (tone) {
1100 case SEC_TONE_OFF: 1149 case SEC_TONE_OFF:
1101 state->tx_tuna[2] = 0xff; 1150 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1151 state->tx_tuna[2] = 0x00;
1152 else
1153 state->tx_tuna[2] = 0xff;
1154
1102 break; 1155 break;
1103 1156
1104 case SEC_TONE_ON: 1157 case SEC_TONE_ON:
@@ -1145,7 +1198,8 @@ static int dst_init(struct dvb_frontend* fe)
1145 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1198 static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1146 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1199 static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1147 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; 1200 static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
1148 state->inversion = INVERSION_ON; 1201// state->inversion = INVERSION_ON;
1202 state->inversion = INVERSION_OFF;
1149 state->voltage = SEC_VOLTAGE_13; 1203 state->voltage = SEC_VOLTAGE_13;
1150 state->tone = SEC_TONE_OFF; 1204 state->tone = SEC_TONE_OFF;
1151 state->symbol_rate = 29473000; 1205 state->symbol_rate = 29473000;
@@ -1174,7 +1228,7 @@ static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
1174 1228
1175 *status = 0; 1229 *status = 0;
1176 if (state->diseq_flags & HAS_LOCK) { 1230 if (state->diseq_flags & HAS_LOCK) {
1177 dst_get_signal(state); 1231// dst_get_signal(state); // don't require(?) to ask MCU
1178 if (state->decode_lock) 1232 if (state->decode_lock)
1179 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI; 1233 *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
1180 } 1234 }
@@ -1208,20 +1262,25 @@ static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1208 1262
1209 dst_set_freq(state, p->frequency); 1263 dst_set_freq(state, p->frequency);
1210 if (verbose > 4) 1264 if (verbose > 4)
1211 dprintk("Set Frequency = [%d]\n", p->frequency); 1265 dprintk("Set Frequency=[%d]\n", p->frequency);
1212 1266
1213 dst_set_inversion(state, p->inversion); 1267// dst_set_inversion(state, p->inversion);
1214 if (state->dst_type == DST_TYPE_IS_SAT) { 1268 if (state->dst_type == DST_TYPE_IS_SAT) {
1269 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1270 dst_set_inversion(state, p->inversion);
1271
1215 dst_set_fec(state, p->u.qpsk.fec_inner); 1272 dst_set_fec(state, p->u.qpsk.fec_inner);
1216 dst_set_symbolrate(state, p->u.qpsk.symbol_rate); 1273 dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
1274 dst_set_polarization(state);
1217 if (verbose > 4) 1275 if (verbose > 4)
1218 dprintk("Set Symbolrate = [%d]\n", p->u.qpsk.symbol_rate); 1276 dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
1219 1277
1220 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1278 } else if (state->dst_type == DST_TYPE_IS_TERR) {
1221 dst_set_bandwidth(state, p->u.ofdm.bandwidth); 1279 dst_set_bandwidth(state, p->u.ofdm.bandwidth);
1222 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1280 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1223 dst_set_fec(state, p->u.qam.fec_inner); 1281 dst_set_fec(state, p->u.qam.fec_inner);
1224 dst_set_symbolrate(state, p->u.qam.symbol_rate); 1282 dst_set_symbolrate(state, p->u.qam.symbol_rate);
1283 dst_set_modulation(state, p->u.qam.modulation);
1225 } 1284 }
1226 dst_write_tuna(fe); 1285 dst_write_tuna(fe);
1227 1286
@@ -1233,8 +1292,11 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1233 struct dst_state* state = fe->demodulator_priv; 1292 struct dst_state* state = fe->demodulator_priv;
1234 1293
1235 p->frequency = state->decode_freq; 1294 p->frequency = state->decode_freq;
1236 p->inversion = state->inversion; 1295// p->inversion = state->inversion;
1237 if (state->dst_type == DST_TYPE_IS_SAT) { 1296 if (state->dst_type == DST_TYPE_IS_SAT) {
1297 if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
1298 p->inversion = state->inversion;
1299
1238 p->u.qpsk.symbol_rate = state->symbol_rate; 1300 p->u.qpsk.symbol_rate = state->symbol_rate;
1239 p->u.qpsk.fec_inner = dst_get_fec(state); 1301 p->u.qpsk.fec_inner = dst_get_fec(state);
1240 } else if (state->dst_type == DST_TYPE_IS_TERR) { 1302 } else if (state->dst_type == DST_TYPE_IS_TERR) {
@@ -1242,7 +1304,8 @@ static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_paramet
1242 } else if (state->dst_type == DST_TYPE_IS_CABLE) { 1304 } else if (state->dst_type == DST_TYPE_IS_CABLE) {
1243 p->u.qam.symbol_rate = state->symbol_rate; 1305 p->u.qam.symbol_rate = state->symbol_rate;
1244 p->u.qam.fec_inner = dst_get_fec(state); 1306 p->u.qam.fec_inner = dst_get_fec(state);
1245 p->u.qam.modulation = QAM_AUTO; 1307// p->u.qam.modulation = QAM_AUTO;
1308 p->u.qam.modulation = dst_get_modulation(state);
1246 } 1309 }
1247 1310
1248 return 0; 1311 return 0;
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index d781504cc2fa..bfaacd5fc20f 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -32,7 +32,7 @@
32#include "dst_ca.h" 32#include "dst_ca.h"
33#include "dst_common.h" 33#include "dst_common.h"
34 34
35static unsigned int verbose = 1; 35static unsigned int verbose = 5;
36module_param(verbose, int, 0644); 36module_param(verbose, int, 0644);
37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 37MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
38 38
@@ -295,34 +295,28 @@ static int ca_get_message(struct dst_state *state, struct ca_msg *p_ca_message,
295 return 0; 295 return 0;
296} 296}
297 297
298static int handle_en50221_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) 298static int handle_dst_tag(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u32 length)
299{ 299{
300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) { 300 if (state->dst_hw_cap & DST_TYPE_HAS_SESSION) {
301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */ 301 hw_buffer->msg[2] = p_ca_message->msg[1]; /* MSB */
302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */ 302 hw_buffer->msg[3] = p_ca_message->msg[2]; /* LSB */
303 } 303 }
304 else { 304 else {
305 hw_buffer->msg[0] = (length & 0xff) + 7;
306 hw_buffer->msg[1] = 0x40;
305 hw_buffer->msg[2] = 0x03; 307 hw_buffer->msg[2] = 0x03;
306 hw_buffer->msg[3] = 0x00; 308 hw_buffer->msg[3] = 0x00;
309 hw_buffer->msg[4] = 0x03;
310 hw_buffer->msg[5] = length & 0xff;
311 hw_buffer->msg[6] = 0x00;
307 } 312 }
308 return 0; 313 return 0;
309} 314}
310 315
311static int debug_8820_buffer(struct ca_msg *hw_buffer)
312{
313 unsigned int i;
314
315 dprintk("%s:Debug=[", __FUNCTION__);
316 for (i = 0; i < (hw_buffer->msg[0] + 1); i++)
317 dprintk(" %02x", hw_buffer->msg[i]);
318 dprintk("]\n");
319
320 return 0;
321}
322 316
323static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 reply) 317static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 length, u8 reply)
324{ 318{
325 if ((dst_put_ci(state, hw_buffer->msg, (hw_buffer->length + 1), hw_buffer->msg, reply)) < 0) { 319 if ((dst_put_ci(state, hw_buffer->msg, length, hw_buffer->msg, reply)) < 0) {
326 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__); 320 dprintk("%s: DST-CI Command failed.\n", __FUNCTION__);
327 dprintk("%s: Resetting DST.\n", __FUNCTION__); 321 dprintk("%s: Resetting DST.\n", __FUNCTION__);
328 rdc_reset_state(state); 322 rdc_reset_state(state);
@@ -334,234 +328,141 @@ static int write_to_8820(struct dst_state *state, struct ca_msg *hw_buffer, u8 r
334 return 0; 328 return 0;
335} 329}
336 330
337 331u32 asn_1_decode(u8 *asn_1_array)
338static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
339{ 332{
340 u32 hw_offset, buf_offset, i, k; 333 u8 length_field = 0, word_count = 0, count = 0;
341 u32 program_info_length = 0, es_info_length = 0, length = 0, words = 0; 334 u32 length = 0;
342 u8 found_prog_ca_desc = 0, found_stream_ca_desc = 0, error_condition = 0, hw_buffer_length = 0; 335
343 336 length_field = asn_1_array[0];
344 if (verbose > 3) 337 dprintk("%s: Length field=[%02x]\n", __FUNCTION__, length_field);
345 dprintk("%s, p_ca_message length %d (0x%x)\n", __FUNCTION__,p_ca_message->length,p_ca_message->length ); 338 if (length_field < 0x80) {
346 339 length = length_field & 0x7f;
347 handle_en50221_tag(state, p_ca_message, hw_buffer); /* EN50221 tag */ 340 dprintk("%s: Length=[%02x]\n", __FUNCTION__, length);
348 341 } else {
349 /* Handle the length field (variable) */ 342 word_count = length_field & 0x7f;
350 if (!(p_ca_message->msg[3] & 0x80)) { /* Length = 1 */ 343 for (count = 0; count < word_count; count++) {
351 length = p_ca_message->msg[3] & 0x7f; 344 length = (length | asn_1_array[count + 1]) << 8;
352 words = 0; /* domi's suggestion */ 345 dprintk("%s: Length=[%04x]\n", __FUNCTION__, length);
353 }
354 else { /* Length = words */
355 words = p_ca_message->msg[3] & 0x7f;
356 for (i = 0; i < words; i++) {
357 length = length << 8;
358 length = length | p_ca_message->msg[4 + i];
359 } 346 }
360 } 347 }
361 if (verbose > 4) { 348 return length;
362 dprintk("%s:Length=[%d (0x%x)], Words=[%d]\n", __FUNCTION__, length,length, words); 349}
363
364 /* Debug Input string */
365 for (i = 0; i < length; i++)
366 dprintk(" %02x", p_ca_message->msg[i]);
367 dprintk("]\n");
368 }
369
370 hw_offset = 7;
371 buf_offset = words + 4;
372
373 /* Program Header */
374 if (verbose > 4)
375 dprintk("\n%s:Program Header=[", __FUNCTION__);
376 for (i = 0; i < 6; i++) {
377 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset];
378 if (verbose > 4)
379 dprintk(" %02x", p_ca_message->msg[buf_offset]);
380 hw_offset++, buf_offset++, hw_buffer_length++;
381 }
382 if (verbose > 4)
383 dprintk("]\n");
384 350
385 program_info_length = 0; 351static int init_buffer(u8 *buffer, u32 length)
386 program_info_length = (((program_info_length | p_ca_message->msg[words + 8]) & 0x0f) << 8) | p_ca_message->msg[words + 9]; 352{
387 if (verbose > 4) 353 u32 i;
388 dprintk("%s:Program info Length=[%d][%02x], hw_offset=[%d], buf_offset=[%d] \n", 354 for (i = 0; i < length; i++)
389 __FUNCTION__, program_info_length, program_info_length, hw_offset, buf_offset); 355 buffer[i] = 0;
390 356
391 if (program_info_length && (program_info_length < 256)) { /* If program_info_length */ 357 return 0;
392 hw_buffer->msg[11] = hw_buffer->msg[11] & 0x0f; /* req only 4 bits */ 358}
393 hw_buffer->msg[12] = hw_buffer->msg[12] + 1; /* increment! ASIC bug! */
394 359
395 if (p_ca_message->msg[buf_offset + 1] == 0x09) { /* Check CA descriptor */ 360static int debug_string(u8 *msg, u32 length, u32 offset)
396 found_prog_ca_desc = 1; 361{
397 if (verbose > 4) 362 u32 i;
398 dprintk("%s: Found CA descriptor @ Program level\n", __FUNCTION__);
399 }
400 363
401 if (found_prog_ca_desc) { /* Command only if CA descriptor */ 364 dprintk(" String=[ ");
402 hw_buffer->msg[13] = p_ca_message->msg[buf_offset]; /* CA PMT command ID */ 365 for (i = offset; i < length; i++)
403 hw_offset++, buf_offset++, hw_buffer_length++; 366 dprintk("%02x ", msg[i]);
404 } 367 dprintk("]\n");
405 368
406 /* Program descriptors */ 369 return 0;
407 if (verbose > 4) { 370}
408 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset);
409 dprintk("%s:Program descriptors=[", __FUNCTION__);
410 }
411 while (program_info_length && !error_condition) { /* Copy prog descriptors */
412 if (program_info_length > p_ca_message->length) { /* Error situation */
413 dprintk ("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d]\n",
414 __FUNCTION__, __LINE__, program_info_length);
415 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
416 error_condition = 1;
417 break;
418 }
419 371
420 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; 372static int copy_string(u8 *destination, u8 *source, u32 dest_offset, u32 source_offset, u32 length)
421 dprintk(" %02x", p_ca_message->msg[buf_offset]); 373{
422 hw_offset++, buf_offset++, hw_buffer_length++, program_info_length--; 374 u32 i;
423 } 375 dprintk("%s: Copying [", __FUNCTION__);
424 if (verbose > 4) { 376 for (i = 0; i < length; i++) {
425 dprintk("]\n"); 377 destination[i + dest_offset] = source[i + source_offset];
426 dprintk("%s:**********>buf_offset=[%d], hw_offset=[%d]\n", __FUNCTION__, buf_offset, hw_offset); 378 dprintk(" %02x", source[i + source_offset]);
427 }
428 if (found_prog_ca_desc) {
429 if (!reply) {
430 hw_buffer->msg[13] = 0x01; /* OK descrambling */
431 if (verbose > 1)
432 dprintk("CA PMT Command = OK Descrambling\n");
433 }
434 else {
435 hw_buffer->msg[13] = 0x02; /* Ok MMI */
436 if (verbose > 1)
437 dprintk("CA PMT Command = Ok MMI\n");
438 }
439 if (query) {
440 hw_buffer->msg[13] = 0x03; /* Query */
441 if (verbose > 1)
442 dprintk("CA PMT Command = CA PMT query\n");
443 }
444 }
445 }
446 else {
447 hw_buffer->msg[11] = hw_buffer->msg[11] & 0xf0; /* Don't write to ASIC */
448 hw_buffer->msg[12] = hw_buffer->msg[12] = 0x00;
449 } 379 }
450 if (verbose > 4) 380 dprintk("]\n");
451 dprintk("%s:**********>p_ca_message->length=[%d], buf_offset=[%d], hw_offset=[%d]\n",
452 __FUNCTION__, p_ca_message->length, buf_offset, hw_offset);
453
454 while ((buf_offset < p_ca_message->length) && !error_condition) {
455 /* Bail out in case of an indefinite loop */
456 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
457 dprintk("%s:\"WARNING\" Length error, line=[%d], prog_info_length=[%d], buf_offset=[%d]\n",
458 __FUNCTION__, __LINE__, program_info_length, buf_offset);
459
460 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
461 error_condition = 1;
462 break;
463 }
464
465 /* Stream Header */
466
467 for (k = 0; k < 5; k++) {
468 hw_buffer->msg[hw_offset + k] = p_ca_message->msg[buf_offset + k];
469 }
470 381
471 es_info_length = 0; 382 return i;
472 es_info_length = (es_info_length | (p_ca_message->msg[buf_offset + 3] & 0x0f)) << 8 | p_ca_message->msg[buf_offset + 4]; 383}
473 384
474 if (verbose > 4) { 385static int modify_4_bits(u8 *message, u32 pos)
475 dprintk("\n%s:----->Stream header=[%02x %02x %02x %02x %02x]\n", __FUNCTION__, 386{
476 p_ca_message->msg[buf_offset + 0], p_ca_message->msg[buf_offset + 1], 387 message[pos] &= 0x0f;
477 p_ca_message->msg[buf_offset + 2], p_ca_message->msg[buf_offset + 3],
478 p_ca_message->msg[buf_offset + 4]);
479 388
480 dprintk("%s:----->Stream type=[%02x], es length=[%d (0x%x)], Chars=[%02x] [%02x], buf_offset=[%d]\n", __FUNCTION__, 389 return 0;
481 p_ca_message->msg[buf_offset + 0], es_info_length, es_info_length, 390}
482 p_ca_message->msg[buf_offset + 3], p_ca_message->msg[buf_offset + 4], buf_offset);
483 }
484 391
485 hw_buffer->msg[hw_offset + 3] &= 0x0f; /* req only 4 bits */
486 392
487 if (found_prog_ca_desc) {
488 hw_buffer->msg[hw_offset + 3] = 0x00;
489 hw_buffer->msg[hw_offset + 4] = 0x00;
490 }
491 393
492 hw_offset += 5, buf_offset += 5, hw_buffer_length += 5; 394static int ca_set_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer, u8 reply, u8 query)
395{
396 u32 length = 0, count = 0;
397 u8 asn_1_words, program_header_length;
398 u16 program_info_length = 0, es_info_length = 0;
399 u32 hw_offset = 0, buf_offset = 0, i;
400 u8 dst_tag_length;
493 401
494 /* Check for CA descriptor */ 402 length = asn_1_decode(&p_ca_message->msg[3]);
495 if (p_ca_message->msg[buf_offset + 1] == 0x09) { 403 dprintk("%s: CA Message length=[%d]\n", __FUNCTION__, length);
496 if (verbose > 4) 404 dprintk("%s: ASN.1 ", __FUNCTION__);
497 dprintk("%s:Found CA descriptor @ Stream level\n", __FUNCTION__); 405 debug_string(&p_ca_message->msg[4], length, 0); // length does not include tag and length
498 found_stream_ca_desc = 1;
499 }
500 406
501 /* ES descriptors */ 407 init_buffer(hw_buffer->msg, length);
502 408 handle_dst_tag(state, p_ca_message, hw_buffer, length);
503 if (es_info_length && !error_condition && !found_prog_ca_desc && found_stream_ca_desc) {
504// if (!ca_pmt_done) {
505 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; /* CA PMT cmd(es) */
506 if (verbose > 4)
507 printk("%s:----->CA PMT Command ID=[%02x]\n", __FUNCTION__, p_ca_message->msg[buf_offset]);
508// hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--, ca_pmt_done = 1;
509 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--;
510// }
511 if (verbose > 4)
512 dprintk("%s:----->ES descriptors=[", __FUNCTION__);
513
514 while (es_info_length && !error_condition) { /* ES descriptors */
515 if ((es_info_length > p_ca_message->length) || (buf_offset > p_ca_message->length)) {
516 if (verbose > 4) {
517 dprintk("%s:\"WARNING\" ES Length error, line=[%d], es_info_length=[%d], buf_offset=[%d]\n",
518 __FUNCTION__, __LINE__, es_info_length, buf_offset);
519
520 dprintk("%s:\"WARNING\" Bailing out of possible loop\n", __FUNCTION__);
521 }
522 error_condition = 1;
523 break;
524 }
525 409
526 hw_buffer->msg[hw_offset] = p_ca_message->msg[buf_offset]; 410 hw_offset = 7;
527 if (verbose > 3) 411 asn_1_words = 1; // just a hack to test, should compute this one
528 dprintk("%02x ", hw_buffer->msg[hw_offset]); 412 buf_offset = 3;
529 hw_offset++, buf_offset++, hw_buffer_length++, es_info_length--; 413 program_header_length = 6;
530 } 414 dst_tag_length = 7;
531 found_stream_ca_desc = 0; /* unset for new streams */ 415
532 dprintk("]\n"); 416// debug_twinhan_ca_params(state, p_ca_message, hw_buffer, reply, query, length, hw_offset, buf_offset);
417// dprintk("%s: Program Header(BUF)", __FUNCTION__);
418// debug_string(&p_ca_message->msg[4], program_header_length, 0);
419// dprintk("%s: Copying Program header\n", __FUNCTION__);
420 copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + asn_1_words), program_header_length);
421 buf_offset += program_header_length, hw_offset += program_header_length;
422 modify_4_bits(hw_buffer->msg, (hw_offset - 2));
423 if (state->type_flags & DST_TYPE_HAS_INC_COUNT) { // workaround
424 dprintk("%s: Probably an ASIC bug !!!\n", __FUNCTION__);
425 debug_string(hw_buffer->msg, (hw_offset + program_header_length), 0);
426 hw_buffer->msg[hw_offset - 1] += 1;
427 }
428
429// dprintk("%s: Program Header(HW), Count=[%d]", __FUNCTION__, count);
430// debug_string(hw_buffer->msg, hw_offset, 0);
431
432 program_info_length = ((program_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
433 dprintk("%s: Program info length=[%02x]\n", __FUNCTION__, program_info_length);
434 if (program_info_length) {
435 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, (buf_offset + 1), (program_info_length + 1) ); // copy next elem, not current
436 buf_offset += count, hw_offset += count;
437// dprintk("%s: Program level ", __FUNCTION__);
438// debug_string(hw_buffer->msg, hw_offset, 0);
439 }
440
441 buf_offset += 1;// hw_offset += 1;
442 for (i = buf_offset; i < length; i++) {
443// dprintk("%s: Stream Header ", __FUNCTION__);
444 count = copy_string(hw_buffer->msg, p_ca_message->msg, hw_offset, buf_offset, 5);
445 modify_4_bits(hw_buffer->msg, (hw_offset + 3));
446
447 hw_offset += 5, buf_offset += 5, i += 4;
448// debug_string(hw_buffer->msg, hw_offset, (hw_offset - 5));
449 es_info_length = ((es_info_length | (p_ca_message->msg[buf_offset - 1] & 0x0f)) << 8) | p_ca_message->msg[buf_offset];
450 dprintk("%s: ES info length=[%02x]\n", __FUNCTION__, es_info_length);
451 if (es_info_length) {
452 // copy descriptors @ STREAM level
453 dprintk("%s: Descriptors @ STREAM level...!!! \n", __FUNCTION__);
533 } 454 }
534 }
535
536 /* MCU Magic words */
537
538 hw_buffer_length += 7;
539 hw_buffer->msg[0] = hw_buffer_length;
540 hw_buffer->msg[1] = 64;
541 hw_buffer->msg[4] = 3;
542 hw_buffer->msg[5] = hw_buffer->msg[0] - 7;
543 hw_buffer->msg[6] = 0;
544
545 455
546 /* Fix length */
547 hw_buffer->length = hw_buffer->msg[0];
548
549 put_checksum(&hw_buffer->msg[0], hw_buffer->msg[0]);
550 /* Do the actual write */
551 if (verbose > 4) {
552 dprintk("%s:======================DEBUGGING================================\n", __FUNCTION__);
553 dprintk("%s: Actual Length=[%d]\n", __FUNCTION__, hw_buffer_length);
554 } 456 }
555 /* Only for debugging! */ 457 hw_buffer->msg[length + dst_tag_length] = dst_check_sum(hw_buffer->msg, (length + dst_tag_length));
556 if (verbose > 2) 458// dprintk("%s: Total length=[%d], Checksum=[%02x]\n", __FUNCTION__, (length + dst_tag_length), hw_buffer->msg[length + dst_tag_length]);
557 debug_8820_buffer(hw_buffer); 459 debug_string(hw_buffer->msg, (length + dst_tag_length + 1), 0); // dst tags also
558 if (verbose > 3) 460 write_to_8820(state, hw_buffer, (length + dst_tag_length + 1), reply); // checksum
559 dprintk("%s: Reply = [%d]\n", __FUNCTION__, reply);
560 write_to_8820(state, hw_buffer, reply);
561 461
562 return 0; 462 return 0;
563} 463}
564 464
465
565/* Board supports CA PMT reply ? */ 466/* Board supports CA PMT reply ? */
566static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer) 467static int dst_check_ca_pmt(struct dst_state *state, struct ca_msg *p_ca_message, struct ca_msg *hw_buffer)
567{ 468{
@@ -605,7 +506,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
605 struct ca_msg *hw_buffer; 506 struct ca_msg *hw_buffer;
606 507
607 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 508 if ((hw_buffer = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
608 printk("%s: Memory allocation failure\n", __FUNCTION__); 509 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
609 return -ENOMEM; 510 return -ENOMEM;
610 } 511 }
611 if (verbose > 3) 512 if (verbose > 3)
@@ -630,8 +531,10 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
630 switch (command) { 531 switch (command) {
631 case CA_PMT: 532 case CA_PMT:
632 if (verbose > 3) 533 if (verbose > 3)
534// dprintk("Command = SEND_CA_PMT\n");
633 dprintk("Command = SEND_CA_PMT\n"); 535 dprintk("Command = SEND_CA_PMT\n");
634 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { 536// if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) {
537 if ((ca_set_pmt(state, p_ca_message, hw_buffer, 0, 0)) < 0) { // code simplification started
635 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__); 538 dprintk("%s: -->CA_PMT Failed !\n", __FUNCTION__);
636 return -1; 539 return -1;
637 } 540 }
@@ -664,7 +567,7 @@ static int ca_send_message(struct dst_state *state, struct ca_msg *p_ca_message,
664 return -1; 567 return -1;
665 } 568 }
666 if (verbose > 3) 569 if (verbose > 3)
667 printk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__); 570 dprintk("%s: -->CA_APP_INFO_ENQUIRY Success !\n", __FUNCTION__);
668 571
669 break; 572 break;
670 } 573 }
@@ -681,17 +584,17 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd
681 struct ca_msg *p_ca_message; 584 struct ca_msg *p_ca_message;
682 585
683 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) { 586 if ((p_ca_message = (struct ca_msg *) kmalloc(sizeof (struct ca_msg), GFP_KERNEL)) == NULL) {
684 printk("%s: Memory allocation failure\n", __FUNCTION__); 587 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
685 return -ENOMEM; 588 return -ENOMEM;
686 } 589 }
687 590
688 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) { 591 if ((p_ca_slot_info = (struct ca_slot_info *) kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL)) == NULL) {
689 printk("%s: Memory allocation failure\n", __FUNCTION__); 592 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
690 return -ENOMEM; 593 return -ENOMEM;
691 } 594 }
692 595
693 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) { 596 if ((p_ca_caps = (struct ca_caps *) kmalloc(sizeof (struct ca_caps), GFP_KERNEL)) == NULL) {
694 printk("%s: Memory allocation failure\n", __FUNCTION__); 597 dprintk("%s: Memory allocation failure\n", __FUNCTION__);
695 return -ENOMEM; 598 return -ENOMEM;
696 } 599 }
697 600
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 0b3da29245fb..ef532a6aceaa 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -47,6 +47,8 @@
47#define DST_TYPE_HAS_FW_2 16 47#define DST_TYPE_HAS_FW_2 16
48#define DST_TYPE_HAS_FW_3 32 48#define DST_TYPE_HAS_FW_3 32
49#define DST_TYPE_HAS_FW_BUILD 64 49#define DST_TYPE_HAS_FW_BUILD 64
50#define DST_TYPE_HAS_OBS_REGS 128
51#define DST_TYPE_HAS_INC_COUNT 256
50 52
51/* Card capability list */ 53/* Card capability list */
52 54
@@ -110,6 +112,7 @@ struct dst_state {
110 u32 dst_hw_cap; 112 u32 dst_hw_cap;
111 u8 dst_fw_version; 113 u8 dst_fw_version;
112 fe_sec_mini_cmd_t minicmd; 114 fe_sec_mini_cmd_t minicmd;
115 fe_modulation_t modulation;
113 u8 messages[256]; 116 u8 messages[256];
114}; 117};
115 118
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 96c57fde95a0..7d8b3cad350b 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -699,6 +699,8 @@ static void cinergyt2_query_rc (void *data)
699 for (n=0; len>0 && n<(len/sizeof(rc_events[0])); n++) { 699 for (n=0; len>0 && n<(len/sizeof(rc_events[0])); n++) {
700 int i; 700 int i;
701 701
702/* dprintk(1,"rc_events[%d].value = %x, type=%x\n",n,le32_to_cpu(rc_events[n].value),rc_events[n].type);*/
703
702 if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC && 704 if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC &&
703 rc_events[n].value == ~0) 705 rc_events[n].value == ~0)
704 { 706 {
@@ -714,7 +716,7 @@ static void cinergyt2_query_rc (void *data)
714 cinergyt2->rc_input_event = KEY_MAX; 716 cinergyt2->rc_input_event = KEY_MAX;
715 for (i=0; i<sizeof(rc_keys)/sizeof(rc_keys[0]); i+=3) { 717 for (i=0; i<sizeof(rc_keys)/sizeof(rc_keys[0]); i+=3) {
716 if (rc_keys[i+0] == rc_events[n].type && 718 if (rc_keys[i+0] == rc_events[n].type &&
717 rc_keys[i+1] == rc_events[n].value) 719 rc_keys[i+1] == le32_to_cpu(rc_events[n].value))
718 { 720 {
719 cinergyt2->rc_input_event = rc_keys[i+2]; 721 cinergyt2->rc_input_event = rc_keys[i+2];
720 break; 722 break;
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index c225de7ffd82..68050cd527cb 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -42,12 +42,6 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
42 42
43#define dprintk if (debug) printk 43#define dprintk if (debug) printk
44 44
45static inline struct dmxdev_filter *
46dvb_dmxdev_file_to_filter(struct file *file)
47{
48 return (struct dmxdev_filter *) file->private_data;
49}
50
51static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer) 45static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer)
52{ 46{
53 buffer->data=NULL; 47 buffer->data=NULL;
@@ -669,8 +663,10 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
669 663
670 ret = filter->feed.ts->start_filtering(filter->feed.ts); 664 ret = filter->feed.ts->start_filtering(filter->feed.ts);
671 665
672 if (ret < 0) 666 if (ret < 0) {
667 dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed);
673 return ret; 668 return ret;
669 }
674 670
675 break; 671 break;
676 } 672 }
@@ -842,7 +838,7 @@ static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil,
842static ssize_t 838static ssize_t
843dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 839dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
844{ 840{
845 struct dmxdev_filter *dmxdevfilter=dvb_dmxdev_file_to_filter(file); 841 struct dmxdev_filter *dmxdevfilter= file->private_data;
846 int ret=0; 842 int ret=0;
847 843
848 if (down_interruptible(&dmxdevfilter->mutex)) 844 if (down_interruptible(&dmxdevfilter->mutex))
@@ -863,7 +859,7 @@ dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
863static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, 859static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
864 unsigned int cmd, void *parg) 860 unsigned int cmd, void *parg)
865{ 861{
866 struct dmxdev_filter *dmxdevfilter=dvb_dmxdev_file_to_filter(file); 862 struct dmxdev_filter *dmxdevfilter = file->private_data;
867 struct dmxdev *dmxdev=dmxdevfilter->dev; 863 struct dmxdev *dmxdev=dmxdevfilter->dev;
868 unsigned long arg=(unsigned long) parg; 864 unsigned long arg=(unsigned long) parg;
869 int ret=0; 865 int ret=0;
@@ -960,7 +956,7 @@ static int dvb_demux_ioctl(struct inode *inode, struct file *file,
960 956
961static unsigned int dvb_demux_poll (struct file *file, poll_table *wait) 957static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
962{ 958{
963 struct dmxdev_filter *dmxdevfilter = dvb_dmxdev_file_to_filter(file); 959 struct dmxdev_filter *dmxdevfilter = file->private_data;
964 unsigned int mask = 0; 960 unsigned int mask = 0;
965 961
966 if (!dmxdevfilter) 962 if (!dmxdevfilter)
@@ -985,7 +981,7 @@ static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
985 981
986static int dvb_demux_release(struct inode *inode, struct file *file) 982static int dvb_demux_release(struct inode *inode, struct file *file)
987{ 983{
988 struct dmxdev_filter *dmxdevfilter = dvb_dmxdev_file_to_filter(file); 984 struct dmxdev_filter *dmxdevfilter = file->private_data;
989 struct dmxdev *dmxdev = dmxdevfilter->dev; 985 struct dmxdev *dmxdev = dmxdevfilter->dev;
990 986
991 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter); 987 return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter);
@@ -1109,7 +1105,6 @@ dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
1109 dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); 1105 dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE);
1110 dmxdev->dvr[i].dev=dmxdev; 1106 dmxdev->dvr[i].dev=dmxdev;
1111 dmxdev->dvr[i].buffer.data=NULL; 1107 dmxdev->dvr[i].buffer.data=NULL;
1112 dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE);
1113 dvb_dmxdev_dvr_state_set(&dmxdev->dvr[i], DMXDEV_STATE_FREE); 1108 dvb_dmxdev_dvr_state_set(&dmxdev->dvr[i], DMXDEV_STATE_FREE);
1114 } 1109 }
1115 1110
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index f11daae91cd4..a8bc84240b50 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -42,6 +42,8 @@
42#include "dvb_frontend.h" 42#include "dvb_frontend.h"
43#include "dvbdev.h" 43#include "dvbdev.h"
44 44
45// #define DEBUG_LOCKLOSS 1
46
45static int dvb_frontend_debug; 47static int dvb_frontend_debug;
46static int dvb_shutdown_timeout = 5; 48static int dvb_shutdown_timeout = 5;
47static int dvb_force_auto_inversion; 49static int dvb_force_auto_inversion;
@@ -113,6 +115,7 @@ struct dvb_frontend_private {
113 int exit; 115 int exit;
114 int wakeup; 116 int wakeup;
115 fe_status_t status; 117 fe_status_t status;
118 fe_sec_tone_mode_t tone;
116}; 119};
117 120
118 121
@@ -434,9 +437,26 @@ static int dvb_frontend_thread(void *data)
434 /* we're tuned, and the lock is still good... */ 437 /* we're tuned, and the lock is still good... */
435 if (s & FE_HAS_LOCK) 438 if (s & FE_HAS_LOCK)
436 continue; 439 continue;
437 else { 440 else { /* if we _WERE_ tuned, but now don't have a lock */
438 /* if we _WERE_ tuned, but now don't have a lock, 441#ifdef DEBUG_LOCKLOSS
439 * need to zigzag */ 442 /* first of all try setting the tone again if it was on - this
443 * sometimes works around problems with noisy power supplies */
444 if (fe->ops->set_tone && (fepriv->tone == SEC_TONE_ON)) {
445 fe->ops->set_tone(fe, fepriv->tone);
446 mdelay(100);
447 s = 0;
448 fe->ops->read_status(fe, &s);
449 if (s & FE_HAS_LOCK) {
450 printk("DVB%i: Lock was lost, but regained by setting "
451 "the tone. This may indicate your power supply "
452 "is noisy/slightly incompatable with this DVB-S "
453 "adapter\n", fe->dvb->num);
454 fepriv->state = FESTATE_TUNED;
455 continue;
456 }
457 }
458#endif
459 /* some other reason for losing the lock - start zigzagging */
440 fepriv->state = FESTATE_ZIGZAG_FAST; 460 fepriv->state = FESTATE_ZIGZAG_FAST;
441 fepriv->started_auto_step = fepriv->auto_step; 461 fepriv->started_auto_step = fepriv->auto_step;
442 check_wrapped = 0; 462 check_wrapped = 0;
@@ -626,11 +646,21 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
626 break; 646 break;
627 } 647 }
628 648
629 case FE_READ_STATUS: 649 case FE_READ_STATUS: {
650 fe_status_t* status = parg;
651
652 /* if retune was requested but hasn't occured yet, prevent
653 * that user get signal state from previous tuning */
654 if(fepriv->state == FESTATE_RETUNE) {
655 err=0;
656 *status = 0;
657 break;
658 }
659
630 if (fe->ops->read_status) 660 if (fe->ops->read_status)
631 err = fe->ops->read_status(fe, (fe_status_t*) parg); 661 err = fe->ops->read_status(fe, status);
632 break; 662 break;
633 663 }
634 case FE_READ_BER: 664 case FE_READ_BER:
635 if (fe->ops->read_ber) 665 if (fe->ops->read_ber)
636 err = fe->ops->read_ber(fe, (__u32*) parg); 666 err = fe->ops->read_ber(fe, (__u32*) parg);
@@ -681,6 +711,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
681 err = fe->ops->set_tone(fe, (fe_sec_tone_mode_t) parg); 711 err = fe->ops->set_tone(fe, (fe_sec_tone_mode_t) parg);
682 fepriv->state = FESTATE_DISEQC; 712 fepriv->state = FESTATE_DISEQC;
683 fepriv->status = 0; 713 fepriv->status = 0;
714 fepriv->tone = (fe_sec_tone_mode_t) parg;
684 } 715 }
685 break; 716 break;
686 717
@@ -883,6 +914,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
883 init_MUTEX (&fepriv->events.sem); 914 init_MUTEX (&fepriv->events.sem);
884 fe->dvb = dvb; 915 fe->dvb = dvb;
885 fepriv->inversion = INVERSION_OFF; 916 fepriv->inversion = INVERSION_OFF;
917 fepriv->tone = SEC_TONE_OFF;
886 918
887 printk ("DVB: registering frontend %i (%s)...\n", 919 printk ("DVB: registering frontend %i (%s)...\n",
888 fe->dvb->num, 920 fe->dvb->num,
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index d2b021792791..9c2c1d1136bd 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -40,28 +40,6 @@
40 40
41#include "dvbdev.h" 41#include "dvbdev.h"
42 42
43/* FIXME: Move to i2c-id.h */
44#define I2C_DRIVERID_DVBFE_SP8870 I2C_DRIVERID_EXP2
45#define I2C_DRIVERID_DVBFE_CX22700 I2C_DRIVERID_EXP2
46#define I2C_DRIVERID_DVBFE_AT76C651 I2C_DRIVERID_EXP2
47#define I2C_DRIVERID_DVBFE_CX24110 I2C_DRIVERID_EXP2
48#define I2C_DRIVERID_DVBFE_CX22702 I2C_DRIVERID_EXP2
49#define I2C_DRIVERID_DVBFE_DIB3000MB I2C_DRIVERID_EXP2
50#define I2C_DRIVERID_DVBFE_DST I2C_DRIVERID_EXP2
51#define I2C_DRIVERID_DVBFE_DUMMY I2C_DRIVERID_EXP2
52#define I2C_DRIVERID_DVBFE_L64781 I2C_DRIVERID_EXP2
53#define I2C_DRIVERID_DVBFE_MT312 I2C_DRIVERID_EXP2
54#define I2C_DRIVERID_DVBFE_MT352 I2C_DRIVERID_EXP2
55#define I2C_DRIVERID_DVBFE_NXT6000 I2C_DRIVERID_EXP2
56#define I2C_DRIVERID_DVBFE_SP887X I2C_DRIVERID_EXP2
57#define I2C_DRIVERID_DVBFE_STV0299 I2C_DRIVERID_EXP2
58#define I2C_DRIVERID_DVBFE_TDA1004X I2C_DRIVERID_EXP2
59#define I2C_DRIVERID_DVBFE_TDA8083 I2C_DRIVERID_EXP2
60#define I2C_DRIVERID_DVBFE_VES1820 I2C_DRIVERID_EXP2
61#define I2C_DRIVERID_DVBFE_VES1X93 I2C_DRIVERID_EXP2
62#define I2C_DRIVERID_DVBFE_TDA80XX I2C_DRIVERID_EXP2
63
64
65struct dvb_frontend_tune_settings { 43struct dvb_frontend_tune_settings {
66 int min_delay_ms; 44 int min_delay_ms;
67 int step_size; 45 int step_size;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 8aa32f6e447b..612e5b087b1c 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -3,30 +3,35 @@ config DVB_USB
3 depends on DVB_CORE && USB 3 depends on DVB_CORE && USB
4 select FW_LOADER 4 select FW_LOADER
5 help 5 help
6 By enabling this you will be able to choose the various USB 1.1 and 6 By enabling this you will be able to choose the various supported
7 USB2.0 DVB devices. 7 USB1.1 and USB2.0 DVB devices.
8 8
9 Almost every USB device needs a firmware, please look into 9 Almost every USB device needs a firmware, please look into
10 <file:Documentation/dvb/README.dvb-usb> 10 <file:Documentation/dvb/README.dvb-usb>.
11 11
12 Say Y if you own an USB DVB device. 12 For a complete list of supported USB devices see the LinuxTV DVB Wiki:
13 <http://www.linuxtv.org/wiki/index.php/DVB_USB>
14
15 Say Y if you own a USB DVB device.
13 16
14config DVB_USB_DEBUG 17config DVB_USB_DEBUG
15 bool "Enable extended debug support for all DVB-USB devices" 18 bool "Enable extended debug support for all DVB-USB devices"
16 depends on DVB_USB 19 depends on DVB_USB
17 help 20 help
18 Say Y if you want to enable debuging. See modinfo dvb-usb (and the 21 Say Y if you want to enable debugging. See modinfo dvb-usb (and the
19 appropriate drivers) for debug levels. 22 appropriate drivers) for debug levels.
20 23
21config DVB_USB_A800 24config DVB_USB_A800
22 tristate "AVerMedia AverTV DVB-T USB 2.0 (A800)" 25 tristate "AVerMedia AverTV DVB-T USB 2.0 (A800)"
23 depends on DVB_USB 26 depends on DVB_USB
27 select DVB_DIB3000MC
24 help 28 help
25 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver. 29 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver.
26 30
27config DVB_USB_DIBUSB_MB 31config DVB_USB_DIBUSB_MB
28 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-B) (see help for device list)" 32 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-B) (see help for device list)"
29 depends on DVB_USB 33 depends on DVB_USB
34 select DVB_DIB3000MB
30 help 35 help
31 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by 36 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by
32 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator. 37 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator.
@@ -52,6 +57,7 @@ config DVB_USB_DIBUSB_MB
52config DVB_USB_DIBUSB_MC 57config DVB_USB_DIBUSB_MC
53 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)" 58 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)"
54 depends on DVB_USB 59 depends on DVB_USB
60 select DVB_DIB3000MC
55 help 61 help
56 Support for 2.0 DVB-T receivers based on reference designs made by 62 Support for 2.0 DVB-T receivers based on reference designs made by
57 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator. 63 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator.
@@ -66,12 +72,23 @@ config DVB_USB_DIBUSB_MC
66config DVB_USB_UMT_010 72config DVB_USB_UMT_010
67 tristate "HanfTek UMT-010 DVB-T USB2.0 support" 73 tristate "HanfTek UMT-010 DVB-T USB2.0 support"
68 depends on DVB_USB 74 depends on DVB_USB
75 select DVB_DIB3000MC
69 help 76 help
70 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver. 77 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver.
71 78
79config DVB_USB_CXUSB
80 tristate "Medion MD95700 hybrid USB2.0 (Conexant) support"
81 depends on DVB_USB
82 select DVB_CX22702
83 help
84 Say Y here to support the Medion MD95700 hybrid USB2.0 device. Currently
85 only the DVB-T part is supported.
86
72config DVB_USB_DIGITV 87config DVB_USB_DIGITV
73 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support" 88 tristate "Nebula Electronics uDigiTV DVB-T USB2.0 support"
74 depends on DVB_USB 89 depends on DVB_USB
90 select DVB_NXT6000
91 select DVB_MT352
75 help 92 help
76 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver. 93 Say Y here to support the Nebula Electronics uDigitV USB2.0 DVB-T receiver.
77 94
@@ -87,13 +104,16 @@ config DVB_USB_VP7045
87config DVB_USB_NOVA_T_USB2 104config DVB_USB_NOVA_T_USB2
88 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support" 105 tristate "Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 support"
89 depends on DVB_USB 106 depends on DVB_USB
107 select DVB_DIB3000MC
90 help 108 help
91 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver. 109 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver.
92 110
93config DVB_USB_DTT200U 111config DVB_USB_DTT200U
94 tristate "Yakumo/Hama/Typhoon/Yuan DVB-T USB2.0 support" 112 tristate "WideView WT-200U and WT-220U (pen) DVB-T USB2.0 support (Yakumo/Hama/Typhoon/Yuan)"
95 depends on DVB_USB 113 depends on DVB_USB
96 help 114 help
97 Say Y here to support the Yakumo/Hama/Typhoon/Yuan DVB-T USB2.0 receiver. 115 Say Y here to support the WideView/Yakumo/Hama/Typhoon/Yuan DVB-T USB2.0 receiver.
98 116
99 The receivers are also known as DTT200U (Yakumo) and UB300 (Yuan). 117 The receivers are also known as DTT200U (Yakumo) and UB300 (Yuan).
118
119 The WT-220U and its clones are pen-sized.
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index d65b50f9abb0..746d87ed6f32 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -27,4 +27,7 @@ obj-$(CONFIG_DVB_USB_UMT_010) += dvb-usb-dibusb-common.o dvb-usb-umt-010.o
27dvb-usb-digitv-objs = digitv.o 27dvb-usb-digitv-objs = digitv.o
28obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o 28obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
29 29
30dvb-usb-cxusb-objs = cxusb.o
31obj-$(CONFIG_DVB_USB_CXUSB) += dvb-usb-cxusb.o
32
30EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 33EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index a3542935604f..f2fcc2f1f846 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -61,6 +61,12 @@ static struct dvb_usb_rc_key a800_rc_keys[] = {
61 { 0x02, 0x00, KEY_LAST }, /* >>| / BLUE */ 61 { 0x02, 0x00, KEY_LAST }, /* >>| / BLUE */
62 { 0x02, 0x04, KEY_EPG }, /* EPG */ 62 { 0x02, 0x04, KEY_EPG }, /* EPG */
63 { 0x02, 0x15, KEY_MENU }, /* MENU */ 63 { 0x02, 0x15, KEY_MENU }, /* MENU */
64
65 { 0x03, 0x03, KEY_CHANNELUP }, /* CH UP */
66 { 0x03, 0x02, KEY_CHANNELDOWN }, /* CH DOWN */
67 { 0x03, 0x01, KEY_FIRST }, /* |<< / GREEN */
68 { 0x03, 0x00, KEY_LAST }, /* >>| / BLUE */
69
64}; 70};
65 71
66int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 72int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
@@ -68,7 +74,7 @@ int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
68 u8 key[5]; 74 u8 key[5];
69 if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0), 75 if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0),
70 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5, 76 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5,
71 2*HZ) != 5) 77 2000) != 5)
72 return -ENODEV; 78 return -ENODEV;
73 79
74 /* call the universal NEC remote processor, to find out the key's state and event */ 80 /* call the universal NEC remote processor, to find out the key's state and event */
@@ -143,7 +149,7 @@ static struct dvb_usb_properties a800_properties = {
143 149
144static struct usb_driver a800_driver = { 150static struct usb_driver a800_driver = {
145 .owner = THIS_MODULE, 151 .owner = THIS_MODULE,
146 .name = "AVerMedia AverTV DVB-T USB 2.0 (A800)", 152 .name = "dvb_usb_a800",
147 .probe = a800_probe, 153 .probe = a800_probe,
148 .disconnect = dvb_usb_device_exit, 154 .disconnect = dvb_usb_device_exit,
149 .id_table = a800_table, 155 .id_table = a800_table,
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
new file mode 100644
index 000000000000..c3e1b661aae6
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -0,0 +1,295 @@
1/* DVB USB compliant linux driver for Conexant USB reference design.
2 *
3 * The Conexant reference design I saw on their website was only for analogue
4 * capturing (using the cx25842). The box I took to write this driver (reverse
5 * engineered) is the one labeled Medion MD95700. In addition to the cx25842
6 * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
7 * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
8 *
9 * Maybe it is a little bit premature to call this driver cxusb, but I assume
10 * the USB protocol is identical or at least inherited from the reference
11 * design, so it can be reused for the "analogue-only" device (if it will
12 * appear at all).
13 *
14 * TODO: check if the cx25840-driver (from ivtv) can be used for the analogue
15 * part
16 *
17 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the Free
21 * Software Foundation, version 2.
22 *
23 * see Documentation/dvb/README.dvb-usb for more information
24 */
25#include "cxusb.h"
26
27#include "cx22702.h"
28
29/* debug */
30int dvb_usb_cxusb_debug;
31module_param_named(debug,dvb_usb_cxusb_debug, int, 0644);
32MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
33
34static int cxusb_ctrl_msg(struct dvb_usb_device *d,
35 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
36{
37 int wo = (rbuf == NULL || rlen == 0); /* write-only */
38 u8 sndbuf[1+wlen];
39 memset(sndbuf,0,1+wlen);
40
41 sndbuf[0] = cmd;
42 memcpy(&sndbuf[1],wbuf,wlen);
43 if (wo)
44 dvb_usb_generic_write(d,sndbuf,1+wlen);
45 else
46 dvb_usb_generic_rw(d,sndbuf,1+wlen,rbuf,rlen,0);
47
48 return 0;
49}
50
51/* I2C */
52static void cxusb_set_i2c_path(struct dvb_usb_device *d, enum cxusb_i2c_pathes path)
53{
54 struct cxusb_state *st = d->priv;
55 u8 o[2],i;
56
57 if (path == st->cur_i2c_path)
58 return;
59
60 o[0] = IOCTL_SET_I2C_PATH;
61 switch (path) {
62 case PATH_CX22702:
63 o[1] = 0;
64 break;
65 case PATH_TUNER_OTHER:
66 o[1] = 1;
67 break;
68 default:
69 err("unkown i2c path");
70 return;
71 }
72 cxusb_ctrl_msg(d,CMD_IOCTL,o,2,&i,1);
73
74 if (i != 0x01)
75 deb_info("i2c_path setting failed.\n");
76
77 st->cur_i2c_path = path;
78}
79
80static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
81{
82 struct dvb_usb_device *d = i2c_get_adapdata(adap);
83 int i;
84
85 if (down_interruptible(&d->i2c_sem) < 0)
86 return -EAGAIN;
87
88 if (num > 2)
89 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
90
91 for (i = 0; i < num; i++) {
92
93 switch (msg[i].addr) {
94 case 0x63:
95 cxusb_set_i2c_path(d,PATH_CX22702);
96 break;
97 default:
98 cxusb_set_i2c_path(d,PATH_TUNER_OTHER);
99 break;
100 }
101
102 /* read request */
103 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
104 u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
105 obuf[0] = msg[i].len;
106 obuf[1] = msg[i+1].len;
107 obuf[2] = msg[i].addr;
108 memcpy(&obuf[3],msg[i].buf,msg[i].len);
109
110 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
111 obuf, 3+msg[i].len,
112 ibuf, 1+msg[i+1].len) < 0)
113 break;
114
115 if (ibuf[0] != 0x08)
116 deb_info("i2c read could have been failed\n");
117
118 memcpy(msg[i+1].buf,&ibuf[1],msg[i+1].len);
119
120 i++;
121 } else { /* write */
122 u8 obuf[2+msg[i].len], ibuf;
123 obuf[0] = msg[i].addr;
124 obuf[1] = msg[i].len;
125 memcpy(&obuf[2],msg[i].buf,msg[i].len);
126
127 if (cxusb_ctrl_msg(d,CMD_I2C_WRITE, obuf, 2+msg[i].len, &ibuf,1) < 0)
128 break;
129 if (ibuf != 0x08)
130 deb_info("i2c write could have been failed\n");
131 }
132 }
133
134 up(&d->i2c_sem);
135 return i;
136}
137
138static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
139{
140 return I2C_FUNC_I2C;
141}
142
143static struct i2c_algorithm cxusb_i2c_algo = {
144 .name = "Conexant USB I2C algorithm",
145 .id = I2C_ALGO_BIT,
146 .master_xfer = cxusb_i2c_xfer,
147 .functionality = cxusb_i2c_func,
148};
149
150static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
151{
152 return 0;
153}
154
155static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
156{
157 u8 buf[2] = { 0x03, 0x00 };
158 if (onoff)
159 cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0);
160 else
161 cxusb_ctrl_msg(d,0x37, NULL, 0, NULL, 0);
162
163 return 0;
164}
165
166struct cx22702_config cxusb_cx22702_config = {
167 .demod_address = 0x63,
168
169 .output_mode = CX22702_PARALLEL_OUTPUT,
170
171 .pll_init = dvb_usb_pll_init_i2c,
172 .pll_set = dvb_usb_pll_set_i2c,
173};
174
175/* Callbacks for DVB USB */
176static int cxusb_tuner_attach(struct dvb_usb_device *d)
177{
178 u8 bpll[4] = { 0x0b, 0xdc, 0x9c, 0xa0 };
179 d->pll_addr = 0x61;
180 memcpy(d->pll_init,bpll,4);
181 d->pll_desc = &dvb_pll_fmd1216me;
182 return 0;
183}
184
185static int cxusb_frontend_attach(struct dvb_usb_device *d)
186{
187 u8 buf[2] = { 0x03, 0x00 };
188 u8 b = 0;
189
190 if (usb_set_interface(d->udev,0,0) < 0)
191 err("set interface to alts=0 failed");
192
193 cxusb_ctrl_msg(d,0xde,&b,0,NULL,0);
194 cxusb_set_i2c_path(d,PATH_TUNER_OTHER);
195 cxusb_ctrl_msg(d,CMD_POWER_OFF, NULL, 0, &b, 1);
196
197 if (usb_set_interface(d->udev,0,6) < 0)
198 err("set interface failed");
199
200 cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0);
201 cxusb_set_i2c_path(d,PATH_CX22702);
202 cxusb_ctrl_msg(d,CMD_POWER_ON, NULL, 0, &b, 1);
203
204 if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL)
205 return 0;
206
207 return -EIO;
208}
209
210/* DVB USB Driver stuff */
211static struct dvb_usb_properties cxusb_properties;
212
213static int cxusb_probe(struct usb_interface *intf,
214 const struct usb_device_id *id)
215{
216 return dvb_usb_device_init(intf,&cxusb_properties,THIS_MODULE);
217}
218
219static struct usb_device_id cxusb_table [] = {
220 { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
221 {} /* Terminating entry */
222};
223MODULE_DEVICE_TABLE (usb, cxusb_table);
224
225static struct dvb_usb_properties cxusb_properties = {
226 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
227
228 .usb_ctrl = CYPRESS_FX2,
229
230 .size_of_priv = sizeof(struct cxusb_state),
231
232 .streaming_ctrl = cxusb_streaming_ctrl,
233 .power_ctrl = cxusb_power_ctrl,
234 .frontend_attach = cxusb_frontend_attach,
235 .tuner_attach = cxusb_tuner_attach,
236
237 .i2c_algo = &cxusb_i2c_algo,
238
239 .generic_bulk_ctrl_endpoint = 0x01,
240 /* parameter for the MPEG2-data transfer */
241 .urb = {
242 .type = DVB_USB_ISOC,
243 .count = 5,
244 .endpoint = 0x02,
245 .u = {
246 .isoc = {
247 .framesperurb = 32,
248 .framesize = 940,
249 .interval = 5,
250 }
251 }
252 },
253
254 .num_device_descs = 1,
255 .devices = {
256 { "Medion MD95700 (MDUSBTV-HYBRID)",
257 { NULL },
258 { &cxusb_table[0], NULL },
259 },
260 }
261};
262
263static struct usb_driver cxusb_driver = {
264 .owner = THIS_MODULE,
265 .name = "dvb_usb_cxusb",
266 .probe = cxusb_probe,
267 .disconnect = dvb_usb_device_exit,
268 .id_table = cxusb_table,
269};
270
271/* module stuff */
272static int __init cxusb_module_init(void)
273{
274 int result;
275 if ((result = usb_register(&cxusb_driver))) {
276 err("usb_register failed. Error number %d",result);
277 return result;
278 }
279
280 return 0;
281}
282
283static void __exit cxusb_module_exit(void)
284{
285 /* deregister this driver from the USB subsystem */
286 usb_deregister(&cxusb_driver);
287}
288
289module_init (cxusb_module_init);
290module_exit (cxusb_module_exit);
291
292MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
293MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
294MODULE_VERSION("1.0-alpha");
295MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/cxusb.h b/drivers/media/dvb/dvb-usb/cxusb.h
new file mode 100644
index 000000000000..1d79016e3195
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cxusb.h
@@ -0,0 +1,30 @@
1#ifndef _DVB_USB_CXUSB_H_
2#define _DVB_USB_CXUSB_H_
3
4#define DVB_USB_LOG_PREFIX "digitv"
5#include "dvb-usb.h"
6
7extern int dvb_usb_cxusb_debug;
8#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
9
10/* usb commands - some of it are guesses, don't have a reference yet */
11#define CMD_I2C_WRITE 0x08
12#define CMD_I2C_READ 0x09
13
14#define CMD_IOCTL 0x0e
15#define IOCTL_SET_I2C_PATH 0x02
16
17#define CMD_POWER_OFF 0x50
18#define CMD_POWER_ON 0x51
19
20enum cxusb_i2c_pathes {
21 PATH_UNDEF = 0x00,
22 PATH_CX22702 = 0x01,
23 PATH_TUNER_OTHER = 0x02,
24};
25
26struct cxusb_state {
27 enum cxusb_i2c_pathes cur_i2c_path;
28};
29
30#endif
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index a0ffbb59fa14..828b5182e16c 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -31,10 +31,17 @@ static int dibusb_dib3000mb_frontend_attach(struct dvb_usb_device *d)
31 return 0; 31 return 0;
32} 32}
33 33
34/* some of the dibusb 1.1 device aren't equipped with the default tuner 34static int dibusb_thomson_tuner_attach(struct dvb_usb_device *d)
35{
36 d->pll_addr = 0x61;
37 d->pll_desc = &dvb_pll_tua6010xs;
38 return 0;
39}
40
41/* Some of the Artec 1.1 device aren't equipped with the default tuner
35 * (Thomson Cable), but with a Panasonic ENV77H11D5. This function figures 42 * (Thomson Cable), but with a Panasonic ENV77H11D5. This function figures
36 * this out. */ 43 * this out. */
37static int dibusb_dib3000mb_tuner_attach (struct dvb_usb_device *d) 44static int dibusb_tuner_probe_and_attach(struct dvb_usb_device *d)
38{ 45{
39 u8 b[2] = { 0,0 }, b2[1]; 46 u8 b[2] = { 0,0 }, b2[1];
40 int ret = 0; 47 int ret = 0;
@@ -59,8 +66,7 @@ static int dibusb_dib3000mb_tuner_attach (struct dvb_usb_device *d)
59 66
60 if (b2[0] == 0xfe) { 67 if (b2[0] == 0xfe) {
61 info("this device has the Thomson Cable onboard. Which is default."); 68 info("this device has the Thomson Cable onboard. Which is default.");
62 d->pll_addr = 0x61; 69 dibusb_thomson_tuner_attach(d);
63 d->pll_desc = &dvb_pll_tua6010xs;
64 } else { 70 } else {
65 u8 bpll[4] = { 0x0b, 0xf5, 0x85, 0xab }; 71 u8 bpll[4] = { 0x0b, 0xf5, 0x85, 0xab };
66 info("this device has the Panasonic ENV77H11D5 onboard."); 72 info("this device has the Panasonic ENV77H11D5 onboard.");
@@ -90,8 +96,8 @@ static int dibusb_probe(struct usb_interface *intf,
90 96
91/* do not change the order of the ID table */ 97/* do not change the order of the ID table */
92static struct usb_device_id dibusb_dib3000mb_table [] = { 98static struct usb_device_id dibusb_dib3000mb_table [] = {
93/* 00 */ { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_AVERMEDIA_DVBT_USB_COLD)}, 99/* 00 */ { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_AVERMEDIA_DVBT_USB_COLD)},
94/* 01 */ { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_AVERMEDIA_DVBT_USB_WARM)}, 100/* 01 */ { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_AVERMEDIA_DVBT_USB_WARM)},
95/* 02 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_COLD) }, 101/* 02 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_COLD) },
96/* 03 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_WARM) }, 102/* 03 */ { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_DVBU2000_WARM) },
97/* 04 */ { USB_DEVICE(USB_VID_COMPRO_UNK, USB_PID_COMPRO_DVBU2000_UNK_COLD) }, 103/* 04 */ { USB_DEVICE(USB_VID_COMPRO_UNK, USB_PID_COMPRO_DVBU2000_UNK_COLD) },
@@ -114,7 +120,17 @@ static struct usb_device_id dibusb_dib3000mb_table [] = {
114/* 21 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_COLD) }, 120/* 21 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_COLD) },
115/* 22 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_WARM) }, 121/* 22 */ { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ULTIMA_TVBOX_AN2235_WARM) },
116/* 23 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_COLD) }, 122/* 23 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_COLD) },
123
124/* device ID with default DIBUSB2_0-firmware and with the hacked firmware */
117/* 24 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_WARM) }, 125/* 24 */ { USB_DEVICE(USB_VID_ADSTECH, USB_PID_ADSTECH_USB2_WARM) },
126/* 25 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_COLD) },
127/* 26 */ { USB_DEVICE(USB_VID_KYE, USB_PID_KYE_DVB_T_WARM) },
128
129// #define DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
130
131#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
132/* 27 */ { USB_DEVICE(USB_VID_ANCHOR, USB_PID_ULTIMA_TVBOX_ANCHOR_COLD) },
133#endif
118 { } /* Terminating entry */ 134 { } /* Terminating entry */
119}; 135};
120MODULE_DEVICE_TABLE (usb, dibusb_dib3000mb_table); 136MODULE_DEVICE_TABLE (usb, dibusb_dib3000mb_table);
@@ -134,7 +150,7 @@ static struct dvb_usb_properties dibusb1_1_properties = {
134 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 150 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
135 .power_ctrl = dibusb_power_ctrl, 151 .power_ctrl = dibusb_power_ctrl,
136 .frontend_attach = dibusb_dib3000mb_frontend_attach, 152 .frontend_attach = dibusb_dib3000mb_frontend_attach,
137 .tuner_attach = dibusb_dib3000mb_tuner_attach, 153 .tuner_attach = dibusb_tuner_probe_and_attach,
138 154
139 .rc_interval = DEFAULT_RC_INTERVAL, 155 .rc_interval = DEFAULT_RC_INTERVAL,
140 .rc_key_map = dibusb_rc_keys, 156 .rc_key_map = dibusb_rc_keys,
@@ -156,7 +172,7 @@ static struct dvb_usb_properties dibusb1_1_properties = {
156 } 172 }
157 }, 173 },
158 174
159 .num_device_descs = 8, 175 .num_device_descs = 9,
160 .devices = { 176 .devices = {
161 { "AVerMedia AverTV DVBT USB1.1", 177 { "AVerMedia AverTV DVBT USB1.1",
162 { &dibusb_dib3000mb_table[0], NULL }, 178 { &dibusb_dib3000mb_table[0], NULL },
@@ -190,11 +206,17 @@ static struct dvb_usb_properties dibusb1_1_properties = {
190 { &dibusb_dib3000mb_table[19], NULL }, 206 { &dibusb_dib3000mb_table[19], NULL },
191 { &dibusb_dib3000mb_table[20], NULL }, 207 { &dibusb_dib3000mb_table[20], NULL },
192 }, 208 },
209 { "VideoWalker DVB-T USB",
210 { &dibusb_dib3000mb_table[25], NULL },
211 { &dibusb_dib3000mb_table[26], NULL },
212 },
193 } 213 }
194}; 214};
195 215
196static struct dvb_usb_properties dibusb1_1_an2235_properties = { 216static struct dvb_usb_properties dibusb1_1_an2235_properties = {
197 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER, 217 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
218 .pid_filter_count = 16,
219
198 .usb_ctrl = CYPRESS_AN2235, 220 .usb_ctrl = CYPRESS_AN2235,
199 221
200 .firmware = "dvb-usb-dibusb-an2235-01.fw", 222 .firmware = "dvb-usb-dibusb-an2235-01.fw",
@@ -206,7 +228,7 @@ static struct dvb_usb_properties dibusb1_1_an2235_properties = {
206 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 228 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
207 .power_ctrl = dibusb_power_ctrl, 229 .power_ctrl = dibusb_power_ctrl,
208 .frontend_attach = dibusb_dib3000mb_frontend_attach, 230 .frontend_attach = dibusb_dib3000mb_frontend_attach,
209 .tuner_attach = dibusb_dib3000mb_tuner_attach, 231 .tuner_attach = dibusb_tuner_probe_and_attach,
210 232
211 .rc_interval = DEFAULT_RC_INTERVAL, 233 .rc_interval = DEFAULT_RC_INTERVAL,
212 .rc_key_map = dibusb_rc_keys, 234 .rc_key_map = dibusb_rc_keys,
@@ -228,20 +250,32 @@ static struct dvb_usb_properties dibusb1_1_an2235_properties = {
228 } 250 }
229 }, 251 },
230 252
253#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
254 .num_device_descs = 2,
255#else
231 .num_device_descs = 1, 256 .num_device_descs = 1,
257#endif
232 .devices = { 258 .devices = {
233 { "Artec T1 USB1.1 TVBOX with AN2235", 259 { "Artec T1 USB1.1 TVBOX with AN2235",
234 { &dibusb_dib3000mb_table[20], NULL }, 260 { &dibusb_dib3000mb_table[20], NULL },
235 { &dibusb_dib3000mb_table[21], NULL }, 261 { &dibusb_dib3000mb_table[21], NULL },
236 }, 262 },
263#ifdef DVB_USB_DIBUSB_MB_FAULTY_USB_IDs
264 { "Artec T1 USB1.1 TVBOX with AN2235 (faulty USB IDs)",
265 { &dibusb_dib3000mb_table[27], NULL },
266 { NULL },
267 },
268#endif
237 } 269 }
238}; 270};
239 271
240static struct dvb_usb_properties dibusb2_0b_properties = { 272static struct dvb_usb_properties dibusb2_0b_properties = {
241 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER, 273 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_IS_AN_I2C_ADAPTER,
274 .pid_filter_count = 32,
275
242 .usb_ctrl = CYPRESS_FX2, 276 .usb_ctrl = CYPRESS_FX2,
243 277
244 .firmware = "dvb-usb-adstech-usb2-01.fw", 278 .firmware = "dvb-usb-adstech-usb2-02.fw",
245 279
246 .size_of_priv = sizeof(struct dibusb_state), 280 .size_of_priv = sizeof(struct dibusb_state),
247 281
@@ -250,7 +284,7 @@ static struct dvb_usb_properties dibusb2_0b_properties = {
250 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 284 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
251 .power_ctrl = dibusb2_0_power_ctrl, 285 .power_ctrl = dibusb2_0_power_ctrl,
252 .frontend_attach = dibusb_dib3000mb_frontend_attach, 286 .frontend_attach = dibusb_dib3000mb_frontend_attach,
253 .tuner_attach = dibusb_dib3000mb_tuner_attach, 287 .tuner_attach = dibusb_thomson_tuner_attach,
254 288
255 .rc_interval = DEFAULT_RC_INTERVAL, 289 .rc_interval = DEFAULT_RC_INTERVAL,
256 .rc_key_map = dibusb_rc_keys, 290 .rc_key_map = dibusb_rc_keys,
@@ -272,18 +306,18 @@ static struct dvb_usb_properties dibusb2_0b_properties = {
272 } 306 }
273 }, 307 },
274 308
275 .num_device_descs = 2, 309 .num_device_descs = 1,
276 .devices = { 310 .devices = {
277 { "KWorld/ADSTech Instant DVB-T USB 2.0", 311 { "KWorld/ADSTech Instant DVB-T USB 2.0",
278 { &dibusb_dib3000mb_table[23], NULL }, 312 { &dibusb_dib3000mb_table[23], NULL },
279 { &dibusb_dib3000mb_table[24], NULL }, /* device ID with default DIBUSB2_0-firmware */ 313 { &dibusb_dib3000mb_table[24], NULL },
280 }, 314 },
281 } 315 }
282}; 316};
283 317
284static struct usb_driver dibusb_driver = { 318static struct usb_driver dibusb_driver = {
285 .owner = THIS_MODULE, 319 .owner = THIS_MODULE,
286 .name = "DiBcom based USB DVB-T devices (DiB3000M-B based)", 320 .name = "dvb_usb_dibusb_mb",
287 .probe = dibusb_probe, 321 .probe = dibusb_probe,
288 .disconnect = dvb_usb_device_exit, 322 .disconnect = dvb_usb_device_exit,
289 .id_table = dibusb_dib3000mb_table, 323 .id_table = dibusb_dib3000mb_table,
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index aad8ed3fe005..e9dac430f37d 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -83,7 +83,7 @@ static struct dvb_usb_properties dibusb_mc_properties = {
83 83
84static struct usb_driver dibusb_mc_driver = { 84static struct usb_driver dibusb_mc_driver = {
85 .owner = THIS_MODULE, 85 .owner = THIS_MODULE,
86 .name = "DiBcom based USB2.0 DVB-T (DiB3000M-C/P based) devices", 86 .name = "dvb_usb_dibusb_mc",
87 .probe = dibusb_mc_probe, 87 .probe = dibusb_mc_probe,
88 .disconnect = dvb_usb_device_exit, 88 .disconnect = dvb_usb_device_exit,
89 .id_table = dibusb_dib3000mc_table, 89 .id_table = dibusb_dib3000mc_table,
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 5acf3fde9522..9a676afc1d6e 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -1,10 +1,9 @@
1/* DVB USB compliant linux driver for Nebula Electronics uDigiTV DVB-T USB2.0 1/* DVB USB compliant linux driver for Nebula Electronics uDigiTV DVB-T USB2.0
2 * receiver 2 * receiver
3 * 3 *
4 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) and 4 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
5 * Allan Third (allan.third@cs.man.ac.uk)
6 * 5 *
7 * partly based on the SDK published by Nebula Electronics (TODO do we want this line ?) 6 * partly based on the SDK published by Nebula Electronics
8 * 7 *
9 * This program is free software; you can redistribute it and/or modify it 8 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free 9 * under the terms of the GNU General Public License as published by the Free
@@ -38,7 +37,7 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
38 dvb_usb_generic_write(d,sndbuf,7); 37 dvb_usb_generic_write(d,sndbuf,7);
39 } else { 38 } else {
40 dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10); 39 dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
41 memcpy(&rbuf,&rcvbuf[3],rlen); 40 memcpy(rbuf,&rcvbuf[3],rlen);
42 } 41 }
43 return 0; 42 return 0;
44} 43}
@@ -95,41 +94,20 @@ static int digitv_identify_state (struct usb_device *udev, struct
95 94
96static int digitv_mt352_demod_init(struct dvb_frontend *fe) 95static int digitv_mt352_demod_init(struct dvb_frontend *fe)
97{ 96{
98 static u8 mt352_clock_config[] = { 0x89, 0x38, 0x2d }; 97 static u8 reset_buf[] = { 0x89, 0x38, 0x8a, 0x2d, 0x50, 0x80 };
99 static u8 mt352_reset[] = { 0x50, 0x80 }; 98 static u8 init_buf[] = { 0x68, 0xa0, 0x8e, 0x40, 0x53, 0x50,
100 static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 }; 99 0x67, 0x20, 0x7d, 0x01, 0x7c, 0x00, 0x7a, 0x00,
101 100 0x79, 0x20, 0x57, 0x05, 0x56, 0x31, 0x88, 0x0f,
102 static u8 mt352_agc_cfg[] = { 0x68, 0xa0 }; 101 0x75, 0x32 };
103 static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0xa0 }; 102 int i;
104 static u8 mt352_acq_ctl[] = { 0x53, 0x50 };
105 static u8 mt352_agc_target[] = { 0x67, 0x20 };
106
107 static u8 mt352_rs_err_per[] = { 0x7c, 0x00, 0x01 };
108 static u8 mt352_snr_select[] = { 0x79, 0x00, 0x20 };
109
110 static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x05 };
111 103
112 static u8 mt352_scan_ctl[] = { 0x88, 0x0f }; 104 for (i = 0; i < ARRAY_SIZE(reset_buf); i += 2)
113 static u8 mt352_capt_range[] = { 0x75, 0x32 }; 105 mt352_write(fe, &reset_buf[i], 2);
114 106
115 mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
116 mt352_write(fe, mt352_reset, sizeof(mt352_reset));
117 msleep(1); 107 msleep(1);
118 mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio));
119
120 mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
121 mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
122 mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl));
123 mt352_write(fe, mt352_agc_target, sizeof(mt352_agc_target));
124
125
126 mt352_write(fe, mt352_rs_err_per, sizeof(mt352_rs_err_per));
127 mt352_write(fe, mt352_snr_select, sizeof(mt352_snr_select));
128 108
129 mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1)); 109 for (i = 0; i < ARRAY_SIZE(init_buf); i += 2)
130 110 mt352_write(fe, &init_buf[i], 2);
131 mt352_write(fe, mt352_scan_ctl, sizeof(mt352_scan_ctl));
132 mt352_write(fe, mt352_capt_range, sizeof(mt352_capt_range));
133 111
134 return 0; 112 return 0;
135} 113}
@@ -137,7 +115,7 @@ static int digitv_mt352_demod_init(struct dvb_frontend *fe)
137static struct mt352_config digitv_mt352_config = { 115static struct mt352_config digitv_mt352_config = {
138 .demod_address = 0x0, /* ignored by the digitv anyway */ 116 .demod_address = 0x0, /* ignored by the digitv anyway */
139 .demod_init = digitv_mt352_demod_init, 117 .demod_init = digitv_mt352_demod_init,
140 .pll_set = NULL, /* TODO */ 118 .pll_set = dvb_usb_pll_set,
141}; 119};
142 120
143static struct nxt6000_config digitv_nxt6000_config = { 121static struct nxt6000_config digitv_nxt6000_config = {
@@ -150,9 +128,9 @@ static struct nxt6000_config digitv_nxt6000_config = {
150 128
151static int digitv_frontend_attach(struct dvb_usb_device *d) 129static int digitv_frontend_attach(struct dvb_usb_device *d)
152{ 130{
153 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) == NULL) 131 if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) != NULL)
154 return 0; 132 return 0;
155 if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) == NULL) { 133 if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) != NULL) {
156 134
157 warn("nxt6000 support is not done yet, in fact you are one of the first " 135 warn("nxt6000 support is not done yet, in fact you are one of the first "
158 "person who wants to use this device in Linux. Please report to " 136 "person who wants to use this device in Linux. Please report to "
@@ -163,6 +141,13 @@ static int digitv_frontend_attach(struct dvb_usb_device *d)
163 return -EIO; 141 return -EIO;
164} 142}
165 143
144static int digitv_tuner_attach(struct dvb_usb_device *d)
145{
146 d->pll_addr = 0x60;
147 d->pll_desc = &dvb_pll_tded4;
148 return 0;
149}
150
166static struct dvb_usb_rc_key digitv_rc_keys[] = { 151static struct dvb_usb_rc_key digitv_rc_keys[] = {
167 { 0x00, 0x16, KEY_POWER }, /* dummy key */ 152 { 0x00, 0x16, KEY_POWER }, /* dummy key */
168}; 153};
@@ -184,7 +169,6 @@ int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
184 return 0; 169 return 0;
185} 170}
186 171
187
188/* DVB USB Driver stuff */ 172/* DVB USB Driver stuff */
189static struct dvb_usb_properties digitv_properties; 173static struct dvb_usb_properties digitv_properties;
190 174
@@ -208,13 +192,8 @@ static struct dvb_usb_properties digitv_properties = {
208 192
209 .size_of_priv = 0, 193 .size_of_priv = 0,
210 194
211 .streaming_ctrl = NULL,
212 .pid_filter = NULL,
213 .pid_filter_ctrl = NULL,
214 .power_ctrl = NULL,
215 .frontend_attach = digitv_frontend_attach, 195 .frontend_attach = digitv_frontend_attach,
216 .tuner_attach = NULL, // digitv_tuner_attach, 196 .tuner_attach = digitv_tuner_attach,
217 .read_mac_address = NULL,
218 197
219 .rc_interval = 1000, 198 .rc_interval = 1000,
220 .rc_key_map = digitv_rc_keys, 199 .rc_key_map = digitv_rc_keys,
@@ -238,7 +217,7 @@ static struct dvb_usb_properties digitv_properties = {
238 } 217 }
239 }, 218 },
240 219
241 .num_device_descs = 2, 220 .num_device_descs = 1,
242 .devices = { 221 .devices = {
243 { "Nebula Electronics uDigiTV DVB-T USB2.0)", 222 { "Nebula Electronics uDigiTV DVB-T USB2.0)",
244 { &digitv_table[0], NULL }, 223 { &digitv_table[0], NULL },
@@ -249,7 +228,7 @@ static struct dvb_usb_properties digitv_properties = {
249 228
250static struct usb_driver digitv_driver = { 229static struct usb_driver digitv_driver = {
251 .owner = THIS_MODULE, 230 .owner = THIS_MODULE,
252 .name = "Nebula Electronics uDigiTV DVB-T USB2.0 device", 231 .name = "dvb_usb_digitv",
253 .probe = digitv_probe, 232 .probe = digitv_probe,
254 .disconnect = dvb_usb_device_exit, 233 .disconnect = dvb_usb_device_exit,
255 .id_table = digitv_table, 234 .id_table = digitv_table,
diff --git a/drivers/media/dvb/dvb-usb/dtt200u-fe.c b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
index d17d768038c6..b032523b07bc 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
@@ -1,5 +1,5 @@
1/* Frontend part of the Linux driver for the Yakumo/Hama/Typhoon DVB-T 1/* Frontend part of the Linux driver for the WideView/ Yakumo/ Hama/
2 * USB2.0 receiver. 2 * Typhoon/ Yuan DVB-T USB2.0 receiver.
3 * 3 *
4 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de> 4 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
5 * 5 *
@@ -14,61 +14,58 @@
14struct dtt200u_fe_state { 14struct dtt200u_fe_state {
15 struct dvb_usb_device *d; 15 struct dvb_usb_device *d;
16 16
17 fe_status_t stat;
18
17 struct dvb_frontend_parameters fep; 19 struct dvb_frontend_parameters fep;
18 struct dvb_frontend frontend; 20 struct dvb_frontend frontend;
19}; 21};
20 22
21#define moan(which,what) info("unexpected value in '%s' for cmd '%02x' - please report to linux-dvb@linuxtv.org",which,what)
22
23static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat) 23static int dtt200u_fe_read_status(struct dvb_frontend* fe, fe_status_t *stat)
24{ 24{
25 struct dtt200u_fe_state *state = fe->demodulator_priv; 25 struct dtt200u_fe_state *state = fe->demodulator_priv;
26 u8 bw = GET_TUNE_STAT; 26 u8 st = GET_TUNE_STATUS, b[3];
27 u8 br[3] = { 0 }; 27
28// u8 bdeb[5] = { 0 }; 28 dvb_usb_generic_rw(state->d,&st,1,b,3,0);
29 29
30 dvb_usb_generic_rw(state->d,&bw,1,br,3,0); 30 switch (b[0]) {
31 switch (br[0]) {
32 case 0x01: 31 case 0x01:
33 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 32 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
33 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
34 break; 34 break;
35 case 0x00: 35 case 0x00: /* pending */
36 *stat = 0; 36 *stat = FE_TIMEDOUT; /* during set_frontend */
37 break; 37 break;
38 default: 38 default:
39 moan("br[0]",GET_TUNE_STAT); 39 case 0x02: /* failed */
40 *stat = 0;
40 break; 41 break;
41 } 42 }
42
43// bw[0] = 0x88;
44// dvb_usb_generic_rw(state->d,bw,1,bdeb,5,0);
45
46// deb_info("%02x: %02x %02x %02x %02x %02x\n",bw[0],bdeb[0],bdeb[1],bdeb[2],bdeb[3],bdeb[4]);
47
48 return 0; 43 return 0;
49} 44}
45
50static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) 46static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
51{ 47{
52 struct dtt200u_fe_state *state = fe->demodulator_priv; 48 struct dtt200u_fe_state *state = fe->demodulator_priv;
53 u8 bw = GET_BER; 49 u8 bw = GET_VIT_ERR_CNT,b[3];
54 *ber = 0; 50 dvb_usb_generic_rw(state->d,&bw,1,b,3,0);
55 dvb_usb_generic_rw(state->d,&bw,1,(u8*) ber,3,0); 51 *ber = (b[0] << 16) | (b[1] << 8) | b[2];
56 return 0; 52 return 0;
57} 53}
58 54
59static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 55static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
60{ 56{
61 struct dtt200u_fe_state *state = fe->demodulator_priv; 57 struct dtt200u_fe_state *state = fe->demodulator_priv;
62 u8 bw = GET_UNK; 58 u8 bw = GET_RS_UNCOR_BLK_CNT,b[2];
63 *unc = 0; 59
64 dvb_usb_generic_rw(state->d,&bw,1,(u8*) unc,3,0); 60 dvb_usb_generic_rw(state->d,&bw,1,b,2,0);
61 *unc = (b[0] << 8) | b[1];
65 return 0; 62 return 0;
66} 63}
67 64
68static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 65static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
69{ 66{
70 struct dtt200u_fe_state *state = fe->demodulator_priv; 67 struct dtt200u_fe_state *state = fe->demodulator_priv;
71 u8 bw = GET_SIG_STRENGTH, b; 68 u8 bw = GET_AGC, b;
72 dvb_usb_generic_rw(state->d,&bw,1,&b,1,0); 69 dvb_usb_generic_rw(state->d,&bw,1,&b,1,0);
73 *strength = (b << 8) | b; 70 *strength = (b << 8) | b;
74 return 0; 71 return 0;
@@ -86,7 +83,7 @@ static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
86static int dtt200u_fe_init(struct dvb_frontend* fe) 83static int dtt200u_fe_init(struct dvb_frontend* fe)
87{ 84{
88 struct dtt200u_fe_state *state = fe->demodulator_priv; 85 struct dtt200u_fe_state *state = fe->demodulator_priv;
89 u8 b = RESET_DEMOD; 86 u8 b = SET_INIT;
90 return dvb_usb_generic_write(state->d,&b,1); 87 return dvb_usb_generic_write(state->d,&b,1);
91} 88}
92 89
@@ -98,8 +95,8 @@ static int dtt200u_fe_sleep(struct dvb_frontend* fe)
98static int dtt200u_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 95static int dtt200u_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
99{ 96{
100 tune->min_delay_ms = 1500; 97 tune->min_delay_ms = 1500;
101 tune->step_size = 166667; 98 tune->step_size = 0;
102 tune->max_drift = 166667 * 2; 99 tune->max_drift = 0;
103 return 0; 100 return 0;
104} 101}
105 102
@@ -107,27 +104,32 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend* fe,
107 struct dvb_frontend_parameters *fep) 104 struct dvb_frontend_parameters *fep)
108{ 105{
109 struct dtt200u_fe_state *state = fe->demodulator_priv; 106 struct dtt200u_fe_state *state = fe->demodulator_priv;
107 int i;
108 fe_status_t st;
110 u16 freq = fep->frequency / 250000; 109 u16 freq = fep->frequency / 250000;
111 u8 bw,bwbuf[2] = { SET_BANDWIDTH, 0 }, freqbuf[3] = { SET_FREQUENCY, 0, 0 }; 110 u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
112 111
113 switch (fep->u.ofdm.bandwidth) { 112 switch (fep->u.ofdm.bandwidth) {
114 case BANDWIDTH_8_MHZ: bw = 8; break; 113 case BANDWIDTH_8_MHZ: bwbuf[1] = 8; break;
115 case BANDWIDTH_7_MHZ: bw = 7; break; 114 case BANDWIDTH_7_MHZ: bwbuf[1] = 7; break;
116 case BANDWIDTH_6_MHZ: bw = 6; break; 115 case BANDWIDTH_6_MHZ: bwbuf[1] = 6; break;
117 case BANDWIDTH_AUTO: return -EOPNOTSUPP; 116 case BANDWIDTH_AUTO: return -EOPNOTSUPP;
118 default: 117 default:
119 return -EINVAL; 118 return -EINVAL;
120 } 119 }
121 deb_info("set_frontend\n");
122 120
123 bwbuf[1] = bw;
124 dvb_usb_generic_write(state->d,bwbuf,2); 121 dvb_usb_generic_write(state->d,bwbuf,2);
125 122
126 freqbuf[1] = freq & 0xff; 123 freqbuf[1] = freq & 0xff;
127 freqbuf[2] = (freq >> 8) & 0xff; 124 freqbuf[2] = (freq >> 8) & 0xff;
128 dvb_usb_generic_write(state->d,freqbuf,3); 125 dvb_usb_generic_write(state->d,freqbuf,3);
129 126
130 memcpy(&state->fep,fep,sizeof(struct dvb_frontend_parameters)); 127 for (i = 0; i < 30; i++) {
128 msleep(20);
129 dtt200u_fe_read_status(fe, &st);
130 if (st & FE_TIMEDOUT)
131 continue;
132 }
131 133
132 return 0; 134 return 0;
133} 135}
@@ -174,7 +176,7 @@ success:
174 176
175static struct dvb_frontend_ops dtt200u_fe_ops = { 177static struct dvb_frontend_ops dtt200u_fe_ops = {
176 .info = { 178 .info = {
177 .name = "DTT200U (Yakumo/Typhoon/Hama) DVB-T", 179 .name = "WideView USB DVB-T",
178 .type = FE_OFDM, 180 .type = FE_OFDM,
179 .frequency_min = 44250000, 181 .frequency_min = 44250000,
180 .frequency_max = 867250000, 182 .frequency_max = 867250000,
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index fb2b5a2da137..47dba6e45968 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -1,8 +1,10 @@
1/* DVB USB library compliant Linux driver for the Yakumo/Hama/Typhoon DVB-T 1/* DVB USB library compliant Linux driver for the WideView/ Yakumo/ Hama/
2 * USB2.0 receiver. 2 * Typhoon/ Yuan DVB-T USB2.0 receiver.
3 * 3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) 4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 * 5 *
6 * Thanks to Steve Chang from WideView for providing support for the WT-220U.
7 *
6 * This program is free software; you can redistribute it and/or modify it 8 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free 9 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2. 10 * Software Foundation, version 2.
@@ -16,14 +18,24 @@ int dvb_usb_dtt200u_debug;
16module_param_named(debug,dvb_usb_dtt200u_debug, int, 0644); 18module_param_named(debug,dvb_usb_dtt200u_debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS); 19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS);
18 20
21static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
22{
23 u8 b = SET_INIT;
24
25 if (onoff)
26 dvb_usb_generic_write(d,&b,2);
27
28 return 0;
29}
30
19static int dtt200u_streaming_ctrl(struct dvb_usb_device *d, int onoff) 31static int dtt200u_streaming_ctrl(struct dvb_usb_device *d, int onoff)
20{ 32{
21 u8 b_streaming[2] = { SET_TS_CTRL, onoff }; 33 u8 b_streaming[2] = { SET_STREAMING, onoff };
22 u8 b_rst_pid = RESET_PID_FILTER; 34 u8 b_rst_pid = RESET_PID_FILTER;
23 35
24 dvb_usb_generic_write(d,b_streaming,2); 36 dvb_usb_generic_write(d,b_streaming,2);
25 37
26 if (!onoff) 38 if (onoff == 0)
27 dvb_usb_generic_write(d,&b_rst_pid,1); 39 dvb_usb_generic_write(d,&b_rst_pid,1);
28 return 0; 40 return 0;
29} 41}
@@ -36,7 +48,7 @@ static int dtt200u_pid_filter(struct dvb_usb_device *d, int index, u16 pid, int
36 b_pid[0] = SET_PID_FILTER; 48 b_pid[0] = SET_PID_FILTER;
37 b_pid[1] = index; 49 b_pid[1] = index;
38 b_pid[2] = pid & 0xff; 50 b_pid[2] = pid & 0xff;
39 b_pid[3] = (pid >> 8) & 0xff; 51 b_pid[3] = (pid >> 8) & 0x1f;
40 52
41 return dvb_usb_generic_write(d,b_pid,4); 53 return dvb_usb_generic_write(d,b_pid,4);
42} 54}
@@ -54,9 +66,9 @@ static struct dvb_usb_rc_key dtt200u_rc_keys[] = {
54 { 0x80, 0x08, KEY_5 }, 66 { 0x80, 0x08, KEY_5 },
55 { 0x80, 0x09, KEY_6 }, 67 { 0x80, 0x09, KEY_6 },
56 { 0x80, 0x0a, KEY_7 }, 68 { 0x80, 0x0a, KEY_7 },
57 { 0x00, 0x0c, KEY_ZOOM }, 69 { 0x80, 0x0c, KEY_ZOOM },
58 { 0x80, 0x0d, KEY_0 }, 70 { 0x80, 0x0d, KEY_0 },
59 { 0x00, 0x0e, KEY_SELECT }, 71 { 0x80, 0x0e, KEY_SELECT },
60 { 0x80, 0x12, KEY_POWER }, 72 { 0x80, 0x12, KEY_POWER },
61 { 0x80, 0x1a, KEY_CHANNELUP }, 73 { 0x80, 0x1a, KEY_CHANNELUP },
62 { 0x80, 0x1b, KEY_8 }, 74 { 0x80, 0x1b, KEY_8 },
@@ -66,7 +78,7 @@ static struct dvb_usb_rc_key dtt200u_rc_keys[] = {
66 78
67static int dtt200u_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 79static int dtt200u_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
68{ 80{
69 u8 key[5],cmd = GET_RC_KEY; 81 u8 key[5],cmd = GET_RC_CODE;
70 dvb_usb_generic_rw(d,&cmd,1,key,5,0); 82 dvb_usb_generic_rw(d,&cmd,1,key,5,0);
71 dvb_usb_nec_rc_key_to_event(d,key,event,state); 83 dvb_usb_nec_rc_key_to_event(d,key,event,state);
72 if (key[0] != 0) 84 if (key[0] != 0)
@@ -81,32 +93,41 @@ static int dtt200u_frontend_attach(struct dvb_usb_device *d)
81} 93}
82 94
83static struct dvb_usb_properties dtt200u_properties; 95static struct dvb_usb_properties dtt200u_properties;
96static struct dvb_usb_properties wt220u_properties;
84 97
85static int dtt200u_usb_probe(struct usb_interface *intf, 98static int dtt200u_usb_probe(struct usb_interface *intf,
86 const struct usb_device_id *id) 99 const struct usb_device_id *id)
87{ 100{
88 return dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE); 101 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE) == 0 ||
102 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE) == 0)
103 return 0;
104
105 return -ENODEV;
89} 106}
90 107
91static struct usb_device_id dtt200u_usb_table [] = { 108static struct usb_device_id dtt200u_usb_table [] = {
92 { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_DTT200U_COLD) }, 109// { USB_DEVICE(0x04b4,0x8613) },
93 { USB_DEVICE(USB_VID_AVERMEDIA_UNK, USB_PID_DTT200U_WARM) }, 110 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_COLD) },
111 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_WARM) },
112 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_COLD) },
113 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) },
94 { 0 }, 114 { 0 },
95}; 115};
96MODULE_DEVICE_TABLE(usb, dtt200u_usb_table); 116MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
97 117
98static struct dvb_usb_properties dtt200u_properties = { 118static struct dvb_usb_properties dtt200u_properties = {
99 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING, 119 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
100 .pid_filter_count = 255, /* It is a guess, but there are at least 10 */ 120 .pid_filter_count = 15,
101 121
102 .usb_ctrl = CYPRESS_FX2, 122 .usb_ctrl = CYPRESS_FX2,
103 .firmware = "dvb-usb-dtt200u-01.fw", 123 .firmware = "dvb-usb-dtt200u-01.fw",
104 124
125 .power_ctrl = dtt200u_power_ctrl,
105 .streaming_ctrl = dtt200u_streaming_ctrl, 126 .streaming_ctrl = dtt200u_streaming_ctrl,
106 .pid_filter = dtt200u_pid_filter, 127 .pid_filter = dtt200u_pid_filter,
107 .frontend_attach = dtt200u_frontend_attach, 128 .frontend_attach = dtt200u_frontend_attach,
108 129
109 .rc_interval = 200, 130 .rc_interval = 300,
110 .rc_key_map = dtt200u_rc_keys, 131 .rc_key_map = dtt200u_rc_keys,
111 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys), 132 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
112 .rc_query = dtt200u_rc_query, 133 .rc_query = dtt200u_rc_query,
@@ -127,18 +148,59 @@ static struct dvb_usb_properties dtt200u_properties = {
127 148
128 .num_device_descs = 1, 149 .num_device_descs = 1,
129 .devices = { 150 .devices = {
130 { .name = "Yakumo/Hama/Typhoon DVB-T USB2.0)", 151 { .name = "WideView/Yuan/Yakumo/Hama/Typhoon DVB-T USB2.0 (WT-200U)",
131 .cold_ids = { &dtt200u_usb_table[0], &dtt200u_usb_table[2] }, 152 .cold_ids = { &dtt200u_usb_table[0], NULL },
132 .warm_ids = { &dtt200u_usb_table[1], NULL }, 153 .warm_ids = { &dtt200u_usb_table[1], NULL },
133 }, 154 },
134 { 0 }, 155 { 0 },
135 } 156 }
136}; 157};
137 158
159static struct dvb_usb_properties wt220u_properties = {
160 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
161 .pid_filter_count = 15,
162
163 .usb_ctrl = CYPRESS_FX2,
164 .firmware = "dvb-usb-wt220u-01.fw",
165
166 .power_ctrl = dtt200u_power_ctrl,
167 .streaming_ctrl = dtt200u_streaming_ctrl,
168 .pid_filter = dtt200u_pid_filter,
169 .frontend_attach = dtt200u_frontend_attach,
170
171 .rc_interval = 300,
172 .rc_key_map = dtt200u_rc_keys,
173 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
174 .rc_query = dtt200u_rc_query,
175
176 .generic_bulk_ctrl_endpoint = 0x01,
177
178 /* parameter for the MPEG2-data transfer */
179 .urb = {
180 .type = DVB_USB_BULK,
181 .count = 7,
182 .endpoint = 0x02,
183 .u = {
184 .bulk = {
185 .buffersize = 4096,
186 }
187 }
188 },
189
190 .num_device_descs = 1,
191 .devices = {
192 { .name = "WideView WT-220U PenType Receiver (and clones)",
193 .cold_ids = { &dtt200u_usb_table[2], NULL },
194 .warm_ids = { &dtt200u_usb_table[3], NULL },
195 },
196 { 0 },
197 }
198};
199
138/* usb specific object needed to register this driver with the usb subsystem */ 200/* usb specific object needed to register this driver with the usb subsystem */
139static struct usb_driver dtt200u_usb_driver = { 201static struct usb_driver dtt200u_usb_driver = {
140 .owner = THIS_MODULE, 202 .owner = THIS_MODULE,
141 .name = "Yakumo/Hama/Typhoon DVB-T USB2.0", 203 .name = "dvb_usb_dtt200u",
142 .probe = dtt200u_usb_probe, 204 .probe = dtt200u_usb_probe,
143 .disconnect = dvb_usb_device_exit, 205 .disconnect = dvb_usb_device_exit,
144 .id_table = dtt200u_usb_table, 206 .id_table = dtt200u_usb_table,
@@ -166,6 +228,6 @@ module_init(dtt200u_usb_module_init);
166module_exit(dtt200u_usb_module_exit); 228module_exit(dtt200u_usb_module_exit);
167 229
168MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 230MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
169MODULE_DESCRIPTION("Driver for the Yakumo/Hama/Typhoon DVB-T USB2.0 device"); 231MODULE_DESCRIPTION("Driver for the WideView/Yakumo/Hama/Typhoon DVB-T USB2.0 devices");
170MODULE_VERSION("1.0"); 232MODULE_VERSION("1.0");
171MODULE_LICENSE("GPL"); 233MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.h b/drivers/media/dvb/dvb-usb/dtt200u.h
index ed4142071518..6f1f3042e21a 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.h
+++ b/drivers/media/dvb/dvb-usb/dtt200u.h
@@ -1,5 +1,5 @@
1/* Common header file of Linux driver for the Yakumo/Hama/Typhoon DVB-T 1/* Common header file of Linux driver for the WideView/ Yakumo/ Hama/
2 * USB2.0 receiver. 2 * Typhoon/ Yuan DVB-T USB2.0 receiver.
3 * 3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) 4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 * 5 *
@@ -22,44 +22,34 @@ extern int dvb_usb_dtt200u_debug;
22/* guessed protocol description (reverse engineered): 22/* guessed protocol description (reverse engineered):
23 * read 23 * read
24 * 00 - USB type 0x02 for usb2.0, 0x01 for usb1.1 24 * 00 - USB type 0x02 for usb2.0, 0x01 for usb1.1
25 * 81 - <TS_LOCK> <current frequency divided by 250000>
26 * 82 - crash - do not touch
27 * 83 - crash - do not touch
28 * 84 - remote control
29 * 85 - crash - do not touch (OK, stop testing here)
30 * 88 - locking 2 bytes (0x80 0x40 == no signal, 0x89 0x20 == nice signal) 25 * 88 - locking 2 bytes (0x80 0x40 == no signal, 0x89 0x20 == nice signal)
31 * 89 - noise-to-signal
32 * 8a - unkown 1 byte - signal_strength
33 * 8c - ber ???
34 * 8d - ber
35 * 8e - unc
36 */ 26 */
37 27
38#define GET_SPEED 0x00 28#define GET_SPEED 0x00
39#define GET_TUNE_STAT 0x81 29#define GET_TUNE_STATUS 0x81
40#define GET_RC_KEY 0x84 30#define GET_RC_CODE 0x84
41#define GET_STATUS 0x88 31#define GET_CONFIGURATION 0x88
42#define GET_SNR 0x89 32#define GET_AGC 0x89
43#define GET_SIG_STRENGTH 0x8a 33#define GET_SNR 0x8a
44#define GET_UNK 0x8c 34#define GET_VIT_ERR_CNT 0x8c
45#define GET_BER 0x8d 35#define GET_RS_ERR_CNT 0x8d
46#define GET_UNC 0x8e 36#define GET_RS_UNCOR_BLK_CNT 0x8e
47 37
48/* write 38/* write
49 * 01 - reset the demod 39 * 01 - init
50 * 02 - frequency (divided by 250000) 40 * 02 - frequency (divided by 250000)
51 * 03 - bandwidth 41 * 03 - bandwidth
52 * 04 - pid table (index pid(7:0) pid(12:8)) 42 * 04 - pid table (index pid(7:0) pid(12:8))
53 * 05 - reset the pid table 43 * 05 - reset the pid table
54 * 08 - demod transfer enabled or not (FX2 transfer is enabled by default) 44 * 08 - transfer switch
55 */ 45 */
56 46
57#define RESET_DEMOD 0x01 47#define SET_INIT 0x01
58#define SET_FREQUENCY 0x02 48#define SET_RF_FREQ 0x02
59#define SET_BANDWIDTH 0x03 49#define SET_BANDWIDTH 0x03
60#define SET_PID_FILTER 0x04 50#define SET_PID_FILTER 0x04
61#define RESET_PID_FILTER 0x05 51#define RESET_PID_FILTER 0x05
62#define SET_TS_CTRL 0x08 52#define SET_STREAMING 0x08
63 53
64extern struct dvb_frontend * dtt200u_fe_attach(struct dvb_usb_device *d); 54extern struct dvb_frontend * dtt200u_fe_attach(struct dvb_usb_device *d);
65 55
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-common.h b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
index 67e0d73fbceb..7300489d3e24 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-common.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
@@ -12,14 +12,16 @@
12#include "dvb-usb.h" 12#include "dvb-usb.h"
13 13
14extern int dvb_usb_debug; 14extern int dvb_usb_debug;
15extern int dvb_usb_disable_rc_polling;
15 16
16#define deb_info(args...) dprintk(dvb_usb_debug,0x01,args) 17#define deb_info(args...) dprintk(dvb_usb_debug,0x01,args)
17#define deb_xfer(args...) dprintk(dvb_usb_debug,0x02,args) 18#define deb_xfer(args...) dprintk(dvb_usb_debug,0x02,args)
18#define deb_pll(args...) dprintk(dvb_usb_debug,0x04,args) 19#define deb_pll(args...) dprintk(dvb_usb_debug,0x04,args)
19#define deb_ts(args...) dprintk(dvb_usb_debug,0x08,args) 20#define deb_ts(args...) dprintk(dvb_usb_debug,0x08,args)
20#define deb_err(args...) dprintk(dvb_usb_debug,0x10,args) 21#define deb_err(args...) dprintk(dvb_usb_debug,0x10,args)
21#define deb_rc(args...) dprintk(dvb_usb_debug,0x20,args) 22#define deb_rc(args...) dprintk(dvb_usb_debug,0x20,args)
22#define deb_fw(args...) dprintk(dvb_usb_debug,0x40,args) 23#define deb_fw(args...) dprintk(dvb_usb_debug,0x40,args)
24#define deb_mem(args...) dprintk(dvb_usb_debug,0x80,args)
23 25
24/* commonly used methods */ 26/* commonly used methods */
25extern int usb_cypress_load_firmware(struct usb_device *, const char *, int); 27extern int usb_cypress_load_firmware(struct usb_device *, const char *, int);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index bdd72f779707..3491ff40885c 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -175,7 +175,7 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
175int dvb_usb_fe_init(struct dvb_usb_device* d) 175int dvb_usb_fe_init(struct dvb_usb_device* d)
176{ 176{
177 if (d->props.frontend_attach == NULL) { 177 if (d->props.frontend_attach == NULL) {
178 err("strange '%s' don't want to attach a frontend.",d->desc->name); 178 err("strange '%s' doesn't want to attach a frontend.",d->desc->name);
179 return 0; 179 return 0;
180 } 180 }
181 181
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index bcb34191868b..794d513a8480 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -12,7 +12,7 @@
12/* Vendor IDs */ 12/* Vendor IDs */
13#define USB_VID_ADSTECH 0x06e1 13#define USB_VID_ADSTECH 0x06e1
14#define USB_VID_ANCHOR 0x0547 14#define USB_VID_ANCHOR 0x0547
15#define USB_VID_AVERMEDIA_UNK 0x14aa 15#define USB_VID_WIDEVIEW 0x14aa
16#define USB_VID_AVERMEDIA 0x07ca 16#define USB_VID_AVERMEDIA 0x07ca
17#define USB_VID_COMPRO 0x185b 17#define USB_VID_COMPRO 0x185b
18#define USB_VID_COMPRO_UNK 0x145f 18#define USB_VID_COMPRO_UNK 0x145f
@@ -24,6 +24,8 @@
24#define USB_VID_HANFTEK 0x15f4 24#define USB_VID_HANFTEK 0x15f4
25#define USB_VID_HAUPPAUGE 0x2040 25#define USB_VID_HAUPPAUGE 0x2040
26#define USB_VID_HYPER_PALTEK 0x1025 26#define USB_VID_HYPER_PALTEK 0x1025
27#define USB_VID_KYE 0x0458
28#define USB_VID_MEDION 0x1660
27#define USB_VID_VISIONPLUS 0x13d3 29#define USB_VID_VISIONPLUS 0x13d3
28#define USB_VID_TWINHAN 0x1822 30#define USB_VID_TWINHAN 0x1822
29#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 31#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
@@ -70,6 +72,8 @@
70#define USB_PID_HANFTEK_UMT_010_WARM 0x0015 72#define USB_PID_HANFTEK_UMT_010_WARM 0x0015
71#define USB_PID_DTT200U_COLD 0x0201 73#define USB_PID_DTT200U_COLD 0x0201
72#define USB_PID_DTT200U_WARM 0x0301 74#define USB_PID_DTT200U_WARM 0x0301
75#define USB_PID_WT220U_COLD 0x0222
76#define USB_PID_WT220U_WARM 0x0221
73#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300 77#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300
74#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301 78#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301
75#define USB_PID_NEBULA_DIGITV 0x0201 79#define USB_PID_NEBULA_DIGITV 0x0201
@@ -78,6 +82,8 @@
78#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820 82#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820
79#define USB_PID_DVICO_BLUEBIRD_LGZ201_1 0xdb01 83#define USB_PID_DVICO_BLUEBIRD_LGZ201_1 0xdb01
80#define USB_PID_DVICO_BLUEBIRD_TH7579_2 0xdb11 84#define USB_PID_DVICO_BLUEBIRD_TH7579_2 0xdb11
81 85#define USB_PID_MEDION_MD95700 0x0932
86#define USB_PID_KYE_DVB_T_COLD 0x701e
87#define USB_PID_KYE_DVB_T_WARM 0x701f
82 88
83#endif 89#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index 3aadec974cf1..65f0c095abc9 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -18,6 +18,10 @@ int dvb_usb_debug;
18module_param_named(debug,dvb_usb_debug, int, 0644); 18module_param_named(debug,dvb_usb_debug, int, 0644);
19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." DVB_USB_DEBUG_STATUS); 19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." DVB_USB_DEBUG_STATUS);
20 20
21int dvb_usb_disable_rc_polling;
22module_param_named(disable_rc_polling, dvb_usb_disable_rc_polling, int, 0644);
23MODULE_PARM_DESC(disable_rc_polling, "disable remote control polling (default: 0).");
24
21/* general initialization functions */ 25/* general initialization functions */
22int dvb_usb_exit(struct dvb_usb_device *d) 26int dvb_usb_exit(struct dvb_usb_device *d)
23{ 27{
@@ -47,17 +51,17 @@ static int dvb_usb_init(struct dvb_usb_device *d)
47 51
48/* speed - when running at FULL speed we need a HW PID filter */ 52/* speed - when running at FULL speed we need a HW PID filter */
49 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) { 53 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) {
50 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a HW PID filter)"); 54 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
51 return -ENODEV; 55 return -ENODEV;
52 } 56 }
53 57
54 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) || 58 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) ||
55 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) { 59 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) {
56 info("will use the device's hw PID filter."); 60 info("will use the device's hardware PID filter (table count: %d).",d->props.pid_filter_count);
57 d->pid_filtering = 1; 61 d->pid_filtering = 1;
58 d->max_feed_count = d->props.pid_filter_count; 62 d->max_feed_count = d->props.pid_filter_count;
59 } else { 63 } else {
60 info("will pass the complete MPEG2 transport stream to the demuxer."); 64 info("will pass the complete MPEG2 transport stream to the software demuxer.");
61 d->pid_filtering = 0; 65 d->pid_filtering = 0;
62 d->max_feed_count = 255; 66 d->max_feed_count = 255;
63 } 67 }
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 9f1e23f82bae..fc7800f1743e 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -21,6 +21,10 @@ static void dvb_usb_read_remote_control(void *data)
21 /* TODO: need a lock here. We can simply skip checking for the remote control 21 /* TODO: need a lock here. We can simply skip checking for the remote control
22 if we're busy. */ 22 if we're busy. */
23 23
24 /* when the parameter has been set to 1 via sysfs while the driver was running */
25 if (dvb_usb_disable_rc_polling)
26 return;
27
24 if (d->props.rc_query(d,&event,&state)) { 28 if (d->props.rc_query(d,&event,&state)) {
25 err("error while querying for an remote control event."); 29 err("error while querying for an remote control event.");
26 goto schedule; 30 goto schedule;
@@ -35,7 +39,7 @@ static void dvb_usb_read_remote_control(void *data)
35 d->last_event = event; 39 d->last_event = event;
36 case REMOTE_KEY_REPEAT: 40 case REMOTE_KEY_REPEAT:
37 deb_rc("key repeated\n"); 41 deb_rc("key repeated\n");
38 input_event(&d->rc_input_dev, EV_KEY, event, 1); 42 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 1);
39 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0); 43 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0);
40 input_sync(&d->rc_input_dev); 44 input_sync(&d->rc_input_dev);
41 break; 45 break;
@@ -85,7 +89,9 @@ schedule:
85int dvb_usb_remote_init(struct dvb_usb_device *d) 89int dvb_usb_remote_init(struct dvb_usb_device *d)
86{ 90{
87 int i; 91 int i;
88 if (d->props.rc_key_map == NULL) 92 if (d->props.rc_key_map == NULL ||
93 d->props.rc_query == NULL ||
94 dvb_usb_disable_rc_polling)
89 return 0; 95 return 0;
90 96
91 /* Initialise the remote-control structures.*/ 97 /* Initialise the remote-control structures.*/
@@ -154,12 +160,12 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
154 break; 160 break;
155 } 161 }
156 /* See if we can match the raw key code. */ 162 /* See if we can match the raw key code. */
157 for (i = 0; i < sizeof(keymap)/sizeof(struct dvb_usb_rc_key); i++) 163 for (i = 0; i < d->props.rc_key_map_size; i++)
158 if (keymap[i].custom == keybuf[1] && 164 if (keymap[i].custom == keybuf[1] &&
159 keymap[i].data == keybuf[3]) { 165 keymap[i].data == keybuf[3]) {
160 *event = keymap[i].event; 166 *event = keymap[i].event;
161 *state = REMOTE_KEY_PRESSED; 167 *state = REMOTE_KEY_PRESSED;
162 break; 168 return 0;
163 } 169 }
164 deb_err("key mapping failed - no appropriate key found in keymapping\n"); 170 deb_err("key mapping failed - no appropriate key found in keymapping\n");
165 break; 171 break;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
index 83d476fb410a..f5799a4c228e 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
@@ -24,11 +24,12 @@ int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
24 if ((ret = down_interruptible(&d->usb_sem))) 24 if ((ret = down_interruptible(&d->usb_sem)))
25 return ret; 25 return ret;
26 26
27 deb_xfer(">>> ");
27 debug_dump(wbuf,wlen,deb_xfer); 28 debug_dump(wbuf,wlen,deb_xfer);
28 29
29 ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev, 30 ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev,
30 d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen, 31 d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen,
31 2*HZ); 32 2000);
32 33
33 if (ret) 34 if (ret)
34 err("bulk message failed: %d (%d/%d)",ret,wlen,actlen); 35 err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
@@ -42,12 +43,14 @@ int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
42 43
43 ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev, 44 ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev,
44 d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen, 45 d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen,
45 2*HZ); 46 2000);
46 47
47 if (ret) 48 if (ret)
48 err("recv bulk message failed: %d",ret); 49 err("recv bulk message failed: %d",ret);
49 else 50 else {
51 deb_xfer("<<< ");
50 debug_dump(rbuf,actlen,deb_xfer); 52 debug_dump(rbuf,actlen,deb_xfer);
53 }
51 } 54 }
52 55
53 up(&d->usb_sem); 56 up(&d->usb_sem);
@@ -61,12 +64,19 @@ int dvb_usb_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
61} 64}
62EXPORT_SYMBOL(dvb_usb_generic_write); 65EXPORT_SYMBOL(dvb_usb_generic_write);
63 66
64static void dvb_usb_bulk_urb_complete(struct urb *urb, struct pt_regs *ptregs) 67
68/* URB stuff for streaming */
69static void dvb_usb_urb_complete(struct urb *urb, struct pt_regs *ptregs)
65{ 70{
66 struct dvb_usb_device *d = urb->context; 71 struct dvb_usb_device *d = urb->context;
72 int ptype = usb_pipetype(urb->pipe);
73 int i;
74 u8 *b;
67 75
68 deb_ts("bulk urb completed. feedcount: %d, status: %d, length: %d\n",d->feedcount,urb->status, 76 deb_ts("'%s' urb completed. feedcount: %d, status: %d, length: %d/%d, pack_num: %d, errors: %d\n",
69 urb->actual_length); 77 ptype == PIPE_ISOCHRONOUS ? "isoc" : "bulk", d->feedcount,
78 urb->status,urb->actual_length,urb->transfer_buffer_length,
79 urb->number_of_packets,urb->error_count);
70 80
71 switch (urb->status) { 81 switch (urb->status) {
72 case 0: /* success */ 82 case 0: /* success */
@@ -81,11 +91,33 @@ static void dvb_usb_bulk_urb_complete(struct urb *urb, struct pt_regs *ptregs)
81 break; 91 break;
82 } 92 }
83 93
84 if (d->feedcount > 0 && urb->actual_length > 0) { 94 if (d->feedcount > 0) {
85 if (d->state & DVB_USB_STATE_DVB) 95 if (d->state & DVB_USB_STATE_DVB) {
86 dvb_dmx_swfilter(&d->demux, (u8*) urb->transfer_buffer,urb->actual_length); 96 switch (ptype) {
87 } else 97 case PIPE_ISOCHRONOUS:
88 deb_ts("URB dropped because of feedcount.\n"); 98 b = (u8 *) urb->transfer_buffer;
99 for (i = 0; i < urb->number_of_packets; i++) {
100 if (urb->iso_frame_desc[i].status != 0)
101 deb_ts("iso frame descriptor has an error: %d\n",urb->iso_frame_desc[i].status);
102 else if (urb->iso_frame_desc[i].actual_length > 0) {
103 dvb_dmx_swfilter(&d->demux,b + urb->iso_frame_desc[i].offset,
104 urb->iso_frame_desc[i].actual_length);
105 }
106 urb->iso_frame_desc[i].status = 0;
107 urb->iso_frame_desc[i].actual_length = 0;
108 }
109 debug_dump(b,20,deb_ts);
110 break;
111 case PIPE_BULK:
112 if (urb->actual_length > 0)
113 dvb_dmx_swfilter(&d->demux, (u8 *) urb->transfer_buffer,urb->actual_length);
114 break;
115 default:
116 err("unkown endpoint type in completition handler.");
117 return;
118 }
119 }
120 }
89 121
90 usb_submit_urb(urb,GFP_ATOMIC); 122 usb_submit_urb(urb,GFP_ATOMIC);
91} 123}
@@ -94,7 +126,7 @@ int dvb_usb_urb_kill(struct dvb_usb_device *d)
94{ 126{
95 int i; 127 int i;
96 for (i = 0; i < d->urbs_submitted; i++) { 128 for (i = 0; i < d->urbs_submitted; i++) {
97 deb_info("killing URB no. %d.\n",i); 129 deb_ts("killing URB no. %d.\n",i);
98 130
99 /* stop the URB */ 131 /* stop the URB */
100 usb_kill_urb(d->urb_list[i]); 132 usb_kill_urb(d->urb_list[i]);
@@ -107,9 +139,9 @@ int dvb_usb_urb_submit(struct dvb_usb_device *d)
107{ 139{
108 int i,ret; 140 int i,ret;
109 for (i = 0; i < d->urbs_initialized; i++) { 141 for (i = 0; i < d->urbs_initialized; i++) {
110 deb_info("submitting URB no. %d\n",i); 142 deb_ts("submitting URB no. %d\n",i);
111 if ((ret = usb_submit_urb(d->urb_list[i],GFP_ATOMIC))) { 143 if ((ret = usb_submit_urb(d->urb_list[i],GFP_ATOMIC))) {
112 err("could not submit URB no. %d - get them all back\n",i); 144 err("could not submit URB no. %d - get them all back",i);
113 dvb_usb_urb_kill(d); 145 dvb_usb_urb_kill(d);
114 return ret; 146 return ret;
115 } 147 }
@@ -118,32 +150,78 @@ int dvb_usb_urb_submit(struct dvb_usb_device *d)
118 return 0; 150 return 0;
119} 151}
120 152
121static int dvb_usb_bulk_urb_init(struct dvb_usb_device *d) 153static int dvb_usb_free_stream_buffers(struct dvb_usb_device *d)
122{ 154{
123 int i,bufsize = d->props.urb.count * d->props.urb.u.bulk.buffersize; 155 if (d->state & DVB_USB_STATE_URB_BUF) {
156 while (d->buf_num) {
157 d->buf_num--;
158 deb_mem("freeing buffer %d\n",d->buf_num);
159 usb_buffer_free(d->udev, d->buf_size,
160 d->buf_list[d->buf_num], d->dma_addr[d->buf_num]);
161 }
162 kfree(d->buf_list);
163 kfree(d->dma_addr);
164 }
165
166 d->state &= ~DVB_USB_STATE_URB_BUF;
124 167
125 deb_info("allocate %d bytes as buffersize for all URBs\n",bufsize); 168 return 0;
126 /* allocate the actual buffer for the URBs */ 169}
127 if ((d->buffer = usb_buffer_alloc(d->udev, bufsize, SLAB_ATOMIC, &d->dma_handle)) == NULL) { 170
128 deb_info("not enough memory for urb-buffer allocation.\n"); 171static int dvb_usb_allocate_stream_buffers(struct dvb_usb_device *d, int num, unsigned long size)
172{
173 d->buf_num = 0;
174 d->buf_size = size;
175
176 deb_mem("all in all I will use %lu bytes for streaming\n",num*size);
177
178 if ((d->buf_list = kmalloc(num*sizeof(u8 *), GFP_ATOMIC)) == NULL)
179 return -ENOMEM;
180
181 if ((d->dma_addr = kmalloc(num*sizeof(dma_addr_t), GFP_ATOMIC)) == NULL) {
182 kfree(d->buf_list);
129 return -ENOMEM; 183 return -ENOMEM;
130 } 184 }
131 deb_info("allocation successful\n"); 185 memset(d->buf_list,0,num*sizeof(u8 *));
132 memset(d->buffer,0,bufsize); 186 memset(d->dma_addr,0,num*sizeof(dma_addr_t));
133 187
134 d->state |= DVB_USB_STATE_URB_BUF; 188 d->state |= DVB_USB_STATE_URB_BUF;
135 189
190 for (d->buf_num = 0; d->buf_num < num; d->buf_num++) {
191 deb_mem("allocating buffer %d\n",d->buf_num);
192 if (( d->buf_list[d->buf_num] =
193 usb_buffer_alloc(d->udev, size, SLAB_ATOMIC,
194 &d->dma_addr[d->buf_num]) ) == NULL) {
195 deb_mem("not enough memory for urb-buffer allocation.\n");
196 dvb_usb_free_stream_buffers(d);
197 return -ENOMEM;
198 }
199 deb_mem("buffer %d: %p (dma: %d)\n",d->buf_num,d->buf_list[d->buf_num],d->dma_addr[d->buf_num]);
200 memset(d->buf_list[d->buf_num],0,size);
201 }
202 deb_mem("allocation successful\n");
203
204 return 0;
205}
206
207static int dvb_usb_bulk_urb_init(struct dvb_usb_device *d)
208{
209 int i;
210
211 if ((i = dvb_usb_allocate_stream_buffers(d,d->props.urb.count,
212 d->props.urb.u.bulk.buffersize)) < 0)
213 return i;
214
136 /* allocate the URBs */ 215 /* allocate the URBs */
137 for (i = 0; i < d->props.urb.count; i++) { 216 for (i = 0; i < d->props.urb.count; i++) {
138 if (!(d->urb_list[i] = usb_alloc_urb(0,GFP_ATOMIC))) { 217 if ((d->urb_list[i] = usb_alloc_urb(0,GFP_ATOMIC)) == NULL)
139 return -ENOMEM; 218 return -ENOMEM;
140 }
141 219
142 usb_fill_bulk_urb( d->urb_list[i], d->udev, 220 usb_fill_bulk_urb( d->urb_list[i], d->udev,
143 usb_rcvbulkpipe(d->udev,d->props.urb.endpoint), 221 usb_rcvbulkpipe(d->udev,d->props.urb.endpoint),
144 &d->buffer[i*d->props.urb.u.bulk.buffersize], 222 d->buf_list[i],
145 d->props.urb.u.bulk.buffersize, 223 d->props.urb.u.bulk.buffersize,
146 dvb_usb_bulk_urb_complete, d); 224 dvb_usb_urb_complete, d);
147 225
148 d->urb_list[i]->transfer_flags = 0; 226 d->urb_list[i]->transfer_flags = 0;
149 d->urbs_initialized++; 227 d->urbs_initialized++;
@@ -151,6 +229,47 @@ static int dvb_usb_bulk_urb_init(struct dvb_usb_device *d)
151 return 0; 229 return 0;
152} 230}
153 231
232static int dvb_usb_isoc_urb_init(struct dvb_usb_device *d)
233{
234 int i,j;
235
236 if ((i = dvb_usb_allocate_stream_buffers(d,d->props.urb.count,
237 d->props.urb.u.isoc.framesize*d->props.urb.u.isoc.framesperurb)) < 0)
238 return i;
239
240 /* allocate the URBs */
241 for (i = 0; i < d->props.urb.count; i++) {
242 struct urb *urb;
243 int frame_offset = 0;
244 if ((d->urb_list[i] =
245 usb_alloc_urb(d->props.urb.u.isoc.framesperurb,GFP_ATOMIC)) == NULL)
246 return -ENOMEM;
247
248 urb = d->urb_list[i];
249
250 urb->dev = d->udev;
251 urb->context = d;
252 urb->complete = dvb_usb_urb_complete;
253 urb->pipe = usb_rcvisocpipe(d->udev,d->props.urb.endpoint);
254 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
255 urb->interval = d->props.urb.u.isoc.interval;
256 urb->number_of_packets = d->props.urb.u.isoc.framesperurb;
257 urb->transfer_buffer_length = d->buf_size;
258 urb->transfer_buffer = d->buf_list[i];
259 urb->transfer_dma = d->dma_addr[i];
260
261 for (j = 0; j < d->props.urb.u.isoc.framesperurb; j++) {
262 urb->iso_frame_desc[j].offset = frame_offset;
263 urb->iso_frame_desc[j].length = d->props.urb.u.isoc.framesize;
264 frame_offset += d->props.urb.u.isoc.framesize;
265 }
266
267 d->urbs_initialized++;
268 }
269 return 0;
270
271}
272
154int dvb_usb_urb_init(struct dvb_usb_device *d) 273int dvb_usb_urb_init(struct dvb_usb_device *d)
155{ 274{
156 /* 275 /*
@@ -174,8 +293,7 @@ int dvb_usb_urb_init(struct dvb_usb_device *d)
174 case DVB_USB_BULK: 293 case DVB_USB_BULK:
175 return dvb_usb_bulk_urb_init(d); 294 return dvb_usb_bulk_urb_init(d);
176 case DVB_USB_ISOC: 295 case DVB_USB_ISOC:
177 err("isochronous transfer not yet implemented in dvb-usb."); 296 return dvb_usb_isoc_urb_init(d);
178 return -EINVAL;
179 default: 297 default:
180 err("unkown URB-type for data transfer."); 298 err("unkown URB-type for data transfer.");
181 return -EINVAL; 299 return -EINVAL;
@@ -191,7 +309,7 @@ int dvb_usb_urb_exit(struct dvb_usb_device *d)
191 if (d->state & DVB_USB_STATE_URB_LIST) { 309 if (d->state & DVB_USB_STATE_URB_LIST) {
192 for (i = 0; i < d->urbs_initialized; i++) { 310 for (i = 0; i < d->urbs_initialized; i++) {
193 if (d->urb_list[i] != NULL) { 311 if (d->urb_list[i] != NULL) {
194 deb_info("freeing URB no. %d.\n",i); 312 deb_mem("freeing URB no. %d.\n",i);
195 /* free the URBs */ 313 /* free the URBs */
196 usb_free_urb(d->urb_list[i]); 314 usb_free_urb(d->urb_list[i]);
197 } 315 }
@@ -202,10 +320,6 @@ int dvb_usb_urb_exit(struct dvb_usb_device *d)
202 d->state &= ~DVB_USB_STATE_URB_LIST; 320 d->state &= ~DVB_USB_STATE_URB_LIST;
203 } 321 }
204 322
205 if (d->state & DVB_USB_STATE_URB_BUF) 323 dvb_usb_free_stream_buffers(d);
206 usb_buffer_free(d->udev, d->props.urb.u.bulk.buffersize * d->props.urb.count,
207 d->buffer, d->dma_handle);
208
209 d->state &= ~DVB_USB_STATE_URB_BUF;
210 return 0; 324 return 0;
211} 325}
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index abcee1943f64..a80567caf508 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -189,12 +189,13 @@ struct dvb_usb_properties {
189 struct { 189 struct {
190 int framesperurb; 190 int framesperurb;
191 int framesize; 191 int framesize;
192 int interval;
192 } isoc; 193 } isoc;
193 } u; 194 } u;
194 } urb; 195 } urb;
195 196
196 int num_device_descs; 197 int num_device_descs;
197 struct dvb_usb_device_description devices[8]; 198 struct dvb_usb_device_description devices[9];
198}; 199};
199 200
200 201
@@ -207,19 +208,28 @@ struct dvb_usb_properties {
207 * @udev: pointer to the device's struct usb_device. 208 * @udev: pointer to the device's struct usb_device.
208 * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS- 209 * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS-
209 * streaming. 210 * streaming.
210 * @buffer: buffer used to streaming. 211 *
211 * @dma_handle: dma_addr_t for buffer. 212 * @buf_num: number of buffer allocated.
213 * @buf_size: size of each buffer in buf_list.
214 * @buf_list: array containing all allocate buffers for streaming.
215 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
216 *
212 * @urbs_initialized: number of URBs initialized. 217 * @urbs_initialized: number of URBs initialized.
213 * @urbs_submitted: number of URBs submitted. 218 * @urbs_submitted: number of URBs submitted.
219 *
214 * @feedcount: number of reqested feeds (used for streaming-activation) 220 * @feedcount: number of reqested feeds (used for streaming-activation)
215 * @pid_filtering: is hardware pid_filtering used or not. 221 * @pid_filtering: is hardware pid_filtering used or not.
222 *
216 * @usb_sem: semaphore of USB control messages (reading needs two messages) 223 * @usb_sem: semaphore of USB control messages (reading needs two messages)
217 * @i2c_sem: semaphore for i2c-transfers 224 * @i2c_sem: semaphore for i2c-transfers
225 *
218 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB 226 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
219 * @pll_addr: I2C address of the tuner for programming 227 * @pll_addr: I2C address of the tuner for programming
220 * @pll_init: array containing the initialization buffer 228 * @pll_init: array containing the initialization buffer
221 * @pll_desc: pointer to the appropriate struct dvb_pll_desc 229 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
222 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod 230 *
231 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
232 *
223 * @dvb_adap: device's dvb_adapter. 233 * @dvb_adap: device's dvb_adapter.
224 * @dmxdev: device's dmxdev. 234 * @dmxdev: device's dmxdev.
225 * @demux: device's software demuxer. 235 * @demux: device's software demuxer.
@@ -253,8 +263,12 @@ struct dvb_usb_device {
253 /* usb */ 263 /* usb */
254 struct usb_device *udev; 264 struct usb_device *udev;
255 struct urb **urb_list; 265 struct urb **urb_list;
256 u8 *buffer; 266
257 dma_addr_t dma_handle; 267 int buf_num;
268 unsigned long buf_size;
269 u8 **buf_list;
270 dma_addr_t *dma_addr;
271
258 int urbs_initialized; 272 int urbs_initialized;
259 int urbs_submitted; 273 int urbs_submitted;
260 274
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index 9d83781aef95..258a92bfbcc7 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -203,7 +203,7 @@ static struct dvb_usb_properties nova_t_properties = {
203 203
204static struct usb_driver nova_t_driver = { 204static struct usb_driver nova_t_driver = {
205 .owner = THIS_MODULE, 205 .owner = THIS_MODULE,
206 .name = "Hauppauge WinTV-NOVA-T usb2", 206 .name = "dvb_usb_nova_t_usb2",
207 .probe = nova_t_probe, 207 .probe = nova_t_probe,
208 .disconnect = dvb_usb_device_exit, 208 .disconnect = dvb_usb_device_exit,
209 .id_table = nova_t_table, 209 .id_table = nova_t_table,
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
index aa560422ce7c..2112ac3cf5e2 100644
--- a/drivers/media/dvb/dvb-usb/umt-010.c
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -129,7 +129,7 @@ static struct dvb_usb_properties umt_properties = {
129 129
130static struct usb_driver umt_driver = { 130static struct usb_driver umt_driver = {
131 .owner = THIS_MODULE, 131 .owner = THIS_MODULE,
132 .name = "HanfTek UMT-010 USB2.0 DVB-T devices", 132 .name = "dvb_usb_umt_010",
133 .probe = umt_probe, 133 .probe = umt_probe,
134 .disconnect = dvb_usb_device_exit, 134 .disconnect = dvb_usb_device_exit,
135 .id_table = umt_table, 135 .id_table = umt_table,
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 02ecc9a8e3b6..9ac95f54f9fc 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -44,7 +44,7 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
44 if (usb_control_msg(d->udev, 44 if (usb_control_msg(d->udev,
45 usb_sndctrlpipe(d->udev,0), 45 usb_sndctrlpipe(d->udev,0),
46 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, 46 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
47 outbuf, 20, 2*HZ) != 20) { 47 outbuf, 20, 2000) != 20) {
48 err("USB control message 'out' went wrong."); 48 err("USB control message 'out' went wrong.");
49 ret = -EIO; 49 ret = -EIO;
50 goto unlock; 50 goto unlock;
@@ -55,7 +55,7 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
55 if (usb_control_msg(d->udev, 55 if (usb_control_msg(d->udev,
56 usb_rcvctrlpipe(d->udev,0), 56 usb_rcvctrlpipe(d->udev,0),
57 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 57 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
58 inbuf, 12, 2*HZ) != 12) { 58 inbuf, 12, 2000) != 12) {
59 err("USB control message 'in' went wrong."); 59 err("USB control message 'in' went wrong.");
60 ret = -EIO; 60 ret = -EIO;
61 goto unlock; 61 goto unlock;
@@ -94,16 +94,41 @@ static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
94/* The keymapping struct. Somehow this should be loaded to the driver, but 94/* The keymapping struct. Somehow this should be loaded to the driver, but
95 * currently it is hardcoded. */ 95 * currently it is hardcoded. */
96static struct dvb_usb_rc_key vp7045_rc_keys[] = { 96static struct dvb_usb_rc_key vp7045_rc_keys[] = {
97 /* insert the keys like this. to make the raw keys visible, enable 97 { 0x00, 0x16, KEY_POWER },
98 * debug=0x04 when loading dvb-usb-vp7045. */ 98 { 0x00, 0x10, KEY_MUTE },
99 99 { 0x00, 0x03, KEY_1 },
100 /* these keys are probably wrong. I don't have a working IR-receiver on my 100 { 0x00, 0x01, KEY_2 },
101 * vp7045, so I can't test it. Patches are welcome. */ 101 { 0x00, 0x06, KEY_3 },
102 { 0x00, 0x01, KEY_1 }, 102 { 0x00, 0x09, KEY_4 },
103 { 0x00, 0x02, KEY_2 }, 103 { 0x00, 0x1d, KEY_5 },
104 { 0x00, 0x1f, KEY_6 },
105 { 0x00, 0x0d, KEY_7 },
106 { 0x00, 0x19, KEY_8 },
107 { 0x00, 0x1b, KEY_9 },
108 { 0x00, 0x15, KEY_0 },
109 { 0x00, 0x05, KEY_CHANNELUP },
110 { 0x00, 0x02, KEY_CHANNELDOWN },
111 { 0x00, 0x1e, KEY_VOLUMEUP },
112 { 0x00, 0x0a, KEY_VOLUMEDOWN },
113 { 0x00, 0x11, KEY_RECORD },
114 { 0x00, 0x17, KEY_FAVORITES }, /* Heart symbol - Channel list. */
115 { 0x00, 0x14, KEY_PLAY },
116 { 0x00, 0x1a, KEY_STOP },
117 { 0x00, 0x40, KEY_REWIND },
118 { 0x00, 0x12, KEY_FASTFORWARD },
119 { 0x00, 0x0e, KEY_PREVIOUS }, /* Recall - Previous channel. */
120 { 0x00, 0x4c, KEY_PAUSE },
121 { 0x00, 0x4d, KEY_SCREEN }, /* Full screen mode. */
122 { 0x00, 0x54, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
123 { 0x00, 0x0c, KEY_CANCEL }, /* Cancel */
124 { 0x00, 0x1c, KEY_EPG }, /* EPG */
125 { 0x00, 0x00, KEY_TAB }, /* Tab */
126 { 0x00, 0x48, KEY_INFO }, /* Preview */
127 { 0x00, 0x04, KEY_LIST }, /* RecordList */
128 { 0x00, 0x0f, KEY_TEXT } /* Teletext */
104}; 129};
105 130
106static int vp7045_rc_query(struct dvb_usb_device *d, u32 *key_buf, int *state) 131static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
107{ 132{
108 u8 key; 133 u8 key;
109 int i; 134 int i;
@@ -119,7 +144,7 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *key_buf, int *state)
119 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++) 144 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++)
120 if (vp7045_rc_keys[i].data == key) { 145 if (vp7045_rc_keys[i].data == key) {
121 *state = REMOTE_KEY_PRESSED; 146 *state = REMOTE_KEY_PRESSED;
122 *key_buf = vp7045_rc_keys[i].event; 147 *event = vp7045_rc_keys[i].event;
123 break; 148 break;
124 } 149 }
125 return 0; 150 return 0;
@@ -230,7 +255,7 @@ static struct dvb_usb_properties vp7045_properties = {
230/* usb specific object needed to register this driver with the usb subsystem */ 255/* usb specific object needed to register this driver with the usb subsystem */
231static struct usb_driver vp7045_usb_driver = { 256static struct usb_driver vp7045_usb_driver = {
232 .owner = THIS_MODULE, 257 .owner = THIS_MODULE,
233 .name = "dvb-usb-vp7045", 258 .name = "dvb_usb_vp7045",
234 .probe = vp7045_usb_probe, 259 .probe = vp7045_usb_probe,
235 .disconnect = dvb_usb_device_exit, 260 .disconnect = dvb_usb_device_exit,
236 .id_table = vp7045_usb_table, 261 .id_table = vp7045_usb_table,
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index b4fddf513ebe..d847c62bd837 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -40,6 +40,12 @@ config DVB_VES1X93
40 help 40 help
41 A DVB-S tuner module. Say Y when you want to support this frontend. 41 A DVB-S tuner module. Say Y when you want to support this frontend.
42 42
43config DVB_S5H1420
44 tristate "Samsung S5H1420 based"
45 depends on DVB_CORE
46 help
47 A DVB-S tuner module. Say Y when you want to support this frontend.
48
43comment "DVB-T (terrestrial) frontends" 49comment "DVB-T (terrestrial) frontends"
44 depends on DVB_CORE 50 depends on DVB_CORE
45 51
@@ -181,4 +187,11 @@ config DVB_BCM3510
181 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to 187 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
182 support this frontend. 188 support this frontend.
183 189
190config DVB_LGDT3302
191 tristate "LGDT3302 based (DViCO FusionHDTV3 Gold)"
192 depends on DVB_CORE
193 help
194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
195 to support this frontend.
196
184endmenu 197endmenu
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 91d6d3576d3d..de5e240cba7f 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -29,3 +29,5 @@ obj-$(CONFIG_DVB_NXT2002) += nxt2002.o
29obj-$(CONFIG_DVB_OR51211) += or51211.o 29obj-$(CONFIG_DVB_OR51211) += or51211.o
30obj-$(CONFIG_DVB_OR51132) += or51132.o 30obj-$(CONFIG_DVB_OR51132) += or51132.o
31obj-$(CONFIG_DVB_BCM3510) += bcm3510.o 31obj-$(CONFIG_DVB_BCM3510) += bcm3510.o
32obj-$(CONFIG_DVB_S5H1420) += s5h1420.o
33obj-$(CONFIG_DVB_LGDT3302) += lgdt3302.o
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index f4aa44136c7c..9f639297a9f2 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -76,7 +76,6 @@ static u8 init_tab [] = {
76 0x49, 0x56, 76 0x49, 0x56,
77 0x6b, 0x1e, 77 0x6b, 0x1e,
78 0xc8, 0x02, 78 0xc8, 0x02,
79 0xf8, 0x02,
80 0xf9, 0x00, 79 0xf9, 0x00,
81 0xfa, 0x00, 80 0xfa, 0x00,
82 0xfb, 0x00, 81 0xfb, 0x00,
@@ -203,7 +202,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
203 struct cx22702_state* state = fe->demodulator_priv; 202 struct cx22702_state* state = fe->demodulator_priv;
204 203
205 /* set PLL */ 204 /* set PLL */
206 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) &0xfe); 205 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) &0xfe);
207 if (state->config->pll_set) { 206 if (state->config->pll_set) {
208 state->config->pll_set(fe, p); 207 state->config->pll_set(fe, p);
209 } else if (state->config->pll_desc) { 208 } else if (state->config->pll_desc) {
@@ -217,7 +216,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
217 } else { 216 } else {
218 BUG(); 217 BUG();
219 } 218 }
220 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) | 1); 219 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) | 1);
221 220
222 /* set inversion */ 221 /* set inversion */
223 cx22702_set_inversion (state, p->inversion); 222 cx22702_set_inversion (state, p->inversion);
@@ -256,7 +255,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
256 cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B) & 0xfc ); 255 cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B) & 0xfc );
257 cx22702_writereg(state, 0x0C, (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40 ); 256 cx22702_writereg(state, 0x0C, (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40 );
258 cx22702_writereg(state, 0x00, 0x01); /* Begin aquisition */ 257 cx22702_writereg(state, 0x00, 0x01); /* Begin aquisition */
259 printk("%s: Autodetecting\n",__FUNCTION__); 258 dprintk("%s: Autodetecting\n",__FUNCTION__);
260 return 0; 259 return 0;
261 } 260 }
262 261
@@ -347,10 +346,11 @@ static int cx22702_init (struct dvb_frontend* fe)
347 for (i=0; i<sizeof(init_tab); i+=2) 346 for (i=0; i<sizeof(init_tab); i+=2)
348 cx22702_writereg (state, init_tab[i], init_tab[i+1]); 347 cx22702_writereg (state, init_tab[i], init_tab[i+1]);
349 348
349 cx22702_writereg (state, 0xf8, (state->config->output_mode << 1) & 0x02);
350 350
351 /* init PLL */ 351 /* init PLL */
352 if (state->config->pll_init) { 352 if (state->config->pll_init) {
353 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) &0xfe); 353 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) & 0xfe);
354 state->config->pll_init(fe); 354 state->config->pll_init(fe);
355 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) | 1); 355 cx22702_writereg (state, 0x0D, cx22702_readreg(state,0x0D) | 1);
356 } 356 }
@@ -440,8 +440,10 @@ static int cx22702_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
440 440
441 /* RS Uncorrectable Packet Count then reset */ 441 /* RS Uncorrectable Packet Count then reset */
442 _ucblocks = cx22702_readreg (state, 0xE3); 442 _ucblocks = cx22702_readreg (state, 0xE3);
443 if (state->prevUCBlocks < _ucblocks) *ucblocks = (_ucblocks - state->prevUCBlocks); 443 if (state->prevUCBlocks < _ucblocks)
444 else *ucblocks = state->prevUCBlocks - _ucblocks; 444 *ucblocks = (_ucblocks - state->prevUCBlocks);
445 else
446 *ucblocks = state->prevUCBlocks - _ucblocks;
445 state->prevUCBlocks = _ucblocks; 447 state->prevUCBlocks = _ucblocks;
446 448
447 return 0; 449 return 0;
@@ -457,6 +459,12 @@ static int cx22702_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
457 return cx22702_get_tps (state, &p->u.ofdm); 459 return cx22702_get_tps (state, &p->u.ofdm);
458} 460}
459 461
462static int cx22702_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
463{
464 tune->min_delay_ms = 1000;
465 return 0;
466}
467
460static void cx22702_release(struct dvb_frontend* fe) 468static void cx22702_release(struct dvb_frontend* fe)
461{ 469{
462 struct cx22702_state* state = fe->demodulator_priv; 470 struct cx22702_state* state = fe->demodulator_priv;
@@ -472,7 +480,8 @@ struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
472 480
473 /* allocate memory for the internal state */ 481 /* allocate memory for the internal state */
474 state = kmalloc(sizeof(struct cx22702_state), GFP_KERNEL); 482 state = kmalloc(sizeof(struct cx22702_state), GFP_KERNEL);
475 if (state == NULL) goto error; 483 if (state == NULL)
484 goto error;
476 485
477 /* setup the state */ 486 /* setup the state */
478 state->config = config; 487 state->config = config;
@@ -481,7 +490,8 @@ struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
481 state->prevUCBlocks = 0; 490 state->prevUCBlocks = 0;
482 491
483 /* check if the demod is there */ 492 /* check if the demod is there */
484 if (cx22702_readreg(state, 0x1f) != 0x3) goto error; 493 if (cx22702_readreg(state, 0x1f) != 0x3)
494 goto error;
485 495
486 /* create dvb_frontend */ 496 /* create dvb_frontend */
487 state->frontend.ops = &state->ops; 497 state->frontend.ops = &state->ops;
@@ -514,6 +524,7 @@ static struct dvb_frontend_ops cx22702_ops = {
514 524
515 .set_frontend = cx22702_set_tps, 525 .set_frontend = cx22702_set_tps,
516 .get_frontend = cx22702_get_frontend, 526 .get_frontend = cx22702_get_frontend,
527 .get_tune_settings = cx22702_get_tune_settings,
517 528
518 .read_status = cx22702_read_status, 529 .read_status = cx22702_read_status,
519 .read_ber = cx22702_read_ber, 530 .read_ber = cx22702_read_ber,
diff --git a/drivers/media/dvb/frontends/cx22702.h b/drivers/media/dvb/frontends/cx22702.h
index 559fdb906669..11f86806756e 100644
--- a/drivers/media/dvb/frontends/cx22702.h
+++ b/drivers/media/dvb/frontends/cx22702.h
@@ -35,6 +35,11 @@ struct cx22702_config
35 /* the demodulator's i2c address */ 35 /* the demodulator's i2c address */
36 u8 demod_address; 36 u8 demod_address;
37 37
38 /* serial/parallel output */
39#define CX22702_PARALLEL_OUTPUT 0
40#define CX22702_SERIAL_OUTPUT 1
41 u8 output_mode;
42
38 /* PLL maintenance */ 43 /* PLL maintenance */
39 u8 pll_address; 44 u8 pll_address;
40 struct dvb_pll_desc *pll_desc; 45 struct dvb_pll_desc *pll_desc;
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index f73b5f48e235..5afeaa9b43b4 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -55,7 +55,7 @@ struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
55}; 55};
56EXPORT_SYMBOL(dvb_pll_thomson_dtt7610); 56EXPORT_SYMBOL(dvb_pll_thomson_dtt7610);
57 57
58static void thomson_dtt759x_bw(u8 *buf, int bandwidth) 58static void thomson_dtt759x_bw(u8 *buf, u32 freq, int bandwidth)
59{ 59{
60 if (BANDWIDTH_7_MHZ == bandwidth) 60 if (BANDWIDTH_7_MHZ == bandwidth)
61 buf[3] |= 0x10; 61 buf[3] |= 0x10;
@@ -93,6 +93,32 @@ struct dvb_pll_desc dvb_pll_lg_z201 = {
93}; 93};
94EXPORT_SYMBOL(dvb_pll_lg_z201); 94EXPORT_SYMBOL(dvb_pll_lg_z201);
95 95
96struct dvb_pll_desc dvb_pll_microtune_4042 = {
97 .name = "Microtune 4042 FI5",
98 .min = 57000000,
99 .max = 858000000,
100 .count = 3,
101 .entries = {
102 { 162000000, 44000000, 62500, 0x8e, 0xa1 },
103 { 457000000, 44000000, 62500, 0x8e, 0x91 },
104 { 999999999, 44000000, 62500, 0x8e, 0x31 },
105 },
106};
107EXPORT_SYMBOL(dvb_pll_microtune_4042);
108
109struct dvb_pll_desc dvb_pll_thomson_dtt7611 = {
110 .name = "Thomson dtt7611",
111 .min = 44000000,
112 .max = 958000000,
113 .count = 3,
114 .entries = {
115 { 157250000, 44000000, 62500, 0x8e, 0x39 },
116 { 454000000, 44000000, 62500, 0x8e, 0x3a },
117 { 999999999, 44000000, 62500, 0x8e, 0x3c },
118 },
119};
120EXPORT_SYMBOL(dvb_pll_thomson_dtt7611);
121
96struct dvb_pll_desc dvb_pll_unknown_1 = { 122struct dvb_pll_desc dvb_pll_unknown_1 = {
97 .name = "unknown 1", /* used by dntv live dvb-t */ 123 .name = "unknown 1", /* used by dntv live dvb-t */
98 .min = 174000000, 124 .min = 174000000,
@@ -146,7 +172,7 @@ EXPORT_SYMBOL(dvb_pll_env57h1xd5);
146/* Philips TDA6650/TDA6651 172/* Philips TDA6650/TDA6651
147 * used in Panasonic ENV77H11D5 173 * used in Panasonic ENV77H11D5
148 */ 174 */
149static void tda665x_bw(u8 *buf, int bandwidth) 175static void tda665x_bw(u8 *buf, u32 freq, int bandwidth)
150{ 176{
151 if (bandwidth == BANDWIDTH_8_MHZ) 177 if (bandwidth == BANDWIDTH_8_MHZ)
152 buf[3] |= 0x08; 178 buf[3] |= 0x08;
@@ -178,7 +204,7 @@ EXPORT_SYMBOL(dvb_pll_tda665x);
178/* Infineon TUA6034 204/* Infineon TUA6034
179 * used in LG TDTP E102P 205 * used in LG TDTP E102P
180 */ 206 */
181static void tua6034_bw(u8 *buf, int bandwidth) 207static void tua6034_bw(u8 *buf, u32 freq, int bandwidth)
182{ 208{
183 if (BANDWIDTH_7_MHZ != bandwidth) 209 if (BANDWIDTH_7_MHZ != bandwidth)
184 buf[3] |= 0x08; 210 buf[3] |= 0x08;
@@ -198,6 +224,57 @@ struct dvb_pll_desc dvb_pll_tua6034 = {
198}; 224};
199EXPORT_SYMBOL(dvb_pll_tua6034); 225EXPORT_SYMBOL(dvb_pll_tua6034);
200 226
227/* Philips FMD1216ME
228 * used in Medion Hybrid PCMCIA card and USB Box
229 */
230static void fmd1216me_bw(u8 *buf, u32 freq, int bandwidth)
231{
232 if (bandwidth == BANDWIDTH_8_MHZ && freq >= 158870000)
233 buf[3] |= 0x08;
234}
235
236struct dvb_pll_desc dvb_pll_fmd1216me = {
237 .name = "Philips FMD1216ME",
238 .min = 50870000,
239 .max = 858000000,
240 .setbw = fmd1216me_bw,
241 .count = 7,
242 .entries = {
243 { 143870000, 36213333, 166667, 0xbc, 0x41 },
244 { 158870000, 36213333, 166667, 0xf4, 0x41 },
245 { 329870000, 36213333, 166667, 0xbc, 0x42 },
246 { 441870000, 36213333, 166667, 0xf4, 0x42 },
247 { 625870000, 36213333, 166667, 0xbc, 0x44 },
248 { 803870000, 36213333, 166667, 0xf4, 0x44 },
249 { 999999999, 36213333, 166667, 0xfc, 0x44 },
250 }
251};
252EXPORT_SYMBOL(dvb_pll_fmd1216me);
253
254/* ALPS TDED4
255 * used in Nebula-Cards and USB boxes
256 */
257static void tded4_bw(u8 *buf, u32 freq, int bandwidth)
258{
259 if (bandwidth == BANDWIDTH_8_MHZ)
260 buf[3] |= 0x04;
261}
262
263struct dvb_pll_desc dvb_pll_tded4 = {
264 .name = "ALPS TDED4",
265 .min = 47000000,
266 .max = 863000000,
267 .setbw = tded4_bw,
268 .count = 4,
269 .entries = {
270 { 153000000, 36166667, 166667, 0x85, 0x01 },
271 { 470000000, 36166667, 166667, 0x85, 0x02 },
272 { 823000000, 36166667, 166667, 0x85, 0x08 },
273 { 999999999, 36166667, 166667, 0x85, 0x88 },
274 }
275};
276EXPORT_SYMBOL(dvb_pll_tded4);
277
201/* ----------------------------------------------------------- */ 278/* ----------------------------------------------------------- */
202/* code */ 279/* code */
203 280
@@ -231,7 +308,7 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
231 buf[3] = desc->entries[i].cb2; 308 buf[3] = desc->entries[i].cb2;
232 309
233 if (desc->setbw) 310 if (desc->setbw)
234 desc->setbw(buf, bandwidth); 311 desc->setbw(buf, freq, bandwidth);
235 312
236 if (debug) 313 if (debug)
237 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", 314 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index b796778624b6..cb794759d89e 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -9,7 +9,7 @@ struct dvb_pll_desc {
9 char *name; 9 char *name;
10 u32 min; 10 u32 min;
11 u32 max; 11 u32 max;
12 void (*setbw)(u8 *buf, int bandwidth); 12 void (*setbw)(u8 *buf, u32 freq, int bandwidth);
13 int count; 13 int count;
14 struct { 14 struct {
15 u32 limit; 15 u32 limit;
@@ -24,12 +24,16 @@ extern struct dvb_pll_desc dvb_pll_thomson_dtt7579;
24extern struct dvb_pll_desc dvb_pll_thomson_dtt759x; 24extern struct dvb_pll_desc dvb_pll_thomson_dtt759x;
25extern struct dvb_pll_desc dvb_pll_thomson_dtt7610; 25extern struct dvb_pll_desc dvb_pll_thomson_dtt7610;
26extern struct dvb_pll_desc dvb_pll_lg_z201; 26extern struct dvb_pll_desc dvb_pll_lg_z201;
27extern struct dvb_pll_desc dvb_pll_microtune_4042;
28extern struct dvb_pll_desc dvb_pll_thomson_dtt7611;
27extern struct dvb_pll_desc dvb_pll_unknown_1; 29extern struct dvb_pll_desc dvb_pll_unknown_1;
28 30
29extern struct dvb_pll_desc dvb_pll_tua6010xs; 31extern struct dvb_pll_desc dvb_pll_tua6010xs;
30extern struct dvb_pll_desc dvb_pll_env57h1xd5; 32extern struct dvb_pll_desc dvb_pll_env57h1xd5;
31extern struct dvb_pll_desc dvb_pll_tua6034; 33extern struct dvb_pll_desc dvb_pll_tua6034;
32extern struct dvb_pll_desc dvb_pll_tda665x; 34extern struct dvb_pll_desc dvb_pll_tda665x;
35extern struct dvb_pll_desc dvb_pll_fmd1216me;
36extern struct dvb_pll_desc dvb_pll_tded4;
33 37
34int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, 38int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
35 u32 freq, int bandwidth); 39 u32 freq, int bandwidth);
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 031a1ddc7d11..faaad1ae8559 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -474,11 +474,12 @@ static int l64781_init(struct dvb_frontend* fe)
474 return 0; 474 return 0;
475} 475}
476 476
477static int l64781_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) 477static int l64781_get_tune_settings(struct dvb_frontend* fe,
478 struct dvb_frontend_tune_settings* fesettings)
478{ 479{
479 fesettings->min_delay_ms = 200; 480 fesettings->min_delay_ms = 4000;
480 fesettings->step_size = 166667; 481 fesettings->step_size = 0;
481 fesettings->max_drift = 166667*2; 482 fesettings->max_drift = 0;
482 return 0; 483 return 0;
483} 484}
484 485
diff --git a/drivers/media/dvb/frontends/lgdt3302.c b/drivers/media/dvb/frontends/lgdt3302.c
new file mode 100644
index 000000000000..c85a2a99df42
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt3302.c
@@ -0,0 +1,599 @@
1/*
2 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
3 *
4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
5 *
6 * Based on code from Kirk Lapray <kirk_lapray@bigfoot.com>
7 * Copyright (C) 2005
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25/*
26 * NOTES ABOUT THIS DRIVER
27 *
28 * This driver supports DViCO FusionHDTV 3 Gold under Linux.
29 *
30 * TODO:
31 * BER and signal strength always return 0.
32 *
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/moduleparam.h>
38#include <linux/init.h>
39#include <linux/delay.h>
40#include <asm/byteorder.h>
41
42#include "dvb_frontend.h"
43#include "dvb-pll.h"
44#include "lgdt3302_priv.h"
45#include "lgdt3302.h"
46
47static int debug = 0;
48module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug,"Turn on/off lgdt3302 frontend debugging (default:off).");
50#define dprintk(args...) \
51do { \
52if (debug) printk(KERN_DEBUG "lgdt3302: " args); \
53} while (0)
54
55struct lgdt3302_state
56{
57 struct i2c_adapter* i2c;
58 struct dvb_frontend_ops ops;
59
60 /* Configuration settings */
61 const struct lgdt3302_config* config;
62
63 struct dvb_frontend frontend;
64
65 /* Demodulator private data */
66 fe_modulation_t current_modulation;
67
68 /* Tuner private data */
69 u32 current_frequency;
70};
71
72static int i2c_writebytes (struct lgdt3302_state* state,
73 u8 addr, /* demod_address or pll_address */
74 u8 *buf, /* data bytes to send */
75 int len /* number of bytes to send */ )
76{
77 if (addr == state->config->pll_address) {
78 struct i2c_msg msg =
79 { .addr = addr, .flags = 0, .buf = buf, .len = len };
80 int err;
81
82 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
83 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
84 if (err < 0)
85 return err;
86 else
87 return -EREMOTEIO;
88 }
89 } else {
90 u8 tmp[] = { buf[0], buf[1] };
91 struct i2c_msg msg =
92 { .addr = addr, .flags = 0, .buf = tmp, .len = 2 };
93 int err;
94 int i;
95
96 for (i=1; i<len; i++) {
97 tmp[1] = buf[i];
98 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
99 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
100 if (err < 0)
101 return err;
102 else
103 return -EREMOTEIO;
104 }
105 tmp[0]++;
106 }
107 }
108 return 0;
109}
110static int i2c_readbytes (struct lgdt3302_state* state,
111 u8 addr, /* demod_address or pll_address */
112 u8 *buf, /* holds data bytes read */
113 int len /* number of bytes to read */ )
114{
115 struct i2c_msg msg =
116 { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
117 int err;
118
119 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
120 printk(KERN_WARNING "lgdt3302: %s error (addr %02x, err == %i)\n", __FUNCTION__, addr, err);
121 return -EREMOTEIO;
122 }
123 return 0;
124}
125
126/*
127 * This routine writes the register (reg) to the demod bus
128 * then reads the data returned for (len) bytes.
129 */
130
131static u8 i2c_selectreadbytes (struct lgdt3302_state* state,
132 enum I2C_REG reg, u8* buf, int len)
133{
134 u8 wr [] = { reg };
135 struct i2c_msg msg [] = {
136 { .addr = state->config->demod_address,
137 .flags = 0, .buf = wr, .len = 1 },
138 { .addr = state->config->demod_address,
139 .flags = I2C_M_RD, .buf = buf, .len = len },
140 };
141 int ret;
142 ret = i2c_transfer(state->i2c, msg, 2);
143 if (ret != 2) {
144 printk(KERN_WARNING "lgdt3302: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __FUNCTION__, state->config->demod_address, reg, ret);
145 } else {
146 ret = 0;
147 }
148 return ret;
149}
150
151/* Software reset */
152int lgdt3302_SwReset(struct lgdt3302_state* state)
153{
154 u8 ret;
155 u8 reset[] = {
156 IRQ_MASK,
157 0x00 /* bit 6 is active low software reset
158 * bits 5-0 are 1 to mask interrupts */
159 };
160
161 ret = i2c_writebytes(state,
162 state->config->demod_address,
163 reset, sizeof(reset));
164 if (ret == 0) {
165 /* spec says reset takes 100 ns why wait */
166 /* mdelay(100); */ /* keep low for 100mS */
167 reset[1] = 0x7f; /* force reset high (inactive)
168 * and unmask interrupts */
169 ret = i2c_writebytes(state,
170 state->config->demod_address,
171 reset, sizeof(reset));
172 }
173 /* Spec does not indicate a need for this either */
174 /*mdelay(5); */ /* wait 5 msec before doing more */
175 return ret;
176}
177
178static int lgdt3302_init(struct dvb_frontend* fe)
179{
180 /* Hardware reset is done using gpio[0] of cx23880x chip.
181 * I'd like to do it here, but don't know how to find chip address.
182 * cx88-cards.c arranges for the reset bit to be inactive (high).
183 * Maybe there needs to be a callable function in cx88-core or
184 * the caller of this function needs to do it. */
185
186 dprintk("%s entered\n", __FUNCTION__);
187 return lgdt3302_SwReset((struct lgdt3302_state*) fe->demodulator_priv);
188}
189
190static int lgdt3302_read_ber(struct dvb_frontend* fe, u32* ber)
191{
192 *ber = 0; /* Dummy out for now */
193 return 0;
194}
195
196static int lgdt3302_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
197{
198 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
199 u8 buf[2];
200
201 i2c_selectreadbytes(state, PACKET_ERR_COUNTER1, buf, sizeof(buf));
202
203 *ucblocks = (buf[0] << 8) | buf[1];
204 return 0;
205}
206
207static int lgdt3302_set_parameters(struct dvb_frontend* fe,
208 struct dvb_frontend_parameters *param)
209{
210 u8 buf[4];
211 struct lgdt3302_state* state =
212 (struct lgdt3302_state*) fe->demodulator_priv;
213
214 /* Use 50MHz parameter values from spec sheet since xtal is 50 */
215 static u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
216 static u8 vsb_freq_cfg[] = { VSB_CARRIER_FREQ0, 0x00, 0x87, 0x8e, 0x01 };
217 static u8 demux_ctrl_cfg[] = { DEMUX_CONTROL, 0xfb };
218 static u8 agc_rf_cfg[] = { AGC_RF_BANDWIDTH0, 0x40, 0x93, 0x00 };
219 static u8 agc_ctrl_cfg[] = { AGC_FUNC_CTRL2, 0xc6, 0x40 };
220 static u8 agc_delay_cfg[] = { AGC_DELAY0, 0x07, 0x00, 0xfe };
221 static u8 agc_loop_cfg[] = { AGC_LOOP_BANDWIDTH0, 0x08, 0x9a };
222
223 /* Change only if we are actually changing the modulation */
224 if (state->current_modulation != param->u.vsb.modulation) {
225 switch(param->u.vsb.modulation) {
226 case VSB_8:
227 dprintk("%s: VSB_8 MODE\n", __FUNCTION__);
228
229 /* Select VSB mode and serial MPEG interface */
230 top_ctrl_cfg[1] = 0x07;
231 break;
232
233 case QAM_64:
234 dprintk("%s: QAM_64 MODE\n", __FUNCTION__);
235
236 /* Select QAM_64 mode and serial MPEG interface */
237 top_ctrl_cfg[1] = 0x04;
238 break;
239
240 case QAM_256:
241 dprintk("%s: QAM_256 MODE\n", __FUNCTION__);
242
243 /* Select QAM_256 mode and serial MPEG interface */
244 top_ctrl_cfg[1] = 0x05;
245 break;
246 default:
247 printk(KERN_WARNING "lgdt3302: %s: Modulation type(%d) UNSUPPORTED\n", __FUNCTION__, param->u.vsb.modulation);
248 return -1;
249 }
250 /* Initializations common to all modes */
251
252 /* Select the requested mode */
253 i2c_writebytes(state, state->config->demod_address,
254 top_ctrl_cfg, sizeof(top_ctrl_cfg));
255
256 /* Change the value of IFBW[11:0]
257 of AGC IF/RF loop filter bandwidth register */
258 i2c_writebytes(state, state->config->demod_address,
259 agc_rf_cfg, sizeof(agc_rf_cfg));
260
261 /* Change the value of bit 6, 'nINAGCBY' and
262 'NSSEL[1:0] of ACG function control register 2 */
263 /* Change the value of bit 6 'RFFIX'
264 of AGC function control register 3 */
265 i2c_writebytes(state, state->config->demod_address,
266 agc_ctrl_cfg, sizeof(agc_ctrl_cfg));
267
268 /* Change the TPCLK pin polarity
269 data is valid on falling clock */
270 i2c_writebytes(state, state->config->demod_address,
271 demux_ctrl_cfg, sizeof(demux_ctrl_cfg));
272
273 /* Change the value of NCOCTFV[25:0] of carrier
274 recovery center frequency register */
275 i2c_writebytes(state, state->config->demod_address,
276 vsb_freq_cfg, sizeof(vsb_freq_cfg));
277
278 /* Set the value of 'INLVTHD' register 0x2a/0x2c to 0x7fe */
279 i2c_writebytes(state, state->config->demod_address,
280 agc_delay_cfg, sizeof(agc_delay_cfg));
281
282 /* Change the value of IAGCBW[15:8]
283 of inner AGC loop filter bandwith */
284 i2c_writebytes(state, state->config->demod_address,
285 agc_loop_cfg, sizeof(agc_loop_cfg));
286
287 state->config->set_ts_params(fe, 0);
288 state->current_modulation = param->u.vsb.modulation;
289 }
290
291 /* Change only if we are actually changing the channel */
292 if (state->current_frequency != param->frequency) {
293 dvb_pll_configure(state->config->pll_desc, buf,
294 param->frequency, 0);
295 dprintk("%s: tuner bytes: 0x%02x 0x%02x "
296 "0x%02x 0x%02x\n", __FUNCTION__, buf[0],buf[1],buf[2],buf[3]);
297 i2c_writebytes(state, state->config->pll_address ,buf, 4);
298
299 /* Check the status of the tuner pll */
300 i2c_readbytes(state, state->config->pll_address, buf, 1);
301 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
302
303 /* Update current frequency */
304 state->current_frequency = param->frequency;
305 }
306 lgdt3302_SwReset(state);
307 return 0;
308}
309
310static int lgdt3302_get_frontend(struct dvb_frontend* fe,
311 struct dvb_frontend_parameters* param)
312{
313 struct lgdt3302_state *state = fe->demodulator_priv;
314 param->frequency = state->current_frequency;
315 return 0;
316}
317
318static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
319{
320 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
321 u8 buf[3];
322
323 *status = 0; /* Reset status result */
324
325 /* Check the status of the tuner pll */
326 i2c_readbytes(state, state->config->pll_address, buf, 1);
327 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
328 if ((buf[0] & 0xc0) != 0x40)
329 return 0; /* Tuner PLL not locked or not powered on */
330
331 /*
332 * You must set the Mask bits to 1 in the IRQ_MASK in order
333 * to see that status bit in the IRQ_STATUS register.
334 * This is done in SwReset();
335 */
336
337 /* AGC status register */
338 i2c_selectreadbytes(state, AGC_STATUS, buf, 1);
339 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]);
340 if ((buf[0] & 0x0c) == 0x8){
341 /* Test signal does not exist flag */
342 /* as well as the AGC lock flag. */
343 *status |= FE_HAS_SIGNAL;
344 } else {
345 /* Without a signal all other status bits are meaningless */
346 return 0;
347 }
348
349 /* signal status */
350 i2c_selectreadbytes(state, TOP_CONTROL, buf, sizeof(buf));
351 dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __FUNCTION__, buf[0], buf[1], buf[2]);
352
353#if 0
354 /* Alternative method to check for a signal */
355 /* using the SNR good/bad interrupts. */
356 if ((buf[2] & 0x30) == 0x10)
357 *status |= FE_HAS_SIGNAL;
358#endif
359
360 /* sync status */
361 if ((buf[2] & 0x03) == 0x01) {
362 *status |= FE_HAS_SYNC;
363 }
364
365 /* FEC error status */
366 if ((buf[2] & 0x0c) == 0x08) {
367 *status |= FE_HAS_LOCK;
368 *status |= FE_HAS_VITERBI;
369 }
370
371 /* Carrier Recovery Lock Status Register */
372 i2c_selectreadbytes(state, CARRIER_LOCK, buf, 1);
373 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]);
374 switch (state->current_modulation) {
375 case QAM_256:
376 case QAM_64:
377 /* Need to undestand why there are 3 lock levels here */
378 if ((buf[0] & 0x07) == 0x07)
379 *status |= FE_HAS_CARRIER;
380 break;
381 case VSB_8:
382 if ((buf[0] & 0x80) == 0x80)
383 *status |= FE_HAS_CARRIER;
384 break;
385 default:
386 printk("KERN_WARNING lgdt3302: %s: Modulation set to unsupported value\n", __FUNCTION__);
387 }
388
389 return 0;
390}
391
392static int lgdt3302_read_signal_strength(struct dvb_frontend* fe, u16* strength)
393{
394 /* not directly available. */
395 return 0;
396}
397
398static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
399{
400#ifdef SNR_IN_DB
401 /*
402 * Spec sheet shows formula for SNR_EQ = 10 log10(25 * 24**2 / noise)
403 * and SNR_PH = 10 log10(25 * 32**2 / noise) for equalizer and phase tracker
404 * respectively. The following tables are built on these formulas.
405 * The usual definition is SNR = 20 log10(signal/noise)
406 * If the specification is wrong the value retuned is 1/2 the actual SNR in db.
407 *
408 * This table is a an ordered list of noise values computed by the
409 * formula from the spec sheet such that the index into the table
410 * starting at 43 or 45 is the SNR value in db. There are duplicate noise
411 * value entries at the beginning because the SNR varies more than
412 * 1 db for a change of 1 digit in noise at very small values of noise.
413 *
414 * Examples from SNR_EQ table:
415 * noise SNR
416 * 0 43
417 * 1 42
418 * 2 39
419 * 3 37
420 * 4 36
421 * 5 35
422 * 6 34
423 * 7 33
424 * 8 33
425 * 9 32
426 * 10 32
427 * 11 31
428 * 12 31
429 * 13 30
430 */
431
432 static const u32 SNR_EQ[] =
433 { 1, 2, 2, 2, 3, 3, 4, 4, 5, 7,
434 9, 11, 13, 17, 21, 26, 33, 41, 52, 65,
435 81, 102, 129, 162, 204, 257, 323, 406, 511, 644,
436 810, 1020, 1284, 1616, 2035, 2561, 3224, 4059, 5110, 6433,
437 8098, 10195, 12835, 16158, 20341, 25608, 32238, 40585, 51094, 64323,
438 80978, 101945, 128341, 161571, 203406, 256073, 0x40000
439 };
440
441 static const u32 SNR_PH[] =
442 { 1, 2, 2, 2, 3, 3, 4, 5, 6, 8,
443 10, 12, 15, 19, 23, 29, 37, 46, 58, 73,
444 91, 115, 144, 182, 229, 288, 362, 456, 574, 722,
445 909, 1144, 1440, 1813, 2282, 2873, 3617, 4553, 5732, 7216,
446 9084, 11436, 14396, 18124, 22817, 28724, 36161, 45524, 57312, 72151,
447 90833, 114351, 143960, 181235, 228161, 0x040000
448 };
449
450 static u8 buf[5];/* read data buffer */
451 static u32 noise; /* noise value */
452 static u32 snr_db; /* index into SNR_EQ[] */
453 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
454
455 /* read both equalizer and pase tracker noise data */
456 i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
457
458 if (state->current_modulation == VSB_8) {
459 /* Equalizer Mean-Square Error Register for VSB */
460 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
461
462 /*
463 * Look up noise value in table.
464 * A better search algorithm could be used...
465 * watch out there are duplicate entries.
466 */
467 for (snr_db = 0; snr_db < sizeof(SNR_EQ); snr_db++) {
468 if (noise < SNR_EQ[snr_db]) {
469 *snr = 43 - snr_db;
470 break;
471 }
472 }
473 } else {
474 /* Phase Tracker Mean-Square Error Register for QAM */
475 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
476
477 /* Look up noise value in table. */
478 for (snr_db = 0; snr_db < sizeof(SNR_PH); snr_db++) {
479 if (noise < SNR_PH[snr_db]) {
480 *snr = 45 - snr_db;
481 break;
482 }
483 }
484 }
485#else
486 /* Return the raw noise value */
487 static u8 buf[5];/* read data buffer */
488 static u32 noise; /* noise value */
489 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
490
491 /* read both equalizer and pase tracker noise data */
492 i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
493
494 if (state->current_modulation == VSB_8) {
495 /* Equalizer Mean-Square Error Register for VSB */
496 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
497 } else {
498 /* Phase Tracker Mean-Square Error Register for QAM */
499 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
500 }
501
502 /* Small values for noise mean signal is better so invert noise */
503 /* Noise is 19 bit value so discard 3 LSB*/
504 *snr = ~noise>>3;
505#endif
506
507 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr);
508
509 return 0;
510}
511
512static int lgdt3302_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings)
513{
514 /* I have no idea about this - it may not be needed */
515 fe_tune_settings->min_delay_ms = 500;
516 fe_tune_settings->step_size = 0;
517 fe_tune_settings->max_drift = 0;
518 return 0;
519}
520
521static void lgdt3302_release(struct dvb_frontend* fe)
522{
523 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
524 kfree(state);
525}
526
527static struct dvb_frontend_ops lgdt3302_ops;
528
529struct dvb_frontend* lgdt3302_attach(const struct lgdt3302_config* config,
530 struct i2c_adapter* i2c)
531{
532 struct lgdt3302_state* state = NULL;
533 u8 buf[1];
534
535 /* Allocate memory for the internal state */
536 state = (struct lgdt3302_state*) kmalloc(sizeof(struct lgdt3302_state), GFP_KERNEL);
537 if (state == NULL)
538 goto error;
539 memset(state,0,sizeof(*state));
540
541 /* Setup the state */
542 state->config = config;
543 state->i2c = i2c;
544 memcpy(&state->ops, &lgdt3302_ops, sizeof(struct dvb_frontend_ops));
545 /* Verify communication with demod chip */
546 if (i2c_selectreadbytes(state, 2, buf, 1))
547 goto error;
548
549 state->current_frequency = -1;
550 state->current_modulation = -1;
551
552 /* Create dvb_frontend */
553 state->frontend.ops = &state->ops;
554 state->frontend.demodulator_priv = state;
555 return &state->frontend;
556
557error:
558 if (state)
559 kfree(state);
560 dprintk("%s: ERROR\n",__FUNCTION__);
561 return NULL;
562}
563
564static struct dvb_frontend_ops lgdt3302_ops = {
565 .info = {
566 .name= "LG Electronics LGDT3302 VSB/QAM Frontend",
567 .type = FE_ATSC,
568 .frequency_min= 54000000,
569 .frequency_max= 858000000,
570 .frequency_stepsize= 62500,
571 /* Symbol rate is for all VSB modes need to check QAM */
572 .symbol_rate_min = 10762000,
573 .symbol_rate_max = 10762000,
574 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
575 },
576 .init = lgdt3302_init,
577 .set_frontend = lgdt3302_set_parameters,
578 .get_frontend = lgdt3302_get_frontend,
579 .get_tune_settings = lgdt3302_get_tune_settings,
580 .read_status = lgdt3302_read_status,
581 .read_ber = lgdt3302_read_ber,
582 .read_signal_strength = lgdt3302_read_signal_strength,
583 .read_snr = lgdt3302_read_snr,
584 .read_ucblocks = lgdt3302_read_ucblocks,
585 .release = lgdt3302_release,
586};
587
588MODULE_DESCRIPTION("LGDT3302 [DViCO FusionHDTV 3 Gold] (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
589MODULE_AUTHOR("Wilson Michaels");
590MODULE_LICENSE("GPL");
591
592EXPORT_SYMBOL(lgdt3302_attach);
593
594/*
595 * Local variables:
596 * c-basic-offset: 8
597 * compile-command: "make DVB=1"
598 * End:
599 */
diff --git a/drivers/media/dvb/frontends/lgdt3302.h b/drivers/media/dvb/frontends/lgdt3302.h
new file mode 100644
index 000000000000..81587a40032b
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt3302.h
@@ -0,0 +1,49 @@
1/*
2 * $Id: lgdt3302.h,v 1.2 2005/06/28 23:50:48 mkrufky Exp $
3 *
4 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
5 *
6 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#ifndef LGDT3302_H
25#define LGDT3302_H
26
27#include <linux/dvb/frontend.h>
28
29struct lgdt3302_config
30{
31 /* The demodulator's i2c address */
32 u8 demod_address;
33 u8 pll_address;
34 struct dvb_pll_desc *pll_desc;
35
36 /* Need to set device param for start_dma */
37 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
38};
39
40extern struct dvb_frontend* lgdt3302_attach(const struct lgdt3302_config* config,
41 struct i2c_adapter* i2c);
42
43#endif /* LGDT3302_H */
44
45/*
46 * Local variables:
47 * c-basic-offset: 8
48 * End:
49 */
diff --git a/drivers/media/dvb/frontends/lgdt3302_priv.h b/drivers/media/dvb/frontends/lgdt3302_priv.h
new file mode 100644
index 000000000000..6193fa7a569d
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt3302_priv.h
@@ -0,0 +1,72 @@
1/*
2 * $Id: lgdt3302_priv.h,v 1.2 2005/06/28 23:50:48 mkrufky Exp $
3 *
4 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
5 *
6 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#ifndef _LGDT3302_PRIV_
25#define _LGDT3302_PRIV_
26
27/* i2c control register addresses */
28enum I2C_REG {
29 TOP_CONTROL= 0x00,
30 IRQ_MASK= 0x01,
31 IRQ_STATUS= 0x02,
32 VSB_CARRIER_FREQ0= 0x16,
33 VSB_CARRIER_FREQ1= 0x17,
34 VSB_CARRIER_FREQ2= 0x18,
35 VSB_CARRIER_FREQ3= 0x19,
36 CARRIER_MSEQAM1= 0x1a,
37 CARRIER_MSEQAM2= 0x1b,
38 CARRIER_LOCK= 0x1c,
39 TIMING_RECOVERY= 0x1d,
40 AGC_DELAY0= 0x2a,
41 AGC_DELAY1= 0x2b,
42 AGC_DELAY2= 0x2c,
43 AGC_RF_BANDWIDTH0= 0x2d,
44 AGC_RF_BANDWIDTH1= 0x2e,
45 AGC_RF_BANDWIDTH2= 0x2f,
46 AGC_LOOP_BANDWIDTH0= 0x30,
47 AGC_LOOP_BANDWIDTH1= 0x31,
48 AGC_FUNC_CTRL1= 0x32,
49 AGC_FUNC_CTRL2= 0x33,
50 AGC_FUNC_CTRL3= 0x34,
51 AGC_RFIF_ACC0= 0x39,
52 AGC_RFIF_ACC1= 0x3a,
53 AGC_RFIF_ACC2= 0x3b,
54 AGC_STATUS= 0x3f,
55 SYNC_STATUS_VSB= 0x43,
56 EQPH_ERR0= 0x47,
57 EQ_ERR1= 0x48,
58 EQ_ERR2= 0x49,
59 PH_ERR1= 0x4a,
60 PH_ERR2= 0x4b,
61 DEMUX_CONTROL= 0x66,
62 PACKET_ERR_COUNTER1= 0x6a,
63 PACKET_ERR_COUNTER2= 0x6b,
64};
65
66#endif /* _LGDT3302_PRIV_ */
67
68/*
69 * Local variables:
70 * c-basic-offset: 8
71 * End:
72 */
diff --git a/drivers/media/dvb/frontends/s5h1420.c b/drivers/media/dvb/frontends/s5h1420.c
new file mode 100644
index 000000000000..4f396ac8de77
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1420.c
@@ -0,0 +1,800 @@
1/*
2Driver for Samsung S5H1420 QPSK Demodulator
3
4Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include <linux/delay.h>
29
30#include "dvb_frontend.h"
31#include "s5h1420.h"
32
33
34
35#define TONE_FREQ 22000
36
37struct s5h1420_state {
38 struct i2c_adapter* i2c;
39 struct dvb_frontend_ops ops;
40 const struct s5h1420_config* config;
41 struct dvb_frontend frontend;
42
43 u8 postlocked:1;
44 u32 fclk;
45 u32 tunedfreq;
46 fe_code_rate_t fec_inner;
47 u32 symbol_rate;
48};
49
50static u32 s5h1420_getsymbolrate(struct s5h1420_state* state);
51static int s5h1420_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings);
52
53
54static int debug = 0;
55#define dprintk if (debug) printk
56
57static int s5h1420_writereg (struct s5h1420_state* state, u8 reg, u8 data)
58{
59 u8 buf [] = { reg, data };
60 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };
61 int err;
62
63 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
64 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data);
65 return -EREMOTEIO;
66 }
67
68 return 0;
69}
70
71static u8 s5h1420_readreg (struct s5h1420_state* state, u8 reg)
72{
73 int ret;
74 u8 b0 [] = { reg };
75 u8 b1 [] = { 0 };
76 struct i2c_msg msg1 = { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 };
77 struct i2c_msg msg2 = { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 };
78
79 if ((ret = i2c_transfer (state->i2c, &msg1, 1)) != 1)
80 return ret;
81
82 if ((ret = i2c_transfer (state->i2c, &msg2, 1)) != 1)
83 return ret;
84
85 return b1[0];
86}
87
88static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
89{
90 struct s5h1420_state* state = fe->demodulator_priv;
91
92 switch(voltage) {
93 case SEC_VOLTAGE_13:
94 s5h1420_writereg(state, 0x3c, (s5h1420_readreg(state, 0x3c) & 0xfe) | 0x02);
95 break;
96
97 case SEC_VOLTAGE_18:
98 s5h1420_writereg(state, 0x3c, s5h1420_readreg(state, 0x3c) | 0x03);
99 break;
100
101 case SEC_VOLTAGE_OFF:
102 s5h1420_writereg(state, 0x3c, s5h1420_readreg(state, 0x3c) & 0xfd);
103 break;
104 }
105
106 return 0;
107}
108
109static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
110{
111 struct s5h1420_state* state = fe->demodulator_priv;
112
113 switch(tone) {
114 case SEC_TONE_ON:
115 s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x74) | 0x08);
116 break;
117
118 case SEC_TONE_OFF:
119 s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01);
120 break;
121 }
122
123 return 0;
124}
125
126static int s5h1420_send_master_cmd (struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
127{
128 struct s5h1420_state* state = fe->demodulator_priv;
129 u8 val;
130 int i;
131 unsigned long timeout;
132 int result = 0;
133
134 /* setup for DISEQC */
135 val = s5h1420_readreg(state, 0x3b);
136 s5h1420_writereg(state, 0x3b, 0x02);
137 msleep(15);
138
139 /* write the DISEQC command bytes */
140 for(i=0; i< cmd->msg_len; i++) {
141 s5h1420_writereg(state, 0x3c + i, cmd->msg[i]);
142 }
143
144 /* kick off transmission */
145 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | ((cmd->msg_len-1) << 4) | 0x08);
146
147 /* wait for transmission to complete */
148 timeout = jiffies + ((100*HZ) / 1000);
149 while(time_before(jiffies, timeout)) {
150 if (s5h1420_readreg(state, 0x3b) & 0x08)
151 break;
152
153 msleep(5);
154 }
155 if (time_after(jiffies, timeout))
156 result = -ETIMEDOUT;
157
158 /* restore original settings */
159 s5h1420_writereg(state, 0x3b, val);
160 msleep(15);
161 return result;
162}
163
164static int s5h1420_recv_slave_reply (struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply)
165{
166 struct s5h1420_state* state = fe->demodulator_priv;
167 u8 val;
168 int i;
169 int length;
170 unsigned long timeout;
171 int result = 0;
172
173 /* setup for DISEQC recieve */
174 val = s5h1420_readreg(state, 0x3b);
175 s5h1420_writereg(state, 0x3b, 0x82); /* FIXME: guess - do we need to set DIS_RDY(0x08) in receive mode? */
176 msleep(15);
177
178 /* wait for reception to complete */
179 timeout = jiffies + ((reply->timeout*HZ) / 1000);
180 while(time_before(jiffies, timeout)) {
181 if (!(s5h1420_readreg(state, 0x3b) & 0x80)) /* FIXME: do we test DIS_RDY(0x08) or RCV_EN(0x80)? */
182 break;
183
184 msleep(5);
185 }
186 if (time_after(jiffies, timeout)) {
187 result = -ETIMEDOUT;
188 goto exit;
189 }
190
191 /* check error flag - FIXME: not sure what this does - docs do not describe
192 * beyond "error flag for diseqc receive data :( */
193 if (s5h1420_readreg(state, 0x49)) {
194 result = -EIO;
195 goto exit;
196 }
197
198 /* check length */
199 length = (s5h1420_readreg(state, 0x3b) & 0x70) >> 4;
200 if (length > sizeof(reply->msg)) {
201 result = -EOVERFLOW;
202 goto exit;
203 }
204 reply->msg_len = length;
205
206 /* extract data */
207 for(i=0; i< length; i++) {
208 reply->msg[i] = s5h1420_readreg(state, 0x3c + i);
209 }
210
211exit:
212 /* restore original settings */
213 s5h1420_writereg(state, 0x3b, val);
214 msleep(15);
215 return result;
216}
217
218static int s5h1420_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
219{
220 struct s5h1420_state* state = fe->demodulator_priv;
221 u8 val;
222 int result = 0;
223 unsigned long timeout;
224
225 /* setup for tone burst */
226 val = s5h1420_readreg(state, 0x3b);
227 s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x70) | 0x01);
228
229 /* set value for B position if requested */
230 if (minicmd == SEC_MINI_B) {
231 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x04);
232 }
233 msleep(15);
234
235 /* start transmission */
236 s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x08);
237
238 /* wait for transmission to complete */
239 timeout = jiffies + ((20*HZ) / 1000);
240 while(time_before(jiffies, timeout)) {
241 if (!(s5h1420_readreg(state, 0x3b) & 0x08))
242 break;
243
244 msleep(5);
245 }
246 if (time_after(jiffies, timeout))
247 result = -ETIMEDOUT;
248
249 /* restore original settings */
250 s5h1420_writereg(state, 0x3b, val);
251 msleep(15);
252 return result;
253}
254
255static fe_status_t s5h1420_get_status_bits(struct s5h1420_state* state)
256{
257 u8 val;
258 fe_status_t status = 0;
259
260 val = s5h1420_readreg(state, 0x14);
261 if (val & 0x02)
262 status |= FE_HAS_SIGNAL; // FIXME: not sure if this is right
263 if (val & 0x01)
264 status |= FE_HAS_CARRIER; // FIXME: not sure if this is right
265 val = s5h1420_readreg(state, 0x36);
266 if (val & 0x01)
267 status |= FE_HAS_VITERBI;
268 if (val & 0x20)
269 status |= FE_HAS_SYNC;
270 if (status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI|FE_HAS_SYNC))
271 status |= FE_HAS_LOCK;
272
273 return status;
274}
275
276static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
277{
278 struct s5h1420_state* state = fe->demodulator_priv;
279 u8 val;
280
281 if (status == NULL)
282 return -EINVAL;
283
284 /* determine lock state */
285 *status = s5h1420_get_status_bits(state);
286
287 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert the inversion,
288 wait a bit and check again */
289 if (*status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI)) {
290 val = s5h1420_readreg(state, 0x32);
291 if ((val & 0x07) == 0x03) {
292 if (val & 0x08)
293 s5h1420_writereg(state, 0x31, 0x13);
294 else
295 s5h1420_writereg(state, 0x31, 0x1b);
296
297 /* wait a bit then update lock status */
298 mdelay(200);
299 *status = s5h1420_get_status_bits(state);
300 }
301 }
302
303 /* perform post lock setup */
304 if ((*status & FE_HAS_LOCK) && (!state->postlocked)) {
305
306 /* calculate the data rate */
307 u32 tmp = s5h1420_getsymbolrate(state);
308 switch(s5h1420_readreg(state, 0x32) & 0x07) {
309 case 0:
310 tmp = (tmp * 2 * 1) / 2;
311 break;
312
313 case 1:
314 tmp = (tmp * 2 * 2) / 3;
315 break;
316
317 case 2:
318 tmp = (tmp * 2 * 3) / 4;
319 break;
320
321 case 3:
322 tmp = (tmp * 2 * 5) / 6;
323 break;
324
325 case 4:
326 tmp = (tmp * 2 * 6) / 7;
327 break;
328
329 case 5:
330 tmp = (tmp * 2 * 7) / 8;
331 break;
332 }
333 tmp = state->fclk / tmp;
334
335 /* set the MPEG_CLK_INTL for the calculated data rate */
336 if (tmp < 4)
337 val = 0x00;
338 else if (tmp < 8)
339 val = 0x01;
340 else if (tmp < 12)
341 val = 0x02;
342 else if (tmp < 16)
343 val = 0x03;
344 else if (tmp < 24)
345 val = 0x04;
346 else if (tmp < 32)
347 val = 0x05;
348 else
349 val = 0x06;
350 s5h1420_writereg(state, 0x22, val);
351
352 /* DC freeze */
353 s5h1420_writereg(state, 0x1f, s5h1420_readreg(state, 0x1f) | 0x01);
354
355 /* kicker disable + remove DC offset */
356 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) & 0x6f);
357
358 /* post-lock processing has been done! */
359 state->postlocked = 1;
360 }
361
362 return 0;
363}
364
365static int s5h1420_read_ber(struct dvb_frontend* fe, u32* ber)
366{
367 struct s5h1420_state* state = fe->demodulator_priv;
368
369 s5h1420_writereg(state, 0x46, 0x1d);
370 mdelay(25);
371 return (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47);
372}
373
374static int s5h1420_read_signal_strength(struct dvb_frontend* fe, u16* strength)
375{
376 struct s5h1420_state* state = fe->demodulator_priv;
377
378 u8 val = 0xff - s5h1420_readreg(state, 0x15);
379
380 return (int) ((val << 8) | val);
381}
382
383static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
384{
385 struct s5h1420_state* state = fe->demodulator_priv;
386
387 s5h1420_writereg(state, 0x46, 0x1f);
388 mdelay(25);
389 return (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47);
390}
391
392static void s5h1420_reset(struct s5h1420_state* state)
393{
394 s5h1420_writereg (state, 0x01, 0x08);
395 s5h1420_writereg (state, 0x01, 0x00);
396 udelay(10);
397}
398
399static void s5h1420_setsymbolrate(struct s5h1420_state* state, struct dvb_frontend_parameters *p)
400{
401 u64 val;
402
403 val = (p->u.qpsk.symbol_rate / 1000) * (1<<24);
404 if (p->u.qpsk.symbol_rate <= 21000000) {
405 val *= 2;
406 }
407 do_div(val, (state->fclk / 1000));
408
409 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) & 0x7f);
410 s5h1420_writereg(state, 0x11, val >> 16);
411 s5h1420_writereg(state, 0x12, val >> 8);
412 s5h1420_writereg(state, 0x13, val & 0xff);
413 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) | 0x80);
414}
415
416static u32 s5h1420_getsymbolrate(struct s5h1420_state* state)
417{
418 u64 val;
419 int sampling = 2;
420
421 if (s5h1420_readreg(state, 0x05) & 0x2)
422 sampling = 1;
423
424 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) | 0x08);
425 val = s5h1420_readreg(state, 0x11) << 16;
426 val |= s5h1420_readreg(state, 0x12) << 8;
427 val |= s5h1420_readreg(state, 0x13);
428 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7);
429
430 val *= (state->fclk / 1000);
431 do_div(val, ((1<<24) * sampling));
432
433 return (u32) (val * 1000);
434}
435
436static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset)
437{
438 int val;
439
440 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
441 * divide fclk by 1000000 to get the correct value. */
442 val = -(int) ((freqoffset * (1<<24)) / (state->fclk / 1000000));
443
444 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) & 0xbf);
445 s5h1420_writereg(state, 0x0e, val >> 16);
446 s5h1420_writereg(state, 0x0f, val >> 8);
447 s5h1420_writereg(state, 0x10, val & 0xff);
448 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) | 0x40);
449}
450
451static int s5h1420_getfreqoffset(struct s5h1420_state* state)
452{
453 int val;
454
455 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) | 0x08);
456 val = s5h1420_readreg(state, 0x0e) << 16;
457 val |= s5h1420_readreg(state, 0x0f) << 8;
458 val |= s5h1420_readreg(state, 0x10);
459 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7);
460
461 if (val & 0x800000)
462 val |= 0xff000000;
463
464 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
465 * divide fclk by 1000000 to get the correct value. */
466 val = - ((val * (state->fclk/1000000)) / (1<<24));
467
468 return val;
469}
470
471static void s5h1420_setfec(struct s5h1420_state* state, struct dvb_frontend_parameters *p)
472{
473 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) {
474 s5h1420_writereg(state, 0x31, 0x00);
475 s5h1420_writereg(state, 0x30, 0x3f);
476 } else {
477 switch(p->u.qpsk.fec_inner) {
478 case FEC_1_2:
479 s5h1420_writereg(state, 0x31, 0x10);
480 s5h1420_writereg(state, 0x30, 0x01);
481 break;
482
483 case FEC_2_3:
484 s5h1420_writereg(state, 0x31, 0x11);
485 s5h1420_writereg(state, 0x30, 0x02);
486 break;
487
488 case FEC_3_4:
489 s5h1420_writereg(state, 0x31, 0x12);
490 s5h1420_writereg(state, 0x30, 0x04);
491 break;
492
493 case FEC_5_6:
494 s5h1420_writereg(state, 0x31, 0x13);
495 s5h1420_writereg(state, 0x30, 0x08);
496 break;
497
498 case FEC_6_7:
499 s5h1420_writereg(state, 0x31, 0x14);
500 s5h1420_writereg(state, 0x30, 0x10);
501 break;
502
503 case FEC_7_8:
504 s5h1420_writereg(state, 0x31, 0x15);
505 s5h1420_writereg(state, 0x30, 0x20);
506 break;
507
508 default:
509 return;
510 }
511 }
512}
513
514static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state)
515{
516 switch(s5h1420_readreg(state, 0x32) & 0x07) {
517 case 0:
518 return FEC_1_2;
519
520 case 1:
521 return FEC_2_3;
522
523 case 2:
524 return FEC_3_4;
525
526 case 3:
527 return FEC_5_6;
528
529 case 4:
530 return FEC_6_7;
531
532 case 5:
533 return FEC_7_8;
534 }
535
536 return FEC_NONE;
537}
538
539static void s5h1420_setinversion(struct s5h1420_state* state, struct dvb_frontend_parameters *p)
540{
541 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) {
542 s5h1420_writereg(state, 0x31, 0x00);
543 s5h1420_writereg(state, 0x30, 0x3f);
544 } else {
545 u8 tmp = s5h1420_readreg(state, 0x31) & 0xf7;
546 tmp |= 0x10;
547
548 if (p->inversion == INVERSION_ON)
549 tmp |= 0x80;
550
551 s5h1420_writereg(state, 0x31, tmp);
552 }
553}
554
555static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state)
556{
557 if (s5h1420_readreg(state, 0x32) & 0x08)
558 return INVERSION_ON;
559
560 return INVERSION_OFF;
561}
562
563static int s5h1420_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
564{
565 struct s5h1420_state* state = fe->demodulator_priv;
566 u32 frequency_delta;
567 struct dvb_frontend_tune_settings fesettings;
568
569 /* check if we should do a fast-tune */
570 memcpy(&fesettings.parameters, p, sizeof(struct dvb_frontend_parameters));
571 s5h1420_get_tune_settings(fe, &fesettings);
572 frequency_delta = p->frequency - state->tunedfreq;
573 if ((frequency_delta > -fesettings.max_drift) && (frequency_delta < fesettings.max_drift) &&
574 (frequency_delta != 0) &&
575 (state->fec_inner == p->u.qpsk.fec_inner) &&
576 (state->symbol_rate == p->u.qpsk.symbol_rate)) {
577
578 s5h1420_setfreqoffset(state, frequency_delta);
579 return 0;
580 }
581
582 /* first of all, software reset */
583 s5h1420_reset(state);
584
585 /* set tuner PLL */
586 if (state->config->pll_set) {
587 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1);
588 state->config->pll_set(fe, p, &state->tunedfreq);
589 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) & 0xfe);
590 }
591
592 /* set s5h1420 fclk PLL according to desired symbol rate */
593 if (p->u.qpsk.symbol_rate > 28000000) {
594 state->fclk = 88000000;
595 s5h1420_writereg(state, 0x03, 0x50);
596 s5h1420_writereg(state, 0x04, 0x40);
597 s5h1420_writereg(state, 0x05, 0xae);
598 } else if (p->u.qpsk.symbol_rate > 21000000) {
599 state->fclk = 59000000;
600 s5h1420_writereg(state, 0x03, 0x33);
601 s5h1420_writereg(state, 0x04, 0x40);
602 s5h1420_writereg(state, 0x05, 0xae);
603 } else {
604 state->fclk = 88000000;
605 s5h1420_writereg(state, 0x03, 0x50);
606 s5h1420_writereg(state, 0x04, 0x40);
607 s5h1420_writereg(state, 0x05, 0xac);
608 }
609
610 /* set misc registers */
611 s5h1420_writereg(state, 0x02, 0x00);
612 s5h1420_writereg(state, 0x07, 0xb0);
613 s5h1420_writereg(state, 0x0a, 0x67);
614 s5h1420_writereg(state, 0x0b, 0x78);
615 s5h1420_writereg(state, 0x0c, 0x48);
616 s5h1420_writereg(state, 0x0d, 0x6b);
617 s5h1420_writereg(state, 0x2e, 0x8e);
618 s5h1420_writereg(state, 0x35, 0x33);
619 s5h1420_writereg(state, 0x38, 0x01);
620 s5h1420_writereg(state, 0x39, 0x7d);
621 s5h1420_writereg(state, 0x3a, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32));
622 s5h1420_writereg(state, 0x3c, 0x00);
623 s5h1420_writereg(state, 0x45, 0x61);
624 s5h1420_writereg(state, 0x46, 0x1d);
625
626 /* start QPSK */
627 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) | 1);
628
629 /* set the frequency offset to adjust for PLL inaccuracy */
630 s5h1420_setfreqoffset(state, p->frequency - state->tunedfreq);
631
632 /* set the reset of the parameters */
633 s5h1420_setsymbolrate(state, p);
634 s5h1420_setinversion(state, p);
635 s5h1420_setfec(state, p);
636
637 state->fec_inner = p->u.qpsk.fec_inner;
638 state->symbol_rate = p->u.qpsk.symbol_rate;
639 state->postlocked = 0;
640 return 0;
641}
642
643static int s5h1420_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
644{
645 struct s5h1420_state* state = fe->demodulator_priv;
646
647 p->frequency = state->tunedfreq + s5h1420_getfreqoffset(state);
648 p->inversion = s5h1420_getinversion(state);
649 p->u.qpsk.symbol_rate = s5h1420_getsymbolrate(state);
650 p->u.qpsk.fec_inner = s5h1420_getfec(state);
651
652 return 0;
653}
654
655static int s5h1420_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
656{
657 if (fesettings->parameters.u.qpsk.symbol_rate > 20000000) {
658 fesettings->min_delay_ms = 50;
659 fesettings->step_size = 2000;
660 fesettings->max_drift = 8000;
661 } else if (fesettings->parameters.u.qpsk.symbol_rate > 12000000) {
662 fesettings->min_delay_ms = 100;
663 fesettings->step_size = 1500;
664 fesettings->max_drift = 9000;
665 } else if (fesettings->parameters.u.qpsk.symbol_rate > 8000000) {
666 fesettings->min_delay_ms = 100;
667 fesettings->step_size = 1000;
668 fesettings->max_drift = 8000;
669 } else if (fesettings->parameters.u.qpsk.symbol_rate > 4000000) {
670 fesettings->min_delay_ms = 100;
671 fesettings->step_size = 500;
672 fesettings->max_drift = 7000;
673 } else if (fesettings->parameters.u.qpsk.symbol_rate > 2000000) {
674 fesettings->min_delay_ms = 200;
675 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
676 fesettings->max_drift = 14 * fesettings->step_size;
677 } else {
678 fesettings->min_delay_ms = 200;
679 fesettings->step_size = (fesettings->parameters.u.qpsk.symbol_rate / 8000);
680 fesettings->max_drift = 18 * fesettings->step_size;
681 }
682
683 return 0;
684}
685
686static int s5h1420_init (struct dvb_frontend* fe)
687{
688 struct s5h1420_state* state = fe->demodulator_priv;
689
690 /* disable power down and do reset */
691 s5h1420_writereg(state, 0x02, 0x10);
692 msleep(10);
693 s5h1420_reset(state);
694
695 /* init PLL */
696 if (state->config->pll_init) {
697 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1);
698 state->config->pll_init(fe);
699 s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) & 0xfe);
700 }
701
702 return 0;
703}
704
705static int s5h1420_sleep(struct dvb_frontend* fe)
706{
707 struct s5h1420_state* state = fe->demodulator_priv;
708
709 return s5h1420_writereg(state, 0x02, 0x12);
710}
711
712static void s5h1420_release(struct dvb_frontend* fe)
713{
714 struct s5h1420_state* state = fe->demodulator_priv;
715 kfree(state);
716}
717
718static struct dvb_frontend_ops s5h1420_ops;
719
720struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, struct i2c_adapter* i2c)
721{
722 struct s5h1420_state* state = NULL;
723 u8 identity;
724
725 /* allocate memory for the internal state */
726 state = kmalloc(sizeof(struct s5h1420_state), GFP_KERNEL);
727 if (state == NULL)
728 goto error;
729
730 /* setup the state */
731 state->config = config;
732 state->i2c = i2c;
733 memcpy(&state->ops, &s5h1420_ops, sizeof(struct dvb_frontend_ops));
734 state->postlocked = 0;
735 state->fclk = 88000000;
736 state->tunedfreq = 0;
737 state->fec_inner = FEC_NONE;
738 state->symbol_rate = 0;
739
740 /* check if the demod is there + identify it */
741 identity = s5h1420_readreg(state, 0x00);
742 if (identity != 0x03)
743 goto error;
744
745 /* create dvb_frontend */
746 state->frontend.ops = &state->ops;
747 state->frontend.demodulator_priv = state;
748 return &state->frontend;
749
750error:
751 kfree(state);
752 return NULL;
753}
754
755static struct dvb_frontend_ops s5h1420_ops = {
756
757 .info = {
758 .name = "Samsung S5H1420 DVB-S",
759 .type = FE_QPSK,
760 .frequency_min = 950000,
761 .frequency_max = 2150000,
762 .frequency_stepsize = 125, /* kHz for QPSK frontends */
763 .frequency_tolerance = 29500,
764 .symbol_rate_min = 1000000,
765 .symbol_rate_max = 45000000,
766 /* .symbol_rate_tolerance = ???,*/
767 .caps = FE_CAN_INVERSION_AUTO |
768 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
769 FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
770 FE_CAN_QPSK
771 },
772
773 .release = s5h1420_release,
774
775 .init = s5h1420_init,
776 .sleep = s5h1420_sleep,
777
778 .set_frontend = s5h1420_set_frontend,
779 .get_frontend = s5h1420_get_frontend,
780 .get_tune_settings = s5h1420_get_tune_settings,
781
782 .read_status = s5h1420_read_status,
783 .read_ber = s5h1420_read_ber,
784 .read_signal_strength = s5h1420_read_signal_strength,
785 .read_ucblocks = s5h1420_read_ucblocks,
786
787 .diseqc_send_master_cmd = s5h1420_send_master_cmd,
788 .diseqc_recv_slave_reply = s5h1420_recv_slave_reply,
789 .diseqc_send_burst = s5h1420_send_burst,
790 .set_tone = s5h1420_set_tone,
791 .set_voltage = s5h1420_set_voltage,
792};
793
794module_param(debug, int, 0644);
795
796MODULE_DESCRIPTION("Samsung S5H1420 DVB-S Demodulator driver");
797MODULE_AUTHOR("Andrew de Quincey");
798MODULE_LICENSE("GPL");
799
800EXPORT_SYMBOL(s5h1420_attach);
diff --git a/drivers/media/dvb/frontends/s5h1420.h b/drivers/media/dvb/frontends/s5h1420.h
new file mode 100644
index 000000000000..b687fc77ceb3
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1420.h
@@ -0,0 +1,41 @@
1/*
2 Driver for S5H1420 QPSK Demodulators
3
4 Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#ifndef S5H1420_H
24#define S5H1420_H
25
26#include <linux/dvb/frontend.h>
27
28struct s5h1420_config
29{
30 /* the demodulator's i2c address */
31 u8 demod_address;
32
33 /* PLL maintenance */
34 int (*pll_init)(struct dvb_frontend* fe);
35 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout);
36};
37
38extern struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config,
39 struct i2c_adapter* i2c);
40
41#endif // S5H1420_H
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index e681263bf079..928aca052afe 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -617,7 +617,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
617 617
618 /* wait for WGAGC lock */ 618 /* wait for WGAGC lock */
619 starttime = jiffies; 619 starttime = jiffies;
620 timeout = jiffies + (200 * HZ) / 1000; 620 timeout = jiffies + msecs_to_jiffies(2000);
621 while (time_before(jiffies, timeout)) { 621 while (time_before(jiffies, timeout)) {
622 msleep(10); 622 msleep(10);
623 if (stv0297_readreg(state, 0x43) & 0x08) 623 if (stv0297_readreg(state, 0x43) & 0x08)
@@ -629,7 +629,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
629 msleep(20); 629 msleep(20);
630 630
631 /* wait for equaliser partial convergence */ 631 /* wait for equaliser partial convergence */
632 timeout = jiffies + (50 * HZ) / 1000; 632 timeout = jiffies + msecs_to_jiffies(500);
633 while (time_before(jiffies, timeout)) { 633 while (time_before(jiffies, timeout)) {
634 msleep(10); 634 msleep(10);
635 635
@@ -642,7 +642,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
642 } 642 }
643 643
644 /* wait for equaliser full convergence */ 644 /* wait for equaliser full convergence */
645 timeout = jiffies + (delay * HZ) / 1000; 645 timeout = jiffies + msecs_to_jiffies(delay);
646 while (time_before(jiffies, timeout)) { 646 while (time_before(jiffies, timeout)) {
647 msleep(10); 647 msleep(10);
648 648
@@ -659,7 +659,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
659 stv0297_writereg_mask(state, 0x88, 8, 0); 659 stv0297_writereg_mask(state, 0x88, 8, 0);
660 660
661 /* wait for main lock */ 661 /* wait for main lock */
662 timeout = jiffies + (20 * HZ) / 1000; 662 timeout = jiffies + msecs_to_jiffies(20);
663 while (time_before(jiffies, timeout)) { 663 while (time_before(jiffies, timeout)) {
664 msleep(10); 664 msleep(10);
665 665
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 0beb370792ae..ab0c032472cc 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -49,10 +49,8 @@ struct tda1004x_state {
49 /* private demod data */ 49 /* private demod data */
50 u8 initialised; 50 u8 initialised;
51 enum tda1004x_demod demod_type; 51 enum tda1004x_demod demod_type;
52 u8 fw_version;
53}; 52};
54 53
55
56static int debug; 54static int debug;
57#define dprintk(args...) \ 55#define dprintk(args...) \
58 do { \ 56 do { \
@@ -122,6 +120,8 @@ static int debug;
122#define TDA10046H_GPIO_OUT_SEL 0x41 120#define TDA10046H_GPIO_OUT_SEL 0x41
123#define TDA10046H_GPIO_SELECT 0x42 121#define TDA10046H_GPIO_SELECT 0x42
124#define TDA10046H_AGC_CONF 0x43 122#define TDA10046H_AGC_CONF 0x43
123#define TDA10046H_AGC_THR 0x44
124#define TDA10046H_AGC_RENORM 0x45
125#define TDA10046H_AGC_GAINS 0x46 125#define TDA10046H_AGC_GAINS 0x46
126#define TDA10046H_AGC_TUN_MIN 0x47 126#define TDA10046H_AGC_TUN_MIN 0x47
127#define TDA10046H_AGC_TUN_MAX 0x48 127#define TDA10046H_AGC_TUN_MAX 0x48
@@ -274,14 +274,26 @@ static int tda10046h_set_bandwidth(struct tda1004x_state *state,
274 switch (bandwidth) { 274 switch (bandwidth) {
275 case BANDWIDTH_6_MHZ: 275 case BANDWIDTH_6_MHZ:
276 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_6mhz, sizeof(bandwidth_6mhz)); 276 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_6mhz, sizeof(bandwidth_6mhz));
277 if (state->config->if_freq == TDA10046_FREQ_045) {
278 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0x09);
279 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x4f);
280 }
277 break; 281 break;
278 282
279 case BANDWIDTH_7_MHZ: 283 case BANDWIDTH_7_MHZ:
280 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_7mhz, sizeof(bandwidth_7mhz)); 284 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_7mhz, sizeof(bandwidth_7mhz));
285 if (state->config->if_freq == TDA10046_FREQ_045) {
286 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0x0a);
287 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x79);
288 }
281 break; 289 break;
282 290
283 case BANDWIDTH_8_MHZ: 291 case BANDWIDTH_8_MHZ:
284 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_8mhz, sizeof(bandwidth_8mhz)); 292 tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_8mhz, sizeof(bandwidth_8mhz));
293 if (state->config->if_freq == TDA10046_FREQ_045) {
294 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0x0b);
295 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0xa3);
296 }
285 break; 297 break;
286 298
287 default: 299 default:
@@ -315,20 +327,35 @@ static int tda1004x_do_upload(struct tda1004x_state *state,
315 memcpy(buf + 1, mem + pos, tx_size); 327 memcpy(buf + 1, mem + pos, tx_size);
316 fw_msg.len = tx_size + 1; 328 fw_msg.len = tx_size + 1;
317 if (i2c_transfer(state->i2c, &fw_msg, 1) != 1) { 329 if (i2c_transfer(state->i2c, &fw_msg, 1) != 1) {
318 printk("tda1004x: Error during firmware upload\n"); 330 printk(KERN_ERR "tda1004x: Error during firmware upload\n");
319 return -EIO; 331 return -EIO;
320 } 332 }
321 pos += tx_size; 333 pos += tx_size;
322 334
323 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos); 335 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos);
324 } 336 }
337 // give the DSP a chance to settle 03/10/05 Hac
338 msleep(100);
325 339
326 return 0; 340 return 0;
327} 341}
328 342
329static int tda1004x_check_upload_ok(struct tda1004x_state *state, u8 dspVersion) 343static int tda1004x_check_upload_ok(struct tda1004x_state *state)
330{ 344{
331 u8 data1, data2; 345 u8 data1, data2;
346 unsigned long timeout;
347
348 if (state->demod_type == TDA1004X_DEMOD_TDA10046) {
349 timeout = jiffies + 2 * HZ;
350 while(!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) {
351 if (time_after(jiffies, timeout)) {
352 printk(KERN_ERR "tda1004x: timeout waiting for DSP ready\n");
353 break;
354 }
355 msleep(1);
356 }
357 } else
358 msleep(100);
332 359
333 // check upload was OK 360 // check upload was OK
334 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0); // we want to read from the DSP 361 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0); // we want to read from the DSP
@@ -336,9 +363,11 @@ static int tda1004x_check_upload_ok(struct tda1004x_state *state, u8 dspVersion)
336 363
337 data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1); 364 data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1);
338 data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2); 365 data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2);
339 if ((data1 != 0x67) || (data2 != dspVersion)) 366 if (data1 != 0x67 || data2 < 0x20 || data2 > 0x2e) {
367 printk(KERN_INFO "tda1004x: found firmware revision %x -- invalid\n", data2);
340 return -EIO; 368 return -EIO;
341 369 }
370 printk(KERN_INFO "tda1004x: found firmware revision %x -- ok\n", data2);
342 return 0; 371 return 0;
343} 372}
344 373
@@ -349,14 +378,14 @@ static int tda10045_fwupload(struct dvb_frontend* fe)
349 const struct firmware *fw; 378 const struct firmware *fw;
350 379
351 /* don't re-upload unless necessary */ 380 /* don't re-upload unless necessary */
352 if (tda1004x_check_upload_ok(state, 0x2c) == 0) 381 if (tda1004x_check_upload_ok(state) == 0)
353 return 0; 382 return 0;
354 383
355 /* request the firmware, this will block until someone uploads it */ 384 /* request the firmware, this will block until someone uploads it */
356 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE); 385 printk(KERN_INFO "tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE);
357 ret = state->config->request_firmware(fe, &fw, TDA10045_DEFAULT_FIRMWARE); 386 ret = state->config->request_firmware(fe, &fw, TDA10045_DEFAULT_FIRMWARE);
358 if (ret) { 387 if (ret) {
359 printk("tda1004x: no firmware upload (timeout or file not found?)\n"); 388 printk(KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
360 return ret; 389 return ret;
361 } 390 }
362 391
@@ -370,95 +399,93 @@ static int tda10045_fwupload(struct dvb_frontend* fe)
370 tda10045h_set_bandwidth(state, BANDWIDTH_8_MHZ); 399 tda10045h_set_bandwidth(state, BANDWIDTH_8_MHZ);
371 400
372 ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10045H_FWPAGE, TDA10045H_CODE_IN); 401 ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10045H_FWPAGE, TDA10045H_CODE_IN);
402 release_firmware(fw);
373 if (ret) 403 if (ret)
374 return ret; 404 return ret;
375 printk("tda1004x: firmware upload complete\n"); 405 printk(KERN_INFO "tda1004x: firmware upload complete\n");
376 406
377 /* wait for DSP to initialise */ 407 /* wait for DSP to initialise */
378 /* DSPREADY doesn't seem to work on the TDA10045H */ 408 /* DSPREADY doesn't seem to work on the TDA10045H */
379 msleep(100); 409 msleep(100);
380 410
381 return tda1004x_check_upload_ok(state, 0x2c); 411 return tda1004x_check_upload_ok(state);
382} 412}
383 413
384static int tda10046_get_fw_version(struct tda1004x_state *state, 414static void tda10046_init_plls(struct dvb_frontend* fe)
385 const struct firmware *fw)
386{ 415{
387 const unsigned char pattern[] = { 0x67, 0x00, 0x50, 0x62, 0x5e, 0x18, 0x67 }; 416 struct tda1004x_state* state = fe->demodulator_priv;
388 unsigned int i;
389
390 /* area guessed from firmware v20, v21 and v25 */
391 for (i = 0x660; i < 0x700; i++) {
392 if (!memcmp(&fw->data[i], pattern, sizeof(pattern))) {
393 state->fw_version = fw->data[i + sizeof(pattern)];
394 printk(KERN_INFO "tda1004x: using firmware v%02x\n",
395 state->fw_version);
396 return 0;
397 }
398 }
399 417
400 return -EINVAL; 418 tda1004x_write_byteI(state, TDA10046H_CONFPLL1, 0xf0);
419 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10
420 if (state->config->xtal_freq == TDA10046_XTAL_4M ) {
421 dprintk("%s: setting up PLLs for a 4 MHz Xtal\n", __FUNCTION__);
422 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0
423 } else {
424 dprintk("%s: setting up PLLs for a 16 MHz Xtal\n", __FUNCTION__);
425 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 3); // PLL P = 0, N = 3
426 }
427 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99);
428 switch (state->config->if_freq) {
429 case TDA10046_FREQ_3617:
430 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
431 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c);
432 break;
433 case TDA10046_FREQ_3613:
434 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
435 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x13);
436 break;
437 case TDA10046_FREQ_045:
438 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0x0b);
439 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0xa3);
440 break;
441 case TDA10046_FREQ_052:
442 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0x0c);
443 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x06);
444 break;
445 }
446 tda10046h_set_bandwidth(state, BANDWIDTH_8_MHZ); // default bandwidth 8 MHz
401} 447}
402 448
403static int tda10046_fwupload(struct dvb_frontend* fe) 449static int tda10046_fwupload(struct dvb_frontend* fe)
404{ 450{
405 struct tda1004x_state* state = fe->demodulator_priv; 451 struct tda1004x_state* state = fe->demodulator_priv;
406 unsigned long timeout;
407 int ret; 452 int ret;
408 const struct firmware *fw; 453 const struct firmware *fw;
409 454
410 /* reset + wake up chip */ 455 /* reset + wake up chip */
411 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 0); 456 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0);
412 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0); 457 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
413 msleep(100); 458 /* let the clocks recover from sleep */
459 msleep(5);
414 460
415 /* don't re-upload unless necessary */ 461 /* don't re-upload unless necessary */
416 if (tda1004x_check_upload_ok(state, state->fw_version) == 0) 462 if (tda1004x_check_upload_ok(state) == 0)
417 return 0; 463 return 0;
418 464
419 /* request the firmware, this will block until someone uploads it */
420 printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE);
421 ret = state->config->request_firmware(fe, &fw, TDA10046_DEFAULT_FIRMWARE);
422 if (ret) {
423 printk("tda1004x: no firmware upload (timeout or file not found?)\n");
424 return ret;
425 }
426
427 if (fw->size < 24478) { /* size of firmware v20, which is the smallest of v20, v21 and v25 */
428 printk("tda1004x: firmware file seems to be too small (%d bytes)\n", fw->size);
429 return -EINVAL;
430 }
431
432 ret = tda10046_get_fw_version(state, fw);
433 if (ret < 0) {
434 printk("tda1004x: unable to find firmware version\n");
435 return ret;
436 }
437
438 /* set parameters */ 465 /* set parameters */
439 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); 466 tda10046_init_plls(fe);
440 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c); 467
441 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); 468 if (state->config->request_firmware != NULL) {
442 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); 469 /* request the firmware, this will block until someone uploads it */
443 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); 470 printk(KERN_INFO "tda1004x: waiting for firmware upload...\n");
444 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); // going to boot from HOST 471 ret = state->config->request_firmware(fe, &fw, TDA10046_DEFAULT_FIRMWARE);
445 472 if (ret) {
446 ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10046H_CODE_CPT, TDA10046H_CODE_IN); 473 printk(KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
447 if (ret) 474 return ret;
448 return ret;
449 printk("tda1004x: firmware upload complete\n");
450
451 /* wait for DSP to initialise */
452 timeout = jiffies + HZ;
453 while (!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) {
454 if (time_after(jiffies, timeout)) {
455 printk("tda1004x: DSP failed to initialised.\n");
456 return -EIO;
457 } 475 }
458 msleep(1); 476 tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); // going to boot from HOST
477 ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10046H_CODE_CPT, TDA10046H_CODE_IN);
478 release_firmware(fw);
479 if (ret)
480 return ret;
481 } else {
482 /* boot from firmware eeprom */
483 /* Hac Note: we might need to do some GPIO Magic here */
484 printk(KERN_INFO "tda1004x: booting from eeprom\n");
485 tda1004x_write_mask(state, TDA1004X_CONFC4, 4, 4);
486 msleep(300);
459 } 487 }
460 488 return tda1004x_check_upload_ok(state);
461 return tda1004x_check_upload_ok(state, state->fw_version);
462} 489}
463 490
464static int tda1004x_encode_fec(int fec) 491static int tda1004x_encode_fec(int fec)
@@ -560,12 +587,10 @@ static int tda10046_init(struct dvb_frontend* fe)
560 587
561 if (tda10046_fwupload(fe)) { 588 if (tda10046_fwupload(fe)) {
562 printk("tda1004x: firmware upload failed\n"); 589 printk("tda1004x: firmware upload failed\n");
563 return -EIO; 590 return -EIO;
564 } 591 }
565 592
566 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 0); // wake up the chip 593 // Init the tuner PLL
567
568 // Init the PLL
569 if (state->config->pll_init) { 594 if (state->config->pll_init) {
570 tda1004x_enable_tuner_i2c(state); 595 tda1004x_enable_tuner_i2c(state);
571 state->config->pll_init(fe); 596 state->config->pll_init(fe);
@@ -574,32 +599,44 @@ static int tda10046_init(struct dvb_frontend* fe)
574 599
575 // tda setup 600 // tda setup
576 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer 601 tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
577 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x40, 0x40); 602 tda1004x_write_byteI(state, TDA1004X_AUTO, 7); // select HP stream
578 tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream 603 tda1004x_write_byteI(state, TDA1004X_CONFC1, 8); // disable pulse killer
579 tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0); // disable pulse killer 604
580 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10 605 tda10046_init_plls(fe);
581 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c); // PLL P = N = 0 606 switch (state->config->agc_config) {
582 tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); // FREQOFFS = 99 607 case TDA10046_AGC_DEFAULT:
583 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); // } PHY2 = -11221 608 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x00); // AGC setup
584 tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); // } 609 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
585 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0); // AGC setup 610 break;
586 tda1004x_write_mask(state, TDA10046H_CONF_POLARITY, 0x60, 0x60); // set AGC polarities 611 case TDA10046_AGC_IFO_AUTO_NEG:
612 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x0a); // AGC setup
613 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
614 break;
615 case TDA10046_AGC_IFO_AUTO_POS:
616 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x0a); // AGC setup
617 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x00); // set AGC polarities
618 break;
619 case TDA10046_AGC_TDA827X:
620 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup
621 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold
622 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x0E); // Gain Renormalize
623 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
624 break;
625 }
626 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on
587 tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MIN, 0); // } 627 tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MIN, 0); // }
588 tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MAX, 0xff); // } AGC min/max values 628 tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MAX, 0xff); // } AGC min/max values
589 tda1004x_write_byteI(state, TDA10046H_AGC_IF_MIN, 0); // } 629 tda1004x_write_byteI(state, TDA10046H_AGC_IF_MIN, 0); // }
590 tda1004x_write_byteI(state, TDA10046H_AGC_IF_MAX, 0xff); // } 630 tda1004x_write_byteI(state, TDA10046H_AGC_IF_MAX, 0xff); // }
591 tda1004x_write_mask(state, TDA10046H_CVBER_CTRL, 0x30, 0x10); // 10^6 VBER measurement bits
592 tda1004x_write_byteI(state, TDA10046H_AGC_GAINS, 1); // IF gain 2, TUN gain 1 631 tda1004x_write_byteI(state, TDA10046H_AGC_GAINS, 1); // IF gain 2, TUN gain 1
593 tda1004x_write_mask(state, TDA1004X_AUTO, 0x80, 0); // crystal is 50ppm 632 tda1004x_write_byteI(state, TDA10046H_CVBER_CTRL, 0x1a); // 10^6 VBER measurement bits
594 tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config 633 tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config
595 tda1004x_write_mask(state, TDA1004X_CONF_TS2, 0x31, 0); // MPEG2 interface config 634 tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0xc0); // MPEG2 interface config
596 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 0x9e, 0); // disable AGC_TUN 635 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
636
597 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE2, 0xe1); // tristate setup 637 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE2, 0xe1); // tristate setup
598 tda1004x_write_byteI(state, TDA10046H_GPIO_OUT_SEL, 0xcc); // GPIO output config 638 tda1004x_write_byteI(state, TDA10046H_GPIO_OUT_SEL, 0xcc); // GPIO output config
599 tda1004x_write_mask(state, TDA10046H_GPIO_SELECT, 8, 8); // GPIO select 639 tda1004x_write_byteI(state, TDA10046H_GPIO_SELECT, 8); // GPIO select
600 tda10046h_set_bandwidth(state, BANDWIDTH_8_MHZ); // default bandwidth 8 MHz
601
602 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
603 640
604 state->initialised = 1; 641 state->initialised = 1;
605 return 0; 642 return 0;
@@ -629,9 +666,6 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
629 state->config->pll_set(fe, fe_params); 666 state->config->pll_set(fe, fe_params);
630 tda1004x_disable_tuner_i2c(state); 667 tda1004x_disable_tuner_i2c(state);
631 668
632 if (state->demod_type == TDA1004X_DEMOD_TDA10046)
633 tda1004x_write_mask(state, TDA10046H_AGC_CONF, 4, 4);
634
635 // Hardcoded to use auto as much as possible on the TDA10045 as it 669 // Hardcoded to use auto as much as possible on the TDA10045 as it
636 // is very unreliable if AUTO mode is _not_ used. 670 // is very unreliable if AUTO mode is _not_ used.
637 if (state->demod_type == TDA1004X_DEMOD_TDA10045) { 671 if (state->demod_type == TDA1004X_DEMOD_TDA10045) {
@@ -1089,6 +1123,11 @@ static int tda1004x_sleep(struct dvb_frontend* fe)
1089 break; 1123 break;
1090 1124
1091 case TDA1004X_DEMOD_TDA10046: 1125 case TDA1004X_DEMOD_TDA10046:
1126 if (state->config->pll_sleep != NULL) {
1127 tda1004x_enable_tuner_i2c(state);
1128 state->config->pll_sleep(fe);
1129 tda1004x_disable_tuner_i2c(state);
1130 }
1092 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1); 1131 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1);
1093 break; 1132 break;
1094 } 1133 }
@@ -1100,8 +1139,9 @@ static int tda1004x_sleep(struct dvb_frontend* fe)
1100static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) 1139static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
1101{ 1140{
1102 fesettings->min_delay_ms = 800; 1141 fesettings->min_delay_ms = 800;
1103 fesettings->step_size = 166667; 1142 /* Drift compensation makes no sense for DVB-T */
1104 fesettings->max_drift = 166667*2; 1143 fesettings->step_size = 0;
1144 fesettings->max_drift = 0;
1105 return 0; 1145 return 0;
1106} 1146}
1107 1147
@@ -1216,7 +1256,6 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
1216 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops)); 1256 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
1217 state->initialised = 0; 1257 state->initialised = 0;
1218 state->demod_type = TDA1004X_DEMOD_TDA10046; 1258 state->demod_type = TDA1004X_DEMOD_TDA10046;
1219 state->fw_version = 0x20; /* dummy default value */
1220 1259
1221 /* check if the demod is there */ 1260 /* check if the demod is there */
1222 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) { 1261 if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) {
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index c8e1d54ff262..8659c52647ad 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -26,6 +26,25 @@
26#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28 28
29enum tda10046_xtal {
30 TDA10046_XTAL_4M,
31 TDA10046_XTAL_16M,
32};
33
34enum tda10046_agc {
35 TDA10046_AGC_DEFAULT, /* original configuration */
36 TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negtive */
37 TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */
38 TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */
39};
40
41enum tda10046_if {
42 TDA10046_FREQ_3617, /* original config, 36,166 MHZ */
43 TDA10046_FREQ_3613, /* 36,13 MHZ */
44 TDA10046_FREQ_045, /* low IF, 4.0, 4.5, or 5.0 MHZ */
45 TDA10046_FREQ_052, /* low IF, 5.1667 MHZ for tda9889 */
46};
47
29struct tda1004x_config 48struct tda1004x_config
30{ 49{
31 /* the demodulator's i2c address */ 50 /* the demodulator's i2c address */
@@ -37,14 +56,22 @@ struct tda1004x_config
37 /* Does the OCLK signal need inverted? */ 56 /* Does the OCLK signal need inverted? */
38 u8 invert_oclk; 57 u8 invert_oclk;
39 58
40 /* value of N_I2C of the CONF_PLL3 register */ 59 /* Xtal frequency, 4 or 16MHz*/
41 u8 n_i2c; 60 enum tda10046_xtal xtal_freq;
61
62 /* IF frequency */
63 enum tda10046_if if_freq;
64
65 /* AGC configuration */
66 enum tda10046_agc agc_config;
42 67
43 /* PLL maintenance */ 68 /* PLL maintenance */
44 int (*pll_init)(struct dvb_frontend* fe); 69 int (*pll_init)(struct dvb_frontend* fe);
70 void (*pll_sleep)(struct dvb_frontend* fe);
45 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params); 71 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
46 72
47 /* request firmware for device */ 73 /* request firmware for device */
74 /* set this to NULL if the card has a firmware EEPROM */
48 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 75 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
49}; 76};
50 77
diff --git a/drivers/media/dvb/frontends/tda80xx.c b/drivers/media/dvb/frontends/tda80xx.c
index 032d348dafb7..88e125079ca1 100644
--- a/drivers/media/dvb/frontends/tda80xx.c
+++ b/drivers/media/dvb/frontends/tda80xx.c
@@ -27,7 +27,6 @@
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/threads.h> 28#include <linux/threads.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/irq.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
diff --git a/drivers/media/dvb/pluto2/Kconfig b/drivers/media/dvb/pluto2/Kconfig
new file mode 100644
index 000000000000..f02842be0d60
--- /dev/null
+++ b/drivers/media/dvb/pluto2/Kconfig
@@ -0,0 +1,16 @@
1config DVB_PLUTO2
2 tristate "Pluto2 cards"
3 depends on DVB_CORE && PCI
4 select I2C
5 select I2C_ALGOBIT
6 select DVB_TDA1004X
7 help
8 Support for PCI cards based on the Pluto2 FPGA like the Satelco
9 Easywatch Mobile Terrestrial DVB-T Receiver.
10
11 Since these cards have no MPEG decoder onboard, they transmit
12 only compressed MPEG data over the PCI bus, so you need
13 an external software decoder to watch TV on your computer.
14
15 Say Y or M if you own such a device and want to use it.
16
diff --git a/drivers/media/dvb/pluto2/Makefile b/drivers/media/dvb/pluto2/Makefile
new file mode 100644
index 000000000000..86ca84b2be6e
--- /dev/null
+++ b/drivers/media/dvb/pluto2/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_DVB_PLUTO2) = pluto2.o
2
3EXTRA_CFLAGS = -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
new file mode 100644
index 000000000000..706e0bcb5ede
--- /dev/null
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -0,0 +1,809 @@
1/*
2 * pluto2.c - Satelco Easywatch Mobile Terrestrial Receiver [DVB-T]
3 *
4 * Copyright (C) 2005 Andreas Oberritter <obi@linuxtv.org>
5 *
6 * based on pluto2.c 1.10 - http://instinct-wp8.no-ip.org/pluto/
7 * by Dany Salman <salmandany@yahoo.fr>
8 * Copyright (c) 2004 TDF
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/i2c.h>
27#include <linux/i2c-algo-bit.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/pci.h>
32#include <linux/dma-mapping.h>
33
34#include "demux.h"
35#include "dmxdev.h"
36#include "dvb_demux.h"
37#include "dvb_frontend.h"
38#include "dvb_net.h"
39#include "dvbdev.h"
40#include "tda1004x.h"
41
42#define DRIVER_NAME "pluto2"
43
44#define REG_PIDn(n) ((n) << 2) /* PID n pattern registers */
45#define REG_PCAR 0x0020 /* PC address register */
46#define REG_TSCR 0x0024 /* TS ctrl & status */
47#define REG_MISC 0x0028 /* miscellaneous */
48#define REG_MMAC 0x002c /* MSB MAC address */
49#define REG_IMAC 0x0030 /* ISB MAC address */
50#define REG_LMAC 0x0034 /* LSB MAC address */
51#define REG_SPID 0x0038 /* SPI data */
52#define REG_SLCS 0x003c /* serial links ctrl/status */
53
54#define PID0_NOFIL (0x0001 << 16)
55#define PIDn_ENP (0x0001 << 15)
56#define PID0_END (0x0001 << 14)
57#define PID0_AFIL (0x0001 << 13)
58#define PIDn_PID (0x1fff << 0)
59
60#define TSCR_NBPACKETS (0x00ff << 24)
61#define TSCR_DEM (0x0001 << 17)
62#define TSCR_DE (0x0001 << 16)
63#define TSCR_RSTN (0x0001 << 15)
64#define TSCR_MSKO (0x0001 << 14)
65#define TSCR_MSKA (0x0001 << 13)
66#define TSCR_MSKL (0x0001 << 12)
67#define TSCR_OVR (0x0001 << 11)
68#define TSCR_AFUL (0x0001 << 10)
69#define TSCR_LOCK (0x0001 << 9)
70#define TSCR_IACK (0x0001 << 8)
71#define TSCR_ADEF (0x007f << 0)
72
73#define MISC_DVR (0x0fff << 4)
74#define MISC_ALED (0x0001 << 3)
75#define MISC_FRST (0x0001 << 2)
76#define MISC_LED1 (0x0001 << 1)
77#define MISC_LED0 (0x0001 << 0)
78
79#define SPID_SPIDR (0x00ff << 0)
80
81#define SLCS_SCL (0x0001 << 7)
82#define SLCS_SDA (0x0001 << 6)
83#define SLCS_CSN (0x0001 << 2)
84#define SLCS_OVR (0x0001 << 1)
85#define SLCS_SWC (0x0001 << 0)
86
87#define TS_DMA_PACKETS (8)
88#define TS_DMA_BYTES (188 * TS_DMA_PACKETS)
89
90#define I2C_ADDR_TDA10046 0x10
91#define I2C_ADDR_TUA6034 0xc2
92#define NHWFILTERS 8
93
94struct pluto {
95 /* pci */
96 struct pci_dev *pdev;
97 u8 __iomem *io_mem;
98
99 /* dvb */
100 struct dmx_frontend hw_frontend;
101 struct dmx_frontend mem_frontend;
102 struct dmxdev dmxdev;
103 struct dvb_adapter dvb_adapter;
104 struct dvb_demux demux;
105 struct dvb_frontend *fe;
106 struct dvb_net dvbnet;
107 unsigned int full_ts_users;
108 unsigned int users;
109
110 /* i2c */
111 struct i2c_algo_bit_data i2c_bit;
112 struct i2c_adapter i2c_adap;
113 unsigned int i2cbug;
114
115 /* irq */
116 unsigned int overflow;
117
118 /* dma */
119 dma_addr_t dma_addr;
120 u8 dma_buf[TS_DMA_BYTES];
121 u8 dummy[4096];
122};
123
124static inline struct pluto *feed_to_pluto(struct dvb_demux_feed *feed)
125{
126 return container_of(feed->demux, struct pluto, demux);
127}
128
129static inline struct pluto *frontend_to_pluto(struct dvb_frontend *fe)
130{
131 return container_of(fe->dvb, struct pluto, dvb_adapter);
132}
133
134static inline u32 pluto_readreg(struct pluto *pluto, u32 reg)
135{
136 return readl(&pluto->io_mem[reg]);
137}
138
139static inline void pluto_writereg(struct pluto *pluto, u32 reg, u32 val)
140{
141 writel(val, &pluto->io_mem[reg]);
142}
143
144static inline void pluto_rw(struct pluto *pluto, u32 reg, u32 mask, u32 bits)
145{
146 u32 val = readl(&pluto->io_mem[reg]);
147 val &= ~mask;
148 val |= bits;
149 writel(val, &pluto->io_mem[reg]);
150}
151
152static void pluto_setsda(void *data, int state)
153{
154 struct pluto *pluto = data;
155
156 if (state)
157 pluto_rw(pluto, REG_SLCS, SLCS_SDA, SLCS_SDA);
158 else
159 pluto_rw(pluto, REG_SLCS, SLCS_SDA, 0);
160}
161
162static void pluto_setscl(void *data, int state)
163{
164 struct pluto *pluto = data;
165
166 if (state)
167 pluto_rw(pluto, REG_SLCS, SLCS_SCL, SLCS_SCL);
168 else
169 pluto_rw(pluto, REG_SLCS, SLCS_SCL, 0);
170
171 /* try to detect i2c_inb() to workaround hardware bug:
172 * reset SDA to high after SCL has been set to low */
173 if ((state) && (pluto->i2cbug == 0)) {
174 pluto->i2cbug = 1;
175 } else {
176 if ((!state) && (pluto->i2cbug == 1))
177 pluto_setsda(pluto, 1);
178 pluto->i2cbug = 0;
179 }
180}
181
182static int pluto_getsda(void *data)
183{
184 struct pluto *pluto = data;
185
186 return pluto_readreg(pluto, REG_SLCS) & SLCS_SDA;
187}
188
189static int pluto_getscl(void *data)
190{
191 struct pluto *pluto = data;
192
193 return pluto_readreg(pluto, REG_SLCS) & SLCS_SCL;
194}
195
196static void pluto_reset_frontend(struct pluto *pluto, int reenable)
197{
198 u32 val = pluto_readreg(pluto, REG_MISC);
199
200 if (val & MISC_FRST) {
201 val &= ~MISC_FRST;
202 pluto_writereg(pluto, REG_MISC, val);
203 }
204 if (reenable) {
205 val |= MISC_FRST;
206 pluto_writereg(pluto, REG_MISC, val);
207 }
208}
209
210static void pluto_reset_ts(struct pluto *pluto, int reenable)
211{
212 u32 val = pluto_readreg(pluto, REG_TSCR);
213
214 if (val & TSCR_RSTN) {
215 val &= ~TSCR_RSTN;
216 pluto_writereg(pluto, REG_TSCR, val);
217 }
218 if (reenable) {
219 val |= TSCR_RSTN;
220 pluto_writereg(pluto, REG_TSCR, val);
221 }
222}
223
224static void pluto_set_dma_addr(struct pluto *pluto)
225{
226 pluto_writereg(pluto, REG_PCAR, cpu_to_le32(pluto->dma_addr));
227}
228
229static int __devinit pluto_dma_map(struct pluto *pluto)
230{
231 pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf,
232 TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
233
234 return pci_dma_mapping_error(pluto->dma_addr);
235}
236
237static void pluto_dma_unmap(struct pluto *pluto)
238{
239 pci_unmap_single(pluto->pdev, pluto->dma_addr,
240 TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
241}
242
243static int pluto_start_feed(struct dvb_demux_feed *f)
244{
245 struct pluto *pluto = feed_to_pluto(f);
246
247 /* enable PID filtering */
248 if (pluto->users++ == 0)
249 pluto_rw(pluto, REG_PIDn(0), PID0_AFIL | PID0_NOFIL, 0);
250
251 if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
252 pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, PIDn_ENP | f->pid);
253 else if (pluto->full_ts_users++ == 0)
254 pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, PID0_NOFIL);
255
256 return 0;
257}
258
259static int pluto_stop_feed(struct dvb_demux_feed *f)
260{
261 struct pluto *pluto = feed_to_pluto(f);
262
263 /* disable PID filtering */
264 if (--pluto->users == 0)
265 pluto_rw(pluto, REG_PIDn(0), PID0_AFIL, PID0_AFIL);
266
267 if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
268 pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, 0x1fff);
269 else if (--pluto->full_ts_users == 0)
270 pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, 0);
271
272 return 0;
273}
274
275static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
276{
277 /* synchronize the DMA transfer with the CPU
278 * first so that we see updated contents. */
279 pci_dma_sync_single_for_cpu(pluto->pdev, pluto->dma_addr,
280 TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
281
282 /* Workaround for broken hardware:
283 * [1] On startup NBPACKETS seems to contain an uninitialized value,
284 * but no packets have been transfered.
285 * [2] Sometimes (actually very often) NBPACKETS stays at zero
286 * although one packet has been transfered.
287 */
288 if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) {
289 unsigned int i = 0, valid;
290 while (pluto->dma_buf[i] == 0x47)
291 i += 188;
292 valid = i / 188;
293 if (nbpackets != valid) {
294 dev_err(&pluto->pdev->dev, "nbpackets=%u valid=%u\n",
295 nbpackets, valid);
296 nbpackets = valid;
297 }
298 }
299
300 dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets);
301
302 /* clear the dma buffer. this is needed to be able to identify
303 * new valid ts packets above */
304 memset(pluto->dma_buf, 0, nbpackets * 188);
305
306 /* reset the dma address */
307 pluto_set_dma_addr(pluto);
308
309 /* sync the buffer and give it back to the card */
310 pci_dma_sync_single_for_device(pluto->pdev, pluto->dma_addr,
311 TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
312}
313
314static irqreturn_t pluto_irq(int irq, void *dev_id, struct pt_regs *regs)
315{
316 struct pluto *pluto = dev_id;
317 u32 tscr;
318
319 /* check whether an interrupt occured on this device */
320 tscr = pluto_readreg(pluto, REG_TSCR);
321 if (!(tscr & (TSCR_DE | TSCR_OVR)))
322 return IRQ_NONE;
323
324 if (tscr == 0xffffffff) {
325 // FIXME: maybe recover somehow
326 dev_err(&pluto->pdev->dev, "card hung up :(\n");
327 return IRQ_HANDLED;
328 }
329
330 /* dma end interrupt */
331 if (tscr & TSCR_DE) {
332 pluto_dma_end(pluto, (tscr & TSCR_NBPACKETS) >> 24);
333 /* overflow interrupt */
334 if (tscr & TSCR_OVR)
335 pluto->overflow++;
336 if (pluto->overflow) {
337 dev_err(&pluto->pdev->dev, "overflow irq (%d)\n",
338 pluto->overflow);
339 pluto_reset_ts(pluto, 1);
340 pluto->overflow = 0;
341 }
342 } else if (tscr & TSCR_OVR) {
343 pluto->overflow++;
344 }
345
346 /* ACK the interrupt */
347 pluto_writereg(pluto, REG_TSCR, tscr | TSCR_IACK);
348
349 return IRQ_HANDLED;
350}
351
352static void __devinit pluto_enable_irqs(struct pluto *pluto)
353{
354 u32 val = pluto_readreg(pluto, REG_TSCR);
355
356 /* set the number of packets */
357 val &= ~TSCR_ADEF;
358 val |= TS_DMA_PACKETS / 2;
359 /* disable AFUL and LOCK interrupts */
360 val |= (TSCR_MSKA | TSCR_MSKL);
361 /* enable DMA and OVERFLOW interrupts */
362 val &= ~(TSCR_DEM | TSCR_MSKO);
363 /* clear pending interrupts */
364 val |= TSCR_IACK;
365
366 pluto_writereg(pluto, REG_TSCR, val);
367}
368
369static void pluto_disable_irqs(struct pluto *pluto)
370{
371 u32 val = pluto_readreg(pluto, REG_TSCR);
372
373 /* disable all interrupts */
374 val |= (TSCR_DEM | TSCR_MSKO | TSCR_MSKA | TSCR_MSKL);
375 /* clear pending interrupts */
376 val |= TSCR_IACK;
377
378 pluto_writereg(pluto, REG_TSCR, val);
379}
380
381static int __devinit pluto_hw_init(struct pluto *pluto)
382{
383 pluto_reset_frontend(pluto, 1);
384
385 /* set automatic LED control by FPGA */
386 pluto_rw(pluto, REG_MISC, MISC_ALED, MISC_ALED);
387
388 /* set data endianess */
389#ifdef __LITTLE_ENDIAN
390 pluto_rw(pluto, REG_PIDn(0), PID0_END, PID0_END);
391#else
392 pluto_rw(pluto, REG_PIDn(0), PID0_END, 0);
393#endif
394 /* map DMA and set address */
395 pluto_dma_map(pluto);
396 pluto_set_dma_addr(pluto);
397
398 /* enable interrupts */
399 pluto_enable_irqs(pluto);
400
401 /* reset TS logic */
402 pluto_reset_ts(pluto, 1);
403
404 return 0;
405}
406
407static void pluto_hw_exit(struct pluto *pluto)
408{
409 /* disable interrupts */
410 pluto_disable_irqs(pluto);
411
412 pluto_reset_ts(pluto, 0);
413
414 /* LED: disable automatic control, enable yellow, disable green */
415 pluto_rw(pluto, REG_MISC, MISC_ALED | MISC_LED1 | MISC_LED0, MISC_LED1);
416
417 /* unmap DMA */
418 pluto_dma_unmap(pluto);
419
420 pluto_reset_frontend(pluto, 0);
421}
422
423static inline u32 divide(u32 numerator, u32 denominator)
424{
425 if (denominator == 0)
426 return ~0;
427
428 return (numerator + denominator / 2) / denominator;
429}
430
431/* LG Innotek TDTE-E001P (Infineon TUA6034) */
432static int lg_tdtpe001p_pll_set(struct dvb_frontend *fe,
433 struct dvb_frontend_parameters *p)
434{
435 struct pluto *pluto = frontend_to_pluto(fe);
436 struct i2c_msg msg;
437 int ret;
438 u8 buf[4];
439 u32 div;
440
441 // Fref = 166.667 Hz
442 // Fref * 3 = 500.000 Hz
443 // IF = 36166667
444 // IF / Fref = 217
445 //div = divide(p->frequency + 36166667, 166667);
446 div = divide(p->frequency * 3, 500000) + 217;
447 buf[0] = (div >> 8) & 0x7f;
448 buf[1] = (div >> 0) & 0xff;
449
450 if (p->frequency < 611000000)
451 buf[2] = 0xb4;
452 else if (p->frequency < 811000000)
453 buf[2] = 0xbc;
454 else
455 buf[2] = 0xf4;
456
457 // VHF: 174-230 MHz
458 // center: 350 MHz
459 // UHF: 470-862 MHz
460 if (p->frequency < 350000000)
461 buf[3] = 0x02;
462 else
463 buf[3] = 0x04;
464
465 if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
466 buf[3] |= 0x08;
467
468 if (sizeof(buf) == 6) {
469 buf[4] = buf[2];
470 buf[4] &= ~0x1c;
471 buf[4] |= 0x18;
472
473 buf[5] = (0 << 7) | (2 << 4);
474 }
475
476 msg.addr = I2C_ADDR_TUA6034 >> 1;
477 msg.flags = 0;
478 msg.buf = buf;
479 msg.len = sizeof(buf);
480
481 ret = i2c_transfer(&pluto->i2c_adap, &msg, 1);
482 if (ret < 0)
483 return ret;
484 else if (ret == 0)
485 return -EREMOTEIO;
486
487 return 0;
488}
489
490static int pluto2_request_firmware(struct dvb_frontend *fe,
491 const struct firmware **fw, char *name)
492{
493 struct pluto *pluto = frontend_to_pluto(fe);
494
495 return request_firmware(fw, name, &pluto->pdev->dev);
496}
497
498static struct tda1004x_config pluto2_fe_config __devinitdata = {
499 .demod_address = I2C_ADDR_TDA10046 >> 1,
500 .invert = 1,
501 .invert_oclk = 0,
502 .xtal_freq = TDA10046_XTAL_16M,
503 .agc_config = TDA10046_AGC_DEFAULT,
504 .if_freq = TDA10046_FREQ_3617,
505 .pll_set = lg_tdtpe001p_pll_set,
506 .pll_sleep = NULL,
507 .request_firmware = pluto2_request_firmware,
508};
509
510static int __devinit frontend_init(struct pluto *pluto)
511{
512 int ret;
513
514 pluto->fe = tda10046_attach(&pluto2_fe_config, &pluto->i2c_adap);
515 if (!pluto->fe) {
516 dev_err(&pluto->pdev->dev, "could not attach frontend\n");
517 return -ENODEV;
518 }
519
520 ret = dvb_register_frontend(&pluto->dvb_adapter, pluto->fe);
521 if (ret < 0) {
522 if (pluto->fe->ops->release)
523 pluto->fe->ops->release(pluto->fe);
524 return ret;
525 }
526
527 return 0;
528}
529
530static void __devinit pluto_read_rev(struct pluto *pluto)
531{
532 u32 val = pluto_readreg(pluto, REG_MISC) & MISC_DVR;
533 dev_info(&pluto->pdev->dev, "board revision %d.%d\n",
534 (val >> 12) & 0x0f, (val >> 4) & 0xff);
535}
536
537static void __devinit pluto_read_mac(struct pluto *pluto, u8 *mac)
538{
539 u32 val = pluto_readreg(pluto, REG_MMAC);
540 mac[0] = (val >> 8) & 0xff;
541 mac[1] = (val >> 0) & 0xff;
542
543 val = pluto_readreg(pluto, REG_IMAC);
544 mac[2] = (val >> 8) & 0xff;
545 mac[3] = (val >> 0) & 0xff;
546
547 val = pluto_readreg(pluto, REG_LMAC);
548 mac[4] = (val >> 8) & 0xff;
549 mac[5] = (val >> 0) & 0xff;
550
551 dev_info(&pluto->pdev->dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
552 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
553}
554
555static int __devinit pluto_read_serial(struct pluto *pluto)
556{
557 struct pci_dev *pdev = pluto->pdev;
558 unsigned int i, j;
559 u8 __iomem *cis;
560
561 cis = pci_iomap(pdev, 1, 0);
562 if (!cis)
563 return -EIO;
564
565 dev_info(&pdev->dev, "S/N ");
566
567 for (i = 0xe0; i < 0x100; i += 4) {
568 u32 val = readl(&cis[i]);
569 for (j = 0; j < 32; j += 8) {
570 if ((val & 0xff) == 0xff)
571 goto out;
572 printk("%c", val & 0xff);
573 val >>= 8;
574 }
575 }
576out:
577 printk("\n");
578 pci_iounmap(pdev, cis);
579
580 return 0;
581}
582
583static int __devinit pluto2_probe(struct pci_dev *pdev,
584 const struct pci_device_id *ent)
585{
586 struct pluto *pluto;
587 struct dvb_adapter *dvb_adapter;
588 struct dvb_demux *dvbdemux;
589 struct dmx_demux *dmx;
590 int ret = -ENOMEM;
591
592 pluto = kmalloc(sizeof(struct pluto), GFP_KERNEL);
593 if (!pluto)
594 goto out;
595
596 memset(pluto, 0, sizeof(struct pluto));
597 pluto->pdev = pdev;
598
599 ret = pci_enable_device(pdev);
600 if (ret < 0)
601 goto err_kfree;
602
603 /* enable interrupts */
604 pci_write_config_dword(pdev, 0x6c, 0x8000);
605
606 ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
607 if (ret < 0)
608 goto err_pci_disable_device;
609
610 pci_set_master(pdev);
611
612 ret = pci_request_regions(pdev, DRIVER_NAME);
613 if (ret < 0)
614 goto err_pci_disable_device;
615
616 pluto->io_mem = pci_iomap(pdev, 0, 0x40);
617 if (!pluto->io_mem) {
618 ret = -EIO;
619 goto err_pci_release_regions;
620 }
621
622 pci_set_drvdata(pdev, pluto);
623
624 ret = request_irq(pdev->irq, pluto_irq, SA_SHIRQ, DRIVER_NAME, pluto);
625 if (ret < 0)
626 goto err_pci_iounmap;
627
628 ret = pluto_hw_init(pluto);
629 if (ret < 0)
630 goto err_free_irq;
631
632 /* i2c */
633 i2c_set_adapdata(&pluto->i2c_adap, pluto);
634 strcpy(pluto->i2c_adap.name, DRIVER_NAME);
635 pluto->i2c_adap.owner = THIS_MODULE;
636 pluto->i2c_adap.id = I2C_ALGO_BIT;
637 pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
638 pluto->i2c_adap.dev.parent = &pdev->dev;
639 pluto->i2c_adap.algo_data = &pluto->i2c_bit;
640 pluto->i2c_bit.data = pluto;
641 pluto->i2c_bit.setsda = pluto_setsda;
642 pluto->i2c_bit.setscl = pluto_setscl;
643 pluto->i2c_bit.getsda = pluto_getsda;
644 pluto->i2c_bit.getscl = pluto_getscl;
645 pluto->i2c_bit.udelay = 10;
646 pluto->i2c_bit.timeout = 10;
647
648 /* Raise SCL and SDA */
649 pluto_setsda(pluto, 1);
650 pluto_setscl(pluto, 1);
651
652 ret = i2c_bit_add_bus(&pluto->i2c_adap);
653 if (ret < 0)
654 goto err_pluto_hw_exit;
655
656 /* dvb */
657 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME, THIS_MODULE);
658 if (ret < 0)
659 goto err_i2c_bit_del_bus;
660
661 dvb_adapter = &pluto->dvb_adapter;
662
663 pluto_read_rev(pluto);
664 pluto_read_serial(pluto);
665 pluto_read_mac(pluto, dvb_adapter->proposed_mac);
666
667 dvbdemux = &pluto->demux;
668 dvbdemux->filternum = 256;
669 dvbdemux->feednum = 256;
670 dvbdemux->start_feed = pluto_start_feed;
671 dvbdemux->stop_feed = pluto_stop_feed;
672 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
673 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
674 ret = dvb_dmx_init(dvbdemux);
675 if (ret < 0)
676 goto err_dvb_unregister_adapter;
677
678 dmx = &dvbdemux->dmx;
679
680 pluto->hw_frontend.source = DMX_FRONTEND_0;
681 pluto->mem_frontend.source = DMX_MEMORY_FE;
682 pluto->dmxdev.filternum = NHWFILTERS;
683 pluto->dmxdev.demux = dmx;
684
685 ret = dvb_dmxdev_init(&pluto->dmxdev, dvb_adapter);
686 if (ret < 0)
687 goto err_dvb_dmx_release;
688
689 ret = dmx->add_frontend(dmx, &pluto->hw_frontend);
690 if (ret < 0)
691 goto err_dvb_dmxdev_release;
692
693 ret = dmx->add_frontend(dmx, &pluto->mem_frontend);
694 if (ret < 0)
695 goto err_remove_hw_frontend;
696
697 ret = dmx->connect_frontend(dmx, &pluto->hw_frontend);
698 if (ret < 0)
699 goto err_remove_mem_frontend;
700
701 ret = frontend_init(pluto);
702 if (ret < 0)
703 goto err_disconnect_frontend;
704
705 dvb_net_init(dvb_adapter, &pluto->dvbnet, dmx);
706out:
707 return ret;
708
709err_disconnect_frontend:
710 dmx->disconnect_frontend(dmx);
711err_remove_mem_frontend:
712 dmx->remove_frontend(dmx, &pluto->mem_frontend);
713err_remove_hw_frontend:
714 dmx->remove_frontend(dmx, &pluto->hw_frontend);
715err_dvb_dmxdev_release:
716 dvb_dmxdev_release(&pluto->dmxdev);
717err_dvb_dmx_release:
718 dvb_dmx_release(dvbdemux);
719err_dvb_unregister_adapter:
720 dvb_unregister_adapter(dvb_adapter);
721err_i2c_bit_del_bus:
722 i2c_bit_del_bus(&pluto->i2c_adap);
723err_pluto_hw_exit:
724 pluto_hw_exit(pluto);
725err_free_irq:
726 free_irq(pdev->irq, pluto);
727err_pci_iounmap:
728 pci_iounmap(pdev, pluto->io_mem);
729err_pci_release_regions:
730 pci_release_regions(pdev);
731err_pci_disable_device:
732 pci_disable_device(pdev);
733err_kfree:
734 pci_set_drvdata(pdev, NULL);
735 kfree(pluto);
736 goto out;
737}
738
739static void __devexit pluto2_remove(struct pci_dev *pdev)
740{
741 struct pluto *pluto = pci_get_drvdata(pdev);
742 struct dvb_adapter *dvb_adapter = &pluto->dvb_adapter;
743 struct dvb_demux *dvbdemux = &pluto->demux;
744 struct dmx_demux *dmx = &dvbdemux->dmx;
745
746 dmx->close(dmx);
747 dvb_net_release(&pluto->dvbnet);
748 if (pluto->fe)
749 dvb_unregister_frontend(pluto->fe);
750
751 dmx->disconnect_frontend(dmx);
752 dmx->remove_frontend(dmx, &pluto->mem_frontend);
753 dmx->remove_frontend(dmx, &pluto->hw_frontend);
754 dvb_dmxdev_release(&pluto->dmxdev);
755 dvb_dmx_release(dvbdemux);
756 dvb_unregister_adapter(dvb_adapter);
757 i2c_bit_del_bus(&pluto->i2c_adap);
758 pluto_hw_exit(pluto);
759 free_irq(pdev->irq, pluto);
760 pci_iounmap(pdev, pluto->io_mem);
761 pci_release_regions(pdev);
762 pci_disable_device(pdev);
763 pci_set_drvdata(pdev, NULL);
764 kfree(pluto);
765}
766
767#ifndef PCI_VENDOR_ID_SCM
768#define PCI_VENDOR_ID_SCM 0x0432
769#endif
770#ifndef PCI_DEVICE_ID_PLUTO2
771#define PCI_DEVICE_ID_PLUTO2 0x0001
772#endif
773
774static struct pci_device_id pluto2_id_table[] __devinitdata = {
775 {
776 .vendor = PCI_VENDOR_ID_SCM,
777 .device = PCI_DEVICE_ID_PLUTO2,
778 .subvendor = PCI_ANY_ID,
779 .subdevice = PCI_ANY_ID,
780 }, {
781 /* empty */
782 },
783};
784
785MODULE_DEVICE_TABLE(pci, pluto2_id_table);
786
787static struct pci_driver pluto2_driver = {
788 .name = DRIVER_NAME,
789 .id_table = pluto2_id_table,
790 .probe = pluto2_probe,
791 .remove = __devexit_p(pluto2_remove),
792};
793
794static int __init pluto2_init(void)
795{
796 return pci_register_driver(&pluto2_driver);
797}
798
799static void __exit pluto2_exit(void)
800{
801 pci_unregister_driver(&pluto2_driver);
802}
803
804module_init(pluto2_init);
805module_exit(pluto2_exit);
806
807MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
808MODULE_DESCRIPTION("Pluto2 driver");
809MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 7ffa2c7315b3..bf3c011d2cfb 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -12,7 +12,7 @@ config DVB_AV7110
12 select DVB_STV0297 12 select DVB_STV0297
13 select DVB_L64781 13 select DVB_L64781
14 help 14 help
15 Support for SAA7146 and AV7110 based DVB cards as produced 15 Support for SAA7146 and AV7110 based DVB cards as produced
16 by Fujitsu-Siemens, Technotrend, Hauppauge and others. 16 by Fujitsu-Siemens, Technotrend, Hauppauge and others.
17 17
18 This driver only supports the fullfeatured cards with 18 This driver only supports the fullfeatured cards with
@@ -33,7 +33,7 @@ config DVB_AV7110_FIRMWARE
33 If you want to compile the firmware into the driver you need to say 33 If you want to compile the firmware into the driver you need to say
34 Y here and provide the correct path of the firmware. You need this 34 Y here and provide the correct path of the firmware. You need this
35 option if you want to compile the whole driver statically into the 35 option if you want to compile the whole driver statically into the
36 kernel. 36 kernel.
37 37
38 All other people say N. 38 All other people say N.
39 39
@@ -66,6 +66,7 @@ config DVB_BUDGET
66 select DVB_L64781 66 select DVB_L64781
67 select DVB_TDA8083 67 select DVB_TDA8083
68 select DVB_TDA10021 68 select DVB_TDA10021
69 select DVB_S5H1420
69 help 70 help
70 Support for simple SAA7146 based DVB cards 71 Support for simple SAA7146 based DVB cards
71 (so called Budget- or Nova-PCI cards) without onboard 72 (so called Budget- or Nova-PCI cards) without onboard
@@ -119,9 +120,9 @@ config DVB_BUDGET_PATCH
119 select DVB_VES1X93 120 select DVB_VES1X93
120 select DVB_TDA8083 121 select DVB_TDA8083
121 help 122 help
122 Support for Budget Patch (full TS) modification on 123 Support for Budget Patch (full TS) modification on
123 SAA7146+AV7110 based cards (DVB-S cards). This 124 SAA7146+AV7110 based cards (DVB-S cards). This
124 driver doesn't use onboard MPEG2 decoder. The 125 driver doesn't use onboard MPEG2 decoder. The
125 card is driven in Budget-only mode. Card is 126 card is driven in Budget-only mode. Card is
126 required to have loaded firmware to tune properly. 127 required to have loaded firmware to tune properly.
127 Firmware can be loaded by insertion and removal of 128 Firmware can be loaded by insertion and removal of
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 8e33a850e13e..e4c6e87f6c5d 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -116,13 +116,18 @@ static int av7110_num = 0;
116 116
117static void init_av7110_av(struct av7110 *av7110) 117static void init_av7110_av(struct av7110 *av7110)
118{ 118{
119 int ret;
119 struct saa7146_dev *dev = av7110->dev; 120 struct saa7146_dev *dev = av7110->dev;
120 121
121 /* set internal volume control to maximum */ 122 /* set internal volume control to maximum */
122 av7110->adac_type = DVB_ADAC_TI; 123 av7110->adac_type = DVB_ADAC_TI;
123 av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right); 124 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right);
125 if (ret < 0)
126 printk("dvb-ttpci:cannot set internal volume to maximum:%d\n",ret);
124 127
125 av7710_set_video_mode(av7110, vidmode); 128 ret = av7710_set_video_mode(av7110, vidmode);
129 if (ret < 0)
130 printk("dvb-ttpci:cannot set video mode:%d\n",ret);
126 131
127 /* handle different card types */ 132 /* handle different card types */
128 /* remaining inits according to card and frontend type */ 133 /* remaining inits according to card and frontend type */
@@ -156,8 +161,12 @@ static void init_av7110_av(struct av7110 *av7110)
156 161
157 if (av7110->adac_type == DVB_ADAC_NONE || av7110->adac_type == DVB_ADAC_MSP) { 162 if (av7110->adac_type == DVB_ADAC_NONE || av7110->adac_type == DVB_ADAC_MSP) {
158 // switch DVB SCART on 163 // switch DVB SCART on
159 av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, MainSwitch, 1, 0); 164 ret = av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, MainSwitch, 1, 0);
160 av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, 1); 165 if (ret < 0)
166 printk("dvb-ttpci:cannot switch on SCART(Main):%d\n",ret);
167 ret = av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, 1);
168 if (ret < 0)
169 printk("dvb-ttpci:cannot switch on SCART(AD):%d\n",ret);
161 if (rgb_on && 170 if (rgb_on &&
162 (av7110->dev->pci->subsystem_vendor == 0x110a) && (av7110->dev->pci->subsystem_device == 0x0000)) { 171 (av7110->dev->pci->subsystem_vendor == 0x110a) && (av7110->dev->pci->subsystem_device == 0x0000)) {
163 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // RGB on, SCART pin 16 172 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // RGB on, SCART pin 16
@@ -165,8 +174,12 @@ static void init_av7110_av(struct av7110 *av7110)
165 } 174 }
166 } 175 }
167 176
168 av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right); 177 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right);
169 av7110_setup_irc_config(av7110, 0); 178 if (ret < 0)
179 printk("dvb-ttpci:cannot set volume :%d\n",ret);
180 ret = av7110_setup_irc_config(av7110, 0);
181 if (ret < 0)
182 printk("dvb-ttpci:cannot setup irc config :%d\n",ret);
170} 183}
171 184
172static void recover_arm(struct av7110 *av7110) 185static void recover_arm(struct av7110 *av7110)
@@ -258,8 +271,9 @@ static int arm_thread(void *data)
258 * 271 *
259 * If we want to support multiple controls we would have to do much more... 272 * If we want to support multiple controls we would have to do much more...
260 */ 273 */
261void av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config) 274int av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config)
262{ 275{
276 int ret = 0;
263 static struct av7110 *last; 277 static struct av7110 *last;
264 278
265 dprintk(4, "%p\n", av7110); 279 dprintk(4, "%p\n", av7110);
@@ -270,9 +284,10 @@ void av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config)
270 last = av7110; 284 last = av7110;
271 285
272 if (av7110) { 286 if (av7110) {
273 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config); 287 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config);
274 av7110->ir_config = ir_config; 288 av7110->ir_config = ir_config;
275 } 289 }
290 return ret;
276} 291}
277 292
278static void (*irc_handler)(u32); 293static void (*irc_handler)(u32);
@@ -765,13 +780,14 @@ static inline int SetPIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
765 pcrpid, vpid, apid, ttpid, subpid); 780 pcrpid, vpid, apid, ttpid, subpid);
766} 781}
767 782
768void ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, 783int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
769 u16 subpid, u16 pcrpid) 784 u16 subpid, u16 pcrpid)
770{ 785{
786 int ret = 0;
771 dprintk(4, "%p\n", av7110); 787 dprintk(4, "%p\n", av7110);
772 788
773 if (down_interruptible(&av7110->pid_mutex)) 789 if (down_interruptible(&av7110->pid_mutex))
774 return; 790 return -ERESTARTSYS;
775 791
776 if (!(vpid & 0x8000)) 792 if (!(vpid & 0x8000))
777 av7110->pids[DMX_PES_VIDEO] = vpid; 793 av7110->pids[DMX_PES_VIDEO] = vpid;
@@ -786,10 +802,11 @@ void ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
786 802
787 if (av7110->fe_synced) { 803 if (av7110->fe_synced) {
788 pcrpid = av7110->pids[DMX_PES_PCR]; 804 pcrpid = av7110->pids[DMX_PES_PCR];
789 SetPIDs(av7110, vpid, apid, ttpid, subpid, pcrpid); 805 ret = SetPIDs(av7110, vpid, apid, ttpid, subpid, pcrpid);
790 } 806 }
791 807
792 up(&av7110->pid_mutex); 808 up(&av7110->pid_mutex);
809 return ret;
793} 810}
794 811
795 812
@@ -832,11 +849,13 @@ static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
832 ret = av7110_fw_request(av7110, buf, 20, &handle, 1); 849 ret = av7110_fw_request(av7110, buf, 20, &handle, 1);
833 if (ret != 0 || handle >= 32) { 850 if (ret != 0 || handle >= 32) {
834 printk("dvb-ttpci: %s error buf %04x %04x %04x %04x " 851 printk("dvb-ttpci: %s error buf %04x %04x %04x %04x "
835 "ret %x handle %04x\n", 852 "ret %d handle %04x\n",
836 __FUNCTION__, buf[0], buf[1], buf[2], buf[3], 853 __FUNCTION__, buf[0], buf[1], buf[2], buf[3],
837 ret, handle); 854 ret, handle);
838 dvbdmxfilter->hw_handle = 0xffff; 855 dvbdmxfilter->hw_handle = 0xffff;
839 return -1; 856 if (!ret)
857 ret = -1;
858 return ret;
840 } 859 }
841 860
842 av7110->handle2filter[handle] = dvbdmxfilter; 861 av7110->handle2filter[handle] = dvbdmxfilter;
@@ -859,7 +878,7 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
859 if (handle >= 32) { 878 if (handle >= 32) {
860 printk("%s tried to stop invalid filter %04x, filter type = %x\n", 879 printk("%s tried to stop invalid filter %04x, filter type = %x\n",
861 __FUNCTION__, handle, dvbdmxfilter->type); 880 __FUNCTION__, handle, dvbdmxfilter->type);
862 return 0; 881 return -EINVAL;
863 } 882 }
864 883
865 av7110->handle2filter[handle] = NULL; 884 av7110->handle2filter[handle] = NULL;
@@ -873,18 +892,20 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
873 "resp %04x %04x pid %d\n", 892 "resp %04x %04x pid %d\n",
874 __FUNCTION__, buf[0], buf[1], buf[2], ret, 893 __FUNCTION__, buf[0], buf[1], buf[2], ret,
875 answ[0], answ[1], dvbdmxfilter->feed->pid); 894 answ[0], answ[1], dvbdmxfilter->feed->pid);
876 ret = -1; 895 if (!ret)
896 ret = -1;
877 } 897 }
878 return ret; 898 return ret;
879} 899}
880 900
881 901
882static void dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed) 902static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
883{ 903{
884 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 904 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
885 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv; 905 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv;
886 u16 *pid = dvbdmx->pids, npids[5]; 906 u16 *pid = dvbdmx->pids, npids[5];
887 int i; 907 int i;
908 int ret = 0;
888 909
889 dprintk(4, "%p\n", av7110); 910 dprintk(4, "%p\n", av7110);
890 911
@@ -893,36 +914,49 @@ static void dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
893 npids[i] = (pid[i]&0x8000) ? 0 : pid[i]; 914 npids[i] = (pid[i]&0x8000) ? 0 : pid[i];
894 if ((i == 2) && npids[i] && (dvbdmxfeed->ts_type & TS_PACKET)) { 915 if ((i == 2) && npids[i] && (dvbdmxfeed->ts_type & TS_PACKET)) {
895 npids[i] = 0; 916 npids[i] = 0;
896 ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]); 917 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
897 StartHWFilter(dvbdmxfeed->filter); 918 if (!ret)
898 return; 919 ret = StartHWFilter(dvbdmxfeed->filter);
920 return ret;
921 }
922 if (dvbdmxfeed->pes_type <= 2 || dvbdmxfeed->pes_type == 4) {
923 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
924 if (ret)
925 return ret;
899 } 926 }
900 if (dvbdmxfeed->pes_type <= 2 || dvbdmxfeed->pes_type == 4)
901 ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
902 927
903 if (dvbdmxfeed->pes_type < 2 && npids[0]) 928 if (dvbdmxfeed->pes_type < 2 && npids[0])
904 if (av7110->fe_synced) 929 if (av7110->fe_synced)
905 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0); 930 {
931 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
932 if (ret)
933 return ret;
934 }
906 935
907 if ((dvbdmxfeed->ts_type & TS_PACKET)) { 936 if ((dvbdmxfeed->ts_type & TS_PACKET)) {
908 if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000)) 937 if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000))
909 av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed); 938 ret = av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed);
910 if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000)) 939 if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000))
911 av7110_av_start_record(av7110, RP_VIDEO, dvbdmxfeed); 940 ret = av7110_av_start_record(av7110, RP_VIDEO, dvbdmxfeed);
912 } 941 }
942 return ret;
913} 943}
914 944
915static void dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed) 945static int dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed)
916{ 946{
917 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 947 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
918 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv; 948 struct av7110 *av7110 = (struct av7110 *) dvbdmx->priv;
919 u16 *pid = dvbdmx->pids, npids[5]; 949 u16 *pid = dvbdmx->pids, npids[5];
920 int i; 950 int i;
921 951
952 int ret = 0;
953
922 dprintk(4, "%p\n", av7110); 954 dprintk(4, "%p\n", av7110);
923 955
924 if (dvbdmxfeed->pes_type <= 1) { 956 if (dvbdmxfeed->pes_type <= 1) {
925 av7110_av_stop(av7110, dvbdmxfeed->pes_type ? RP_VIDEO : RP_AUDIO); 957 ret = av7110_av_stop(av7110, dvbdmxfeed->pes_type ? RP_VIDEO : RP_AUDIO);
958 if (ret)
959 return ret;
926 if (!av7110->rec_mode) 960 if (!av7110->rec_mode)
927 dvbdmx->recording = 0; 961 dvbdmx->recording = 0;
928 if (!av7110->playing) 962 if (!av7110->playing)
@@ -933,24 +967,27 @@ static void dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed)
933 switch (i) { 967 switch (i) {
934 case 2: //teletext 968 case 2: //teletext
935 if (dvbdmxfeed->ts_type & TS_PACKET) 969 if (dvbdmxfeed->ts_type & TS_PACKET)
936 StopHWFilter(dvbdmxfeed->filter); 970 ret = StopHWFilter(dvbdmxfeed->filter);
937 npids[2] = 0; 971 npids[2] = 0;
938 break; 972 break;
939 case 0: 973 case 0:
940 case 1: 974 case 1:
941 case 4: 975 case 4:
942 if (!pids_off) 976 if (!pids_off)
943 return; 977 return 0;
944 npids[i] = (pid[i]&0x8000) ? 0 : pid[i]; 978 npids[i] = (pid[i]&0x8000) ? 0 : pid[i];
945 break; 979 break;
946 } 980 }
947 ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]); 981 if (!ret)
982 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
983 return ret;
948} 984}
949 985
950static int av7110_start_feed(struct dvb_demux_feed *feed) 986static int av7110_start_feed(struct dvb_demux_feed *feed)
951{ 987{
952 struct dvb_demux *demux = feed->demux; 988 struct dvb_demux *demux = feed->demux;
953 struct av7110 *av7110 = demux->priv; 989 struct av7110 *av7110 = demux->priv;
990 int ret = 0;
954 991
955 dprintk(4, "%p\n", av7110); 992 dprintk(4, "%p\n", av7110);
956 993
@@ -971,21 +1008,22 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
971 !(demux->pids[1] & 0x8000)) { 1008 !(demux->pids[1] & 0x8000)) {
972 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout); 1009 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
973 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout); 1010 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
974 av7110_av_start_play(av7110,RP_AV); 1011 ret = av7110_av_start_play(av7110,RP_AV);
975 demux->playing = 1; 1012 if (!ret)
1013 demux->playing = 1;
976 } 1014 }
977 break; 1015 break;
978 default: 1016 default:
979 dvb_feed_start_pid(feed); 1017 ret = dvb_feed_start_pid(feed);
980 break; 1018 break;
981 } 1019 }
982 } else if ((feed->ts_type & TS_PACKET) && 1020 } else if ((feed->ts_type & TS_PACKET) &&
983 (demux->dmx.frontend->source != DMX_MEMORY_FE)) { 1021 (demux->dmx.frontend->source != DMX_MEMORY_FE)) {
984 StartHWFilter(feed->filter); 1022 ret = StartHWFilter(feed->filter);
985 } 1023 }
986 } 1024 }
987 1025
988 if (feed->type == DMX_TYPE_SEC) { 1026 else if (feed->type == DMX_TYPE_SEC) {
989 int i; 1027 int i;
990 1028
991 for (i = 0; i < demux->filternum; i++) { 1029 for (i = 0; i < demux->filternum; i++) {
@@ -996,12 +1034,15 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
996 if (demux->filter[i].filter.parent != &feed->feed.sec) 1034 if (demux->filter[i].filter.parent != &feed->feed.sec)
997 continue; 1035 continue;
998 demux->filter[i].state = DMX_STATE_GO; 1036 demux->filter[i].state = DMX_STATE_GO;
999 if (demux->dmx.frontend->source != DMX_MEMORY_FE) 1037 if (demux->dmx.frontend->source != DMX_MEMORY_FE) {
1000 StartHWFilter(&demux->filter[i]); 1038 ret = StartHWFilter(&demux->filter[i]);
1039 if (ret)
1040 break;
1041 }
1001 } 1042 }
1002 } 1043 }
1003 1044
1004 return 0; 1045 return ret;
1005} 1046}
1006 1047
1007 1048
@@ -1009,7 +1050,7 @@ static int av7110_stop_feed(struct dvb_demux_feed *feed)
1009{ 1050{
1010 struct dvb_demux *demux = feed->demux; 1051 struct dvb_demux *demux = feed->demux;
1011 struct av7110 *av7110 = demux->priv; 1052 struct av7110 *av7110 = demux->priv;
1012 1053 int i, rc, ret = 0;
1013 dprintk(4, "%p\n", av7110); 1054 dprintk(4, "%p\n", av7110);
1014 1055
1015 if (feed->type == DMX_TYPE_TS) { 1056 if (feed->type == DMX_TYPE_TS) {
@@ -1022,26 +1063,29 @@ static int av7110_stop_feed(struct dvb_demux_feed *feed)
1022 } 1063 }
1023 if (feed->ts_type & TS_DECODER && 1064 if (feed->ts_type & TS_DECODER &&
1024 feed->pes_type < DMX_TS_PES_OTHER) { 1065 feed->pes_type < DMX_TS_PES_OTHER) {
1025 dvb_feed_stop_pid(feed); 1066 ret = dvb_feed_stop_pid(feed);
1026 } else 1067 } else
1027 if ((feed->ts_type & TS_PACKET) && 1068 if ((feed->ts_type & TS_PACKET) &&
1028 (demux->dmx.frontend->source != DMX_MEMORY_FE)) 1069 (demux->dmx.frontend->source != DMX_MEMORY_FE))
1029 StopHWFilter(feed->filter); 1070 ret = StopHWFilter(feed->filter);
1030 } 1071 }
1031 1072
1032 if (feed->type == DMX_TYPE_SEC) { 1073 if (!ret && feed->type == DMX_TYPE_SEC) {
1033 int i; 1074 for (i = 0; i<demux->filternum; i++) {
1034
1035 for (i = 0; i<demux->filternum; i++)
1036 if (demux->filter[i].state == DMX_STATE_GO && 1075 if (demux->filter[i].state == DMX_STATE_GO &&
1037 demux->filter[i].filter.parent == &feed->feed.sec) { 1076 demux->filter[i].filter.parent == &feed->feed.sec) {
1038 demux->filter[i].state = DMX_STATE_READY; 1077 demux->filter[i].state = DMX_STATE_READY;
1039 if (demux->dmx.frontend->source != DMX_MEMORY_FE) 1078 if (demux->dmx.frontend->source != DMX_MEMORY_FE) {
1040 StopHWFilter(&demux->filter[i]); 1079 rc = StopHWFilter(&demux->filter[i]);
1080 if (!ret)
1081 ret = rc;
1082 /* keep going, stop as many filters as possible */
1083 }
1084 }
1041 } 1085 }
1042 } 1086 }
1043 1087
1044 return 0; 1088 return ret;
1045} 1089}
1046 1090
1047 1091
@@ -1093,7 +1137,7 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1093 ret = av7110_fw_request(av7110, &tag, 0, fwstc, 4); 1137 ret = av7110_fw_request(av7110, &tag, 0, fwstc, 4);
1094 if (ret) { 1138 if (ret) {
1095 printk(KERN_ERR "%s: av7110_fw_request error\n", __FUNCTION__); 1139 printk(KERN_ERR "%s: av7110_fw_request error\n", __FUNCTION__);
1096 return -EIO; 1140 return ret;
1097 } 1141 }
1098 dprintk(2, "fwstc = %04hx %04hx %04hx %04hx\n", 1142 dprintk(2, "fwstc = %04hx %04hx %04hx %04hx\n",
1099 fwstc[0], fwstc[1], fwstc[2], fwstc[3]); 1143 fwstc[0], fwstc[1], fwstc[2], fwstc[3]);
@@ -1119,18 +1163,14 @@ static int av7110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
1119 1163
1120 switch (tone) { 1164 switch (tone) {
1121 case SEC_TONE_ON: 1165 case SEC_TONE_ON:
1122 Set22K(av7110, 1); 1166 return Set22K(av7110, 1);
1123 break;
1124 1167
1125 case SEC_TONE_OFF: 1168 case SEC_TONE_OFF:
1126 Set22K(av7110, 0); 1169 return Set22K(av7110, 0);
1127 break;
1128 1170
1129 default: 1171 default:
1130 return -EINVAL; 1172 return -EINVAL;
1131 } 1173 }
1132
1133 return 0;
1134} 1174}
1135 1175
1136static int av7110_diseqc_send_master_cmd(struct dvb_frontend* fe, 1176static int av7110_diseqc_send_master_cmd(struct dvb_frontend* fe,
@@ -1138,9 +1178,7 @@ static int av7110_diseqc_send_master_cmd(struct dvb_frontend* fe,
1138{ 1178{
1139 struct av7110* av7110 = fe->dvb->priv; 1179 struct av7110* av7110 = fe->dvb->priv;
1140 1180
1141 av7110_diseqc_send(av7110, cmd->msg_len, cmd->msg, -1); 1181 return av7110_diseqc_send(av7110, cmd->msg_len, cmd->msg, -1);
1142
1143 return 0;
1144} 1182}
1145 1183
1146static int av7110_diseqc_send_burst(struct dvb_frontend* fe, 1184static int av7110_diseqc_send_burst(struct dvb_frontend* fe,
@@ -1148,9 +1186,7 @@ static int av7110_diseqc_send_burst(struct dvb_frontend* fe,
1148{ 1186{
1149 struct av7110* av7110 = fe->dvb->priv; 1187 struct av7110* av7110 = fe->dvb->priv;
1150 1188
1151 av7110_diseqc_send(av7110, 0, NULL, minicmd); 1189 return av7110_diseqc_send(av7110, 0, NULL, minicmd);
1152
1153 return 0;
1154} 1190}
1155 1191
1156/* simplified code from budget-core.c */ 1192/* simplified code from budget-core.c */
@@ -1992,76 +2028,85 @@ static struct l64781_config grundig_29504_401_config = {
1992 2028
1993 2029
1994 2030
1995static void av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status) 2031static int av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status)
1996{ 2032{
2033 int ret = 0;
1997 int synced = (status & FE_HAS_LOCK) ? 1 : 0; 2034 int synced = (status & FE_HAS_LOCK) ? 1 : 0;
1998 2035
1999 av7110->fe_status = status; 2036 av7110->fe_status = status;
2000 2037
2001 if (av7110->fe_synced == synced) 2038 if (av7110->fe_synced == synced)
2002 return; 2039 return 0;
2003
2004 av7110->fe_synced = synced;
2005 2040
2006 if (av7110->playing) 2041 if (av7110->playing)
2007 return; 2042 return 0;
2008 2043
2009 if (down_interruptible(&av7110->pid_mutex)) 2044 if (down_interruptible(&av7110->pid_mutex))
2010 return; 2045 return -ERESTARTSYS;
2011 2046
2012 if (av7110->fe_synced) { 2047 if (synced) {
2013 SetPIDs(av7110, av7110->pids[DMX_PES_VIDEO], 2048 ret = SetPIDs(av7110, av7110->pids[DMX_PES_VIDEO],
2014 av7110->pids[DMX_PES_AUDIO], 2049 av7110->pids[DMX_PES_AUDIO],
2015 av7110->pids[DMX_PES_TELETEXT], 0, 2050 av7110->pids[DMX_PES_TELETEXT], 0,
2016 av7110->pids[DMX_PES_PCR]); 2051 av7110->pids[DMX_PES_PCR]);
2017 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0); 2052 if (!ret)
2053 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
2018 } else { 2054 } else {
2019 SetPIDs(av7110, 0, 0, 0, 0, 0); 2055 ret = SetPIDs(av7110, 0, 0, 0, 0, 0);
2020 av7110_fw_cmd(av7110, COMTYPE_PID_FILTER, FlushTSQueue, 0); 2056 if (!ret) {
2021 av7110_wait_msgstate(av7110, GPMQBusy); 2057 ret = av7110_fw_cmd(av7110, COMTYPE_PID_FILTER, FlushTSQueue, 0);
2058 if (!ret)
2059 ret = av7110_wait_msgstate(av7110, GPMQBusy);
2060 }
2022 } 2061 }
2023 2062
2063 if (!ret)
2064 av7110->fe_synced = synced;
2065
2024 up(&av7110->pid_mutex); 2066 up(&av7110->pid_mutex);
2067 return ret;
2025} 2068}
2026 2069
2027static int av7110_fe_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 2070static int av7110_fe_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
2028{ 2071{
2029 struct av7110* av7110 = fe->dvb->priv; 2072 struct av7110* av7110 = fe->dvb->priv;
2030 av7110_fe_lock_fix(av7110, 0); 2073
2031 return av7110->fe_set_frontend(fe, params); 2074 int ret = av7110_fe_lock_fix(av7110, 0);
2075 if (!ret)
2076 ret = av7110->fe_set_frontend(fe, params);
2077 return ret;
2032} 2078}
2033 2079
2034static int av7110_fe_init(struct dvb_frontend* fe) 2080static int av7110_fe_init(struct dvb_frontend* fe)
2035{ 2081{
2036 struct av7110* av7110 = fe->dvb->priv; 2082 struct av7110* av7110 = fe->dvb->priv;
2037 2083
2038 av7110_fe_lock_fix(av7110, 0); 2084 int ret = av7110_fe_lock_fix(av7110, 0);
2039 return av7110->fe_init(fe); 2085 if (!ret)
2086 ret = av7110->fe_init(fe);
2087 return ret;
2040} 2088}
2041 2089
2042static int av7110_fe_read_status(struct dvb_frontend* fe, fe_status_t* status) 2090static int av7110_fe_read_status(struct dvb_frontend* fe, fe_status_t* status)
2043{ 2091{
2044 struct av7110* av7110 = fe->dvb->priv; 2092 struct av7110* av7110 = fe->dvb->priv;
2045 int ret;
2046 2093
2047 /* call the real implementation */ 2094 /* call the real implementation */
2048 ret = av7110->fe_read_status(fe, status); 2095 int ret = av7110->fe_read_status(fe, status);
2049 if (ret) 2096 if (!ret)
2050 return ret; 2097 if (((*status ^ av7110->fe_status) & FE_HAS_LOCK) && (*status & FE_HAS_LOCK))
2051 2098 ret = av7110_fe_lock_fix(av7110, *status);
2052 if (((*status ^ av7110->fe_status) & FE_HAS_LOCK) && (*status & FE_HAS_LOCK)) { 2099 return ret;
2053 av7110_fe_lock_fix(av7110, *status);
2054 }
2055
2056 return 0;
2057} 2100}
2058 2101
2059static int av7110_fe_diseqc_reset_overload(struct dvb_frontend* fe) 2102static int av7110_fe_diseqc_reset_overload(struct dvb_frontend* fe)
2060{ 2103{
2061 struct av7110* av7110 = fe->dvb->priv; 2104 struct av7110* av7110 = fe->dvb->priv;
2062 2105
2063 av7110_fe_lock_fix(av7110, 0); 2106 int ret = av7110_fe_lock_fix(av7110, 0);
2064 return av7110->fe_diseqc_reset_overload(fe); 2107 if (!ret)
2108 ret = av7110->fe_diseqc_reset_overload(fe);
2109 return ret;
2065} 2110}
2066 2111
2067static int av7110_fe_diseqc_send_master_cmd(struct dvb_frontend* fe, 2112static int av7110_fe_diseqc_send_master_cmd(struct dvb_frontend* fe,
@@ -2069,40 +2114,50 @@ static int av7110_fe_diseqc_send_master_cmd(struct dvb_frontend* fe,
2069{ 2114{
2070 struct av7110* av7110 = fe->dvb->priv; 2115 struct av7110* av7110 = fe->dvb->priv;
2071 2116
2072 av7110_fe_lock_fix(av7110, 0); 2117 int ret = av7110_fe_lock_fix(av7110, 0);
2073 return av7110->fe_diseqc_send_master_cmd(fe, cmd); 2118 if (!ret)
2119 ret = av7110->fe_diseqc_send_master_cmd(fe, cmd);
2120 return ret;
2074} 2121}
2075 2122
2076static int av7110_fe_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) 2123static int av7110_fe_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
2077{ 2124{
2078 struct av7110* av7110 = fe->dvb->priv; 2125 struct av7110* av7110 = fe->dvb->priv;
2079 2126
2080 av7110_fe_lock_fix(av7110, 0); 2127 int ret = av7110_fe_lock_fix(av7110, 0);
2081 return av7110->fe_diseqc_send_burst(fe, minicmd); 2128 if (!ret)
2129 ret = av7110->fe_diseqc_send_burst(fe, minicmd);
2130 return ret;
2082} 2131}
2083 2132
2084static int av7110_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 2133static int av7110_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
2085{ 2134{
2086 struct av7110* av7110 = fe->dvb->priv; 2135 struct av7110* av7110 = fe->dvb->priv;
2087 2136
2088 av7110_fe_lock_fix(av7110, 0); 2137 int ret = av7110_fe_lock_fix(av7110, 0);
2089 return av7110->fe_set_tone(fe, tone); 2138 if (!ret)
2139 ret = av7110->fe_set_tone(fe, tone);
2140 return ret;
2090} 2141}
2091 2142
2092static int av7110_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) 2143static int av7110_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
2093{ 2144{
2094 struct av7110* av7110 = fe->dvb->priv; 2145 struct av7110* av7110 = fe->dvb->priv;
2095 2146
2096 av7110_fe_lock_fix(av7110, 0); 2147 int ret = av7110_fe_lock_fix(av7110, 0);
2097 return av7110->fe_set_voltage(fe, voltage); 2148 if (!ret)
2149 ret = av7110->fe_set_voltage(fe, voltage);
2150 return ret;
2098} 2151}
2099 2152
2100static int av7110_fe_dishnetwork_send_legacy_command(struct dvb_frontend* fe, unsigned int cmd) 2153static int av7110_fe_dishnetwork_send_legacy_command(struct dvb_frontend* fe, unsigned int cmd)
2101{ 2154{
2102 struct av7110* av7110 = fe->dvb->priv; 2155 struct av7110* av7110 = fe->dvb->priv;
2103 2156
2104 av7110_fe_lock_fix(av7110, 0); 2157 int ret = av7110_fe_lock_fix(av7110, 0);
2105 return av7110->fe_dishnetwork_send_legacy_command(fe, cmd); 2158 if (!ret)
2159 ret = av7110->fe_dishnetwork_send_legacy_command(fe, cmd);
2160 return ret;
2106} 2161}
2107 2162
2108static u8 read_pwm(struct av7110* av7110) 2163static u8 read_pwm(struct av7110* av7110)
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 4f69b4d01479..508b7739c609 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -119,8 +119,7 @@ struct av7110 {
119 volatile int bmp_state; 119 volatile int bmp_state;
120#define BMP_NONE 0 120#define BMP_NONE 0
121#define BMP_LOADING 1 121#define BMP_LOADING 1
122#define BMP_LOADINGS 2 122#define BMP_LOADED 2
123#define BMP_LOADED 3
124 wait_queue_head_t bmpq; 123 wait_queue_head_t bmpq;
125 124
126 125
@@ -255,12 +254,12 @@ struct av7110 {
255}; 254};
256 255
257 256
258extern void ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, 257extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
259 u16 subpid, u16 pcrpid); 258 u16 subpid, u16 pcrpid);
260 259
261extern void av7110_register_irc_handler(void (*func)(u32)); 260extern void av7110_register_irc_handler(void (*func)(u32));
262extern void av7110_unregister_irc_handler(void (*func)(u32)); 261extern void av7110_unregister_irc_handler(void (*func)(u32));
263extern void av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config); 262extern int av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config);
264 263
265extern int av7110_ir_init (void); 264extern int av7110_ir_init (void);
266extern void av7110_ir_exit (void); 265extern void av7110_ir_exit (void);
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index ccf946125d02..0696a5a4f855 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -121,6 +121,7 @@ static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
121int av7110_av_start_record(struct av7110 *av7110, int av, 121int av7110_av_start_record(struct av7110 *av7110, int av,
122 struct dvb_demux_feed *dvbdmxfeed) 122 struct dvb_demux_feed *dvbdmxfeed)
123{ 123{
124 int ret = 0;
124 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 125 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
125 126
126 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed); 127 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed);
@@ -137,7 +138,7 @@ int av7110_av_start_record(struct av7110 *av7110, int av,
137 dvbdmx->pesfilter[0]->pid, 138 dvbdmx->pesfilter[0]->pid,
138 dvb_filter_pes2ts_cb, 139 dvb_filter_pes2ts_cb,
139 (void *) dvbdmx->pesfilter[0]); 140 (void *) dvbdmx->pesfilter[0]);
140 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0); 141 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
141 break; 142 break;
142 143
143 case RP_VIDEO: 144 case RP_VIDEO:
@@ -145,7 +146,7 @@ int av7110_av_start_record(struct av7110 *av7110, int av,
145 dvbdmx->pesfilter[1]->pid, 146 dvbdmx->pesfilter[1]->pid,
146 dvb_filter_pes2ts_cb, 147 dvb_filter_pes2ts_cb,
147 (void *) dvbdmx->pesfilter[1]); 148 (void *) dvbdmx->pesfilter[1]);
148 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0); 149 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
149 break; 150 break;
150 151
151 case RP_AV: 152 case RP_AV:
@@ -157,14 +158,15 @@ int av7110_av_start_record(struct av7110 *av7110, int av,
157 dvbdmx->pesfilter[1]->pid, 158 dvbdmx->pesfilter[1]->pid,
158 dvb_filter_pes2ts_cb, 159 dvb_filter_pes2ts_cb,
159 (void *) dvbdmx->pesfilter[1]); 160 (void *) dvbdmx->pesfilter[1]);
160 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0); 161 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0);
161 break; 162 break;
162 } 163 }
163 return 0; 164 return ret;
164} 165}
165 166
166int av7110_av_start_play(struct av7110 *av7110, int av) 167int av7110_av_start_play(struct av7110 *av7110, int av)
167{ 168{
169 int ret = 0;
168 dprintk(2, "av7110:%p, \n", av7110); 170 dprintk(2, "av7110:%p, \n", av7110);
169 171
170 if (av7110->rec_mode) 172 if (av7110->rec_mode)
@@ -182,54 +184,57 @@ int av7110_av_start_play(struct av7110 *av7110, int av)
182 av7110->playing |= av; 184 av7110->playing |= av;
183 switch (av7110->playing) { 185 switch (av7110->playing) {
184 case RP_AUDIO: 186 case RP_AUDIO:
185 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0); 187 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
186 break; 188 break;
187 case RP_VIDEO: 189 case RP_VIDEO:
188 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0); 190 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
189 av7110->sinfo = 0; 191 av7110->sinfo = 0;
190 break; 192 break;
191 case RP_AV: 193 case RP_AV:
192 av7110->sinfo = 0; 194 av7110->sinfo = 0;
193 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0); 195 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0);
194 break; 196 break;
195 } 197 }
196 return av7110->playing; 198 if (!ret)
199 ret = av7110->playing;
200 return ret;
197} 201}
198 202
199void av7110_av_stop(struct av7110 *av7110, int av) 203int av7110_av_stop(struct av7110 *av7110, int av)
200{ 204{
205 int ret = 0;
201 dprintk(2, "av7110:%p, \n", av7110); 206 dprintk(2, "av7110:%p, \n", av7110);
202 207
203 if (!(av7110->playing & av) && !(av7110->rec_mode & av)) 208 if (!(av7110->playing & av) && !(av7110->rec_mode & av))
204 return; 209 return 0;
205
206 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0); 210 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
207 if (av7110->playing) { 211 if (av7110->playing) {
208 av7110->playing &= ~av; 212 av7110->playing &= ~av;
209 switch (av7110->playing) { 213 switch (av7110->playing) {
210 case RP_AUDIO: 214 case RP_AUDIO:
211 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0); 215 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
212 break; 216 break;
213 case RP_VIDEO: 217 case RP_VIDEO:
214 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0); 218 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
215 break; 219 break;
216 case RP_NONE: 220 case RP_NONE:
217 av7110_set_vidmode(av7110, av7110->vidmode); 221 ret = av7110_set_vidmode(av7110, av7110->vidmode);
218 break; 222 break;
219 } 223 }
220 } else { 224 } else {
221 av7110->rec_mode &= ~av; 225 av7110->rec_mode &= ~av;
222 switch (av7110->rec_mode) { 226 switch (av7110->rec_mode) {
223 case RP_AUDIO: 227 case RP_AUDIO:
224 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0); 228 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
225 break; 229 break;
226 case RP_VIDEO: 230 case RP_VIDEO:
227 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0); 231 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
228 break; 232 break;
229 case RP_NONE: 233 case RP_NONE:
230 break; 234 break;
231 } 235 }
232 } 236 }
237 return ret;
233} 238}
234 239
235 240
@@ -317,19 +322,22 @@ int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
317 return 0; 322 return 0;
318} 323}
319 324
320void av7110_set_vidmode(struct av7110 *av7110, int mode) 325int av7110_set_vidmode(struct av7110 *av7110, int mode)
321{ 326{
327 int ret;
322 dprintk(2, "av7110:%p, \n", av7110); 328 dprintk(2, "av7110:%p, \n", av7110);
323 329
324 av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode); 330 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode);
325 331
326 if (!av7110->playing) { 332 if (!ret && !av7110->playing) {
327 ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO], 333 ret = ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO],
328 av7110->pids[DMX_PES_AUDIO], 334 av7110->pids[DMX_PES_AUDIO],
329 av7110->pids[DMX_PES_TELETEXT], 335 av7110->pids[DMX_PES_TELETEXT],
330 0, av7110->pids[DMX_PES_PCR]); 336 0, av7110->pids[DMX_PES_PCR]);
331 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0); 337 if (!ret)
338 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
332 } 339 }
340 return ret;
333} 341}
334 342
335 343
@@ -340,17 +348,18 @@ static int sw2mode[16] = {
340 VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, 348 VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL,
341}; 349};
342 350
343static void get_video_format(struct av7110 *av7110, u8 *buf, int count) 351static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
344{ 352{
345 int i; 353 int i;
346 int hsize, vsize; 354 int hsize, vsize;
347 int sw; 355 int sw;
348 u8 *p; 356 u8 *p;
357 int ret = 0;
349 358
350 dprintk(2, "av7110:%p, \n", av7110); 359 dprintk(2, "av7110:%p, \n", av7110);
351 360
352 if (av7110->sinfo) 361 if (av7110->sinfo)
353 return; 362 return 0;
354 for (i = 7; i < count - 10; i++) { 363 for (i = 7; i < count - 10; i++) {
355 p = buf + i; 364 p = buf + i;
356 if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3) 365 if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3)
@@ -359,11 +368,14 @@ static void get_video_format(struct av7110 *av7110, u8 *buf, int count)
359 hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4); 368 hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4);
360 vsize = ((p[1] &0x0F) << 8) | (p[2]); 369 vsize = ((p[1] &0x0F) << 8) | (p[2]);
361 sw = (p[3] & 0x0F); 370 sw = (p[3] & 0x0F);
362 av7110_set_vidmode(av7110, sw2mode[sw]); 371 ret = av7110_set_vidmode(av7110, sw2mode[sw]);
363 dprintk(2, "playback %dx%d fr=%d\n", hsize, vsize, sw); 372 if (!ret) {
364 av7110->sinfo = 1; 373 dprintk(2, "playback %dx%d fr=%d\n", hsize, vsize, sw);
374 av7110->sinfo = 1;
375 }
365 break; 376 break;
366 } 377 }
378 return ret;
367} 379}
368 380
369 381
@@ -974,7 +986,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
974 unsigned long arg = (unsigned long) parg; 986 unsigned long arg = (unsigned long) parg;
975 int ret = 0; 987 int ret = 0;
976 988
977 dprintk(2, "av7110:%p, \n", av7110); 989 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
978 990
979 if ((file->f_flags & O_ACCMODE) == O_RDONLY) { 991 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
980 if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT && 992 if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT &&
@@ -987,49 +999,57 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
987 case VIDEO_STOP: 999 case VIDEO_STOP:
988 av7110->videostate.play_state = VIDEO_STOPPED; 1000 av7110->videostate.play_state = VIDEO_STOPPED;
989 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) 1001 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
990 av7110_av_stop(av7110, RP_VIDEO); 1002 ret = av7110_av_stop(av7110, RP_VIDEO);
991 else 1003 else
992 vidcom(av7110, VIDEO_CMD_STOP, 1004 ret = vidcom(av7110, VIDEO_CMD_STOP,
993 av7110->videostate.video_blank ? 0 : 1); 1005 av7110->videostate.video_blank ? 0 : 1);
994 av7110->trickmode = TRICK_NONE; 1006 if (!ret)
1007 av7110->trickmode = TRICK_NONE;
995 break; 1008 break;
996 1009
997 case VIDEO_PLAY: 1010 case VIDEO_PLAY:
998 av7110->trickmode = TRICK_NONE; 1011 av7110->trickmode = TRICK_NONE;
999 if (av7110->videostate.play_state == VIDEO_FREEZED) { 1012 if (av7110->videostate.play_state == VIDEO_FREEZED) {
1000 av7110->videostate.play_state = VIDEO_PLAYING; 1013 av7110->videostate.play_state = VIDEO_PLAYING;
1001 vidcom(av7110, VIDEO_CMD_PLAY, 0); 1014 ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
1015 if (ret)
1016 break;
1002 } 1017 }
1003 1018
1004 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) { 1019 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) {
1005 if (av7110->playing == RP_AV) { 1020 if (av7110->playing == RP_AV) {
1006 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0); 1021 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
1022 if (ret)
1023 break;
1007 av7110->playing &= ~RP_VIDEO; 1024 av7110->playing &= ~RP_VIDEO;
1008 } 1025 }
1009 av7110_av_start_play(av7110, RP_VIDEO); 1026 ret = av7110_av_start_play(av7110, RP_VIDEO);
1010 vidcom(av7110, VIDEO_CMD_PLAY, 0);
1011 } else {
1012 //av7110_av_stop(av7110, RP_VIDEO);
1013 vidcom(av7110, VIDEO_CMD_PLAY, 0);
1014 } 1027 }
1015 av7110->videostate.play_state = VIDEO_PLAYING; 1028 if (!ret)
1029 ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
1030 if (!ret)
1031 av7110->videostate.play_state = VIDEO_PLAYING;
1016 break; 1032 break;
1017 1033
1018 case VIDEO_FREEZE: 1034 case VIDEO_FREEZE:
1019 av7110->videostate.play_state = VIDEO_FREEZED; 1035 av7110->videostate.play_state = VIDEO_FREEZED;
1020 if (av7110->playing & RP_VIDEO) 1036 if (av7110->playing & RP_VIDEO)
1021 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0); 1037 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0);
1022 else 1038 else
1023 vidcom(av7110, VIDEO_CMD_FREEZE, 1); 1039 ret = vidcom(av7110, VIDEO_CMD_FREEZE, 1);
1024 av7110->trickmode = TRICK_FREEZE; 1040 if (!ret)
1041 av7110->trickmode = TRICK_FREEZE;
1025 break; 1042 break;
1026 1043
1027 case VIDEO_CONTINUE: 1044 case VIDEO_CONTINUE:
1028 if (av7110->playing & RP_VIDEO) 1045 if (av7110->playing & RP_VIDEO)
1029 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0); 1046 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0);
1030 vidcom(av7110, VIDEO_CMD_PLAY, 0); 1047 if (!ret)
1031 av7110->videostate.play_state = VIDEO_PLAYING; 1048 ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
1032 av7110->trickmode = TRICK_NONE; 1049 if (!ret) {
1050 av7110->videostate.play_state = VIDEO_PLAYING;
1051 av7110->trickmode = TRICK_NONE;
1052 }
1033 break; 1053 break;
1034 1054
1035 case VIDEO_SELECT_SOURCE: 1055 case VIDEO_SELECT_SOURCE:
@@ -1045,7 +1065,7 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
1045 break; 1065 break;
1046 1066
1047 case VIDEO_GET_EVENT: 1067 case VIDEO_GET_EVENT:
1048 ret=dvb_video_get_event(av7110, parg, file->f_flags); 1068 ret = dvb_video_get_event(av7110, parg, file->f_flags);
1049 break; 1069 break;
1050 1070
1051 case VIDEO_GET_SIZE: 1071 case VIDEO_GET_SIZE:
@@ -1105,25 +1125,32 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
1105 case VIDEO_FAST_FORWARD: 1125 case VIDEO_FAST_FORWARD:
1106 //note: arg is ignored by firmware 1126 //note: arg is ignored by firmware
1107 if (av7110->playing & RP_VIDEO) 1127 if (av7110->playing & RP_VIDEO)
1108 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, 1128 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1109 __Scan_I, 2, AV_PES, 0); 1129 __Scan_I, 2, AV_PES, 0);
1110 else 1130 else
1111 vidcom(av7110, VIDEO_CMD_FFWD, arg); 1131 ret = vidcom(av7110, VIDEO_CMD_FFWD, arg);
1112 av7110->trickmode = TRICK_FAST; 1132 if (!ret) {
1113 av7110->videostate.play_state = VIDEO_PLAYING; 1133 av7110->trickmode = TRICK_FAST;
1134 av7110->videostate.play_state = VIDEO_PLAYING;
1135 }
1114 break; 1136 break;
1115 1137
1116 case VIDEO_SLOWMOTION: 1138 case VIDEO_SLOWMOTION:
1117 if (av7110->playing&RP_VIDEO) { 1139 if (av7110->playing&RP_VIDEO) {
1118 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0); 1140 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0);
1119 vidcom(av7110, VIDEO_CMD_SLOW, arg); 1141 if (!ret)
1142 ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
1120 } else { 1143 } else {
1121 vidcom(av7110, VIDEO_CMD_PLAY, 0); 1144 ret = vidcom(av7110, VIDEO_CMD_PLAY, 0);
1122 vidcom(av7110, VIDEO_CMD_STOP, 0); 1145 if (!ret)
1123 vidcom(av7110, VIDEO_CMD_SLOW, arg); 1146 ret = vidcom(av7110, VIDEO_CMD_STOP, 0);
1147 if (!ret)
1148 ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
1149 }
1150 if (!ret) {
1151 av7110->trickmode = TRICK_SLOW;
1152 av7110->videostate.play_state = VIDEO_PLAYING;
1124 } 1153 }
1125 av7110->trickmode = TRICK_SLOW;
1126 av7110->videostate.play_state = VIDEO_PLAYING;
1127 break; 1154 break;
1128 1155
1129 case VIDEO_GET_CAPABILITIES: 1156 case VIDEO_GET_CAPABILITIES:
@@ -1136,18 +1163,21 @@ static int dvb_video_ioctl(struct inode *inode, struct file *file,
1136 av7110_ipack_reset(&av7110->ipack[1]); 1163 av7110_ipack_reset(&av7110->ipack[1]);
1137 1164
1138 if (av7110->playing == RP_AV) { 1165 if (av7110->playing == RP_AV) {
1139 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, 1166 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1140 __Play, 2, AV_PES, 0); 1167 __Play, 2, AV_PES, 0);
1168 if (ret)
1169 break;
1141 if (av7110->trickmode == TRICK_FAST) 1170 if (av7110->trickmode == TRICK_FAST)
1142 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, 1171 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1143 __Scan_I, 2, AV_PES, 0); 1172 __Scan_I, 2, AV_PES, 0);
1144 if (av7110->trickmode == TRICK_SLOW) { 1173 if (av7110->trickmode == TRICK_SLOW) {
1145 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, 1174 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1146 __Slow, 2, 0, 0); 1175 __Slow, 2, 0, 0);
1147 vidcom(av7110, VIDEO_CMD_SLOW, arg); 1176 if (!ret)
1177 ret = vidcom(av7110, VIDEO_CMD_SLOW, arg);
1148 } 1178 }
1149 if (av7110->trickmode == TRICK_FREEZE) 1179 if (av7110->trickmode == TRICK_FREEZE)
1150 vidcom(av7110, VIDEO_CMD_STOP, 1); 1180 ret = vidcom(av7110, VIDEO_CMD_STOP, 1);
1151 } 1181 }
1152 break; 1182 break;
1153 1183
@@ -1170,7 +1200,7 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1170 unsigned long arg = (unsigned long) parg; 1200 unsigned long arg = (unsigned long) parg;
1171 int ret = 0; 1201 int ret = 0;
1172 1202
1173 dprintk(2, "av7110:%p, \n", av7110); 1203 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
1174 1204
1175 if (((file->f_flags & O_ACCMODE) == O_RDONLY) && 1205 if (((file->f_flags & O_ACCMODE) == O_RDONLY) &&
1176 (cmd != AUDIO_GET_STATUS)) 1206 (cmd != AUDIO_GET_STATUS))
@@ -1179,28 +1209,32 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1179 switch (cmd) { 1209 switch (cmd) {
1180 case AUDIO_STOP: 1210 case AUDIO_STOP:
1181 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY) 1211 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
1182 av7110_av_stop(av7110, RP_AUDIO); 1212 ret = av7110_av_stop(av7110, RP_AUDIO);
1183 else 1213 else
1184 audcom(av7110, AUDIO_CMD_MUTE); 1214 ret = audcom(av7110, AUDIO_CMD_MUTE);
1185 av7110->audiostate.play_state = AUDIO_STOPPED; 1215 if (!ret)
1216 av7110->audiostate.play_state = AUDIO_STOPPED;
1186 break; 1217 break;
1187 1218
1188 case AUDIO_PLAY: 1219 case AUDIO_PLAY:
1189 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY) 1220 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
1190 av7110_av_start_play(av7110, RP_AUDIO); 1221 ret = av7110_av_start_play(av7110, RP_AUDIO);
1191 audcom(av7110, AUDIO_CMD_UNMUTE); 1222 if (!ret)
1192 av7110->audiostate.play_state = AUDIO_PLAYING; 1223 ret = audcom(av7110, AUDIO_CMD_UNMUTE);
1224 if (!ret)
1225 av7110->audiostate.play_state = AUDIO_PLAYING;
1193 break; 1226 break;
1194 1227
1195 case AUDIO_PAUSE: 1228 case AUDIO_PAUSE:
1196 audcom(av7110, AUDIO_CMD_MUTE); 1229 ret = audcom(av7110, AUDIO_CMD_MUTE);
1197 av7110->audiostate.play_state = AUDIO_PAUSED; 1230 if (!ret)
1231 av7110->audiostate.play_state = AUDIO_PAUSED;
1198 break; 1232 break;
1199 1233
1200 case AUDIO_CONTINUE: 1234 case AUDIO_CONTINUE:
1201 if (av7110->audiostate.play_state == AUDIO_PAUSED) { 1235 if (av7110->audiostate.play_state == AUDIO_PAUSED) {
1202 av7110->audiostate.play_state = AUDIO_PLAYING; 1236 av7110->audiostate.play_state = AUDIO_PLAYING;
1203 audcom(av7110, AUDIO_CMD_MUTE | AUDIO_CMD_PCM16); 1237 ret = audcom(av7110, AUDIO_CMD_UNMUTE | AUDIO_CMD_PCM16);
1204 } 1238 }
1205 break; 1239 break;
1206 1240
@@ -1210,14 +1244,15 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1210 1244
1211 case AUDIO_SET_MUTE: 1245 case AUDIO_SET_MUTE:
1212 { 1246 {
1213 audcom(av7110, arg ? AUDIO_CMD_MUTE : AUDIO_CMD_UNMUTE); 1247 ret = audcom(av7110, arg ? AUDIO_CMD_MUTE : AUDIO_CMD_UNMUTE);
1214 av7110->audiostate.mute_state = (int) arg; 1248 if (!ret)
1249 av7110->audiostate.mute_state = (int) arg;
1215 break; 1250 break;
1216 } 1251 }
1217 1252
1218 case AUDIO_SET_AV_SYNC: 1253 case AUDIO_SET_AV_SYNC:
1219 av7110->audiostate.AV_sync_state = (int) arg; 1254 av7110->audiostate.AV_sync_state = (int) arg;
1220 audcom(av7110, arg ? AUDIO_CMD_SYNC_ON : AUDIO_CMD_SYNC_OFF); 1255 ret = audcom(av7110, arg ? AUDIO_CMD_SYNC_ON : AUDIO_CMD_SYNC_OFF);
1221 break; 1256 break;
1222 1257
1223 case AUDIO_SET_BYPASS_MODE: 1258 case AUDIO_SET_BYPASS_MODE:
@@ -1229,21 +1264,24 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1229 1264
1230 switch(av7110->audiostate.channel_select) { 1265 switch(av7110->audiostate.channel_select) {
1231 case AUDIO_STEREO: 1266 case AUDIO_STEREO:
1232 audcom(av7110, AUDIO_CMD_STEREO); 1267 ret = audcom(av7110, AUDIO_CMD_STEREO);
1233 if (av7110->adac_type == DVB_ADAC_CRYSTAL) 1268 if (!ret)
1234 i2c_writereg(av7110, 0x20, 0x02, 0x49); 1269 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1270 i2c_writereg(av7110, 0x20, 0x02, 0x49);
1235 break; 1271 break;
1236 1272
1237 case AUDIO_MONO_LEFT: 1273 case AUDIO_MONO_LEFT:
1238 audcom(av7110, AUDIO_CMD_MONO_L); 1274 ret = audcom(av7110, AUDIO_CMD_MONO_L);
1239 if (av7110->adac_type == DVB_ADAC_CRYSTAL) 1275 if (!ret)
1240 i2c_writereg(av7110, 0x20, 0x02, 0x4a); 1276 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1277 i2c_writereg(av7110, 0x20, 0x02, 0x4a);
1241 break; 1278 break;
1242 1279
1243 case AUDIO_MONO_RIGHT: 1280 case AUDIO_MONO_RIGHT:
1244 audcom(av7110, AUDIO_CMD_MONO_R); 1281 ret = audcom(av7110, AUDIO_CMD_MONO_R);
1245 if (av7110->adac_type == DVB_ADAC_CRYSTAL) 1282 if (!ret)
1246 i2c_writereg(av7110, 0x20, 0x02, 0x45); 1283 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1284 i2c_writereg(av7110, 0x20, 0x02, 0x45);
1247 break; 1285 break;
1248 1286
1249 default: 1287 default:
@@ -1264,8 +1302,8 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1264 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout); 1302 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1265 av7110_ipack_reset(&av7110->ipack[0]); 1303 av7110_ipack_reset(&av7110->ipack[0]);
1266 if (av7110->playing == RP_AV) 1304 if (av7110->playing == RP_AV)
1267 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, 1305 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1268 __Play, 2, AV_PES, 0); 1306 __Play, 2, AV_PES, 0);
1269 break; 1307 break;
1270 case AUDIO_SET_ID: 1308 case AUDIO_SET_ID:
1271 1309
@@ -1274,7 +1312,7 @@ static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1274 { 1312 {
1275 struct audio_mixer *amix = (struct audio_mixer *)parg; 1313 struct audio_mixer *amix = (struct audio_mixer *)parg;
1276 1314
1277 av7110_set_volume(av7110, amix->volume_left, amix->volume_right); 1315 ret = av7110_set_volume(av7110, amix->volume_left, amix->volume_right);
1278 break; 1316 break;
1279 } 1317 }
1280 case AUDIO_SET_STREAMTYPE: 1318 case AUDIO_SET_STREAMTYPE:
diff --git a/drivers/media/dvb/ttpci/av7110_av.h b/drivers/media/dvb/ttpci/av7110_av.h
index cc5e7a7e87c3..45dc144b8b43 100644
--- a/drivers/media/dvb/ttpci/av7110_av.h
+++ b/drivers/media/dvb/ttpci/av7110_av.h
@@ -3,14 +3,14 @@
3 3
4struct av7110; 4struct av7110;
5 5
6extern void av7110_set_vidmode(struct av7110 *av7110, int mode); 6extern int av7110_set_vidmode(struct av7110 *av7110, int mode);
7 7
8extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len); 8extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len);
9extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen); 9extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen);
10extern int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len); 10extern int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len);
11 11
12extern int av7110_set_volume(struct av7110 *av7110, int volleft, int volright); 12extern int av7110_set_volume(struct av7110 *av7110, int volleft, int volright);
13extern void av7110_av_stop(struct av7110 *av7110, int av); 13extern int av7110_av_stop(struct av7110 *av7110, int av);
14extern int av7110_av_start_record(struct av7110 *av7110, int av, 14extern int av7110_av_start_record(struct av7110 *av7110, int av,
15 struct dvb_demux_feed *dvbdmxfeed); 15 struct dvb_demux_feed *dvbdmxfeed);
16extern int av7110_av_start_play(struct av7110 *av7110, int av); 16extern int av7110_av_start_play(struct av7110 *av7110, int av);
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 7fa4a0ebe133..1220826696c5 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -137,7 +137,7 @@ static int waitdebi(struct av7110 *av7110, int adr, int state)
137 return 0; 137 return 0;
138 udelay(5); 138 udelay(5);
139 } 139 }
140 return -1; 140 return -ETIMEDOUT;
141} 141}
142 142
143static int load_dram(struct av7110 *av7110, u32 *data, int len) 143static int load_dram(struct av7110 *av7110, u32 *data, int len)
@@ -155,7 +155,7 @@ static int load_dram(struct av7110 *av7110, u32 *data, int len)
155 for (i = 0; i < blocks; i++) { 155 for (i = 0; i < blocks; i++) {
156 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) { 156 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
157 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at block %d\n", i); 157 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at block %d\n", i);
158 return -1; 158 return -ETIMEDOUT;
159 } 159 }
160 dprintk(4, "writing DRAM block %d\n", i); 160 dprintk(4, "writing DRAM block %d\n", i);
161 mwdebi(av7110, DEBISWAB, bootblock, 161 mwdebi(av7110, DEBISWAB, bootblock,
@@ -170,7 +170,7 @@ static int load_dram(struct av7110 *av7110, u32 *data, int len)
170 if (rest > 0) { 170 if (rest > 0) {
171 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) { 171 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
172 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at last block\n"); 172 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at last block\n");
173 return -1; 173 return -ETIMEDOUT;
174 } 174 }
175 if (rest > 4) 175 if (rest > 4)
176 mwdebi(av7110, DEBISWAB, bootblock, 176 mwdebi(av7110, DEBISWAB, bootblock,
@@ -185,13 +185,13 @@ static int load_dram(struct av7110 *av7110, u32 *data, int len)
185 } 185 }
186 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) { 186 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
187 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout after last block\n"); 187 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout after last block\n");
188 return -1; 188 return -ETIMEDOUT;
189 } 189 }
190 iwdebi(av7110, DEBINOSWAP, BOOT_SIZE, 0, 2); 190 iwdebi(av7110, DEBINOSWAP, BOOT_SIZE, 0, 2);
191 iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2); 191 iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
192 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BOOT_COMPLETE) < 0) { 192 if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BOOT_COMPLETE) < 0) {
193 printk(KERN_ERR "dvb-ttpci: load_dram(): final handshake timeout\n"); 193 printk(KERN_ERR "dvb-ttpci: load_dram(): final handshake timeout\n");
194 return -1; 194 return -ETIMEDOUT;
195 } 195 }
196 return 0; 196 return 0;
197} 197}
@@ -263,7 +263,7 @@ int av7110_bootarm(struct av7110 *av7110)
263 if (saa7146_wait_for_debi_done(av7110->dev, 1)) { 263 if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
264 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): " 264 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
265 "saa7146_wait_for_debi_done() timed out\n"); 265 "saa7146_wait_for_debi_done() timed out\n");
266 return -1; 266 return -ETIMEDOUT;
267 } 267 }
268 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI); 268 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
269 mdelay(1); 269 mdelay(1);
@@ -284,7 +284,7 @@ int av7110_bootarm(struct av7110 *av7110)
284 if (saa7146_wait_for_debi_done(av7110->dev, 1)) { 284 if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
285 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): " 285 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
286 "saa7146_wait_for_debi_done() timed out after loading DRAM\n"); 286 "saa7146_wait_for_debi_done() timed out after loading DRAM\n");
287 return -1; 287 return -ETIMEDOUT;
288 } 288 }
289 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI); 289 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
290 msleep(30); /* the firmware needs some time to initialize */ 290 msleep(30); /* the firmware needs some time to initialize */
@@ -308,6 +308,7 @@ int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
308{ 308{
309 unsigned long start; 309 unsigned long start;
310 u32 stat; 310 u32 stat;
311 int err;
311 312
312 if (FW_VERSION(av7110->arm_app) <= 0x261c) { 313 if (FW_VERSION(av7110->arm_app) <= 0x261c) {
313 /* not supported by old firmware */ 314 /* not supported by old firmware */
@@ -318,17 +319,17 @@ int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
318 /* new firmware */ 319 /* new firmware */
319 start = jiffies; 320 start = jiffies;
320 for (;;) { 321 for (;;) {
322 err = time_after(jiffies, start + ARM_WAIT_FREE);
321 if (down_interruptible(&av7110->dcomlock)) 323 if (down_interruptible(&av7110->dcomlock))
322 return -ERESTARTSYS; 324 return -ERESTARTSYS;
323 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 325 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
324 up(&av7110->dcomlock); 326 up(&av7110->dcomlock);
325 if ((stat & flags) == 0) { 327 if ((stat & flags) == 0)
326 break; 328 break;
327 } 329 if (err) {
328 if (time_after(jiffies, start + ARM_WAIT_FREE)) {
329 printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n", 330 printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n",
330 __FUNCTION__, stat & flags); 331 __FUNCTION__, stat & flags);
331 return -1; 332 return -ETIMEDOUT;
332 } 333 }
333 msleep(1); 334 msleep(1);
334 } 335 }
@@ -342,6 +343,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
342 char *type = NULL; 343 char *type = NULL;
343 u16 flags[2] = {0, 0}; 344 u16 flags[2] = {0, 0};
344 u32 stat; 345 u32 stat;
346 int err;
345 347
346// dprintk(4, "%p\n", av7110); 348// dprintk(4, "%p\n", av7110);
347 349
@@ -351,24 +353,30 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
351 } 353 }
352 354
353 start = jiffies; 355 start = jiffies;
354 while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 )) { 356 while (1) {
355 msleep(1); 357 err = time_after(jiffies, start + ARM_WAIT_FREE);
356 if (time_after(jiffies, start + ARM_WAIT_FREE)) { 358 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
359 break;
360 if (err) {
357 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __FUNCTION__); 361 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __FUNCTION__);
358 return -ETIMEDOUT; 362 return -ETIMEDOUT;
359 } 363 }
364 msleep(1);
360 } 365 }
361 366
362 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2); 367 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2);
363 368
364#ifndef _NOHANDSHAKE 369#ifndef _NOHANDSHAKE
365 start = jiffies; 370 start = jiffies;
366 while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 )) { 371 while (1) {
367 msleep(1); 372 err = time_after(jiffies, start + ARM_WAIT_SHAKE);
368 if (time_after(jiffies, start + ARM_WAIT_SHAKE)) { 373 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
374 break;
375 if (err) {
369 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __FUNCTION__); 376 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
370 return -ETIMEDOUT; 377 return -ETIMEDOUT;
371 } 378 }
379 msleep(1);
372 } 380 }
373#endif 381#endif
374 382
@@ -401,6 +409,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
401 /* non-immediate COMMAND type */ 409 /* non-immediate COMMAND type */
402 start = jiffies; 410 start = jiffies;
403 for (;;) { 411 for (;;) {
412 err = time_after(jiffies, start + ARM_WAIT_FREE);
404 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 413 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
405 if (stat & flags[0]) { 414 if (stat & flags[0]) {
406 printk(KERN_ERR "%s: %s QUEUE overflow\n", 415 printk(KERN_ERR "%s: %s QUEUE overflow\n",
@@ -409,10 +418,10 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
409 } 418 }
410 if ((stat & flags[1]) == 0) 419 if ((stat & flags[1]) == 0)
411 break; 420 break;
412 if (time_after(jiffies, start + ARM_WAIT_FREE)) { 421 if (err) {
413 printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n", 422 printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n",
414 __FUNCTION__, type); 423 __FUNCTION__, type);
415 return -1; 424 return -ETIMEDOUT;
416 } 425 }
417 msleep(1); 426 msleep(1);
418 } 427 }
@@ -432,13 +441,16 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
432 441
433#ifdef COM_DEBUG 442#ifdef COM_DEBUG
434 start = jiffies; 443 start = jiffies;
435 while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 )) { 444 while (1) {
436 msleep(1); 445 err = time_after(jiffies, start + ARM_WAIT_FREE);
437 if (time_after(jiffies, start + ARM_WAIT_FREE)) { 446 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
438 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND to complete\n", 447 break;
439 __FUNCTION__); 448 if (err) {
449 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND %d to complete\n",
450 __FUNCTION__, (buf[0] >> 8) & 0xff);
440 return -ETIMEDOUT; 451 return -ETIMEDOUT;
441 } 452 }
453 msleep(1);
442 } 454 }
443 455
444 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 456 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
@@ -470,7 +482,7 @@ static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
470 482
471 ret = __av7110_send_fw_cmd(av7110, buf, length); 483 ret = __av7110_send_fw_cmd(av7110, buf, length);
472 up(&av7110->dcomlock); 484 up(&av7110->dcomlock);
473 if (ret) 485 if (ret && ret!=-ERESTARTSYS)
474 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n", 486 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
475 __FUNCTION__, ret); 487 __FUNCTION__, ret);
476 return ret; 488 return ret;
@@ -495,7 +507,7 @@ int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
495 } 507 }
496 508
497 ret = av7110_send_fw_cmd(av7110, buf, num + 2); 509 ret = av7110_send_fw_cmd(av7110, buf, num + 2);
498 if (ret) 510 if (ret && ret != -ERESTARTSYS)
499 printk(KERN_ERR "dvb-ttpci: av7110_fw_cmd error %d\n", ret); 511 printk(KERN_ERR "dvb-ttpci: av7110_fw_cmd error %d\n", ret);
500 return ret; 512 return ret;
501} 513}
@@ -518,7 +530,7 @@ int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
518 } 530 }
519 531
520 ret = av7110_send_fw_cmd(av7110, cmd, 18); 532 ret = av7110_send_fw_cmd(av7110, cmd, 18);
521 if (ret) 533 if (ret && ret != -ERESTARTSYS)
522 printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret); 534 printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret);
523 return ret; 535 return ret;
524} 536}
@@ -551,26 +563,32 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
551 } 563 }
552 564
553 start = jiffies; 565 start = jiffies;
554 while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2)) { 566 while (1) {
555#ifdef _NOHANDSHAKE 567 err = time_after(jiffies, start + ARM_WAIT_FREE);
556 msleep(1); 568 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
557#endif 569 break;
558 if (time_after(jiffies, start + ARM_WAIT_FREE)) { 570 if (err) {
559 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__); 571 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
560 up(&av7110->dcomlock); 572 up(&av7110->dcomlock);
561 return -1; 573 return -ETIMEDOUT;
562 } 574 }
575#ifdef _NOHANDSHAKE
576 msleep(1);
577#endif
563 } 578 }
564 579
565#ifndef _NOHANDSHAKE 580#ifndef _NOHANDSHAKE
566 start = jiffies; 581 start = jiffies;
567 while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 )) { 582 while (1) {
568 msleep(1); 583 err = time_after(jiffies, start + ARM_WAIT_SHAKE);
569 if (time_after(jiffies, start + ARM_WAIT_SHAKE)) { 584 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
585 break;
586 if (err) {
570 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__); 587 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
571 up(&av7110->dcomlock); 588 up(&av7110->dcomlock);
572 return -1; 589 return -ETIMEDOUT;
573 } 590 }
591 msleep(1);
574 } 592 }
575#endif 593#endif
576 594
@@ -667,10 +685,10 @@ int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long bu
667 for (i = 0; i < len; i++) 685 for (i = 0; i < len; i++)
668 buf[i + 4] = msg[i]; 686 buf[i + 4] = msg[i];
669 687
670 if ((ret = av7110_send_fw_cmd(av7110, buf, 18))) 688 ret = av7110_send_fw_cmd(av7110, buf, 18);
689 if (ret && ret!=-ERESTARTSYS)
671 printk(KERN_ERR "dvb-ttpci: av7110_diseqc_send error %d\n", ret); 690 printk(KERN_ERR "dvb-ttpci: av7110_diseqc_send error %d\n", ret);
672 691 return ret;
673 return 0;
674} 692}
675 693
676 694
@@ -705,18 +723,22 @@ static inline int SetFont(struct av7110 *av7110, u8 windownr, u8 fontsize,
705static int FlushText(struct av7110 *av7110) 723static int FlushText(struct av7110 *av7110)
706{ 724{
707 unsigned long start; 725 unsigned long start;
726 int err;
708 727
709 if (down_interruptible(&av7110->dcomlock)) 728 if (down_interruptible(&av7110->dcomlock))
710 return -ERESTARTSYS; 729 return -ERESTARTSYS;
711 start = jiffies; 730 start = jiffies;
712 while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) { 731 while (1) {
713 msleep(1); 732 err = time_after(jiffies, start + ARM_WAIT_OSD);
714 if (time_after(jiffies, start + ARM_WAIT_OSD)) { 733 if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
734 break;
735 if (err) {
715 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n", 736 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
716 __FUNCTION__); 737 __FUNCTION__);
717 up(&av7110->dcomlock); 738 up(&av7110->dcomlock);
718 return -1; 739 return -ETIMEDOUT;
719 } 740 }
741 msleep(1);
720 } 742 }
721 up(&av7110->dcomlock); 743 up(&av7110->dcomlock);
722 return 0; 744 return 0;
@@ -733,25 +755,31 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
733 return -ERESTARTSYS; 755 return -ERESTARTSYS;
734 756
735 start = jiffies; 757 start = jiffies;
736 while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) { 758 while (1) {
737 msleep(1); 759 ret = time_after(jiffies, start + ARM_WAIT_OSD);
738 if (time_after(jiffies, start + ARM_WAIT_OSD)) { 760 if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
761 break;
762 if (ret) {
739 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n", 763 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
740 __FUNCTION__); 764 __FUNCTION__);
741 up(&av7110->dcomlock); 765 up(&av7110->dcomlock);
742 return -1; 766 return -ETIMEDOUT;
743 } 767 }
768 msleep(1);
744 } 769 }
745#ifndef _NOHANDSHAKE 770#ifndef _NOHANDSHAKE
746 start = jiffies; 771 start = jiffies;
747 while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2)) { 772 while (1) {
748 msleep(1); 773 ret = time_after(jiffies, start + ARM_WAIT_SHAKE);
749 if (time_after(jiffies, start + ARM_WAIT_SHAKE)) { 774 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
775 break;
776 if (ret) {
750 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n", 777 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
751 __FUNCTION__); 778 __FUNCTION__);
752 up(&av7110->dcomlock); 779 up(&av7110->dcomlock);
753 return -1; 780 return -ETIMEDOUT;
754 } 781 }
782 msleep(1);
755 } 783 }
756#endif 784#endif
757 for (i = 0; i < length / 2; i++) 785 for (i = 0; i < length / 2; i++)
@@ -761,7 +789,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
761 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2); 789 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
762 ret = __av7110_send_fw_cmd(av7110, cbuf, 5); 790 ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
763 up(&av7110->dcomlock); 791 up(&av7110->dcomlock);
764 if (ret) 792 if (ret && ret!=-ERESTARTSYS)
765 printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret); 793 printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret);
766 return ret; 794 return ret;
767} 795}
@@ -816,9 +844,25 @@ static osd_raw_window_t bpp2bit[8] = {
816 OSD_BITMAP1, OSD_BITMAP2, 0, OSD_BITMAP4, 0, 0, 0, OSD_BITMAP8 844 OSD_BITMAP1, OSD_BITMAP2, 0, OSD_BITMAP4, 0, 0, 0, OSD_BITMAP8
817}; 845};
818 846
819static inline int LoadBitmap(struct av7110 *av7110, u16 format, 847static inline int WaitUntilBmpLoaded(struct av7110 *av7110)
848{
849 int ret = wait_event_interruptible_timeout(av7110->bmpq,
850 av7110->bmp_state != BMP_LOADING, 10*HZ);
851 if (ret == -ERESTARTSYS)
852 return ret;
853 if (ret == 0) {
854 printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
855 ret, av7110->bmp_state);
856 av7110->bmp_state = BMP_NONE;
857 return -ETIMEDOUT;
858 }
859 return 0;
860}
861
862static inline int LoadBitmap(struct av7110 *av7110,
820 u16 dx, u16 dy, int inc, u8 __user * data) 863 u16 dx, u16 dy, int inc, u8 __user * data)
821{ 864{
865 u16 format;
822 int bpp; 866 int bpp;
823 int i; 867 int i;
824 int d, delta; 868 int d, delta;
@@ -827,14 +871,7 @@ static inline int LoadBitmap(struct av7110 *av7110, u16 format,
827 871
828 dprintk(4, "%p\n", av7110); 872 dprintk(4, "%p\n", av7110);
829 873
830 ret = wait_event_interruptible_timeout(av7110->bmpq, av7110->bmp_state != BMP_LOADING, HZ); 874 format = bpp2bit[av7110->osdbpp[av7110->osdwin]];
831 if (ret == -ERESTARTSYS || ret == 0) {
832 printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
833 ret, av7110->bmp_state);
834 av7110->bmp_state = BMP_NONE;
835 return -1;
836 }
837 BUG_ON (av7110->bmp_state == BMP_LOADING);
838 875
839 av7110->bmp_state = BMP_LOADING; 876 av7110->bmp_state = BMP_LOADING;
840 if (format == OSD_BITMAP8) { 877 if (format == OSD_BITMAP8) {
@@ -847,18 +884,18 @@ static inline int LoadBitmap(struct av7110 *av7110, u16 format,
847 bpp=1; delta = 8; 884 bpp=1; delta = 8;
848 } else { 885 } else {
849 av7110->bmp_state = BMP_NONE; 886 av7110->bmp_state = BMP_NONE;
850 return -1; 887 return -EINVAL;
851 } 888 }
852 av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8; 889 av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8;
853 av7110->bmpp = 0; 890 av7110->bmpp = 0;
854 if (av7110->bmplen > 32768) { 891 if (av7110->bmplen > 32768) {
855 av7110->bmp_state = BMP_NONE; 892 av7110->bmp_state = BMP_NONE;
856 return -1; 893 return -EINVAL;
857 } 894 }
858 for (i = 0; i < dy; i++) { 895 for (i = 0; i < dy; i++) {
859 if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) { 896 if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) {
860 av7110->bmp_state = BMP_NONE; 897 av7110->bmp_state = BMP_NONE;
861 return -1; 898 return -EINVAL;
862 } 899 }
863 } 900 }
864 if (format != OSD_BITMAP8) { 901 if (format != OSD_BITMAP8) {
@@ -873,37 +910,27 @@ static inline int LoadBitmap(struct av7110 *av7110, u16 format,
873 } 910 }
874 av7110->bmplen += 1024; 911 av7110->bmplen += 1024;
875 dprintk(4, "av7110_fw_cmd: LoadBmp size %d\n", av7110->bmplen); 912 dprintk(4, "av7110_fw_cmd: LoadBmp size %d\n", av7110->bmplen);
876 return av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy); 913 ret = av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy);
914 if (!ret)
915 ret = WaitUntilBmpLoaded(av7110);
916 return ret;
877} 917}
878 918
879static int BlitBitmap(struct av7110 *av7110, u16 win, u16 x, u16 y, u16 trans) 919static int BlitBitmap(struct av7110 *av7110, u16 x, u16 y)
880{ 920{
881 int ret;
882
883 dprintk(4, "%p\n", av7110); 921 dprintk(4, "%p\n", av7110);
884 922
885 BUG_ON (av7110->bmp_state == BMP_NONE); 923 return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, av7110->osdwin, x, y, 0);
886
887 ret = wait_event_interruptible_timeout(av7110->bmpq,
888 av7110->bmp_state != BMP_LOADING, 10*HZ);
889 if (ret == -ERESTARTSYS || ret == 0) {
890 printk("dvb-ttpci: warning: timeout waiting in BlitBitmap: %d, %d\n",
891 ret, av7110->bmp_state);
892 av7110->bmp_state = BMP_NONE;
893 return (ret == 0) ? -ETIMEDOUT : ret;
894 }
895
896 BUG_ON (av7110->bmp_state != BMP_LOADED);
897
898 return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, win, x, y, trans);
899} 924}
900 925
901static inline int ReleaseBitmap(struct av7110 *av7110) 926static inline int ReleaseBitmap(struct av7110 *av7110)
902{ 927{
903 dprintk(4, "%p\n", av7110); 928 dprintk(4, "%p\n", av7110);
904 929
905 if (av7110->bmp_state != BMP_LOADED) 930 if (av7110->bmp_state != BMP_LOADED && FW_VERSION(av7110->arm_app) < 0x261e)
906 return -1; 931 return -1;
932 if (av7110->bmp_state == BMP_LOADING)
933 dprintk(1,"ReleaseBitmap called while BMP_LOADING\n");
907 av7110->bmp_state = BMP_NONE; 934 av7110->bmp_state = BMP_NONE;
908 return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0); 935 return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0);
909} 936}
@@ -924,18 +951,22 @@ static u32 RGB2YUV(u16 R, u16 G, u16 B)
924 return Cr | (Cb << 16) | (Y << 8); 951 return Cr | (Cb << 16) | (Y << 8);
925} 952}
926 953
927static void OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend) 954static int OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend)
928{ 955{
956 int ret;
957
929 u16 ch, cl; 958 u16 ch, cl;
930 u32 yuv; 959 u32 yuv;
931 960
932 yuv = blend ? RGB2YUV(r,g,b) : 0; 961 yuv = blend ? RGB2YUV(r,g,b) : 0;
933 cl = (yuv & 0xffff); 962 cl = (yuv & 0xffff);
934 ch = ((yuv >> 16) & 0xffff); 963 ch = ((yuv >> 16) & 0xffff);
935 SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]], 964 ret = SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
936 color, ch, cl); 965 color, ch, cl);
937 SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]], 966 if (!ret)
938 color, ((blend >> 4) & 0x0f)); 967 ret = SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
968 color, ((blend >> 4) & 0x0f));
969 return ret;
939} 970}
940 971
941static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last) 972static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last)
@@ -968,14 +999,14 @@ static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
968{ 999{
969 uint w, h, bpp, bpl, size, lpb, bnum, brest; 1000 uint w, h, bpp, bpl, size, lpb, bnum, brest;
970 int i; 1001 int i;
971 int rc; 1002 int rc,release_rc;
972 1003
973 w = x1 - x0 + 1; 1004 w = x1 - x0 + 1;
974 h = y1 - y0 + 1; 1005 h = y1 - y0 + 1;
975 if (inc <= 0) 1006 if (inc <= 0)
976 inc = w; 1007 inc = w;
977 if (w <= 0 || w > 720 || h <= 0 || h > 576) 1008 if (w <= 0 || w > 720 || h <= 0 || h > 576)
978 return -1; 1009 return -EINVAL;
979 bpp = av7110->osdbpp[av7110->osdwin] + 1; 1010 bpp = av7110->osdbpp[av7110->osdwin] + 1;
980 bpl = ((w * bpp + 7) & ~7) / 8; 1011 bpl = ((w * bpp + 7) & ~7) / 8;
981 size = h * bpl; 1012 size = h * bpl;
@@ -983,176 +1014,186 @@ static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
983 bnum = size / (lpb * bpl); 1014 bnum = size / (lpb * bpl);
984 brest = size - bnum * lpb * bpl; 1015 brest = size - bnum * lpb * bpl;
985 1016
986 for (i = 0; i < bnum; i++) { 1017 if (av7110->bmp_state == BMP_LOADING) {
987 rc = LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]], 1018 /* possible if syscall is repeated by -ERESTARTSYS and if firmware cannot abort */
988 w, lpb, inc, data); 1019 BUG_ON (FW_VERSION(av7110->arm_app) >= 0x261e);
989 if (rc) 1020 rc = WaitUntilBmpLoaded(av7110);
990 return rc;
991 rc = BlitBitmap(av7110, av7110->osdwin, x0, y0 + i * lpb, 0);
992 if (rc) 1021 if (rc)
993 return rc; 1022 return rc;
994 data += lpb * inc; 1023 /* just continue. This should work for all fw versions
1024 * if bnum==1 && !brest && LoadBitmap was successful
1025 */
995 } 1026 }
996 if (brest) { 1027
997 rc = LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]], 1028 rc = 0;
998 w, brest / bpl, inc, data); 1029 for (i = 0; i < bnum; i++) {
1030 rc = LoadBitmap(av7110, w, lpb, inc, data);
999 if (rc) 1031 if (rc)
1000 return rc; 1032 break;
1001 rc = BlitBitmap(av7110, av7110->osdwin, x0, y0 + bnum * lpb, 0); 1033 rc = BlitBitmap(av7110, x0, y0 + i * lpb);
1002 if (rc) 1034 if (rc)
1003 return rc; 1035 break;
1036 data += lpb * inc;
1004 } 1037 }
1005 ReleaseBitmap(av7110); 1038 if (!rc && brest) {
1006 return 0; 1039 rc = LoadBitmap(av7110, w, brest / bpl, inc, data);
1040 if (!rc)
1041 rc = BlitBitmap(av7110, x0, y0 + bnum * lpb);
1042 }
1043 release_rc = ReleaseBitmap(av7110);
1044 if (!rc)
1045 rc = release_rc;
1046 if (rc)
1047 dprintk(1,"returns %d\n",rc);
1048 return rc;
1007} 1049}
1008 1050
1009int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc) 1051int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
1010{ 1052{
1011 int ret; 1053 int ret;
1012 1054
1013 ret = down_interruptible(&av7110->osd_sema); 1055 if (down_interruptible(&av7110->osd_sema))
1014 if (ret)
1015 return -ERESTARTSYS; 1056 return -ERESTARTSYS;
1016 1057
1017 /* stupid, but OSD functions don't provide a return code anyway */
1018 ret = 0;
1019
1020 switch (dc->cmd) { 1058 switch (dc->cmd) {
1021 case OSD_Close: 1059 case OSD_Close:
1022 DestroyOSDWindow(av7110, av7110->osdwin); 1060 ret = DestroyOSDWindow(av7110, av7110->osdwin);
1023 goto out; 1061 break;
1024 case OSD_Open: 1062 case OSD_Open:
1025 av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7; 1063 av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7;
1026 CreateOSDWindow(av7110, av7110->osdwin, 1064 ret = CreateOSDWindow(av7110, av7110->osdwin,
1027 bpp2bit[av7110->osdbpp[av7110->osdwin]], 1065 bpp2bit[av7110->osdbpp[av7110->osdwin]],
1028 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1); 1066 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
1067 if (ret)
1068 break;
1029 if (!dc->data) { 1069 if (!dc->data) {
1030 MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0); 1070 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1031 SetColorBlend(av7110, av7110->osdwin); 1071 if (ret)
1072 break;
1073 ret = SetColorBlend(av7110, av7110->osdwin);
1032 } 1074 }
1033 goto out; 1075 break;
1034 case OSD_Show: 1076 case OSD_Show:
1035 MoveWindowRel(av7110, av7110->osdwin, 0, 0); 1077 ret = MoveWindowRel(av7110, av7110->osdwin, 0, 0);
1036 goto out; 1078 break;
1037 case OSD_Hide: 1079 case OSD_Hide:
1038 HideWindow(av7110, av7110->osdwin); 1080 ret = HideWindow(av7110, av7110->osdwin);
1039 goto out; 1081 break;
1040 case OSD_Clear: 1082 case OSD_Clear:
1041 DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0); 1083 ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0);
1042 goto out; 1084 break;
1043 case OSD_Fill: 1085 case OSD_Fill:
1044 DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color); 1086 ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color);
1045 goto out; 1087 break;
1046 case OSD_SetColor: 1088 case OSD_SetColor:
1047 OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1); 1089 ret = OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1);
1048 goto out; 1090 break;
1049 case OSD_SetPalette: 1091 case OSD_SetPalette:
1050 { 1092 if (FW_VERSION(av7110->arm_app) >= 0x2618)
1051 if (FW_VERSION(av7110->arm_app) >= 0x2618) {
1052 ret = OSDSetPalette(av7110, dc->data, dc->color, dc->x0); 1093 ret = OSDSetPalette(av7110, dc->data, dc->color, dc->x0);
1053 goto out; 1094 else {
1054 } else {
1055 int i, len = dc->x0-dc->color+1; 1095 int i, len = dc->x0-dc->color+1;
1056 u8 __user *colors = (u8 __user *)dc->data; 1096 u8 __user *colors = (u8 __user *)dc->data;
1057 u8 r, g, b, blend; 1097 u8 r, g, b, blend;
1058 1098 ret = 0;
1059 for (i = 0; i<len; i++) { 1099 for (i = 0; i<len; i++) {
1060 if (get_user(r, colors + i * 4) || 1100 if (get_user(r, colors + i * 4) ||
1061 get_user(g, colors + i * 4 + 1) || 1101 get_user(g, colors + i * 4 + 1) ||
1062 get_user(b, colors + i * 4 + 2) || 1102 get_user(b, colors + i * 4 + 2) ||
1063 get_user(blend, colors + i * 4 + 3)) { 1103 get_user(blend, colors + i * 4 + 3)) {
1064 ret = -EFAULT; 1104 ret = -EFAULT;
1065 goto out; 1105 break;
1066 } 1106 }
1067 OSDSetColor(av7110, dc->color + i, r, g, b, blend); 1107 ret = OSDSetColor(av7110, dc->color + i, r, g, b, blend);
1108 if (ret)
1109 break;
1068 } 1110 }
1069 } 1111 }
1070 ret = 0; 1112 break;
1071 goto out;
1072 }
1073 case OSD_SetTrans:
1074 goto out;
1075 case OSD_SetPixel: 1113 case OSD_SetPixel:
1076 DrawLine(av7110, av7110->osdwin, 1114 ret = DrawLine(av7110, av7110->osdwin,
1077 dc->x0, dc->y0, 0, 0, dc->color); 1115 dc->x0, dc->y0, 0, 0, dc->color);
1078 goto out; 1116 break;
1079 case OSD_GetPixel:
1080 goto out;
1081 case OSD_SetRow: 1117 case OSD_SetRow:
1082 dc->y1 = dc->y0; 1118 dc->y1 = dc->y0;
1083 /* fall through */ 1119 /* fall through */
1084 case OSD_SetBlock: 1120 case OSD_SetBlock:
1085 ret = OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data); 1121 ret = OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data);
1086 goto out; 1122 break;
1087 case OSD_FillRow: 1123 case OSD_FillRow:
1088 DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0, 1124 ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
1089 dc->x1-dc->x0+1, dc->y1, dc->color); 1125 dc->x1-dc->x0+1, dc->y1, dc->color);
1090 goto out; 1126 break;
1091 case OSD_FillBlock: 1127 case OSD_FillBlock:
1092 DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0, 1128 ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
1093 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color); 1129 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color);
1094 goto out; 1130 break;
1095 case OSD_Line: 1131 case OSD_Line:
1096 DrawLine(av7110, av7110->osdwin, 1132 ret = DrawLine(av7110, av7110->osdwin,
1097 dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color); 1133 dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color);
1098 goto out; 1134 break;
1099 case OSD_Query:
1100 goto out;
1101 case OSD_Test:
1102 goto out;
1103 case OSD_Text: 1135 case OSD_Text:
1104 { 1136 {
1105 char textbuf[240]; 1137 char textbuf[240];
1106 1138
1107 if (strncpy_from_user(textbuf, dc->data, 240) < 0) { 1139 if (strncpy_from_user(textbuf, dc->data, 240) < 0) {
1108 ret = -EFAULT; 1140 ret = -EFAULT;
1109 goto out; 1141 break;
1110 } 1142 }
1111 textbuf[239] = 0; 1143 textbuf[239] = 0;
1112 if (dc->x1 > 3) 1144 if (dc->x1 > 3)
1113 dc->x1 = 3; 1145 dc->x1 = 3;
1114 SetFont(av7110, av7110->osdwin, dc->x1, 1146 ret = SetFont(av7110, av7110->osdwin, dc->x1,
1115 (u16) (dc->color & 0xffff), (u16) (dc->color >> 16)); 1147 (u16) (dc->color & 0xffff), (u16) (dc->color >> 16));
1116 FlushText(av7110); 1148 if (!ret)
1117 WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf); 1149 ret = FlushText(av7110);
1118 goto out; 1150 if (!ret)
1151 ret = WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf);
1152 break;
1119 } 1153 }
1120 case OSD_SetWindow: 1154 case OSD_SetWindow:
1121 if (dc->x0 < 1 || dc->x0 > 7) { 1155 if (dc->x0 < 1 || dc->x0 > 7)
1122 ret = -EINVAL; 1156 ret = -EINVAL;
1123 goto out; 1157 else {
1158 av7110->osdwin = dc->x0;
1159 ret = 0;
1124 } 1160 }
1125 av7110->osdwin = dc->x0; 1161 break;
1126 goto out;
1127 case OSD_MoveWindow: 1162 case OSD_MoveWindow:
1128 MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0); 1163 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1129 SetColorBlend(av7110, av7110->osdwin); 1164 if (!ret)
1130 goto out; 1165 ret = SetColorBlend(av7110, av7110->osdwin);
1166 break;
1131 case OSD_OpenRaw: 1167 case OSD_OpenRaw:
1132 if (dc->color < OSD_BITMAP1 || dc->color > OSD_CURSOR) { 1168 if (dc->color < OSD_BITMAP1 || dc->color > OSD_CURSOR) {
1133 ret = -EINVAL; 1169 ret = -EINVAL;
1134 goto out; 1170 break;
1135 } 1171 }
1136 if (dc->color >= OSD_BITMAP1 && dc->color <= OSD_BITMAP8HR) { 1172 if (dc->color >= OSD_BITMAP1 && dc->color <= OSD_BITMAP8HR)
1137 av7110->osdbpp[av7110->osdwin] = (1 << (dc->color & 3)) - 1; 1173 av7110->osdbpp[av7110->osdwin] = (1 << (dc->color & 3)) - 1;
1138 } 1174 else
1139 else {
1140 av7110->osdbpp[av7110->osdwin] = 0; 1175 av7110->osdbpp[av7110->osdwin] = 0;
1141 } 1176 ret = CreateOSDWindow(av7110, av7110->osdwin, (osd_raw_window_t)dc->color,
1142 CreateOSDWindow(av7110, av7110->osdwin, (osd_raw_window_t)dc->color,
1143 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1); 1177 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
1178 if (ret)
1179 break;
1144 if (!dc->data) { 1180 if (!dc->data) {
1145 MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0); 1181 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1146 SetColorBlend(av7110, av7110->osdwin); 1182 if (!ret)
1183 ret = SetColorBlend(av7110, av7110->osdwin);
1147 } 1184 }
1148 goto out; 1185 break;
1149 default: 1186 default:
1150 ret = -EINVAL; 1187 ret = -EINVAL;
1151 goto out; 1188 break;
1152 } 1189 }
1153 1190
1154out:
1155 up(&av7110->osd_sema); 1191 up(&av7110->osd_sema);
1192 if (ret==-ERESTARTSYS)
1193 dprintk(1, "av7110_osd_cmd(%d) returns with -ERESTARTSYS\n",dc->cmd);
1194 else if (ret)
1195 dprintk(1, "av7110_osd_cmd(%d) returns with %d\n",dc->cmd,ret);
1196
1156 return ret; 1197 return ret;
1157} 1198}
1158 1199
diff --git a/drivers/media/dvb/ttpci/av7110_hw.h b/drivers/media/dvb/ttpci/av7110_hw.h
index 52061e17c6dd..fedd20f9815d 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.h
+++ b/drivers/media/dvb/ttpci/av7110_hw.h
@@ -458,27 +458,27 @@ static inline int SendDAC(struct av7110 *av7110, u8 addr, u8 data)
458 return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, AudioDAC, 2, addr, data); 458 return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, AudioDAC, 2, addr, data);
459} 459}
460 460
461static inline void av7710_set_video_mode(struct av7110 *av7110, int mode) 461static inline int av7710_set_video_mode(struct av7110 *av7110, int mode)
462{ 462{
463 av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetVidMode, 1, mode); 463 return av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetVidMode, 1, mode);
464} 464}
465 465
466static int inline vidcom(struct av7110 *av7110, u32 com, u32 arg) 466static inline int vidcom(struct av7110 *av7110, u32 com, u32 arg)
467{ 467{
468 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_VIDEO_COMMAND, 4, 468 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_VIDEO_COMMAND, 4,
469 (com>>16), (com&0xffff), 469 (com>>16), (com&0xffff),
470 (arg>>16), (arg&0xffff)); 470 (arg>>16), (arg&0xffff));
471} 471}
472 472
473static int inline audcom(struct av7110 *av7110, u32 com) 473static inline int audcom(struct av7110 *av7110, u32 com)
474{ 474{
475 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_AUDIO_COMMAND, 2, 475 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_AUDIO_COMMAND, 2,
476 (com>>16), (com&0xffff)); 476 (com>>16), (com&0xffff));
477} 477}
478 478
479static inline void Set22K(struct av7110 *av7110, int state) 479static inline int Set22K(struct av7110 *av7110, int state)
480{ 480{
481 av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, (state ? ON22K : OFF22K), 0); 481 return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, (state ? ON22K : OFF22K), 0);
482} 482}
483 483
484 484
diff --git a/drivers/media/dvb/ttpci/av7110_ipack.c b/drivers/media/dvb/ttpci/av7110_ipack.c
index 246640741888..699ef8b5b99a 100644
--- a/drivers/media/dvb/ttpci/av7110_ipack.c
+++ b/drivers/media/dvb/ttpci/av7110_ipack.c
@@ -24,7 +24,7 @@ int av7110_ipack_init(struct ipack *p, int size,
24 void (*func)(u8 *buf, int size, void *priv)) 24 void (*func)(u8 *buf, int size, void *priv))
25{ 25{
26 if (!(p->buf = vmalloc(size*sizeof(u8)))) { 26 if (!(p->buf = vmalloc(size*sizeof(u8)))) {
27 printk ("Couldn't allocate memory for ipack\n"); 27 printk(KERN_WARNING "Couldn't allocate memory for ipack\n");
28 return -ENOMEM; 28 return -ENOMEM;
29 } 29 }
30 p->size = size; 30 p->size = size;
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 6e0f5d307c52..9746d2bb916f 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -570,9 +570,9 @@ static int philips_cu1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_p
570 570
571 buf[0] = (div >> 8) & 0x7f; 571 buf[0] = (div >> 8) & 0x7f;
572 buf[1] = div & 0xff; 572 buf[1] = div & 0xff;
573 buf[2] = 0x8e; 573 buf[2] = 0x86;
574 buf[3] = (params->frequency < 174500000 ? 0xa1 : 574 buf[3] = (params->frequency < 150000000 ? 0x01 :
575 params->frequency < 454000000 ? 0x92 : 0x34); 575 params->frequency < 445000000 ? 0x02 : 0x04);
576 576
577 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1) 577 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
578 return -EIO; 578 return -EIO;
@@ -695,8 +695,12 @@ static struct tda1004x_config philips_tu1216_config = {
695 .demod_address = 0x8, 695 .demod_address = 0x8,
696 .invert = 1, 696 .invert = 1,
697 .invert_oclk = 1, 697 .invert_oclk = 1,
698 .xtal_freq = TDA10046_XTAL_4M,
699 .agc_config = TDA10046_AGC_DEFAULT,
700 .if_freq = TDA10046_FREQ_3617,
698 .pll_init = philips_tu1216_pll_init, 701 .pll_init = philips_tu1216_pll_init,
699 .pll_set = philips_tu1216_pll_set, 702 .pll_set = philips_tu1216_pll_set,
703 .pll_sleep = NULL,
700 .request_firmware = philips_tu1216_request_firmware, 704 .request_firmware = philips_tu1216_request_firmware,
701}; 705};
702 706
@@ -1018,7 +1022,7 @@ static struct pci_device_id pci_tbl[] = {
1018MODULE_DEVICE_TABLE(pci, pci_tbl); 1022MODULE_DEVICE_TABLE(pci, pci_tbl);
1019 1023
1020static struct saa7146_extension budget_extension = { 1024static struct saa7146_extension budget_extension = {
1021 .name = "budget dvb /w video in\0", 1025 .name = "budget_av",
1022 .pci_tbl = pci_tbl, 1026 .pci_tbl = pci_tbl,
1023 1027
1024 .module = THIS_MODULE, 1028 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index dce116111376..a1267054bc01 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -69,6 +69,7 @@ struct budget_ci {
69 int slot_status; 69 int slot_status;
70 struct dvb_ca_en50221 ca; 70 struct dvb_ca_en50221 ca;
71 char ir_dev_name[50]; 71 char ir_dev_name[50];
72 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
72}; 73};
73 74
74/* from reading the following remotes: 75/* from reading the following remotes:
@@ -723,7 +724,7 @@ static int philips_tdm1316l_pll_init(struct dvb_frontend *fe)
723 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; 724 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
724 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab }; 725 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
725 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; 726 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
726 struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = td1316_init,.len = 727 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
727 sizeof(td1316_init) }; 728 sizeof(td1316_init) };
728 729
729 // setup PLL configuration 730 // setup PLL configuration
@@ -746,7 +747,7 @@ static int philips_tdm1316l_pll_set(struct dvb_frontend *fe, struct dvb_frontend
746{ 747{
747 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; 748 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
748 u8 tuner_buf[4]; 749 u8 tuner_buf[4];
749 struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) }; 750 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
750 int tuner_frequency = 0; 751 int tuner_frequency = 0;
751 u8 band, cp, filter; 752 u8 band, cp, filter;
752 753
@@ -838,8 +839,12 @@ static struct tda1004x_config philips_tdm1316l_config = {
838 .demod_address = 0x8, 839 .demod_address = 0x8,
839 .invert = 0, 840 .invert = 0,
840 .invert_oclk = 0, 841 .invert_oclk = 0,
842 .xtal_freq = TDA10046_XTAL_4M,
843 .agc_config = TDA10046_AGC_DEFAULT,
844 .if_freq = TDA10046_FREQ_3617,
841 .pll_init = philips_tdm1316l_pll_init, 845 .pll_init = philips_tdm1316l_pll_init,
842 .pll_set = philips_tdm1316l_pll_set, 846 .pll_set = philips_tdm1316l_pll_set,
847 .pll_sleep = NULL,
843 .request_firmware = philips_tdm1316l_request_firmware, 848 .request_firmware = philips_tdm1316l_request_firmware,
844}; 849};
845 850
@@ -865,12 +870,22 @@ static void frontend_init(struct budget_ci *budget_ci)
865 break; 870 break;
866 871
867 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) 872 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
873 budget_ci->tuner_pll_address = 0x63;
868 budget_ci->budget.dvb_frontend = 874 budget_ci->budget.dvb_frontend =
869 tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap); 875 tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
870 if (budget_ci->budget.dvb_frontend) { 876 if (budget_ci->budget.dvb_frontend) {
871 break; 877 break;
872 } 878 }
873 break; 879 break;
880
881 case 0x1012: // Hauppauge/TT Nova-T CI budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
882 budget_ci->tuner_pll_address = 0x60;
883 budget_ci->budget.dvb_frontend =
884 tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
885 if (budget_ci->budget.dvb_frontend) {
886 break;
887 }
888 break;
874 } 889 }
875 890
876 if (budget_ci->budget.dvb_frontend == NULL) { 891 if (budget_ci->budget.dvb_frontend == NULL) {
@@ -950,11 +965,13 @@ static struct saa7146_extension budget_extension;
950 965
951MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC); 966MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
952MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); 967MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
968MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
953 969
954static struct pci_device_id pci_tbl[] = { 970static struct pci_device_id pci_tbl[] = {
955 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c), 971 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
956 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f), 972 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
957 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011), 973 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
974 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
958 { 975 {
959 .vendor = 0, 976 .vendor = 0,
960 } 977 }
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 083fd44e5f90..9961917e8a7f 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -40,6 +40,7 @@
40#include "ves1820.h" 40#include "ves1820.h"
41#include "l64781.h" 41#include "l64781.h"
42#include "tda8083.h" 42#include "tda8083.h"
43#include "s5h1420.h"
43 44
44static void Set22K (struct budget *budget, int state) 45static void Set22K (struct budget *budget, int state)
45{ 46{
@@ -177,6 +178,62 @@ static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t m
177 return 0; 178 return 0;
178} 179}
179 180
181static int lnbp21_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
182{
183 struct budget* budget = (struct budget*) fe->dvb->priv;
184 u8 buf;
185 struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) };
186
187 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
188
189 switch(voltage) {
190 case SEC_VOLTAGE_13:
191 buf = (buf & 0xf7) | 0x04;
192 break;
193
194 case SEC_VOLTAGE_18:
195 buf = (buf & 0xf7) | 0x0c;
196 break;
197
198 case SEC_VOLTAGE_OFF:
199 buf = buf & 0xf0;
200 break;
201 }
202
203 msg.flags = 0;
204 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
205
206 return 0;
207}
208
209static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend* fe, int arg)
210{
211 struct budget* budget = (struct budget*) fe->dvb->priv;
212 u8 buf;
213 struct i2c_msg msg = { .addr = 0x08, .flags = I2C_M_RD, .buf = &buf, .len = sizeof(buf) };
214
215 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
216
217 if (arg) {
218 buf = buf | 0x10;
219 } else {
220 buf = buf & 0xef;
221 }
222
223 msg.flags = 0;
224 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
225
226 return 0;
227}
228
229static void lnbp21_init(struct budget* budget)
230{
231 u8 buf = 0x00;
232 struct i2c_msg msg = { .addr = 0x08, .flags = 0, .buf = &buf, .len = sizeof(buf) };
233
234 i2c_transfer (&budget->i2c_adap, &msg, 1);
235}
236
180static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 237static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
181{ 238{
182 struct budget* budget = (struct budget*) fe->dvb->priv; 239 struct budget* budget = (struct budget*) fe->dvb->priv;
@@ -395,6 +452,38 @@ static struct tda8083_config grundig_29504_451_config = {
395 .pll_set = grundig_29504_451_pll_set, 452 .pll_set = grundig_29504_451_pll_set,
396}; 453};
397 454
455static int s5h1420_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u32* freqout)
456{
457 struct budget* budget = (struct budget*) fe->dvb->priv;
458 u32 div;
459 u8 data[4];
460 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
461
462 div = params->frequency / 1000;
463 data[0] = (div >> 8) & 0x7f;
464 data[1] = div & 0xff;
465 data[2] = 0xc2;
466
467 if (div < 1450)
468 data[3] = 0x00;
469 else if (div < 1850)
470 data[3] = 0x40;
471 else if (div < 2000)
472 data[3] = 0x80;
473 else
474 data[3] = 0xc0;
475
476 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
477
478 *freqout = div * 1000;
479 return 0;
480}
481
482static struct s5h1420_config s5h1420_config = {
483 .demod_address = 0x53,
484 .pll_set = s5h1420_pll_set,
485};
486
398static u8 read_pwm(struct budget* budget) 487static u8 read_pwm(struct budget* budget)
399{ 488{
400 u8 b = 0xff; 489 u8 b = 0xff;
@@ -459,6 +548,15 @@ static void frontend_init(struct budget *budget)
459 break; 548 break;
460 } 549 }
461 break; 550 break;
551
552 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
553 budget->dvb_frontend = s5h1420_attach(&s5h1420_config, &budget->i2c_adap);
554 if (budget->dvb_frontend) {
555 budget->dvb_frontend->ops->set_voltage = lnbp21_set_voltage;
556 budget->dvb_frontend->ops->enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
557 lnbp21_init(budget);
558 break;
559 }
462 } 560 }
463 561
464 if (budget->dvb_frontend == NULL) { 562 if (budget->dvb_frontend == NULL) {
@@ -532,6 +630,7 @@ static struct pci_device_id pci_tbl[] = {
532 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004), 630 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
533 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005), 631 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
534 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013), 632 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
633 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
535 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), 634 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
536 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), 635 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
537 { 636 {
diff --git a/drivers/media/dvb/ttusb-budget/Kconfig b/drivers/media/dvb/ttusb-budget/Kconfig
index 4aa714ab4c28..c6c1d41a2efb 100644
--- a/drivers/media/dvb/ttusb-budget/Kconfig
+++ b/drivers/media/dvb/ttusb-budget/Kconfig
@@ -3,6 +3,7 @@ config DVB_TTUSB_BUDGET
3 depends on DVB_CORE && USB 3 depends on DVB_CORE && USB
4 select DVB_CX22700 4 select DVB_CX22700
5 select DVB_TDA1004X 5 select DVB_TDA1004X
6 select DVB_VES1820
6 select DVB_TDA8083 7 select DVB_TDA8083
7 select DVB_STV0299 8 select DVB_STV0299
8 help 9 help
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index afa0e7a0e506..aa43b5fcb8e7 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -24,6 +24,7 @@
24#include "dmxdev.h" 24#include "dmxdev.h"
25#include "dvb_demux.h" 25#include "dvb_demux.h"
26#include "dvb_net.h" 26#include "dvb_net.h"
27#include "ves1820.h"
27#include "cx22700.h" 28#include "cx22700.h"
28#include "tda1004x.h" 29#include "tda1004x.h"
29#include "stv0299.h" 30#include "stv0299.h"
@@ -1367,6 +1368,47 @@ static struct tda8083_config ttusb_novas_grundig_29504_491_config = {
1367 .pll_set = ttusb_novas_grundig_29504_491_pll_set, 1368 .pll_set = ttusb_novas_grundig_29504_491_pll_set,
1368}; 1369};
1369 1370
1371static int alps_tdbe2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1372{
1373 struct ttusb* ttusb = fe->dvb->priv;
1374 u32 div;
1375 u8 data[4];
1376 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
1377
1378 div = (params->frequency + 35937500 + 31250) / 62500;
1379
1380 data[0] = (div >> 8) & 0x7f;
1381 data[1] = div & 0xff;
1382 data[2] = 0x85 | ((div >> 10) & 0x60);
1383 data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
1384
1385 if (i2c_transfer (&ttusb->i2c_adap, &msg, 1) != 1)
1386 return -EIO;
1387
1388 return 0;
1389}
1390
1391
1392static struct ves1820_config alps_tdbe2_config = {
1393 .demod_address = 0x09,
1394 .xin = 57840000UL,
1395 .invert = 1,
1396 .selagc = VES1820_SELAGC_SIGNAMPERR,
1397 .pll_set = alps_tdbe2_pll_set,
1398};
1399
1400static u8 read_pwm(struct ttusb* ttusb)
1401{
1402 u8 b = 0xff;
1403 u8 pwm;
1404 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
1405 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
1406
1407 if ((i2c_transfer(&ttusb->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
1408 pwm = 0x48;
1409
1410 return pwm;
1411}
1370 1412
1371 1413
1372static void frontend_init(struct ttusb* ttusb) 1414static void frontend_init(struct ttusb* ttusb)
@@ -1394,6 +1436,12 @@ static void frontend_init(struct ttusb* ttusb)
1394 1436
1395 break; 1437 break;
1396 1438
1439 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1440 ttusb->fe = ves1820_attach(&alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));
1441 if (ttusb->fe != NULL)
1442 break;
1443 break;
1444
1397 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??)) 1445 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1398 // try the ALPS TDMB7 first 1446 // try the ALPS TDMB7 first
1399 ttusb->fe = cx22700_attach(&alps_tdmb7_config, &ttusb->i2c_adap); 1447 ttusb->fe = cx22700_attach(&alps_tdmb7_config, &ttusb->i2c_adap);
@@ -1570,7 +1618,7 @@ static void ttusb_disconnect(struct usb_interface *intf)
1570 1618
1571static struct usb_device_id ttusb_table[] = { 1619static struct usb_device_id ttusb_table[] = {
1572 {USB_DEVICE(0xb48, 0x1003)}, 1620 {USB_DEVICE(0xb48, 0x1003)},
1573/* {USB_DEVICE(0xb48, 0x1004)},UNDEFINED HARDWARE - mail linuxtv.org list*/ /* to be confirmed ???? */ 1621 {USB_DEVICE(0xb48, 0x1004)},
1574 {USB_DEVICE(0xb48, 0x1005)}, 1622 {USB_DEVICE(0xb48, 0x1005)},
1575 {} 1623 {}
1576}; 1624};
@@ -1578,7 +1626,7 @@ static struct usb_device_id ttusb_table[] = {
1578MODULE_DEVICE_TABLE(usb, ttusb_table); 1626MODULE_DEVICE_TABLE(usb, ttusb_table);
1579 1627
1580static struct usb_driver ttusb_driver = { 1628static struct usb_driver ttusb_driver = {
1581 .name = "Technotrend/Hauppauge USB-Nova", 1629 .name = "ttusb",
1582 .probe = ttusb_probe, 1630 .probe = ttusb_probe,
1583 .disconnect = ttusb_disconnect, 1631 .disconnect = ttusb_disconnect,
1584 .id_table = ttusb_table, 1632 .id_table = ttusb_table,
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 505bdaff5a7e..45c9a9a08e4d 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -1281,6 +1281,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1281 if (firmware_size < 60) { 1281 if (firmware_size < 60) {
1282 printk("%s: firmware size too small for DSP code (%zu < 60).\n", 1282 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1283 __FUNCTION__, firmware_size); 1283 __FUNCTION__, firmware_size);
1284 release_firmware(fw_entry);
1284 return -1; 1285 return -1;
1285 } 1286 }
1286 1287
@@ -1294,6 +1295,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1294 printk("%s: crc32 check of DSP code failed (calculated " 1295 printk("%s: crc32 check of DSP code failed (calculated "
1295 "0x%08x != 0x%08x in file), file invalid.\n", 1296 "0x%08x != 0x%08x in file), file invalid.\n",
1296 __FUNCTION__, crc32_csum, crc32_check); 1297 __FUNCTION__, crc32_csum, crc32_check);
1298 release_firmware(fw_entry);
1297 return -1; 1299 return -1;
1298 } 1300 }
1299 memcpy(idstring, &firmware[36], 20); 1301 memcpy(idstring, &firmware[36], 20);
@@ -1308,15 +1310,19 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1308 1310
1309 result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL); 1311 result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
1310 1312
1311 if (result) 1313 if (result) {
1314 release_firmware(fw_entry);
1312 return result; 1315 return result;
1316 }
1313 1317
1314 trans_count = 0; 1318 trans_count = 0;
1315 j = 0; 1319 j = 0;
1316 1320
1317 b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL); 1321 b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL);
1318 if (b == NULL) 1322 if (b == NULL) {
1323 release_firmware(fw_entry);
1319 return -ENOMEM; 1324 return -ENOMEM;
1325 }
1320 1326
1321 for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) { 1327 for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) {
1322 size = firmware_size - i; 1328 size = firmware_size - i;
@@ -1345,6 +1351,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1345 1351
1346 result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL); 1352 result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
1347 1353
1354 release_firmware(fw_entry);
1348 kfree(b); 1355 kfree(b);
1349 1356
1350 return result; 1357 return result;
diff --git a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
index 1699cc9f6bb0..725af3af5b27 100644
--- a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
@@ -157,7 +157,8 @@ struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* conf
157 157
158 /* allocate memory for the internal state */ 158 /* allocate memory for the internal state */
159 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); 159 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
160 if (state == NULL) goto error; 160 if (state == NULL)
161 return NULL;
161 162
162 /* setup the state */ 163 /* setup the state */
163 state->config = config; 164 state->config = config;
@@ -167,10 +168,6 @@ struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* conf
167 state->frontend.ops = &state->ops; 168 state->frontend.ops = &state->ops;
168 state->frontend.demodulator_priv = state; 169 state->frontend.demodulator_priv = state;
169 return &state->frontend; 170 return &state->frontend;
170
171error:
172 kfree(state);
173 return NULL;
174} 171}
175 172
176static struct dvb_frontend_ops ttusbdecfe_dvbs_ops; 173static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
@@ -181,7 +178,8 @@ struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* conf
181 178
182 /* allocate memory for the internal state */ 179 /* allocate memory for the internal state */
183 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL); 180 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
184 if (state == NULL) goto error; 181 if (state == NULL)
182 return NULL;
185 183
186 /* setup the state */ 184 /* setup the state */
187 state->config = config; 185 state->config = config;
@@ -193,10 +191,6 @@ struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* conf
193 state->frontend.ops = &state->ops; 191 state->frontend.ops = &state->ops;
194 state->frontend.demodulator_priv = state; 192 state->frontend.demodulator_priv = state;
195 return &state->frontend; 193 return &state->frontend;
196
197error:
198 kfree(state);
199 return NULL;
200} 194}
201 195
202static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = { 196static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f9383e7f34ff..f461750c7646 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -7,19 +7,6 @@ menu "Video For Linux"
7 7
8comment "Video Adapters" 8comment "Video Adapters"
9 9
10config CONFIG_TUNER_MULTI_I2C
11 bool "Enable support for multiple I2C devices on Video Adapters (EXPERIMENTAL)"
12 depends on VIDEO_DEV && EXPERIMENTAL
13 ---help---
14 Some video adapters have more than one tuner inside. This patch
15 enables support for using more than one tuner. This is required
16 for some cards to allow tunning both video and radio.
17 It also improves I2C autodetection for these cards.
18
19 Only few tuners currently is supporting this. More to come.
20
21 It is safe to say 'Y' here even if your card has only one I2C tuner.
22
23config VIDEO_BT848 10config VIDEO_BT848
24 tristate "BT848 Video For Linux" 11 tristate "BT848 Video For Linux"
25 depends on VIDEO_DEV && PCI && I2C 12 depends on VIDEO_DEV && PCI && I2C
@@ -344,6 +331,7 @@ config VIDEO_CX88_DVB
344 select DVB_MT352 331 select DVB_MT352
345 select DVB_OR51132 332 select DVB_OR51132
346 select DVB_CX22702 333 select DVB_CX22702
334 select DVB_LGDT3302
347 ---help--- 335 ---help---
348 This adds support for DVB/ATSC cards based on the 336 This adds support for DVB/ATSC cards based on the
349 Connexant 2388x chip. 337 Connexant 2388x chip.
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 2dc906fdfa55..810e7aac0a53 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -7,8 +7,7 @@ bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
8zr36067-objs := zoran_procfs.o zoran_device.o \ 8zr36067-objs := zoran_procfs.o zoran_device.o \
9 zoran_driver.o zoran_card.o 9 zoran_driver.o zoran_card.o
10tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o 10tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o
11
12obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o 11obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o
13 12
14obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \ 13obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c
index 9a642c7de545..a070417e65e6 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt832.c
@@ -138,25 +138,13 @@ int bt832_init(struct i2c_client *i2c_client_s)
138 138
139 bt832_hexdump(i2c_client_s,buf); 139 bt832_hexdump(i2c_client_s,buf);
140 140
141#if 0
142 // Full 30/25 Frame rate
143 printk("Full 30/25 Frame rate\n");
144 buf[0]=BT832_VP_CONTROL0; // Reg.39
145 buf[1]= 0x00;
146 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
147 printk("bt832: i2c i/o error FFR: rc == %d (should be 2)\n",rc);
148
149 bt832_hexdump(i2c_client_s,buf);
150#endif
151 141
152#if 1
153 // for testing (even works when no camera attached) 142 // for testing (even works when no camera attached)
154 printk("bt832: *** Generate NTSC M Bars *****\n"); 143 printk("bt832: *** Generate NTSC M Bars *****\n");
155 buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42 144 buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
156 buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally 145 buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
157 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) 146 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
158 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc); 147 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
159#endif
160 148
161 printk("Bt832: Camera Present: %s\n", 149 printk("Bt832: Camera Present: %s\n",
162 (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no"); 150 (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 251092e7f19f..2dbf5ec43abd 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-cards.c,v 1.49 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-cards.c,v 1.53 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv-cards.c 4 bttv-cards.c
5 5
@@ -39,9 +39,6 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#include "bttvp.h" 41#include "bttvp.h"
42#if 0 /* not working yet */
43#include "bt832.h"
44#endif
45 42
46/* fwd decl */ 43/* fwd decl */
47static void boot_msp34xx(struct bttv *btv, int pin); 44static void boot_msp34xx(struct bttv *btv, int pin);
@@ -513,13 +510,8 @@ struct tvcard bttv_tvcards[] = {
513 .svhs = 2, 510 .svhs = 2,
514 .gpiomask = 0x01fe00, 511 .gpiomask = 0x01fe00,
515 .muxsel = { 2, 3, 1, 1}, 512 .muxsel = { 2, 3, 1, 1},
516#if 0
517 // old
518 .audiomux = { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 },
519#else
520 // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> 513 // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru>
521 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 }, 514 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
522#endif
523 .needs_tvaudio = 1, 515 .needs_tvaudio = 1,
524 .pll = PLL_28, 516 .pll = PLL_28,
525 .tuner_type = -1, 517 .tuner_type = -1,
@@ -766,14 +758,9 @@ struct tvcard bttv_tvcards[] = {
766 .tuner = 0, 758 .tuner = 0,
767 .svhs = 2, 759 .svhs = 2,
768 .muxsel = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector 760 .muxsel = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector
769#if 0
770 .gpiomask = 0xc33000,
771 .audiomux = { 0x422000,0x1000,0x0000,0x620000,0x800000 },
772#else
773 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 761 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
774 .gpiomask = 0xb33000, 762 .gpiomask = 0xb33000,
775 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 }, 763 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 },
776#endif
777 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !) 764 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
778 gpio23 -- hef4052:nEnable (0x800000) 765 gpio23 -- hef4052:nEnable (0x800000)
779 gpio12 -- hef4052:A1 766 gpio12 -- hef4052:A1
@@ -1603,20 +1590,11 @@ struct tvcard bttv_tvcards[] = {
1603 .video_inputs = 4, 1590 .video_inputs = 4,
1604 .audio_inputs = 1, 1591 .audio_inputs = 1,
1605 .tuner = -1, 1592 .tuner = -1,
1606#if 0 /* TODO ... */
1607 .svhs = OSPREY540_SVID_ANALOG,
1608 .muxsel = { [OSPREY540_COMP_ANALOG] = 2,
1609 [OSPREY540_SVID_ANALOG] = 3, },
1610#endif
1611 .pll = PLL_28, 1593 .pll = PLL_28,
1612 .tuner_type = -1, 1594 .tuner_type = -1,
1613 .no_msp34xx = 1, 1595 .no_msp34xx = 1,
1614 .no_tda9875 = 1, 1596 .no_tda9875 = 1,
1615 .no_tda7432 = 1, 1597 .no_tda7432 = 1,
1616#if 0 /* TODO ... */
1617 .muxsel_hook = osprey_540_muxsel,
1618 .picture_hook = osprey_540_set_picture,
1619#endif
1620},{ 1598},{
1621 1599
1622 /* ---- card 0x5C ---------------------------------- */ 1600 /* ---- card 0x5C ---------------------------------- */
@@ -2546,21 +2524,12 @@ static void eagle_muxsel(struct bttv *btv, unsigned int input)
2546 btaor((2)<<5, ~(3<<5), BT848_IFORM); 2524 btaor((2)<<5, ~(3<<5), BT848_IFORM);
2547 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]); 2525 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]);
2548 2526
2549#if 0
2550 /* svhs */
2551 /* wake chroma ADC */
2552 btand(~BT848_ADC_C_SLEEP, BT848_ADC);
2553 /* set to YC video */
2554 btor(BT848_CONTROL_COMP, BT848_E_CONTROL);
2555 btor(BT848_CONTROL_COMP, BT848_O_CONTROL);
2556#else
2557 /* composite */ 2527 /* composite */
2558 /* set chroma ADC to sleep */ 2528 /* set chroma ADC to sleep */
2559 btor(BT848_ADC_C_SLEEP, BT848_ADC); 2529 btor(BT848_ADC_C_SLEEP, BT848_ADC);
2560 /* set to composite video */ 2530 /* set to composite video */
2561 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL); 2531 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
2562 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL); 2532 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
2563#endif
2564 2533
2565 /* switch sync drive off */ 2534 /* switch sync drive off */
2566 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE); 2535 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
@@ -2813,10 +2782,18 @@ void __devinit bttv_init_card2(struct bttv *btv)
2813 btv->tuner_type = tuner[btv->c.nr]; 2782 btv->tuner_type = tuner[btv->c.nr];
2814 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type); 2783 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type);
2815 if (btv->pinnacle_id != UNSET) 2784 if (btv->pinnacle_id != UNSET)
2816 bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE, 2785 bttv_call_i2c_clients(btv, AUDC_CONFIG_PINNACLE,
2817 &btv->pinnacle_id); 2786 &btv->pinnacle_id);
2818 if (btv->tuner_type != UNSET) 2787 if (btv->tuner_type != UNSET) {
2819 bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type); 2788 struct tuner_setup tun_setup;
2789
2790 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2791 tun_setup.type = btv->tuner_type;
2792 tun_setup.addr = ADDR_UNSET;
2793
2794 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup);
2795 }
2796
2820 btv->svhs = bttv_tvcards[btv->c.type].svhs; 2797 btv->svhs = bttv_tvcards[btv->c.type].svhs;
2821 if (svhs[btv->c.nr] != UNSET) 2798 if (svhs[btv->c.nr] != UNSET)
2822 btv->svhs = svhs[btv->c.nr]; 2799 btv->svhs = svhs[btv->c.nr];
@@ -3125,14 +3102,6 @@ static int tuner_0_table[] = {
3125 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM, 3102 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM,
3126 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL, 3103 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL,
3127 TUNER_PHILIPS_FM1216ME_MK3 }; 3104 TUNER_PHILIPS_FM1216ME_MK3 };
3128#if 0
3129int tuner_0_fm_table[] = {
3130 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL,
3131 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
3132 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
3133 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
3134 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
3135#endif
3136 3105
3137static int tuner_1_table[] = { 3106static int tuner_1_table[] = {
3138 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL, 3107 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL,
@@ -3218,36 +3187,6 @@ static void __devinit boot_msp34xx(struct bttv *btv, int pin)
3218 3187
3219static void __devinit boot_bt832(struct bttv *btv) 3188static void __devinit boot_bt832(struct bttv *btv)
3220{ 3189{
3221#if 0 /* not working yet */
3222 int resetbit=0;
3223
3224 switch (btv->c.type) {
3225 case BTTV_PXELVWPLTVPAK:
3226 resetbit = 0x400000;
3227 break;
3228 case BTTV_MODTEC_205:
3229 resetbit = 1<<9;
3230 break;
3231 default:
3232 BUG();
3233 }
3234
3235 request_module("bt832");
3236 bttv_call_i2c_clients(btv, BT832_HEXDUMP, NULL);
3237
3238 printk("bttv%d: Reset Bt832 [line=0x%x]\n",btv->c.nr,resetbit);
3239 gpio_write(0);
3240 gpio_inout(resetbit, resetbit);
3241 udelay(5);
3242 gpio_bits(resetbit, resetbit);
3243 udelay(5);
3244 gpio_bits(resetbit, 0);
3245 udelay(5);
3246
3247 // bt832 on pixelview changes from i2c 0x8a to 0x88 after
3248 // being reset as above. So we must follow by this:
3249 bttv_call_i2c_clients(btv, BT832_REATTACH, NULL);
3250#endif
3251} 3190}
3252 3191
3253/* ----------------------------------------------------------------------- */ 3192/* ----------------------------------------------------------------------- */
@@ -3572,11 +3511,6 @@ void tea5757_set_freq(struct bttv *btv, unsigned short freq)
3572{ 3511{
3573 dprintk("tea5757_set_freq %d\n",freq); 3512 dprintk("tea5757_set_freq %d\n",freq);
3574 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */ 3513 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
3575#if 0
3576 /* breaks Miro PCTV */
3577 value = tea5757_read(btv);
3578 dprintk("bttv%d: tea5757 readback=0x%x\n",btv->c.nr,value);
3579#endif
3580} 3514}
3581 3515
3582 3516
@@ -3656,13 +3590,8 @@ gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set)
3656{ 3590{
3657 unsigned int val, con; 3591 unsigned int val, con;
3658 3592
3659#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3660 if (btv->radio_user) 3593 if (btv->radio_user)
3661 return; 3594 return;
3662#else
3663 if (btv->radio)
3664 return;
3665#endif
3666 3595
3667 val = gpio_read(); 3596 val = gpio_read();
3668 if (set) { 3597 if (set) {
@@ -3851,13 +3780,8 @@ pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set)
3851{ 3780{
3852 unsigned int val = 0; 3781 unsigned int val = 0;
3853 3782
3854#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3855 if (btv->radio_user) 3783 if (btv->radio_user)
3856 return; 3784 return;
3857#else
3858 if (btv->radio)
3859 return;
3860#endif
3861 3785
3862 if (set) { 3786 if (set) {
3863 if (v->mode & VIDEO_SOUND_MONO) { 3787 if (v->mode & VIDEO_SOUND_MONO) {
@@ -3888,13 +3812,8 @@ fv2000s_audio(struct bttv *btv, struct video_audio *v, int set)
3888{ 3812{
3889 unsigned int val = 0xffff; 3813 unsigned int val = 0xffff;
3890 3814
3891#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3892 if (btv->radio_user) 3815 if (btv->radio_user)
3893 return; 3816 return;
3894#else
3895 if (btv->radio)
3896 return;
3897#endif
3898 if (set) { 3817 if (set) {
3899 if (v->mode & VIDEO_SOUND_MONO) { 3818 if (v->mode & VIDEO_SOUND_MONO) {
3900 val = 0x0000; 3819 val = 0x0000;
@@ -4371,11 +4290,6 @@ void __devinit bttv_check_chipset(void)
4371 latency = 0x0A; 4290 latency = 0x0A;
4372#endif 4291#endif
4373 4292
4374#if 0
4375 /* print which chipset we have */
4376 while ((dev = pci_find_class(PCI_CLASS_BRIDGE_HOST << 8,dev)))
4377 printk(KERN_INFO "bttv: Host bridge is %s\n",pci_name(dev));
4378#endif
4379 4293
4380 /* print warnings about any quirks found */ 4294 /* print warnings about any quirks found */
4381 if (triton1) 4295 if (triton1)
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 290289a99757..51a0f6d68e73 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.38 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-driver.c,v 1.42 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -35,6 +35,7 @@
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/kdev_t.h> 37#include <linux/kdev_t.h>
38#include <linux/dma-mapping.h>
38 39
39#include <asm/io.h> 40#include <asm/io.h>
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
@@ -76,6 +77,9 @@ static unsigned int whitecrush_upper = 0xCF;
76static unsigned int whitecrush_lower = 0x7F; 77static unsigned int whitecrush_lower = 0x7F;
77static unsigned int vcr_hack = 0; 78static unsigned int vcr_hack = 0;
78static unsigned int irq_iswitch = 0; 79static unsigned int irq_iswitch = 0;
80static unsigned int uv_ratio = 50;
81static unsigned int full_luma_range = 0;
82static unsigned int coring = 0;
79 83
80/* API features (turn on/off stuff for testing) */ 84/* API features (turn on/off stuff for testing) */
81static unsigned int v4l2 = 1; 85static unsigned int v4l2 = 1;
@@ -106,6 +110,9 @@ module_param(adc_crush, int, 0444);
106module_param(whitecrush_upper, int, 0444); 110module_param(whitecrush_upper, int, 0444);
107module_param(whitecrush_lower, int, 0444); 111module_param(whitecrush_lower, int, 0444);
108module_param(vcr_hack, int, 0444); 112module_param(vcr_hack, int, 0444);
113module_param(uv_ratio, int, 0444);
114module_param(full_luma_range, int, 0444);
115module_param(coring, int, 0444);
109 116
110module_param_array(radio, int, NULL, 0444); 117module_param_array(radio, int, NULL, 0444);
111 118
@@ -124,6 +131,9 @@ MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is
124MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127"); 131MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127");
125MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)"); 132MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");
126MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler"); 133MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");
134MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50");
135MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)");
136MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)");
127 137
128MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards"); 138MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
129MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr"); 139MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
@@ -484,7 +494,10 @@ static const unsigned int BTTV_FORMATS = ARRAY_SIZE(bttv_formats);
484#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5) 494#define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5)
485#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6) 495#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6)
486#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7) 496#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7)
487#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 8) 497#define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8)
498#define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9)
499#define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10)
500#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11)
488 501
489static const struct v4l2_queryctrl no_ctl = { 502static const struct v4l2_queryctrl no_ctl = {
490 .name = "42", 503 .name = "42",
@@ -618,8 +631,32 @@ static const struct v4l2_queryctrl bttv_ctls[] = {
618 .step = 1, 631 .step = 1,
619 .default_value = 0x7F, 632 .default_value = 0x7F,
620 .type = V4L2_CTRL_TYPE_INTEGER, 633 .type = V4L2_CTRL_TYPE_INTEGER,
634 },{
635 .id = V4L2_CID_PRIVATE_UV_RATIO,
636 .name = "uv ratio",
637 .minimum = 0,
638 .maximum = 100,
639 .step = 1,
640 .default_value = 50,
641 .type = V4L2_CTRL_TYPE_INTEGER,
642 },{
643 .id = V4L2_CID_PRIVATE_FULL_LUMA_RANGE,
644 .name = "full luma range",
645 .minimum = 0,
646 .maximum = 1,
647 .type = V4L2_CTRL_TYPE_BOOLEAN,
648 },{
649 .id = V4L2_CID_PRIVATE_CORING,
650 .name = "coring",
651 .minimum = 0,
652 .maximum = 3,
653 .step = 1,
654 .default_value = 0,
655 .type = V4L2_CTRL_TYPE_INTEGER,
621 } 656 }
622 657
658
659
623}; 660};
624static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls); 661static const int BTTV_CTLS = ARRAY_SIZE(bttv_ctls);
625 662
@@ -662,12 +699,10 @@ int locked_btres(struct bttv *btv, int bit)
662static 699static
663void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits) 700void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
664{ 701{
665#if 1 /* DEBUG */
666 if ((fh->resources & bits) != bits) { 702 if ((fh->resources & bits) != bits) {
667 /* trying to free ressources not allocated by us ... */ 703 /* trying to free ressources not allocated by us ... */
668 printk("bttv: BUG! (btres)\n"); 704 printk("bttv: BUG! (btres)\n");
669 } 705 }
670#endif
671 down(&btv->reslock); 706 down(&btv->reslock);
672 fh->resources &= ~bits; 707 fh->resources &= ~bits;
673 btv->resources &= ~bits; 708 btv->resources &= ~bits;
@@ -833,8 +868,8 @@ static void bt848_sat(struct bttv *btv, int color)
833 btv->saturation = color; 868 btv->saturation = color;
834 869
835 /* 0-511 for the color */ 870 /* 0-511 for the color */
836 val_u = color >> 7; 871 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
837 val_v = ((color>>7)*180L)/254; 872 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
838 hibits = (val_u >> 7) & 2; 873 hibits = (val_u >> 7) & 2;
839 hibits |= (val_v >> 8) & 1; 874 hibits |= (val_v >> 8) & 1;
840 btwrite(val_u & 0xff, BT848_SAT_U_LO); 875 btwrite(val_u & 0xff, BT848_SAT_U_LO);
@@ -907,11 +942,6 @@ audio_mux(struct bttv *btv, int mode)
907 i2c_mux = mux = (btv->audio & AUDIO_MUTE) ? AUDIO_OFF : btv->audio; 942 i2c_mux = mux = (btv->audio & AUDIO_MUTE) ? AUDIO_OFF : btv->audio;
908 if (btv->opt_automute && !signal && !btv->radio_user) 943 if (btv->opt_automute && !signal && !btv->radio_user)
909 mux = AUDIO_OFF; 944 mux = AUDIO_OFF;
910#if 0
911 printk("bttv%d: amux: mode=%d audio=%d signal=%s mux=%d/%d irq=%s\n",
912 btv->c.nr, mode, btv->audio, signal ? "yes" : "no",
913 mux, i2c_mux, in_interrupt() ? "yes" : "no");
914#endif
915 945
916 val = bttv_tvcards[btv->c.type].audiomux[mux]; 946 val = bttv_tvcards[btv->c.type].audiomux[mux];
917 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,val); 947 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,val);
@@ -958,11 +988,6 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
958 case BTTV_VOODOOTV_FM: 988 case BTTV_VOODOOTV_FM:
959 bttv_tda9880_setnorm(btv,norm); 989 bttv_tda9880_setnorm(btv,norm);
960 break; 990 break;
961#if 0
962 case BTTV_OSPREY540:
963 osprey_540_set_norm(btv,norm);
964 break;
965#endif
966 } 991 }
967 return 0; 992 return 0;
968} 993}
@@ -1151,6 +1176,15 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1151 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER: 1176 case V4L2_CID_PRIVATE_WHITECRUSH_LOWER:
1152 c->value = btv->opt_whitecrush_lower; 1177 c->value = btv->opt_whitecrush_lower;
1153 break; 1178 break;
1179 case V4L2_CID_PRIVATE_UV_RATIO:
1180 c->value = btv->opt_uv_ratio;
1181 break;
1182 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1183 c->value = btv->opt_full_luma_range;
1184 break;
1185 case V4L2_CID_PRIVATE_CORING:
1186 c->value = btv->opt_coring;
1187 break;
1154 default: 1188 default:
1155 return -EINVAL; 1189 return -EINVAL;
1156 } 1190 }
@@ -1247,6 +1281,18 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1247 btv->opt_whitecrush_lower = c->value; 1281 btv->opt_whitecrush_lower = c->value;
1248 btwrite(c->value, BT848_WC_DOWN); 1282 btwrite(c->value, BT848_WC_DOWN);
1249 break; 1283 break;
1284 case V4L2_CID_PRIVATE_UV_RATIO:
1285 btv->opt_uv_ratio = c->value;
1286 bt848_sat(btv, btv->saturation);
1287 break;
1288 case V4L2_CID_PRIVATE_FULL_LUMA_RANGE:
1289 btv->opt_full_luma_range = c->value;
1290 btaor((c->value<<7), ~BT848_OFORM_RANGE, BT848_OFORM);
1291 break;
1292 case V4L2_CID_PRIVATE_CORING:
1293 btv->opt_coring = c->value;
1294 btaor((c->value<<5), ~BT848_OFORM_CORE32, BT848_OFORM);
1295 break;
1250 default: 1296 default:
1251 return -EINVAL; 1297 return -EINVAL;
1252 } 1298 }
@@ -1792,7 +1838,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1792 1838
1793 if (unlikely(f->tuner != 0)) 1839 if (unlikely(f->tuner != 0))
1794 return -EINVAL; 1840 return -EINVAL;
1795 if (unlikely(f->type != V4L2_TUNER_ANALOG_TV)) 1841 if (unlikely (f->type != V4L2_TUNER_ANALOG_TV))
1796 return -EINVAL; 1842 return -EINVAL;
1797 down(&btv->lock); 1843 down(&btv->lock);
1798 btv->freq = f->frequency; 1844 btv->freq = f->frequency;
@@ -3117,11 +3163,6 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
3117 return -EINVAL; 3163 return -EINVAL;
3118 memset(v,0,sizeof(*v)); 3164 memset(v,0,sizeof(*v));
3119 strcpy(v->name, "Radio"); 3165 strcpy(v->name, "Radio");
3120 /* japan: 76.0 MHz - 89.9 MHz
3121 western europe: 87.5 MHz - 108.0 MHz
3122 russia: 65.0 MHz - 108.0 MHz */
3123 v->rangelow=(int)(65*16);
3124 v->rangehigh=(int)(108*16);
3125 bttv_call_i2c_clients(btv,cmd,v); 3166 bttv_call_i2c_clients(btv,cmd,v);
3126 return 0; 3167 return 0;
3127 } 3168 }
@@ -3813,7 +3854,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3813 btv->c.nr); 3854 btv->c.nr);
3814 return -EIO; 3855 return -EIO;
3815 } 3856 }
3816 if (pci_set_dma_mask(dev, 0xffffffff)) { 3857 if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
3817 printk(KERN_WARNING "bttv%d: No suitable DMA available.\n", 3858 printk(KERN_WARNING "bttv%d: No suitable DMA available.\n",
3818 btv->c.nr); 3859 btv->c.nr);
3819 return -EIO; 3860 return -EIO;
@@ -3876,6 +3917,9 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3876 btv->opt_vcr_hack = vcr_hack; 3917 btv->opt_vcr_hack = vcr_hack;
3877 btv->opt_whitecrush_upper = whitecrush_upper; 3918 btv->opt_whitecrush_upper = whitecrush_upper;
3878 btv->opt_whitecrush_lower = whitecrush_lower; 3919 btv->opt_whitecrush_lower = whitecrush_lower;
3920 btv->opt_uv_ratio = uv_ratio;
3921 btv->opt_full_luma_range = full_luma_range;
3922 btv->opt_coring = coring;
3879 3923
3880 /* fill struct bttv with some useful defaults */ 3924 /* fill struct bttv with some useful defaults */
3881 btv->init.btv = btv; 3925 btv->init.btv = btv;
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c
index da448a5f9e9c..234a85563769 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bttv-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-i2c.c,v 1.21 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-i2c.c,v 1.25 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv-i2c.c -- all the i2c code is here 4 bttv-i2c.c -- all the i2c code is here
5 5
@@ -295,14 +295,26 @@ static int attach_inform(struct i2c_client *client)
295{ 295{
296 struct bttv *btv = i2c_get_adapdata(client->adapter); 296 struct bttv *btv = i2c_get_adapdata(client->adapter);
297 297
298 if (btv->tuner_type != UNSET) 298 if (bttv_debug)
299 bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type); 299 printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n",
300 btv->c.nr,client->driver->name,client->addr,
301 i2c_clientname(client));
302 if (!client->driver->command)
303 return 0;
304
305 if (btv->tuner_type != UNSET) {
306 struct tuner_setup tun_setup;
307
308 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
309 tun_setup.type = btv->tuner_type;
310 tun_setup.addr = ADDR_UNSET;
311
312 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
313 }
314
300 if (btv->pinnacle_id != UNSET) 315 if (btv->pinnacle_id != UNSET)
301 bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE, 316 client->driver->command(client,AUDC_CONFIG_PINNACLE,
302 &btv->pinnacle_id); 317 &btv->pinnacle_id);
303 if (bttv_debug)
304 printk("bttv%d: i2c attach [client=%s]\n",
305 btv->c.nr, i2c_clientname(client));
306 return 0; 318 return 0;
307} 319}
308 320
diff --git a/drivers/media/video/bttv-risc.c b/drivers/media/video/bttv-risc.c
index bdc5ce6c43b9..9ed21fd190c6 100644
--- a/drivers/media/video/bttv-risc.c
+++ b/drivers/media/video/bttv-risc.c
@@ -334,10 +334,6 @@ bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
334 } 334 }
335 335
336 vdelay = tvnorm->vdelay; 336 vdelay = tvnorm->vdelay;
337#if 0 /* FIXME */
338 if (vdelay < btv->vbi.lines*2)
339 vdelay = btv->vbi.lines*2;
340#endif
341 337
342 xsf = (width*scaledtwidth)/swidth; 338 xsf = (width*scaledtwidth)/swidth;
343 geo->hscale = ((totalwidth*4096UL)/xsf-4096); 339 geo->hscale = ((totalwidth*4096UL)/xsf-4096);
@@ -776,13 +772,8 @@ bttv_overlay_risc(struct bttv *btv,
776 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0); 772 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0);
777 break; 773 break;
778 case V4L2_FIELD_INTERLACED: 774 case V4L2_FIELD_INTERLACED:
779#if 0
780 bttv_risc_overlay(btv, &buf->top, fmt, ov, 1, 0);
781 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 1);
782#else
783 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1); 775 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1);
784 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0); 776 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0);
785#endif
786 break; 777 break;
787 default: 778 default:
788 BUG(); 779 BUG();
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index 7b6f1e856028..f3293e4a15ad 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttvp.h,v 1.17 2005/02/16 12:14:10 kraxel Exp $ 2 $Id: bttvp.h,v 1.19 2005/06/16 21:38:45 nsh Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -326,6 +326,9 @@ struct bttv {
326 int opt_vcr_hack; 326 int opt_vcr_hack;
327 int opt_whitecrush_upper; 327 int opt_whitecrush_upper;
328 int opt_whitecrush_lower; 328 int opt_whitecrush_lower;
329 int opt_uv_ratio;
330 int opt_full_luma_range;
331 int opt_coring;
329 332
330 /* radio data/state */ 333 /* radio data/state */
331 int has_radio; 334 int has_radio;
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 91f8afeded88..4f39688f780a 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -690,11 +690,9 @@ static void blackbird_codec_settings(struct cx8802_dev *dev)
690 int bitrate_mode = 1; 690 int bitrate_mode = 1;
691 int bitrate = 7500000; 691 int bitrate = 7500000;
692 int bitrate_peak = 7500000; 692 int bitrate_peak = 7500000;
693#if 1
694 bitrate_mode = BLACKBIRD_VIDEO_CBR; 693 bitrate_mode = BLACKBIRD_VIDEO_CBR;
695 bitrate = 4000*1024; 694 bitrate = 4000*1024;
696 bitrate_peak = 4000*1024; 695 bitrate_peak = 4000*1024;
697#endif
698 696
699 /* assign stream type */ 697 /* assign stream type */
700 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM); 698 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM);
@@ -810,9 +808,6 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
810 cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */ 808 cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */
811 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */ 809 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
812 810
813#if 0 /* FIXME */
814 set_scale(dev, 720, 480, V4L2_FIELD_INTERLACED);
815#endif
816 blackbird_codec_settings(dev); 811 blackbird_codec_settings(dev);
817 msleep(1); 812 msleep(1);
818 813
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index b3fb04356b71..3d0c784b376f 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-cards.c,v 1.76 2005/06/08 01:28:09 mchehab Exp $ 2 * $Id: cx88-cards.c,v 1.86 2005/07/14 03:06:43 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * card-specific stuff. 5 * card-specific stuff.
@@ -401,7 +401,7 @@ struct cx88_board cx88_boards[] = {
401 .dvb = 1, 401 .dvb = 1,
402 }, 402 },
403 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1] = { 403 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1] = {
404 .name = "DVICO FusionHDTV DVB-T1", 404 .name = "DViCO FusionHDTV DVB-T1",
405 .tuner_type = TUNER_ABSENT, /* No analog tuner */ 405 .tuner_type = TUNER_ABSENT, /* No analog tuner */
406 .radio_type = UNSET, 406 .radio_type = UNSET,
407 .tuner_addr = ADDR_UNSET, 407 .tuner_addr = ADDR_UNSET,
@@ -445,8 +445,8 @@ struct cx88_board cx88_boards[] = {
445 .gpio0 = 0x000007f8, 445 .gpio0 = 0x000007f8,
446 }, 446 },
447 }, 447 },
448 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD] = { 448 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q] = {
449 .name = "DViCO - FusionHDTV 3 Gold", 449 .name = "DViCO FusionHDTV 3 Gold-Q",
450 .tuner_type = TUNER_MICROTUNE_4042FI5, 450 .tuner_type = TUNER_MICROTUNE_4042FI5,
451 .radio_type = UNSET, 451 .radio_type = UNSET,
452 .tuner_addr = ADDR_UNSET, 452 .tuner_addr = ADDR_UNSET,
@@ -464,6 +464,9 @@ struct cx88_board cx88_boards[] = {
464 GPIO[3] selects RF input connector on tuner module 464 GPIO[3] selects RF input connector on tuner module
465 0 - RF connector labeled CABLE 465 0 - RF connector labeled CABLE
466 1 - RF connector labeled ANT 466 1 - RF connector labeled ANT
467 GPIO[4] selects high RF for QAM256 mode
468 0 - normal RF
469 1 - high RF
467 */ 470 */
468 .input = {{ 471 .input = {{
469 .type = CX88_VMUX_TELEVISION, 472 .type = CX88_VMUX_TELEVISION,
@@ -482,6 +485,7 @@ struct cx88_board cx88_boards[] = {
482 .vmux = 2, 485 .vmux = 2,
483 .gpio0 = 0x0f00, 486 .gpio0 = 0x0f00,
484 }}, 487 }},
488 .dvb = 1,
485 }, 489 },
486 [CX88_BOARD_HAUPPAUGE_DVB_T1] = { 490 [CX88_BOARD_HAUPPAUGE_DVB_T1] = {
487 .name = "Hauppauge Nova-T DVB-T", 491 .name = "Hauppauge Nova-T DVB-T",
@@ -520,7 +524,7 @@ struct cx88_board cx88_boards[] = {
520 .blackbird = 1, 524 .blackbird = 1,
521 }, 525 },
522 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS] = { 526 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS] = {
523 .name = "DVICO FusionHDTV DVB-T Plus", 527 .name = "DViCO FusionHDTV DVB-T Plus",
524 .tuner_type = TUNER_ABSENT, /* No analog tuner */ 528 .tuner_type = TUNER_ABSENT, /* No analog tuner */
525 .radio_type = UNSET, 529 .radio_type = UNSET,
526 .tuner_addr = ADDR_UNSET, 530 .tuner_addr = ADDR_UNSET,
@@ -678,9 +682,9 @@ struct cx88_board cx88_boards[] = {
678 .name = "PixelView PlayTV Ultra Pro (Stereo)", 682 .name = "PixelView PlayTV Ultra Pro (Stereo)",
679 /* May be also TUNER_YMEC_TVF_5533MF for NTSC/M or PAL/M */ 683 /* May be also TUNER_YMEC_TVF_5533MF for NTSC/M or PAL/M */
680 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 684 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
681 .radio_type = TUNER_TEA5767, 685 .radio_type = UNSET,
682 .tuner_addr = 0xc2>>1, 686 .tuner_addr = ADDR_UNSET,
683 .radio_addr = 0xc0>>1, 687 .radio_addr = ADDR_UNSET,
684 .input = {{ 688 .input = {{
685 .type = CX88_VMUX_TELEVISION, 689 .type = CX88_VMUX_TELEVISION,
686 .vmux = 0, 690 .vmux = 0,
@@ -700,21 +704,17 @@ struct cx88_board cx88_boards[] = {
700 }, 704 },
701 }, 705 },
702 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T] = { 706 [CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T] = {
703 .name = "DViCO - FusionHDTV 3 Gold-T", 707 .name = "DViCO FusionHDTV 3 Gold-T",
704 .tuner_type = TUNER_THOMSON_DTT7611, 708 .tuner_type = TUNER_THOMSON_DTT7611,
705 .radio_type = UNSET, 709 .radio_type = UNSET,
706 .tuner_addr = ADDR_UNSET, 710 .tuner_addr = ADDR_UNSET,
707 .radio_addr = ADDR_UNSET, 711 .radio_addr = ADDR_UNSET,
708 /* See DViCO FusionHDTV 3 Gold for GPIO documentation. */ 712 /* See DViCO FusionHDTV 3 Gold-Q for GPIO documentation. */
709 .input = {{ 713 .input = {{
710 .type = CX88_VMUX_TELEVISION, 714 .type = CX88_VMUX_TELEVISION,
711 .vmux = 0, 715 .vmux = 0,
712 .gpio0 = 0x0f0d, 716 .gpio0 = 0x0f0d,
713 },{ 717 },{
714 .type = CX88_VMUX_CABLE,
715 .vmux = 0,
716 .gpio0 = 0x0f05,
717 },{
718 .type = CX88_VMUX_COMPOSITE1, 718 .type = CX88_VMUX_COMPOSITE1,
719 .vmux = 1, 719 .vmux = 1,
720 .gpio0 = 0x0f00, 720 .gpio0 = 0x0f00,
@@ -723,7 +723,36 @@ struct cx88_board cx88_boards[] = {
723 .vmux = 2, 723 .vmux = 2,
724 .gpio0 = 0x0f00, 724 .gpio0 = 0x0f00,
725 }}, 725 }},
726 .dvb = 1,
726 }, 727 },
728 [CX88_BOARD_ADSTECH_DVB_T_PCI] = {
729 .name = "ADS Tech Instant TV DVB-T PCI",
730 .tuner_type = TUNER_ABSENT,
731 .radio_type = UNSET,
732 .tuner_addr = ADDR_UNSET,
733 .radio_addr = ADDR_UNSET,
734 .input = {{
735 .type = CX88_VMUX_COMPOSITE1,
736 .vmux = 1,
737 .gpio0 = 0x0700,
738 .gpio2 = 0x0101,
739 },{
740 .type = CX88_VMUX_SVIDEO,
741 .vmux = 2,
742 .gpio0 = 0x0700,
743 .gpio2 = 0x0101,
744 }},
745 .dvb = 1,
746 },
747 [CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1] = {
748 .name = "TerraTec Cinergy 1400 DVB-T",
749 .tuner_type = TUNER_ABSENT,
750 .input = {{
751 .type = CX88_VMUX_DVB,
752 .vmux = 0,
753 }},
754 .dvb = 1,
755 },
727}; 756};
728const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 757const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
729 758
@@ -794,7 +823,7 @@ struct cx88_subid cx88_subids[] = {
794 },{ 823 },{
795 .subvendor = 0x18ac, 824 .subvendor = 0x18ac,
796 .subdevice = 0xd810, 825 .subdevice = 0xd810,
797 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD, 826 .card = CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q,
798 },{ 827 },{
799 .subvendor = 0x18ac, 828 .subvendor = 0x18ac,
800 .subdevice = 0xd820, 829 .subdevice = 0xd820,
@@ -843,7 +872,15 @@ struct cx88_subid cx88_subids[] = {
843 .subvendor = 0x10fc, 872 .subvendor = 0x10fc,
844 .subdevice = 0xd035, 873 .subdevice = 0xd035,
845 .card = CX88_BOARD_IODATA_GVBCTV7E, 874 .card = CX88_BOARD_IODATA_GVBCTV7E,
846 } 875 },{
876 .subvendor = 0x1421,
877 .subdevice = 0x0334,
878 .card = CX88_BOARD_ADSTECH_DVB_T_PCI,
879 },{
880 .subvendor = 0x153b,
881 .subdevice = 0x1166,
882 .card = CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1,
883 },
847}; 884};
848const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids); 885const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
849 886
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index c046a23537d3..5e868f5cd0c0 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-core.c,v 1.28 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: cx88-core.c,v 1.33 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * driver core 5 * driver core
@@ -470,25 +470,6 @@ int cx88_risc_decode(u32 risc)
470 return incr[risc >> 28] ? incr[risc >> 28] : 1; 470 return incr[risc >> 28] ? incr[risc >> 28] : 1;
471} 471}
472 472
473#if 0 /* currently unused, but useful for debugging */
474void cx88_risc_disasm(struct cx88_core *core,
475 struct btcx_riscmem *risc)
476{
477 unsigned int i,j,n;
478
479 printk("%s: risc disasm: %p [dma=0x%08lx]\n",
480 core->name, risc->cpu, (unsigned long)risc->dma);
481 for (i = 0; i < (risc->size >> 2); i += n) {
482 printk("%s: %04d: ", core->name, i);
483 n = cx88_risc_decode(risc->cpu[i]);
484 for (j = 1; j < n; j++)
485 printk("%s: %04d: 0x%08x [ arg #%d ]\n",
486 core->name, i+j, risc->cpu[i+j], j);
487 if (risc->cpu[i] == RISC_JUMP)
488 break;
489 }
490}
491#endif
492 473
493void cx88_sram_channel_dump(struct cx88_core *core, 474void cx88_sram_channel_dump(struct cx88_core *core,
494 struct sram_channel *ch) 475 struct sram_channel *ch)
@@ -551,21 +532,6 @@ static char *cx88_pci_irqs[32] = {
551 "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err", 532 "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err",
552 "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1" 533 "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1"
553}; 534};
554char *cx88_vid_irqs[32] = {
555 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
556 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
557 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
558 "y_sync", "u_sync", "v_sync", "vbi_sync",
559 "opc_err", "par_err", "rip_err", "pci_abort",
560};
561char *cx88_mpeg_irqs[32] = {
562 "ts_risci1", NULL, NULL, NULL,
563 "ts_risci2", NULL, NULL, NULL,
564 "ts_oflow", NULL, NULL, NULL,
565 "ts_sync", NULL, NULL, NULL,
566 "opc_err", "par_err", "rip_err", "pci_abort",
567 "ts_err?",
568};
569 535
570void cx88_print_irqbits(char *name, char *tag, char **strings, 536void cx88_print_irqbits(char *name, char *tag, char **strings,
571 u32 bits, u32 mask) 537 u32 bits, u32 mask)
@@ -615,16 +581,11 @@ void cx88_wakeup(struct cx88_core *core,
615 break; 581 break;
616 buf = list_entry(q->active.next, 582 buf = list_entry(q->active.next,
617 struct cx88_buffer, vb.queue); 583 struct cx88_buffer, vb.queue);
618#if 0
619 if (buf->count > count)
620 break;
621#else
622 /* count comes from the hw and is is 16bit wide -- 584 /* count comes from the hw and is is 16bit wide --
623 * this trick handles wrap-arounds correctly for 585 * this trick handles wrap-arounds correctly for
624 * up to 32767 buffers in flight... */ 586 * up to 32767 buffers in flight... */
625 if ((s16) (count - buf->count) < 0) 587 if ((s16) (count - buf->count) < 0)
626 break; 588 break;
627#endif
628 do_gettimeofday(&buf->vb.ts); 589 do_gettimeofday(&buf->vb.ts);
629 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, 590 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i,
630 count, buf->count); 591 count, buf->count);
@@ -952,12 +913,10 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
952 norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); 913 norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
953 cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat); 914 cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat);
954 915
955#if 1
956 // FIXME: as-is from DScaler 916 // FIXME: as-is from DScaler
957 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n", 917 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
958 norm->cxoformat, cx_read(MO_OUTPUT_FORMAT)); 918 norm->cxoformat, cx_read(MO_OUTPUT_FORMAT));
959 cx_write(MO_OUTPUT_FORMAT, norm->cxoformat); 919 cx_write(MO_OUTPUT_FORMAT, norm->cxoformat);
960#endif
961 920
962 // MO_SCONV_REG = adc clock / video dec clock * 2^17 921 // MO_SCONV_REG = adc clock / video dec clock * 2^17
963 tmp64 = adc_clock * (u64)(1 << 17); 922 tmp64 = adc_clock * (u64)(1 << 17);
@@ -1006,21 +965,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
1006 set_tvaudio(core); 965 set_tvaudio(core);
1007 966
1008 // tell i2c chips 967 // tell i2c chips
1009#ifdef V4L2_I2C_CLIENTS
1010 cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm->id); 968 cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm->id);
1011#else
1012 {
1013 struct video_channel c;
1014 memset(&c,0,sizeof(c));
1015 c.channel = core->input;
1016 c.norm = VIDEO_MODE_PAL;
1017 if ((norm->id & (V4L2_STD_NTSC_M|V4L2_STD_NTSC_M_JP)))
1018 c.norm = VIDEO_MODE_NTSC;
1019 if (norm->id & V4L2_STD_SECAM)
1020 c.norm = VIDEO_MODE_SECAM;
1021 cx88_call_i2c_clients(core,VIDIOCSCHAN,&c);
1022 }
1023#endif
1024 969
1025 // done 970 // done
1026 return 0; 971 return 0;
@@ -1230,8 +1175,6 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1230/* ------------------------------------------------------------------ */ 1175/* ------------------------------------------------------------------ */
1231 1176
1232EXPORT_SYMBOL(cx88_print_ioctl); 1177EXPORT_SYMBOL(cx88_print_ioctl);
1233EXPORT_SYMBOL(cx88_vid_irqs);
1234EXPORT_SYMBOL(cx88_mpeg_irqs);
1235EXPORT_SYMBOL(cx88_print_irqbits); 1178EXPORT_SYMBOL(cx88_print_irqbits);
1236 1179
1237EXPORT_SYMBOL(cx88_core_irq); 1180EXPORT_SYMBOL(cx88_core_irq);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 1a259c3966cd..6ad1458ab652 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-dvb.c,v 1.33 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: cx88-dvb.c,v 1.42 2005/07/12 15:44:55 mkrufky Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines 5 * MPEG Transport Stream (DVB) routines
@@ -30,20 +30,27 @@
30#include <linux/file.h> 30#include <linux/file.h>
31#include <linux/suspend.h> 31#include <linux/suspend.h>
32 32
33/* those two frontends need merging via linuxtv cvs ... */ 33#define CONFIG_DVB_MT352 1
34#define HAVE_CX22702 1 34#define CONFIG_DVB_CX22702 1
35#define HAVE_OR51132 1 35#define CONFIG_DVB_OR51132 1
36#define CONFIG_DVB_LGDT3302 1
36 37
37#include "cx88.h" 38#include "cx88.h"
38#include "dvb-pll.h" 39#include "dvb-pll.h"
39#include "mt352.h" 40
40#include "mt352_priv.h" 41#if CONFIG_DVB_MT352
41#if HAVE_CX22702 42# include "mt352.h"
43# include "mt352_priv.h"
44#endif
45#if CONFIG_DVB_CX22702
42# include "cx22702.h" 46# include "cx22702.h"
43#endif 47#endif
44#if HAVE_OR51132 48#if CONFIG_DVB_OR51132
45# include "or51132.h" 49# include "or51132.h"
46#endif 50#endif
51#if CONFIG_DVB_LGDT3302
52# include "lgdt3302.h"
53#endif
47 54
48MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 55MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
49MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); 56MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
@@ -100,6 +107,7 @@ static struct videobuf_queue_ops dvb_qops = {
100 107
101/* ------------------------------------------------------------------ */ 108/* ------------------------------------------------------------------ */
102 109
110#if CONFIG_DVB_MT352
103static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 111static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
104{ 112{
105 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 }; 113 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
@@ -167,22 +175,25 @@ static struct mt352_config dntv_live_dvbt_config = {
167 .demod_init = dntv_live_dvbt_demod_init, 175 .demod_init = dntv_live_dvbt_demod_init,
168 .pll_set = mt352_pll_set, 176 .pll_set = mt352_pll_set,
169}; 177};
178#endif
170 179
171#if HAVE_CX22702 180#if CONFIG_DVB_CX22702
172static struct cx22702_config connexant_refboard_config = { 181static struct cx22702_config connexant_refboard_config = {
173 .demod_address = 0x43, 182 .demod_address = 0x43,
183 .output_mode = CX22702_SERIAL_OUTPUT,
174 .pll_address = 0x60, 184 .pll_address = 0x60,
175 .pll_desc = &dvb_pll_thomson_dtt7579, 185 .pll_desc = &dvb_pll_thomson_dtt7579,
176}; 186};
177 187
178static struct cx22702_config hauppauge_novat_config = { 188static struct cx22702_config hauppauge_novat_config = {
179 .demod_address = 0x43, 189 .demod_address = 0x43,
190 .output_mode = CX22702_SERIAL_OUTPUT,
180 .pll_address = 0x61, 191 .pll_address = 0x61,
181 .pll_desc = &dvb_pll_thomson_dtt759x, 192 .pll_desc = &dvb_pll_thomson_dtt759x,
182}; 193};
183#endif 194#endif
184 195
185#if HAVE_OR51132 196#if CONFIG_DVB_OR51132
186static int or51132_set_ts_param(struct dvb_frontend* fe, 197static int or51132_set_ts_param(struct dvb_frontend* fe,
187 int is_punctured) 198 int is_punctured)
188{ 199{
@@ -199,6 +210,32 @@ static struct or51132_config pchdtv_hd3000 = {
199}; 210};
200#endif 211#endif
201 212
213#if CONFIG_DVB_LGDT3302
214static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
215{
216 struct cx8802_dev *dev= fe->dvb->priv;
217 if (is_punctured)
218 dev->ts_gen_cntrl |= 0x04;
219 else
220 dev->ts_gen_cntrl &= ~0x04;
221 return 0;
222}
223
224static struct lgdt3302_config fusionhdtv_3_gold_q = {
225 .demod_address = 0x0e,
226 .pll_address = 0x61,
227 .pll_desc = &dvb_pll_microtune_4042,
228 .set_ts_params = lgdt3302_set_ts_param,
229};
230
231static struct lgdt3302_config fusionhdtv_3_gold_t = {
232 .demod_address = 0x0e,
233 .pll_address = 0x61,
234 .pll_desc = &dvb_pll_thomson_dtt7611,
235 .set_ts_params = lgdt3302_set_ts_param,
236};
237#endif
238
202static int dvb_register(struct cx8802_dev *dev) 239static int dvb_register(struct cx8802_dev *dev)
203{ 240{
204 /* init struct videobuf_dvb */ 241 /* init struct videobuf_dvb */
@@ -207,16 +244,18 @@ static int dvb_register(struct cx8802_dev *dev)
207 244
208 /* init frontend */ 245 /* init frontend */
209 switch (dev->core->board) { 246 switch (dev->core->board) {
210#if HAVE_CX22702 247#if CONFIG_DVB_CX22702
211 case CX88_BOARD_HAUPPAUGE_DVB_T1: 248 case CX88_BOARD_HAUPPAUGE_DVB_T1:
212 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config, 249 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
213 &dev->core->i2c_adap); 250 &dev->core->i2c_adap);
214 break; 251 break;
252 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
215 case CX88_BOARD_CONEXANT_DVB_T1: 253 case CX88_BOARD_CONEXANT_DVB_T1:
216 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config, 254 dev->dvb.frontend = cx22702_attach(&connexant_refboard_config,
217 &dev->core->i2c_adap); 255 &dev->core->i2c_adap);
218 break; 256 break;
219#endif 257#endif
258#if CONFIG_DVB_MT352
220 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 259 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
221 dev->core->pll_addr = 0x61; 260 dev->core->pll_addr = 0x61;
222 dev->core->pll_desc = &dvb_pll_lg_z201; 261 dev->core->pll_desc = &dvb_pll_lg_z201;
@@ -231,17 +270,49 @@ static int dvb_register(struct cx8802_dev *dev)
231 break; 270 break;
232 case CX88_BOARD_KWORLD_DVB_T: 271 case CX88_BOARD_KWORLD_DVB_T:
233 case CX88_BOARD_DNTV_LIVE_DVB_T: 272 case CX88_BOARD_DNTV_LIVE_DVB_T:
273 case CX88_BOARD_ADSTECH_DVB_T_PCI:
234 dev->core->pll_addr = 0x61; 274 dev->core->pll_addr = 0x61;
235 dev->core->pll_desc = &dvb_pll_unknown_1; 275 dev->core->pll_desc = &dvb_pll_unknown_1;
236 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config, 276 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
237 &dev->core->i2c_adap); 277 &dev->core->i2c_adap);
238 break; 278 break;
239#if HAVE_OR51132 279#endif
280#if CONFIG_DVB_OR51132
240 case CX88_BOARD_PCHDTV_HD3000: 281 case CX88_BOARD_PCHDTV_HD3000:
241 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, 282 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
242 &dev->core->i2c_adap); 283 &dev->core->i2c_adap);
243 break; 284 break;
244#endif 285#endif
286#if CONFIG_DVB_LGDT3302
287 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
288 dev->ts_gen_cntrl = 0x08;
289 {
290 /* Do a hardware reset of chip before using it. */
291 struct cx88_core *core = dev->core;
292
293 cx_clear(MO_GP0_IO, 1);
294 mdelay(100);
295 cx_set(MO_GP0_IO, 9); // ANT connector too FIXME
296 mdelay(200);
297 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q,
298 &dev->core->i2c_adap);
299 }
300 break;
301 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
302 dev->ts_gen_cntrl = 0x08;
303 {
304 /* Do a hardware reset of chip before using it. */
305 struct cx88_core *core = dev->core;
306
307 cx_clear(MO_GP0_IO, 1);
308 mdelay(100);
309 cx_set(MO_GP0_IO, 9); /* ANT connector too FIXME */
310 mdelay(200);
311 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_t,
312 &dev->core->i2c_adap);
313 }
314 break;
315#endif
245 default: 316 default:
246 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 317 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
247 dev->core->name); 318 dev->core->name);
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index e20adefcfc6c..8403c4e95050 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-i2c.c,v 1.23 2005/06/12 04:19:19 mchehab Exp $ 2 $Id: cx88-i2c.c,v 1.28 2005/07/05 17:37:35 nsh Exp $
3 3
4 cx88-i2c.c -- all the i2c code is here 4 cx88-i2c.c -- all the i2c code is here
5 5
@@ -91,25 +91,32 @@ static int cx8800_bit_getsda(void *data)
91 91
92static int attach_inform(struct i2c_client *client) 92static int attach_inform(struct i2c_client *client)
93{ 93{
94 struct tuner_addr tun_addr; 94 struct tuner_setup tun_setup;
95 struct cx88_core *core = i2c_get_adapdata(client->adapter); 95 struct cx88_core *core = i2c_get_adapdata(client->adapter);
96 96
97 dprintk(1, "i2c attach [addr=0x%x,client=%s]\n", 97 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
98 client->addr, i2c_clientname(client)); 98 client->driver->name,client->addr,i2c_clientname(client));
99 if (!client->driver->command) 99 if (!client->driver->command)
100 return 0; 100 return 0;
101 101
102 if (core->radio_type != UNSET) { 102 if (core->radio_type != UNSET) {
103 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO; 103 if ((core->radio_addr==ADDR_UNSET)||(core->radio_addr==client->addr)) {
104 tun_addr.type = core->radio_type; 104 tun_setup.mode_mask = T_RADIO;
105 tun_addr.addr = core->radio_addr; 105 tun_setup.type = core->radio_type;
106 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr); 106 tun_setup.addr = core->radio_addr;
107
108 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
109 }
107 } 110 }
108 if (core->tuner_type != UNSET) { 111 if (core->tuner_type != UNSET) {
109 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV; 112 if ((core->tuner_addr==ADDR_UNSET)||(core->tuner_addr==client->addr)) {
110 tun_addr.type = core->tuner_type; 113
111 tun_addr.addr = core->tuner_addr; 114 tun_setup.mode_mask = T_ANALOG_TV;
112 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr); 115 tun_setup.type = core->tuner_type;
116 tun_setup.addr = core->tuner_addr;
117
118 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
119 }
113 } 120 }
114 121
115 if (core->tda9887_conf) 122 if (core->tda9887_conf)
@@ -157,6 +164,7 @@ static struct i2c_client cx8800_i2c_client_template = {
157}; 164};
158 165
159static char *i2c_devs[128] = { 166static char *i2c_devs[128] = {
167 [ 0x1c >> 1 ] = "lgdt3302",
160 [ 0x86 >> 1 ] = "tda9887/cx22702", 168 [ 0x86 >> 1 ] = "tda9887/cx22702",
161 [ 0xa0 >> 1 ] = "eeprom", 169 [ 0xa0 >> 1 ] = "eeprom",
162 [ 0xc0 >> 1 ] = "tuner (analog)", 170 [ 0xc0 >> 1 ] = "tuner (analog)",
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index dc0dcf249aac..214887798192 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-input.c,v 1.11 2005/05/22 20:57:56 nsh Exp $ 2 * $Id: cx88-input.c,v 1.15 2005/07/07 13:58:38 mchehab Exp $
3 * 3 *
4 * Device driver for GPIO attached remote control interfaces 4 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards. 5 * on Conexant 2388x based TV/DVB cards.
@@ -38,119 +38,206 @@
38 38
39/* DigitalNow DNTV Live DVB-T Remote */ 39/* DigitalNow DNTV Live DVB-T Remote */
40static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = { 40static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
41 [ 0x00 ] = KEY_ESC, // 'go up a level?' 41 [0x00] = KEY_ESC, /* 'go up a level?' */
42 [ 0x01 ] = KEY_KP1, // '1' 42 /* Keys 0 to 9 */
43 [ 0x02 ] = KEY_KP2, // '2' 43 [0x0a] = KEY_KP0,
44 [ 0x03 ] = KEY_KP3, // '3' 44 [0x01] = KEY_KP1,
45 [ 0x04 ] = KEY_KP4, // '4' 45 [0x02] = KEY_KP2,
46 [ 0x05 ] = KEY_KP5, // '5' 46 [0x03] = KEY_KP3,
47 [ 0x06 ] = KEY_KP6, // '6' 47 [0x04] = KEY_KP4,
48 [ 0x07 ] = KEY_KP7, // '7' 48 [0x05] = KEY_KP5,
49 [ 0x08 ] = KEY_KP8, // '8' 49 [0x06] = KEY_KP6,
50 [ 0x09 ] = KEY_KP9, // '9' 50 [0x07] = KEY_KP7,
51 [ 0x0a ] = KEY_KP0, // '0' 51 [0x08] = KEY_KP8,
52 [ 0x0b ] = KEY_TUNER, // 'tv/fm' 52 [0x09] = KEY_KP9,
53 [ 0x0c ] = KEY_SEARCH, // 'scan' 53
54 [ 0x0d ] = KEY_STOP, // 'stop' 54 [0x0b] = KEY_TUNER, /* tv/fm */
55 [ 0x0e ] = KEY_PAUSE, // 'pause' 55 [0x0c] = KEY_SEARCH, /* scan */
56 [ 0x0f ] = KEY_LIST, // 'source' 56 [0x0d] = KEY_STOP,
57 57 [0x0e] = KEY_PAUSE,
58 [ 0x10 ] = KEY_MUTE, // 'mute' 58 [0x0f] = KEY_LIST, /* source */
59 [ 0x11 ] = KEY_REWIND, // 'backward <<' 59
60 [ 0x12 ] = KEY_POWER, // 'power' 60 [0x10] = KEY_MUTE,
61 [ 0x13 ] = KEY_S, // 'snap' 61 [0x11] = KEY_REWIND, /* backward << */
62 [ 0x14 ] = KEY_AUDIO, // 'stereo' 62 [0x12] = KEY_POWER,
63 [ 0x15 ] = KEY_CLEAR, // 'reset' 63 [0x13] = KEY_S, /* snap */
64 [ 0x16 ] = KEY_PLAY, // 'play' 64 [0x14] = KEY_AUDIO, /* stereo */
65 [ 0x17 ] = KEY_ENTER, // 'enter' 65 [0x15] = KEY_CLEAR, /* reset */
66 [ 0x18 ] = KEY_ZOOM, // 'full screen' 66 [0x16] = KEY_PLAY,
67 [ 0x19 ] = KEY_FASTFORWARD, // 'forward >>' 67 [0x17] = KEY_ENTER,
68 [ 0x1a ] = KEY_CHANNELUP, // 'channel +' 68 [0x18] = KEY_ZOOM, /* full screen */
69 [ 0x1b ] = KEY_VOLUMEUP, // 'volume +' 69 [0x19] = KEY_FASTFORWARD, /* forward >> */
70 [ 0x1c ] = KEY_INFO, // 'preview' 70 [0x1a] = KEY_CHANNELUP,
71 [ 0x1d ] = KEY_RECORD, // 'record' 71 [0x1b] = KEY_VOLUMEUP,
72 [ 0x1e ] = KEY_CHANNELDOWN, // 'channel -' 72 [0x1c] = KEY_INFO, /* preview */
73 [ 0x1f ] = KEY_VOLUMEDOWN, // 'volume -' 73 [0x1d] = KEY_RECORD, /* record */
74 [0x1e] = KEY_CHANNELDOWN,
75 [0x1f] = KEY_VOLUMEDOWN,
74}; 76};
75 77
76/* ---------------------------------------------------------------------- */ 78/* ---------------------------------------------------------------------- */
77 79
78/* IO-DATA BCTV7E Remote */ 80/* IO-DATA BCTV7E Remote */
79static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = { 81static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
80 [ 0x40 ] = KEY_TV, // TV 82 [0x40] = KEY_TV,
81 [ 0x20 ] = KEY_RADIO, // FM 83 [0x20] = KEY_RADIO, /* FM */
82 [ 0x60 ] = KEY_EPG, // EPG 84 [0x60] = KEY_EPG,
83 [ 0x00 ] = KEY_POWER, // power 85 [0x00] = KEY_POWER,
84 86
85 [ 0x50 ] = KEY_KP1, // 1 87 /* Keys 0 to 9 */
86 [ 0x30 ] = KEY_KP2, // 2 88 [0x44] = KEY_KP0, /* 10 */
87 [ 0x70 ] = KEY_KP3, // 3 89 [0x50] = KEY_KP1,
88 [ 0x10 ] = KEY_L, // Live 90 [0x30] = KEY_KP2,
89 91 [0x70] = KEY_KP3,
90 [ 0x48 ] = KEY_KP4, // 4 92 [0x48] = KEY_KP4,
91 [ 0x28 ] = KEY_KP5, // 5 93 [0x28] = KEY_KP5,
92 [ 0x68 ] = KEY_KP6, // 6 94 [0x68] = KEY_KP6,
93 [ 0x08 ] = KEY_T, // Time Shift 95 [0x58] = KEY_KP7,
94 96 [0x38] = KEY_KP8,
95 [ 0x58 ] = KEY_KP7, // 7 97 [0x78] = KEY_KP9,
96 [ 0x38 ] = KEY_KP8, // 8 98
97 [ 0x78 ] = KEY_KP9, // 9 99 [0x10] = KEY_L, /* Live */
98 [ 0x18 ] = KEY_PLAYPAUSE, // Play 100 [0x08] = KEY_T, /* Time Shift */
99 101
100 [ 0x44 ] = KEY_KP0, // 10 102 [0x18] = KEY_PLAYPAUSE, /* Play */
101 [ 0x24 ] = KEY_ENTER, // 11 103
102 [ 0x64 ] = KEY_ESC, // 12 104 [0x24] = KEY_ENTER, /* 11 */
103 [ 0x04 ] = KEY_M, // Multi 105 [0x64] = KEY_ESC, /* 12 */
104 106 [0x04] = KEY_M, /* Multi */
105 [ 0x54 ] = KEY_VIDEO, // VIDEO 107
106 [ 0x34 ] = KEY_CHANNELUP, // channel + 108 [0x54] = KEY_VIDEO,
107 [ 0x74 ] = KEY_VOLUMEUP, // volume + 109 [0x34] = KEY_CHANNELUP,
108 [ 0x14 ] = KEY_MUTE, // Mute 110 [0x74] = KEY_VOLUMEUP,
109 111 [0x14] = KEY_MUTE,
110 [ 0x4c ] = KEY_S, // SVIDEO 112
111 [ 0x2c ] = KEY_CHANNELDOWN, // channel - 113 [0x4c] = KEY_S, /* SVIDEO */
112 [ 0x6c ] = KEY_VOLUMEDOWN, // volume - 114 [0x2c] = KEY_CHANNELDOWN,
113 [ 0x0c ] = KEY_ZOOM, // Zoom 115 [0x6c] = KEY_VOLUMEDOWN,
114 116 [0x0c] = KEY_ZOOM,
115 [ 0x5c ] = KEY_PAUSE, // pause 117
116 [ 0x3c ] = KEY_C, // || (red) 118 [0x5c] = KEY_PAUSE,
117 [ 0x7c ] = KEY_RECORD, // recording 119 [0x3c] = KEY_C, /* || (red) */
118 [ 0x1c ] = KEY_STOP, // stop 120 [0x7c] = KEY_RECORD, /* recording */
119 121 [0x1c] = KEY_STOP,
120 [ 0x41 ] = KEY_REWIND, // backward << 122
121 [ 0x21 ] = KEY_PLAY, // play 123 [0x41] = KEY_REWIND, /* backward << */
122 [ 0x61 ] = KEY_FASTFORWARD, // forward >> 124 [0x21] = KEY_PLAY,
123 [ 0x01 ] = KEY_NEXT, // skip >| 125 [0x61] = KEY_FASTFORWARD, /* forward >> */
126 [0x01] = KEY_NEXT, /* skip >| */
127};
128
129/* ---------------------------------------------------------------------- */
130
131/* ADS Tech Instant TV DVB-T PCI Remote */
132static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
133 /* Keys 0 to 9 */
134 [0x4d] = KEY_0,
135 [0x57] = KEY_1,
136 [0x4f] = KEY_2,
137 [0x53] = KEY_3,
138 [0x56] = KEY_4,
139 [0x4e] = KEY_5,
140 [0x5e] = KEY_6,
141 [0x54] = KEY_7,
142 [0x4c] = KEY_8,
143 [0x5c] = KEY_9,
144
145 [0x5b] = KEY_POWER,
146 [0x5f] = KEY_MUTE,
147 [0x55] = KEY_GOTO,
148 [0x5d] = KEY_SEARCH,
149 [0x17] = KEY_EPG, /* Guide */
150 [0x1f] = KEY_MENU,
151 [0x0f] = KEY_UP,
152 [0x46] = KEY_DOWN,
153 [0x16] = KEY_LEFT,
154 [0x1e] = KEY_RIGHT,
155 [0x0e] = KEY_SELECT, /* Enter */
156 [0x5a] = KEY_INFO,
157 [0x52] = KEY_EXIT,
158 [0x59] = KEY_PREVIOUS,
159 [0x51] = KEY_NEXT,
160 [0x58] = KEY_REWIND,
161 [0x50] = KEY_FORWARD,
162 [0x44] = KEY_PLAYPAUSE,
163 [0x07] = KEY_STOP,
164 [0x1b] = KEY_RECORD,
165 [0x13] = KEY_TUNER, /* Live */
166 [0x0a] = KEY_A,
167 [0x12] = KEY_B,
168 [0x03] = KEY_PROG1, /* 1 */
169 [0x01] = KEY_PROG2, /* 2 */
170 [0x00] = KEY_PROG3, /* 3 */
171 [0x06] = KEY_DVD,
172 [0x48] = KEY_AUX, /* Photo */
173 [0x40] = KEY_VIDEO,
174 [0x19] = KEY_AUDIO, /* Music */
175 [0x0b] = KEY_CHANNELUP,
176 [0x08] = KEY_CHANNELDOWN,
177 [0x15] = KEY_VOLUMEUP,
178 [0x1c] = KEY_VOLUMEDOWN,
179};
180
181/* ---------------------------------------------------------------------- */
182
183/* MSI TV@nywhere remote */
184static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
185 /* Keys 0 to 9 */
186 [0x00] = KEY_0,
187 [0x01] = KEY_1,
188 [0x02] = KEY_2,
189 [0x03] = KEY_3,
190 [0x04] = KEY_4,
191 [0x05] = KEY_5,
192 [0x06] = KEY_6,
193 [0x07] = KEY_7,
194 [0x08] = KEY_8,
195 [0x09] = KEY_9,
196
197 [0x0c] = KEY_MUTE,
198 [0x0f] = KEY_SCREEN, /* Full Screen */
199 [0x10] = KEY_F, /* Funtion */
200 [0x11] = KEY_T, /* Time shift */
201 [0x12] = KEY_POWER,
202 [0x13] = KEY_MEDIA, /* MTS */
203 [0x14] = KEY_SLOW,
204 [0x16] = KEY_REWIND, /* backward << */
205 [0x17] = KEY_ENTER, /* Return */
206 [0x18] = KEY_FASTFORWARD, /* forward >> */
207 [0x1a] = KEY_CHANNELUP,
208 [0x1b] = KEY_VOLUMEUP,
209 [0x1e] = KEY_CHANNELDOWN,
210 [0x1f] = KEY_VOLUMEDOWN,
124}; 211};
125 212
126/* ---------------------------------------------------------------------- */ 213/* ---------------------------------------------------------------------- */
127 214
128struct cx88_IR { 215struct cx88_IR {
129 struct cx88_core *core; 216 struct cx88_core *core;
130 struct input_dev input; 217 struct input_dev input;
131 struct ir_input_state ir; 218 struct ir_input_state ir;
132 char name[32]; 219 char name[32];
133 char phys[32]; 220 char phys[32];
134 221
135 /* sample from gpio pin 16 */ 222 /* sample from gpio pin 16 */
136 int sampling; 223 int sampling;
137 u32 samples[16]; 224 u32 samples[16];
138 int scount; 225 int scount;
139 unsigned long release; 226 unsigned long release;
140 227
141 /* poll external decoder */ 228 /* poll external decoder */
142 int polling; 229 int polling;
143 struct work_struct work; 230 struct work_struct work;
144 struct timer_list timer; 231 struct timer_list timer;
145 u32 gpio_addr; 232 u32 gpio_addr;
146 u32 last_gpio; 233 u32 last_gpio;
147 u32 mask_keycode; 234 u32 mask_keycode;
148 u32 mask_keydown; 235 u32 mask_keydown;
149 u32 mask_keyup; 236 u32 mask_keyup;
150}; 237};
151 238
152static int ir_debug = 0; 239static int ir_debug = 0;
153module_param(ir_debug, int, 0644); /* debug level [IR] */ 240module_param(ir_debug, int, 0644); /* debug level [IR] */
154MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 241MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
155 242
156#define ir_dprintk(fmt, arg...) if (ir_debug) \ 243#define ir_dprintk(fmt, arg...) if (ir_debug) \
@@ -174,37 +261,37 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
174 /* extract data */ 261 /* extract data */
175 data = ir_extract_bits(gpio, ir->mask_keycode); 262 data = ir_extract_bits(gpio, ir->mask_keycode);
176 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n", 263 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
177 gpio, data, 264 gpio, data,
178 ir->polling ? "poll" : "irq", 265 ir->polling ? "poll" : "irq",
179 (gpio & ir->mask_keydown) ? " down" : "", 266 (gpio & ir->mask_keydown) ? " down" : "",
180 (gpio & ir->mask_keyup) ? " up" : ""); 267 (gpio & ir->mask_keyup) ? " up" : "");
181 268
182 if (ir->mask_keydown) { 269 if (ir->mask_keydown) {
183 /* bit set on keydown */ 270 /* bit set on keydown */
184 if (gpio & ir->mask_keydown) { 271 if (gpio & ir->mask_keydown) {
185 ir_input_keydown(&ir->input,&ir->ir,data,data); 272 ir_input_keydown(&ir->input, &ir->ir, data, data);
186 } else { 273 } else {
187 ir_input_nokey(&ir->input,&ir->ir); 274 ir_input_nokey(&ir->input, &ir->ir);
188 } 275 }
189 276
190 } else if (ir->mask_keyup) { 277 } else if (ir->mask_keyup) {
191 /* bit cleared on keydown */ 278 /* bit cleared on keydown */
192 if (0 == (gpio & ir->mask_keyup)) { 279 if (0 == (gpio & ir->mask_keyup)) {
193 ir_input_keydown(&ir->input,&ir->ir,data,data); 280 ir_input_keydown(&ir->input, &ir->ir, data, data);
194 } else { 281 } else {
195 ir_input_nokey(&ir->input,&ir->ir); 282 ir_input_nokey(&ir->input, &ir->ir);
196 } 283 }
197 284
198 } else { 285 } else {
199 /* can't distinguish keydown/up :-/ */ 286 /* can't distinguish keydown/up :-/ */
200 ir_input_keydown(&ir->input,&ir->ir,data,data); 287 ir_input_keydown(&ir->input, &ir->ir, data, data);
201 ir_input_nokey(&ir->input,&ir->ir); 288 ir_input_nokey(&ir->input, &ir->ir);
202 } 289 }
203} 290}
204 291
205static void ir_timer(unsigned long data) 292static void ir_timer(unsigned long data)
206{ 293{
207 struct cx88_IR *ir = (struct cx88_IR*)data; 294 struct cx88_IR *ir = (struct cx88_IR *)data;
208 295
209 schedule_work(&ir->work); 296 schedule_work(&ir->work);
210} 297}
@@ -227,47 +314,61 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
227 IR_KEYTAB_TYPE *ir_codes = NULL; 314 IR_KEYTAB_TYPE *ir_codes = NULL;
228 int ir_type = IR_TYPE_OTHER; 315 int ir_type = IR_TYPE_OTHER;
229 316
230 ir = kmalloc(sizeof(*ir),GFP_KERNEL); 317 ir = kmalloc(sizeof(*ir), GFP_KERNEL);
231 if (NULL == ir) 318 if (NULL == ir)
232 return -ENOMEM; 319 return -ENOMEM;
233 memset(ir,0,sizeof(*ir)); 320 memset(ir, 0, sizeof(*ir));
234 321
235 /* detect & configure */ 322 /* detect & configure */
236 switch (core->board) { 323 switch (core->board) {
237 case CX88_BOARD_DNTV_LIVE_DVB_T: 324 case CX88_BOARD_DNTV_LIVE_DVB_T:
238 case CX88_BOARD_KWORLD_DVB_T: 325 case CX88_BOARD_KWORLD_DVB_T:
239 ir_codes = ir_codes_dntv_live_dvb_t; 326 ir_codes = ir_codes_dntv_live_dvb_t;
240 ir->gpio_addr = MO_GP1_IO; 327 ir->gpio_addr = MO_GP1_IO;
241 ir->mask_keycode = 0x1f; 328 ir->mask_keycode = 0x1f;
242 ir->mask_keyup = 0x60; 329 ir->mask_keyup = 0x60;
243 ir->polling = 50; // ms 330 ir->polling = 50; /* ms */
244 break; 331 break;
245 case CX88_BOARD_HAUPPAUGE: 332 case CX88_BOARD_HAUPPAUGE:
246 case CX88_BOARD_HAUPPAUGE_DVB_T1: 333 case CX88_BOARD_HAUPPAUGE_DVB_T1:
247 ir_codes = ir_codes_hauppauge_new; 334 ir_codes = ir_codes_hauppauge_new;
248 ir_type = IR_TYPE_RC5; 335 ir_type = IR_TYPE_RC5;
249 ir->sampling = 1; 336 ir->sampling = 1;
250 break; 337 break;
251 case CX88_BOARD_WINFAST2000XP_EXPERT: 338 case CX88_BOARD_WINFAST2000XP_EXPERT:
252 ir_codes = ir_codes_winfast; 339 ir_codes = ir_codes_winfast;
253 ir->gpio_addr = MO_GP0_IO; 340 ir->gpio_addr = MO_GP0_IO;
254 ir->mask_keycode = 0x8f8; 341 ir->mask_keycode = 0x8f8;
255 ir->mask_keyup = 0x100; 342 ir->mask_keyup = 0x100;
256 ir->polling = 1; // ms 343 ir->polling = 1; /* ms */
257 break; 344 break;
258 case CX88_BOARD_IODATA_GVBCTV7E: 345 case CX88_BOARD_IODATA_GVBCTV7E:
259 ir_codes = ir_codes_iodata_bctv7e; 346 ir_codes = ir_codes_iodata_bctv7e;
260 ir->gpio_addr = MO_GP0_IO; 347 ir->gpio_addr = MO_GP0_IO;
261 ir->mask_keycode = 0xfd; 348 ir->mask_keycode = 0xfd;
262 ir->mask_keydown = 0x02; 349 ir->mask_keydown = 0x02;
263 ir->polling = 5; // ms 350 ir->polling = 5; /* ms */
264 break; 351 break;
265 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: 352 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
266 ir_codes = ir_codes_pixelview; 353 ir_codes = ir_codes_pixelview;
267 ir->gpio_addr = MO_GP1_IO; 354 ir->gpio_addr = MO_GP1_IO;
355 ir->mask_keycode = 0x1f;
356 ir->mask_keyup = 0x80;
357 ir->polling = 1; /* ms */
358 break;
359 case CX88_BOARD_ADSTECH_DVB_T_PCI:
360 ir_codes = ir_codes_adstech_dvb_t_pci;
361 ir->gpio_addr = MO_GP1_IO;
362 ir->mask_keycode = 0xbf;
363 ir->mask_keyup = 0x40;
364 ir->polling = 50; /* ms */
365 break;
366 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
367 ir_codes = ir_codes_msi_tvanywhere;
368 ir->gpio_addr = MO_GP1_IO;
268 ir->mask_keycode = 0x1f; 369 ir->mask_keycode = 0x1f;
269 ir->mask_keyup = 0x80; 370 ir->mask_keyup = 0x40;
270 ir->polling = 1; // ms 371 ir->polling = 1; /* ms */
271 break; 372 break;
272 } 373 }
273 374
@@ -279,8 +380,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
279 /* init input device */ 380 /* init input device */
280 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", 381 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
281 cx88_boards[core->board].name); 382 cx88_boards[core->board].name);
282 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 383 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
283 pci_name(pci));
284 384
285 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes); 385 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes);
286 ir->input.name = ir->name; 386 ir->input.name = ir->name;
@@ -288,10 +388,10 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
288 ir->input.id.bustype = BUS_PCI; 388 ir->input.id.bustype = BUS_PCI;
289 ir->input.id.version = 1; 389 ir->input.id.version = 1;
290 if (pci->subsystem_vendor) { 390 if (pci->subsystem_vendor) {
291 ir->input.id.vendor = pci->subsystem_vendor; 391 ir->input.id.vendor = pci->subsystem_vendor;
292 ir->input.id.product = pci->subsystem_device; 392 ir->input.id.product = pci->subsystem_device;
293 } else { 393 } else {
294 ir->input.id.vendor = pci->vendor; 394 ir->input.id.vendor = pci->vendor;
295 ir->input.id.product = pci->device; 395 ir->input.id.product = pci->device;
296 } 396 }
297 397
@@ -303,13 +403,13 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
303 INIT_WORK(&ir->work, cx88_ir_work, ir); 403 INIT_WORK(&ir->work, cx88_ir_work, ir);
304 init_timer(&ir->timer); 404 init_timer(&ir->timer);
305 ir->timer.function = ir_timer; 405 ir->timer.function = ir_timer;
306 ir->timer.data = (unsigned long)ir; 406 ir->timer.data = (unsigned long)ir;
307 schedule_work(&ir->work); 407 schedule_work(&ir->work);
308 } 408 }
309 if (ir->sampling) { 409 if (ir->sampling) {
310 core->pci_irqmask |= (1<<18); // IR_SMP_INT 410 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
311 cx_write(MO_DDS_IO, 0xa80a80); // 4 kHz sample rate 411 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
312 cx_write(MO_DDSCFG_IO, 0x5); // enable 412 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
313 } 413 }
314 414
315 /* all done */ 415 /* all done */
@@ -345,7 +445,7 @@ int cx88_ir_fini(struct cx88_core *core)
345void cx88_ir_irq(struct cx88_core *core) 445void cx88_ir_irq(struct cx88_core *core)
346{ 446{
347 struct cx88_IR *ir = core->ir; 447 struct cx88_IR *ir = core->ir;
348 u32 samples,rc5; 448 u32 samples, rc5;
349 int i; 449 int i;
350 450
351 if (NULL == ir) 451 if (NULL == ir)
@@ -354,7 +454,7 @@ void cx88_ir_irq(struct cx88_core *core)
354 return; 454 return;
355 455
356 samples = cx_read(MO_SAMPLE_IO); 456 samples = cx_read(MO_SAMPLE_IO);
357 if (0 != samples && 0xffffffff != samples) { 457 if (0 != samples && 0xffffffff != samples) {
358 /* record sample data */ 458 /* record sample data */
359 if (ir->scount < ARRAY_SIZE(ir->samples)) 459 if (ir->scount < ARRAY_SIZE(ir->samples))
360 ir->samples[ir->scount++] = samples; 460 ir->samples[ir->scount++] = samples;
@@ -362,8 +462,8 @@ void cx88_ir_irq(struct cx88_core *core)
362 } 462 }
363 if (!ir->scount) { 463 if (!ir->scount) {
364 /* nothing to sample */ 464 /* nothing to sample */
365 if (ir->ir.keypressed && time_after(jiffies,ir->release)) 465 if (ir->ir.keypressed && time_after(jiffies, ir->release))
366 ir_input_nokey(&ir->input,&ir->ir); 466 ir_input_nokey(&ir->input, &ir->ir);
367 return; 467 return;
368 } 468 }
369 469
@@ -373,14 +473,14 @@ void cx88_ir_irq(struct cx88_core *core)
373 for (i = 0; i < ir->scount; i++) 473 for (i = 0; i < ir->scount; i++)
374 ir->samples[i] = ~ir->samples[i]; 474 ir->samples[i] = ~ir->samples[i];
375 if (ir_debug) 475 if (ir_debug)
376 ir_dump_samples(ir->samples,ir->scount); 476 ir_dump_samples(ir->samples, ir->scount);
377 477
378 /* decode it */ 478 /* decode it */
379 switch (core->board) { 479 switch (core->board) {
380 case CX88_BOARD_HAUPPAUGE: 480 case CX88_BOARD_HAUPPAUGE:
381 case CX88_BOARD_HAUPPAUGE_DVB_T1: 481 case CX88_BOARD_HAUPPAUGE_DVB_T1:
382 rc5 = ir_decode_biphase(ir->samples,ir->scount,5,7); 482 rc5 = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
383 ir_dprintk("biphase decoded: %x\n",rc5); 483 ir_dprintk("biphase decoded: %x\n", rc5);
384 if ((rc5 & 0xfffff000) != 0x3000) 484 if ((rc5 & 0xfffff000) != 0x3000)
385 break; 485 break;
386 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5); 486 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5);
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 9ade2ae91e9b..fe2767c0ff94 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-mpeg.c,v 1.26 2005/06/03 13:31:51 mchehab Exp $ 2 * $Id: cx88-mpeg.c,v 1.31 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * Support for the mpeg transport stream transfers 4 * Support for the mpeg transport stream transfers
5 * PCI function #2 of the cx2388x. 5 * PCI function #2 of the cx2388x.
@@ -64,17 +64,21 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
64 /* write TS length to chip */ 64 /* write TS length to chip */
65 cx_write(MO_TS_LNGTH, buf->vb.width); 65 cx_write(MO_TS_LNGTH, buf->vb.width);
66 66
67#if 1
68 /* FIXME: this needs a review. 67 /* FIXME: this needs a review.
69 * also: move to cx88-blackbird + cx88-dvb source files? */ 68 * also: move to cx88-blackbird + cx88-dvb source files? */
70 69
71 if (cx88_boards[core->board].dvb) { 70 if (cx88_boards[core->board].dvb) {
72 /* negedge driven & software reset */ 71 /* negedge driven & software reset */
73 cx_write(TS_GEN_CNTRL, 0x40); 72 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
74 udelay(100); 73 udelay(100);
75 cx_write(MO_PINMUX_IO, 0x00); 74 cx_write(MO_PINMUX_IO, 0x00);
76 cx_write(TS_HW_SOP_CNTRL,47<<16|188<<4|0x00); 75 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
77 cx_write(TS_SOP_STAT,0x00); 76 if ((core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q) ||
77 (core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T)) {
78 cx_write(TS_SOP_STAT, 1<<13);
79 } else {
80 cx_write(TS_SOP_STAT, 0x00);
81 }
78 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl); 82 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
79 udelay(100); 83 udelay(100);
80 } 84 }
@@ -93,7 +97,6 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
93 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 97 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
94 udelay(100); 98 udelay(100);
95 } 99 }
96#endif
97 100
98 /* reset counter */ 101 /* reset counter */
99 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET); 102 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
@@ -265,6 +268,15 @@ static void cx8802_timeout(unsigned long data)
265 do_cancel_buffers(dev,"timeout",1); 268 do_cancel_buffers(dev,"timeout",1);
266} 269}
267 270
271static char *cx88_mpeg_irqs[32] = {
272 "ts_risci1", NULL, NULL, NULL,
273 "ts_risci2", NULL, NULL, NULL,
274 "ts_oflow", NULL, NULL, NULL,
275 "ts_sync", NULL, NULL, NULL,
276 "opc_err", "par_err", "rip_err", "pci_abort",
277 "ts_err?",
278};
279
268static void cx8802_mpeg_irq(struct cx8802_dev *dev) 280static void cx8802_mpeg_irq(struct cx8802_dev *dev)
269{ 281{
270 struct cx88_core *core = dev->core; 282 struct cx88_core *core = dev->core;
@@ -277,10 +289,7 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
277 return; 289 return;
278 290
279 cx_write(MO_TS_INTSTAT, status); 291 cx_write(MO_TS_INTSTAT, status);
280#if 0 292
281 cx88_print_irqbits(core->name, "irq mpeg ",
282 cx88_mpeg_irqs, status, mask);
283#endif
284 if (debug || (status & mask & ~0xff)) 293 if (debug || (status & mask & ~0xff))
285 cx88_print_irqbits(core->name, "irq mpeg ", 294 cx88_print_irqbits(core->name, "irq mpeg ",
286 cx88_mpeg_irqs, status, mask); 295 cx88_mpeg_irqs, status, mask);
@@ -436,10 +445,8 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
436 } 445 }
437 spin_unlock(&dev->slock); 446 spin_unlock(&dev->slock);
438 447
439#if 1
440 /* FIXME -- shutdown device */ 448 /* FIXME -- shutdown device */
441 cx88_shutdown(dev->core); 449 cx88_shutdown(dev->core);
442#endif
443 450
444 pci_save_state(pci_dev); 451 pci_save_state(pci_dev);
445 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { 452 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
@@ -461,10 +468,8 @@ int cx8802_resume_common(struct pci_dev *pci_dev)
461 pci_set_power_state(pci_dev, PCI_D0); 468 pci_set_power_state(pci_dev, PCI_D0);
462 pci_restore_state(pci_dev); 469 pci_restore_state(pci_dev);
463 470
464#if 1
465 /* FIXME: re-initialize hardware */ 471 /* FIXME: re-initialize hardware */
466 cx88_reset(dev->core); 472 cx88_reset(dev->core);
467#endif
468 473
469 /* restart video+vbi capture */ 474 /* restart video+vbi capture */
470 spin_lock(&dev->slock); 475 spin_lock(&dev->slock);
diff --git a/drivers/media/video/cx88/cx88-reg.h b/drivers/media/video/cx88/cx88-reg.h
index 63ad33f5818b..37f82662d265 100644
--- a/drivers/media/video/cx88/cx88-reg.h
+++ b/drivers/media/video/cx88/cx88-reg.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-reg.h,v 1.7 2005/06/03 13:31:51 mchehab Exp $ 2 $Id: cx88-reg.h,v 1.8 2005/07/07 13:58:38 mchehab Exp $
3 3
4 cx88x-hw.h - CX2388x register offsets 4 cx88x-hw.h - CX2388x register offsets
5 5
@@ -604,20 +604,11 @@
604#define EN_I2SIN_STR2DAC 0x00004000 604#define EN_I2SIN_STR2DAC 0x00004000
605#define EN_I2SIN_ENABLE 0x00008000 605#define EN_I2SIN_ENABLE 0x00008000
606 606
607#if 0
608/* old */
609#define EN_DMTRX_SUMDIFF 0x00000800
610#define EN_DMTRX_SUMR 0x00000880
611#define EN_DMTRX_LR 0x00000900
612#define EN_DMTRX_MONO 0x00000980
613#else
614/* dscaler cvs */
615#define EN_DMTRX_SUMDIFF (0 << 7) 607#define EN_DMTRX_SUMDIFF (0 << 7)
616#define EN_DMTRX_SUMR (1 << 7) 608#define EN_DMTRX_SUMR (1 << 7)
617#define EN_DMTRX_LR (2 << 7) 609#define EN_DMTRX_LR (2 << 7)
618#define EN_DMTRX_MONO (3 << 7) 610#define EN_DMTRX_MONO (3 << 7)
619#define EN_DMTRX_BYPASS (1 << 11) 611#define EN_DMTRX_BYPASS (1 << 11)
620#endif
621 612
622// Video 613// Video
623#define VID_CAPTURE_CONTROL 0x310180 614#define VID_CAPTURE_CONTROL 0x310180
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 46d78b1dc9b2..91207f10bae7 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-tvaudio.c,v 1.36 2005/06/05 05:53:45 mchehab Exp $ 2 $Id: cx88-tvaudio.c,v 1.37 2005/07/07 13:58:38 mchehab Exp $
3 3
4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver 4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
5 5
@@ -278,80 +278,6 @@ static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap)
278 set_audio_finish(core); 278 set_audio_finish(core);
279} 279}
280 280
281#if 0
282static void set_audio_standard_NICAM(struct cx88_core *core)
283{
284 static const struct rlist nicam_common[] = {
285 /* from dscaler */
286 { AUD_RATE_ADJ1, 0x00000010 },
287 { AUD_RATE_ADJ2, 0x00000040 },
288 { AUD_RATE_ADJ3, 0x00000100 },
289 { AUD_RATE_ADJ4, 0x00000400 },
290 { AUD_RATE_ADJ5, 0x00001000 },
291 // { AUD_DMD_RA_DDS, 0x00c0d5ce },
292
293 // Deemphasis 1:
294 { AUD_DEEMPHGAIN_R, 0x000023c2 },
295 { AUD_DEEMPHNUMER1_R, 0x0002a7bc },
296 { AUD_DEEMPHNUMER2_R, 0x0003023e },
297 { AUD_DEEMPHDENOM1_R, 0x0000f3d0 },
298 { AUD_DEEMPHDENOM2_R, 0x00000000 },
299
300#if 0
301 // Deemphasis 2: (other tv norm?)
302 { AUD_DEEMPHGAIN_R, 0x0000c600 },
303 { AUD_DEEMPHNUMER1_R, 0x00066738 },
304 { AUD_DEEMPHNUMER2_R, 0x00066739 },
305 { AUD_DEEMPHDENOM1_R, 0x0001e88c },
306 { AUD_DEEMPHDENOM2_R, 0x0001e88c },
307#endif
308
309 { AUD_DEEMPHDENOM2_R, 0x00000000 },
310 { AUD_ERRLOGPERIOD_R, 0x00000fff },
311 { AUD_ERRINTRPTTHSHLD1_R, 0x000003ff },
312 { AUD_ERRINTRPTTHSHLD2_R, 0x000000ff },
313 { AUD_ERRINTRPTTHSHLD3_R, 0x0000003f },
314 { AUD_POLYPH80SCALEFAC, 0x00000003 },
315
316 // setup QAM registers
317 { AUD_PDF_DDS_CNST_BYTE2, 0x06 },
318 { AUD_PDF_DDS_CNST_BYTE1, 0x82 },
319 { AUD_PDF_DDS_CNST_BYTE0, 0x16 },
320 { AUD_QAM_MODE, 0x05 },
321
322 { /* end of list */ },
323 };
324 static const struct rlist nicam_pal_i[] = {
325 { AUD_PDF_DDS_CNST_BYTE0, 0x12 },
326 { AUD_PHACC_FREQ_8MSB, 0x3a },
327 { AUD_PHACC_FREQ_8LSB, 0x93 },
328
329 { /* end of list */ },
330 };
331 static const struct rlist nicam_default[] = {
332 { AUD_PDF_DDS_CNST_BYTE0, 0x16 },
333 { AUD_PHACC_FREQ_8MSB, 0x34 },
334 { AUD_PHACC_FREQ_8LSB, 0x4c },
335
336 { /* end of list */ },
337 };
338
339 set_audio_start(core, 0x0010,
340 EN_DMTRX_LR | EN_DMTRX_BYPASS | EN_NICAM_AUTO_STEREO);
341 set_audio_registers(core, nicam_common);
342 switch (core->tvaudio) {
343 case WW_NICAM_I:
344 dprintk("%s PAL-I NICAM (status: unknown)\n",__FUNCTION__);
345 set_audio_registers(core, nicam_pal_i);
346 break;
347 case WW_NICAM_BGDKL:
348 dprintk("%s PAL-BGDK NICAM (status: unknown)\n",__FUNCTION__);
349 set_audio_registers(core, nicam_default);
350 break;
351 };
352 set_audio_finish(core);
353}
354#endif
355 281
356static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo) 282static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo)
357{ 283{
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index e4ca7350df15..5588a3aeecb4 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-video.c,v 1.63 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: cx88-video.c,v 1.80 2005/07/13 08:49:08 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -86,13 +86,6 @@ static struct cx88_tvnorm tvnorms[] = {
86 .id = V4L2_STD_NTSC_M_JP, 86 .id = V4L2_STD_NTSC_M_JP,
87 .cxiformat = VideoFormatNTSCJapan, 87 .cxiformat = VideoFormatNTSCJapan,
88 .cxoformat = 0x181f0008, 88 .cxoformat = 0x181f0008,
89#if 0
90 },{
91 .name = "NTSC-4.43",
92 .id = FIXME,
93 .cxiformat = VideoFormatNTSC443,
94 .cxoformat = 0x181f0008,
95#endif
96 },{ 89 },{
97 .name = "PAL-BG", 90 .name = "PAL-BG",
98 .id = V4L2_STD_PAL_BG, 91 .id = V4L2_STD_PAL_BG,
@@ -248,6 +241,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
248 .default_value = 0, 241 .default_value = 0,
249 .type = V4L2_CTRL_TYPE_INTEGER, 242 .type = V4L2_CTRL_TYPE_INTEGER,
250 }, 243 },
244 .off = 0,
251 .reg = MO_CONTR_BRIGHT, 245 .reg = MO_CONTR_BRIGHT,
252 .mask = 0xff00, 246 .mask = 0xff00,
253 .shift = 8, 247 .shift = 8,
@@ -261,7 +255,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
261 .default_value = 0, 255 .default_value = 0,
262 .type = V4L2_CTRL_TYPE_INTEGER, 256 .type = V4L2_CTRL_TYPE_INTEGER,
263 }, 257 },
264 .off = 0, 258 .off = 128,
265 .reg = MO_HUE, 259 .reg = MO_HUE,
266 .mask = 0x00ff, 260 .mask = 0x00ff,
267 .shift = 0, 261 .shift = 0,
@@ -674,231 +668,6 @@ static struct videobuf_queue_ops cx8800_video_qops = {
674 668
675/* ------------------------------------------------------------------ */ 669/* ------------------------------------------------------------------ */
676 670
677#if 0 /* overlay support not finished yet */
678static u32* ov_risc_field(struct cx8800_dev *dev, struct cx8800_fh *fh,
679 u32 *rp, struct btcx_skiplist *skips,
680 u32 sync_line, int skip_even, int skip_odd)
681{
682 int line,maxy,start,end,skip,nskips;
683 u32 ri,ra;
684 u32 addr;
685
686 /* sync instruction */
687 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
688
689 addr = (unsigned long)dev->fbuf.base;
690 addr += dev->fbuf.fmt.bytesperline * fh->win.w.top;
691 addr += (fh->fmt->depth >> 3) * fh->win.w.left;
692
693 /* scan lines */
694 for (maxy = -1, line = 0; line < fh->win.w.height;
695 line++, addr += dev->fbuf.fmt.bytesperline) {
696 if ((line%2) == 0 && skip_even)
697 continue;
698 if ((line%2) == 1 && skip_odd)
699 continue;
700
701 /* calculate clipping */
702 if (line > maxy)
703 btcx_calc_skips(line, fh->win.w.width, &maxy,
704 skips, &nskips, fh->clips, fh->nclips);
705
706 /* write out risc code */
707 for (start = 0, skip = 0; start < fh->win.w.width; start = end) {
708 if (skip >= nskips) {
709 ri = RISC_WRITE;
710 end = fh->win.w.width;
711 } else if (start < skips[skip].start) {
712 ri = RISC_WRITE;
713 end = skips[skip].start;
714 } else {
715 ri = RISC_SKIP;
716 end = skips[skip].end;
717 skip++;
718 }
719 if (RISC_WRITE == ri)
720 ra = addr + (fh->fmt->depth>>3)*start;
721 else
722 ra = 0;
723
724 if (0 == start)
725 ri |= RISC_SOL;
726 if (fh->win.w.width == end)
727 ri |= RISC_EOL;
728 ri |= (fh->fmt->depth>>3) * (end-start);
729
730 *(rp++)=cpu_to_le32(ri);
731 if (0 != ra)
732 *(rp++)=cpu_to_le32(ra);
733 }
734 }
735 kfree(skips);
736 return rp;
737}
738
739static int ov_risc_frame(struct cx8800_dev *dev, struct cx8800_fh *fh,
740 struct cx88_buffer *buf)
741{
742 struct btcx_skiplist *skips;
743 u32 instructions,fields;
744 u32 *rp;
745 int rc;
746
747 /* skip list for window clipping */
748 if (NULL == (skips = kmalloc(sizeof(*skips) * fh->nclips,GFP_KERNEL)))
749 return -ENOMEM;
750
751 fields = 0;
752 if (V4L2_FIELD_HAS_TOP(fh->win.field))
753 fields++;
754 if (V4L2_FIELD_HAS_BOTTOM(fh->win.field))
755 fields++;
756
757 /* estimate risc mem: worst case is (clip+1) * lines instructions
758 + syncs + jump (all 2 dwords) */
759 instructions = (fh->nclips+1) * fh->win.w.height;
760 instructions += 3 + 4;
761 if ((rc = btcx_riscmem_alloc(dev->pci,&buf->risc,instructions*8)) < 0) {
762 kfree(skips);
763 return rc;
764 }
765
766 /* write risc instructions */
767 rp = buf->risc.cpu;
768 switch (fh->win.field) {
769 case V4L2_FIELD_TOP:
770 rp = ov_risc_field(dev, fh, rp, skips, 0, 0, 0);
771 break;
772 case V4L2_FIELD_BOTTOM:
773 rp = ov_risc_field(dev, fh, rp, skips, 0x200, 0, 0);
774 break;
775 case V4L2_FIELD_INTERLACED:
776 rp = ov_risc_field(dev, fh, rp, skips, 0, 0, 1);
777 rp = ov_risc_field(dev, fh, rp, skips, 0x200, 1, 0);
778 break;
779 default:
780 BUG();
781 }
782
783 /* save pointer to jmp instruction address */
784 buf->risc.jmp = rp;
785 kfree(skips);
786 return 0;
787}
788
789static int verify_window(struct cx8800_dev *dev, struct v4l2_window *win)
790{
791 enum v4l2_field field;
792 int maxw, maxh;
793
794 if (NULL == dev->fbuf.base)
795 return -EINVAL;
796 if (win->w.width < 48 || win->w.height < 32)
797 return -EINVAL;
798 if (win->clipcount > 2048)
799 return -EINVAL;
800
801 field = win->field;
802 maxw = norm_maxw(core->tvnorm);
803 maxh = norm_maxh(core->tvnorm);
804
805 if (V4L2_FIELD_ANY == field) {
806 field = (win->w.height > maxh/2)
807 ? V4L2_FIELD_INTERLACED
808 : V4L2_FIELD_TOP;
809 }
810 switch (field) {
811 case V4L2_FIELD_TOP:
812 case V4L2_FIELD_BOTTOM:
813 maxh = maxh / 2;
814 break;
815 case V4L2_FIELD_INTERLACED:
816 break;
817 default:
818 return -EINVAL;
819 }
820
821 win->field = field;
822 if (win->w.width > maxw)
823 win->w.width = maxw;
824 if (win->w.height > maxh)
825 win->w.height = maxh;
826 return 0;
827}
828
829static int setup_window(struct cx8800_dev *dev, struct cx8800_fh *fh,
830 struct v4l2_window *win)
831{
832 struct v4l2_clip *clips = NULL;
833 int n,size,retval = 0;
834
835 if (NULL == fh->fmt)
836 return -EINVAL;
837 retval = verify_window(dev,win);
838 if (0 != retval)
839 return retval;
840
841 /* copy clips -- luckily v4l1 + v4l2 are binary
842 compatible here ...*/
843 n = win->clipcount;
844 size = sizeof(*clips)*(n+4);
845 clips = kmalloc(size,GFP_KERNEL);
846 if (NULL == clips)
847 return -ENOMEM;
848 if (n > 0) {
849 if (copy_from_user(clips,win->clips,sizeof(struct v4l2_clip)*n)) {
850 kfree(clips);
851 return -EFAULT;
852 }
853 }
854
855 /* clip against screen */
856 if (NULL != dev->fbuf.base)
857 n = btcx_screen_clips(dev->fbuf.fmt.width, dev->fbuf.fmt.height,
858 &win->w, clips, n);
859 btcx_sort_clips(clips,n);
860
861 /* 4-byte alignments */
862 switch (fh->fmt->depth) {
863 case 8:
864 case 24:
865 btcx_align(&win->w, clips, n, 3);
866 break;
867 case 16:
868 btcx_align(&win->w, clips, n, 1);
869 break;
870 case 32:
871 /* no alignment fixups needed */
872 break;
873 default:
874 BUG();
875 }
876
877 down(&fh->vidq.lock);
878 if (fh->clips)
879 kfree(fh->clips);
880 fh->clips = clips;
881 fh->nclips = n;
882 fh->win = *win;
883#if 0
884 fh->ov.setup_ok = 1;
885#endif
886
887 /* update overlay if needed */
888 retval = 0;
889#if 0
890 if (check_btres(fh, RESOURCE_OVERLAY)) {
891 struct bttv_buffer *new;
892
893 new = videobuf_alloc(sizeof(*new));
894 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
895 retval = bttv_switch_overlay(btv,fh,new);
896 }
897#endif
898 up(&fh->vidq.lock);
899 return retval;
900}
901#endif
902 671
903/* ------------------------------------------------------------------ */ 672/* ------------------------------------------------------------------ */
904 673
@@ -1327,9 +1096,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1327 struct cx8800_fh *fh = file->private_data; 1096 struct cx8800_fh *fh = file->private_data;
1328 struct cx8800_dev *dev = fh->dev; 1097 struct cx8800_dev *dev = fh->dev;
1329 struct cx88_core *core = dev->core; 1098 struct cx88_core *core = dev->core;
1330#if 0
1331 unsigned long flags;
1332#endif
1333 int err; 1099 int err;
1334 1100
1335 if (video_debug > 1) 1101 if (video_debug > 1)
@@ -1350,12 +1116,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1350 V4L2_CAP_READWRITE | 1116 V4L2_CAP_READWRITE |
1351 V4L2_CAP_STREAMING | 1117 V4L2_CAP_STREAMING |
1352 V4L2_CAP_VBI_CAPTURE | 1118 V4L2_CAP_VBI_CAPTURE |
1353#if 0
1354 V4L2_TUNER_CAP_LOW |
1355#endif
1356#if 0
1357 V4L2_CAP_VIDEO_OVERLAY |
1358#endif
1359 0; 1119 0;
1360 if (UNSET != core->tuner_type) 1120 if (UNSET != core->tuner_type)
1361 cap->capabilities |= V4L2_CAP_TUNER; 1121 cap->capabilities |= V4L2_CAP_TUNER;
@@ -1456,36 +1216,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1456 } 1216 }
1457 1217
1458 1218
1459#if 0
1460 /* needs review */
1461 case VIDIOC_G_AUDIO:
1462 {
1463 struct v4l2_audio *a = arg;
1464 unsigned int n = a->index;
1465
1466 memset(a,0,sizeof(*a));
1467 a->index = n;
1468 switch (n) {
1469 case 0:
1470 if ((CX88_VMUX_TELEVISION == INPUT(n)->type)
1471 || (CX88_VMUX_CABLE == INPUT(n)->type)) {
1472 strcpy(a->name,"Television");
1473 // FIXME figure out if stereo received and set V4L2_AUDCAP_STEREO.
1474 return 0;
1475 }
1476 break;
1477 case 1:
1478 if (CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD == core->board) {
1479 strcpy(a->name,"Line In");
1480 a->capability = V4L2_AUDCAP_STEREO;
1481 return 0;
1482 }
1483 break;
1484 }
1485 // Audio input not available.
1486 return -EINVAL;
1487 }
1488#endif
1489 1219
1490 /* --- capture ioctls ---------------------------------------- */ 1220 /* --- capture ioctls ---------------------------------------- */
1491 case VIDIOC_ENUM_FMT: 1221 case VIDIOC_ENUM_FMT:
@@ -1588,13 +1318,16 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1588 { 1318 {
1589 struct v4l2_frequency *f = arg; 1319 struct v4l2_frequency *f = arg;
1590 1320
1321 memset(f,0,sizeof(*f));
1322
1591 if (UNSET == core->tuner_type) 1323 if (UNSET == core->tuner_type)
1592 return -EINVAL; 1324 return -EINVAL;
1593 if (f->tuner != 0) 1325
1594 return -EINVAL;
1595 memset(f,0,sizeof(*f));
1596 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1326 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1597 f->frequency = dev->freq; 1327 f->frequency = dev->freq;
1328
1329 cx88_call_i2c_clients(dev->core,VIDIOC_G_FREQUENCY,f);
1330
1598 return 0; 1331 return 0;
1599 } 1332 }
1600 case VIDIOC_S_FREQUENCY: 1333 case VIDIOC_S_FREQUENCY:
@@ -1612,11 +1345,12 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1612 down(&dev->lock); 1345 down(&dev->lock);
1613 dev->freq = f->frequency; 1346 dev->freq = f->frequency;
1614 cx88_newstation(core); 1347 cx88_newstation(core);
1615#ifdef V4L2_I2C_CLIENTS
1616 cx88_call_i2c_clients(dev->core,VIDIOC_S_FREQUENCY,f); 1348 cx88_call_i2c_clients(dev->core,VIDIOC_S_FREQUENCY,f);
1617#else 1349
1618 cx88_call_i2c_clients(dev->core,VIDIOCSFREQ,&dev->freq); 1350 /* When changing channels it is required to reset TVAUDIO */
1619#endif 1351 msleep (10);
1352 cx88_set_tvaudio(core);
1353
1620 up(&dev->lock); 1354 up(&dev->lock);
1621 return 0; 1355 return 0;
1622 } 1356 }
@@ -1714,11 +1448,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1714 sizeof(cap->card)); 1448 sizeof(cap->card));
1715 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci)); 1449 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1716 cap->version = CX88_VERSION_CODE; 1450 cap->version = CX88_VERSION_CODE;
1717 cap->capabilities = V4L2_CAP_TUNER 1451 cap->capabilities = V4L2_CAP_TUNER;
1718#if 0
1719 | V4L2_TUNER_CAP_LOW
1720#endif
1721 ;
1722 return 0; 1452 return 0;
1723 } 1453 }
1724 case VIDIOC_G_TUNER: 1454 case VIDIOC_G_TUNER:
@@ -1730,19 +1460,8 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1730 1460
1731 memset(t,0,sizeof(*t)); 1461 memset(t,0,sizeof(*t));
1732 strcpy(t->name, "Radio"); 1462 strcpy(t->name, "Radio");
1733 t->rangelow = (int)(65*16);
1734 t->rangehigh = (int)(108*16);
1735 1463
1736#ifdef V4L2_I2C_CLIENTS
1737 cx88_call_i2c_clients(dev->core,VIDIOC_G_TUNER,t); 1464 cx88_call_i2c_clients(dev->core,VIDIOC_G_TUNER,t);
1738#else
1739 {
1740 struct video_tuner vt;
1741 memset(&vt,0,sizeof(vt));
1742 cx88_call_i2c_clients(dev,VIDIOCGTUNER,&vt);
1743 t->signal = vt.signal;
1744 }
1745#endif
1746 return 0; 1465 return 0;
1747 } 1466 }
1748 case VIDIOC_ENUMINPUT: 1467 case VIDIOC_ENUMINPUT:
@@ -1775,8 +1494,29 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
1775 *id = 0; 1494 *id = 0;
1776 return 0; 1495 return 0;
1777 } 1496 }
1778 case VIDIOC_S_AUDIO: 1497 case VIDIOCSTUNER:
1498 {
1499 struct video_tuner *v = arg;
1500
1501 if (v->tuner) /* Only tuner 0 */
1502 return -EINVAL;
1503
1504 cx88_call_i2c_clients(dev->core,VIDIOCSTUNER,v);
1505 return 0;
1506 }
1779 case VIDIOC_S_TUNER: 1507 case VIDIOC_S_TUNER:
1508 {
1509 struct v4l2_tuner *t = arg;
1510
1511 if (0 != t->index)
1512 return -EINVAL;
1513
1514 cx88_call_i2c_clients(dev->core,VIDIOC_S_TUNER,t);
1515
1516 return 0;
1517 }
1518
1519 case VIDIOC_S_AUDIO:
1780 case VIDIOC_S_INPUT: 1520 case VIDIOC_S_INPUT:
1781 case VIDIOC_S_STD: 1521 case VIDIOC_S_STD:
1782 return 0; 1522 return 0;
@@ -1847,6 +1587,14 @@ static void cx8800_vid_timeout(unsigned long data)
1847 spin_unlock_irqrestore(&dev->slock,flags); 1587 spin_unlock_irqrestore(&dev->slock,flags);
1848} 1588}
1849 1589
1590static char *cx88_vid_irqs[32] = {
1591 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1592 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1593 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1594 "y_sync", "u_sync", "v_sync", "vbi_sync",
1595 "opc_err", "par_err", "rip_err", "pci_abort",
1596};
1597
1850static void cx8800_vid_irq(struct cx8800_dev *dev) 1598static void cx8800_vid_irq(struct cx8800_dev *dev)
1851{ 1599{
1852 struct cx88_core *core = dev->core; 1600 struct cx88_core *core = dev->core;
@@ -2014,7 +1762,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2014{ 1762{
2015 struct cx8800_dev *dev; 1763 struct cx8800_dev *dev;
2016 struct cx88_core *core; 1764 struct cx88_core *core;
2017 struct tuner_addr tun_addr;
2018 int err; 1765 int err;
2019 1766
2020 dev = kmalloc(sizeof(*dev),GFP_KERNEL); 1767 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
@@ -2088,22 +1835,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2088 request_module("tuner"); 1835 request_module("tuner");
2089 if (core->tda9887_conf) 1836 if (core->tda9887_conf)
2090 request_module("tda9887"); 1837 request_module("tda9887");
2091 if (core->radio_type != UNSET) {
2092 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO;
2093 tun_addr.type = core->radio_type;
2094 tun_addr.addr = core->radio_addr;
2095 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2096 }
2097 if (core->tuner_type != UNSET) {
2098 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV;
2099 tun_addr.type = core->tuner_type;
2100 tun_addr.addr = core->tuner_addr;
2101 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2102 }
2103
2104 if (core->tda9887_conf)
2105 cx88_call_i2c_clients(dev->core,TDA9887_SET_CONFIG,&core->tda9887_conf);
2106
2107 /* register v4l devices */ 1838 /* register v4l devices */
2108 dev->video_dev = cx88_vdev_init(core,dev->pci, 1839 dev->video_dev = cx88_vdev_init(core,dev->pci,
2109 &cx8800_video_template,"video"); 1840 &cx8800_video_template,"video");
@@ -2213,10 +1944,8 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2213 } 1944 }
2214 spin_unlock(&dev->slock); 1945 spin_unlock(&dev->slock);
2215 1946
2216#if 1
2217 /* FIXME -- shutdown device */ 1947 /* FIXME -- shutdown device */
2218 cx88_shutdown(dev->core); 1948 cx88_shutdown(dev->core);
2219#endif
2220 1949
2221 pci_save_state(pci_dev); 1950 pci_save_state(pci_dev);
2222 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { 1951 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
@@ -2238,10 +1967,8 @@ static int cx8800_resume(struct pci_dev *pci_dev)
2238 pci_set_power_state(pci_dev, PCI_D0); 1967 pci_set_power_state(pci_dev, PCI_D0);
2239 pci_restore_state(pci_dev); 1968 pci_restore_state(pci_dev);
2240 1969
2241#if 1
2242 /* FIXME: re-initialize hardware */ 1970 /* FIXME: re-initialize hardware */
2243 cx88_reset(dev->core); 1971 cx88_reset(dev->core);
2244#endif
2245 1972
2246 /* restart video+vbi capture */ 1973 /* restart video+vbi capture */
2247 spin_lock(&dev->slock); 1974 spin_lock(&dev->slock);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 867e988a5a93..b008f7db6dfd 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88.h,v 1.62 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: cx88.h,v 1.69 2005/07/13 17:25:25 mchehab Exp $
3 * 3 *
4 * v4l2 device driver for cx2388x based TV cards 4 * v4l2 device driver for cx2388x based TV cards
5 * 5 *
@@ -35,8 +35,8 @@
35#include "btcx-risc.h" 35#include "btcx-risc.h"
36#include "cx88-reg.h" 36#include "cx88-reg.h"
37 37
38#include <linux/version.h> 38#include <linux/utsname.h>
39#define CX88_VERSION_CODE KERNEL_VERSION(0,0,4) 39#define CX88_VERSION_CODE KERNEL_VERSION(0,0,5)
40 40
41#ifndef TRUE 41#ifndef TRUE
42# define TRUE (1==1) 42# define TRUE (1==1)
@@ -51,8 +51,6 @@
51/* ----------------------------------------------------------- */ 51/* ----------------------------------------------------------- */
52/* defines and enums */ 52/* defines and enums */
53 53
54#define V4L2_I2C_CLIENTS 1
55
56#define FORMAT_FLAGS_PACKED 0x01 54#define FORMAT_FLAGS_PACKED 0x01
57#define FORMAT_FLAGS_PLANAR 0x02 55#define FORMAT_FLAGS_PLANAR 0x02
58 56
@@ -84,9 +82,9 @@ struct cx88_tvnorm {
84static unsigned int inline norm_maxw(struct cx88_tvnorm *norm) 82static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
85{ 83{
86 return (norm->id & V4L2_STD_625_50) ? 768 : 640; 84 return (norm->id & V4L2_STD_625_50) ? 768 : 640;
87// return (norm->id & V4L2_STD_625_50) ? 720 : 640;
88} 85}
89 86
87
90static unsigned int inline norm_maxh(struct cx88_tvnorm *norm) 88static unsigned int inline norm_maxh(struct cx88_tvnorm *norm)
91{ 89{
92 return (norm->id & V4L2_STD_625_50) ? 576 : 480; 90 return (norm->id & V4L2_STD_625_50) ? 576 : 480;
@@ -159,7 +157,7 @@ extern struct sram_channel cx88_sram_channels[];
159#define CX88_BOARD_KWORLD_DVB_T 14 157#define CX88_BOARD_KWORLD_DVB_T 14
160#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15 158#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1 15
161#define CX88_BOARD_KWORLD_LTV883 16 159#define CX88_BOARD_KWORLD_LTV883 16
162#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD 17 160#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q 17
163#define CX88_BOARD_HAUPPAUGE_DVB_T1 18 161#define CX88_BOARD_HAUPPAUGE_DVB_T1 18
164#define CX88_BOARD_CONEXANT_DVB_T1 19 162#define CX88_BOARD_CONEXANT_DVB_T1 19
165#define CX88_BOARD_PROVIDEO_PV259 20 163#define CX88_BOARD_PROVIDEO_PV259 20
@@ -167,10 +165,12 @@ extern struct sram_channel cx88_sram_channels[];
167#define CX88_BOARD_PCHDTV_HD3000 22 165#define CX88_BOARD_PCHDTV_HD3000 22
168#define CX88_BOARD_DNTV_LIVE_DVB_T 23 166#define CX88_BOARD_DNTV_LIVE_DVB_T 23
169#define CX88_BOARD_HAUPPAUGE_ROSLYN 24 167#define CX88_BOARD_HAUPPAUGE_ROSLYN 24
170#define CX88_BOARD_DIGITALLOGIC_MEC 25 168#define CX88_BOARD_DIGITALLOGIC_MEC 25
171#define CX88_BOARD_IODATA_GVBCTV7E 26 169#define CX88_BOARD_IODATA_GVBCTV7E 26
172#define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27 170#define CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO 27
173#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28 171#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28
172#define CX88_BOARD_ADSTECH_DVB_T_PCI 29
173#define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1 30
174 174
175enum cx88_itype { 175enum cx88_itype {
176 CX88_VMUX_COMPOSITE1 = 1, 176 CX88_VMUX_COMPOSITE1 = 1,
@@ -220,7 +220,6 @@ struct cx88_subid {
220#define RESOURCE_VBI 4 220#define RESOURCE_VBI 4
221 221
222#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */ 222#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
223//#define BUFFER_TIMEOUT (HZ*2)
224 223
225/* buffer for one video frame */ 224/* buffer for one video frame */
226struct cx88_buffer { 225struct cx88_buffer {
@@ -336,11 +335,6 @@ struct cx8800_dev {
336 struct pci_dev *pci; 335 struct pci_dev *pci;
337 unsigned char pci_rev,pci_lat; 336 unsigned char pci_rev,pci_lat;
338 337
339#if 0
340 /* video overlay */
341 struct v4l2_framebuffer fbuf;
342 struct cx88_buffer *screen;
343#endif
344 338
345 /* capture queues */ 339 /* capture queues */
346 struct cx88_dmaqueue vidq; 340 struct cx88_dmaqueue vidq;
@@ -435,8 +429,6 @@ struct cx8802_dev {
435/* ----------------------------------------------------------- */ 429/* ----------------------------------------------------------- */
436/* cx88-core.c */ 430/* cx88-core.c */
437 431
438extern char *cx88_vid_irqs[32];
439extern char *cx88_mpeg_irqs[32];
440extern void cx88_print_irqbits(char *name, char *tag, char **strings, 432extern void cx88_print_irqbits(char *name, char *tag, char **strings,
441 u32 bits, u32 mask); 433 u32 bits, u32 mask);
442extern void cx88_print_ioctl(char *name, unsigned int cmd); 434extern void cx88_print_ioctl(char *name, unsigned int cmd);
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 92664f75d327..9fc5055e001c 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-kbd-i2c.c,v 1.10 2004/12/09 12:51:35 kraxel Exp $ 2 * $Id: ir-kbd-i2c.c,v 1.11 2005/07/07 16:42:11 mchehab Exp $
3 * 3 *
4 * keyboard input driver for i2c IR remote controls 4 * keyboard input driver for i2c IR remote controls
5 * 5 *
@@ -66,26 +66,26 @@ static IR_KEYTAB_TYPE ir_codes_pv951[IR_KEYTAB_SIZE] = {
66 [ 29 ] = KEY_PAGEDOWN, 66 [ 29 ] = KEY_PAGEDOWN,
67 [ 19 ] = KEY_SOUND, 67 [ 19 ] = KEY_SOUND,
68 68
69 [ 24 ] = KEY_KPPLUSMINUS, // CH +/- 69 [ 24 ] = KEY_KPPLUSMINUS, /* CH +/- */
70 [ 22 ] = KEY_SUBTITLE, // CC 70 [ 22 ] = KEY_SUBTITLE, /* CC */
71 [ 13 ] = KEY_TEXT, // TTX 71 [ 13 ] = KEY_TEXT, /* TTX */
72 [ 11 ] = KEY_TV, // AIR/CBL 72 [ 11 ] = KEY_TV, /* AIR/CBL */
73 [ 17 ] = KEY_PC, // PC/TV 73 [ 17 ] = KEY_PC, /* PC/TV */
74 [ 23 ] = KEY_OK, // CH RTN 74 [ 23 ] = KEY_OK, /* CH RTN */
75 [ 25 ] = KEY_MODE, // FUNC 75 [ 25 ] = KEY_MODE, /* FUNC */
76 [ 12 ] = KEY_SEARCH, // AUTOSCAN 76 [ 12 ] = KEY_SEARCH, /* AUTOSCAN */
77 77
78 /* Not sure what to do with these ones! */ 78 /* Not sure what to do with these ones! */
79 [ 15 ] = KEY_SELECT, // SOURCE 79 [ 15 ] = KEY_SELECT, /* SOURCE */
80 [ 10 ] = KEY_KPPLUS, // +100 80 [ 10 ] = KEY_KPPLUS, /* +100 */
81 [ 20 ] = KEY_KPEQUAL, // SYNC 81 [ 20 ] = KEY_KPEQUAL, /* SYNC */
82 [ 28 ] = KEY_MEDIA, // PC/TV 82 [ 28 ] = KEY_MEDIA, /* PC/TV */
83}; 83};
84 84
85static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = { 85static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
86 [ 0x3 ] = KEY_POWER, 86 [ 0x3 ] = KEY_POWER,
87 [ 0x6f ] = KEY_MUTE, 87 [ 0x6f ] = KEY_MUTE,
88 [ 0x10 ] = KEY_BACKSPACE, // Recall 88 [ 0x10 ] = KEY_BACKSPACE, /* Recall */
89 89
90 [ 0x11 ] = KEY_KP0, 90 [ 0x11 ] = KEY_KP0,
91 [ 0x4 ] = KEY_KP1, 91 [ 0x4 ] = KEY_KP1,
@@ -97,7 +97,7 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
97 [ 0xc ] = KEY_KP7, 97 [ 0xc ] = KEY_KP7,
98 [ 0xd ] = KEY_KP8, 98 [ 0xd ] = KEY_KP8,
99 [ 0xe ] = KEY_KP9, 99 [ 0xe ] = KEY_KP9,
100 [ 0x12 ] = KEY_KPDOT, // 100+ 100 [ 0x12 ] = KEY_KPDOT, /* 100+ */
101 101
102 [ 0x7 ] = KEY_VOLUMEUP, 102 [ 0x7 ] = KEY_VOLUMEUP,
103 [ 0xb ] = KEY_VOLUMEDOWN, 103 [ 0xb ] = KEY_VOLUMEDOWN,
@@ -109,25 +109,16 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
109 [ 0x13 ] = KEY_CHANNELDOWN, 109 [ 0x13 ] = KEY_CHANNELDOWN,
110 [ 0x48 ] = KEY_ZOOM, 110 [ 0x48 ] = KEY_ZOOM,
111 111
112 [ 0x1b ] = KEY_VIDEO, // Video source 112 [ 0x1b ] = KEY_VIDEO, /* Video source */
113#if 0 113 [ 0x49 ] = KEY_LANGUAGE, /* MTS Select */
114 [ 0x1f ] = KEY_S, // Snapshot 114 [ 0x19 ] = KEY_SEARCH, /* Auto Scan */
115#endif
116 [ 0x49 ] = KEY_LANGUAGE, // MTS Select
117 [ 0x19 ] = KEY_SEARCH, // Auto Scan
118 115
119 [ 0x4b ] = KEY_RECORD, 116 [ 0x4b ] = KEY_RECORD,
120 [ 0x46 ] = KEY_PLAY, 117 [ 0x46 ] = KEY_PLAY,
121 [ 0x45 ] = KEY_PAUSE, // Pause 118 [ 0x45 ] = KEY_PAUSE, /* Pause */
122 [ 0x44 ] = KEY_STOP, 119 [ 0x44 ] = KEY_STOP,
123#if 0 120 [ 0x40 ] = KEY_FORWARD, /* Forward ? */
124 [ 0x43 ] = KEY_T, // Time Shift 121 [ 0x42 ] = KEY_REWIND, /* Backward ? */
125 [ 0x47 ] = KEY_Y, // Time Shift OFF
126 [ 0x4a ] = KEY_O, // TOP
127 [ 0x17 ] = KEY_F, // SURF CH
128#endif
129 [ 0x40 ] = KEY_FORWARD, // Forward ?
130 [ 0x42 ] = KEY_REWIND, // Backward ?
131 122
132}; 123};
133 124
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index b4ee9dfe6d42..6239254db27e 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -567,10 +567,6 @@ static void msp3400c_set_audmode(struct i2c_client *client, int audmode)
567 switch (audmode) { 567 switch (audmode) {
568 case V4L2_TUNER_MODE_STEREO: 568 case V4L2_TUNER_MODE_STEREO:
569 src = 0x0020 | nicam; 569 src = 0x0020 | nicam;
570#if 0
571 /* spatial effect */
572 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0005,0x4000);
573#endif
574 break; 570 break;
575 case V4L2_TUNER_MODE_MONO: 571 case V4L2_TUNER_MODE_MONO:
576 if (msp->mode == MSP_MODE_AM_NICAM) { 572 if (msp->mode == MSP_MODE_AM_NICAM) {
@@ -741,16 +737,14 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
741 set_current_state(TASK_INTERRUPTIBLE); 737 set_current_state(TASK_INTERRUPTIBLE);
742 schedule(); 738 schedule();
743 } else { 739 } else {
744#if 0
745 /* hmm, that one doesn't return on wakeup ... */
746 msleep_interruptible(timeout);
747#else
748 set_current_state(TASK_INTERRUPTIBLE); 740 set_current_state(TASK_INTERRUPTIBLE);
749 schedule_timeout(msecs_to_jiffies(timeout)); 741 schedule_timeout(msecs_to_jiffies(timeout));
750#endif
751 } 742 }
752 } 743 }
753 try_to_freeze(); 744 if (current->flags & PF_FREEZE) {
745 refrigerator ();
746 }
747
754 remove_wait_queue(&msp->wq, &wait); 748 remove_wait_queue(&msp->wq, &wait);
755 return msp->restart; 749 return msp->restart;
756} 750}
@@ -1154,17 +1148,10 @@ static int msp3410d_thread(void *data)
1154 MSP_CARRIER(10.7)); 1148 MSP_CARRIER(10.7));
1155 /* scart routing */ 1149 /* scart routing */
1156 msp3400c_set_scart(client,SCART_IN2,0); 1150 msp3400c_set_scart(client,SCART_IN2,0);
1157#if 0
1158 /* radio from SCART_IN2 */
1159 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0220);
1160 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0220);
1161 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0220);
1162#else
1163 /* msp34xx does radio decoding */ 1151 /* msp34xx does radio decoding */
1164 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020); 1152 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020);
1165 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020); 1153 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020);
1166 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020); 1154 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020);
1167#endif
1168 break; 1155 break;
1169 case 0x0003: 1156 case 0x0003:
1170 case 0x0004: 1157 case 0x0004:
@@ -1507,10 +1494,6 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1507 return -1; 1494 return -1;
1508 } 1495 }
1509 1496
1510#if 0
1511 /* this will turn on a 1kHz beep - might be useful for debugging... */
1512 msp3400c_write(c,I2C_MSP3400C_DFP, 0x0014, 0x1040);
1513#endif
1514 msp3400c_setvolume(c, msp->muted, msp->volume, msp->balance); 1497 msp3400c_setvolume(c, msp->muted, msp->volume, msp->balance);
1515 1498
1516 snprintf(c->name, sizeof(c->name), "MSP34%02d%c-%c%d", 1499 snprintf(c->name, sizeof(c->name), "MSP34%02d%c-%c%d",
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 95ad17b7f38e..2fb7c2d1787a 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mt20xx.c,v 1.4 2005/03/04 09:24:56 kraxel Exp $ 2 * $Id: mt20xx.c,v 1.5 2005/06/16 08:29:49 nsh Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls microtune tuners, mt2032 + mt2050 at the moment. 5 * controls microtune tuners, mt2032 + mt2050 at the moment.
@@ -295,8 +295,8 @@ static void mt2032_set_radio_freq(struct i2c_client *c, unsigned int freq)
295 int if2 = t->radio_if2; 295 int if2 = t->radio_if2;
296 296
297 // per Manual for FM tuning: first if center freq. 1085 MHz 297 // per Manual for FM tuning: first if center freq. 1085 MHz
298 mt2032_set_if_freq(c, freq*62500 /* freq*1000*1000/16 */, 298 mt2032_set_if_freq(c, freq * 1000 / 16,
299 1085*1000*1000,if2,if2,if2); 299 1085*1000*1000,if2,if2,if2);
300} 300}
301 301
302// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 302// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
@@ -511,22 +511,6 @@ int microtune_init(struct i2c_client *c)
511 tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n", 511 tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n",
512 company_code,buf[0x13],buf[0x14]); 512 company_code,buf[0x13],buf[0x14]);
513 513
514#if 0
515 /* seems to cause more problems than it solves ... */
516 switch (company_code) {
517 case 0x30bf:
518 case 0x3cbf:
519 case 0x3dbf:
520 case 0x4d54:
521 case 0x8e81:
522 case 0x8e91:
523 /* ok (?) */
524 break;
525 default:
526 tuner_warn("tuner: microtune: unknown companycode\n");
527 return 0;
528 }
529#endif
530 514
531 if (buf[0x13] < ARRAY_SIZE(microtune_part) && 515 if (buf[0x13] < ARRAY_SIZE(microtune_part) &&
532 NULL != microtune_part[buf[0x13]]) 516 NULL != microtune_part[buf[0x13]])
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 70bf1f1fad59..486234d41b56 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -326,6 +326,7 @@ static int mxb_init_done(struct saa7146_dev* dev)
326 struct mxb* mxb = (struct mxb*)dev->ext_priv; 326 struct mxb* mxb = (struct mxb*)dev->ext_priv;
327 struct video_decoder_init init; 327 struct video_decoder_init init;
328 struct i2c_msg msg; 328 struct i2c_msg msg;
329 struct tuner_setup tun_setup;
329 330
330 int i = 0, err = 0; 331 int i = 0, err = 0;
331 struct tea6415c_multiplex vm; 332 struct tea6415c_multiplex vm;
@@ -349,8 +350,10 @@ static int mxb_init_done(struct saa7146_dev* dev)
349 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i); 350 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i);
350 351
351 /* select a tuner type */ 352 /* select a tuner type */
352 i = 5; 353 tun_setup.mode_mask = T_ANALOG_TV;
353 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE, &i); 354 tun_setup.addr = ADDR_UNSET;
355 tun_setup.type = 5;
356 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup);
354 357
355 /* mute audio on tea6420s */ 358 /* mute audio on tea6420s */
356 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]); 359 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index e6d0a18833d6..79d05ea1b69b 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -155,10 +155,6 @@ static struct v4l2_mpeg_compression param_defaults =
155 .target = 256, 155 .target = 256,
156 }, 156 },
157 157
158#if 0
159 /* FIXME: size? via S_FMT? */
160 .video_format = MPEG_VIDEO_FORMAT_D1,
161#endif
162}; 158};
163 159
164/* ---------------------------------------------------------------------- */ 160/* ---------------------------------------------------------------------- */
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 0c781e24c446..88b71a20b602 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1,6 +1,5 @@
1
2/* 1/*
3 * $Id: saa7134-cards.c,v 1.58 2005/06/07 18:05:00 nsh Exp $ 2 * $Id: saa7134-cards.c,v 1.80 2005/07/07 01:49:30 mkrufky Exp $
4 * 3 *
5 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
6 * card-specific stuff. 5 * card-specific stuff.
@@ -47,6 +46,10 @@ struct saa7134_board saa7134_boards[] = {
47 .name = "UNKNOWN/GENERIC", 46 .name = "UNKNOWN/GENERIC",
48 .audio_clock = 0x00187de7, 47 .audio_clock = 0x00187de7,
49 .tuner_type = TUNER_ABSENT, 48 .tuner_type = TUNER_ABSENT,
49 .radio_type = UNSET,
50 .tuner_addr = ADDR_UNSET,
51 .radio_addr = ADDR_UNSET,
52
50 .inputs = {{ 53 .inputs = {{
51 .name = "default", 54 .name = "default",
52 .vmux = 0, 55 .vmux = 0,
@@ -58,6 +61,10 @@ struct saa7134_board saa7134_boards[] = {
58 .name = "Proteus Pro [philips reference design]", 61 .name = "Proteus Pro [philips reference design]",
59 .audio_clock = 0x00187de7, 62 .audio_clock = 0x00187de7,
60 .tuner_type = TUNER_PHILIPS_PAL, 63 .tuner_type = TUNER_PHILIPS_PAL,
64 .radio_type = UNSET,
65 .tuner_addr = ADDR_UNSET,
66 .radio_addr = ADDR_UNSET,
67
61 .inputs = {{ 68 .inputs = {{
62 .name = name_comp1, 69 .name = name_comp1,
63 .vmux = 0, 70 .vmux = 0,
@@ -83,6 +90,10 @@ struct saa7134_board saa7134_boards[] = {
83 .name = "LifeView FlyVIDEO3000", 90 .name = "LifeView FlyVIDEO3000",
84 .audio_clock = 0x00200000, 91 .audio_clock = 0x00200000,
85 .tuner_type = TUNER_PHILIPS_PAL, 92 .tuner_type = TUNER_PHILIPS_PAL,
93 .radio_type = UNSET,
94 .tuner_addr = ADDR_UNSET,
95 .radio_addr = ADDR_UNSET,
96
86 .gpiomask = 0xe000, 97 .gpiomask = 0xe000,
87 .inputs = {{ 98 .inputs = {{
88 .name = name_tv, 99 .name = name_tv,
@@ -90,7 +101,7 @@ struct saa7134_board saa7134_boards[] = {
90 .amux = TV, 101 .amux = TV,
91 .gpio = 0x8000, 102 .gpio = 0x8000,
92 .tv = 1, 103 .tv = 1,
93 },{ 104 },{
94 .name = name_tv_mono, 105 .name = name_tv_mono,
95 .vmux = 1, 106 .vmux = 1,
96 .amux = LINE2, 107 .amux = LINE2,
@@ -117,12 +128,21 @@ struct saa7134_board saa7134_boards[] = {
117 .amux = LINE2, 128 .amux = LINE2,
118 .gpio = 0x2000, 129 .gpio = 0x2000,
119 }, 130 },
131 .mute = {
132 .name = name_mute,
133 .amux = TV,
134 .gpio = 0x8000,
135 },
120 }, 136 },
121 [SAA7134_BOARD_FLYVIDEO2000] = { 137 [SAA7134_BOARD_FLYVIDEO2000] = {
122 /* "TC Wan" <tcwan@cs.usm.my> */ 138 /* "TC Wan" <tcwan@cs.usm.my> */
123 .name = "LifeView FlyVIDEO2000", 139 .name = "LifeView FlyVIDEO2000",
124 .audio_clock = 0x00200000, 140 .audio_clock = 0x00200000,
125 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 141 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
142 .radio_type = UNSET,
143 .tuner_addr = ADDR_UNSET,
144 .radio_addr = ADDR_UNSET,
145
126 .gpiomask = 0xe000, 146 .gpiomask = 0xe000,
127 .inputs = {{ 147 .inputs = {{
128 .name = name_tv, 148 .name = name_tv,
@@ -146,14 +166,14 @@ struct saa7134_board saa7134_boards[] = {
146 .amux = LINE2, 166 .amux = LINE2,
147 .gpio = 0x4000, 167 .gpio = 0x4000,
148 }}, 168 }},
149 .radio = { 169 .radio = {
150 .name = name_radio, 170 .name = name_radio,
151 .amux = LINE2, 171 .amux = LINE2,
152 .gpio = 0x2000, 172 .gpio = 0x2000,
153 }, 173 },
154 .mute = { 174 .mute = {
155 .name = name_mute, 175 .name = name_mute,
156 .amux = LINE2, 176 .amux = LINE2,
157 .gpio = 0x8000, 177 .gpio = 0x8000,
158 }, 178 },
159 }, 179 },
@@ -162,6 +182,10 @@ struct saa7134_board saa7134_boards[] = {
162 .name = "LifeView FlyTV Platinum Mini", 182 .name = "LifeView FlyTV Platinum Mini",
163 .audio_clock = 0x00200000, 183 .audio_clock = 0x00200000,
164 .tuner_type = TUNER_PHILIPS_TDA8290, 184 .tuner_type = TUNER_PHILIPS_TDA8290,
185 .radio_type = UNSET,
186 .tuner_addr = ADDR_UNSET,
187 .radio_addr = ADDR_UNSET,
188
165 .inputs = {{ 189 .inputs = {{
166 .name = name_tv, 190 .name = name_tv,
167 .vmux = 1, 191 .vmux = 1,
@@ -183,6 +207,10 @@ struct saa7134_board saa7134_boards[] = {
183 .name = "LifeView FlyTV Platinum FM", 207 .name = "LifeView FlyTV Platinum FM",
184 .audio_clock = 0x00200000, 208 .audio_clock = 0x00200000,
185 .tuner_type = TUNER_PHILIPS_TDA8290, 209 .tuner_type = TUNER_PHILIPS_TDA8290,
210 .radio_type = UNSET,
211 .tuner_addr = ADDR_UNSET,
212 .radio_addr = ADDR_UNSET,
213
186 .gpiomask = 0x1E000, /* Set GP16 and unused 15,14,13 to Output */ 214 .gpiomask = 0x1E000, /* Set GP16 and unused 15,14,13 to Output */
187 .inputs = {{ 215 .inputs = {{
188 .name = name_tv, 216 .name = name_tv,
@@ -190,7 +218,7 @@ struct saa7134_board saa7134_boards[] = {
190 .amux = TV, 218 .amux = TV,
191 .gpio = 0x10000, /* GP16=1 selects TV input */ 219 .gpio = 0x10000, /* GP16=1 selects TV input */
192 .tv = 1, 220 .tv = 1,
193 },{ 221 },{
194/* .name = name_tv_mono, 222/* .name = name_tv_mono,
195 .vmux = 1, 223 .vmux = 1,
196 .amux = LINE2, 224 .amux = LINE2,
@@ -200,29 +228,38 @@ struct saa7134_board saa7134_boards[] = {
200*/ .name = name_comp1, /* Composite signal on S-Video input */ 228*/ .name = name_comp1, /* Composite signal on S-Video input */
201 .vmux = 0, 229 .vmux = 0,
202 .amux = LINE2, 230 .amux = LINE2,
203// .gpio = 0x4000, 231/* .gpio = 0x4000, */
204 },{ 232 },{
205 .name = name_comp2, /* Composite input */ 233 .name = name_comp2, /* Composite input */
206 .vmux = 3, 234 .vmux = 3,
207 .amux = LINE2, 235 .amux = LINE2,
208// .gpio = 0x4000, 236/* .gpio = 0x4000, */
209 },{ 237 },{
210 .name = name_svideo, /* S-Video signal on S-Video input */ 238 .name = name_svideo, /* S-Video signal on S-Video input */
211 .vmux = 8, 239 .vmux = 8,
212 .amux = LINE2, 240 .amux = LINE2,
213// .gpio = 0x4000, 241/* .gpio = 0x4000, */
214 }}, 242 }},
215 .radio = { 243 .radio = {
216 .name = name_radio, 244 .name = name_radio,
217 .amux = TV, 245 .amux = TV,
218 .gpio = 0x00000, /* GP16=0 selects FM radio antenna */ 246 .gpio = 0x00000, /* GP16=0 selects FM radio antenna */
219 }, 247 },
248 .mute = {
249 .name = name_mute,
250 .amux = TV,
251 .gpio = 0x10000,
252 },
220 }, 253 },
221 [SAA7134_BOARD_EMPRESS] = { 254 [SAA7134_BOARD_EMPRESS] = {
222 /* "Gert Vervoort" <gert.vervoort@philips.com> */ 255 /* "Gert Vervoort" <gert.vervoort@philips.com> */
223 .name = "EMPRESS", 256 .name = "EMPRESS",
224 .audio_clock = 0x00187de7, 257 .audio_clock = 0x00187de7,
225 .tuner_type = TUNER_PHILIPS_PAL, 258 .tuner_type = TUNER_PHILIPS_PAL,
259 .radio_type = UNSET,
260 .tuner_addr = ADDR_UNSET,
261 .radio_addr = ADDR_UNSET,
262
226 .inputs = {{ 263 .inputs = {{
227 .name = name_comp1, 264 .name = name_comp1,
228 .vmux = 0, 265 .vmux = 0,
@@ -245,33 +282,40 @@ struct saa7134_board saa7134_boards[] = {
245 .video_out = CCIR656, 282 .video_out = CCIR656,
246 }, 283 },
247 [SAA7134_BOARD_MONSTERTV] = { 284 [SAA7134_BOARD_MONSTERTV] = {
248 /* "K.Ohta" <alpha292@bremen.or.jp> */ 285 /* "K.Ohta" <alpha292@bremen.or.jp> */
249 .name = "SKNet Monster TV", 286 .name = "SKNet Monster TV",
250 .audio_clock = 0x00187de7, 287 .audio_clock = 0x00187de7,
251 .tuner_type = TUNER_PHILIPS_NTSC_M, 288 .tuner_type = TUNER_PHILIPS_NTSC_M,
252 .inputs = {{ 289 .radio_type = UNSET,
253 .name = name_tv, 290 .tuner_addr = ADDR_UNSET,
254 .vmux = 1, 291 .radio_addr = ADDR_UNSET,
255 .amux = TV, 292
256 .tv = 1, 293 .inputs = {{
257 },{ 294 .name = name_tv,
258 .name = name_comp1, 295 .vmux = 1,
259 .vmux = 0, 296 .amux = TV,
260 .amux = LINE1, 297 .tv = 1,
261 },{ 298 },{
262 .name = name_svideo, 299 .name = name_comp1,
263 .vmux = 8, 300 .vmux = 0,
264 .amux = LINE1, 301 .amux = LINE1,
265 }}, 302 },{
266 .radio = { 303 .name = name_svideo,
267 .name = name_radio, 304 .vmux = 8,
268 .amux = LINE2, 305 .amux = LINE1,
269 }, 306 }},
307 .radio = {
308 .name = name_radio,
309 .amux = LINE2,
310 },
270 }, 311 },
271 [SAA7134_BOARD_MD9717] = { 312 [SAA7134_BOARD_MD9717] = {
272 .name = "Tevion MD 9717", 313 .name = "Tevion MD 9717",
273 .audio_clock = 0x00200000, 314 .audio_clock = 0x00200000,
274 .tuner_type = TUNER_PHILIPS_PAL, 315 .tuner_type = TUNER_PHILIPS_PAL,
316 .radio_type = UNSET,
317 .tuner_addr = ADDR_UNSET,
318 .radio_addr = ADDR_UNSET,
275 .inputs = {{ 319 .inputs = {{
276 .name = name_tv, 320 .name = name_tv,
277 .vmux = 1, 321 .vmux = 1,
@@ -302,10 +346,13 @@ struct saa7134_board saa7134_boards[] = {
302 }, 346 },
303 }, 347 },
304 [SAA7134_BOARD_TVSTATION_RDS] = { 348 [SAA7134_BOARD_TVSTATION_RDS] = {
305 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */ 349 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */
306 .name = "KNC One TV-Station RDS / Typhoon TV Tuner RDS", 350 .name = "KNC One TV-Station RDS / Typhoon TV Tuner RDS",
307 .audio_clock = 0x00200000, 351 .audio_clock = 0x00200000,
308 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 352 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
353 .radio_type = UNSET,
354 .tuner_addr = ADDR_UNSET,
355 .radio_addr = ADDR_UNSET,
309 .tda9887_conf = TDA9887_PRESENT, 356 .tda9887_conf = TDA9887_PRESENT,
310 .inputs = {{ 357 .inputs = {{
311 .name = name_tv, 358 .name = name_tv,
@@ -314,10 +361,10 @@ struct saa7134_board saa7134_boards[] = {
314 .tv = 1, 361 .tv = 1,
315 },{ 362 },{
316 .name = name_tv_mono, 363 .name = name_tv_mono,
317 .vmux = 1, 364 .vmux = 1,
318 .amux = LINE2, 365 .amux = LINE2,
319 .tv = 1, 366 .tv = 1,
320 },{ 367 },{
321 368
322 .name = name_svideo, 369 .name = name_svideo,
323 .vmux = 8, 370 .vmux = 8,
@@ -328,10 +375,10 @@ struct saa7134_board saa7134_boards[] = {
328 .amux = LINE1, 375 .amux = LINE1,
329 },{ 376 },{
330 377
331 .name = "CVid over SVid", 378 .name = "CVid over SVid",
332 .vmux = 0, 379 .vmux = 0,
333 .amux = LINE1, 380 .amux = LINE1,
334 }}, 381 }},
335 .radio = { 382 .radio = {
336 .name = name_radio, 383 .name = name_radio,
337 .amux = LINE2, 384 .amux = LINE2,
@@ -341,6 +388,9 @@ struct saa7134_board saa7134_boards[] = {
341 .name = "KNC One TV-Station DVR", 388 .name = "KNC One TV-Station DVR",
342 .audio_clock = 0x00200000, 389 .audio_clock = 0x00200000,
343 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 390 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
391 .radio_type = UNSET,
392 .tuner_addr = ADDR_UNSET,
393 .radio_addr = ADDR_UNSET,
344 .tda9887_conf = TDA9887_PRESENT, 394 .tda9887_conf = TDA9887_PRESENT,
345 .gpiomask = 0x820000, 395 .gpiomask = 0x820000,
346 .inputs = {{ 396 .inputs = {{
@@ -369,32 +419,38 @@ struct saa7134_board saa7134_boards[] = {
369 .video_out = CCIR656, 419 .video_out = CCIR656,
370 }, 420 },
371 [SAA7134_BOARD_CINERGY400] = { 421 [SAA7134_BOARD_CINERGY400] = {
372 .name = "Terratec Cinergy 400 TV", 422 .name = "Terratec Cinergy 400 TV",
373 .audio_clock = 0x00200000, 423 .audio_clock = 0x00200000,
374 .tuner_type = TUNER_PHILIPS_PAL, 424 .tuner_type = TUNER_PHILIPS_PAL,
375 .inputs = {{ 425 .radio_type = UNSET,
376 .name = name_tv, 426 .tuner_addr = ADDR_UNSET,
377 .vmux = 1, 427 .radio_addr = ADDR_UNSET,
378 .amux = TV, 428 .inputs = {{
379 .tv = 1, 429 .name = name_tv,
380 },{ 430 .vmux = 1,
381 .name = name_comp1, 431 .amux = TV,
382 .vmux = 4, 432 .tv = 1,
383 .amux = LINE1, 433 },{
384 },{ 434 .name = name_comp1,
385 .name = name_svideo, 435 .vmux = 4,
386 .vmux = 8, 436 .amux = LINE1,
387 .amux = LINE1, 437 },{
388 },{ 438 .name = name_svideo,
389 .name = name_comp2, // CVideo over SVideo Connector 439 .vmux = 8,
390 .vmux = 0, 440 .amux = LINE1,
391 .amux = LINE1, 441 },{
392 }} 442 .name = name_comp2, /* CVideo over SVideo Connector */
393 }, 443 .vmux = 0,
444 .amux = LINE1,
445 }}
446 },
394 [SAA7134_BOARD_MD5044] = { 447 [SAA7134_BOARD_MD5044] = {
395 .name = "Medion 5044", 448 .name = "Medion 5044",
396 .audio_clock = 0x00187de7, // was: 0x00200000, 449 .audio_clock = 0x00187de7, /* was: 0x00200000, */
397 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 450 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
451 .radio_type = UNSET,
452 .tuner_addr = ADDR_UNSET,
453 .radio_addr = ADDR_UNSET,
398 .tda9887_conf = TDA9887_PRESENT, 454 .tda9887_conf = TDA9887_PRESENT,
399 .inputs = {{ 455 .inputs = {{
400 .name = name_tv, 456 .name = name_tv,
@@ -426,57 +482,65 @@ struct saa7134_board saa7134_boards[] = {
426 }, 482 },
427 }, 483 },
428 [SAA7134_BOARD_KWORLD] = { 484 [SAA7134_BOARD_KWORLD] = {
429 .name = "Kworld/KuroutoShikou SAA7130-TVPCI", 485 .name = "Kworld/KuroutoShikou SAA7130-TVPCI",
430 .audio_clock = 0x00187de7, 486 .audio_clock = 0x00187de7,
431 .tuner_type = TUNER_PHILIPS_NTSC_M, 487 .tuner_type = TUNER_PHILIPS_NTSC_M,
432 .inputs = {{ 488 .radio_type = UNSET,
433 .name = name_svideo, 489 .tuner_addr = ADDR_UNSET,
434 .vmux = 8, 490 .radio_addr = ADDR_UNSET,
435 .amux = LINE1, 491 .inputs = {{
436 },{ 492 .name = name_svideo,
437 .name = name_comp1, 493 .vmux = 8,
438 .vmux = 3, 494 .amux = LINE1,
439 .amux = LINE1, 495 },{
440 },{ 496 .name = name_comp1,
441 .name = name_tv, 497 .vmux = 3,
442 .vmux = 1, 498 .amux = LINE1,
443 .amux = LINE2, 499 },{
444 .tv = 1, 500 .name = name_tv,
445 }}, 501 .vmux = 1,
446 }, 502 .amux = LINE2,
503 .tv = 1,
504 }},
505 },
447 [SAA7134_BOARD_CINERGY600] = { 506 [SAA7134_BOARD_CINERGY600] = {
448 .name = "Terratec Cinergy 600 TV", 507 .name = "Terratec Cinergy 600 TV",
449 .audio_clock = 0x00200000, 508 .audio_clock = 0x00200000,
450 .tuner_type = TUNER_PHILIPS_PAL, 509 .tuner_type = TUNER_PHILIPS_PAL,
510 .radio_type = UNSET,
511 .tuner_addr = ADDR_UNSET,
512 .radio_addr = ADDR_UNSET,
451 .tda9887_conf = TDA9887_PRESENT, 513 .tda9887_conf = TDA9887_PRESENT,
452 .inputs = {{ 514 .inputs = {{
453 .name = name_tv, 515 .name = name_tv,
454 .vmux = 1, 516 .vmux = 1,
455 .amux = TV, 517 .amux = TV,
456 .tv = 1, 518 .tv = 1,
457 },{ 519 },{
458 .name = name_comp1, 520 .name = name_comp1,
459 .vmux = 4, 521 .vmux = 4,
460 .amux = LINE1, 522 .amux = LINE1,
461 },{ 523 },{
462 .name = name_svideo, 524 .name = name_svideo,
463 .vmux = 8, 525 .vmux = 8,
464 .amux = LINE1, 526 .amux = LINE1,
465 },{ 527 },{
466 .name = name_comp2, // CVideo over SVideo Connector 528 .name = name_comp2, /* CVideo over SVideo Connector */
467 .vmux = 0, 529 .vmux = 0,
468 .amux = LINE1, 530 .amux = LINE1,
469 }}, 531 }},
470 .radio = { 532 .radio = {
471 .name = name_radio, 533 .name = name_radio,
472 .amux = LINE2, 534 .amux = LINE2,
473 }, 535 },
474 }, 536 },
475 [SAA7134_BOARD_MD7134] = { 537 [SAA7134_BOARD_MD7134] = {
476 .name = "Medion 7134", 538 .name = "Medion 7134",
477 //.audio_clock = 0x00200000,
478 .audio_clock = 0x00187de7, 539 .audio_clock = 0x00187de7,
479 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 540 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
541 .radio_type = UNSET,
542 .tuner_addr = ADDR_UNSET,
543 .radio_addr = ADDR_UNSET,
480 .tda9887_conf = TDA9887_PRESENT, 544 .tda9887_conf = TDA9887_PRESENT,
481 .mpeg = SAA7134_MPEG_DVB, 545 .mpeg = SAA7134_MPEG_DVB,
482 .inputs = {{ 546 .inputs = {{
@@ -504,6 +568,9 @@ struct saa7134_board saa7134_boards[] = {
504 .name = "Typhoon TV+Radio 90031", 568 .name = "Typhoon TV+Radio 90031",
505 .audio_clock = 0x00200000, 569 .audio_clock = 0x00200000,
506 .tuner_type = TUNER_PHILIPS_PAL, 570 .tuner_type = TUNER_PHILIPS_PAL,
571 .radio_type = UNSET,
572 .tuner_addr = ADDR_UNSET,
573 .radio_addr = ADDR_UNSET,
507 .tda9887_conf = TDA9887_PRESENT, 574 .tda9887_conf = TDA9887_PRESENT,
508 .inputs = {{ 575 .inputs = {{
509 .name = name_tv, 576 .name = name_tv,
@@ -523,11 +590,14 @@ struct saa7134_board saa7134_boards[] = {
523 .name = name_radio, 590 .name = name_radio,
524 .amux = LINE2, 591 .amux = LINE2,
525 }, 592 },
526 }, 593 },
527 [SAA7134_BOARD_ELSA] = { 594 [SAA7134_BOARD_ELSA] = {
528 .name = "ELSA EX-VISION 300TV", 595 .name = "ELSA EX-VISION 300TV",
529 .audio_clock = 0x00187de7, 596 .audio_clock = 0x00187de7,
530 .tuner_type = TUNER_HITACHI_NTSC, 597 .tuner_type = TUNER_HITACHI_NTSC,
598 .radio_type = UNSET,
599 .tuner_addr = ADDR_UNSET,
600 .radio_addr = ADDR_UNSET,
531 .inputs = {{ 601 .inputs = {{
532 .name = name_svideo, 602 .name = name_svideo,
533 .vmux = 8, 603 .vmux = 8,
@@ -542,11 +612,14 @@ struct saa7134_board saa7134_boards[] = {
542 .amux = LINE2, 612 .amux = LINE2,
543 .tv = 1, 613 .tv = 1,
544 }}, 614 }},
545 }, 615 },
546 [SAA7134_BOARD_ELSA_500TV] = { 616 [SAA7134_BOARD_ELSA_500TV] = {
547 .name = "ELSA EX-VISION 500TV", 617 .name = "ELSA EX-VISION 500TV",
548 .audio_clock = 0x00187de7, 618 .audio_clock = 0x00187de7,
549 .tuner_type = TUNER_HITACHI_NTSC, 619 .tuner_type = TUNER_HITACHI_NTSC,
620 .radio_type = UNSET,
621 .tuner_addr = ADDR_UNSET,
622 .radio_addr = ADDR_UNSET,
550 .inputs = {{ 623 .inputs = {{
551 .name = name_svideo, 624 .name = name_svideo,
552 .vmux = 7, 625 .vmux = 7,
@@ -562,83 +635,100 @@ struct saa7134_board saa7134_boards[] = {
562 .amux = LINE2, 635 .amux = LINE2,
563 .tv = 1, 636 .tv = 1,
564 }}, 637 }},
565 }, 638 },
566 [SAA7134_BOARD_ASUSTeK_TVFM7134] = { 639 [SAA7134_BOARD_ASUSTeK_TVFM7134] = {
567 .name = "ASUS TV-FM 7134", 640 .name = "ASUS TV-FM 7134",
568 .audio_clock = 0x00187de7, 641 .audio_clock = 0x00187de7,
569 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 642 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
570 .tda9887_conf = TDA9887_PRESENT, 643 .radio_type = UNSET,
571 .inputs = {{ 644 .tuner_addr = ADDR_UNSET,
572 .name = name_tv, 645 .radio_addr = ADDR_UNSET,
573 .vmux = 1, 646 .tda9887_conf = TDA9887_PRESENT,
574 .amux = TV, 647 .inputs = {{
575 .tv = 1, 648 .name = name_tv,
576 },{ 649 .vmux = 1,
577 .name = name_comp1, 650 .amux = TV,
578 .vmux = 4, 651 .tv = 1,
579 .amux = LINE2, 652 },{
580 },{ 653 .name = name_comp1,
581 .name = name_svideo, 654 .vmux = 4,
582 .vmux = 6, 655 .amux = LINE2,
583 .amux = LINE2, 656 },{
584 }}, 657 .name = name_svideo,
585 .radio = { 658 .vmux = 6,
586 .name = name_radio, 659 .amux = LINE2,
587 .amux = LINE1, 660 }},
588 }, 661 .radio = {
589 }, 662 .name = name_radio,
590 [SAA7135_BOARD_ASUSTeK_TVFM7135] = { 663 .amux = LINE1,
591 .name = "ASUS TV-FM 7135", 664 },
592 .audio_clock = 0x00187de7, 665 },
593 .tuner_type = TUNER_PHILIPS_TDA8290, 666 [SAA7134_BOARD_ASUSTeK_TVFM7135] = {
667 .name = "ASUS TV-FM 7135",
668 .audio_clock = 0x00187de7,
669 .tuner_type = TUNER_PHILIPS_TDA8290,
670 .radio_type = UNSET,
671 .tuner_addr = ADDR_UNSET,
672 .radio_addr = ADDR_UNSET,
594 .gpiomask = 0x200000, 673 .gpiomask = 0x200000,
595 .inputs = {{ 674 .inputs = {{
596 .name = name_tv, 675 .name = name_tv,
597 .vmux = 1, 676 .vmux = 1,
598 .amux = TV, 677 .amux = TV,
599 .gpio = 0x0000, 678 .gpio = 0x0000,
600 .tv = 1, 679 .tv = 1,
601 },{ 680 },{
602 .name = name_comp1, 681 .name = name_comp1,
603 .vmux = 4, 682 .vmux = 4,
604 .amux = LINE2, 683 .amux = LINE2,
605 .gpio = 0x0000, 684 .gpio = 0x0000,
606 },{ 685 },{
607 .name = name_svideo, 686 .name = name_svideo,
608 .vmux = 6, 687 .vmux = 6,
609 .amux = LINE2, 688 .amux = LINE2,
610 .gpio = 0x0000, 689 .gpio = 0x0000,
611 }}, 690 }},
612 .radio = { 691 .radio = {
613 .name = name_radio, 692 .name = name_radio,
614 .amux = TV, 693 .amux = TV,
615 .gpio = 0x200000, 694 .gpio = 0x200000,
616 }, 695 },
696 .mute = {
697 .name = name_mute,
698 .gpio = 0x0000,
699 },
700
617 }, 701 },
618 [SAA7134_BOARD_VA1000POWER] = { 702 [SAA7134_BOARD_VA1000POWER] = {
619 .name = "AOPEN VA1000 POWER", 703 .name = "AOPEN VA1000 POWER",
620 .audio_clock = 0x00187de7, 704 .audio_clock = 0x00187de7,
621 .tuner_type = TUNER_PHILIPS_NTSC, 705 .tuner_type = TUNER_PHILIPS_NTSC,
622 .inputs = {{ 706 .radio_type = UNSET,
623 .name = name_svideo, 707 .tuner_addr = ADDR_UNSET,
624 .vmux = 8, 708 .radio_addr = ADDR_UNSET,
625 .amux = LINE1, 709 .inputs = {{
626 },{ 710 .name = name_svideo,
627 .name = name_comp1, 711 .vmux = 8,
628 .vmux = 3, 712 .amux = LINE1,
629 .amux = LINE1, 713 },{
630 },{ 714 .name = name_comp1,
631 .name = name_tv, 715 .vmux = 3,
632 .vmux = 1, 716 .amux = LINE1,
633 .amux = LINE2, 717 },{
634 .tv = 1, 718 .name = name_tv,
635 }}, 719 .vmux = 1,
720 .amux = LINE2,
721 .tv = 1,
722 }},
636 }, 723 },
637 [SAA7134_BOARD_10MOONSTVMASTER] = { 724 [SAA7134_BOARD_10MOONSTVMASTER] = {
638 /* "lilicheng" <llc@linuxfans.org> */ 725 /* "lilicheng" <llc@linuxfans.org> */
639 .name = "10MOONS PCI TV CAPTURE CARD", 726 .name = "10MOONS PCI TV CAPTURE CARD",
640 .audio_clock = 0x00200000, 727 .audio_clock = 0x00200000,
641 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 728 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
729 .radio_type = UNSET,
730 .tuner_addr = ADDR_UNSET,
731 .radio_addr = ADDR_UNSET,
642 .gpiomask = 0xe000, 732 .gpiomask = 0xe000,
643 .inputs = {{ 733 .inputs = {{
644 .name = name_tv, 734 .name = name_tv,
@@ -662,14 +752,14 @@ struct saa7134_board saa7134_boards[] = {
662 .amux = LINE2, 752 .amux = LINE2,
663 .gpio = 0x4000, 753 .gpio = 0x4000,
664 }}, 754 }},
665 .radio = { 755 .radio = {
666 .name = name_radio, 756 .name = name_radio,
667 .amux = LINE2, 757 .amux = LINE2,
668 .gpio = 0x2000, 758 .gpio = 0x2000,
669 }, 759 },
670 .mute = { 760 .mute = {
671 .name = name_mute, 761 .name = name_mute,
672 .amux = LINE2, 762 .amux = LINE2,
673 .gpio = 0x8000, 763 .gpio = 0x8000,
674 }, 764 },
675 }, 765 },
@@ -678,6 +768,9 @@ struct saa7134_board saa7134_boards[] = {
678 .name = "BMK MPEX No Tuner", 768 .name = "BMK MPEX No Tuner",
679 .audio_clock = 0x200000, 769 .audio_clock = 0x200000,
680 .tuner_type = TUNER_ABSENT, 770 .tuner_type = TUNER_ABSENT,
771 .radio_type = UNSET,
772 .tuner_addr = ADDR_UNSET,
773 .radio_addr = ADDR_UNSET,
681 .inputs = {{ 774 .inputs = {{
682 .name = name_comp1, 775 .name = name_comp1,
683 .vmux = 4, 776 .vmux = 4,
@@ -706,80 +799,94 @@ struct saa7134_board saa7134_boards[] = {
706 .name = "Compro VideoMate TV", 799 .name = "Compro VideoMate TV",
707 .audio_clock = 0x00187de7, 800 .audio_clock = 0x00187de7,
708 .tuner_type = TUNER_PHILIPS_NTSC_M, 801 .tuner_type = TUNER_PHILIPS_NTSC_M,
709 .inputs = {{ 802 .radio_type = UNSET,
710 .name = name_svideo, 803 .tuner_addr = ADDR_UNSET,
711 .vmux = 8, 804 .radio_addr = ADDR_UNSET,
712 .amux = LINE1, 805 .inputs = {{
713 },{ 806 .name = name_svideo,
714 .name = name_comp1, 807 .vmux = 8,
715 .vmux = 3, 808 .amux = LINE1,
716 .amux = LINE1, 809 },{
717 },{ 810 .name = name_comp1,
718 .name = name_tv, 811 .vmux = 3,
719 .vmux = 1, 812 .amux = LINE1,
720 .amux = LINE2, 813 },{
721 .tv = 1, 814 .name = name_tv,
722 }}, 815 .vmux = 1,
723 }, 816 .amux = LINE2,
724 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS] = { 817 .tv = 1,
818 }},
819 },
820 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS] = {
725 .name = "Compro VideoMate TV Gold+", 821 .name = "Compro VideoMate TV Gold+",
726 .audio_clock = 0x00187de7, 822 .audio_clock = 0x00187de7,
727 .tuner_type = TUNER_PHILIPS_NTSC_M, 823 .tuner_type = TUNER_PHILIPS_NTSC_M,
728 .gpiomask = 0x800c0000, 824 .gpiomask = 0x800c0000,
729 .inputs = {{ 825 .radio_type = UNSET,
730 .name = name_svideo, 826 .tuner_addr = ADDR_UNSET,
731 .vmux = 8, 827 .radio_addr = ADDR_UNSET,
732 .amux = LINE1, 828 .inputs = {{
733 .gpio = 0x06c00012, 829 .name = name_svideo,
734 },{ 830 .vmux = 8,
735 .name = name_comp1, 831 .amux = LINE1,
736 .vmux = 3, 832 .gpio = 0x06c00012,
737 .amux = LINE1, 833 },{
738 .gpio = 0x0ac20012, 834 .name = name_comp1,
739 },{ 835 .vmux = 3,
740 .name = name_tv, 836 .amux = LINE1,
741 .vmux = 1, 837 .gpio = 0x0ac20012,
742 .amux = LINE2, 838 },{
743 .gpio = 0x08c20012, 839 .name = name_tv,
744 .tv = 1, 840 .vmux = 1,
745 }}, 841 .amux = LINE2,
746 }, 842 .gpio = 0x08c20012,
843 .tv = 1,
844 }}, /* radio and probably mute is missing */
845 },
747 [SAA7134_BOARD_CRONOS_PLUS] = { 846 [SAA7134_BOARD_CRONOS_PLUS] = {
748 /* gpio pins: 847 /*
749 0 .. 3 BASE_ID 848 gpio pins:
750 4 .. 7 PROTECT_ID 849 0 .. 3 BASE_ID
751 8 .. 11 USER_OUT 850 4 .. 7 PROTECT_ID
752 12 .. 13 USER_IN 851 8 .. 11 USER_OUT
753 14 .. 15 VIDIN_SEL */ 852 12 .. 13 USER_IN
853 14 .. 15 VIDIN_SEL
854 */
754 .name = "Matrox CronosPlus", 855 .name = "Matrox CronosPlus",
755 .tuner_type = TUNER_ABSENT, 856 .tuner_type = TUNER_ABSENT,
857 .radio_type = UNSET,
858 .tuner_addr = ADDR_UNSET,
859 .radio_addr = ADDR_UNSET,
756 .gpiomask = 0xcf00, 860 .gpiomask = 0xcf00,
757 .inputs = {{ 861 .inputs = {{
758 .name = name_comp1, 862 .name = name_comp1,
759 .vmux = 0, 863 .vmux = 0,
760 .gpio = 2 << 14, 864 .gpio = 2 << 14,
761 },{ 865 },{
762 .name = name_comp2, 866 .name = name_comp2,
763 .vmux = 0, 867 .vmux = 0,
764 .gpio = 1 << 14, 868 .gpio = 1 << 14,
765 },{ 869 },{
766 .name = name_comp3, 870 .name = name_comp3,
767 .vmux = 0, 871 .vmux = 0,
768 .gpio = 0 << 14, 872 .gpio = 0 << 14,
769 },{ 873 },{
770 .name = name_comp4, 874 .name = name_comp4,
771 .vmux = 0, 875 .vmux = 0,
772 .gpio = 3 << 14, 876 .gpio = 3 << 14,
773 },{ 877 },{
774 .name = name_svideo, 878 .name = name_svideo,
775 .vmux = 8, 879 .vmux = 8,
776 .gpio = 2 << 14, 880 .gpio = 2 << 14,
777 }}, 881 }},
778 }, 882 },
779 [SAA7134_BOARD_MD2819] = { 883 [SAA7134_BOARD_MD2819] = {
780 .name = "AverMedia M156 / Medion 2819", 884 .name = "AverMedia M156 / Medion 2819",
781 .audio_clock = 0x00187de7, 885 .audio_clock = 0x00187de7,
782 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 886 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
887 .radio_type = UNSET,
888 .tuner_addr = ADDR_UNSET,
889 .radio_addr = ADDR_UNSET,
783 .tda9887_conf = TDA9887_PRESENT, 890 .tda9887_conf = TDA9887_PRESENT,
784 .inputs = {{ 891 .inputs = {{
785 .name = name_tv, 892 .name = name_tv,
@@ -809,6 +916,9 @@ struct saa7134_board saa7134_boards[] = {
809 .name = "BMK MPEX Tuner", 916 .name = "BMK MPEX Tuner",
810 .audio_clock = 0x200000, 917 .audio_clock = 0x200000,
811 .tuner_type = TUNER_PHILIPS_PAL, 918 .tuner_type = TUNER_PHILIPS_PAL,
919 .radio_type = UNSET,
920 .tuner_addr = ADDR_UNSET,
921 .radio_addr = ADDR_UNSET,
812 .inputs = {{ 922 .inputs = {{
813 .name = name_comp1, 923 .name = name_comp1,
814 .vmux = 1, 924 .vmux = 1,
@@ -825,62 +935,72 @@ struct saa7134_board saa7134_boards[] = {
825 }}, 935 }},
826 .mpeg = SAA7134_MPEG_EMPRESS, 936 .mpeg = SAA7134_MPEG_EMPRESS,
827 .video_out = CCIR656, 937 .video_out = CCIR656,
828 }, 938 },
829 [SAA7134_BOARD_ASUSTEK_TVFM7133] = { 939 [SAA7134_BOARD_ASUSTEK_TVFM7133] = {
830 .name = "ASUS TV-FM 7133", 940 .name = "ASUS TV-FM 7133",
831 .audio_clock = 0x00187de7, 941 .audio_clock = 0x00187de7,
832 // probably wrong, the 7133 one is the NTSC version ... 942 /* probably wrong, the 7133 one is the NTSC version ...
833 // .tuner_type = TUNER_PHILIPS_FM1236_MK3 943 * .tuner_type = TUNER_PHILIPS_FM1236_MK3 */
834 .tuner_type = TUNER_LG_NTSC_NEW_TAPC, 944 .tuner_type = TUNER_LG_NTSC_NEW_TAPC,
835 .tda9887_conf = TDA9887_PRESENT, 945 .radio_type = UNSET,
836 .inputs = {{ 946 .tuner_addr = ADDR_UNSET,
837 .name = name_tv, 947 .radio_addr = ADDR_UNSET,
838 .vmux = 1, 948 .tda9887_conf = TDA9887_PRESENT,
839 .amux = TV, 949 .inputs = {{
840 .tv = 1, 950 .name = name_tv,
841 },{ 951 .vmux = 1,
842 .name = name_comp1, 952 .amux = TV,
843 .vmux = 4, 953 .tv = 1,
844 .amux = LINE2, 954
845 },{ 955 },{
846 .name = name_svideo, 956 .name = name_comp1,
847 .vmux = 6, 957 .vmux = 4,
848 .amux = LINE2, 958 .amux = LINE2,
849 }}, 959 },{
850 .radio = { 960 .name = name_svideo,
851 .name = name_radio, 961 .vmux = 6,
852 .amux = LINE1, 962 .amux = LINE2,
853 }, 963 }},
854 }, 964 .radio = {
965 .name = name_radio,
966 .amux = LINE1,
967 },
968 },
855 [SAA7134_BOARD_PINNACLE_PCTV_STEREO] = { 969 [SAA7134_BOARD_PINNACLE_PCTV_STEREO] = {
856 .name = "Pinnacle PCTV Stereo (saa7134)", 970 .name = "Pinnacle PCTV Stereo (saa7134)",
857 .audio_clock = 0x00187de7, 971 .audio_clock = 0x00187de7,
858 .tuner_type = TUNER_MT2032, 972 .tuner_type = TUNER_MT2032,
859 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER, 973 .radio_type = UNSET,
860 .inputs = {{ 974 .tuner_addr = ADDR_UNSET,
861 .name = name_tv, 975 .radio_addr = ADDR_UNSET,
862 .vmux = 3, 976 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER,
863 .amux = TV, 977 .inputs = {{
864 .tv = 1, 978 .name = name_tv,
865 },{ 979 .vmux = 3,
866 .name = name_comp1, 980 .amux = TV,
867 .vmux = 0, 981 .tv = 1,
868 .amux = LINE2, 982 },{
869 },{ 983 .name = name_comp1,
870 .name = name_comp2, 984 .vmux = 0,
871 .vmux = 1, 985 .amux = LINE2,
872 .amux = LINE2, 986 },{
873 },{ 987 .name = name_comp2,
874 .name = name_svideo, 988 .vmux = 1,
875 .vmux = 8, 989 .amux = LINE2,
876 .amux = LINE2, 990 },{
877 }}, 991 .name = name_svideo,
878 }, 992 .vmux = 8,
993 .amux = LINE2,
994 }},
995 },
879 [SAA7134_BOARD_MANLI_MTV002] = { 996 [SAA7134_BOARD_MANLI_MTV002] = {
880 /* Ognjen Nastic <ognjen@logosoft.ba> */ 997 /* Ognjen Nastic <ognjen@logosoft.ba> */
881 .name = "Manli MuchTV M-TV002/Behold TV 403 FM", 998 .name = "Manli MuchTV M-TV002/Behold TV 403 FM",
882 .audio_clock = 0x00200000, 999 .audio_clock = 0x00200000,
883 .tuner_type = TUNER_PHILIPS_PAL, 1000 .tuner_type = TUNER_PHILIPS_PAL,
1001 .radio_type = UNSET,
1002 .tuner_addr = ADDR_UNSET,
1003 .radio_addr = ADDR_UNSET,
884 .inputs = {{ 1004 .inputs = {{
885 .name = name_svideo, 1005 .name = name_svideo,
886 .vmux = 8, 1006 .vmux = 8,
@@ -905,6 +1025,9 @@ struct saa7134_board saa7134_boards[] = {
905 .name = "Manli MuchTV M-TV001/Behold TV 401", 1025 .name = "Manli MuchTV M-TV001/Behold TV 401",
906 .audio_clock = 0x00200000, 1026 .audio_clock = 0x00200000,
907 .tuner_type = TUNER_PHILIPS_PAL, 1027 .tuner_type = TUNER_PHILIPS_PAL,
1028 .radio_type = UNSET,
1029 .tuner_addr = ADDR_UNSET,
1030 .radio_addr = ADDR_UNSET,
908 .inputs = {{ 1031 .inputs = {{
909 .name = name_svideo, 1032 .name = name_svideo,
910 .vmux = 8, 1033 .vmux = 8,
@@ -921,14 +1044,17 @@ struct saa7134_board saa7134_boards[] = {
921 }}, 1044 }},
922 .mute = { 1045 .mute = {
923 .name = name_mute, 1046 .name = name_mute,
924 .amux = LINE1, 1047 .amux = LINE1,
925 }, 1048 },
926 }, 1049 },
927 [SAA7134_BOARD_TG3000TV] = { 1050 [SAA7134_BOARD_TG3000TV] = {
928 /* TransGear 3000TV */ 1051 /* TransGear 3000TV */
929 .name = "Nagase Sangyo TransGear 3000TV", 1052 .name = "Nagase Sangyo TransGear 3000TV",
930 .audio_clock = 0x00187de7, 1053 .audio_clock = 0x00187de7,
931 .tuner_type = TUNER_PHILIPS_NTSC_M, 1054 .tuner_type = TUNER_PHILIPS_NTSC_M,
1055 .radio_type = UNSET,
1056 .tuner_addr = ADDR_UNSET,
1057 .radio_addr = ADDR_UNSET,
932 .inputs = {{ 1058 .inputs = {{
933 .name = name_tv, 1059 .name = name_tv,
934 .vmux = 1, 1060 .vmux = 1,
@@ -944,81 +1070,90 @@ struct saa7134_board saa7134_boards[] = {
944 .amux = LINE2, 1070 .amux = LINE2,
945 }}, 1071 }},
946 }, 1072 },
947 [SAA7134_BOARD_ECS_TVP3XP] = { 1073 [SAA7134_BOARD_ECS_TVP3XP] = {
948 .name = "Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) ", 1074 .name = "Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) ",
949 .audio_clock = 0x187de7, // xtal 32.1 MHz 1075 .audio_clock = 0x187de7, /* xtal 32.1 MHz */
950 .tuner_type = TUNER_PHILIPS_PAL, 1076 .tuner_type = TUNER_PHILIPS_PAL,
951 .inputs = {{ 1077 .radio_type = UNSET,
952 .name = name_tv, 1078 .tuner_addr = ADDR_UNSET,
953 .vmux = 1, 1079 .radio_addr = ADDR_UNSET,
954 .amux = TV, 1080 .inputs = {{
955 .tv = 1, 1081 .name = name_tv,
956 },{ 1082 .vmux = 1,
957 .name = name_tv_mono, 1083 .amux = TV,
958 .vmux = 1, 1084 .tv = 1,
959 .amux = LINE2, 1085 },{
960 .tv = 1, 1086 .name = name_tv_mono,
961 },{ 1087 .vmux = 1,
962 .name = name_comp1, 1088 .amux = LINE2,
963 .vmux = 3, 1089 .tv = 1,
964 .amux = LINE1, 1090 },{
965 },{ 1091 .name = name_comp1,
966 .name = name_svideo, 1092 .vmux = 3,
967 .vmux = 8, 1093 .amux = LINE1,
968 .amux = LINE1, 1094 },{
1095 .name = name_svideo,
1096 .vmux = 8,
1097 .amux = LINE1,
969 },{ 1098 },{
970 .name = "CVid over SVid", 1099 .name = "CVid over SVid",
971 .vmux = 0, 1100 .vmux = 0,
972 .amux = LINE1, 1101 .amux = LINE1,
973 }}, 1102 }},
974 .radio = { 1103 .radio = {
975 .name = name_radio, 1104 .name = name_radio,
976 .amux = LINE2, 1105 .amux = LINE2,
977 }, 1106 },
978 }, 1107 },
979 [SAA7134_BOARD_ECS_TVP3XP_4CB5] = { 1108 [SAA7134_BOARD_ECS_TVP3XP_4CB5] = {
980 .name = "Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM)", 1109 .name = "Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM)",
981 .audio_clock = 0x187de7, 1110 .audio_clock = 0x187de7,
982 .tuner_type = TUNER_PHILIPS_NTSC, 1111 .tuner_type = TUNER_PHILIPS_NTSC,
983 .inputs = {{ 1112 .radio_type = UNSET,
984 .name = name_tv, 1113 .tuner_addr = ADDR_UNSET,
985 .vmux = 1, 1114 .radio_addr = ADDR_UNSET,
986 .amux = TV, 1115 .inputs = {{
987 .tv = 1, 1116 .name = name_tv,
988 },{ 1117 .vmux = 1,
989 .name = name_tv_mono, 1118 .amux = TV,
990 .vmux = 1, 1119 .tv = 1,
991 .amux = LINE2, 1120 },{
992 .tv = 1, 1121 .name = name_tv_mono,
993 },{ 1122 .vmux = 1,
994 .name = name_comp1, 1123 .amux = LINE2,
995 .vmux = 3, 1124 .tv = 1,
996 .amux = LINE1, 1125 },{
997 },{ 1126 .name = name_comp1,
998 .name = name_svideo, 1127 .vmux = 3,
999 .vmux = 8, 1128 .amux = LINE1,
1000 .amux = LINE1, 1129 },{
1001 },{ 1130 .name = name_svideo,
1002 .name = "CVid over SVid", 1131 .vmux = 8,
1003 .vmux = 0, 1132 .amux = LINE1,
1004 .amux = LINE1, 1133 },{
1005 }}, 1134 .name = "CVid over SVid",
1006 .radio = { 1135 .vmux = 0,
1007 .name = name_radio, 1136 .amux = LINE1,
1008 .amux = LINE2, 1137 }},
1009 }, 1138 .radio = {
1010 }, 1139 .name = name_radio,
1140 .amux = LINE2,
1141 },
1142 },
1011 [SAA7134_BOARD_AVACSSMARTTV] = { 1143 [SAA7134_BOARD_AVACSSMARTTV] = {
1012 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */ 1144 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */
1013 .name = "AVACS SmartTV", 1145 .name = "AVACS SmartTV",
1014 .audio_clock = 0x00187de7, 1146 .audio_clock = 0x00187de7,
1015 .tuner_type = TUNER_PHILIPS_PAL, 1147 .tuner_type = TUNER_PHILIPS_PAL,
1148 .radio_type = UNSET,
1149 .tuner_addr = ADDR_UNSET,
1150 .radio_addr = ADDR_UNSET,
1016 .inputs = {{ 1151 .inputs = {{
1017 .name = name_tv, 1152 .name = name_tv,
1018 .vmux = 1, 1153 .vmux = 1,
1019 .amux = TV, 1154 .amux = TV,
1020 .tv = 1, 1155 .tv = 1,
1021 },{ 1156 },{
1022 .name = name_tv_mono, 1157 .name = name_tv_mono,
1023 .vmux = 1, 1158 .vmux = 1,
1024 .amux = LINE2, 1159 .amux = LINE2,
@@ -1047,6 +1182,9 @@ struct saa7134_board saa7134_boards[] = {
1047 .name = "AVerMedia DVD EZMaker", 1182 .name = "AVerMedia DVD EZMaker",
1048 .audio_clock = 0x00187de7, 1183 .audio_clock = 0x00187de7,
1049 .tuner_type = TUNER_ABSENT, 1184 .tuner_type = TUNER_ABSENT,
1185 .radio_type = UNSET,
1186 .tuner_addr = ADDR_UNSET,
1187 .radio_addr = ADDR_UNSET,
1050 .inputs = {{ 1188 .inputs = {{
1051 .name = name_comp1, 1189 .name = name_comp1,
1052 .vmux = 3, 1190 .vmux = 3,
@@ -1055,28 +1193,34 @@ struct saa7134_board saa7134_boards[] = {
1055 .vmux = 8, 1193 .vmux = 8,
1056 }}, 1194 }},
1057 }, 1195 },
1058 [SAA7134_BOARD_NOVAC_PRIMETV7133] = { 1196 [SAA7134_BOARD_NOVAC_PRIMETV7133] = {
1059 /* toshii@netbsd.org */ 1197 /* toshii@netbsd.org */
1060 .name = "Noval Prime TV 7133", 1198 .name = "Noval Prime TV 7133",
1061 .audio_clock = 0x00200000, 1199 .audio_clock = 0x00200000,
1062 .tuner_type = TUNER_ALPS_TSBH1_NTSC, 1200 .tuner_type = TUNER_ALPS_TSBH1_NTSC,
1063 .inputs = {{ 1201 .radio_type = UNSET,
1064 .name = name_comp1, 1202 .tuner_addr = ADDR_UNSET,
1065 .vmux = 3, 1203 .radio_addr = ADDR_UNSET,
1066 },{ 1204 .inputs = {{
1067 .name = name_tv, 1205 .name = name_comp1,
1068 .vmux = 1, 1206 .vmux = 3,
1069 .amux = TV, 1207 },{
1070 .tv = 1, 1208 .name = name_tv,
1071 },{ 1209 .vmux = 1,
1072 .name = name_svideo, 1210 .amux = TV,
1073 .vmux = 8, 1211 .tv = 1,
1074 }}, 1212 },{
1075 }, 1213 .name = name_svideo,
1214 .vmux = 8,
1215 }},
1216 },
1076 [SAA7134_BOARD_AVERMEDIA_STUDIO_305] = { 1217 [SAA7134_BOARD_AVERMEDIA_STUDIO_305] = {
1077 .name = "AverMedia AverTV Studio 305", 1218 .name = "AverMedia AverTV Studio 305",
1078 .audio_clock = 0x00187de7, 1219 .audio_clock = 0x00187de7,
1079 .tuner_type = TUNER_PHILIPS_FM1256_IH3, 1220 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
1221 .radio_type = UNSET,
1222 .tuner_addr = ADDR_UNSET,
1223 .radio_addr = ADDR_UNSET,
1080 .tda9887_conf = TDA9887_PRESENT, 1224 .tda9887_conf = TDA9887_PRESENT,
1081 .inputs = {{ 1225 .inputs = {{
1082 .name = name_tv, 1226 .name = name_tv,
@@ -1097,35 +1241,41 @@ struct saa7134_board saa7134_boards[] = {
1097 .amux = LINE2, 1241 .amux = LINE2,
1098 }}, 1242 }},
1099 .radio = { 1243 .radio = {
1100 .name = name_radio, 1244 .name = name_radio,
1101 .amux = LINE2, 1245 .amux = LINE2,
1102 }, 1246 },
1103 .mute = { 1247 .mute = {
1104 .name = name_mute, 1248 .name = name_mute,
1105 .amux = LINE1, 1249 .amux = LINE1,
1106 }, 1250 },
1107 }, 1251 },
1108 [SAA7133_BOARD_UPMOST_PURPLE_TV] = { 1252 [SAA7134_BOARD_UPMOST_PURPLE_TV] = {
1109 .name = "UPMOST PURPLE TV", 1253 .name = "UPMOST PURPLE TV",
1110 .audio_clock = 0x00187de7, 1254 .audio_clock = 0x00187de7,
1111 .tuner_type = TUNER_PHILIPS_FM1236_MK3, 1255 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
1112 .tda9887_conf = TDA9887_PRESENT, 1256 .radio_type = UNSET,
1113 .inputs = {{ 1257 .tuner_addr = ADDR_UNSET,
1114 .name = name_tv, 1258 .radio_addr = ADDR_UNSET,
1115 .vmux = 7, 1259 .tda9887_conf = TDA9887_PRESENT,
1116 .amux = TV, 1260 .inputs = {{
1117 .tv = 1, 1261 .name = name_tv,
1118 },{ 1262 .vmux = 7,
1119 .name = name_svideo, 1263 .amux = TV,
1120 .vmux = 7, 1264 .tv = 1,
1121 .amux = LINE1, 1265 },{
1122 }}, 1266 .name = name_svideo,
1267 .vmux = 7,
1268 .amux = LINE1,
1269 }},
1123 }, 1270 },
1124 [SAA7134_BOARD_ITEMS_MTV005] = { 1271 [SAA7134_BOARD_ITEMS_MTV005] = {
1125 /* Norman Jonas <normanjonas@arcor.de> */ 1272 /* Norman Jonas <normanjonas@arcor.de> */
1126 .name = "Items MuchTV Plus / IT-005", 1273 .name = "Items MuchTV Plus / IT-005",
1127 .audio_clock = 0x00187de7, 1274 .audio_clock = 0x00187de7,
1128 .tuner_type = TUNER_PHILIPS_PAL, 1275 .tuner_type = TUNER_PHILIPS_PAL,
1276 .radio_type = UNSET,
1277 .tuner_addr = ADDR_UNSET,
1278 .radio_addr = ADDR_UNSET,
1129 .inputs = {{ 1279 .inputs = {{
1130 .name = name_tv, 1280 .name = name_tv,
1131 .vmux = 3, 1281 .vmux = 3,
@@ -1149,27 +1299,30 @@ struct saa7134_board saa7134_boards[] = {
1149 .name = "Terratec Cinergy 200 TV", 1299 .name = "Terratec Cinergy 200 TV",
1150 .audio_clock = 0x00200000, 1300 .audio_clock = 0x00200000,
1151 .tuner_type = TUNER_PHILIPS_PAL, 1301 .tuner_type = TUNER_PHILIPS_PAL,
1302 .radio_type = UNSET,
1303 .tuner_addr = ADDR_UNSET,
1304 .radio_addr = ADDR_UNSET,
1152 .inputs = {{ 1305 .inputs = {{
1153 .name = name_tv, 1306 .name = name_tv,
1154 .vmux = 1, 1307 .vmux = 1,
1155 .amux = LINE2, 1308 .amux = LINE2,
1156 .tv = 1, 1309 .tv = 1,
1157 },{ 1310 },{
1158 .name = name_comp1, 1311 .name = name_comp1,
1159 .vmux = 4, 1312 .vmux = 4,
1160 .amux = LINE1, 1313 .amux = LINE1,
1161 },{ 1314 },{
1162 .name = name_svideo, 1315 .name = name_svideo,
1163 .vmux = 8, 1316 .vmux = 8,
1164 .amux = LINE1, 1317 .amux = LINE1,
1165 },{ 1318 },{
1166 .name = name_comp2, // CVideo over SVideo Connector 1319 .name = name_comp2, /* CVideo over SVideo Connector */
1167 .vmux = 0, 1320 .vmux = 0,
1168 .amux = LINE1, 1321 .amux = LINE1,
1169 }}, 1322 }},
1170 .mute = { 1323 .mute = {
1171 .name = name_mute, 1324 .name = name_mute,
1172 .amux = LINE2, 1325 .amux = LINE2,
1173 }, 1326 },
1174 }, 1327 },
1175 [SAA7134_BOARD_VIDEOMATE_TV_PVR] = { 1328 [SAA7134_BOARD_VIDEOMATE_TV_PVR] = {
@@ -1177,84 +1330,96 @@ struct saa7134_board saa7134_boards[] = {
1177 .name = "Compro VideoMate TV PVR/FM", 1330 .name = "Compro VideoMate TV PVR/FM",
1178 .audio_clock = 0x00187de7, 1331 .audio_clock = 0x00187de7,
1179 .tuner_type = TUNER_PHILIPS_NTSC_M, 1332 .tuner_type = TUNER_PHILIPS_NTSC_M,
1333 .radio_type = UNSET,
1334 .tuner_addr = ADDR_UNSET,
1335 .radio_addr = ADDR_UNSET,
1180 .gpiomask = 0x808c0080, 1336 .gpiomask = 0x808c0080,
1181 .inputs = {{ 1337 .inputs = {{
1182 .name = name_svideo, 1338 .name = name_svideo,
1183 .vmux = 8, 1339 .vmux = 8,
1184 .amux = LINE1, 1340 .amux = LINE1,
1185 .gpio = 0x00080, 1341 .gpio = 0x00080,
1186 },{ 1342 },{
1187 .name = name_comp1, 1343 .name = name_comp1,
1188 .vmux = 3, 1344 .vmux = 3,
1189 .amux = LINE1, 1345 .amux = LINE1,
1190 .gpio = 0x00080, 1346 .gpio = 0x00080,
1191 },{ 1347 },{
1192 .name = name_tv, 1348 .name = name_tv,
1193 .vmux = 1, 1349 .vmux = 1,
1194 .amux = LINE2_LEFT, 1350 .amux = LINE2_LEFT,
1195 .tv = 1, 1351 .tv = 1,
1196 .gpio = 0x00080, 1352 .gpio = 0x00080,
1197 }}, 1353 }},
1198 .radio = { 1354 .radio = {
1199 .name = name_radio, 1355 .name = name_radio,
1200 .amux = LINE2, 1356 .amux = LINE2,
1201 .gpio = 0x80000, 1357 .gpio = 0x80000,
1202 }, 1358 },
1203 .mute = { 1359 .mute = {
1204 .name = name_mute, 1360 .name = name_mute,
1205 .amux = LINE2, 1361 .amux = LINE2,
1206 .gpio = 0x40000, 1362 .gpio = 0x40000,
1207 }, 1363 },
1208 }, 1364 },
1209 [SAA7134_BOARD_SABRENT_SBTTVFM] = { 1365 [SAA7134_BOARD_SABRENT_SBTTVFM] = {
1210 /* Michael Rodriguez-Torrent <mrtorrent@asu.edu> */ 1366 /* Michael Rodriguez-Torrent <mrtorrent@asu.edu> */
1211 .name = "Sabrent SBT-TVFM (saa7130)", 1367 .name = "Sabrent SBT-TVFM (saa7130)",
1212 .audio_clock = 0x00187de7, 1368 .audio_clock = 0x00187de7,
1213 .tuner_type = TUNER_PHILIPS_NTSC_M, 1369 .tuner_type = TUNER_PHILIPS_NTSC_M,
1214 .inputs = {{ 1370 .radio_type = UNSET,
1371 .tuner_addr = ADDR_UNSET,
1372 .radio_addr = ADDR_UNSET,
1373 .inputs = {{
1215 .name = name_comp1, 1374 .name = name_comp1,
1216 .vmux = 1, 1375 .vmux = 1,
1217 .amux = LINE2, 1376 .amux = LINE2,
1218 },{ 1377 },{
1219 .name = name_tv, 1378 .name = name_tv,
1220 .vmux = 3, 1379 .vmux = 3,
1221 .amux = LINE2, 1380 .amux = LINE2,
1222 .tv = 1, 1381 .tv = 1,
1223 },{ 1382 },{
1224 .name = name_svideo, 1383 .name = name_svideo,
1225 .vmux = 8, 1384 .vmux = 8,
1226 .amux = LINE2, 1385 .amux = LINE2,
1227 }}, 1386 }},
1228 .radio = { 1387 .radio = {
1229 .name = name_radio, 1388 .name = name_radio,
1230 .amux = LINE2, 1389 .amux = LINE2,
1231 }, 1390 },
1232 }, 1391 },
1233 [SAA7134_BOARD_ZOLID_XPERT_TV7134] = { 1392 [SAA7134_BOARD_ZOLID_XPERT_TV7134] = {
1234 /* Helge Jensen <helge.jensen@slog.dk> */ 1393 /* Helge Jensen <helge.jensen@slog.dk> */
1235 .name = ":Zolid Xpert TV7134", 1394 .name = ":Zolid Xpert TV7134",
1236 .audio_clock = 0x00187de7, 1395 .audio_clock = 0x00187de7,
1237 .tuner_type = TUNER_PHILIPS_NTSC, 1396 .tuner_type = TUNER_PHILIPS_NTSC,
1238 .inputs = {{ 1397 .radio_type = UNSET,
1398 .tuner_addr = ADDR_UNSET,
1399 .radio_addr = ADDR_UNSET,
1400 .inputs = {{
1239 .name = name_svideo, 1401 .name = name_svideo,
1240 .vmux = 8, 1402 .vmux = 8,
1241 .amux = LINE1, 1403 .amux = LINE1,
1242 },{ 1404 },{
1243 .name = name_comp1, 1405 .name = name_comp1,
1244 .vmux = 3, 1406 .vmux = 3,
1245 .amux = LINE1, 1407 .amux = LINE1,
1246 },{ 1408 },{
1247 .name = name_tv, 1409 .name = name_tv,
1248 .vmux = 1, 1410 .vmux = 1,
1249 .amux = LINE2, 1411 .amux = LINE2,
1250 .tv = 1, 1412 .tv = 1,
1251 }}, 1413 }},
1252 }, 1414 },
1253 [SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE] = { 1415 [SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE] = {
1254 /* "Matteo Az" <matte.az@nospam.libero.it> ;-) */ 1416 /* "Matteo Az" <matte.az@nospam.libero.it> ;-) */
1255 .name = "Empire PCI TV-Radio LE", 1417 .name = "Empire PCI TV-Radio LE",
1256 .audio_clock = 0x00187de7, 1418 .audio_clock = 0x00187de7,
1257 .tuner_type = TUNER_PHILIPS_PAL, 1419 .tuner_type = TUNER_PHILIPS_PAL,
1420 .radio_type = UNSET,
1421 .tuner_addr = ADDR_UNSET,
1422 .radio_addr = ADDR_UNSET,
1258 .gpiomask = 0x4000, 1423 .gpiomask = 0x4000,
1259 .inputs = {{ 1424 .inputs = {{
1260 .name = name_tv_mono, 1425 .name = name_tv_mono,
@@ -1273,18 +1438,18 @@ struct saa7134_board saa7134_boards[] = {
1273 .amux = LINE1, 1438 .amux = LINE1,
1274 .gpio = 0x8000, 1439 .gpio = 0x8000,
1275 }}, 1440 }},
1276 .radio = { 1441 .radio = {
1277 .name = name_radio, 1442 .name = name_radio,
1278 .amux = LINE1, 1443 .amux = LINE1,
1279 .gpio = 0x8000, 1444 .gpio = 0x8000,
1280 }, 1445 },
1281 .mute = { 1446 .mute = {
1282 .name = name_mute, 1447 .name = name_mute,
1283 .amux = TV, 1448 .amux = TV,
1284 .gpio =0x8000, 1449 .gpio =0x8000,
1285 } 1450 }
1286 }, 1451 },
1287 [SAA7134_BOARD_AVERMEDIA_STUDIO_307] = { 1452 [SAA7134_BOARD_AVERMEDIA_STUDIO_307] = {
1288 /* 1453 /*
1289 Nickolay V. Shmyrev <nshmyrev@yandex.ru> 1454 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
1290 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru> 1455 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru>
@@ -1292,6 +1457,9 @@ struct saa7134_board saa7134_boards[] = {
1292 .name = "Avermedia AVerTV Studio 307", 1457 .name = "Avermedia AVerTV Studio 307",
1293 .audio_clock = 0x00187de7, 1458 .audio_clock = 0x00187de7,
1294 .tuner_type = TUNER_PHILIPS_FM1256_IH3, 1459 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
1460 .radio_type = UNSET,
1461 .tuner_addr = ADDR_UNSET,
1462 .radio_addr = ADDR_UNSET,
1295 .tda9887_conf = TDA9887_PRESENT, 1463 .tda9887_conf = TDA9887_PRESENT,
1296 .gpiomask = 0x03, 1464 .gpiomask = 0x03,
1297 .inputs = {{ 1465 .inputs = {{
@@ -1321,13 +1489,21 @@ struct saa7134_board saa7134_boards[] = {
1321 .amux = LINE1, 1489 .amux = LINE1,
1322 .gpio = 0x01, 1490 .gpio = 0x01,
1323 }, 1491 },
1324 }, 1492 .mute = {
1325 [SAA7134_BOARD_AVERMEDIA_GO_007_FM] = { 1493 .name = name_mute,
1494 .amux = LINE1,
1495 .gpio = 0x00,
1496 },
1497 },
1498 [SAA7134_BOARD_AVERMEDIA_GO_007_FM] = {
1326 .name = "Avermedia AVerTV GO 007 FM", 1499 .name = "Avermedia AVerTV GO 007 FM",
1327 .audio_clock = 0x00187de7, 1500 .audio_clock = 0x00187de7,
1328 .tuner_type = TUNER_PHILIPS_TDA8290, 1501 .tuner_type = TUNER_PHILIPS_TDA8290,
1502 .radio_type = UNSET,
1503 .tuner_addr = ADDR_UNSET,
1504 .radio_addr = ADDR_UNSET,
1329 .gpiomask = 0x00300003, 1505 .gpiomask = 0x00300003,
1330// .gpiomask = 0x8c240003, 1506 /* .gpiomask = 0x8c240003, */
1331 .inputs = {{ 1507 .inputs = {{
1332 .name = name_tv, 1508 .name = name_tv,
1333 .vmux = 1, 1509 .vmux = 1,
@@ -1350,16 +1526,24 @@ struct saa7134_board saa7134_boards[] = {
1350 .amux = LINE1, 1526 .amux = LINE1,
1351 .gpio = 0x00300001, 1527 .gpio = 0x00300001,
1352 }, 1528 },
1353 }, 1529 .mute = {
1530 .name = name_mute,
1531 .amux = TV,
1532 .gpio = 0x01,
1533 },
1534 },
1354 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = { 1535 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = {
1355 /* Jon Westgate <oryn@oryn.fsck.tv> */ 1536 /* Kees.Blom@cwi.nl */
1356 .name = "AVerMedia Cardbus TV/Radio", 1537 .name = "AVerMedia Cardbus TV/Radio (E500)",
1357 .audio_clock = 0x00200000, 1538 .audio_clock = 0x187de7,
1358 .tuner_type = TUNER_PHILIPS_PAL, 1539 .tuner_type = TUNER_PHILIPS_TDA8290,
1540 .radio_type = UNSET,
1541 .tuner_addr = ADDR_UNSET,
1542 .radio_addr = ADDR_UNSET,
1359 .inputs = {{ 1543 .inputs = {{
1360 .name = name_tv, 1544 .name = name_tv,
1361 .vmux = 1, 1545 .vmux = 1,
1362 .amux = LINE2, 1546 .amux = TV,
1363 .tv = 1, 1547 .tv = 1,
1364 },{ 1548 },{
1365 .name = name_comp1, 1549 .name = name_comp1,
@@ -1368,10 +1552,10 @@ struct saa7134_board saa7134_boards[] = {
1368 },{ 1552 },{
1369 .name = name_svideo, 1553 .name = name_svideo,
1370 .vmux = 8, 1554 .vmux = 8,
1371 .amux = LINE2, 1555 .amux = LINE1,
1372 }}, 1556 }},
1373 .radio = { 1557 .radio = {
1374 .name = name_radio, 1558 .name = name_radio,
1375 .amux = LINE1, 1559 .amux = LINE1,
1376 }, 1560 },
1377 }, 1561 },
@@ -1379,119 +1563,134 @@ struct saa7134_board saa7134_boards[] = {
1379 .name = "Terratec Cinergy 400 mobile", 1563 .name = "Terratec Cinergy 400 mobile",
1380 .audio_clock = 0x187de7, 1564 .audio_clock = 0x187de7,
1381 .tuner_type = TUNER_ALPS_TSBE5_PAL, 1565 .tuner_type = TUNER_ALPS_TSBE5_PAL,
1382 .tda9887_conf = TDA9887_PRESENT, 1566 .radio_type = UNSET,
1567 .tuner_addr = ADDR_UNSET,
1568 .radio_addr = ADDR_UNSET,
1569 .tda9887_conf = TDA9887_PRESENT,
1383 .inputs = {{ 1570 .inputs = {{
1384 .name = name_tv, 1571 .name = name_tv,
1385 .vmux = 1, 1572 .vmux = 1,
1386 .amux = TV, 1573 .amux = TV,
1387 .tv = 1, 1574 .tv = 1,
1388 },{ 1575 },{
1389 .name = name_tv_mono, 1576 .name = name_tv_mono,
1390 .vmux = 1, 1577 .vmux = 1,
1391 .amux = LINE2, 1578 .amux = LINE2,
1392 .tv = 1, 1579 .tv = 1,
1393 },{ 1580 },{
1394 .name = name_comp1, 1581 .name = name_comp1,
1395 .vmux = 3, 1582 .vmux = 3,
1396 .amux = LINE1, 1583 .amux = LINE1,
1397 },{ 1584 },{
1398 .name = name_svideo, 1585 .name = name_svideo,
1399 .vmux = 8, 1586 .vmux = 8,
1400 .amux = LINE1, 1587 .amux = LINE1,
1401 }}, 1588 }},
1402 }, 1589 },
1403 [SAA7134_BOARD_CINERGY600_MK3] = { 1590 [SAA7134_BOARD_CINERGY600_MK3] = {
1404 .name = "Terratec Cinergy 600 TV MK3", 1591 .name = "Terratec Cinergy 600 TV MK3",
1405 .audio_clock = 0x00200000, 1592 .audio_clock = 0x00200000,
1406 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 1593 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
1407 .tda9887_conf = TDA9887_PRESENT, 1594 .radio_type = UNSET,
1408 .inputs = {{ 1595 .tuner_addr = ADDR_UNSET,
1409 .name = name_tv, 1596 .radio_addr = ADDR_UNSET,
1410 .vmux = 1, 1597 .tda9887_conf = TDA9887_PRESENT,
1411 .amux = TV, 1598 .inputs = {{
1412 .tv = 1, 1599 .name = name_tv,
1413 },{ 1600 .vmux = 1,
1414 .name = name_comp1, 1601 .amux = TV,
1415 .vmux = 4, 1602 .tv = 1,
1416 .amux = LINE1, 1603 },{
1417 },{ 1604 .name = name_comp1,
1418 .name = name_svideo, 1605 .vmux = 4,
1419 .vmux = 8, 1606 .amux = LINE1,
1420 .amux = LINE1, 1607 },{
1421 },{ 1608 .name = name_svideo,
1422 .name = name_comp2, // CVideo over SVideo Connector 1609 .vmux = 8,
1423 .vmux = 0, 1610 .amux = LINE1,
1424 .amux = LINE1, 1611 },{
1425 }}, 1612 .name = name_comp2, /* CVideo over SVideo Connector */
1613 .vmux = 0,
1614 .amux = LINE1,
1615 }},
1426 .radio = { 1616 .radio = {
1427 .name = name_radio, 1617 .name = name_radio,
1428 .amux = LINE2, 1618 .amux = LINE2,
1429 }, 1619 },
1430 }, 1620 },
1431 [SAA7134_BOARD_VIDEOMATE_GOLD_PLUS] = { 1621 [SAA7134_BOARD_VIDEOMATE_GOLD_PLUS] = {
1432 /* Dylan Walkden <dylan_walkden@hotmail.com> */ 1622 /* Dylan Walkden <dylan_walkden@hotmail.com> */
1433 .name = "Compro VideoMate Gold+ Pal", 1623 .name = "Compro VideoMate Gold+ Pal",
1434 .audio_clock = 0x00187de7, 1624 .audio_clock = 0x00187de7,
1435 .tuner_type = TUNER_PHILIPS_PAL, 1625 .tuner_type = TUNER_PHILIPS_PAL,
1436 .gpiomask = 0x1ce780, 1626 .radio_type = UNSET,
1437 .inputs = {{ 1627 .tuner_addr = ADDR_UNSET,
1438 .name = name_svideo, 1628 .radio_addr = ADDR_UNSET,
1439 .vmux = 0, // CVideo over SVideo Connector - ok? 1629 .gpiomask = 0x1ce780,
1440 .amux = LINE1, 1630 .inputs = {{
1441 .gpio = 0x008080, 1631 .name = name_svideo,
1442 },{ 1632 .vmux = 0, /* CVideo over SVideo Connector - ok? */
1443 .name = name_comp1, 1633 .amux = LINE1,
1444 .vmux = 3, 1634 .gpio = 0x008080,
1445 .amux = LINE1, 1635 },{
1446 .gpio = 0x008080, 1636 .name = name_comp1,
1447 },{ 1637 .vmux = 3,
1448 .name = name_tv, 1638 .amux = LINE1,
1449 .vmux = 1, 1639 .gpio = 0x008080,
1450 .amux = TV, 1640 },{
1451 .tv = 1, 1641 .name = name_tv,
1452 .gpio = 0x008080, 1642 .vmux = 1,
1453 }}, 1643 .amux = TV,
1454 .radio = { 1644 .tv = 1,
1455 .name = name_radio, 1645 .gpio = 0x008080,
1456 .amux = LINE2, 1646 }},
1457 .gpio = 0x80000, 1647 .radio = {
1458 }, 1648 .name = name_radio,
1459 .mute = { 1649 .amux = LINE2,
1460 .name = name_mute, 1650 .gpio = 0x80000,
1461 .amux = LINE2, 1651 },
1462 .gpio = 0x0c8000, 1652 .mute = {
1463 }, 1653 .name = name_mute,
1464 }, 1654 .amux = LINE2,
1655 .gpio = 0x0c8000,
1656 },
1657 },
1465 [SAA7134_BOARD_PINNACLE_300I_DVBT_PAL] = { 1658 [SAA7134_BOARD_PINNACLE_300I_DVBT_PAL] = {
1466 .name = "Pinnacle PCTV 300i DVB-T + PAL", 1659 .name = "Pinnacle PCTV 300i DVB-T + PAL",
1467 .audio_clock = 0x00187de7, 1660 .audio_clock = 0x00187de7,
1468 .tuner_type = TUNER_MT2032, 1661 .tuner_type = TUNER_MT2032,
1469 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER, 1662 .radio_type = UNSET,
1663 .tuner_addr = ADDR_UNSET,
1664 .radio_addr = ADDR_UNSET,
1665 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER,
1470 .mpeg = SAA7134_MPEG_DVB, 1666 .mpeg = SAA7134_MPEG_DVB,
1471 .inputs = {{ 1667 .inputs = {{
1472 .name = name_tv, 1668 .name = name_tv,
1473 .vmux = 3, 1669 .vmux = 3,
1474 .amux = TV, 1670 .amux = TV,
1475 .tv = 1, 1671 .tv = 1,
1476 },{ 1672 },{
1477 .name = name_comp1, 1673 .name = name_comp1,
1478 .vmux = 0, 1674 .vmux = 0,
1479 .amux = LINE2, 1675 .amux = LINE2,
1480 },{ 1676 },{
1481 .name = name_comp2, 1677 .name = name_comp2,
1482 .vmux = 1, 1678 .vmux = 1,
1483 .amux = LINE2, 1679 .amux = LINE2,
1484 },{ 1680 },{
1485 .name = name_svideo, 1681 .name = name_svideo,
1486 .vmux = 8, 1682 .vmux = 8,
1487 .amux = LINE2, 1683 .amux = LINE2,
1488 }}, 1684 }},
1489 }, 1685 },
1490 [SAA7134_BOARD_PROVIDEO_PV952] = { 1686 [SAA7134_BOARD_PROVIDEO_PV952] = {
1491 /* andreas.kretschmer@web.de */ 1687 /* andreas.kretschmer@web.de */
1492 .name = "ProVideo PV952", 1688 .name = "ProVideo PV952",
1493 .audio_clock = 0x00187de7, 1689 .audio_clock = 0x00187de7,
1494 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 1690 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
1691 .radio_type = UNSET,
1692 .tuner_addr = ADDR_UNSET,
1693 .radio_addr = ADDR_UNSET,
1495 .tda9887_conf = TDA9887_PRESENT, 1694 .tda9887_conf = TDA9887_PRESENT,
1496 .inputs = {{ 1695 .inputs = {{
1497 .name = name_comp1, 1696 .name = name_comp1,
@@ -1515,10 +1714,13 @@ struct saa7134_board saa7134_boards[] = {
1515 }, 1714 },
1516 [SAA7134_BOARD_AVERMEDIA_305] = { 1715 [SAA7134_BOARD_AVERMEDIA_305] = {
1517 /* much like the "studio" version but without radio 1716 /* much like the "studio" version but without radio
1518 * and another tuner (sirspiritus@yandex.ru) */ 1717 * and another tuner (sirspiritus@yandex.ru) */
1519 .name = "AverMedia AverTV/305", 1718 .name = "AverMedia AverTV/305",
1520 .audio_clock = 0x00187de7, 1719 .audio_clock = 0x00187de7,
1521 .tuner_type = TUNER_PHILIPS_FQ1216ME, 1720 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1721 .radio_type = UNSET,
1722 .tuner_addr = ADDR_UNSET,
1723 .radio_addr = ADDR_UNSET,
1522 .tda9887_conf = TDA9887_PRESENT, 1724 .tda9887_conf = TDA9887_PRESENT,
1523 .inputs = {{ 1725 .inputs = {{
1524 .name = name_tv, 1726 .name = name_tv,
@@ -1539,115 +1741,268 @@ struct saa7134_board saa7134_boards[] = {
1539 .amux = LINE2, 1741 .amux = LINE2,
1540 }}, 1742 }},
1541 .mute = { 1743 .mute = {
1542 .name = name_mute, 1744 .name = name_mute,
1543 .amux = LINE1, 1745 .amux = LINE1,
1544 }, 1746 },
1545 }, 1747 },
1546 [SAA7134_BOARD_FLYDVBTDUO] = { 1748 [SAA7134_BOARD_FLYDVBTDUO] = {
1547 /* LifeView FlyDVB-T DUO */ 1749 /* LifeView FlyDVB-T DUO */
1548 /* "Nico Sabbi <nsabbi@tiscali.it> */ 1750 /* "Nico Sabbi <nsabbi@tiscali.it> Hartmut Hackmann hartmut.hackmann@t-online.de*/
1549 .name = "LifeView FlyDVB-T DUO", 1751 .name = "LifeView FlyDVB-T DUO",
1550 .audio_clock = 0x00200000, 1752 .audio_clock = 0x00200000,
1551 .tuner_type = TUNER_PHILIPS_TDA8290, 1753 .tuner_type = TUNER_PHILIPS_TDA8290,
1552// .gpiomask = 0xe000, 1754 .radio_type = UNSET,
1755 .tuner_addr = ADDR_UNSET,
1756 .radio_addr = ADDR_UNSET,
1757 .mpeg = SAA7134_MPEG_DVB,
1553 .inputs = {{ 1758 .inputs = {{
1554 .name = name_tv, 1759 .name = name_tv,
1555 .vmux = 1, 1760 .vmux = 1,
1556 .amux = TV, 1761 .amux = TV,
1557// .gpio = 0x0000,
1558 .tv = 1, 1762 .tv = 1,
1559 },{ 1763 },{
1560 .name = name_comp1, /* Composite signal on S-Video input */ 1764 .name = name_comp1, /* Composite signal on S-Video input */
1561 .vmux = 0, 1765 .vmux = 0,
1562 .amux = LINE2, 1766 .amux = LINE2,
1563// .gpio = 0x4000,
1564 },{ 1767 },{
1565 .name = name_comp2, /* Composite input */ 1768 .name = name_comp2, /* Composite input */
1566 .vmux = 3, 1769 .vmux = 3,
1567 .amux = LINE2, 1770 .amux = LINE2,
1568// .gpio = 0x4000,
1569 },{ 1771 },{
1570 .name = name_svideo, /* S-Video signal on S-Video input */ 1772 .name = name_svideo, /* S-Video signal on S-Video input */
1571 .vmux = 8, 1773 .vmux = 8,
1572 .amux = LINE2, 1774 .amux = LINE2,
1573// .gpio = 0x4000,
1574 }}, 1775 }},
1575 }, 1776 },
1576 [SAA7134_BOARD_AVERMEDIA_307] = { 1777 [SAA7134_BOARD_PHILIPS_TOUGH] = {
1577 /* 1778 .name = "Philips TOUGH DVB-T reference design",
1578 Davydov Vladimir <vladimir@iqmedia.com> 1779 .tuner_type = TUNER_ABSENT,
1579 */ 1780 .audio_clock = 0x00187de7,
1580 .name = "Avermedia AVerTV 307", 1781 .radio_type = UNSET,
1581 .audio_clock = 0x00187de7, 1782 .tuner_addr = ADDR_UNSET,
1582 .tuner_type = TUNER_PHILIPS_FQ1216ME, 1783 .radio_addr = ADDR_UNSET,
1583 .tda9887_conf = TDA9887_PRESENT, 1784 .mpeg = SAA7134_MPEG_DVB,
1584 .inputs = {{ 1785 .inputs = {{
1585 .name = name_tv, 1786 .name = name_comp1,
1586 .vmux = 1, 1787 .vmux = 0,
1587 .amux = TV, 1788 .amux = LINE1,
1588 .tv = 1, 1789 },{
1589 },{ 1790 .name = name_svideo,
1590 .name = name_comp1, 1791 .vmux = 8,
1591 .vmux = 0, 1792 .amux = LINE1,
1592 .amux = LINE1, 1793 }},
1593 },{ 1794 },
1594 .name = name_comp2, 1795 [SAA7134_BOARD_AVERMEDIA_307] = {
1595 .vmux = 3, 1796 /*
1596 .amux = LINE1, 1797 Davydov Vladimir <vladimir@iqmedia.com>
1597 },{ 1798 */
1598 .name = name_svideo, 1799 .name = "Avermedia AVerTV 307",
1599 .vmux = 8, 1800 .audio_clock = 0x00187de7,
1600 .amux = LINE1, 1801 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1601 }}, 1802 .radio_type = UNSET,
1602 }, 1803 .tuner_addr = ADDR_UNSET,
1804 .radio_addr = ADDR_UNSET,
1805 .tda9887_conf = TDA9887_PRESENT,
1806 .inputs = {{
1807 .name = name_tv,
1808 .vmux = 1,
1809 .amux = TV,
1810 .tv = 1,
1811 },{
1812 .name = name_comp1,
1813 .vmux = 0,
1814 .amux = LINE1,
1815 },{
1816 .name = name_comp2,
1817 .vmux = 3,
1818 .amux = LINE1,
1819 },{
1820 .name = name_svideo,
1821 .vmux = 8,
1822 .amux = LINE1,
1823 }},
1824 },
1603 [SAA7134_BOARD_ADS_INSTANT_TV] = { 1825 [SAA7134_BOARD_ADS_INSTANT_TV] = {
1604 .name = "ADS Tech Instant TV (saa7135)", 1826 .name = "ADS Tech Instant TV (saa7135)",
1827 .audio_clock = 0x00187de7,
1828 .tuner_type = TUNER_PHILIPS_TDA8290,
1829 .radio_type = UNSET,
1830 .tuner_addr = ADDR_UNSET,
1831 .radio_addr = ADDR_UNSET,
1832 .inputs = {{
1833 .name = name_tv,
1834 .vmux = 1,
1835 .amux = TV,
1836 .tv = 1,
1837 },{
1838 .name = name_comp1,
1839 .vmux = 3,
1840 .amux = LINE2,
1841 },{
1842 .name = name_svideo,
1843 .vmux = 8,
1844 .amux = LINE2,
1845 }},
1846 },
1847 [SAA7134_BOARD_KWORLD_VSTREAM_XPERT] = {
1848 .name = "Kworld/Tevion V-Stream Xpert TV PVR7134",
1605 .audio_clock = 0x00187de7, 1849 .audio_clock = 0x00187de7,
1606 .tuner_type = TUNER_PHILIPS_TDA8290, 1850 .tuner_type = TUNER_PHILIPS_PAL_I,
1607 .inputs = {{ 1851 .radio_type = UNSET,
1608 .name = name_tv, 1852 .tuner_addr = ADDR_UNSET,
1609 .vmux = 1, 1853 .radio_addr = ADDR_UNSET,
1610 .amux = TV, 1854 .gpiomask = 0x0700,
1611 .tv = 1, 1855 .inputs = {{
1612 },{ 1856 .name = name_tv,
1613 .name = name_comp1, 1857 .vmux = 1,
1614 .vmux = 3, 1858 .amux = TV,
1615 .amux = LINE2, 1859 .tv = 1,
1616 },{ 1860 .gpio = 0x000,
1617 .name = name_svideo, 1861 },{
1618 .vmux = 8, 1862 .name = name_comp1,
1619 .amux = LINE2, 1863 .vmux = 3,
1620 }}, 1864 .amux = LINE1,
1621 }, 1865 .gpio = 0x200, /* gpio by DScaler */
1622 [SAA7134_BOARD_KWORLD_VSTREAM_XPERT] = { 1866 },{
1623 .name = "Kworld/Tevion V-Stream Xpert TV PVR7134", 1867 .name = name_svideo,
1624 .audio_clock = 0x00187de7, 1868 .vmux = 0,
1625 .tuner_type = TUNER_PHILIPS_PAL_I, 1869 .amux = LINE1,
1626 .gpiomask = 0x0700, 1870 .gpio = 0x200,
1627 .inputs = {{ 1871 }},
1628 .name = name_tv, 1872 .radio = {
1629 .vmux = 1, 1873 .name = name_radio,
1630 .amux = TV, 1874 .amux = LINE1,
1631 .tv = 1, 1875 .gpio = 0x100,
1632 .gpio = 0x000, 1876 },
1633 },{ 1877 .mute = {
1634 .name = name_comp1, 1878 .name = name_mute,
1635 .vmux = 3, 1879 .amux = TV,
1636 .amux = LINE1, 1880 .gpio = 0x000,
1637 .gpio = 0x200, //gpio by DScaler 1881 },
1638 },{ 1882 },
1639 .name = name_svideo, 1883 [SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS] = {
1640 .vmux = 0, 1884 .name = "Typhoon DVB-T Duo Digital/Analog Cardbus",
1641 .amux = LINE1, 1885 .audio_clock = 0x00200000,
1642 .gpio = 0x200, 1886 .tuner_type = TUNER_PHILIPS_TDA8290,
1643 }}, 1887 .radio_type = UNSET,
1644 .radio = { 1888 .tuner_addr = ADDR_UNSET,
1645 .name = name_radio, 1889 .radio_addr = ADDR_UNSET,
1646 .amux = LINE1, 1890 .mpeg = SAA7134_MPEG_DVB,
1647 .gpio = 0x100, 1891 /* .gpiomask = 0xe000, */
1648 }, 1892 .inputs = {{
1649 }, 1893 .name = name_tv,
1650 }; 1894 .vmux = 1,
1895 .amux = TV,
1896 /* .gpio = 0x0000, */
1897 .tv = 1,
1898 },{
1899 .name = name_comp1, /* Composite signal on S-Video input */
1900 .vmux = 0,
1901 .amux = LINE2,
1902 /* .gpio = 0x4000, */
1903 },{
1904 .name = name_comp2, /* Composite input */
1905 .vmux = 3,
1906 .amux = LINE2,
1907 /* .gpio = 0x4000, */
1908 },{
1909 .name = name_svideo, /* S-Video signal on S-Video input */
1910 .vmux = 8,
1911 .amux = LINE2,
1912 /* .gpio = 0x4000, */
1913 }},
1914 .radio = {
1915 .name = name_radio,
1916 .amux = LINE2,
1917 },
1918 .mute = {
1919 .name = name_mute,
1920 .amux = LINE1,
1921 },
1922 },
1923 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII] = {
1924 .name = "Compro VideoMate TV Gold+II",
1925 .audio_clock = 0x002187de7,
1926 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1927 .radio_type = TUNER_TEA5767,
1928 .tuner_addr = 0x63,
1929 .radio_addr = 0x60,
1930 .gpiomask = 0x8c1880,
1931 .inputs = {{
1932 .name = name_svideo,
1933 .vmux = 0,
1934 .amux = LINE1,
1935 .gpio = 0x800800,
1936 },{
1937 .name = name_comp1,
1938 .vmux = 3,
1939 .amux = LINE1,
1940 .gpio = 0x801000,
1941 },{
1942 .name = name_tv,
1943 .vmux = 1,
1944 .amux = TV,
1945 .tv = 1,
1946 .gpio = 0x800000,
1947 }},
1948 .radio = {
1949 .name = name_radio,
1950 .amux = TV,
1951 .gpio = 0x880000,
1952 },
1953 .mute = {
1954 .name = name_mute,
1955 .amux = LINE2,
1956 .gpio = 0x840000,
1957 },
1958 },
1959 [SAA7134_BOARD_KWORLD_XPERT] = {
1960 /*
1961 FIXME:
1962 - Remote control doesn't initialize properly.
1963 - Audio volume starts muted,
1964 then gradually increases after channel change.
1965 - Overlay scaling problems (application error?)
1966 - Composite S-Video untested.
1967 From: Konrad Rzepecki <hannibal@megapolis.pl>
1968 */
1969 .name = "Kworld Xpert TV PVR7134",
1970 .audio_clock = 0x00187de7,
1971 .tuner_type = TUNER_TENA_9533_DI,
1972 .radio_type = TUNER_TEA5767,
1973 .tuner_addr = 0x61,
1974 .radio_addr = 0x60,
1975 .gpiomask = 0x0700,
1976 .inputs = {{
1977 .name = name_tv,
1978 .vmux = 1,
1979 .amux = TV,
1980 .tv = 1,
1981 .gpio = 0x000,
1982 },{
1983 .name = name_comp1,
1984 .vmux = 3,
1985 .amux = LINE1,
1986 .gpio = 0x200, /* gpio by DScaler */
1987 },{
1988 .name = name_svideo,
1989 .vmux = 0,
1990 .amux = LINE1,
1991 .gpio = 0x200,
1992 }},
1993 .radio = {
1994 .name = name_radio,
1995 .amux = LINE1,
1996 .gpio = 0x100,
1997 },
1998 .mute = {
1999 .name = name_mute,
2000 .amux = TV,
2001 .gpio = 0x000,
2002 },
2003 },
2004};
2005
1651 2006
1652const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 2007const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
1653 2008
@@ -1661,13 +2016,13 @@ struct pci_device_id saa7134_pci_tbl[] = {
1661 .subvendor = PCI_VENDOR_ID_PHILIPS, 2016 .subvendor = PCI_VENDOR_ID_PHILIPS,
1662 .subdevice = 0x2001, 2017 .subdevice = 0x2001,
1663 .driver_data = SAA7134_BOARD_PROTEUS_PRO, 2018 .driver_data = SAA7134_BOARD_PROTEUS_PRO,
1664 },{ 2019 },{
1665 .vendor = PCI_VENDOR_ID_PHILIPS, 2020 .vendor = PCI_VENDOR_ID_PHILIPS,
1666 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2021 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1667 .subvendor = PCI_VENDOR_ID_PHILIPS, 2022 .subvendor = PCI_VENDOR_ID_PHILIPS,
1668 .subdevice = 0x2001, 2023 .subdevice = 0x2001,
1669 .driver_data = SAA7134_BOARD_PROTEUS_PRO, 2024 .driver_data = SAA7134_BOARD_PROTEUS_PRO,
1670 },{ 2025 },{
1671 .vendor = PCI_VENDOR_ID_PHILIPS, 2026 .vendor = PCI_VENDOR_ID_PHILIPS,
1672 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2027 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1673 .subvendor = PCI_VENDOR_ID_PHILIPS, 2028 .subvendor = PCI_VENDOR_ID_PHILIPS,
@@ -1676,70 +2031,70 @@ struct pci_device_id saa7134_pci_tbl[] = {
1676 },{ 2031 },{
1677 .vendor = PCI_VENDOR_ID_PHILIPS, 2032 .vendor = PCI_VENDOR_ID_PHILIPS,
1678 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2033 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1679 .subvendor = 0x1131, 2034 .subvendor = 0x1131,
1680 .subdevice = 0x4e85, 2035 .subdevice = 0x4e85,
1681 .driver_data = SAA7134_BOARD_MONSTERTV, 2036 .driver_data = SAA7134_BOARD_MONSTERTV,
1682 },{ 2037 },{
1683 .vendor = PCI_VENDOR_ID_PHILIPS, 2038 .vendor = PCI_VENDOR_ID_PHILIPS,
1684 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2039 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1685 .subvendor = 0x153B, 2040 .subvendor = 0x153B,
1686 .subdevice = 0x1142, 2041 .subdevice = 0x1142,
1687 .driver_data = SAA7134_BOARD_CINERGY400, 2042 .driver_data = SAA7134_BOARD_CINERGY400,
1688 },{ 2043 },{
1689 .vendor = PCI_VENDOR_ID_PHILIPS, 2044 .vendor = PCI_VENDOR_ID_PHILIPS,
1690 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2045 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1691 .subvendor = 0x153B, 2046 .subvendor = 0x153B,
1692 .subdevice = 0x1143, 2047 .subdevice = 0x1143,
1693 .driver_data = SAA7134_BOARD_CINERGY600, 2048 .driver_data = SAA7134_BOARD_CINERGY600,
1694 },{ 2049 },{
1695 .vendor = PCI_VENDOR_ID_PHILIPS, 2050 .vendor = PCI_VENDOR_ID_PHILIPS,
1696 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2051 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1697 .subvendor = 0x153B, 2052 .subvendor = 0x153B,
1698 .subdevice = 0x1158, 2053 .subdevice = 0x1158,
1699 .driver_data = SAA7134_BOARD_CINERGY600_MK3, 2054 .driver_data = SAA7134_BOARD_CINERGY600_MK3,
1700 },{ 2055 },{
1701 .vendor = PCI_VENDOR_ID_PHILIPS, 2056 .vendor = PCI_VENDOR_ID_PHILIPS,
1702 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2057 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1703 .subvendor = 0x153b, 2058 .subvendor = 0x153b,
1704 .subdevice = 0x1162, 2059 .subdevice = 0x1162,
1705 .driver_data = SAA7134_BOARD_CINERGY400_CARDBUS, 2060 .driver_data = SAA7134_BOARD_CINERGY400_CARDBUS,
1706 },{ 2061 },{
1707 .vendor = PCI_VENDOR_ID_PHILIPS, 2062 .vendor = PCI_VENDOR_ID_PHILIPS,
1708 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2063 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1709 .subvendor = 0x5168, 2064 .subvendor = 0x5168,
1710 .subdevice = 0x0138, 2065 .subdevice = 0x0138,
1711 .driver_data = SAA7134_BOARD_FLYVIDEO3000, 2066 .driver_data = SAA7134_BOARD_FLYVIDEO3000,
1712 },{ 2067 },{
1713 .vendor = PCI_VENDOR_ID_PHILIPS, 2068 .vendor = PCI_VENDOR_ID_PHILIPS,
1714 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2069 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1715 .subvendor = 0x4e42, //"Typhoon PCI Capture TV Card" Art.No. 50673 2070 .subvendor = 0x4e42, /* "Typhoon PCI Capture TV Card" Art.No. 50673 */
1716 .subdevice = 0x0138, 2071 .subdevice = 0x0138,
1717 .driver_data = SAA7134_BOARD_FLYVIDEO3000, 2072 .driver_data = SAA7134_BOARD_FLYVIDEO3000,
1718 },{ 2073 },{
1719 .vendor = PCI_VENDOR_ID_PHILIPS, 2074 .vendor = PCI_VENDOR_ID_PHILIPS,
1720 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2075 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1721 .subvendor = 0x5168, 2076 .subvendor = 0x5168,
1722 .subdevice = 0x0138, 2077 .subdevice = 0x0138,
1723 .driver_data = SAA7134_BOARD_FLYVIDEO2000, 2078 .driver_data = SAA7134_BOARD_FLYVIDEO2000,
1724 },{ 2079 },{
1725 .vendor = PCI_VENDOR_ID_PHILIPS, 2080 .vendor = PCI_VENDOR_ID_PHILIPS,
1726 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2081 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1727 .subvendor = 0x5168, 2082 .subvendor = 0x5168,
1728 .subdevice = 0x0212, /* minipci, LR212 */ 2083 .subdevice = 0x0212, /* minipci, LR212 */
1729 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_MINI, 2084 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_MINI,
1730 },{ 2085 },{
1731 .vendor = PCI_VENDOR_ID_PHILIPS, 2086 .vendor = PCI_VENDOR_ID_PHILIPS,
1732 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2087 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1733 .subvendor = 0x5168, /* Animation Technologies (LifeView) */ 2088 .subvendor = 0x5168, /* Animation Technologies (LifeView) */
1734 .subdevice = 0x0214, /* Standard PCI, LR214WF */ 2089 .subdevice = 0x0214, /* Standard PCI, LR214WF */
1735 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, 2090 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM,
1736 },{ 2091 },{
1737 .vendor = PCI_VENDOR_ID_PHILIPS, 2092 .vendor = PCI_VENDOR_ID_PHILIPS,
1738 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2093 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1739 .subvendor = 0x1489, /* KYE */ 2094 .subvendor = 0x1489, /* KYE */
1740 .subdevice = 0x0214, /* Genius VideoWonder ProTV */ 2095 .subdevice = 0x0214, /* Genius VideoWonder ProTV */
1741 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, /* is an LR214WF actually */ 2096 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, /* is an LR214WF actually */
1742 },{ 2097 },{
1743 .vendor = PCI_VENDOR_ID_PHILIPS, 2098 .vendor = PCI_VENDOR_ID_PHILIPS,
1744 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2099 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1745 .subvendor = 0x16be, 2100 .subvendor = 0x16be,
@@ -1758,36 +2113,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
1758 .subdevice = 0x226b, 2113 .subdevice = 0x226b,
1759 .driver_data = SAA7134_BOARD_ELSA_500TV, 2114 .driver_data = SAA7134_BOARD_ELSA_500TV,
1760 },{ 2115 },{
1761 .vendor = PCI_VENDOR_ID_PHILIPS, 2116 .vendor = PCI_VENDOR_ID_PHILIPS,
1762 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2117 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1763 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2118 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1764 .subdevice = 0x4842, 2119 .subdevice = 0x4842,
1765 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134, 2120 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1766 },{ 2121 },{
1767 .vendor = PCI_VENDOR_ID_PHILIPS, 2122 .vendor = PCI_VENDOR_ID_PHILIPS,
1768 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2123 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1769 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2124 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1770 .subdevice = 0x4845, 2125 .subdevice = 0x4845,
1771 .driver_data = SAA7135_BOARD_ASUSTeK_TVFM7135, 2126 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7135,
1772 },{ 2127 },{
1773 .vendor = PCI_VENDOR_ID_PHILIPS, 2128 .vendor = PCI_VENDOR_ID_PHILIPS,
1774 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2129 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1775 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2130 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1776 .subdevice = 0x4830, 2131 .subdevice = 0x4830,
1777 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134, 2132 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1778 },{ 2133 },{
1779 .vendor = PCI_VENDOR_ID_PHILIPS, 2134 .vendor = PCI_VENDOR_ID_PHILIPS,
1780 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2135 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1781 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2136 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1782 .subdevice = 0x4843, 2137 .subdevice = 0x4843,
1783 .driver_data = SAA7134_BOARD_ASUSTEK_TVFM7133, 2138 .driver_data = SAA7134_BOARD_ASUSTEK_TVFM7133,
2139 },{
2140 .vendor = PCI_VENDOR_ID_PHILIPS,
2141 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2142 .subvendor = PCI_VENDOR_ID_ASUSTEK,
2143 .subdevice = 0x4840,
2144 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1784 },{ 2145 },{
1785 .vendor = PCI_VENDOR_ID_PHILIPS,
1786 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1787 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1788 .subdevice = 0x4840,
1789 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1790 },{
1791 .vendor = PCI_VENDOR_ID_PHILIPS, 2146 .vendor = PCI_VENDOR_ID_PHILIPS,
1792 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2147 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1793 .subvendor = PCI_VENDOR_ID_PHILIPS, 2148 .subvendor = PCI_VENDOR_ID_PHILIPS,
@@ -1808,118 +2163,118 @@ struct pci_device_id saa7134_pci_tbl[] = {
1808 },{ 2163 },{
1809 .vendor = PCI_VENDOR_ID_PHILIPS, 2164 .vendor = PCI_VENDOR_ID_PHILIPS,
1810 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2165 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1811 .subvendor = 0x1131, 2166 .subvendor = 0x1131,
1812 .subdevice = 0x7133, 2167 .subdevice = 0x7133,
1813 .driver_data = SAA7134_BOARD_VA1000POWER, 2168 .driver_data = SAA7134_BOARD_VA1000POWER,
1814 },{ 2169 },{
1815 .vendor = PCI_VENDOR_ID_PHILIPS, 2170 .vendor = PCI_VENDOR_ID_PHILIPS,
1816 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2171 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1817 .subvendor = PCI_VENDOR_ID_PHILIPS, 2172 .subvendor = PCI_VENDOR_ID_PHILIPS,
1818 .subdevice = 0x2001, 2173 .subdevice = 0x2001,
1819 .driver_data = SAA7134_BOARD_10MOONSTVMASTER, 2174 .driver_data = SAA7134_BOARD_10MOONSTVMASTER,
1820 },{ 2175 },{
1821 .vendor = PCI_VENDOR_ID_PHILIPS, 2176 .vendor = PCI_VENDOR_ID_PHILIPS,
1822 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2177 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1823 .subvendor = 0x185b, 2178 .subvendor = 0x185b,
1824 .subdevice = 0xc100, 2179 .subdevice = 0xc100,
1825 .driver_data = SAA7134_BOARD_VIDEOMATE_TV, 2180 .driver_data = SAA7134_BOARD_VIDEOMATE_TV,
1826 },{ 2181 },{
1827 .vendor = PCI_VENDOR_ID_PHILIPS, 2182 .vendor = PCI_VENDOR_ID_PHILIPS,
1828 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2183 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1829 .subvendor = 0x185b, 2184 .subvendor = 0x185b,
1830 .subdevice = 0xc100, 2185 .subdevice = 0xc100,
1831 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS, 2186 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS,
1832 },{ 2187 },{
1833 .vendor = PCI_VENDOR_ID_PHILIPS, 2188 .vendor = PCI_VENDOR_ID_PHILIPS,
1834 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2189 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1835 .subvendor = PCI_VENDOR_ID_MATROX, 2190 .subvendor = PCI_VENDOR_ID_MATROX,
1836 .subdevice = 0x48d0, 2191 .subdevice = 0x48d0,
1837 .driver_data = SAA7134_BOARD_CRONOS_PLUS, 2192 .driver_data = SAA7134_BOARD_CRONOS_PLUS,
1838 },{ 2193 },{
1839 .vendor = PCI_VENDOR_ID_PHILIPS, 2194 .vendor = PCI_VENDOR_ID_PHILIPS,
1840 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2195 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1841 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2196 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1842 .subdevice = 0xa70b, 2197 .subdevice = 0xa70b,
1843 .driver_data = SAA7134_BOARD_MD2819, 2198 .driver_data = SAA7134_BOARD_MD2819,
1844 },{ 2199 },{
1845 .vendor = PCI_VENDOR_ID_PHILIPS, 2200 .vendor = PCI_VENDOR_ID_PHILIPS,
1846 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2201 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1847 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2202 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1848 .subdevice = 0x2115, 2203 .subdevice = 0x2115,
1849 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_305, 2204 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_305,
1850 },{ 2205 },{
1851 .vendor = PCI_VENDOR_ID_PHILIPS, 2206 .vendor = PCI_VENDOR_ID_PHILIPS,
1852 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2207 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1853 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2208 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1854 .subdevice = 0x2108, 2209 .subdevice = 0x2108,
1855 .driver_data = SAA7134_BOARD_AVERMEDIA_305, 2210 .driver_data = SAA7134_BOARD_AVERMEDIA_305,
1856 },{ 2211 },{
1857 .vendor = PCI_VENDOR_ID_PHILIPS, 2212 .vendor = PCI_VENDOR_ID_PHILIPS,
1858 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2213 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1859 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2214 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1860 .subdevice = 0x10ff, 2215 .subdevice = 0x10ff,
1861 .driver_data = SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER, 2216 .driver_data = SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER,
1862 },{ 2217 },{
1863 /* AVerMedia CardBus */ 2218 /* AVerMedia CardBus */
1864 .vendor = PCI_VENDOR_ID_PHILIPS, 2219 .vendor = PCI_VENDOR_ID_PHILIPS,
1865 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2220 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1866 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2221 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1867 .subdevice = 0xd6ee, 2222 .subdevice = 0xd6ee,
1868 .driver_data = SAA7134_BOARD_AVERMEDIA_CARDBUS, 2223 .driver_data = SAA7134_BOARD_AVERMEDIA_CARDBUS,
1869 },{ 2224 },{
1870 /* TransGear 3000TV */ 2225 /* TransGear 3000TV */
1871 .vendor = PCI_VENDOR_ID_PHILIPS, 2226 .vendor = PCI_VENDOR_ID_PHILIPS,
1872 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2227 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1873 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2228 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1874 .subdevice = 0x050c, 2229 .subdevice = 0x050c,
1875 .driver_data = SAA7134_BOARD_TG3000TV, 2230 .driver_data = SAA7134_BOARD_TG3000TV,
1876 },{ 2231 },{
1877 .vendor = PCI_VENDOR_ID_PHILIPS,
1878 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1879 .subvendor = 0x11bd,
1880 .subdevice = 0x002b,
1881 .driver_data = SAA7134_BOARD_PINNACLE_PCTV_STEREO,
1882 },{
1883 .vendor = PCI_VENDOR_ID_PHILIPS,
1884 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1885 .subvendor = 0x11bd,
1886 .subdevice = 0x002d,
1887 .driver_data = SAA7134_BOARD_PINNACLE_300I_DVBT_PAL,
1888 },{
1889 .vendor = PCI_VENDOR_ID_PHILIPS,
1890 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1891 .subvendor = 0x1019,
1892 .subdevice = 0x4cb4,
1893 .driver_data = SAA7134_BOARD_ECS_TVP3XP,
1894 },{
1895 .vendor = PCI_VENDOR_ID_PHILIPS,
1896 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1897 .subvendor = 0x1019,
1898 .subdevice = 0x4cb5,
1899 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5,
1900 },{
1901 .vendor = PCI_VENDOR_ID_PHILIPS, 2232 .vendor = PCI_VENDOR_ID_PHILIPS,
1902 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2233 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1903 .subvendor = 0x12ab, 2234 .subvendor = 0x11bd,
1904 .subdevice = 0x0800, 2235 .subdevice = 0x002b,
1905 .driver_data = SAA7133_BOARD_UPMOST_PURPLE_TV, 2236 .driver_data = SAA7134_BOARD_PINNACLE_PCTV_STEREO,
2237 },{
2238 .vendor = PCI_VENDOR_ID_PHILIPS,
2239 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2240 .subvendor = 0x11bd,
2241 .subdevice = 0x002d,
2242 .driver_data = SAA7134_BOARD_PINNACLE_300I_DVBT_PAL,
2243 },{
2244 .vendor = PCI_VENDOR_ID_PHILIPS,
2245 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2246 .subvendor = 0x1019,
2247 .subdevice = 0x4cb4,
2248 .driver_data = SAA7134_BOARD_ECS_TVP3XP,
2249 },{
2250 .vendor = PCI_VENDOR_ID_PHILIPS,
2251 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2252 .subvendor = 0x1019,
2253 .subdevice = 0x4cb5,
2254 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5,
2255 },{
2256 .vendor = PCI_VENDOR_ID_PHILIPS,
2257 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2258 .subvendor = 0x12ab,
2259 .subdevice = 0x0800,
2260 .driver_data = SAA7134_BOARD_UPMOST_PURPLE_TV,
1906 },{ 2261 },{
1907 .vendor = PCI_VENDOR_ID_PHILIPS, 2262 .vendor = PCI_VENDOR_ID_PHILIPS,
1908 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2263 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1909 .subvendor = 0x153B, 2264 .subvendor = 0x153B,
1910 .subdevice = 0x1152, 2265 .subdevice = 0x1152,
1911 .driver_data = SAA7134_BOARD_CINERGY200, 2266 .driver_data = SAA7134_BOARD_CINERGY200,
1912 },{ 2267 },{
1913 .vendor = PCI_VENDOR_ID_PHILIPS, 2268 .vendor = PCI_VENDOR_ID_PHILIPS,
1914 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2269 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1915 .subvendor = 0x185b, 2270 .subvendor = 0x185b,
1916 .subdevice = 0xc100, 2271 .subdevice = 0xc100,
1917 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR, 2272 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR,
1918 },{ 2273 },{
1919 .vendor = PCI_VENDOR_ID_PHILIPS, 2274 .vendor = PCI_VENDOR_ID_PHILIPS,
1920 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2275 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1921 .subvendor = 0x1131, 2276 .subvendor = 0x1131,
1922 .subdevice = 0, 2277 .subdevice = 0,
1923 .driver_data = SAA7134_BOARD_SABRENT_SBTTVFM, 2278 .driver_data = SAA7134_BOARD_SABRENT_SBTTVFM,
1924 },{ 2279 },{
1925 .vendor = PCI_VENDOR_ID_PHILIPS, 2280 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -1939,18 +2294,24 @@ struct pci_device_id saa7134_pci_tbl[] = {
1939 .subvendor = 0x185b, 2294 .subvendor = 0x185b,
1940 .subdevice = 0xc200, 2295 .subdevice = 0xc200,
1941 .driver_data = SAA7134_BOARD_VIDEOMATE_GOLD_PLUS, 2296 .driver_data = SAA7134_BOARD_VIDEOMATE_GOLD_PLUS,
1942 },{ 2297 },{
1943 .vendor = PCI_VENDOR_ID_PHILIPS, 2298 .vendor = PCI_VENDOR_ID_PHILIPS,
1944 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2299 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1945 .subvendor = 0x1540, 2300 .subvendor = 0x1540,
1946 .subdevice = 0x9524, 2301 .subdevice = 0x9524,
1947 .driver_data = SAA7134_BOARD_PROVIDEO_PV952, 2302 .driver_data = SAA7134_BOARD_PROVIDEO_PV952,
1948 2303
1949 },{ 2304 },{
1950 .vendor = PCI_VENDOR_ID_PHILIPS, 2305 .vendor = PCI_VENDOR_ID_PHILIPS,
1951 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2306 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1952 .subvendor = 0x5168, 2307 .subvendor = 0x5168,
1953 .subdevice = 0x0306, 2308 .subdevice = 0x0502, /* Cardbus version */
2309 .driver_data = SAA7134_BOARD_FLYDVBTDUO,
2310 },{
2311 .vendor = PCI_VENDOR_ID_PHILIPS,
2312 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2313 .subvendor = 0x5168,
2314 .subdevice = 0x0306, /* PCI version */
1954 .driver_data = SAA7134_BOARD_FLYDVBTDUO, 2315 .driver_data = SAA7134_BOARD_FLYDVBTDUO,
1955 },{ 2316 },{
1956 .vendor = PCI_VENDOR_ID_PHILIPS, 2317 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -1959,31 +2320,44 @@ struct pci_device_id saa7134_pci_tbl[] = {
1959 .subdevice = 0xf31f, 2320 .subdevice = 0xf31f,
1960 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM, 2321 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM,
1961 2322
1962 },{ 2323 },{
1963 .vendor = PCI_VENDOR_ID_PHILIPS, 2324 .vendor = PCI_VENDOR_ID_PHILIPS,
1964 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2325 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
2326 .subvendor = PCI_VENDOR_ID_PHILIPS,
2327 .subdevice = 0x2004,
2328 .driver_data = SAA7134_BOARD_PHILIPS_TOUGH,
2329 },{
2330 .vendor = PCI_VENDOR_ID_PHILIPS,
2331 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1965 .subvendor = 0x1421, 2332 .subvendor = 0x1421,
1966 .subdevice = 0x0350, /* PCI version */ 2333 .subdevice = 0x0350, /* PCI version */
1967 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV, 2334 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1968 2335
1969 },{ 2336 },{
1970 .vendor = PCI_VENDOR_ID_PHILIPS, 2337 .vendor = PCI_VENDOR_ID_PHILIPS,
1971 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2338 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1972 .subvendor = 0x1421, 2339 .subvendor = 0x1421,
1973 .subdevice = 0x0370, /* cardbus version */ 2340 .subdevice = 0x0370, /* cardbus version */
1974 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV, 2341 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1975 2342
1976 },{ 2343 },{ /* Typhoon DVB-T Duo Digital/Analog Cardbus */
2344 .vendor = PCI_VENDOR_ID_PHILIPS,
2345 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2346 .subvendor = 0x4e42,
2347 .subdevice = 0x0502,
2348 .driver_data = SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS,
2349
2350 },{
1977 /* --- boards without eeprom + subsystem ID --- */ 2351 /* --- boards without eeprom + subsystem ID --- */
1978 .vendor = PCI_VENDOR_ID_PHILIPS, 2352 .vendor = PCI_VENDOR_ID_PHILIPS,
1979 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2353 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1980 .subvendor = PCI_VENDOR_ID_PHILIPS, 2354 .subvendor = PCI_VENDOR_ID_PHILIPS,
1981 .subdevice = 0, 2355 .subdevice = 0,
1982 .driver_data = SAA7134_BOARD_NOAUTO, 2356 .driver_data = SAA7134_BOARD_NOAUTO,
1983 },{ 2357 },{
1984 .vendor = PCI_VENDOR_ID_PHILIPS, 2358 .vendor = PCI_VENDOR_ID_PHILIPS,
1985 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2359 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1986 .subvendor = PCI_VENDOR_ID_PHILIPS, 2360 .subvendor = PCI_VENDOR_ID_PHILIPS,
1987 .subdevice = 0, 2361 .subdevice = 0,
1988 .driver_data = SAA7134_BOARD_NOAUTO, 2362 .driver_data = SAA7134_BOARD_NOAUTO,
1989 },{ 2363 },{
@@ -1991,26 +2365,26 @@ struct pci_device_id saa7134_pci_tbl[] = {
1991 /* --- default catch --- */ 2365 /* --- default catch --- */
1992 .vendor = PCI_VENDOR_ID_PHILIPS, 2366 .vendor = PCI_VENDOR_ID_PHILIPS,
1993 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2367 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1994 .subvendor = PCI_ANY_ID, 2368 .subvendor = PCI_ANY_ID,
1995 .subdevice = PCI_ANY_ID, 2369 .subdevice = PCI_ANY_ID,
1996 .driver_data = SAA7134_BOARD_UNKNOWN, 2370 .driver_data = SAA7134_BOARD_UNKNOWN,
1997 },{ 2371 },{
1998 .vendor = PCI_VENDOR_ID_PHILIPS, 2372 .vendor = PCI_VENDOR_ID_PHILIPS,
1999 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2373 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2000 .subvendor = PCI_ANY_ID, 2374 .subvendor = PCI_ANY_ID,
2001 .subdevice = PCI_ANY_ID, 2375 .subdevice = PCI_ANY_ID,
2002 .driver_data = SAA7134_BOARD_UNKNOWN, 2376 .driver_data = SAA7134_BOARD_UNKNOWN,
2003 },{ 2377 },{
2004 .vendor = PCI_VENDOR_ID_PHILIPS, 2378 .vendor = PCI_VENDOR_ID_PHILIPS,
2005 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2379 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2006 .subvendor = PCI_ANY_ID, 2380 .subvendor = PCI_ANY_ID,
2007 .subdevice = PCI_ANY_ID, 2381 .subdevice = PCI_ANY_ID,
2008 .driver_data = SAA7134_BOARD_UNKNOWN, 2382 .driver_data = SAA7134_BOARD_UNKNOWN,
2009 },{ 2383 },{
2010 .vendor = PCI_VENDOR_ID_PHILIPS, 2384 .vendor = PCI_VENDOR_ID_PHILIPS,
2011 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2385 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
2012 .subvendor = PCI_ANY_ID, 2386 .subvendor = PCI_ANY_ID,
2013 .subdevice = PCI_ANY_ID, 2387 .subdevice = PCI_ANY_ID,
2014 .driver_data = SAA7134_BOARD_UNKNOWN, 2388 .driver_data = SAA7134_BOARD_UNKNOWN,
2015 },{ 2389 },{
2016 /* --- end of list --- */ 2390 /* --- end of list --- */
@@ -2021,46 +2395,9 @@ MODULE_DEVICE_TABLE(pci, saa7134_pci_tbl);
2021/* ----------------------------------------------------------- */ 2395/* ----------------------------------------------------------- */
2022/* flyvideo tweaks */ 2396/* flyvideo tweaks */
2023 2397
2024#if 0
2025static struct {
2026 char *model;
2027 int tuner_type;
2028} fly_list[0x20] = {
2029 /* default catch ... */
2030 [ 0 ... 0x1f ] = {
2031 .model = "UNKNOWN",
2032 .tuner_type = TUNER_ABSENT,
2033 },
2034 /* ... the ones known so far */
2035 [ 0x05 ] = {
2036 .model = "PAL-BG",
2037 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
2038 },
2039 [ 0x10 ] = {
2040 .model = "PAL-BG / PAL-DK",
2041 .tuner_type = TUNER_PHILIPS_PAL,
2042 },
2043 [ 0x15 ] = {
2044 .model = "NTSC",
2045 .tuner_type = TUNER_ABSENT /* FIXME */,
2046 },
2047};
2048#endif
2049 2398
2050static void board_flyvideo(struct saa7134_dev *dev) 2399static void board_flyvideo(struct saa7134_dev *dev)
2051{ 2400{
2052#if 0
2053 /* non-working attempt to detect the correct tuner type ... */
2054 u32 value;
2055 int index;
2056
2057 value = dev->gpio_value;
2058 index = (value & 0x1f00) >> 8;
2059 printk(KERN_INFO "%s: flyvideo: gpio is 0x%x [model=%s,tuner=%d]\n",
2060 dev->name, value, fly_list[index].model,
2061 fly_list[index].tuner_type);
2062 dev->tuner_type = fly_list[index].tuner_type;
2063#endif
2064 printk("%s: there are different flyvideo cards with different tuners\n" 2401 printk("%s: there are different flyvideo cards with different tuners\n"
2065 "%s: out there, you might have to use the tuner=<nr> insmod\n" 2402 "%s: out there, you might have to use the tuner=<nr> insmod\n"
2066 "%s: option to override the default value.\n", 2403 "%s: option to override the default value.\n",
@@ -2071,7 +2408,7 @@ static void board_flyvideo(struct saa7134_dev *dev)
2071 2408
2072int saa7134_board_init1(struct saa7134_dev *dev) 2409int saa7134_board_init1(struct saa7134_dev *dev)
2073{ 2410{
2074 // Always print gpio, often manufacturers encode tuner type and other info. 2411 /* Always print gpio, often manufacturers encode tuner type and other info. */
2075 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0); 2412 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0);
2076 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); 2413 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
2077 printk(KERN_INFO "%s: board init: gpio is %x\n", dev->name, dev->gpio_value); 2414 printk(KERN_INFO "%s: board init: gpio is %x\n", dev->name, dev->gpio_value);
@@ -2082,7 +2419,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2082 dev->has_remote = 1; 2419 dev->has_remote = 1;
2083 board_flyvideo(dev); 2420 board_flyvideo(dev);
2084 break; 2421 break;
2085 case SAA7134_BOARD_FLYTVPLATINUM_FM: 2422 case SAA7134_BOARD_FLYTVPLATINUM_FM:
2086 case SAA7134_BOARD_CINERGY400: 2423 case SAA7134_BOARD_CINERGY400:
2087 case SAA7134_BOARD_CINERGY600: 2424 case SAA7134_BOARD_CINERGY600:
2088 case SAA7134_BOARD_CINERGY600_MK3: 2425 case SAA7134_BOARD_CINERGY600_MK3:
@@ -2090,23 +2427,25 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2090 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 2427 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
2091 case SAA7134_BOARD_MD2819: 2428 case SAA7134_BOARD_MD2819:
2092 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 2429 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
2430 case SAA7134_BOARD_KWORLD_XPERT:
2093 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 2431 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
2094 case SAA7134_BOARD_AVERMEDIA_305: 2432 case SAA7134_BOARD_AVERMEDIA_305:
2095 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 2433 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
2096 case SAA7134_BOARD_AVERMEDIA_307: 2434 case SAA7134_BOARD_AVERMEDIA_307:
2097 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 2435 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
2098// case SAA7134_BOARD_SABRENT_SBTTVFM: /* not finished yet */ 2436/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */
2099 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 2437 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
2100 case SAA7134_BOARD_MANLI_MTV001: 2438 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
2101 case SAA7134_BOARD_MANLI_MTV002: 2439 case SAA7134_BOARD_MANLI_MTV001:
2440 case SAA7134_BOARD_MANLI_MTV002:
2102 case SAA7134_BOARD_AVACSSMARTTV: 2441 case SAA7134_BOARD_AVACSSMARTTV:
2103 dev->has_remote = 1; 2442 dev->has_remote = 1;
2104 break; 2443 break;
2105 case SAA7134_BOARD_MD5044: 2444 case SAA7134_BOARD_MD5044:
2106 printk("%s: seems there are two different versions of the MD5044\n" 2445 printk("%s: seems there are two different versions of the MD5044\n"
2107 "%s: (with the same ID) out there. If sound doesn't work for\n" 2446 "%s: (with the same ID) out there. If sound doesn't work for\n"
2108 "%s: you try the audio_clock_override=0x200000 insmod option.\n", 2447 "%s: you try the audio_clock_override=0x200000 insmod option.\n",
2109 dev->name,dev->name,dev->name); 2448 dev->name,dev->name,dev->name);
2110 break; 2449 break;
2111 case SAA7134_BOARD_CINERGY400_CARDBUS: 2450 case SAA7134_BOARD_CINERGY400_CARDBUS:
2112 /* power-up tuner chip */ 2451 /* power-up tuner chip */
@@ -2114,11 +2453,19 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2114 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00040000, 0x00000000); 2453 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00040000, 0x00000000);
2115 msleep(1); 2454 msleep(1);
2116 break; 2455 break;
2456 case SAA7134_BOARD_FLYDVBTDUO:
2457 case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
2458 /* turn the fan on Hac: static for the time being */
2459 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08);
2460 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06);
2461 break;
2462 case SAA7134_BOARD_AVERMEDIA_CARDBUS:
2463 /* power-up tuner chip */
2464 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff);
2465 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff);
2466 msleep(1);
2467 break;
2117 } 2468 }
2118 if (dev->has_remote)
2119 dev->irq2_mask |= (SAA7134_IRQ2_INTE_GPIO18 |
2120 SAA7134_IRQ2_INTE_GPIO18A |
2121 SAA7134_IRQ2_INTE_GPIO16 );
2122 return 0; 2469 return 0;
2123} 2470}
2124 2471
@@ -2139,10 +2486,85 @@ int saa7134_board_init2(struct saa7134_dev *dev)
2139 break; 2486 break;
2140 dev->board = board; 2487 dev->board = board;
2141 printk("%s: board type fixup: %s\n", dev->name, 2488 printk("%s: board type fixup: %s\n", dev->name,
2142 saa7134_boards[dev->board].name); 2489 saa7134_boards[dev->board].name);
2143 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 2490 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
2144 if (TUNER_ABSENT != dev->tuner_type) 2491
2145 saa7134_i2c_call_clients(dev,TUNER_SET_TYPE,&dev->tuner_type); 2492 if (TUNER_ABSENT != dev->tuner_type) {
2493 struct tuner_setup tun_setup;
2494
2495 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2496 tun_setup.type = dev->tuner_type;
2497 tun_setup.addr = ADDR_UNSET;
2498
2499 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR, &tun_setup);
2500 }
2501 break;
2502case SAA7134_BOARD_MD7134:
2503 {
2504 struct tuner_setup tun_setup;
2505 u8 subaddr;
2506 u8 data[3];
2507 int ret, tuner_t;
2508
2509 struct i2c_msg msg[] = {{.addr=0x50, .flags=0, .buf=&subaddr, .len = 1},
2510 {.addr=0x50, .flags=I2C_M_RD, .buf=data, .len = 3}};
2511 subaddr= 0x14;
2512 tuner_t = 0;
2513 ret = i2c_transfer(&dev->i2c_adap, msg, 2);
2514 if (ret != 2) {
2515 printk(KERN_ERR "EEPROM read failure\n");
2516 } else if ((data[0] != 0) && (data[0] != 0xff)) {
2517 /* old config structure */
2518 subaddr = data[0] + 2;
2519 msg[1].len = 2;
2520 i2c_transfer(&dev->i2c_adap, msg, 2);
2521 tuner_t = (data[0] << 8) + data[1];
2522 switch (tuner_t){
2523 case 0x0103:
2524 dev->tuner_type = TUNER_PHILIPS_PAL;
2525 break;
2526 case 0x010C:
2527 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
2528 break;
2529 default:
2530 printk(KERN_ERR "%s Cant determine tuner type %x from EEPROM\n", dev->name, tuner_t);
2531 }
2532 } else if ((data[1] != 0) && (data[1] != 0xff)) {
2533 /* new config structure */
2534 subaddr = data[1] + 1;
2535 msg[1].len = 1;
2536 i2c_transfer(&dev->i2c_adap, msg, 2);
2537 subaddr = data[0] + 1;
2538 msg[1].len = 2;
2539 i2c_transfer(&dev->i2c_adap, msg, 2);
2540 tuner_t = (data[1] << 8) + data[0];
2541 switch (tuner_t) {
2542 case 0x0005:
2543 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
2544 break;
2545 case 0x001d:
2546 dev->tuner_type = TUNER_PHILIPS_FMD1216ME_MK3;
2547 printk(KERN_INFO "%s Board has DVB-T\n", dev->name);
2548 break;
2549 default:
2550 printk(KERN_ERR "%s Cant determine tuner type %x from EEPROM\n", dev->name, tuner_t);
2551 }
2552 } else {
2553 printk(KERN_ERR "%s unexpected config structure\n", dev->name);
2554 }
2555
2556 printk(KERN_INFO "%s Tuner type is %d\n", dev->name, dev->tuner_type);
2557 if (dev->tuner_type == TUNER_PHILIPS_FMD1216ME_MK3) {
2558 dev->tda9887_conf = TDA9887_PRESENT | TDA9887_PORT1_ACTIVE | TDA9887_PORT2_ACTIVE;
2559 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG, &dev->tda9887_conf);
2560 }
2561
2562 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2563 tun_setup.type = dev->tuner_type;
2564 tun_setup.addr = ADDR_UNSET;
2565
2566 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR,&tun_setup);
2567 }
2146 break; 2568 break;
2147 } 2569 }
2148 return 0; 2570 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index f61ed1849a2a..1dbe61755e9f 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-core.c,v 1.30 2005/05/22 19:23:39 nsh Exp $ 2 * $Id: saa7134-core.c,v 1.39 2005/07/05 17:37:35 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * driver core 5 * driver core
@@ -183,46 +183,6 @@ void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
183 183
184/* ------------------------------------------------------------------ */ 184/* ------------------------------------------------------------------ */
185 185
186#if 0
187static char *dec1_bits[8] = {
188 "DCSTD0", "DCSCT1", "WIPA", "GLIMB",
189 "GLIMT", "SLTCA", "HLCK"
190};
191static char *dec2_bits[8] = {
192 "RDCAP", "COPRO", "COLSTR", "TYPE3",
193 NULL, "FIDT", "HLVLN", "INTL"
194};
195static char *scale1_bits[8] = {
196 "VID_A", "VBI_A", NULL, NULL, "VID_B", "VBI_B"
197};
198static char *scale2_bits[8] = {
199 "TRERR", "CFERR", "LDERR", "WASRST",
200 "FIDSCI", "FIDSCO", "D6^D5", "TASK"
201};
202
203static void dump_statusreg(struct saa7134_dev *dev, int reg,
204 char *regname, char **bits)
205{
206 int value,i;
207
208 value = saa_readb(reg);
209 printk(KERN_DEBUG "%s: %s:", dev->name, regname);
210 for (i = 7; i >= 0; i--) {
211 if (NULL == bits[i])
212 continue;
213 printk(" %s=%d", bits[i], (value & (1 << i)) ? 1 : 0);
214 }
215 printk("\n");
216}
217
218static void dump_statusregs(struct saa7134_dev *dev)
219{
220 dump_statusreg(dev,SAA7134_STATUS_VIDEO1,"dec1",dec1_bits);
221 dump_statusreg(dev,SAA7134_STATUS_VIDEO2,"dec2",dec2_bits);
222 dump_statusreg(dev,SAA7134_SCALER_STATUS0,"scale0",scale1_bits);
223 dump_statusreg(dev,SAA7134_SCALER_STATUS1,"scale1",scale2_bits);
224}
225#endif
226 186
227/* ----------------------------------------------------------- */ 187/* ----------------------------------------------------------- */
228/* delayed request_module */ 188/* delayed request_module */
@@ -616,10 +576,6 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id, struct pt_regs *regs)
616 if (irq_debug) 576 if (irq_debug)
617 print_irqstatus(dev,loop,report,status); 577 print_irqstatus(dev,loop,report,status);
618 578
619#if 0
620 if (report & SAA7134_IRQ_REPORT_CONF_ERR)
621 dump_statusregs(dev);
622#endif
623 579
624 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */) 580 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */)
625 saa7134_irq_video_intl(dev); 581 saa7134_irq_video_intl(dev);
@@ -711,7 +667,6 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
711 SAA7134_MAIN_CTRL_EVFE1 | 667 SAA7134_MAIN_CTRL_EVFE1 |
712 SAA7134_MAIN_CTRL_EVFE2 | 668 SAA7134_MAIN_CTRL_EVFE2 |
713 SAA7134_MAIN_CTRL_ESFE | 669 SAA7134_MAIN_CTRL_ESFE |
714 SAA7134_MAIN_CTRL_EBADC |
715 SAA7134_MAIN_CTRL_EBDAC); 670 SAA7134_MAIN_CTRL_EBDAC);
716 671
717 /* enable peripheral devices */ 672 /* enable peripheral devices */
@@ -726,14 +681,28 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
726/* late init (with i2c + irq) */ 681/* late init (with i2c + irq) */
727static int saa7134_hwinit2(struct saa7134_dev *dev) 682static int saa7134_hwinit2(struct saa7134_dev *dev)
728{ 683{
684 unsigned int irq2_mask;
729 dprintk("hwinit2\n"); 685 dprintk("hwinit2\n");
730 686
731 saa7134_video_init2(dev); 687 saa7134_video_init2(dev);
732 saa7134_tvaudio_init2(dev); 688 saa7134_tvaudio_init2(dev);
733 689
734 /* enable IRQ's */ 690 /* enable IRQ's */
691 irq2_mask =
692 SAA7134_IRQ2_INTE_DEC3 |
693 SAA7134_IRQ2_INTE_DEC2 |
694 SAA7134_IRQ2_INTE_DEC1 |
695 SAA7134_IRQ2_INTE_DEC0 |
696 SAA7134_IRQ2_INTE_PE |
697 SAA7134_IRQ2_INTE_AR;
698
699 if (dev->has_remote)
700 irq2_mask |= (SAA7134_IRQ2_INTE_GPIO18 |
701 SAA7134_IRQ2_INTE_GPIO18A |
702 SAA7134_IRQ2_INTE_GPIO16 );
703
735 saa_writel(SAA7134_IRQ1, 0); 704 saa_writel(SAA7134_IRQ1, 0);
736 saa_writel(SAA7134_IRQ2, dev->irq2_mask); 705 saa_writel(SAA7134_IRQ2, irq2_mask);
737 706
738 return 0; 707 return 0;
739} 708}
@@ -954,13 +923,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
954 } 923 }
955 924
956 /* initialize hardware #1 */ 925 /* initialize hardware #1 */
957 dev->irq2_mask =
958 SAA7134_IRQ2_INTE_DEC3 |
959 SAA7134_IRQ2_INTE_DEC2 |
960 SAA7134_IRQ2_INTE_DEC1 |
961 SAA7134_IRQ2_INTE_DEC0 |
962 SAA7134_IRQ2_INTE_PE |
963 SAA7134_IRQ2_INTE_AR;
964 saa7134_board_init1(dev); 926 saa7134_board_init1(dev);
965 saa7134_hwinit1(dev); 927 saa7134_hwinit1(dev);
966 928
@@ -990,6 +952,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
990 request_module("saa6752hs"); 952 request_module("saa6752hs");
991 request_module_depend("saa7134-empress",&need_empress); 953 request_module_depend("saa7134-empress",&need_empress);
992 } 954 }
955
993 if (card_is_dvb(dev)) 956 if (card_is_dvb(dev))
994 request_module_depend("saa7134-dvb",&need_dvb); 957 request_module_depend("saa7134-dvb",&need_dvb);
995 958
@@ -1144,9 +1107,6 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1144 release_mem_region(pci_resource_start(pci_dev,0), 1107 release_mem_region(pci_resource_start(pci_dev,0),
1145 pci_resource_len(pci_dev,0)); 1108 pci_resource_len(pci_dev,0));
1146 1109
1147#if 0 /* causes some trouble when reinserting the driver ... */
1148 pci_disable_device(pci_dev);
1149#endif
1150 pci_set_drvdata(pci_dev, NULL); 1110 pci_set_drvdata(pci_dev, NULL);
1151 1111
1152 /* free memory */ 1112 /* free memory */
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index aa8e2cf62d55..334bc1850092 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1,8 +1,11 @@
1/* 1/*
2 * $Id: saa7134-dvb.c,v 1.13 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: saa7134-dvb.c,v 1.18 2005/07/04 16:05:50 mkrufky Exp $
3 * 3 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 5 *
6 * Extended 3 / 2005 by Hartmut Hackmann to support various
7 * cards with the tda10046 DVB-T channel decoder
8 *
6 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -27,23 +30,31 @@
27#include <linux/kthread.h> 30#include <linux/kthread.h>
28#include <linux/suspend.h> 31#include <linux/suspend.h>
29 32
33#define CONFIG_DVB_MT352 1
34#define CONFIG_DVB_TDA1004X 1
35
30#include "saa7134-reg.h" 36#include "saa7134-reg.h"
31#include "saa7134.h" 37#include "saa7134.h"
32 38
33#include "dvb-pll.h" 39#if CONFIG_DVB_MT352
34#include "mt352.h" 40# include "mt352.h"
35#include "mt352_priv.h" /* FIXME */ 41# include "mt352_priv.h" /* FIXME */
36#include "tda1004x.h" 42#endif
43#if CONFIG_DVB_TDA1004X
44# include "tda1004x.h"
45#endif
37 46
38MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 47MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
39MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
40 49
41static unsigned int antenna_pwr = 0; 50static unsigned int antenna_pwr = 0;
51
42module_param(antenna_pwr, int, 0444); 52module_param(antenna_pwr, int, 0444);
43MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 53MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
44 54
45/* ------------------------------------------------------------------ */ 55/* ------------------------------------------------------------------ */
46 56
57#if CONFIG_DVB_MT352
47static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
48{ 59{
49 u32 ok; 60 u32 ok;
@@ -138,51 +149,390 @@ static struct mt352_config pinnacle_300i = {
138 .demod_init = mt352_pinnacle_init, 149 .demod_init = mt352_pinnacle_init,
139 .pll_set = mt352_pinnacle_pll_set, 150 .pll_set = mt352_pinnacle_pll_set,
140}; 151};
152#endif
141 153
142/* ------------------------------------------------------------------ */ 154/* ------------------------------------------------------------------ */
143 155
144static int medion_cardbus_init(struct dvb_frontend* fe) 156#if CONFIG_DVB_TDA1004X
157static int philips_tu1216_pll_init(struct dvb_frontend *fe)
145{ 158{
146 /* anything to do here ??? */ 159 struct saa7134_dev *dev = fe->dvb->priv;
160 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
161 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
162
163 /* setup PLL configuration */
164 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
165 return -EIO;
166 msleep(1);
167
147 return 0; 168 return 0;
148} 169}
149 170
150static int medion_cardbus_pll_set(struct dvb_frontend* fe, 171static int philips_tu1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
151 struct dvb_frontend_parameters* params)
152{ 172{
153 struct saa7134_dev *dev = fe->dvb->priv; 173 struct saa7134_dev *dev = fe->dvb->priv;
154 struct v4l2_frequency f; 174 u8 tuner_buf[4];
175 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len =
176 sizeof(tuner_buf) };
177 int tuner_frequency = 0;
178 u8 band, cp, filter;
179
180 /* determine charge pump */
181 tuner_frequency = params->frequency + 36166000;
182 if (tuner_frequency < 87000000)
183 return -EINVAL;
184 else if (tuner_frequency < 130000000)
185 cp = 3;
186 else if (tuner_frequency < 160000000)
187 cp = 5;
188 else if (tuner_frequency < 200000000)
189 cp = 6;
190 else if (tuner_frequency < 290000000)
191 cp = 3;
192 else if (tuner_frequency < 420000000)
193 cp = 5;
194 else if (tuner_frequency < 480000000)
195 cp = 6;
196 else if (tuner_frequency < 620000000)
197 cp = 3;
198 else if (tuner_frequency < 830000000)
199 cp = 5;
200 else if (tuner_frequency < 895000000)
201 cp = 7;
202 else
203 return -EINVAL;
204
205 /* determine band */
206 if (params->frequency < 49000000)
207 return -EINVAL;
208 else if (params->frequency < 161000000)
209 band = 1;
210 else if (params->frequency < 444000000)
211 band = 2;
212 else if (params->frequency < 861000000)
213 band = 4;
214 else
215 return -EINVAL;
216
217 /* setup PLL filter */
218 switch (params->u.ofdm.bandwidth) {
219 case BANDWIDTH_6_MHZ:
220 filter = 0;
221 break;
155 222
156 /* 223 case BANDWIDTH_7_MHZ:
157 * this instructs tuner.o to set the frequency, the call will 224 filter = 0;
158 * end up in tuner_command(), VIDIOC_S_FREQUENCY switch. 225 break;
159 * tda9887.o will see that as well. 226
227 case BANDWIDTH_8_MHZ:
228 filter = 1;
229 break;
230
231 default:
232 return -EINVAL;
233 }
234
235 /* calculate divisor
236 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
160 */ 237 */
161 f.tuner = 0; 238 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
162 f.type = V4L2_TUNER_DIGITAL_TV; 239
163 f.frequency = params->frequency / 1000 * 16 / 1000; 240 /* setup tuner buffer */
164 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f); 241 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
242 tuner_buf[1] = tuner_frequency & 0xff;
243 tuner_buf[2] = 0xca;
244 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
245
246 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
247 return -EIO;
248
249 msleep(1);
165 return 0; 250 return 0;
166} 251}
167 252
168static int fe_request_firmware(struct dvb_frontend* fe, 253static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
169 const struct firmware **fw, char* name) 254 const struct firmware **fw, char *name)
170{ 255{
171 struct saa7134_dev *dev = fe->dvb->priv; 256 struct saa7134_dev *dev = fe->dvb->priv;
172 return request_firmware(fw, name, &dev->pci->dev); 257 return request_firmware(fw, name, &dev->pci->dev);
173} 258}
174 259
260static struct tda1004x_config philips_tu1216_config = {
261
262 .demod_address = 0x8,
263 .invert = 1,
264 .invert_oclk = 1,
265 .xtal_freq = TDA10046_XTAL_4M,
266 .agc_config = TDA10046_AGC_DEFAULT,
267 .if_freq = TDA10046_FREQ_3617,
268 .pll_init = philips_tu1216_pll_init,
269 .pll_set = philips_tu1216_pll_set,
270 .pll_sleep = NULL,
271 .request_firmware = philips_tu1216_request_firmware,
272};
273
274/* ------------------------------------------------------------------ */
275
276
277static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
278{
279 struct saa7134_dev *dev = fe->dvb->priv;
280 /* this message is to set up ATC and ALC */
281 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
282 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
283
284 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
285 return -EIO;
286 msleep(1);
287
288 return 0;
289}
290
291static void philips_fmd1216_analog(struct dvb_frontend *fe)
292{
293 struct saa7134_dev *dev = fe->dvb->priv;
294 /* this message actually turns the tuner back to analog mode */
295 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
296 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
297
298 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
299 msleep(1);
300 fmd1216_init[2] = 0x86;
301 fmd1216_init[3] = 0x54;
302 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
303 msleep(1);
304}
305
306static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
307{
308 struct saa7134_dev *dev = fe->dvb->priv;
309 u8 tuner_buf[4];
310 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
311 sizeof(tuner_buf) };
312 int tuner_frequency = 0;
313 int divider = 0;
314 u8 band, mode, cp;
315
316 /* determine charge pump */
317 tuner_frequency = params->frequency + 36130000;
318 if (tuner_frequency < 87000000)
319 return -EINVAL;
320 /* low band */
321 else if (tuner_frequency < 180000000) {
322 band = 1;
323 mode = 7;
324 cp = 0;
325 } else if (tuner_frequency < 195000000) {
326 band = 1;
327 mode = 6;
328 cp = 1;
329 /* mid band */
330 } else if (tuner_frequency < 366000000) {
331 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
332 band = 10;
333 } else {
334 band = 2;
335 }
336 mode = 7;
337 cp = 0;
338 } else if (tuner_frequency < 478000000) {
339 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
340 band = 10;
341 } else {
342 band = 2;
343 }
344 mode = 6;
345 cp = 1;
346 /* high band */
347 } else if (tuner_frequency < 662000000) {
348 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
349 band = 12;
350 } else {
351 band = 4;
352 }
353 mode = 7;
354 cp = 0;
355 } else if (tuner_frequency < 840000000) {
356 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
357 band = 12;
358 } else {
359 band = 4;
360 }
361 mode = 6;
362 cp = 1;
363 } else {
364 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
365 band = 12;
366 } else {
367 band = 4;
368 }
369 mode = 7;
370 cp = 1;
371
372 }
373 /* calculate divisor */
374 /* ((36166000 + Finput) / 166666) rounded! */
375 divider = (tuner_frequency + 83333) / 166667;
376
377 /* setup tuner buffer */
378 tuner_buf[0] = (divider >> 8) & 0x7f;
379 tuner_buf[1] = divider & 0xff;
380 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
381 tuner_buf[3] = 0x40 | band;
382
383 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
384 return -EIO;
385 return 0;
386}
387
388
175static struct tda1004x_config medion_cardbus = { 389static struct tda1004x_config medion_cardbus = {
176 .demod_address = 0x08, /* not sure this is correct */ 390 .demod_address = 0x08,
177 .invert = 0, 391 .invert = 1,
178 .invert_oclk = 0, 392 .invert_oclk = 0,
179 .pll_init = medion_cardbus_init, 393 .xtal_freq = TDA10046_XTAL_16M,
180 .pll_set = medion_cardbus_pll_set, 394 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
181 .request_firmware = fe_request_firmware, 395 .if_freq = TDA10046_FREQ_3613,
396 .pll_init = philips_fmd1216_pll_init,
397 .pll_set = philips_fmd1216_pll_set,
398 .pll_sleep = philips_fmd1216_analog,
399 .request_firmware = NULL,
182}; 400};
183 401
184/* ------------------------------------------------------------------ */ 402/* ------------------------------------------------------------------ */
185 403
404struct tda827x_data {
405 u32 lomax;
406 u8 spd;
407 u8 bs;
408 u8 bp;
409 u8 cp;
410 u8 gc3;
411 u8 div1p5;
412};
413
414static struct tda827x_data tda827x_dvbt[] = {
415 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
416 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
417 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
418 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
419 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
420 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
421 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
422 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
423 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
424 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
425 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
426 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
427 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
428 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
429 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
430 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
431 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
432 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
433 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
434 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
435 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
436 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
437 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
438 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
439 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
440 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
441 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
442 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
443 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
444};
445
446static int philips_tda827x_pll_init(struct dvb_frontend *fe)
447{
448 return 0;
449}
450
451static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
452{
453 struct saa7134_dev *dev = fe->dvb->priv;
454 u8 tuner_buf[14];
455
456 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
457 .len = sizeof(tuner_buf) };
458 int i, tuner_freq, if_freq;
459 u32 N;
460 switch (params->u.ofdm.bandwidth) {
461 case BANDWIDTH_6_MHZ:
462 if_freq = 4000000;
463 break;
464 case BANDWIDTH_7_MHZ:
465 if_freq = 4500000;
466 break;
467 default: /* 8 MHz or Auto */
468 if_freq = 5000000;
469 break;
470 }
471 tuner_freq = params->frequency + if_freq;
472
473 i = 0;
474 while (tda827x_dvbt[i].lomax < tuner_freq) {
475 if(tda827x_dvbt[i + 1].lomax == 0)
476 break;
477 i++;
478 }
479
480 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
481 tuner_buf[0] = 0;
482 tuner_buf[1] = (N>>8) | 0x40;
483 tuner_buf[2] = N & 0xff;
484 tuner_buf[3] = 0;
485 tuner_buf[4] = 0x52;
486 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
487 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
488 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
489 tuner_buf[7] = 0xbf;
490 tuner_buf[8] = 0x2a;
491 tuner_buf[9] = 0x05;
492 tuner_buf[10] = 0xff;
493 tuner_buf[11] = 0x00;
494 tuner_buf[12] = 0x00;
495 tuner_buf[13] = 0x40;
496
497 tuner_msg.len = 14;
498 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
499 return -EIO;
500
501 msleep(500);
502 /* correct CP value */
503 tuner_buf[0] = 0x30;
504 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
505 tuner_msg.len = 2;
506 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
507
508 return 0;
509}
510
511static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
512{
513 struct saa7134_dev *dev = fe->dvb->priv;
514 static u8 tda827x_sleep[] = { 0x30, 0xd0};
515 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
516 .len = sizeof(tda827x_sleep) };
517 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
518}
519
520static struct tda1004x_config tda827x_lifeview_config = {
521 .demod_address = 0x08,
522 .invert = 1,
523 .invert_oclk = 0,
524 .xtal_freq = TDA10046_XTAL_16M,
525 .agc_config = TDA10046_AGC_TDA827X,
526 .if_freq = TDA10046_FREQ_045,
527 .pll_init = philips_tda827x_pll_init,
528 .pll_set = philips_tda827x_pll_set,
529 .pll_sleep = philips_tda827x_pll_sleep,
530 .request_firmware = NULL,
531};
532#endif
533
534/* ------------------------------------------------------------------ */
535
186static int dvb_init(struct saa7134_dev *dev) 536static int dvb_init(struct saa7134_dev *dev)
187{ 537{
188 /* init struct videobuf_dvb */ 538 /* init struct videobuf_dvb */
@@ -197,18 +547,31 @@ static int dvb_init(struct saa7134_dev *dev)
197 dev); 547 dev);
198 548
199 switch (dev->board) { 549 switch (dev->board) {
550#if CONFIG_DVB_MT352
200 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 551 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
201 printk("%s: pinnacle 300i dvb setup\n",dev->name); 552 printk("%s: pinnacle 300i dvb setup\n",dev->name);
202 dev->dvb.frontend = mt352_attach(&pinnacle_300i, 553 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
203 &dev->i2c_adap); 554 &dev->i2c_adap);
204 break; 555 break;
556#endif
557#if CONFIG_DVB_TDA1004X
205 case SAA7134_BOARD_MD7134: 558 case SAA7134_BOARD_MD7134:
206 dev->dvb.frontend = tda10046_attach(&medion_cardbus, 559 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
207 &dev->i2c_adap); 560 &dev->i2c_adap);
208 if (NULL == dev->dvb.frontend)
209 printk("%s: Hmm, looks like this is the old MD7134 "
210 "version without DVB-T support\n",dev->name);
211 break; 561 break;
562 case SAA7134_BOARD_PHILIPS_TOUGH:
563 dev->dvb.frontend = tda10046_attach(&philips_tu1216_config,
564 &dev->i2c_adap);
565 break;
566 case SAA7134_BOARD_FLYDVBTDUO:
567 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
568 &dev->i2c_adap);
569 break;
570 case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
571 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
572 &dev->i2c_adap);
573 break;
574#endif
212 default: 575 default:
213 printk("%s: Huh? unknown DVB card?\n",dev->name); 576 printk("%s: Huh? unknown DVB card?\n",dev->name);
214 break; 577 break;
@@ -227,8 +590,6 @@ static int dvb_fini(struct saa7134_dev *dev)
227{ 590{
228 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE; 591 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
229 592
230 printk("%s: %s\n",dev->name,__FUNCTION__);
231
232 switch (dev->board) { 593 switch (dev->board) {
233 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 594 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
234 /* otherwise we don't detect the tuner on next insmod */ 595 /* otherwise we don't detect the tuner on next insmod */
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index b6f002e8421d..93dd61978541 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-i2c.c,v 1.11 2005/06/12 01:36:14 mchehab Exp $ 2 * $Id: saa7134-i2c.c,v 1.19 2005/07/07 01:49:30 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * i2c interface support 5 * i2c interface support
@@ -197,10 +197,6 @@ static inline int i2c_send_byte(struct saa7134_dev *dev,
197 enum i2c_status status; 197 enum i2c_status status;
198 __u32 dword; 198 __u32 dword;
199 199
200#if 0
201 i2c_set_attr(dev,attr);
202 saa_writeb(SAA7134_I2C_DATA, data);
203#else
204 /* have to write both attr + data in one 32bit word */ 200 /* have to write both attr + data in one 32bit word */
205 dword = saa_readl(SAA7134_I2C_ATTR_STATUS >> 2); 201 dword = saa_readl(SAA7134_I2C_ATTR_STATUS >> 2);
206 dword &= 0x0f; 202 dword &= 0x0f;
@@ -210,7 +206,6 @@ static inline int i2c_send_byte(struct saa7134_dev *dev,
210// dword |= 0x40 << 16; /* 400 kHz */ 206// dword |= 0x40 << 16; /* 400 kHz */
211 dword |= 0xf0 << 24; 207 dword |= 0xf0 << 24;
212 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword); 208 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword);
213#endif
214 d2printk(KERN_DEBUG "%s: i2c data => 0x%x\n",dev->name,data); 209 d2printk(KERN_DEBUG "%s: i2c data => 0x%x\n",dev->name,data);
215 210
216 if (!i2c_is_busy_wait(dev)) 211 if (!i2c_is_busy_wait(dev))
@@ -331,12 +326,44 @@ static u32 functionality(struct i2c_adapter *adap)
331 326
332static int attach_inform(struct i2c_client *client) 327static int attach_inform(struct i2c_client *client)
333{ 328{
334 struct saa7134_dev *dev = client->adapter->algo_data; 329 struct saa7134_dev *dev = client->adapter->algo_data;
335 int tuner = dev->tuner_type; 330 int tuner = dev->tuner_type;
336 int conf = dev->tda9887_conf; 331 int conf = dev->tda9887_conf;
332 struct tuner_setup tun_setup;
333
334 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
335 client->driver->name,client->addr,i2c_clientname(client));
336
337 if (!client->driver->command)
338 return 0;
339
340 if (saa7134_boards[dev->board].radio_type != UNSET) {
341
342 tun_setup.type = saa7134_boards[dev->board].radio_type;
343 tun_setup.addr = saa7134_boards[dev->board].radio_addr;
344
345 if ((tun_setup.addr == ADDR_UNSET) || (tun_setup.addr == client->addr)) {
346 tun_setup.mode_mask = T_RADIO;
347
348 client->driver->command(client, TUNER_SET_TYPE_ADDR, &tun_setup);
349 }
350 }
351
352 if (tuner != UNSET) {
353
354 tun_setup.type = tuner;
355 tun_setup.addr = saa7134_boards[dev->board].tuner_addr;
356
357 if ((tun_setup.addr == ADDR_UNSET)||(tun_setup.addr == client->addr)) {
358
359 tun_setup.mode_mask = T_ANALOG_TV;
360
361 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_setup);
362 }
363 }
364
365 client->driver->command(client, TDA9887_SET_CONFIG, &conf);
337 366
338 saa7134_i2c_call_clients(dev,TUNER_SET_TYPE,&tuner);
339 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&conf);
340 return 0; 367 return 0;
341} 368}
342 369
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index aba2b9de60de..213740122fe6 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-input.c,v 1.19 2005/06/07 18:02:26 nsh Exp $ 2 * $Id: saa7134-input.c,v 1.21 2005/06/22 23:37:34 nsh Exp $
3 * 3 *
4 * handle saa7134 IR remotes via linux kernel input layer. 4 * handle saa7134 IR remotes via linux kernel input layer.
5 * 5 *
@@ -68,10 +68,8 @@ static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
68 [ 6 ] = KEY_AGAIN, // Recal 68 [ 6 ] = KEY_AGAIN, // Recal
69 [ 16 ] = KEY_KPENTER, // Enter 69 [ 16 ] = KEY_KPENTER, // Enter
70 70
71#if 1 /* FIXME */
72 [ 26 ] = KEY_F22, // Stereo 71 [ 26 ] = KEY_F22, // Stereo
73 [ 24 ] = KEY_EDIT, // AV Source 72 [ 24 ] = KEY_EDIT, // AV Source
74#endif
75}; 73};
76 74
77static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = { 75static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
@@ -172,45 +170,45 @@ static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
172}; 170};
173 171
174static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = { 172static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = {
175 [ 30 ] = KEY_POWER, // power 173 [ 30 ] = KEY_POWER, // power
176 [ 28 ] = KEY_SEARCH, // scan 174 [ 28 ] = KEY_SEARCH, // scan
177 [ 7 ] = KEY_SELECT, // source 175 [ 7 ] = KEY_SELECT, // source
178 176
179 [ 22 ] = KEY_VOLUMEUP, 177 [ 22 ] = KEY_VOLUMEUP,
180 [ 20 ] = KEY_VOLUMEDOWN, 178 [ 20 ] = KEY_VOLUMEDOWN,
181 [ 31 ] = KEY_CHANNELUP, 179 [ 31 ] = KEY_CHANNELUP,
182 [ 23 ] = KEY_CHANNELDOWN, 180 [ 23 ] = KEY_CHANNELDOWN,
183 [ 24 ] = KEY_MUTE, 181 [ 24 ] = KEY_MUTE,
184 182
185 [ 2 ] = KEY_KP0, 183 [ 2 ] = KEY_KP0,
186 [ 1 ] = KEY_KP1, 184 [ 1 ] = KEY_KP1,
187 [ 11 ] = KEY_KP2, 185 [ 11 ] = KEY_KP2,
188 [ 27 ] = KEY_KP3, 186 [ 27 ] = KEY_KP3,
189 [ 5 ] = KEY_KP4, 187 [ 5 ] = KEY_KP4,
190 [ 9 ] = KEY_KP5, 188 [ 9 ] = KEY_KP5,
191 [ 21 ] = KEY_KP6, 189 [ 21 ] = KEY_KP6,
192 [ 6 ] = KEY_KP7, 190 [ 6 ] = KEY_KP7,
193 [ 10 ] = KEY_KP8, 191 [ 10 ] = KEY_KP8,
194 [ 18 ] = KEY_KP9, 192 [ 18 ] = KEY_KP9,
195 [ 16 ] = KEY_KPDOT, 193 [ 16 ] = KEY_KPDOT,
196 194
197 [ 3 ] = KEY_TUNER, // tv/fm 195 [ 3 ] = KEY_TUNER, // tv/fm
198 [ 4 ] = KEY_REWIND, // fm tuning left or function left 196 [ 4 ] = KEY_REWIND, // fm tuning left or function left
199 [ 12 ] = KEY_FORWARD, // fm tuning right or function right 197 [ 12 ] = KEY_FORWARD, // fm tuning right or function right
200 198
201 [ 0 ] = KEY_RECORD, 199 [ 0 ] = KEY_RECORD,
202 [ 8 ] = KEY_STOP, 200 [ 8 ] = KEY_STOP,
203 [ 17 ] = KEY_PLAY, 201 [ 17 ] = KEY_PLAY,
204 202
205 [ 25 ] = KEY_ZOOM, 203 [ 25 ] = KEY_ZOOM,
206 [ 14 ] = KEY_MENU, // function 204 [ 14 ] = KEY_MENU, // function
207 [ 19 ] = KEY_AGAIN, // recall 205 [ 19 ] = KEY_AGAIN, // recall
208 [ 29 ] = KEY_RESTART, // reset 206 [ 29 ] = KEY_RESTART, // reset
207 [ 26 ] = KEY_SHUFFLE, // snapshot/shuffle
209 208
210// FIXME 209// FIXME
211 [ 13 ] = KEY_F21, // mts 210 [ 13 ] = KEY_F21, // mts
212 [ 15 ] = KEY_F22, // min 211 [ 15 ] = KEY_F22, // min
213 [ 26 ] = KEY_F23, // freeze
214}; 212};
215 213
216/* Alex Hermann <gaaf@gmx.net> */ 214/* Alex Hermann <gaaf@gmx.net> */
@@ -489,13 +487,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
489 break; 487 break;
490 case SAA7134_BOARD_ECS_TVP3XP: 488 case SAA7134_BOARD_ECS_TVP3XP:
491 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 489 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
492 ir_codes = eztv_codes; 490 ir_codes = eztv_codes;
493 mask_keycode = 0x00017c; 491 mask_keycode = 0x00017c;
494 mask_keyup = 0x000002; 492 mask_keyup = 0x000002;
495 polling = 50; // ms 493 polling = 50; // ms
496 break; 494 break;
495 case SAA7134_BOARD_KWORLD_XPERT:
497 case SAA7134_BOARD_AVACSSMARTTV: 496 case SAA7134_BOARD_AVACSSMARTTV:
498 ir_codes = avacssmart_codes; 497 ir_codes = avacssmart_codes;
499 mask_keycode = 0x00001F; 498 mask_keycode = 0x00001F;
500 mask_keyup = 0x000020; 499 mask_keyup = 0x000020;
501 polling = 50; // ms 500 polling = 50; // ms
@@ -524,6 +523,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
524 polling = 50; // ms 523 polling = 50; // ms
525 break; 524 break;
526 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 525 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
526 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
527 ir_codes = videomate_tv_pvr_codes; 527 ir_codes = videomate_tv_pvr_codes;
528 mask_keycode = 0x00003F; 528 mask_keycode = 0x00003F;
529 mask_keyup = 0x400000; 529 mask_keyup = 0x400000;
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 81732904623f..b5bede95dbf5 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-oss.c,v 1.14 2005/05/18 22:45:16 hhackmann Exp $ 2 * $Id: saa7134-oss.c,v 1.17 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * oss dsp interface 5 * oss dsp interface
@@ -556,21 +556,28 @@ mixer_recsrc_7134(struct saa7134_dev *dev)
556static int 556static int
557mixer_recsrc_7133(struct saa7134_dev *dev) 557mixer_recsrc_7133(struct saa7134_dev *dev)
558{ 558{
559 u32 value = 0xbbbbbb; 559 u32 anabar, xbarin;
560 560
561 xbarin = 0x03; // adc
562 anabar = 0;
561 switch (dev->oss.input) { 563 switch (dev->oss.input) {
562 case TV: 564 case TV:
563 value = 0xbbbb10; /* MAIN */ 565 xbarin = 0; // Demodulator
566 anabar = 2; // DACs
564 break; 567 break;
565 case LINE1: 568 case LINE1:
566 value = 0xbbbb32; /* AUX1 */ 569 anabar = 0; // aux1, aux1
567 break; 570 break;
568 case LINE2: 571 case LINE2:
569 case LINE2_LEFT: 572 case LINE2_LEFT:
570 value = 0xbbbb54; /* AUX2 */ 573 anabar = 9; // aux2, aux2
571 break; 574 break;
572 } 575 }
573 saa_dsp_writel(dev, 0x46c >> 2, value); 576 /* output xbar always main channel */
577 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
578 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
579 saa_writel(0x594 >> 2, anabar);
580
574 return 0; 581 return 0;
575} 582}
576 583
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 345eb2a8c28d..4dd9f1b23928 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-ts.c,v 1.14 2005/02/03 10:24:33 kraxel Exp $ 2 * $Id: saa7134-ts.c,v 1.15 2005/06/14 22:48:18 hhackmann Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -221,10 +221,10 @@ void saa7134_irq_ts_done(struct saa7134_dev *dev, unsigned long status)
221 if (dev->ts_q.curr) { 221 if (dev->ts_q.curr) {
222 field = dev->ts_q.curr->vb.field; 222 field = dev->ts_q.curr->vb.field;
223 if (field == V4L2_FIELD_TOP) { 223 if (field == V4L2_FIELD_TOP) {
224 if ((status & 0x100000) != 0x000000) 224 if ((status & 0x100000) != 0x100000)
225 goto done; 225 goto done;
226 } else { 226 } else {
227 if ((status & 0x100000) != 0x100000) 227 if ((status & 0x100000) != 0x000000)
228 goto done; 228 goto done;
229 } 229 }
230 saa7134_buffer_finish(dev,&dev->ts_q,STATE_DONE); 230 saa7134_buffer_finish(dev,&dev->ts_q,STATE_DONE);
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 3617e7f7a410..eeafa5a71d2b 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-tvaudio.c,v 1.25 2005/06/07 19:00:38 nsh Exp $ 2 * $Id: saa7134-tvaudio.c,v 1.30 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * tv audio decoder (fm stereo, nicam, ...) 5 * tv audio decoder (fm stereo, nicam, ...)
@@ -169,7 +169,7 @@ static void tvaudio_init(struct saa7134_dev *dev)
169 int clock = saa7134_boards[dev->board].audio_clock; 169 int clock = saa7134_boards[dev->board].audio_clock;
170 170
171 if (UNSET != audio_clock_override) 171 if (UNSET != audio_clock_override)
172 clock = audio_clock_override; 172 clock = audio_clock_override;
173 173
174 /* init all audio registers */ 174 /* init all audio registers */
175 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00); 175 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
@@ -219,14 +219,17 @@ static void mute_input_7134(struct saa7134_dev *dev)
219 in = dev->input; 219 in = dev->input;
220 mute = (dev->ctl_mute || 220 mute = (dev->ctl_mute ||
221 (dev->automute && (&card(dev).radio) != in)); 221 (dev->automute && (&card(dev).radio) != in));
222 if (PCI_DEVICE_ID_PHILIPS_SAA7130 == dev->pci->device && 222 if (card(dev).mute.name) {
223 card(dev).mute.name) { 223 /*
224 /* 7130 - we'll mute using some unconnected audio input */ 224 * 7130 - we'll mute using some unconnected audio input
225 * 7134 - we'll probably should switch external mux with gpio
226 */
225 if (mute) 227 if (mute)
226 in = &card(dev).mute; 228 in = &card(dev).mute;
227 } 229 }
230
228 if (dev->hw_mute == mute && 231 if (dev->hw_mute == mute &&
229 dev->hw_input == in) { 232 dev->hw_input == in) {
230 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n", 233 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n",
231 mute,in->name); 234 mute,in->name);
232 return; 235 return;
@@ -260,6 +263,7 @@ static void mute_input_7134(struct saa7134_dev *dev)
260 /* switch gpio-connected external audio mux */ 263 /* switch gpio-connected external audio mux */
261 if (0 == card(dev).gpiomask) 264 if (0 == card(dev).gpiomask)
262 return; 265 return;
266
263 mask = card(dev).gpiomask; 267 mask = card(dev).gpiomask;
264 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask); 268 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
265 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio); 269 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio);
@@ -339,13 +343,8 @@ static int tvaudio_sleep(struct saa7134_dev *dev, int timeout)
339 set_current_state(TASK_INTERRUPTIBLE); 343 set_current_state(TASK_INTERRUPTIBLE);
340 schedule(); 344 schedule();
341 } else { 345 } else {
342#if 0
343 /* hmm, that one doesn't return on wakeup ... */
344 msleep_interruptible(timeout);
345#else
346 set_current_state(TASK_INTERRUPTIBLE); 346 set_current_state(TASK_INTERRUPTIBLE);
347 schedule_timeout(msecs_to_jiffies(timeout)); 347 schedule_timeout(msecs_to_jiffies(timeout));
348#endif
349 } 348 }
350 } 349 }
351 remove_wait_queue(&dev->thread.wq, &wait); 350 remove_wait_queue(&dev->thread.wq, &wait);
@@ -400,27 +399,10 @@ static int tvaudio_checkcarrier(struct saa7134_dev *dev, struct mainscan *scan)
400 return value; 399 return value;
401} 400}
402 401
403#if 0
404static void sifdebug_dump_regs(struct saa7134_dev *dev)
405{
406 print_regb(AUDIO_STATUS);
407 print_regb(IDENT_SIF);
408 print_regb(LEVEL_READOUT1);
409 print_regb(LEVEL_READOUT2);
410 print_regb(DCXO_IDENT_CTRL);
411 print_regb(DEMODULATOR);
412 print_regb(AGC_GAIN_SELECT);
413 print_regb(MONITOR_SELECT);
414 print_regb(FM_DEEMPHASIS);
415 print_regb(FM_DEMATRIX);
416 print_regb(SIF_SAMPLE_FREQ);
417 print_regb(ANALOG_IO_SELECT);
418}
419#endif
420 402
421static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *audio) 403static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *audio)
422{ 404{
423 __u32 idp,nicam; 405 __u32 idp, nicam, nicam_status;
424 int retval = -1; 406 int retval = -1;
425 407
426 switch (audio->mode) { 408 switch (audio->mode) {
@@ -442,18 +424,24 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
442 break; 424 break;
443 case TVAUDIO_NICAM_FM: 425 case TVAUDIO_NICAM_FM:
444 case TVAUDIO_NICAM_AM: 426 case TVAUDIO_NICAM_AM:
445 nicam = saa_readb(SAA7134_NICAM_STATUS); 427 nicam = saa_readb(SAA7134_AUDIO_STATUS);
446 dprintk("getstereo: nicam=0x%x\n",nicam); 428 dprintk("getstereo: nicam=0x%x\n",nicam);
447 switch (nicam & 0x0b) { 429 if (nicam & 0x1) {
448 case 0x08: 430 nicam_status = saa_readb(SAA7134_NICAM_STATUS);
449 retval = V4L2_TUNER_SUB_MONO; 431 dprintk("getstereo: nicam_status=0x%x\n", nicam_status);
450 break; 432
451 case 0x09: 433 switch (nicam_status & 0x03) {
452 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 434 case 0x01:
453 break; 435 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
454 case 0x0a: 436 break;
455 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 437 case 0x02:
456 break; 438 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
439 break;
440 default:
441 retval = V4L2_TUNER_SUB_MONO;
442 }
443 } else {
444 /* No nicam detected */
457 } 445 }
458 break; 446 break;
459 } 447 }
@@ -489,15 +477,15 @@ static int tvaudio_setstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
489 break; 477 break;
490 case TVAUDIO_FM_K_STEREO: 478 case TVAUDIO_FM_K_STEREO:
491 case TVAUDIO_FM_BG_STEREO: 479 case TVAUDIO_FM_BG_STEREO:
480 case TVAUDIO_NICAM_AM:
481 case TVAUDIO_NICAM_FM:
492 dprintk("setstereo [fm] => %s\n", 482 dprintk("setstereo [fm] => %s\n",
493 name[ mode % ARRAY_SIZE(name) ]); 483 name[ mode % ARRAY_SIZE(name) ]);
494 reg = fm[ mode % ARRAY_SIZE(fm) ]; 484 reg = fm[ mode % ARRAY_SIZE(fm) ];
495 saa_writeb(SAA7134_FM_DEMATRIX, reg); 485 saa_writeb(SAA7134_FM_DEMATRIX, reg);
496 break; 486 break;
497 case TVAUDIO_FM_SAT_STEREO: 487 case TVAUDIO_FM_SAT_STEREO:
498 case TVAUDIO_NICAM_AM: 488 /* Not implemented */
499 case TVAUDIO_NICAM_FM:
500 /* FIXME */
501 break; 489 break;
502 } 490 }
503 return 0; 491 return 0;
@@ -596,7 +584,7 @@ static int tvaudio_thread(void *data)
596 /* find the exact tv audio norm */ 584 /* find the exact tv audio norm */
597 for (audio = UNSET, i = 0; i < TVAUDIO; i++) { 585 for (audio = UNSET, i = 0; i < TVAUDIO; i++) {
598 if (dev->tvnorm->id != UNSET && 586 if (dev->tvnorm->id != UNSET &&
599 !(dev->tvnorm->id & tvaudio[i].std)) 587 !(dev->tvnorm->id & tvaudio[i].std))
600 continue; 588 continue;
601 if (tvaudio[i].carr1 != carrier) 589 if (tvaudio[i].carr1 != carrier)
602 continue; 590 continue;
@@ -703,24 +691,6 @@ static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit)
703 return 0; 691 return 0;
704} 692}
705 693
706#if 0
707static int saa_dsp_readl(struct saa7134_dev *dev, int reg, u32 *value)
708{
709 int err;
710
711 d2printk("dsp read reg 0x%x\n", reg<<2);
712 saa_readl(reg);
713 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_RDB);
714 if (err < 0)
715 return err;
716 *value = saa_readl(reg);
717 d2printk("dsp read => 0x%06x\n", *value & 0xffffff);
718 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_IDA);
719 if (err < 0)
720 return err;
721 return 0;
722}
723#endif
724 694
725int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value) 695int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value)
726{ 696{
@@ -753,31 +723,50 @@ static int getstereo_7133(struct saa7134_dev *dev)
753static int mute_input_7133(struct saa7134_dev *dev) 723static int mute_input_7133(struct saa7134_dev *dev)
754{ 724{
755 u32 reg = 0; 725 u32 reg = 0;
726 u32 xbarin, xbarout;
756 int mask; 727 int mask;
728 struct saa7134_input *in;
757 729
730 /* Hac 0506 route OSS sound simultanously */
731 xbarin = 0x03;
758 switch (dev->input->amux) { 732 switch (dev->input->amux) {
759 case TV: 733 case TV:
760 reg = 0x02; 734 reg = 0x02;
735 xbarin = 0;
761 break; 736 break;
762 case LINE1: 737 case LINE1:
763 reg = 0x00; 738 reg = 0x00;
764 break; 739 break;
765 case LINE2: 740 case LINE2:
766 case LINE2_LEFT: 741 case LINE2_LEFT:
767 reg = 0x01; 742 reg = 0x09;
768 break; 743 break;
769 } 744 }
770 if (dev->ctl_mute) 745 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
746 if (dev->ctl_mute) {
771 reg = 0x07; 747 reg = 0x07;
748 xbarout = 0xbbbbbb;
749 } else
750 xbarout = 0xbbbb10;
751 saa_dsp_writel(dev, 0x46c >> 2, xbarout);
752
772 saa_writel(0x594 >> 2, reg); 753 saa_writel(0x594 >> 2, reg);
773 754
755
774 /* switch gpio-connected external audio mux */ 756 /* switch gpio-connected external audio mux */
775 if (0 != card(dev).gpiomask) { 757 if (0 != card(dev).gpiomask) {
776 mask = card(dev).gpiomask; 758 mask = card(dev).gpiomask;
759
760 if (card(dev).mute.name && dev->ctl_mute)
761 in = &card(dev).mute;
762 else
763 in = dev->input;
764
777 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask); 765 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
778 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, dev->input->gpio); 766 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio);
779 saa7134_track_gpio(dev,dev->input->name); 767 saa7134_track_gpio(dev,in->name);
780 } 768 }
769
781 return 0; 770 return 0;
782} 771}
783 772
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index 3c33c591cc85..29e51cad2aaf 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -130,13 +130,7 @@ static int buffer_prepare(struct videobuf_queue *q,
130 lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1; 130 lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
131 if (lines > VBI_LINE_COUNT) 131 if (lines > VBI_LINE_COUNT)
132 lines = VBI_LINE_COUNT; 132 lines = VBI_LINE_COUNT;
133#if 1
134 llength = VBI_LINE_LENGTH; 133 llength = VBI_LINE_LENGTH;
135#else
136 llength = (norm->h_stop - norm->h_start +1) * 2;
137 if (llength > VBI_LINE_LENGTH)
138 llength = VBI_LINE_LENGTH;
139#endif
140 size = lines * llength * 2; 134 size = lines * llength * 2;
141 if (0 != buf->vb.baddr && buf->vb.bsize < size) 135 if (0 != buf->vb.baddr && buf->vb.bsize < size)
142 return -EINVAL; 136 return -EINVAL;
@@ -178,13 +172,7 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
178 int llength,lines; 172 int llength,lines;
179 173
180 lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1; 174 lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1;
181#if 1
182 llength = VBI_LINE_LENGTH; 175 llength = VBI_LINE_LENGTH;
183#else
184 llength = (norm->h_stop - norm->h_start +1) * 2;
185 if (llength > VBI_LINE_LENGTH)
186 llength = VBI_LINE_LENGTH;
187#endif
188 *size = lines * llength * 2; 176 *size = lines * llength * 2;
189 if (0 == *count) 177 if (0 == *count)
190 *count = vbibufs; 178 *count = vbibufs;
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index c0a2ee520531..a4c2f751d097 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-video.c,v 1.30 2005/06/07 19:00:38 nsh Exp $ 2 * $Id: saa7134-video.c,v 1.36 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -274,7 +274,7 @@ static struct saa7134_tvnorm tvnorms[] = {
274 274
275 .h_start = 0, 275 .h_start = 0,
276 .h_stop = 719, 276 .h_stop = 719,
277 .video_v_start = 23, 277 .video_v_start = 23,
278 .video_v_stop = 262, 278 .video_v_stop = 262,
279 .vbi_v_start_0 = 10, 279 .vbi_v_start_0 = 10,
280 .vbi_v_stop_0 = 21, 280 .vbi_v_stop_0 = 21,
@@ -1204,7 +1204,6 @@ static int video_open(struct inode *inode, struct file *file)
1204 struct list_head *list; 1204 struct list_head *list;
1205 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1205 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1206 int radio = 0; 1206 int radio = 0;
1207
1208 list_for_each(list,&saa7134_devlist) { 1207 list_for_each(list,&saa7134_devlist) {
1209 h = list_entry(list, struct saa7134_dev, devlist); 1208 h = list_entry(list, struct saa7134_dev, devlist);
1210 if (h->video_dev && (h->video_dev->minor == minor)) 1209 if (h->video_dev && (h->video_dev->minor == minor))
@@ -1256,12 +1255,12 @@ static int video_open(struct inode *inode, struct file *file)
1256 if (fh->radio) { 1255 if (fh->radio) {
1257 /* switch to radio mode */ 1256 /* switch to radio mode */
1258 saa7134_tvaudio_setinput(dev,&card(dev).radio); 1257 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1259 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO,NULL); 1258 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO, NULL);
1260 } else { 1259 } else {
1261 /* switch to video/vbi mode */ 1260 /* switch to video/vbi mode */
1262 video_mux(dev,dev->ctl_input); 1261 video_mux(dev,dev->ctl_input);
1263 } 1262 }
1264 return 0; 1263 return 0;
1265} 1264}
1266 1265
1267static ssize_t 1266static ssize_t
@@ -1304,10 +1303,10 @@ video_poll(struct file *file, struct poll_table_struct *wait)
1304 } else { 1303 } else {
1305 down(&fh->cap.lock); 1304 down(&fh->cap.lock);
1306 if (UNSET == fh->cap.read_off) { 1305 if (UNSET == fh->cap.read_off) {
1307 /* need to capture a new frame */ 1306 /* need to capture a new frame */
1308 if (res_locked(fh->dev,RESOURCE_VIDEO)) { 1307 if (res_locked(fh->dev,RESOURCE_VIDEO)) {
1309 up(&fh->cap.lock); 1308 up(&fh->cap.lock);
1310 return POLLERR; 1309 return POLLERR;
1311 } 1310 }
1312 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) { 1311 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) {
1313 up(&fh->cap.lock); 1312 up(&fh->cap.lock);
@@ -1363,6 +1362,36 @@ static int video_release(struct inode *inode, struct file *file)
1363 res_free(dev,fh,RESOURCE_VBI); 1362 res_free(dev,fh,RESOURCE_VBI);
1364 } 1363 }
1365 1364
1365 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1366 saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0);
1367 saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0);
1368 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1369 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1370
1371 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) {
1372 u8 data[2];
1373 int ret;
1374 struct i2c_msg msg = {.addr=I2C_ADDR_TDA8290, .flags=0, .buf=data, .len = 2};
1375 data[0] = 0x21;
1376 data[1] = 0xc0;
1377 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1378 if (ret != 1)
1379 printk(KERN_ERR "TDA8290 access failure\n");
1380 msg.addr = I2C_ADDR_TDA8275;
1381 data[0] = 0x30;
1382 data[1] = 0xd0;
1383 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1384 if (ret != 1)
1385 printk(KERN_ERR "TDA8275 access failure\n");
1386 msg.addr = I2C_ADDR_TDA8290;
1387 data[0] = 0x21;
1388 data[1] = 0x80;
1389 i2c_transfer(&dev->i2c_adap, &msg, 1);
1390 data[0] = 0x00;
1391 data[1] = 0x02;
1392 i2c_transfer(&dev->i2c_adap, &msg, 1);
1393 }
1394
1366 /* free stuff */ 1395 /* free stuff */
1367 videobuf_mmap_free(&fh->cap); 1396 videobuf_mmap_free(&fh->cap);
1368 videobuf_mmap_free(&fh->vbi); 1397 videobuf_mmap_free(&fh->vbi);
@@ -1399,13 +1428,6 @@ static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
1399 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1428 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1400 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */ 1429 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1401 1430
1402#if 0
1403 if (V4L2_STD_PAL == norm->id) {
1404 /* FIXME */
1405 f->fmt.vbi.start[0] += 3;
1406 f->fmt.vbi.start[1] += 3*2;
1407 }
1408#endif
1409} 1431}
1410 1432
1411static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh, 1433static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
@@ -2120,8 +2142,6 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
2120 2142
2121 memset(t,0,sizeof(*t)); 2143 memset(t,0,sizeof(*t));
2122 strcpy(t->name, "Radio"); 2144 strcpy(t->name, "Radio");
2123 t->rangelow = (int)(65*16);
2124 t->rangehigh = (int)(108*16);
2125 2145
2126 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t); 2146 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
2127 2147
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index d6b1c0d4d0f9..6836c07794fc 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134.h,v 1.41 2005/06/07 18:02:26 nsh Exp $ 2 * $Id: saa7134.h,v 1.48 2005/07/01 08:22:24 nsh Exp $
3 * 3 *
4 * v4l2 device driver for philips saa7134 based TV cards 4 * v4l2 device driver for philips saa7134 based TV cards
5 * 5 *
@@ -46,8 +46,6 @@
46#endif 46#endif
47#define UNSET (-1U) 47#define UNSET (-1U)
48 48
49/* 2.4 / 2.5 driver compatibility stuff */
50
51/* ----------------------------------------------------------- */ 49/* ----------------------------------------------------------- */
52/* enums */ 50/* enums */
53 51
@@ -159,7 +157,7 @@ struct saa7134_format {
159#define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33 157#define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33
160#define SAA7134_BOARD_NOVAC_PRIMETV7133 34 158#define SAA7134_BOARD_NOVAC_PRIMETV7133 34
161#define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35 159#define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35
162#define SAA7133_BOARD_UPMOST_PURPLE_TV 36 160#define SAA7134_BOARD_UPMOST_PURPLE_TV 36
163#define SAA7134_BOARD_ITEMS_MTV005 37 161#define SAA7134_BOARD_ITEMS_MTV005 37
164#define SAA7134_BOARD_CINERGY200 38 162#define SAA7134_BOARD_CINERGY200 38
165#define SAA7134_BOARD_FLYTVPLATINUM_MINI 39 163#define SAA7134_BOARD_FLYTVPLATINUM_MINI 39
@@ -176,13 +174,17 @@ struct saa7134_format {
176#define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50 174#define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50
177#define SAA7134_BOARD_PROVIDEO_PV952 51 175#define SAA7134_BOARD_PROVIDEO_PV952 51
178#define SAA7134_BOARD_AVERMEDIA_305 52 176#define SAA7134_BOARD_AVERMEDIA_305 52
179#define SAA7135_BOARD_ASUSTeK_TVFM7135 53 177#define SAA7134_BOARD_ASUSTeK_TVFM7135 53
180#define SAA7134_BOARD_FLYTVPLATINUM_FM 54 178#define SAA7134_BOARD_FLYTVPLATINUM_FM 54
181#define SAA7134_BOARD_FLYDVBTDUO 55 179#define SAA7134_BOARD_FLYDVBTDUO 55
182#define SAA7134_BOARD_AVERMEDIA_307 56 180#define SAA7134_BOARD_AVERMEDIA_307 56
183#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57 181#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57
184#define SAA7134_BOARD_ADS_INSTANT_TV 58 182#define SAA7134_BOARD_ADS_INSTANT_TV 58
185#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59 183#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59
184#define SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS 60
185#define SAA7134_BOARD_PHILIPS_TOUGH 61
186#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62
187#define SAA7134_BOARD_KWORLD_XPERT 63
186 188
187#define SAA7134_MAXBOARDS 8 189#define SAA7134_MAXBOARDS 8
188#define SAA7134_INPUT_MAX 8 190#define SAA7134_INPUT_MAX 8
@@ -213,6 +215,10 @@ struct saa7134_board {
213 215
214 /* i2c chip info */ 216 /* i2c chip info */
215 unsigned int tuner_type; 217 unsigned int tuner_type;
218 unsigned int radio_type;
219 unsigned char tuner_addr;
220 unsigned char radio_addr;
221
216 unsigned int tda9887_conf; 222 unsigned int tda9887_conf;
217 223
218 /* peripheral I/O */ 224 /* peripheral I/O */
@@ -403,9 +409,12 @@ struct saa7134_dev {
403 /* config info */ 409 /* config info */
404 unsigned int board; 410 unsigned int board;
405 unsigned int tuner_type; 411 unsigned int tuner_type;
412 unsigned int radio_type;
413 unsigned char tuner_addr;
414 unsigned char radio_addr;
415
406 unsigned int tda9887_conf; 416 unsigned int tda9887_conf;
407 unsigned int gpio_value; 417 unsigned int gpio_value;
408 unsigned int irq2_mask;
409 418
410 /* i2c i/o */ 419 /* i2c i/o */
411 struct i2c_adapter i2c_adap; 420 struct i2c_adapter i2c_adap;
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 07ba6d3ed08c..7cb1fb3e66f9 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -243,19 +243,6 @@ static int tda7432_write(struct i2c_client *client, int subaddr, int val)
243} 243}
244 244
245/* I don't think we ever actually _read_ the chip... */ 245/* I don't think we ever actually _read_ the chip... */
246#if 0
247static int tda7432_read(struct i2c_client *client)
248{
249 unsigned char buffer;
250 d2printk("tda7432: In tda7432_read\n");
251 if (1 != i2c_master_recv(client,&buffer,1)) {
252 printk(KERN_WARNING "tda7432: I/O error, trying (read)\n");
253 return -1;
254 }
255 dprintk("tda7432: Read 0x%02x\n", buffer);
256 return buffer;
257}
258#endif
259 246
260static int tda7432_set(struct i2c_client *client) 247static int tda7432_set(struct i2c_client *client)
261{ 248{
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index b27cc348d95c..a8b6a8df5109 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tda8290.c,v 1.7 2005/03/07 12:01:51 kraxel Exp $ 2 * $Id: tda8290.c,v 1.15 2005/07/08 20:21:33 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls the philips tda8290+75 tuner chip combo. 5 * controls the philips tda8290+75 tuner chip combo.
@@ -69,7 +69,7 @@ static __u8 get_freq_entry( struct freq_entry* table, __u16 freq)
69static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 }; 69static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 };
70static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 }; 70static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 };
71static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00, 71static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
72 0x7C, 0x04, 0xA3, 0x3F, 72 0xfC, 0x04, 0xA3, 0x3F,
73 0x2A, 0x04, 0xFF, 0x00, 73 0x2A, 0x04, 0xFF, 0x00,
74 0x00, 0x40 }; 74 0x00, 0x40 };
75static unsigned char i2c_set_VS[2] = { 0x30, 0x6F }; 75static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
@@ -136,18 +136,23 @@ static int tda8290_tune(struct i2c_client *c)
136 return 0; 136 return 0;
137} 137}
138 138
139static void set_frequency(struct tuner *t, u16 ifc) 139static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq)
140{ 140{
141 u32 N = (((t->freq<<3)+ifc)&0x3fffc); 141 u32 N;
142 142
143 N = N >> get_freq_entry(div_table, t->freq); 143 if (t->mode == V4L2_TUNER_RADIO)
144 freq = freq / 1000;
145
146 N = (((freq<<3)+ifc)&0x3fffc);
147
148 N = N >> get_freq_entry(div_table, freq);
144 t->i2c_set_freq[0] = 0; 149 t->i2c_set_freq[0] = 0;
145 t->i2c_set_freq[1] = (unsigned char)(N>>8); 150 t->i2c_set_freq[1] = (unsigned char)(N>>8);
146 t->i2c_set_freq[2] = (unsigned char) N; 151 t->i2c_set_freq[2] = (unsigned char) N;
147 t->i2c_set_freq[3] = 0x40; 152 t->i2c_set_freq[3] = 0x40;
148 t->i2c_set_freq[4] = 0x52; 153 t->i2c_set_freq[4] = 0x52;
149 t->i2c_set_freq[5] = get_freq_entry(band_table, t->freq); 154 t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
150 t->i2c_set_freq[6] = get_freq_entry(agc_table, t->freq); 155 t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
151 t->i2c_set_freq[7] = 0x8f; 156 t->i2c_set_freq[7] = 0x8f;
152} 157}
153 158
@@ -179,14 +184,14 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
179 struct tuner *t = i2c_get_clientdata(c); 184 struct tuner *t = i2c_get_clientdata(c);
180 185
181 set_audio(t); 186 set_audio(t);
182 set_frequency(t, 864); 187 set_frequency(t, 864, freq);
183 tda8290_tune(c); 188 tda8290_tune(c);
184} 189}
185 190
186static void set_radio_freq(struct i2c_client *c, unsigned int freq) 191static void set_radio_freq(struct i2c_client *c, unsigned int freq)
187{ 192{
188 struct tuner *t = i2c_get_clientdata(c); 193 struct tuner *t = i2c_get_clientdata(c);
189 set_frequency(t, 704); 194 set_frequency(t, 704, freq);
190 tda8290_tune(c); 195 tda8290_tune(c);
191} 196}
192 197
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 97b113e070f3..566e1a5ca135 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -123,19 +123,6 @@ static int tda9875_write(struct i2c_client *client, int subaddr, unsigned char v
123 return 0; 123 return 0;
124} 124}
125 125
126#if 0
127static int tda9875_read(struct i2c_client *client)
128{
129 unsigned char buffer;
130 dprintk("In tda9875_read\n");
131 if (1 != i2c_master_recv(client,&buffer,1)) {
132 printk(KERN_WARNING "tda9875: I/O error, trying (read)\n");
133 return -1;
134 }
135 dprintk("Read 0x%02x\n", buffer);
136 return buffer;
137}
138#endif
139 126
140static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg) 127static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg)
141{ 128{
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 39773633cc3c..108c3ad7d622 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -368,7 +368,7 @@ static int tda9887_set_tvnorm(struct tda9887 *t, char *buf)
368 if (t->radio_mode == V4L2_TUNER_MODE_MONO) 368 if (t->radio_mode == V4L2_TUNER_MODE_MONO)
369 norm = &radio_mono; 369 norm = &radio_mono;
370 else 370 else
371 norm = &radio_stereo; 371 norm = &radio_stereo;
372 } else { 372 } else {
373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) { 373 for (i = 0; i < ARRAY_SIZE(tvnorms); i++) {
374 if (tvnorms[i].std & t->std) { 374 if (tvnorms[i].std & t->std) {
@@ -566,19 +566,9 @@ static int tda9887_configure(struct tda9887 *t)
566 if (UNSET != t->pinnacle_id) { 566 if (UNSET != t->pinnacle_id) {
567 tda9887_set_pinnacle(t,buf); 567 tda9887_set_pinnacle(t,buf);
568 } 568 }
569
570 tda9887_set_config(t,buf); 569 tda9887_set_config(t,buf);
571 tda9887_set_insmod(t,buf); 570 tda9887_set_insmod(t,buf);
572 571
573#if 0
574 /* This as-is breaks some cards, must be fixed in a
575 * card-specific way, probably using TDA9887_SET_CONFIG to
576 * turn on/off port2 */
577 if (t->std & V4L2_STD_SECAM_L) {
578 /* secam fixup (FIXME: move this to tvnorms array?) */
579 buf[1] &= ~cOutputPort2Inactive;
580 }
581#endif
582 572
583 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n", 573 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n",
584 buf[1],buf[2],buf[3]); 574 buf[1],buf[2],buf[3]);
@@ -615,8 +605,8 @@ static int tda9887_attach(struct i2c_adapter *adap, int addr, int kind)
615 t->pinnacle_id = UNSET; 605 t->pinnacle_id = UNSET;
616 t->radio_mode = V4L2_TUNER_MODE_STEREO; 606 t->radio_mode = V4L2_TUNER_MODE_STEREO;
617 607
618 i2c_set_clientdata(&t->client, t); 608 i2c_set_clientdata(&t->client, t);
619 i2c_attach_client(&t->client); 609 i2c_attach_client(&t->client);
620 610
621 return 0; 611 return 0;
622} 612}
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
new file mode 100644
index 000000000000..4d27ac1b7fb8
--- /dev/null
+++ b/drivers/media/video/tea5767.c
@@ -0,0 +1,342 @@
1/*
2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
3 * I2C address is allways 0xC0.
4 *
5 * $Id: tea5767.c,v 1.21 2005/07/14 03:06:43 mchehab Exp $
6 *
7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
8 * This code is placed under the terms of the GNU General Public License
9 *
10 * tea5767 autodetection thanks to Torsten Seeboth and Atsushi Nakagawa
11 * from their contributions on DScaler.
12 */
13
14#include <linux/i2c.h>
15#include <linux/videodev.h>
16#include <linux/delay.h>
17#include <media/tuner.h>
18#include <media/tuner.h>
19
20#define PREFIX "TEA5767 "
21
22/*****************************************************************************/
23
24/******************************
25 * Write mode register values *
26 ******************************/
27
28/* First register */
29#define TEA5767_MUTE 0x80 /* Mutes output */
30#define TEA5767_SEARCH 0x40 /* Activates station search */
31/* Bits 0-5 for divider MSB */
32
33/* Second register */
34/* Bits 0-7 for divider LSB */
35
36/* Third register */
37
38/* Station search from botton to up */
39#define TEA5767_SEARCH_UP 0x80
40
41/* Searches with ADC output = 10 */
42#define TEA5767_SRCH_HIGH_LVL 0x60
43
44/* Searches with ADC output = 10 */
45#define TEA5767_SRCH_MID_LVL 0x40
46
47/* Searches with ADC output = 5 */
48#define TEA5767_SRCH_LOW_LVL 0x20
49
50/* if on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq) */
51#define TEA5767_HIGH_LO_INJECT 0x10
52
53/* Disable stereo */
54#define TEA5767_MONO 0x08
55
56/* Disable right channel and turns to mono */
57#define TEA5767_MUTE_RIGHT 0x04
58
59/* Disable left channel and turns to mono */
60#define TEA5767_MUTE_LEFT 0x02
61
62#define TEA5767_PORT1_HIGH 0x01
63
64/* Forth register */
65#define TEA5767_PORT2_HIGH 0x80
66/* Chips stops working. Only I2C bus remains on */
67#define TEA5767_STDBY 0x40
68
69/* Japan freq (76-108 MHz. If disabled, 87.5-108 MHz */
70#define TEA5767_JAPAN_BAND 0x20
71
72/* Unselected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz */
73#define TEA5767_XTAL_32768 0x10
74
75/* Cuts weak signals */
76#define TEA5767_SOFT_MUTE 0x08
77
78/* Activates high cut control */
79#define TEA5767_HIGH_CUT_CTRL 0x04
80
81/* Activates stereo noise control */
82#define TEA5767_ST_NOISE_CTL 0x02
83
84/* If activate PORT 1 indicates SEARCH or else it is used as PORT1 */
85#define TEA5767_SRCH_IND 0x01
86
87/* Fiveth register */
88
89/* By activating, it will use Xtal at 13 MHz as reference for divider */
90#define TEA5767_PLLREF_ENABLE 0x80
91
92/* By activating, deemphasis=50, or else, deemphasis of 50us */
93#define TEA5767_DEEMPH_75 0X40
94
95/*****************************
96 * Read mode register values *
97 *****************************/
98
99/* First register */
100#define TEA5767_READY_FLAG_MASK 0x80
101#define TEA5767_BAND_LIMIT_MASK 0X40
102/* Bits 0-5 for divider MSB after search or preset */
103
104/* Second register */
105/* Bits 0-7 for divider LSB after search or preset */
106
107/* Third register */
108#define TEA5767_STEREO_MASK 0x80
109#define TEA5767_IF_CNTR_MASK 0x7f
110
111/* Four register */
112#define TEA5767_ADC_LEVEL_MASK 0xf0
113
114/* should be 0 */
115#define TEA5767_CHIP_ID_MASK 0x0f
116
117/* Fiveth register */
118/* Reserved for future extensions */
119#define TEA5767_RESERVED_MASK 0xff
120
121enum tea5767_xtal_freq {
122 TEA5767_LOW_LO_32768 = 0,
123 TEA5767_HIGH_LO_32768 = 1,
124 TEA5767_LOW_LO_13MHz = 2,
125 TEA5767_HIGH_LO_13MHz = 3,
126};
127
128
129/*****************************************************************************/
130
131static void set_tv_freq(struct i2c_client *c, unsigned int freq)
132{
133 struct tuner *t = i2c_get_clientdata(c);
134
135 tuner_warn("This tuner doesn't support TV freq.\n");
136}
137
138static void tea5767_status_dump(unsigned char *buffer)
139{
140 unsigned int div, frq;
141
142 if (TEA5767_READY_FLAG_MASK & buffer[0])
143 printk(PREFIX "Ready Flag ON\n");
144 else
145 printk(PREFIX "Ready Flag OFF\n");
146
147 if (TEA5767_BAND_LIMIT_MASK & buffer[0])
148 printk(PREFIX "Tuner at band limit\n");
149 else
150 printk(PREFIX "Tuner not at band limit\n");
151
152 div = ((buffer[0] & 0x3f) << 8) | buffer[1];
153
154 switch (TEA5767_HIGH_LO_32768) {
155 case TEA5767_HIGH_LO_13MHz:
156 frq = (div * 50000 - 700000 - 225000) / 4; /* Freq in KHz */
157 break;
158 case TEA5767_LOW_LO_13MHz:
159 frq = (div * 50000 + 700000 + 225000) / 4; /* Freq in KHz */
160 break;
161 case TEA5767_LOW_LO_32768:
162 frq = (div * 32768 + 700000 + 225000) / 4; /* Freq in KHz */
163 break;
164 case TEA5767_HIGH_LO_32768:
165 default:
166 frq = (div * 32768 - 700000 - 225000) / 4; /* Freq in KHz */
167 break;
168 }
169 buffer[0] = (div >> 8) & 0x3f;
170 buffer[1] = div & 0xff;
171
172 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n",
173 frq / 1000, frq % 1000, div);
174
175 if (TEA5767_STEREO_MASK & buffer[2])
176 printk(PREFIX "Stereo\n");
177 else
178 printk(PREFIX "Mono\n");
179
180 printk(PREFIX "IF Counter = %d\n", buffer[2] & TEA5767_IF_CNTR_MASK);
181
182 printk(PREFIX "ADC Level = %d\n",
183 (buffer[3] & TEA5767_ADC_LEVEL_MASK) >> 4);
184
185 printk(PREFIX "Chip ID = %d\n", (buffer[3] & TEA5767_CHIP_ID_MASK));
186
187 printk(PREFIX "Reserved = 0x%02x\n",
188 (buffer[4] & TEA5767_RESERVED_MASK));
189}
190
191/* Freq should be specifyed at 62.5 Hz */
192static void set_radio_freq(struct i2c_client *c, unsigned int frq)
193{
194 struct tuner *t = i2c_get_clientdata(c);
195 unsigned char buffer[5];
196 unsigned div;
197 int rc;
198
199 tuner_dbg (PREFIX "radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000);
200
201 /* Rounds freq to next decimal value - for 62.5 KHz step */
202 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
203
204 buffer[2] = TEA5767_PORT1_HIGH;
205 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL |
206 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
207 buffer[4] = 0;
208
209 if (t->mode == T_STANDBY) {
210 tuner_dbg("TEA5767 set to standby mode\n");
211 buffer[3] |= TEA5767_STDBY;
212 }
213
214 if (t->audmode == V4L2_TUNER_MODE_MONO) {
215 tuner_dbg("TEA5767 set to mono\n");
216 buffer[2] |= TEA5767_MONO;
217 } else {
218 tuner_dbg("TEA5767 set to stereo\n");
219 }
220
221 /* Should be replaced */
222 switch (TEA5767_HIGH_LO_32768) {
223 case TEA5767_HIGH_LO_13MHz:
224 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n");
225 buffer[2] |= TEA5767_HIGH_LO_INJECT;
226 buffer[4] |= TEA5767_PLLREF_ENABLE;
227 div = (frq * 4000 / 16 + 700000 + 225000 + 25000) / 50000;
228 break;
229 case TEA5767_LOW_LO_13MHz:
230 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 13 MHz\n");
231
232 buffer[4] |= TEA5767_PLLREF_ENABLE;
233 div = (frq * 4000 / 16 - 700000 - 225000 + 25000) / 50000;
234 break;
235 case TEA5767_LOW_LO_32768:
236 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n");
237 buffer[3] |= TEA5767_XTAL_32768;
238 /* const 700=4000*175 Khz - to adjust freq to right value */
239 div = ((frq * 4000 / 16 - 700000 - 225000) + 16384) >> 15;
240 break;
241 case TEA5767_HIGH_LO_32768:
242 default:
243 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n");
244
245 buffer[2] |= TEA5767_HIGH_LO_INJECT;
246 buffer[3] |= TEA5767_XTAL_32768;
247 div = ((frq * (4000 / 16) + 700000 + 225000) + 16384) >> 15;
248 break;
249 }
250 buffer[0] = (div >> 8) & 0x3f;
251 buffer[1] = div & 0xff;
252
253 if (5 != (rc = i2c_master_send(c, buffer, 5)))
254 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
255
256 if (tuner_debug) {
257 if (5 != (rc = i2c_master_recv(c, buffer, 5)))
258 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
259 else
260 tea5767_status_dump(buffer);
261 }
262}
263
264static int tea5767_signal(struct i2c_client *c)
265{
266 unsigned char buffer[5];
267 int rc;
268 struct tuner *t = i2c_get_clientdata(c);
269
270 memset(buffer, 0, sizeof(buffer));
271 if (5 != (rc = i2c_master_recv(c, buffer, 5)))
272 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
273
274 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << (13 - 4));
275}
276
277static int tea5767_stereo(struct i2c_client *c)
278{
279 unsigned char buffer[5];
280 int rc;
281 struct tuner *t = i2c_get_clientdata(c);
282
283 memset(buffer, 0, sizeof(buffer));
284 if (5 != (rc = i2c_master_recv(c, buffer, 5)))
285 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
286
287 rc = buffer[2] & TEA5767_STEREO_MASK;
288
289 tuner_dbg("TEA5767 radio ST GET = %02x\n", rc);
290
291 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0);
292}
293
294int tea5767_autodetection(struct i2c_client *c)
295{
296 unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
297 int rc;
298 struct tuner *t = i2c_get_clientdata(c);
299
300 if (5 != (rc = i2c_master_recv(c, buffer, 5))) {
301 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc);
302 return EINVAL;
303 }
304
305 /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */
306 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
307 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
308 tuner_warn("All bytes are equal. It is not a TEA5767\n");
309 return EINVAL;
310 }
311
312 /* Status bytes:
313 * Byte 4: bit 3:1 : CI (Chip Identification) == 0
314 * bit 0 : internally set to 0
315 * Byte 5: bit 7:0 : == 0
316 */
317 if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) {
318 tuner_warn("Chip ID is not zero. It is not a TEA5767\n");
319 return EINVAL;
320 }
321
322 tuner_warn("TEA5767 detected.\n");
323 return 0;
324}
325
326int tea5767_tuner_init(struct i2c_client *c)
327{
328 struct tuner *t = i2c_get_clientdata(c);
329
330 if (tea5767_autodetection(c) == EINVAL)
331 return EINVAL;
332
333 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio");
334 strlcpy(c->name, "tea5767", sizeof(c->name));
335
336 t->tv_freq = set_tv_freq;
337 t->radio_freq = set_radio_freq;
338 t->has_signal = tea5767_signal;
339 t->is_stereo = tea5767_stereo;
340
341 return (0);
342}
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index 51748c6578d1..7d825e510ffd 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -152,7 +152,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
152 152
153 switch (cmd) 153 switch (cmd)
154 { 154 {
155 case TUNER_SET_TVFREQ: 155 case VIDIOCSFREQ:
156 set_tv_freq(client, *iarg); 156 set_tv_freq(client, *iarg);
157 break; 157 break;
158 158
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index eaabfc858703..b25a9c08ac02 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $ 2 * $Id: tuner-core.c,v 1.58 2005/07/14 03:06:43 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -23,45 +23,39 @@
23#include <media/tuner.h> 23#include <media/tuner.h>
24#include <media/audiochip.h> 24#include <media/audiochip.h>
25 25
26/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */
29#define CONFIG_TUNER_MULTI_I2C /**/
30
31#define UNSET (-1U) 26#define UNSET (-1U)
32 27
33/* standard i2c insmod options */ 28/* standard i2c insmod options */
34static unsigned short normal_i2c[] = { 29static unsigned short normal_i2c[] = {
35 0x4b, /* tda8290 */ 30 0x4b, /* tda8290 */
36 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 31 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
37 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 32 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
38 I2C_CLIENT_END 33 I2C_CLIENT_END
39}; 34};
35
40I2C_CLIENT_INSMOD; 36I2C_CLIENT_INSMOD;
41 37
42/* insmod options used at init time => read/only */ 38/* insmod options used at init time => read/only */
43static unsigned int addr = 0; 39static unsigned int addr = 0;
44module_param(addr, int, 0444); 40module_param(addr, int, 0444);
45 41
42static unsigned int no_autodetect = 0;
43module_param(no_autodetect, int, 0444);
44
46/* insmod options used at runtime => read/write */ 45/* insmod options used at runtime => read/write */
47unsigned int tuner_debug = 0; 46unsigned int tuner_debug = 0;
48module_param(tuner_debug, int, 0644); 47module_param(tuner_debug, int, 0644);
49 48
50static unsigned int tv_range[2] = { 44, 958 }; 49static unsigned int tv_range[2] = { 44, 958 };
51static unsigned int radio_range[2] = { 65, 108 }; 50static unsigned int radio_range[2] = { 65, 108 };
52 51
53module_param_array(tv_range, int, NULL, 0644); 52module_param_array(tv_range, int, NULL, 0644);
54module_param_array(radio_range, int, NULL, 0644); 53module_param_array(radio_range, int, NULL, 0644);
55 54
56MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners"); 55MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
57MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); 56MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
58MODULE_LICENSE("GPL"); 57MODULE_LICENSE("GPL");
59 58
60static int this_adap;
61#ifdef CONFIG_TUNER_MULTI_I2C
62static unsigned short first_tuner, tv_tuner, radio_tuner;
63#endif
64
65static struct i2c_driver driver; 59static struct i2c_driver driver;
66static struct i2c_client client_template; 60static struct i2c_client client_template;
67 61
@@ -73,35 +67,19 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
73 struct tuner *t = i2c_get_clientdata(c); 67 struct tuner *t = i2c_get_clientdata(c);
74 68
75 if (t->type == UNSET) { 69 if (t->type == UNSET) {
76 tuner_info("tuner type not set\n"); 70 tuner_warn ("tuner type not set\n");
77 return; 71 return;
78 } 72 }
79 if (NULL == t->tv_freq) { 73 if (NULL == t->tv_freq) {
80 tuner_info("Huh? tv_set is NULL?\n"); 74 tuner_warn ("Tuner has no way to set tv freq\n");
81 return; 75 return;
82 } 76 }
83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 77 if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
84 78 tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
85 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) { 79 freq / 16, freq % 16 * 100 / 16, tv_range[0],
86 /* V4L2_TUNER_CAP_LOW frequency */ 80 tv_range[1]);
87
88 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n");
89
90 t->tv_freq(c,freq>>10);
91
92 return;
93 } else {
94 /* FIXME: better do that chip-specific, but
95 right now we don't have that in the config
96 struct and this way is still better than no
97 check at all */
98 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n",
99 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
100 return;
101 }
102 } 81 }
103 tuner_dbg("62.5 Khz freq step selected for TV.\n"); 82 t->tv_freq(c, freq);
104 t->tv_freq(c,freq);
105} 83}
106 84
107static void set_radio_freq(struct i2c_client *c, unsigned int freq) 85static void set_radio_freq(struct i2c_client *c, unsigned int freq)
@@ -109,38 +87,21 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
109 struct tuner *t = i2c_get_clientdata(c); 87 struct tuner *t = i2c_get_clientdata(c);
110 88
111 if (t->type == UNSET) { 89 if (t->type == UNSET) {
112 tuner_info("tuner type not set\n"); 90 tuner_warn ("tuner type not set\n");
113 return; 91 return;
114 } 92 }
115 if (NULL == t->radio_freq) { 93 if (NULL == t->radio_freq) {
116 tuner_info("no radio tuning for this one, sorry.\n"); 94 tuner_warn ("tuner has no way to set radio frequency\n");
117 return; 95 return;
118 } 96 }
119 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) { 97 if (freq <= radio_range[0] * 16000 || freq >= radio_range[1] * 16000) {
120 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) { 98 tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
121 /* V4L2_TUNER_CAP_LOW frequency */ 99 freq / 16000, freq % 16000 * 100 / 16000,
122 if (t->type == TUNER_TEA5767) { 100 radio_range[0], radio_range[1]);
123 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
124 t->radio_freq(c,freq>>10);
125 return;
126 }
127
128 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n");
129
130 tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
131
132 t->radio_freq(c,freq>>10);
133 return;
134
135 } else {
136 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
137 freq/16,freq%16*100/16,
138 radio_range[0],radio_range[1]);
139 return;
140 }
141 } 101 }
142 tuner_dbg("62.5 Khz freq step selected for Radio.\n"); 102
143 t->radio_freq(c,freq); 103 t->radio_freq(c, freq);
104 return;
144} 105}
145 106
146static void set_freq(struct i2c_client *c, unsigned long freq) 107static void set_freq(struct i2c_client *c, unsigned long freq)
@@ -150,42 +111,45 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
150 switch (t->mode) { 111 switch (t->mode) {
151 case V4L2_TUNER_RADIO: 112 case V4L2_TUNER_RADIO:
152 tuner_dbg("radio freq set to %lu.%02lu\n", 113 tuner_dbg("radio freq set to %lu.%02lu\n",
153 freq/16,freq%16*100/16); 114 freq / 16000, freq % 16000 * 100 / 16000);
154 set_radio_freq(c,freq); 115 set_radio_freq(c, freq);
155 break; 116 break;
156 case V4L2_TUNER_ANALOG_TV: 117 case V4L2_TUNER_ANALOG_TV:
157 case V4L2_TUNER_DIGITAL_TV: 118 case V4L2_TUNER_DIGITAL_TV:
158 tuner_dbg("tv freq set to %lu.%02lu\n", 119 tuner_dbg("tv freq set to %lu.%02lu\n",
159 freq/16,freq%16*100/16); 120 freq / 16, freq % 16 * 100 / 16);
160 set_tv_freq(c, freq); 121 set_tv_freq(c, freq);
161 break; 122 break;
162 } 123 }
163 t->freq = freq; 124 t->freq = freq;
164} 125}
165 126
166static void set_type(struct i2c_client *c, unsigned int type) 127static void set_type(struct i2c_client *c, unsigned int type,
128 unsigned int new_mode_mask)
167{ 129{
168 struct tuner *t = i2c_get_clientdata(c); 130 struct tuner *t = i2c_get_clientdata(c);
131 unsigned char buffer[4];
169 132
170 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type); 133 if (type == UNSET || type == TUNER_ABSENT) {
171 /* sanity check */ 134 tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr);
172 if (type == UNSET || type == TUNER_ABSENT)
173 return; 135 return;
174 if (type >= tuner_count) 136 }
137
138 if (type >= tuner_count) {
139 tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count);
175 return; 140 return;
141 }
176 142
143 /* This code detects calls by card attach_inform */
177 if (NULL == t->i2c.dev.driver) { 144 if (NULL == t->i2c.dev.driver) {
178 /* not registered yet */ 145 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
179 t->type = type; 146
147 t->type=type;
180 return; 148 return;
181 } 149 }
182 if (t->initialized)
183 /* run only once */
184 return;
185
186 t->initialized = 1;
187 150
188 t->type = type; 151 t->type = type;
152
189 switch (t->type) { 153 switch (t->type) {
190 case TUNER_MT2032: 154 case TUNER_MT2032:
191 microtune_init(c); 155 microtune_init(c);
@@ -193,127 +157,197 @@ static void set_type(struct i2c_client *c, unsigned int type)
193 case TUNER_PHILIPS_TDA8290: 157 case TUNER_PHILIPS_TDA8290:
194 tda8290_init(c); 158 tda8290_init(c);
195 break; 159 break;
160 case TUNER_TEA5767:
161 if (tea5767_tuner_init(c) == EINVAL) {
162 t->type = TUNER_ABSENT;
163 t->mode_mask = T_UNINITIALIZED;
164 return;
165 }
166 t->mode_mask = T_RADIO;
167 break;
168 case TUNER_PHILIPS_FMD1216ME_MK3:
169 buffer[0] = 0x0b;
170 buffer[1] = 0xdc;
171 buffer[2] = 0x9c;
172 buffer[3] = 0x60;
173 i2c_master_send(c, buffer, 4);
174 mdelay(1);
175 buffer[2] = 0x86;
176 buffer[3] = 0x54;
177 i2c_master_send(c, buffer, 4);
178 default_tuner_init(c);
179 break;
196 default: 180 default:
197 default_tuner_init(c); 181 default_tuner_init(c);
198 break; 182 break;
199 } 183 }
184
185 if (t->mode_mask == T_UNINITIALIZED)
186 t->mode_mask = new_mode_mask;
187
188 set_freq(c, t->freq);
189 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
190 c->adapter->name, c->driver->name, c->addr << 1, type,
191 t->mode_mask);
200} 192}
201 193
202#ifdef CONFIG_TUNER_MULTI_I2C 194/*
203#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \ 195 * This function apply tuner config to tuner specified
204 return 0; } else \ 196 * by tun_setup structure. I addr is unset, then admin status
205 tuner_info ("Cmd %s accepted to "tun"\n",cmd); 197 * and tun addr status is more precise then current status,
206#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \ 198 * it's applied. Otherwise status and type are applied only to
207 CHECK_ADDR(radio_tuner,cmd,"radio") } else \ 199 * tuner with exactly the same addr.
208 { CHECK_ADDR(tv_tuner,cmd,"TV"); } 200*/
209#else 201
210#define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd); 202static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
211#define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd);
212#endif
213
214#ifdef CONFIG_TUNER_MULTI_I2C
215
216static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
217{ 203{
218 /* ADDR_UNSET defaults to first available tuner */ 204 struct tuner *t = i2c_get_clientdata(c);
219 if ( tun_addr->addr == ADDR_UNSET ) { 205
220 if (first_tuner != c->addr) 206 if (tun_setup->addr == ADDR_UNSET) {
221 return; 207 if (t->mode_mask & tun_setup->mode_mask)
222 switch (tun_addr->v4l2_tuner) { 208 set_type(c, tun_setup->type, tun_setup->mode_mask);
209 } else if (tun_setup->addr == c->addr) {
210 set_type(c, tun_setup->type, tun_setup->mode_mask);
211 }
212}
213
214static inline int check_mode(struct tuner *t, char *cmd)
215{
216 if (1 << t->mode & t->mode_mask) {
217 switch (t->mode) {
223 case V4L2_TUNER_RADIO: 218 case V4L2_TUNER_RADIO:
224 radio_tuner=c->addr; 219 tuner_dbg("Cmd %s accepted for radio\n", cmd);
225 break; 220 break;
226 default: 221 case V4L2_TUNER_ANALOG_TV:
227 tv_tuner=c->addr; 222 tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
223 break;
224 case V4L2_TUNER_DIGITAL_TV:
225 tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
228 break; 226 break;
229 } 227 }
230 } else { 228 return 0;
231 /* Sets tuner to its configured value */
232 switch (tun_addr->v4l2_tuner) {
233 case V4L2_TUNER_RADIO:
234 radio_tuner=tun_addr->addr;
235 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
236 return;
237 default:
238 tv_tuner=tun_addr->addr;
239 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
240 return;
241 }
242 } 229 }
243 set_type(c,tun_addr->type); 230 return EINVAL;
244} 231}
245#else
246#define set_addr(c,tun_addr) set_type(c,(tun_addr)->type)
247#endif
248 232
249static char pal[] = "-"; 233static char pal[] = "-";
250module_param_string(pal, pal, sizeof(pal), 0644); 234module_param_string(pal, pal, sizeof(pal), 0644);
235static char secam[] = "-";
236module_param_string(secam, secam, sizeof(secam), 0644);
251 237
238/* get more precise norm info from insmod option */
252static int tuner_fixup_std(struct tuner *t) 239static int tuner_fixup_std(struct tuner *t)
253{ 240{
254 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { 241 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
255 /* get more precise norm info from insmod option */
256 switch (pal[0]) { 242 switch (pal[0]) {
257 case 'b': 243 case 'b':
258 case 'B': 244 case 'B':
259 case 'g': 245 case 'g':
260 case 'G': 246 case 'G':
261 tuner_dbg("insmod fixup: PAL => PAL-BG\n"); 247 tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
262 t->std = V4L2_STD_PAL_BG; 248 t->std = V4L2_STD_PAL_BG;
263 break; 249 break;
264 case 'i': 250 case 'i':
265 case 'I': 251 case 'I':
266 tuner_dbg("insmod fixup: PAL => PAL-I\n"); 252 tuner_dbg ("insmod fixup: PAL => PAL-I\n");
267 t->std = V4L2_STD_PAL_I; 253 t->std = V4L2_STD_PAL_I;
268 break; 254 break;
269 case 'd': 255 case 'd':
270 case 'D': 256 case 'D':
271 case 'k': 257 case 'k':
272 case 'K': 258 case 'K':
273 tuner_dbg("insmod fixup: PAL => PAL-DK\n"); 259 tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
274 t->std = V4L2_STD_PAL_DK; 260 t->std = V4L2_STD_PAL_DK;
275 break; 261 break;
262 case 'M':
263 case 'm':
264 tuner_dbg ("insmod fixup: PAL => PAL-M\n");
265 t->std = V4L2_STD_PAL_M;
266 break;
267 case 'N':
268 case 'n':
269 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
270 t->std = V4L2_STD_PAL_N;
271 break;
276 } 272 }
277 } 273 }
274 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
275 switch (secam[0]) {
276 case 'd':
277 case 'D':
278 case 'k':
279 case 'K':
280 tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
281 t->std = V4L2_STD_SECAM_DK;
282 break;
283 case 'l':
284 case 'L':
285 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
286 t->std = V4L2_STD_SECAM_L;
287 break;
288 }
289 }
290
278 return 0; 291 return 0;
279} 292}
280 293
281/* ---------------------------------------------------------------------- */ 294/* ---------------------------------------------------------------------- */
282 295
296/* static var Used only in tuner_attach and tuner_probe */
297static unsigned default_mode_mask;
298
299/* During client attach, set_type is called by adapter's attach_inform callback.
300 set_type must then be completed by tuner_attach.
301 */
283static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) 302static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
284{ 303{
285 struct tuner *t; 304 struct tuner *t;
286 305
287#ifndef CONFIG_TUNER_MULTI_I2C 306 client_template.adapter = adap;
288 if (this_adap > 0) 307 client_template.addr = addr;
289 return -1;
290#else
291 /* by default, first I2C card is both tv and radio tuner */
292 if (this_adap == 0) {
293 first_tuner = addr;
294 tv_tuner = addr;
295 radio_tuner = addr;
296 }
297#endif
298 this_adap++;
299
300 client_template.adapter = adap;
301 client_template.addr = addr;
302 308
303 t = kmalloc(sizeof(struct tuner),GFP_KERNEL); 309 t = kmalloc(sizeof(struct tuner), GFP_KERNEL);
304 if (NULL == t) 310 if (NULL == t)
305 return -ENOMEM; 311 return -ENOMEM;
306 memset(t,0,sizeof(struct tuner)); 312 memset(t, 0, sizeof(struct tuner));
307 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client)); 313 memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
308 i2c_set_clientdata(&t->i2c, t); 314 i2c_set_clientdata(&t->i2c, t);
309 t->type = UNSET; 315 t->type = UNSET;
310 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */ 316 t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
317 t->audmode = V4L2_TUNER_MODE_STEREO;
318 t->mode_mask = T_UNINITIALIZED;
319
320
321 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
322
323 /* TEA5767 autodetection code - only for addr = 0xc0 */
324 if (!no_autodetect) {
325 if (addr == 0x60) {
326 if (tea5767_autodetection(&t->i2c) != EINVAL) {
327 t->type = TUNER_TEA5767;
328 t->mode_mask = T_RADIO;
329 t->mode = T_STANDBY;
330 t->freq = 87.5 * 16; /* Sets freq to FM range */
331 default_mode_mask &= ~T_RADIO;
332
333 i2c_attach_client (&t->i2c);
334 set_type(&t->i2c,t->type, t->mode_mask);
335 return 0;
336 }
337 }
338 }
311 339
312 i2c_attach_client(&t->i2c); 340 /* Initializes only the first adapter found */
313 tuner_info("chip found @ 0x%x (%s)\n", 341 if (default_mode_mask != T_UNINITIALIZED) {
314 addr << 1, adap->name); 342 tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
343 t->mode_mask = default_mode_mask;
344 t->freq = 400 * 16; /* Sets freq to VHF High */
345 default_mode_mask = T_UNINITIALIZED;
346 }
315 347
316 set_type(&t->i2c, t->type); 348 /* Should be just before return */
349 i2c_attach_client (&t->i2c);
350 set_type (&t->i2c,t->type, t->mode_mask);
317 return 0; 351 return 0;
318} 352}
319 353
@@ -323,13 +357,8 @@ static int tuner_probe(struct i2c_adapter *adap)
323 normal_i2c[0] = addr; 357 normal_i2c[0] = addr;
324 normal_i2c[1] = I2C_CLIENT_END; 358 normal_i2c[1] = I2C_CLIENT_END;
325 } 359 }
326 this_adap = 0;
327 360
328#ifdef CONFIG_TUNER_MULTI_I2C 361 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
329 first_tuner = 0;
330 tv_tuner = 0;
331 radio_tuner = 0;
332#endif
333 362
334 if (adap->class & I2C_CLASS_TV_ANALOG) 363 if (adap->class & I2C_CLASS_TV_ANALOG)
335 return i2c_probe(adap, &addr_data, tuner_attach); 364 return i2c_probe(adap, &addr_data, tuner_attach);
@@ -341,9 +370,10 @@ static int tuner_detach(struct i2c_client *client)
341 struct tuner *t = i2c_get_clientdata(client); 370 struct tuner *t = i2c_get_clientdata(client);
342 int err; 371 int err;
343 372
344 err=i2c_detach_client(&t->i2c); 373 err = i2c_detach_client(&t->i2c);
345 if (err) { 374 if (err) {
346 tuner_warn ("Client deregistration failed, client not detached.\n"); 375 tuner_warn
376 ("Client deregistration failed, client not detached.\n");
347 return err; 377 return err;
348 } 378 }
349 379
@@ -351,37 +381,65 @@ static int tuner_detach(struct i2c_client *client)
351 return 0; 381 return 0;
352} 382}
353 383
354#define SWITCH_V4L2 if (!t->using_v4l2 && tuner_debug) \ 384/*
355 tuner_info("switching to v4l2\n"); \ 385 * Switch tuner to other mode. If tuner support both tv and radio,
356 t->using_v4l2 = 1; 386 * set another frequency to some value (This is needed for some pal
357#define CHECK_V4L2 if (t->using_v4l2) { if (tuner_debug) \ 387 * tuners to avoid locking). Otherwise, just put second tuner in
358 tuner_info("ignore v4l1 call\n"); \ 388 * standby mode.
359 return 0; } 389 */
360 390
361static int 391static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
362tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) 392{
393 if (mode != t->mode) {
394
395 t->mode = mode;
396 if (check_mode(t, cmd) == EINVAL) {
397 t->mode = T_STANDBY;
398 if (V4L2_TUNER_RADIO == mode) {
399 set_tv_freq(client, 400 * 16);
400 } else {
401 set_radio_freq(client, 87.5 * 16000);
402 }
403 return EINVAL;
404 }
405 }
406 return 0;
407}
408
409#define switch_v4l2() if (!t->using_v4l2) \
410 tuner_dbg("switching to v4l2\n"); \
411 t->using_v4l2 = 1;
412
413static inline int check_v4l2(struct tuner *t)
414{
415 if (t->using_v4l2) {
416 tuner_dbg ("ignore v4l1 call\n");
417 return EINVAL;
418 }
419 return 0;
420}
421
422static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
363{ 423{
364 struct tuner *t = i2c_get_clientdata(client); 424 struct tuner *t = i2c_get_clientdata(client);
365 unsigned int *iarg = (int*)arg; 425 unsigned int *iarg = (int *)arg;
366 426
367 switch (cmd) { 427 switch (cmd) {
368 /* --- configuration --- */ 428 /* --- configuration --- */
369 case TUNER_SET_TYPE:
370 set_type(client,*iarg);
371 break;
372 case TUNER_SET_TYPE_ADDR: 429 case TUNER_SET_TYPE_ADDR:
373 set_addr(client,(struct tuner_addr *)arg); 430 tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n",
431 ((struct tuner_setup *)arg)->type,
432 ((struct tuner_setup *)arg)->addr,
433 ((struct tuner_setup *)arg)->mode_mask);
434
435 set_addr(client, (struct tuner_setup *)arg);
374 break; 436 break;
375 case AUDC_SET_RADIO: 437 case AUDC_SET_RADIO:
376 t->mode = V4L2_TUNER_RADIO; 438 set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO");
377 CHECK_ADDR(tv_tuner,"AUDC_SET_RADIO","TV");
378
379 if (V4L2_TUNER_RADIO != t->mode) {
380 set_tv_freq(client,400 * 16);
381 }
382 break; 439 break;
383 case AUDC_CONFIG_PINNACLE: 440 case AUDC_CONFIG_PINNACLE:
384 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE","TV"); 441 if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL)
442 return 0;
385 switch (*iarg) { 443 switch (*iarg) {
386 case 2: 444 case 2:
387 tuner_dbg("pinnacle pal\n"); 445 tuner_dbg("pinnacle pal\n");
@@ -392,188 +450,241 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
392 t->radio_if2 = 41300 * 1000; 450 t->radio_if2 = 41300 * 1000;
393 break; 451 break;
394 } 452 }
395 break; 453 break;
396 454 case TDA9887_SET_CONFIG:
455 break;
397 /* --- v4l ioctls --- */ 456 /* --- v4l ioctls --- */
398 /* take care: bttv does userspace copying, we'll get a 457 /* take care: bttv does userspace copying, we'll get a
399 kernel pointer here... */ 458 kernel pointer here... */
400 case VIDIOCSCHAN: 459 case VIDIOCSCHAN:
401 { 460 {
402 static const v4l2_std_id map[] = { 461 static const v4l2_std_id map[] = {
403 [ VIDEO_MODE_PAL ] = V4L2_STD_PAL, 462 [VIDEO_MODE_PAL] = V4L2_STD_PAL,
404 [ VIDEO_MODE_NTSC ] = V4L2_STD_NTSC_M, 463 [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
405 [ VIDEO_MODE_SECAM ] = V4L2_STD_SECAM, 464 [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
406 [ 4 /* bttv */ ] = V4L2_STD_PAL_M, 465 [4 /* bttv */ ] = V4L2_STD_PAL_M,
407 [ 5 /* bttv */ ] = V4L2_STD_PAL_N, 466 [5 /* bttv */ ] = V4L2_STD_PAL_N,
408 [ 6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, 467 [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
409 }; 468 };
410 struct video_channel *vc = arg; 469 struct video_channel *vc = arg;
411 470
412 CHECK_V4L2; 471 if (check_v4l2(t) == EINVAL)
413 t->mode = V4L2_TUNER_ANALOG_TV; 472 return 0;
414 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN","TV"); 473
415 474 if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL)
416 if (vc->norm < ARRAY_SIZE(map)) 475 return 0;
417 t->std = map[vc->norm]; 476
418 tuner_fixup_std(t); 477 if (vc->norm < ARRAY_SIZE(map))
419 if (t->freq) 478 t->std = map[vc->norm];
420 set_tv_freq(client,t->freq); 479 tuner_fixup_std(t);
421 return 0; 480 if (t->freq)
422 } 481 set_tv_freq(client, t->freq);
482 return 0;
483 }
423 case VIDIOCSFREQ: 484 case VIDIOCSFREQ:
424 { 485 {
425 unsigned long *v = arg; 486 unsigned long *v = arg;
426 487
427 CHECK_MODE("VIDIOCSFREQ"); 488 if (check_mode(t, "VIDIOCSFREQ") == EINVAL)
428 CHECK_V4L2; 489 return 0;
429 set_freq(client,*v); 490 if (check_v4l2(t) == EINVAL)
430 return 0; 491 return 0;
431 } 492
493 set_freq(client, *v);
494 return 0;
495 }
432 case VIDIOCGTUNER: 496 case VIDIOCGTUNER:
433 { 497 {
434 struct video_tuner *vt = arg; 498 struct video_tuner *vt = arg;
435 499
436 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER","radio"); 500 if (check_mode(t, "VIDIOCGTUNER") == EINVAL)
437 CHECK_V4L2; 501 return 0;
438 if (V4L2_TUNER_RADIO == t->mode) { 502 if (check_v4l2(t) == EINVAL)
439 if (t->has_signal) 503 return 0;
440 vt->signal = t->has_signal(client); 504
441 if (t->is_stereo) { 505 if (V4L2_TUNER_RADIO == t->mode) {
442 if (t->is_stereo(client)) 506 if (t->has_signal)
443 vt-> flags |= VIDEO_TUNER_STEREO_ON; 507 vt->signal = t->has_signal(client);
444 else 508 if (t->is_stereo) {
445 vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON; 509 if (t->is_stereo(client))
510 vt->flags |=
511 VIDEO_TUNER_STEREO_ON;
512 else
513 vt->flags &=
514 ~VIDEO_TUNER_STEREO_ON;
515 }
516 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
517
518 vt->rangelow = radio_range[0] * 16000;
519 vt->rangehigh = radio_range[1] * 16000;
520
521 } else {
522 vt->rangelow = tv_range[0] * 16;
523 vt->rangehigh = tv_range[1] * 16;
446 } 524 }
447 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */
448 }
449 525
450 return 0; 526 return 0;
451 } 527 }
452 case VIDIOCGAUDIO: 528 case VIDIOCGAUDIO:
453 { 529 {
454 struct video_audio *va = arg; 530 struct video_audio *va = arg;
455 531
456 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO","radio"); 532 if (check_mode(t, "VIDIOCGAUDIO") == EINVAL)
457 CHECK_V4L2; 533 return 0;
458 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) 534 if (check_v4l2(t) == EINVAL)
459 va->mode = t->is_stereo(client) 535 return 0;
460 ? VIDEO_SOUND_STEREO 536
461 : VIDEO_SOUND_MONO; 537 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
462 return 0; 538 va->mode = t->is_stereo(client)
463 } 539 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
540 return 0;
541 }
464 542
465 case VIDIOC_S_STD: 543 case VIDIOC_S_STD:
466 { 544 {
467 v4l2_std_id *id = arg; 545 v4l2_std_id *id = arg;
468 546
469 SWITCH_V4L2; 547 if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD")
470 t->mode = V4L2_TUNER_ANALOG_TV; 548 == EINVAL)
471 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD","TV"); 549 return 0;
472 550
473 t->std = *id; 551 switch_v4l2();
474 tuner_fixup_std(t); 552
475 if (t->freq) 553 t->std = *id;
476 set_freq(client,t->freq); 554 tuner_fixup_std(t);
477 break; 555 if (t->freq)
478 } 556 set_freq(client, t->freq);
557 break;
558 }
479 case VIDIOC_S_FREQUENCY: 559 case VIDIOC_S_FREQUENCY:
480 { 560 {
481 struct v4l2_frequency *f = arg; 561 struct v4l2_frequency *f = arg;
482 562
483 CHECK_MODE("VIDIOC_S_FREQUENCY"); 563 t->freq = f->frequency;
484 SWITCH_V4L2; 564 switch_v4l2();
485 if (V4L2_TUNER_RADIO == f->type && 565 if (V4L2_TUNER_RADIO == f->type &&
486 V4L2_TUNER_RADIO != t->mode) 566 V4L2_TUNER_RADIO != t->mode) {
487 set_tv_freq(client,400*16); 567 if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY")
488 t->mode = f->type; 568 == EINVAL)
489 set_freq(client,f->frequency); 569 return 0;
490 break; 570 }
491 } 571 set_freq(client,t->freq);
492 case VIDIOC_G_FREQUENCY:
493 {
494 struct v4l2_frequency *f = arg;
495 572
496 CHECK_MODE("VIDIOC_G_FREQUENCY"); 573 break;
497 SWITCH_V4L2; 574 }
498 f->type = t->mode; 575 case VIDIOC_G_FREQUENCY:
499 f->frequency = t->freq; 576 {
500 break; 577 struct v4l2_frequency *f = arg;
501 } 578
579 if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL)
580 return 0;
581 switch_v4l2();
582 f->type = t->mode;
583 f->frequency = t->freq;
584 break;
585 }
502 case VIDIOC_G_TUNER: 586 case VIDIOC_G_TUNER:
503 { 587 {
504 struct v4l2_tuner *tuner = arg; 588 struct v4l2_tuner *tuner = arg;
505 589
506 CHECK_MODE("VIDIOC_G_TUNER"); 590 if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL)
507 SWITCH_V4L2; 591 return 0;
508 if (V4L2_TUNER_RADIO == t->mode) { 592 switch_v4l2();
509 if (t->has_signal) 593
510 tuner -> signal = t->has_signal(client); 594 if (V4L2_TUNER_RADIO == t->mode) {
511 if (t->is_stereo) { 595
512 if (t->is_stereo(client)) { 596 if (t->has_signal)
513 tuner -> capability |= V4L2_TUNER_CAP_STEREO; 597 tuner->signal = t->has_signal(client);
514 tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO; 598
515 } else { 599 if (t->is_stereo) {
516 tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO; 600 if (t->is_stereo(client)) {
601 tuner->rxsubchans =
602 V4L2_TUNER_SUB_STEREO |
603 V4L2_TUNER_SUB_MONO;
604 } else {
605 tuner->rxsubchans =
606 V4L2_TUNER_SUB_MONO;
607 }
517 } 608 }
609
610 tuner->capability |=
611 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
612
613 tuner->audmode = t->audmode;
614
615 tuner->rangelow = radio_range[0] * 16000;
616 tuner->rangehigh = radio_range[1] * 16000;
617 } else {
618 tuner->rangelow = tv_range[0] * 16;
619 tuner->rangehigh = tv_range[1] * 16;
518 } 620 }
621 break;
622 }
623 case VIDIOC_S_TUNER:
624 {
625 struct v4l2_tuner *tuner = arg;
626
627 if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL)
628 return 0;
629
630 switch_v4l2();
631
632 if (V4L2_TUNER_RADIO == t->mode) {
633 t->audmode = tuner->audmode;
634 set_radio_freq(client, t->freq);
635 }
636 break;
519 } 637 }
520 /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */
521 tuner->rangelow = tv_range[0] * 16;
522// tuner->rangehigh = tv_range[1] * 16;
523// tuner->rangelow = tv_range[0] * 16384;
524 tuner->rangehigh = tv_range[1] * 16384;
525 break;
526 }
527 default: 638 default:
528 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd); 639 tuner_dbg("Unimplemented IOCTL 0x%08x(dir=%d,tp=0x%02x,nr=%d,sz=%d)\n",
529 /* nothing */ 640 cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd),
641 _IOC_NR(cmd), _IOC_SIZE(cmd));
530 break; 642 break;
531 } 643 }
532 644
533 return 0; 645 return 0;
534} 646}
535 647
536static int tuner_suspend(struct device * dev, u32 state, u32 level) 648static int tuner_suspend(struct device *dev, u32 state, u32 level)
537{ 649{
538 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 650 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
539 struct tuner *t = i2c_get_clientdata(c); 651 struct tuner *t = i2c_get_clientdata (c);
540 652
541 tuner_dbg("suspend\n"); 653 tuner_dbg ("suspend\n");
542 /* FIXME: power down ??? */ 654 /* FIXME: power down ??? */
543 return 0; 655 return 0;
544} 656}
545 657
546static int tuner_resume(struct device * dev, u32 level) 658static int tuner_resume(struct device *dev, u32 level)
547{ 659{
548 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 660 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
549 struct tuner *t = i2c_get_clientdata(c); 661 struct tuner *t = i2c_get_clientdata (c);
550 662
551 tuner_dbg("resume\n"); 663 tuner_dbg ("resume\n");
552 if (t->freq) 664 if (t->freq)
553 set_freq(c,t->freq); 665 set_freq(c, t->freq);
554 return 0; 666 return 0;
555} 667}
556 668
557/* ----------------------------------------------------------------------- */ 669/* ----------------------------------------------------------------------- */
558 670
559static struct i2c_driver driver = { 671static struct i2c_driver driver = {
560 .owner = THIS_MODULE, 672 .owner = THIS_MODULE,
561 .name = "tuner", 673 .name = "tuner",
562 .id = I2C_DRIVERID_TUNER, 674 .id = I2C_DRIVERID_TUNER,
563 .flags = I2C_DF_NOTIFY, 675 .flags = I2C_DF_NOTIFY,
564 .attach_adapter = tuner_probe, 676 .attach_adapter = tuner_probe,
565 .detach_client = tuner_detach, 677 .detach_client = tuner_detach,
566 .command = tuner_command, 678 .command = tuner_command,
567 .driver = { 679 .driver = {
568 .suspend = tuner_suspend, 680 .suspend = tuner_suspend,
569 .resume = tuner_resume, 681 .resume = tuner_resume,
570 }, 682 },
571}; 683};
572static struct i2c_client client_template = 684static struct i2c_client client_template = {
573{
574 I2C_DEVNAME("(tuner unset)"), 685 I2C_DEVNAME("(tuner unset)"),
575 .flags = I2C_CLIENT_ALLOW_USE, 686 .flags = I2C_CLIENT_ALLOW_USE,
576 .driver = &driver, 687 .driver = &driver,
577}; 688};
578 689
579static int __init tuner_init_module(void) 690static int __init tuner_init_module(void)
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 539f30557317..a3f8e83f5314 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.21 2005/06/10 19:53:26 nsh Exp $ 2 * $Id: tuner-simple.c,v 1.39 2005/07/07 01:49:30 mkrufky Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 5 * controls all those simple 4-control-bytes style tuners.
@@ -54,6 +54,27 @@
54#define PHILIPS_MF_SET_PAL_L 0x03 // France 54#define PHILIPS_MF_SET_PAL_L 0x03 // France
55#define PHILIPS_MF_SET_PAL_L2 0x02 // L' 55#define PHILIPS_MF_SET_PAL_L2 0x02 // L'
56 56
57/* Control byte */
58
59#define TUNER_RATIO_MASK 0x06 /* Bit cb1:cb2 */
60#define TUNER_RATIO_SELECT_50 0x00
61#define TUNER_RATIO_SELECT_32 0x02
62#define TUNER_RATIO_SELECT_166 0x04
63#define TUNER_RATIO_SELECT_62 0x06
64
65#define TUNER_CHARGE_PUMP 0x40 /* Bit cb6 */
66
67/* Status byte */
68
69#define TUNER_POR 0x80
70#define TUNER_FL 0x40
71#define TUNER_MODE 0x38
72#define TUNER_AFC 0x07
73#define TUNER_SIGNAL 0x07
74#define TUNER_STEREO 0x10
75
76#define TUNER_PLL_LOCKED 0x40
77#define TUNER_STEREO_MK3 0x04
57 78
58/* ---------------------------------------------------------------------- */ 79/* ---------------------------------------------------------------------- */
59 80
@@ -207,28 +228,23 @@ static struct tunertype tuners[] = {
207 { "LG PAL (TAPE series)", LGINNOTEK, PAL, 228 { "LG PAL (TAPE series)", LGINNOTEK, PAL,
208 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623}, 229 16*170.00, 16*450.00, 0x01,0x02,0x08,0xce,623},
209 230
210 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL, 231 { "Philips PAL/SECAM multi (FQ1216AME MK4)", Philips, PAL,
211 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 232 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 },
212 { "Philips FQ1236A MK4", Philips, NTSC, 233 { "Philips FQ1236A MK4", Philips, NTSC,
213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 234 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 },
214 235 { "Ymec TVision TVF-8531MF/8831MF/8731MF", Philips, NTSC,
215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */
216 { "Ymec TVision TVF-8531MF", Philips, NTSC,
217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732}, 236 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
218 { "Ymec TVision TVF-5533MF", Philips, NTSC, 237 { "Ymec TVision TVF-5533MF", Philips, NTSC,
219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732}, 238 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732},
220 239
221 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC, 240 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC,
222 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 241 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
223 { "Tena TNF9533-D/IF", LGINNOTEK, PAL, 242 { "Tena TNF9533-D/IF/TNF9533-B/DF", Philips, PAL,
224 16*160.25, 16*464.25, 0x01,0x02,0x08,0x8e,623}, 243 16*160.25,16*464.25,0x01,0x02,0x04,0x8e,623},
225 244 { "Philips TEA5767HN FM Radio", Philips, RADIO,
226 /* 245 /* see tea5767.c for details */},
227 * This entry is for TEA5767 FM radio only chip used on several boards 246 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL,
228 * w/TV tuner 247 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 },
229 */
230 { TEA5767_TUNER_NAME, Philips, RADIO,
231 -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0},
232}; 248};
233 249
234unsigned const int tuner_count = ARRAY_SIZE(tuners); 250unsigned const int tuner_count = ARRAY_SIZE(tuners);
@@ -245,15 +261,6 @@ static int tuner_getstatus(struct i2c_client *c)
245 return byte; 261 return byte;
246} 262}
247 263
248#define TUNER_POR 0x80
249#define TUNER_FL 0x40
250#define TUNER_MODE 0x38
251#define TUNER_AFC 0x07
252
253#define TUNER_STEREO 0x10 /* radio mode */
254#define TUNER_STEREO_MK3 0x04 /* radio mode */
255#define TUNER_SIGNAL 0x07 /* radio mode */
256
257static int tuner_signal(struct i2c_client *c) 264static int tuner_signal(struct i2c_client *c)
258{ 265{
259 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13; 266 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13;
@@ -279,22 +286,6 @@ static int tuner_stereo(struct i2c_client *c)
279 return stereo; 286 return stereo;
280} 287}
281 288
282#if 0 /* unused */
283static int tuner_islocked (struct i2c_client *c)
284{
285 return (tuner_getstatus (c) & TUNER_FL);
286}
287
288static int tuner_afcstatus (struct i2c_client *c)
289{
290 return (tuner_getstatus (c) & TUNER_AFC) - 2;
291}
292
293static int tuner_mode (struct i2c_client *c)
294{
295 return (tuner_getstatus (c) & TUNER_MODE) >> 3;
296}
297#endif
298 289
299/* ---------------------------------------------------------------------- */ 290/* ---------------------------------------------------------------------- */
300 291
@@ -377,7 +368,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
377 368
378 case TUNER_MICROTUNE_4042FI5: 369 case TUNER_MICROTUNE_4042FI5:
379 /* Set the charge pump for fast tuning */ 370 /* Set the charge pump for fast tuning */
380 tun->config |= 0x40; 371 tun->config |= TUNER_CHARGE_PUMP;
381 break; 372 break;
382 } 373 }
383 374
@@ -426,14 +417,13 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
426 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); 417 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
427 break; 418 break;
428 } 419 }
429 /* bit 6 is PLL locked indicator */ 420 if (status_byte & TUNER_PLL_LOCKED)
430 if (status_byte & 0x40)
431 break; 421 break;
432 udelay(10); 422 udelay(10);
433 } 423 }
434 424
435 /* Set the charge pump for optimized phase noise figure */ 425 /* Set the charge pump for optimized phase noise figure */
436 tun->config &= ~0x40; 426 tun->config &= ~TUNER_CHARGE_PUMP;
437 buffer[0] = (div>>8) & 0x7f; 427 buffer[0] = (div>>8) & 0x7f;
438 buffer[1] = div & 0xff; 428 buffer[1] = div & 0xff;
439 buffer[2] = tun->config; 429 buffer[2] = tun->config;
@@ -454,26 +444,22 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
454 unsigned div; 444 unsigned div;
455 int rc; 445 int rc;
456 446
457 tun=&tuners[t->type]; 447 tun = &tuners[t->type];
458 div = freq + (int)(16*10.7); 448 div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */
459 buffer[2] = tun->config; 449 buffer[2] = (tun->config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */
460 450
461 switch (t->type) { 451 switch (t->type) {
462 case TUNER_TENA_9533_DI: 452 case TUNER_TENA_9533_DI:
463 case TUNER_YMEC_TVF_5533MF: 453 case TUNER_YMEC_TVF_5533MF:
464 454 tuner_dbg ("This tuner doesn't have FM. Most cards has a TEA5767 for FM\n");
465 /*These values are empirically determinated */ 455 return;
466 div = (freq*122)/16 - 20;
467 buffer[2] = 0x88; /* could be also 0x80 */
468 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */
469 break;
470 case TUNER_PHILIPS_FM1216ME_MK3: 456 case TUNER_PHILIPS_FM1216ME_MK3:
471 case TUNER_PHILIPS_FM1236_MK3: 457 case TUNER_PHILIPS_FM1236_MK3:
458 case TUNER_PHILIPS_FMD1216ME_MK3:
472 buffer[3] = 0x19; 459 buffer[3] = 0x19;
473 break; 460 break;
474 case TUNER_PHILIPS_FM1256_IH3: 461 case TUNER_PHILIPS_FM1256_IH3:
475 div = (20 * freq)/16 + 333 * 2; 462 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */
476 buffer[2] = 0x80;
477 buffer[3] = 0x19; 463 buffer[3] = 0x19;
478 break; 464 break;
479 case TUNER_LG_PAL_FM: 465 case TUNER_LG_PAL_FM:
@@ -505,6 +491,7 @@ int default_tuner_init(struct i2c_client *c)
505 t->radio_freq = default_set_radio_freq; 491 t->radio_freq = default_set_radio_freq;
506 t->has_signal = tuner_signal; 492 t->has_signal = tuner_signal;
507 t->is_stereo = tuner_stereo; 493 t->is_stereo = tuner_stereo;
494
508 return 0; 495 return 0;
509} 496}
510 497
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 9a493bea76d8..d8b78f1d686b 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -864,13 +864,8 @@ static int tda9874a_getmode(struct CHIPSTATE *chip)
864 * But changing the mode to VIDEO_SOUND_MONO would switch 864 * But changing the mode to VIDEO_SOUND_MONO would switch
865 * external 4052 multiplexer in audio_hook(). 865 * external 4052 multiplexer in audio_hook().
866 */ 866 */
867#if 0
868 if((nsr & 0x02) && !(dsr & 0x10)) /* NSR.S/MB=1 and DSR.AMSTAT=0 */
869 mode |= VIDEO_SOUND_STEREO;
870#else
871 if(nsr & 0x02) /* NSR.S/MB=1 */ 867 if(nsr & 0x02) /* NSR.S/MB=1 */
872 mode |= VIDEO_SOUND_STEREO; 868 mode |= VIDEO_SOUND_STEREO;
873#endif
874 if(nsr & 0x01) /* NSR.D/SB=1 */ 869 if(nsr & 0x01) /* NSR.D/SB=1 */
875 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 870 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
876 } else { 871 } else {
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 0f03c25489f1..e8d9440977cb 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -400,14 +400,6 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
400 } 400 }
401 } 401 }
402 402
403#if 0
404 if (t_format < sizeof(hauppauge_tuner_fmt)/sizeof(struct HAUPPAUGE_TUNER_FMT)) {
405 tvee->tuner_formats = hauppauge_tuner_fmt[t_format].id;
406 t_fmt_name = hauppauge_tuner_fmt[t_format].name;
407 } else {
408 t_fmt_name = "<unknown>";
409 }
410#endif
411 403
412 TVEEPROM_KERN_INFO("Hauppauge: model = %d, rev = %s, serial# = %d\n", 404 TVEEPROM_KERN_INFO("Hauppauge: model = %d, rev = %s, serial# = %d\n",
413 tvee->model, 405 tvee->model,
@@ -482,6 +474,7 @@ static unsigned short normal_i2c[] = {
482 0xa0 >> 1, 474 0xa0 >> 1,
483 I2C_CLIENT_END, 475 I2C_CLIENT_END,
484}; 476};
477
485I2C_CLIENT_INSMOD; 478I2C_CLIENT_INSMOD;
486 479
487struct i2c_driver i2c_driver_tveeprom; 480struct i2c_driver i2c_driver_tveeprom;
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 8b623278ccd2..ffbe6f4720e1 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -1363,19 +1363,7 @@ mpt_suspend(struct pci_dev *pdev, pm_message_t state)
1363 u32 device_state; 1363 u32 device_state;
1364 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1364 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1365 1365
1366 switch(state) 1366 device_state=pci_choose_state(pdev, state);
1367 {
1368 case 1: /* S1 */
1369 device_state=1; /* D1 */;
1370 break;
1371 case 3: /* S3 */
1372 case 4: /* S4 */
1373 device_state=3; /* D3 */;
1374 break;
1375 default:
1376 return -EAGAIN /*FIXME*/;
1377 break;
1378 }
1379 1367
1380 printk(MYIOC_s_INFO_FMT 1368 printk(MYIOC_s_INFO_FMT
1381 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n", 1369 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index 29f66de4e8f1..13771abea13f 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -347,9 +347,7 @@ static struct pci_driver mptfc_driver = {
347 .id_table = mptfc_pci_table, 347 .id_table = mptfc_pci_table,
348 .probe = mptfc_probe, 348 .probe = mptfc_probe,
349 .remove = __devexit_p(mptscsih_remove), 349 .remove = __devexit_p(mptscsih_remove),
350 .driver = { 350 .shutdown = mptscsih_shutdown,
351 .shutdown = mptscsih_shutdown,
352 },
353#ifdef CONFIG_PM 351#ifdef CONFIG_PM
354 .suspend = mptscsih_suspend, 352 .suspend = mptscsih_suspend,
355 .resume = mptscsih_resume, 353 .resume = mptscsih_resume,
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 364c49cb7482..b9d4f78725b4 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -170,7 +170,7 @@ static void mptscsih_fillbuf(char *buffer, int size, int index, int width);
170#endif 170#endif
171 171
172void mptscsih_remove(struct pci_dev *); 172void mptscsih_remove(struct pci_dev *);
173void mptscsih_shutdown(struct device *); 173void mptscsih_shutdown(struct pci_dev *);
174#ifdef CONFIG_PM 174#ifdef CONFIG_PM
175int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state); 175int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
176int mptscsih_resume(struct pci_dev *pdev); 176int mptscsih_resume(struct pci_dev *pdev);
@@ -988,7 +988,7 @@ mptscsih_remove(struct pci_dev *pdev)
988#endif 988#endif
989#endif 989#endif
990 990
991 mptscsih_shutdown(&pdev->dev); 991 mptscsih_shutdown(pdev);
992 992
993 sz1=0; 993 sz1=0;
994 994
@@ -1026,9 +1026,9 @@ mptscsih_remove(struct pci_dev *pdev)
1026 * 1026 *
1027 */ 1027 */
1028void 1028void
1029mptscsih_shutdown(struct device * dev) 1029mptscsih_shutdown(struct pci_dev *pdev)
1030{ 1030{
1031 MPT_ADAPTER *ioc = pci_get_drvdata(to_pci_dev(dev)); 1031 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1032 struct Scsi_Host *host = ioc->sh; 1032 struct Scsi_Host *host = ioc->sh;
1033 MPT_SCSI_HOST *hd; 1033 MPT_SCSI_HOST *hd;
1034 1034
@@ -1054,7 +1054,7 @@ mptscsih_shutdown(struct device * dev)
1054int 1054int
1055mptscsih_suspend(struct pci_dev *pdev, pm_message_t state) 1055mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
1056{ 1056{
1057 mptscsih_shutdown(&pdev->dev); 1057 mptscsih_shutdown(pdev);
1058 return mpt_suspend(pdev,state); 1058 return mpt_suspend(pdev,state);
1059} 1059}
1060 1060
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index c202ce89a0ff..51c0255ac16e 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -82,9 +82,9 @@
82#endif 82#endif
83 83
84extern void mptscsih_remove(struct pci_dev *); 84extern void mptscsih_remove(struct pci_dev *);
85extern void mptscsih_shutdown(struct device *); 85extern void mptscsih_shutdown(struct pci_dev *);
86#ifdef CONFIG_PM 86#ifdef CONFIG_PM
87extern int mptscsih_suspend(struct pci_dev *pdev, u32 state); 87extern int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
88extern int mptscsih_resume(struct pci_dev *pdev); 88extern int mptscsih_resume(struct pci_dev *pdev);
89#endif 89#endif
90extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func); 90extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func);
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index a0a2e0afb21d..dfa8806b1e13 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -402,9 +402,7 @@ static struct pci_driver mptspi_driver = {
402 .id_table = mptspi_pci_table, 402 .id_table = mptspi_pci_table,
403 .probe = mptspi_probe, 403 .probe = mptspi_probe,
404 .remove = __devexit_p(mptscsih_remove), 404 .remove = __devexit_p(mptscsih_remove),
405 .driver = { 405 .shutdown = mptscsih_shutdown,
406 .shutdown = mptscsih_shutdown,
407 },
408#ifdef CONFIG_PM 406#ifdef CONFIG_PM
409 .suspend = mptscsih_suspend, 407 .suspend = mptscsih_suspend,
410 .resume = mptscsih_resume, 408 .resume = mptscsih_resume,
diff --git a/drivers/message/i2o/config-osm.c b/drivers/message/i2o/config-osm.c
index d0267609a949..fe2e7afc9eae 100644
--- a/drivers/message/i2o/config-osm.c
+++ b/drivers/message/i2o/config-osm.c
@@ -15,7 +15,9 @@
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/i2o.h> 17#include <linux/i2o.h>
18#include <linux/dcache.h>
18#include <linux/namei.h> 19#include <linux/namei.h>
20#include <linux/fs.h>
19 21
20#include <asm/uaccess.h> 22#include <asm/uaccess.h>
21 23
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4cecdafeb87d..7fc692a8f5b0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -6,8 +6,7 @@ menu "Misc devices"
6 6
7config IBM_ASM 7config IBM_ASM
8 tristate "Device driver for IBM RSA service processor" 8 tristate "Device driver for IBM RSA service processor"
9 depends on X86 && EXPERIMENTAL 9 depends on X86 && PCI && EXPERIMENTAL
10 default n
11 ---help--- 10 ---help---
12 This option enables device driver support for in-band access to the 11 This option enables device driver support for in-band access to the
13 IBM RSA (Condor) service processor in eServer xSeries systems. 12 IBM RSA (Condor) service processor in eServer xSeries systems.
@@ -22,7 +21,7 @@ config IBM_ASM
22 21
23 WARNING: This software may not be supported or function 22 WARNING: This software may not be supported or function
24 correctly on your IBM server. Please consult the IBM ServerProven 23 correctly on your IBM server. Please consult the IBM ServerProven
25 website <http://www.pc.ibm/ww/eserver/xseries/serverproven> for 24 website <http://www.pc.ibm.com/ww/eserver/xseries/serverproven> for
26 information on the specific driver level and support statement 25 information on the specific driver level and support statement
27 for your IBM server. 26 for your IBM server.
28 27
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index 3a5f6ac5b364..7a42966d755b 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -20,6 +20,7 @@
20#include <linux/mmc/host.h> 20#include <linux/mmc/host.h>
21#include <linux/mmc/protocol.h> 21#include <linux/mmc/protocol.h>
22 22
23#include <asm/div64.h>
23#include <asm/io.h> 24#include <asm/io.h>
24#include <asm/irq.h> 25#include <asm/irq.h>
25#include <asm/scatterlist.h> 26#include <asm/scatterlist.h>
@@ -70,6 +71,7 @@ static void mmci_stop_data(struct mmci_host *host)
70static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) 71static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
71{ 72{
72 unsigned int datactrl, timeout, irqmask; 73 unsigned int datactrl, timeout, irqmask;
74 unsigned long long clks;
73 void __iomem *base; 75 void __iomem *base;
74 76
75 DBG(host, "blksz %04x blks %04x flags %08x\n", 77 DBG(host, "blksz %04x blks %04x flags %08x\n",
@@ -81,9 +83,10 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
81 83
82 mmci_init_sg(host, data); 84 mmci_init_sg(host, data);
83 85
84 timeout = data->timeout_clks + 86 clks = (unsigned long long)data->timeout_ns * host->cclk;
85 ((unsigned long long)data->timeout_ns * host->cclk) / 87 do_div(clks, 1000000000UL);
86 1000000000ULL; 88
89 timeout = data->timeout_clks + (unsigned int)clks;
87 90
88 base = host->base; 91 base = host->base;
89 writel(timeout, base + MMCIDATATIMER); 92 writel(timeout, base + MMCIDATATIMER);
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index b7fbd30b49a0..0c41d4b41a65 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -54,28 +54,6 @@
54#define DBGF(x...) do { } while (0) 54#define DBGF(x...) do { } while (0)
55#endif 55#endif
56 56
57#ifdef CONFIG_MMC_DEBUG
58void DBG_REG(int reg, u8 value)
59{
60 int i;
61
62 printk(KERN_DEBUG "wbsd: Register %d: 0x%02X %3d '%c' ",
63 reg, (int)value, (int)value, (value < 0x20)?'.':value);
64
65 for (i = 7;i >= 0;i--)
66 {
67 if (value & (1 << i))
68 printk("x");
69 else
70 printk(".");
71 }
72
73 printk("\n");
74}
75#else
76#define DBG_REG(r, v) do {} while (0)
77#endif
78
79/* 57/*
80 * Device resources 58 * Device resources
81 */ 59 */
@@ -92,6 +70,13 @@ MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
92 70
93#endif /* CONFIG_PNP */ 71#endif /* CONFIG_PNP */
94 72
73static const int config_ports[] = { 0x2E, 0x4E };
74static const int unlock_codes[] = { 0x83, 0x87 };
75
76static const int valid_ids[] = {
77 0x7112,
78 };
79
95#ifdef CONFIG_PNP 80#ifdef CONFIG_PNP
96static unsigned int nopnp = 0; 81static unsigned int nopnp = 0;
97#else 82#else
@@ -1051,6 +1036,20 @@ static struct mmc_host_ops wbsd_ops = {
1051\*****************************************************************************/ 1036\*****************************************************************************/
1052 1037
1053/* 1038/*
1039 * Helper function for card detection
1040 */
1041static void wbsd_detect_card(unsigned long data)
1042{
1043 struct wbsd_host *host = (struct wbsd_host*)data;
1044
1045 BUG_ON(host == NULL);
1046
1047 DBG("Executing card detection\n");
1048
1049 mmc_detect_change(host->mmc);
1050}
1051
1052/*
1054 * Tasklets 1053 * Tasklets
1055 */ 1054 */
1056 1055
@@ -1075,7 +1074,6 @@ static void wbsd_tasklet_card(unsigned long param)
1075{ 1074{
1076 struct wbsd_host* host = (struct wbsd_host*)param; 1075 struct wbsd_host* host = (struct wbsd_host*)param;
1077 u8 csr; 1076 u8 csr;
1078 int change = 0;
1079 1077
1080 spin_lock(&host->lock); 1078 spin_lock(&host->lock);
1081 1079
@@ -1094,14 +1092,20 @@ static void wbsd_tasklet_card(unsigned long param)
1094 { 1092 {
1095 DBG("Card inserted\n"); 1093 DBG("Card inserted\n");
1096 host->flags |= WBSD_FCARD_PRESENT; 1094 host->flags |= WBSD_FCARD_PRESENT;
1097 change = 1; 1095
1096 /*
1097 * Delay card detection to allow electrical connections
1098 * to stabilise.
1099 */
1100 mod_timer(&host->timer, jiffies + HZ/2);
1098 } 1101 }
1102
1103 spin_unlock(&host->lock);
1099 } 1104 }
1100 else if (host->flags & WBSD_FCARD_PRESENT) 1105 else if (host->flags & WBSD_FCARD_PRESENT)
1101 { 1106 {
1102 DBG("Card removed\n"); 1107 DBG("Card removed\n");
1103 host->flags &= ~WBSD_FCARD_PRESENT; 1108 host->flags &= ~WBSD_FCARD_PRESENT;
1104 change = 1;
1105 1109
1106 if (host->mrq) 1110 if (host->mrq)
1107 { 1111 {
@@ -1112,15 +1116,14 @@ static void wbsd_tasklet_card(unsigned long param)
1112 host->mrq->cmd->error = MMC_ERR_FAILED; 1116 host->mrq->cmd->error = MMC_ERR_FAILED;
1113 tasklet_schedule(&host->finish_tasklet); 1117 tasklet_schedule(&host->finish_tasklet);
1114 } 1118 }
1115 } 1119
1116 1120 /*
1117 /* 1121 * Unlock first since we might get a call back.
1118 * Unlock first since we might get a call back. 1122 */
1119 */ 1123 spin_unlock(&host->lock);
1120 spin_unlock(&host->lock);
1121 1124
1122 if (change)
1123 mmc_detect_change(host->mmc); 1125 mmc_detect_change(host->mmc);
1126 }
1124} 1127}
1125 1128
1126static void wbsd_tasklet_fifo(unsigned long param) 1129static void wbsd_tasklet_fifo(unsigned long param)
@@ -1325,6 +1328,13 @@ static int __devinit wbsd_alloc_mmc(struct device* dev)
1325 spin_lock_init(&host->lock); 1328 spin_lock_init(&host->lock);
1326 1329
1327 /* 1330 /*
1331 * Set up detection timer
1332 */
1333 init_timer(&host->timer);
1334 host->timer.data = (unsigned long)host;
1335 host->timer.function = wbsd_detect_card;
1336
1337 /*
1328 * Maximum number of segments. Worst case is one sector per segment 1338 * Maximum number of segments. Worst case is one sector per segment
1329 * so this will be 64kB/512. 1339 * so this will be 64kB/512.
1330 */ 1340 */
@@ -1351,11 +1361,17 @@ static int __devinit wbsd_alloc_mmc(struct device* dev)
1351static void __devexit wbsd_free_mmc(struct device* dev) 1361static void __devexit wbsd_free_mmc(struct device* dev)
1352{ 1362{
1353 struct mmc_host* mmc; 1363 struct mmc_host* mmc;
1364 struct wbsd_host* host;
1354 1365
1355 mmc = dev_get_drvdata(dev); 1366 mmc = dev_get_drvdata(dev);
1356 if (!mmc) 1367 if (!mmc)
1357 return; 1368 return;
1358 1369
1370 host = mmc_priv(mmc);
1371 BUG_ON(host == NULL);
1372
1373 del_timer_sync(&host->timer);
1374
1359 mmc_free_host(mmc); 1375 mmc_free_host(mmc);
1360 1376
1361 dev_set_drvdata(dev, NULL); 1377 dev_set_drvdata(dev, NULL);
diff --git a/drivers/mmc/wbsd.h b/drivers/mmc/wbsd.h
index 864f30828d01..661a9f6a6e6f 100644
--- a/drivers/mmc/wbsd.h
+++ b/drivers/mmc/wbsd.h
@@ -8,13 +8,6 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11const int config_ports[] = { 0x2E, 0x4E };
12const int unlock_codes[] = { 0x83, 0x87 };
13
14const int valid_ids[] = {
15 0x7112,
16 };
17
18#define LOCK_CODE 0xAA 11#define LOCK_CODE 0xAA
19 12
20#define WBSD_CONF_SWRST 0x02 13#define WBSD_CONF_SWRST 0x02
@@ -187,4 +180,6 @@ struct wbsd_host
187 struct tasklet_struct timeout_tasklet; 180 struct tasklet_struct timeout_tasklet;
188 struct tasklet_struct finish_tasklet; 181 struct tasklet_struct finish_tasklet;
189 struct tasklet_struct block_tasklet; 182 struct tasklet_struct block_tasklet;
183
184 struct timer_list timer; /* Card detection timer */
190}; 185};
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 801e6c7d0892..7363e101eb0f 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -219,7 +219,7 @@ static int parse_afs_partitions(struct mtd_info *mtd,
219 */ 219 */
220 for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { 220 for (idx = off = 0; off < mtd->size; off += mtd->erasesize) {
221 struct image_info_struct iis; 221 struct image_info_struct iis;
222 u_int iis_ptr, img_ptr, size; 222 u_int iis_ptr, img_ptr;
223 223
224 /* Read the footer. */ 224 /* Read the footer. */
225 ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask); 225 ret = afs_read_footer(mtd, &img_ptr, &iis_ptr, off, mask);
@@ -236,21 +236,9 @@ static int parse_afs_partitions(struct mtd_info *mtd,
236 continue; 236 continue;
237 237
238 strcpy(str, iis.name); 238 strcpy(str, iis.name);
239 size = mtd->erasesize + off - img_ptr;
240
241 /*
242 * In order to support JFFS2 partitions on this layout,
243 * we must lie to MTD about the real size of JFFS2
244 * partitions; this ensures that the AFS flash footer
245 * won't be erased by JFFS2. Please ensure that your
246 * JFFS2 partitions are given image numbers between
247 * 1000 and 2000 inclusive.
248 */
249 if (iis.imageNumber >= 1000 && iis.imageNumber < 2000)
250 size -= mtd->erasesize;
251 239
252 parts[idx].name = str; 240 parts[idx].name = str;
253 parts[idx].size = size; 241 parts[idx].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1);
254 parts[idx].offset = img_ptr; 242 parts[idx].offset = img_ptr;
255 parts[idx].mask_flags = 0; 243 parts[idx].mask_flags = 0;
256 244
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index d682dbc8157e..df95d2158b16 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/chips/Kconfig 1# drivers/mtd/chips/Kconfig
2# $Id: Kconfig,v 1.13 2004/12/01 15:49:10 nico Exp $ 2# $Id: Kconfig,v 1.15 2005/06/06 23:04:35 tpoynor Exp $
3 3
4menu "RAM/ROM/Flash chip drivers" 4menu "RAM/ROM/Flash chip drivers"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -155,6 +155,31 @@ config MTD_CFI_I8
155 If your flash chips are interleaved in eights - i.e. you have eight 155 If your flash chips are interleaved in eights - i.e. you have eight
156 flash chips addressed by each bus cycle, then say 'Y'. 156 flash chips addressed by each bus cycle, then say 'Y'.
157 157
158config MTD_OTP
159 bool "Protection Registers aka one-time programmable (OTP) bits"
160 depends on MTD_CFI_ADV_OPTIONS
161 default n
162 help
163 This enables support for reading, writing and locking so called
164 "Protection Registers" present on some flash chips.
165 A subset of them are pre-programmed at the factory with a
166 unique set of values. The rest is user-programmable.
167
168 The user-programmable Protection Registers contain one-time
169 programmable (OTP) bits; when programmed, register bits cannot be
170 erased. Each Protection Register can be accessed multiple times to
171 program individual bits, as long as the register remains unlocked.
172
173 Each Protection Register has an associated Lock Register bit. When a
174 Lock Register bit is programmed, the associated Protection Register
175 can only be read; it can no longer be programmed. Additionally,
176 because the Lock Register bits themselves are OTP, when programmed,
177 Lock Register bits cannot be erased. Therefore, when a Protection
178 Register is locked, it cannot be unlocked.
179
180 This feature should therefore be used with extreme care. Any mistake
181 in the programming of OTP bits will waste them.
182
158config MTD_CFI_INTELEXT 183config MTD_CFI_INTELEXT
159 tristate "Support for Intel/Sharp flash chips" 184 tristate "Support for Intel/Sharp flash chips"
160 depends on MTD_GEN_PROBE 185 depends on MTD_GEN_PROBE
@@ -275,7 +300,7 @@ config MTD_JEDEC
275 300
276config MTD_XIP 301config MTD_XIP
277 bool "XIP aware MTD support" 302 bool "XIP aware MTD support"
278 depends on !SMP && MTD_CFI_INTELEXT && EXPERIMENTAL 303 depends on !SMP && (MTD_CFI_INTELEXT || MTD_CFI_AMDSTD) && EXPERIMENTAL && ARM
279 default y if XIP_KERNEL 304 default y if XIP_KERNEL
280 help 305 help
281 This allows MTD support to work with flash memory which is also 306 This allows MTD support to work with flash memory which is also
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index 41e2e3e31603..2dafeba3f3d5 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Jonas Holmberg <jonas.holmberg@axis.com> 4 * Author: Jonas Holmberg <jonas.holmberg@axis.com>
5 * 5 *
6 * $Id: amd_flash.c,v 1.26 2004/11/20 12:49:04 dwmw2 Exp $ 6 * $Id: amd_flash.c,v 1.27 2005/02/04 07:43:09 jonashg Exp $
7 * 7 *
8 * Copyright (c) 2001 Axis Communications AB 8 * Copyright (c) 2001 Axis Communications AB
9 * 9 *
@@ -67,7 +67,6 @@
67#define AM29LV160DT 0x22C4 67#define AM29LV160DT 0x22C4
68#define AM29LV160DB 0x2249 68#define AM29LV160DB 0x2249
69#define AM29BDS323D 0x22D1 69#define AM29BDS323D 0x22D1
70#define AM29BDS643D 0x227E
71 70
72/* Atmel */ 71/* Atmel */
73#define AT49xV16x 0x00C0 72#define AT49xV16x 0x00C0
@@ -618,17 +617,6 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
618 { .offset = 0x3f0000, .erasesize = 0x02000, .numblocks = 8 }, 617 { .offset = 0x3f0000, .erasesize = 0x02000, .numblocks = 8 },
619 } 618 }
620 }, { 619 }, {
621 .mfr_id = MANUFACTURER_AMD,
622 .dev_id = AM29BDS643D,
623 .name = "AMD AM29BDS643D",
624 .size = 0x00800000,
625 .numeraseregions = 3,
626 .regions = {
627 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 96 },
628 { .offset = 0x600000, .erasesize = 0x10000, .numblocks = 31 },
629 { .offset = 0x7f0000, .erasesize = 0x02000, .numblocks = 8 },
630 }
631 }, {
632 .mfr_id = MANUFACTURER_ATMEL, 620 .mfr_id = MANUFACTURER_ATMEL,
633 .dev_id = AT49xV16x, 621 .dev_id = AT49xV16x,
634 .name = "Atmel AT49xV16x", 622 .name = "Atmel AT49xV16x",
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index c268bcd71720..0cfcd88468e0 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * (C) 2000 Red Hat. GPL'd 5 * (C) 2000 Red Hat. GPL'd
6 * 6 *
7 * $Id: cfi_cmdset_0001.c,v 1.164 2004/11/16 18:29:00 dwmw2 Exp $ 7 * $Id: cfi_cmdset_0001.c,v 1.178 2005/05/19 17:05:43 nico Exp $
8 * 8 *
9 * 9 *
10 * 10/10/2000 Nicolas Pitre <nico@cam.org> 10 * 10/10/2000 Nicolas Pitre <nico@cam.org>
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/reboot.h>
32#include <linux/mtd/xip.h> 33#include <linux/mtd/xip.h>
33#include <linux/mtd/map.h> 34#include <linux/mtd/map.h>
34#include <linux/mtd/mtd.h> 35#include <linux/mtd/mtd.h>
@@ -48,16 +49,25 @@
48#define M50LPW080 0x002F 49#define M50LPW080 0x002F
49 50
50static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 51static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
51//static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
52//static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
53static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 52static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
54static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 53static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
55static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *); 54static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
56static void cfi_intelext_sync (struct mtd_info *); 55static void cfi_intelext_sync (struct mtd_info *);
57static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len); 56static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len);
58static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len); 57static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len);
58#ifdef CONFIG_MTD_OTP
59static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
60static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
61static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
62static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t);
63static int cfi_intelext_get_fact_prot_info (struct mtd_info *,
64 struct otp_info *, size_t);
65static int cfi_intelext_get_user_prot_info (struct mtd_info *,
66 struct otp_info *, size_t);
67#endif
59static int cfi_intelext_suspend (struct mtd_info *); 68static int cfi_intelext_suspend (struct mtd_info *);
60static void cfi_intelext_resume (struct mtd_info *); 69static void cfi_intelext_resume (struct mtd_info *);
70static int cfi_intelext_reboot (struct notifier_block *, unsigned long, void *);
61 71
62static void cfi_intelext_destroy(struct mtd_info *); 72static void cfi_intelext_destroy(struct mtd_info *);
63 73
@@ -252,7 +262,8 @@ read_pri_intelext(struct map_info *map, __u16 adr)
252 int nb_parts, i; 262 int nb_parts, i;
253 263
254 /* Protection Register info */ 264 /* Protection Register info */
255 extra_size += (extp->NumProtectionFields - 1) * (4 + 6); 265 extra_size += (extp->NumProtectionFields - 1) *
266 sizeof(struct cfi_intelext_otpinfo);
256 267
257 /* Burst Read info */ 268 /* Burst Read info */
258 extra_size += 6; 269 extra_size += 6;
@@ -324,7 +335,9 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
324 mtd->resume = cfi_intelext_resume; 335 mtd->resume = cfi_intelext_resume;
325 mtd->flags = MTD_CAP_NORFLASH; 336 mtd->flags = MTD_CAP_NORFLASH;
326 mtd->name = map->name; 337 mtd->name = map->name;
327 338
339 mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
340
328 if (cfi->cfi_mode == CFI_MODE_CFI) { 341 if (cfi->cfi_mode == CFI_MODE_CFI) {
329 /* 342 /*
330 * It's a real CFI chip, not one for which the probe 343 * It's a real CFI chip, not one for which the probe
@@ -422,9 +435,13 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
422 mtd->eraseregions[i].numblocks); 435 mtd->eraseregions[i].numblocks);
423 } 436 }
424 437
425#if 0 438#ifdef CONFIG_MTD_OTP
426 mtd->read_user_prot_reg = cfi_intelext_read_user_prot_reg;
427 mtd->read_fact_prot_reg = cfi_intelext_read_fact_prot_reg; 439 mtd->read_fact_prot_reg = cfi_intelext_read_fact_prot_reg;
440 mtd->read_user_prot_reg = cfi_intelext_read_user_prot_reg;
441 mtd->write_user_prot_reg = cfi_intelext_write_user_prot_reg;
442 mtd->lock_user_prot_reg = cfi_intelext_lock_user_prot_reg;
443 mtd->get_fact_prot_info = cfi_intelext_get_fact_prot_info;
444 mtd->get_user_prot_info = cfi_intelext_get_user_prot_info;
428#endif 445#endif
429 446
430 /* This function has the potential to distort the reality 447 /* This function has the potential to distort the reality
@@ -433,6 +450,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
433 goto setup_err; 450 goto setup_err;
434 451
435 __module_get(THIS_MODULE); 452 __module_get(THIS_MODULE);
453 register_reboot_notifier(&mtd->reboot_notifier);
436 return mtd; 454 return mtd;
437 455
438 setup_err: 456 setup_err:
@@ -471,7 +489,8 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
471 int offs, numregions, numparts, partshift, numvirtchips, i, j; 489 int offs, numregions, numparts, partshift, numvirtchips, i, j;
472 490
473 /* Protection Register info */ 491 /* Protection Register info */
474 offs = (extp->NumProtectionFields - 1) * (4 + 6); 492 offs = (extp->NumProtectionFields - 1) *
493 sizeof(struct cfi_intelext_otpinfo);
475 494
476 /* Burst Read info */ 495 /* Burst Read info */
477 offs += 6; 496 offs += 6;
@@ -563,7 +582,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
563 resettime: 582 resettime:
564 timeo = jiffies + HZ; 583 timeo = jiffies + HZ;
565 retry: 584 retry:
566 if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING)) { 585 if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING || mode == FL_OTP_WRITE)) {
567 /* 586 /*
568 * OK. We have possibility for contension on the write/erase 587 * OK. We have possibility for contension on the write/erase
569 * operations which are global to the real chip and not per 588 * operations which are global to the real chip and not per
@@ -807,10 +826,6 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
807 * assembly to make sure inline functions were actually inlined and that gcc 826 * assembly to make sure inline functions were actually inlined and that gcc
808 * didn't emit calls to its own support functions). Also configuring MTD CFI 827 * didn't emit calls to its own support functions). Also configuring MTD CFI
809 * support to a single buswidth and a single interleave is also recommended. 828 * support to a single buswidth and a single interleave is also recommended.
810 * Note that not only IRQs are disabled but the preemption count is also
811 * increased to prevent other locking primitives (namely spin_unlock) from
812 * decrementing the preempt count to zero and scheduling the CPU away while
813 * not in array mode.
814 */ 829 */
815 830
816static void xip_disable(struct map_info *map, struct flchip *chip, 831static void xip_disable(struct map_info *map, struct flchip *chip,
@@ -818,7 +833,6 @@ static void xip_disable(struct map_info *map, struct flchip *chip,
818{ 833{
819 /* TODO: chips with no XIP use should ignore and return */ 834 /* TODO: chips with no XIP use should ignore and return */
820 (void) map_read(map, adr); /* ensure mmu mapping is up to date */ 835 (void) map_read(map, adr); /* ensure mmu mapping is up to date */
821 preempt_disable();
822 local_irq_disable(); 836 local_irq_disable();
823} 837}
824 838
@@ -831,9 +845,8 @@ static void __xipram xip_enable(struct map_info *map, struct flchip *chip,
831 chip->state = FL_READY; 845 chip->state = FL_READY;
832 } 846 }
833 (void) map_read(map, adr); 847 (void) map_read(map, adr);
834 asm volatile (".rep 8; nop; .endr"); /* fill instruction prefetch */ 848 xip_iprefetch();
835 local_irq_enable(); 849 local_irq_enable();
836 preempt_enable();
837} 850}
838 851
839/* 852/*
@@ -909,7 +922,7 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
909 (void) map_read(map, adr); 922 (void) map_read(map, adr);
910 asm volatile (".rep 8; nop; .endr"); 923 asm volatile (".rep 8; nop; .endr");
911 local_irq_enable(); 924 local_irq_enable();
912 preempt_enable(); 925 spin_unlock(chip->mutex);
913 asm volatile (".rep 8; nop; .endr"); 926 asm volatile (".rep 8; nop; .endr");
914 cond_resched(); 927 cond_resched();
915 928
@@ -919,15 +932,15 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
919 * a suspended erase state. If so let's wait 932 * a suspended erase state. If so let's wait
920 * until it's done. 933 * until it's done.
921 */ 934 */
922 preempt_disable(); 935 spin_lock(chip->mutex);
923 while (chip->state != newstate) { 936 while (chip->state != newstate) {
924 DECLARE_WAITQUEUE(wait, current); 937 DECLARE_WAITQUEUE(wait, current);
925 set_current_state(TASK_UNINTERRUPTIBLE); 938 set_current_state(TASK_UNINTERRUPTIBLE);
926 add_wait_queue(&chip->wq, &wait); 939 add_wait_queue(&chip->wq, &wait);
927 preempt_enable(); 940 spin_unlock(chip->mutex);
928 schedule(); 941 schedule();
929 remove_wait_queue(&chip->wq, &wait); 942 remove_wait_queue(&chip->wq, &wait);
930 preempt_disable(); 943 spin_lock(chip->mutex);
931 } 944 }
932 /* Disallow XIP again */ 945 /* Disallow XIP again */
933 local_irq_disable(); 946 local_irq_disable();
@@ -956,12 +969,14 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
956 * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while 969 * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while
957 * the flash is actively programming or erasing since we have to poll for 970 * the flash is actively programming or erasing since we have to poll for
958 * the operation to complete anyway. We can't do that in a generic way with 971 * the operation to complete anyway. We can't do that in a generic way with
959 * a XIP setup so do it before the actual flash operation in this case. 972 * a XIP setup so do it before the actual flash operation in this case
973 * and stub it out from INVALIDATE_CACHE_UDELAY.
960 */ 974 */
961#undef INVALIDATE_CACHED_RANGE 975#define XIP_INVAL_CACHED_RANGE(map, from, size) \
962#define INVALIDATE_CACHED_RANGE(x...) 976 INVALIDATE_CACHED_RANGE(map, from, size)
963#define XIP_INVAL_CACHED_RANGE(map, from, size) \ 977
964 do { if(map->inval_cache) map->inval_cache(map, from, size); } while(0) 978#define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
979 UDELAY(map, chip, adr, usec)
965 980
966/* 981/*
967 * Extra notes: 982 * Extra notes:
@@ -984,11 +999,23 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
984 999
985#define xip_disable(map, chip, adr) 1000#define xip_disable(map, chip, adr)
986#define xip_enable(map, chip, adr) 1001#define xip_enable(map, chip, adr)
987
988#define UDELAY(map, chip, adr, usec) cfi_udelay(usec)
989
990#define XIP_INVAL_CACHED_RANGE(x...) 1002#define XIP_INVAL_CACHED_RANGE(x...)
991 1003
1004#define UDELAY(map, chip, adr, usec) \
1005do { \
1006 spin_unlock(chip->mutex); \
1007 cfi_udelay(usec); \
1008 spin_lock(chip->mutex); \
1009} while (0)
1010
1011#define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
1012do { \
1013 spin_unlock(chip->mutex); \
1014 INVALIDATE_CACHED_RANGE(map, adr, len); \
1015 cfi_udelay(usec); \
1016 spin_lock(chip->mutex); \
1017} while (0)
1018
992#endif 1019#endif
993 1020
994static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len) 1021static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
@@ -1176,111 +1203,11 @@ static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, siz
1176 return ret; 1203 return ret;
1177} 1204}
1178 1205
1179#if 0
1180static int __xipram cfi_intelext_read_prot_reg (struct mtd_info *mtd,
1181 loff_t from, size_t len,
1182 size_t *retlen,
1183 u_char *buf,
1184 int base_offst, int reg_sz)
1185{
1186 struct map_info *map = mtd->priv;
1187 struct cfi_private *cfi = map->fldrv_priv;
1188 struct cfi_pri_intelext *extp = cfi->cmdset_priv;
1189 struct flchip *chip;
1190 int ofs_factor = cfi->interleave * cfi->device_type;
1191 int count = len;
1192 int chip_num, offst;
1193 int ret;
1194
1195 chip_num = ((unsigned int)from/reg_sz);
1196 offst = from - (reg_sz*chip_num)+base_offst;
1197
1198 while (count) {
1199 /* Calculate which chip & protection register offset we need */
1200
1201 if (chip_num >= cfi->numchips)
1202 goto out;
1203
1204 chip = &cfi->chips[chip_num];
1205
1206 spin_lock(chip->mutex);
1207 ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
1208 if (ret) {
1209 spin_unlock(chip->mutex);
1210 return (len-count)?:ret;
1211 }
1212
1213 xip_disable(map, chip, chip->start);
1214
1215 if (chip->state != FL_JEDEC_QUERY) {
1216 map_write(map, CMD(0x90), chip->start);
1217 chip->state = FL_JEDEC_QUERY;
1218 }
1219
1220 while (count && ((offst-base_offst) < reg_sz)) {
1221 *buf = map_read8(map,(chip->start+((extp->ProtRegAddr+1)*ofs_factor)+offst));
1222 buf++;
1223 offst++;
1224 count--;
1225 }
1226
1227 xip_enable(map, chip, chip->start);
1228 put_chip(map, chip, chip->start);
1229 spin_unlock(chip->mutex);
1230
1231 /* Move on to the next chip */
1232 chip_num++;
1233 offst = base_offst;
1234 }
1235
1236 out:
1237 return len-count;
1238}
1239
1240static int cfi_intelext_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
1241{
1242 struct map_info *map = mtd->priv;
1243 struct cfi_private *cfi = map->fldrv_priv;
1244 struct cfi_pri_intelext *extp=cfi->cmdset_priv;
1245 int base_offst,reg_sz;
1246
1247 /* Check that we actually have some protection registers */
1248 if(!extp || !(extp->FeatureSupport&64)){
1249 printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name);
1250 return 0;
1251 }
1252
1253 base_offst=(1<<extp->FactProtRegSize);
1254 reg_sz=(1<<extp->UserProtRegSize);
1255
1256 return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz);
1257}
1258
1259static int cfi_intelext_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
1260{
1261 struct map_info *map = mtd->priv;
1262 struct cfi_private *cfi = map->fldrv_priv;
1263 struct cfi_pri_intelext *extp=cfi->cmdset_priv;
1264 int base_offst,reg_sz;
1265
1266 /* Check that we actually have some protection registers */
1267 if(!extp || !(extp->FeatureSupport&64)){
1268 printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name);
1269 return 0;
1270 }
1271
1272 base_offst=0;
1273 reg_sz=(1<<extp->FactProtRegSize);
1274
1275 return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz);
1276}
1277#endif
1278
1279static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, 1206static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1280 unsigned long adr, map_word datum) 1207 unsigned long adr, map_word datum, int mode)
1281{ 1208{
1282 struct cfi_private *cfi = map->fldrv_priv; 1209 struct cfi_private *cfi = map->fldrv_priv;
1283 map_word status, status_OK; 1210 map_word status, status_OK, write_cmd;
1284 unsigned long timeo; 1211 unsigned long timeo;
1285 int z, ret=0; 1212 int z, ret=0;
1286 1213
@@ -1288,9 +1215,14 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1288 1215
1289 /* Let's determine this according to the interleave only once */ 1216 /* Let's determine this according to the interleave only once */
1290 status_OK = CMD(0x80); 1217 status_OK = CMD(0x80);
1218 switch (mode) {
1219 case FL_WRITING: write_cmd = CMD(0x40); break;
1220 case FL_OTP_WRITE: write_cmd = CMD(0xc0); break;
1221 default: return -EINVAL;
1222 }
1291 1223
1292 spin_lock(chip->mutex); 1224 spin_lock(chip->mutex);
1293 ret = get_chip(map, chip, adr, FL_WRITING); 1225 ret = get_chip(map, chip, adr, mode);
1294 if (ret) { 1226 if (ret) {
1295 spin_unlock(chip->mutex); 1227 spin_unlock(chip->mutex);
1296 return ret; 1228 return ret;
@@ -1299,19 +1231,18 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1299 XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); 1231 XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map));
1300 ENABLE_VPP(map); 1232 ENABLE_VPP(map);
1301 xip_disable(map, chip, adr); 1233 xip_disable(map, chip, adr);
1302 map_write(map, CMD(0x40), adr); 1234 map_write(map, write_cmd, adr);
1303 map_write(map, datum, adr); 1235 map_write(map, datum, adr);
1304 chip->state = FL_WRITING; 1236 chip->state = mode;
1305 1237
1306 spin_unlock(chip->mutex); 1238 INVALIDATE_CACHE_UDELAY(map, chip,
1307 INVALIDATE_CACHED_RANGE(map, adr, map_bankwidth(map)); 1239 adr, map_bankwidth(map),
1308 UDELAY(map, chip, adr, chip->word_write_time); 1240 chip->word_write_time);
1309 spin_lock(chip->mutex);
1310 1241
1311 timeo = jiffies + (HZ/2); 1242 timeo = jiffies + (HZ/2);
1312 z = 0; 1243 z = 0;
1313 for (;;) { 1244 for (;;) {
1314 if (chip->state != FL_WRITING) { 1245 if (chip->state != mode) {
1315 /* Someone's suspended the write. Sleep */ 1246 /* Someone's suspended the write. Sleep */
1316 DECLARE_WAITQUEUE(wait, current); 1247 DECLARE_WAITQUEUE(wait, current);
1317 1248
@@ -1339,10 +1270,8 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1339 } 1270 }
1340 1271
1341 /* Latency issues. Drop the lock, wait a while and retry */ 1272 /* Latency issues. Drop the lock, wait a while and retry */
1342 spin_unlock(chip->mutex);
1343 z++; 1273 z++;
1344 UDELAY(map, chip, adr, 1); 1274 UDELAY(map, chip, adr, 1);
1345 spin_lock(chip->mutex);
1346 } 1275 }
1347 if (!z) { 1276 if (!z) {
1348 chip->word_write_time--; 1277 chip->word_write_time--;
@@ -1399,7 +1328,7 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1399 datum = map_word_load_partial(map, datum, buf, gap, n); 1328 datum = map_word_load_partial(map, datum, buf, gap, n);
1400 1329
1401 ret = do_write_oneword(map, &cfi->chips[chipnum], 1330 ret = do_write_oneword(map, &cfi->chips[chipnum],
1402 bus_ofs, datum); 1331 bus_ofs, datum, FL_WRITING);
1403 if (ret) 1332 if (ret)
1404 return ret; 1333 return ret;
1405 1334
@@ -1420,7 +1349,7 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1420 map_word datum = map_word_load(map, buf); 1349 map_word datum = map_word_load(map, buf);
1421 1350
1422 ret = do_write_oneword(map, &cfi->chips[chipnum], 1351 ret = do_write_oneword(map, &cfi->chips[chipnum],
1423 ofs, datum); 1352 ofs, datum, FL_WRITING);
1424 if (ret) 1353 if (ret)
1425 return ret; 1354 return ret;
1426 1355
@@ -1444,7 +1373,7 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1444 datum = map_word_load_partial(map, datum, buf, 0, len); 1373 datum = map_word_load_partial(map, datum, buf, 0, len);
1445 1374
1446 ret = do_write_oneword(map, &cfi->chips[chipnum], 1375 ret = do_write_oneword(map, &cfi->chips[chipnum],
1447 ofs, datum); 1376 ofs, datum, FL_WRITING);
1448 if (ret) 1377 if (ret)
1449 return ret; 1378 return ret;
1450 1379
@@ -1506,9 +1435,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1506 if (map_word_andequal(map, status, status_OK, status_OK)) 1435 if (map_word_andequal(map, status, status_OK, status_OK))
1507 break; 1436 break;
1508 1437
1509 spin_unlock(chip->mutex);
1510 UDELAY(map, chip, cmd_adr, 1); 1438 UDELAY(map, chip, cmd_adr, 1);
1511 spin_lock(chip->mutex);
1512 1439
1513 if (++z > 20) { 1440 if (++z > 20) {
1514 /* Argh. Not ready for write to buffer */ 1441 /* Argh. Not ready for write to buffer */
@@ -1554,10 +1481,9 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1554 map_write(map, CMD(0xd0), cmd_adr); 1481 map_write(map, CMD(0xd0), cmd_adr);
1555 chip->state = FL_WRITING; 1482 chip->state = FL_WRITING;
1556 1483
1557 spin_unlock(chip->mutex); 1484 INVALIDATE_CACHE_UDELAY(map, chip,
1558 INVALIDATE_CACHED_RANGE(map, adr, len); 1485 cmd_adr, len,
1559 UDELAY(map, chip, cmd_adr, chip->buffer_write_time); 1486 chip->buffer_write_time);
1560 spin_lock(chip->mutex);
1561 1487
1562 timeo = jiffies + (HZ/2); 1488 timeo = jiffies + (HZ/2);
1563 z = 0; 1489 z = 0;
@@ -1589,10 +1515,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1589 } 1515 }
1590 1516
1591 /* Latency issues. Drop the lock, wait a while and retry */ 1517 /* Latency issues. Drop the lock, wait a while and retry */
1592 spin_unlock(chip->mutex);
1593 UDELAY(map, chip, cmd_adr, 1);
1594 z++; 1518 z++;
1595 spin_lock(chip->mutex); 1519 UDELAY(map, chip, cmd_adr, 1);
1596 } 1520 }
1597 if (!z) { 1521 if (!z) {
1598 chip->buffer_write_time--; 1522 chip->buffer_write_time--;
@@ -1720,10 +1644,9 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1720 chip->state = FL_ERASING; 1644 chip->state = FL_ERASING;
1721 chip->erase_suspended = 0; 1645 chip->erase_suspended = 0;
1722 1646
1723 spin_unlock(chip->mutex); 1647 INVALIDATE_CACHE_UDELAY(map, chip,
1724 INVALIDATE_CACHED_RANGE(map, adr, len); 1648 adr, len,
1725 UDELAY(map, chip, adr, chip->erase_time*1000/2); 1649 chip->erase_time*1000/2);
1726 spin_lock(chip->mutex);
1727 1650
1728 /* FIXME. Use a timer to check this, and return immediately. */ 1651 /* FIXME. Use a timer to check this, and return immediately. */
1729 /* Once the state machine's known to be working I'll do that */ 1652 /* Once the state machine's known to be working I'll do that */
@@ -1768,9 +1691,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1768 } 1691 }
1769 1692
1770 /* Latency issues. Drop the lock, wait a while and retry */ 1693 /* Latency issues. Drop the lock, wait a while and retry */
1771 spin_unlock(chip->mutex);
1772 UDELAY(map, chip, adr, 1000000/HZ); 1694 UDELAY(map, chip, adr, 1000000/HZ);
1773 spin_lock(chip->mutex);
1774 } 1695 }
1775 1696
1776 /* We've broken this before. It doesn't hurt to be safe */ 1697 /* We've broken this before. It doesn't hurt to be safe */
@@ -1780,44 +1701,34 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1780 1701
1781 /* check for lock bit */ 1702 /* check for lock bit */
1782 if (map_word_bitsset(map, status, CMD(0x3a))) { 1703 if (map_word_bitsset(map, status, CMD(0x3a))) {
1783 unsigned char chipstatus; 1704 unsigned long chipstatus;
1784 1705
1785 /* Reset the error bits */ 1706 /* Reset the error bits */
1786 map_write(map, CMD(0x50), adr); 1707 map_write(map, CMD(0x50), adr);
1787 map_write(map, CMD(0x70), adr); 1708 map_write(map, CMD(0x70), adr);
1788 xip_enable(map, chip, adr); 1709 xip_enable(map, chip, adr);
1789 1710
1790 chipstatus = status.x[0]; 1711 chipstatus = MERGESTATUS(status);
1791 if (!map_word_equal(map, status, CMD(chipstatus))) {
1792 int i, w;
1793 for (w=0; w<map_words(map); w++) {
1794 for (i = 0; i<cfi_interleave(cfi); i++) {
1795 chipstatus |= status.x[w] >> (cfi->device_type * 8);
1796 }
1797 }
1798 printk(KERN_WARNING "Status is not identical for all chips: 0x%lx. Merging to give 0x%02x\n",
1799 status.x[0], chipstatus);
1800 }
1801 1712
1802 if ((chipstatus & 0x30) == 0x30) { 1713 if ((chipstatus & 0x30) == 0x30) {
1803 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%x\n", chipstatus); 1714 printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus);
1804 ret = -EIO; 1715 ret = -EIO;
1805 } else if (chipstatus & 0x02) { 1716 } else if (chipstatus & 0x02) {
1806 /* Protection bit set */ 1717 /* Protection bit set */
1807 ret = -EROFS; 1718 ret = -EROFS;
1808 } else if (chipstatus & 0x8) { 1719 } else if (chipstatus & 0x8) {
1809 /* Voltage */ 1720 /* Voltage */
1810 printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%x\n", chipstatus); 1721 printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%lx\n", chipstatus);
1811 ret = -EIO; 1722 ret = -EIO;
1812 } else if (chipstatus & 0x20) { 1723 } else if (chipstatus & 0x20) {
1813 if (retries--) { 1724 if (retries--) {
1814 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x. Retrying...\n", adr, chipstatus); 1725 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
1815 timeo = jiffies + HZ; 1726 timeo = jiffies + HZ;
1816 put_chip(map, chip, adr); 1727 put_chip(map, chip, adr);
1817 spin_unlock(chip->mutex); 1728 spin_unlock(chip->mutex);
1818 goto retry; 1729 goto retry;
1819 } 1730 }
1820 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x\n", adr, chipstatus); 1731 printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus);
1821 ret = -EIO; 1732 ret = -EIO;
1822 } 1733 }
1823 } else { 1734 } else {
@@ -1882,6 +1793,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
1882 1793
1883 if (chip->state == FL_SYNCING) { 1794 if (chip->state == FL_SYNCING) {
1884 chip->state = chip->oldstate; 1795 chip->state = chip->oldstate;
1796 chip->oldstate = FL_READY;
1885 wake_up(&chip->wq); 1797 wake_up(&chip->wq);
1886 } 1798 }
1887 spin_unlock(chip->mutex); 1799 spin_unlock(chip->mutex);
@@ -1897,8 +1809,9 @@ static int __xipram do_printlockstatus_oneblock(struct map_info *map,
1897 struct cfi_private *cfi = map->fldrv_priv; 1809 struct cfi_private *cfi = map->fldrv_priv;
1898 int status, ofs_factor = cfi->interleave * cfi->device_type; 1810 int status, ofs_factor = cfi->interleave * cfi->device_type;
1899 1811
1812 adr += chip->start;
1900 xip_disable(map, chip, adr+(2*ofs_factor)); 1813 xip_disable(map, chip, adr+(2*ofs_factor));
1901 cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL); 1814 map_write(map, CMD(0x90), adr+(2*ofs_factor));
1902 chip->state = FL_JEDEC_QUERY; 1815 chip->state = FL_JEDEC_QUERY;
1903 status = cfi_read_query(map, adr+(2*ofs_factor)); 1816 status = cfi_read_query(map, adr+(2*ofs_factor));
1904 xip_enable(map, chip, 0); 1817 xip_enable(map, chip, 0);
@@ -1915,6 +1828,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1915 unsigned long adr, int len, void *thunk) 1828 unsigned long adr, int len, void *thunk)
1916{ 1829{
1917 struct cfi_private *cfi = map->fldrv_priv; 1830 struct cfi_private *cfi = map->fldrv_priv;
1831 struct cfi_pri_intelext *extp = cfi->cmdset_priv;
1918 map_word status, status_OK; 1832 map_word status, status_OK;
1919 unsigned long timeo = jiffies + HZ; 1833 unsigned long timeo = jiffies + HZ;
1920 int ret; 1834 int ret;
@@ -1944,9 +1858,13 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1944 } else 1858 } else
1945 BUG(); 1859 BUG();
1946 1860
1947 spin_unlock(chip->mutex); 1861 /*
1948 UDELAY(map, chip, adr, 1000000/HZ); 1862 * If Instant Individual Block Locking supported then no need
1949 spin_lock(chip->mutex); 1863 * to delay.
1864 */
1865
1866 if (!extp || !(extp->FeatureSupport & (1 << 5)))
1867 UDELAY(map, chip, adr, 1000000/HZ);
1950 1868
1951 /* FIXME. Use a timer to check this, and return immediately. */ 1869 /* FIXME. Use a timer to check this, and return immediately. */
1952 /* Once the state machine's known to be working I'll do that */ 1870 /* Once the state machine's known to be working I'll do that */
@@ -1973,9 +1891,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
1973 } 1891 }
1974 1892
1975 /* Latency issues. Drop the lock, wait a while and retry */ 1893 /* Latency issues. Drop the lock, wait a while and retry */
1976 spin_unlock(chip->mutex);
1977 UDELAY(map, chip, adr, 1); 1894 UDELAY(map, chip, adr, 1);
1978 spin_lock(chip->mutex);
1979 } 1895 }
1980 1896
1981 /* Done and happy. */ 1897 /* Done and happy. */
@@ -2034,6 +1950,274 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2034 return ret; 1950 return ret;
2035} 1951}
2036 1952
1953#ifdef CONFIG_MTD_OTP
1954
1955typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
1956 u_long data_offset, u_char *buf, u_int size,
1957 u_long prot_offset, u_int groupno, u_int groupsize);
1958
1959static int __xipram
1960do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
1961 u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
1962{
1963 struct cfi_private *cfi = map->fldrv_priv;
1964 int ret;
1965
1966 spin_lock(chip->mutex);
1967 ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
1968 if (ret) {
1969 spin_unlock(chip->mutex);
1970 return ret;
1971 }
1972
1973 /* let's ensure we're not reading back cached data from array mode */
1974 INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
1975
1976 xip_disable(map, chip, chip->start);
1977 if (chip->state != FL_JEDEC_QUERY) {
1978 map_write(map, CMD(0x90), chip->start);
1979 chip->state = FL_JEDEC_QUERY;
1980 }
1981 map_copy_from(map, buf, chip->start + offset, size);
1982 xip_enable(map, chip, chip->start);
1983
1984 /* then ensure we don't keep OTP data in the cache */
1985 INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
1986
1987 put_chip(map, chip, chip->start);
1988 spin_unlock(chip->mutex);
1989 return 0;
1990}
1991
1992static int
1993do_otp_write(struct map_info *map, struct flchip *chip, u_long offset,
1994 u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
1995{
1996 int ret;
1997
1998 while (size) {
1999 unsigned long bus_ofs = offset & ~(map_bankwidth(map)-1);
2000 int gap = offset - bus_ofs;
2001 int n = min_t(int, size, map_bankwidth(map)-gap);
2002 map_word datum = map_word_ff(map);
2003
2004 datum = map_word_load_partial(map, datum, buf, gap, n);
2005 ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE);
2006 if (ret)
2007 return ret;
2008
2009 offset += n;
2010 buf += n;
2011 size -= n;
2012 }
2013
2014 return 0;
2015}
2016
2017static int
2018do_otp_lock(struct map_info *map, struct flchip *chip, u_long offset,
2019 u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
2020{
2021 struct cfi_private *cfi = map->fldrv_priv;
2022 map_word datum;
2023
2024 /* make sure area matches group boundaries */
2025 if (size != grpsz)
2026 return -EXDEV;
2027
2028 datum = map_word_ff(map);
2029 datum = map_word_clr(map, datum, CMD(1 << grpno));
2030 return do_write_oneword(map, chip, prot, datum, FL_OTP_WRITE);
2031}
2032
2033static int cfi_intelext_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
2034 size_t *retlen, u_char *buf,
2035 otp_op_t action, int user_regs)
2036{
2037 struct map_info *map = mtd->priv;
2038 struct cfi_private *cfi = map->fldrv_priv;
2039 struct cfi_pri_intelext *extp = cfi->cmdset_priv;
2040 struct flchip *chip;
2041 struct cfi_intelext_otpinfo *otp;
2042 u_long devsize, reg_prot_offset, data_offset;
2043 u_int chip_num, chip_step, field, reg_fact_size, reg_user_size;
2044 u_int groups, groupno, groupsize, reg_fact_groups, reg_user_groups;
2045 int ret;
2046
2047 *retlen = 0;
2048
2049 /* Check that we actually have some OTP registers */
2050 if (!extp || !(extp->FeatureSupport & 64) || !extp->NumProtectionFields)
2051 return -ENODATA;
2052
2053 /* we need real chips here not virtual ones */
2054 devsize = (1 << cfi->cfiq->DevSize) * cfi->interleave;
2055 chip_step = devsize >> cfi->chipshift;
2056 chip_num = 0;
2057
2058 /* Some chips have OTP located in the _top_ partition only.
2059 For example: Intel 28F256L18T (T means top-parameter device) */
2060 if (cfi->mfr == MANUFACTURER_INTEL) {
2061 switch (cfi->id) {
2062 case 0x880b:
2063 case 0x880c:
2064 case 0x880d:
2065 chip_num = chip_step - 1;
2066 }
2067 }
2068
2069 for ( ; chip_num < cfi->numchips; chip_num += chip_step) {
2070 chip = &cfi->chips[chip_num];
2071 otp = (struct cfi_intelext_otpinfo *)&extp->extra[0];
2072
2073 /* first OTP region */
2074 field = 0;
2075 reg_prot_offset = extp->ProtRegAddr;
2076 reg_fact_groups = 1;
2077 reg_fact_size = 1 << extp->FactProtRegSize;
2078 reg_user_groups = 1;
2079 reg_user_size = 1 << extp->UserProtRegSize;
2080
2081 while (len > 0) {
2082 /* flash geometry fixup */
2083 data_offset = reg_prot_offset + 1;
2084 data_offset *= cfi->interleave * cfi->device_type;
2085 reg_prot_offset *= cfi->interleave * cfi->device_type;
2086 reg_fact_size *= cfi->interleave;
2087 reg_user_size *= cfi->interleave;
2088
2089 if (user_regs) {
2090 groups = reg_user_groups;
2091 groupsize = reg_user_size;
2092 /* skip over factory reg area */
2093 groupno = reg_fact_groups;
2094 data_offset += reg_fact_groups * reg_fact_size;
2095 } else {
2096 groups = reg_fact_groups;
2097 groupsize = reg_fact_size;
2098 groupno = 0;
2099 }
2100
2101 while (len > 0 && groups > 0) {
2102 if (!action) {
2103 /*
2104 * Special case: if action is NULL
2105 * we fill buf with otp_info records.
2106 */
2107 struct otp_info *otpinfo;
2108 map_word lockword;
2109 len -= sizeof(struct otp_info);
2110 if (len <= 0)
2111 return -ENOSPC;
2112 ret = do_otp_read(map, chip,
2113 reg_prot_offset,
2114 (u_char *)&lockword,
2115 map_bankwidth(map),
2116 0, 0, 0);
2117 if (ret)
2118 return ret;
2119 otpinfo = (struct otp_info *)buf;
2120 otpinfo->start = from;
2121 otpinfo->length = groupsize;
2122 otpinfo->locked =
2123 !map_word_bitsset(map, lockword,
2124 CMD(1 << groupno));
2125 from += groupsize;
2126 buf += sizeof(*otpinfo);
2127 *retlen += sizeof(*otpinfo);
2128 } else if (from >= groupsize) {
2129 from -= groupsize;
2130 data_offset += groupsize;
2131 } else {
2132 int size = groupsize;
2133 data_offset += from;
2134 size -= from;
2135 from = 0;
2136 if (size > len)
2137 size = len;
2138 ret = action(map, chip, data_offset,
2139 buf, size, reg_prot_offset,
2140 groupno, groupsize);
2141 if (ret < 0)
2142 return ret;
2143 buf += size;
2144 len -= size;
2145 *retlen += size;
2146 data_offset += size;
2147 }
2148 groupno++;
2149 groups--;
2150 }
2151
2152 /* next OTP region */
2153 if (++field == extp->NumProtectionFields)
2154 break;
2155 reg_prot_offset = otp->ProtRegAddr;
2156 reg_fact_groups = otp->FactGroups;
2157 reg_fact_size = 1 << otp->FactProtRegSize;
2158 reg_user_groups = otp->UserGroups;
2159 reg_user_size = 1 << otp->UserProtRegSize;
2160 otp++;
2161 }
2162 }
2163
2164 return 0;
2165}
2166
2167static int cfi_intelext_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
2168 size_t len, size_t *retlen,
2169 u_char *buf)
2170{
2171 return cfi_intelext_otp_walk(mtd, from, len, retlen,
2172 buf, do_otp_read, 0);
2173}
2174
2175static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
2176 size_t len, size_t *retlen,
2177 u_char *buf)
2178{
2179 return cfi_intelext_otp_walk(mtd, from, len, retlen,
2180 buf, do_otp_read, 1);
2181}
2182
2183static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
2184 size_t len, size_t *retlen,
2185 u_char *buf)
2186{
2187 return cfi_intelext_otp_walk(mtd, from, len, retlen,
2188 buf, do_otp_write, 1);
2189}
2190
2191static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,
2192 loff_t from, size_t len)
2193{
2194 size_t retlen;
2195 return cfi_intelext_otp_walk(mtd, from, len, &retlen,
2196 NULL, do_otp_lock, 1);
2197}
2198
2199static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd,
2200 struct otp_info *buf, size_t len)
2201{
2202 size_t retlen;
2203 int ret;
2204
2205 ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0);
2206 return ret ? : retlen;
2207}
2208
2209static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd,
2210 struct otp_info *buf, size_t len)
2211{
2212 size_t retlen;
2213 int ret;
2214
2215 ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1);
2216 return ret ? : retlen;
2217}
2218
2219#endif
2220
2037static int cfi_intelext_suspend(struct mtd_info *mtd) 2221static int cfi_intelext_suspend(struct mtd_info *mtd)
2038{ 2222{
2039 struct map_info *map = mtd->priv; 2223 struct map_info *map = mtd->priv;
@@ -2125,10 +2309,46 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
2125 } 2309 }
2126} 2310}
2127 2311
2312static int cfi_intelext_reset(struct mtd_info *mtd)
2313{
2314 struct map_info *map = mtd->priv;
2315 struct cfi_private *cfi = map->fldrv_priv;
2316 int i, ret;
2317
2318 for (i=0; i < cfi->numchips; i++) {
2319 struct flchip *chip = &cfi->chips[i];
2320
2321 /* force the completion of any ongoing operation
2322 and switch to array mode so any bootloader in
2323 flash is accessible for soft reboot. */
2324 spin_lock(chip->mutex);
2325 ret = get_chip(map, chip, chip->start, FL_SYNCING);
2326 if (!ret) {
2327 map_write(map, CMD(0xff), chip->start);
2328 chip->state = FL_READY;
2329 }
2330 spin_unlock(chip->mutex);
2331 }
2332
2333 return 0;
2334}
2335
2336static int cfi_intelext_reboot(struct notifier_block *nb, unsigned long val,
2337 void *v)
2338{
2339 struct mtd_info *mtd;
2340
2341 mtd = container_of(nb, struct mtd_info, reboot_notifier);
2342 cfi_intelext_reset(mtd);
2343 return NOTIFY_DONE;
2344}
2345
2128static void cfi_intelext_destroy(struct mtd_info *mtd) 2346static void cfi_intelext_destroy(struct mtd_info *mtd)
2129{ 2347{
2130 struct map_info *map = mtd->priv; 2348 struct map_info *map = mtd->priv;
2131 struct cfi_private *cfi = map->fldrv_priv; 2349 struct cfi_private *cfi = map->fldrv_priv;
2350 cfi_intelext_reset(mtd);
2351 unregister_reboot_notifier(&mtd->reboot_notifier);
2132 kfree(cfi->cmdset_priv); 2352 kfree(cfi->cmdset_priv);
2133 kfree(cfi->cfiq); 2353 kfree(cfi->cfiq);
2134 kfree(cfi->chips[0].priv); 2354 kfree(cfi->chips[0].priv);
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index fca8ff6f7e14..8505f118f2db 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -4,16 +4,20 @@
4 * 4 *
5 * Copyright (C) 2000 Crossnet Co. <info@crossnet.co.jp> 5 * Copyright (C) 2000 Crossnet Co. <info@crossnet.co.jp>
6 * Copyright (C) 2004 Arcom Control Systems Ltd <linux@arcom.com> 6 * Copyright (C) 2004 Arcom Control Systems Ltd <linux@arcom.com>
7 * Copyright (C) 2005 MontaVista Software Inc. <source@mvista.com>
7 * 8 *
8 * 2_by_8 routines added by Simon Munton 9 * 2_by_8 routines added by Simon Munton
9 * 10 *
10 * 4_by_16 work by Carolyn J. Smith 11 * 4_by_16 work by Carolyn J. Smith
11 * 12 *
13 * XIP support hooks by Vitaly Wool (based on code for Intel flash
14 * by Nicolas Pitre)
15 *
12 * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com 16 * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com
13 * 17 *
14 * This code is GPL 18 * This code is GPL
15 * 19 *
16 * $Id: cfi_cmdset_0002.c,v 1.114 2004/12/11 15:43:53 dedekind Exp $ 20 * $Id: cfi_cmdset_0002.c,v 1.118 2005/07/04 22:34:29 gleixner Exp $
17 * 21 *
18 */ 22 */
19 23
@@ -34,6 +38,7 @@
34#include <linux/mtd/map.h> 38#include <linux/mtd/map.h>
35#include <linux/mtd/mtd.h> 39#include <linux/mtd/mtd.h>
36#include <linux/mtd/cfi.h> 40#include <linux/mtd/cfi.h>
41#include <linux/mtd/xip.h>
37 42
38#define AMD_BOOTLOC_BUG 43#define AMD_BOOTLOC_BUG
39#define FORCE_WORD_WRITE 0 44#define FORCE_WORD_WRITE 0
@@ -43,6 +48,7 @@
43#define MANUFACTURER_AMD 0x0001 48#define MANUFACTURER_AMD 0x0001
44#define MANUFACTURER_SST 0x00BF 49#define MANUFACTURER_SST 0x00BF
45#define SST49LF004B 0x0060 50#define SST49LF004B 0x0060
51#define SST49LF008A 0x005a
46 52
47static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 53static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
48static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 54static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
@@ -191,6 +197,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
191}; 197};
192static struct cfi_fixup jedec_fixup_table[] = { 198static struct cfi_fixup jedec_fixup_table[] = {
193 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, }, 199 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, },
200 { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, },
194 { 0, 0, NULL, NULL } 201 { 0, 0, NULL, NULL }
195}; 202};
196 203
@@ -391,7 +398,7 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
391 * correctly and is therefore not done (particulary with interleaved chips 398 * correctly and is therefore not done (particulary with interleaved chips
392 * as each chip must be checked independantly of the others). 399 * as each chip must be checked independantly of the others).
393 */ 400 */
394static int chip_ready(struct map_info *map, unsigned long addr) 401static int __xipram chip_ready(struct map_info *map, unsigned long addr)
395{ 402{
396 map_word d, t; 403 map_word d, t;
397 404
@@ -401,6 +408,32 @@ static int chip_ready(struct map_info *map, unsigned long addr)
401 return map_word_equal(map, d, t); 408 return map_word_equal(map, d, t);
402} 409}
403 410
411/*
412 * Return true if the chip is ready and has the correct value.
413 *
414 * Ready is one of: read mode, query mode, erase-suspend-read mode (in any
415 * non-suspended sector) and it is indicated by no bits toggling.
416 *
417 * Error are indicated by toggling bits or bits held with the wrong value,
418 * or with bits toggling.
419 *
420 * Note that anything more complicated than checking if no bits are toggling
421 * (including checking DQ5 for an error status) is tricky to get working
422 * correctly and is therefore not done (particulary with interleaved chips
423 * as each chip must be checked independantly of the others).
424 *
425 */
426static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word expected)
427{
428 map_word oldd, curd;
429
430 oldd = map_read(map, addr);
431 curd = map_read(map, addr);
432
433 return map_word_equal(map, oldd, curd) &&
434 map_word_equal(map, curd, expected);
435}
436
404static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode) 437static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode)
405{ 438{
406 DECLARE_WAITQUEUE(wait, current); 439 DECLARE_WAITQUEUE(wait, current);
@@ -420,12 +453,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
420 453
421 if (time_after(jiffies, timeo)) { 454 if (time_after(jiffies, timeo)) {
422 printk(KERN_ERR "Waiting for chip to be ready timed out.\n"); 455 printk(KERN_ERR "Waiting for chip to be ready timed out.\n");
423 cfi_spin_unlock(chip->mutex); 456 spin_unlock(chip->mutex);
424 return -EIO; 457 return -EIO;
425 } 458 }
426 cfi_spin_unlock(chip->mutex); 459 spin_unlock(chip->mutex);
427 cfi_udelay(1); 460 cfi_udelay(1);
428 cfi_spin_lock(chip->mutex); 461 spin_lock(chip->mutex);
429 /* Someone else might have been playing with it. */ 462 /* Someone else might have been playing with it. */
430 goto retry; 463 goto retry;
431 } 464 }
@@ -473,15 +506,23 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
473 return -EIO; 506 return -EIO;
474 } 507 }
475 508
476 cfi_spin_unlock(chip->mutex); 509 spin_unlock(chip->mutex);
477 cfi_udelay(1); 510 cfi_udelay(1);
478 cfi_spin_lock(chip->mutex); 511 spin_lock(chip->mutex);
479 /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING. 512 /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING.
480 So we can just loop here. */ 513 So we can just loop here. */
481 } 514 }
482 chip->state = FL_READY; 515 chip->state = FL_READY;
483 return 0; 516 return 0;
484 517
518 case FL_XIP_WHILE_ERASING:
519 if (mode != FL_READY && mode != FL_POINT &&
520 (!cfip || !(cfip->EraseSuspend&2)))
521 goto sleep;
522 chip->oldstate = chip->state;
523 chip->state = FL_READY;
524 return 0;
525
485 case FL_POINT: 526 case FL_POINT:
486 /* Only if there's no operation suspended... */ 527 /* Only if there's no operation suspended... */
487 if (mode == FL_READY && chip->oldstate == FL_READY) 528 if (mode == FL_READY && chip->oldstate == FL_READY)
@@ -491,10 +532,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
491 sleep: 532 sleep:
492 set_current_state(TASK_UNINTERRUPTIBLE); 533 set_current_state(TASK_UNINTERRUPTIBLE);
493 add_wait_queue(&chip->wq, &wait); 534 add_wait_queue(&chip->wq, &wait);
494 cfi_spin_unlock(chip->mutex); 535 spin_unlock(chip->mutex);
495 schedule(); 536 schedule();
496 remove_wait_queue(&chip->wq, &wait); 537 remove_wait_queue(&chip->wq, &wait);
497 cfi_spin_lock(chip->mutex); 538 spin_lock(chip->mutex);
498 goto resettime; 539 goto resettime;
499 } 540 }
500} 541}
@@ -512,6 +553,11 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
512 chip->state = FL_ERASING; 553 chip->state = FL_ERASING;
513 break; 554 break;
514 555
556 case FL_XIP_WHILE_ERASING:
557 chip->state = chip->oldstate;
558 chip->oldstate = FL_READY;
559 break;
560
515 case FL_READY: 561 case FL_READY:
516 case FL_STATUS: 562 case FL_STATUS:
517 /* We should really make set_vpp() count, rather than doing this */ 563 /* We should really make set_vpp() count, rather than doing this */
@@ -523,6 +569,198 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
523 wake_up(&chip->wq); 569 wake_up(&chip->wq);
524} 570}
525 571
572#ifdef CONFIG_MTD_XIP
573
574/*
575 * No interrupt what so ever can be serviced while the flash isn't in array
576 * mode. This is ensured by the xip_disable() and xip_enable() functions
577 * enclosing any code path where the flash is known not to be in array mode.
578 * And within a XIP disabled code path, only functions marked with __xipram
579 * may be called and nothing else (it's a good thing to inspect generated
580 * assembly to make sure inline functions were actually inlined and that gcc
581 * didn't emit calls to its own support functions). Also configuring MTD CFI
582 * support to a single buswidth and a single interleave is also recommended.
583 */
584
585static void xip_disable(struct map_info *map, struct flchip *chip,
586 unsigned long adr)
587{
588 /* TODO: chips with no XIP use should ignore and return */
589 (void) map_read(map, adr); /* ensure mmu mapping is up to date */
590 local_irq_disable();
591}
592
593static void __xipram xip_enable(struct map_info *map, struct flchip *chip,
594 unsigned long adr)
595{
596 struct cfi_private *cfi = map->fldrv_priv;
597
598 if (chip->state != FL_POINT && chip->state != FL_READY) {
599 map_write(map, CMD(0xf0), adr);
600 chip->state = FL_READY;
601 }
602 (void) map_read(map, adr);
603 xip_iprefetch();
604 local_irq_enable();
605}
606
607/*
608 * When a delay is required for the flash operation to complete, the
609 * xip_udelay() function is polling for both the given timeout and pending
610 * (but still masked) hardware interrupts. Whenever there is an interrupt
611 * pending then the flash erase operation is suspended, array mode restored
612 * and interrupts unmasked. Task scheduling might also happen at that
613 * point. The CPU eventually returns from the interrupt or the call to
614 * schedule() and the suspended flash operation is resumed for the remaining
615 * of the delay period.
616 *
617 * Warning: this function _will_ fool interrupt latency tracing tools.
618 */
619
620static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
621 unsigned long adr, int usec)
622{
623 struct cfi_private *cfi = map->fldrv_priv;
624 struct cfi_pri_amdstd *extp = cfi->cmdset_priv;
625 map_word status, OK = CMD(0x80);
626 unsigned long suspended, start = xip_currtime();
627 flstate_t oldstate;
628
629 do {
630 cpu_relax();
631 if (xip_irqpending() && extp &&
632 ((chip->state == FL_ERASING && (extp->EraseSuspend & 2))) &&
633 (cfi_interleave_is_1(cfi) || chip->oldstate == FL_READY)) {
634 /*
635 * Let's suspend the erase operation when supported.
636 * Note that we currently don't try to suspend
637 * interleaved chips if there is already another
638 * operation suspended (imagine what happens
639 * when one chip was already done with the current
640 * operation while another chip suspended it, then
641 * we resume the whole thing at once). Yes, it
642 * can happen!
643 */
644 map_write(map, CMD(0xb0), adr);
645 usec -= xip_elapsed_since(start);
646 suspended = xip_currtime();
647 do {
648 if (xip_elapsed_since(suspended) > 100000) {
649 /*
650 * The chip doesn't want to suspend
651 * after waiting for 100 msecs.
652 * This is a critical error but there
653 * is not much we can do here.
654 */
655 return;
656 }
657 status = map_read(map, adr);
658 } while (!map_word_andequal(map, status, OK, OK));
659
660 /* Suspend succeeded */
661 oldstate = chip->state;
662 if (!map_word_bitsset(map, status, CMD(0x40)))
663 break;
664 chip->state = FL_XIP_WHILE_ERASING;
665 chip->erase_suspended = 1;
666 map_write(map, CMD(0xf0), adr);
667 (void) map_read(map, adr);
668 asm volatile (".rep 8; nop; .endr");
669 local_irq_enable();
670 spin_unlock(chip->mutex);
671 asm volatile (".rep 8; nop; .endr");
672 cond_resched();
673
674 /*
675 * We're back. However someone else might have
676 * decided to go write to the chip if we are in
677 * a suspended erase state. If so let's wait
678 * until it's done.
679 */
680 spin_lock(chip->mutex);
681 while (chip->state != FL_XIP_WHILE_ERASING) {
682 DECLARE_WAITQUEUE(wait, current);
683 set_current_state(TASK_UNINTERRUPTIBLE);
684 add_wait_queue(&chip->wq, &wait);
685 spin_unlock(chip->mutex);
686 schedule();
687 remove_wait_queue(&chip->wq, &wait);
688 spin_lock(chip->mutex);
689 }
690 /* Disallow XIP again */
691 local_irq_disable();
692
693 /* Resume the write or erase operation */
694 map_write(map, CMD(0x30), adr);
695 chip->state = oldstate;
696 start = xip_currtime();
697 } else if (usec >= 1000000/HZ) {
698 /*
699 * Try to save on CPU power when waiting delay
700 * is at least a system timer tick period.
701 * No need to be extremely accurate here.
702 */
703 xip_cpu_idle();
704 }
705 status = map_read(map, adr);
706 } while (!map_word_andequal(map, status, OK, OK)
707 && xip_elapsed_since(start) < usec);
708}
709
710#define UDELAY(map, chip, adr, usec) xip_udelay(map, chip, adr, usec)
711
712/*
713 * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while
714 * the flash is actively programming or erasing since we have to poll for
715 * the operation to complete anyway. We can't do that in a generic way with
716 * a XIP setup so do it before the actual flash operation in this case
717 * and stub it out from INVALIDATE_CACHE_UDELAY.
718 */
719#define XIP_INVAL_CACHED_RANGE(map, from, size) \
720 INVALIDATE_CACHED_RANGE(map, from, size)
721
722#define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
723 UDELAY(map, chip, adr, usec)
724
725/*
726 * Extra notes:
727 *
728 * Activating this XIP support changes the way the code works a bit. For
729 * example the code to suspend the current process when concurrent access
730 * happens is never executed because xip_udelay() will always return with the
731 * same chip state as it was entered with. This is why there is no care for
732 * the presence of add_wait_queue() or schedule() calls from within a couple
733 * xip_disable()'d areas of code, like in do_erase_oneblock for example.
734 * The queueing and scheduling are always happening within xip_udelay().
735 *
736 * Similarly, get_chip() and put_chip() just happen to always be executed
737 * with chip->state set to FL_READY (or FL_XIP_WHILE_*) where flash state
738 * is in array mode, therefore never executing many cases therein and not
739 * causing any problem with XIP.
740 */
741
742#else
743
744#define xip_disable(map, chip, adr)
745#define xip_enable(map, chip, adr)
746#define XIP_INVAL_CACHED_RANGE(x...)
747
748#define UDELAY(map, chip, adr, usec) \
749do { \
750 spin_unlock(chip->mutex); \
751 cfi_udelay(usec); \
752 spin_lock(chip->mutex); \
753} while (0)
754
755#define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
756do { \
757 spin_unlock(chip->mutex); \
758 INVALIDATE_CACHED_RANGE(map, adr, len); \
759 cfi_udelay(usec); \
760 spin_lock(chip->mutex); \
761} while (0)
762
763#endif
526 764
527static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf) 765static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
528{ 766{
@@ -535,10 +773,10 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
535 /* Ensure cmd read/writes are aligned. */ 773 /* Ensure cmd read/writes are aligned. */
536 cmd_addr = adr & ~(map_bankwidth(map)-1); 774 cmd_addr = adr & ~(map_bankwidth(map)-1);
537 775
538 cfi_spin_lock(chip->mutex); 776 spin_lock(chip->mutex);
539 ret = get_chip(map, chip, cmd_addr, FL_READY); 777 ret = get_chip(map, chip, cmd_addr, FL_READY);
540 if (ret) { 778 if (ret) {
541 cfi_spin_unlock(chip->mutex); 779 spin_unlock(chip->mutex);
542 return ret; 780 return ret;
543 } 781 }
544 782
@@ -551,7 +789,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
551 789
552 put_chip(map, chip, cmd_addr); 790 put_chip(map, chip, cmd_addr);
553 791
554 cfi_spin_unlock(chip->mutex); 792 spin_unlock(chip->mutex);
555 return 0; 793 return 0;
556} 794}
557 795
@@ -605,7 +843,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
605 struct cfi_private *cfi = map->fldrv_priv; 843 struct cfi_private *cfi = map->fldrv_priv;
606 844
607 retry: 845 retry:
608 cfi_spin_lock(chip->mutex); 846 spin_lock(chip->mutex);
609 847
610 if (chip->state != FL_READY){ 848 if (chip->state != FL_READY){
611#if 0 849#if 0
@@ -614,7 +852,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
614 set_current_state(TASK_UNINTERRUPTIBLE); 852 set_current_state(TASK_UNINTERRUPTIBLE);
615 add_wait_queue(&chip->wq, &wait); 853 add_wait_queue(&chip->wq, &wait);
616 854
617 cfi_spin_unlock(chip->mutex); 855 spin_unlock(chip->mutex);
618 856
619 schedule(); 857 schedule();
620 remove_wait_queue(&chip->wq, &wait); 858 remove_wait_queue(&chip->wq, &wait);
@@ -643,7 +881,7 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
643 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 881 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
644 882
645 wake_up(&chip->wq); 883 wake_up(&chip->wq);
646 cfi_spin_unlock(chip->mutex); 884 spin_unlock(chip->mutex);
647 885
648 return 0; 886 return 0;
649} 887}
@@ -692,7 +930,7 @@ static int cfi_amdstd_secsi_read (struct mtd_info *mtd, loff_t from, size_t len,
692} 930}
693 931
694 932
695static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, map_word datum) 933static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, map_word datum)
696{ 934{
697 struct cfi_private *cfi = map->fldrv_priv; 935 struct cfi_private *cfi = map->fldrv_priv;
698 unsigned long timeo = jiffies + HZ; 936 unsigned long timeo = jiffies + HZ;
@@ -712,10 +950,10 @@ static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned
712 950
713 adr += chip->start; 951 adr += chip->start;
714 952
715 cfi_spin_lock(chip->mutex); 953 spin_lock(chip->mutex);
716 ret = get_chip(map, chip, adr, FL_WRITING); 954 ret = get_chip(map, chip, adr, FL_WRITING);
717 if (ret) { 955 if (ret) {
718 cfi_spin_unlock(chip->mutex); 956 spin_unlock(chip->mutex);
719 return ret; 957 return ret;
720 } 958 }
721 959
@@ -735,7 +973,9 @@ static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned
735 goto op_done; 973 goto op_done;
736 } 974 }
737 975
976 XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map));
738 ENABLE_VPP(map); 977 ENABLE_VPP(map);
978 xip_disable(map, chip, adr);
739 retry: 979 retry:
740 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 980 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
741 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 981 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
@@ -743,9 +983,9 @@ static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned
743 map_write(map, datum, adr); 983 map_write(map, datum, adr);
744 chip->state = FL_WRITING; 984 chip->state = FL_WRITING;
745 985
746 cfi_spin_unlock(chip->mutex); 986 INVALIDATE_CACHE_UDELAY(map, chip,
747 cfi_udelay(chip->word_write_time); 987 adr, map_bankwidth(map),
748 cfi_spin_lock(chip->mutex); 988 chip->word_write_time);
749 989
750 /* See comment above for timeout value. */ 990 /* See comment above for timeout value. */
751 timeo = jiffies + uWriteTimeout; 991 timeo = jiffies + uWriteTimeout;
@@ -756,39 +996,43 @@ static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned
756 996
757 set_current_state(TASK_UNINTERRUPTIBLE); 997 set_current_state(TASK_UNINTERRUPTIBLE);
758 add_wait_queue(&chip->wq, &wait); 998 add_wait_queue(&chip->wq, &wait);
759 cfi_spin_unlock(chip->mutex); 999 spin_unlock(chip->mutex);
760 schedule(); 1000 schedule();
761 remove_wait_queue(&chip->wq, &wait); 1001 remove_wait_queue(&chip->wq, &wait);
762 timeo = jiffies + (HZ / 2); /* FIXME */ 1002 timeo = jiffies + (HZ / 2); /* FIXME */
763 cfi_spin_lock(chip->mutex); 1003 spin_lock(chip->mutex);
764 continue; 1004 continue;
765 } 1005 }
766 1006
767 if (chip_ready(map, adr)) 1007 if (chip_ready(map, adr))
768 goto op_done; 1008 break;
769 1009
770 if (time_after(jiffies, timeo)) 1010 if (time_after(jiffies, timeo)) {
1011 xip_enable(map, chip, adr);
1012 printk(KERN_WARNING "MTD %s(): software timeout\n", __func__);
1013 xip_disable(map, chip, adr);
771 break; 1014 break;
1015 }
772 1016
773 /* Latency issues. Drop the lock, wait a while and retry */ 1017 /* Latency issues. Drop the lock, wait a while and retry */
774 cfi_spin_unlock(chip->mutex); 1018 UDELAY(map, chip, adr, 1);
775 cfi_udelay(1);
776 cfi_spin_lock(chip->mutex);
777 } 1019 }
1020 /* Did we succeed? */
1021 if (!chip_good(map, adr, datum)) {
1022 /* reset on all failures. */
1023 map_write( map, CMD(0xF0), chip->start );
1024 /* FIXME - should have reset delay before continuing */
778 1025
779 printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); 1026 if (++retry_cnt <= MAX_WORD_RETRIES)
780 1027 goto retry;
781 /* reset on all failures. */
782 map_write( map, CMD(0xF0), chip->start );
783 /* FIXME - should have reset delay before continuing */
784 if (++retry_cnt <= MAX_WORD_RETRIES)
785 goto retry;
786 1028
787 ret = -EIO; 1029 ret = -EIO;
1030 }
1031 xip_enable(map, chip, adr);
788 op_done: 1032 op_done:
789 chip->state = FL_READY; 1033 chip->state = FL_READY;
790 put_chip(map, chip, adr); 1034 put_chip(map, chip, adr);
791 cfi_spin_unlock(chip->mutex); 1035 spin_unlock(chip->mutex);
792 1036
793 return ret; 1037 return ret;
794} 1038}
@@ -820,7 +1064,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
820 map_word tmp_buf; 1064 map_word tmp_buf;
821 1065
822 retry: 1066 retry:
823 cfi_spin_lock(cfi->chips[chipnum].mutex); 1067 spin_lock(cfi->chips[chipnum].mutex);
824 1068
825 if (cfi->chips[chipnum].state != FL_READY) { 1069 if (cfi->chips[chipnum].state != FL_READY) {
826#if 0 1070#if 0
@@ -829,7 +1073,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
829 set_current_state(TASK_UNINTERRUPTIBLE); 1073 set_current_state(TASK_UNINTERRUPTIBLE);
830 add_wait_queue(&cfi->chips[chipnum].wq, &wait); 1074 add_wait_queue(&cfi->chips[chipnum].wq, &wait);
831 1075
832 cfi_spin_unlock(cfi->chips[chipnum].mutex); 1076 spin_unlock(cfi->chips[chipnum].mutex);
833 1077
834 schedule(); 1078 schedule();
835 remove_wait_queue(&cfi->chips[chipnum].wq, &wait); 1079 remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
@@ -843,7 +1087,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
843 /* Load 'tmp_buf' with old contents of flash */ 1087 /* Load 'tmp_buf' with old contents of flash */
844 tmp_buf = map_read(map, bus_ofs+chipstart); 1088 tmp_buf = map_read(map, bus_ofs+chipstart);
845 1089
846 cfi_spin_unlock(cfi->chips[chipnum].mutex); 1090 spin_unlock(cfi->chips[chipnum].mutex);
847 1091
848 /* Number of bytes to copy from buffer */ 1092 /* Number of bytes to copy from buffer */
849 n = min_t(int, len, map_bankwidth(map)-i); 1093 n = min_t(int, len, map_bankwidth(map)-i);
@@ -898,7 +1142,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
898 map_word tmp_buf; 1142 map_word tmp_buf;
899 1143
900 retry1: 1144 retry1:
901 cfi_spin_lock(cfi->chips[chipnum].mutex); 1145 spin_lock(cfi->chips[chipnum].mutex);
902 1146
903 if (cfi->chips[chipnum].state != FL_READY) { 1147 if (cfi->chips[chipnum].state != FL_READY) {
904#if 0 1148#if 0
@@ -907,7 +1151,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
907 set_current_state(TASK_UNINTERRUPTIBLE); 1151 set_current_state(TASK_UNINTERRUPTIBLE);
908 add_wait_queue(&cfi->chips[chipnum].wq, &wait); 1152 add_wait_queue(&cfi->chips[chipnum].wq, &wait);
909 1153
910 cfi_spin_unlock(cfi->chips[chipnum].mutex); 1154 spin_unlock(cfi->chips[chipnum].mutex);
911 1155
912 schedule(); 1156 schedule();
913 remove_wait_queue(&cfi->chips[chipnum].wq, &wait); 1157 remove_wait_queue(&cfi->chips[chipnum].wq, &wait);
@@ -920,7 +1164,7 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
920 1164
921 tmp_buf = map_read(map, ofs + chipstart); 1165 tmp_buf = map_read(map, ofs + chipstart);
922 1166
923 cfi_spin_unlock(cfi->chips[chipnum].mutex); 1167 spin_unlock(cfi->chips[chipnum].mutex);
924 1168
925 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len); 1169 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len);
926 1170
@@ -939,8 +1183,9 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
939/* 1183/*
940 * FIXME: interleaved mode not tested, and probably not supported! 1184 * FIXME: interleaved mode not tested, and probably not supported!
941 */ 1185 */
942static inline int do_write_buffer(struct map_info *map, struct flchip *chip, 1186static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
943 unsigned long adr, const u_char *buf, int len) 1187 unsigned long adr, const u_char *buf,
1188 int len)
944{ 1189{
945 struct cfi_private *cfi = map->fldrv_priv; 1190 struct cfi_private *cfi = map->fldrv_priv;
946 unsigned long timeo = jiffies + HZ; 1191 unsigned long timeo = jiffies + HZ;
@@ -954,10 +1199,10 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
954 adr += chip->start; 1199 adr += chip->start;
955 cmd_adr = adr; 1200 cmd_adr = adr;
956 1201
957 cfi_spin_lock(chip->mutex); 1202 spin_lock(chip->mutex);
958 ret = get_chip(map, chip, adr, FL_WRITING); 1203 ret = get_chip(map, chip, adr, FL_WRITING);
959 if (ret) { 1204 if (ret) {
960 cfi_spin_unlock(chip->mutex); 1205 spin_unlock(chip->mutex);
961 return ret; 1206 return ret;
962 } 1207 }
963 1208
@@ -966,7 +1211,10 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
966 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", 1211 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n",
967 __func__, adr, datum.x[0] ); 1212 __func__, adr, datum.x[0] );
968 1213
1214 XIP_INVAL_CACHED_RANGE(map, adr, len);
969 ENABLE_VPP(map); 1215 ENABLE_VPP(map);
1216 xip_disable(map, chip, cmd_adr);
1217
970 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1218 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
971 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1219 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
972 //cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1220 //cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
@@ -996,9 +1244,9 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
996 map_write(map, CMD(0x29), cmd_adr); 1244 map_write(map, CMD(0x29), cmd_adr);
997 chip->state = FL_WRITING; 1245 chip->state = FL_WRITING;
998 1246
999 cfi_spin_unlock(chip->mutex); 1247 INVALIDATE_CACHE_UDELAY(map, chip,
1000 cfi_udelay(chip->buffer_write_time); 1248 adr, map_bankwidth(map),
1001 cfi_spin_lock(chip->mutex); 1249 chip->word_write_time);
1002 1250
1003 timeo = jiffies + uWriteTimeout; 1251 timeo = jiffies + uWriteTimeout;
1004 1252
@@ -1009,38 +1257,39 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
1009 1257
1010 set_current_state(TASK_UNINTERRUPTIBLE); 1258 set_current_state(TASK_UNINTERRUPTIBLE);
1011 add_wait_queue(&chip->wq, &wait); 1259 add_wait_queue(&chip->wq, &wait);
1012 cfi_spin_unlock(chip->mutex); 1260 spin_unlock(chip->mutex);
1013 schedule(); 1261 schedule();
1014 remove_wait_queue(&chip->wq, &wait); 1262 remove_wait_queue(&chip->wq, &wait);
1015 timeo = jiffies + (HZ / 2); /* FIXME */ 1263 timeo = jiffies + (HZ / 2); /* FIXME */
1016 cfi_spin_lock(chip->mutex); 1264 spin_lock(chip->mutex);
1017 continue; 1265 continue;
1018 } 1266 }
1019 1267
1020 if (chip_ready(map, adr)) 1268 if (chip_ready(map, adr)) {
1269 xip_enable(map, chip, adr);
1021 goto op_done; 1270 goto op_done;
1271 }
1022 1272
1023 if( time_after(jiffies, timeo)) 1273 if( time_after(jiffies, timeo))
1024 break; 1274 break;
1025 1275
1026 /* Latency issues. Drop the lock, wait a while and retry */ 1276 /* Latency issues. Drop the lock, wait a while and retry */
1027 cfi_spin_unlock(chip->mutex); 1277 UDELAY(map, chip, adr, 1);
1028 cfi_udelay(1);
1029 cfi_spin_lock(chip->mutex);
1030 } 1278 }
1031 1279
1032 printk(KERN_WARNING "MTD %s(): software timeout\n",
1033 __func__ );
1034
1035 /* reset on all failures. */ 1280 /* reset on all failures. */
1036 map_write( map, CMD(0xF0), chip->start ); 1281 map_write( map, CMD(0xF0), chip->start );
1282 xip_enable(map, chip, adr);
1037 /* FIXME - should have reset delay before continuing */ 1283 /* FIXME - should have reset delay before continuing */
1038 1284
1285 printk(KERN_WARNING "MTD %s(): software timeout\n",
1286 __func__ );
1287
1039 ret = -EIO; 1288 ret = -EIO;
1040 op_done: 1289 op_done:
1041 chip->state = FL_READY; 1290 chip->state = FL_READY;
1042 put_chip(map, chip, adr); 1291 put_chip(map, chip, adr);
1043 cfi_spin_unlock(chip->mutex); 1292 spin_unlock(chip->mutex);
1044 1293
1045 return ret; 1294 return ret;
1046} 1295}
@@ -1130,7 +1379,7 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
1130 * Handle devices with one erase region, that only implement 1379 * Handle devices with one erase region, that only implement
1131 * the chip erase command. 1380 * the chip erase command.
1132 */ 1381 */
1133static inline int do_erase_chip(struct map_info *map, struct flchip *chip) 1382static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
1134{ 1383{
1135 struct cfi_private *cfi = map->fldrv_priv; 1384 struct cfi_private *cfi = map->fldrv_priv;
1136 unsigned long timeo = jiffies + HZ; 1385 unsigned long timeo = jiffies + HZ;
@@ -1140,17 +1389,20 @@ static inline int do_erase_chip(struct map_info *map, struct flchip *chip)
1140 1389
1141 adr = cfi->addr_unlock1; 1390 adr = cfi->addr_unlock1;
1142 1391
1143 cfi_spin_lock(chip->mutex); 1392 spin_lock(chip->mutex);
1144 ret = get_chip(map, chip, adr, FL_WRITING); 1393 ret = get_chip(map, chip, adr, FL_WRITING);
1145 if (ret) { 1394 if (ret) {
1146 cfi_spin_unlock(chip->mutex); 1395 spin_unlock(chip->mutex);
1147 return ret; 1396 return ret;
1148 } 1397 }
1149 1398
1150 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1399 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n",
1151 __func__, chip->start ); 1400 __func__, chip->start );
1152 1401
1402 XIP_INVAL_CACHED_RANGE(map, adr, map->size);
1153 ENABLE_VPP(map); 1403 ENABLE_VPP(map);
1404 xip_disable(map, chip, adr);
1405
1154 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1406 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1155 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1407 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
1156 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1408 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
@@ -1162,9 +1414,9 @@ static inline int do_erase_chip(struct map_info *map, struct flchip *chip)
1162 chip->erase_suspended = 0; 1414 chip->erase_suspended = 0;
1163 chip->in_progress_block_addr = adr; 1415 chip->in_progress_block_addr = adr;
1164 1416
1165 cfi_spin_unlock(chip->mutex); 1417 INVALIDATE_CACHE_UDELAY(map, chip,
1166 msleep(chip->erase_time/2); 1418 adr, map->size,
1167 cfi_spin_lock(chip->mutex); 1419 chip->erase_time*500);
1168 1420
1169 timeo = jiffies + (HZ*20); 1421 timeo = jiffies + (HZ*20);
1170 1422
@@ -1173,10 +1425,10 @@ static inline int do_erase_chip(struct map_info *map, struct flchip *chip)
1173 /* Someone's suspended the erase. Sleep */ 1425 /* Someone's suspended the erase. Sleep */
1174 set_current_state(TASK_UNINTERRUPTIBLE); 1426 set_current_state(TASK_UNINTERRUPTIBLE);
1175 add_wait_queue(&chip->wq, &wait); 1427 add_wait_queue(&chip->wq, &wait);
1176 cfi_spin_unlock(chip->mutex); 1428 spin_unlock(chip->mutex);
1177 schedule(); 1429 schedule();
1178 remove_wait_queue(&chip->wq, &wait); 1430 remove_wait_queue(&chip->wq, &wait);
1179 cfi_spin_lock(chip->mutex); 1431 spin_lock(chip->mutex);
1180 continue; 1432 continue;
1181 } 1433 }
1182 if (chip->erase_suspended) { 1434 if (chip->erase_suspended) {
@@ -1187,36 +1439,36 @@ static inline int do_erase_chip(struct map_info *map, struct flchip *chip)
1187 } 1439 }
1188 1440
1189 if (chip_ready(map, adr)) 1441 if (chip_ready(map, adr))
1190 goto op_done; 1442 break;
1191 1443
1192 if (time_after(jiffies, timeo)) 1444 if (time_after(jiffies, timeo)) {
1445 printk(KERN_WARNING "MTD %s(): software timeout\n",
1446 __func__ );
1193 break; 1447 break;
1448 }
1194 1449
1195 /* Latency issues. Drop the lock, wait a while and retry */ 1450 /* Latency issues. Drop the lock, wait a while and retry */
1196 cfi_spin_unlock(chip->mutex); 1451 UDELAY(map, chip, adr, 1000000/HZ);
1197 set_current_state(TASK_UNINTERRUPTIBLE);
1198 schedule_timeout(1);
1199 cfi_spin_lock(chip->mutex);
1200 } 1452 }
1453 /* Did we succeed? */
1454 if (!chip_good(map, adr, map_word_ff(map))) {
1455 /* reset on all failures. */
1456 map_write( map, CMD(0xF0), chip->start );
1457 /* FIXME - should have reset delay before continuing */
1201 1458
1202 printk(KERN_WARNING "MTD %s(): software timeout\n", 1459 ret = -EIO;
1203 __func__ ); 1460 }
1204
1205 /* reset on all failures. */
1206 map_write( map, CMD(0xF0), chip->start );
1207 /* FIXME - should have reset delay before continuing */
1208 1461
1209 ret = -EIO;
1210 op_done:
1211 chip->state = FL_READY; 1462 chip->state = FL_READY;
1463 xip_enable(map, chip, adr);
1212 put_chip(map, chip, adr); 1464 put_chip(map, chip, adr);
1213 cfi_spin_unlock(chip->mutex); 1465 spin_unlock(chip->mutex);
1214 1466
1215 return ret; 1467 return ret;
1216} 1468}
1217 1469
1218 1470
1219static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr, int len, void *thunk) 1471static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr, int len, void *thunk)
1220{ 1472{
1221 struct cfi_private *cfi = map->fldrv_priv; 1473 struct cfi_private *cfi = map->fldrv_priv;
1222 unsigned long timeo = jiffies + HZ; 1474 unsigned long timeo = jiffies + HZ;
@@ -1225,17 +1477,20 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1225 1477
1226 adr += chip->start; 1478 adr += chip->start;
1227 1479
1228 cfi_spin_lock(chip->mutex); 1480 spin_lock(chip->mutex);
1229 ret = get_chip(map, chip, adr, FL_ERASING); 1481 ret = get_chip(map, chip, adr, FL_ERASING);
1230 if (ret) { 1482 if (ret) {
1231 cfi_spin_unlock(chip->mutex); 1483 spin_unlock(chip->mutex);
1232 return ret; 1484 return ret;
1233 } 1485 }
1234 1486
1235 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1487 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n",
1236 __func__, adr ); 1488 __func__, adr );
1237 1489
1490 XIP_INVAL_CACHED_RANGE(map, adr, len);
1238 ENABLE_VPP(map); 1491 ENABLE_VPP(map);
1492 xip_disable(map, chip, adr);
1493
1239 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1494 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1240 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1495 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
1241 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1496 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
@@ -1246,10 +1501,10 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1246 chip->state = FL_ERASING; 1501 chip->state = FL_ERASING;
1247 chip->erase_suspended = 0; 1502 chip->erase_suspended = 0;
1248 chip->in_progress_block_addr = adr; 1503 chip->in_progress_block_addr = adr;
1249 1504
1250 cfi_spin_unlock(chip->mutex); 1505 INVALIDATE_CACHE_UDELAY(map, chip,
1251 msleep(chip->erase_time/2); 1506 adr, len,
1252 cfi_spin_lock(chip->mutex); 1507 chip->erase_time*500);
1253 1508
1254 timeo = jiffies + (HZ*20); 1509 timeo = jiffies + (HZ*20);
1255 1510
@@ -1258,10 +1513,10 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1258 /* Someone's suspended the erase. Sleep */ 1513 /* Someone's suspended the erase. Sleep */
1259 set_current_state(TASK_UNINTERRUPTIBLE); 1514 set_current_state(TASK_UNINTERRUPTIBLE);
1260 add_wait_queue(&chip->wq, &wait); 1515 add_wait_queue(&chip->wq, &wait);
1261 cfi_spin_unlock(chip->mutex); 1516 spin_unlock(chip->mutex);
1262 schedule(); 1517 schedule();
1263 remove_wait_queue(&chip->wq, &wait); 1518 remove_wait_queue(&chip->wq, &wait);
1264 cfi_spin_lock(chip->mutex); 1519 spin_lock(chip->mutex);
1265 continue; 1520 continue;
1266 } 1521 }
1267 if (chip->erase_suspended) { 1522 if (chip->erase_suspended) {
@@ -1271,31 +1526,33 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
1271 chip->erase_suspended = 0; 1526 chip->erase_suspended = 0;
1272 } 1527 }
1273 1528
1274 if (chip_ready(map, adr)) 1529 if (chip_ready(map, adr)) {
1275 goto op_done; 1530 xip_enable(map, chip, adr);
1531 break;
1532 }
1276 1533
1277 if (time_after(jiffies, timeo)) 1534 if (time_after(jiffies, timeo)) {
1535 xip_enable(map, chip, adr);
1536 printk(KERN_WARNING "MTD %s(): software timeout\n",
1537 __func__ );
1278 break; 1538 break;
1539 }
1279 1540
1280 /* Latency issues. Drop the lock, wait a while and retry */ 1541 /* Latency issues. Drop the lock, wait a while and retry */
1281 cfi_spin_unlock(chip->mutex); 1542 UDELAY(map, chip, adr, 1000000/HZ);
1282 set_current_state(TASK_UNINTERRUPTIBLE); 1543 }
1283 schedule_timeout(1); 1544 /* Did we succeed? */
1284 cfi_spin_lock(chip->mutex); 1545 if (!chip_good(map, adr, map_word_ff(map))) {
1546 /* reset on all failures. */
1547 map_write( map, CMD(0xF0), chip->start );
1548 /* FIXME - should have reset delay before continuing */
1549
1550 ret = -EIO;
1285 } 1551 }
1286
1287 printk(KERN_WARNING "MTD %s(): software timeout\n",
1288 __func__ );
1289
1290 /* reset on all failures. */
1291 map_write( map, CMD(0xF0), chip->start );
1292 /* FIXME - should have reset delay before continuing */
1293 1552
1294 ret = -EIO;
1295 op_done:
1296 chip->state = FL_READY; 1553 chip->state = FL_READY;
1297 put_chip(map, chip, adr); 1554 put_chip(map, chip, adr);
1298 cfi_spin_unlock(chip->mutex); 1555 spin_unlock(chip->mutex);
1299 return ret; 1556 return ret;
1300} 1557}
1301 1558
@@ -1355,7 +1612,7 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1355 chip = &cfi->chips[i]; 1612 chip = &cfi->chips[i];
1356 1613
1357 retry: 1614 retry:
1358 cfi_spin_lock(chip->mutex); 1615 spin_lock(chip->mutex);
1359 1616
1360 switch(chip->state) { 1617 switch(chip->state) {
1361 case FL_READY: 1618 case FL_READY:
@@ -1369,14 +1626,14 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1369 * with the chip now anyway. 1626 * with the chip now anyway.
1370 */ 1627 */
1371 case FL_SYNCING: 1628 case FL_SYNCING:
1372 cfi_spin_unlock(chip->mutex); 1629 spin_unlock(chip->mutex);
1373 break; 1630 break;
1374 1631
1375 default: 1632 default:
1376 /* Not an idle state */ 1633 /* Not an idle state */
1377 add_wait_queue(&chip->wq, &wait); 1634 add_wait_queue(&chip->wq, &wait);
1378 1635
1379 cfi_spin_unlock(chip->mutex); 1636 spin_unlock(chip->mutex);
1380 1637
1381 schedule(); 1638 schedule();
1382 1639
@@ -1391,13 +1648,13 @@ static void cfi_amdstd_sync (struct mtd_info *mtd)
1391 for (i--; i >=0; i--) { 1648 for (i--; i >=0; i--) {
1392 chip = &cfi->chips[i]; 1649 chip = &cfi->chips[i];
1393 1650
1394 cfi_spin_lock(chip->mutex); 1651 spin_lock(chip->mutex);
1395 1652
1396 if (chip->state == FL_SYNCING) { 1653 if (chip->state == FL_SYNCING) {
1397 chip->state = chip->oldstate; 1654 chip->state = chip->oldstate;
1398 wake_up(&chip->wq); 1655 wake_up(&chip->wq);
1399 } 1656 }
1400 cfi_spin_unlock(chip->mutex); 1657 spin_unlock(chip->mutex);
1401 } 1658 }
1402} 1659}
1403 1660
@@ -1413,7 +1670,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1413 for (i=0; !ret && i<cfi->numchips; i++) { 1670 for (i=0; !ret && i<cfi->numchips; i++) {
1414 chip = &cfi->chips[i]; 1671 chip = &cfi->chips[i];
1415 1672
1416 cfi_spin_lock(chip->mutex); 1673 spin_lock(chip->mutex);
1417 1674
1418 switch(chip->state) { 1675 switch(chip->state) {
1419 case FL_READY: 1676 case FL_READY:
@@ -1433,7 +1690,7 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1433 ret = -EAGAIN; 1690 ret = -EAGAIN;
1434 break; 1691 break;
1435 } 1692 }
1436 cfi_spin_unlock(chip->mutex); 1693 spin_unlock(chip->mutex);
1437 } 1694 }
1438 1695
1439 /* Unlock the chips again */ 1696 /* Unlock the chips again */
@@ -1442,13 +1699,13 @@ static int cfi_amdstd_suspend(struct mtd_info *mtd)
1442 for (i--; i >=0; i--) { 1699 for (i--; i >=0; i--) {
1443 chip = &cfi->chips[i]; 1700 chip = &cfi->chips[i];
1444 1701
1445 cfi_spin_lock(chip->mutex); 1702 spin_lock(chip->mutex);
1446 1703
1447 if (chip->state == FL_PM_SUSPENDED) { 1704 if (chip->state == FL_PM_SUSPENDED) {
1448 chip->state = chip->oldstate; 1705 chip->state = chip->oldstate;
1449 wake_up(&chip->wq); 1706 wake_up(&chip->wq);
1450 } 1707 }
1451 cfi_spin_unlock(chip->mutex); 1708 spin_unlock(chip->mutex);
1452 } 1709 }
1453 } 1710 }
1454 1711
@@ -1467,7 +1724,7 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
1467 1724
1468 chip = &cfi->chips[i]; 1725 chip = &cfi->chips[i];
1469 1726
1470 cfi_spin_lock(chip->mutex); 1727 spin_lock(chip->mutex);
1471 1728
1472 if (chip->state == FL_PM_SUSPENDED) { 1729 if (chip->state == FL_PM_SUSPENDED) {
1473 chip->state = FL_READY; 1730 chip->state = FL_READY;
@@ -1477,7 +1734,7 @@ static void cfi_amdstd_resume(struct mtd_info *mtd)
1477 else 1734 else
1478 printk(KERN_ERR "Argh. Chip not in PM_SUSPENDED state upon resume()\n"); 1735 printk(KERN_ERR "Argh. Chip not in PM_SUSPENDED state upon resume()\n");
1479 1736
1480 cfi_spin_unlock(chip->mutex); 1737 spin_unlock(chip->mutex);
1481 } 1738 }
1482} 1739}
1483 1740
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 8c24e18db3b4..c894f8801578 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -4,7 +4,7 @@
4 * 4 *
5 * (C) 2000 Red Hat. GPL'd 5 * (C) 2000 Red Hat. GPL'd
6 * 6 *
7 * $Id: cfi_cmdset_0020.c,v 1.17 2004/11/20 12:49:04 dwmw2 Exp $ 7 * $Id: cfi_cmdset_0020.c,v 1.19 2005/07/13 15:52:45 dwmw2 Exp $
8 * 8 *
9 * 10/10/2000 Nicolas Pitre <nico@cam.org> 9 * 10/10/2000 Nicolas Pitre <nico@cam.org>
10 * - completely revamped method functions so they are aware and 10 * - completely revamped method functions so they are aware and
@@ -16,6 +16,8 @@
16 * - modified Intel Command Set 0x0001 to support ST Advanced Architecture 16 * - modified Intel Command Set 0x0001 to support ST Advanced Architecture
17 * (command set 0x0020) 17 * (command set 0x0020)
18 * - added a writev function 18 * - added a writev function
19 * 07/13/2005 Joern Engel <joern@wh.fh-wedel.de>
20 * - Plugged memory leak in cfi_staa_writev().
19 */ 21 */
20 22
21#include <linux/version.h> 23#include <linux/version.h>
@@ -719,6 +721,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
719write_error: 721write_error:
720 if (retlen) 722 if (retlen)
721 *retlen = totlen; 723 *retlen = totlen;
724 kfree(buffer);
722 return ret; 725 return ret;
723} 726}
724 727
diff --git a/drivers/mtd/chips/fwh_lock.h b/drivers/mtd/chips/fwh_lock.h
index fbf44708a861..e1a5b76596c5 100644
--- a/drivers/mtd/chips/fwh_lock.h
+++ b/drivers/mtd/chips/fwh_lock.h
@@ -58,10 +58,10 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
58 * to flash memory - that means that we don't have to check status 58 * to flash memory - that means that we don't have to check status
59 * and timeout. 59 * and timeout.
60 */ 60 */
61 cfi_spin_lock(chip->mutex); 61 spin_lock(chip->mutex);
62 ret = get_chip(map, chip, adr, FL_LOCKING); 62 ret = get_chip(map, chip, adr, FL_LOCKING);
63 if (ret) { 63 if (ret) {
64 cfi_spin_unlock(chip->mutex); 64 spin_unlock(chip->mutex);
65 return ret; 65 return ret;
66 } 66 }
67 67
@@ -71,7 +71,7 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
71 /* Done and happy. */ 71 /* Done and happy. */
72 chip->state = FL_READY; 72 chip->state = FL_READY;
73 put_chip(map, chip, adr); 73 put_chip(map, chip, adr);
74 cfi_spin_unlock(chip->mutex); 74 spin_unlock(chip->mutex);
75 return 0; 75 return 0;
76} 76}
77 77
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index fc982c4671f0..dc065b22f79e 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -2,7 +2,7 @@
2 * Routines common to all CFI-type probes. 2 * Routines common to all CFI-type probes.
3 * (C) 2001-2003 Red Hat, Inc. 3 * (C) 2001-2003 Red Hat, Inc.
4 * GPL'd 4 * GPL'd
5 * $Id: gen_probe.c,v 1.21 2004/08/14 15:14:05 dwmw2 Exp $ 5 * $Id: gen_probe.c,v 1.22 2005/01/24 23:49:50 rmk Exp $
6 */ 6 */
7 7
8#include <linux/kernel.h> 8#include <linux/kernel.h>
@@ -162,7 +162,7 @@ static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp,
162 int max_chips = map_bankwidth(map); /* And minimum 1 */ 162 int max_chips = map_bankwidth(map); /* And minimum 1 */
163 int nr_chips, type; 163 int nr_chips, type;
164 164
165 for (nr_chips = min_chips; nr_chips <= max_chips; nr_chips <<= 1) { 165 for (nr_chips = max_chips; nr_chips >= min_chips; nr_chips >>= 1) {
166 166
167 if (!cfi_interleave_supported(nr_chips)) 167 if (!cfi_interleave_supported(nr_chips))
168 continue; 168 continue;
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 30325a25ab95..30da428eb7b9 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -1,7 +1,7 @@
1/* 1/*
2 Common Flash Interface probe code. 2 Common Flash Interface probe code.
3 (C) 2000 Red Hat. GPL'd. 3 (C) 2000 Red Hat. GPL'd.
4 $Id: jedec_probe.c,v 1.61 2004/11/19 20:52:16 thayne Exp $ 4 $Id: jedec_probe.c,v 1.63 2005/02/14 16:30:32 bjd Exp $
5 See JEDEC (http://www.jedec.org/) standard JESD21C (section 3.5) 5 See JEDEC (http://www.jedec.org/) standard JESD21C (section 3.5)
6 for the standard this probe goes back to. 6 for the standard this probe goes back to.
7 7
@@ -142,6 +142,7 @@
142#define SST29LE512 0x003d 142#define SST29LE512 0x003d
143#define SST39LF800 0x2781 143#define SST39LF800 0x2781
144#define SST39LF160 0x2782 144#define SST39LF160 0x2782
145#define SST39VF1601 0x234b
145#define SST39LF512 0x00D4 146#define SST39LF512 0x00D4
146#define SST39LF010 0x00D5 147#define SST39LF010 0x00D5
147#define SST39LF020 0x00D6 148#define SST39LF020 0x00D6
@@ -1448,6 +1449,21 @@ static const struct amd_flash_info jedec_table[] = {
1448 ERASEINFO(0x1000,256), 1449 ERASEINFO(0x1000,256),
1449 ERASEINFO(0x1000,256) 1450 ERASEINFO(0x1000,256)
1450 } 1451 }
1452 }, {
1453 .mfr_id = MANUFACTURER_SST, /* should be CFI */
1454 .dev_id = SST39VF1601,
1455 .name = "SST 39VF1601",
1456 .uaddr = {
1457 [0] = MTD_UADDR_0x5555_0x2AAA, /* x8 */
1458 [1] = MTD_UADDR_0x5555_0x2AAA /* x16 */
1459 },
1460 .DevSize = SIZE_2MiB,
1461 .CmdSet = P_ID_AMD_STD,
1462 .NumEraseRegions= 2,
1463 .regions = {
1464 ERASEINFO(0x1000,256),
1465 ERASEINFO(0x1000,256)
1466 }
1451 1467
1452 }, { 1468 }, {
1453 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ 1469 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */
@@ -1856,6 +1872,16 @@ static inline int jedec_match( __u32 base,
1856 case CFI_DEVICETYPE_X8: 1872 case CFI_DEVICETYPE_X8:
1857 mfr = (__u8)finfo->mfr_id; 1873 mfr = (__u8)finfo->mfr_id;
1858 id = (__u8)finfo->dev_id; 1874 id = (__u8)finfo->dev_id;
1875
1876 /* bjd: it seems that if we do this, we can end up
1877 * detecting 16bit flashes as an 8bit device, even though
1878 * there aren't.
1879 */
1880 if (finfo->dev_id > 0xff) {
1881 DEBUG( MTD_DEBUG_LEVEL3, "%s(): ID is not 8bit\n",
1882 __func__);
1883 goto match_done;
1884 }
1859 break; 1885 break;
1860 case CFI_DEVICETYPE_X16: 1886 case CFI_DEVICETYPE_X16:
1861 mfr = (__u16)finfo->mfr_id; 1887 mfr = (__u16)finfo->mfr_id;
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 60ab4b89a2f9..ef24837019d3 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $ 2 * $Id: cmdlinepart.c,v 1.18 2005/06/07 15:04:26 joern Exp $
3 * 3 *
4 * Read flash partition table from command line 4 * Read flash partition table from command line
5 * 5 *
@@ -239,7 +239,8 @@ static int mtdpart_setup_real(char *s)
239 &num_parts, /* out: number of parts */ 239 &num_parts, /* out: number of parts */
240 0, /* first partition */ 240 0, /* first partition */
241 (unsigned char**)&this_mtd, /* out: extra mem */ 241 (unsigned char**)&this_mtd, /* out: extra mem */
242 mtd_id_len + 1 + sizeof(*this_mtd)); 242 mtd_id_len + 1 + sizeof(*this_mtd) +
243 sizeof(void*)-1 /*alignment*/);
243 if(!parts) 244 if(!parts)
244 { 245 {
245 /* 246 /*
@@ -252,6 +253,9 @@ static int mtdpart_setup_real(char *s)
252 return 0; 253 return 0;
253 } 254 }
254 255
256 /* align this_mtd */
257 this_mtd = (struct cmdline_mtd_partition *)
258 ALIGN((unsigned long)this_mtd, sizeof(void*));
255 /* enter results */ 259 /* enter results */
256 this_mtd->parts = parts; 260 this_mtd->parts = parts;
257 this_mtd->num_parts = num_parts; 261 this_mtd->num_parts = num_parts;
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index cfe6ccf07972..4a7a805e7564 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -1,10 +1,9 @@
1/* 1/*
2 * $Id: block2mtd.c,v 1.23 2005/01/05 17:05:46 dwmw2 Exp $ 2 * $Id: block2mtd.c,v 1.28 2005/03/19 22:40:44 gleixner Exp $
3 * 3 *
4 * block2mtd.c - create an mtd from a block device 4 * block2mtd.c - create an mtd from a block device
5 * 5 *
6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk> 6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk>
7 * Copyright (C) 2004 Gareth Bult <Gareth@Encryptec.net>
8 * Copyright (C) 2004,2005 Jörn Engel <joern@wh.fh-wedel.de> 7 * Copyright (C) 2004,2005 Jörn Engel <joern@wh.fh-wedel.de>
9 * 8 *
10 * Licence: GPL 9 * Licence: GPL
@@ -20,7 +19,7 @@
20#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
21#include <linux/buffer_head.h> 20#include <linux/buffer_head.h>
22 21
23#define VERSION "$Revision: 1.23 $" 22#define VERSION "$Revision: 1.28 $"
24 23
25 24
26#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) 25#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args)
@@ -89,7 +88,6 @@ void cache_readahead(struct address_space *mapping, int index)
89static struct page* page_readahead(struct address_space *mapping, int index) 88static struct page* page_readahead(struct address_space *mapping, int index)
90{ 89{
91 filler_t *filler = (filler_t*)mapping->a_ops->readpage; 90 filler_t *filler = (filler_t*)mapping->a_ops->readpage;
92 //do_page_cache_readahead(mapping, index, XXX, 64);
93 cache_readahead(mapping, index); 91 cache_readahead(mapping, index);
94 return read_cache_page(mapping, index, filler, NULL); 92 return read_cache_page(mapping, index, filler, NULL);
95} 93}
@@ -157,7 +155,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
157 struct block2mtd_dev *dev = mtd->priv; 155 struct block2mtd_dev *dev = mtd->priv;
158 struct page *page; 156 struct page *page;
159 int index = from >> PAGE_SHIFT; 157 int index = from >> PAGE_SHIFT;
160 int offset = from & (PAGE_SHIFT-1); 158 int offset = from & (PAGE_SIZE-1);
161 int cpylen; 159 int cpylen;
162 160
163 if (from > mtd->size) 161 if (from > mtd->size)
@@ -370,16 +368,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base)
370} 368}
371 369
372 370
373static int parse_num32(u32 *num32, const char *token) 371static int parse_num(size_t *num, const char *token)
374{ 372{
375 char *endp; 373 char *endp;
376 unsigned long n; 374 size_t n;
377 375
378 n = ustrtoul(token, &endp, 0); 376 n = (size_t) ustrtoul(token, &endp, 0);
379 if (*endp) 377 if (*endp)
380 return -EINVAL; 378 return -EINVAL;
381 379
382 *num32 = n; 380 *num = n;
383 return 0; 381 return 0;
384} 382}
385 383
@@ -422,7 +420,7 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
422 char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */ 420 char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */
423 char *token[2]; 421 char *token[2];
424 char *name; 422 char *name;
425 u32 erase_size = PAGE_SIZE; 423 size_t erase_size = PAGE_SIZE;
426 int i, ret; 424 int i, ret;
427 425
428 if (strnlen(val, sizeof(buf)) >= sizeof(buf)) 426 if (strnlen(val, sizeof(buf)) >= sizeof(buf))
@@ -449,7 +447,7 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
449 return 0; 447 return 0;
450 448
451 if (token[1]) { 449 if (token[1]) {
452 ret = parse_num32(&erase_size, token[1]); 450 ret = parse_num(&erase_size, token[1]);
453 if (ret) 451 if (ret)
454 parse_err("illegal erase size"); 452 parse_err("illegal erase size");
455 } 453 }
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 380ff08d29e4..f5026cee087f 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -6,7 +6,7 @@
6 * as published by the Free Software Foundation; either version 6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version. 7 * 2 of the License, or (at your option) any later version.
8 * 8 *
9 * $Id: ms02-nv.c,v 1.8 2005/01/05 18:05:12 dwmw2 Exp $ 9 * $Id: ms02-nv.c,v 1.10 2005/06/20 12:24:41 macro Exp $
10 */ 10 */
11 11
12#include <linux/init.h> 12#include <linux/init.h>
@@ -99,8 +99,8 @@ static inline uint ms02nv_probe_one(ulong addr)
99 * The firmware writes MS02NV_ID at MS02NV_MAGIC and also 99 * The firmware writes MS02NV_ID at MS02NV_MAGIC and also
100 * a diagnostic status at MS02NV_DIAG. 100 * a diagnostic status at MS02NV_DIAG.
101 */ 101 */
102 ms02nv_diagp = (ms02nv_uint *)(KSEG1ADDR(addr + MS02NV_DIAG)); 102 ms02nv_diagp = (ms02nv_uint *)(CKSEG1ADDR(addr + MS02NV_DIAG));
103 ms02nv_magicp = (ms02nv_uint *)(KSEG1ADDR(addr + MS02NV_MAGIC)); 103 ms02nv_magicp = (ms02nv_uint *)(CKSEG1ADDR(addr + MS02NV_MAGIC));
104 err = get_dbe(ms02nv_magic, ms02nv_magicp); 104 err = get_dbe(ms02nv_magic, ms02nv_magicp);
105 if (err) 105 if (err)
106 return 0; 106 return 0;
@@ -233,7 +233,7 @@ static int __init ms02nv_init_one(ulong addr)
233 goto err_out_csr_res; 233 goto err_out_csr_res;
234 } 234 }
235 235
236 printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %uMiB.\n", 236 printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %zuMiB.\n",
237 mtd->index, ms02nv_name, addr, size >> 20); 237 mtd->index, ms02nv_name, addr, size >> 20);
238 238
239 mp->next = root_ms02nv_mtd; 239 mp->next = root_ms02nv_mtd;
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index edac4156d69c..bb713fed2f37 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * mtdram - a test mtd device 2 * mtdram - a test mtd device
3 * $Id: mtdram.c,v 1.35 2005/01/05 18:05:12 dwmw2 Exp $ 3 * $Id: mtdram.c,v 1.37 2005/04/21 03:42:11 joern Exp $
4 * Author: Alexander Larsson <alex@cendio.se> 4 * Author: Alexander Larsson <alex@cendio.se>
5 * 5 *
6 * Copyright (c) 1999 Alexander Larsson <alex@cendio.se> 6 * Copyright (c) 1999 Alexander Larsson <alex@cendio.se>
7 * Copyright (c) 2005 Joern Engel <joern@wh.fh-wedel.de>
7 * 8 *
8 * This code is GPL 9 * This code is GPL
9 * 10 *
@@ -18,213 +19,140 @@
18#include <linux/mtd/compatmac.h> 19#include <linux/mtd/compatmac.h>
19#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
20 21
21#ifndef CONFIG_MTDRAM_ABS_POS
22 #define CONFIG_MTDRAM_ABS_POS 0
23#endif
24
25#if CONFIG_MTDRAM_ABS_POS > 0
26 #include <asm/io.h>
27#endif
28
29#ifdef MODULE
30static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; 22static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE;
31static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; 23static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE;
32module_param(total_size,ulong,0);
33MODULE_PARM_DESC(total_size, "Total device size in KiB");
34module_param(erase_size,ulong,0);
35MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
36#define MTDRAM_TOTAL_SIZE (total_size * 1024) 24#define MTDRAM_TOTAL_SIZE (total_size * 1024)
37#define MTDRAM_ERASE_SIZE (erase_size * 1024) 25#define MTDRAM_ERASE_SIZE (erase_size * 1024)
38#else
39#define MTDRAM_TOTAL_SIZE (CONFIG_MTDRAM_TOTAL_SIZE * 1024)
40#define MTDRAM_ERASE_SIZE (CONFIG_MTDRAM_ERASE_SIZE * 1024)
41#endif
42 26
27#ifdef MODULE
28module_param(total_size, ulong, 0);
29MODULE_PARM_DESC(total_size, "Total device size in KiB");
30module_param(erase_size, ulong, 0);
31MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
32#endif
43 33
44// We could store these in the mtd structure, but we only support 1 device.. 34// We could store these in the mtd structure, but we only support 1 device..
45static struct mtd_info *mtd_info; 35static struct mtd_info *mtd_info;
46 36
47 37static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
48static int
49ram_erase(struct mtd_info *mtd, struct erase_info *instr)
50{ 38{
51 DEBUG(MTD_DEBUG_LEVEL2, "ram_erase(pos:%ld, len:%ld)\n", (long)instr->addr, (long)instr->len); 39 if (instr->addr + instr->len > mtd->size)
52 if (instr->addr + instr->len > mtd->size) { 40 return -EINVAL;
53 DEBUG(MTD_DEBUG_LEVEL1, "ram_erase() out of bounds (%ld > %ld)\n", (long)(instr->addr + instr->len), (long)mtd->size); 41
54 return -EINVAL; 42 memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
55 } 43
56 44 instr->state = MTD_ERASE_DONE;
57 memset((char *)mtd->priv + instr->addr, 0xff, instr->len); 45 mtd_erase_callback(instr);
58 46
59 instr->state = MTD_ERASE_DONE; 47 return 0;
60 mtd_erase_callback(instr);
61
62 return 0;
63} 48}
64 49
65static int ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf) 50static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
51 size_t *retlen, u_char **mtdbuf)
66{ 52{
67 if (from + len > mtd->size) 53 if (from + len > mtd->size)
68 return -EINVAL; 54 return -EINVAL;
69 55
70 *mtdbuf = mtd->priv + from; 56 *mtdbuf = mtd->priv + from;
71 *retlen = len; 57 *retlen = len;
72 return 0; 58 return 0;
73} 59}
74 60
75static void ram_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, 61static void ram_unpoint(struct mtd_info *mtd, u_char * addr, loff_t from,
76 size_t len) 62 size_t len)
77{ 63{
78 DEBUG(MTD_DEBUG_LEVEL2, "ram_unpoint\n");
79} 64}
80 65
81static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, 66static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
82 size_t *retlen, u_char *buf) 67 size_t *retlen, u_char *buf)
83{ 68{
84 DEBUG(MTD_DEBUG_LEVEL2, "ram_read(pos:%ld, len:%ld)\n", (long)from, (long)len); 69 if (from + len > mtd->size)
85 if (from + len > mtd->size) { 70 return -EINVAL;
86 DEBUG(MTD_DEBUG_LEVEL1, "ram_read() out of bounds (%ld > %ld)\n", (long)(from + len), (long)mtd->size);
87 return -EINVAL;
88 }
89 71
90 memcpy(buf, mtd->priv + from, len); 72 memcpy(buf, mtd->priv + from, len);
91 73
92 *retlen=len; 74 *retlen = len;
93 return 0; 75 return 0;
94} 76}
95 77
96static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, 78static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
97 size_t *retlen, const u_char *buf) 79 size_t *retlen, const u_char *buf)
98{ 80{
99 DEBUG(MTD_DEBUG_LEVEL2, "ram_write(pos:%ld, len:%ld)\n", (long)to, (long)len); 81 if (to + len > mtd->size)
100 if (to + len > mtd->size) { 82 return -EINVAL;
101 DEBUG(MTD_DEBUG_LEVEL1, "ram_write() out of bounds (%ld > %ld)\n", (long)(to + len), (long)mtd->size);
102 return -EINVAL;
103 }
104 83
105 memcpy ((char *)mtd->priv + to, buf, len); 84 memcpy((char *)mtd->priv + to, buf, len);
106 85
107 *retlen=len; 86 *retlen = len;
108 return 0; 87 return 0;
109} 88}
110 89
111static void __exit cleanup_mtdram(void) 90static void __exit cleanup_mtdram(void)
112{ 91{
113 if (mtd_info) { 92 if (mtd_info) {
114 del_mtd_device(mtd_info); 93 del_mtd_device(mtd_info);
115#if CONFIG_MTDRAM_TOTAL_SIZE > 0 94 if (mtd_info->priv)
116 if (mtd_info->priv) 95 vfree(mtd_info->priv);
117#if CONFIG_MTDRAM_ABS_POS > 0 96 kfree(mtd_info);
118 iounmap(mtd_info->priv); 97 }
119#else
120 vfree(mtd_info->priv);
121#endif
122#endif
123 kfree(mtd_info);
124 }
125}
126
127int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
128 unsigned long size, char *name)
129{
130 memset(mtd, 0, sizeof(*mtd));
131
132 /* Setup the MTD structure */
133 mtd->name = name;
134 mtd->type = MTD_RAM;
135 mtd->flags = MTD_CAP_RAM;
136 mtd->size = size;
137 mtd->erasesize = MTDRAM_ERASE_SIZE;
138 mtd->priv = mapped_address;
139
140 mtd->owner = THIS_MODULE;
141 mtd->erase = ram_erase;
142 mtd->point = ram_point;
143 mtd->unpoint = ram_unpoint;
144 mtd->read = ram_read;
145 mtd->write = ram_write;
146
147 if (add_mtd_device(mtd)) {
148 return -EIO;
149 }
150
151 return 0;
152}
153
154#if CONFIG_MTDRAM_TOTAL_SIZE > 0
155#if CONFIG_MTDRAM_ABS_POS > 0
156static int __init init_mtdram(void)
157{
158 void *addr;
159 int err;
160 /* Allocate some memory */
161 mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
162 if (!mtd_info)
163 return -ENOMEM;
164
165 addr = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE);
166 if (!addr) {
167 DEBUG(MTD_DEBUG_LEVEL1,
168 "Failed to ioremap) memory region of size %ld at ABS_POS:%ld\n",
169 (long)MTDRAM_TOTAL_SIZE, (long)CONFIG_MTDRAM_ABS_POS);
170 kfree(mtd_info);
171 mtd_info = NULL;
172 return -ENOMEM;
173 }
174 err = mtdram_init_device(mtd_info, addr,
175 MTDRAM_TOTAL_SIZE, "mtdram test device");
176 if (err)
177 {
178 iounmap(addr);
179 kfree(mtd_info);
180 mtd_info = NULL;
181 return err;
182 }
183 memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
184 return err;
185} 98}
186 99
187#else /* CONFIG_MTDRAM_ABS_POS > 0 */ 100int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
188 101 unsigned long size, char *name)
189static int __init init_mtdram(void)
190{ 102{
191 void *addr; 103 memset(mtd, 0, sizeof(*mtd));
192 int err; 104
193 /* Allocate some memory */ 105 /* Setup the MTD structure */
194 mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 106 mtd->name = name;
195 if (!mtd_info) 107 mtd->type = MTD_RAM;
196 return -ENOMEM; 108 mtd->flags = MTD_CAP_RAM;
197 109 mtd->size = size;
198 addr = vmalloc(MTDRAM_TOTAL_SIZE); 110 mtd->erasesize = MTDRAM_ERASE_SIZE;
199 if (!addr) { 111 mtd->priv = mapped_address;
200 DEBUG(MTD_DEBUG_LEVEL1, 112
201 "Failed to vmalloc memory region of size %ld\n", 113 mtd->owner = THIS_MODULE;
202 (long)MTDRAM_TOTAL_SIZE); 114 mtd->erase = ram_erase;
203 kfree(mtd_info); 115 mtd->point = ram_point;
204 mtd_info = NULL; 116 mtd->unpoint = ram_unpoint;
205 return -ENOMEM; 117 mtd->read = ram_read;
206 } 118 mtd->write = ram_write;
207 err = mtdram_init_device(mtd_info, addr, 119
208 MTDRAM_TOTAL_SIZE, "mtdram test device"); 120 if (add_mtd_device(mtd)) {
209 if (err) 121 return -EIO;
210 { 122 }
211 vfree(addr); 123
212 kfree(mtd_info); 124 return 0;
213 mtd_info = NULL;
214 return err;
215 }
216 memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
217 return err;
218} 125}
219#endif /* !(CONFIG_MTDRAM_ABS_POS > 0) */
220
221#else /* CONFIG_MTDRAM_TOTAL_SIZE > 0 */
222 126
223static int __init init_mtdram(void) 127static int __init init_mtdram(void)
224{ 128{
225 return 0; 129 void *addr;
130 int err;
131
132 if (!total_size)
133 return -EINVAL;
134
135 /* Allocate some memory */
136 mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
137 if (!mtd_info)
138 return -ENOMEM;
139
140 addr = vmalloc(MTDRAM_TOTAL_SIZE);
141 if (!addr) {
142 kfree(mtd_info);
143 mtd_info = NULL;
144 return -ENOMEM;
145 }
146 err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device");
147 if (err) {
148 vfree(addr);
149 kfree(mtd_info);
150 mtd_info = NULL;
151 return err;
152 }
153 memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
154 return err;
226} 155}
227#endif /* !(CONFIG_MTDRAM_TOTAL_SIZE > 0) */
228 156
229module_init(init_mtdram); 157module_init(init_mtdram);
230module_exit(cleanup_mtdram); 158module_exit(cleanup_mtdram);
@@ -232,4 +160,3 @@ module_exit(cleanup_mtdram);
232MODULE_LICENSE("GPL"); 160MODULE_LICENSE("GPL");
233MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>"); 161MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>");
234MODULE_DESCRIPTION("Simulated MTD driver for testing"); 162MODULE_DESCRIPTION("Simulated MTD driver for testing");
235
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 5f8e164ddb71..a423a382095a 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * $Id: phram.c,v 1.11 2005/01/05 18:05:13 dwmw2 Exp $ 2 * $Id: phram.c,v 1.14 2005/03/07 21:43:38 joern Exp $
3 * 3 *
4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de> 4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de>
5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de> 5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de>
@@ -15,9 +15,7 @@
15 * 15 *
16 * Example: 16 * Example:
17 * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi 17 * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi
18 *
19 */ 18 */
20
21#include <asm/io.h> 19#include <asm/io.h>
22#include <linux/init.h> 20#include <linux/init.h>
23#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -36,7 +34,6 @@ struct phram_mtd_list {
36static LIST_HEAD(phram_list); 34static LIST_HEAD(phram_list);
37 35
38 36
39
40static int phram_erase(struct mtd_info *mtd, struct erase_info *instr) 37static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
41{ 38{
42 u_char *start = mtd->priv; 39 u_char *start = mtd->priv;
@@ -71,7 +68,8 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
71 return 0; 68 return 0;
72} 69}
73 70
74static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 71static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from,
72 size_t len)
75{ 73{
76} 74}
77 75
@@ -80,8 +78,11 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
80{ 78{
81 u_char *start = mtd->priv; 79 u_char *start = mtd->priv;
82 80
83 if (from + len > mtd->size) 81 if (from >= mtd->size)
84 return -EINVAL; 82 return -EINVAL;
83
84 if (len > mtd->size - from)
85 len = mtd->size - from;
85 86
86 memcpy(buf, start + from, len); 87 memcpy(buf, start + from, len);
87 88
@@ -94,8 +95,11 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
94{ 95{
95 u_char *start = mtd->priv; 96 u_char *start = mtd->priv;
96 97
97 if (to + len > mtd->size) 98 if (to >= mtd->size)
98 return -EINVAL; 99 return -EINVAL;
100
101 if (len > mtd->size - to)
102 len = mtd->size - to;
99 103
100 memcpy(start + to, buf, len); 104 memcpy(start + to, buf, len);
101 105
@@ -107,9 +111,9 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
107 111
108static void unregister_devices(void) 112static void unregister_devices(void)
109{ 113{
110 struct phram_mtd_list *this; 114 struct phram_mtd_list *this, *safe;
111 115
112 list_for_each_entry(this, &phram_list, list) { 116 list_for_each_entry_safe(this, safe, &phram_list, list) {
113 del_mtd_device(&this->mtd); 117 del_mtd_device(&this->mtd);
114 iounmap(this->mtd.priv); 118 iounmap(this->mtd.priv);
115 kfree(this); 119 kfree(this);
@@ -145,7 +149,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
145 new->mtd.write = phram_write; 149 new->mtd.write = phram_write;
146 new->mtd.owner = THIS_MODULE; 150 new->mtd.owner = THIS_MODULE;
147 new->mtd.type = MTD_RAM; 151 new->mtd.type = MTD_RAM;
148 new->mtd.erasesize = 0; 152 new->mtd.erasesize = PAGE_SIZE;
149 153
150 ret = -EAGAIN; 154 ret = -EAGAIN;
151 if (add_mtd_device(&new->mtd)) { 155 if (add_mtd_device(&new->mtd)) {
@@ -214,6 +218,15 @@ static int parse_name(char **pname, const char *token)
214 return 0; 218 return 0;
215} 219}
216 220
221
222static inline void kill_final_newline(char *str)
223{
224 char *newline = strrchr(str, '\n');
225 if (newline && !newline[1])
226 *newline = 0;
227}
228
229
217#define parse_err(fmt, args...) do { \ 230#define parse_err(fmt, args...) do { \
218 ERROR(fmt , ## args); \ 231 ERROR(fmt , ## args); \
219 return 0; \ 232 return 0; \
@@ -232,6 +245,7 @@ static int phram_setup(const char *val, struct kernel_param *kp)
232 parse_err("parameter too long\n"); 245 parse_err("parameter too long\n");
233 246
234 strcpy(str, val); 247 strcpy(str, val);
248 kill_final_newline(str);
235 249
236 for (i=0; i<3; i++) 250 for (i=0; i<3; i++)
237 token[i] = strsep(&str, ","); 251 token[i] = strsep(&str, ",");
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 5ab15e643be7..84fa91392a8c 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -1,6 +1,6 @@
1/*====================================================================== 1/*======================================================================
2 2
3 $Id: slram.c,v 1.33 2005/01/05 18:05:13 dwmw2 Exp $ 3 $Id: slram.c,v 1.34 2005/01/06 21:16:42 jwboyer Exp $
4 4
5 This driver provides a method to access memory not used by the kernel 5 This driver provides a method to access memory not used by the kernel
6 itself (i.e. if the kernel commandline mem=xxx is used). To actually 6 itself (i.e. if the kernel commandline mem=xxx is used). To actually
@@ -50,6 +50,7 @@
50#include <linux/mtd/mtd.h> 50#include <linux/mtd/mtd.h>
51 51
52#define SLRAM_MAX_DEVICES_PARAMS 6 /* 3 parameters / device */ 52#define SLRAM_MAX_DEVICES_PARAMS 6 /* 3 parameters / device */
53#define SLRAM_BLK_SZ 0x4000
53 54
54#define T(fmt, args...) printk(KERN_DEBUG fmt, ## args) 55#define T(fmt, args...) printk(KERN_DEBUG fmt, ## args)
55#define E(fmt, args...) printk(KERN_NOTICE fmt, ## args) 56#define E(fmt, args...) printk(KERN_NOTICE fmt, ## args)
@@ -108,6 +109,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
108{ 109{
109 slram_priv_t *priv = mtd->priv; 110 slram_priv_t *priv = mtd->priv;
110 111
112 if (from + len > mtd->size)
113 return -EINVAL;
114
111 *mtdbuf = priv->start + from; 115 *mtdbuf = priv->start + from;
112 *retlen = len; 116 *retlen = len;
113 return(0); 117 return(0);
@@ -121,7 +125,13 @@ static int slram_read(struct mtd_info *mtd, loff_t from, size_t len,
121 size_t *retlen, u_char *buf) 125 size_t *retlen, u_char *buf)
122{ 126{
123 slram_priv_t *priv = mtd->priv; 127 slram_priv_t *priv = mtd->priv;
124 128
129 if (from > mtd->size)
130 return -EINVAL;
131
132 if (from + len > mtd->size)
133 len = mtd->size - from;
134
125 memcpy(buf, priv->start + from, len); 135 memcpy(buf, priv->start + from, len);
126 136
127 *retlen = len; 137 *retlen = len;
@@ -133,6 +143,9 @@ static int slram_write(struct mtd_info *mtd, loff_t to, size_t len,
133{ 143{
134 slram_priv_t *priv = mtd->priv; 144 slram_priv_t *priv = mtd->priv;
135 145
146 if (to + len > mtd->size)
147 return -EINVAL;
148
136 memcpy(priv->start + to, buf, len); 149 memcpy(priv->start + to, buf, len);
137 150
138 *retlen = len; 151 *retlen = len;
@@ -188,7 +201,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
188 (*curmtd)->mtdinfo->name = name; 201 (*curmtd)->mtdinfo->name = name;
189 (*curmtd)->mtdinfo->size = length; 202 (*curmtd)->mtdinfo->size = length;
190 (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS | 203 (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS |
191 MTD_WRITEB_WRITEABLE | MTD_VOLATILE; 204 MTD_WRITEB_WRITEABLE | MTD_VOLATILE | MTD_CAP_RAM;
192 (*curmtd)->mtdinfo->erase = slram_erase; 205 (*curmtd)->mtdinfo->erase = slram_erase;
193 (*curmtd)->mtdinfo->point = slram_point; 206 (*curmtd)->mtdinfo->point = slram_point;
194 (*curmtd)->mtdinfo->unpoint = slram_unpoint; 207 (*curmtd)->mtdinfo->unpoint = slram_unpoint;
@@ -196,7 +209,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
196 (*curmtd)->mtdinfo->write = slram_write; 209 (*curmtd)->mtdinfo->write = slram_write;
197 (*curmtd)->mtdinfo->owner = THIS_MODULE; 210 (*curmtd)->mtdinfo->owner = THIS_MODULE;
198 (*curmtd)->mtdinfo->type = MTD_RAM; 211 (*curmtd)->mtdinfo->type = MTD_RAM;
199 (*curmtd)->mtdinfo->erasesize = 0x0; 212 (*curmtd)->mtdinfo->erasesize = SLRAM_BLK_SZ;
200 213
201 if (add_mtd_device((*curmtd)->mtdinfo)) { 214 if (add_mtd_device((*curmtd)->mtdinfo)) {
202 E("slram: Failed to register new device\n"); 215 E("slram: Failed to register new device\n");
@@ -261,7 +274,7 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
261 } 274 }
262 T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n", 275 T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
263 devname, devstart, devlength); 276 devname, devstart, devlength);
264 if ((devstart < 0) || (devlength < 0)) { 277 if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
265 E("slram: Illegal start / length parameter.\n"); 278 E("slram: Illegal start / length parameter.\n");
266 return(-EINVAL); 279 return(-EINVAL);
267 } 280 }
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 18cc8846e733..d9ab60b36fd4 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1,5 +1,5 @@
1/* This version ported to the Linux-MTD system by dwmw2@infradead.org 1/* This version ported to the Linux-MTD system by dwmw2@infradead.org
2 * $Id: ftl.c,v 1.54 2004/11/16 18:33:15 dwmw2 Exp $ 2 * $Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $
3 * 3 *
4 * Fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br> 4 * Fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 * - fixes some leaks on failure in build_maps and ftl_notify_add, cleanups 5 * - fixes some leaks on failure in build_maps and ftl_notify_add, cleanups
@@ -357,6 +357,7 @@ static int erase_xfer(partition_t *part,
357 if (!erase) 357 if (!erase)
358 return -ENOMEM; 358 return -ENOMEM;
359 359
360 erase->mtd = part->mbd.mtd;
360 erase->callback = ftl_erase_callback; 361 erase->callback = ftl_erase_callback;
361 erase->addr = xfer->Offset; 362 erase->addr = xfer->Offset;
362 erase->len = 1 << part->header.EraseUnitSize; 363 erase->len = 1 << part->header.EraseUnitSize;
@@ -1096,7 +1097,7 @@ struct mtd_blktrans_ops ftl_tr = {
1096 1097
1097int init_ftl(void) 1098int init_ftl(void)
1098{ 1099{
1099 DEBUG(0, "$Id: ftl.c,v 1.54 2004/11/16 18:33:15 dwmw2 Exp $\n"); 1100 DEBUG(0, "$Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $\n");
1100 1101
1101 return register_mtd_blktrans(&ftl_tr); 1102 return register_mtd_blktrans(&ftl_tr);
1102} 1103}
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 8480057eadb4..44781a83b2e7 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/maps/Kconfig 1# drivers/mtd/maps/Kconfig
2# $Id: Kconfig,v 1.42 2005/01/05 16:59:50 dwmw2 Exp $ 2# $Id: Kconfig,v 1.55 2005/07/02 01:53:24 tpoynor Exp $
3 3
4menu "Mapping drivers for chip access" 4menu "Mapping drivers for chip access"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -122,16 +122,6 @@ config MTD_SBC_GXX
122 More info at 122 More info at
123 <http://www.arcomcontrols.com/products/icp/pc104/processors/SBC_GX1.htm>. 123 <http://www.arcomcontrols.com/products/icp/pc104/processors/SBC_GX1.htm>.
124 124
125config MTD_ELAN_104NC
126 tristate "CFI Flash device mapped on Arcom ELAN-104NC"
127 depends on X86 && MTD_CFI_INTELEXT && MTD_PARTITIONS && MTD_COMPLEX_MAPPINGS
128 help
129 This provides a driver for the on-board flash of the Arcom Control
130 System's ELAN-104NC development board. By default the flash
131 is split into 3 partitions which are accessed as separate MTD
132 devices. This board utilizes Intel StrataFlash. More info at
133 <http://www.arcomcontrols.com/products/icp/pc104/processors/ELAN104NC.htm>.
134
135config MTD_LUBBOCK 125config MTD_LUBBOCK
136 tristate "CFI Flash device mapped on Intel Lubbock XScale eval board" 126 tristate "CFI Flash device mapped on Intel Lubbock XScale eval board"
137 depends on ARCH_LUBBOCK && MTD_CFI_INTELEXT && MTD_PARTITIONS 127 depends on ARCH_LUBBOCK && MTD_CFI_INTELEXT && MTD_PARTITIONS
@@ -139,6 +129,14 @@ config MTD_LUBBOCK
139 This provides a driver for the on-board flash of the Intel 129 This provides a driver for the on-board flash of the Intel
140 'Lubbock' XScale evaluation board. 130 'Lubbock' XScale evaluation board.
141 131
132config MTD_MAINSTONE
133 tristate "CFI Flash device mapped on Intel Mainstone XScale eval board"
134 depends on MACH_MAINSTONE && MTD_CFI_INTELEXT
135 select MTD_PARTITIONS
136 help
137 This provides a driver for the on-board flash of the Intel
138 'Mainstone PXA27x evaluation board.
139
142config MTD_OCTAGON 140config MTD_OCTAGON
143 tristate "JEDEC Flash device mapped on Octagon 5066 SBC" 141 tristate "JEDEC Flash device mapped on Octagon 5066 SBC"
144 depends on X86 && MTD_JEDEC && MTD_COMPLEX_MAPPINGS 142 depends on X86 && MTD_JEDEC && MTD_COMPLEX_MAPPINGS
@@ -213,74 +211,11 @@ config MTD_NETtel
213 help 211 help
214 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 212 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
215 213
216config MTD_PB1XXX 214config MTD_ALCHEMY
217 tristate "Flash devices on Alchemy PB1xxx boards" 215 tristate ' AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support'
218 depends on MIPS && ( MIPS_PB1000 || MIPS_PB1100 || MIPS_PB1500 ) 216 depends on MIPS && SOC_AU1X00
219 help
220 Flash memory access on Alchemy Pb1000/Pb1100/Pb1500 boards
221
222config MTD_PB1XXX_BOOT
223 bool "PB1x00 boot flash device"
224 depends on MTD_PB1XXX && ( MIPS_PB1100 || MIPS_PB1500 )
225 help
226 Use the first of the two 32MiB flash banks on Pb1100/Pb1500 board.
227 You can say 'Y' to both this and 'MTD_PB1XXX_USER' below, to use
228 both banks.
229
230config MTD_PB1XXX_USER
231 bool "PB1x00 user flash device"
232 depends on MTD_PB1XXX && ( MIPS_PB1100 || MIPS_PB1500 )
233 default y if MTD_PB1XX_BOOT = n
234 help
235 Use the second of the two 32MiB flash banks on Pb1100/Pb1500 board.
236 You can say 'Y' to both this and 'MTD_PB1XXX_BOOT' above, to use
237 both banks.
238
239config MTD_PB1550
240 tristate "Flash devices on Alchemy PB1550 board"
241 depends on MIPS && MIPS_PB1550
242 help
243 Flash memory access on Alchemy Pb1550 board
244
245config MTD_PB1550_BOOT
246 bool "PB1550 boot flash device"
247 depends on MTD_PB1550
248 help
249 Use the first of the two 64MiB flash banks on Pb1550 board.
250 You can say 'Y' to both this and 'MTD_PB1550_USER' below, to use
251 both banks.
252
253config MTD_PB1550_USER
254 bool "PB1550 user flash device"
255 depends on MTD_PB1550
256 default y if MTD_PB1550_BOOT = n
257 help
258 Use the second of the two 64MiB flash banks on Pb1550 board.
259 You can say 'Y' to both this and 'MTD_PB1550_BOOT' above, to use
260 both banks.
261
262config MTD_DB1550
263 tristate "Flash devices on Alchemy DB1550 board"
264 depends on MIPS && MIPS_DB1550
265 help
266 Flash memory access on Alchemy Db1550 board
267
268config MTD_DB1550_BOOT
269 bool "DB1550 boot flash device"
270 depends on MTD_DB1550
271 help
272 Use the first of the two 64MiB flash banks on Db1550 board.
273 You can say 'Y' to both this and 'MTD_DB1550_USER' below, to use
274 both banks.
275
276config MTD_DB1550_USER
277 bool "DB1550 user flash device"
278 depends on MTD_DB1550
279 default y if MTD_DB1550_BOOT = n
280 help 217 help
281 Use the second of the two 64MiB flash banks on Db1550 board. 218 Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
282 You can say 'Y' to both this and 'MTD_DB1550_BOOT' above, to use
283 both banks.
284 219
285config MTD_DILNETPC 220config MTD_DILNETPC
286 tristate "CFI Flash device mapped on DIL/Net PC" 221 tristate "CFI Flash device mapped on DIL/Net PC"
@@ -588,6 +523,15 @@ config MTD_MPC1211
588 This enables access to the flash chips on the Interface MPC-1211(CTP/PCI/MPC-SH02). 523 This enables access to the flash chips on the Interface MPC-1211(CTP/PCI/MPC-SH02).
589 If you have such a board, say 'Y'. 524 If you have such a board, say 'Y'.
590 525
526config MTD_OMAP_NOR
527 tristate "TI OMAP board mappings"
528 depends on MTD_CFI && ARCH_OMAP
529 help
530 This enables access to the NOR flash chips on TI OMAP-based
531 boards defining flash platform devices and flash platform data.
532 These boards include the Innovator, H2, H3, OSK, Perseus2, and
533 more. If you have such a board, say 'Y'.
534
591# This needs CFI or JEDEC, depending on the cards found. 535# This needs CFI or JEDEC, depending on the cards found.
592config MTD_PCI 536config MTD_PCI
593 tristate "PCI MTD driver" 537 tristate "PCI MTD driver"
@@ -607,6 +551,16 @@ config MTD_PCMCIA
607 cards are usually around 4-16MiB in size. This does not include 551 cards are usually around 4-16MiB in size. This does not include
608 Compact Flash cards which are treated as IDE devices. 552 Compact Flash cards which are treated as IDE devices.
609 553
554config MTD_PCMCIA_ANONYMOUS
555 bool "Use PCMCIA MTD drivers for anonymous PCMCIA cards"
556 depends on MTD_PCMCIA
557 default N
558 help
559 If this option is enabled, PCMCIA cards which do not report
560 anything about themselves are assumed to be MTD cards.
561
562 If unsure, say N.
563
610config MTD_UCLINUX 564config MTD_UCLINUX
611 tristate "Generic uClinux RAM/ROM filesystem support" 565 tristate "Generic uClinux RAM/ROM filesystem support"
612 depends on MTD_PARTITIONS && !MMU 566 depends on MTD_PARTITIONS && !MMU
@@ -637,13 +591,14 @@ config MTD_DMV182
637 Map driver for Dy-4 SVME/DMV-182 board. 591 Map driver for Dy-4 SVME/DMV-182 board.
638 592
639config MTD_BAST 593config MTD_BAST
640 tristate "Map driver for Simtec BAST (EB2410ITX)" 594 tristate "Map driver for Simtec BAST (EB2410ITX) or Thorcom VR1000"
641 depends on ARCH_BAST 595 depends on ARCH_BAST || MACH_VR1000
642 select MTD_PARTITIONS 596 select MTD_PARTITIONS
643 select MTD_MAP_BANK_WIDTH_16 597 select MTD_MAP_BANK_WIDTH_16
644 select MTD_JEDECPROBE 598 select MTD_JEDECPROBE
645 help 599 help
646 Map driver for NOR flash on the Simtec BAST (EB2410ITX). 600 Map driver for NOR flash on the Simtec BAST (EB2410ITX), or the
601 Thorcom VR1000
647 602
648 Note, this driver *cannot* over-ride the WP link on the 603 Note, this driver *cannot* over-ride the WP link on the
649 board, or currently detect the state of the link. 604 board, or currently detect the state of the link.
@@ -659,5 +614,15 @@ config MTD_SHARP_SL
659 help 614 help
660 This enables access to the flash chip on the Sharp SL Series of PDAs. 615 This enables access to the flash chip on the Sharp SL Series of PDAs.
661 616
617config MTD_PLATRAM
618 tristate "Map driver for platform device RAM (mtd-ram)"
619 depends on MTD
620 select MTD_RAM
621 help
622 Map driver for RAM areas described via the platform device
623 system.
624
625 This selection automatically selects the map_ram driver.
626
662endmenu 627endmenu
663 628
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 7ffe02b85301..7bcbc49e329f 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# linux/drivers/maps/Makefile 2# linux/drivers/maps/Makefile
3# 3#
4# $Id: Makefile.common,v 1.23 2005/01/05 17:06:36 dwmw2 Exp $ 4# $Id: Makefile.common,v 1.30 2005/07/02 01:53:24 tpoynor Exp $
5 5
6ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y) 6ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y)
7obj-$(CONFIG_MTD) += map_funcs.o 7obj-$(CONFIG_MTD) += map_funcs.o
@@ -15,7 +15,6 @@ obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
15obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o 15obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o
16obj-$(CONFIG_MTD_DC21285) += dc21285.o 16obj-$(CONFIG_MTD_DC21285) += dc21285.o
17obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o 17obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o
18obj-$(CONFIG_MTD_ELAN_104NC) += elan-104nc.o
19obj-$(CONFIG_MTD_EPXA10DB) += epxa10db-flash.o 18obj-$(CONFIG_MTD_EPXA10DB) += epxa10db-flash.o
20obj-$(CONFIG_MTD_IQ80310) += iq80310.o 19obj-$(CONFIG_MTD_IQ80310) += iq80310.o
21obj-$(CONFIG_MTD_L440GX) += l440gx.o 20obj-$(CONFIG_MTD_L440GX) += l440gx.o
@@ -23,6 +22,7 @@ obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o
23obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o 22obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o
24obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 23obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
25obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o 24obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o
25obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o
26obj-$(CONFIG_MTD_MBX860) += mbx860.o 26obj-$(CONFIG_MTD_MBX860) += mbx860.o
27obj-$(CONFIG_MTD_CEIVA) += ceiva.o 27obj-$(CONFIG_MTD_CEIVA) += ceiva.o
28obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 28obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
@@ -44,10 +44,7 @@ obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
44obj-$(CONFIG_MTD_OCELOT) += ocelot.o 44obj-$(CONFIG_MTD_OCELOT) += ocelot.o
45obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 45obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
46obj-$(CONFIG_MTD_PCI) += pci.o 46obj-$(CONFIG_MTD_PCI) += pci.o
47obj-$(CONFIG_MTD_PB1XXX) += pb1xxx-flash.o 47obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o
48obj-$(CONFIG_MTD_DB1X00) += db1x00-flash.o
49obj-$(CONFIG_MTD_PB1550) += pb1550-flash.o
50obj-$(CONFIG_MTD_DB1550) += db1550-flash.o
51obj-$(CONFIG_MTD_LASAT) += lasat.o 48obj-$(CONFIG_MTD_LASAT) += lasat.o
52obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o 49obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
53obj-$(CONFIG_MTD_EDB7312) += edb7312.o 50obj-$(CONFIG_MTD_EDB7312) += edb7312.o
@@ -71,3 +68,5 @@ obj-$(CONFIG_MTD_IXP2000) += ixp2000.o
71obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o 68obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o
72obj-$(CONFIG_MTD_DMV182) += dmv182.o 69obj-$(CONFIG_MTD_DMV182) += dmv182.o
73obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o 70obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o
71obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
72obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c
new file mode 100644
index 000000000000..27fd2a3c3b60
--- /dev/null
+++ b/drivers/mtd/maps/alchemy-flash.c
@@ -0,0 +1,192 @@
1/*
2 * Flash memory access on AMD Alchemy evaluation boards
3 *
4 * $Id: alchemy-flash.c,v 1.1 2005/02/27 21:50:21 ppopov Exp $
5 *
6 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
7 *
8 */
9
10#include <linux/config.h>
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/kernel.h>
15
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
18#include <linux/mtd/partitions.h>
19
20#include <asm/io.h>
21
22#ifdef DEBUG_RW
23#define DBG(x...) printk(x)
24#else
25#define DBG(x...)
26#endif
27
28#ifdef CONFIG_MIPS_PB1000
29#define BOARD_MAP_NAME "Pb1000 Flash"
30#define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
31#define BOARD_FLASH_WIDTH 4 /* 32-bits */
32#endif
33
34#ifdef CONFIG_MIPS_PB1500
35#define BOARD_MAP_NAME "Pb1500 Flash"
36#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
37#define BOARD_FLASH_WIDTH 4 /* 32-bits */
38#endif
39
40#ifdef CONFIG_MIPS_PB1100
41#define BOARD_MAP_NAME "Pb1100 Flash"
42#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
43#define BOARD_FLASH_WIDTH 4 /* 32-bits */
44#endif
45
46#ifdef CONFIG_MIPS_PB1550
47#define BOARD_MAP_NAME "Pb1550 Flash"
48#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
49#define BOARD_FLASH_WIDTH 4 /* 32-bits */
50#endif
51
52#ifdef CONFIG_MIPS_PB1200
53#define BOARD_MAP_NAME "Pb1200 Flash"
54#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
55#define BOARD_FLASH_WIDTH 2 /* 16-bits */
56#endif
57
58#ifdef CONFIG_MIPS_DB1000
59#define BOARD_MAP_NAME "Db1000 Flash"
60#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
61#define BOARD_FLASH_WIDTH 4 /* 32-bits */
62#endif
63
64#ifdef CONFIG_MIPS_DB1500
65#define BOARD_MAP_NAME "Db1500 Flash"
66#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
67#define BOARD_FLASH_WIDTH 4 /* 32-bits */
68#endif
69
70#ifdef CONFIG_MIPS_DB1100
71#define BOARD_MAP_NAME "Db1100 Flash"
72#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
73#define BOARD_FLASH_WIDTH 4 /* 32-bits */
74#endif
75
76#ifdef CONFIG_MIPS_DB1550
77#define BOARD_MAP_NAME "Db1550 Flash"
78#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
79#define BOARD_FLASH_WIDTH 4 /* 32-bits */
80#endif
81
82#ifdef CONFIG_MIPS_DB1200
83#define BOARD_MAP_NAME "Db1200 Flash"
84#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
85#define BOARD_FLASH_WIDTH 2 /* 16-bits */
86#endif
87
88#ifdef CONFIG_MIPS_HYDROGEN3
89#define BOARD_MAP_NAME "Hydrogen3 Flash"
90#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
91#define BOARD_FLASH_WIDTH 4 /* 32-bits */
92#define USE_LOCAL_ACCESSORS /* why? */
93#endif
94
95#ifdef CONFIG_MIPS_BOSPORUS
96#define BOARD_MAP_NAME "Bosporus Flash"
97#define BOARD_FLASH_SIZE 0x01000000 /* 16MB */
98#define BOARD_FLASH_WIDTH 2 /* 16-bits */
99#endif
100
101#ifdef CONFIG_MIPS_MIRAGE
102#define BOARD_MAP_NAME "Mirage Flash"
103#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
104#define BOARD_FLASH_WIDTH 4 /* 32-bits */
105#define USE_LOCAL_ACCESSORS /* why? */
106#endif
107
108static struct map_info alchemy_map = {
109 .name = BOARD_MAP_NAME,
110};
111
112static struct mtd_partition alchemy_partitions[] = {
113 {
114 .name = "User FS",
115 .size = BOARD_FLASH_SIZE - 0x00400000,
116 .offset = 0x0000000
117 },{
118 .name = "YAMON",
119 .size = 0x0100000,
120 .offset = MTDPART_OFS_APPEND,
121 .mask_flags = MTD_WRITEABLE
122 },{
123 .name = "raw kernel",
124 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
125 .offset = MTDPART_OFS_APPEND,
126 }
127};
128
129#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
130
131static struct mtd_info *mymtd;
132
133int __init alchemy_mtd_init(void)
134{
135 struct mtd_partition *parts;
136 int nb_parts = 0;
137 unsigned long window_addr;
138 unsigned long window_size;
139
140 /* Default flash buswidth */
141 alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
142
143 window_addr = 0x20000000 - BOARD_FLASH_SIZE;
144 window_size = BOARD_FLASH_SIZE;
145#ifdef CONFIG_MIPS_MIRAGE_WHY
146 /* Boot ROM flash bank only; no user bank */
147 window_addr = 0x1C000000;
148 window_size = 0x04000000;
149 /* USERFS from 0x1C00 0000 to 0x1FC00000 */
150 alchemy_partitions[0].size = 0x03C00000;
151#endif
152
153 /*
154 * Static partition definition selection
155 */
156 parts = alchemy_partitions;
157 nb_parts = NB_OF(alchemy_partitions);
158 alchemy_map.size = window_size;
159
160 /*
161 * Now let's probe for the actual flash. Do it here since
162 * specific machine settings might have been set above.
163 */
164 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
165 alchemy_map.bankwidth*8);
166 alchemy_map.virt = ioremap(window_addr, window_size);
167 mymtd = do_map_probe("cfi_probe", &alchemy_map);
168 if (!mymtd) {
169 iounmap(alchemy_map.virt);
170 return -ENXIO;
171 }
172 mymtd->owner = THIS_MODULE;
173
174 add_mtd_partitions(mymtd, parts, nb_parts);
175 return 0;
176}
177
178static void __exit alchemy_mtd_cleanup(void)
179{
180 if (mymtd) {
181 del_mtd_partitions(mymtd);
182 map_destroy(mymtd);
183 iounmap(alchemy_map.virt);
184 }
185}
186
187module_init(alchemy_mtd_init);
188module_exit(alchemy_mtd_cleanup);
189
190MODULE_AUTHOR("Embedded Alley Solutions, Inc");
191MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver");
192MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 51e97b05304e..e8a900a77685 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -2,7 +2,7 @@
2 * amd76xrom.c 2 * amd76xrom.c
3 * 3 *
4 * Normal mappings of chips in physical memory 4 * Normal mappings of chips in physical memory
5 * $Id: amd76xrom.c,v 1.19 2004/11/28 09:40:39 dwmw2 Exp $ 5 * $Id: amd76xrom.c,v 1.20 2005/03/18 14:04:35 gleixner Exp $
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/module.h>
@@ -314,7 +314,7 @@ static int __init init_amd76xrom(void)
314 } 314 }
315 return -ENXIO; 315 return -ENXIO;
316#if 0 316#if 0
317 return pci_module_init(&amd76xrom_driver); 317 return pci_register_driver(&amd76xrom_driver);
318#endif 318#endif
319} 319}
320 320
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index 44de3a81b277..0c45464e3f7b 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -1,14 +1,15 @@
1/* linux/drivers/mtd/maps/bast_flash.c 1/* linux/drivers/mtd/maps/bast_flash.c
2 * 2 *
3 * Copyright (c) 2004 Simtec Electronics 3 * Copyright (c) 2004-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 4 * Ben Dooks <ben@simtec.co.uk>
5 * 5 *
6 * Simtec Bast (EB2410ITX) NOR MTD Mapping driver 6 * Simtec Bast (EB2410ITX) NOR MTD Mapping driver
7 * 7 *
8 * Changelog: 8 * Changelog:
9 * 20-Sep-2004 BJD Initial version 9 * 20-Sep-2004 BJD Initial version
10 * 17-Jan-2005 BJD Add whole device if no partitions found
10 * 11 *
11 * $Id: bast-flash.c,v 1.1 2004/09/21 14:29:04 bjd Exp $ 12 * $Id: bast-flash.c,v 1.2 2005/01/18 11:13:47 bjd Exp $
12 * 13 *
13 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
@@ -46,9 +47,9 @@
46#include <asm/arch/bast-cpld.h> 47#include <asm/arch/bast-cpld.h>
47 48
48#ifdef CONFIG_MTD_BAST_MAXSIZE 49#ifdef CONFIG_MTD_BAST_MAXSIZE
49#define AREA_MAXSIZE (CONFIG_MTD_BAST_MAXSIZE * (1024*1024)) 50#define AREA_MAXSIZE (CONFIG_MTD_BAST_MAXSIZE * SZ_1M)
50#else 51#else
51#define AREA_MAXSIZE (32*1024*1024) 52#define AREA_MAXSIZE (32 * SZ_1M)
52#endif 53#endif
53 54
54#define PFX "bast-flash: " 55#define PFX "bast-flash: "
@@ -189,6 +190,8 @@ static int bast_flash_probe(struct device *dev)
189 err = add_mtd_partitions(info->mtd, info->partitions, err); 190 err = add_mtd_partitions(info->mtd, info->partitions, err);
190 if (err) 191 if (err)
191 printk(KERN_ERR PFX "cannot add/parse partitions\n"); 192 printk(KERN_ERR PFX "cannot add/parse partitions\n");
193 } else {
194 err = add_mtd_device(info->mtd);
192 } 195 }
193 196
194 if (err == 0) 197 if (err == 0)
diff --git a/drivers/mtd/maps/db1550-flash.c b/drivers/mtd/maps/db1550-flash.c
deleted file mode 100644
index d213888462a4..000000000000
--- a/drivers/mtd/maps/db1550-flash.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/*
2 * Flash memory access on Alchemy Db1550 board
3 *
4 * $Id: db1550-flash.c,v 1.7 2004/11/04 13:24:14 gleixner Exp $
5 *
6 * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c:
7 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/map.h>
19#include <linux/mtd/partitions.h>
20
21#include <asm/io.h>
22
23#ifdef DEBUG_RW
24#define DBG(x...) printk(x)
25#else
26#define DBG(x...)
27#endif
28
29static unsigned long window_addr;
30static unsigned long window_size;
31
32
33static struct map_info db1550_map = {
34 .name = "Db1550 flash",
35};
36
37static unsigned char flash_bankwidth = 4;
38
39/*
40 * Support only 64MB NOR Flash parts
41 */
42
43#if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
44#define DB1550_BOTH_BANKS
45#elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER)
46#define DB1550_BOOT_ONLY
47#elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
48#define DB1550_USER_ONLY
49#endif
50
51#ifdef DB1550_BOTH_BANKS
52/* both banks will be used. Combine the first bank and the first
53 * part of the second bank together into a single jffs/jffs2
54 * partition.
55 */
56static struct mtd_partition db1550_partitions[] = {
57 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
58 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
59 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
60 */
61 {
62 .name = "User FS",
63 .size = (0x1FC00000 - 0x18000000),
64 .offset = 0x0000000
65 },{
66 .name = "yamon",
67 .size = 0x0100000,
68 .offset = MTDPART_OFS_APPEND,
69 .mask_flags = MTD_WRITEABLE
70 },{
71 .name = "raw kernel",
72 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
73 .offset = MTDPART_OFS_APPEND,
74 }
75};
76#elif defined(DB1550_BOOT_ONLY)
77static struct mtd_partition db1550_partitions[] = {
78 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
79 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
80 */
81 {
82 .name = "User FS",
83 .size = 0x03c00000,
84 .offset = 0x0000000
85 },{
86 .name = "yamon",
87 .size = 0x0100000,
88 .offset = MTDPART_OFS_APPEND,
89 .mask_flags = MTD_WRITEABLE
90 },{
91 .name = "raw kernel",
92 .size = (0x300000-0x40000), /* last 256KB is yamon env */
93 .offset = MTDPART_OFS_APPEND,
94 }
95};
96#elif defined(DB1550_USER_ONLY)
97static struct mtd_partition db1550_partitions[] = {
98 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
99 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
100 */
101 {
102 .name = "User FS",
103 .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
104 .offset = 0x0000000
105 },{
106 .name = "raw kernel",
107 .size = MTDPART_SIZ_FULL,
108 .offset = MTDPART_OFS_APPEND,
109 }
110};
111#else
112#error MTD_DB1550 define combo error /* should never happen */
113#endif
114
115#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
116
117static struct mtd_info *mymtd;
118
119/*
120 * Probe the flash density and setup window address and size
121 * based on user CONFIG options. There are times when we don't
122 * want the MTD driver to be probing the boot or user flash,
123 * so having the option to enable only one bank is important.
124 */
125int setup_flash_params(void)
126{
127#if defined(DB1550_BOTH_BANKS)
128 window_addr = 0x18000000;
129 window_size = 0x8000000;
130#elif defined(DB1550_BOOT_ONLY)
131 window_addr = 0x1C000000;
132 window_size = 0x4000000;
133#else /* USER ONLY */
134 window_addr = 0x18000000;
135 window_size = 0x4000000;
136#endif
137 return 0;
138}
139
140int __init db1550_mtd_init(void)
141{
142 struct mtd_partition *parts;
143 int nb_parts = 0;
144
145 /* Default flash bankwidth */
146 db1550_map.bankwidth = flash_bankwidth;
147
148 if (setup_flash_params())
149 return -ENXIO;
150
151 /*
152 * Static partition definition selection
153 */
154 parts = db1550_partitions;
155 nb_parts = NB_OF(db1550_partitions);
156 db1550_map.size = window_size;
157
158 /*
159 * Now let's probe for the actual flash. Do it here since
160 * specific machine settings might have been set above.
161 */
162 printk(KERN_NOTICE "Db1550 flash: probing %d-bit flash bus\n",
163 db1550_map.bankwidth*8);
164 db1550_map.virt = ioremap(window_addr, window_size);
165 mymtd = do_map_probe("cfi_probe", &db1550_map);
166 if (!mymtd) return -ENXIO;
167 mymtd->owner = THIS_MODULE;
168
169 add_mtd_partitions(mymtd, parts, nb_parts);
170 return 0;
171}
172
173static void __exit db1550_mtd_cleanup(void)
174{
175 if (mymtd) {
176 del_mtd_partitions(mymtd);
177 map_destroy(mymtd);
178 iounmap((void *) db1550_map.virt);
179 }
180}
181
182module_init(db1550_mtd_init);
183module_exit(db1550_mtd_cleanup);
184
185MODULE_AUTHOR("Embedded Edge, LLC");
186MODULE_DESCRIPTION("Db1550 mtd map driver");
187MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/db1x00-flash.c b/drivers/mtd/maps/db1x00-flash.c
deleted file mode 100644
index faa68ec56902..000000000000
--- a/drivers/mtd/maps/db1x00-flash.c
+++ /dev/null
@@ -1,226 +0,0 @@
1/*
2 * Flash memory access on Alchemy Db1xxx boards
3 *
4 * $Id: db1x00-flash.c,v 1.6 2004/11/04 13:24:14 gleixner Exp $
5 *
6 * (C) 2003 Pete Popov <ppopov@embeddedalley.com>
7 *
8 */
9
10#include <linux/config.h>
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/kernel.h>
15
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
18#include <linux/mtd/partitions.h>
19
20#include <asm/io.h>
21
22#ifdef DEBUG_RW
23#define DBG(x...) printk(x)
24#else
25#define DBG(x...)
26#endif
27
28/* MTD CONFIG OPTIONS */
29#if defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
30#define DB1X00_BOTH_BANKS
31#elif defined(CONFIG_MTD_DB1X00_BOOT) && !defined(CONFIG_MTD_DB1X00_USER)
32#define DB1X00_BOOT_ONLY
33#elif !defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
34#define DB1X00_USER_ONLY
35#endif
36
37static unsigned long window_addr;
38static unsigned long window_size;
39static unsigned long flash_size;
40
41static unsigned short *bcsr = (unsigned short *)0xAE000000;
42static unsigned char flash_bankwidth = 4;
43
44/*
45 * The Db1x boards support different flash densities. We setup
46 * the mtd_partition structures below for default of 64Mbit
47 * flash densities, and override the partitions sizes, if
48 * necessary, after we check the board status register.
49 */
50
51#ifdef DB1X00_BOTH_BANKS
52/* both banks will be used. Combine the first bank and the first
53 * part of the second bank together into a single jffs/jffs2
54 * partition.
55 */
56static struct mtd_partition db1x00_partitions[] = {
57 {
58 .name = "User FS",
59 .size = 0x1c00000,
60 .offset = 0x0000000
61 },{
62 .name = "yamon",
63 .size = 0x0100000,
64 .offset = MTDPART_OFS_APPEND,
65 .mask_flags = MTD_WRITEABLE
66 },{
67 .name = "raw kernel",
68 .size = (0x300000-0x40000), /* last 256KB is env */
69 .offset = MTDPART_OFS_APPEND,
70 }
71};
72#elif defined(DB1X00_BOOT_ONLY)
73static struct mtd_partition db1x00_partitions[] = {
74 {
75 .name = "User FS",
76 .size = 0x00c00000,
77 .offset = 0x0000000
78 },{
79 .name = "yamon",
80 .size = 0x0100000,
81 .offset = MTDPART_OFS_APPEND,
82 .mask_flags = MTD_WRITEABLE
83 },{
84 .name = "raw kernel",
85 .size = (0x300000-0x40000), /* last 256KB is env */
86 .offset = MTDPART_OFS_APPEND,
87 }
88};
89#elif defined(DB1X00_USER_ONLY)
90static struct mtd_partition db1x00_partitions[] = {
91 {
92 .name = "User FS",
93 .size = 0x0e00000,
94 .offset = 0x0000000
95 },{
96 .name = "raw kernel",
97 .size = MTDPART_SIZ_FULL,
98 .offset = MTDPART_OFS_APPEND,
99 }
100};
101#else
102#error MTD_DB1X00 define combo error /* should never happen */
103#endif
104#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
105
106#define NAME "Db1x00 Linux Flash"
107
108static struct map_info db1xxx_mtd_map = {
109 .name = NAME,
110};
111
112static struct mtd_partition *parsed_parts;
113static struct mtd_info *db1xxx_mtd;
114
115/*
116 * Probe the flash density and setup window address and size
117 * based on user CONFIG options. There are times when we don't
118 * want the MTD driver to be probing the boot or user flash,
119 * so having the option to enable only one bank is important.
120 */
121int setup_flash_params(void)
122{
123 switch ((bcsr[2] >> 14) & 0x3) {
124 case 0: /* 64Mbit devices */
125 flash_size = 0x800000; /* 8MB per part */
126#if defined(DB1X00_BOTH_BANKS)
127 window_addr = 0x1E000000;
128 window_size = 0x2000000;
129#elif defined(DB1X00_BOOT_ONLY)
130 window_addr = 0x1F000000;
131 window_size = 0x1000000;
132#else /* USER ONLY */
133 window_addr = 0x1E000000;
134 window_size = 0x1000000;
135#endif
136 break;
137 case 1:
138 /* 128 Mbit devices */
139 flash_size = 0x1000000; /* 16MB per part */
140#if defined(DB1X00_BOTH_BANKS)
141 window_addr = 0x1C000000;
142 window_size = 0x4000000;
143 /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
144 db1x00_partitions[0].size = 0x3C00000;
145#elif defined(DB1X00_BOOT_ONLY)
146 window_addr = 0x1E000000;
147 window_size = 0x2000000;
148 /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
149 db1x00_partitions[0].size = 0x1C00000;
150#else /* USER ONLY */
151 window_addr = 0x1C000000;
152 window_size = 0x2000000;
153 /* USERFS from 0x1C00 0000 to 0x1DE00000 */
154 db1x00_partitions[0].size = 0x1DE0000;
155#endif
156 break;
157 case 2:
158 /* 256 Mbit devices */
159 flash_size = 0x4000000; /* 64MB per part */
160#if defined(DB1X00_BOTH_BANKS)
161 return 1;
162#elif defined(DB1X00_BOOT_ONLY)
163 /* Boot ROM flash bank only; no user bank */
164 window_addr = 0x1C000000;
165 window_size = 0x4000000;
166 /* USERFS from 0x1C00 0000 to 0x1FC00000 */
167 db1x00_partitions[0].size = 0x3C00000;
168#else /* USER ONLY */
169 return 1;
170#endif
171 break;
172 default:
173 return 1;
174 }
175 db1xxx_mtd_map.size = window_size;
176 db1xxx_mtd_map.bankwidth = flash_bankwidth;
177 db1xxx_mtd_map.phys = window_addr;
178 db1xxx_mtd_map.bankwidth = flash_bankwidth;
179 return 0;
180}
181
182int __init db1x00_mtd_init(void)
183{
184 struct mtd_partition *parts;
185 int nb_parts = 0;
186
187 if (setup_flash_params())
188 return -ENXIO;
189
190 /*
191 * Static partition definition selection
192 */
193 parts = db1x00_partitions;
194 nb_parts = NB_OF(db1x00_partitions);
195
196 /*
197 * Now let's probe for the actual flash. Do it here since
198 * specific machine settings might have been set above.
199 */
200 printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n",
201 db1xxx_mtd_map.bankwidth*8);
202 db1xxx_mtd_map.virt = ioremap(window_addr, window_size);
203 db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map);
204 if (!db1xxx_mtd) return -ENXIO;
205 db1xxx_mtd->owner = THIS_MODULE;
206
207 add_mtd_partitions(db1xxx_mtd, parts, nb_parts);
208 return 0;
209}
210
211static void __exit db1x00_mtd_cleanup(void)
212{
213 if (db1xxx_mtd) {
214 del_mtd_partitions(db1xxx_mtd);
215 map_destroy(db1xxx_mtd);
216 if (parsed_parts)
217 kfree(parsed_parts);
218 }
219}
220
221module_init(db1x00_mtd_init);
222module_exit(db1x00_mtd_cleanup);
223
224MODULE_AUTHOR("Pete Popov");
225MODULE_DESCRIPTION("Db1x00 mtd map driver");
226MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/elan-104nc.c b/drivers/mtd/maps/elan-104nc.c
deleted file mode 100644
index e9465f5c069e..000000000000
--- a/drivers/mtd/maps/elan-104nc.c
+++ /dev/null
@@ -1,228 +0,0 @@
1/* elan-104nc.c -- MTD map driver for Arcom Control Systems ELAN-104NC
2
3 Copyright (C) 2000 Arcom Control System Ltd
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18
19 $Id: elan-104nc.c,v 1.25 2004/11/28 09:40:39 dwmw2 Exp $
20
21The ELAN-104NC has up to 8 Mibyte of Intel StrataFlash (28F320/28F640) in x16
22mode. This drivers uses the CFI probe and Intel Extended Command Set drivers.
23
24The flash is accessed as follows:
25
26 32 kbyte memory window at 0xb0000-0xb7fff
27
28 16 bit I/O port (0x22) for some sort of paging.
29
30The single flash device is divided into 3 partition which appear as separate
31MTD devices.
32
33Linux thinks that the I/O port is used by the PIC and hence check_region() will
34always fail. So we don't do it. I just hope it doesn't break anything.
35*/
36#include <linux/module.h>
37#include <linux/slab.h>
38#include <linux/ioport.h>
39#include <linux/init.h>
40#include <asm/io.h>
41
42#include <linux/mtd/map.h>
43#include <linux/mtd/mtd.h>
44#include <linux/mtd/partitions.h>
45
46#define WINDOW_START 0xb0000
47/* Number of bits in offset. */
48#define WINDOW_SHIFT 15
49#define WINDOW_LENGTH (1 << WINDOW_SHIFT)
50/* The bits for the offset into the window. */
51#define WINDOW_MASK (WINDOW_LENGTH-1)
52#define PAGE_IO 0x22
53#define PAGE_IO_SIZE 2
54
55static volatile int page_in_window = -1; // Current page in window.
56static void __iomem *iomapadr;
57static DEFINE_SPINLOCK(elan_104nc_spin);
58
59/* partition_info gives details on the logical partitions that the split the
60 * single flash device into. If the size if zero we use up to the end of the
61 * device. */
62static struct mtd_partition partition_info[]={
63 { .name = "ELAN-104NC flash boot partition",
64 .offset = 0,
65 .size = 640*1024 },
66 { .name = "ELAN-104NC flash partition 1",
67 .offset = 640*1024,
68 .size = 896*1024 },
69 { .name = "ELAN-104NC flash partition 2",
70 .offset = (640+896)*1024 }
71};
72#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
73
74/*
75 * If no idea what is going on here. This is taken from the FlashFX stuff.
76 */
77#define ROMCS 1
78
79static inline void elan_104nc_setup(void)
80{
81 u16 t;
82
83 outw( 0x0023 + ROMCS*2, PAGE_IO );
84 t=inb( PAGE_IO+1 );
85
86 t=(t & 0xf9) | 0x04;
87
88 outw( ((0x0023 + ROMCS*2) | (t << 8)), PAGE_IO );
89}
90
91static inline void elan_104nc_page(struct map_info *map, unsigned long ofs)
92{
93 unsigned long page = ofs >> WINDOW_SHIFT;
94
95 if( page!=page_in_window ) {
96 int cmd1;
97 int cmd2;
98
99 cmd1=(page & 0x700) + 0x0833 + ROMCS*0x4000;
100 cmd2=((page & 0xff) << 8) + 0x0032;
101
102 outw( cmd1, PAGE_IO );
103 outw( cmd2, PAGE_IO );
104
105 page_in_window = page;
106 }
107}
108
109
110static map_word elan_104nc_read16(struct map_info *map, unsigned long ofs)
111{
112 map_word ret;
113 spin_lock(&elan_104nc_spin);
114 elan_104nc_page(map, ofs);
115 ret.x[0] = readw(iomapadr + (ofs & WINDOW_MASK));
116 spin_unlock(&elan_104nc_spin);
117 return ret;
118}
119
120static void elan_104nc_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
121{
122 while (len) {
123 unsigned long thislen = len;
124 if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
125 thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
126
127 spin_lock(&elan_104nc_spin);
128 elan_104nc_page(map, from);
129 memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
130 spin_unlock(&elan_104nc_spin);
131 to += thislen;
132 from += thislen;
133 len -= thislen;
134 }
135}
136
137static void elan_104nc_write16(struct map_info *map, map_word d, unsigned long adr)
138{
139 spin_lock(&elan_104nc_spin);
140 elan_104nc_page(map, adr);
141 writew(d.x[0], iomapadr + (adr & WINDOW_MASK));
142 spin_unlock(&elan_104nc_spin);
143}
144
145static void elan_104nc_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
146{
147 while(len) {
148 unsigned long thislen = len;
149 if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
150 thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
151
152 spin_lock(&elan_104nc_spin);
153 elan_104nc_page(map, to);
154 memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
155 spin_unlock(&elan_104nc_spin);
156 to += thislen;
157 from += thislen;
158 len -= thislen;
159 }
160}
161
162static struct map_info elan_104nc_map = {
163 .name = "ELAN-104NC flash",
164 .phys = NO_XIP,
165 .size = 8*1024*1024, /* this must be set to a maximum possible amount
166 of flash so the cfi probe routines find all
167 the chips */
168 .bankwidth = 2,
169 .read = elan_104nc_read16,
170 .copy_from = elan_104nc_copy_from,
171 .write = elan_104nc_write16,
172 .copy_to = elan_104nc_copy_to
173};
174
175/* MTD device for all of the flash. */
176static struct mtd_info *all_mtd;
177
178static void cleanup_elan_104nc(void)
179{
180 if( all_mtd ) {
181 del_mtd_partitions( all_mtd );
182 map_destroy( all_mtd );
183 }
184
185 iounmap(iomapadr);
186}
187
188static int __init init_elan_104nc(void)
189{
190 /* Urg! We use I/O port 0x22 without request_region()ing it,
191 because it's already allocated to the PIC. */
192
193 iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
194 if (!iomapadr) {
195 printk( KERN_ERR"%s: failed to ioremap memory region\n",
196 elan_104nc_map.name );
197 return -EIO;
198 }
199
200 printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
201 elan_104nc_map.name,
202 PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
203 WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
204
205 elan_104nc_setup();
206
207 /* Probe for chip. */
208 all_mtd = do_map_probe("cfi_probe", &elan_104nc_map );
209 if( !all_mtd ) {
210 cleanup_elan_104nc();
211 return -ENXIO;
212 }
213
214 all_mtd->owner = THIS_MODULE;
215
216 /* Create MTD devices for each partition. */
217 add_mtd_partitions( all_mtd, partition_info, NUM_PARTITIONS );
218
219 return 0;
220}
221
222module_init(init_elan_104nc);
223module_exit(cleanup_elan_104nc);
224
225
226MODULE_LICENSE("GPL");
227MODULE_AUTHOR("Arcom Control Systems Ltd.");
228MODULE_DESCRIPTION("MTD map driver for Arcom Control Systems ELAN-104NC");
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 29d1cc1bb426..e505207cd489 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -2,7 +2,7 @@
2 * ichxrom.c 2 * ichxrom.c
3 * 3 *
4 * Normal mappings of chips in physical memory 4 * Normal mappings of chips in physical memory
5 * $Id: ichxrom.c,v 1.16 2004/11/28 09:40:39 dwmw2 Exp $ 5 * $Id: ichxrom.c,v 1.18 2005/07/07 10:26:20 dwmw2 Exp $
6 */ 6 */
7 7
8#include <linux/module.h> 8#include <linux/module.h>
@@ -338,9 +338,9 @@ static struct pci_device_id ichxrom_pci_tbl[] __devinitdata = {
338 { 0, }, 338 { 0, },
339}; 339};
340 340
341#if 0
341MODULE_DEVICE_TABLE(pci, ichxrom_pci_tbl); 342MODULE_DEVICE_TABLE(pci, ichxrom_pci_tbl);
342 343
343#if 0
344static struct pci_driver ichxrom_driver = { 344static struct pci_driver ichxrom_driver = {
345 .name = MOD_NAME, 345 .name = MOD_NAME,
346 .id_table = ichxrom_pci_tbl, 346 .id_table = ichxrom_pci_tbl,
@@ -366,7 +366,7 @@ static int __init init_ichxrom(void)
366 } 366 }
367 return -ENXIO; 367 return -ENXIO;
368#if 0 368#if 0
369 return pci_module_init(&ichxrom_driver); 369 return pci_register_driver(&ichxrom_driver);
370#endif 370#endif
371} 371}
372 372
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index c5b5f447e34b..3e94b616743d 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ixp2000.c,v 1.5 2004/11/16 17:15:48 dsaxena Exp $ 2 * $Id: ixp2000.c,v 1.6 2005/03/18 14:07:46 gleixner Exp $
3 * 3 *
4 * drivers/mtd/maps/ixp2000.c 4 * drivers/mtd/maps/ixp2000.c
5 * 5 *
@@ -216,11 +216,6 @@ static int ixp2000_flash_probe(struct device *_dev)
216 goto Error; 216 goto Error;
217 } 217 }
218 218
219 /*
220 * Setup read mode for FLASH
221 */
222 *IXP2000_SLOWPORT_FRM = 1;
223
224#if defined(__ARMEB__) 219#if defined(__ARMEB__)
225 /* 220 /*
226 * Enable erratum 44 workaround for NPUs with broken slowport 221 * Enable erratum 44 workaround for NPUs with broken slowport
diff --git a/drivers/mtd/maps/mainstone-flash.c b/drivers/mtd/maps/mainstone-flash.c
new file mode 100644
index 000000000000..87e93fa60588
--- /dev/null
+++ b/drivers/mtd/maps/mainstone-flash.c
@@ -0,0 +1,178 @@
1/*
2 * $Id: $
3 *
4 * Map driver for the Mainstone developer platform.
5 *
6 * Author: Nicolas Pitre
7 * Copyright: (C) 2001 MontaVista Software Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/dma-mapping.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h>
22#include <asm/io.h>
23#include <asm/hardware.h>
24#include <asm/arch/pxa-regs.h>
25#include <asm/arch/mainstone.h>
26
27
28#define ROM_ADDR 0x00000000
29#define FLASH_ADDR 0x04000000
30
31#define WINDOW_SIZE 0x04000000
32
33static void mainstone_map_inval_cache(struct map_info *map, unsigned long from,
34 ssize_t len)
35{
36 consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
37}
38
39static struct map_info mainstone_maps[2] = { {
40 .size = WINDOW_SIZE,
41 .phys = PXA_CS0_PHYS,
42 .inval_cache = mainstone_map_inval_cache,
43}, {
44 .size = WINDOW_SIZE,
45 .phys = PXA_CS1_PHYS,
46 .inval_cache = mainstone_map_inval_cache,
47} };
48
49static struct mtd_partition mainstone_partitions[] = {
50 {
51 .name = "Bootloader",
52 .size = 0x00040000,
53 .offset = 0,
54 .mask_flags = MTD_WRITEABLE /* force read-only */
55 },{
56 .name = "Kernel",
57 .size = 0x00400000,
58 .offset = 0x00040000,
59 },{
60 .name = "Filesystem",
61 .size = MTDPART_SIZ_FULL,
62 .offset = 0x00440000
63 }
64};
65
66static struct mtd_info *mymtds[2];
67static struct mtd_partition *parsed_parts[2];
68static int nr_parsed_parts[2];
69
70static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
71
72static int __init init_mainstone(void)
73{
74 int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */
75 int ret = 0, i;
76
77 mainstone_maps[0].bankwidth = (BOOT_DEF & 1) ? 2 : 4;
78 mainstone_maps[1].bankwidth = 4;
79
80 /* Compensate for SW7 which swaps the flash banks */
81 mainstone_maps[SW7].name = "processor flash";
82 mainstone_maps[SW7 ^ 1].name = "main board flash";
83
84 printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
85 mainstone_maps[0].name);
86
87 for (i = 0; i < 2; i++) {
88 mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys,
89 WINDOW_SIZE);
90 if (!mainstone_maps[i].virt) {
91 printk(KERN_WARNING "Failed to ioremap %s\n",
92 mainstone_maps[i].name);
93 if (!ret)
94 ret = -ENOMEM;
95 continue;
96 }
97 mainstone_maps[i].cached =
98 ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE);
99 if (!mainstone_maps[i].cached)
100 printk(KERN_WARNING "Failed to ioremap cached %s\n",
101 mainstone_maps[i].name);
102 simple_map_init(&mainstone_maps[i]);
103
104 printk(KERN_NOTICE
105 "Probing %s at physical address 0x%08lx"
106 " (%d-bit bankwidth)\n",
107 mainstone_maps[i].name, mainstone_maps[i].phys,
108 mainstone_maps[i].bankwidth * 8);
109
110 mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]);
111
112 if (!mymtds[i]) {
113 iounmap((void *)mainstone_maps[i].virt);
114 if (mainstone_maps[i].cached)
115 iounmap(mainstone_maps[i].cached);
116 if (!ret)
117 ret = -EIO;
118 continue;
119 }
120 mymtds[i]->owner = THIS_MODULE;
121
122 ret = parse_mtd_partitions(mymtds[i], probes,
123 &parsed_parts[i], 0);
124
125 if (ret > 0)
126 nr_parsed_parts[i] = ret;
127 }
128
129 if (!mymtds[0] && !mymtds[1])
130 return ret;
131
132 for (i = 0; i < 2; i++) {
133 if (!mymtds[i]) {
134 printk(KERN_WARNING "%s is absent. Skipping\n",
135 mainstone_maps[i].name);
136 } else if (nr_parsed_parts[i]) {
137 add_mtd_partitions(mymtds[i], parsed_parts[i],
138 nr_parsed_parts[i]);
139 } else if (!i) {
140 printk("Using static partitions on %s\n",
141 mainstone_maps[i].name);
142 add_mtd_partitions(mymtds[i], mainstone_partitions,
143 ARRAY_SIZE(mainstone_partitions));
144 } else {
145 printk("Registering %s as whole device\n",
146 mainstone_maps[i].name);
147 add_mtd_device(mymtds[i]);
148 }
149 }
150 return 0;
151}
152
153static void __exit cleanup_mainstone(void)
154{
155 int i;
156 for (i = 0; i < 2; i++) {
157 if (!mymtds[i])
158 continue;
159
160 if (nr_parsed_parts[i] || !i)
161 del_mtd_partitions(mymtds[i]);
162 else
163 del_mtd_device(mymtds[i]);
164
165 map_destroy(mymtds[i]);
166 iounmap((void *)mainstone_maps[i].virt);
167 if (mainstone_maps[i].cached)
168 iounmap(mainstone_maps[i].cached);
169 kfree(parsed_parts[i]);
170 }
171}
172
173module_init(init_mainstone);
174module_exit(cleanup_mainstone);
175
176MODULE_LICENSE("GPL");
177MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
178MODULE_DESCRIPTION("MTD map driver for Intel Mainstone");
diff --git a/drivers/mtd/maps/map_funcs.c b/drivers/mtd/maps/map_funcs.c
index 38f6a7af53f8..9105e6ca0aa6 100644
--- a/drivers/mtd/maps/map_funcs.c
+++ b/drivers/mtd/maps/map_funcs.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: map_funcs.c,v 1.9 2004/07/13 22:33:15 dwmw2 Exp $ 2 * $Id: map_funcs.c,v 1.10 2005/06/06 23:04:36 tpoynor Exp $
3 * 3 *
4 * Out-of-line map I/O functions for simple maps when CONFIG_COMPLEX_MAPPINGS 4 * Out-of-line map I/O functions for simple maps when CONFIG_COMPLEX_MAPPINGS
5 * is enabled. 5 * is enabled.
@@ -9,23 +9,24 @@
9#include <linux/module.h> 9#include <linux/module.h>
10 10
11#include <linux/mtd/map.h> 11#include <linux/mtd/map.h>
12#include <linux/mtd/xip.h>
12 13
13static map_word simple_map_read(struct map_info *map, unsigned long ofs) 14static map_word __xipram simple_map_read(struct map_info *map, unsigned long ofs)
14{ 15{
15 return inline_map_read(map, ofs); 16 return inline_map_read(map, ofs);
16} 17}
17 18
18static void simple_map_write(struct map_info *map, const map_word datum, unsigned long ofs) 19static void __xipram simple_map_write(struct map_info *map, const map_word datum, unsigned long ofs)
19{ 20{
20 inline_map_write(map, datum, ofs); 21 inline_map_write(map, datum, ofs);
21} 22}
22 23
23static void simple_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 24static void __xipram simple_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
24{ 25{
25 inline_map_copy_from(map, to, from, len); 26 inline_map_copy_from(map, to, from, len);
26} 27}
27 28
28static void simple_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 29static void __xipram simple_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
29{ 30{
30 inline_map_copy_to(map, to, from, len); 31 inline_map_copy_to(map, to, from, len);
31} 32}
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
new file mode 100644
index 000000000000..8cc71409a328
--- /dev/null
+++ b/drivers/mtd/maps/omap_nor.c
@@ -0,0 +1,179 @@
1/*
2 * Flash memory support for various TI OMAP boards
3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Copyright (C) 2003-2004 Texas Instruments
6 * Copyright (C) 2004 Nokia Corporation
7 *
8 * Assembled using driver code copyright the companies above
9 * and written by David Brownell, Jian Zhang <jzhang@ti.com>,
10 * Tony Lindgren <tony@atomide.com> and others.
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 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/device.h>
34#include <linux/module.h>
35#include <linux/types.h>
36#include <linux/kernel.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <linux/mtd/mtd.h>
40#include <linux/mtd/map.h>
41#include <linux/mtd/partitions.h>
42
43#include <asm/io.h>
44#include <asm/hardware.h>
45#include <asm/mach-types.h>
46#include <asm/mach/flash.h>
47#include <asm/arch/tc.h>
48
49#ifdef CONFIG_MTD_PARTITIONS
50static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };
51#endif
52
53struct omapflash_info {
54 struct mtd_partition *parts;
55 struct mtd_info *mtd;
56 struct map_info map;
57};
58
59static void omap_set_vpp(struct map_info *map, int enable)
60{
61 static int count;
62
63 if (enable) {
64 if (count++ == 0)
65 OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP;
66 } else {
67 if (count && (--count == 0))
68 OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP;
69 }
70}
71
72static int __devinit omapflash_probe(struct device *dev)
73{
74 int err;
75 struct omapflash_info *info;
76 struct platform_device *pdev = to_platform_device(dev);
77 struct flash_platform_data *pdata = pdev->dev.platform_data;
78 struct resource *res = pdev->resource;
79 unsigned long size = res->end - res->start + 1;
80
81 info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL);
82 if (!info)
83 return -ENOMEM;
84
85 memset(info, 0, sizeof(struct omapflash_info));
86
87 if (!request_mem_region(res->start, size, "flash")) {
88 err = -EBUSY;
89 goto out_free_info;
90 }
91
92 info->map.virt = ioremap(res->start, size);
93 if (!info->map.virt) {
94 err = -ENOMEM;
95 goto out_release_mem_region;
96 }
97 info->map.name = pdev->dev.bus_id;
98 info->map.phys = res->start;
99 info->map.size = size;
100 info->map.bankwidth = pdata->width;
101 info->map.set_vpp = omap_set_vpp;
102
103 simple_map_init(&info->map);
104 info->mtd = do_map_probe(pdata->map_name, &info->map);
105 if (!info->mtd) {
106 err = -EIO;
107 goto out_iounmap;
108 }
109 info->mtd->owner = THIS_MODULE;
110
111#ifdef CONFIG_MTD_PARTITIONS
112 err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
113 if (err > 0)
114 add_mtd_partitions(info->mtd, info->parts, err);
115 else if (err < 0 && pdata->parts)
116 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
117 else
118#endif
119 add_mtd_device(info->mtd);
120
121 dev_set_drvdata(&pdev->dev, info);
122
123 return 0;
124
125out_iounmap:
126 iounmap(info->map.virt);
127out_release_mem_region:
128 release_mem_region(res->start, size);
129out_free_info:
130 kfree(info);
131
132 return err;
133}
134
135static int __devexit omapflash_remove(struct device *dev)
136{
137 struct platform_device *pdev = to_platform_device(dev);
138 struct omapflash_info *info = dev_get_drvdata(&pdev->dev);
139
140 dev_set_drvdata(&pdev->dev, NULL);
141
142 if (info) {
143 if (info->parts) {
144 del_mtd_partitions(info->mtd);
145 kfree(info->parts);
146 } else
147 del_mtd_device(info->mtd);
148 map_destroy(info->mtd);
149 release_mem_region(info->map.phys, info->map.size);
150 iounmap((void __iomem *) info->map.virt);
151 kfree(info);
152 }
153
154 return 0;
155}
156
157static struct device_driver omapflash_driver = {
158 .name = "omapflash",
159 .bus = &platform_bus_type,
160 .probe = omapflash_probe,
161 .remove = __devexit_p(omapflash_remove),
162};
163
164static int __init omapflash_init(void)
165{
166 return driver_register(&omapflash_driver);
167}
168
169static void __exit omapflash_exit(void)
170{
171 driver_unregister(&omapflash_driver);
172}
173
174module_init(omapflash_init);
175module_exit(omapflash_exit);
176
177MODULE_LICENSE("GPL");
178MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
179
diff --git a/drivers/mtd/maps/pb1550-flash.c b/drivers/mtd/maps/pb1550-flash.c
deleted file mode 100644
index 1424726a219e..000000000000
--- a/drivers/mtd/maps/pb1550-flash.c
+++ /dev/null
@@ -1,203 +0,0 @@
1/*
2 * Flash memory access on Alchemy Pb1550 board
3 *
4 * $Id: pb1550-flash.c,v 1.6 2004/11/04 13:24:15 gleixner Exp $
5 *
6 * (C) 2004 Embedded Edge, LLC, based on pb1550-flash.c:
7 * (C) 2003 Pete Popov <ppopov@pacbell.net>
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/map.h>
19#include <linux/mtd/partitions.h>
20
21#include <asm/io.h>
22#include <asm/au1000.h>
23#include <asm/pb1550.h>
24
25#ifdef DEBUG_RW
26#define DBG(x...) printk(x)
27#else
28#define DBG(x...)
29#endif
30
31static unsigned long window_addr;
32static unsigned long window_size;
33
34
35static struct map_info pb1550_map = {
36 .name = "Pb1550 flash",
37};
38
39static unsigned char flash_bankwidth = 4;
40
41/*
42 * Support only 64MB NOR Flash parts
43 */
44
45#ifdef PB1550_BOTH_BANKS
46/* both banks will be used. Combine the first bank and the first
47 * part of the second bank together into a single jffs/jffs2
48 * partition.
49 */
50static struct mtd_partition pb1550_partitions[] = {
51 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
52 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
53 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
54 */
55 {
56 .name = "User FS",
57 .size = (0x1FC00000 - 0x18000000),
58 .offset = 0x0000000
59 },{
60 .name = "yamon",
61 .size = 0x0100000,
62 .offset = MTDPART_OFS_APPEND,
63 .mask_flags = MTD_WRITEABLE
64 },{
65 .name = "raw kernel",
66 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
67 .offset = MTDPART_OFS_APPEND,
68 }
69};
70#elif defined(PB1550_BOOT_ONLY)
71static struct mtd_partition pb1550_partitions[] = {
72 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
73 * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
74 */
75 {
76 .name = "User FS",
77 .size = 0x03c00000,
78 .offset = 0x0000000
79 },{
80 .name = "yamon",
81 .size = 0x0100000,
82 .offset = MTDPART_OFS_APPEND,
83 .mask_flags = MTD_WRITEABLE
84 },{
85 .name = "raw kernel",
86 .size = (0x300000-0x40000), /* last 256KB is yamon env */
87 .offset = MTDPART_OFS_APPEND,
88 }
89};
90#elif defined(PB1550_USER_ONLY)
91static struct mtd_partition pb1550_partitions[] = {
92 /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
93 * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
94 */
95 {
96 .name = "User FS",
97 .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
98 .offset = 0x0000000
99 },{
100 .name = "raw kernel",
101 .size = MTDPART_SIZ_FULL,
102 .offset = MTDPART_OFS_APPEND,
103 }
104};
105#else
106#error MTD_PB1550 define combo error /* should never happen */
107#endif
108
109#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
110
111static struct mtd_info *mymtd;
112
113/*
114 * Probe the flash density and setup window address and size
115 * based on user CONFIG options. There are times when we don't
116 * want the MTD driver to be probing the boot or user flash,
117 * so having the option to enable only one bank is important.
118 */
119int setup_flash_params(void)
120{
121 u16 boot_swapboot;
122 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) |
123 ((bcsr->status >> 6) & 0x1);
124 printk("Pb1550 MTD: boot:swap %d\n", boot_swapboot);
125
126 switch (boot_swapboot) {
127 case 0: /* 512Mbit devices, both enabled */
128 case 1:
129 case 8:
130 case 9:
131#if defined(PB1550_BOTH_BANKS)
132 window_addr = 0x18000000;
133 window_size = 0x8000000;
134#elif defined(PB1550_BOOT_ONLY)
135 window_addr = 0x1C000000;
136 window_size = 0x4000000;
137#else /* USER ONLY */
138 window_addr = 0x1E000000;
139 window_size = 0x4000000;
140#endif
141 break;
142 case 0xC:
143 case 0xD:
144 case 0xE:
145 case 0xF:
146 /* 64 MB Boot NOR Flash is disabled */
147 /* and the start address is moved to 0x0C00000 */
148 window_addr = 0x0C000000;
149 window_size = 0x4000000;
150 default:
151 printk("Pb1550 MTD: unsupported boot:swap setting\n");
152 return 1;
153 }
154 return 0;
155}
156
157int __init pb1550_mtd_init(void)
158{
159 struct mtd_partition *parts;
160 int nb_parts = 0;
161
162 /* Default flash bankwidth */
163 pb1550_map.bankwidth = flash_bankwidth;
164
165 if (setup_flash_params())
166 return -ENXIO;
167
168 /*
169 * Static partition definition selection
170 */
171 parts = pb1550_partitions;
172 nb_parts = NB_OF(pb1550_partitions);
173 pb1550_map.size = window_size;
174
175 /*
176 * Now let's probe for the actual flash. Do it here since
177 * specific machine settings might have been set above.
178 */
179 printk(KERN_NOTICE "Pb1550 flash: probing %d-bit flash bus\n",
180 pb1550_map.bankwidth*8);
181 pb1550_map.virt = ioremap(window_addr, window_size);
182 mymtd = do_map_probe("cfi_probe", &pb1550_map);
183 if (!mymtd) return -ENXIO;
184 mymtd->owner = THIS_MODULE;
185
186 add_mtd_partitions(mymtd, parts, nb_parts);
187 return 0;
188}
189
190static void __exit pb1550_mtd_cleanup(void)
191{
192 if (mymtd) {
193 del_mtd_partitions(mymtd);
194 map_destroy(mymtd);
195 }
196}
197
198module_init(pb1550_mtd_init);
199module_exit(pb1550_mtd_cleanup);
200
201MODULE_AUTHOR("Embedded Edge, LLC");
202MODULE_DESCRIPTION("Pb1550 mtd map driver");
203MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/pb1xxx-flash.c b/drivers/mtd/maps/pb1xxx-flash.c
deleted file mode 100644
index 06e731540552..000000000000
--- a/drivers/mtd/maps/pb1xxx-flash.c
+++ /dev/null
@@ -1,178 +0,0 @@
1/*
2 * Flash memory access on Alchemy Pb1xxx boards
3 *
4 * (C) 2001 Pete Popov <ppopov@mvista.com>
5 *
6 * $Id: pb1xxx-flash.c,v 1.14 2004/11/04 13:24:15 gleixner Exp $
7 */
8
9#include <linux/config.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/init.h>
13#include <linux/kernel.h>
14
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/map.h>
17#include <linux/mtd/partitions.h>
18
19#include <asm/io.h>
20
21#ifdef DEBUG_RW
22#define DBG(x...) printk(x)
23#else
24#define DBG(x...)
25#endif
26
27#ifdef CONFIG_MIPS_PB1000
28
29#define WINDOW_ADDR 0x1F800000
30#define WINDOW_SIZE 0x800000
31
32static struct mtd_partition pb1xxx_partitions[] = {
33 {
34 .name = "yamon env",
35 .size = 0x00020000,
36 .offset = 0,
37 .mask_flags = MTD_WRITEABLE},
38 {
39 .name = "User FS",
40 .size = 0x003e0000,
41 .offset = 0x20000,},
42 {
43 .name = "boot code",
44 .size = 0x100000,
45 .offset = 0x400000,
46 .mask_flags = MTD_WRITEABLE},
47 {
48 .name = "raw/kernel",
49 .size = 0x300000,
50 .offset = 0x500000}
51};
52
53#elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100)
54
55#if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
56/* both 32MB banks will be used. Combine the first 32MB bank and the
57 * first 28MB of the second bank together into a single jffs/jffs2
58 * partition.
59 */
60#define WINDOW_ADDR 0x1C000000
61#define WINDOW_SIZE 0x4000000
62static struct mtd_partition pb1xxx_partitions[] = {
63 {
64 .name = "User FS",
65 .size = 0x3c00000,
66 .offset = 0x0000000
67 },{
68 .name = "yamon",
69 .size = 0x0100000,
70 .offset = 0x3c00000,
71 .mask_flags = MTD_WRITEABLE
72 },{
73 .name = "raw kernel",
74 .size = 0x02c0000,
75 .offset = 0x3d00000
76 }
77};
78#elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER)
79#define WINDOW_ADDR 0x1E000000
80#define WINDOW_SIZE 0x2000000
81static struct mtd_partition pb1xxx_partitions[] = {
82 {
83 .name = "User FS",
84 .size = 0x1c00000,
85 .offset = 0x0000000
86 },{
87 .name = "yamon",
88 .size = 0x0100000,
89 .offset = 0x1c00000,
90 .mask_flags = MTD_WRITEABLE
91 },{
92 .name = "raw kernel",
93 .size = 0x02c0000,
94 .offset = 0x1d00000
95 }
96};
97#elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
98#define WINDOW_ADDR 0x1C000000
99#define WINDOW_SIZE 0x2000000
100static struct mtd_partition pb1xxx_partitions[] = {
101 {
102 .name = "User FS",
103 .size = 0x1e00000,
104 .offset = 0x0000000
105 },{
106 .name = "raw kernel",
107 .size = 0x0200000,
108 .offset = 0x1e00000,
109 }
110};
111#else
112#error MTD_PB1500 define combo error /* should never happen */
113#endif
114#else
115#error Unsupported board
116#endif
117
118#define NAME "Pb1x00 Linux Flash"
119#define PADDR WINDOW_ADDR
120#define BUSWIDTH 4
121#define SIZE WINDOW_SIZE
122#define PARTITIONS 4
123
124static struct map_info pb1xxx_mtd_map = {
125 .name = NAME,
126 .size = SIZE,
127 .bankwidth = BUSWIDTH,
128 .phys = PADDR,
129};
130
131static struct mtd_info *pb1xxx_mtd;
132
133int __init pb1xxx_mtd_init(void)
134{
135 struct mtd_partition *parts;
136 int nb_parts = 0;
137 char *part_type;
138
139 /*
140 * Static partition definition selection
141 */
142 part_type = "static";
143 parts = pb1xxx_partitions;
144 nb_parts = ARRAY_SIZE(pb1xxx_partitions);
145
146 /*
147 * Now let's probe for the actual flash. Do it here since
148 * specific machine settings might have been set above.
149 */
150 printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n",
151 BUSWIDTH*8);
152 pb1xxx_mtd_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
153
154 simple_map_init(&pb1xxx_mtd_map);
155
156 pb1xxx_mtd = do_map_probe("cfi_probe", &pb1xxx_mtd_map);
157 if (!pb1xxx_mtd) return -ENXIO;
158 pb1xxx_mtd->owner = THIS_MODULE;
159
160 add_mtd_partitions(pb1xxx_mtd, parts, nb_parts);
161 return 0;
162}
163
164static void __exit pb1xxx_mtd_cleanup(void)
165{
166 if (pb1xxx_mtd) {
167 del_mtd_partitions(pb1xxx_mtd);
168 map_destroy(pb1xxx_mtd);
169 iounmap((void *) pb1xxx_mtd_map.virt);
170 }
171}
172
173module_init(pb1xxx_mtd_init);
174module_exit(pb1xxx_mtd_cleanup);
175
176MODULE_AUTHOR("Pete Popov");
177MODULE_DESCRIPTION("Pb1xxx CFI map driver");
178MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 08b60bdc5381..18dbd3af1eaa 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -7,7 +7,7 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * 9 *
10 * $Id: pci.c,v 1.9 2004/11/28 09:40:40 dwmw2 Exp $ 10 * $Id: pci.c,v 1.10 2005/03/18 14:04:35 gleixner Exp $
11 * 11 *
12 * Generic PCI memory map driver. We support the following boards: 12 * Generic PCI memory map driver. We support the following boards:
13 * - Intel IQ80310 ATU. 13 * - Intel IQ80310 ATU.
@@ -370,7 +370,7 @@ static struct pci_driver mtd_pci_driver = {
370 370
371static int __init mtd_pci_maps_init(void) 371static int __init mtd_pci_maps_init(void)
372{ 372{
373 return pci_module_init(&mtd_pci_driver); 373 return pci_register_driver(&mtd_pci_driver);
374} 374}
375 375
376static void __exit mtd_pci_maps_exit(void) 376static void __exit mtd_pci_maps_exit(void)
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index e37b4c1976e5..ff7c50d10180 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -18,7 +18,6 @@
18#include <asm/io.h> 18#include <asm/io.h>
19#include <asm/system.h> 19#include <asm/system.h>
20 20
21#include <pcmcia/version.h>
22#include <pcmcia/cs_types.h> 21#include <pcmcia/cs_types.h>
23#include <pcmcia/cs.h> 22#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
@@ -800,11 +799,6 @@ static dev_link_t *pcmciamtd_attach(void)
800 799
801 /* Register with Card Services */ 800 /* Register with Card Services */
802 client_reg.dev_info = &dev_info; 801 client_reg.dev_info = &dev_info;
803 client_reg.EventMask =
804 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
805 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
806 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
807 client_reg.event_handler = &pcmciamtd_event;
808 client_reg.Version = 0x0210; 802 client_reg.Version = 0x0210;
809 client_reg.event_callback_args.client_data = link; 803 client_reg.event_callback_args.client_data = link;
810 DEBUG(2, "Calling RegisterClient"); 804 DEBUG(2, "Calling RegisterClient");
@@ -818,14 +812,42 @@ static dev_link_t *pcmciamtd_attach(void)
818 return link; 812 return link;
819} 813}
820 814
815static struct pcmcia_device_id pcmciamtd_ids[] = {
816 PCMCIA_DEVICE_FUNC_ID(1),
817 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCS-2M", "2MB SRAM", 0x547e66dc, 0x1fed36cd, 0x36eadd21),
818 PCMCIA_DEVICE_PROD_ID12("IBM", "2MB SRAM", 0xb569a6e5, 0x36eadd21),
819 PCMCIA_DEVICE_PROD_ID12("IBM", "4MB FLASH", 0xb569a6e5, 0x8bc54d2a),
820 PCMCIA_DEVICE_PROD_ID12("IBM", "8MB FLASH", 0xb569a6e5, 0x6df1be3e),
821 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E20SW", 0x816cc815, 0xd14c9dcf),
822 PCMCIA_DEVICE_PROD_ID12("Intel", "S2E8 SW", 0x816cc815, 0xa2d7dedb),
823 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-02 ", 0x40ade711, 0x145cea5c),
824 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-04 ", 0x40ade711, 0x42064dda),
825 PCMCIA_DEVICE_PROD_ID12("intel", "SERIES2-20 ", 0x40ade711, 0x25ee5cb0),
826 PCMCIA_DEVICE_PROD_ID12("intel", "VALUE SERIES 100 ", 0x40ade711, 0xdf8506d8),
827 PCMCIA_DEVICE_PROD_ID12("KINGMAX TECHNOLOGY INC.", "SRAM 256K Bytes", 0x54d0c69c, 0xad12c29c),
828 PCMCIA_DEVICE_PROD_ID12("Maxtor", "MAXFL MobileMax Flash Memory Card", 0xb68968c8, 0x2dfb47b0),
829 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB101EN20", 0xf9876baf, 0xad0b207b),
830 PCMCIA_DEVICE_PROD_ID12("SEIKO EPSON", "WWB513EN20", 0xf9876baf, 0xe8d884ad),
831 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-3000", 0x05ddca47, 0xe7d67bca),
832 PCMCIA_DEVICE_PROD_ID12("Starfish, Inc.", "REX-4100", 0x05ddca47, 0x7bc32944),
833 /* the following was commented out in pcmcia-cs-3.2.7 */
834 /* PCMCIA_DEVICE_PROD_ID12("RATOC Systems,Inc.", "SmartMedia ADAPTER PC Card", 0xf4a2fefe, 0x5885b2ae), */
835#ifdef CONFIG_MTD_PCMCIA_ANONYMOUS
836 { .match_flags = PCMCIA_DEV_ID_MATCH_ANONYMOUS, },
837#endif
838 PCMCIA_DEVICE_NULL
839};
840MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids);
821 841
822static struct pcmcia_driver pcmciamtd_driver = { 842static struct pcmcia_driver pcmciamtd_driver = {
823 .drv = { 843 .drv = {
824 .name = "pcmciamtd" 844 .name = "pcmciamtd"
825 }, 845 },
826 .attach = pcmciamtd_attach, 846 .attach = pcmciamtd_attach,
847 .event = pcmciamtd_event,
827 .detach = pcmciamtd_detach, 848 .detach = pcmciamtd_detach,
828 .owner = THIS_MODULE 849 .owner = THIS_MODULE,
850 .id_table = pcmciamtd_ids,
829}; 851};
830 852
831 853
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
new file mode 100644
index 000000000000..118b04544cad
--- /dev/null
+++ b/drivers/mtd/maps/plat-ram.c
@@ -0,0 +1,278 @@
1/* drivers/mtd/maps/plat-ram.c
2 *
3 * (c) 2004-2005 Simtec Electronics
4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * Generic platfrom device based RAM map
8 *
9 * $Id: plat-ram.c,v 1.3 2005/03/19 22:41:27 gleixner Exp $
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 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24*/
25
26#include <linux/module.h>
27#include <linux/types.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/string.h>
31#include <linux/ioport.h>
32#include <linux/device.h>
33
34#include <linux/mtd/mtd.h>
35#include <linux/mtd/map.h>
36#include <linux/mtd/partitions.h>
37#include <linux/mtd/plat-ram.h>
38
39#include <asm/io.h>
40
41/* private structure for each mtd platform ram device created */
42
43struct platram_info {
44 struct device *dev;
45 struct mtd_info *mtd;
46 struct map_info map;
47 struct mtd_partition *partitions;
48 struct resource *area;
49 struct platdata_mtd_ram *pdata;
50};
51
52/* to_platram_info()
53 *
54 * device private data to struct platram_info conversion
55*/
56
57static inline struct platram_info *to_platram_info(struct device *dev)
58{
59 return (struct platram_info *)dev_get_drvdata(dev);
60}
61
62/* platram_setrw
63 *
64 * call the platform device's set rw/ro control
65 *
66 * to = 0 => read-only
67 * = 1 => read-write
68*/
69
70static inline void platram_setrw(struct platram_info *info, int to)
71{
72 if (info->pdata == NULL)
73 return;
74
75 if (info->pdata->set_rw != NULL)
76 (info->pdata->set_rw)(info->dev, to);
77}
78
79/* platram_remove
80 *
81 * called to remove the device from the driver's control
82*/
83
84static int platram_remove(struct device *dev)
85{
86 struct platram_info *info = to_platram_info(dev);
87
88 dev_set_drvdata(dev, NULL);
89
90 dev_dbg(dev, "removing device\n");
91
92 if (info == NULL)
93 return 0;
94
95 if (info->mtd) {
96#ifdef CONFIG_MTD_PARTITIONS
97 if (info->partitions) {
98 del_mtd_partitions(info->mtd);
99 kfree(info->partitions);
100 }
101#endif
102 del_mtd_device(info->mtd);
103 map_destroy(info->mtd);
104 }
105
106 /* ensure ram is left read-only */
107
108 platram_setrw(info, PLATRAM_RO);
109
110 /* release resources */
111
112 if (info->area) {
113 release_resource(info->area);
114 kfree(info->area);
115 }
116
117 if (info->map.virt != NULL)
118 iounmap(info->map.virt);
119
120 kfree(info);
121
122 return 0;
123}
124
125/* platram_probe
126 *
127 * called from device drive system when a device matching our
128 * driver is found.
129*/
130
131static int platram_probe(struct device *dev)
132{
133 struct platform_device *pd = to_platform_device(dev);
134 struct platdata_mtd_ram *pdata;
135 struct platram_info *info;
136 struct resource *res;
137 int err = 0;
138
139 dev_dbg(dev, "probe entered\n");
140
141 if (dev->platform_data == NULL) {
142 dev_err(dev, "no platform data supplied\n");
143 err = -ENOENT;
144 goto exit_error;
145 }
146
147 pdata = dev->platform_data;
148
149 info = kmalloc(sizeof(*info), GFP_KERNEL);
150 if (info == NULL) {
151 dev_err(dev, "no memory for flash info\n");
152 err = -ENOMEM;
153 goto exit_error;
154 }
155
156 memset(info, 0, sizeof(*info));
157 dev_set_drvdata(dev, info);
158
159 info->dev = dev;
160 info->pdata = pdata;
161
162 /* get the resource for the memory mapping */
163
164 res = platform_get_resource(pd, IORESOURCE_MEM, 0);
165
166 if (res == NULL) {
167 dev_err(dev, "no memory resource specified\n");
168 err = -ENOENT;
169 goto exit_free;
170 }
171
172 dev_dbg(dev, "got platform resource %p (0x%lx)\n", res, res->start);
173
174 /* setup map parameters */
175
176 info->map.phys = res->start;
177 info->map.size = (res->end - res->start) + 1;
178 info->map.name = pdata->mapname != NULL ? pdata->mapname : pd->name;
179 info->map.bankwidth = pdata->bankwidth;
180
181 /* register our usage of the memory area */
182
183 info->area = request_mem_region(res->start, info->map.size, pd->name);
184 if (info->area == NULL) {
185 dev_err(dev, "failed to request memory region\n");
186 err = -EIO;
187 goto exit_free;
188 }
189
190 /* remap the memory area */
191
192 info->map.virt = ioremap(res->start, info->map.size);
193 dev_dbg(dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
194
195 if (info->map.virt == NULL) {
196 dev_err(dev, "failed to ioremap() region\n");
197 err = -EIO;
198 goto exit_free;
199 }
200
201 simple_map_init(&info->map);
202
203 dev_dbg(dev, "initialised map, probing for mtd\n");
204
205 /* probe for the right mtd map driver */
206
207 info->mtd = do_map_probe("map_ram" , &info->map);
208 if (info->mtd == NULL) {
209 dev_err(dev, "failed to probe for map_ram\n");
210 err = -ENOMEM;
211 goto exit_free;
212 }
213
214 info->mtd->owner = THIS_MODULE;
215
216 platram_setrw(info, PLATRAM_RW);
217
218 /* check to see if there are any available partitions, or wether
219 * to add this device whole */
220
221#ifdef CONFIG_MTD_PARTITIONS
222 if (pdata->nr_partitions > 0) {
223 const char **probes = { NULL };
224
225 if (pdata->probes)
226 probes = (const char **)pdata->probes;
227
228 err = parse_mtd_partitions(info->mtd, probes,
229 &info->partitions, 0);
230 if (err > 0) {
231 err = add_mtd_partitions(info->mtd, info->partitions,
232 err);
233 }
234 }
235#endif /* CONFIG_MTD_PARTITIONS */
236
237 if (add_mtd_device(info->mtd)) {
238 dev_err(dev, "add_mtd_device() failed\n");
239 err = -ENOMEM;
240 }
241
242 dev_info(dev, "registered mtd device\n");
243 return err;
244
245 exit_free:
246 platram_remove(dev);
247 exit_error:
248 return err;
249}
250
251/* device driver info */
252
253static struct device_driver platram_driver = {
254 .name = "mtd-ram",
255 .bus = &platform_bus_type,
256 .probe = platram_probe,
257 .remove = platram_remove,
258};
259
260/* module init/exit */
261
262static int __init platram_init(void)
263{
264 printk("Generic platform RAM MTD, (c) 2004 Simtec Electronics\n");
265 return driver_register(&platram_driver);
266}
267
268static void __exit platram_exit(void)
269{
270 driver_unregister(&platram_driver);
271}
272
273module_init(platram_init);
274module_exit(platram_exit);
275
276MODULE_LICENSE("GPL");
277MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
278MODULE_DESCRIPTION("MTD platform RAM map driver");
diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c
index 5bb3b600e5d0..97a8dfd69258 100644
--- a/drivers/mtd/maps/scb2_flash.c
+++ b/drivers/mtd/maps/scb2_flash.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * MTD map driver for BIOS Flash on Intel SCB2 boards 2 * MTD map driver for BIOS Flash on Intel SCB2 boards
3 * $Id: scb2_flash.c,v 1.11 2004/11/28 09:40:40 dwmw2 Exp $ 3 * $Id: scb2_flash.c,v 1.12 2005/03/18 14:04:35 gleixner Exp $
4 * Copyright (C) 2002 Sun Microsystems, Inc. 4 * Copyright (C) 2002 Sun Microsystems, Inc.
5 * Tim Hockin <thockin@sun.com> 5 * Tim Hockin <thockin@sun.com>
6 * 6 *
@@ -238,7 +238,7 @@ static struct pci_driver scb2_flash_driver = {
238static int __init 238static int __init
239scb2_flash_init(void) 239scb2_flash_init(void)
240{ 240{
241 return pci_module_init(&scb2_flash_driver); 241 return pci_register_driver(&scb2_flash_driver);
242} 242}
243 243
244static void __exit 244static void __exit
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
index b3b39cb7c608..d15da6fd84c1 100644
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ b/drivers/mtd/maps/sharpsl-flash.c
@@ -4,7 +4,7 @@
4 * Copyright (C) 2001 Lineo Japan, Inc. 4 * Copyright (C) 2001 Lineo Japan, Inc.
5 * Copyright (C) 2002 SHARP 5 * Copyright (C) 2002 SHARP
6 * 6 *
7 * $Id: sharpsl-flash.c,v 1.2 2004/11/24 20:38:06 rpurdie Exp $ 7 * $Id: sharpsl-flash.c,v 1.5 2005/03/21 08:42:11 rpurdie Exp $
8 * 8 *
9 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp 9 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp
10 * Handle mapping of the flash on the RPX Lite and CLLF boards 10 * Handle mapping of the flash on the RPX Lite and CLLF boards
@@ -24,13 +24,14 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <asm/io.h>
28#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
29#include <linux/mtd/map.h> 28#include <linux/mtd/map.h>
30#include <linux/mtd/partitions.h> 29#include <linux/mtd/partitions.h>
30#include <asm/io.h>
31#include <asm/mach-types.h>
31 32
32#define WINDOW_ADDR 0x00000000 33#define WINDOW_ADDR 0x00000000
33#define WINDOW_SIZE 0x01000000 34#define WINDOW_SIZE 0x00800000
34#define BANK_WIDTH 2 35#define BANK_WIDTH 2
35 36
36static struct mtd_info *mymtd; 37static struct mtd_info *mymtd;
@@ -44,9 +45,7 @@ struct map_info sharpsl_map = {
44 45
45static struct mtd_partition sharpsl_partitions[1] = { 46static struct mtd_partition sharpsl_partitions[1] = {
46 { 47 {
47 name: "Filesystem", 48 name: "Boot PROM Filesystem",
48 size: 0x006d0000,
49 offset: 0x00120000
50 } 49 }
51}; 50};
52 51
@@ -58,12 +57,16 @@ int __init init_sharpsl(void)
58 int nb_parts = 0; 57 int nb_parts = 0;
59 char *part_type = "static"; 58 char *part_type = "static";
60 59
61 printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR); 60 printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n",
61 WINDOW_SIZE, WINDOW_ADDR);
62 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); 62 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
63 if (!sharpsl_map.virt) { 63 if (!sharpsl_map.virt) {
64 printk("Failed to ioremap\n"); 64 printk("Failed to ioremap\n");
65 return -EIO; 65 return -EIO;
66 } 66 }
67
68 simple_map_init(&sharpsl_map);
69
67 mymtd = do_map_probe("map_rom", &sharpsl_map); 70 mymtd = do_map_probe("map_rom", &sharpsl_map);
68 if (!mymtd) { 71 if (!mymtd) {
69 iounmap(sharpsl_map.virt); 72 iounmap(sharpsl_map.virt);
@@ -72,6 +75,22 @@ int __init init_sharpsl(void)
72 75
73 mymtd->owner = THIS_MODULE; 76 mymtd->owner = THIS_MODULE;
74 77
78 if (machine_is_corgi() || machine_is_shepherd() || machine_is_husky()
79 || machine_is_poodle()) {
80 sharpsl_partitions[0].size=0x006d0000;
81 sharpsl_partitions[0].offset=0x00120000;
82 } else if (machine_is_tosa()) {
83 sharpsl_partitions[0].size=0x006a0000;
84 sharpsl_partitions[0].offset=0x00160000;
85 } else if (machine_is_spitz()) {
86 sharpsl_partitions[0].size=0x006b0000;
87 sharpsl_partitions[0].offset=0x00140000;
88 } else {
89 map_destroy(mymtd);
90 iounmap(sharpsl_map.virt);
91 return -ENODEV;
92 }
93
75 parts = sharpsl_partitions; 94 parts = sharpsl_partitions;
76 nb_parts = NB_OF(sharpsl_partitions); 95 nb_parts = NB_OF(sharpsl_partitions);
77 96
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 510ad78312cc..1ed602a0f24c 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mtdchar.c,v 1.66 2005/01/05 18:05:11 dwmw2 Exp $ 2 * $Id: mtdchar.c,v 1.73 2005/07/04 17:36:41 gleixner Exp $
3 * 3 *
4 * Character-device access to raw MTD devices. 4 * Character-device access to raw MTD devices.
5 * 5 *
@@ -15,27 +15,30 @@
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <asm/uaccess.h> 16#include <asm/uaccess.h>
17 17
18#ifdef CONFIG_DEVFS_FS 18#include <linux/device.h>
19#include <linux/devfs_fs_kernel.h> 19
20static struct class *mtd_class;
20 21
21static void mtd_notify_add(struct mtd_info* mtd) 22static void mtd_notify_add(struct mtd_info* mtd)
22{ 23{
23 if (!mtd) 24 if (!mtd)
24 return; 25 return;
25 26
26 devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 27 class_device_create(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
27 S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index); 28 NULL, "mtd%d", mtd->index);
28 29
29 devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 30 class_device_create(mtd_class,
30 S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index); 31 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
32 NULL, "mtd%dro", mtd->index);
31} 33}
32 34
33static void mtd_notify_remove(struct mtd_info* mtd) 35static void mtd_notify_remove(struct mtd_info* mtd)
34{ 36{
35 if (!mtd) 37 if (!mtd)
36 return; 38 return;
37 devfs_remove("mtd/%d", mtd->index); 39
38 devfs_remove("mtd/%dro", mtd->index); 40 class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
41 class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
39} 42}
40 43
41static struct mtd_notifier notifier = { 44static struct mtd_notifier notifier = {
@@ -43,25 +46,25 @@ static struct mtd_notifier notifier = {
43 .remove = mtd_notify_remove, 46 .remove = mtd_notify_remove,
44}; 47};
45 48
46static inline void mtdchar_devfs_init(void) 49/*
47{ 50 * We use file->private_data to store a pointer to the MTDdevice.
48 devfs_mk_dir("mtd"); 51 * Since alighment is at least 32 bits, we have 2 bits free for OTP
49 register_mtd_user(&notifier); 52 * modes as well.
50} 53 */
51 54
52static inline void mtdchar_devfs_exit(void) 55#define TO_MTD(file) (struct mtd_info *)((long)((file)->private_data) & ~3L)
53{ 56
54 unregister_mtd_user(&notifier); 57#define MTD_MODE_OTP_FACT 1
55 devfs_remove("mtd"); 58#define MTD_MODE_OTP_USER 2
56} 59#define MTD_MODE(file) ((long)((file)->private_data) & 3)
57#else /* !DEVFS */ 60
58#define mtdchar_devfs_init() do { } while(0) 61#define SET_MTD_MODE(file, mode) \
59#define mtdchar_devfs_exit() do { } while(0) 62 do { long __p = (long)((file)->private_data); \
60#endif 63 (file)->private_data = (void *)((__p & ~3L) | mode); } while (0)
61 64
62static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) 65static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
63{ 66{
64 struct mtd_info *mtd = file->private_data; 67 struct mtd_info *mtd = TO_MTD(file);
65 68
66 switch (orig) { 69 switch (orig) {
67 case 0: 70 case 0:
@@ -134,7 +137,7 @@ static int mtd_close(struct inode *inode, struct file *file)
134 137
135 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); 138 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
136 139
137 mtd = file->private_data; 140 mtd = TO_MTD(file);
138 141
139 if (mtd->sync) 142 if (mtd->sync)
140 mtd->sync(mtd); 143 mtd->sync(mtd);
@@ -151,7 +154,7 @@ static int mtd_close(struct inode *inode, struct file *file)
151 154
152static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos) 155static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
153{ 156{
154 struct mtd_info *mtd = file->private_data; 157 struct mtd_info *mtd = TO_MTD(file);
155 size_t retlen=0; 158 size_t retlen=0;
156 size_t total_retlen=0; 159 size_t total_retlen=0;
157 int ret=0; 160 int ret=0;
@@ -178,7 +181,16 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
178 if (!kbuf) 181 if (!kbuf)
179 return -ENOMEM; 182 return -ENOMEM;
180 183
181 ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf); 184 switch (MTD_MODE(file)) {
185 case MTD_MODE_OTP_FACT:
186 ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
187 break;
188 case MTD_MODE_OTP_USER:
189 ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
190 break;
191 default:
192 ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf);
193 }
182 /* Nand returns -EBADMSG on ecc errors, but it returns 194 /* Nand returns -EBADMSG on ecc errors, but it returns
183 * the data. For our userspace tools it is important 195 * the data. For our userspace tools it is important
184 * to dump areas with ecc errors ! 196 * to dump areas with ecc errors !
@@ -196,6 +208,8 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
196 208
197 count -= retlen; 209 count -= retlen;
198 buf += retlen; 210 buf += retlen;
211 if (retlen == 0)
212 count = 0;
199 } 213 }
200 else { 214 else {
201 kfree(kbuf); 215 kfree(kbuf);
@@ -210,7 +224,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
210 224
211static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos) 225static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos)
212{ 226{
213 struct mtd_info *mtd = file->private_data; 227 struct mtd_info *mtd = TO_MTD(file);
214 char *kbuf; 228 char *kbuf;
215 size_t retlen; 229 size_t retlen;
216 size_t total_retlen=0; 230 size_t total_retlen=0;
@@ -245,7 +259,20 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
245 return -EFAULT; 259 return -EFAULT;
246 } 260 }
247 261
248 ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf); 262 switch (MTD_MODE(file)) {
263 case MTD_MODE_OTP_FACT:
264 ret = -EROFS;
265 break;
266 case MTD_MODE_OTP_USER:
267 if (!mtd->write_user_prot_reg) {
268 ret = -EOPNOTSUPP;
269 break;
270 }
271 ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
272 break;
273 default:
274 ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf);
275 }
249 if (!ret) { 276 if (!ret) {
250 *ppos += retlen; 277 *ppos += retlen;
251 total_retlen += retlen; 278 total_retlen += retlen;
@@ -276,7 +303,7 @@ static void mtdchar_erase_callback (struct erase_info *instr)
276static int mtd_ioctl(struct inode *inode, struct file *file, 303static int mtd_ioctl(struct inode *inode, struct file *file,
277 u_int cmd, u_long arg) 304 u_int cmd, u_long arg)
278{ 305{
279 struct mtd_info *mtd = file->private_data; 306 struct mtd_info *mtd = TO_MTD(file);
280 void __user *argp = (void __user *)arg; 307 void __user *argp = (void __user *)arg;
281 int ret = 0; 308 int ret = 0;
282 u_long size; 309 u_long size;
@@ -518,6 +545,80 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
518 break; 545 break;
519 } 546 }
520 547
548#ifdef CONFIG_MTD_OTP
549 case OTPSELECT:
550 {
551 int mode;
552 if (copy_from_user(&mode, argp, sizeof(int)))
553 return -EFAULT;
554 SET_MTD_MODE(file, 0);
555 switch (mode) {
556 case MTD_OTP_FACTORY:
557 if (!mtd->read_fact_prot_reg)
558 ret = -EOPNOTSUPP;
559 else
560 SET_MTD_MODE(file, MTD_MODE_OTP_FACT);
561 break;
562 case MTD_OTP_USER:
563 if (!mtd->read_fact_prot_reg)
564 ret = -EOPNOTSUPP;
565 else
566 SET_MTD_MODE(file, MTD_MODE_OTP_USER);
567 break;
568 default:
569 ret = -EINVAL;
570 case MTD_OTP_OFF:
571 break;
572 }
573 file->f_pos = 0;
574 break;
575 }
576
577 case OTPGETREGIONCOUNT:
578 case OTPGETREGIONINFO:
579 {
580 struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
581 if (!buf)
582 return -ENOMEM;
583 ret = -EOPNOTSUPP;
584 switch (MTD_MODE(file)) {
585 case MTD_MODE_OTP_FACT:
586 if (mtd->get_fact_prot_info)
587 ret = mtd->get_fact_prot_info(mtd, buf, 4096);
588 break;
589 case MTD_MODE_OTP_USER:
590 if (mtd->get_user_prot_info)
591 ret = mtd->get_user_prot_info(mtd, buf, 4096);
592 break;
593 }
594 if (ret >= 0) {
595 if (cmd == OTPGETREGIONCOUNT) {
596 int nbr = ret / sizeof(struct otp_info);
597 ret = copy_to_user(argp, &nbr, sizeof(int));
598 } else
599 ret = copy_to_user(argp, buf, ret);
600 if (ret)
601 ret = -EFAULT;
602 }
603 kfree(buf);
604 break;
605 }
606
607 case OTPLOCK:
608 {
609 struct otp_info info;
610
611 if (MTD_MODE(file) != MTD_MODE_OTP_USER)
612 return -EINVAL;
613 if (copy_from_user(&info, argp, sizeof(info)))
614 return -EFAULT;
615 if (!mtd->lock_user_prot_reg)
616 return -EOPNOTSUPP;
617 ret = mtd->lock_user_prot_reg(mtd, info.start, info.length);
618 break;
619 }
620#endif
621
521 default: 622 default:
522 ret = -ENOTTY; 623 ret = -ENOTTY;
523 } 624 }
@@ -543,13 +644,22 @@ static int __init init_mtdchar(void)
543 return -EAGAIN; 644 return -EAGAIN;
544 } 645 }
545 646
546 mtdchar_devfs_init(); 647 mtd_class = class_create(THIS_MODULE, "mtd");
648
649 if (IS_ERR(mtd_class)) {
650 printk(KERN_ERR "Error creating mtd class.\n");
651 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
652 return PTR_ERR(mtd_class);
653 }
654
655 register_mtd_user(&notifier);
547 return 0; 656 return 0;
548} 657}
549 658
550static void __exit cleanup_mtdchar(void) 659static void __exit cleanup_mtdchar(void)
551{ 660{
552 mtdchar_devfs_exit(); 661 unregister_mtd_user(&notifier);
662 class_destroy(mtd_class);
553 unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); 663 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
554} 664}
555 665
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9c0315d1b1c4..dc86df18e94b 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: mtdcore.c,v 1.44 2004/11/16 18:28:59 dwmw2 Exp $ 2 * $Id: mtdcore.c,v 1.45 2005/02/18 14:34:50 dedekind Exp $
3 * 3 *
4 * Core registration and callback routines for MTD 4 * Core registration and callback routines for MTD
5 * drivers and users. 5 * drivers and users.
@@ -149,8 +149,8 @@ void register_mtd_user (struct mtd_notifier *new)
149} 149}
150 150
151/** 151/**
152 * register_mtd_user - unregister a 'user' of MTD devices. 152 * unregister_mtd_user - unregister a 'user' of MTD devices.
153 * @new: pointer to notifier info structure 153 * @old: pointer to notifier info structure
154 * 154 *
155 * Removes a callback function pair from the list of 'users' to be 155 * Removes a callback function pair from the list of 'users' to be
156 * notified upon addition or removal of MTD devices. Causes the 156 * notified upon addition or removal of MTD devices. Causes the
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 96ebb52f24b1..b92e6bfffaf2 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * This code is GPL 6 * This code is GPL
7 * 7 *
8 * $Id: mtdpart.c,v 1.51 2004/11/16 18:28:59 dwmw2 Exp $ 8 * $Id: mtdpart.c,v 1.53 2005/02/08 17:11:13 nico Exp $
9 * 9 *
10 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de> 10 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de>
11 * added support for read_oob, write_oob 11 * added support for read_oob, write_oob
@@ -116,6 +116,13 @@ static int part_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t le
116 len, retlen, buf); 116 len, retlen, buf);
117} 117}
118 118
119static int part_get_user_prot_info (struct mtd_info *mtd,
120 struct otp_info *buf, size_t len)
121{
122 struct mtd_part *part = PART(mtd);
123 return part->master->get_user_prot_info (part->master, buf, len);
124}
125
119static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, 126static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
120 size_t *retlen, u_char *buf) 127 size_t *retlen, u_char *buf)
121{ 128{
@@ -124,6 +131,13 @@ static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t le
124 len, retlen, buf); 131 len, retlen, buf);
125} 132}
126 133
134static int part_get_fact_prot_info (struct mtd_info *mtd,
135 struct otp_info *buf, size_t len)
136{
137 struct mtd_part *part = PART(mtd);
138 return part->master->get_fact_prot_info (part->master, buf, len);
139}
140
127static int part_write (struct mtd_info *mtd, loff_t to, size_t len, 141static int part_write (struct mtd_info *mtd, loff_t to, size_t len,
128 size_t *retlen, const u_char *buf) 142 size_t *retlen, const u_char *buf)
129{ 143{
@@ -182,6 +196,12 @@ static int part_write_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t l
182 len, retlen, buf); 196 len, retlen, buf);
183} 197}
184 198
199static int part_lock_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len)
200{
201 struct mtd_part *part = PART(mtd);
202 return part->master->lock_user_prot_reg (part->master, from, len);
203}
204
185static int part_writev (struct mtd_info *mtd, const struct kvec *vecs, 205static int part_writev (struct mtd_info *mtd, const struct kvec *vecs,
186 unsigned long count, loff_t to, size_t *retlen) 206 unsigned long count, loff_t to, size_t *retlen)
187{ 207{
@@ -409,6 +429,12 @@ int add_mtd_partitions(struct mtd_info *master,
409 slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg; 429 slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
410 if(master->write_user_prot_reg) 430 if(master->write_user_prot_reg)
411 slave->mtd.write_user_prot_reg = part_write_user_prot_reg; 431 slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
432 if(master->lock_user_prot_reg)
433 slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
434 if(master->get_user_prot_info)
435 slave->mtd.get_user_prot_info = part_get_user_prot_info;
436 if(master->get_fact_prot_info)
437 slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
412 if (master->sync) 438 if (master->sync)
413 slave->mtd.sync = part_sync; 439 slave->mtd.sync = part_sync;
414 if (!i && master->suspend && master->resume) { 440 if (!i && master->suspend && master->resume) {
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index f7801eb730ce..36d34e5e5a5a 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -1,5 +1,5 @@
1# drivers/mtd/nand/Kconfig 1# drivers/mtd/nand/Kconfig
2# $Id: Kconfig,v 1.26 2005/01/05 12:42:24 dwmw2 Exp $ 2# $Id: Kconfig,v 1.31 2005/06/20 12:03:21 bjd Exp $
3 3
4menu "NAND Flash Device Drivers" 4menu "NAND Flash Device Drivers"
5 depends on MTD!=n 5 depends on MTD!=n
@@ -58,20 +58,6 @@ config MTD_NAND_TOTO
58config MTD_NAND_IDS 58config MTD_NAND_IDS
59 tristate 59 tristate
60 60
61config MTD_NAND_TX4925NDFMC
62 tristate "SmartMedia Card on Toshiba RBTX4925 reference board"
63 depends on TOSHIBA_RBTX4925 && MTD_NAND && TOSHIBA_RBTX4925_MPLEX_NAND
64 help
65 This enables the driver for the NAND flash device found on the
66 Toshiba RBTX4925 reference board, which is a SmartMediaCard.
67
68config MTD_NAND_TX4938NDFMC
69 tristate "NAND Flash device on Toshiba RBTX4938 reference board"
70 depends on TOSHIBA_RBTX4938 && MTD_NAND && TOSHIBA_RBTX4938_MPLEX_NAND
71 help
72 This enables the driver for the NAND flash device found on the
73 Toshiba RBTX4938 reference board.
74
75config MTD_NAND_AU1550 61config MTD_NAND_AU1550
76 tristate "Au1550 NAND support" 62 tristate "Au1550 NAND support"
77 depends on SOC_AU1550 && MTD_NAND 63 depends on SOC_AU1550 && MTD_NAND
@@ -95,10 +81,11 @@ config MTD_NAND_PPCHAMELEONEVB
95 This enables the NAND flash driver on the PPChameleon EVB Board. 81 This enables the NAND flash driver on the PPChameleon EVB Board.
96 82
97config MTD_NAND_S3C2410 83config MTD_NAND_S3C2410
98 tristate "NAND Flash support for S3C2410 SoC" 84 tristate "NAND Flash support for S3C2410/S3C2440 SoC"
99 depends on ARCH_S3C2410 && MTD_NAND 85 depends on ARCH_S3C2410 && MTD_NAND
100 help 86 help
101 This enables the NAND flash controller on the S3C2410. 87 This enables the NAND flash controller on the S3C2410 and S3C2440
88 SoCs
102 89
103 No board specfic support is done by this driver, each board 90 No board specfic support is done by this driver, each board
104 must advertise a platform_device for the driver to attach. 91 must advertise a platform_device for the driver to attach.
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index d9dc8cc2da8c..41742026a52e 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -10,8 +10,6 @@ obj-$(CONFIG_MTD_NAND_SPIA) += spia.o
10obj-$(CONFIG_MTD_NAND_TOTO) += toto.o 10obj-$(CONFIG_MTD_NAND_TOTO) += toto.o
11obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o 11obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o
12obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o 12obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o
13obj-$(CONFIG_MTD_NAND_TX4925NDFMC) += tx4925ndfmc.o
14obj-$(CONFIG_MTD_NAND_TX4938NDFMC) += tx4938ndfmc.o
15obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o 13obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o
16obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o 14obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o
17obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o 15obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 02135c3ac29a..fdb5d4ad3d52 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -16,7 +16,7 @@
16 * 16 *
17 * Interface to generic NAND code for M-Systems DiskOnChip devices 17 * Interface to generic NAND code for M-Systems DiskOnChip devices
18 * 18 *
19 * $Id: diskonchip.c,v 1.45 2005/01/05 18:05:14 dwmw2 Exp $ 19 * $Id: diskonchip.c,v 1.54 2005/04/07 14:22:55 dbrown Exp $
20 */ 20 */
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -35,13 +35,13 @@
35#include <linux/mtd/inftl.h> 35#include <linux/mtd/inftl.h>
36 36
37/* Where to look for the devices? */ 37/* Where to look for the devices? */
38#ifndef CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS 38#ifndef CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS
39#define CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS 0 39#define CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 0
40#endif 40#endif
41 41
42static unsigned long __initdata doc_locations[] = { 42static unsigned long __initdata doc_locations[] = {
43#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) 43#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
44#ifdef CONFIG_MTD_DISKONCHIP_PROBE_HIGH 44#ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH
45 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, 45 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
46 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, 46 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
47 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, 47 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
@@ -81,11 +81,6 @@ struct doc_priv {
81 struct mtd_info *nextdoc; 81 struct mtd_info *nextdoc;
82}; 82};
83 83
84/* Max number of eraseblocks to scan (from start of device) for the (I)NFTL
85 MediaHeader. The spec says to just keep going, I think, but that's just
86 silly. */
87#define MAX_MEDIAHEADER_SCAN 8
88
89/* This is the syndrome computed by the HW ecc generator upon reading an empty 84/* This is the syndrome computed by the HW ecc generator upon reading an empty
90 page, one with all 0xff for data and stored ecc code. */ 85 page, one with all 0xff for data and stored ecc code. */
91static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a }; 86static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a };
@@ -111,10 +106,11 @@ module_param(try_dword, int, 0);
111static int no_ecc_failures=0; 106static int no_ecc_failures=0;
112module_param(no_ecc_failures, int, 0); 107module_param(no_ecc_failures, int, 0);
113 108
114#ifdef CONFIG_MTD_PARTITIONS
115static int no_autopart=0; 109static int no_autopart=0;
116module_param(no_autopart, int, 0); 110module_param(no_autopart, int, 0);
117#endif 111
112static int show_firmware_partition=0;
113module_param(show_firmware_partition, int, 0);
118 114
119#ifdef MTD_NAND_DISKONCHIP_BBTWRITE 115#ifdef MTD_NAND_DISKONCHIP_BBTWRITE
120static int inftl_bbt_write=1; 116static int inftl_bbt_write=1;
@@ -123,7 +119,7 @@ static int inftl_bbt_write=0;
123#endif 119#endif
124module_param(inftl_bbt_write, int, 0); 120module_param(inftl_bbt_write, int, 0);
125 121
126static unsigned long doc_config_location = CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS; 122static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS;
127module_param(doc_config_location, ulong, 0); 123module_param(doc_config_location, ulong, 0);
128MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip"); 124MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
129 125
@@ -410,7 +406,12 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
410 doc200x_hwcontrol(mtd, NAND_CTL_SETALE); 406 doc200x_hwcontrol(mtd, NAND_CTL_SETALE);
411 this->write_byte(mtd, 0); 407 this->write_byte(mtd, 0);
412 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE); 408 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
413 409
410 /* We cant' use dev_ready here, but at least we wait for the
411 * command to complete
412 */
413 udelay(50);
414
414 ret = this->read_byte(mtd) << 8; 415 ret = this->read_byte(mtd) << 8;
415 ret |= this->read_byte(mtd); 416 ret |= this->read_byte(mtd);
416 417
@@ -429,6 +430,8 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
429 doc2000_write_byte(mtd, 0); 430 doc2000_write_byte(mtd, 0);
430 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE); 431 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
431 432
433 udelay(50);
434
432 ident.dword = readl(docptr + DoC_2k_CDSN_IO); 435 ident.dword = readl(docptr + DoC_2k_CDSN_IO);
433 if (((ident.byte[0] << 8) | ident.byte[1]) == ret) { 436 if (((ident.byte[0] << 8) | ident.byte[1]) == ret) {
434 printk(KERN_INFO "DiskOnChip 2000 responds to DWORD access\n"); 437 printk(KERN_INFO "DiskOnChip 2000 responds to DWORD access\n");
@@ -1046,11 +1049,21 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
1046 1049
1047//u_char mydatabuf[528]; 1050//u_char mydatabuf[528];
1048 1051
1052/* The strange out-of-order .oobfree list below is a (possibly unneeded)
1053 * attempt to retain compatibility. It used to read:
1054 * .oobfree = { {8, 8} }
1055 * Since that leaves two bytes unusable, it was changed. But the following
1056 * scheme might affect existing jffs2 installs by moving the cleanmarker:
1057 * .oobfree = { {6, 10} }
1058 * jffs2 seems to handle the above gracefully, but the current scheme seems
1059 * safer. The only problem with it is that any code that parses oobfree must
1060 * be able to handle out-of-order segments.
1061 */
1049static struct nand_oobinfo doc200x_oobinfo = { 1062static struct nand_oobinfo doc200x_oobinfo = {
1050 .useecc = MTD_NANDECC_AUTOPLACE, 1063 .useecc = MTD_NANDECC_AUTOPLACE,
1051 .eccbytes = 6, 1064 .eccbytes = 6,
1052 .eccpos = {0, 1, 2, 3, 4, 5}, 1065 .eccpos = {0, 1, 2, 3, 4, 5},
1053 .oobfree = { {8, 8} } 1066 .oobfree = { {8, 8}, {6, 2} }
1054}; 1067};
1055 1068
1056/* Find the (I)NFTL Media Header, and optionally also the mirror media header. 1069/* Find the (I)NFTL Media Header, and optionally also the mirror media header.
@@ -1064,12 +1077,11 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf,
1064{ 1077{
1065 struct nand_chip *this = mtd->priv; 1078 struct nand_chip *this = mtd->priv;
1066 struct doc_priv *doc = this->priv; 1079 struct doc_priv *doc = this->priv;
1067 unsigned offs, end = (MAX_MEDIAHEADER_SCAN << this->phys_erase_shift); 1080 unsigned offs;
1068 int ret; 1081 int ret;
1069 size_t retlen; 1082 size_t retlen;
1070 1083
1071 end = min(end, mtd->size); // paranoia 1084 for (offs = 0; offs < mtd->size; offs += mtd->erasesize) {
1072 for (offs = 0; offs < end; offs += mtd->erasesize) {
1073 ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf); 1085 ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf);
1074 if (retlen != mtd->oobblock) continue; 1086 if (retlen != mtd->oobblock) continue;
1075 if (ret) { 1087 if (ret) {
@@ -1111,6 +1123,7 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
1111 u_char *buf; 1123 u_char *buf;
1112 struct NFTLMediaHeader *mh; 1124 struct NFTLMediaHeader *mh;
1113 const unsigned psize = 1 << this->page_shift; 1125 const unsigned psize = 1 << this->page_shift;
1126 int numparts = 0;
1114 unsigned blocks, maxblocks; 1127 unsigned blocks, maxblocks;
1115 int offs, numheaders; 1128 int offs, numheaders;
1116 1129
@@ -1122,8 +1135,10 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
1122 if (!(numheaders=find_media_headers(mtd, buf, "ANAND", 1))) goto out; 1135 if (!(numheaders=find_media_headers(mtd, buf, "ANAND", 1))) goto out;
1123 mh = (struct NFTLMediaHeader *) buf; 1136 mh = (struct NFTLMediaHeader *) buf;
1124 1137
1125//#ifdef CONFIG_MTD_DEBUG_VERBOSE 1138 mh->NumEraseUnits = le16_to_cpu(mh->NumEraseUnits);
1126// if (CONFIG_MTD_DEBUG_VERBOSE >= 2) 1139 mh->FirstPhysicalEUN = le16_to_cpu(mh->FirstPhysicalEUN);
1140 mh->FormattedSize = le32_to_cpu(mh->FormattedSize);
1141
1127 printk(KERN_INFO " DataOrgID = %s\n" 1142 printk(KERN_INFO " DataOrgID = %s\n"
1128 " NumEraseUnits = %d\n" 1143 " NumEraseUnits = %d\n"
1129 " FirstPhysicalEUN = %d\n" 1144 " FirstPhysicalEUN = %d\n"
@@ -1132,7 +1147,6 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
1132 mh->DataOrgID, mh->NumEraseUnits, 1147 mh->DataOrgID, mh->NumEraseUnits,
1133 mh->FirstPhysicalEUN, mh->FormattedSize, 1148 mh->FirstPhysicalEUN, mh->FormattedSize,
1134 mh->UnitSizeFactor); 1149 mh->UnitSizeFactor);
1135//#endif
1136 1150
1137 blocks = mtd->size >> this->phys_erase_shift; 1151 blocks = mtd->size >> this->phys_erase_shift;
1138 maxblocks = min(32768U, mtd->erasesize - psize); 1152 maxblocks = min(32768U, mtd->erasesize - psize);
@@ -1175,23 +1189,28 @@ static inline int __init nftl_partscan(struct mtd_info *mtd,
1175 offs <<= this->page_shift; 1189 offs <<= this->page_shift;
1176 offs += mtd->erasesize; 1190 offs += mtd->erasesize;
1177 1191
1178 //parts[0].name = " DiskOnChip Boot / Media Header partition"; 1192 if (show_firmware_partition == 1) {
1179 //parts[0].offset = 0; 1193 parts[0].name = " DiskOnChip Firmware / Media Header partition";
1180 //parts[0].size = offs; 1194 parts[0].offset = 0;
1195 parts[0].size = offs;
1196 numparts = 1;
1197 }
1181 1198
1182 parts[0].name = " DiskOnChip BDTL partition"; 1199 parts[numparts].name = " DiskOnChip BDTL partition";
1183 parts[0].offset = offs; 1200 parts[numparts].offset = offs;
1184 parts[0].size = (mh->NumEraseUnits - numheaders) << this->bbt_erase_shift; 1201 parts[numparts].size = (mh->NumEraseUnits - numheaders) << this->bbt_erase_shift;
1202
1203 offs += parts[numparts].size;
1204 numparts++;
1185 1205
1186 offs += parts[0].size;
1187 if (offs < mtd->size) { 1206 if (offs < mtd->size) {
1188 parts[1].name = " DiskOnChip Remainder partition"; 1207 parts[numparts].name = " DiskOnChip Remainder partition";
1189 parts[1].offset = offs; 1208 parts[numparts].offset = offs;
1190 parts[1].size = mtd->size - offs; 1209 parts[numparts].size = mtd->size - offs;
1191 ret = 2; 1210 numparts++;
1192 goto out;
1193 } 1211 }
1194 ret = 1; 1212
1213 ret = numparts;
1195out: 1214out:
1196 kfree(buf); 1215 kfree(buf);
1197 return ret; 1216 return ret;
@@ -1233,8 +1252,6 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
1233 mh->FormatFlags = le32_to_cpu(mh->FormatFlags); 1252 mh->FormatFlags = le32_to_cpu(mh->FormatFlags);
1234 mh->PercentUsed = le32_to_cpu(mh->PercentUsed); 1253 mh->PercentUsed = le32_to_cpu(mh->PercentUsed);
1235 1254
1236//#ifdef CONFIG_MTD_DEBUG_VERBOSE
1237// if (CONFIG_MTD_DEBUG_VERBOSE >= 2)
1238 printk(KERN_INFO " bootRecordID = %s\n" 1255 printk(KERN_INFO " bootRecordID = %s\n"
1239 " NoOfBootImageBlocks = %d\n" 1256 " NoOfBootImageBlocks = %d\n"
1240 " NoOfBinaryPartitions = %d\n" 1257 " NoOfBinaryPartitions = %d\n"
@@ -1252,7 +1269,6 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
1252 ((unsigned char *) &mh->OsakVersion)[2] & 0xf, 1269 ((unsigned char *) &mh->OsakVersion)[2] & 0xf,
1253 ((unsigned char *) &mh->OsakVersion)[3] & 0xf, 1270 ((unsigned char *) &mh->OsakVersion)[3] & 0xf,
1254 mh->PercentUsed); 1271 mh->PercentUsed);
1255//#endif
1256 1272
1257 vshift = this->phys_erase_shift + mh->BlockMultiplierBits; 1273 vshift = this->phys_erase_shift + mh->BlockMultiplierBits;
1258 1274
@@ -1278,8 +1294,6 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
1278 ip->spareUnits = le32_to_cpu(ip->spareUnits); 1294 ip->spareUnits = le32_to_cpu(ip->spareUnits);
1279 ip->Reserved0 = le32_to_cpu(ip->Reserved0); 1295 ip->Reserved0 = le32_to_cpu(ip->Reserved0);
1280 1296
1281//#ifdef CONFIG_MTD_DEBUG_VERBOSE
1282// if (CONFIG_MTD_DEBUG_VERBOSE >= 2)
1283 printk(KERN_INFO " PARTITION[%d] ->\n" 1297 printk(KERN_INFO " PARTITION[%d] ->\n"
1284 " virtualUnits = %d\n" 1298 " virtualUnits = %d\n"
1285 " firstUnit = %d\n" 1299 " firstUnit = %d\n"
@@ -1289,16 +1303,14 @@ static inline int __init inftl_partscan(struct mtd_info *mtd,
1289 i, ip->virtualUnits, ip->firstUnit, 1303 i, ip->virtualUnits, ip->firstUnit,
1290 ip->lastUnit, ip->flags, 1304 ip->lastUnit, ip->flags,
1291 ip->spareUnits); 1305 ip->spareUnits);
1292//#endif
1293 1306
1294/* 1307 if ((show_firmware_partition == 1) &&
1295 if ((i == 0) && (ip->firstUnit > 0)) { 1308 (i == 0) && (ip->firstUnit > 0)) {
1296 parts[0].name = " DiskOnChip IPL / Media Header partition"; 1309 parts[0].name = " DiskOnChip IPL / Media Header partition";
1297 parts[0].offset = 0; 1310 parts[0].offset = 0;
1298 parts[0].size = mtd->erasesize * ip->firstUnit; 1311 parts[0].size = mtd->erasesize * ip->firstUnit;
1299 numparts = 1; 1312 numparts = 1;
1300 } 1313 }
1301*/
1302 1314
1303 if (ip->flags & INFTL_BINARY) 1315 if (ip->flags & INFTL_BINARY)
1304 parts[numparts].name = " DiskOnChip BDK partition"; 1316 parts[numparts].name = " DiskOnChip BDK partition";
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 44d5b128911f..eee5115658c8 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -28,6 +28,24 @@
28 * among multiple independend devices. Suggestions and initial patch 28 * among multiple independend devices. Suggestions and initial patch
29 * from Ben Dooks <ben-mtd@fluff.org> 29 * from Ben Dooks <ben-mtd@fluff.org>
30 * 30 *
31 * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue.
32 * Basically, any block not rewritten may lose data when surrounding blocks
33 * are rewritten many times. JFFS2 ensures this doesn't happen for blocks
34 * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they
35 * do not lose data, force them to be rewritten when some of the surrounding
36 * blocks are erased. Rather than tracking a specific nearby block (which
37 * could itself go bad), use a page address 'mask' to select several blocks
38 * in the same area, and rewrite the BBT when any of them are erased.
39 *
40 * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas
41 * AG-AND chips. If there was a sudden loss of power during an erase operation,
42 * a "device recovery" operation must be performed when power is restored
43 * to ensure correct operation.
44 *
45 * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to
46 * perform extra error status checks on erase and write failures. This required
47 * adding a wrapper function for nand_read_ecc.
48 *
31 * Credits: 49 * Credits:
32 * David Woodhouse for adding multichip support 50 * David Woodhouse for adding multichip support
33 * 51 *
@@ -41,7 +59,7 @@
41 * The AG-AND chips have nice features for speed improvement, 59 * The AG-AND chips have nice features for speed improvement,
42 * which are not supported yet. Read / program 4 pages in one go. 60 * which are not supported yet. Read / program 4 pages in one go.
43 * 61 *
44 * $Id: nand_base.c,v 1.126 2004/12/13 11:22:25 lavinen Exp $ 62 * $Id: nand_base.c,v 1.147 2005/07/15 07:18:06 gleixner Exp $
45 * 63 *
46 * This program is free software; you can redistribute it and/or modify 64 * This program is free software; you can redistribute it and/or modify
47 * it under the terms of the GNU General Public License version 2 as 65 * it under the terms of the GNU General Public License version 2 as
@@ -149,17 +167,21 @@ static void nand_release_device (struct mtd_info *mtd)
149 167
150 /* De-select the NAND device */ 168 /* De-select the NAND device */
151 this->select_chip(mtd, -1); 169 this->select_chip(mtd, -1);
152 /* Do we have a hardware controller ? */ 170
153 if (this->controller) { 171 if (this->controller) {
172 /* Release the controller and the chip */
154 spin_lock(&this->controller->lock); 173 spin_lock(&this->controller->lock);
155 this->controller->active = NULL; 174 this->controller->active = NULL;
175 this->state = FL_READY;
176 wake_up(&this->controller->wq);
156 spin_unlock(&this->controller->lock); 177 spin_unlock(&this->controller->lock);
178 } else {
179 /* Release the chip */
180 spin_lock(&this->chip_lock);
181 this->state = FL_READY;
182 wake_up(&this->wq);
183 spin_unlock(&this->chip_lock);
157 } 184 }
158 /* Release the chip */
159 spin_lock (&this->chip_lock);
160 this->state = FL_READY;
161 wake_up (&this->wq);
162 spin_unlock (&this->chip_lock);
163} 185}
164 186
165/** 187/**
@@ -443,7 +465,8 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
443 465
444 /* Get block number */ 466 /* Get block number */
445 block = ((int) ofs) >> this->bbt_erase_shift; 467 block = ((int) ofs) >> this->bbt_erase_shift;
446 this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 468 if (this->bbt)
469 this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
447 470
448 /* Do we have a flash based bad block table ? */ 471 /* Do we have a flash based bad block table ? */
449 if (this->options & NAND_USE_FLASH_BBT) 472 if (this->options & NAND_USE_FLASH_BBT)
@@ -466,7 +489,7 @@ static int nand_check_wp (struct mtd_info *mtd)
466 struct nand_chip *this = mtd->priv; 489 struct nand_chip *this = mtd->priv;
467 /* Check the WP bit */ 490 /* Check the WP bit */
468 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); 491 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
469 return (this->read_byte(mtd) & 0x80) ? 0 : 1; 492 return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1;
470} 493}
471 494
472/** 495/**
@@ -490,6 +513,22 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i
490 return nand_isbad_bbt (mtd, ofs, allowbbt); 513 return nand_isbad_bbt (mtd, ofs, allowbbt);
491} 514}
492 515
516/*
517 * Wait for the ready pin, after a command
518 * The timeout is catched later.
519 */
520static void nand_wait_ready(struct mtd_info *mtd)
521{
522 struct nand_chip *this = mtd->priv;
523 unsigned long timeo = jiffies + 2;
524
525 /* wait until command is processed or timeout occures */
526 do {
527 if (this->dev_ready(mtd))
528 return;
529 } while (time_before(jiffies, timeo));
530}
531
493/** 532/**
494 * nand_command - [DEFAULT] Send command to NAND device 533 * nand_command - [DEFAULT] Send command to NAND device
495 * @mtd: MTD device structure 534 * @mtd: MTD device structure
@@ -571,7 +610,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
571 this->hwcontrol(mtd, NAND_CTL_SETCLE); 610 this->hwcontrol(mtd, NAND_CTL_SETCLE);
572 this->write_byte(mtd, NAND_CMD_STATUS); 611 this->write_byte(mtd, NAND_CMD_STATUS);
573 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 612 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
574 while ( !(this->read_byte(mtd) & 0x40)); 613 while ( !(this->read_byte(mtd) & NAND_STATUS_READY));
575 return; 614 return;
576 615
577 /* This applies to read commands */ 616 /* This applies to read commands */
@@ -585,12 +624,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in
585 return; 624 return;
586 } 625 }
587 } 626 }
588
589 /* Apply this short delay always to ensure that we do wait tWB in 627 /* Apply this short delay always to ensure that we do wait tWB in
590 * any case on any machine. */ 628 * any case on any machine. */
591 ndelay (100); 629 ndelay (100);
592 /* wait until command is processed */ 630
593 while (!this->dev_ready(mtd)); 631 nand_wait_ready(mtd);
594} 632}
595 633
596/** 634/**
@@ -619,7 +657,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
619 /* Begin command latch cycle */ 657 /* Begin command latch cycle */
620 this->hwcontrol(mtd, NAND_CTL_SETCLE); 658 this->hwcontrol(mtd, NAND_CTL_SETCLE);
621 /* Write out the command to the device. */ 659 /* Write out the command to the device. */
622 this->write_byte(mtd, command); 660 this->write_byte(mtd, (command & 0xff));
623 /* End command latch cycle */ 661 /* End command latch cycle */
624 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 662 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
625 663
@@ -647,8 +685,8 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
647 685
648 /* 686 /*
649 * program and erase have their own busy handlers 687 * program and erase have their own busy handlers
650 * status and sequential in needs no delay 688 * status, sequential in, and deplete1 need no delay
651 */ 689 */
652 switch (command) { 690 switch (command) {
653 691
654 case NAND_CMD_CACHEDPROG: 692 case NAND_CMD_CACHEDPROG:
@@ -657,8 +695,19 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
657 case NAND_CMD_ERASE2: 695 case NAND_CMD_ERASE2:
658 case NAND_CMD_SEQIN: 696 case NAND_CMD_SEQIN:
659 case NAND_CMD_STATUS: 697 case NAND_CMD_STATUS:
698 case NAND_CMD_DEPLETE1:
660 return; 699 return;
661 700
701 /*
702 * read error status commands require only a short delay
703 */
704 case NAND_CMD_STATUS_ERROR:
705 case NAND_CMD_STATUS_ERROR0:
706 case NAND_CMD_STATUS_ERROR1:
707 case NAND_CMD_STATUS_ERROR2:
708 case NAND_CMD_STATUS_ERROR3:
709 udelay(this->chip_delay);
710 return;
662 711
663 case NAND_CMD_RESET: 712 case NAND_CMD_RESET:
664 if (this->dev_ready) 713 if (this->dev_ready)
@@ -667,7 +716,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
667 this->hwcontrol(mtd, NAND_CTL_SETCLE); 716 this->hwcontrol(mtd, NAND_CTL_SETCLE);
668 this->write_byte(mtd, NAND_CMD_STATUS); 717 this->write_byte(mtd, NAND_CMD_STATUS);
669 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 718 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
670 while ( !(this->read_byte(mtd) & 0x40)); 719 while ( !(this->read_byte(mtd) & NAND_STATUS_READY));
671 return; 720 return;
672 721
673 case NAND_CMD_READ0: 722 case NAND_CMD_READ0:
@@ -690,12 +739,12 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
690 return; 739 return;
691 } 740 }
692 } 741 }
693 742
694 /* Apply this short delay always to ensure that we do wait tWB in 743 /* Apply this short delay always to ensure that we do wait tWB in
695 * any case on any machine. */ 744 * any case on any machine. */
696 ndelay (100); 745 ndelay (100);
697 /* wait until command is processed */ 746
698 while (!this->dev_ready(mtd)); 747 nand_wait_ready(mtd);
699} 748}
700 749
701/** 750/**
@@ -708,37 +757,34 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
708 */ 757 */
709static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) 758static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
710{ 759{
711 struct nand_chip *active = this; 760 struct nand_chip *active;
712 761 spinlock_t *lock;
762 wait_queue_head_t *wq;
713 DECLARE_WAITQUEUE (wait, current); 763 DECLARE_WAITQUEUE (wait, current);
714 764
715 /* 765 lock = (this->controller) ? &this->controller->lock : &this->chip_lock;
716 * Grab the lock and see if the device is available 766 wq = (this->controller) ? &this->controller->wq : &this->wq;
717 */
718retry: 767retry:
768 active = this;
769 spin_lock(lock);
770
719 /* Hardware controller shared among independend devices */ 771 /* Hardware controller shared among independend devices */
720 if (this->controller) { 772 if (this->controller) {
721 spin_lock (&this->controller->lock);
722 if (this->controller->active) 773 if (this->controller->active)
723 active = this->controller->active; 774 active = this->controller->active;
724 else 775 else
725 this->controller->active = this; 776 this->controller->active = this;
726 spin_unlock (&this->controller->lock);
727 } 777 }
728 778 if (active == this && this->state == FL_READY) {
729 if (active == this) { 779 this->state = new_state;
730 spin_lock (&this->chip_lock); 780 spin_unlock(lock);
731 if (this->state == FL_READY) { 781 return;
732 this->state = new_state; 782 }
733 spin_unlock (&this->chip_lock); 783 set_current_state(TASK_UNINTERRUPTIBLE);
734 return; 784 add_wait_queue(wq, &wait);
735 } 785 spin_unlock(lock);
736 } 786 schedule();
737 set_current_state (TASK_UNINTERRUPTIBLE); 787 remove_wait_queue(wq, &wait);
738 add_wait_queue (&active->wq, &wait);
739 spin_unlock (&active->chip_lock);
740 schedule ();
741 remove_wait_queue (&active->wq, &wait);
742 goto retry; 788 goto retry;
743} 789}
744 790
@@ -785,7 +831,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
785 if (this->read_byte(mtd) & NAND_STATUS_READY) 831 if (this->read_byte(mtd) & NAND_STATUS_READY)
786 break; 832 break;
787 } 833 }
788 yield (); 834 cond_resched();
789 } 835 }
790 status = (int) this->read_byte(mtd); 836 status = (int) this->read_byte(mtd);
791 return status; 837 return status;
@@ -871,8 +917,14 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa
871 if (!cached) { 917 if (!cached) {
872 /* call wait ready function */ 918 /* call wait ready function */
873 status = this->waitfunc (mtd, this, FL_WRITING); 919 status = this->waitfunc (mtd, this, FL_WRITING);
920
921 /* See if operation failed and additional status checks are available */
922 if ((status & NAND_STATUS_FAIL) && (this->errstat)) {
923 status = this->errstat(mtd, this, FL_WRITING, status, page);
924 }
925
874 /* See if device thinks it succeeded */ 926 /* See if device thinks it succeeded */
875 if (status & 0x01) { 927 if (status & NAND_STATUS_FAIL) {
876 DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page); 928 DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page);
877 return -EIO; 929 return -EIO;
878 } 930 }
@@ -975,7 +1027,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
975 if (!this->dev_ready) 1027 if (!this->dev_ready)
976 udelay (this->chip_delay); 1028 udelay (this->chip_delay);
977 else 1029 else
978 while (!this->dev_ready(mtd)); 1030 nand_wait_ready(mtd);
979 1031
980 /* All done, return happy */ 1032 /* All done, return happy */
981 if (!numpages) 1033 if (!numpages)
@@ -997,23 +1049,24 @@ out:
997#endif 1049#endif
998 1050
999/** 1051/**
1000 * nand_read - [MTD Interface] MTD compability function for nand_read_ecc 1052 * nand_read - [MTD Interface] MTD compability function for nand_do_read_ecc
1001 * @mtd: MTD device structure 1053 * @mtd: MTD device structure
1002 * @from: offset to read from 1054 * @from: offset to read from
1003 * @len: number of bytes to read 1055 * @len: number of bytes to read
1004 * @retlen: pointer to variable to store the number of read bytes 1056 * @retlen: pointer to variable to store the number of read bytes
1005 * @buf: the databuffer to put data 1057 * @buf: the databuffer to put data
1006 * 1058 *
1007 * This function simply calls nand_read_ecc with oob buffer and oobsel = NULL 1059 * This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL
1008*/ 1060 * and flags = 0xff
1061 */
1009static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) 1062static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf)
1010{ 1063{
1011 return nand_read_ecc (mtd, from, len, retlen, buf, NULL, NULL); 1064 return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff);
1012} 1065}
1013 1066
1014 1067
1015/** 1068/**
1016 * nand_read_ecc - [MTD Interface] Read data with ECC 1069 * nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc
1017 * @mtd: MTD device structure 1070 * @mtd: MTD device structure
1018 * @from: offset to read from 1071 * @from: offset to read from
1019 * @len: number of bytes to read 1072 * @len: number of bytes to read
@@ -1022,11 +1075,39 @@ static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * re
1022 * @oob_buf: filesystem supplied oob data buffer 1075 * @oob_buf: filesystem supplied oob data buffer
1023 * @oobsel: oob selection structure 1076 * @oobsel: oob selection structure
1024 * 1077 *
1025 * NAND read with ECC 1078 * This function simply calls nand_do_read_ecc with flags = 0xff
1026 */ 1079 */
1027static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 1080static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1028 size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel) 1081 size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel)
1029{ 1082{
1083 /* use userspace supplied oobinfo, if zero */
1084 if (oobsel == NULL)
1085 oobsel = &mtd->oobinfo;
1086 return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff);
1087}
1088
1089
1090/**
1091 * nand_do_read_ecc - [MTD Interface] Read data with ECC
1092 * @mtd: MTD device structure
1093 * @from: offset to read from
1094 * @len: number of bytes to read
1095 * @retlen: pointer to variable to store the number of read bytes
1096 * @buf: the databuffer to put data
1097 * @oob_buf: filesystem supplied oob data buffer (can be NULL)
1098 * @oobsel: oob selection structure
1099 * @flags: flag to indicate if nand_get_device/nand_release_device should be preformed
1100 * and how many corrected error bits are acceptable:
1101 * bits 0..7 - number of tolerable errors
1102 * bit 8 - 0 == do not get/release chip, 1 == get/release chip
1103 *
1104 * NAND read with ECC
1105 */
1106int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1107 size_t * retlen, u_char * buf, u_char * oob_buf,
1108 struct nand_oobinfo *oobsel, int flags)
1109{
1110
1030 int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; 1111 int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1;
1031 int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0; 1112 int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0;
1032 struct nand_chip *this = mtd->priv; 1113 struct nand_chip *this = mtd->priv;
@@ -1051,12 +1132,9 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1051 } 1132 }
1052 1133
1053 /* Grab the lock and see if the device is available */ 1134 /* Grab the lock and see if the device is available */
1054 nand_get_device (this, mtd ,FL_READING); 1135 if (flags & NAND_GET_DEVICE)
1136 nand_get_device (this, mtd, FL_READING);
1055 1137
1056 /* use userspace supplied oobinfo, if zero */
1057 if (oobsel == NULL)
1058 oobsel = &mtd->oobinfo;
1059
1060 /* Autoplace of oob data ? Use the default placement scheme */ 1138 /* Autoplace of oob data ? Use the default placement scheme */
1061 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1139 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE)
1062 oobsel = this->autooob; 1140 oobsel = this->autooob;
@@ -1118,7 +1196,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1118 } 1196 }
1119 1197
1120 /* get oob area, if we have no oob buffer from fs-driver */ 1198 /* get oob area, if we have no oob buffer from fs-driver */
1121 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1199 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE ||
1200 oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1122 oob_data = &this->data_buf[end]; 1201 oob_data = &this->data_buf[end];
1123 1202
1124 eccsteps = this->eccsteps; 1203 eccsteps = this->eccsteps;
@@ -1155,7 +1234,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1155 /* We calc error correction directly, it checks the hw 1234 /* We calc error correction directly, it checks the hw
1156 * generator for an error, reads back the syndrome and 1235 * generator for an error, reads back the syndrome and
1157 * does the error correction on the fly */ 1236 * does the error correction on the fly */
1158 if (this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]) == -1) { 1237 ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]);
1238 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
1159 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " 1239 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: "
1160 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); 1240 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr);
1161 ecc_failed++; 1241 ecc_failed++;
@@ -1194,7 +1274,7 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1194 p[i] = ecc_status; 1274 p[i] = ecc_status;
1195 } 1275 }
1196 1276
1197 if (ecc_status == -1) { 1277 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
1198 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); 1278 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page);
1199 ecc_failed++; 1279 ecc_failed++;
1200 } 1280 }
@@ -1206,14 +1286,14 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1206 /* without autoplace. Legacy mode used by YAFFS1 */ 1286 /* without autoplace. Legacy mode used by YAFFS1 */
1207 switch(oobsel->useecc) { 1287 switch(oobsel->useecc) {
1208 case MTD_NANDECC_AUTOPLACE: 1288 case MTD_NANDECC_AUTOPLACE:
1289 case MTD_NANDECC_AUTOPL_USR:
1209 /* Walk through the autoplace chunks */ 1290 /* Walk through the autoplace chunks */
1210 for (i = 0, j = 0; j < mtd->oobavail; i++) { 1291 for (i = 0; oobsel->oobfree[i][1]; i++) {
1211 int from = oobsel->oobfree[i][0]; 1292 int from = oobsel->oobfree[i][0];
1212 int num = oobsel->oobfree[i][1]; 1293 int num = oobsel->oobfree[i][1];
1213 memcpy(&oob_buf[oob], &oob_data[from], num); 1294 memcpy(&oob_buf[oob], &oob_data[from], num);
1214 j+= num; 1295 oob += num;
1215 } 1296 }
1216 oob += mtd->oobavail;
1217 break; 1297 break;
1218 case MTD_NANDECC_PLACE: 1298 case MTD_NANDECC_PLACE:
1219 /* YAFFS1 legacy mode */ 1299 /* YAFFS1 legacy mode */
@@ -1239,7 +1319,7 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1239 if (!this->dev_ready) 1319 if (!this->dev_ready)
1240 udelay (this->chip_delay); 1320 udelay (this->chip_delay);
1241 else 1321 else
1242 while (!this->dev_ready(mtd)); 1322 nand_wait_ready(mtd);
1243 1323
1244 if (read == len) 1324 if (read == len)
1245 break; 1325 break;
@@ -1264,7 +1344,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
1264 } 1344 }
1265 1345
1266 /* Deselect and wake up anyone waiting on the device */ 1346 /* Deselect and wake up anyone waiting on the device */
1267 nand_release_device(mtd); 1347 if (flags & NAND_GET_DEVICE)
1348 nand_release_device(mtd);
1268 1349
1269 /* 1350 /*
1270 * Return success, if no ECC failures, else -EBADMSG 1351 * Return success, if no ECC failures, else -EBADMSG
@@ -1328,16 +1409,6 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
1328 thislen = min_t(int, thislen, len); 1409 thislen = min_t(int, thislen, len);
1329 this->read_buf(mtd, &buf[i], thislen); 1410 this->read_buf(mtd, &buf[i], thislen);
1330 i += thislen; 1411 i += thislen;
1331
1332 /* Apply delay or wait for ready/busy pin
1333 * Do this before the AUTOINCR check, so no problems
1334 * arise if a chip which does auto increment
1335 * is marked as NOAUTOINCR by the board driver.
1336 */
1337 if (!this->dev_ready)
1338 udelay (this->chip_delay);
1339 else
1340 while (!this->dev_ready(mtd));
1341 1412
1342 /* Read more ? */ 1413 /* Read more ? */
1343 if (i < len) { 1414 if (i < len) {
@@ -1351,6 +1422,16 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t
1351 this->select_chip(mtd, chipnr); 1422 this->select_chip(mtd, chipnr);
1352 } 1423 }
1353 1424
1425 /* Apply delay or wait for ready/busy pin
1426 * Do this before the AUTOINCR check, so no problems
1427 * arise if a chip which does auto increment
1428 * is marked as NOAUTOINCR by the board driver.
1429 */
1430 if (!this->dev_ready)
1431 udelay (this->chip_delay);
1432 else
1433 nand_wait_ready(mtd);
1434
1354 /* Check, if the chip supports auto page increment 1435 /* Check, if the chip supports auto page increment
1355 * or if we have hit a block boundary. 1436 * or if we have hit a block boundary.
1356 */ 1437 */
@@ -1417,7 +1498,7 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
1417 if (!this->dev_ready) 1498 if (!this->dev_ready)
1418 udelay (this->chip_delay); 1499 udelay (this->chip_delay);
1419 else 1500 else
1420 while (!this->dev_ready(mtd)); 1501 nand_wait_ready(mtd);
1421 1502
1422 /* Check, if the chip supports auto page increment */ 1503 /* Check, if the chip supports auto page increment */
1423 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) 1504 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck))
@@ -1567,6 +1648,8 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
1567 oobsel = this->autooob; 1648 oobsel = this->autooob;
1568 autoplace = 1; 1649 autoplace = 1;
1569 } 1650 }
1651 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1652 autoplace = 1;
1570 1653
1571 /* Setup variables and oob buffer */ 1654 /* Setup variables and oob buffer */
1572 totalpages = len >> this->page_shift; 1655 totalpages = len >> this->page_shift;
@@ -1733,7 +1816,7 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t *
1733 status = this->waitfunc (mtd, this, FL_WRITING); 1816 status = this->waitfunc (mtd, this, FL_WRITING);
1734 1817
1735 /* See if device thinks it succeeded */ 1818 /* See if device thinks it succeeded */
1736 if (status & 0x01) { 1819 if (status & NAND_STATUS_FAIL) {
1737 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page); 1820 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page);
1738 ret = -EIO; 1821 ret = -EIO;
1739 goto out; 1822 goto out;
@@ -1841,6 +1924,8 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig
1841 oobsel = this->autooob; 1924 oobsel = this->autooob;
1842 autoplace = 1; 1925 autoplace = 1;
1843 } 1926 }
1927 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1928 autoplace = 1;
1844 1929
1845 /* Setup start page */ 1930 /* Setup start page */
1846 page = (int) (to >> this->page_shift); 1931 page = (int) (to >> this->page_shift);
@@ -1987,6 +2072,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr)
1987 return nand_erase_nand (mtd, instr, 0); 2072 return nand_erase_nand (mtd, instr, 0);
1988} 2073}
1989 2074
2075#define BBT_PAGE_MASK 0xffffff3f
1990/** 2076/**
1991 * nand_erase_intern - [NAND Interface] erase block(s) 2077 * nand_erase_intern - [NAND Interface] erase block(s)
1992 * @mtd: MTD device structure 2078 * @mtd: MTD device structure
@@ -1999,6 +2085,10 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
1999{ 2085{
2000 int page, len, status, pages_per_block, ret, chipnr; 2086 int page, len, status, pages_per_block, ret, chipnr;
2001 struct nand_chip *this = mtd->priv; 2087 struct nand_chip *this = mtd->priv;
2088 int rewrite_bbt[NAND_MAX_CHIPS]={0}; /* flags to indicate the page, if bbt needs to be rewritten. */
2089 unsigned int bbt_masked_page; /* bbt mask to compare to page being erased. */
2090 /* It is used to see if the current page is in the same */
2091 /* 256 block group and the same bank as the bbt. */
2002 2092
2003 DEBUG (MTD_DEBUG_LEVEL3, 2093 DEBUG (MTD_DEBUG_LEVEL3,
2004 "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len); 2094 "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
@@ -2044,6 +2134,13 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2044 goto erase_exit; 2134 goto erase_exit;
2045 } 2135 }
2046 2136
2137 /* if BBT requires refresh, set the BBT page mask to see if the BBT should be rewritten */
2138 if (this->options & BBT_AUTO_REFRESH) {
2139 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
2140 } else {
2141 bbt_masked_page = 0xffffffff; /* should not match anything */
2142 }
2143
2047 /* Loop through the pages */ 2144 /* Loop through the pages */
2048 len = instr->len; 2145 len = instr->len;
2049 2146
@@ -2066,13 +2163,26 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2066 2163
2067 status = this->waitfunc (mtd, this, FL_ERASING); 2164 status = this->waitfunc (mtd, this, FL_ERASING);
2068 2165
2166 /* See if operation failed and additional status checks are available */
2167 if ((status & NAND_STATUS_FAIL) && (this->errstat)) {
2168 status = this->errstat(mtd, this, FL_ERASING, status, page);
2169 }
2170
2069 /* See if block erase succeeded */ 2171 /* See if block erase succeeded */
2070 if (status & 0x01) { 2172 if (status & NAND_STATUS_FAIL) {
2071 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); 2173 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page);
2072 instr->state = MTD_ERASE_FAILED; 2174 instr->state = MTD_ERASE_FAILED;
2073 instr->fail_addr = (page << this->page_shift); 2175 instr->fail_addr = (page << this->page_shift);
2074 goto erase_exit; 2176 goto erase_exit;
2075 } 2177 }
2178
2179 /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */
2180 if (this->options & BBT_AUTO_REFRESH) {
2181 if (((page & BBT_PAGE_MASK) == bbt_masked_page) &&
2182 (page != this->bbt_td->pages[chipnr])) {
2183 rewrite_bbt[chipnr] = (page << this->page_shift);
2184 }
2185 }
2076 2186
2077 /* Increment page address and decrement length */ 2187 /* Increment page address and decrement length */
2078 len -= (1 << this->phys_erase_shift); 2188 len -= (1 << this->phys_erase_shift);
@@ -2083,6 +2193,13 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb
2083 chipnr++; 2193 chipnr++;
2084 this->select_chip(mtd, -1); 2194 this->select_chip(mtd, -1);
2085 this->select_chip(mtd, chipnr); 2195 this->select_chip(mtd, chipnr);
2196
2197 /* if BBT requires refresh and BBT-PERCHIP,
2198 * set the BBT page mask to see if this BBT should be rewritten */
2199 if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) {
2200 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
2201 }
2202
2086 } 2203 }
2087 } 2204 }
2088 instr->state = MTD_ERASE_DONE; 2205 instr->state = MTD_ERASE_DONE;
@@ -2097,6 +2214,18 @@ erase_exit:
2097 /* Deselect and wake up anyone waiting on the device */ 2214 /* Deselect and wake up anyone waiting on the device */
2098 nand_release_device(mtd); 2215 nand_release_device(mtd);
2099 2216
2217 /* if BBT requires refresh and erase was successful, rewrite any selected bad block tables */
2218 if ((this->options & BBT_AUTO_REFRESH) && (!ret)) {
2219 for (chipnr = 0; chipnr < this->numchips; chipnr++) {
2220 if (rewrite_bbt[chipnr]) {
2221 /* update the BBT for chip */
2222 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n",
2223 chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]);
2224 nand_update_bbt (mtd, rewrite_bbt[chipnr]);
2225 }
2226 }
2227 }
2228
2100 /* Return more or less happy */ 2229 /* Return more or less happy */
2101 return ret; 2230 return ret;
2102} 2231}
@@ -2168,7 +2297,7 @@ static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs)
2168 */ 2297 */
2169int nand_scan (struct mtd_info *mtd, int maxchips) 2298int nand_scan (struct mtd_info *mtd, int maxchips)
2170{ 2299{
2171 int i, j, nand_maf_id, nand_dev_id, busw; 2300 int i, nand_maf_id, nand_dev_id, busw, maf_id;
2172 struct nand_chip *this = mtd->priv; 2301 struct nand_chip *this = mtd->priv;
2173 2302
2174 /* Get buswidth to select the correct functions*/ 2303 /* Get buswidth to select the correct functions*/
@@ -2256,12 +2385,18 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2256 busw = nand_flash_ids[i].options & NAND_BUSWIDTH_16; 2385 busw = nand_flash_ids[i].options & NAND_BUSWIDTH_16;
2257 } 2386 }
2258 2387
2388 /* Try to identify manufacturer */
2389 for (maf_id = 0; nand_manuf_ids[maf_id].id != 0x0; maf_id++) {
2390 if (nand_manuf_ids[maf_id].id == nand_maf_id)
2391 break;
2392 }
2393
2259 /* Check, if buswidth is correct. Hardware drivers should set 2394 /* Check, if buswidth is correct. Hardware drivers should set
2260 * this correct ! */ 2395 * this correct ! */
2261 if (busw != (this->options & NAND_BUSWIDTH_16)) { 2396 if (busw != (this->options & NAND_BUSWIDTH_16)) {
2262 printk (KERN_INFO "NAND device: Manufacturer ID:" 2397 printk (KERN_INFO "NAND device: Manufacturer ID:"
2263 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2398 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
2264 nand_manuf_ids[i].name , mtd->name); 2399 nand_manuf_ids[maf_id].name , mtd->name);
2265 printk (KERN_WARNING 2400 printk (KERN_WARNING
2266 "NAND bus width %d instead %d bit\n", 2401 "NAND bus width %d instead %d bit\n",
2267 (this->options & NAND_BUSWIDTH_16) ? 16 : 8, 2402 (this->options & NAND_BUSWIDTH_16) ? 16 : 8,
@@ -2300,14 +2435,9 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2300 if (mtd->oobblock > 512 && this->cmdfunc == nand_command) 2435 if (mtd->oobblock > 512 && this->cmdfunc == nand_command)
2301 this->cmdfunc = nand_command_lp; 2436 this->cmdfunc = nand_command_lp;
2302 2437
2303 /* Try to identify manufacturer */
2304 for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
2305 if (nand_manuf_ids[j].id == nand_maf_id)
2306 break;
2307 }
2308 printk (KERN_INFO "NAND device: Manufacturer ID:" 2438 printk (KERN_INFO "NAND device: Manufacturer ID:"
2309 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2439 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id,
2310 nand_manuf_ids[j].name , nand_flash_ids[i].name); 2440 nand_manuf_ids[maf_id].name , nand_flash_ids[i].name);
2311 break; 2441 break;
2312 } 2442 }
2313 2443
@@ -2388,12 +2518,9 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2388 2518
2389 /* The number of bytes available for the filesystem to place fs dependend 2519 /* The number of bytes available for the filesystem to place fs dependend
2390 * oob data */ 2520 * oob data */
2391 if (this->options & NAND_BUSWIDTH_16) { 2521 mtd->oobavail = 0;
2392 mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 2); 2522 for (i = 0; this->autooob->oobfree[i][1]; i++)
2393 if (this->autooob->eccbytes & 0x01) 2523 mtd->oobavail += this->autooob->oobfree[i][1];
2394 mtd->oobavail--;
2395 } else
2396 mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 1);
2397 2524
2398 /* 2525 /*
2399 * check ECC mode, default to software 2526 * check ECC mode, default to software
@@ -2524,6 +2651,10 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
2524 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); 2651 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
2525 2652
2526 mtd->owner = THIS_MODULE; 2653 mtd->owner = THIS_MODULE;
2654
2655 /* Check, if we should skip the bad block table scan */
2656 if (this->options & NAND_SKIP_BBTSCAN)
2657 return 0;
2527 2658
2528 /* Build bad block table */ 2659 /* Build bad block table */
2529 return this->scan_bbt (mtd); 2660 return this->scan_bbt (mtd);
@@ -2555,8 +2686,8 @@ void nand_release (struct mtd_info *mtd)
2555 kfree (this->data_buf); 2686 kfree (this->data_buf);
2556} 2687}
2557 2688
2558EXPORT_SYMBOL (nand_scan); 2689EXPORT_SYMBOL_GPL (nand_scan);
2559EXPORT_SYMBOL (nand_release); 2690EXPORT_SYMBOL_GPL (nand_release);
2560 2691
2561MODULE_LICENSE ("GPL"); 2692MODULE_LICENSE ("GPL");
2562MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>"); 2693MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>");
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 9a1949751c1f..7535ef53685e 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -6,7 +6,7 @@
6 * 6 *
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
8 * 8 *
9 * $Id: nand_bbt.c,v 1.28 2004/11/13 10:19:09 gleixner Exp $ 9 * $Id: nand_bbt.c,v 1.35 2005/07/15 13:53:47 gleixner Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -77,7 +77,7 @@
77*/ 77*/
78static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 78static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
79{ 79{
80 int i, end; 80 int i, end = 0;
81 uint8_t *p = buf; 81 uint8_t *p = buf;
82 82
83 end = paglen + td->offs; 83 end = paglen + td->offs;
@@ -95,9 +95,9 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
95 return -1; 95 return -1;
96 } 96 }
97 97
98 p += td->len;
99 end += td->len;
100 if (td->options & NAND_BBT_SCANEMPTY) { 98 if (td->options & NAND_BBT_SCANEMPTY) {
99 p += td->len;
100 end += td->len;
101 for (i = end; i < len; i++) { 101 for (i = end; i < len; i++) {
102 if (*p++ != 0xff) 102 if (*p++ != 0xff)
103 return -1; 103 return -1;
@@ -106,6 +106,29 @@ static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_des
106 return 0; 106 return 0;
107} 107}
108 108
109/**
110 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
111 * @buf: the buffer to search
112 * @td: search pattern descriptor
113 *
114 * Check for a pattern at the given place. Used to search bad block
115 * tables and good / bad block identifiers. Same as check_pattern, but
116 * no optional empty check
117 *
118*/
119static int check_short_pattern (uint8_t *buf, struct nand_bbt_descr *td)
120{
121 int i;
122 uint8_t *p = buf;
123
124 /* Compare the pattern */
125 for (i = 0; i < td->len; i++) {
126 if (p[td->offs + i] != td->pattern[i])
127 return -1;
128 }
129 return 0;
130}
131
109/** 132/**
110 * read_bbt - [GENERIC] Read the bad block table starting from page 133 * read_bbt - [GENERIC] Read the bad block table starting from page
111 * @mtd: MTD device structure 134 * @mtd: MTD device structure
@@ -252,7 +275,7 @@ static int read_abs_bbts (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_de
252 * Create a bad block table by scanning the device 275 * Create a bad block table by scanning the device
253 * for the given good/bad block identify pattern 276 * for the given good/bad block identify pattern
254 */ 277 */
255static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) 278static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip)
256{ 279{
257 struct nand_chip *this = mtd->priv; 280 struct nand_chip *this = mtd->priv;
258 int i, j, numblocks, len, scanlen; 281 int i, j, numblocks, len, scanlen;
@@ -270,9 +293,17 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
270 else 293 else
271 len = 1; 294 len = 1;
272 } 295 }
273 scanlen = mtd->oobblock + mtd->oobsize; 296
274 readlen = len * mtd->oobblock; 297 if (!(bd->options & NAND_BBT_SCANEMPTY)) {
275 ooblen = len * mtd->oobsize; 298 /* We need only read few bytes from the OOB area */
299 scanlen = ooblen = 0;
300 readlen = bd->len;
301 } else {
302 /* Full page content should be read */
303 scanlen = mtd->oobblock + mtd->oobsize;
304 readlen = len * mtd->oobblock;
305 ooblen = len * mtd->oobsize;
306 }
276 307
277 if (chip == -1) { 308 if (chip == -1) {
278 /* Note that numblocks is 2 * (real numblocks) here, see i+=2 below as it 309 /* Note that numblocks is 2 * (real numblocks) here, see i+=2 below as it
@@ -284,7 +315,7 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
284 if (chip >= this->numchips) { 315 if (chip >= this->numchips) {
285 printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n", 316 printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n",
286 chip + 1, this->numchips); 317 chip + 1, this->numchips);
287 return; 318 return -EINVAL;
288 } 319 }
289 numblocks = this->chipsize >> (this->bbt_erase_shift - 1); 320 numblocks = this->chipsize >> (this->bbt_erase_shift - 1);
290 startblock = chip * numblocks; 321 startblock = chip * numblocks;
@@ -293,18 +324,42 @@ static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
293 } 324 }
294 325
295 for (i = startblock; i < numblocks;) { 326 for (i = startblock; i < numblocks;) {
296 nand_read_raw (mtd, buf, from, readlen, ooblen); 327 int ret;
328
329 if (bd->options & NAND_BBT_SCANEMPTY)
330 if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen)))
331 return ret;
332
297 for (j = 0; j < len; j++) { 333 for (j = 0; j < len; j++) {
298 if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { 334 if (!(bd->options & NAND_BBT_SCANEMPTY)) {
299 this->bbt[i >> 3] |= 0x03 << (i & 0x6); 335 size_t retlen;
300 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 336
301 i >> 1, (unsigned int) from); 337 /* Read the full oob until read_oob is fixed to
302 break; 338 * handle single byte reads for 16 bit buswidth */
339 ret = mtd->read_oob(mtd, from + j * mtd->oobblock,
340 mtd->oobsize, &retlen, buf);
341 if (ret)
342 return ret;
343
344 if (check_short_pattern (buf, bd)) {
345 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
346 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
347 i >> 1, (unsigned int) from);
348 break;
349 }
350 } else {
351 if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) {
352 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
353 printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
354 i >> 1, (unsigned int) from);
355 break;
356 }
303 } 357 }
304 } 358 }
305 i += 2; 359 i += 2;
306 from += (1 << this->bbt_erase_shift); 360 from += (1 << this->bbt_erase_shift);
307 } 361 }
362 return 0;
308} 363}
309 364
310/** 365/**
@@ -589,14 +644,12 @@ write:
589 * The function creates a memory based bbt by scanning the device 644 * The function creates a memory based bbt by scanning the device
590 * for manufacturer / software marked good / bad blocks 645 * for manufacturer / software marked good / bad blocks
591*/ 646*/
592static int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) 647static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
593{ 648{
594 struct nand_chip *this = mtd->priv; 649 struct nand_chip *this = mtd->priv;
595 650
596 /* Ensure that we only scan for the pattern and nothing else */ 651 bd->options &= ~NAND_BBT_SCANEMPTY;
597 bd->options = 0; 652 return create_bbt (mtd, this->data_buf, bd, -1);
598 create_bbt (mtd, this->data_buf, bd, -1);
599 return 0;
600} 653}
601 654
602/** 655/**
@@ -808,8 +861,14 @@ int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd)
808 /* If no primary table decriptor is given, scan the device 861 /* If no primary table decriptor is given, scan the device
809 * to build a memory based bad block table 862 * to build a memory based bad block table
810 */ 863 */
811 if (!td) 864 if (!td) {
812 return nand_memory_bbt(mtd, bd); 865 if ((res = nand_memory_bbt(mtd, bd))) {
866 printk (KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n");
867 kfree (this->bbt);
868 this->bbt = NULL;
869 }
870 return res;
871 }
813 872
814 /* Allocate a temporary buffer for one eraseblock incl. oob */ 873 /* Allocate a temporary buffer for one eraseblock incl. oob */
815 len = (1 << this->bbt_erase_shift); 874 len = (1 << this->bbt_erase_shift);
@@ -904,14 +963,11 @@ out:
904} 963}
905 964
906/* Define some generic bad / good block scan pattern which are used 965/* Define some generic bad / good block scan pattern which are used
907 * while scanning a device for factory marked good / bad blocks 966 * while scanning a device for factory marked good / bad blocks. */
908 *
909 * The memory based patterns just
910 */
911static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 967static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
912 968
913static struct nand_bbt_descr smallpage_memorybased = { 969static struct nand_bbt_descr smallpage_memorybased = {
914 .options = 0, 970 .options = NAND_BBT_SCAN2NDPAGE,
915 .offs = 5, 971 .offs = 5,
916 .len = 1, 972 .len = 1,
917 .pattern = scan_ff_pattern 973 .pattern = scan_ff_pattern
@@ -1042,7 +1098,7 @@ int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt)
1042 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; 1098 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
1043 1099
1044 DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1100 DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
1045 (unsigned int)offs, res, block >> 1); 1101 (unsigned int)offs, block >> 1, res);
1046 1102
1047 switch ((int)res) { 1103 switch ((int)res) {
1048 case 0x00: return 0; 1104 case 0x00: return 0;
diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c
index 2d8c4321275b..efe246961b69 100644
--- a/drivers/mtd/nand/nand_ids.c
+++ b/drivers/mtd/nand/nand_ids.c
@@ -2,8 +2,8 @@
2 * drivers/mtd/nandids.c 2 * drivers/mtd/nandids.c
3 * 3 *
4 * Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de) 4 * Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de)
5 * 5 *
6 * $Id: nand_ids.c,v 1.10 2004/05/26 13:40:12 gleixner Exp $ 6 * $Id: nand_ids.c,v 1.14 2005/06/23 09:38:50 gleixner Exp $
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
@@ -56,17 +56,24 @@ struct nand_flash_dev nand_flash_ids[] = {
56 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 56 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16},
57 57
58 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0}, 58 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0},
59 {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0},
59 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0}, 60 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0},
60 {"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 61 {"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16},
62 {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16},
61 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 63 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16},
64 {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16},
62 65
63 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0}, 66 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0},
64 67
65 {"NAND 512MiB 3,3V 8-bit", 0xDC, 512, 512, 0x4000, 0},
66
67 /* These are the new chips with large page size. The pagesize 68 /* These are the new chips with large page size. The pagesize
68 * and the erasesize is determined from the extended id bytes 69 * and the erasesize is determined from the extended id bytes
69 */ 70 */
71 /*512 Megabit */
72 {"NAND 64MiB 1,8V 8-bit", 0xA2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
73 {"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
74 {"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
75 {"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
76
70 /* 1 Gigabit */ 77 /* 1 Gigabit */
71 {"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 78 {"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
72 {"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 79 {"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
@@ -103,7 +110,7 @@ struct nand_flash_dev nand_flash_ids[] = {
103 * Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go 110 * Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go
104 * There are more speed improvements for reads and writes possible, but not implemented now 111 * There are more speed improvements for reads and writes possible, but not implemented now
105 */ 112 */
106 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY}, 113 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY | BBT_AUTO_REFRESH},
107 114
108 {NULL,} 115 {NULL,}
109}; 116};
@@ -118,6 +125,7 @@ struct nand_manufacturers nand_manuf_ids[] = {
118 {NAND_MFR_NATIONAL, "National"}, 125 {NAND_MFR_NATIONAL, "National"},
119 {NAND_MFR_RENESAS, "Renesas"}, 126 {NAND_MFR_RENESAS, "Renesas"},
120 {NAND_MFR_STMICRO, "ST Micro"}, 127 {NAND_MFR_STMICRO, "ST Micro"},
128 {NAND_MFR_HYNIX, "Hynix"},
121 {0x0, "Unknown"} 129 {0x0, "Unknown"}
122}; 130};
123 131
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 13feefd7d8ca..754b6ed7ce14 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -22,7 +22,7 @@
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
24 * 24 *
25 * $Id: nandsim.c,v 1.7 2004/12/06 11:53:06 dedekind Exp $ 25 * $Id: nandsim.c,v 1.8 2005/03/19 15:33:56 dedekind Exp $
26 */ 26 */
27 27
28#include <linux/config.h> 28#include <linux/config.h>
@@ -1484,33 +1484,6 @@ ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1484} 1484}
1485 1485
1486/* 1486/*
1487 * Having only NAND chip IDs we call nand_scan which detects NAND flash
1488 * parameters and then calls scan_bbt in order to scan/find/build the
1489 * NAND flash bad block table. But since at that moment the NAND flash
1490 * image isn't allocated in the simulator, errors arise. To avoid this
1491 * we redefine the scan_bbt callback and initialize the nandsim structure
1492 * before the flash media scanning.
1493 */
1494int ns_scan_bbt(struct mtd_info *mtd)
1495{
1496 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
1497 struct nandsim *ns = (struct nandsim *)(chip->priv);
1498 int retval;
1499
1500 if (!NS_IS_INITIALIZED(ns))
1501 if ((retval = init_nandsim(mtd)) != 0) {
1502 NS_ERR("scan_bbt: can't initialize the nandsim structure\n");
1503 return retval;
1504 }
1505 if ((retval = nand_default_bbt(mtd)) != 0) {
1506 free_nandsim(ns);
1507 return retval;
1508 }
1509
1510 return 0;
1511}
1512
1513/*
1514 * Module initialization function 1487 * Module initialization function
1515 */ 1488 */
1516int __init ns_init_module(void) 1489int __init ns_init_module(void)
@@ -1544,7 +1517,6 @@ int __init ns_init_module(void)
1544 chip->hwcontrol = ns_hwcontrol; 1517 chip->hwcontrol = ns_hwcontrol;
1545 chip->read_byte = ns_nand_read_byte; 1518 chip->read_byte = ns_nand_read_byte;
1546 chip->dev_ready = ns_device_ready; 1519 chip->dev_ready = ns_device_ready;
1547 chip->scan_bbt = ns_scan_bbt;
1548 chip->write_byte = ns_nand_write_byte; 1520 chip->write_byte = ns_nand_write_byte;
1549 chip->write_buf = ns_nand_write_buf; 1521 chip->write_buf = ns_nand_write_buf;
1550 chip->read_buf = ns_nand_read_buf; 1522 chip->read_buf = ns_nand_read_buf;
@@ -1552,6 +1524,7 @@ int __init ns_init_module(void)
1552 chip->write_word = ns_nand_write_word; 1524 chip->write_word = ns_nand_write_word;
1553 chip->read_word = ns_nand_read_word; 1525 chip->read_word = ns_nand_read_word;
1554 chip->eccmode = NAND_ECC_SOFT; 1526 chip->eccmode = NAND_ECC_SOFT;
1527 chip->options |= NAND_SKIP_BBTSCAN;
1555 1528
1556 /* 1529 /*
1557 * Perform minimum nandsim structure initialization to handle 1530 * Perform minimum nandsim structure initialization to handle
@@ -1580,6 +1553,16 @@ int __init ns_init_module(void)
1580 goto error; 1553 goto error;
1581 } 1554 }
1582 1555
1556 if ((retval = init_nandsim(nsmtd)) != 0) {
1557 NS_ERR("scan_bbt: can't initialize the nandsim structure\n");
1558 goto error;
1559 }
1560
1561 if ((retval = nand_default_bbt(nsmtd)) != 0) {
1562 free_nandsim(nand);
1563 goto error;
1564 }
1565
1583 /* Register NAND as one big partition */ 1566 /* Register NAND as one big partition */
1584 add_mtd_partitions(nsmtd, &nand->part, 1); 1567 add_mtd_partitions(nsmtd, &nand->part, 1);
1585 1568
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 02305a2adca7..031051cbde76 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -6,7 +6,7 @@
6 * Derived from drivers/mtd/nand/spia.c 6 * Derived from drivers/mtd/nand/spia.c
7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
8 * 8 *
9 * $Id: rtc_from4.c,v 1.7 2004/11/04 12:53:10 gleixner Exp $ 9 * $Id: rtc_from4.c,v 1.9 2005/01/24 20:40:11 dmarlin Exp $
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -83,13 +83,18 @@ static struct mtd_info *rtc_from4_mtd = NULL;
83#define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070) 83#define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070)
84#define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7) 84#define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7)
85 85
86#define ERR_STAT_ECC_AVAILABLE 0x20
87
86/* Undefine for software ECC */ 88/* Undefine for software ECC */
87#define RTC_FROM4_HWECC 1 89#define RTC_FROM4_HWECC 1
88 90
91/* Define as 1 for no virtual erase blocks (in JFFS2) */
92#define RTC_FROM4_NO_VIRTBLOCKS 0
93
89/* 94/*
90 * Module stuff 95 * Module stuff
91 */ 96 */
92static void __iomem *rtc_from4_fio_base = P2SEGADDR(RTC_FROM4_FIO_BASE); 97static void __iomem *rtc_from4_fio_base = (void *)P2SEGADDR(RTC_FROM4_FIO_BASE);
93 98
94const static struct mtd_partition partition_info[] = { 99const static struct mtd_partition partition_info[] = {
95 { 100 {
@@ -267,7 +272,6 @@ static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip)
267} 272}
268 273
269 274
270
271/* 275/*
272 * rtc_from4_nand_device_ready - hardware specific ready/busy check 276 * rtc_from4_nand_device_ready - hardware specific ready/busy check
273 * @mtd: MTD device structure 277 * @mtd: MTD device structure
@@ -286,6 +290,40 @@ static int rtc_from4_nand_device_ready(struct mtd_info *mtd)
286 290
287} 291}
288 292
293
294/*
295 * deplete - code to perform device recovery in case there was a power loss
296 * @mtd: MTD device structure
297 * @chip: Chip to select (0 == slot 3, 1 == slot 4)
298 *
299 * If there was a sudden loss of power during an erase operation, a
300 * "device recovery" operation must be performed when power is restored
301 * to ensure correct operation. This routine performs the required steps
302 * for the requested chip.
303 *
304 * See page 86 of the data sheet for details.
305 *
306 */
307static void deplete(struct mtd_info *mtd, int chip)
308{
309 struct nand_chip *this = mtd->priv;
310
311 /* wait until device is ready */
312 while (!this->dev_ready(mtd));
313
314 this->select_chip(mtd, chip);
315
316 /* Send the commands for device recovery, phase 1 */
317 this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000);
318 this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1);
319
320 /* Send the commands for device recovery, phase 2 */
321 this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0004);
322 this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1);
323
324}
325
326
289#ifdef RTC_FROM4_HWECC 327#ifdef RTC_FROM4_HWECC
290/* 328/*
291 * rtc_from4_enable_hwecc - hardware specific hardware ECC enable function 329 * rtc_from4_enable_hwecc - hardware specific hardware ECC enable function
@@ -329,6 +367,7 @@ static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
329 367
330} 368}
331 369
370
332/* 371/*
333 * rtc_from4_calculate_ecc - hardware specific code to read ECC code 372 * rtc_from4_calculate_ecc - hardware specific code to read ECC code
334 * @mtd: MTD device structure 373 * @mtd: MTD device structure
@@ -356,6 +395,7 @@ static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_c
356 ecc_code[7] |= 0x0f; /* set the last four bits (not used) */ 395 ecc_code[7] |= 0x0f; /* set the last four bits (not used) */
357} 396}
358 397
398
359/* 399/*
360 * rtc_from4_correct_data - hardware specific code to correct data using ECC code 400 * rtc_from4_correct_data - hardware specific code to correct data using ECC code
361 * @mtd: MTD device structure 401 * @mtd: MTD device structure
@@ -365,16 +405,14 @@ static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_c
365 * 405 *
366 * The FPGA tells us fast, if there's an error or not. If no, we go back happy 406 * The FPGA tells us fast, if there's an error or not. If no, we go back happy
367 * else we read the ecc results from the fpga and call the rs library to decode 407 * else we read the ecc results from the fpga and call the rs library to decode
368 * and hopefully correct the error 408 * and hopefully correct the error.
369 * 409 *
370 * For now I use the code, which we read from the FLASH to use the RS lib,
371 * as the syndrom conversion has a unresolved issue.
372 */ 410 */
373static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2) 411static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2)
374{ 412{
375 int i, j, res; 413 int i, j, res;
376 unsigned short status; 414 unsigned short status;
377 uint16_t par[6], syn[6], tmp; 415 uint16_t par[6], syn[6];
378 uint8_t ecc[8]; 416 uint8_t ecc[8];
379 volatile unsigned short *rs_ecc; 417 volatile unsigned short *rs_ecc;
380 418
@@ -416,15 +454,86 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
416 } 454 }
417 455
418 /* Let the library code do its magic.*/ 456 /* Let the library code do its magic.*/
419 res = decode_rs8(rs_decoder, buf, par, 512, syn, 0, NULL, 0xff, NULL); 457 res = decode_rs8(rs_decoder, (uint8_t *)buf, par, 512, syn, 0, NULL, 0xff, NULL);
420 if (res > 0) { 458 if (res > 0) {
421 DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " 459 DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: "
422 "ECC corrected %d errors on read\n", res); 460 "ECC corrected %d errors on read\n", res);
423 } 461 }
424 return res; 462 return res;
425} 463}
464
465
466/**
467 * rtc_from4_errstat - perform additional error status checks
468 * @mtd: MTD device structure
469 * @this: NAND chip structure
470 * @state: state or the operation
471 * @status: status code returned from read status
472 * @page: startpage inside the chip, must be called with (page & this->pagemask)
473 *
474 * Perform additional error status checks on erase and write failures
475 * to determine if errors are correctable. For this device, correctable
476 * 1-bit errors on erase and write are considered acceptable.
477 *
478 * note: see pages 34..37 of data sheet for details.
479 *
480 */
481static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page)
482{
483 int er_stat=0;
484 int rtn, retlen;
485 size_t len;
486 uint8_t *buf;
487 int i;
488
489 this->cmdfunc (mtd, NAND_CMD_STATUS_CLEAR, -1, -1);
490
491 if (state == FL_ERASING) {
492 for (i=0; i<4; i++) {
493 if (status & 1<<(i+1)) {
494 this->cmdfunc (mtd, (NAND_CMD_STATUS_ERROR + i + 1), -1, -1);
495 rtn = this->read_byte(mtd);
496 this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1);
497 if (!(rtn & ERR_STAT_ECC_AVAILABLE)) {
498 er_stat |= 1<<(i+1); /* err_ecc_not_avail */
499 }
500 }
501 }
502 } else if (state == FL_WRITING) {
503 /* single bank write logic */
504 this->cmdfunc (mtd, NAND_CMD_STATUS_ERROR, -1, -1);
505 rtn = this->read_byte(mtd);
506 this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1);
507 if (!(rtn & ERR_STAT_ECC_AVAILABLE)) {
508 er_stat |= 1<<1; /* err_ecc_not_avail */
509 } else {
510 len = mtd->oobblock;
511 buf = kmalloc (len, GFP_KERNEL);
512 if (!buf) {
513 printk (KERN_ERR "rtc_from4_errstat: Out of memory!\n");
514 er_stat = 1; /* if we can't check, assume failed */
515 } else {
516 /* recovery read */
517 /* page read */
518 rtn = nand_do_read_ecc (mtd, page, len, &retlen, buf, NULL, this->autooob, 1);
519 if (rtn) { /* if read failed or > 1-bit error corrected */
520 er_stat |= 1<<1; /* ECC read failed */
521 }
522 kfree(buf);
523 }
524 }
525 }
526
527 rtn = status;
528 if (er_stat == 0) { /* if ECC is available */
529 rtn = (status & ~NAND_STATUS_FAIL); /* clear the error bit */
530 }
531
532 return rtn;
533}
426#endif 534#endif
427 535
536
428/* 537/*
429 * Main initialization routine 538 * Main initialization routine
430 */ 539 */
@@ -432,6 +541,7 @@ int __init rtc_from4_init (void)
432{ 541{
433 struct nand_chip *this; 542 struct nand_chip *this;
434 unsigned short bcr1, bcr2, wcr2; 543 unsigned short bcr1, bcr2, wcr2;
544 int i;
435 545
436 /* Allocate memory for MTD device structure and private data */ 546 /* Allocate memory for MTD device structure and private data */
437 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip), 547 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip),
@@ -483,6 +593,8 @@ int __init rtc_from4_init (void)
483 593
484 this->eccmode = NAND_ECC_HW8_512; 594 this->eccmode = NAND_ECC_HW8_512;
485 this->options |= NAND_HWECC_SYNDROME; 595 this->options |= NAND_HWECC_SYNDROME;
596 /* return the status of extra status and ECC checks */
597 this->errstat = rtc_from4_errstat;
486 /* set the nand_oobinfo to support FPGA H/W error detection */ 598 /* set the nand_oobinfo to support FPGA H/W error detection */
487 this->autooob = &rtc_from4_nand_oobinfo; 599 this->autooob = &rtc_from4_nand_oobinfo;
488 this->enable_hwecc = rtc_from4_enable_hwecc; 600 this->enable_hwecc = rtc_from4_enable_hwecc;
@@ -504,6 +616,18 @@ int __init rtc_from4_init (void)
504 return -ENXIO; 616 return -ENXIO;
505 } 617 }
506 618
619 /* Perform 'device recovery' for each chip in case there was a power loss. */
620 for (i=0; i < this->numchips; i++) {
621 deplete(rtc_from4_mtd, i);
622 }
623
624#if RTC_FROM4_NO_VIRTBLOCKS
625 /* use a smaller erase block to minimize wasted space when a block is bad */
626 /* note: this uses eight times as much RAM as using the default and makes */
627 /* mounts take four times as long. */
628 rtc_from4_mtd->flags |= MTD_NO_VIRTBLOCKS;
629#endif
630
507 /* Register the partitions */ 631 /* Register the partitions */
508 add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS); 632 add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
509 633
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index d05e9b97947d..891e3a1b9110 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -1,17 +1,24 @@
1/* linux/drivers/mtd/nand/s3c2410.c 1/* linux/drivers/mtd/nand/s3c2410.c
2 * 2 *
3 * Copyright (c) 2004 Simtec Electronics 3 * Copyright (c) 2004,2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk>
5 * 6 *
6 * Samsung S3C2410 NAND driver 7 * Samsung S3C2410/S3C240 NAND driver
7 * 8 *
8 * Changelog: 9 * Changelog:
9 * 21-Sep-2004 BJD Initial version 10 * 21-Sep-2004 BJD Initial version
10 * 23-Sep-2004 BJD Mulitple device support 11 * 23-Sep-2004 BJD Mulitple device support
11 * 28-Sep-2004 BJD Fixed ECC placement for Hardware mode 12 * 28-Sep-2004 BJD Fixed ECC placement for Hardware mode
12 * 12-Oct-2004 BJD Fixed errors in use of platform data 13 * 12-Oct-2004 BJD Fixed errors in use of platform data
14 * 18-Feb-2005 BJD Fix sparse errors
15 * 14-Mar-2005 BJD Applied tglx's code reduction patch
16 * 02-May-2005 BJD Fixed s3c2440 support
17 * 02-May-2005 BJD Reduced hwcontrol decode
18 * 20-Jun-2005 BJD Updated s3c2440 support, fixed timing bug
19 * 08-Jul-2005 BJD Fix OOPS when no platform data supplied
13 * 20 *
14 * $Id: s3c2410.c,v 1.7 2005/01/05 18:05:14 dwmw2 Exp $ 21 * $Id: s3c2410.c,v 1.14 2005/07/06 20:05:06 bjd Exp $
15 * 22 *
16 * This program is free software; you can redistribute it and/or modify 23 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by 24 * it under the terms of the GNU General Public License as published by
@@ -69,10 +76,10 @@ static int hardware_ecc = 0;
69 */ 76 */
70 77
71static struct nand_oobinfo nand_hw_eccoob = { 78static struct nand_oobinfo nand_hw_eccoob = {
72 .useecc = MTD_NANDECC_AUTOPLACE, 79 .useecc = MTD_NANDECC_AUTOPLACE,
73 .eccbytes = 3, 80 .eccbytes = 3,
74 .eccpos = {0, 1, 2 }, 81 .eccpos = {0, 1, 2 },
75 .oobfree = { {8, 8} } 82 .oobfree = { {8, 8} }
76}; 83};
77 84
78/* controller and mtd information */ 85/* controller and mtd information */
@@ -99,8 +106,10 @@ struct s3c2410_nand_info {
99 struct device *device; 106 struct device *device;
100 struct resource *area; 107 struct resource *area;
101 struct clk *clk; 108 struct clk *clk;
102 void *regs; 109 void __iomem *regs;
103 int mtd_count; 110 int mtd_count;
111
112 unsigned char is_s3c2440;
104}; 113};
105 114
106/* conversion functions */ 115/* conversion functions */
@@ -165,12 +174,12 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
165 /* calculate the timing information for the controller */ 174 /* calculate the timing information for the controller */
166 175
167 if (plat != NULL) { 176 if (plat != NULL) {
168 tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 8); 177 tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 4);
169 twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8); 178 twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8);
170 twrph1 = s3c2410_nand_calc_rate(plat->twrph1, clkrate, 8); 179 twrph1 = s3c2410_nand_calc_rate(plat->twrph1, clkrate, 8);
171 } else { 180 } else {
172 /* default timings */ 181 /* default timings */
173 tacls = 8; 182 tacls = 4;
174 twrph0 = 8; 183 twrph0 = 8;
175 twrph1 = 8; 184 twrph1 = 8;
176 } 185 }
@@ -185,10 +194,16 @@ static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
185 to_ns(twrph0, clkrate), 194 to_ns(twrph0, clkrate),
186 to_ns(twrph1, clkrate)); 195 to_ns(twrph1, clkrate));
187 196
188 cfg = S3C2410_NFCONF_EN; 197 if (!info->is_s3c2440) {
189 cfg |= S3C2410_NFCONF_TACLS(tacls-1); 198 cfg = S3C2410_NFCONF_EN;
190 cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1); 199 cfg |= S3C2410_NFCONF_TACLS(tacls-1);
191 cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1); 200 cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1);
201 cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1);
202 } else {
203 cfg = S3C2440_NFCONF_TACLS(tacls-1);
204 cfg |= S3C2440_NFCONF_TWRPH0(twrph0-1);
205 cfg |= S3C2440_NFCONF_TWRPH1(twrph1-1);
206 }
192 207
193 pr_debug(PFX "NF_CONF is 0x%lx\n", cfg); 208 pr_debug(PFX "NF_CONF is 0x%lx\n", cfg);
194 209
@@ -203,17 +218,22 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
203 struct s3c2410_nand_info *info; 218 struct s3c2410_nand_info *info;
204 struct s3c2410_nand_mtd *nmtd; 219 struct s3c2410_nand_mtd *nmtd;
205 struct nand_chip *this = mtd->priv; 220 struct nand_chip *this = mtd->priv;
221 void __iomem *reg;
206 unsigned long cur; 222 unsigned long cur;
223 unsigned long bit;
207 224
208 nmtd = this->priv; 225 nmtd = this->priv;
209 info = nmtd->info; 226 info = nmtd->info;
210 227
211 cur = readl(info->regs + S3C2410_NFCONF); 228 bit = (info->is_s3c2440) ? S3C2440_NFCONT_nFCE : S3C2410_NFCONF_nFCE;
229 reg = info->regs+((info->is_s3c2440) ? S3C2440_NFCONT:S3C2410_NFCONF);
230
231 cur = readl(reg);
212 232
213 if (chip == -1) { 233 if (chip == -1) {
214 cur |= S3C2410_NFCONF_nFCE; 234 cur |= bit;
215 } else { 235 } else {
216 if (chip > nmtd->set->nr_chips) { 236 if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
217 printk(KERN_ERR PFX "chip %d out of range\n", chip); 237 printk(KERN_ERR PFX "chip %d out of range\n", chip);
218 return; 238 return;
219 } 239 }
@@ -223,143 +243,76 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
223 (info->platform->select_chip)(nmtd->set, chip); 243 (info->platform->select_chip)(nmtd->set, chip);
224 } 244 }
225 245
226 cur &= ~S3C2410_NFCONF_nFCE; 246 cur &= ~bit;
227 } 247 }
228 248
229 writel(cur, info->regs + S3C2410_NFCONF); 249 writel(cur, reg);
230} 250}
231 251
232/* command and control functions */ 252/* command and control functions
253 *
254 * Note, these all use tglx's method of changing the IO_ADDR_W field
255 * to make the code simpler, and use the nand layer's code to issue the
256 * command and address sequences via the proper IO ports.
257 *
258*/
233 259
234static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd) 260static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd)
235{ 261{
236 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 262 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
237 unsigned long cur; 263 struct nand_chip *chip = mtd->priv;
238 264
239 switch (cmd) { 265 switch (cmd) {
240 case NAND_CTL_SETNCE: 266 case NAND_CTL_SETNCE:
241 cur = readl(info->regs + S3C2410_NFCONF);
242 cur &= ~S3C2410_NFCONF_nFCE;
243 writel(cur, info->regs + S3C2410_NFCONF);
244 break;
245
246 case NAND_CTL_CLRNCE: 267 case NAND_CTL_CLRNCE:
247 cur = readl(info->regs + S3C2410_NFCONF); 268 printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__);
248 cur |= S3C2410_NFCONF_nFCE;
249 writel(cur, info->regs + S3C2410_NFCONF);
250 break; 269 break;
251 270
252 /* we don't need to implement these */
253 case NAND_CTL_SETCLE: 271 case NAND_CTL_SETCLE:
254 case NAND_CTL_CLRCLE: 272 chip->IO_ADDR_W = info->regs + S3C2410_NFCMD;
273 break;
274
255 case NAND_CTL_SETALE: 275 case NAND_CTL_SETALE:
256 case NAND_CTL_CLRALE: 276 chip->IO_ADDR_W = info->regs + S3C2410_NFADDR;
257 pr_debug(PFX "s3c2410_nand_hwcontrol(%d) unusedn", cmd); 277 break;
278
279 /* NAND_CTL_CLRCLE: */
280 /* NAND_CTL_CLRALE: */
281 default:
282 chip->IO_ADDR_W = info->regs + S3C2410_NFDATA;
258 break; 283 break;
259 } 284 }
260} 285}
261 286
262/* s3c2410_nand_command 287/* command and control functions */
263 *
264 * This function implements sending commands and the relevant address
265 * information to the chip, via the hardware controller. Since the
266 * S3C2410 generates the correct ALE/CLE signaling automatically, we
267 * do not need to use hwcontrol.
268*/
269 288
270static void s3c2410_nand_command (struct mtd_info *mtd, unsigned command, 289static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd)
271 int column, int page_addr)
272{ 290{
273 register struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 291 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
274 register struct nand_chip *this = mtd->priv; 292 struct nand_chip *chip = mtd->priv;
275 293
276 /* 294 switch (cmd) {
277 * Write out the command to the device. 295 case NAND_CTL_SETNCE:
278 */ 296 case NAND_CTL_CLRNCE:
279 if (command == NAND_CMD_SEQIN) { 297 printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__);
280 int readcmd; 298 break;
281
282 if (column >= mtd->oobblock) {
283 /* OOB area */
284 column -= mtd->oobblock;
285 readcmd = NAND_CMD_READOOB;
286 } else if (column < 256) {
287 /* First 256 bytes --> READ0 */
288 readcmd = NAND_CMD_READ0;
289 } else {
290 column -= 256;
291 readcmd = NAND_CMD_READ1;
292 }
293
294 writeb(readcmd, info->regs + S3C2410_NFCMD);
295 }
296 writeb(command, info->regs + S3C2410_NFCMD);
297 299
298 /* Set ALE and clear CLE to start address cycle */ 300 case NAND_CTL_SETCLE:
301 chip->IO_ADDR_W = info->regs + S3C2440_NFCMD;
302 break;
299 303
300 if (column != -1 || page_addr != -1) { 304 case NAND_CTL_SETALE:
305 chip->IO_ADDR_W = info->regs + S3C2440_NFADDR;
306 break;
301 307
302 /* Serially input address */ 308 /* NAND_CTL_CLRCLE: */
303 if (column != -1) { 309 /* NAND_CTL_CLRALE: */
304 /* Adjust columns for 16 bit buswidth */
305 if (this->options & NAND_BUSWIDTH_16)
306 column >>= 1;
307 writeb(column, info->regs + S3C2410_NFADDR);
308 }
309 if (page_addr != -1) {
310 writeb((unsigned char) (page_addr), info->regs + S3C2410_NFADDR);
311 writeb((unsigned char) (page_addr >> 8), info->regs + S3C2410_NFADDR);
312 /* One more address cycle for higher density devices */
313 if (this->chipsize & 0x0c000000)
314 writeb((unsigned char) ((page_addr >> 16) & 0x0f),
315 info->regs + S3C2410_NFADDR);
316 }
317 /* Latch in address */
318 }
319
320 /*
321 * program and erase have their own busy handlers
322 * status and sequential in needs no delay
323 */
324 switch (command) {
325
326 case NAND_CMD_PAGEPROG:
327 case NAND_CMD_ERASE1:
328 case NAND_CMD_ERASE2:
329 case NAND_CMD_SEQIN:
330 case NAND_CMD_STATUS:
331 return;
332
333 case NAND_CMD_RESET:
334 if (this->dev_ready)
335 break;
336
337 udelay(this->chip_delay);
338 writeb(NAND_CMD_STATUS, info->regs + S3C2410_NFCMD);
339
340 while ( !(this->read_byte(mtd) & 0x40));
341 return;
342
343 /* This applies to read commands */
344 default: 310 default:
345 /* 311 chip->IO_ADDR_W = info->regs + S3C2440_NFDATA;
346 * If we don't have access to the busy pin, we apply the given 312 break;
347 * command delay
348 */
349 if (!this->dev_ready) {
350 udelay (this->chip_delay);
351 return;
352 }
353 } 313 }
354
355 /* Apply this short delay always to ensure that we do wait tWB in
356 * any case on any machine. */
357 ndelay (100);
358 /* wait until command is processed */
359 while (!this->dev_ready(mtd));
360} 314}
361 315
362
363/* s3c2410_nand_devready() 316/* s3c2410_nand_devready()
364 * 317 *
365 * returns 0 if the nand is busy, 1 if it is ready 318 * returns 0 if the nand is busy, 1 if it is ready
@@ -369,9 +322,12 @@ static int s3c2410_nand_devready(struct mtd_info *mtd)
369{ 322{
370 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 323 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
371 324
325 if (info->is_s3c2440)
326 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
372 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY; 327 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
373} 328}
374 329
330
375/* ECC handling functions */ 331/* ECC handling functions */
376 332
377static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, 333static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
@@ -394,6 +350,12 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
394 return -1; 350 return -1;
395} 351}
396 352
353/* ECC functions
354 *
355 * These allow the s3c2410 and s3c2440 to use the controller's ECC
356 * generator block to ECC the data as it passes through]
357*/
358
397static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode) 359static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
398{ 360{
399 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 361 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
@@ -404,6 +366,15 @@ static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
404 writel(ctrl, info->regs + S3C2410_NFCONF); 366 writel(ctrl, info->regs + S3C2410_NFCONF);
405} 367}
406 368
369static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
370{
371 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
372 unsigned long ctrl;
373
374 ctrl = readl(info->regs + S3C2440_NFCONT);
375 writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
376}
377
407static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, 378static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd,
408 const u_char *dat, u_char *ecc_code) 379 const u_char *dat, u_char *ecc_code)
409{ 380{
@@ -420,7 +391,26 @@ static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd,
420} 391}
421 392
422 393
423/* over-ride the standard functions for a little more speed? */ 394static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd,
395 const u_char *dat, u_char *ecc_code)
396{
397 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
398 unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
399
400 ecc_code[0] = ecc;
401 ecc_code[1] = ecc >> 8;
402 ecc_code[2] = ecc >> 16;
403
404 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n",
405 ecc_code[0], ecc_code[1], ecc_code[2]);
406
407 return 0;
408}
409
410
411/* over-ride the standard functions for a little more speed. We can
412 * use read/write block to move the data buffers to/from the controller
413*/
424 414
425static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 415static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
426{ 416{
@@ -523,11 +513,10 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
523{ 513{
524 struct nand_chip *chip = &nmtd->chip; 514 struct nand_chip *chip = &nmtd->chip;
525 515
526 chip->IO_ADDR_R = (char *)info->regs + S3C2410_NFDATA; 516 chip->IO_ADDR_R = info->regs + S3C2410_NFDATA;
527 chip->IO_ADDR_W = (char *)info->regs + S3C2410_NFDATA; 517 chip->IO_ADDR_W = info->regs + S3C2410_NFDATA;
528 chip->hwcontrol = s3c2410_nand_hwcontrol; 518 chip->hwcontrol = s3c2410_nand_hwcontrol;
529 chip->dev_ready = s3c2410_nand_devready; 519 chip->dev_ready = s3c2410_nand_devready;
530 chip->cmdfunc = s3c2410_nand_command;
531 chip->write_buf = s3c2410_nand_write_buf; 520 chip->write_buf = s3c2410_nand_write_buf;
532 chip->read_buf = s3c2410_nand_read_buf; 521 chip->read_buf = s3c2410_nand_read_buf;
533 chip->select_chip = s3c2410_nand_select_chip; 522 chip->select_chip = s3c2410_nand_select_chip;
@@ -536,6 +525,12 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
536 chip->options = 0; 525 chip->options = 0;
537 chip->controller = &info->controller; 526 chip->controller = &info->controller;
538 527
528 if (info->is_s3c2440) {
529 chip->IO_ADDR_R = info->regs + S3C2440_NFDATA;
530 chip->IO_ADDR_W = info->regs + S3C2440_NFDATA;
531 chip->hwcontrol = s3c2440_nand_hwcontrol;
532 }
533
539 nmtd->info = info; 534 nmtd->info = info;
540 nmtd->mtd.priv = chip; 535 nmtd->mtd.priv = chip;
541 nmtd->set = set; 536 nmtd->set = set;
@@ -546,6 +541,11 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
546 chip->calculate_ecc = s3c2410_nand_calculate_ecc; 541 chip->calculate_ecc = s3c2410_nand_calculate_ecc;
547 chip->eccmode = NAND_ECC_HW3_512; 542 chip->eccmode = NAND_ECC_HW3_512;
548 chip->autooob = &nand_hw_eccoob; 543 chip->autooob = &nand_hw_eccoob;
544
545 if (info->is_s3c2440) {
546 chip->enable_hwecc = s3c2440_nand_enable_hwecc;
547 chip->calculate_ecc = s3c2440_nand_calculate_ecc;
548 }
549 } else { 549 } else {
550 chip->eccmode = NAND_ECC_SOFT; 550 chip->eccmode = NAND_ECC_SOFT;
551 } 551 }
@@ -559,7 +559,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
559 * nand layer to look for devices 559 * nand layer to look for devices
560*/ 560*/
561 561
562static int s3c2410_nand_probe(struct device *dev) 562static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440)
563{ 563{
564 struct platform_device *pdev = to_platform_device(dev); 564 struct platform_device *pdev = to_platform_device(dev);
565 struct s3c2410_platform_nand *plat = to_nand_plat(dev); 565 struct s3c2410_platform_nand *plat = to_nand_plat(dev);
@@ -585,6 +585,7 @@ static int s3c2410_nand_probe(struct device *dev)
585 dev_set_drvdata(dev, info); 585 dev_set_drvdata(dev, info);
586 586
587 spin_lock_init(&info->controller.lock); 587 spin_lock_init(&info->controller.lock);
588 init_waitqueue_head(&info->controller.wq);
588 589
589 /* get the clock source and enable it */ 590 /* get the clock source and enable it */
590 591
@@ -600,7 +601,8 @@ static int s3c2410_nand_probe(struct device *dev)
600 601
601 /* allocate and map the resource */ 602 /* allocate and map the resource */
602 603
603 res = pdev->resource; /* assume that the flash has one resource */ 604 /* currently we assume we have the one resource */
605 res = pdev->resource;
604 size = res->end - res->start + 1; 606 size = res->end - res->start + 1;
605 607
606 info->area = request_mem_region(res->start, size, pdev->name); 608 info->area = request_mem_region(res->start, size, pdev->name);
@@ -611,9 +613,10 @@ static int s3c2410_nand_probe(struct device *dev)
611 goto exit_error; 613 goto exit_error;
612 } 614 }
613 615
614 info->device = dev; 616 info->device = dev;
615 info->platform = plat; 617 info->platform = plat;
616 info->regs = ioremap(res->start, size); 618 info->regs = ioremap(res->start, size);
619 info->is_s3c2440 = is_s3c2440;
617 620
618 if (info->regs == NULL) { 621 if (info->regs == NULL) {
619 printk(KERN_ERR PFX "cannot reserve register region\n"); 622 printk(KERN_ERR PFX "cannot reserve register region\n");
@@ -678,6 +681,18 @@ static int s3c2410_nand_probe(struct device *dev)
678 return err; 681 return err;
679} 682}
680 683
684/* driver device registration */
685
686static int s3c2410_nand_probe(struct device *dev)
687{
688 return s3c24xx_nand_probe(dev, 0);
689}
690
691static int s3c2440_nand_probe(struct device *dev)
692{
693 return s3c24xx_nand_probe(dev, 1);
694}
695
681static struct device_driver s3c2410_nand_driver = { 696static struct device_driver s3c2410_nand_driver = {
682 .name = "s3c2410-nand", 697 .name = "s3c2410-nand",
683 .bus = &platform_bus_type, 698 .bus = &platform_bus_type,
@@ -685,14 +700,24 @@ static struct device_driver s3c2410_nand_driver = {
685 .remove = s3c2410_nand_remove, 700 .remove = s3c2410_nand_remove,
686}; 701};
687 702
703static struct device_driver s3c2440_nand_driver = {
704 .name = "s3c2440-nand",
705 .bus = &platform_bus_type,
706 .probe = s3c2440_nand_probe,
707 .remove = s3c2410_nand_remove,
708};
709
688static int __init s3c2410_nand_init(void) 710static int __init s3c2410_nand_init(void)
689{ 711{
690 printk("S3C2410 NAND Driver, (c) 2004 Simtec Electronics\n"); 712 printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
713
714 driver_register(&s3c2440_nand_driver);
691 return driver_register(&s3c2410_nand_driver); 715 return driver_register(&s3c2410_nand_driver);
692} 716}
693 717
694static void __exit s3c2410_nand_exit(void) 718static void __exit s3c2410_nand_exit(void)
695{ 719{
720 driver_unregister(&s3c2440_nand_driver);
696 driver_unregister(&s3c2410_nand_driver); 721 driver_unregister(&s3c2410_nand_driver);
697} 722}
698 723
@@ -701,4 +726,4 @@ module_exit(s3c2410_nand_exit);
701 726
702MODULE_LICENSE("GPL"); 727MODULE_LICENSE("GPL");
703MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 728MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
704MODULE_DESCRIPTION("S3C2410 MTD NAND driver"); 729MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 29572793334c..9853b87bb756 100755..100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2004 Richard Purdie 4 * Copyright (C) 2004 Richard Purdie
5 * 5 *
6 * $Id: sharpsl.c,v 1.3 2005/01/03 14:53:50 rpurdie Exp $ 6 * $Id: sharpsl.c,v 1.4 2005/01/23 11:09:19 rpurdie Exp $
7 * 7 *
8 * Based on Sharp's NAND driver sharp_sl.c 8 * Based on Sharp's NAND driver sharp_sl.c
9 * 9 *
@@ -216,7 +216,7 @@ sharpsl_nand_init(void)
216 nr_partitions = DEFAULT_NUM_PARTITIONS; 216 nr_partitions = DEFAULT_NUM_PARTITIONS;
217 sharpsl_partition_info = sharpsl_nand_default_partition_info; 217 sharpsl_partition_info = sharpsl_nand_default_partition_info;
218 if (machine_is_poodle()) { 218 if (machine_is_poodle()) {
219 sharpsl_partition_info[1].size=22 * 1024 * 1024; 219 sharpsl_partition_info[1].size=30 * 1024 * 1024;
220 } else if (machine_is_corgi() || machine_is_shepherd()) { 220 } else if (machine_is_corgi() || machine_is_shepherd()) {
221 sharpsl_partition_info[1].size=25 * 1024 * 1024; 221 sharpsl_partition_info[1].size=25 * 1024 * 1024;
222 } else if (machine_is_husky()) { 222 } else if (machine_is_husky()) {
diff --git a/drivers/mtd/nand/tx4925ndfmc.c b/drivers/mtd/nand/tx4925ndfmc.c
deleted file mode 100644
index bba688830c9b..000000000000
--- a/drivers/mtd/nand/tx4925ndfmc.c
+++ /dev/null
@@ -1,416 +0,0 @@
1/*
2 * drivers/mtd/tx4925ndfmc.c
3 *
4 * Overview:
5 * This is a device driver for the NAND flash device found on the
6 * Toshiba RBTX4925 reference board, which is a SmartMediaCard. It supports
7 * 16MiB, 32MiB and 64MiB cards.
8 *
9 * Author: MontaVista Software, Inc. source@mvista.com
10 *
11 * Derived from drivers/mtd/autcpu12.c
12 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
13 *
14 * $Id: tx4925ndfmc.c,v 1.5 2004/10/05 13:50:20 gleixner Exp $
15 *
16 * Copyright (C) 2001 Toshiba Corporation
17 *
18 * 2003 (c) MontaVista Software, Inc. This file is licensed under
19 * the terms of the GNU General Public License version 2. This program
20 * is licensed "as is" without any warranty of any kind, whether express
21 * or implied.
22 *
23 */
24
25#include <linux/slab.h>
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/mtd/mtd.h>
29#include <linux/mtd/nand.h>
30#include <linux/mtd/partitions.h>
31#include <linux/delay.h>
32#include <asm/io.h>
33#include <asm/tx4925/tx4925_nand.h>
34
35extern struct nand_oobinfo jffs2_oobinfo;
36
37/*
38 * MTD structure for RBTX4925 board
39 */
40static struct mtd_info *tx4925ndfmc_mtd = NULL;
41
42/*
43 * Define partitions for flash devices
44 */
45
46static struct mtd_partition partition_info16k[] = {
47 { .name = "RBTX4925 flash partition 1",
48 .offset = 0,
49 .size = 8 * 0x00100000 },
50 { .name = "RBTX4925 flash partition 2",
51 .offset = 8 * 0x00100000,
52 .size = 8 * 0x00100000 },
53};
54
55static struct mtd_partition partition_info32k[] = {
56 { .name = "RBTX4925 flash partition 1",
57 .offset = 0,
58 .size = 8 * 0x00100000 },
59 { .name = "RBTX4925 flash partition 2",
60 .offset = 8 * 0x00100000,
61 .size = 24 * 0x00100000 },
62};
63
64static struct mtd_partition partition_info64k[] = {
65 { .name = "User FS",
66 .offset = 0,
67 .size = 16 * 0x00100000 },
68 { .name = "RBTX4925 flash partition 2",
69 .offset = 16 * 0x00100000,
70 .size = 48 * 0x00100000},
71};
72
73static struct mtd_partition partition_info128k[] = {
74 { .name = "Skip bad section",
75 .offset = 0,
76 .size = 16 * 0x00100000 },
77 { .name = "User FS",
78 .offset = 16 * 0x00100000,
79 .size = 112 * 0x00100000 },
80};
81#define NUM_PARTITIONS16K 2
82#define NUM_PARTITIONS32K 2
83#define NUM_PARTITIONS64K 2
84#define NUM_PARTITIONS128K 2
85
86/*
87 * hardware specific access to control-lines
88*/
89static void tx4925ndfmc_hwcontrol(struct mtd_info *mtd, int cmd)
90{
91
92 switch(cmd){
93
94 case NAND_CTL_SETCLE:
95 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_CLE;
96 break;
97 case NAND_CTL_CLRCLE:
98 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_CLE;
99 break;
100 case NAND_CTL_SETALE:
101 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ALE;
102 break;
103 case NAND_CTL_CLRALE:
104 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ALE;
105 break;
106 case NAND_CTL_SETNCE:
107 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_CE;
108 break;
109 case NAND_CTL_CLRNCE:
110 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_CE;
111 break;
112 case NAND_CTL_SETWP:
113 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_WE;
114 break;
115 case NAND_CTL_CLRWP:
116 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_WE;
117 break;
118 }
119}
120
121/*
122* read device ready pin
123*/
124static int tx4925ndfmc_device_ready(struct mtd_info *mtd)
125{
126 int ready;
127 ready = (tx4925_ndfmcptr->sr & TX4925_NDSFR_BUSY) ? 0 : 1;
128 return ready;
129}
130void tx4925ndfmc_enable_hwecc(struct mtd_info *mtd, int mode)
131{
132 /* reset first */
133 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_MASK;
134 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK;
135 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_ENAB;
136}
137static void tx4925ndfmc_disable_ecc(void)
138{
139 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK;
140}
141static void tx4925ndfmc_enable_read_ecc(void)
142{
143 tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK;
144 tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_READ;
145}
146void tx4925ndfmc_readecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code){
147 int i;
148 u_char *ecc = ecc_code;
149 tx4925ndfmc_enable_read_ecc();
150 for (i = 0;i < 6;i++,ecc++)
151 *ecc = tx4925_read_nfmc(&(tx4925_ndfmcptr->dtr));
152 tx4925ndfmc_disable_ecc();
153}
154void tx4925ndfmc_device_setup(void)
155{
156
157 *(unsigned char *)0xbb005000 &= ~0x08;
158
159 /* reset NDFMC */
160 tx4925_ndfmcptr->rstr |= TX4925_NDFRSTR_RST;
161 while (tx4925_ndfmcptr->rstr & TX4925_NDFRSTR_RST);
162
163 /* setup BusSeparete, Hold Time, Strobe Pulse Width */
164 tx4925_ndfmcptr->mcr = TX4925_BSPRT ? TX4925_NDFMCR_BSPRT : 0;
165 tx4925_ndfmcptr->spr = TX4925_HOLD << 4 | TX4925_SPW;
166}
167static u_char tx4925ndfmc_nand_read_byte(struct mtd_info *mtd)
168{
169 struct nand_chip *this = mtd->priv;
170 return tx4925_read_nfmc(this->IO_ADDR_R);
171}
172
173static void tx4925ndfmc_nand_write_byte(struct mtd_info *mtd, u_char byte)
174{
175 struct nand_chip *this = mtd->priv;
176 tx4925_write_nfmc(byte, this->IO_ADDR_W);
177}
178
179static void tx4925ndfmc_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
180{
181 int i;
182 struct nand_chip *this = mtd->priv;
183
184 for (i=0; i<len; i++)
185 tx4925_write_nfmc(buf[i], this->IO_ADDR_W);
186}
187
188static void tx4925ndfmc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
189{
190 int i;
191 struct nand_chip *this = mtd->priv;
192
193 for (i=0; i<len; i++)
194 buf[i] = tx4925_read_nfmc(this->IO_ADDR_R);
195}
196
197static int tx4925ndfmc_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
198{
199 int i;
200 struct nand_chip *this = mtd->priv;
201
202 for (i=0; i<len; i++)
203 if (buf[i] != tx4925_read_nfmc(this->IO_ADDR_R))
204 return -EFAULT;
205
206 return 0;
207}
208
209/*
210 * Send command to NAND device
211 */
212static void tx4925ndfmc_nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
213{
214 register struct nand_chip *this = mtd->priv;
215
216 /* Begin command latch cycle */
217 this->hwcontrol(mtd, NAND_CTL_SETCLE);
218 /*
219 * Write out the command to the device.
220 */
221 if (command == NAND_CMD_SEQIN) {
222 int readcmd;
223
224 if (column >= mtd->oobblock) {
225 /* OOB area */
226 column -= mtd->oobblock;
227 readcmd = NAND_CMD_READOOB;
228 } else if (column < 256) {
229 /* First 256 bytes --> READ0 */
230 readcmd = NAND_CMD_READ0;
231 } else {
232 column -= 256;
233 readcmd = NAND_CMD_READ1;
234 }
235 this->write_byte(mtd, readcmd);
236 }
237 this->write_byte(mtd, command);
238
239 /* Set ALE and clear CLE to start address cycle */
240 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
241
242 if (column != -1 || page_addr != -1) {
243 this->hwcontrol(mtd, NAND_CTL_SETALE);
244
245 /* Serially input address */
246 if (column != -1)
247 this->write_byte(mtd, column);
248 if (page_addr != -1) {
249 this->write_byte(mtd, (unsigned char) (page_addr & 0xff));
250 this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff));
251 /* One more address cycle for higher density devices */
252 if (mtd->size & 0x0c000000)
253 this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f));
254 }
255 /* Latch in address */
256 this->hwcontrol(mtd, NAND_CTL_CLRALE);
257 }
258
259 /*
260 * program and erase have their own busy handlers
261 * status and sequential in needs no delay
262 */
263 switch (command) {
264
265 case NAND_CMD_PAGEPROG:
266 /* Turn off WE */
267 this->hwcontrol (mtd, NAND_CTL_CLRWP);
268 return;
269
270 case NAND_CMD_SEQIN:
271 /* Turn on WE */
272 this->hwcontrol (mtd, NAND_CTL_SETWP);
273 return;
274
275 case NAND_CMD_ERASE1:
276 case NAND_CMD_ERASE2:
277 case NAND_CMD_STATUS:
278 return;
279
280 case NAND_CMD_RESET:
281 if (this->dev_ready)
282 break;
283 this->hwcontrol(mtd, NAND_CTL_SETCLE);
284 this->write_byte(mtd, NAND_CMD_STATUS);
285 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
286 while ( !(this->read_byte(mtd) & 0x40));
287 return;
288
289 /* This applies to read commands */
290 default:
291 /*
292 * If we don't have access to the busy pin, we apply the given
293 * command delay
294 */
295 if (!this->dev_ready) {
296 udelay (this->chip_delay);
297 return;
298 }
299 }
300
301 /* wait until command is processed */
302 while (!this->dev_ready(mtd));
303}
304
305#ifdef CONFIG_MTD_CMDLINE_PARTS
306extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partitio
307n **pparts, char *);
308#endif
309
310/*
311 * Main initialization routine
312 */
313extern int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
314int __init tx4925ndfmc_init (void)
315{
316 struct nand_chip *this;
317 int err = 0;
318
319 /* Allocate memory for MTD device structure and private data */
320 tx4925ndfmc_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
321 GFP_KERNEL);
322 if (!tx4925ndfmc_mtd) {
323 printk ("Unable to allocate RBTX4925 NAND MTD device structure.\n");
324 err = -ENOMEM;
325 goto out;
326 }
327
328 tx4925ndfmc_device_setup();
329
330 /* io is indirect via a register so don't need to ioremap address */
331
332 /* Get pointer to private data */
333 this = (struct nand_chip *) (&tx4925ndfmc_mtd[1]);
334
335 /* Initialize structures */
336 memset((char *) tx4925ndfmc_mtd, 0, sizeof(struct mtd_info));
337 memset((char *) this, 0, sizeof(struct nand_chip));
338
339 /* Link the private data with the MTD structure */
340 tx4925ndfmc_mtd->priv = this;
341
342 /* Set address of NAND IO lines */
343 this->IO_ADDR_R = (void __iomem *)&(tx4925_ndfmcptr->dtr);
344 this->IO_ADDR_W = (void __iomem *)&(tx4925_ndfmcptr->dtr);
345 this->hwcontrol = tx4925ndfmc_hwcontrol;
346 this->enable_hwecc = tx4925ndfmc_enable_hwecc;
347 this->calculate_ecc = tx4925ndfmc_readecc;
348 this->correct_data = nand_correct_data;
349 this->eccmode = NAND_ECC_HW6_512;
350 this->dev_ready = tx4925ndfmc_device_ready;
351 /* 20 us command delay time */
352 this->chip_delay = 20;
353 this->read_byte = tx4925ndfmc_nand_read_byte;
354 this->write_byte = tx4925ndfmc_nand_write_byte;
355 this->cmdfunc = tx4925ndfmc_nand_command;
356 this->write_buf = tx4925ndfmc_nand_write_buf;
357 this->read_buf = tx4925ndfmc_nand_read_buf;
358 this->verify_buf = tx4925ndfmc_nand_verify_buf;
359
360 /* Scan to find existance of the device */
361 if (nand_scan (tx4925ndfmc_mtd, 1)) {
362 err = -ENXIO;
363 goto out_ior;
364 }
365
366 /* Register the partitions */
367#ifdef CONFIG_MTD_CMDLINE_PARTS
368 {
369 int mtd_parts_nb = 0;
370 struct mtd_partition *mtd_parts = 0;
371 mtd_parts_nb = parse_cmdline_partitions(tx4925ndfmc_mtd, &mtd_parts, "tx4925ndfmc");
372 if (mtd_parts_nb > 0)
373 add_mtd_partitions(tx4925ndfmc_mtd, mtd_parts, mtd_parts_nb);
374 else
375 add_mtd_device(tx4925ndfmc_mtd);
376 }
377#else /* ifdef CONFIG_MTD_CMDLINE_PARTS */
378 switch(tx4925ndfmc_mtd->size){
379 case 0x01000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info16k, NUM_PARTITIONS16K); break;
380 case 0x02000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info32k, NUM_PARTITIONS32K); break;
381 case 0x04000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info64k, NUM_PARTITIONS64K); break;
382 case 0x08000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info128k, NUM_PARTITIONS128K); break;
383 default: {
384 printk ("Unsupported SmartMedia device\n");
385 err = -ENXIO;
386 goto out_ior;
387 }
388 }
389#endif /* ifdef CONFIG_MTD_CMDLINE_PARTS */
390 goto out;
391
392out_ior:
393out:
394 return err;
395}
396
397module_init(tx4925ndfmc_init);
398
399/*
400 * Clean up routine
401 */
402#ifdef MODULE
403static void __exit tx4925ndfmc_cleanup (void)
404{
405 /* Release resources, unregister device */
406 nand_release (tx4925ndfmc_mtd);
407
408 /* Free the MTD device structure */
409 kfree (tx4925ndfmc_mtd);
410}
411module_exit(tx4925ndfmc_cleanup);
412#endif
413
414MODULE_LICENSE("GPL");
415MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
416MODULE_DESCRIPTION("Glue layer for SmartMediaCard on Toshiba RBTX4925");
diff --git a/drivers/mtd/nand/tx4938ndfmc.c b/drivers/mtd/nand/tx4938ndfmc.c
deleted file mode 100644
index df26e58820b3..000000000000
--- a/drivers/mtd/nand/tx4938ndfmc.c
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 * drivers/mtd/nand/tx4938ndfmc.c
3 *
4 * Overview:
5 * This is a device driver for the NAND flash device connected to
6 * TX4938 internal NAND Memory Controller.
7 * TX4938 NDFMC is almost same as TX4925 NDFMC, but register size are 64 bit.
8 *
9 * Author: source@mvista.com
10 *
11 * Based on spia.c by Steven J. Hill
12 *
13 * $Id: tx4938ndfmc.c,v 1.4 2004/10/05 13:50:20 gleixner Exp $
14 *
15 * Copyright (C) 2000-2001 Toshiba Corporation
16 *
17 * 2003 (c) MontaVista Software, Inc. This file is licensed under the
18 * terms of the GNU General Public License version 2. This program is
19 * licensed "as is" without any warranty of any kind, whether express
20 * or implied.
21 */
22#include <linux/config.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/mtd/mtd.h>
27#include <linux/mtd/nand.h>
28#include <linux/mtd/nand_ecc.h>
29#include <linux/mtd/partitions.h>
30#include <asm/io.h>
31#include <asm/bootinfo.h>
32#include <linux/delay.h>
33#include <asm/tx4938/rbtx4938.h>
34
35extern struct nand_oobinfo jffs2_oobinfo;
36
37/*
38 * MTD structure for TX4938 NDFMC
39 */
40static struct mtd_info *tx4938ndfmc_mtd;
41
42/*
43 * Define partitions for flash device
44 */
45#define flush_wb() (void)tx4938_ndfmcptr->mcr;
46
47#define NUM_PARTITIONS 3
48#define NUMBER_OF_CIS_BLOCKS 24
49#define SIZE_OF_BLOCK 0x00004000
50#define NUMBER_OF_BLOCK_PER_ZONE 1024
51#define SIZE_OF_ZONE (NUMBER_OF_BLOCK_PER_ZONE * SIZE_OF_BLOCK)
52#ifndef CONFIG_MTD_CMDLINE_PARTS
53/*
54 * You can use the following sample of MTD partitions
55 * on the NAND Flash Memory 32MB or more.
56 *
57 * The following figure shows the image of the sample partition on
58 * the 32MB NAND Flash Memory.
59 *
60 * Block No.
61 * 0 +-----------------------------+ ------
62 * | CIS | ^
63 * 24 +-----------------------------+ |
64 * | kernel image | | Zone 0
65 * | | |
66 * +-----------------------------+ |
67 * 1023 | unused area | v
68 * +-----------------------------+ ------
69 * 1024 | JFFS2 | ^
70 * | | |
71 * | | | Zone 1
72 * | | |
73 * | | |
74 * | | v
75 * 2047 +-----------------------------+ ------
76 *
77 */
78static struct mtd_partition partition_info[NUM_PARTITIONS] = {
79 {
80 .name = "RBTX4938 CIS Area",
81 .offset = 0,
82 .size = (NUMBER_OF_CIS_BLOCKS * SIZE_OF_BLOCK),
83 .mask_flags = MTD_WRITEABLE /* This partition is NOT writable */
84 },
85 {
86 .name = "RBTX4938 kernel image",
87 .offset = MTDPART_OFS_APPEND,
88 .size = 8 * 0x00100000, /* 8MB (Depends on size of kernel image) */
89 .mask_flags = MTD_WRITEABLE /* This partition is NOT writable */
90 },
91 {
92 .name = "Root FS (JFFS2)",
93 .offset = (0 + SIZE_OF_ZONE), /* start address of next zone */
94 .size = MTDPART_SIZ_FULL
95 },
96};
97#endif
98
99static void tx4938ndfmc_hwcontrol(struct mtd_info *mtd, int cmd)
100{
101 switch (cmd) {
102 case NAND_CTL_SETCLE:
103 tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_CLE;
104 break;
105 case NAND_CTL_CLRCLE:
106 tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_CLE;
107 break;
108 case NAND_CTL_SETALE:
109 tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_ALE;
110 break;
111 case NAND_CTL_CLRALE:
112 tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_ALE;
113 break;
114 /* TX4938_NDFMCR_CE bit is 0:high 1:low */
115 case NAND_CTL_SETNCE:
116 tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_CE;
117 break;
118 case NAND_CTL_CLRNCE:
119 tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_CE;
120 break;
121 case NAND_CTL_SETWP:
122 tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_WE;
123 break;
124 case NAND_CTL_CLRWP:
125 tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_WE;
126 break;
127 }
128}
129static int tx4938ndfmc_dev_ready(struct mtd_info *mtd)
130{
131 flush_wb();
132 return !(tx4938_ndfmcptr->sr & TX4938_NDFSR_BUSY);
133}
134static void tx4938ndfmc_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
135{
136 u32 mcr = tx4938_ndfmcptr->mcr;
137 mcr &= ~TX4938_NDFMCR_ECC_ALL;
138 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF;
139 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_READ;
140 ecc_code[1] = tx4938_ndfmcptr->dtr;
141 ecc_code[0] = tx4938_ndfmcptr->dtr;
142 ecc_code[2] = tx4938_ndfmcptr->dtr;
143 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF;
144}
145static void tx4938ndfmc_enable_hwecc(struct mtd_info *mtd, int mode)
146{
147 u32 mcr = tx4938_ndfmcptr->mcr;
148 mcr &= ~TX4938_NDFMCR_ECC_ALL;
149 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_RESET;
150 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF;
151 tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_ON;
152}
153
154static u_char tx4938ndfmc_nand_read_byte(struct mtd_info *mtd)
155{
156 struct nand_chip *this = mtd->priv;
157 return tx4938_read_nfmc(this->IO_ADDR_R);
158}
159
160static void tx4938ndfmc_nand_write_byte(struct mtd_info *mtd, u_char byte)
161{
162 struct nand_chip *this = mtd->priv;
163 tx4938_write_nfmc(byte, this->IO_ADDR_W);
164}
165
166static void tx4938ndfmc_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
167{
168 int i;
169 struct nand_chip *this = mtd->priv;
170
171 for (i=0; i<len; i++)
172 tx4938_write_nfmc(buf[i], this->IO_ADDR_W);
173}
174
175static void tx4938ndfmc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
176{
177 int i;
178 struct nand_chip *this = mtd->priv;
179
180 for (i=0; i<len; i++)
181 buf[i] = tx4938_read_nfmc(this->IO_ADDR_R);
182}
183
184static int tx4938ndfmc_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
185{
186 int i;
187 struct nand_chip *this = mtd->priv;
188
189 for (i=0; i<len; i++)
190 if (buf[i] != tx4938_read_nfmc(this->IO_ADDR_R))
191 return -EFAULT;
192
193 return 0;
194}
195
196/*
197 * Send command to NAND device
198 */
199static void tx4938ndfmc_nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
200{
201 register struct nand_chip *this = mtd->priv;
202
203 /* Begin command latch cycle */
204 this->hwcontrol(mtd, NAND_CTL_SETCLE);
205 /*
206 * Write out the command to the device.
207 */
208 if (command == NAND_CMD_SEQIN) {
209 int readcmd;
210
211 if (column >= mtd->oobblock) {
212 /* OOB area */
213 column -= mtd->oobblock;
214 readcmd = NAND_CMD_READOOB;
215 } else if (column < 256) {
216 /* First 256 bytes --> READ0 */
217 readcmd = NAND_CMD_READ0;
218 } else {
219 column -= 256;
220 readcmd = NAND_CMD_READ1;
221 }
222 this->write_byte(mtd, readcmd);
223 }
224 this->write_byte(mtd, command);
225
226 /* Set ALE and clear CLE to start address cycle */
227 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
228
229 if (column != -1 || page_addr != -1) {
230 this->hwcontrol(mtd, NAND_CTL_SETALE);
231
232 /* Serially input address */
233 if (column != -1)
234 this->write_byte(mtd, column);
235 if (page_addr != -1) {
236 this->write_byte(mtd, (unsigned char) (page_addr & 0xff));
237 this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff));
238 /* One more address cycle for higher density devices */
239 if (mtd->size & 0x0c000000)
240 this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f));
241 }
242 /* Latch in address */
243 this->hwcontrol(mtd, NAND_CTL_CLRALE);
244 }
245
246 /*
247 * program and erase have their own busy handlers
248 * status and sequential in needs no delay
249 */
250 switch (command) {
251
252 case NAND_CMD_PAGEPROG:
253 /* Turn off WE */
254 this->hwcontrol (mtd, NAND_CTL_CLRWP);
255 return;
256
257 case NAND_CMD_SEQIN:
258 /* Turn on WE */
259 this->hwcontrol (mtd, NAND_CTL_SETWP);
260 return;
261
262 case NAND_CMD_ERASE1:
263 case NAND_CMD_ERASE2:
264 case NAND_CMD_STATUS:
265 return;
266
267 case NAND_CMD_RESET:
268 if (this->dev_ready)
269 break;
270 this->hwcontrol(mtd, NAND_CTL_SETCLE);
271 this->write_byte(mtd, NAND_CMD_STATUS);
272 this->hwcontrol(mtd, NAND_CTL_CLRCLE);
273 while ( !(this->read_byte(mtd) & 0x40));
274 return;
275
276 /* This applies to read commands */
277 default:
278 /*
279 * If we don't have access to the busy pin, we apply the given
280 * command delay
281 */
282 if (!this->dev_ready) {
283 udelay (this->chip_delay);
284 return;
285 }
286 }
287
288 /* wait until command is processed */
289 while (!this->dev_ready(mtd));
290}
291
292#ifdef CONFIG_MTD_CMDLINE_PARTS
293extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, char *);
294#endif
295/*
296 * Main initialization routine
297 */
298int __init tx4938ndfmc_init (void)
299{
300 struct nand_chip *this;
301 int bsprt = 0, hold = 0xf, spw = 0xf;
302 int protected = 0;
303
304 if ((*rbtx4938_piosel_ptr & 0x0c) != 0x08) {
305 printk("TX4938 NDFMC: disabled by IOC PIOSEL\n");
306 return -ENODEV;
307 }
308 bsprt = 1;
309 hold = 2;
310 spw = 9 - 1; /* 8 GBUSCLK = 80ns (@ GBUSCLK 100MHz) */
311
312 if ((tx4938_ccfgptr->pcfg &
313 (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL))
314 != TX4938_PCFG_NDF_SEL) {
315 printk("TX4938 NDFMC: disabled by PCFG.\n");
316 return -ENODEV;
317 }
318
319 /* reset NDFMC */
320 tx4938_ndfmcptr->rstr |= TX4938_NDFRSTR_RST;
321 while (tx4938_ndfmcptr->rstr & TX4938_NDFRSTR_RST)
322 ;
323 /* setup BusSeparete, Hold Time, Strobe Pulse Width */
324 tx4938_ndfmcptr->mcr = bsprt ? TX4938_NDFMCR_BSPRT : 0;
325 tx4938_ndfmcptr->spr = hold << 4 | spw;
326
327 /* Allocate memory for MTD device structure and private data */
328 tx4938ndfmc_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
329 GFP_KERNEL);
330 if (!tx4938ndfmc_mtd) {
331 printk ("Unable to allocate TX4938 NDFMC MTD device structure.\n");
332 return -ENOMEM;
333 }
334
335 /* Get pointer to private data */
336 this = (struct nand_chip *) (&tx4938ndfmc_mtd[1]);
337
338 /* Initialize structures */
339 memset((char *) tx4938ndfmc_mtd, 0, sizeof(struct mtd_info));
340 memset((char *) this, 0, sizeof(struct nand_chip));
341
342 /* Link the private data with the MTD structure */
343 tx4938ndfmc_mtd->priv = this;
344
345 /* Set address of NAND IO lines */
346 this->IO_ADDR_R = (unsigned long)&tx4938_ndfmcptr->dtr;
347 this->IO_ADDR_W = (unsigned long)&tx4938_ndfmcptr->dtr;
348 this->hwcontrol = tx4938ndfmc_hwcontrol;
349 this->dev_ready = tx4938ndfmc_dev_ready;
350 this->calculate_ecc = tx4938ndfmc_calculate_ecc;
351 this->correct_data = nand_correct_data;
352 this->enable_hwecc = tx4938ndfmc_enable_hwecc;
353 this->eccmode = NAND_ECC_HW3_256;
354 this->chip_delay = 100;
355 this->read_byte = tx4938ndfmc_nand_read_byte;
356 this->write_byte = tx4938ndfmc_nand_write_byte;
357 this->cmdfunc = tx4938ndfmc_nand_command;
358 this->write_buf = tx4938ndfmc_nand_write_buf;
359 this->read_buf = tx4938ndfmc_nand_read_buf;
360 this->verify_buf = tx4938ndfmc_nand_verify_buf;
361
362 /* Scan to find existance of the device */
363 if (nand_scan (tx4938ndfmc_mtd, 1)) {
364 kfree (tx4938ndfmc_mtd);
365 return -ENXIO;
366 }
367
368 if (protected) {
369 printk(KERN_INFO "TX4938 NDFMC: write protected.\n");
370 tx4938ndfmc_mtd->flags &= ~(MTD_WRITEABLE | MTD_ERASEABLE);
371 }
372
373#ifdef CONFIG_MTD_CMDLINE_PARTS
374 {
375 int mtd_parts_nb = 0;
376 struct mtd_partition *mtd_parts = 0;
377 mtd_parts_nb = parse_cmdline_partitions(tx4938ndfmc_mtd, &mtd_parts, "tx4938ndfmc");
378 if (mtd_parts_nb > 0)
379 add_mtd_partitions(tx4938ndfmc_mtd, mtd_parts, mtd_parts_nb);
380 else
381 add_mtd_device(tx4938ndfmc_mtd);
382 }
383#else
384 add_mtd_partitions(tx4938ndfmc_mtd, partition_info, NUM_PARTITIONS );
385#endif
386
387 return 0;
388}
389module_init(tx4938ndfmc_init);
390
391/*
392 * Clean up routine
393 */
394static void __exit tx4938ndfmc_cleanup (void)
395{
396 /* Release resources, unregister device */
397 nand_release (tx4938ndfmc_mtd);
398
399 /* Free the MTD device structure */
400 kfree (tx4938ndfmc_mtd);
401}
402module_exit(tx4938ndfmc_cleanup);
403
404MODULE_LICENSE("GPL");
405MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
406MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on TX4938 NDFMC");
diff --git a/drivers/net/3c503.c b/drivers/net/3c503.c
index 29dfd47f41d2..5c5eebdb6914 100644
--- a/drivers/net/3c503.c
+++ b/drivers/net/3c503.c
@@ -171,12 +171,7 @@ struct net_device * __init el2_probe(int unit)
171 err = do_el2_probe(dev); 171 err = do_el2_probe(dev);
172 if (err) 172 if (err)
173 goto out; 173 goto out;
174 err = register_netdev(dev);
175 if (err)
176 goto out1;
177 return dev; 174 return dev;
178out1:
179 cleanup_card(dev);
180out: 175out:
181 free_netdev(dev); 176 free_netdev(dev);
182 return ERR_PTR(err); 177 return ERR_PTR(err);
@@ -356,6 +351,10 @@ el2_probe1(struct net_device *dev, int ioaddr)
356 dev->poll_controller = ei_poll; 351 dev->poll_controller = ei_poll;
357#endif 352#endif
358 353
354 retval = register_netdev(dev);
355 if (retval)
356 goto out1;
357
359 if (dev->mem_start) 358 if (dev->mem_start)
360 printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n", 359 printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
361 dev->name, ei_status.name, (wordlength+1)<<3, 360 dev->name, ei_status.name, (wordlength+1)<<3,
@@ -715,11 +714,8 @@ init_module(void)
715 dev->base_addr = io[this_dev]; 714 dev->base_addr = io[this_dev];
716 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ 715 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
717 if (do_el2_probe(dev) == 0) { 716 if (do_el2_probe(dev) == 0) {
718 if (register_netdev(dev) == 0) { 717 dev_el2[found++] = dev;
719 dev_el2[found++] = dev; 718 continue;
720 continue;
721 }
722 cleanup_card(dev);
723 } 719 }
724 free_netdev(dev); 720 free_netdev(dev);
725 printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]); 721 printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index 76fa8cc24085..ad17f17e8e7a 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -1317,8 +1317,7 @@ static int __init elp_sense(struct net_device *dev)
1317 if (orig_HSR & DIR) { 1317 if (orig_HSR & DIR) {
1318 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */ 1318 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1319 outb(0, dev->base_addr + PORT_CONTROL); 1319 outb(0, dev->base_addr + PORT_CONTROL);
1320 set_current_state(TASK_UNINTERRUPTIBLE); 1320 msleep(300);
1321 schedule_timeout(30*HZ/100);
1322 if (inb_status(addr) & DIR) { 1321 if (inb_status(addr) & DIR) {
1323 if (elp_debug > 0) 1322 if (elp_debug > 0)
1324 printk(notfound_msg, 2); 1323 printk(notfound_msg, 2);
@@ -1327,8 +1326,7 @@ static int __init elp_sense(struct net_device *dev)
1327 } else { 1326 } else {
1328 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */ 1327 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1329 outb(DIR, dev->base_addr + PORT_CONTROL); 1328 outb(DIR, dev->base_addr + PORT_CONTROL);
1330 set_current_state(TASK_UNINTERRUPTIBLE); 1329 msleep(300);
1331 schedule_timeout(30*HZ/100);
1332 if (!(inb_status(addr) & DIR)) { 1330 if (!(inb_status(addr) & DIR)) {
1333 if (elp_debug > 0) 1331 if (elp_debug > 0)
1334 printk(notfound_msg, 3); 1332 printk(notfound_msg, 3);
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index e843109d4f62..977935a3d898 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -217,6 +217,7 @@ static void el3_poll_controller(struct net_device *dev);
217static struct eisa_device_id el3_eisa_ids[] = { 217static struct eisa_device_id el3_eisa_ids[] = {
218 { "TCM5092" }, 218 { "TCM5092" },
219 { "TCM5093" }, 219 { "TCM5093" },
220 { "TCM5095" },
220 { "" } 221 { "" }
221}; 222};
222 223
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index c4cf4fcd1344..91d1c4c24d9b 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -365,7 +365,7 @@ static int nopnp;
365#endif /* __ISAPNP__ */ 365#endif /* __ISAPNP__ */
366 366
367static struct net_device *corkscrew_scan(int unit); 367static struct net_device *corkscrew_scan(int unit);
368static void corkscrew_setup(struct net_device *dev, int ioaddr, 368static int corkscrew_setup(struct net_device *dev, int ioaddr,
369 struct pnp_dev *idev, int card_number); 369 struct pnp_dev *idev, int card_number);
370static int corkscrew_open(struct net_device *dev); 370static int corkscrew_open(struct net_device *dev);
371static void corkscrew_timer(unsigned long arg); 371static void corkscrew_timer(unsigned long arg);
@@ -539,10 +539,9 @@ static struct net_device *corkscrew_scan(int unit)
539 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n", 539 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
540 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000)); 540 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
541 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */ 541 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
542 corkscrew_setup(dev, ioaddr, idev, cards_found++);
543 SET_NETDEV_DEV(dev, &idev->dev); 542 SET_NETDEV_DEV(dev, &idev->dev);
544 pnp_cards++; 543 pnp_cards++;
545 err = register_netdev(dev); 544 err = corkscrew_setup(dev, ioaddr, idev, cards_found++);
546 if (!err) 545 if (!err)
547 return dev; 546 return dev;
548 cleanup_card(dev); 547 cleanup_card(dev);
@@ -558,8 +557,7 @@ no_pnp:
558 557
559 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n", 558 printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
560 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000)); 559 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
561 corkscrew_setup(dev, ioaddr, NULL, cards_found++); 560 err = corkscrew_setup(dev, ioaddr, NULL, cards_found++);
562 err = register_netdev(dev);
563 if (!err) 561 if (!err)
564 return dev; 562 return dev;
565 cleanup_card(dev); 563 cleanup_card(dev);
@@ -568,7 +566,7 @@ no_pnp:
568 return NULL; 566 return NULL;
569} 567}
570 568
571static void corkscrew_setup(struct net_device *dev, int ioaddr, 569static int corkscrew_setup(struct net_device *dev, int ioaddr,
572 struct pnp_dev *idev, int card_number) 570 struct pnp_dev *idev, int card_number)
573{ 571{
574 struct corkscrew_private *vp = netdev_priv(dev); 572 struct corkscrew_private *vp = netdev_priv(dev);
@@ -691,6 +689,8 @@ static void corkscrew_setup(struct net_device *dev, int ioaddr,
691 dev->get_stats = &corkscrew_get_stats; 689 dev->get_stats = &corkscrew_get_stats;
692 dev->set_multicast_list = &set_rx_mode; 690 dev->set_multicast_list = &set_rx_mode;
693 dev->ethtool_ops = &netdev_ethtool_ops; 691 dev->ethtool_ops = &netdev_ethtool_ops;
692
693 return register_netdev(dev);
694} 694}
695 695
696 696
@@ -822,7 +822,7 @@ static int corkscrew_open(struct net_device *dev)
822 break; /* Bad news! */ 822 break; /* Bad news! */
823 skb->dev = dev; /* Mark as being used by this device. */ 823 skb->dev = dev; /* Mark as being used by this device. */
824 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 824 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
825 vp->rx_ring[i].addr = isa_virt_to_bus(skb->tail); 825 vp->rx_ring[i].addr = isa_virt_to_bus(skb->data);
826 } 826 }
827 vp->rx_ring[i - 1].next = isa_virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */ 827 vp->rx_ring[i - 1].next = isa_virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */
828 outl(isa_virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr); 828 outl(isa_virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
@@ -1406,7 +1406,7 @@ static int boomerang_rx(struct net_device *dev)
1406 break; /* Bad news! */ 1406 break; /* Bad news! */
1407 skb->dev = dev; /* Mark as being used by this device. */ 1407 skb->dev = dev; /* Mark as being used by this device. */
1408 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1408 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1409 vp->rx_ring[entry].addr = isa_virt_to_bus(skb->tail); 1409 vp->rx_ring[entry].addr = isa_virt_to_bus(skb->data);
1410 vp->rx_skbuff[entry] = skb; 1410 vp->rx_skbuff[entry] = skb;
1411 } 1411 }
1412 vp->rx_ring[entry].status = 0; /* Clear complete bit. */ 1412 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index 8f6b2fa13e28..9e1fe2e0478c 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -572,6 +572,10 @@ static int __init do_elmc_probe(struct net_device *dev)
572 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */ 572 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
573#endif 573#endif
574 574
575 retval = register_netdev(dev);
576 if (retval)
577 goto err_out;
578
575 return 0; 579 return 0;
576err_out: 580err_out:
577 mca_set_adapter_procfn(slot, NULL, NULL); 581 mca_set_adapter_procfn(slot, NULL, NULL);
@@ -600,12 +604,7 @@ struct net_device * __init elmc_probe(int unit)
600 err = do_elmc_probe(dev); 604 err = do_elmc_probe(dev);
601 if (err) 605 if (err)
602 goto out; 606 goto out;
603 err = register_netdev(dev);
604 if (err)
605 goto out1;
606 return dev; 607 return dev;
607out1:
608 cleanup_card(dev);
609out: 608out:
610 free_netdev(dev); 609 free_netdev(dev);
611 return ERR_PTR(err); 610 return ERR_PTR(err);
@@ -1275,6 +1274,7 @@ module_param_array(irq, int, NULL, 0);
1275module_param_array(io, int, NULL, 0); 1274module_param_array(io, int, NULL, 0);
1276MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)"); 1275MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1277MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)"); 1276MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
1277MODULE_LICENSE("GPL");
1278 1278
1279int init_module(void) 1279int init_module(void)
1280{ 1280{
@@ -1288,12 +1288,9 @@ int init_module(void)
1288 dev->irq=irq[this_dev]; 1288 dev->irq=irq[this_dev];
1289 dev->base_addr=io[this_dev]; 1289 dev->base_addr=io[this_dev];
1290 if (do_elmc_probe(dev) == 0) { 1290 if (do_elmc_probe(dev) == 0) {
1291 if (register_netdev(dev) == 0) { 1291 dev_elmc[this_dev] = dev;
1292 dev_elmc[this_dev] = dev; 1292 found++;
1293 found++; 1293 continue;
1294 continue;
1295 }
1296 cleanup_card(dev);
1297 } 1294 }
1298 free_netdev(dev); 1295 free_netdev(dev);
1299 if (io[this_dev]==0) 1296 if (io[this_dev]==0)
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 80ec9aa575bb..07746b95fd83 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -1802,7 +1802,7 @@ vortex_open(struct net_device *dev)
1802 break; /* Bad news! */ 1802 break; /* Bad news! */
1803 skb->dev = dev; /* Mark as being used by this device. */ 1803 skb->dev = dev; /* Mark as being used by this device. */
1804 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1804 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1805 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE)); 1805 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
1806 } 1806 }
1807 if (i != RX_RING_SIZE) { 1807 if (i != RX_RING_SIZE) {
1808 int j; 1808 int j;
@@ -2632,7 +2632,7 @@ boomerang_rx(struct net_device *dev)
2632 pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2632 pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2633 /* 'skb_put()' points to the start of sk_buff data area. */ 2633 /* 'skb_put()' points to the start of sk_buff data area. */
2634 memcpy(skb_put(skb, pkt_len), 2634 memcpy(skb_put(skb, pkt_len),
2635 vp->rx_skbuff[entry]->tail, 2635 vp->rx_skbuff[entry]->data,
2636 pkt_len); 2636 pkt_len);
2637 pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 2637 pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2638 vp->rx_copy++; 2638 vp->rx_copy++;
@@ -2678,7 +2678,7 @@ boomerang_rx(struct net_device *dev)
2678 } 2678 }
2679 skb->dev = dev; /* Mark as being used by this device. */ 2679 skb->dev = dev; /* Mark as being used by this device. */
2680 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 2680 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
2681 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE)); 2681 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
2682 vp->rx_skbuff[entry] = skb; 2682 vp->rx_skbuff[entry] = skb;
2683 } 2683 }
2684 vp->rx_ring[entry].status = 0; /* Clear complete bit. */ 2684 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 72cdf19e1be1..7b293f01c9ed 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -61,6 +61,7 @@
61#include <linux/etherdevice.h> 61#include <linux/etherdevice.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/pci.h> 63#include <linux/pci.h>
64#include <linux/dma-mapping.h>
64#include <linux/delay.h> 65#include <linux/delay.h>
65#include <linux/ethtool.h> 66#include <linux/ethtool.h>
66#include <linux/mii.h> 67#include <linux/mii.h>
@@ -595,7 +596,7 @@ rx_status_loop:
595 596
596 mapping = 597 mapping =
597 cp->rx_skb[rx_tail].mapping = 598 cp->rx_skb[rx_tail].mapping =
598 pci_map_single(cp->pdev, new_skb->tail, 599 pci_map_single(cp->pdev, new_skb->data,
599 buflen, PCI_DMA_FROMDEVICE); 600 buflen, PCI_DMA_FROMDEVICE);
600 cp->rx_skb[rx_tail].skb = new_skb; 601 cp->rx_skb[rx_tail].skb = new_skb;
601 602
@@ -1100,7 +1101,7 @@ static int cp_refill_rx (struct cp_private *cp)
1100 skb_reserve(skb, RX_OFFSET); 1101 skb_reserve(skb, RX_OFFSET);
1101 1102
1102 cp->rx_skb[i].mapping = pci_map_single(cp->pdev, 1103 cp->rx_skb[i].mapping = pci_map_single(cp->pdev,
1103 skb->tail, cp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1104 skb->data, cp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1104 cp->rx_skb[i].skb = skb; 1105 cp->rx_skb[i].skb = skb;
1105 1106
1106 cp->rx_ring[i].opts2 = 0; 1107 cp->rx_ring[i].opts2 = 0;
@@ -1515,22 +1516,22 @@ static void cp_get_ethtool_stats (struct net_device *dev,
1515 struct ethtool_stats *estats, u64 *tmp_stats) 1516 struct ethtool_stats *estats, u64 *tmp_stats)
1516{ 1517{
1517 struct cp_private *cp = netdev_priv(dev); 1518 struct cp_private *cp = netdev_priv(dev);
1518 unsigned int work = 100;
1519 int i; 1519 int i;
1520 1520
1521 memset(cp->nic_stats, 0, sizeof(struct cp_dma_stats));
1522
1521 /* begin NIC statistics dump */ 1523 /* begin NIC statistics dump */
1522 cpw32(StatsAddr + 4, (cp->nic_stats_dma >> 16) >> 16); 1524 cpw32(StatsAddr + 4, (cp->nic_stats_dma >> 16) >> 16);
1523 cpw32(StatsAddr, (cp->nic_stats_dma & 0xffffffff) | DumpStats); 1525 cpw32(StatsAddr, (cp->nic_stats_dma & 0xffffffff) | DumpStats);
1524 cpr32(StatsAddr); 1526 cpr32(StatsAddr);
1525 1527
1526 while (work-- > 0) { 1528 for (i = 0; i < 1000; i++) {
1527 if ((cpr32(StatsAddr) & DumpStats) == 0) 1529 if ((cpr32(StatsAddr) & DumpStats) == 0)
1528 break; 1530 break;
1529 cpu_relax(); 1531 udelay(10);
1530 } 1532 }
1531 1533 cpw32(StatsAddr, 0);
1532 if (cpr32(StatsAddr) & DumpStats) 1534 cpw32(StatsAddr + 4, 0);
1533 return /* -EIO */;
1534 1535
1535 i = 0; 1536 i = 0;
1536 tmp_stats[i++] = le64_to_cpu(cp->nic_stats->tx_ok); 1537 tmp_stats[i++] = le64_to_cpu(cp->nic_stats->tx_ok);
@@ -1732,19 +1733,19 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1732 1733
1733 /* Configure DMA attributes. */ 1734 /* Configure DMA attributes. */
1734 if ((sizeof(dma_addr_t) > 4) && 1735 if ((sizeof(dma_addr_t) > 4) &&
1735 !pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL) && 1736 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) &&
1736 !pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 1737 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1737 pci_using_dac = 1; 1738 pci_using_dac = 1;
1738 } else { 1739 } else {
1739 pci_using_dac = 0; 1740 pci_using_dac = 0;
1740 1741
1741 rc = pci_set_dma_mask(pdev, 0xffffffffULL); 1742 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1742 if (rc) { 1743 if (rc) {
1743 printk(KERN_ERR PFX "No usable DMA configuration, " 1744 printk(KERN_ERR PFX "No usable DMA configuration, "
1744 "aborting.\n"); 1745 "aborting.\n");
1745 goto err_out_res; 1746 goto err_out_res;
1746 } 1747 }
1747 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffULL); 1748 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1748 if (rc) { 1749 if (rc) {
1749 printk(KERN_ERR PFX "No usable consistent DMA configuration, " 1750 printk(KERN_ERR PFX "No usable consistent DMA configuration, "
1750 "aborting.\n"); 1751 "aborting.\n");
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 65f97b1dc581..13b745b39667 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -546,11 +546,11 @@ static inline void init_rx_bufs(struct net_device *dev)
546 rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1)); 546 rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
547 rbd->b_addr = WSWAPrbd(virt_to_bus(rbd)); 547 rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
548 rbd->skb = skb; 548 rbd->skb = skb;
549 rbd->v_data = skb->tail; 549 rbd->v_data = skb->data;
550 rbd->b_data = WSWAPchar(virt_to_bus(skb->tail)); 550 rbd->b_data = WSWAPchar(virt_to_bus(skb->data));
551 rbd->size = PKT_BUF_SZ; 551 rbd->size = PKT_BUF_SZ;
552#ifdef __mc68000__ 552#ifdef __mc68000__
553 cache_clear(virt_to_phys(skb->tail), PKT_BUF_SZ); 553 cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ);
554#endif 554#endif
555 } 555 }
556 lp->rbd_head = lp->rbds; 556 lp->rbd_head = lp->rbds;
@@ -816,10 +816,10 @@ static inline int i596_rx(struct net_device *dev)
816 rx_in_place = 1; 816 rx_in_place = 1;
817 rbd->skb = newskb; 817 rbd->skb = newskb;
818 newskb->dev = dev; 818 newskb->dev = dev;
819 rbd->v_data = newskb->tail; 819 rbd->v_data = newskb->data;
820 rbd->b_data = WSWAPchar(virt_to_bus(newskb->tail)); 820 rbd->b_data = WSWAPchar(virt_to_bus(newskb->data));
821#ifdef __mc68000__ 821#ifdef __mc68000__
822 cache_clear(virt_to_phys(newskb->tail), PKT_BUF_SZ); 822 cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ);
823#endif 823#endif
824 } 824 }
825 else 825 else
@@ -840,7 +840,7 @@ memory_squeeze:
840 skb->protocol=eth_type_trans(skb,dev); 840 skb->protocol=eth_type_trans(skb,dev);
841 skb->len = pkt_len; 841 skb->len = pkt_len;
842#ifdef __mc68000__ 842#ifdef __mc68000__
843 cache_clear(virt_to_phys(rbd->skb->tail), 843 cache_clear(virt_to_phys(rbd->skb->data),
844 pkt_len); 844 pkt_len);
845#endif 845#endif
846 netif_rx(skb); 846 netif_rx(skb);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index fa9f76c953dd..534b598866b3 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -3,6 +3,8 @@
3# Network device configuration 3# Network device configuration
4# 4#
5 5
6menu "Network device support"
7
6config NETDEVICES 8config NETDEVICES
7 depends on NET 9 depends on NET
8 bool "Network device support" 10 bool "Network device support"
@@ -1320,7 +1322,7 @@ config FORCEDETH
1320 1322
1321config CS89x0 1323config CS89x0
1322 tristate "CS89x0 support" 1324 tristate "CS89x0 support"
1323 depends on NET_PCI && (ISA || ARCH_IXDP2X01) 1325 depends on (NET_PCI && (ISA || ARCH_IXDP2X01)) || ARCH_PNX0105
1324 ---help--- 1326 ---help---
1325 Support for CS89x0 chipset based Ethernet cards. If you have a 1327 Support for CS89x0 chipset based Ethernet cards. If you have a
1326 network (Ethernet) card of this type, say Y and read the 1328 network (Ethernet) card of this type, say Y and read the
@@ -1488,14 +1490,14 @@ config 8139CP
1488 will be called 8139cp. This is recommended. 1490 will be called 8139cp. This is recommended.
1489 1491
1490config 8139TOO 1492config 8139TOO
1491 tristate "RealTek RTL-8139 PCI Fast Ethernet Adapter support" 1493 tristate "RealTek RTL-8129/8130/8139 PCI Fast Ethernet Adapter support"
1492 depends on NET_PCI && PCI 1494 depends on NET_PCI && PCI
1493 select CRC32 1495 select CRC32
1494 select MII 1496 select MII
1495 ---help--- 1497 ---help---
1496 This is a driver for the Fast Ethernet PCI network cards based on 1498 This is a driver for the Fast Ethernet PCI network cards based on
1497 the RTL8139 chips. If you have one of those, say Y and read 1499 the RTL 8129/8130/8139 chips. If you have one of those, say Y and
1498 the Ethernet-HOWTO <http://www.tldp.org/docs.html#howto>. 1500 read the Ethernet-HOWTO <http://www.tldp.org/docs.html#howto>.
1499 1501
1500 To compile this driver as a module, choose M here: the module 1502 To compile this driver as a module, choose M here: the module
1501 will be called 8139too. This is recommended. 1503 will be called 8139too. This is recommended.
@@ -2542,8 +2544,25 @@ config SHAPER
2542 2544
2543config NETCONSOLE 2545config NETCONSOLE
2544 tristate "Network console logging support (EXPERIMENTAL)" 2546 tristate "Network console logging support (EXPERIMENTAL)"
2545 depends on NETDEVICES && EXPERIMENTAL 2547 depends on NETDEVICES && INET && EXPERIMENTAL
2546 ---help--- 2548 ---help---
2547 If you want to log kernel messages over the network, enable this. 2549 If you want to log kernel messages over the network, enable this.
2548 See <file:Documentation/networking/netconsole.txt> for details. 2550 See <file:Documentation/networking/netconsole.txt> for details.
2549 2551
2552config NETPOLL
2553 def_bool NETCONSOLE
2554
2555config NETPOLL_RX
2556 bool "Netpoll support for trapping incoming packets"
2557 default n
2558 depends on NETPOLL
2559
2560config NETPOLL_TRAP
2561 bool "Netpoll traffic trapping"
2562 default n
2563 depends on NETPOLL
2564
2565config NET_POLL_CONTROLLER
2566 def_bool NETPOLL
2567
2568endmenu
diff --git a/drivers/net/ac3200.c b/drivers/net/ac3200.c
index 24fba36b5c1d..91791ba37769 100644
--- a/drivers/net/ac3200.c
+++ b/drivers/net/ac3200.c
@@ -146,12 +146,7 @@ struct net_device * __init ac3200_probe(int unit)
146 err = do_ac3200_probe(dev); 146 err = do_ac3200_probe(dev);
147 if (err) 147 if (err)
148 goto out; 148 goto out;
149 err = register_netdev(dev);
150 if (err)
151 goto out1;
152 return dev; 149 return dev;
153out1:
154 cleanup_card(dev);
155out: 150out:
156 free_netdev(dev); 151 free_netdev(dev);
157 return ERR_PTR(err); 152 return ERR_PTR(err);
@@ -273,7 +268,14 @@ static int __init ac_probe1(int ioaddr, struct net_device *dev)
273 dev->poll_controller = ei_poll; 268 dev->poll_controller = ei_poll;
274#endif 269#endif
275 NS8390_init(dev, 0); 270 NS8390_init(dev, 0);
271
272 retval = register_netdev(dev);
273 if (retval)
274 goto out2;
276 return 0; 275 return 0;
276out2:
277 if (ei_status.reg0)
278 iounmap((void *)dev->mem_start);
277out1: 279out1:
278 free_irq(dev->irq, dev); 280 free_irq(dev->irq, dev);
279out: 281out:
@@ -392,11 +394,8 @@ init_module(void)
392 dev->base_addr = io[this_dev]; 394 dev->base_addr = io[this_dev];
393 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */ 395 dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
394 if (do_ac3200_probe(dev) == 0) { 396 if (do_ac3200_probe(dev) == 0) {
395 if (register_netdev(dev) == 0) { 397 dev_ac32[found++] = dev;
396 dev_ac32[found++] = dev; 398 continue;
397 continue;
398 }
399 cleanup_card(dev);
400 } 399 }
401 free_netdev(dev); 400 free_netdev(dev);
402 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]); 401 printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index 6eea3a8accb7..dbecc6bf7851 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -58,6 +58,7 @@
58#include <linux/errno.h> 58#include <linux/errno.h>
59#include <linux/ioport.h> 59#include <linux/ioport.h>
60#include <linux/pci.h> 60#include <linux/pci.h>
61#include <linux/dma-mapping.h>
61#include <linux/kernel.h> 62#include <linux/kernel.h>
62#include <linux/netdevice.h> 63#include <linux/netdevice.h>
63#include <linux/etherdevice.h> 64#include <linux/etherdevice.h>
@@ -1167,9 +1168,9 @@ static int __devinit ace_init(struct net_device *dev)
1167 /* 1168 /*
1168 * Configure DMA attributes. 1169 * Configure DMA attributes.
1169 */ 1170 */
1170 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 1171 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1171 ap->pci_using_dac = 1; 1172 ap->pci_using_dac = 1;
1172 } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) { 1173 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1173 ap->pci_using_dac = 0; 1174 ap->pci_using_dac = 0;
1174 } else { 1175 } else {
1175 ecode = -ENODEV; 1176 ecode = -ENODEV;
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index b7dd7260cafb..8618012df06a 100755
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -87,6 +87,7 @@ Revision History:
87#include <linux/if_vlan.h> 87#include <linux/if_vlan.h>
88#include <linux/ctype.h> 88#include <linux/ctype.h>
89#include <linux/crc32.h> 89#include <linux/crc32.h>
90#include <linux/dma-mapping.h>
90 91
91#include <asm/system.h> 92#include <asm/system.h>
92#include <asm/io.h> 93#include <asm/io.h>
@@ -2006,12 +2007,11 @@ static int __devinit amd8111e_probe_one(struct pci_dev *pdev,
2006 } 2007 }
2007 2008
2008 /* Initialize DMA */ 2009 /* Initialize DMA */
2009 if(!pci_dma_supported(pdev, 0xffffffff)){ 2010 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) < 0) {
2010 printk(KERN_ERR "amd8111e: DMA not supported," 2011 printk(KERN_ERR "amd8111e: DMA not supported,"
2011 "exiting.\n"); 2012 "exiting.\n");
2012 goto err_free_reg; 2013 goto err_free_reg;
2013 } else 2014 }
2014 pdev->dma_mask = 0xffffffff;
2015 2015
2016 reg_addr = pci_resource_start(pdev, 0); 2016 reg_addr = pci_resource_start(pdev, 0);
2017 reg_len = pci_resource_len(pdev, 0); 2017 reg_len = pci_resource_len(pdev, 0);
diff --git a/drivers/net/appletalk/Kconfig b/drivers/net/appletalk/Kconfig
index 69c488d933a2..b14e89004c3a 100644
--- a/drivers/net/appletalk/Kconfig
+++ b/drivers/net/appletalk/Kconfig
@@ -1,6 +1,33 @@
1# 1#
2# Appletalk driver configuration 2# Appletalk driver configuration
3# 3#
4config ATALK
5 tristate "Appletalk protocol support"
6 select LLC
7 ---help---
8 AppleTalk is the protocol that Apple computers can use to communicate
9 on a network. If your Linux box is connected to such a network and you
10 wish to connect to it, say Y. You will need to use the netatalk package
11 so that your Linux box can act as a print and file server for Macs as
12 well as access AppleTalk printers. Check out
13 <http://www.zettabyte.net/netatalk/> on the WWW for details.
14 EtherTalk is the name used for AppleTalk over Ethernet and the
15 cheaper and slower LocalTalk is AppleTalk over a proprietary Apple
16 network using serial links. EtherTalk and LocalTalk are fully
17 supported by Linux.
18
19 General information about how to connect Linux, Windows machines and
20 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>. The
21 NET-3-HOWTO, available from
22 <http://www.tldp.org/docs.html#howto>, contains valuable
23 information as well.
24
25 To compile this driver as a module, choose M here: the module will be
26 called appletalk. You almost certainly want to compile it as a
27 module so you can restart your AppleTalk stack without rebooting
28 your machine. I hear that the GNU boycott of Apple is over, so
29 even politically correct people are allowed to say Y here.
30
4config DEV_APPLETALK 31config DEV_APPLETALK
5 bool "Appletalk interfaces support" 32 bool "Appletalk interfaces support"
6 depends on ATALK 33 depends on ATALK
diff --git a/drivers/net/arm/etherh.c b/drivers/net/arm/etherh.c
index 2e28c201dcc0..942a2819576c 100644
--- a/drivers/net/arm/etherh.c
+++ b/drivers/net/arm/etherh.c
@@ -68,7 +68,6 @@ struct etherh_priv {
68 void __iomem *dma_base; 68 void __iomem *dma_base;
69 unsigned int id; 69 unsigned int id;
70 void __iomem *ctrl_port; 70 void __iomem *ctrl_port;
71 void __iomem *base;
72 unsigned char ctrl; 71 unsigned char ctrl;
73 u32 supported; 72 u32 supported;
74}; 73};
@@ -178,7 +177,7 @@ etherh_setif(struct net_device *dev)
178 switch (etherh_priv(dev)->id) { 177 switch (etherh_priv(dev)->id) {
179 case PROD_I3_ETHERLAN600: 178 case PROD_I3_ETHERLAN600:
180 case PROD_I3_ETHERLAN600A: 179 case PROD_I3_ETHERLAN600A:
181 addr = etherh_priv(dev)->base + EN0_RCNTHI; 180 addr = (void *)dev->base_addr + EN0_RCNTHI;
182 181
183 switch (dev->if_port) { 182 switch (dev->if_port) {
184 case IF_PORT_10BASE2: 183 case IF_PORT_10BASE2:
@@ -219,7 +218,7 @@ etherh_getifstat(struct net_device *dev)
219 switch (etherh_priv(dev)->id) { 218 switch (etherh_priv(dev)->id) {
220 case PROD_I3_ETHERLAN600: 219 case PROD_I3_ETHERLAN600:
221 case PROD_I3_ETHERLAN600A: 220 case PROD_I3_ETHERLAN600A:
222 addr = etherh_priv(dev)->base + EN0_RCNTHI; 221 addr = (void *)dev->base_addr + EN0_RCNTHI;
223 switch (dev->if_port) { 222 switch (dev->if_port) {
224 case IF_PORT_10BASE2: 223 case IF_PORT_10BASE2:
225 stat = 1; 224 stat = 1;
@@ -282,7 +281,7 @@ static void
282etherh_reset(struct net_device *dev) 281etherh_reset(struct net_device *dev)
283{ 282{
284 struct ei_device *ei_local = netdev_priv(dev); 283 struct ei_device *ei_local = netdev_priv(dev);
285 void __iomem *addr = etherh_priv(dev)->base; 284 void __iomem *addr = (void *)dev->base_addr;
286 285
287 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr); 286 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
288 287
@@ -328,7 +327,7 @@ etherh_block_output (struct net_device *dev, int count, const unsigned char *buf
328 327
329 ei_local->dmaing = 1; 328 ei_local->dmaing = 1;
330 329
331 addr = etherh_priv(dev)->base; 330 addr = (void *)dev->base_addr;
332 dma_base = etherh_priv(dev)->dma_base; 331 dma_base = etherh_priv(dev)->dma_base;
333 332
334 count = (count + 1) & ~1; 333 count = (count + 1) & ~1;
@@ -388,7 +387,7 @@ etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int
388 387
389 ei_local->dmaing = 1; 388 ei_local->dmaing = 1;
390 389
391 addr = etherh_priv(dev)->base; 390 addr = (void *)dev->base_addr;
392 dma_base = etherh_priv(dev)->dma_base; 391 dma_base = etherh_priv(dev)->dma_base;
393 392
394 buf = skb->data; 393 buf = skb->data;
@@ -428,7 +427,7 @@ etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_p
428 427
429 ei_local->dmaing = 1; 428 ei_local->dmaing = 1;
430 429
431 addr = etherh_priv(dev)->base; 430 addr = (void *)dev->base_addr;
432 dma_base = etherh_priv(dev)->dma_base; 431 dma_base = etherh_priv(dev)->dma_base;
433 432
434 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD); 433 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
@@ -697,8 +696,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
697 eh->ctrl_port = eh->ioc_fast; 696 eh->ctrl_port = eh->ioc_fast;
698 } 697 }
699 698
700 eh->base = eh->memc + data->ns8390_offset; 699 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
701 dev->base_addr = (unsigned long)eh->base;
702 eh->dma_base = eh->memc + data->dataport_offset; 700 eh->dma_base = eh->memc + data->dataport_offset;
703 eh->ctrl_port += data->ctrlport_offset; 701 eh->ctrl_port += data->ctrlport_offset;
704 702
diff --git a/drivers/net/at1700.c b/drivers/net/at1700.c
index b8ab2b6355eb..e613cc289749 100644
--- a/drivers/net/at1700.c
+++ b/drivers/net/at1700.c
@@ -34,10 +34,6 @@
34 only is it difficult to detect, it also moves around in I/O space in 34 only is it difficult to detect, it also moves around in I/O space in
35 response to inb()s from other device probes! 35 response to inb()s from other device probes!
36*/ 36*/
37/*
38 99/03/03 Allied Telesis RE1000 Plus support by T.Hagawa
39 99/12/30 port to 2.3.35 by K.Takai
40*/
41 37
42#include <linux/config.h> 38#include <linux/config.h>
43#include <linux/errno.h> 39#include <linux/errno.h>
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 3fe8ba992c38..94939f570f78 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -1285,6 +1285,9 @@ static int b44_open(struct net_device *dev)
1285 b44_init_hw(bp); 1285 b44_init_hw(bp);
1286 bp->flags |= B44_FLAG_INIT_COMPLETE; 1286 bp->flags |= B44_FLAG_INIT_COMPLETE;
1287 1287
1288 netif_carrier_off(dev);
1289 b44_check_phy(bp);
1290
1288 spin_unlock_irq(&bp->lock); 1291 spin_unlock_irq(&bp->lock);
1289 1292
1290 init_timer(&bp->timer); 1293 init_timer(&bp->timer);
@@ -1927,6 +1930,7 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
1927 b44_free_rings(bp); 1930 b44_free_rings(bp);
1928 1931
1929 spin_unlock_irq(&bp->lock); 1932 spin_unlock_irq(&bp->lock);
1933 pci_disable_device(pdev);
1930 return 0; 1934 return 0;
1931} 1935}
1932 1936
@@ -1936,6 +1940,8 @@ static int b44_resume(struct pci_dev *pdev)
1936 struct b44 *bp = netdev_priv(dev); 1940 struct b44 *bp = netdev_priv(dev);
1937 1941
1938 pci_restore_state(pdev); 1942 pci_restore_state(pdev);
1943 pci_enable_device(pdev);
1944 pci_set_master(pdev);
1939 1945
1940 if (!netif_running(dev)) 1946 if (!netif_running(dev))
1941 return 0; 1947 return 0;
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 00e5257b176f..8dc657fc8afb 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1261,7 +1261,7 @@ static void bmac_reset_and_enable(struct net_device *dev)
1261 spin_unlock_irqrestore(&bp->lock, flags); 1261 spin_unlock_irqrestore(&bp->lock, flags);
1262} 1262}
1263 1263
1264static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_match *match) 1264static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match)
1265{ 1265{
1266 int j, rev, ret; 1266 int j, rev, ret;
1267 struct bmac_data *bp; 1267 struct bmac_data *bp;
@@ -1645,16 +1645,13 @@ static int __devexit bmac_remove(struct macio_dev *mdev)
1645 return 0; 1645 return 0;
1646} 1646}
1647 1647
1648static struct of_match bmac_match[] = 1648static struct of_device_id bmac_match[] =
1649{ 1649{
1650 { 1650 {
1651 .name = "bmac", 1651 .name = "bmac",
1652 .type = OF_ANY_MATCH,
1653 .compatible = OF_ANY_MATCH,
1654 .data = (void *)0, 1652 .data = (void *)0,
1655 }, 1653 },
1656 { 1654 {
1657 .name = OF_ANY_MATCH,
1658 .type = "network", 1655 .type = "network",
1659 .compatible = "bmac+", 1656 .compatible = "bmac+",
1660 .data = (void *)1, 1657 .data = (void *)1,
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 6233c4ffb805..a2e8dda5afac 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2346,7 +2346,6 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2346{ 2346{
2347 struct slave *slave, *start_at; 2347 struct slave *slave, *start_at;
2348 struct bonding *bond = dev->priv; 2348 struct bonding *bond = dev->priv;
2349 struct ethhdr *data = (struct ethhdr *)skb->data;
2350 int slave_agg_no; 2349 int slave_agg_no;
2351 int slaves_in_agg; 2350 int slaves_in_agg;
2352 int agg_id; 2351 int agg_id;
@@ -2377,7 +2376,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2377 goto out; 2376 goto out;
2378 } 2377 }
2379 2378
2380 slave_agg_no = (data->h_dest[5]^bond->dev->dev_addr[5]) % slaves_in_agg; 2379 slave_agg_no = bond->xmit_hash_policy(skb, dev, slaves_in_agg);
2381 2380
2382 bond_for_each_slave(bond, slave, i) { 2381 bond_for_each_slave(bond, slave, i) {
2383 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; 2382 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 269a5e407349..2c930da90a85 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -475,7 +475,18 @@
475 * Solution is to move call to dev_remove_pack outside of the 475 * Solution is to move call to dev_remove_pack outside of the
476 * spinlock. 476 * spinlock.
477 * Set version to 2.6.1. 477 * Set version to 2.6.1.
478 * 478 * 2005/06/05 - Jay Vosburgh <fubar@us.ibm.com>
479 * - Support for generating gratuitous ARPs in active-backup mode.
480 * Includes support for VLAN tagging all bonding-generated ARPs
481 * as needed. Set version to 2.6.2.
482 * 2005/06/08 - Jason Gabler <jygabler at lbl dot gov>
483 * - alternate hashing policy support for mode 2
484 * * Added kernel parameter "xmit_hash_policy" to allow the selection
485 * of different hashing policies for mode 2. The original mode 2
486 * policy is the default, now found in xmit_hash_policy_layer2().
487 * * Added xmit_hash_policy_layer34()
488 * - Modified by Jay Vosburgh <fubar@us.ibm.com> to also support mode 4.
489 * Set version to 2.6.3.
479 */ 490 */
480 491
481//#define BONDING_DEBUG 1 492//#define BONDING_DEBUG 1
@@ -490,7 +501,10 @@
490#include <linux/ptrace.h> 501#include <linux/ptrace.h>
491#include <linux/ioport.h> 502#include <linux/ioport.h>
492#include <linux/in.h> 503#include <linux/in.h>
504#include <net/ip.h>
493#include <linux/ip.h> 505#include <linux/ip.h>
506#include <linux/tcp.h>
507#include <linux/udp.h>
494#include <linux/slab.h> 508#include <linux/slab.h>
495#include <linux/string.h> 509#include <linux/string.h>
496#include <linux/init.h> 510#include <linux/init.h>
@@ -519,6 +533,7 @@
519#include <linux/ethtool.h> 533#include <linux/ethtool.h>
520#include <linux/if_vlan.h> 534#include <linux/if_vlan.h>
521#include <linux/if_bonding.h> 535#include <linux/if_bonding.h>
536#include <net/route.h>
522#include "bonding.h" 537#include "bonding.h"
523#include "bond_3ad.h" 538#include "bond_3ad.h"
524#include "bond_alb.h" 539#include "bond_alb.h"
@@ -537,6 +552,7 @@ static int use_carrier = 1;
537static char *mode = NULL; 552static char *mode = NULL;
538static char *primary = NULL; 553static char *primary = NULL;
539static char *lacp_rate = NULL; 554static char *lacp_rate = NULL;
555static char *xmit_hash_policy = NULL;
540static int arp_interval = BOND_LINK_ARP_INTERV; 556static int arp_interval = BOND_LINK_ARP_INTERV;
541static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, }; 557static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
542 558
@@ -556,6 +572,8 @@ module_param(primary, charp, 0);
556MODULE_PARM_DESC(primary, "Primary network device to use"); 572MODULE_PARM_DESC(primary, "Primary network device to use");
557module_param(lacp_rate, charp, 0); 573module_param(lacp_rate, charp, 0);
558MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)"); 574MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner (slow/fast)");
575module_param(xmit_hash_policy, charp, 0);
576MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method : 0 for layer 2 (default), 1 for layer 3+4");
559module_param(arp_interval, int, 0); 577module_param(arp_interval, int, 0);
560MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds"); 578MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
561module_param_array(arp_ip_target, charp, NULL, 0); 579module_param_array(arp_ip_target, charp, NULL, 0);
@@ -574,8 +592,8 @@ static struct proc_dir_entry *bond_proc_dir = NULL;
574 592
575static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ; 593static u32 arp_target[BOND_MAX_ARP_TARGETS] = { 0, } ;
576static int arp_ip_count = 0; 594static int arp_ip_count = 0;
577static u32 my_ip = 0;
578static int bond_mode = BOND_MODE_ROUNDROBIN; 595static int bond_mode = BOND_MODE_ROUNDROBIN;
596static int xmit_hashtype= BOND_XMIT_POLICY_LAYER2;
579static int lacp_fast = 0; 597static int lacp_fast = 0;
580static int app_abi_ver = 0; 598static int app_abi_ver = 0;
581static int orig_app_abi_ver = -1; /* This is used to save the first ABI version 599static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
@@ -585,7 +603,6 @@ static int orig_app_abi_ver = -1; /* This is used to save the first ABI version
585 * command comes from an application using 603 * command comes from an application using
586 * another ABI version. 604 * another ABI version.
587 */ 605 */
588
589struct bond_parm_tbl { 606struct bond_parm_tbl {
590 char *modename; 607 char *modename;
591 int mode; 608 int mode;
@@ -608,9 +625,16 @@ static struct bond_parm_tbl bond_mode_tbl[] = {
608{ NULL, -1}, 625{ NULL, -1},
609}; 626};
610 627
628static struct bond_parm_tbl xmit_hashtype_tbl[] = {
629{ "layer2", BOND_XMIT_POLICY_LAYER2},
630{ "layer3+4", BOND_XMIT_POLICY_LAYER34},
631{ NULL, -1},
632};
633
611/*-------------------------- Forward declarations ---------------------------*/ 634/*-------------------------- Forward declarations ---------------------------*/
612 635
613static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode); 636static inline void bond_set_mode_ops(struct bonding *bond, int mode);
637static void bond_send_gratuitous_arp(struct bonding *bond);
614 638
615/*---------------------------- General routines -----------------------------*/ 639/*---------------------------- General routines -----------------------------*/
616 640
@@ -659,6 +683,7 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
659 683
660 INIT_LIST_HEAD(&vlan->vlan_list); 684 INIT_LIST_HEAD(&vlan->vlan_list);
661 vlan->vlan_id = vlan_id; 685 vlan->vlan_id = vlan_id;
686 vlan->vlan_ip = 0;
662 687
663 write_lock_bh(&bond->lock); 688 write_lock_bh(&bond->lock);
664 689
@@ -1468,16 +1493,6 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
1468 } 1493 }
1469 } 1494 }
1470 1495
1471 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1472 if (old_active) {
1473 bond_set_slave_inactive_flags(old_active);
1474 }
1475
1476 if (new_active) {
1477 bond_set_slave_active_flags(new_active);
1478 }
1479 }
1480
1481 if (USES_PRIMARY(bond->params.mode)) { 1496 if (USES_PRIMARY(bond->params.mode)) {
1482 bond_mc_swap(bond, new_active, old_active); 1497 bond_mc_swap(bond, new_active, old_active);
1483 } 1498 }
@@ -1488,6 +1503,17 @@ static void bond_change_active_slave(struct bonding *bond, struct slave *new_act
1488 } else { 1503 } else {
1489 bond->curr_active_slave = new_active; 1504 bond->curr_active_slave = new_active;
1490 } 1505 }
1506
1507 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1508 if (old_active) {
1509 bond_set_slave_inactive_flags(old_active);
1510 }
1511
1512 if (new_active) {
1513 bond_set_slave_active_flags(new_active);
1514 }
1515 bond_send_gratuitous_arp(bond);
1516 }
1491} 1517}
1492 1518
1493/** 1519/**
@@ -2694,15 +2720,180 @@ out:
2694 read_unlock(&bond->lock); 2720 read_unlock(&bond->lock);
2695} 2721}
2696 2722
2723
2724static u32 bond_glean_dev_ip(struct net_device *dev)
2725{
2726 struct in_device *idev;
2727 struct in_ifaddr *ifa;
2728 u32 addr = 0;
2729
2730 if (!dev)
2731 return 0;
2732
2733 rcu_read_lock();
2734 idev = __in_dev_get(dev);
2735 if (!idev)
2736 goto out;
2737
2738 ifa = idev->ifa_list;
2739 if (!ifa)
2740 goto out;
2741
2742 addr = ifa->ifa_local;
2743out:
2744 rcu_read_unlock();
2745 return addr;
2746}
2747
2748static int bond_has_ip(struct bonding *bond)
2749{
2750 struct vlan_entry *vlan, *vlan_next;
2751
2752 if (bond->master_ip)
2753 return 1;
2754
2755 if (list_empty(&bond->vlan_list))
2756 return 0;
2757
2758 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2759 vlan_list) {
2760 if (vlan->vlan_ip)
2761 return 1;
2762 }
2763
2764 return 0;
2765}
2766
2767/*
2768 * We go to the (large) trouble of VLAN tagging ARP frames because
2769 * switches in VLAN mode (especially if ports are configured as
2770 * "native" to a VLAN) might not pass non-tagged frames.
2771 */
2772static void bond_arp_send(struct net_device *slave_dev, int arp_op, u32 dest_ip, u32 src_ip, unsigned short vlan_id)
2773{
2774 struct sk_buff *skb;
2775
2776 dprintk("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
2777 slave_dev->name, dest_ip, src_ip, vlan_id);
2778
2779 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
2780 NULL, slave_dev->dev_addr, NULL);
2781
2782 if (!skb) {
2783 printk(KERN_ERR DRV_NAME ": ARP packet allocation failed\n");
2784 return;
2785 }
2786 if (vlan_id) {
2787 skb = vlan_put_tag(skb, vlan_id);
2788 if (!skb) {
2789 printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
2790 return;
2791 }
2792 }
2793 arp_xmit(skb);
2794}
2795
2796
2697static void bond_arp_send_all(struct bonding *bond, struct slave *slave) 2797static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2698{ 2798{
2699 int i; 2799 int i, vlan_id, rv;
2700 u32 *targets = bond->params.arp_targets; 2800 u32 *targets = bond->params.arp_targets;
2801 struct vlan_entry *vlan, *vlan_next;
2802 struct net_device *vlan_dev;
2803 struct flowi fl;
2804 struct rtable *rt;
2701 2805
2702 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) { 2806 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2703 arp_send(ARPOP_REQUEST, ETH_P_ARP, targets[i], slave->dev, 2807 dprintk("basa: target %x\n", targets[i]);
2704 my_ip, NULL, slave->dev->dev_addr, 2808 if (list_empty(&bond->vlan_list)) {
2705 NULL); 2809 dprintk("basa: empty vlan: arp_send\n");
2810 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2811 bond->master_ip, 0);
2812 continue;
2813 }
2814
2815 /*
2816 * If VLANs are configured, we do a route lookup to
2817 * determine which VLAN interface would be used, so we
2818 * can tag the ARP with the proper VLAN tag.
2819 */
2820 memset(&fl, 0, sizeof(fl));
2821 fl.fl4_dst = targets[i];
2822 fl.fl4_tos = RTO_ONLINK;
2823
2824 rv = ip_route_output_key(&rt, &fl);
2825 if (rv) {
2826 if (net_ratelimit()) {
2827 printk(KERN_WARNING DRV_NAME
2828 ": %s: no route to arp_ip_target %u.%u.%u.%u\n",
2829 bond->dev->name, NIPQUAD(fl.fl4_dst));
2830 }
2831 continue;
2832 }
2833
2834 /*
2835 * This target is not on a VLAN
2836 */
2837 if (rt->u.dst.dev == bond->dev) {
2838 dprintk("basa: rtdev == bond->dev: arp_send\n");
2839 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2840 bond->master_ip, 0);
2841 continue;
2842 }
2843
2844 vlan_id = 0;
2845 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
2846 vlan_list) {
2847 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
2848 if (vlan_dev == rt->u.dst.dev) {
2849 vlan_id = vlan->vlan_id;
2850 dprintk("basa: vlan match on %s %d\n",
2851 vlan_dev->name, vlan_id);
2852 break;
2853 }
2854 }
2855
2856 if (vlan_id) {
2857 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2858 vlan->vlan_ip, vlan_id);
2859 continue;
2860 }
2861
2862 if (net_ratelimit()) {
2863 printk(KERN_WARNING DRV_NAME
2864 ": %s: no path to arp_ip_target %u.%u.%u.%u via rt.dev %s\n",
2865 bond->dev->name, NIPQUAD(fl.fl4_dst),
2866 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
2867 }
2868 }
2869}
2870
2871/*
2872 * Kick out a gratuitous ARP for an IP on the bonding master plus one
2873 * for each VLAN above us.
2874 */
2875static void bond_send_gratuitous_arp(struct bonding *bond)
2876{
2877 struct slave *slave = bond->curr_active_slave;
2878 struct vlan_entry *vlan;
2879 struct net_device *vlan_dev;
2880
2881 dprintk("bond_send_grat_arp: bond %s slave %s\n", bond->dev->name,
2882 slave ? slave->dev->name : "NULL");
2883 if (!slave)
2884 return;
2885
2886 if (bond->master_ip) {
2887 bond_arp_send(slave->dev, ARPOP_REPLY, bond->master_ip,
2888 bond->master_ip, 0);
2889 }
2890
2891 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2892 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
2893 if (vlan->vlan_ip) {
2894 bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip,
2895 vlan->vlan_ip, vlan->vlan_id);
2896 }
2706 } 2897 }
2707} 2898}
2708 2899
@@ -2781,7 +2972,7 @@ static void bond_loadbalance_arp_mon(struct net_device *bond_dev)
2781 */ 2972 */
2782 if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 2973 if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
2783 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 2974 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
2784 my_ip)) { 2975 bond_has_ip(bond))) {
2785 2976
2786 slave->link = BOND_LINK_DOWN; 2977 slave->link = BOND_LINK_DOWN;
2787 slave->state = BOND_STATE_BACKUP; 2978 slave->state = BOND_STATE_BACKUP;
@@ -2920,7 +3111,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
2920 if ((slave != bond->curr_active_slave) && 3111 if ((slave != bond->curr_active_slave) &&
2921 (!bond->current_arp_slave) && 3112 (!bond->current_arp_slave) &&
2922 (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) && 3113 (((jiffies - slave->dev->last_rx) >= 3*delta_in_ticks) &&
2923 my_ip)) { 3114 bond_has_ip(bond))) {
2924 /* a backup slave has gone down; three times 3115 /* a backup slave has gone down; three times
2925 * the delta allows the current slave to be 3116 * the delta allows the current slave to be
2926 * taken out before the backup slave. 3117 * taken out before the backup slave.
@@ -2966,8 +3157,8 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
2966 * if it is up and needs to take over as the curr_active_slave 3157 * if it is up and needs to take over as the curr_active_slave
2967 */ 3158 */
2968 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 3159 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) ||
2969 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 3160 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) &&
2970 my_ip)) && 3161 bond_has_ip(bond))) &&
2971 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) { 3162 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) {
2972 3163
2973 slave->link = BOND_LINK_DOWN; 3164 slave->link = BOND_LINK_DOWN;
@@ -3019,7 +3210,7 @@ static void bond_activebackup_arp_mon(struct net_device *bond_dev)
3019 /* the current slave must tx an arp to ensure backup slaves 3210 /* the current slave must tx an arp to ensure backup slaves
3020 * rx traffic 3211 * rx traffic
3021 */ 3212 */
3022 if (slave && my_ip) { 3213 if (slave && bond_has_ip(bond)) {
3023 bond_arp_send_all(bond, slave); 3214 bond_arp_send_all(bond, slave);
3024 } 3215 }
3025 } 3216 }
@@ -3471,10 +3662,67 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
3471 return NOTIFY_DONE; 3662 return NOTIFY_DONE;
3472} 3663}
3473 3664
3665/*
3666 * bond_inetaddr_event: handle inetaddr notifier chain events.
3667 *
3668 * We keep track of device IPs primarily to use as source addresses in
3669 * ARP monitor probes (rather than spewing out broadcasts all the time).
3670 *
3671 * We track one IP for the main device (if it has one), plus one per VLAN.
3672 */
3673static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
3674{
3675 struct in_ifaddr *ifa = ptr;
3676 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
3677 struct bonding *bond, *bond_next;
3678 struct vlan_entry *vlan, *vlan_next;
3679
3680 list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) {
3681 if (bond->dev == event_dev) {
3682 switch (event) {
3683 case NETDEV_UP:
3684 bond->master_ip = ifa->ifa_local;
3685 return NOTIFY_OK;
3686 case NETDEV_DOWN:
3687 bond->master_ip = bond_glean_dev_ip(bond->dev);
3688 return NOTIFY_OK;
3689 default:
3690 return NOTIFY_DONE;
3691 }
3692 }
3693
3694 if (list_empty(&bond->vlan_list))
3695 continue;
3696
3697 list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list,
3698 vlan_list) {
3699 vlan_dev = bond->vlgrp->vlan_devices[vlan->vlan_id];
3700 if (vlan_dev == event_dev) {
3701 switch (event) {
3702 case NETDEV_UP:
3703 vlan->vlan_ip = ifa->ifa_local;
3704 return NOTIFY_OK;
3705 case NETDEV_DOWN:
3706 vlan->vlan_ip =
3707 bond_glean_dev_ip(vlan_dev);
3708 return NOTIFY_OK;
3709 default:
3710 return NOTIFY_DONE;
3711 }
3712 }
3713 }
3714 }
3715 return NOTIFY_DONE;
3716}
3717
3474static struct notifier_block bond_netdev_notifier = { 3718static struct notifier_block bond_netdev_notifier = {
3475 .notifier_call = bond_netdev_event, 3719 .notifier_call = bond_netdev_event,
3476}; 3720};
3477 3721
3722static struct notifier_block bond_inetaddr_notifier = {
3723 .notifier_call = bond_inetaddr_event,
3724};
3725
3478/*-------------------------- Packet type handling ---------------------------*/ 3726/*-------------------------- Packet type handling ---------------------------*/
3479 3727
3480/* register to receive lacpdus on a bond */ 3728/* register to receive lacpdus on a bond */
@@ -3496,6 +3744,46 @@ static void bond_unregister_lacpdu(struct bonding *bond)
3496 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type)); 3744 dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type));
3497} 3745}
3498 3746
3747/*---------------------------- Hashing Policies -----------------------------*/
3748
3749/*
3750 * Hash for the the output device based upon layer 3 and layer 4 data. If
3751 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3752 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3753 */
3754static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
3755 struct net_device *bond_dev, int count)
3756{
3757 struct ethhdr *data = (struct ethhdr *)skb->data;
3758 struct iphdr *iph = skb->nh.iph;
3759 u16 *layer4hdr = (u16 *)((u32 *)iph + iph->ihl);
3760 int layer4_xor = 0;
3761
3762 if (skb->protocol == __constant_htons(ETH_P_IP)) {
3763 if (!(iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) &&
3764 (iph->protocol == IPPROTO_TCP ||
3765 iph->protocol == IPPROTO_UDP)) {
3766 layer4_xor = htons((*layer4hdr ^ *(layer4hdr + 1)));
3767 }
3768 return (layer4_xor ^
3769 ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
3770
3771 }
3772
3773 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
3774}
3775
3776/*
3777 * Hash for the output device based upon layer 2 data
3778 */
3779static int bond_xmit_hash_policy_l2(struct sk_buff *skb,
3780 struct net_device *bond_dev, int count)
3781{
3782 struct ethhdr *data = (struct ethhdr *)skb->data;
3783
3784 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
3785}
3786
3499/*-------------------------- Device entry points ----------------------------*/ 3787/*-------------------------- Device entry points ----------------------------*/
3500 3788
3501static int bond_open(struct net_device *bond_dev) 3789static int bond_open(struct net_device *bond_dev)
@@ -4060,17 +4348,6 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
4060 struct bonding *bond = bond_dev->priv; 4348 struct bonding *bond = bond_dev->priv;
4061 int res = 1; 4349 int res = 1;
4062 4350
4063 /* if we are sending arp packets, try to at least
4064 identify our own ip address */
4065 if (bond->params.arp_interval && !my_ip &&
4066 (skb->protocol == __constant_htons(ETH_P_ARP))) {
4067 char *the_ip = (char *)skb->data +
4068 sizeof(struct ethhdr) +
4069 sizeof(struct arphdr) +
4070 ETH_ALEN;
4071 memcpy(&my_ip, the_ip, 4);
4072 }
4073
4074 read_lock(&bond->lock); 4351 read_lock(&bond->lock);
4075 read_lock(&bond->curr_slave_lock); 4352 read_lock(&bond->curr_slave_lock);
4076 4353
@@ -4093,14 +4370,13 @@ out:
4093} 4370}
4094 4371
4095/* 4372/*
4096 * in XOR mode, we determine the output device by performing xor on 4373 * In bond_xmit_xor() , we determine the output device by using a pre-
4097 * the source and destination hw adresses. If this device is not 4374 * determined xmit_hash_policy(), If the selected device is not enabled,
4098 * enabled, find the next slave following this xor slave. 4375 * find the next active slave.
4099 */ 4376 */
4100static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) 4377static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4101{ 4378{
4102 struct bonding *bond = bond_dev->priv; 4379 struct bonding *bond = bond_dev->priv;
4103 struct ethhdr *data = (struct ethhdr *)skb->data;
4104 struct slave *slave, *start_at; 4380 struct slave *slave, *start_at;
4105 int slave_no; 4381 int slave_no;
4106 int i; 4382 int i;
@@ -4112,7 +4388,7 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4112 goto out; 4388 goto out;
4113 } 4389 }
4114 4390
4115 slave_no = (data->h_dest[5]^bond_dev->dev_addr[5]) % bond->slave_cnt; 4391 slave_no = bond->xmit_hash_policy(skb, bond_dev, bond->slave_cnt);
4116 4392
4117 bond_for_each_slave(bond, slave, i) { 4393 bond_for_each_slave(bond, slave, i) {
4118 slave_no--; 4394 slave_no--;
@@ -4208,8 +4484,10 @@ out:
4208/* 4484/*
4209 * set bond mode specific net device operations 4485 * set bond mode specific net device operations
4210 */ 4486 */
4211static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode) 4487static inline void bond_set_mode_ops(struct bonding *bond, int mode)
4212{ 4488{
4489 struct net_device *bond_dev = bond->dev;
4490
4213 switch (mode) { 4491 switch (mode) {
4214 case BOND_MODE_ROUNDROBIN: 4492 case BOND_MODE_ROUNDROBIN:
4215 bond_dev->hard_start_xmit = bond_xmit_roundrobin; 4493 bond_dev->hard_start_xmit = bond_xmit_roundrobin;
@@ -4219,12 +4497,20 @@ static inline void bond_set_mode_ops(struct net_device *bond_dev, int mode)
4219 break; 4497 break;
4220 case BOND_MODE_XOR: 4498 case BOND_MODE_XOR:
4221 bond_dev->hard_start_xmit = bond_xmit_xor; 4499 bond_dev->hard_start_xmit = bond_xmit_xor;
4500 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
4501 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4502 else
4503 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4222 break; 4504 break;
4223 case BOND_MODE_BROADCAST: 4505 case BOND_MODE_BROADCAST:
4224 bond_dev->hard_start_xmit = bond_xmit_broadcast; 4506 bond_dev->hard_start_xmit = bond_xmit_broadcast;
4225 break; 4507 break;
4226 case BOND_MODE_8023AD: 4508 case BOND_MODE_8023AD:
4227 bond_dev->hard_start_xmit = bond_3ad_xmit_xor; 4509 bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
4510 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
4511 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4512 else
4513 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4228 break; 4514 break;
4229 case BOND_MODE_TLB: 4515 case BOND_MODE_TLB:
4230 case BOND_MODE_ALB: 4516 case BOND_MODE_ALB:
@@ -4273,7 +4559,7 @@ static int __init bond_init(struct net_device *bond_dev, struct bond_params *par
4273 bond_dev->change_mtu = bond_change_mtu; 4559 bond_dev->change_mtu = bond_change_mtu;
4274 bond_dev->set_mac_address = bond_set_mac_address; 4560 bond_dev->set_mac_address = bond_set_mac_address;
4275 4561
4276 bond_set_mode_ops(bond_dev, bond->params.mode); 4562 bond_set_mode_ops(bond, bond->params.mode);
4277 4563
4278 bond_dev->destructor = free_netdev; 4564 bond_dev->destructor = free_netdev;
4279 4565
@@ -4384,6 +4670,25 @@ static int bond_check_params(struct bond_params *params)
4384 } 4670 }
4385 } 4671 }
4386 4672
4673 if (xmit_hash_policy) {
4674 if ((bond_mode != BOND_MODE_XOR) &&
4675 (bond_mode != BOND_MODE_8023AD)) {
4676 printk(KERN_INFO DRV_NAME
4677 ": xor_mode param is irrelevant in mode %s\n",
4678 bond_mode_name(bond_mode));
4679 } else {
4680 xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4681 xmit_hashtype_tbl);
4682 if (xmit_hashtype == -1) {
4683 printk(KERN_ERR DRV_NAME
4684 ": Error: Invalid xmit_hash_policy \"%s\"\n",
4685 xmit_hash_policy == NULL ? "NULL" :
4686 xmit_hash_policy);
4687 return -EINVAL;
4688 }
4689 }
4690 }
4691
4387 if (lacp_rate) { 4692 if (lacp_rate) {
4388 if (bond_mode != BOND_MODE_8023AD) { 4693 if (bond_mode != BOND_MODE_8023AD) {
4389 printk(KERN_INFO DRV_NAME 4694 printk(KERN_INFO DRV_NAME
@@ -4595,6 +4900,7 @@ static int bond_check_params(struct bond_params *params)
4595 4900
4596 /* fill params struct with the proper values */ 4901 /* fill params struct with the proper values */
4597 params->mode = bond_mode; 4902 params->mode = bond_mode;
4903 params->xmit_policy = xmit_hashtype;
4598 params->miimon = miimon; 4904 params->miimon = miimon;
4599 params->arp_interval = arp_interval; 4905 params->arp_interval = arp_interval;
4600 params->updelay = updelay; 4906 params->updelay = updelay;
@@ -4669,6 +4975,7 @@ static int __init bonding_init(void)
4669 4975
4670 rtnl_unlock(); 4976 rtnl_unlock();
4671 register_netdevice_notifier(&bond_netdev_notifier); 4977 register_netdevice_notifier(&bond_netdev_notifier);
4978 register_inetaddr_notifier(&bond_inetaddr_notifier);
4672 4979
4673 return 0; 4980 return 0;
4674 4981
@@ -4684,6 +4991,7 @@ out_err:
4684static void __exit bonding_exit(void) 4991static void __exit bonding_exit(void)
4685{ 4992{
4686 unregister_netdevice_notifier(&bond_netdev_notifier); 4993 unregister_netdevice_notifier(&bond_netdev_notifier);
4994 unregister_inetaddr_notifier(&bond_inetaddr_notifier);
4687 4995
4688 rtnl_lock(); 4996 rtnl_lock();
4689 bond_free_all(); 4997 bond_free_all();
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 8c325308489d..d27f377b3eeb 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -25,6 +25,10 @@
25 * 25 *
26 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com> 26 * 2003/12/01 - Shmulik Hen <shmulik.hen at intel dot com>
27 * - Code cleanup and style changes 27 * - Code cleanup and style changes
28 *
29 * 2005/05/05 - Jason Gabler <jygabler at lbl dot gov>
30 * - added "xmit_policy" kernel parameter for alternate hashing policy
31 * support for mode 2
28 */ 32 */
29 33
30#ifndef _LINUX_BONDING_H 34#ifndef _LINUX_BONDING_H
@@ -36,8 +40,8 @@
36#include "bond_3ad.h" 40#include "bond_3ad.h"
37#include "bond_alb.h" 41#include "bond_alb.h"
38 42
39#define DRV_VERSION "2.6.1" 43#define DRV_VERSION "2.6.3"
40#define DRV_RELDATE "October 29, 2004" 44#define DRV_RELDATE "June 8, 2005"
41#define DRV_NAME "bonding" 45#define DRV_NAME "bonding"
42#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 46#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
43 47
@@ -137,6 +141,7 @@
137 141
138struct bond_params { 142struct bond_params {
139 int mode; 143 int mode;
144 int xmit_policy;
140 int miimon; 145 int miimon;
141 int arp_interval; 146 int arp_interval;
142 int use_carrier; 147 int use_carrier;
@@ -149,6 +154,7 @@ struct bond_params {
149 154
150struct vlan_entry { 155struct vlan_entry {
151 struct list_head vlan_list; 156 struct list_head vlan_list;
157 u32 vlan_ip;
152 unsigned short vlan_id; 158 unsigned short vlan_id;
153}; 159};
154 160
@@ -197,6 +203,8 @@ struct bonding {
197#endif /* CONFIG_PROC_FS */ 203#endif /* CONFIG_PROC_FS */
198 struct list_head bond_list; 204 struct list_head bond_list;
199 struct dev_mc_list *mc_list; 205 struct dev_mc_list *mc_list;
206 int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
207 u32 master_ip;
200 u16 flags; 208 u16 flags;
201 struct ad_bond_info ad_info; 209 struct ad_bond_info ad_info;
202 struct alb_bond_info alb_info; 210 struct alb_bond_info alb_info;
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 5c5f540da26a..b96d6fb1929e 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -174,6 +174,13 @@ static unsigned int cs8900_irq_map[] = {1,0,0,0};
174#include <asm/irq.h> 174#include <asm/irq.h>
175static unsigned int netcard_portlist[] __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0}; 175static unsigned int netcard_portlist[] __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0};
176static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0}; 176static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0};
177#elif defined(CONFIG_ARCH_PNX0105)
178#include <asm/irq.h>
179#include <asm/arch/gpio.h>
180#define CIRRUS_DEFAULT_BASE IO_ADDRESS(EXT_STATIC2_s0_BASE + 0x200000) /* = Physical address 0x48200000 */
181#define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */
182static unsigned int netcard_portlist[] __initdata = {CIRRUS_DEFAULT_BASE, 0};
183static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0};
177#else 184#else
178static unsigned int netcard_portlist[] __initdata = 185static unsigned int netcard_portlist[] __initdata =
179 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0}; 186 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
@@ -319,13 +326,7 @@ struct net_device * __init cs89x0_probe(int unit)
319 } 326 }
320 if (err) 327 if (err)
321 goto out; 328 goto out;
322 err = register_netdev(dev);
323 if (err)
324 goto out1;
325 return dev; 329 return dev;
326out1:
327 outw(PP_ChipID, dev->base_addr + ADD_PORT);
328 release_region(dev->base_addr, NETCARD_IO_EXTENT);
329out: 330out:
330 free_netdev(dev); 331 free_netdev(dev);
331 printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n"); 332 printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
@@ -437,6 +438,30 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
437#endif 438#endif
438 } 439 }
439 440
441#ifdef CONFIG_ARCH_PNX0105
442 initialize_ebi();
443
444 /* Map GPIO registers for the pins connected to the CS8900a. */
445 if (map_cirrus_gpio() < 0)
446 return -ENODEV;
447
448 reset_cirrus();
449
450 /* Map event-router registers. */
451 if (map_event_router() < 0)
452 return -ENODEV;
453
454 enable_cirrus_irq();
455
456 unmap_cirrus_gpio();
457 unmap_event_router();
458
459 dev->base_addr = ioaddr;
460
461 for (i = 0 ; i < 3 ; i++)
462 readreg(dev, 0);
463#endif
464
440 /* Grab the region so we can find another board if autoIRQ fails. */ 465 /* Grab the region so we can find another board if autoIRQ fails. */
441 /* WTF is going on here? */ 466 /* WTF is going on here? */
442 if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) { 467 if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) {
@@ -678,7 +703,7 @@ printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
678 } else { 703 } else {
679 i = lp->isa_config & INT_NO_MASK; 704 i = lp->isa_config & INT_NO_MASK;
680 if (lp->chip_type == CS8900) { 705 if (lp->chip_type == CS8900) {
681#ifdef CONFIG_ARCH_IXDP2X01 706#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105)
682 i = cs8900_irq_map[0]; 707 i = cs8900_irq_map[0];
683#else 708#else
684 /* Translate the IRQ using the IRQ mapping table. */ 709 /* Translate the IRQ using the IRQ mapping table. */
@@ -735,7 +760,13 @@ printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
735 printk("\n"); 760 printk("\n");
736 if (net_debug) 761 if (net_debug)
737 printk("cs89x0_probe1() successful\n"); 762 printk("cs89x0_probe1() successful\n");
763
764 retval = register_netdev(dev);
765 if (retval)
766 goto out3;
738 return 0; 767 return 0;
768out3:
769 outw(PP_ChipID, dev->base_addr + ADD_PORT);
739out2: 770out2:
740 release_region(ioaddr & ~3, NETCARD_IO_EXTENT); 771 release_region(ioaddr & ~3, NETCARD_IO_EXTENT);
741out1: 772out1:
@@ -1145,7 +1176,7 @@ net_open(struct net_device *dev)
1145 int i; 1176 int i;
1146 int ret; 1177 int ret;
1147 1178
1148#ifndef CONFIG_SH_HICOSH4 /* uses irq#1, so this won't work */ 1179#if !defined(CONFIG_SH_HICOSH4) && !defined(CONFIG_ARCH_PNX0105) /* uses irq#1, so this won't work */
1149 if (dev->irq < 2) { 1180 if (dev->irq < 2) {
1150 /* Allow interrupts to be generated by the chip */ 1181 /* Allow interrupts to be generated by the chip */
1151/* Cirrus' release had this: */ 1182/* Cirrus' release had this: */
@@ -1176,7 +1207,7 @@ net_open(struct net_device *dev)
1176 else 1207 else
1177#endif 1208#endif
1178 { 1209 {
1179#ifndef CONFIG_ARCH_IXDP2X01 1210#if !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX0105)
1180 if (((1 << dev->irq) & lp->irq_map) == 0) { 1211 if (((1 << dev->irq) & lp->irq_map) == 0) {
1181 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n", 1212 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
1182 dev->name, dev->irq, lp->irq_map); 1213 dev->name, dev->irq, lp->irq_map);
@@ -1261,6 +1292,9 @@ net_open(struct net_device *dev)
1261 case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break; 1292 case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
1262 default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2); 1293 default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
1263 } 1294 }
1295#ifdef CONFIG_ARCH_PNX0105
1296 result = A_CNF_10B_T;
1297#endif
1264 if (!result) { 1298 if (!result) {
1265 printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name); 1299 printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name);
1266 release_irq: 1300 release_irq:
@@ -1831,13 +1865,6 @@ init_module(void)
1831 if (ret) 1865 if (ret)
1832 goto out; 1866 goto out;
1833 1867
1834 if (register_netdev(dev) != 0) {
1835 printk(KERN_ERR "cs89x0.c: No card found at 0x%x\n", io);
1836 ret = -ENXIO;
1837 outw(PP_ChipID, dev->base_addr + ADD_PORT);
1838 release_region(dev->base_addr, NETCARD_IO_EXTENT);
1839 goto out;
1840 }
1841 dev_cs89x0 = dev; 1868 dev_cs89x0 = dev;
1842 return 0; 1869 return 0;
1843out: 1870out:
diff --git a/drivers/net/cs89x0.h b/drivers/net/cs89x0.h
index b0ef7ad2baad..bd3ad8e6cce9 100644
--- a/drivers/net/cs89x0.h
+++ b/drivers/net/cs89x0.h
@@ -16,7 +16,7 @@
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18 18
19#ifdef CONFIG_ARCH_IXDP2X01 19#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105)
20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */ 20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */
21#define CS89x0_PORT(reg) ((reg) * 2) 21#define CS89x0_PORT(reg) ((reg) * 2)
22#else 22#else
diff --git a/drivers/net/defxx.c b/drivers/net/defxx.c
index a6aa56598f27..5acd35c312ac 100644
--- a/drivers/net/defxx.c
+++ b/drivers/net/defxx.c
@@ -191,6 +191,7 @@
191 * Feb 2001 davej PCI enable cleanups. 191 * Feb 2001 davej PCI enable cleanups.
192 * 04 Aug 2003 macro Converted to the DMA API. 192 * 04 Aug 2003 macro Converted to the DMA API.
193 * 14 Aug 2004 macro Fix device names reported. 193 * 14 Aug 2004 macro Fix device names reported.
194 * 14 Jun 2005 macro Use irqreturn_t.
194 */ 195 */
195 196
196/* Include files */ 197/* Include files */
@@ -217,8 +218,8 @@
217 218
218/* Version information string should be updated prior to each new release! */ 219/* Version information string should be updated prior to each new release! */
219#define DRV_NAME "defxx" 220#define DRV_NAME "defxx"
220#define DRV_VERSION "v1.07" 221#define DRV_VERSION "v1.08"
221#define DRV_RELDATE "2004/08/14" 222#define DRV_RELDATE "2005/06/14"
222 223
223static char version[] __devinitdata = 224static char version[] __devinitdata =
224 DRV_NAME ": " DRV_VERSION " " DRV_RELDATE 225 DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
@@ -247,7 +248,8 @@ static int dfx_close(struct net_device *dev);
247static void dfx_int_pr_halt_id(DFX_board_t *bp); 248static void dfx_int_pr_halt_id(DFX_board_t *bp);
248static void dfx_int_type_0_process(DFX_board_t *bp); 249static void dfx_int_type_0_process(DFX_board_t *bp);
249static void dfx_int_common(struct net_device *dev); 250static void dfx_int_common(struct net_device *dev);
250static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs); 251static irqreturn_t dfx_interrupt(int irq, void *dev_id,
252 struct pt_regs *regs);
251 253
252static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev); 254static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
253static void dfx_ctl_set_multicast_list(struct net_device *dev); 255static void dfx_ctl_set_multicast_list(struct net_device *dev);
@@ -437,7 +439,8 @@ static int __devinit dfx_init_one_pci_or_eisa(struct pci_dev *pdev, long ioaddr)
437 } 439 }
438 440
439 SET_MODULE_OWNER(dev); 441 SET_MODULE_OWNER(dev);
440 SET_NETDEV_DEV(dev, &pdev->dev); 442 if (pdev != NULL)
443 SET_NETDEV_DEV(dev, &pdev->dev);
441 444
442 bp = dev->priv; 445 bp = dev->priv;
443 446
@@ -1225,7 +1228,7 @@ static int dfx_open(struct net_device *dev)
1225 1228
1226 /* Register IRQ - support shared interrupts by passing device ptr */ 1229 /* Register IRQ - support shared interrupts by passing device ptr */
1227 1230
1228 ret = request_irq(dev->irq, (void *)dfx_interrupt, SA_SHIRQ, dev->name, dev); 1231 ret = request_irq(dev->irq, dfx_interrupt, SA_SHIRQ, dev->name, dev);
1229 if (ret) { 1232 if (ret) {
1230 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq); 1233 printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
1231 return ret; 1234 return ret;
@@ -1680,13 +1683,13 @@ static void dfx_int_common(struct net_device *dev)
1680 * ================= 1683 * =================
1681 * = dfx_interrupt = 1684 * = dfx_interrupt =
1682 * ================= 1685 * =================
1683 * 1686 *
1684 * Overview: 1687 * Overview:
1685 * Interrupt processing routine 1688 * Interrupt processing routine
1686 * 1689 *
1687 * Returns: 1690 * Returns:
1688 * None 1691 * Whether a valid interrupt was seen.
1689 * 1692 *
1690 * Arguments: 1693 * Arguments:
1691 * irq - interrupt vector 1694 * irq - interrupt vector
1692 * dev_id - pointer to device information 1695 * dev_id - pointer to device information
@@ -1699,7 +1702,8 @@ static void dfx_int_common(struct net_device *dev)
1699 * structure context. 1702 * structure context.
1700 * 1703 *
1701 * Return Codes: 1704 * Return Codes:
1702 * None 1705 * IRQ_HANDLED - an IRQ was handled.
1706 * IRQ_NONE - no IRQ was handled.
1703 * 1707 *
1704 * Assumptions: 1708 * Assumptions:
1705 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC 1709 * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
@@ -1712,60 +1716,70 @@ static void dfx_int_common(struct net_device *dev)
1712 * Interrupts are disabled, then reenabled at the adapter. 1716 * Interrupts are disabled, then reenabled at the adapter.
1713 */ 1717 */
1714 1718
1715static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1719static irqreturn_t dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1716 { 1720{
1717 struct net_device *dev = dev_id; 1721 struct net_device *dev = dev_id;
1718 DFX_board_t *bp; /* private board structure pointer */ 1722 DFX_board_t *bp; /* private board structure pointer */
1719 u8 tmp; /* used for disabling/enabling ints */
1720 1723
1721 /* Get board pointer only if device structure is valid */ 1724 /* Get board pointer only if device structure is valid */
1722 1725
1723 bp = dev->priv; 1726 bp = dev->priv;
1724 1727
1725 spin_lock(&bp->lock);
1726
1727 /* See if we're already servicing an interrupt */ 1728 /* See if we're already servicing an interrupt */
1728 1729
1729 /* Service adapter interrupts */ 1730 /* Service adapter interrupts */
1730 1731
1731 if (bp->bus_type == DFX_BUS_TYPE_PCI) 1732 if (bp->bus_type == DFX_BUS_TYPE_PCI) {
1732 { 1733 u32 status;
1733 /* Disable PDQ-PFI interrupts at PFI */
1734 1734
1735 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, PFI_MODE_M_DMA_ENB); 1735 dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
1736 if (!(status & PFI_STATUS_M_PDQ_INT))
1737 return IRQ_NONE;
1736 1738
1737 /* Call interrupt service routine for this adapter */ 1739 spin_lock(&bp->lock);
1740
1741 /* Disable PDQ-PFI interrupts at PFI */
1742 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1743 PFI_MODE_M_DMA_ENB);
1738 1744
1745 /* Call interrupt service routine for this adapter */
1739 dfx_int_common(dev); 1746 dfx_int_common(dev);
1740 1747
1741 /* Clear PDQ interrupt status bit and reenable interrupts */ 1748 /* Clear PDQ interrupt status bit and reenable interrupts */
1742 1749 dfx_port_write_long(bp, PFI_K_REG_STATUS,
1743 dfx_port_write_long(bp, PFI_K_REG_STATUS, PFI_STATUS_M_PDQ_INT); 1750 PFI_STATUS_M_PDQ_INT);
1744 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 1751 dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1745 (PFI_MODE_M_PDQ_INT_ENB + PFI_MODE_M_DMA_ENB)); 1752 (PFI_MODE_M_PDQ_INT_ENB |
1746 } 1753 PFI_MODE_M_DMA_ENB));
1747 else
1748 {
1749 /* Disable interrupts at the ESIC */
1750 1754
1751 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp); 1755 spin_unlock(&bp->lock);
1752 tmp &= ~PI_CONFIG_STAT_0_M_INT_ENB; 1756 } else {
1753 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp); 1757 u8 status;
1754 1758
1755 /* Call interrupt service routine for this adapter */ 1759 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &status);
1760 if (!(status & PI_CONFIG_STAT_0_M_PEND))
1761 return IRQ_NONE;
1756 1762
1763 spin_lock(&bp->lock);
1764
1765 /* Disable interrupts at the ESIC */
1766 status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
1767 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, status);
1768
1769 /* Call interrupt service routine for this adapter */
1757 dfx_int_common(dev); 1770 dfx_int_common(dev);
1758 1771
1759 /* Reenable interrupts at the ESIC */ 1772 /* Reenable interrupts at the ESIC */
1773 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &status);
1774 status |= PI_CONFIG_STAT_0_M_INT_ENB;
1775 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, status);
1760 1776
1761 dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp); 1777 spin_unlock(&bp->lock);
1762 tmp |= PI_CONFIG_STAT_0_M_INT_ENB;
1763 dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1764 }
1765
1766 spin_unlock(&bp->lock);
1767 } 1778 }
1768 1779
1780 return IRQ_HANDLED;
1781}
1782
1769 1783
1770/* 1784/*
1771 * ===================== 1785 * =====================
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index aa42b7a27735..430c628279b3 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -547,7 +547,7 @@ rio_timer (unsigned long data)
547 skb_reserve (skb, 2); 547 skb_reserve (skb, 2);
548 np->rx_ring[entry].fraginfo = 548 np->rx_ring[entry].fraginfo =
549 cpu_to_le64 (pci_map_single 549 cpu_to_le64 (pci_map_single
550 (np->pdev, skb->tail, np->rx_buf_sz, 550 (np->pdev, skb->data, np->rx_buf_sz,
551 PCI_DMA_FROMDEVICE)); 551 PCI_DMA_FROMDEVICE));
552 } 552 }
553 np->rx_ring[entry].fraginfo |= 553 np->rx_ring[entry].fraginfo |=
@@ -618,7 +618,7 @@ alloc_list (struct net_device *dev)
618 /* Rubicon now supports 40 bits of addressing space. */ 618 /* Rubicon now supports 40 bits of addressing space. */
619 np->rx_ring[i].fraginfo = 619 np->rx_ring[i].fraginfo =
620 cpu_to_le64 ( pci_map_single ( 620 cpu_to_le64 ( pci_map_single (
621 np->pdev, skb->tail, np->rx_buf_sz, 621 np->pdev, skb->data, np->rx_buf_sz,
622 PCI_DMA_FROMDEVICE)); 622 PCI_DMA_FROMDEVICE));
623 np->rx_ring[i].fraginfo |= cpu_to_le64 (np->rx_buf_sz) << 48; 623 np->rx_ring[i].fraginfo |= cpu_to_le64 (np->rx_buf_sz) << 48;
624 } 624 }
@@ -906,7 +906,7 @@ receive_packet (struct net_device *dev)
906 /* 16 byte align the IP header */ 906 /* 16 byte align the IP header */
907 skb_reserve (skb, 2); 907 skb_reserve (skb, 2);
908 eth_copy_and_sum (skb, 908 eth_copy_and_sum (skb,
909 np->rx_skbuff[entry]->tail, 909 np->rx_skbuff[entry]->data,
910 pkt_len, 0); 910 pkt_len, 0);
911 skb_put (skb, pkt_len); 911 skb_put (skb, pkt_len);
912 pci_dma_sync_single_for_device(np->pdev, 912 pci_dma_sync_single_for_device(np->pdev,
@@ -950,7 +950,7 @@ receive_packet (struct net_device *dev)
950 skb_reserve (skb, 2); 950 skb_reserve (skb, 2);
951 np->rx_ring[entry].fraginfo = 951 np->rx_ring[entry].fraginfo =
952 cpu_to_le64 (pci_map_single 952 cpu_to_le64 (pci_map_single
953 (np->pdev, skb->tail, np->rx_buf_sz, 953 (np->pdev, skb->data, np->rx_buf_sz,
954 PCI_DMA_FROMDEVICE)); 954 PCI_DMA_FROMDEVICE));
955 } 955 }
956 np->rx_ring[entry].fraginfo |= 956 np->rx_ring[entry].fraginfo |=
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index f4ba0ffb8637..5fddc0ff8878 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -224,7 +224,7 @@ static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count)
224 224
225static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count) 225static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count)
226{ 226{
227 readsb(reg, data, count+1); 227 readsb(reg, data, count);
228} 228}
229 229
230 230
@@ -364,7 +364,7 @@ dm9000_release_board(struct platform_device *pdev, struct board_info *db)
364 } 364 }
365 365
366 if (db->addr_res != NULL) { 366 if (db->addr_res != NULL) {
367 release_resource(db->data_req); 367 release_resource(db->addr_res);
368 kfree(db->addr_req); 368 kfree(db->addr_req);
369 } 369 }
370} 370}
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 4a47df5a9ff9..d0fa2448761d 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -143,6 +143,7 @@
143#include <linux/delay.h> 143#include <linux/delay.h>
144#include <linux/init.h> 144#include <linux/init.h>
145#include <linux/pci.h> 145#include <linux/pci.h>
146#include <linux/dma-mapping.h>
146#include <linux/netdevice.h> 147#include <linux/netdevice.h>
147#include <linux/etherdevice.h> 148#include <linux/etherdevice.h>
148#include <linux/mii.h> 149#include <linux/mii.h>
@@ -1092,11 +1093,16 @@ static int e100_phy_init(struct nic *nic)
1092 } 1093 }
1093 1094
1094 if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) && 1095 if((nic->mac >= mac_82550_D102) || ((nic->flags & ich) &&
1095 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000) && 1096 (mdio_read(netdev, nic->mii.phy_id, MII_TPISTATUS) & 0x8000))) {
1096 (nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))) 1097 /* enable/disable MDI/MDI-X auto-switching.
1097 /* enable/disable MDI/MDI-X auto-switching */ 1098 MDI/MDI-X auto-switching is disabled for 82551ER/QM chips */
1098 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 1099 if((nic->mac == mac_82551_E) || (nic->mac == mac_82551_F) ||
1099 nic->mii.force_media ? 0 : NCONFIG_AUTO_SWITCH); 1100 (nic->mac == mac_82551_10) || (nic->mii.force_media) ||
1101 !(nic->eeprom[eeprom_cnfg_mdix] & eeprom_mdix_enabled))
1102 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, 0);
1103 else
1104 mdio_write(netdev, nic->mii.phy_id, MII_NCONFIG, NCONFIG_AUTO_SWITCH);
1105 }
1100 1106
1101 return 0; 1107 return 0;
1102} 1108}
@@ -1665,8 +1671,10 @@ static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
1665 if(stat_ack & stat_ack_rnr) 1671 if(stat_ack & stat_ack_rnr)
1666 nic->ru_running = RU_SUSPENDED; 1672 nic->ru_running = RU_SUSPENDED;
1667 1673
1668 e100_disable_irq(nic); 1674 if(likely(netif_rx_schedule_prep(netdev))) {
1669 netif_rx_schedule(netdev); 1675 e100_disable_irq(nic);
1676 __netif_rx_schedule(netdev);
1677 }
1670 1678
1671 return IRQ_HANDLED; 1679 return IRQ_HANDLED;
1672} 1680}
@@ -2286,7 +2294,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2286 goto err_out_disable_pdev; 2294 goto err_out_disable_pdev;
2287 } 2295 }
2288 2296
2289 if((err = pci_set_dma_mask(pdev, 0xFFFFFFFFULL))) { 2297 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
2290 DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n"); 2298 DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n");
2291 goto err_out_free_res; 2299 goto err_out_free_res;
2292 } 2300 }
@@ -2334,11 +2342,11 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2334 goto err_out_iounmap; 2342 goto err_out_iounmap;
2335 } 2343 }
2336 2344
2337 e100_phy_init(nic);
2338
2339 if((err = e100_eeprom_load(nic))) 2345 if((err = e100_eeprom_load(nic)))
2340 goto err_out_free; 2346 goto err_out_free;
2341 2347
2348 e100_phy_init(nic);
2349
2342 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN); 2350 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
2343 if(!is_valid_ether_addr(netdev->dev_addr)) { 2351 if(!is_valid_ether_addr(netdev->dev_addr)) {
2344 DPRINTK(PROBE, ERR, "Invalid MAC address from " 2352 DPRINTK(PROBE, ERR, "Invalid MAC address from "
@@ -2439,9 +2447,8 @@ static int e100_resume(struct pci_dev *pdev)
2439#endif 2447#endif
2440 2448
2441 2449
2442static void e100_shutdown(struct device *dev) 2450static void e100_shutdown(struct pci_dev *pdev)
2443{ 2451{
2444 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
2445 struct net_device *netdev = pci_get_drvdata(pdev); 2452 struct net_device *netdev = pci_get_drvdata(pdev);
2446 struct nic *nic = netdev_priv(netdev); 2453 struct nic *nic = netdev_priv(netdev);
2447 2454
@@ -2462,11 +2469,7 @@ static struct pci_driver e100_driver = {
2462 .suspend = e100_suspend, 2469 .suspend = e100_suspend,
2463 .resume = e100_resume, 2470 .resume = e100_resume,
2464#endif 2471#endif
2465 2472 .shutdown = e100_shutdown,
2466 .driver = {
2467 .shutdown = e100_shutdown,
2468 }
2469
2470}; 2473};
2471 2474
2472static int __init e100_init_module(void) 2475static int __init e100_init_module(void)
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index af1e82c5b808..092757bc721f 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -140,7 +140,7 @@ struct e1000_adapter;
140#define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 140#define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */
141 141
142#define AUTO_ALL_MODES 0 142#define AUTO_ALL_MODES 0
143#define E1000_EEPROM_82544_APM 0x0400 143#define E1000_EEPROM_82544_APM 0x0004
144#define E1000_EEPROM_APME 0x0400 144#define E1000_EEPROM_APME 0x0400
145 145
146#ifndef E1000_MASTER_SLAVE 146#ifndef E1000_MASTER_SLAVE
@@ -159,7 +159,7 @@ struct e1000_adapter;
159 * so a DMA handle can be stored along with the buffer */ 159 * so a DMA handle can be stored along with the buffer */
160struct e1000_buffer { 160struct e1000_buffer {
161 struct sk_buff *skb; 161 struct sk_buff *skb;
162 uint64_t dma; 162 dma_addr_t dma;
163 unsigned long time_stamp; 163 unsigned long time_stamp;
164 uint16_t length; 164 uint16_t length;
165 uint16_t next_to_watch; 165 uint16_t next_to_watch;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index 237247f74df4..f133ff0b0b94 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -105,7 +105,7 @@ static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
105static int 105static int
106e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 106e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
107{ 107{
108 struct e1000_adapter *adapter = netdev->priv; 108 struct e1000_adapter *adapter = netdev_priv(netdev);
109 struct e1000_hw *hw = &adapter->hw; 109 struct e1000_hw *hw = &adapter->hw;
110 110
111 if(hw->media_type == e1000_media_type_copper) { 111 if(hw->media_type == e1000_media_type_copper) {
@@ -141,9 +141,9 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
141 SUPPORTED_FIBRE | 141 SUPPORTED_FIBRE |
142 SUPPORTED_Autoneg); 142 SUPPORTED_Autoneg);
143 143
144 ecmd->advertising = (SUPPORTED_1000baseT_Full | 144 ecmd->advertising = (ADVERTISED_1000baseT_Full |
145 SUPPORTED_FIBRE | 145 ADVERTISED_FIBRE |
146 SUPPORTED_Autoneg); 146 ADVERTISED_Autoneg);
147 147
148 ecmd->port = PORT_FIBRE; 148 ecmd->port = PORT_FIBRE;
149 149
@@ -179,13 +179,24 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
179static int 179static int
180e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 180e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
181{ 181{
182 struct e1000_adapter *adapter = netdev->priv; 182 struct e1000_adapter *adapter = netdev_priv(netdev);
183 struct e1000_hw *hw = &adapter->hw; 183 struct e1000_hw *hw = &adapter->hw;
184 184
185 if(ecmd->autoneg == AUTONEG_ENABLE) { 185 if(ecmd->autoneg == AUTONEG_ENABLE) {
186 hw->autoneg = 1; 186 hw->autoneg = 1;
187 hw->autoneg_advertised = 0x002F; 187 if(hw->media_type == e1000_media_type_fiber)
188 ecmd->advertising = 0x002F; 188 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
189 ADVERTISED_FIBRE |
190 ADVERTISED_Autoneg;
191 else
192 hw->autoneg_advertised = ADVERTISED_10baseT_Half |
193 ADVERTISED_10baseT_Full |
194 ADVERTISED_100baseT_Half |
195 ADVERTISED_100baseT_Full |
196 ADVERTISED_1000baseT_Full|
197 ADVERTISED_Autoneg |
198 ADVERTISED_TP;
199 ecmd->advertising = hw->autoneg_advertised;
189 } else 200 } else
190 if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) 201 if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex))
191 return -EINVAL; 202 return -EINVAL;
@@ -206,7 +217,7 @@ static void
206e1000_get_pauseparam(struct net_device *netdev, 217e1000_get_pauseparam(struct net_device *netdev,
207 struct ethtool_pauseparam *pause) 218 struct ethtool_pauseparam *pause)
208{ 219{
209 struct e1000_adapter *adapter = netdev->priv; 220 struct e1000_adapter *adapter = netdev_priv(netdev);
210 struct e1000_hw *hw = &adapter->hw; 221 struct e1000_hw *hw = &adapter->hw;
211 222
212 pause->autoneg = 223 pause->autoneg =
@@ -226,7 +237,7 @@ static int
226e1000_set_pauseparam(struct net_device *netdev, 237e1000_set_pauseparam(struct net_device *netdev,
227 struct ethtool_pauseparam *pause) 238 struct ethtool_pauseparam *pause)
228{ 239{
229 struct e1000_adapter *adapter = netdev->priv; 240 struct e1000_adapter *adapter = netdev_priv(netdev);
230 struct e1000_hw *hw = &adapter->hw; 241 struct e1000_hw *hw = &adapter->hw;
231 242
232 adapter->fc_autoneg = pause->autoneg; 243 adapter->fc_autoneg = pause->autoneg;
@@ -259,14 +270,14 @@ e1000_set_pauseparam(struct net_device *netdev,
259static uint32_t 270static uint32_t
260e1000_get_rx_csum(struct net_device *netdev) 271e1000_get_rx_csum(struct net_device *netdev)
261{ 272{
262 struct e1000_adapter *adapter = netdev->priv; 273 struct e1000_adapter *adapter = netdev_priv(netdev);
263 return adapter->rx_csum; 274 return adapter->rx_csum;
264} 275}
265 276
266static int 277static int
267e1000_set_rx_csum(struct net_device *netdev, uint32_t data) 278e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
268{ 279{
269 struct e1000_adapter *adapter = netdev->priv; 280 struct e1000_adapter *adapter = netdev_priv(netdev);
270 adapter->rx_csum = data; 281 adapter->rx_csum = data;
271 282
272 if(netif_running(netdev)) { 283 if(netif_running(netdev)) {
@@ -286,7 +297,7 @@ e1000_get_tx_csum(struct net_device *netdev)
286static int 297static int
287e1000_set_tx_csum(struct net_device *netdev, uint32_t data) 298e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
288{ 299{
289 struct e1000_adapter *adapter = netdev->priv; 300 struct e1000_adapter *adapter = netdev_priv(netdev);
290 301
291 if(adapter->hw.mac_type < e1000_82543) { 302 if(adapter->hw.mac_type < e1000_82543) {
292 if (!data) 303 if (!data)
@@ -306,8 +317,8 @@ e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
306static int 317static int
307e1000_set_tso(struct net_device *netdev, uint32_t data) 318e1000_set_tso(struct net_device *netdev, uint32_t data)
308{ 319{
309 struct e1000_adapter *adapter = netdev->priv; 320 struct e1000_adapter *adapter = netdev_priv(netdev);
310 if ((adapter->hw.mac_type < e1000_82544) || 321 if((adapter->hw.mac_type < e1000_82544) ||
311 (adapter->hw.mac_type == e1000_82547)) 322 (adapter->hw.mac_type == e1000_82547))
312 return data ? -EINVAL : 0; 323 return data ? -EINVAL : 0;
313 324
@@ -322,14 +333,14 @@ e1000_set_tso(struct net_device *netdev, uint32_t data)
322static uint32_t 333static uint32_t
323e1000_get_msglevel(struct net_device *netdev) 334e1000_get_msglevel(struct net_device *netdev)
324{ 335{
325 struct e1000_adapter *adapter = netdev->priv; 336 struct e1000_adapter *adapter = netdev_priv(netdev);
326 return adapter->msg_enable; 337 return adapter->msg_enable;
327} 338}
328 339
329static void 340static void
330e1000_set_msglevel(struct net_device *netdev, uint32_t data) 341e1000_set_msglevel(struct net_device *netdev, uint32_t data)
331{ 342{
332 struct e1000_adapter *adapter = netdev->priv; 343 struct e1000_adapter *adapter = netdev_priv(netdev);
333 adapter->msg_enable = data; 344 adapter->msg_enable = data;
334} 345}
335 346
@@ -344,7 +355,7 @@ static void
344e1000_get_regs(struct net_device *netdev, 355e1000_get_regs(struct net_device *netdev,
345 struct ethtool_regs *regs, void *p) 356 struct ethtool_regs *regs, void *p)
346{ 357{
347 struct e1000_adapter *adapter = netdev->priv; 358 struct e1000_adapter *adapter = netdev_priv(netdev);
348 struct e1000_hw *hw = &adapter->hw; 359 struct e1000_hw *hw = &adapter->hw;
349 uint32_t *regs_buff = p; 360 uint32_t *regs_buff = p;
350 uint16_t phy_data; 361 uint16_t phy_data;
@@ -432,7 +443,7 @@ e1000_get_regs(struct net_device *netdev,
432static int 443static int
433e1000_get_eeprom_len(struct net_device *netdev) 444e1000_get_eeprom_len(struct net_device *netdev)
434{ 445{
435 struct e1000_adapter *adapter = netdev->priv; 446 struct e1000_adapter *adapter = netdev_priv(netdev);
436 return adapter->hw.eeprom.word_size * 2; 447 return adapter->hw.eeprom.word_size * 2;
437} 448}
438 449
@@ -440,7 +451,7 @@ static int
440e1000_get_eeprom(struct net_device *netdev, 451e1000_get_eeprom(struct net_device *netdev,
441 struct ethtool_eeprom *eeprom, uint8_t *bytes) 452 struct ethtool_eeprom *eeprom, uint8_t *bytes)
442{ 453{
443 struct e1000_adapter *adapter = netdev->priv; 454 struct e1000_adapter *adapter = netdev_priv(netdev);
444 struct e1000_hw *hw = &adapter->hw; 455 struct e1000_hw *hw = &adapter->hw;
445 uint16_t *eeprom_buff; 456 uint16_t *eeprom_buff;
446 int first_word, last_word; 457 int first_word, last_word;
@@ -486,7 +497,7 @@ static int
486e1000_set_eeprom(struct net_device *netdev, 497e1000_set_eeprom(struct net_device *netdev,
487 struct ethtool_eeprom *eeprom, uint8_t *bytes) 498 struct ethtool_eeprom *eeprom, uint8_t *bytes)
488{ 499{
489 struct e1000_adapter *adapter = netdev->priv; 500 struct e1000_adapter *adapter = netdev_priv(netdev);
490 struct e1000_hw *hw = &adapter->hw; 501 struct e1000_hw *hw = &adapter->hw;
491 uint16_t *eeprom_buff; 502 uint16_t *eeprom_buff;
492 void *ptr; 503 void *ptr;
@@ -547,7 +558,7 @@ static void
547e1000_get_drvinfo(struct net_device *netdev, 558e1000_get_drvinfo(struct net_device *netdev,
548 struct ethtool_drvinfo *drvinfo) 559 struct ethtool_drvinfo *drvinfo)
549{ 560{
550 struct e1000_adapter *adapter = netdev->priv; 561 struct e1000_adapter *adapter = netdev_priv(netdev);
551 562
552 strncpy(drvinfo->driver, e1000_driver_name, 32); 563 strncpy(drvinfo->driver, e1000_driver_name, 32);
553 strncpy(drvinfo->version, e1000_driver_version, 32); 564 strncpy(drvinfo->version, e1000_driver_version, 32);
@@ -563,7 +574,7 @@ static void
563e1000_get_ringparam(struct net_device *netdev, 574e1000_get_ringparam(struct net_device *netdev,
564 struct ethtool_ringparam *ring) 575 struct ethtool_ringparam *ring)
565{ 576{
566 struct e1000_adapter *adapter = netdev->priv; 577 struct e1000_adapter *adapter = netdev_priv(netdev);
567 e1000_mac_type mac_type = adapter->hw.mac_type; 578 e1000_mac_type mac_type = adapter->hw.mac_type;
568 struct e1000_desc_ring *txdr = &adapter->tx_ring; 579 struct e1000_desc_ring *txdr = &adapter->tx_ring;
569 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 580 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
@@ -584,7 +595,7 @@ static int
584e1000_set_ringparam(struct net_device *netdev, 595e1000_set_ringparam(struct net_device *netdev,
585 struct ethtool_ringparam *ring) 596 struct ethtool_ringparam *ring)
586{ 597{
587 struct e1000_adapter *adapter = netdev->priv; 598 struct e1000_adapter *adapter = netdev_priv(netdev);
588 e1000_mac_type mac_type = adapter->hw.mac_type; 599 e1000_mac_type mac_type = adapter->hw.mac_type;
589 struct e1000_desc_ring *txdr = &adapter->tx_ring; 600 struct e1000_desc_ring *txdr = &adapter->tx_ring;
590 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 601 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
@@ -651,6 +662,9 @@ err_setup_rx:
651 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \ 662 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
652 value = E1000_READ_REG(&adapter->hw, R); \ 663 value = E1000_READ_REG(&adapter->hw, R); \
653 if(value != (test[pat] & W & M)) { \ 664 if(value != (test[pat] & W & M)) { \
665 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
666 "0x%08X expected 0x%08X\n", \
667 E1000_##R, value, (test[pat] & W & M)); \
654 *data = (adapter->hw.mac_type < e1000_82543) ? \ 668 *data = (adapter->hw.mac_type < e1000_82543) ? \
655 E1000_82542_##R : E1000_##R; \ 669 E1000_82542_##R : E1000_##R; \
656 return 1; \ 670 return 1; \
@@ -663,7 +677,9 @@ err_setup_rx:
663 uint32_t value; \ 677 uint32_t value; \
664 E1000_WRITE_REG(&adapter->hw, R, W & M); \ 678 E1000_WRITE_REG(&adapter->hw, R, W & M); \
665 value = E1000_READ_REG(&adapter->hw, R); \ 679 value = E1000_READ_REG(&adapter->hw, R); \
666 if ((W & M) != (value & M)) { \ 680 if((W & M) != (value & M)) { \
681 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
682 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
667 *data = (adapter->hw.mac_type < e1000_82543) ? \ 683 *data = (adapter->hw.mac_type < e1000_82543) ? \
668 E1000_82542_##R : E1000_##R; \ 684 E1000_82542_##R : E1000_##R; \
669 return 1; \ 685 return 1; \
@@ -673,18 +689,33 @@ err_setup_rx:
673static int 689static int
674e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data) 690e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
675{ 691{
676 uint32_t value; 692 uint32_t value, before, after;
677 uint32_t i; 693 uint32_t i, toggle;
678 694
679 /* The status register is Read Only, so a write should fail. 695 /* The status register is Read Only, so a write should fail.
680 * Some bits that get toggled are ignored. 696 * Some bits that get toggled are ignored.
681 */ 697 */
682 value = (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833)); 698 switch (adapter->hw.mac_type) {
683 E1000_WRITE_REG(&adapter->hw, STATUS, (0xFFFFFFFF)); 699 case e1000_82573:
684 if(value != (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833))) { 700 toggle = 0x7FFFF033;
701 break;
702 default:
703 toggle = 0xFFFFF833;
704 break;
705 }
706
707 before = E1000_READ_REG(&adapter->hw, STATUS);
708 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
709 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
710 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
711 if(value != after) {
712 DPRINTK(DRV, ERR, "failed STATUS register test got: "
713 "0x%08X expected: 0x%08X\n", after, value);
685 *data = 1; 714 *data = 1;
686 return 1; 715 return 1;
687 } 716 }
717 /* restore previous status */
718 E1000_WRITE_REG(&adapter->hw, STATUS, before);
688 719
689 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF); 720 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
690 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF); 721 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
@@ -766,7 +797,7 @@ e1000_test_intr(int irq,
766 struct pt_regs *regs) 797 struct pt_regs *regs)
767{ 798{
768 struct net_device *netdev = (struct net_device *) data; 799 struct net_device *netdev = (struct net_device *) data;
769 struct e1000_adapter *adapter = netdev->priv; 800 struct e1000_adapter *adapter = netdev_priv(netdev);
770 801
771 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR); 802 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
772 803
@@ -1214,6 +1245,7 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
1214 case e1000_82541_rev_2: 1245 case e1000_82541_rev_2:
1215 case e1000_82547: 1246 case e1000_82547:
1216 case e1000_82547_rev_2: 1247 case e1000_82547_rev_2:
1248 case e1000_82573:
1217 return e1000_integrated_phy_loopback(adapter); 1249 return e1000_integrated_phy_loopback(adapter);
1218 break; 1250 break;
1219 1251
@@ -1422,7 +1454,7 @@ static void
1422e1000_diag_test(struct net_device *netdev, 1454e1000_diag_test(struct net_device *netdev,
1423 struct ethtool_test *eth_test, uint64_t *data) 1455 struct ethtool_test *eth_test, uint64_t *data)
1424{ 1456{
1425 struct e1000_adapter *adapter = netdev->priv; 1457 struct e1000_adapter *adapter = netdev_priv(netdev);
1426 boolean_t if_running = netif_running(netdev); 1458 boolean_t if_running = netif_running(netdev);
1427 1459
1428 if(eth_test->flags == ETH_TEST_FL_OFFLINE) { 1460 if(eth_test->flags == ETH_TEST_FL_OFFLINE) {
@@ -1482,7 +1514,7 @@ e1000_diag_test(struct net_device *netdev,
1482static void 1514static void
1483e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 1515e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1484{ 1516{
1485 struct e1000_adapter *adapter = netdev->priv; 1517 struct e1000_adapter *adapter = netdev_priv(netdev);
1486 struct e1000_hw *hw = &adapter->hw; 1518 struct e1000_hw *hw = &adapter->hw;
1487 1519
1488 switch(adapter->hw.device_id) { 1520 switch(adapter->hw.device_id) {
@@ -1527,7 +1559,7 @@ e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1527static int 1559static int
1528e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 1560e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1529{ 1561{
1530 struct e1000_adapter *adapter = netdev->priv; 1562 struct e1000_adapter *adapter = netdev_priv(netdev);
1531 struct e1000_hw *hw = &adapter->hw; 1563 struct e1000_hw *hw = &adapter->hw;
1532 1564
1533 switch(adapter->hw.device_id) { 1565 switch(adapter->hw.device_id) {
@@ -1588,22 +1620,31 @@ e1000_led_blink_callback(unsigned long data)
1588static int 1620static int
1589e1000_phys_id(struct net_device *netdev, uint32_t data) 1621e1000_phys_id(struct net_device *netdev, uint32_t data)
1590{ 1622{
1591 struct e1000_adapter *adapter = netdev->priv; 1623 struct e1000_adapter *adapter = netdev_priv(netdev);
1592 1624
1593 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ)) 1625 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1594 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ); 1626 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1595 1627
1596 if(!adapter->blink_timer.function) { 1628 if(adapter->hw.mac_type < e1000_82573) {
1597 init_timer(&adapter->blink_timer); 1629 if(!adapter->blink_timer.function) {
1598 adapter->blink_timer.function = e1000_led_blink_callback; 1630 init_timer(&adapter->blink_timer);
1599 adapter->blink_timer.data = (unsigned long) adapter; 1631 adapter->blink_timer.function = e1000_led_blink_callback;
1632 adapter->blink_timer.data = (unsigned long) adapter;
1633 }
1634 e1000_setup_led(&adapter->hw);
1635 mod_timer(&adapter->blink_timer, jiffies);
1636 msleep_interruptible(data * 1000);
1637 del_timer_sync(&adapter->blink_timer);
1638 }
1639 else {
1640 E1000_WRITE_REG(&adapter->hw, LEDCTL, (E1000_LEDCTL_LED2_BLINK_RATE |
1641 E1000_LEDCTL_LED1_BLINK | E1000_LEDCTL_LED2_BLINK |
1642 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
1643 (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED1_MODE_SHIFT) |
1644 (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT)));
1645 msleep_interruptible(data * 1000);
1600 } 1646 }
1601 1647
1602 e1000_setup_led(&adapter->hw);
1603 mod_timer(&adapter->blink_timer, jiffies);
1604
1605 msleep_interruptible(data * 1000);
1606 del_timer_sync(&adapter->blink_timer);
1607 e1000_led_off(&adapter->hw); 1648 e1000_led_off(&adapter->hw);
1608 clear_bit(E1000_LED_ON, &adapter->led_status); 1649 clear_bit(E1000_LED_ON, &adapter->led_status);
1609 e1000_cleanup_led(&adapter->hw); 1650 e1000_cleanup_led(&adapter->hw);
@@ -1614,7 +1655,7 @@ e1000_phys_id(struct net_device *netdev, uint32_t data)
1614static int 1655static int
1615e1000_nway_reset(struct net_device *netdev) 1656e1000_nway_reset(struct net_device *netdev)
1616{ 1657{
1617 struct e1000_adapter *adapter = netdev->priv; 1658 struct e1000_adapter *adapter = netdev_priv(netdev);
1618 if(netif_running(netdev)) { 1659 if(netif_running(netdev)) {
1619 e1000_down(adapter); 1660 e1000_down(adapter);
1620 e1000_up(adapter); 1661 e1000_up(adapter);
@@ -1632,7 +1673,7 @@ static void
1632e1000_get_ethtool_stats(struct net_device *netdev, 1673e1000_get_ethtool_stats(struct net_device *netdev,
1633 struct ethtool_stats *stats, uint64_t *data) 1674 struct ethtool_stats *stats, uint64_t *data)
1634{ 1675{
1635 struct e1000_adapter *adapter = netdev->priv; 1676 struct e1000_adapter *adapter = netdev_priv(netdev);
1636 int i; 1677 int i;
1637 1678
1638 e1000_update_stats(adapter); 1679 e1000_update_stats(adapter);
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 723589b28be5..045f5426ab9a 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -354,18 +354,27 @@ e1000_set_media_type(struct e1000_hw *hw)
354 hw->media_type = e1000_media_type_internal_serdes; 354 hw->media_type = e1000_media_type_internal_serdes;
355 break; 355 break;
356 default: 356 default:
357 if(hw->mac_type >= e1000_82543) { 357 switch (hw->mac_type) {
358 case e1000_82542_rev2_0:
359 case e1000_82542_rev2_1:
360 hw->media_type = e1000_media_type_fiber;
361 break;
362 case e1000_82573:
363 /* The STATUS_TBIMODE bit is reserved or reused for the this
364 * device.
365 */
366 hw->media_type = e1000_media_type_copper;
367 break;
368 default:
358 status = E1000_READ_REG(hw, STATUS); 369 status = E1000_READ_REG(hw, STATUS);
359 if(status & E1000_STATUS_TBIMODE) { 370 if (status & E1000_STATUS_TBIMODE) {
360 hw->media_type = e1000_media_type_fiber; 371 hw->media_type = e1000_media_type_fiber;
361 /* tbi_compatibility not valid on fiber */ 372 /* tbi_compatibility not valid on fiber */
362 hw->tbi_compatibility_en = FALSE; 373 hw->tbi_compatibility_en = FALSE;
363 } else { 374 } else {
364 hw->media_type = e1000_media_type_copper; 375 hw->media_type = e1000_media_type_copper;
365 } 376 }
366 } else { 377 break;
367 /* This is an 82542 (fiber only) */
368 hw->media_type = e1000_media_type_fiber;
369 } 378 }
370 } 379 }
371} 380}
@@ -1189,9 +1198,9 @@ e1000_copper_link_igp_setup(struct e1000_hw *hw)
1189 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); 1198 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1190 if(ret_val) 1199 if(ret_val)
1191 return ret_val; 1200 return ret_val;
1192 } 1201 }
1193 1202
1194 return E1000_SUCCESS; 1203 return E1000_SUCCESS;
1195} 1204}
1196 1205
1197 1206
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index a0263ee96c6b..93e9f8788751 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -66,6 +66,7 @@ typedef enum {
66 e1000_eeprom_spi, 66 e1000_eeprom_spi,
67 e1000_eeprom_microwire, 67 e1000_eeprom_microwire,
68 e1000_eeprom_flash, 68 e1000_eeprom_flash,
69 e1000_eeprom_none, /* No NVM support */
69 e1000_num_eeprom_types 70 e1000_num_eeprom_types
70} e1000_eeprom_type; 71} e1000_eeprom_type;
71 72
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 137226d98d47..cb7f051a60ad 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -29,6 +29,8 @@
29#include "e1000.h" 29#include "e1000.h"
30 30
31/* Change Log 31/* Change Log
32 * 6.0.58 4/20/05
33 * o Accepted ethtool cleanup patch from Stephen Hemminger
32 * 6.0.44+ 2/15/05 34 * 6.0.44+ 2/15/05
33 * o applied Anton's patch to resolve tx hang in hardware 35 * o applied Anton's patch to resolve tx hang in hardware
34 * o Applied Andrew Mortons patch - e1000 stops working after resume 36 * o Applied Andrew Mortons patch - e1000 stops working after resume
@@ -41,9 +43,9 @@ char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41#else 43#else
42#define DRIVERNAPI "-NAPI" 44#define DRIVERNAPI "-NAPI"
43#endif 45#endif
44#define DRV_VERSION "6.0.54-k2"DRIVERNAPI 46#define DRV_VERSION "6.0.60-k2"DRIVERNAPI
45char e1000_driver_version[] = DRV_VERSION; 47char e1000_driver_version[] = DRV_VERSION;
46char e1000_copyright[] = "Copyright (c) 1999-2004 Intel Corporation."; 48char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
47 49
48/* e1000_pci_tbl - PCI Device ID Table 50/* e1000_pci_tbl - PCI Device ID Table
49 * 51 *
@@ -517,7 +519,7 @@ e1000_probe(struct pci_dev *pdev,
517 SET_NETDEV_DEV(netdev, &pdev->dev); 519 SET_NETDEV_DEV(netdev, &pdev->dev);
518 520
519 pci_set_drvdata(pdev, netdev); 521 pci_set_drvdata(pdev, netdev);
520 adapter = netdev->priv; 522 adapter = netdev_priv(netdev);
521 adapter->netdev = netdev; 523 adapter->netdev = netdev;
522 adapter->pdev = pdev; 524 adapter->pdev = pdev;
523 adapter->hw.back = adapter; 525 adapter->hw.back = adapter;
@@ -738,7 +740,7 @@ static void __devexit
738e1000_remove(struct pci_dev *pdev) 740e1000_remove(struct pci_dev *pdev)
739{ 741{
740 struct net_device *netdev = pci_get_drvdata(pdev); 742 struct net_device *netdev = pci_get_drvdata(pdev);
741 struct e1000_adapter *adapter = netdev->priv; 743 struct e1000_adapter *adapter = netdev_priv(netdev);
742 uint32_t manc, swsm; 744 uint32_t manc, swsm;
743 745
744 flush_scheduled_work(); 746 flush_scheduled_work();
@@ -871,7 +873,7 @@ e1000_sw_init(struct e1000_adapter *adapter)
871static int 873static int
872e1000_open(struct net_device *netdev) 874e1000_open(struct net_device *netdev)
873{ 875{
874 struct e1000_adapter *adapter = netdev->priv; 876 struct e1000_adapter *adapter = netdev_priv(netdev);
875 int err; 877 int err;
876 878
877 /* allocate transmit descriptors */ 879 /* allocate transmit descriptors */
@@ -919,7 +921,7 @@ err_setup_tx:
919static int 921static int
920e1000_close(struct net_device *netdev) 922e1000_close(struct net_device *netdev)
921{ 923{
922 struct e1000_adapter *adapter = netdev->priv; 924 struct e1000_adapter *adapter = netdev_priv(netdev);
923 925
924 e1000_down(adapter); 926 e1000_down(adapter);
925 927
@@ -1599,7 +1601,7 @@ e1000_leave_82542_rst(struct e1000_adapter *adapter)
1599static int 1601static int
1600e1000_set_mac(struct net_device *netdev, void *p) 1602e1000_set_mac(struct net_device *netdev, void *p)
1601{ 1603{
1602 struct e1000_adapter *adapter = netdev->priv; 1604 struct e1000_adapter *adapter = netdev_priv(netdev);
1603 struct sockaddr *addr = p; 1605 struct sockaddr *addr = p;
1604 1606
1605 if(!is_valid_ether_addr(addr->sa_data)) 1607 if(!is_valid_ether_addr(addr->sa_data))
@@ -1634,7 +1636,7 @@ e1000_set_mac(struct net_device *netdev, void *p)
1634static void 1636static void
1635e1000_set_multi(struct net_device *netdev) 1637e1000_set_multi(struct net_device *netdev)
1636{ 1638{
1637 struct e1000_adapter *adapter = netdev->priv; 1639 struct e1000_adapter *adapter = netdev_priv(netdev);
1638 struct e1000_hw *hw = &adapter->hw; 1640 struct e1000_hw *hw = &adapter->hw;
1639 struct dev_mc_list *mc_ptr; 1641 struct dev_mc_list *mc_ptr;
1640 unsigned long flags; 1642 unsigned long flags;
@@ -2213,7 +2215,7 @@ e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2213static int 2215static int
2214e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2216e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2215{ 2217{
2216 struct e1000_adapter *adapter = netdev->priv; 2218 struct e1000_adapter *adapter = netdev_priv(netdev);
2217 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; 2219 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2218 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; 2220 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2219 unsigned int tx_flags = 0; 2221 unsigned int tx_flags = 0;
@@ -2344,7 +2346,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2344static void 2346static void
2345e1000_tx_timeout(struct net_device *netdev) 2347e1000_tx_timeout(struct net_device *netdev)
2346{ 2348{
2347 struct e1000_adapter *adapter = netdev->priv; 2349 struct e1000_adapter *adapter = netdev_priv(netdev);
2348 2350
2349 /* Do the reset outside of interrupt context */ 2351 /* Do the reset outside of interrupt context */
2350 schedule_work(&adapter->tx_timeout_task); 2352 schedule_work(&adapter->tx_timeout_task);
@@ -2353,7 +2355,7 @@ e1000_tx_timeout(struct net_device *netdev)
2353static void 2355static void
2354e1000_tx_timeout_task(struct net_device *netdev) 2356e1000_tx_timeout_task(struct net_device *netdev)
2355{ 2357{
2356 struct e1000_adapter *adapter = netdev->priv; 2358 struct e1000_adapter *adapter = netdev_priv(netdev);
2357 2359
2358 e1000_down(adapter); 2360 e1000_down(adapter);
2359 e1000_up(adapter); 2361 e1000_up(adapter);
@@ -2370,7 +2372,7 @@ e1000_tx_timeout_task(struct net_device *netdev)
2370static struct net_device_stats * 2372static struct net_device_stats *
2371e1000_get_stats(struct net_device *netdev) 2373e1000_get_stats(struct net_device *netdev)
2372{ 2374{
2373 struct e1000_adapter *adapter = netdev->priv; 2375 struct e1000_adapter *adapter = netdev_priv(netdev);
2374 2376
2375 e1000_update_stats(adapter); 2377 e1000_update_stats(adapter);
2376 return &adapter->net_stats; 2378 return &adapter->net_stats;
@@ -2387,7 +2389,7 @@ e1000_get_stats(struct net_device *netdev)
2387static int 2389static int
2388e1000_change_mtu(struct net_device *netdev, int new_mtu) 2390e1000_change_mtu(struct net_device *netdev, int new_mtu)
2389{ 2391{
2390 struct e1000_adapter *adapter = netdev->priv; 2392 struct e1000_adapter *adapter = netdev_priv(netdev);
2391 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; 2393 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
2392 2394
2393 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || 2395 if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
@@ -2598,7 +2600,7 @@ static irqreturn_t
2598e1000_intr(int irq, void *data, struct pt_regs *regs) 2600e1000_intr(int irq, void *data, struct pt_regs *regs)
2599{ 2601{
2600 struct net_device *netdev = data; 2602 struct net_device *netdev = data;
2601 struct e1000_adapter *adapter = netdev->priv; 2603 struct e1000_adapter *adapter = netdev_priv(netdev);
2602 struct e1000_hw *hw = &adapter->hw; 2604 struct e1000_hw *hw = &adapter->hw;
2603 uint32_t icr = E1000_READ_REG(hw, ICR); 2605 uint32_t icr = E1000_READ_REG(hw, ICR);
2604#ifndef CONFIG_E1000_NAPI 2606#ifndef CONFIG_E1000_NAPI
@@ -2661,7 +2663,7 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2661static int 2663static int
2662e1000_clean(struct net_device *netdev, int *budget) 2664e1000_clean(struct net_device *netdev, int *budget)
2663{ 2665{
2664 struct e1000_adapter *adapter = netdev->priv; 2666 struct e1000_adapter *adapter = netdev_priv(netdev);
2665 int work_to_do = min(*budget, netdev->quota); 2667 int work_to_do = min(*budget, netdev->quota);
2666 int tx_cleaned; 2668 int tx_cleaned;
2667 int work_done = 0; 2669 int work_done = 0;
@@ -2672,8 +2674,8 @@ e1000_clean(struct net_device *netdev, int *budget)
2672 *budget -= work_done; 2674 *budget -= work_done;
2673 netdev->quota -= work_done; 2675 netdev->quota -= work_done;
2674 2676
2675 /* If no Tx and no Rx work done, exit the polling mode */
2676 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) { 2677 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2678 /* If no Tx and not enough Rx work done, exit the polling mode */
2677 netif_rx_complete(netdev); 2679 netif_rx_complete(netdev);
2678 e1000_irq_enable(adapter); 2680 e1000_irq_enable(adapter);
2679 return 0; 2681 return 0;
@@ -2769,13 +2771,13 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2769 i = tx_ring->next_to_clean; 2771 i = tx_ring->next_to_clean;
2770 eop = tx_ring->buffer_info[i].next_to_watch; 2772 eop = tx_ring->buffer_info[i].next_to_watch;
2771 eop_desc = E1000_TX_DESC(*tx_ring, eop); 2773 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2772 DPRINTK(TX_ERR, ERR, "Detected Tx Unit Hang\n" 2774 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
2773 " TDH <%x>\n" 2775 " TDH <%x>\n"
2774 " TDT <%x>\n" 2776 " TDT <%x>\n"
2775 " next_to_use <%x>\n" 2777 " next_to_use <%x>\n"
2776 " next_to_clean <%x>\n" 2778 " next_to_clean <%x>\n"
2777 "buffer_info[next_to_clean]\n" 2779 "buffer_info[next_to_clean]\n"
2778 " dma <%llx>\n" 2780 " dma <%zx>\n"
2779 " time_stamp <%lx>\n" 2781 " time_stamp <%lx>\n"
2780 " next_to_watch <%x>\n" 2782 " next_to_watch <%x>\n"
2781 " jiffies <%lx>\n" 2783 " jiffies <%lx>\n"
@@ -2994,7 +2996,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
2994 2996
2995 i = rx_ring->next_to_clean; 2997 i = rx_ring->next_to_clean;
2996 rx_desc = E1000_RX_DESC_PS(*rx_ring, i); 2998 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
2997 staterr = rx_desc->wb.middle.status_error; 2999 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
2998 3000
2999 while(staterr & E1000_RXD_STAT_DD) { 3001 while(staterr & E1000_RXD_STAT_DD) {
3000 buffer_info = &rx_ring->buffer_info[i]; 3002 buffer_info = &rx_ring->buffer_info[i];
@@ -3065,16 +3067,16 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3065#ifdef CONFIG_E1000_NAPI 3067#ifdef CONFIG_E1000_NAPI
3066 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { 3068 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3067 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, 3069 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3068 le16_to_cpu(rx_desc->wb.middle.vlan & 3070 le16_to_cpu(rx_desc->wb.middle.vlan) &
3069 E1000_RXD_SPC_VLAN_MASK)); 3071 E1000_RXD_SPC_VLAN_MASK);
3070 } else { 3072 } else {
3071 netif_receive_skb(skb); 3073 netif_receive_skb(skb);
3072 } 3074 }
3073#else /* CONFIG_E1000_NAPI */ 3075#else /* CONFIG_E1000_NAPI */
3074 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { 3076 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3075 vlan_hwaccel_rx(skb, adapter->vlgrp, 3077 vlan_hwaccel_rx(skb, adapter->vlgrp,
3076 le16_to_cpu(rx_desc->wb.middle.vlan & 3078 le16_to_cpu(rx_desc->wb.middle.vlan) &
3077 E1000_RXD_SPC_VLAN_MASK)); 3079 E1000_RXD_SPC_VLAN_MASK);
3078 } else { 3080 } else {
3079 netif_rx(skb); 3081 netif_rx(skb);
3080 } 3082 }
@@ -3087,7 +3089,7 @@ next_desc:
3087 if(unlikely(++i == rx_ring->count)) i = 0; 3089 if(unlikely(++i == rx_ring->count)) i = 0;
3088 3090
3089 rx_desc = E1000_RX_DESC_PS(*rx_ring, i); 3091 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3090 staterr = rx_desc->wb.middle.status_error; 3092 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3091 } 3093 }
3092 rx_ring->next_to_clean = i; 3094 rx_ring->next_to_clean = i;
3093 adapter->alloc_rx_buf(adapter); 3095 adapter->alloc_rx_buf(adapter);
@@ -3371,11 +3373,12 @@ e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3371static int 3373static int
3372e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 3374e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3373{ 3375{
3374 struct e1000_adapter *adapter = netdev->priv; 3376 struct e1000_adapter *adapter = netdev_priv(netdev);
3375 struct mii_ioctl_data *data = if_mii(ifr); 3377 struct mii_ioctl_data *data = if_mii(ifr);
3376 int retval; 3378 int retval;
3377 uint16_t mii_reg; 3379 uint16_t mii_reg;
3378 uint16_t spddplx; 3380 uint16_t spddplx;
3381 unsigned long flags;
3379 3382
3380 if(adapter->hw.media_type != e1000_media_type_copper) 3383 if(adapter->hw.media_type != e1000_media_type_copper)
3381 return -EOPNOTSUPP; 3384 return -EOPNOTSUPP;
@@ -3385,22 +3388,29 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3385 data->phy_id = adapter->hw.phy_addr; 3388 data->phy_id = adapter->hw.phy_addr;
3386 break; 3389 break;
3387 case SIOCGMIIREG: 3390 case SIOCGMIIREG:
3388 if (!capable(CAP_NET_ADMIN)) 3391 if(!capable(CAP_NET_ADMIN))
3389 return -EPERM; 3392 return -EPERM;
3390 if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, 3393 spin_lock_irqsave(&adapter->stats_lock, flags);
3391 &data->val_out)) 3394 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
3395 &data->val_out)) {
3396 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3392 return -EIO; 3397 return -EIO;
3398 }
3399 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3393 break; 3400 break;
3394 case SIOCSMIIREG: 3401 case SIOCSMIIREG:
3395 if (!capable(CAP_NET_ADMIN)) 3402 if(!capable(CAP_NET_ADMIN))
3396 return -EPERM; 3403 return -EPERM;
3397 if (data->reg_num & ~(0x1F)) 3404 if(data->reg_num & ~(0x1F))
3398 return -EFAULT; 3405 return -EFAULT;
3399 mii_reg = data->val_in; 3406 mii_reg = data->val_in;
3400 if (e1000_write_phy_reg(&adapter->hw, data->reg_num, 3407 spin_lock_irqsave(&adapter->stats_lock, flags);
3401 mii_reg)) 3408 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
3409 mii_reg)) {
3410 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3402 return -EIO; 3411 return -EIO;
3403 if (adapter->hw.phy_type == e1000_phy_m88) { 3412 }
3413 if(adapter->hw.phy_type == e1000_phy_m88) {
3404 switch (data->reg_num) { 3414 switch (data->reg_num) {
3405 case PHY_CTRL: 3415 case PHY_CTRL:
3406 if(mii_reg & MII_CR_POWER_DOWN) 3416 if(mii_reg & MII_CR_POWER_DOWN)
@@ -3420,8 +3430,12 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3420 HALF_DUPLEX; 3430 HALF_DUPLEX;
3421 retval = e1000_set_spd_dplx(adapter, 3431 retval = e1000_set_spd_dplx(adapter,
3422 spddplx); 3432 spddplx);
3423 if(retval) 3433 if(retval) {
3434 spin_unlock_irqrestore(
3435 &adapter->stats_lock,
3436 flags);
3424 return retval; 3437 return retval;
3438 }
3425 } 3439 }
3426 if(netif_running(adapter->netdev)) { 3440 if(netif_running(adapter->netdev)) {
3427 e1000_down(adapter); 3441 e1000_down(adapter);
@@ -3431,8 +3445,11 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3431 break; 3445 break;
3432 case M88E1000_PHY_SPEC_CTRL: 3446 case M88E1000_PHY_SPEC_CTRL:
3433 case M88E1000_EXT_PHY_SPEC_CTRL: 3447 case M88E1000_EXT_PHY_SPEC_CTRL:
3434 if (e1000_phy_reset(&adapter->hw)) 3448 if(e1000_phy_reset(&adapter->hw)) {
3449 spin_unlock_irqrestore(
3450 &adapter->stats_lock, flags);
3435 return -EIO; 3451 return -EIO;
3452 }
3436 break; 3453 break;
3437 } 3454 }
3438 } else { 3455 } else {
@@ -3448,6 +3465,7 @@ e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
3448 break; 3465 break;
3449 } 3466 }
3450 } 3467 }
3468 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3451 break; 3469 break;
3452 default: 3470 default:
3453 return -EOPNOTSUPP; 3471 return -EOPNOTSUPP;
@@ -3504,7 +3522,7 @@ e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
3504static void 3522static void
3505e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) 3523e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3506{ 3524{
3507 struct e1000_adapter *adapter = netdev->priv; 3525 struct e1000_adapter *adapter = netdev_priv(netdev);
3508 uint32_t ctrl, rctl; 3526 uint32_t ctrl, rctl;
3509 3527
3510 e1000_irq_disable(adapter); 3528 e1000_irq_disable(adapter);
@@ -3544,7 +3562,7 @@ e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
3544static void 3562static void
3545e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) 3563e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3546{ 3564{
3547 struct e1000_adapter *adapter = netdev->priv; 3565 struct e1000_adapter *adapter = netdev_priv(netdev);
3548 uint32_t vfta, index; 3566 uint32_t vfta, index;
3549 if((adapter->hw.mng_cookie.status & 3567 if((adapter->hw.mng_cookie.status &
3550 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && 3568 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
@@ -3560,7 +3578,7 @@ e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
3560static void 3578static void
3561e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) 3579e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
3562{ 3580{
3563 struct e1000_adapter *adapter = netdev->priv; 3581 struct e1000_adapter *adapter = netdev_priv(netdev);
3564 uint32_t vfta, index; 3582 uint32_t vfta, index;
3565 3583
3566 e1000_irq_disable(adapter); 3584 e1000_irq_disable(adapter);
@@ -3601,6 +3619,13 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3601{ 3619{
3602 adapter->hw.autoneg = 0; 3620 adapter->hw.autoneg = 0;
3603 3621
3622 /* Fiber NICs only allow 1000 gbps Full duplex */
3623 if((adapter->hw.media_type == e1000_media_type_fiber) &&
3624 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
3625 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
3626 return -EINVAL;
3627 }
3628
3604 switch(spddplx) { 3629 switch(spddplx) {
3605 case SPEED_10 + DUPLEX_HALF: 3630 case SPEED_10 + DUPLEX_HALF:
3606 adapter->hw.forced_speed_duplex = e1000_10_half; 3631 adapter->hw.forced_speed_duplex = e1000_10_half;
@@ -3647,7 +3672,7 @@ static int
3647e1000_suspend(struct pci_dev *pdev, uint32_t state) 3672e1000_suspend(struct pci_dev *pdev, uint32_t state)
3648{ 3673{
3649 struct net_device *netdev = pci_get_drvdata(pdev); 3674 struct net_device *netdev = pci_get_drvdata(pdev);
3650 struct e1000_adapter *adapter = netdev->priv; 3675 struct e1000_adapter *adapter = netdev_priv(netdev);
3651 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm; 3676 uint32_t ctrl, ctrl_ext, rctl, manc, status, swsm;
3652 uint32_t wufc = adapter->wol; 3677 uint32_t wufc = adapter->wol;
3653 3678
@@ -3740,12 +3765,12 @@ static int
3740e1000_resume(struct pci_dev *pdev) 3765e1000_resume(struct pci_dev *pdev)
3741{ 3766{
3742 struct net_device *netdev = pci_get_drvdata(pdev); 3767 struct net_device *netdev = pci_get_drvdata(pdev);
3743 struct e1000_adapter *adapter = netdev->priv; 3768 struct e1000_adapter *adapter = netdev_priv(netdev);
3744 uint32_t manc, ret, swsm; 3769 uint32_t manc, ret_val, swsm;
3745 3770
3746 pci_set_power_state(pdev, 0); 3771 pci_set_power_state(pdev, 0);
3747 pci_restore_state(pdev); 3772 pci_restore_state(pdev);
3748 ret = pci_enable_device(pdev); 3773 ret_val = pci_enable_device(pdev);
3749 pci_set_master(pdev); 3774 pci_set_master(pdev);
3750 3775
3751 pci_enable_wake(pdev, 3, 0); 3776 pci_enable_wake(pdev, 3, 0);
@@ -3788,7 +3813,7 @@ e1000_resume(struct pci_dev *pdev)
3788static void 3813static void
3789e1000_netpoll(struct net_device *netdev) 3814e1000_netpoll(struct net_device *netdev)
3790{ 3815{
3791 struct e1000_adapter *adapter = netdev->priv; 3816 struct e1000_adapter *adapter = netdev_priv(netdev);
3792 disable_irq(adapter->pdev->irq); 3817 disable_irq(adapter->pdev->irq);
3793 e1000_intr(adapter->pdev->irq, netdev, NULL); 3818 e1000_intr(adapter->pdev->irq, netdev, NULL);
3794 enable_irq(adapter->pdev->irq); 3819 enable_irq(adapter->pdev->irq);
diff --git a/drivers/net/e2100.c b/drivers/net/e2100.c
index 51c9fa260830..f5a4dd7d8564 100644
--- a/drivers/net/e2100.c
+++ b/drivers/net/e2100.c
@@ -162,12 +162,7 @@ struct net_device * __init e2100_probe(int unit)
162 err = do_e2100_probe(dev); 162 err = do_e2100_probe(dev);
163 if (err) 163 if (err)
164 goto out; 164 goto out;
165 err = register_netdev(dev);
166 if (err)
167 goto out1;
168 return dev; 165 return dev;
169out1:
170 cleanup_card(dev);
171out: 166out:
172 free_netdev(dev); 167 free_netdev(dev);
173 return ERR_PTR(err); 168 return ERR_PTR(err);
@@ -286,6 +281,9 @@ static int __init e21_probe1(struct net_device *dev, int ioaddr)
286#endif 281#endif
287 NS8390_init(dev, 0); 282 NS8390_init(dev, 0);
288 283
284 retval = register_netdev(dev);
285 if (retval)
286 goto out;
289 return 0; 287 return 0;
290out: 288out:
291 release_region(ioaddr, E21_IO_EXTENT); 289 release_region(ioaddr, E21_IO_EXTENT);
@@ -453,11 +451,8 @@ init_module(void)
453 dev->mem_start = mem[this_dev]; 451 dev->mem_start = mem[this_dev];
454 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ 452 dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
455 if (do_e2100_probe(dev) == 0) { 453 if (do_e2100_probe(dev) == 0) {
456 if (register_netdev(dev) == 0) { 454 dev_e21[found++] = dev;
457 dev_e21[found++] = dev; 455 continue;
458 continue;
459 }
460 cleanup_card(dev);
461 } 456 }
462 free_netdev(dev); 457 free_netdev(dev);
463 printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]); 458 printk(KERN_WARNING "e2100.c: No E2100 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index cd2475683027..dcb3028bb60f 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -600,12 +600,7 @@ struct net_device * __init eepro_probe(int unit)
600 err = do_eepro_probe(dev); 600 err = do_eepro_probe(dev);
601 if (err) 601 if (err)
602 goto out; 602 goto out;
603 err = register_netdev(dev);
604 if (err)
605 goto out1;
606 return dev; 603 return dev;
607out1:
608 release_region(dev->base_addr, EEPRO_IO_EXTENT);
609out: 604out:
610 free_netdev(dev); 605 free_netdev(dev);
611 return ERR_PTR(err); 606 return ERR_PTR(err);
@@ -758,6 +753,7 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
758 int i; 753 int i;
759 struct eepro_local *lp; 754 struct eepro_local *lp;
760 int ioaddr = dev->base_addr; 755 int ioaddr = dev->base_addr;
756 int err;
761 757
762 /* Grab the region so we can find another board if autoIRQ fails. */ 758 /* Grab the region so we can find another board if autoIRQ fails. */
763 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) { 759 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
@@ -873,10 +869,16 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
873 869
874 /* reset 82595 */ 870 /* reset 82595 */
875 eepro_reset(ioaddr); 871 eepro_reset(ioaddr);
872
873 err = register_netdev(dev);
874 if (err)
875 goto err;
876 return 0; 876 return 0;
877exit: 877exit:
878 err = -ENODEV;
879err:
878 release_region(dev->base_addr, EEPRO_IO_EXTENT); 880 release_region(dev->base_addr, EEPRO_IO_EXTENT);
879 return -ENODEV; 881 return err;
880} 882}
881 883
882/* Open/initialize the board. This is called (in the current kernel) 884/* Open/initialize the board. This is called (in the current kernel)
@@ -1834,11 +1836,8 @@ init_module(void)
1834 dev->irq = irq[i]; 1836 dev->irq = irq[i];
1835 1837
1836 if (do_eepro_probe(dev) == 0) { 1838 if (do_eepro_probe(dev) == 0) {
1837 if (register_netdev(dev) == 0) { 1839 dev_eepro[n_eepro++] = dev;
1838 dev_eepro[n_eepro++] = dev; 1840 continue;
1839 continue;
1840 }
1841 release_region(dev->base_addr, EEPRO_IO_EXTENT);
1842 } 1841 }
1843 free_netdev(dev); 1842 free_netdev(dev);
1844 break; 1843 break;
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 98b3a2fdce90..1795425f512e 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -1269,7 +1269,7 @@ speedo_init_rx_ring(struct net_device *dev)
1269 if (skb == NULL) 1269 if (skb == NULL)
1270 break; /* OK. Just initially short of Rx bufs. */ 1270 break; /* OK. Just initially short of Rx bufs. */
1271 skb->dev = dev; /* Mark as being used by this device. */ 1271 skb->dev = dev; /* Mark as being used by this device. */
1272 rxf = (struct RxFD *)skb->tail; 1272 rxf = (struct RxFD *)skb->data;
1273 sp->rx_ringp[i] = rxf; 1273 sp->rx_ringp[i] = rxf;
1274 sp->rx_ring_dma[i] = 1274 sp->rx_ring_dma[i] =
1275 pci_map_single(sp->pdev, rxf, 1275 pci_map_single(sp->pdev, rxf,
@@ -1661,7 +1661,7 @@ static inline struct RxFD *speedo_rx_alloc(struct net_device *dev, int entry)
1661 sp->rx_ringp[entry] = NULL; 1661 sp->rx_ringp[entry] = NULL;
1662 return NULL; 1662 return NULL;
1663 } 1663 }
1664 rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->tail; 1664 rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->data;
1665 sp->rx_ring_dma[entry] = 1665 sp->rx_ring_dma[entry] =
1666 pci_map_single(sp->pdev, rxf, 1666 pci_map_single(sp->pdev, rxf,
1667 PKT_BUF_SZ + sizeof(struct RxFD), PCI_DMA_FROMDEVICE); 1667 PKT_BUF_SZ + sizeof(struct RxFD), PCI_DMA_FROMDEVICE);
@@ -1808,10 +1808,10 @@ speedo_rx(struct net_device *dev)
1808 1808
1809#if 1 || USE_IP_CSUM 1809#if 1 || USE_IP_CSUM
1810 /* Packet is in one chunk -- we can copy + cksum. */ 1810 /* Packet is in one chunk -- we can copy + cksum. */
1811 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->tail, pkt_len, 0); 1811 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->data, pkt_len, 0);
1812 skb_put(skb, pkt_len); 1812 skb_put(skb, pkt_len);
1813#else 1813#else
1814 memcpy(skb_put(skb, pkt_len), sp->rx_skbuff[entry]->tail, 1814 memcpy(skb_put(skb, pkt_len), sp->rx_skbuff[entry]->data,
1815 pkt_len); 1815 pkt_len);
1816#endif 1816#endif
1817 pci_dma_sync_single_for_device(sp->pdev, sp->rx_ring_dma[entry], 1817 pci_dma_sync_single_for_device(sp->pdev, sp->rx_ring_dma[entry],
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index fc8e7947b334..82bd356e4f3a 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -436,11 +436,8 @@ struct net_device * __init express_probe(int unit)
436 netdev_boot_setup_check(dev); 436 netdev_boot_setup_check(dev);
437 437
438 err = do_express_probe(dev); 438 err = do_express_probe(dev);
439 if (!err) { 439 if (!err)
440 err = register_netdev(dev); 440 return dev;
441 if (!err)
442 return dev;
443 }
444 free_netdev(dev); 441 free_netdev(dev);
445 return ERR_PTR(err); 442 return ERR_PTR(err);
446} 443}
@@ -1205,7 +1202,8 @@ static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
1205 dev->set_multicast_list = &eexp_set_multicast; 1202 dev->set_multicast_list = &eexp_set_multicast;
1206 dev->tx_timeout = eexp_timeout; 1203 dev->tx_timeout = eexp_timeout;
1207 dev->watchdog_timeo = 2*HZ; 1204 dev->watchdog_timeo = 2*HZ;
1208 return 0; 1205
1206 return register_netdev(dev);
1209} 1207}
1210 1208
1211/* 1209/*
@@ -1716,7 +1714,7 @@ int init_module(void)
1716 break; 1714 break;
1717 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n"); 1715 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1718 } 1716 }
1719 if (do_express_probe(dev) == 0 && register_netdev(dev) == 0) { 1717 if (do_express_probe(dev) == 0) {
1720 dev_eexp[this_dev] = dev; 1718 dev_eexp[this_dev] = dev;
1721 found++; 1719 found++;
1722 continue; 1720 continue;
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 81ebaedaa240..87f522738bfc 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -1003,7 +1003,7 @@ static void epic_init_ring(struct net_device *dev)
1003 skb->dev = dev; /* Mark as being used by this device. */ 1003 skb->dev = dev; /* Mark as being used by this device. */
1004 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1004 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1005 ep->rx_ring[i].bufaddr = pci_map_single(ep->pci_dev, 1005 ep->rx_ring[i].bufaddr = pci_map_single(ep->pci_dev,
1006 skb->tail, ep->rx_buf_sz, PCI_DMA_FROMDEVICE); 1006 skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
1007 ep->rx_ring[i].rxstatus = cpu_to_le32(DescOwn); 1007 ep->rx_ring[i].rxstatus = cpu_to_le32(DescOwn);
1008 } 1008 }
1009 ep->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 1009 ep->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
@@ -1274,7 +1274,7 @@ static int epic_rx(struct net_device *dev, int budget)
1274 ep->rx_ring[entry].bufaddr, 1274 ep->rx_ring[entry].bufaddr,
1275 ep->rx_buf_sz, 1275 ep->rx_buf_sz,
1276 PCI_DMA_FROMDEVICE); 1276 PCI_DMA_FROMDEVICE);
1277 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->tail, pkt_len, 0); 1277 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->data, pkt_len, 0);
1278 skb_put(skb, pkt_len); 1278 skb_put(skb, pkt_len);
1279 pci_dma_sync_single_for_device(ep->pci_dev, 1279 pci_dma_sync_single_for_device(ep->pci_dev,
1280 ep->rx_ring[entry].bufaddr, 1280 ep->rx_ring[entry].bufaddr,
@@ -1308,7 +1308,7 @@ static int epic_rx(struct net_device *dev, int budget)
1308 skb->dev = dev; /* Mark as being used by this device. */ 1308 skb->dev = dev; /* Mark as being used by this device. */
1309 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1309 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1310 ep->rx_ring[entry].bufaddr = pci_map_single(ep->pci_dev, 1310 ep->rx_ring[entry].bufaddr = pci_map_single(ep->pci_dev,
1311 skb->tail, ep->rx_buf_sz, PCI_DMA_FROMDEVICE); 1311 skb->data, ep->rx_buf_sz, PCI_DMA_FROMDEVICE);
1312 work_done++; 1312 work_done++;
1313 } 1313 }
1314 ep->rx_ring[entry].rxstatus = cpu_to_le32(DescOwn); 1314 ep->rx_ring[entry].rxstatus = cpu_to_le32(DescOwn);
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
index dd6865820372..aa1569182fd6 100644
--- a/drivers/net/eql.c
+++ b/drivers/net/eql.c
@@ -132,7 +132,7 @@ static struct net_device_stats *eql_get_stats(struct net_device *dev);
132#define eql_is_slave(dev) ((dev->flags & IFF_SLAVE) == IFF_SLAVE) 132#define eql_is_slave(dev) ((dev->flags & IFF_SLAVE) == IFF_SLAVE)
133#define eql_is_master(dev) ((dev->flags & IFF_MASTER) == IFF_MASTER) 133#define eql_is_master(dev) ((dev->flags & IFF_MASTER) == IFF_MASTER)
134 134
135static void eql_kill_one_slave(slave_t *slave); 135static void eql_kill_one_slave(slave_queue_t *queue, slave_t *slave);
136 136
137static void eql_timer(unsigned long param) 137static void eql_timer(unsigned long param)
138{ 138{
@@ -149,7 +149,7 @@ static void eql_timer(unsigned long param)
149 if (slave->bytes_queued < 0) 149 if (slave->bytes_queued < 0)
150 slave->bytes_queued = 0; 150 slave->bytes_queued = 0;
151 } else { 151 } else {
152 eql_kill_one_slave(slave); 152 eql_kill_one_slave(&eql->queue, slave);
153 } 153 }
154 154
155 } 155 }
@@ -214,9 +214,10 @@ static int eql_open(struct net_device *dev)
214 return 0; 214 return 0;
215} 215}
216 216
217static void eql_kill_one_slave(slave_t *slave) 217static void eql_kill_one_slave(slave_queue_t *queue, slave_t *slave)
218{ 218{
219 list_del(&slave->list); 219 list_del(&slave->list);
220 queue->num_slaves--;
220 slave->dev->flags &= ~IFF_SLAVE; 221 slave->dev->flags &= ~IFF_SLAVE;
221 dev_put(slave->dev); 222 dev_put(slave->dev);
222 kfree(slave); 223 kfree(slave);
@@ -232,8 +233,7 @@ static void eql_kill_slave_queue(slave_queue_t *queue)
232 list_for_each_safe(this, tmp, head) { 233 list_for_each_safe(this, tmp, head) {
233 slave_t *s = list_entry(this, slave_t, list); 234 slave_t *s = list_entry(this, slave_t, list);
234 235
235 eql_kill_one_slave(s); 236 eql_kill_one_slave(queue, s);
236 queue->num_slaves--;
237 } 237 }
238 238
239 spin_unlock_bh(&queue->lock); 239 spin_unlock_bh(&queue->lock);
@@ -318,7 +318,7 @@ static slave_t *__eql_schedule_slaves(slave_queue_t *queue)
318 } 318 }
319 } else { 319 } else {
320 /* We found a dead slave, kill it. */ 320 /* We found a dead slave, kill it. */
321 eql_kill_one_slave(slave); 321 eql_kill_one_slave(queue, slave);
322 } 322 }
323 } 323 }
324 return best_slave; 324 return best_slave;
@@ -393,7 +393,7 @@ static int __eql_insert_slave(slave_queue_t *queue, slave_t *slave)
393 393
394 duplicate_slave = __eql_find_slave_dev(queue, slave->dev); 394 duplicate_slave = __eql_find_slave_dev(queue, slave->dev);
395 if (duplicate_slave != 0) 395 if (duplicate_slave != 0)
396 eql_kill_one_slave(duplicate_slave); 396 eql_kill_one_slave(queue, duplicate_slave);
397 397
398 list_add(&slave->list, &queue->all_slaves); 398 list_add(&slave->list, &queue->all_slaves);
399 queue->num_slaves++; 399 queue->num_slaves++;
@@ -471,7 +471,7 @@ static int eql_emancipate(struct net_device *master_dev, slaving_request_t __use
471 slave_dev); 471 slave_dev);
472 472
473 if (slave) { 473 if (slave) {
474 eql_kill_one_slave(slave); 474 eql_kill_one_slave(&eql->queue, slave);
475 ret = 0; 475 ret = 0;
476 } 476 }
477 } 477 }
diff --git a/drivers/net/es3210.c b/drivers/net/es3210.c
index f1e8150ed2a0..50f8e23bb9e5 100644
--- a/drivers/net/es3210.c
+++ b/drivers/net/es3210.c
@@ -177,12 +177,7 @@ struct net_device * __init es_probe(int unit)
177 err = do_es_probe(dev); 177 err = do_es_probe(dev);
178 if (err) 178 if (err)
179 goto out; 179 goto out;
180 err = register_netdev(dev);
181 if (err)
182 goto out1;
183 return dev; 180 return dev;
184out1:
185 cleanup_card(dev);
186out: 181out:
187 free_netdev(dev); 182 free_netdev(dev);
188 return ERR_PTR(err); 183 return ERR_PTR(err);
@@ -310,6 +305,10 @@ static int __init es_probe1(struct net_device *dev, int ioaddr)
310 dev->poll_controller = ei_poll; 305 dev->poll_controller = ei_poll;
311#endif 306#endif
312 NS8390_init(dev, 0); 307 NS8390_init(dev, 0);
308
309 retval = register_netdev(dev);
310 if (retval)
311 goto out1;
313 return 0; 312 return 0;
314out1: 313out1:
315 free_irq(dev->irq, dev); 314 free_irq(dev->irq, dev);
@@ -445,11 +444,8 @@ init_module(void)
445 dev->base_addr = io[this_dev]; 444 dev->base_addr = io[this_dev];
446 dev->mem_start = mem[this_dev]; 445 dev->mem_start = mem[this_dev];
447 if (do_es_probe(dev) == 0) { 446 if (do_es_probe(dev) == 0) {
448 if (register_netdev(dev) == 0) { 447 dev_es3210[found++] = dev;
449 dev_es3210[found++] = dev; 448 continue;
450 continue;
451 }
452 cleanup_card(dev);
453 } 449 }
454 free_netdev(dev); 450 free_netdev(dev);
455 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]); 451 printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/eth16i.c b/drivers/net/eth16i.c
index ccae6ba5f7c5..f32a6b3acb2a 100644
--- a/drivers/net/eth16i.c
+++ b/drivers/net/eth16i.c
@@ -473,13 +473,7 @@ struct net_device * __init eth16i_probe(int unit)
473 err = do_eth16i_probe(dev); 473 err = do_eth16i_probe(dev);
474 if (err) 474 if (err)
475 goto out; 475 goto out;
476 err = register_netdev(dev);
477 if (err)
478 goto out1;
479 return dev; 476 return dev;
480out1:
481 free_irq(dev->irq, dev);
482 release_region(dev->base_addr, ETH16I_IO_EXTENT);
483out: 477out:
484 free_netdev(dev); 478 free_netdev(dev);
485 return ERR_PTR(err); 479 return ERR_PTR(err);
@@ -569,7 +563,13 @@ static int __init eth16i_probe1(struct net_device *dev, int ioaddr)
569 dev->tx_timeout = eth16i_timeout; 563 dev->tx_timeout = eth16i_timeout;
570 dev->watchdog_timeo = TX_TIMEOUT; 564 dev->watchdog_timeo = TX_TIMEOUT;
571 spin_lock_init(&lp->lock); 565 spin_lock_init(&lp->lock);
566
567 retval = register_netdev(dev);
568 if (retval)
569 goto out1;
572 return 0; 570 return 0;
571out1:
572 free_irq(dev->irq, dev);
573out: 573out:
574 release_region(ioaddr, ETH16I_IO_EXTENT); 574 release_region(ioaddr, ETH16I_IO_EXTENT);
575 return retval; 575 return retval;
@@ -1462,12 +1462,8 @@ int init_module(void)
1462 } 1462 }
1463 1463
1464 if (do_eth16i_probe(dev) == 0) { 1464 if (do_eth16i_probe(dev) == 0) {
1465 if (register_netdev(dev) == 0) { 1465 dev_eth16i[found++] = dev;
1466 dev_eth16i[found++] = dev; 1466 continue;
1467 continue;
1468 }
1469 free_irq(dev->irq, dev);
1470 release_region(dev->base_addr, ETH16I_IO_EXTENT);
1471 } 1467 }
1472 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n", 1468 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n",
1473 io[this_dev]); 1469 io[this_dev]);
diff --git a/drivers/net/ewrk3.c b/drivers/net/ewrk3.c
index dcf969b20be9..b987f9474730 100644
--- a/drivers/net/ewrk3.c
+++ b/drivers/net/ewrk3.c
@@ -1308,15 +1308,9 @@ static int __init eisa_probe(struct net_device *dev, u_long ioaddr)
1308 if (ioaddr < 0x1000) 1308 if (ioaddr < 0x1000)
1309 goto out; 1309 goto out;
1310 1310
1311 if (ioaddr == 0) { /* Autoprobing */ 1311 iobase = ioaddr;
1312 iobase = EISA_SLOT_INC; /* Get the first slot address */ 1312 i = (ioaddr >> 12);
1313 i = 1; 1313 maxSlots = i + 1;
1314 maxSlots = MAX_EISA_SLOTS;
1315 } else { /* Probe a specific location */
1316 iobase = ioaddr;
1317 i = (ioaddr >> 12);
1318 maxSlots = i + 1;
1319 }
1320 1314
1321 for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) { 1315 for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) {
1322 if (EISA_signature(name, EISA_ID) == 0) { 1316 if (EISA_signature(name, EISA_ID) == 0) {
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index d05e9dd1e140..55dbe9a3fd56 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -1107,7 +1107,7 @@ static void allocate_rx_buffers(struct net_device *dev)
1107 1107
1108 skb->dev = dev; /* Mark as being used by this device. */ 1108 skb->dev = dev; /* Mark as being used by this device. */
1109 np->lack_rxbuf->skbuff = skb; 1109 np->lack_rxbuf->skbuff = skb;
1110 np->lack_rxbuf->buffer = pci_map_single(np->pci_dev, skb->tail, 1110 np->lack_rxbuf->buffer = pci_map_single(np->pci_dev, skb->data,
1111 np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1111 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1112 np->lack_rxbuf->status = RXOWN; 1112 np->lack_rxbuf->status = RXOWN;
1113 ++np->really_rx_count; 1113 ++np->really_rx_count;
@@ -1300,7 +1300,7 @@ static void init_ring(struct net_device *dev)
1300 ++np->really_rx_count; 1300 ++np->really_rx_count;
1301 np->rx_ring[i].skbuff = skb; 1301 np->rx_ring[i].skbuff = skb;
1302 skb->dev = dev; /* Mark as being used by this device. */ 1302 skb->dev = dev; /* Mark as being used by this device. */
1303 np->rx_ring[i].buffer = pci_map_single(np->pci_dev, skb->tail, 1303 np->rx_ring[i].buffer = pci_map_single(np->pci_dev, skb->data,
1304 np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1304 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1305 np->rx_ring[i].status = RXOWN; 1305 np->rx_ring[i].status = RXOWN;
1306 np->rx_ring[i].control |= RXIC; 1306 np->rx_ring[i].control |= RXIC;
@@ -1423,8 +1423,7 @@ static void reset_tx_descriptors(struct net_device *dev)
1423 if (cur->skbuff) { 1423 if (cur->skbuff) {
1424 pci_unmap_single(np->pci_dev, cur->buffer, 1424 pci_unmap_single(np->pci_dev, cur->buffer,
1425 cur->skbuff->len, PCI_DMA_TODEVICE); 1425 cur->skbuff->len, PCI_DMA_TODEVICE);
1426 dev_kfree_skb(cur->skbuff); 1426 dev_kfree_skb_any(cur->skbuff);
1427 /* or dev_kfree_skb_irq(cur->skbuff); ? */
1428 cur->skbuff = NULL; 1427 cur->skbuff = NULL;
1429 } 1428 }
1430 cur->status = 0; 1429 cur->status = 0;
@@ -1738,11 +1737,11 @@ static int netdev_rx(struct net_device *dev)
1738 1737
1739#if ! defined(__alpha__) 1738#if ! defined(__alpha__)
1740 eth_copy_and_sum(skb, 1739 eth_copy_and_sum(skb,
1741 np->cur_rx->skbuff->tail, pkt_len, 0); 1740 np->cur_rx->skbuff->data, pkt_len, 0);
1742 skb_put(skb, pkt_len); 1741 skb_put(skb, pkt_len);
1743#else 1742#else
1744 memcpy(skb_put(skb, pkt_len), 1743 memcpy(skb_put(skb, pkt_len),
1745 np->cur_rx->skbuff->tail, pkt_len); 1744 np->cur_rx->skbuff->data, pkt_len);
1746#endif 1745#endif
1747 pci_dma_sync_single_for_device(np->pci_dev, 1746 pci_dma_sync_single_for_device(np->pci_dev,
1748 np->cur_rx->buffer, 1747 np->cur_rx->buffer,
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 4ebcd052e150..64f0f697c958 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -82,6 +82,9 @@
82 * 0.31: 14 Nov 2004: ethtool support for getting/setting link 82 * 0.31: 14 Nov 2004: ethtool support for getting/setting link
83 * capabilities. 83 * capabilities.
84 * 0.32: 16 Apr 2005: RX_ERROR4 handling added. 84 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
85 * 0.33: 16 May 2005: Support for MCP51 added.
86 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
87 * 0.35: 26 Jun 2005: Support for MCP55 added.
85 * 88 *
86 * Known bugs: 89 * Known bugs:
87 * We suspect that on some hardware no TX done interrupts are generated. 90 * We suspect that on some hardware no TX done interrupts are generated.
@@ -93,7 +96,7 @@
93 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few 96 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
94 * superfluous timer interrupts from the nic. 97 * superfluous timer interrupts from the nic.
95 */ 98 */
96#define FORCEDETH_VERSION "0.32" 99#define FORCEDETH_VERSION "0.35"
97#define DRV_NAME "forcedeth" 100#define DRV_NAME "forcedeth"
98 101
99#include <linux/module.h> 102#include <linux/module.h>
@@ -2005,7 +2008,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2005 /* handle different descriptor versions */ 2008 /* handle different descriptor versions */
2006 if (pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 || 2009 if (pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 ||
2007 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 || 2010 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 ||
2008 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_3) 2011 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_3 ||
2012 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
2013 pci_dev->device == PCI_DEVICE_ID_NVIDIA_NVENET_13)
2009 np->desc_ver = DESC_VER_1; 2014 np->desc_ver = DESC_VER_1;
2010 else 2015 else
2011 np->desc_ver = DESC_VER_2; 2016 np->desc_ver = DESC_VER_2;
@@ -2215,56 +2220,84 @@ static struct pci_device_id pci_tbl[] = {
2215 .device = PCI_DEVICE_ID_NVIDIA_NVENET_4, 2220 .device = PCI_DEVICE_ID_NVIDIA_NVENET_4,
2216 .subvendor = PCI_ANY_ID, 2221 .subvendor = PCI_ANY_ID,
2217 .subdevice = PCI_ANY_ID, 2222 .subdevice = PCI_ANY_ID,
2218 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2223 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2219 }, 2224 },
2220 { /* nForce3 Ethernet Controller */ 2225 { /* nForce3 Ethernet Controller */
2221 .vendor = PCI_VENDOR_ID_NVIDIA, 2226 .vendor = PCI_VENDOR_ID_NVIDIA,
2222 .device = PCI_DEVICE_ID_NVIDIA_NVENET_5, 2227 .device = PCI_DEVICE_ID_NVIDIA_NVENET_5,
2223 .subvendor = PCI_ANY_ID, 2228 .subvendor = PCI_ANY_ID,
2224 .subdevice = PCI_ANY_ID, 2229 .subdevice = PCI_ANY_ID,
2225 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2230 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2226 }, 2231 },
2227 { /* nForce3 Ethernet Controller */ 2232 { /* nForce3 Ethernet Controller */
2228 .vendor = PCI_VENDOR_ID_NVIDIA, 2233 .vendor = PCI_VENDOR_ID_NVIDIA,
2229 .device = PCI_DEVICE_ID_NVIDIA_NVENET_6, 2234 .device = PCI_DEVICE_ID_NVIDIA_NVENET_6,
2230 .subvendor = PCI_ANY_ID, 2235 .subvendor = PCI_ANY_ID,
2231 .subdevice = PCI_ANY_ID, 2236 .subdevice = PCI_ANY_ID,
2232 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2237 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2233 }, 2238 },
2234 { /* nForce3 Ethernet Controller */ 2239 { /* nForce3 Ethernet Controller */
2235 .vendor = PCI_VENDOR_ID_NVIDIA, 2240 .vendor = PCI_VENDOR_ID_NVIDIA,
2236 .device = PCI_DEVICE_ID_NVIDIA_NVENET_7, 2241 .device = PCI_DEVICE_ID_NVIDIA_NVENET_7,
2237 .subvendor = PCI_ANY_ID, 2242 .subvendor = PCI_ANY_ID,
2238 .subdevice = PCI_ANY_ID, 2243 .subdevice = PCI_ANY_ID,
2239 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2244 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2240 }, 2245 },
2241 { /* CK804 Ethernet Controller */ 2246 { /* CK804 Ethernet Controller */
2242 .vendor = PCI_VENDOR_ID_NVIDIA, 2247 .vendor = PCI_VENDOR_ID_NVIDIA,
2243 .device = PCI_DEVICE_ID_NVIDIA_NVENET_8, 2248 .device = PCI_DEVICE_ID_NVIDIA_NVENET_8,
2244 .subvendor = PCI_ANY_ID, 2249 .subvendor = PCI_ANY_ID,
2245 .subdevice = PCI_ANY_ID, 2250 .subdevice = PCI_ANY_ID,
2246 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2251 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2247 }, 2252 },
2248 { /* CK804 Ethernet Controller */ 2253 { /* CK804 Ethernet Controller */
2249 .vendor = PCI_VENDOR_ID_NVIDIA, 2254 .vendor = PCI_VENDOR_ID_NVIDIA,
2250 .device = PCI_DEVICE_ID_NVIDIA_NVENET_9, 2255 .device = PCI_DEVICE_ID_NVIDIA_NVENET_9,
2251 .subvendor = PCI_ANY_ID, 2256 .subvendor = PCI_ANY_ID,
2252 .subdevice = PCI_ANY_ID, 2257 .subdevice = PCI_ANY_ID,
2253 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2258 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2254 }, 2259 },
2255 { /* MCP04 Ethernet Controller */ 2260 { /* MCP04 Ethernet Controller */
2256 .vendor = PCI_VENDOR_ID_NVIDIA, 2261 .vendor = PCI_VENDOR_ID_NVIDIA,
2257 .device = PCI_DEVICE_ID_NVIDIA_NVENET_10, 2262 .device = PCI_DEVICE_ID_NVIDIA_NVENET_10,
2258 .subvendor = PCI_ANY_ID, 2263 .subvendor = PCI_ANY_ID,
2259 .subdevice = PCI_ANY_ID, 2264 .subdevice = PCI_ANY_ID,
2260 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2265 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2261 }, 2266 },
2262 { /* MCP04 Ethernet Controller */ 2267 { /* MCP04 Ethernet Controller */
2263 .vendor = PCI_VENDOR_ID_NVIDIA, 2268 .vendor = PCI_VENDOR_ID_NVIDIA,
2264 .device = PCI_DEVICE_ID_NVIDIA_NVENET_11, 2269 .device = PCI_DEVICE_ID_NVIDIA_NVENET_11,
2265 .subvendor = PCI_ANY_ID, 2270 .subvendor = PCI_ANY_ID,
2266 .subdevice = PCI_ANY_ID, 2271 .subdevice = PCI_ANY_ID,
2267 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ, 2272 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2273 },
2274 { /* MCP51 Ethernet Controller */
2275 .vendor = PCI_VENDOR_ID_NVIDIA,
2276 .device = PCI_DEVICE_ID_NVIDIA_NVENET_12,
2277 .subvendor = PCI_ANY_ID,
2278 .subdevice = PCI_ANY_ID,
2279 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2280 },
2281 { /* MCP51 Ethernet Controller */
2282 .vendor = PCI_VENDOR_ID_NVIDIA,
2283 .device = PCI_DEVICE_ID_NVIDIA_NVENET_13,
2284 .subvendor = PCI_ANY_ID,
2285 .subdevice = PCI_ANY_ID,
2286 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2287 },
2288 { /* MCP55 Ethernet Controller */
2289 .vendor = PCI_VENDOR_ID_NVIDIA,
2290 .device = PCI_DEVICE_ID_NVIDIA_NVENET_14,
2291 .subvendor = PCI_ANY_ID,
2292 .subdevice = PCI_ANY_ID,
2293 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2294 },
2295 { /* MCP55 Ethernet Controller */
2296 .vendor = PCI_VENDOR_ID_NVIDIA,
2297 .device = PCI_DEVICE_ID_NVIDIA_NVENET_15,
2298 .subvendor = PCI_ANY_ID,
2299 .subdevice = PCI_ANY_ID,
2300 .driver_data = DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
2268 }, 2301 },
2269 {0,}, 2302 {0,},
2270}; 2303};
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index b43b2b11aacd..6518334b9280 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * drivers/net/gianfar.c 2 * drivers/net/gianfar.c
3 * 3 *
4 * Gianfar Ethernet Driver 4 * Gianfar Ethernet Driver
@@ -22,10 +22,9 @@
22 * B-V +1.62 22 * B-V +1.62
23 * 23 *
24 * Theory of operation 24 * Theory of operation
25 * This driver is designed for the Triple-speed Ethernet 25 * This driver is designed for the non-CPM ethernet controllers
26 * controllers on the Freescale 8540/8560 integrated processors, 26 * on the 85xx and 83xx family of integrated processors
27 * as well as the Fast Ethernet Controller on the 8540. 27 *
28 *
29 * The driver is initialized through platform_device. Structures which 28 * The driver is initialized through platform_device. Structures which
30 * define the configuration needed by the board are defined in a 29 * define the configuration needed by the board are defined in a
31 * board structure in arch/ppc/platforms (though I do not 30 * board structure in arch/ppc/platforms (though I do not
@@ -39,12 +38,12 @@
39 * 38 *
40 * The Gianfar Ethernet Controller uses a ring of buffer 39 * The Gianfar Ethernet Controller uses a ring of buffer
41 * descriptors. The beginning is indicated by a register 40 * descriptors. The beginning is indicated by a register
42 * pointing to the physical address of the start of the ring. 41 * pointing to the physical address of the start of the ring.
43 * The end is determined by a "wrap" bit being set in the 42 * The end is determined by a "wrap" bit being set in the
44 * last descriptor of the ring. 43 * last descriptor of the ring.
45 * 44 *
46 * When a packet is received, the RXF bit in the 45 * When a packet is received, the RXF bit in the
47 * IEVENT register is set, triggering an interrupt when the 46 * IEVENT register is set, triggering an interrupt when the
48 * corresponding bit in the IMASK register is also set (if 47 * corresponding bit in the IMASK register is also set (if
49 * interrupt coalescing is active, then the interrupt may not 48 * interrupt coalescing is active, then the interrupt may not
50 * happen immediately, but will wait until either a set number 49 * happen immediately, but will wait until either a set number
@@ -52,7 +51,7 @@
52 * interrupt handler will signal there is work to be done, and 51 * interrupt handler will signal there is work to be done, and
53 * exit. Without NAPI, the packet(s) will be handled 52 * exit. Without NAPI, the packet(s) will be handled
54 * immediately. Both methods will start at the last known empty 53 * immediately. Both methods will start at the last known empty
55 * descriptor, and process every subsequent descriptor until there 54 * descriptor, and process every subsequent descriptor until there
56 * are none left with data (NAPI will stop after a set number of 55 * are none left with data (NAPI will stop after a set number of
57 * packets to give time to other tasks, but will eventually 56 * packets to give time to other tasks, but will eventually
58 * process all the packets). The data arrives inside a 57 * process all the packets). The data arrives inside a
@@ -83,9 +82,13 @@
83#include <linux/netdevice.h> 82#include <linux/netdevice.h>
84#include <linux/etherdevice.h> 83#include <linux/etherdevice.h>
85#include <linux/skbuff.h> 84#include <linux/skbuff.h>
85#include <linux/if_vlan.h>
86#include <linux/spinlock.h> 86#include <linux/spinlock.h>
87#include <linux/mm.h> 87#include <linux/mm.h>
88#include <linux/device.h> 88#include <linux/device.h>
89#include <linux/ip.h>
90#include <linux/tcp.h>
91#include <linux/udp.h>
89 92
90#include <asm/io.h> 93#include <asm/io.h>
91#include <asm/irq.h> 94#include <asm/irq.h>
@@ -123,7 +126,7 @@ static int gfar_set_mac_address(struct net_device *dev);
123static int gfar_change_mtu(struct net_device *dev, int new_mtu); 126static int gfar_change_mtu(struct net_device *dev, int new_mtu);
124static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs); 127static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs);
125static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs); 128static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs);
126irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs); 129static irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs);
127static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs); 130static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs);
128static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs); 131static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
129static void gfar_phy_change(void *data); 132static void gfar_phy_change(void *data);
@@ -139,9 +142,12 @@ static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
139#ifdef CONFIG_GFAR_NAPI 142#ifdef CONFIG_GFAR_NAPI
140static int gfar_poll(struct net_device *dev, int *budget); 143static int gfar_poll(struct net_device *dev, int *budget);
141#endif 144#endif
142static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); 145int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
143static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length); 146static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
144static void gfar_phy_startup_timer(unsigned long data); 147static void gfar_phy_startup_timer(unsigned long data);
148static void gfar_vlan_rx_register(struct net_device *netdev,
149 struct vlan_group *grp);
150static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
145 151
146extern struct ethtool_ops gfar_ethtool_ops; 152extern struct ethtool_ops gfar_ethtool_ops;
147 153
@@ -149,6 +155,13 @@ MODULE_AUTHOR("Freescale Semiconductor, Inc");
149MODULE_DESCRIPTION("Gianfar Ethernet Driver"); 155MODULE_DESCRIPTION("Gianfar Ethernet Driver");
150MODULE_LICENSE("GPL"); 156MODULE_LICENSE("GPL");
151 157
158int gfar_uses_fcb(struct gfar_private *priv)
159{
160 if (priv->vlan_enable || priv->rx_csum_enable)
161 return 1;
162 else
163 return 0;
164}
152static int gfar_probe(struct device *device) 165static int gfar_probe(struct device *device)
153{ 166{
154 u32 tempval; 167 u32 tempval;
@@ -159,7 +172,6 @@ static int gfar_probe(struct device *device)
159 struct resource *r; 172 struct resource *r;
160 int idx; 173 int idx;
161 int err = 0; 174 int err = 0;
162 int dev_ethtool_ops = 0;
163 175
164 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data; 176 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data;
165 177
@@ -265,15 +277,69 @@ static int gfar_probe(struct device *device)
265 dev->mtu = 1500; 277 dev->mtu = 1500;
266 dev->set_multicast_list = gfar_set_multi; 278 dev->set_multicast_list = gfar_set_multi;
267 279
268 /* Index into the array of possible ethtool 280 dev->ethtool_ops = &gfar_ethtool_ops;
269 * ops to catch all 4 possibilities */ 281
270 if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) == 0) 282 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
271 dev_ethtool_ops += 1; 283 priv->rx_csum_enable = 1;
284 dev->features |= NETIF_F_IP_CSUM;
285 } else
286 priv->rx_csum_enable = 0;
287
288 priv->vlgrp = NULL;
272 289
273 if((priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE) == 0) 290 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
274 dev_ethtool_ops += 2; 291 dev->vlan_rx_register = gfar_vlan_rx_register;
292 dev->vlan_rx_kill_vid = gfar_vlan_rx_kill_vid;
275 293
276 dev->ethtool_ops = gfar_op_array[dev_ethtool_ops]; 294 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
295
296 priv->vlan_enable = 1;
297 }
298
299 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
300 priv->extended_hash = 1;
301 priv->hash_width = 9;
302
303 priv->hash_regs[0] = &priv->regs->igaddr0;
304 priv->hash_regs[1] = &priv->regs->igaddr1;
305 priv->hash_regs[2] = &priv->regs->igaddr2;
306 priv->hash_regs[3] = &priv->regs->igaddr3;
307 priv->hash_regs[4] = &priv->regs->igaddr4;
308 priv->hash_regs[5] = &priv->regs->igaddr5;
309 priv->hash_regs[6] = &priv->regs->igaddr6;
310 priv->hash_regs[7] = &priv->regs->igaddr7;
311 priv->hash_regs[8] = &priv->regs->gaddr0;
312 priv->hash_regs[9] = &priv->regs->gaddr1;
313 priv->hash_regs[10] = &priv->regs->gaddr2;
314 priv->hash_regs[11] = &priv->regs->gaddr3;
315 priv->hash_regs[12] = &priv->regs->gaddr4;
316 priv->hash_regs[13] = &priv->regs->gaddr5;
317 priv->hash_regs[14] = &priv->regs->gaddr6;
318 priv->hash_regs[15] = &priv->regs->gaddr7;
319
320 } else {
321 priv->extended_hash = 0;
322 priv->hash_width = 8;
323
324 priv->hash_regs[0] = &priv->regs->gaddr0;
325 priv->hash_regs[1] = &priv->regs->gaddr1;
326 priv->hash_regs[2] = &priv->regs->gaddr2;
327 priv->hash_regs[3] = &priv->regs->gaddr3;
328 priv->hash_regs[4] = &priv->regs->gaddr4;
329 priv->hash_regs[5] = &priv->regs->gaddr5;
330 priv->hash_regs[6] = &priv->regs->gaddr6;
331 priv->hash_regs[7] = &priv->regs->gaddr7;
332 }
333
334 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
335 priv->padding = DEFAULT_PADDING;
336 else
337 priv->padding = 0;
338
339 dev->hard_header_len += priv->padding;
340
341 if (dev->features & NETIF_F_IP_CSUM)
342 dev->hard_header_len += GMAC_FCB_LEN;
277 343
278 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; 344 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
279#ifdef CONFIG_GFAR_BUFSTASH 345#ifdef CONFIG_GFAR_BUFSTASH
@@ -289,6 +355,9 @@ static int gfar_probe(struct device *device)
289 priv->rxcount = DEFAULT_RXCOUNT; 355 priv->rxcount = DEFAULT_RXCOUNT;
290 priv->rxtime = DEFAULT_RXTIME; 356 priv->rxtime = DEFAULT_RXTIME;
291 357
358 /* Enable most messages by default */
359 priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
360
292 err = register_netdev(dev); 361 err = register_netdev(dev);
293 362
294 if (err) { 363 if (err) {
@@ -360,8 +429,9 @@ static int init_phy(struct net_device *dev)
360 GFP_KERNEL); 429 GFP_KERNEL);
361 430
362 if(NULL == mii_info) { 431 if(NULL == mii_info) {
363 printk(KERN_ERR "%s: Could not allocate mii_info\n", 432 if (netif_msg_ifup(priv))
364 dev->name); 433 printk(KERN_ERR "%s: Could not allocate mii_info\n",
434 dev->name);
365 return -ENOMEM; 435 return -ENOMEM;
366 } 436 }
367 437
@@ -410,7 +480,8 @@ static int init_phy(struct net_device *dev)
410 curphy = get_phy_info(priv->mii_info); 480 curphy = get_phy_info(priv->mii_info);
411 481
412 if (curphy == NULL) { 482 if (curphy == NULL) {
413 printk(KERN_ERR "%s: No PHY found\n", dev->name); 483 if (netif_msg_ifup(priv))
484 printk(KERN_ERR "%s: No PHY found\n", dev->name);
414 err = -1; 485 err = -1;
415 goto no_phy; 486 goto no_phy;
416 } 487 }
@@ -421,7 +492,7 @@ static int init_phy(struct net_device *dev)
421 if(curphy->init) { 492 if(curphy->init) {
422 err = curphy->init(priv->mii_info); 493 err = curphy->init(priv->mii_info);
423 494
424 if (err) 495 if (err)
425 goto phy_init_fail; 496 goto phy_init_fail;
426 } 497 }
427 498
@@ -446,14 +517,14 @@ static void init_registers(struct net_device *dev)
446 gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR); 517 gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
447 518
448 /* Init hash registers to zero */ 519 /* Init hash registers to zero */
449 gfar_write(&priv->regs->iaddr0, 0); 520 gfar_write(&priv->regs->igaddr0, 0);
450 gfar_write(&priv->regs->iaddr1, 0); 521 gfar_write(&priv->regs->igaddr1, 0);
451 gfar_write(&priv->regs->iaddr2, 0); 522 gfar_write(&priv->regs->igaddr2, 0);
452 gfar_write(&priv->regs->iaddr3, 0); 523 gfar_write(&priv->regs->igaddr3, 0);
453 gfar_write(&priv->regs->iaddr4, 0); 524 gfar_write(&priv->regs->igaddr4, 0);
454 gfar_write(&priv->regs->iaddr5, 0); 525 gfar_write(&priv->regs->igaddr5, 0);
455 gfar_write(&priv->regs->iaddr6, 0); 526 gfar_write(&priv->regs->igaddr6, 0);
456 gfar_write(&priv->regs->iaddr7, 0); 527 gfar_write(&priv->regs->igaddr7, 0);
457 528
458 gfar_write(&priv->regs->gaddr0, 0); 529 gfar_write(&priv->regs->gaddr0, 0);
459 gfar_write(&priv->regs->gaddr1, 0); 530 gfar_write(&priv->regs->gaddr1, 0);
@@ -464,9 +535,6 @@ static void init_registers(struct net_device *dev)
464 gfar_write(&priv->regs->gaddr6, 0); 535 gfar_write(&priv->regs->gaddr6, 0);
465 gfar_write(&priv->regs->gaddr7, 0); 536 gfar_write(&priv->regs->gaddr7, 0);
466 537
467 /* Zero out rctrl */
468 gfar_write(&priv->regs->rctrl, 0x00000000);
469
470 /* Zero out the rmon mib registers if it has them */ 538 /* Zero out the rmon mib registers if it has them */
471 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { 539 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
472 memset((void *) &(priv->regs->rmon), 0, 540 memset((void *) &(priv->regs->rmon), 0,
@@ -497,20 +565,14 @@ static void init_registers(struct net_device *dev)
497 gfar_write(&priv->regs->tbipa, TBIPA_VALUE); 565 gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
498} 566}
499 567
500void stop_gfar(struct net_device *dev) 568
569/* Halt the receive and transmit queues */
570void gfar_halt(struct net_device *dev)
501{ 571{
502 struct gfar_private *priv = netdev_priv(dev); 572 struct gfar_private *priv = netdev_priv(dev);
503 struct gfar *regs = priv->regs; 573 struct gfar *regs = priv->regs;
504 unsigned long flags;
505 u32 tempval; 574 u32 tempval;
506 575
507 /* Lock it down */
508 spin_lock_irqsave(&priv->lock, flags);
509
510 /* Tell the kernel the link is down */
511 priv->mii_info->link = 0;
512 adjust_link(dev);
513
514 /* Mask all interrupts */ 576 /* Mask all interrupts */
515 gfar_write(&regs->imask, IMASK_INIT_CLEAR); 577 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
516 578
@@ -533,13 +595,29 @@ void stop_gfar(struct net_device *dev)
533 tempval = gfar_read(&regs->maccfg1); 595 tempval = gfar_read(&regs->maccfg1);
534 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN); 596 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
535 gfar_write(&regs->maccfg1, tempval); 597 gfar_write(&regs->maccfg1, tempval);
598}
599
600void stop_gfar(struct net_device *dev)
601{
602 struct gfar_private *priv = netdev_priv(dev);
603 struct gfar *regs = priv->regs;
604 unsigned long flags;
605
606 /* Lock it down */
607 spin_lock_irqsave(&priv->lock, flags);
608
609 /* Tell the kernel the link is down */
610 priv->mii_info->link = 0;
611 adjust_link(dev);
612
613 gfar_halt(dev);
536 614
537 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { 615 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
538 /* Clear any pending interrupts */ 616 /* Clear any pending interrupts */
539 mii_clear_phy_interrupt(priv->mii_info); 617 mii_clear_phy_interrupt(priv->mii_info);
540 618
541 /* Disable PHY Interrupts */ 619 /* Disable PHY Interrupts */
542 mii_configure_phy_interrupt(priv->mii_info, 620 mii_configure_phy_interrupt(priv->mii_info,
543 MII_INTERRUPT_DISABLED); 621 MII_INTERRUPT_DISABLED);
544 } 622 }
545 623
@@ -566,7 +644,7 @@ void stop_gfar(struct net_device *dev)
566 sizeof(struct txbd8)*priv->tx_ring_size 644 sizeof(struct txbd8)*priv->tx_ring_size
567 + sizeof(struct rxbd8)*priv->rx_ring_size, 645 + sizeof(struct rxbd8)*priv->rx_ring_size,
568 priv->tx_bd_base, 646 priv->tx_bd_base,
569 gfar_read(&regs->tbase)); 647 gfar_read(&regs->tbase0));
570} 648}
571 649
572/* If there are any tx skbs or rx skbs still around, free them. 650/* If there are any tx skbs or rx skbs still around, free them.
@@ -620,6 +698,34 @@ void free_skb_resources(struct gfar_private *priv)
620 } 698 }
621} 699}
622 700
701void gfar_start(struct net_device *dev)
702{
703 struct gfar_private *priv = netdev_priv(dev);
704 struct gfar *regs = priv->regs;
705 u32 tempval;
706
707 /* Enable Rx and Tx in MACCFG1 */
708 tempval = gfar_read(&regs->maccfg1);
709 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
710 gfar_write(&regs->maccfg1, tempval);
711
712 /* Initialize DMACTRL to have WWR and WOP */
713 tempval = gfar_read(&priv->regs->dmactrl);
714 tempval |= DMACTRL_INIT_SETTINGS;
715 gfar_write(&priv->regs->dmactrl, tempval);
716
717 /* Clear THLT, so that the DMA starts polling now */
718 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
719
720 /* Make sure we aren't stopped */
721 tempval = gfar_read(&priv->regs->dmactrl);
722 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
723 gfar_write(&priv->regs->dmactrl, tempval);
724
725 /* Unmask the interrupts we look for */
726 gfar_write(&regs->imask, IMASK_DEFAULT);
727}
728
623/* Bring the controller up and running */ 729/* Bring the controller up and running */
624int startup_gfar(struct net_device *dev) 730int startup_gfar(struct net_device *dev)
625{ 731{
@@ -630,33 +736,34 @@ int startup_gfar(struct net_device *dev)
630 int i; 736 int i;
631 struct gfar_private *priv = netdev_priv(dev); 737 struct gfar_private *priv = netdev_priv(dev);
632 struct gfar *regs = priv->regs; 738 struct gfar *regs = priv->regs;
633 u32 tempval;
634 int err = 0; 739 int err = 0;
740 u32 rctrl = 0;
635 741
636 gfar_write(&regs->imask, IMASK_INIT_CLEAR); 742 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
637 743
638 /* Allocate memory for the buffer descriptors */ 744 /* Allocate memory for the buffer descriptors */
639 vaddr = (unsigned long) dma_alloc_coherent(NULL, 745 vaddr = (unsigned long) dma_alloc_coherent(NULL,
640 sizeof (struct txbd8) * priv->tx_ring_size + 746 sizeof (struct txbd8) * priv->tx_ring_size +
641 sizeof (struct rxbd8) * priv->rx_ring_size, 747 sizeof (struct rxbd8) * priv->rx_ring_size,
642 &addr, GFP_KERNEL); 748 &addr, GFP_KERNEL);
643 749
644 if (vaddr == 0) { 750 if (vaddr == 0) {
645 printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n", 751 if (netif_msg_ifup(priv))
646 dev->name); 752 printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
753 dev->name);
647 return -ENOMEM; 754 return -ENOMEM;
648 } 755 }
649 756
650 priv->tx_bd_base = (struct txbd8 *) vaddr; 757 priv->tx_bd_base = (struct txbd8 *) vaddr;
651 758
652 /* enet DMA only understands physical addresses */ 759 /* enet DMA only understands physical addresses */
653 gfar_write(&regs->tbase, addr); 760 gfar_write(&regs->tbase0, addr);
654 761
655 /* Start the rx descriptor ring where the tx ring leaves off */ 762 /* Start the rx descriptor ring where the tx ring leaves off */
656 addr = addr + sizeof (struct txbd8) * priv->tx_ring_size; 763 addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
657 vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size; 764 vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
658 priv->rx_bd_base = (struct rxbd8 *) vaddr; 765 priv->rx_bd_base = (struct rxbd8 *) vaddr;
659 gfar_write(&regs->rbase, addr); 766 gfar_write(&regs->rbase0, addr);
660 767
661 /* Setup the skbuff rings */ 768 /* Setup the skbuff rings */
662 priv->tx_skbuff = 769 priv->tx_skbuff =
@@ -664,8 +771,9 @@ int startup_gfar(struct net_device *dev)
664 priv->tx_ring_size, GFP_KERNEL); 771 priv->tx_ring_size, GFP_KERNEL);
665 772
666 if (priv->tx_skbuff == NULL) { 773 if (priv->tx_skbuff == NULL) {
667 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", 774 if (netif_msg_ifup(priv))
668 dev->name); 775 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
776 dev->name);
669 err = -ENOMEM; 777 err = -ENOMEM;
670 goto tx_skb_fail; 778 goto tx_skb_fail;
671 } 779 }
@@ -678,8 +786,9 @@ int startup_gfar(struct net_device *dev)
678 priv->rx_ring_size, GFP_KERNEL); 786 priv->rx_ring_size, GFP_KERNEL);
679 787
680 if (priv->rx_skbuff == NULL) { 788 if (priv->rx_skbuff == NULL) {
681 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", 789 if (netif_msg_ifup(priv))
682 dev->name); 790 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
791 dev->name);
683 err = -ENOMEM; 792 err = -ENOMEM;
684 goto rx_skb_fail; 793 goto rx_skb_fail;
685 } 794 }
@@ -726,12 +835,13 @@ int startup_gfar(struct net_device *dev)
726 /* If the device has multiple interrupts, register for 835 /* If the device has multiple interrupts, register for
727 * them. Otherwise, only register for the one */ 836 * them. Otherwise, only register for the one */
728 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { 837 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
729 /* Install our interrupt handlers for Error, 838 /* Install our interrupt handlers for Error,
730 * Transmit, and Receive */ 839 * Transmit, and Receive */
731 if (request_irq(priv->interruptError, gfar_error, 840 if (request_irq(priv->interruptError, gfar_error,
732 0, "enet_error", dev) < 0) { 841 0, "enet_error", dev) < 0) {
733 printk(KERN_ERR "%s: Can't get IRQ %d\n", 842 if (netif_msg_intr(priv))
734 dev->name, priv->interruptError); 843 printk(KERN_ERR "%s: Can't get IRQ %d\n",
844 dev->name, priv->interruptError);
735 845
736 err = -1; 846 err = -1;
737 goto err_irq_fail; 847 goto err_irq_fail;
@@ -739,8 +849,9 @@ int startup_gfar(struct net_device *dev)
739 849
740 if (request_irq(priv->interruptTransmit, gfar_transmit, 850 if (request_irq(priv->interruptTransmit, gfar_transmit,
741 0, "enet_tx", dev) < 0) { 851 0, "enet_tx", dev) < 0) {
742 printk(KERN_ERR "%s: Can't get IRQ %d\n", 852 if (netif_msg_intr(priv))
743 dev->name, priv->interruptTransmit); 853 printk(KERN_ERR "%s: Can't get IRQ %d\n",
854 dev->name, priv->interruptTransmit);
744 855
745 err = -1; 856 err = -1;
746 857
@@ -749,8 +860,9 @@ int startup_gfar(struct net_device *dev)
749 860
750 if (request_irq(priv->interruptReceive, gfar_receive, 861 if (request_irq(priv->interruptReceive, gfar_receive,
751 0, "enet_rx", dev) < 0) { 862 0, "enet_rx", dev) < 0) {
752 printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n", 863 if (netif_msg_intr(priv))
753 dev->name, priv->interruptReceive); 864 printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
865 dev->name, priv->interruptReceive);
754 866
755 err = -1; 867 err = -1;
756 goto rx_irq_fail; 868 goto rx_irq_fail;
@@ -758,8 +870,9 @@ int startup_gfar(struct net_device *dev)
758 } else { 870 } else {
759 if (request_irq(priv->interruptTransmit, gfar_interrupt, 871 if (request_irq(priv->interruptTransmit, gfar_interrupt,
760 0, "gfar_interrupt", dev) < 0) { 872 0, "gfar_interrupt", dev) < 0) {
761 printk(KERN_ERR "%s: Can't get IRQ %d\n", 873 if (netif_msg_intr(priv))
762 dev->name, priv->interruptError); 874 printk(KERN_ERR "%s: Can't get IRQ %d\n",
875 dev->name, priv->interruptError);
763 876
764 err = -1; 877 err = -1;
765 goto err_irq_fail; 878 goto err_irq_fail;
@@ -787,28 +900,22 @@ int startup_gfar(struct net_device *dev)
787 else 900 else
788 gfar_write(&regs->rxic, 0); 901 gfar_write(&regs->rxic, 0);
789 902
790 init_waitqueue_head(&priv->rxcleanupq); 903 if (priv->rx_csum_enable)
904 rctrl |= RCTRL_CHECKSUMMING;
791 905
792 /* Enable Rx and Tx in MACCFG1 */ 906 if (priv->extended_hash)
793 tempval = gfar_read(&regs->maccfg1); 907 rctrl |= RCTRL_EXTHASH;
794 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
795 gfar_write(&regs->maccfg1, tempval);
796 908
797 /* Initialize DMACTRL to have WWR and WOP */ 909 if (priv->vlan_enable)
798 tempval = gfar_read(&priv->regs->dmactrl); 910 rctrl |= RCTRL_VLAN;
799 tempval |= DMACTRL_INIT_SETTINGS;
800 gfar_write(&priv->regs->dmactrl, tempval);
801 911
802 /* Clear THLT, so that the DMA starts polling now */ 912 /* Init rctrl based on our settings */
803 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT); 913 gfar_write(&priv->regs->rctrl, rctrl);
804 914
805 /* Make sure we aren't stopped */ 915 if (dev->features & NETIF_F_IP_CSUM)
806 tempval = gfar_read(&priv->regs->dmactrl); 916 gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
807 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
808 gfar_write(&priv->regs->dmactrl, tempval);
809 917
810 /* Unmask the interrupts we look for */ 918 gfar_start(dev);
811 gfar_write(&regs->imask, IMASK_DEFAULT);
812 919
813 return 0; 920 return 0;
814 921
@@ -824,7 +931,7 @@ tx_skb_fail:
824 sizeof(struct txbd8)*priv->tx_ring_size 931 sizeof(struct txbd8)*priv->tx_ring_size
825 + sizeof(struct rxbd8)*priv->rx_ring_size, 932 + sizeof(struct rxbd8)*priv->rx_ring_size,
826 priv->tx_bd_base, 933 priv->tx_bd_base,
827 gfar_read(&regs->tbase)); 934 gfar_read(&regs->tbase0));
828 935
829 if (priv->mii_info->phyinfo->close) 936 if (priv->mii_info->phyinfo->close)
830 priv->mii_info->phyinfo->close(priv->mii_info); 937 priv->mii_info->phyinfo->close(priv->mii_info);
@@ -857,11 +964,62 @@ static int gfar_enet_open(struct net_device *dev)
857 return err; 964 return err;
858} 965}
859 966
967static struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp)
968{
969 struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
970
971 memset(fcb, 0, GMAC_FCB_LEN);
972
973 /* Flag the bd so the controller looks for the FCB */
974 bdp->status |= TXBD_TOE;
975
976 return fcb;
977}
978
979static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
980{
981 int len;
982
983 /* If we're here, it's a IP packet with a TCP or UDP
984 * payload. We set it to checksum, using a pseudo-header
985 * we provide
986 */
987 fcb->ip = 1;
988 fcb->tup = 1;
989 fcb->ctu = 1;
990 fcb->nph = 1;
991
992 /* Notify the controller what the protocol is */
993 if (skb->nh.iph->protocol == IPPROTO_UDP)
994 fcb->udp = 1;
995
996 /* l3os is the distance between the start of the
997 * frame (skb->data) and the start of the IP hdr.
998 * l4os is the distance between the start of the
999 * l3 hdr and the l4 hdr */
1000 fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN);
1001 fcb->l4os = (u16)(skb->h.raw - skb->nh.raw);
1002
1003 len = skb->nh.iph->tot_len - fcb->l4os;
1004
1005 /* Provide the pseudoheader csum */
1006 fcb->phcs = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1007 skb->nh.iph->daddr, len,
1008 skb->nh.iph->protocol, 0);
1009}
1010
1011void gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
1012{
1013 fcb->vln = 1;
1014 fcb->vlctl = vlan_tx_tag_get(skb);
1015}
1016
860/* This is called by the kernel when a frame is ready for transmission. */ 1017/* This is called by the kernel when a frame is ready for transmission. */
861/* It is pointed to by the dev->hard_start_xmit function pointer */ 1018/* It is pointed to by the dev->hard_start_xmit function pointer */
862static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) 1019static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
863{ 1020{
864 struct gfar_private *priv = netdev_priv(dev); 1021 struct gfar_private *priv = netdev_priv(dev);
1022 struct txfcb *fcb = NULL;
865 struct txbd8 *txbdp; 1023 struct txbd8 *txbdp;
866 1024
867 /* Update transmit stats */ 1025 /* Update transmit stats */
@@ -876,9 +1034,24 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
876 /* Clear all but the WRAP status flags */ 1034 /* Clear all but the WRAP status flags */
877 txbdp->status &= TXBD_WRAP; 1035 txbdp->status &= TXBD_WRAP;
878 1036
1037 /* Set up checksumming */
1038 if ((dev->features & NETIF_F_IP_CSUM)
1039 && (CHECKSUM_HW == skb->ip_summed)) {
1040 fcb = gfar_add_fcb(skb, txbdp);
1041 gfar_tx_checksum(skb, fcb);
1042 }
1043
1044 if (priv->vlan_enable &&
1045 unlikely(priv->vlgrp && vlan_tx_tag_present(skb))) {
1046 if (NULL == fcb)
1047 fcb = gfar_add_fcb(skb, txbdp);
1048
1049 gfar_tx_vlan(skb, fcb);
1050 }
1051
879 /* Set buffer length and pointer */ 1052 /* Set buffer length and pointer */
880 txbdp->length = skb->len; 1053 txbdp->length = skb->len;
881 txbdp->bufPtr = dma_map_single(NULL, skb->data, 1054 txbdp->bufPtr = dma_map_single(NULL, skb->data,
882 skb->len, DMA_TO_DEVICE); 1055 skb->len, DMA_TO_DEVICE);
883 1056
884 /* Save the skb pointer so we can free it later */ 1057 /* Save the skb pointer so we can free it later */
@@ -972,15 +1145,78 @@ int gfar_set_mac_address(struct net_device *dev)
972} 1145}
973 1146
974 1147
1148/* Enables and disables VLAN insertion/extraction */
1149static void gfar_vlan_rx_register(struct net_device *dev,
1150 struct vlan_group *grp)
1151{
1152 struct gfar_private *priv = netdev_priv(dev);
1153 unsigned long flags;
1154 u32 tempval;
1155
1156 spin_lock_irqsave(&priv->lock, flags);
1157
1158 priv->vlgrp = grp;
1159
1160 if (grp) {
1161 /* Enable VLAN tag insertion */
1162 tempval = gfar_read(&priv->regs->tctrl);
1163 tempval |= TCTRL_VLINS;
1164
1165 gfar_write(&priv->regs->tctrl, tempval);
1166
1167 /* Enable VLAN tag extraction */
1168 tempval = gfar_read(&priv->regs->rctrl);
1169 tempval |= RCTRL_VLEX;
1170 gfar_write(&priv->regs->rctrl, tempval);
1171 } else {
1172 /* Disable VLAN tag insertion */
1173 tempval = gfar_read(&priv->regs->tctrl);
1174 tempval &= ~TCTRL_VLINS;
1175 gfar_write(&priv->regs->tctrl, tempval);
1176
1177 /* Disable VLAN tag extraction */
1178 tempval = gfar_read(&priv->regs->rctrl);
1179 tempval &= ~RCTRL_VLEX;
1180 gfar_write(&priv->regs->rctrl, tempval);
1181 }
1182
1183 spin_unlock_irqrestore(&priv->lock, flags);
1184}
1185
1186
1187static void gfar_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
1188{
1189 struct gfar_private *priv = netdev_priv(dev);
1190 unsigned long flags;
1191
1192 spin_lock_irqsave(&priv->lock, flags);
1193
1194 if (priv->vlgrp)
1195 priv->vlgrp->vlan_devices[vid] = NULL;
1196
1197 spin_unlock_irqrestore(&priv->lock, flags);
1198}
1199
1200
975static int gfar_change_mtu(struct net_device *dev, int new_mtu) 1201static int gfar_change_mtu(struct net_device *dev, int new_mtu)
976{ 1202{
977 int tempsize, tempval; 1203 int tempsize, tempval;
978 struct gfar_private *priv = netdev_priv(dev); 1204 struct gfar_private *priv = netdev_priv(dev);
979 int oldsize = priv->rx_buffer_size; 1205 int oldsize = priv->rx_buffer_size;
980 int frame_size = new_mtu + 18; 1206 int frame_size = new_mtu + ETH_HLEN;
1207
1208 if (priv->vlan_enable)
1209 frame_size += VLAN_ETH_HLEN;
1210
1211 if (gfar_uses_fcb(priv))
1212 frame_size += GMAC_FCB_LEN;
1213
1214 frame_size += priv->padding;
981 1215
982 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) { 1216 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
983 printk(KERN_ERR "%s: Invalid MTU setting\n", dev->name); 1217 if (netif_msg_drv(priv))
1218 printk(KERN_ERR "%s: Invalid MTU setting\n",
1219 dev->name);
984 return -EINVAL; 1220 return -EINVAL;
985 } 1221 }
986 1222
@@ -1120,7 +1356,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1120 skb->dev = dev; 1356 skb->dev = dev;
1121 1357
1122 bdp->bufPtr = dma_map_single(NULL, skb->data, 1358 bdp->bufPtr = dma_map_single(NULL, skb->data,
1123 priv->rx_buffer_size + RXBUF_ALIGNMENT, 1359 priv->rx_buffer_size + RXBUF_ALIGNMENT,
1124 DMA_FROM_DEVICE); 1360 DMA_FROM_DEVICE);
1125 1361
1126 bdp->length = 0; 1362 bdp->length = 0;
@@ -1190,11 +1426,10 @@ irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs)
1190 1426
1191 __netif_rx_schedule(dev); 1427 __netif_rx_schedule(dev);
1192 } else { 1428 } else {
1193#ifdef VERBOSE_GFAR_ERRORS 1429 if (netif_msg_rx_err(priv))
1194 printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n", 1430 printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
1195 dev->name, gfar_read(&priv->regs->ievent), 1431 dev->name, gfar_read(&priv->regs->ievent),
1196 gfar_read(&priv->regs->imask)); 1432 gfar_read(&priv->regs->imask));
1197#endif
1198 } 1433 }
1199#else 1434#else
1200 1435
@@ -1209,15 +1444,43 @@ irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs)
1209 else 1444 else
1210 gfar_write(&priv->regs->rxic, 0); 1445 gfar_write(&priv->regs->rxic, 0);
1211 1446
1212 /* Just in case we need to wake the ring param changer */
1213 priv->rxclean = 1;
1214
1215 spin_unlock(&priv->lock); 1447 spin_unlock(&priv->lock);
1216#endif 1448#endif
1217 1449
1218 return IRQ_HANDLED; 1450 return IRQ_HANDLED;
1219} 1451}
1220 1452
1453static inline int gfar_rx_vlan(struct sk_buff *skb,
1454 struct vlan_group *vlgrp, unsigned short vlctl)
1455{
1456#ifdef CONFIG_GFAR_NAPI
1457 return vlan_hwaccel_receive_skb(skb, vlgrp, vlctl);
1458#else
1459 return vlan_hwaccel_rx(skb, vlgrp, vlctl);
1460#endif
1461}
1462
1463static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
1464{
1465 /* If valid headers were found, and valid sums
1466 * were verified, then we tell the kernel that no
1467 * checksumming is necessary. Otherwise, it is */
1468 if (fcb->cip && !fcb->eip && fcb->ctu && !fcb->etu)
1469 skb->ip_summed = CHECKSUM_UNNECESSARY;
1470 else
1471 skb->ip_summed = CHECKSUM_NONE;
1472}
1473
1474
1475static inline struct rxfcb *gfar_get_fcb(struct sk_buff *skb)
1476{
1477 struct rxfcb *fcb = (struct rxfcb *)skb->data;
1478
1479 /* Remove the FCB from the skb */
1480 skb_pull(skb, GMAC_FCB_LEN);
1481
1482 return fcb;
1483}
1221 1484
1222/* gfar_process_frame() -- handle one incoming packet if skb 1485/* gfar_process_frame() -- handle one incoming packet if skb
1223 * isn't NULL. */ 1486 * isn't NULL. */
@@ -1225,35 +1488,51 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
1225 int length) 1488 int length)
1226{ 1489{
1227 struct gfar_private *priv = netdev_priv(dev); 1490 struct gfar_private *priv = netdev_priv(dev);
1491 struct rxfcb *fcb = NULL;
1228 1492
1229 if (skb == NULL) { 1493 if (skb == NULL) {
1230#ifdef BRIEF_GFAR_ERRORS 1494 if (netif_msg_rx_err(priv))
1231 printk(KERN_WARNING "%s: Missing skb!!.\n", 1495 printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name);
1232 dev->name);
1233#endif
1234 priv->stats.rx_dropped++; 1496 priv->stats.rx_dropped++;
1235 priv->extra_stats.rx_skbmissing++; 1497 priv->extra_stats.rx_skbmissing++;
1236 } else { 1498 } else {
1499 int ret;
1500
1237 /* Prep the skb for the packet */ 1501 /* Prep the skb for the packet */
1238 skb_put(skb, length); 1502 skb_put(skb, length);
1239 1503
1504 /* Grab the FCB if there is one */
1505 if (gfar_uses_fcb(priv))
1506 fcb = gfar_get_fcb(skb);
1507
1508 /* Remove the padded bytes, if there are any */
1509 if (priv->padding)
1510 skb_pull(skb, priv->padding);
1511
1512 if (priv->rx_csum_enable)
1513 gfar_rx_checksum(skb, fcb);
1514
1240 /* Tell the skb what kind of packet this is */ 1515 /* Tell the skb what kind of packet this is */
1241 skb->protocol = eth_type_trans(skb, dev); 1516 skb->protocol = eth_type_trans(skb, dev);
1242 1517
1243 /* Send the packet up the stack */ 1518 /* Send the packet up the stack */
1244 if (RECEIVE(skb) == NET_RX_DROP) { 1519 if (unlikely(priv->vlgrp && fcb->vln))
1520 ret = gfar_rx_vlan(skb, priv->vlgrp, fcb->vlctl);
1521 else
1522 ret = RECEIVE(skb);
1523
1524 if (NET_RX_DROP == ret)
1245 priv->extra_stats.kernel_dropped++; 1525 priv->extra_stats.kernel_dropped++;
1246 }
1247 } 1526 }
1248 1527
1249 return 0; 1528 return 0;
1250} 1529}
1251 1530
1252/* gfar_clean_rx_ring() -- Processes each frame in the rx ring 1531/* gfar_clean_rx_ring() -- Processes each frame in the rx ring
1253 * until the budget/quota has been reached. Returns the number 1532 * until the budget/quota has been reached. Returns the number
1254 * of frames handled 1533 * of frames handled
1255 */ 1534 */
1256static int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit) 1535int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1257{ 1536{
1258 struct rxbd8 *bdp; 1537 struct rxbd8 *bdp;
1259 struct sk_buff *skb; 1538 struct sk_buff *skb;
@@ -1355,9 +1634,6 @@ static int gfar_poll(struct net_device *dev, int *budget)
1355 mk_ic_value(priv->rxcount, priv->rxtime)); 1634 mk_ic_value(priv->rxcount, priv->rxtime));
1356 else 1635 else
1357 gfar_write(&priv->regs->rxic, 0); 1636 gfar_write(&priv->regs->rxic, 0);
1358
1359 /* Signal to the ring size changer that it's safe to go */
1360 priv->rxclean = 1;
1361 } 1637 }
1362 1638
1363 return (rx_work_limit < 0) ? 1 : 0; 1639 return (rx_work_limit < 0) ? 1 : 0;
@@ -1393,10 +1669,8 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1393 if (events & IEVENT_CRL) 1669 if (events & IEVENT_CRL)
1394 priv->stats.tx_aborted_errors++; 1670 priv->stats.tx_aborted_errors++;
1395 if (events & IEVENT_XFUN) { 1671 if (events & IEVENT_XFUN) {
1396#ifdef VERBOSE_GFAR_ERRORS 1672 if (netif_msg_tx_err(priv))
1397 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", 1673 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", dev->name);
1398 dev->name);
1399#endif
1400 priv->stats.tx_dropped++; 1674 priv->stats.tx_dropped++;
1401 priv->extra_stats.tx_underrun++; 1675 priv->extra_stats.tx_underrun++;
1402 1676
@@ -1415,36 +1689,30 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1415 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT); 1689 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1416#endif 1690#endif
1417 1691
1418#ifdef VERBOSE_GFAR_ERRORS 1692 if (netif_msg_rx_err(priv))
1419 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name, 1693 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1420 gfar_read(&priv->regs->rstat)); 1694 dev->name,
1421#endif 1695 gfar_read(&priv->regs->rstat));
1422 } 1696 }
1423 if (events & IEVENT_BABR) { 1697 if (events & IEVENT_BABR) {
1424 priv->stats.rx_errors++; 1698 priv->stats.rx_errors++;
1425 priv->extra_stats.rx_babr++; 1699 priv->extra_stats.rx_babr++;
1426 1700
1427#ifdef VERBOSE_GFAR_ERRORS 1701 if (netif_msg_rx_err(priv))
1428 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 1702 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1429#endif
1430 } 1703 }
1431 if (events & IEVENT_EBERR) { 1704 if (events & IEVENT_EBERR) {
1432 priv->extra_stats.eberr++; 1705 priv->extra_stats.eberr++;
1433#ifdef VERBOSE_GFAR_ERRORS 1706 if (netif_msg_rx_err(priv))
1434 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 1707 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1435#endif
1436 }
1437 if (events & IEVENT_RXC) {
1438#ifdef VERBOSE_GFAR_ERRORS
1439 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1440#endif
1441 } 1708 }
1709 if ((events & IEVENT_RXC) && (netif_msg_rx_err(priv)))
1710 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1442 1711
1443 if (events & IEVENT_BABT) { 1712 if (events & IEVENT_BABT) {
1444 priv->extra_stats.tx_babt++; 1713 priv->extra_stats.tx_babt++;
1445#ifdef VERBOSE_GFAR_ERRORS 1714 if (netif_msg_rx_err(priv))
1446 printk(KERN_DEBUG "%s: babt error\n", dev->name); 1715 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1447#endif
1448 } 1716 }
1449 1717
1450 return IRQ_HANDLED; 1718 return IRQ_HANDLED;
@@ -1510,7 +1778,7 @@ static void gfar_phy_timer(unsigned long data)
1510 * If, after GFAR_AN_TIMEOUT seconds, it has not 1778 * If, after GFAR_AN_TIMEOUT seconds, it has not
1511 * finished, we switch to forced. 1779 * finished, we switch to forced.
1512 * Either way, once the process has completed, we either 1780 * Either way, once the process has completed, we either
1513 * request the interrupt, or switch the timer over to 1781 * request the interrupt, or switch the timer over to
1514 * using gfar_phy_timer to check status */ 1782 * using gfar_phy_timer to check status */
1515static void gfar_phy_startup_timer(unsigned long data) 1783static void gfar_phy_startup_timer(unsigned long data)
1516{ 1784{
@@ -1535,8 +1803,9 @@ static void gfar_phy_startup_timer(unsigned long data)
1535 1803
1536 /* Forcing failed! Give up */ 1804 /* Forcing failed! Give up */
1537 if(result) { 1805 if(result) {
1538 printk(KERN_ERR "%s: Forcing failed!\n", 1806 if (netif_msg_link(priv))
1539 mii_info->dev->name); 1807 printk(KERN_ERR "%s: Forcing failed!\n",
1808 mii_info->dev->name);
1540 return; 1809 return;
1541 } 1810 }
1542 } 1811 }
@@ -1546,16 +1815,17 @@ static void gfar_phy_startup_timer(unsigned long data)
1546 1815
1547 /* Grab the PHY interrupt, if necessary/possible */ 1816 /* Grab the PHY interrupt, if necessary/possible */
1548 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) { 1817 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
1549 if (request_irq(priv->einfo->interruptPHY, 1818 if (request_irq(priv->einfo->interruptPHY,
1550 phy_interrupt, 1819 phy_interrupt,
1551 SA_SHIRQ, 1820 SA_SHIRQ,
1552 "phy_interrupt", 1821 "phy_interrupt",
1553 mii_info->dev) < 0) { 1822 mii_info->dev) < 0) {
1554 printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n", 1823 if (netif_msg_intr(priv))
1555 mii_info->dev->name, 1824 printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n",
1825 mii_info->dev->name,
1556 priv->einfo->interruptPHY); 1826 priv->einfo->interruptPHY);
1557 } else { 1827 } else {
1558 mii_configure_phy_interrupt(priv->mii_info, 1828 mii_configure_phy_interrupt(priv->mii_info,
1559 MII_INTERRUPT_ENABLED); 1829 MII_INTERRUPT_ENABLED);
1560 return; 1830 return;
1561 } 1831 }
@@ -1592,15 +1862,17 @@ static void adjust_link(struct net_device *dev)
1592 tempval &= ~(MACCFG2_FULL_DUPLEX); 1862 tempval &= ~(MACCFG2_FULL_DUPLEX);
1593 gfar_write(&regs->maccfg2, tempval); 1863 gfar_write(&regs->maccfg2, tempval);
1594 1864
1595 printk(KERN_INFO "%s: Half Duplex\n", 1865 if (netif_msg_link(priv))
1596 dev->name); 1866 printk(KERN_INFO "%s: Half Duplex\n",
1867 dev->name);
1597 } else { 1868 } else {
1598 tempval = gfar_read(&regs->maccfg2); 1869 tempval = gfar_read(&regs->maccfg2);
1599 tempval |= MACCFG2_FULL_DUPLEX; 1870 tempval |= MACCFG2_FULL_DUPLEX;
1600 gfar_write(&regs->maccfg2, tempval); 1871 gfar_write(&regs->maccfg2, tempval);
1601 1872
1602 printk(KERN_INFO "%s: Full Duplex\n", 1873 if (netif_msg_link(priv))
1603 dev->name); 1874 printk(KERN_INFO "%s: Full Duplex\n",
1875 dev->name);
1604 } 1876 }
1605 1877
1606 priv->oldduplex = mii_info->duplex; 1878 priv->oldduplex = mii_info->duplex;
@@ -1622,27 +1894,32 @@ static void adjust_link(struct net_device *dev)
1622 gfar_write(&regs->maccfg2, tempval); 1894 gfar_write(&regs->maccfg2, tempval);
1623 break; 1895 break;
1624 default: 1896 default:
1625 printk(KERN_WARNING 1897 if (netif_msg_link(priv))
1626 "%s: Ack! Speed (%d) is not 10/100/1000!\n", 1898 printk(KERN_WARNING
1627 dev->name, mii_info->speed); 1899 "%s: Ack! Speed (%d) is not 10/100/1000!\n",
1900 dev->name, mii_info->speed);
1628 break; 1901 break;
1629 } 1902 }
1630 1903
1631 printk(KERN_INFO "%s: Speed %dBT\n", dev->name, 1904 if (netif_msg_link(priv))
1632 mii_info->speed); 1905 printk(KERN_INFO "%s: Speed %dBT\n", dev->name,
1906 mii_info->speed);
1633 1907
1634 priv->oldspeed = mii_info->speed; 1908 priv->oldspeed = mii_info->speed;
1635 } 1909 }
1636 1910
1637 if (!priv->oldlink) { 1911 if (!priv->oldlink) {
1638 printk(KERN_INFO "%s: Link is up\n", dev->name); 1912 if (netif_msg_link(priv))
1913 printk(KERN_INFO "%s: Link is up\n", dev->name);
1639 priv->oldlink = 1; 1914 priv->oldlink = 1;
1640 netif_carrier_on(dev); 1915 netif_carrier_on(dev);
1641 netif_schedule(dev); 1916 netif_schedule(dev);
1642 } 1917 }
1643 } else { 1918 } else {
1644 if (priv->oldlink) { 1919 if (priv->oldlink) {
1645 printk(KERN_INFO "%s: Link is down\n", dev->name); 1920 if (netif_msg_link(priv))
1921 printk(KERN_INFO "%s: Link is down\n",
1922 dev->name);
1646 priv->oldlink = 0; 1923 priv->oldlink = 0;
1647 priv->oldspeed = 0; 1924 priv->oldspeed = 0;
1648 priv->oldduplex = -1; 1925 priv->oldduplex = -1;
@@ -1664,8 +1941,9 @@ static void gfar_set_multi(struct net_device *dev)
1664 u32 tempval; 1941 u32 tempval;
1665 1942
1666 if(dev->flags & IFF_PROMISC) { 1943 if(dev->flags & IFF_PROMISC) {
1667 printk(KERN_INFO "%s: Entering promiscuous mode.\n", 1944 if (netif_msg_drv(priv))
1668 dev->name); 1945 printk(KERN_INFO "%s: Entering promiscuous mode.\n",
1946 dev->name);
1669 /* Set RCTRL to PROM */ 1947 /* Set RCTRL to PROM */
1670 tempval = gfar_read(&regs->rctrl); 1948 tempval = gfar_read(&regs->rctrl);
1671 tempval |= RCTRL_PROM; 1949 tempval |= RCTRL_PROM;
@@ -1679,6 +1957,14 @@ static void gfar_set_multi(struct net_device *dev)
1679 1957
1680 if(dev->flags & IFF_ALLMULTI) { 1958 if(dev->flags & IFF_ALLMULTI) {
1681 /* Set the hash to rx all multicast frames */ 1959 /* Set the hash to rx all multicast frames */
1960 gfar_write(&regs->igaddr0, 0xffffffff);
1961 gfar_write(&regs->igaddr1, 0xffffffff);
1962 gfar_write(&regs->igaddr2, 0xffffffff);
1963 gfar_write(&regs->igaddr3, 0xffffffff);
1964 gfar_write(&regs->igaddr4, 0xffffffff);
1965 gfar_write(&regs->igaddr5, 0xffffffff);
1966 gfar_write(&regs->igaddr6, 0xffffffff);
1967 gfar_write(&regs->igaddr7, 0xffffffff);
1682 gfar_write(&regs->gaddr0, 0xffffffff); 1968 gfar_write(&regs->gaddr0, 0xffffffff);
1683 gfar_write(&regs->gaddr1, 0xffffffff); 1969 gfar_write(&regs->gaddr1, 0xffffffff);
1684 gfar_write(&regs->gaddr2, 0xffffffff); 1970 gfar_write(&regs->gaddr2, 0xffffffff);
@@ -1689,6 +1975,14 @@ static void gfar_set_multi(struct net_device *dev)
1689 gfar_write(&regs->gaddr7, 0xffffffff); 1975 gfar_write(&regs->gaddr7, 0xffffffff);
1690 } else { 1976 } else {
1691 /* zero out the hash */ 1977 /* zero out the hash */
1978 gfar_write(&regs->igaddr0, 0x0);
1979 gfar_write(&regs->igaddr1, 0x0);
1980 gfar_write(&regs->igaddr2, 0x0);
1981 gfar_write(&regs->igaddr3, 0x0);
1982 gfar_write(&regs->igaddr4, 0x0);
1983 gfar_write(&regs->igaddr5, 0x0);
1984 gfar_write(&regs->igaddr6, 0x0);
1985 gfar_write(&regs->igaddr7, 0x0);
1692 gfar_write(&regs->gaddr0, 0x0); 1986 gfar_write(&regs->gaddr0, 0x0);
1693 gfar_write(&regs->gaddr1, 0x0); 1987 gfar_write(&regs->gaddr1, 0x0);
1694 gfar_write(&regs->gaddr2, 0x0); 1988 gfar_write(&regs->gaddr2, 0x0);
@@ -1727,16 +2021,15 @@ static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
1727{ 2021{
1728 u32 tempval; 2022 u32 tempval;
1729 struct gfar_private *priv = netdev_priv(dev); 2023 struct gfar_private *priv = netdev_priv(dev);
1730 struct gfar *regs = priv->regs;
1731 u32 *hash = &regs->gaddr0;
1732 u32 result = ether_crc(MAC_ADDR_LEN, addr); 2024 u32 result = ether_crc(MAC_ADDR_LEN, addr);
1733 u8 whichreg = ((result >> 29) & 0x7); 2025 int width = priv->hash_width;
1734 u8 whichbit = ((result >> 24) & 0x1f); 2026 u8 whichbit = (result >> (32 - width)) & 0x1f;
2027 u8 whichreg = result >> (32 - width + 5);
1735 u32 value = (1 << (31-whichbit)); 2028 u32 value = (1 << (31-whichbit));
1736 2029
1737 tempval = gfar_read(&hash[whichreg]); 2030 tempval = gfar_read(priv->hash_regs[whichreg]);
1738 tempval |= value; 2031 tempval |= value;
1739 gfar_write(&hash[whichreg], tempval); 2032 gfar_write(priv->hash_regs[whichreg], tempval);
1740 2033
1741 return; 2034 return;
1742} 2035}
@@ -1754,10 +2047,9 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1754 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK); 2047 gfar_write(&priv->regs->ievent, IEVENT_ERR_MASK);
1755 2048
1756 /* Hmm... */ 2049 /* Hmm... */
1757#if defined (BRIEF_GFAR_ERRORS) || defined (VERBOSE_GFAR_ERRORS) 2050 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
1758 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n", 2051 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
1759 dev->name, events, gfar_read(&priv->regs->imask)); 2052 dev->name, events, gfar_read(&priv->regs->imask));
1760#endif
1761 2053
1762 /* Update the error counters */ 2054 /* Update the error counters */
1763 if (events & IEVENT_TXE) { 2055 if (events & IEVENT_TXE) {
@@ -1768,19 +2060,17 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1768 if (events & IEVENT_CRL) 2060 if (events & IEVENT_CRL)
1769 priv->stats.tx_aborted_errors++; 2061 priv->stats.tx_aborted_errors++;
1770 if (events & IEVENT_XFUN) { 2062 if (events & IEVENT_XFUN) {
1771#ifdef VERBOSE_GFAR_ERRORS 2063 if (netif_msg_tx_err(priv))
1772 printk(KERN_DEBUG "%s: underrun. packet dropped.\n", 2064 printk(KERN_DEBUG "%s: underrun. packet dropped.\n",
1773 dev->name); 2065 dev->name);
1774#endif
1775 priv->stats.tx_dropped++; 2066 priv->stats.tx_dropped++;
1776 priv->extra_stats.tx_underrun++; 2067 priv->extra_stats.tx_underrun++;
1777 2068
1778 /* Reactivate the Tx Queues */ 2069 /* Reactivate the Tx Queues */
1779 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT); 2070 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1780 } 2071 }
1781#ifdef VERBOSE_GFAR_ERRORS 2072 if (netif_msg_tx_err(priv))
1782 printk(KERN_DEBUG "%s: Transmit Error\n", dev->name); 2073 printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
1783#endif
1784 } 2074 }
1785 if (events & IEVENT_BSY) { 2075 if (events & IEVENT_BSY) {
1786 priv->stats.rx_errors++; 2076 priv->stats.rx_errors++;
@@ -1793,35 +2083,31 @@ static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs)
1793 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT); 2083 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1794#endif 2084#endif
1795 2085
1796#ifdef VERBOSE_GFAR_ERRORS 2086 if (netif_msg_rx_err(priv))
1797 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", dev->name, 2087 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1798 gfar_read(&priv->regs->rstat)); 2088 dev->name,
1799#endif 2089 gfar_read(&priv->regs->rstat));
1800 } 2090 }
1801 if (events & IEVENT_BABR) { 2091 if (events & IEVENT_BABR) {
1802 priv->stats.rx_errors++; 2092 priv->stats.rx_errors++;
1803 priv->extra_stats.rx_babr++; 2093 priv->extra_stats.rx_babr++;
1804 2094
1805#ifdef VERBOSE_GFAR_ERRORS 2095 if (netif_msg_rx_err(priv))
1806 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 2096 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1807#endif
1808 } 2097 }
1809 if (events & IEVENT_EBERR) { 2098 if (events & IEVENT_EBERR) {
1810 priv->extra_stats.eberr++; 2099 priv->extra_stats.eberr++;
1811#ifdef VERBOSE_GFAR_ERRORS 2100 if (netif_msg_rx_err(priv))
1812 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 2101 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1813#endif
1814 } 2102 }
1815 if (events & IEVENT_RXC) 2103 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
1816#ifdef VERBOSE_GFAR_ERRORS 2104 if (netif_msg_rx_status(priv))
1817 printk(KERN_DEBUG "%s: control frame\n", dev->name); 2105 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1818#endif
1819 2106
1820 if (events & IEVENT_BABT) { 2107 if (events & IEVENT_BABT) {
1821 priv->extra_stats.tx_babt++; 2108 priv->extra_stats.tx_babt++;
1822#ifdef VERBOSE_GFAR_ERRORS 2109 if (netif_msg_tx_err(priv))
1823 printk(KERN_DEBUG "%s: babt error\n", dev->name); 2110 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1824#endif
1825 } 2111 }
1826 return IRQ_HANDLED; 2112 return IRQ_HANDLED;
1827} 2113}
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index c2f783a6a9fa..28af087d9fbb 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -1,4 +1,4 @@
1/* 1/*
2 * drivers/net/gianfar.h 2 * drivers/net/gianfar.h
3 * 3 *
4 * Gianfar Ethernet Driver 4 * Gianfar Ethernet Driver
@@ -53,6 +53,12 @@
53/* The maximum number of packets to be handled in one call of gfar_poll */ 53/* The maximum number of packets to be handled in one call of gfar_poll */
54#define GFAR_DEV_WEIGHT 64 54#define GFAR_DEV_WEIGHT 64
55 55
56/* Length for FCB */
57#define GMAC_FCB_LEN 8
58
59/* Default padding amount */
60#define DEFAULT_PADDING 2
61
56/* Number of bytes to align the rx bufs to */ 62/* Number of bytes to align the rx bufs to */
57#define RXBUF_ALIGNMENT 64 63#define RXBUF_ALIGNMENT 64
58 64
@@ -91,7 +97,7 @@ extern const char gfar_driver_version[];
91#define JUMBO_FRAME_SIZE 9600 97#define JUMBO_FRAME_SIZE 9600
92 98
93/* Latency of interface clock in nanoseconds */ 99/* Latency of interface clock in nanoseconds */
94/* Interface clock latency , in this case, means the 100/* Interface clock latency , in this case, means the
95 * time described by a value of 1 in the interrupt 101 * time described by a value of 1 in the interrupt
96 * coalescing registers' time fields. Since those fields 102 * coalescing registers' time fields. Since those fields
97 * refer to the time it takes for 64 clocks to pass, the 103 * refer to the time it takes for 64 clocks to pass, the
@@ -166,9 +172,28 @@ extern const char gfar_driver_version[];
166 mk_ic_icft(count) | \ 172 mk_ic_icft(count) | \
167 mk_ic_ictt(time)) 173 mk_ic_ictt(time))
168 174
175#define RCTRL_PAL_MASK 0x001f0000
176#define RCTRL_VLEX 0x00002000
177#define RCTRL_FILREN 0x00001000
178#define RCTRL_GHTX 0x00000400
179#define RCTRL_IPCSEN 0x00000200
180#define RCTRL_TUCSEN 0x00000100
181#define RCTRL_PRSDEP_MASK 0x000000c0
182#define RCTRL_PRSDEP_INIT 0x000000c0
169#define RCTRL_PROM 0x00000008 183#define RCTRL_PROM 0x00000008
184#define RCTRL_CHECKSUMMING (RCTRL_IPCSEN \
185 | RCTRL_TUCSEN | RCTRL_PRSDEP_INIT)
186#define RCTRL_EXTHASH (RCTRL_GHTX)
187#define RCTRL_VLAN (RCTRL_PRSDEP_INIT)
188
189
170#define RSTAT_CLEAR_RHALT 0x00800000 190#define RSTAT_CLEAR_RHALT 0x00800000
171 191
192#define TCTRL_IPCSEN 0x00004000
193#define TCTRL_TUCSEN 0x00002000
194#define TCTRL_VLINS 0x00001000
195#define TCTRL_INIT_CSUM (TCTRL_TUCSEN | TCTRL_IPCSEN)
196
172#define IEVENT_INIT_CLEAR 0xffffffff 197#define IEVENT_INIT_CLEAR 0xffffffff
173#define IEVENT_BABR 0x80000000 198#define IEVENT_BABR 0x80000000
174#define IEVENT_RXC 0x40000000 199#define IEVENT_RXC 0x40000000
@@ -187,12 +212,16 @@ extern const char gfar_driver_version[];
187#define IEVENT_RXB0 0x00008000 212#define IEVENT_RXB0 0x00008000
188#define IEVENT_GRSC 0x00000100 213#define IEVENT_GRSC 0x00000100
189#define IEVENT_RXF0 0x00000080 214#define IEVENT_RXF0 0x00000080
215#define IEVENT_FIR 0x00000008
216#define IEVENT_FIQ 0x00000004
217#define IEVENT_DPE 0x00000002
218#define IEVENT_PERR 0x00000001
190#define IEVENT_RX_MASK (IEVENT_RXB0 | IEVENT_RXF0) 219#define IEVENT_RX_MASK (IEVENT_RXB0 | IEVENT_RXF0)
191#define IEVENT_TX_MASK (IEVENT_TXB | IEVENT_TXF) 220#define IEVENT_TX_MASK (IEVENT_TXB | IEVENT_TXF)
192#define IEVENT_ERR_MASK \ 221#define IEVENT_ERR_MASK \
193(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \ 222(IEVENT_RXC | IEVENT_BSY | IEVENT_EBERR | IEVENT_MSRO | \
194 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \ 223 IEVENT_BABT | IEVENT_TXC | IEVENT_TXE | IEVENT_LC \
195 | IEVENT_CRL | IEVENT_XFUN) 224 | IEVENT_CRL | IEVENT_XFUN | IEVENT_DPE | IEVENT_PERR)
196 225
197#define IMASK_INIT_CLEAR 0x00000000 226#define IMASK_INIT_CLEAR 0x00000000
198#define IMASK_BABR 0x80000000 227#define IMASK_BABR 0x80000000
@@ -212,10 +241,15 @@ extern const char gfar_driver_version[];
212#define IMASK_RXB0 0x00008000 241#define IMASK_RXB0 0x00008000
213#define IMASK_GTSC 0x00000100 242#define IMASK_GTSC 0x00000100
214#define IMASK_RXFEN0 0x00000080 243#define IMASK_RXFEN0 0x00000080
244#define IMASK_FIR 0x00000008
245#define IMASK_FIQ 0x00000004
246#define IMASK_DPE 0x00000002
247#define IMASK_PERR 0x00000001
215#define IMASK_RX_DISABLED ~(IMASK_RXFEN0 | IMASK_BSY) 248#define IMASK_RX_DISABLED ~(IMASK_RXFEN0 | IMASK_BSY)
216#define IMASK_DEFAULT (IMASK_TXEEN | IMASK_TXFEN | IMASK_TXBEN | \ 249#define IMASK_DEFAULT (IMASK_TXEEN | IMASK_TXFEN | IMASK_TXBEN | \
217 IMASK_RXFEN0 | IMASK_BSY | IMASK_EBERR | IMASK_BABR | \ 250 IMASK_RXFEN0 | IMASK_BSY | IMASK_EBERR | IMASK_BABR | \
218 IMASK_XFUN | IMASK_RXC | IMASK_BABT) 251 IMASK_XFUN | IMASK_RXC | IMASK_BABT | IMASK_DPE \
252 | IMASK_PERR)
219 253
220 254
221/* Attribute fields */ 255/* Attribute fields */
@@ -254,6 +288,18 @@ extern const char gfar_driver_version[];
254#define TXBD_RETRYLIMIT 0x0040 288#define TXBD_RETRYLIMIT 0x0040
255#define TXBD_RETRYCOUNTMASK 0x003c 289#define TXBD_RETRYCOUNTMASK 0x003c
256#define TXBD_UNDERRUN 0x0002 290#define TXBD_UNDERRUN 0x0002
291#define TXBD_TOE 0x0002
292
293/* Tx FCB param bits */
294#define TXFCB_VLN 0x80
295#define TXFCB_IP 0x40
296#define TXFCB_IP6 0x20
297#define TXFCB_TUP 0x10
298#define TXFCB_UDP 0x08
299#define TXFCB_CIP 0x04
300#define TXFCB_CTU 0x02
301#define TXFCB_NPH 0x01
302#define TXFCB_DEFAULT (TXFCB_IP|TXFCB_TUP|TXFCB_CTU|TXFCB_NPH)
257 303
258/* RxBD status field bits */ 304/* RxBD status field bits */
259#define RXBD_EMPTY 0x8000 305#define RXBD_EMPTY 0x8000
@@ -273,6 +319,18 @@ extern const char gfar_driver_version[];
273#define RXBD_TRUNCATED 0x0001 319#define RXBD_TRUNCATED 0x0001
274#define RXBD_STATS 0x01ff 320#define RXBD_STATS 0x01ff
275 321
322/* Rx FCB status field bits */
323#define RXFCB_VLN 0x8000
324#define RXFCB_IP 0x4000
325#define RXFCB_IP6 0x2000
326#define RXFCB_TUP 0x1000
327#define RXFCB_CIP 0x0800
328#define RXFCB_CTU 0x0400
329#define RXFCB_EIP 0x0200
330#define RXFCB_ETU 0x0100
331#define RXFCB_PERR_MASK 0x000c
332#define RXFCB_PERR_BADL3 0x0008
333
276struct txbd8 334struct txbd8
277{ 335{
278 u16 status; /* Status Fields */ 336 u16 status; /* Status Fields */
@@ -280,6 +338,22 @@ struct txbd8
280 u32 bufPtr; /* Buffer Pointer */ 338 u32 bufPtr; /* Buffer Pointer */
281}; 339};
282 340
341struct txfcb {
342 u8 vln:1,
343 ip:1,
344 ip6:1,
345 tup:1,
346 udp:1,
347 cip:1,
348 ctu:1,
349 nph:1;
350 u8 reserved;
351 u8 l4os; /* Level 4 Header Offset */
352 u8 l3os; /* Level 3 Header Offset */
353 u16 phcs; /* Pseudo-header Checksum */
354 u16 vlctl; /* VLAN control word */
355};
356
283struct rxbd8 357struct rxbd8
284{ 358{
285 u16 status; /* Status Fields */ 359 u16 status; /* Status Fields */
@@ -287,6 +361,21 @@ struct rxbd8
287 u32 bufPtr; /* Buffer Pointer */ 361 u32 bufPtr; /* Buffer Pointer */
288}; 362};
289 363
364struct rxfcb {
365 u16 vln:1,
366 ip:1,
367 ip6:1,
368 tup:1,
369 cip:1,
370 ctu:1,
371 eip:1,
372 etu:1;
373 u8 rq; /* Receive Queue index */
374 u8 pro; /* Layer 4 Protocol */
375 u16 reserved;
376 u16 vlctl; /* VLAN control word */
377};
378
290struct rmon_mib 379struct rmon_mib
291{ 380{
292 u32 tr64; /* 0x.680 - Transmit and Receive 64-byte Frame Counter */ 381 u32 tr64; /* 0x.680 - Transmit and Receive 64-byte Frame Counter */
@@ -371,90 +460,191 @@ struct gfar_stats {
371 460
372 461
373struct gfar { 462struct gfar {
374 u8 res1[16]; 463 u32 tsec_id; /* 0x.000 - Controller ID register */
375 u32 ievent; /* 0x.010 - Interrupt Event Register */ 464 u8 res1[12];
376 u32 imask; /* 0x.014 - Interrupt Mask Register */ 465 u32 ievent; /* 0x.010 - Interrupt Event Register */
377 u32 edis; /* 0x.018 - Error Disabled Register */ 466 u32 imask; /* 0x.014 - Interrupt Mask Register */
467 u32 edis; /* 0x.018 - Error Disabled Register */
378 u8 res2[4]; 468 u8 res2[4];
379 u32 ecntrl; /* 0x.020 - Ethernet Control Register */ 469 u32 ecntrl; /* 0x.020 - Ethernet Control Register */
380 u32 minflr; /* 0x.024 - Minimum Frame Length Register */ 470 u32 minflr; /* 0x.024 - Minimum Frame Length Register */
381 u32 ptv; /* 0x.028 - Pause Time Value Register */ 471 u32 ptv; /* 0x.028 - Pause Time Value Register */
382 u32 dmactrl; /* 0x.02c - DMA Control Register */ 472 u32 dmactrl; /* 0x.02c - DMA Control Register */
383 u32 tbipa; /* 0x.030 - TBI PHY Address Register */ 473 u32 tbipa; /* 0x.030 - TBI PHY Address Register */
384 u8 res3[88]; 474 u8 res3[88];
385 u32 fifo_tx_thr; /* 0x.08c - FIFO transmit threshold register */ 475 u32 fifo_tx_thr; /* 0x.08c - FIFO transmit threshold register */
386 u8 res4[8]; 476 u8 res4[8];
387 u32 fifo_tx_starve; /* 0x.098 - FIFO transmit starve register */ 477 u32 fifo_tx_starve; /* 0x.098 - FIFO transmit starve register */
388 u32 fifo_tx_starve_shutoff; /* 0x.09c - FIFO transmit starve shutoff register */ 478 u32 fifo_tx_starve_shutoff; /* 0x.09c - FIFO transmit starve shutoff register */
389 u8 res5[96]; 479 u8 res5[4];
390 u32 tctrl; /* 0x.100 - Transmit Control Register */ 480 u32 fifo_rx_pause; /* 0x.0a4 - FIFO receive pause threshold register */
391 u32 tstat; /* 0x.104 - Transmit Status Register */ 481 u32 fifo_rx_alarm; /* 0x.0a8 - FIFO receive alarm threshold register */
392 u8 res6[4]; 482 u8 res6[84];
393 u32 tbdlen; /* 0x.10c - Transmit Buffer Descriptor Data Length Register */ 483 u32 tctrl; /* 0x.100 - Transmit Control Register */
394 u32 txic; /* 0x.110 - Transmit Interrupt Coalescing Configuration Register */ 484 u32 tstat; /* 0x.104 - Transmit Status Register */
395 u8 res7[16]; 485 u32 dfvlan; /* 0x.108 - Default VLAN Control word */
396 u32 ctbptr; /* 0x.124 - Current Transmit Buffer Descriptor Pointer Register */ 486 u32 tbdlen; /* 0x.10c - Transmit Buffer Descriptor Data Length Register */
397 u8 res8[92]; 487 u32 txic; /* 0x.110 - Transmit Interrupt Coalescing Configuration Register */
398 u32 tbptr; /* 0x.184 - Transmit Buffer Descriptor Pointer Low Register */ 488 u32 tqueue; /* 0x.114 - Transmit queue control register */
399 u8 res9[124]; 489 u8 res7[40];
400 u32 tbase; /* 0x.204 - Transmit Descriptor Base Address Register */ 490 u32 tr03wt; /* 0x.140 - TxBD Rings 0-3 round-robin weightings */
401 u8 res10[168]; 491 u32 tr47wt; /* 0x.144 - TxBD Rings 4-7 round-robin weightings */
402 u32 ostbd; /* 0x.2b0 - Out-of-Sequence Transmit Buffer Descriptor Register */ 492 u8 res8[52];
403 u32 ostbdp; /* 0x.2b4 - Out-of-Sequence Transmit Data Buffer Pointer Register */ 493 u32 tbdbph; /* 0x.17c - Tx data buffer pointer high */
404 u8 res11[72]; 494 u8 res9a[4];
405 u32 rctrl; /* 0x.300 - Receive Control Register */ 495 u32 tbptr0; /* 0x.184 - TxBD Pointer for ring 0 */
406 u32 rstat; /* 0x.304 - Receive Status Register */ 496 u8 res9b[4];
407 u8 res12[4]; 497 u32 tbptr1; /* 0x.18c - TxBD Pointer for ring 1 */
408 u32 rbdlen; /* 0x.30c - RxBD Data Length Register */ 498 u8 res9c[4];
409 u32 rxic; /* 0x.310 - Receive Interrupt Coalescing Configuration Register */ 499 u32 tbptr2; /* 0x.194 - TxBD Pointer for ring 2 */
410 u8 res13[16]; 500 u8 res9d[4];
411 u32 crbptr; /* 0x.324 - Current Receive Buffer Descriptor Pointer */ 501 u32 tbptr3; /* 0x.19c - TxBD Pointer for ring 3 */
412 u8 res14[24]; 502 u8 res9e[4];
413 u32 mrblr; /* 0x.340 - Maximum Receive Buffer Length Register */ 503 u32 tbptr4; /* 0x.1a4 - TxBD Pointer for ring 4 */
414 u8 res15[64]; 504 u8 res9f[4];
415 u32 rbptr; /* 0x.384 - Receive Buffer Descriptor Pointer */ 505 u32 tbptr5; /* 0x.1ac - TxBD Pointer for ring 5 */
416 u8 res16[124]; 506 u8 res9g[4];
417 u32 rbase; /* 0x.404 - Receive Descriptor Base Address */ 507 u32 tbptr6; /* 0x.1b4 - TxBD Pointer for ring 6 */
418 u8 res17[248]; 508 u8 res9h[4];
419 u32 maccfg1; /* 0x.500 - MAC Configuration 1 Register */ 509 u32 tbptr7; /* 0x.1bc - TxBD Pointer for ring 7 */
420 u32 maccfg2; /* 0x.504 - MAC Configuration 2 Register */ 510 u8 res9[64];
421 u32 ipgifg; /* 0x.508 - Inter Packet Gap/Inter Frame Gap Register */ 511 u32 tbaseh; /* 0x.200 - TxBD base address high */
422 u32 hafdup; /* 0x.50c - Half Duplex Register */ 512 u32 tbase0; /* 0x.204 - TxBD Base Address of ring 0 */
423 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */ 513 u8 res10a[4];
514 u32 tbase1; /* 0x.20c - TxBD Base Address of ring 1 */
515 u8 res10b[4];
516 u32 tbase2; /* 0x.214 - TxBD Base Address of ring 2 */
517 u8 res10c[4];
518 u32 tbase3; /* 0x.21c - TxBD Base Address of ring 3 */
519 u8 res10d[4];
520 u32 tbase4; /* 0x.224 - TxBD Base Address of ring 4 */
521 u8 res10e[4];
522 u32 tbase5; /* 0x.22c - TxBD Base Address of ring 5 */
523 u8 res10f[4];
524 u32 tbase6; /* 0x.234 - TxBD Base Address of ring 6 */
525 u8 res10g[4];
526 u32 tbase7; /* 0x.23c - TxBD Base Address of ring 7 */
527 u8 res10[192];
528 u32 rctrl; /* 0x.300 - Receive Control Register */
529 u32 rstat; /* 0x.304 - Receive Status Register */
530 u8 res12[8];
531 u32 rxic; /* 0x.310 - Receive Interrupt Coalescing Configuration Register */
532 u32 rqueue; /* 0x.314 - Receive queue control register */
533 u8 res13[24];
534 u32 rbifx; /* 0x.330 - Receive bit field extract control register */
535 u32 rqfar; /* 0x.334 - Receive queue filing table address register */
536 u32 rqfcr; /* 0x.338 - Receive queue filing table control register */
537 u32 rqfpr; /* 0x.33c - Receive queue filing table property register */
538 u32 mrblr; /* 0x.340 - Maximum Receive Buffer Length Register */
539 u8 res14[56];
540 u32 rbdbph; /* 0x.37c - Rx data buffer pointer high */
541 u8 res15a[4];
542 u32 rbptr0; /* 0x.384 - RxBD pointer for ring 0 */
543 u8 res15b[4];
544 u32 rbptr1; /* 0x.38c - RxBD pointer for ring 1 */
545 u8 res15c[4];
546 u32 rbptr2; /* 0x.394 - RxBD pointer for ring 2 */
547 u8 res15d[4];
548 u32 rbptr3; /* 0x.39c - RxBD pointer for ring 3 */
549 u8 res15e[4];
550 u32 rbptr4; /* 0x.3a4 - RxBD pointer for ring 4 */
551 u8 res15f[4];
552 u32 rbptr5; /* 0x.3ac - RxBD pointer for ring 5 */
553 u8 res15g[4];
554 u32 rbptr6; /* 0x.3b4 - RxBD pointer for ring 6 */
555 u8 res15h[4];
556 u32 rbptr7; /* 0x.3bc - RxBD pointer for ring 7 */
557 u8 res16[64];
558 u32 rbaseh; /* 0x.400 - RxBD base address high */
559 u32 rbase0; /* 0x.404 - RxBD base address of ring 0 */
560 u8 res17a[4];
561 u32 rbase1; /* 0x.40c - RxBD base address of ring 1 */
562 u8 res17b[4];
563 u32 rbase2; /* 0x.414 - RxBD base address of ring 2 */
564 u8 res17c[4];
565 u32 rbase3; /* 0x.41c - RxBD base address of ring 3 */
566 u8 res17d[4];
567 u32 rbase4; /* 0x.424 - RxBD base address of ring 4 */
568 u8 res17e[4];
569 u32 rbase5; /* 0x.42c - RxBD base address of ring 5 */
570 u8 res17f[4];
571 u32 rbase6; /* 0x.434 - RxBD base address of ring 6 */
572 u8 res17g[4];
573 u32 rbase7; /* 0x.43c - RxBD base address of ring 7 */
574 u8 res17[192];
575 u32 maccfg1; /* 0x.500 - MAC Configuration 1 Register */
576 u32 maccfg2; /* 0x.504 - MAC Configuration 2 Register */
577 u32 ipgifg; /* 0x.508 - Inter Packet Gap/Inter Frame Gap Register */
578 u32 hafdup; /* 0x.50c - Half Duplex Register */
579 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */
424 u8 res18[12]; 580 u8 res18[12];
425 u32 miimcfg; /* 0x.520 - MII Management Configuration Register */ 581 u32 miimcfg; /* 0x.520 - MII Management Configuration Register */
426 u32 miimcom; /* 0x.524 - MII Management Command Register */ 582 u32 miimcom; /* 0x.524 - MII Management Command Register */
427 u32 miimadd; /* 0x.528 - MII Management Address Register */ 583 u32 miimadd; /* 0x.528 - MII Management Address Register */
428 u32 miimcon; /* 0x.52c - MII Management Control Register */ 584 u32 miimcon; /* 0x.52c - MII Management Control Register */
429 u32 miimstat; /* 0x.530 - MII Management Status Register */ 585 u32 miimstat; /* 0x.530 - MII Management Status Register */
430 u32 miimind; /* 0x.534 - MII Management Indicator Register */ 586 u32 miimind; /* 0x.534 - MII Management Indicator Register */
431 u8 res19[4]; 587 u8 res19[4];
432 u32 ifstat; /* 0x.53c - Interface Status Register */ 588 u32 ifstat; /* 0x.53c - Interface Status Register */
433 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */ 589 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */
434 u32 macstnaddr2; /* 0x.544 - Station Address Part 2 Register */ 590 u32 macstnaddr2; /* 0x.544 - Station Address Part 2 Register */
435 u8 res20[312]; 591 u32 mac01addr1; /* 0x.548 - MAC exact match address 1, part 1 */
436 struct rmon_mib rmon; 592 u32 mac01addr2; /* 0x.54c - MAC exact match address 1, part 2 */
437 u8 res21[192]; 593 u32 mac02addr1; /* 0x.550 - MAC exact match address 2, part 1 */
438 u32 iaddr0; /* 0x.800 - Indivdual address register 0 */ 594 u32 mac02addr2; /* 0x.554 - MAC exact match address 2, part 2 */
439 u32 iaddr1; /* 0x.804 - Indivdual address register 1 */ 595 u32 mac03addr1; /* 0x.558 - MAC exact match address 3, part 1 */
440 u32 iaddr2; /* 0x.808 - Indivdual address register 2 */ 596 u32 mac03addr2; /* 0x.55c - MAC exact match address 3, part 2 */
441 u32 iaddr3; /* 0x.80c - Indivdual address register 3 */ 597 u32 mac04addr1; /* 0x.560 - MAC exact match address 4, part 1 */
442 u32 iaddr4; /* 0x.810 - Indivdual address register 4 */ 598 u32 mac04addr2; /* 0x.564 - MAC exact match address 4, part 2 */
443 u32 iaddr5; /* 0x.814 - Indivdual address register 5 */ 599 u32 mac05addr1; /* 0x.568 - MAC exact match address 5, part 1 */
444 u32 iaddr6; /* 0x.818 - Indivdual address register 6 */ 600 u32 mac05addr2; /* 0x.56c - MAC exact match address 5, part 2 */
445 u32 iaddr7; /* 0x.81c - Indivdual address register 7 */ 601 u32 mac06addr1; /* 0x.570 - MAC exact match address 6, part 1 */
602 u32 mac06addr2; /* 0x.574 - MAC exact match address 6, part 2 */
603 u32 mac07addr1; /* 0x.578 - MAC exact match address 7, part 1 */
604 u32 mac07addr2; /* 0x.57c - MAC exact match address 7, part 2 */
605 u32 mac08addr1; /* 0x.580 - MAC exact match address 8, part 1 */
606 u32 mac08addr2; /* 0x.584 - MAC exact match address 8, part 2 */
607 u32 mac09addr1; /* 0x.588 - MAC exact match address 9, part 1 */
608 u32 mac09addr2; /* 0x.58c - MAC exact match address 9, part 2 */
609 u32 mac10addr1; /* 0x.590 - MAC exact match address 10, part 1*/
610 u32 mac10addr2; /* 0x.594 - MAC exact match address 10, part 2*/
611 u32 mac11addr1; /* 0x.598 - MAC exact match address 11, part 1*/
612 u32 mac11addr2; /* 0x.59c - MAC exact match address 11, part 2*/
613 u32 mac12addr1; /* 0x.5a0 - MAC exact match address 12, part 1*/
614 u32 mac12addr2; /* 0x.5a4 - MAC exact match address 12, part 2*/
615 u32 mac13addr1; /* 0x.5a8 - MAC exact match address 13, part 1*/
616 u32 mac13addr2; /* 0x.5ac - MAC exact match address 13, part 2*/
617 u32 mac14addr1; /* 0x.5b0 - MAC exact match address 14, part 1*/
618 u32 mac14addr2; /* 0x.5b4 - MAC exact match address 14, part 2*/
619 u32 mac15addr1; /* 0x.5b8 - MAC exact match address 15, part 1*/
620 u32 mac15addr2; /* 0x.5bc - MAC exact match address 15, part 2*/
621 u8 res20[192];
622 struct rmon_mib rmon; /* 0x.680-0x.73c */
623 u32 rrej; /* 0x.740 - Receive filer rejected packet counter */
624 u8 res21[188];
625 u32 igaddr0; /* 0x.800 - Indivdual/Group address register 0*/
626 u32 igaddr1; /* 0x.804 - Indivdual/Group address register 1*/
627 u32 igaddr2; /* 0x.808 - Indivdual/Group address register 2*/
628 u32 igaddr3; /* 0x.80c - Indivdual/Group address register 3*/
629 u32 igaddr4; /* 0x.810 - Indivdual/Group address register 4*/
630 u32 igaddr5; /* 0x.814 - Indivdual/Group address register 5*/
631 u32 igaddr6; /* 0x.818 - Indivdual/Group address register 6*/
632 u32 igaddr7; /* 0x.81c - Indivdual/Group address register 7*/
446 u8 res22[96]; 633 u8 res22[96];
447 u32 gaddr0; /* 0x.880 - Global address register 0 */ 634 u32 gaddr0; /* 0x.880 - Group address register 0 */
448 u32 gaddr1; /* 0x.884 - Global address register 1 */ 635 u32 gaddr1; /* 0x.884 - Group address register 1 */
449 u32 gaddr2; /* 0x.888 - Global address register 2 */ 636 u32 gaddr2; /* 0x.888 - Group address register 2 */
450 u32 gaddr3; /* 0x.88c - Global address register 3 */ 637 u32 gaddr3; /* 0x.88c - Group address register 3 */
451 u32 gaddr4; /* 0x.890 - Global address register 4 */ 638 u32 gaddr4; /* 0x.890 - Group address register 4 */
452 u32 gaddr5; /* 0x.894 - Global address register 5 */ 639 u32 gaddr5; /* 0x.894 - Group address register 5 */
453 u32 gaddr6; /* 0x.898 - Global address register 6 */ 640 u32 gaddr6; /* 0x.898 - Group address register 6 */
454 u32 gaddr7; /* 0x.89c - Global address register 7 */ 641 u32 gaddr7; /* 0x.89c - Group address register 7 */
455 u8 res23[856]; 642 u8 res23a[352];
456 u32 attr; /* 0x.bf8 - Attributes Register */ 643 u32 fifocfg; /* 0x.a00 - FIFO interface config register */
457 u32 attreli; /* 0x.bfc - Attributes Extract Length and Extract Index Register */ 644 u8 res23b[252];
645 u8 res23c[248];
646 u32 attr; /* 0x.bf8 - Attributes Register */
647 u32 attreli; /* 0x.bfc - Attributes Extract Length and Extract Index Register */
458 u8 res24[1024]; 648 u8 res24[1024];
459 649
460}; 650};
@@ -496,6 +686,8 @@ struct gfar_private {
496 struct txbd8 *cur_tx; /* Next free ring entry */ 686 struct txbd8 *cur_tx; /* Next free ring entry */
497 struct txbd8 *dirty_tx; /* The Ring entry to be freed. */ 687 struct txbd8 *dirty_tx; /* The Ring entry to be freed. */
498 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */ 688 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */
689 u32 *hash_regs[16];
690 int hash_width;
499 struct gfar *phyregs; 691 struct gfar *phyregs;
500 struct work_struct tq; 692 struct work_struct tq;
501 struct timer_list phy_info_timer; 693 struct timer_list phy_info_timer;
@@ -506,9 +698,12 @@ struct gfar_private {
506 unsigned int rx_stash_size; 698 unsigned int rx_stash_size;
507 unsigned int tx_ring_size; 699 unsigned int tx_ring_size;
508 unsigned int rx_ring_size; 700 unsigned int rx_ring_size;
509 wait_queue_head_t rxcleanupq;
510 unsigned int rxclean;
511 701
702 unsigned char vlan_enable:1,
703 rx_csum_enable:1,
704 extended_hash:1;
705 unsigned short padding;
706 struct vlan_group *vlgrp;
512 /* Info structure initialized by board setup code */ 707 /* Info structure initialized by board setup code */
513 unsigned int interruptTransmit; 708 unsigned int interruptTransmit;
514 unsigned int interruptReceive; 709 unsigned int interruptReceive;
@@ -519,6 +714,8 @@ struct gfar_private {
519 int oldspeed; 714 int oldspeed;
520 int oldduplex; 715 int oldduplex;
521 int oldlink; 716 int oldlink;
717
718 uint32_t msg_enable;
522}; 719};
523 720
524extern inline u32 gfar_read(volatile unsigned *addr) 721extern inline u32 gfar_read(volatile unsigned *addr)
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index 28046e9e88ba..a451de629197 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -46,16 +46,18 @@
46 46
47extern int startup_gfar(struct net_device *dev); 47extern int startup_gfar(struct net_device *dev);
48extern void stop_gfar(struct net_device *dev); 48extern void stop_gfar(struct net_device *dev);
49extern void gfar_receive(int irq, void *dev_id, struct pt_regs *regs); 49extern void gfar_halt(struct net_device *dev);
50extern void gfar_start(struct net_device *dev);
51extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
50 52
51void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, 53static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
52 u64 * buf); 54 u64 * buf);
53void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); 55static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
54int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); 56static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
55int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); 57static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
56void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals); 58static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
57int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals); 59static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
58void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo); 60static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
59 61
60static char stat_gstrings[][ETH_GSTRING_LEN] = { 62static char stat_gstrings[][ETH_GSTRING_LEN] = {
61 "rx-dropped-by-kernel", 63 "rx-dropped-by-kernel",
@@ -118,57 +120,56 @@ static char stat_gstrings[][ETH_GSTRING_LEN] = {
118 "tx-fragmented-frames", 120 "tx-fragmented-frames",
119}; 121};
120 122
123/* Fill in a buffer with the strings which correspond to the
124 * stats */
125static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
126{
127 struct gfar_private *priv = netdev_priv(dev);
128
129 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
130 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
131 else
132 memcpy(buf, stat_gstrings,
133 GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
134}
135
121/* Fill in an array of 64-bit statistics from various sources. 136/* Fill in an array of 64-bit statistics from various sources.
122 * This array will be appended to the end of the ethtool_stats 137 * This array will be appended to the end of the ethtool_stats
123 * structure, and returned to user space 138 * structure, and returned to user space
124 */ 139 */
125void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf) 140static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
126{ 141{
127 int i; 142 int i;
128 struct gfar_private *priv = netdev_priv(dev); 143 struct gfar_private *priv = netdev_priv(dev);
129 u32 *rmon = (u32 *) & priv->regs->rmon;
130 u64 *extra = (u64 *) & priv->extra_stats; 144 u64 *extra = (u64 *) & priv->extra_stats;
131 struct gfar_stats *stats = (struct gfar_stats *) buf;
132 145
133 for (i = 0; i < GFAR_RMON_LEN; i++) { 146 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
134 stats->rmon[i] = (u64) (rmon[i]); 147 u32 *rmon = (u32 *) & priv->regs->rmon;
135 } 148 struct gfar_stats *stats = (struct gfar_stats *) buf;
136
137 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) {
138 stats->extra[i] = extra[i];
139 }
140}
141 149
142/* Returns the number of stats (and their corresponding strings) */ 150 for (i = 0; i < GFAR_RMON_LEN; i++)
143int gfar_stats_count(struct net_device *dev) 151 stats->rmon[i] = (u64) (rmon[i]);
144{
145 return GFAR_STATS_LEN;
146}
147 152
148void gfar_gstrings_normon(struct net_device *dev, u32 stringset, u8 * buf) 153 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
149{ 154 stats->extra[i] = extra[i];
150 memcpy(buf, stat_gstrings, GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); 155 } else
156 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
157 buf[i] = extra[i];
151} 158}
152 159
153void gfar_fill_stats_normon(struct net_device *dev, 160/* Returns the number of stats (and their corresponding strings) */
154 struct ethtool_stats *dummy, u64 * buf) 161static int gfar_stats_count(struct net_device *dev)
155{ 162{
156 int i;
157 struct gfar_private *priv = netdev_priv(dev); 163 struct gfar_private *priv = netdev_priv(dev);
158 u64 *extra = (u64 *) & priv->extra_stats;
159 164
160 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) { 165 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
161 buf[i] = extra[i]; 166 return GFAR_STATS_LEN;
162 } 167 else
168 return GFAR_EXTRA_STATS_LEN;
163} 169}
164 170
165
166int gfar_stats_count_normon(struct net_device *dev)
167{
168 return GFAR_EXTRA_STATS_LEN;
169}
170/* Fills in the drvinfo structure with some basic info */ 171/* Fills in the drvinfo structure with some basic info */
171void gfar_gdrvinfo(struct net_device *dev, struct 172static void gfar_gdrvinfo(struct net_device *dev, struct
172 ethtool_drvinfo *drvinfo) 173 ethtool_drvinfo *drvinfo)
173{ 174{
174 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); 175 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
@@ -182,7 +183,7 @@ void gfar_gdrvinfo(struct net_device *dev, struct
182} 183}
183 184
184/* Return the current settings in the ethtool_cmd structure */ 185/* Return the current settings in the ethtool_cmd structure */
185int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) 186static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
186{ 187{
187 struct gfar_private *priv = netdev_priv(dev); 188 struct gfar_private *priv = netdev_priv(dev);
188 uint gigabit_support = 189 uint gigabit_support =
@@ -216,13 +217,13 @@ int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
216} 217}
217 218
218/* Return the length of the register structure */ 219/* Return the length of the register structure */
219int gfar_reglen(struct net_device *dev) 220static int gfar_reglen(struct net_device *dev)
220{ 221{
221 return sizeof (struct gfar); 222 return sizeof (struct gfar);
222} 223}
223 224
224/* Return a dump of the GFAR register space */ 225/* Return a dump of the GFAR register space */
225void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf) 226static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
226{ 227{
227 int i; 228 int i;
228 struct gfar_private *priv = netdev_priv(dev); 229 struct gfar_private *priv = netdev_priv(dev);
@@ -233,13 +234,6 @@ void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regb
233 buf[i] = theregs[i]; 234 buf[i] = theregs[i];
234} 235}
235 236
236/* Fill in a buffer with the strings which correspond to the
237 * stats */
238void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
239{
240 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
241}
242
243/* Convert microseconds to ethernet clock ticks, which changes 237/* Convert microseconds to ethernet clock ticks, which changes
244 * depending on what speed the controller is running at */ 238 * depending on what speed the controller is running at */
245static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) 239static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
@@ -291,9 +285,12 @@ static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int tic
291 285
292/* Get the coalescing parameters, and put them in the cvals 286/* Get the coalescing parameters, and put them in the cvals
293 * structure. */ 287 * structure. */
294int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) 288static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
295{ 289{
296 struct gfar_private *priv = netdev_priv(dev); 290 struct gfar_private *priv = netdev_priv(dev);
291
292 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
293 return -EOPNOTSUPP;
297 294
298 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime); 295 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime);
299 cvals->rx_max_coalesced_frames = priv->rxcount; 296 cvals->rx_max_coalesced_frames = priv->rxcount;
@@ -337,10 +334,13 @@ int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
337 * Both cvals->*_usecs and cvals->*_frames have to be > 0 334 * Both cvals->*_usecs and cvals->*_frames have to be > 0
338 * in order for coalescing to be active 335 * in order for coalescing to be active
339 */ 336 */
340int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) 337static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
341{ 338{
342 struct gfar_private *priv = netdev_priv(dev); 339 struct gfar_private *priv = netdev_priv(dev);
343 340
341 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
342 return -EOPNOTSUPP;
343
344 /* Set up rx coalescing */ 344 /* Set up rx coalescing */
345 if ((cvals->rx_coalesce_usecs == 0) || 345 if ((cvals->rx_coalesce_usecs == 0) ||
346 (cvals->rx_max_coalesced_frames == 0)) 346 (cvals->rx_max_coalesced_frames == 0))
@@ -379,7 +379,7 @@ int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
379/* Fills in rvals with the current ring parameters. Currently, 379/* Fills in rvals with the current ring parameters. Currently,
380 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and 380 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
381 * jumbo are ignored by the driver */ 381 * jumbo are ignored by the driver */
382void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) 382static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
383{ 383{
384 struct gfar_private *priv = netdev_priv(dev); 384 struct gfar_private *priv = netdev_priv(dev);
385 385
@@ -401,9 +401,8 @@ void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
401 * necessary so that we don't mess things up while we're in 401 * necessary so that we don't mess things up while we're in
402 * motion. We wait for the ring to be clean before reallocating 402 * motion. We wait for the ring to be clean before reallocating
403 * the rings. */ 403 * the rings. */
404int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) 404static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
405{ 405{
406 u32 tempval;
407 struct gfar_private *priv = netdev_priv(dev); 406 struct gfar_private *priv = netdev_priv(dev);
408 int err = 0; 407 int err = 0;
409 408
@@ -425,37 +424,54 @@ int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
425 return -EINVAL; 424 return -EINVAL;
426 } 425 }
427 426
428 /* Stop the controller so we don't rx any more frames */ 427 if (dev->flags & IFF_UP) {
429 /* But first, make sure we clear the bits */ 428 unsigned long flags;
430 tempval = gfar_read(&priv->regs->dmactrl);
431 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
432 gfar_write(&priv->regs->dmactrl, tempval);
433 429
434 tempval = gfar_read(&priv->regs->dmactrl); 430 /* Halt TX and RX, and process the frames which
435 tempval |= (DMACTRL_GRS | DMACTRL_GTS); 431 * have already been received */
436 gfar_write(&priv->regs->dmactrl, tempval); 432 spin_lock_irqsave(&priv->lock, flags);
433 gfar_halt(dev);
434 gfar_clean_rx_ring(dev, priv->rx_ring_size);
435 spin_unlock_irqrestore(&priv->lock, flags);
437 436
438 while (!(gfar_read(&priv->regs->ievent) & (IEVENT_GRSC | IEVENT_GTSC))) 437 /* Now we take down the rings to rebuild them */
439 cpu_relax(); 438 stop_gfar(dev);
439 }
440 440
441 /* Note that rx is not clean right now */ 441 /* Change the size */
442 priv->rxclean = 0; 442 priv->rx_ring_size = rvals->rx_pending;
443 priv->tx_ring_size = rvals->tx_pending;
443 444
444 if (dev->flags & IFF_UP) { 445 /* Rebuild the rings with the new size */
445 /* Tell the driver to process the rest of the frames */ 446 if (dev->flags & IFF_UP)
446 gfar_receive(0, (void *) dev, NULL); 447 err = startup_gfar(dev);
447 448
448 /* Now wait for it to be done */ 449 return err;
449 wait_event_interruptible(priv->rxcleanupq, priv->rxclean); 450}
450 451
451 /* Ok, all packets have been handled. Now we bring it down, 452static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
452 * change the ring size, and bring it up */ 453{
454 struct gfar_private *priv = netdev_priv(dev);
455 int err = 0;
453 456
457 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
458 return -EOPNOTSUPP;
459
460 if (dev->flags & IFF_UP) {
461 unsigned long flags;
462
463 /* Halt TX and RX, and process the frames which
464 * have already been received */
465 spin_lock_irqsave(&priv->lock, flags);
466 gfar_halt(dev);
467 gfar_clean_rx_ring(dev, priv->rx_ring_size);
468 spin_unlock_irqrestore(&priv->lock, flags);
469
470 /* Now we take down the rings to rebuild them */
454 stop_gfar(dev); 471 stop_gfar(dev);
455 } 472 }
456 473
457 priv->rx_ring_size = rvals->rx_pending; 474 priv->rx_csum_enable = data;
458 priv->tx_ring_size = rvals->tx_pending;
459 475
460 if (dev->flags & IFF_UP) 476 if (dev->flags & IFF_UP)
461 err = startup_gfar(dev); 477 err = startup_gfar(dev);
@@ -463,6 +479,61 @@ int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
463 return err; 479 return err;
464} 480}
465 481
482static uint32_t gfar_get_rx_csum(struct net_device *dev)
483{
484 struct gfar_private *priv = netdev_priv(dev);
485
486 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
487 return 0;
488
489 return priv->rx_csum_enable;
490}
491
492static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
493{
494 unsigned long flags;
495 struct gfar_private *priv = netdev_priv(dev);
496
497 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
498 return -EOPNOTSUPP;
499
500 spin_lock_irqsave(&priv->lock, flags);
501 gfar_halt(dev);
502
503 if (data)
504 dev->features |= NETIF_F_IP_CSUM;
505 else
506 dev->features &= ~NETIF_F_IP_CSUM;
507
508 gfar_start(dev);
509 spin_unlock_irqrestore(&priv->lock, flags);
510
511 return 0;
512}
513
514static uint32_t gfar_get_tx_csum(struct net_device *dev)
515{
516 struct gfar_private *priv = netdev_priv(dev);
517
518 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
519 return 0;
520
521 return (dev->features & NETIF_F_IP_CSUM) != 0;
522}
523
524static uint32_t gfar_get_msglevel(struct net_device *dev)
525{
526 struct gfar_private *priv = netdev_priv(dev);
527 return priv->msg_enable;
528}
529
530static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
531{
532 struct gfar_private *priv = netdev_priv(dev);
533 priv->msg_enable = data;
534}
535
536
466struct ethtool_ops gfar_ethtool_ops = { 537struct ethtool_ops gfar_ethtool_ops = {
467 .get_settings = gfar_gsettings, 538 .get_settings = gfar_gsettings,
468 .get_drvinfo = gfar_gdrvinfo, 539 .get_drvinfo = gfar_gdrvinfo,
@@ -476,52 +547,10 @@ struct ethtool_ops gfar_ethtool_ops = {
476 .get_strings = gfar_gstrings, 547 .get_strings = gfar_gstrings,
477 .get_stats_count = gfar_stats_count, 548 .get_stats_count = gfar_stats_count,
478 .get_ethtool_stats = gfar_fill_stats, 549 .get_ethtool_stats = gfar_fill_stats,
479}; 550 .get_rx_csum = gfar_get_rx_csum,
480 551 .get_tx_csum = gfar_get_tx_csum,
481struct ethtool_ops gfar_normon_nocoalesce_ethtool_ops = { 552 .set_rx_csum = gfar_set_rx_csum,
482 .get_settings = gfar_gsettings, 553 .set_tx_csum = gfar_set_tx_csum,
483 .get_drvinfo = gfar_gdrvinfo, 554 .get_msglevel = gfar_get_msglevel,
484 .get_regs_len = gfar_reglen, 555 .set_msglevel = gfar_set_msglevel,
485 .get_regs = gfar_get_regs,
486 .get_link = ethtool_op_get_link,
487 .get_ringparam = gfar_gringparam,
488 .set_ringparam = gfar_sringparam,
489 .get_strings = gfar_gstrings_normon,
490 .get_stats_count = gfar_stats_count_normon,
491 .get_ethtool_stats = gfar_fill_stats_normon,
492};
493
494struct ethtool_ops gfar_nocoalesce_ethtool_ops = {
495 .get_settings = gfar_gsettings,
496 .get_drvinfo = gfar_gdrvinfo,
497 .get_regs_len = gfar_reglen,
498 .get_regs = gfar_get_regs,
499 .get_link = ethtool_op_get_link,
500 .get_ringparam = gfar_gringparam,
501 .set_ringparam = gfar_sringparam,
502 .get_strings = gfar_gstrings,
503 .get_stats_count = gfar_stats_count,
504 .get_ethtool_stats = gfar_fill_stats,
505};
506
507struct ethtool_ops gfar_normon_ethtool_ops = {
508 .get_settings = gfar_gsettings,
509 .get_drvinfo = gfar_gdrvinfo,
510 .get_regs_len = gfar_reglen,
511 .get_regs = gfar_get_regs,
512 .get_link = ethtool_op_get_link,
513 .get_coalesce = gfar_gcoalesce,
514 .set_coalesce = gfar_scoalesce,
515 .get_ringparam = gfar_gringparam,
516 .set_ringparam = gfar_sringparam,
517 .get_strings = gfar_gstrings_normon,
518 .get_stats_count = gfar_stats_count_normon,
519 .get_ethtool_stats = gfar_fill_stats_normon,
520};
521
522struct ethtool_ops *gfar_op_array[] = {
523 &gfar_ethtool_ops,
524 &gfar_normon_ethtool_ops,
525 &gfar_nocoalesce_ethtool_ops,
526 &gfar_normon_nocoalesce_ethtool_ops
527}; 556};
diff --git a/drivers/net/gianfar_phy.c b/drivers/net/gianfar_phy.c
index 02b16abc89bd..7c965f268a82 100644
--- a/drivers/net/gianfar_phy.c
+++ b/drivers/net/gianfar_phy.c
@@ -572,7 +572,7 @@ static struct phy_info phy_info_dm9161 = {
572static struct phy_info phy_info_marvell = { 572static struct phy_info phy_info_marvell = {
573 .phy_id = 0x01410c00, 573 .phy_id = 0x01410c00,
574 .phy_id_mask = 0xffffff00, 574 .phy_id_mask = 0xffffff00,
575 .name = "Marvell 88E1101", 575 .name = "Marvell 88E1101/88E1111",
576 .features = MII_GBIT_FEATURES, 576 .features = MII_GBIT_FEATURES,
577 .config_aneg = &marvell_config_aneg, 577 .config_aneg = &marvell_config_aneg,
578 .read_status = &marvell_read_status, 578 .read_status = &marvell_read_status,
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 3d96714ed3cf..d9df1d9a5739 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -1149,7 +1149,7 @@ static void hamachi_tx_timeout(struct net_device *dev)
1149 skb->dev = dev; /* Mark as being used by this device. */ 1149 skb->dev = dev; /* Mark as being used by this device. */
1150 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1150 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1151 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1151 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1152 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1152 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1153 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn | 1153 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
1154 DescEndPacket | DescIntr | (hmp->rx_buf_sz - 2)); 1154 DescEndPacket | DescIntr | (hmp->rx_buf_sz - 2));
1155 } 1155 }
@@ -1210,7 +1210,7 @@ static void hamachi_init_ring(struct net_device *dev)
1210 skb->dev = dev; /* Mark as being used by this device. */ 1210 skb->dev = dev; /* Mark as being used by this device. */
1211 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1211 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1212 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1212 hmp->rx_ring[i].addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1213 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1213 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1214 /* -2 because it doesn't REALLY have that first 2 bytes -KDU */ 1214 /* -2 because it doesn't REALLY have that first 2 bytes -KDU */
1215 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn | 1215 hmp->rx_ring[i].status_n_length = cpu_to_le32(DescOwn |
1216 DescEndPacket | DescIntr | (hmp->rx_buf_sz -2)); 1216 DescEndPacket | DescIntr | (hmp->rx_buf_sz -2));
@@ -1509,7 +1509,7 @@ static int hamachi_rx(struct net_device *dev)
1509 desc->addr, 1509 desc->addr,
1510 hmp->rx_buf_sz, 1510 hmp->rx_buf_sz,
1511 PCI_DMA_FROMDEVICE); 1511 PCI_DMA_FROMDEVICE);
1512 buf_addr = (u8 *) hmp->rx_skbuff[entry]->tail; 1512 buf_addr = (u8 *) hmp->rx_skbuff[entry]->data;
1513 frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12]))); 1513 frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12])));
1514 if (hamachi_debug > 4) 1514 if (hamachi_debug > 4)
1515 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n", 1515 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n",
@@ -1678,7 +1678,7 @@ static int hamachi_rx(struct net_device *dev)
1678 skb->dev = dev; /* Mark as being used by this device. */ 1678 skb->dev = dev; /* Mark as being used by this device. */
1679 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1679 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1680 desc->addr = cpu_to_leXX(pci_map_single(hmp->pci_dev, 1680 desc->addr = cpu_to_leXX(pci_map_single(hmp->pci_dev,
1681 skb->tail, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1681 skb->data, hmp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1682 } 1682 }
1683 desc->status_n_length = cpu_to_le32(hmp->rx_buf_sz); 1683 desc->status_n_length = cpu_to_le32(hmp->rx_buf_sz);
1684 if (entry >= RX_RING_SIZE-1) 1684 if (entry >= RX_RING_SIZE-1)
@@ -1772,9 +1772,9 @@ static int hamachi_close(struct net_device *dev)
1772 readl(ioaddr + RxCurPtr) == (long)&hmp->rx_ring[i] ? '>' : ' ', 1772 readl(ioaddr + RxCurPtr) == (long)&hmp->rx_ring[i] ? '>' : ' ',
1773 i, hmp->rx_ring[i].status_n_length, hmp->rx_ring[i].addr); 1773 i, hmp->rx_ring[i].status_n_length, hmp->rx_ring[i].addr);
1774 if (hamachi_debug > 6) { 1774 if (hamachi_debug > 6) {
1775 if (*(u8*)hmp->rx_skbuff[i]->tail != 0x69) { 1775 if (*(u8*)hmp->rx_skbuff[i]->data != 0x69) {
1776 u16 *addr = (u16 *) 1776 u16 *addr = (u16 *)
1777 hmp->rx_skbuff[i]->tail; 1777 hmp->rx_skbuff[i]->data;
1778 int j; 1778 int j;
1779 1779
1780 for (j = 0; j < 0x50; j++) 1780 for (j = 0; j < 0x50; j++)
diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c
index ece1b1a13186..c27e417f32bf 100644
--- a/drivers/net/hamradio/scc.c
+++ b/drivers/net/hamradio/scc.c
@@ -304,7 +304,7 @@ static inline void scc_discard_buffers(struct scc_channel *scc)
304 scc->tx_buff = NULL; 304 scc->tx_buff = NULL;
305 } 305 }
306 306
307 while (skb_queue_len(&scc->tx_queue)) 307 while (!skb_queue_empty(&scc->tx_queue))
308 dev_kfree_skb(skb_dequeue(&scc->tx_queue)); 308 dev_kfree_skb(skb_dequeue(&scc->tx_queue));
309 309
310 spin_unlock_irqrestore(&scc->lock, flags); 310 spin_unlock_irqrestore(&scc->lock, flags);
@@ -1126,8 +1126,7 @@ static void t_dwait(unsigned long channel)
1126 1126
1127 if (scc->stat.tx_state == TXS_WAIT) /* maxkeyup or idle timeout */ 1127 if (scc->stat.tx_state == TXS_WAIT) /* maxkeyup or idle timeout */
1128 { 1128 {
1129 if (skb_queue_len(&scc->tx_queue) == 0) /* nothing to send */ 1129 if (skb_queue_empty(&scc->tx_queue)) { /* nothing to send */
1130 {
1131 scc->stat.tx_state = TXS_IDLE; 1130 scc->stat.tx_state = TXS_IDLE;
1132 netif_wake_queue(scc->dev); /* t_maxkeyup locked it. */ 1131 netif_wake_queue(scc->dev); /* t_maxkeyup locked it. */
1133 return; 1132 return;
diff --git a/drivers/net/hp-plus.c b/drivers/net/hp-plus.c
index 4834314b676d..0abf5dd08b4c 100644
--- a/drivers/net/hp-plus.c
+++ b/drivers/net/hp-plus.c
@@ -159,12 +159,7 @@ struct net_device * __init hp_plus_probe(int unit)
159 err = do_hpp_probe(dev); 159 err = do_hpp_probe(dev);
160 if (err) 160 if (err)
161 goto out; 161 goto out;
162 err = register_netdev(dev);
163 if (err)
164 goto out1;
165 return dev; 162 return dev;
166out1:
167 cleanup_card(dev);
168out: 163out:
169 free_netdev(dev); 164 free_netdev(dev);
170 return ERR_PTR(err); 165 return ERR_PTR(err);
@@ -271,6 +266,9 @@ static int __init hpp_probe1(struct net_device *dev, int ioaddr)
271 /* Leave the 8390 and HP chip reset. */ 266 /* Leave the 8390 and HP chip reset. */
272 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION); 267 outw(inw(ioaddr + HPP_OPTION) & ~EnableIRQ, ioaddr + HPP_OPTION);
273 268
269 retval = register_netdev(dev);
270 if (retval)
271 goto out;
274 return 0; 272 return 0;
275out: 273out:
276 release_region(ioaddr, HP_IO_EXTENT); 274 release_region(ioaddr, HP_IO_EXTENT);
@@ -463,11 +461,8 @@ init_module(void)
463 dev->irq = irq[this_dev]; 461 dev->irq = irq[this_dev];
464 dev->base_addr = io[this_dev]; 462 dev->base_addr = io[this_dev];
465 if (do_hpp_probe(dev) == 0) { 463 if (do_hpp_probe(dev) == 0) {
466 if (register_netdev(dev) == 0) { 464 dev_hpp[found++] = dev;
467 dev_hpp[found++] = dev; 465 continue;
468 continue;
469 }
470 cleanup_card(dev);
471 } 466 }
472 free_netdev(dev); 467 free_netdev(dev);
473 printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]); 468 printk(KERN_WARNING "hp-plus.c: No HP-Plus card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/hp.c b/drivers/net/hp.c
index 026888611d6f..59cf841b14ab 100644
--- a/drivers/net/hp.c
+++ b/drivers/net/hp.c
@@ -123,12 +123,7 @@ struct net_device * __init hp_probe(int unit)
123 err = do_hp_probe(dev); 123 err = do_hp_probe(dev);
124 if (err) 124 if (err)
125 goto out; 125 goto out;
126 err = register_netdev(dev);
127 if (err)
128 goto out1;
129 return dev; 126 return dev;
130out1:
131 cleanup_card(dev);
132out: 127out:
133 free_netdev(dev); 128 free_netdev(dev);
134 return ERR_PTR(err); 129 return ERR_PTR(err);
@@ -227,7 +222,12 @@ static int __init hp_probe1(struct net_device *dev, int ioaddr)
227 ei_status.block_output = &hp_block_output; 222 ei_status.block_output = &hp_block_output;
228 hp_init_card(dev); 223 hp_init_card(dev);
229 224
225 retval = register_netdev(dev);
226 if (retval)
227 goto out1;
230 return 0; 228 return 0;
229out1:
230 free_irq(dev->irq, dev);
231out: 231out:
232 release_region(ioaddr, HP_IO_EXTENT); 232 release_region(ioaddr, HP_IO_EXTENT);
233 return retval; 233 return retval;
@@ -432,11 +432,8 @@ init_module(void)
432 dev->irq = irq[this_dev]; 432 dev->irq = irq[this_dev];
433 dev->base_addr = io[this_dev]; 433 dev->base_addr = io[this_dev];
434 if (do_hp_probe(dev) == 0) { 434 if (do_hp_probe(dev) == 0) {
435 if (register_netdev(dev) == 0) { 435 dev_hp[found++] = dev;
436 dev_hp[found++] = dev; 436 continue;
437 continue;
438 }
439 cleanup_card(dev);
440 } 437 }
441 free_netdev(dev); 438 free_netdev(dev);
442 printk(KERN_WARNING "hp.c: No HP card found (i/o = 0x%x).\n", io[this_dev]); 439 printk(KERN_WARNING "hp.c: No HP card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c
index b3a898c5a585..cf0ac6fda1a1 100644
--- a/drivers/net/hp100.c
+++ b/drivers/net/hp100.c
@@ -106,6 +106,7 @@
106#include <linux/interrupt.h> 106#include <linux/interrupt.h>
107#include <linux/eisa.h> 107#include <linux/eisa.h>
108#include <linux/pci.h> 108#include <linux/pci.h>
109#include <linux/dma-mapping.h>
109#include <linux/spinlock.h> 110#include <linux/spinlock.h>
110#include <linux/netdevice.h> 111#include <linux/netdevice.h>
111#include <linux/etherdevice.h> 112#include <linux/etherdevice.h>
@@ -417,12 +418,7 @@ struct net_device * __init hp100_probe(int unit)
417 if (err) 418 if (err)
418 goto out; 419 goto out;
419 420
420 err = register_netdev(dev);
421 if (err)
422 goto out1;
423 return dev; 421 return dev;
424 out1:
425 release_region(dev->base_addr, HP100_REGION_SIZE);
426 out: 422 out:
427 free_netdev(dev); 423 free_netdev(dev);
428 return ERR_PTR(err); 424 return ERR_PTR(err);
@@ -562,7 +558,7 @@ static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
562 * Also, we can have EISA Busmaster cards (not tested), 558 * Also, we can have EISA Busmaster cards (not tested),
563 * so beware !!! - Jean II */ 559 * so beware !!! - Jean II */
564 if((bus == HP100_BUS_PCI) && 560 if((bus == HP100_BUS_PCI) &&
565 (pci_set_dma_mask(pci_dev, 0xffffffff))) { 561 (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK))) {
566 /* Gracefully fallback to shared memory */ 562 /* Gracefully fallback to shared memory */
567 goto busmasterfail; 563 goto busmasterfail;
568 } 564 }
@@ -776,11 +772,22 @@ static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
776 printk("Warning! Link down.\n"); 772 printk("Warning! Link down.\n");
777 } 773 }
778 774
775 err = register_netdev(dev);
776 if (err)
777 goto out3;
778
779 return 0; 779 return 0;
780out3:
781 if (local_mode == 1)
782 pci_free_consistent(lp->pci_dev, MAX_RINGSIZE + 0x0f,
783 lp->page_vaddr_algn,
784 virt_to_whatever(dev, lp->page_vaddr_algn));
785 if (mem_ptr_virt)
786 iounmap(mem_ptr_virt);
780out2: 787out2:
781 release_region(ioaddr, HP100_REGION_SIZE); 788 release_region(ioaddr, HP100_REGION_SIZE);
782out1: 789out1:
783 return -ENODEV; 790 return err;
784} 791}
785 792
786/* This procedure puts the card into a stable init state */ 793/* This procedure puts the card into a stable init state */
@@ -2875,18 +2882,12 @@ static int __init hp100_eisa_probe (struct device *gendev)
2875 if (err) 2882 if (err)
2876 goto out1; 2883 goto out1;
2877 2884
2878 err = register_netdev(dev);
2879 if (err)
2880 goto out2;
2881
2882#ifdef HP100_DEBUG 2885#ifdef HP100_DEBUG
2883 printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name, 2886 printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name,
2884 dev->base_addr); 2887 dev->base_addr);
2885#endif 2888#endif
2886 gendev->driver_data = dev; 2889 gendev->driver_data = dev;
2887 return 0; 2890 return 0;
2888 out2:
2889 release_region(dev->base_addr, HP100_REGION_SIZE);
2890 out1: 2891 out1:
2891 free_netdev(dev); 2892 free_netdev(dev);
2892 return err; 2893 return err;
@@ -2951,17 +2952,12 @@ static int __devinit hp100_pci_probe (struct pci_dev *pdev,
2951 err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev); 2952 err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev);
2952 if (err) 2953 if (err)
2953 goto out1; 2954 goto out1;
2954 err = register_netdev(dev);
2955 if (err)
2956 goto out2;
2957 2955
2958#ifdef HP100_DEBUG 2956#ifdef HP100_DEBUG
2959 printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr); 2957 printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr);
2960#endif 2958#endif
2961 pci_set_drvdata(pdev, dev); 2959 pci_set_drvdata(pdev, dev);
2962 return 0; 2960 return 0;
2963 out2:
2964 release_region(dev->base_addr, HP100_REGION_SIZE);
2965 out1: 2961 out1:
2966 free_netdev(dev); 2962 free_netdev(dev);
2967 out0: 2963 out0:
@@ -3032,15 +3028,9 @@ static int __init hp100_isa_init(void)
3032 SET_MODULE_OWNER(dev); 3028 SET_MODULE_OWNER(dev);
3033 3029
3034 err = hp100_isa_probe(dev, hp100_port[i]); 3030 err = hp100_isa_probe(dev, hp100_port[i]);
3035 if (!err) { 3031 if (!err)
3036 err = register_netdev(dev); 3032 hp100_devlist[cards++] = dev;
3037 if (!err) 3033 else
3038 hp100_devlist[cards++] = dev;
3039 else
3040 release_region(dev->base_addr, HP100_REGION_SIZE);
3041 }
3042
3043 if (err)
3044 free_netdev(dev); 3034 free_netdev(dev);
3045 } 3035 }
3046 3036
diff --git a/drivers/net/isa-skeleton.c b/drivers/net/isa-skeleton.c
index 50bebb55e9ee..88ae8a04fabc 100644
--- a/drivers/net/isa-skeleton.c
+++ b/drivers/net/isa-skeleton.c
@@ -176,12 +176,7 @@ struct net_device * __init netcard_probe(int unit)
176 err = do_netcard_probe(dev); 176 err = do_netcard_probe(dev);
177 if (err) 177 if (err)
178 goto out; 178 goto out;
179 err = register_netdev(dev);
180 if (err)
181 goto out1;
182 return dev; 179 return dev;
183out1:
184 cleanup_card(dev);
185out: 180out:
186 free_netdev(dev); 181 free_netdev(dev);
187 return ERR_PTR(err); 182 return ERR_PTR(err);
@@ -316,7 +311,15 @@ static int __init netcard_probe1(struct net_device *dev, int ioaddr)
316 311
317 dev->tx_timeout = &net_tx_timeout; 312 dev->tx_timeout = &net_tx_timeout;
318 dev->watchdog_timeo = MY_TX_TIMEOUT; 313 dev->watchdog_timeo = MY_TX_TIMEOUT;
314
315 err = register_netdev(dev);
316 if (err)
317 goto out2;
319 return 0; 318 return 0;
319out2:
320#ifdef jumpered_dma
321 free_dma(dev->dma);
322#endif
320out1: 323out1:
321#ifdef jumpered_interrupts 324#ifdef jumpered_interrupts
322 free_irq(dev->irq, dev); 325 free_irq(dev->irq, dev);
@@ -691,11 +694,8 @@ int init_module(void)
691 dev->dma = dma; 694 dev->dma = dma;
692 dev->mem_start = mem; 695 dev->mem_start = mem;
693 if (do_netcard_probe(dev) == 0) { 696 if (do_netcard_probe(dev) == 0) {
694 if (register_netdev(dev) == 0) 697 this_device = dev;
695 this_device = dev; 698 return 0;
696 return 0;
697 }
698 cleanup_card(dev);
699 } 699 }
700 free_netdev(dev); 700 free_netdev(dev);
701 return -ENXIO; 701 return -ENXIO;
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 35f6a7c271a2..097b90ccf575 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -47,7 +47,9 @@ char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
47#else 47#else
48#define DRIVERNAPI "-NAPI" 48#define DRIVERNAPI "-NAPI"
49#endif 49#endif
50char ixgb_driver_version[] = "1.0.95-k2"DRIVERNAPI; 50
51#define DRV_VERSION "1.0.95-k2"DRIVERNAPI
52char ixgb_driver_version[] = DRV_VERSION;
51char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; 53char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
52 54
53/* ixgb_pci_tbl - PCI Device ID Table 55/* ixgb_pci_tbl - PCI Device ID Table
@@ -140,6 +142,7 @@ static struct pci_driver ixgb_driver = {
140MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); 142MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
141MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver"); 143MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
142MODULE_LICENSE("GPL"); 144MODULE_LICENSE("GPL");
145MODULE_VERSION(DRV_VERSION);
143 146
144/* some defines for controlling descriptor fetches in h/w */ 147/* some defines for controlling descriptor fetches in h/w */
145#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */ 148#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index dec557fb6a99..b4929beb33b2 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -356,11 +356,8 @@ int init_module(void)
356 dev->base_addr = io[this_dev]; 356 dev->base_addr = io[this_dev];
357 dev->dma = dma[this_dev]; 357 dev->dma = dma[this_dev];
358 if (do_lance_probe(dev) == 0) { 358 if (do_lance_probe(dev) == 0) {
359 if (register_netdev(dev) == 0) { 359 dev_lance[found++] = dev;
360 dev_lance[found++] = dev; 360 continue;
361 continue;
362 }
363 cleanup_card(dev);
364 } 361 }
365 free_netdev(dev); 362 free_netdev(dev);
366 break; 363 break;
@@ -448,12 +445,7 @@ struct net_device * __init lance_probe(int unit)
448 err = do_lance_probe(dev); 445 err = do_lance_probe(dev);
449 if (err) 446 if (err)
450 goto out; 447 goto out;
451 err = register_netdev(dev);
452 if (err)
453 goto out1;
454 return dev; 448 return dev;
455out1:
456 cleanup_card(dev);
457out: 449out:
458 free_netdev(dev); 450 free_netdev(dev);
459 return ERR_PTR(err); 451 return ERR_PTR(err);
@@ -724,6 +716,9 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
724 dev->tx_timeout = lance_tx_timeout; 716 dev->tx_timeout = lance_tx_timeout;
725 dev->watchdog_timeo = TX_TIMEOUT; 717 dev->watchdog_timeo = TX_TIMEOUT;
726 718
719 err = register_netdev(dev);
720 if (err)
721 goto out_dma;
727 return 0; 722 return 0;
728out_dma: 723out_dma:
729 if (dev->dma != 4) 724 if (dev->dma != 4)
@@ -867,7 +862,7 @@ lance_init_ring(struct net_device *dev, int gfp)
867 lp->rx_skbuff[i] = skb; 862 lp->rx_skbuff[i] = skb;
868 if (skb) { 863 if (skb) {
869 skb->dev = dev; 864 skb->dev = dev;
870 rx_buff = skb->tail; 865 rx_buff = skb->data;
871 } else 866 } else
872 rx_buff = kmalloc(PKT_BUF_SZ, GFP_DMA | gfp); 867 rx_buff = kmalloc(PKT_BUF_SZ, GFP_DMA | gfp);
873 if (rx_buff == NULL) 868 if (rx_buff == NULL)
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index 5e263fcba669..41bad07ac1ac 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -553,14 +553,14 @@ static inline void init_rx_bufs(struct net_device *dev)
553 if (skb == NULL) 553 if (skb == NULL)
554 panic("%s: alloc_skb() failed", __FILE__); 554 panic("%s: alloc_skb() failed", __FILE__);
555 skb_reserve(skb, 2); 555 skb_reserve(skb, 2);
556 dma_addr = dma_map_single(lp->dev, skb->tail,PKT_BUF_SZ, 556 dma_addr = dma_map_single(lp->dev, skb->data,PKT_BUF_SZ,
557 DMA_FROM_DEVICE); 557 DMA_FROM_DEVICE);
558 skb->dev = dev; 558 skb->dev = dev;
559 rbd->v_next = rbd+1; 559 rbd->v_next = rbd+1;
560 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1)); 560 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1));
561 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd)); 561 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd));
562 rbd->skb = skb; 562 rbd->skb = skb;
563 rbd->v_data = skb->tail; 563 rbd->v_data = skb->data;
564 rbd->b_data = WSWAPchar(dma_addr); 564 rbd->b_data = WSWAPchar(dma_addr);
565 rbd->size = PKT_BUF_SZ; 565 rbd->size = PKT_BUF_SZ;
566 } 566 }
@@ -783,8 +783,8 @@ static inline int i596_rx(struct net_device *dev)
783 rx_in_place = 1; 783 rx_in_place = 1;
784 rbd->skb = newskb; 784 rbd->skb = newskb;
785 newskb->dev = dev; 785 newskb->dev = dev;
786 dma_addr = dma_map_single(lp->dev, newskb->tail, PKT_BUF_SZ, DMA_FROM_DEVICE); 786 dma_addr = dma_map_single(lp->dev, newskb->data, PKT_BUF_SZ, DMA_FROM_DEVICE);
787 rbd->v_data = newskb->tail; 787 rbd->v_data = newskb->data;
788 rbd->b_data = WSWAPchar(dma_addr); 788 rbd->b_data = WSWAPchar(dma_addr);
789 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd)); 789 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
790 } 790 }
diff --git a/drivers/net/lne390.c b/drivers/net/lne390.c
index 179a97c0af69..27f0d8ac4c40 100644
--- a/drivers/net/lne390.c
+++ b/drivers/net/lne390.c
@@ -167,12 +167,7 @@ struct net_device * __init lne390_probe(int unit)
167 err = do_lne390_probe(dev); 167 err = do_lne390_probe(dev);
168 if (err) 168 if (err)
169 goto out; 169 goto out;
170 err = register_netdev(dev);
171 if (err)
172 goto out1;
173 return dev; 170 return dev;
174out1:
175 cleanup_card(dev);
176out: 171out:
177 free_netdev(dev); 172 free_netdev(dev);
178 return ERR_PTR(err); 173 return ERR_PTR(err);
@@ -296,7 +291,14 @@ static int __init lne390_probe1(struct net_device *dev, int ioaddr)
296 dev->poll_controller = ei_poll; 291 dev->poll_controller = ei_poll;
297#endif 292#endif
298 NS8390_init(dev, 0); 293 NS8390_init(dev, 0);
294
295 ret = register_netdev(dev);
296 if (ret)
297 goto unmap;
299 return 0; 298 return 0;
299unmap:
300 if (ei_status.reg0)
301 iounmap((void *)dev->mem_start);
300cleanup: 302cleanup:
301 free_irq(dev->irq, dev); 303 free_irq(dev->irq, dev);
302 return ret; 304 return ret;
@@ -426,11 +428,8 @@ int init_module(void)
426 dev->base_addr = io[this_dev]; 428 dev->base_addr = io[this_dev];
427 dev->mem_start = mem[this_dev]; 429 dev->mem_start = mem[this_dev];
428 if (do_lne390_probe(dev) == 0) { 430 if (do_lne390_probe(dev) == 0) {
429 if (register_netdev(dev) == 0) { 431 dev_lne[found++] = dev;
430 dev_lne[found++] = dev; 432 continue;
431 continue;
432 }
433 cleanup_card(dev);
434 } 433 }
435 free_netdev(dev); 434 free_netdev(dev);
436 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]); 435 printk(KERN_WARNING "lne390.c: No LNE390 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index 6ed2d7dbd44c..81d0a26e4f41 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -109,7 +109,7 @@ bitrev(int b)
109} 109}
110 110
111 111
112static int __devinit mace_probe(struct macio_dev *mdev, const struct of_match *match) 112static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_id *match)
113{ 113{
114 struct device_node *mace = macio_get_of_node(mdev); 114 struct device_node *mace = macio_get_of_node(mdev);
115 struct net_device *dev; 115 struct net_device *dev;
@@ -1009,12 +1009,10 @@ static irqreturn_t mace_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
1009 return IRQ_HANDLED; 1009 return IRQ_HANDLED;
1010} 1010}
1011 1011
1012static struct of_match mace_match[] = 1012static struct of_device_id mace_match[] =
1013{ 1013{
1014 { 1014 {
1015 .name = "mace", 1015 .name = "mace",
1016 .type = OF_ANY_MATCH,
1017 .compatible = OF_ANY_MATCH
1018 }, 1016 },
1019 {}, 1017 {},
1020}; 1018};
diff --git a/drivers/net/myri_code.h b/drivers/net/myri_code.h
index 851eba8a3e00..e9c6e569d1f4 100644
--- a/drivers/net/myri_code.h
+++ b/drivers/net/myri_code.h
@@ -4775,1288 +4775,7 @@ static unsigned char lanai4_code[76256] __initdata = {
4775/* This is the LANai data */ 4775/* This is the LANai data */
4776 4776
4777static unsigned int lanai4_data_off = 0x94F0; /* half-word offset */ 4777static unsigned int lanai4_data_off = 0x94F0; /* half-word offset */
4778static unsigned char lanai4_data[20472] __initdata = { 4778static unsigned char lanai4_data[20472] __initdata;
47790x00,0x00,
47800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
47990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
48990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
49990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
50990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
51990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
52990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
53990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
54990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
55990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
56990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
57990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x01,
58900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
58990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59590x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59600x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59610x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59620x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59630x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59640x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59650x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59660x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59670x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59680x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59690x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59700x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59710x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59720x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59730x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59740x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59750x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59760x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59770x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59780x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59790x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59800x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59810x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59820x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59830x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59840x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59850x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59860x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59870x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59880x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59890x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59900x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59910x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59920x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59930x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59940x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59950x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59960x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59970x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59980x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
59990x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60000x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60010x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60020x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60030x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60040x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60050x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60060x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60070x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60080x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60090x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60100x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60110x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60120x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60130x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60140x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60150x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60160x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60170x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60180x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60190x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60200x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60210x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60220x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60230x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60240x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60250x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60260x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60270x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60280x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60290x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60300x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60310x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60320x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60330x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60340x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60350x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60360x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60370x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60380x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60390x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60400x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60410x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60420x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60430x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60440x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60450x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60460x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60470x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60480x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60490x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60500x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60510x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60520x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60530x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60540x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60550x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60560x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60570x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60580x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
60590x00,0x00, 0x00,0x00, 0x00,0x00, } ;
6060 4779
6061 4780
6062#ifdef SYMBOL_DEFINES_COMPILED 4781#ifdef SYMBOL_DEFINES_COMPILED
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index aad5494c83cf..f0996ce5c268 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -369,7 +369,7 @@ static void myri_tx(struct myri_eth *mp, struct net_device *dev)
369 * assume 802.3 if the type field is short enough to be a length. 369 * assume 802.3 if the type field is short enough to be a length.
370 * This is normal practice and works for any 'now in use' protocol. 370 * This is normal practice and works for any 'now in use' protocol.
371 */ 371 */
372static unsigned short myri_type_trans(struct sk_buff *skb, struct net_device *dev) 372static __be16 myri_type_trans(struct sk_buff *skb, struct net_device *dev)
373{ 373{
374 struct ethhdr *eth; 374 struct ethhdr *eth;
375 unsigned char *rawp; 375 unsigned char *rawp;
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index babb59e146ea..9d6d2548c2d3 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -1926,7 +1926,7 @@ static void refill_rx(struct net_device *dev)
1926 break; /* Better luck next round. */ 1926 break; /* Better luck next round. */
1927 skb->dev = dev; /* Mark as being used by this device. */ 1927 skb->dev = dev; /* Mark as being used by this device. */
1928 np->rx_dma[entry] = pci_map_single(np->pci_dev, 1928 np->rx_dma[entry] = pci_map_single(np->pci_dev,
1929 skb->tail, buflen, PCI_DMA_FROMDEVICE); 1929 skb->data, buflen, PCI_DMA_FROMDEVICE);
1930 np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]); 1930 np->rx_ring[entry].addr = cpu_to_le32(np->rx_dma[entry]);
1931 } 1931 }
1932 np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz); 1932 np->rx_ring[entry].cmd_status = cpu_to_le32(np->rx_buf_sz);
@@ -2280,7 +2280,7 @@ static void netdev_rx(struct net_device *dev)
2280 buflen, 2280 buflen,
2281 PCI_DMA_FROMDEVICE); 2281 PCI_DMA_FROMDEVICE);
2282 eth_copy_and_sum(skb, 2282 eth_copy_and_sum(skb,
2283 np->rx_skbuff[entry]->tail, pkt_len, 0); 2283 np->rx_skbuff[entry]->data, pkt_len, 0);
2284 skb_put(skb, pkt_len); 2284 skb_put(skb, pkt_len);
2285 pci_dma_sync_single_for_device(np->pci_dev, 2285 pci_dma_sync_single_for_device(np->pci_dev,
2286 np->rx_dma[entry], 2286 np->rx_dma[entry],
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index 84e291e24935..8f40368cf2e9 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -180,12 +180,7 @@ struct net_device * __init ne_probe(int unit)
180 err = do_ne_probe(dev); 180 err = do_ne_probe(dev);
181 if (err) 181 if (err)
182 goto out; 182 goto out;
183 err = register_netdev(dev);
184 if (err)
185 goto out1;
186 return dev; 183 return dev;
187out1:
188 cleanup_card(dev);
189out: 184out:
190 free_netdev(dev); 185 free_netdev(dev);
191 return ERR_PTR(err); 186 return ERR_PTR(err);
@@ -325,8 +320,13 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
325 dev->poll_controller = ei_poll; 320 dev->poll_controller = ei_poll;
326#endif 321#endif
327 NS8390_init(dev, 0); 322 NS8390_init(dev, 0);
328 return 0;
329 323
324 ret = register_netdev(dev);
325 if (ret)
326 goto out_irq;
327 return 0;
328out_irq:
329 free_irq(dev->irq, dev);
330err_out: 330err_out:
331 release_region(ioaddr, NE_IO_EXTENT); 331 release_region(ioaddr, NE_IO_EXTENT);
332 return ret; 332 return ret;
@@ -633,11 +633,8 @@ int init_module(void)
633 err = init_reg_offset(dev, dev->base_addr); 633 err = init_reg_offset(dev, dev->base_addr);
634 if (!err) { 634 if (!err) {
635 if (do_ne_probe(dev) == 0) { 635 if (do_ne_probe(dev) == 0) {
636 if (register_netdev(dev) == 0) { 636 dev_ne[found++] = dev;
637 dev_ne[found++] = dev; 637 continue;
638 continue;
639 }
640 cleanup_card(dev);
641 } 638 }
642 } 639 }
643 free_netdev(dev); 640 free_netdev(dev);
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index 496433902ade..6c57096aa2e1 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -229,12 +229,7 @@ struct net_device * __init ne_probe(int unit)
229 err = do_ne_probe(dev); 229 err = do_ne_probe(dev);
230 if (err) 230 if (err)
231 goto out; 231 goto out;
232 err = register_netdev(dev);
233 if (err)
234 goto out1;
235 return dev; 232 return dev;
236out1:
237 cleanup_card(dev);
238out: 233out:
239 free_netdev(dev); 234 free_netdev(dev);
240 return ERR_PTR(err); 235 return ERR_PTR(err);
@@ -534,8 +529,14 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
534 dev->poll_controller = ei_poll; 529 dev->poll_controller = ei_poll;
535#endif 530#endif
536 NS8390_init(dev, 0); 531 NS8390_init(dev, 0);
532
533 ret = register_netdev(dev);
534 if (ret)
535 goto out_irq;
537 return 0; 536 return 0;
538 537
538out_irq:
539 free_irq(dev->irq, dev);
539err_out: 540err_out:
540 release_region(ioaddr, NE_IO_EXTENT); 541 release_region(ioaddr, NE_IO_EXTENT);
541 return ret; 542 return ret;
@@ -826,11 +827,8 @@ int init_module(void)
826 dev->mem_end = bad[this_dev]; 827 dev->mem_end = bad[this_dev];
827 dev->base_addr = io[this_dev]; 828 dev->base_addr = io[this_dev];
828 if (do_ne_probe(dev) == 0) { 829 if (do_ne_probe(dev) == 0) {
829 if (register_netdev(dev) == 0) { 830 dev_ne[found++] = dev;
830 dev_ne[found++] = dev; 831 continue;
831 continue;
832 }
833 cleanup_card(dev);
834 } 832 }
835 free_netdev(dev); 833 free_netdev(dev);
836 if (found) 834 if (found)
diff --git a/drivers/net/ne2.c b/drivers/net/ne2.c
index 6ebef27dbfae..6d62ada85de6 100644
--- a/drivers/net/ne2.c
+++ b/drivers/net/ne2.c
@@ -301,12 +301,7 @@ struct net_device * __init ne2_probe(int unit)
301 err = do_ne2_probe(dev); 301 err = do_ne2_probe(dev);
302 if (err) 302 if (err)
303 goto out; 303 goto out;
304 err = register_netdev(dev);
305 if (err)
306 goto out1;
307 return dev; 304 return dev;
308out1:
309 cleanup_card(dev);
310out: 305out:
311 free_netdev(dev); 306 free_netdev(dev);
312 return ERR_PTR(err); 307 return ERR_PTR(err);
@@ -517,7 +512,14 @@ static int __init ne2_probe1(struct net_device *dev, int slot)
517 dev->poll_controller = ei_poll; 512 dev->poll_controller = ei_poll;
518#endif 513#endif
519 NS8390_init(dev, 0); 514 NS8390_init(dev, 0);
515
516 retval = register_netdev(dev);
517 if (retval)
518 goto out1;
520 return 0; 519 return 0;
520out1:
521 mca_set_adapter_procfn( ei_status.priv, NULL, NULL);
522 free_irq(dev->irq, dev);
521out: 523out:
522 release_region(base_addr, NE_IO_EXTENT); 524 release_region(base_addr, NE_IO_EXTENT);
523 return retval; 525 return retval;
@@ -798,11 +800,8 @@ int init_module(void)
798 dev->mem_end = bad[this_dev]; 800 dev->mem_end = bad[this_dev];
799 dev->base_addr = io[this_dev]; 801 dev->base_addr = io[this_dev];
800 if (do_ne2_probe(dev) == 0) { 802 if (do_ne2_probe(dev) == 0) {
801 if (register_netdev(dev) == 0) { 803 dev_ne[found++] = dev;
802 dev_ne[found++] = dev; 804 continue;
803 continue;
804 }
805 cleanup_card(dev);
806 } 805 }
807 free_netdev(dev); 806 free_netdev(dev);
808 break; 807 break;
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index a1a6c08e7dcf..f1c01ac29102 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -660,6 +660,7 @@ static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state)
660 660
661 netif_device_detach(dev); 661 netif_device_detach(dev);
662 pci_save_state(pdev); 662 pci_save_state(pdev);
663 pci_disable_device(pdev);
663 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 664 pci_set_power_state(pdev, pci_choose_state(pdev, state));
664 665
665 return 0; 666 return 0;
@@ -671,6 +672,8 @@ static int ne2k_pci_resume (struct pci_dev *pdev)
671 672
672 pci_set_power_state(pdev, 0); 673 pci_set_power_state(pdev, 0);
673 pci_restore_state(pdev); 674 pci_restore_state(pdev);
675 pci_enable_device(pdev);
676 pci_set_master(pdev);
674 NS8390_init(dev, 1); 677 NS8390_init(dev, 1);
675 netif_device_attach(dev); 678 netif_device_attach(dev);
676 679
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index c336b46bd332..e64df4d0800b 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -101,6 +101,7 @@
101#include <linux/moduleparam.h> 101#include <linux/moduleparam.h>
102#include <linux/types.h> 102#include <linux/types.h>
103#include <linux/pci.h> 103#include <linux/pci.h>
104#include <linux/dma-mapping.h>
104#include <linux/netdevice.h> 105#include <linux/netdevice.h>
105#include <linux/etherdevice.h> 106#include <linux/etherdevice.h>
106#include <linux/delay.h> 107#include <linux/delay.h>
@@ -573,7 +574,7 @@ static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb)
573 574
574 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC; 575 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC;
575 cmdsts = REAL_RX_BUF_SIZE | CMDSTS_INTR; 576 cmdsts = REAL_RX_BUF_SIZE | CMDSTS_INTR;
576 buf = pci_map_single(dev->pci_dev, skb->tail, 577 buf = pci_map_single(dev->pci_dev, skb->data,
577 REAL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 578 REAL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
578 build_rx_desc(dev, sg, 0, buf, cmdsts, 0); 579 build_rx_desc(dev, sg, 0, buf, cmdsts, 0);
579 /* update link of previous rx */ 580 /* update link of previous rx */
@@ -603,7 +604,7 @@ static inline int rx_refill(struct net_device *ndev, int gfp)
603 if (unlikely(!skb)) 604 if (unlikely(!skb))
604 break; 605 break;
605 606
606 res = (long)skb->tail & 0xf; 607 res = (long)skb->data & 0xf;
607 res = 0x10 - res; 608 res = 0x10 - res;
608 res &= 0xf; 609 res &= 0xf;
609 skb_reserve(skb, res); 610 skb_reserve(skb, res);
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index c6e8b25f9685..71fd41122c91 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -86,7 +86,6 @@ earlier 3Com products.
86#include <linux/ethtool.h> 86#include <linux/ethtool.h>
87#include <linux/bitops.h> 87#include <linux/bitops.h>
88 88
89#include <pcmcia/version.h>
90#include <pcmcia/cs_types.h> 89#include <pcmcia/cs_types.h>
91#include <pcmcia/cs.h> 90#include <pcmcia/cs.h>
92#include <pcmcia/cistpl.h> 91#include <pcmcia/cistpl.h>
@@ -312,11 +311,6 @@ static dev_link_t *tc574_attach(void)
312 link->next = dev_list; 311 link->next = dev_list;
313 dev_list = link; 312 dev_list = link;
314 client_reg.dev_info = &dev_info; 313 client_reg.dev_info = &dev_info;
315 client_reg.EventMask =
316 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
317 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
318 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
319 client_reg.event_handler = &tc574_event;
320 client_reg.Version = 0x0210; 314 client_reg.Version = 0x0210;
321 client_reg.event_callback_args.client_data = link; 315 client_reg.event_callback_args.client_data = link;
322 ret = pcmcia_register_client(&link->handle, &client_reg); 316 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -1286,13 +1280,22 @@ static int el3_close(struct net_device *dev)
1286 return 0; 1280 return 0;
1287} 1281}
1288 1282
1283static struct pcmcia_device_id tc574_ids[] = {
1284 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1285 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "3CCFEM556.cis"),
1286 PCMCIA_DEVICE_NULL,
1287};
1288MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1289
1289static struct pcmcia_driver tc574_driver = { 1290static struct pcmcia_driver tc574_driver = {
1290 .owner = THIS_MODULE, 1291 .owner = THIS_MODULE,
1291 .drv = { 1292 .drv = {
1292 .name = "3c574_cs", 1293 .name = "3c574_cs",
1293 }, 1294 },
1294 .attach = tc574_attach, 1295 .attach = tc574_attach,
1296 .event = tc574_event,
1295 .detach = tc574_detach, 1297 .detach = tc574_detach,
1298 .id_table = tc574_ids,
1296}; 1299};
1297 1300
1298static int __init init_tc574(void) 1301static int __init init_tc574(void)
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 89abdda1d343..d83fdd8c1943 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -40,7 +40,6 @@
40#include <linux/ioport.h> 40#include <linux/ioport.h>
41#include <linux/bitops.h> 41#include <linux/bitops.h>
42 42
43#include <pcmcia/version.h>
44#include <pcmcia/cs_types.h> 43#include <pcmcia/cs_types.h>
45#include <pcmcia/cs.h> 44#include <pcmcia/cs.h>
46#include <pcmcia/cistpl.h> 45#include <pcmcia/cistpl.h>
@@ -226,11 +225,6 @@ static dev_link_t *tc589_attach(void)
226 link->next = dev_list; 225 link->next = dev_list;
227 dev_list = link; 226 dev_list = link;
228 client_reg.dev_info = &dev_info; 227 client_reg.dev_info = &dev_info;
229 client_reg.EventMask =
230 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
231 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
232 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
233 client_reg.event_handler = &tc589_event;
234 client_reg.Version = 0x0210; 228 client_reg.Version = 0x0210;
235 client_reg.event_callback_args.client_data = link; 229 client_reg.event_callback_args.client_data = link;
236 ret = pcmcia_register_client(&link->handle, &client_reg); 230 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -1057,13 +1051,26 @@ static int el3_close(struct net_device *dev)
1057 return 0; 1051 return 0;
1058} 1052}
1059 1053
1054static struct pcmcia_device_id tc589_ids[] = {
1055 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0101, 0x0562),
1056 PCMCIA_MFC_DEVICE_PROD_ID1(0, "Motorola MARQUIS", 0xf03e4e77),
1057 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0589),
1058 PCMCIA_DEVICE_PROD_ID12("Farallon", "ENet", 0x58d93fc4, 0x992c2202),
1059 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035, "3CXEM556.cis"),
1060 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d, "3CXEM556.cis"),
1061 PCMCIA_DEVICE_NULL,
1062};
1063MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
1064
1060static struct pcmcia_driver tc589_driver = { 1065static struct pcmcia_driver tc589_driver = {
1061 .owner = THIS_MODULE, 1066 .owner = THIS_MODULE,
1062 .drv = { 1067 .drv = {
1063 .name = "3c589_cs", 1068 .name = "3c589_cs",
1064 }, 1069 },
1065 .attach = tc589_attach, 1070 .attach = tc589_attach,
1071 .event = tc589_event,
1066 .detach = tc589_detach, 1072 .detach = tc589_detach,
1073 .id_table = tc589_ids,
1067}; 1074};
1068 1075
1069static int __init init_tc589(void) 1076static int __init init_tc589(void)
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 853b586e481a..8bb4e85689ea 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -37,7 +37,6 @@
37#include <linux/netdevice.h> 37#include <linux/netdevice.h>
38#include "../8390.h" 38#include "../8390.h"
39 39
40#include <pcmcia/version.h>
41#include <pcmcia/cs_types.h> 40#include <pcmcia/cs_types.h>
42#include <pcmcia/cs.h> 41#include <pcmcia/cs.h>
43#include <pcmcia/cistpl.h> 42#include <pcmcia/cistpl.h>
@@ -181,11 +180,6 @@ static dev_link_t *axnet_attach(void)
181 link->next = dev_list; 180 link->next = dev_list;
182 dev_list = link; 181 dev_list = link;
183 client_reg.dev_info = &dev_info; 182 client_reg.dev_info = &dev_info;
184 client_reg.EventMask =
185 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
186 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
187 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
188 client_reg.event_handler = &axnet_event;
189 client_reg.Version = 0x0210; 183 client_reg.Version = 0x0210;
190 client_reg.event_callback_args.client_data = link; 184 client_reg.event_callback_args.client_data = link;
191 ret = pcmcia_register_client(&link->handle, &client_reg); 185 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -850,13 +844,43 @@ static void block_output(struct net_device *dev, int count,
850 outsw(nic_base + AXNET_DATAPORT, buf, count>>1); 844 outsw(nic_base + AXNET_DATAPORT, buf, count>>1);
851} 845}
852 846
847static struct pcmcia_device_id axnet_ids[] = {
848 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081),
849 PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301),
850 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301),
851 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303),
852 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309),
853 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106),
854 PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab),
855 PCMCIA_DEVICE_PROD_ID124("Fast Ethernet", "16-bit PC Card", "AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef),
856 PCMCIA_DEVICE_PROD_ID12("ASIX", "AX88190", 0x0959823b, 0xab9be5ef),
857 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNA-100B", 0x552ab682, 0xbc3b87e1),
858 PCMCIA_DEVICE_PROD_ID12("CHEETAH ETHERCARD", "EN2228", 0x00fa7bc8, 0x00e990cc),
859 PCMCIA_DEVICE_PROD_ID12("CNet", "CNF301", 0xbc477dde, 0x78c5f40b),
860 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXD", 0x5261440f, 0x436768c5),
861 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e),
862 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L100C16", 0x55632fd5, 0x66bc2a90),
863 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
864 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609),
865 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04),
866 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116),
867 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058),
868 PCMCIA_DEVICE_PROD_ID14("Network Everywhere", "AX88190", 0x820a67b6, 0xab9be5ef),
869 /* this is not specific enough */
870 /* PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202), */
871 PCMCIA_DEVICE_NULL,
872};
873MODULE_DEVICE_TABLE(pcmcia, axnet_ids);
874
853static struct pcmcia_driver axnet_cs_driver = { 875static struct pcmcia_driver axnet_cs_driver = {
854 .owner = THIS_MODULE, 876 .owner = THIS_MODULE,
855 .drv = { 877 .drv = {
856 .name = "axnet_cs", 878 .name = "axnet_cs",
857 }, 879 },
858 .attach = axnet_attach, 880 .attach = axnet_attach,
881 .event = axnet_event,
859 .detach = axnet_detach, 882 .detach = axnet_detach,
883 .id_table = axnet_ids,
860}; 884};
861 885
862static int __init init_axnet_cs(void) 886static int __init init_axnet_cs(void)
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 4294e1e3f156..b9355d9498a3 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -43,7 +43,6 @@
43#include <linux/arcdevice.h> 43#include <linux/arcdevice.h>
44#include <linux/com20020.h> 44#include <linux/com20020.h>
45 45
46#include <pcmcia/version.h>
47#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
48#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
@@ -200,11 +199,6 @@ static dev_link_t *com20020_attach(void)
200 link->next = dev_list; 199 link->next = dev_list;
201 dev_list = link; 200 dev_list = link;
202 client_reg.dev_info = &dev_info; 201 client_reg.dev_info = &dev_info;
203 client_reg.EventMask =
204 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
205 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
206 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
207 client_reg.event_handler = &com20020_event;
208 client_reg.Version = 0x0210; 202 client_reg.Version = 0x0210;
209 client_reg.event_callback_args.client_data = link; 203 client_reg.event_callback_args.client_data = link;
210 ret = pcmcia_register_client(&link->handle, &client_reg); 204 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -483,7 +477,11 @@ static int com20020_event(event_t event, int priority,
483 return 0; 477 return 0;
484} /* com20020_event */ 478} /* com20020_event */
485 479
486 480static struct pcmcia_device_id com20020_ids[] = {
481 PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.", "PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf),
482 PCMCIA_DEVICE_NULL
483};
484MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
487 485
488static struct pcmcia_driver com20020_cs_driver = { 486static struct pcmcia_driver com20020_cs_driver = {
489 .owner = THIS_MODULE, 487 .owner = THIS_MODULE,
@@ -491,7 +489,9 @@ static struct pcmcia_driver com20020_cs_driver = {
491 .name = "com20020_cs", 489 .name = "com20020_cs",
492 }, 490 },
493 .attach = com20020_attach, 491 .attach = com20020_attach,
492 .event = com20020_event,
494 .detach = com20020_detach, 493 .detach = com20020_detach,
494 .id_table = com20020_ids,
495}; 495};
496 496
497static int __init init_com20020_cs(void) 497static int __init init_com20020_cs(void)
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index 0424865e8094..9d8197bb293a 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -49,7 +49,6 @@
49#include <linux/ioport.h> 49#include <linux/ioport.h>
50#include <linux/crc32.h> 50#include <linux/crc32.h>
51 51
52#include <pcmcia/version.h>
53#include <pcmcia/cs_types.h> 52#include <pcmcia/cs_types.h>
54#include <pcmcia/cs.h> 53#include <pcmcia/cs.h>
55#include <pcmcia/cistpl.h> 54#include <pcmcia/cistpl.h>
@@ -288,11 +287,6 @@ static dev_link_t *fmvj18x_attach(void)
288 link->next = dev_list; 287 link->next = dev_list;
289 dev_list = link; 288 dev_list = link;
290 client_reg.dev_info = &dev_info; 289 client_reg.dev_info = &dev_info;
291 client_reg.EventMask =
292 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
293 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
294 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
295 client_reg.event_handler = &fmvj18x_event;
296 client_reg.Version = 0x0210; 290 client_reg.Version = 0x0210;
297 client_reg.event_callback_args.client_data = link; 291 client_reg.event_callback_args.client_data = link;
298 ret = pcmcia_register_client(&link->handle, &client_reg); 292 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -435,7 +429,9 @@ static void fmvj18x_config(dev_link_t *link)
435 pcmcia_get_status(handle, &status); 429 pcmcia_get_status(handle, &status);
436 if (status.CardState & CS_EVENT_3VCARD) 430 if (status.CardState & CS_EVENT_3VCARD)
437 link->conf.Vcc = 33; /* inserted in 3.3V slot */ 431 link->conf.Vcc = 33; /* inserted in 3.3V slot */
438 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410) { 432 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
433 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610
434 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) {
439 /* MultiFunction Card */ 435 /* MultiFunction Card */
440 link->conf.ConfigBase = 0x800; 436 link->conf.ConfigBase = 0x800;
441 link->conf.ConfigIndex = 0x47; 437 link->conf.ConfigIndex = 0x47;
@@ -764,13 +760,40 @@ static int fmvj18x_event(event_t event, int priority,
764 return 0; 760 return 0;
765} /* fmvj18x_event */ 761} /* fmvj18x_event */
766 762
763static struct pcmcia_device_id fmvj18x_ids[] = {
764 PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004),
765 PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59),
766 PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922),
767 PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922),
768 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db),
769 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e),
770 PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2),
771 PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4),
772 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6),
773 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6),
774 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666),
775 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70),
776 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a),
777 PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2),
778 PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454),
779 PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da),
780 PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080),
781 PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
782 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
783 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
784 PCMCIA_DEVICE_NULL,
785};
786MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
787
767static struct pcmcia_driver fmvj18x_cs_driver = { 788static struct pcmcia_driver fmvj18x_cs_driver = {
768 .owner = THIS_MODULE, 789 .owner = THIS_MODULE,
769 .drv = { 790 .drv = {
770 .name = "fmvj18x_cs", 791 .name = "fmvj18x_cs",
771 }, 792 },
772 .attach = fmvj18x_attach, 793 .attach = fmvj18x_attach,
794 .event = fmvj18x_event,
773 .detach = fmvj18x_detach, 795 .detach = fmvj18x_detach,
796 .id_table = fmvj18x_ids,
774}; 797};
775 798
776static int __init init_fmvj18x_cs(void) 799static int __init init_fmvj18x_cs(void)
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index 3107ccfe8f3d..b6c140eb9799 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -57,7 +57,6 @@
57#include <linux/trdevice.h> 57#include <linux/trdevice.h>
58#include <linux/ibmtr.h> 58#include <linux/ibmtr.h>
59 59
60#include <pcmcia/version.h>
61#include <pcmcia/cs_types.h> 60#include <pcmcia/cs_types.h>
62#include <pcmcia/cs.h> 61#include <pcmcia/cs.h>
63#include <pcmcia/cistpl.h> 62#include <pcmcia/cistpl.h>
@@ -119,9 +118,6 @@ static void ibmtr_detach(dev_link_t *);
119 118
120static dev_link_t *dev_list; 119static dev_link_t *dev_list;
121 120
122extern int ibmtr_probe_card(struct net_device *dev);
123extern irqreturn_t tok_interrupt (int irq, void *dev_id, struct pt_regs *regs);
124
125/*====================================================================*/ 121/*====================================================================*/
126 122
127typedef struct ibmtr_dev_t { 123typedef struct ibmtr_dev_t {
@@ -193,11 +189,6 @@ static dev_link_t *ibmtr_attach(void)
193 link->next = dev_list; 189 link->next = dev_list;
194 dev_list = link; 190 dev_list = link;
195 client_reg.dev_info = &dev_info; 191 client_reg.dev_info = &dev_info;
196 client_reg.EventMask =
197 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
198 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
199 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
200 client_reg.event_handler = &ibmtr_event;
201 client_reg.Version = 0x0210; 192 client_reg.Version = 0x0210;
202 client_reg.event_callback_args.client_data = link; 193 client_reg.event_callback_args.client_data = link;
203 ret = pcmcia_register_client(&link->handle, &client_reg); 194 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -511,13 +502,22 @@ static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase)
511 return; 502 return;
512} 503}
513 504
505static struct pcmcia_device_id ibmtr_ids[] = {
506 PCMCIA_DEVICE_PROD_ID12("3Com", "TokenLink Velocity PC Card", 0x41240e5b, 0x82c3734e),
507 PCMCIA_DEVICE_PROD_ID12("IBM", "TOKEN RING", 0xb569a6e5, 0xbf8eed47),
508 PCMCIA_DEVICE_NULL,
509};
510MODULE_DEVICE_TABLE(pcmcia, ibmtr_ids);
511
514static struct pcmcia_driver ibmtr_cs_driver = { 512static struct pcmcia_driver ibmtr_cs_driver = {
515 .owner = THIS_MODULE, 513 .owner = THIS_MODULE,
516 .drv = { 514 .drv = {
517 .name = "ibmtr_cs", 515 .name = "ibmtr_cs",
518 }, 516 },
519 .attach = ibmtr_attach, 517 .attach = ibmtr_attach,
518 .event = ibmtr_event,
520 .detach = ibmtr_detach, 519 .detach = ibmtr_detach,
520 .id_table = ibmtr_ids,
521}; 521};
522 522
523static int __init init_ibmtr_cs(void) 523static int __init init_ibmtr_cs(void)
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 4603807fcafb..dbb941004ae9 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -146,7 +146,6 @@ Include Files
146#include <linux/ioport.h> 146#include <linux/ioport.h>
147#include <linux/bitops.h> 147#include <linux/bitops.h>
148 148
149#include <pcmcia/version.h>
150#include <pcmcia/cs_types.h> 149#include <pcmcia/cs_types.h>
151#include <pcmcia/cs.h> 150#include <pcmcia/cs.h>
152#include <pcmcia/cisreg.h> 151#include <pcmcia/cisreg.h>
@@ -502,11 +501,6 @@ static dev_link_t *nmclan_attach(void)
502 link->next = dev_list; 501 link->next = dev_list;
503 dev_list = link; 502 dev_list = link;
504 client_reg.dev_info = &dev_info; 503 client_reg.dev_info = &dev_info;
505 client_reg.EventMask =
506 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
507 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
508 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
509 client_reg.event_handler = &nmclan_event;
510 client_reg.Version = 0x0210; 504 client_reg.Version = 0x0210;
511 client_reg.event_callback_args.client_data = link; 505 client_reg.event_callback_args.client_data = link;
512 ret = pcmcia_register_client(&link->handle, &client_reg); 506 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -1675,13 +1669,22 @@ static void set_multicast_list(struct net_device *dev)
1675 1669
1676} /* set_multicast_list */ 1670} /* set_multicast_list */
1677 1671
1672static struct pcmcia_device_id nmclan_ids[] = {
1673 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
1674 PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet", 0x0ebf1d60, 0x00b2e941),
1675 PCMCIA_DEVICE_NULL,
1676};
1677MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
1678
1678static struct pcmcia_driver nmclan_cs_driver = { 1679static struct pcmcia_driver nmclan_cs_driver = {
1679 .owner = THIS_MODULE, 1680 .owner = THIS_MODULE,
1680 .drv = { 1681 .drv = {
1681 .name = "nmclan_cs", 1682 .name = "nmclan_cs",
1682 }, 1683 },
1683 .attach = nmclan_attach, 1684 .attach = nmclan_attach,
1685 .event = nmclan_event,
1684 .detach = nmclan_detach, 1686 .detach = nmclan_detach,
1687 .id_table = nmclan_ids,
1685}; 1688};
1686 1689
1687static int __init init_nmclan_cs(void) 1690static int __init init_nmclan_cs(void)
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 181b6ed55003..e1664aef3dfd 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -40,7 +40,6 @@
40#include <linux/netdevice.h> 40#include <linux/netdevice.h>
41#include <../drivers/net/8390.h> 41#include <../drivers/net/8390.h>
42 42
43#include <pcmcia/version.h>
44#include <pcmcia/cs_types.h> 43#include <pcmcia/cs_types.h>
45#include <pcmcia/cs.h> 44#include <pcmcia/cs.h>
46#include <pcmcia/cistpl.h> 45#include <pcmcia/cistpl.h>
@@ -276,11 +275,6 @@ static dev_link_t *pcnet_attach(void)
276 link->next = dev_list; 275 link->next = dev_list;
277 dev_list = link; 276 dev_list = link;
278 client_reg.dev_info = &dev_info; 277 client_reg.dev_info = &dev_info;
279 client_reg.EventMask =
280 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
281 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
282 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
283 client_reg.event_handler = &pcnet_event;
284 client_reg.Version = 0x0210; 278 client_reg.Version = 0x0210;
285 client_reg.event_callback_args.client_data = link; 279 client_reg.event_callback_args.client_data = link;
286 ret = pcmcia_register_client(&link->handle, &client_reg); 280 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -1155,11 +1149,13 @@ static int set_config(struct net_device *dev, struct ifmap *map)
1155static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs) 1149static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
1156{ 1150{
1157 struct net_device *dev = dev_id; 1151 struct net_device *dev = dev_id;
1158 pcnet_dev_t *info = PRIV(dev); 1152 pcnet_dev_t *info;
1159 irqreturn_t ret = ei_interrupt(irq, dev_id, regs); 1153 irqreturn_t ret = ei_interrupt(irq, dev_id, regs);
1160 1154
1161 if (ret == IRQ_HANDLED) 1155 if (ret == IRQ_HANDLED) {
1156 info = PRIV(dev);
1162 info->stale = 0; 1157 info->stale = 0;
1158 }
1163 return ret; 1159 return ret;
1164} 1160}
1165 1161
@@ -1350,7 +1346,7 @@ static void dma_block_input(struct net_device *dev, int count,
1350 if (count & 0x01) 1346 if (count & 0x01)
1351 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++; 1347 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
1352 1348
1353 /* This was for the ALPHA version only, but enough people have 1349 /* This was for the ALPHA version only, but enough people have been
1354 encountering problems that it is still here. */ 1350 encountering problems that it is still here. */
1355#ifdef PCMCIA_DEBUG 1351#ifdef PCMCIA_DEBUG
1356 if (ei_debug > 4) { /* DMA termination address check... */ 1352 if (ei_debug > 4) { /* DMA termination address check... */
@@ -1424,7 +1420,7 @@ static void dma_block_output(struct net_device *dev, int count,
1424 dma_start = jiffies; 1420 dma_start = jiffies;
1425 1421
1426#ifdef PCMCIA_DEBUG 1422#ifdef PCMCIA_DEBUG
1427 /* This was for the ALPHA version only, but enough people have 1423 /* This was for the ALPHA version only, but enough people have been
1428 encountering problems that it is still here. */ 1424 encountering problems that it is still here. */
1429 if (ei_debug > 4) { /* DMA termination address check... */ 1425 if (ei_debug > 4) { /* DMA termination address check... */
1430 int addr, tries = 20; 1426 int addr, tries = 20;
@@ -1635,13 +1631,217 @@ failed:
1635 1631
1636/*====================================================================*/ 1632/*====================================================================*/
1637 1633
1634static struct pcmcia_device_id pcnet_ids[] = {
1635 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0057, 0x0021),
1636 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0104, 0x000a),
1637 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0xea15),
1638 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0x3341),
1639 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab),
1640 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101),
1641 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab),
1642 PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e),
1643 PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
1644 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
1645 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
1646 PCMCIA_PFC_DEVICE_PROD_ID12(0, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
1647 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1648 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
1649 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
1650 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
1651 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
1652 PCMCIA_MFC_DEVICE_PROD_ID123(0, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
1653 PCMCIA_MFC_DEVICE_PROD_ID2(0, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
1654 PCMCIA_DEVICE_MANF_CARD(0x0057, 0x1004),
1655 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x000d),
1656 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0075),
1657 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0145),
1658 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x0230),
1659 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x4530),
1660/* PCMCIA_DEVICE_MANF_CARD(0x0149, 0xc1ab), conflict with axnet_cs */
1661 PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0110),
1662 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x2328),
1663 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x8041),
1664 PCMCIA_DEVICE_MANF_CARD(0x0213, 0x2452),
1665/* PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202), conflict with axnet_cs */
1666 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0300),
1667 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0307),
1668 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030a),
1669 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1103),
1670 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1121),
1671 PCMCIA_DEVICE_PROD_ID12("2408LAN", "Ethernet", 0x352fff7f, 0x00b2e941),
1672 PCMCIA_DEVICE_PROD_ID123("Cardwell", "PCMCIA", "ETHERNET", 0x9533672e, 0x281f1c5d, 0x3ff7175b),
1673 PCMCIA_DEVICE_PROD_ID123("CNet ", "CN30BC", "ETHERNET", 0x9fe55d3d, 0x85601198, 0x3ff7175b),
1674 PCMCIA_DEVICE_PROD_ID123("Digital", "Ethernet", "Adapter", 0x9999ab35, 0x00b2e941, 0x4b0d829e),
1675 PCMCIA_DEVICE_PROD_ID123("Edimax Technology Inc.", "PCMCIA", "Ethernet Card", 0x738a0019, 0x281f1c5d, 0x5e9d92c0),
1676 PCMCIA_DEVICE_PROD_ID123("EFA ", "EFA207", "ETHERNET", 0x3d294be4, 0xeb9aab6c, 0x3ff7175b),
1677 PCMCIA_DEVICE_PROD_ID123("I-O DATA", "PCLA", "ETHERNET", 0x1d55d7ec, 0xe4c64d34, 0x3ff7175b),
1678 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCLATE", "ETHERNET", 0x547e66dc, 0x6b260753, 0x3ff7175b),
1679 PCMCIA_DEVICE_PROD_ID123("KingMax Technology Inc.", "EN10-T2", "PCMCIA Ethernet Card", 0x932b7189, 0x699e4436, 0x6f6652e0),
1680 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2216", 0x281f1c5d, 0xd4cd2f20, 0xb87add82),
1681 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2620", 0x281f1c5d, 0xd4cd2f20, 0x7d3d83a8),
1682 PCMCIA_DEVICE_PROD_ID1("2412LAN", 0x67f236ab),
1683 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2212", 0xdfc6b5b2, 0xcb112a11),
1684 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2216-PCMCIA-ETHERNET", 0xdfc6b5b2, 0x5542bfff),
1685 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA100-PCM-T V2 100/10M LAN PC Card", 0xbb7fbdd7, 0xcd91cc68),
1686 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM", 0xbb7fbdd7, 0x5ba10d49),
1687 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA100-PCM V2", 0x36634a66, 0xc6d05997),
1688 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM_V2", 0xbb7fBdd7, 0x28e299f8),
1689 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA-PCM V3", 0x36634a66, 0x62241d96),
1690 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8010", 0x5070a7f9, 0x82f96e96),
1691 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8610", 0x5070a7f9, 0x86741224),
1692 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002", 0x93b15570, 0x75ec3efb),
1693 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002T", 0x93b15570, 0x461c5247),
1694 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8010", 0x93b15570, 0x82f96e96),
1695 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet", 0x578ba6e7, 0x0a9888c1),
1696 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet 10/100", 0x578ba6e7, 0x939fedbd),
1697 PCMCIA_DEVICE_PROD_ID12("AROWANA", "PCMCIA Ethernet LAN Card", 0x313adbc8, 0x08d9f190),
1698 PCMCIA_DEVICE_PROD_ID12("ASANTE", "FriendlyNet PC Card", 0x3a7ade0f, 0x41c64504),
1699 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNT-10TB", 0x552ab682, 0xeeb1ba6a),
1700 PCMCIA_DEVICE_PROD_ID12("CF", "10Base-Ethernet", 0x44ebf863, 0x93ae4d79),
1701 PCMCIA_DEVICE_PROD_ID12("CNet", "CN40BC Ethernet", 0xbc477dde, 0xfba775a7),
1702 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "BASEline PCMCIA 10 MBit Ethernetadapter", 0xfa2e424d, 0xe9190d8a),
1703 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "FASTline PCMCIA 10/100 Fast-Ethernet", 0xfa2e424d, 0x3953d9b9),
1704 PCMCIA_DEVICE_PROD_ID12("CONTEC", "C-NET(PC)C-10L", 0x21cab552, 0xf6f90722),
1705 PCMCIA_DEVICE_PROD_ID12("corega", "FEther PCC-TXF", 0x0a21501a, 0xa51564a2),
1706 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-T", 0x5261440f, 0xfa9d85bd),
1707 PCMCIA_DEVICE_PROD_ID12("Corega K.K.", "corega EtherII PCC-TD", 0xd4fdcbd8, 0xc49bd73d),
1708 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega Ether PCC-T", 0x5261440f, 0x6705fcaa),
1709 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FastEther PCC-TX", 0x5261440f, 0x485e85d9),
1710 PCMCIA_DEVICE_PROD_ID12("Corega,K.K.", "Ethernet LAN Card", 0x110d26d9, 0x9fd2f0a2),
1711 PCMCIA_DEVICE_PROD_ID12("corega,K.K.", "Ethernet LAN Card", 0x9791a90e, 0x9fd2f0a2),
1712 PCMCIA_DEVICE_PROD_ID12("CouplerlessPCMCIA", "100BASE", 0xee5af0ad, 0x7c2add04),
1713 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-010", 0x77008979, 0x9d8d445d),
1714 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-110E 10/100M LAN Card", 0x77008979, 0xfd184814),
1715 PCMCIA_DEVICE_PROD_ID12("DataTrek.", "NetCard ", 0x5cd66d9d, 0x84697ce0),
1716 PCMCIA_DEVICE_PROD_ID12("Dayna Communications, Inc.", "CommuniCard E", 0x0c629325, 0xb4e7dbaf),
1717 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100", 0x697403d8, 0xe160b995),
1718 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100 Dongless", 0x697403d8, 0xa6d3b233),
1719 PCMCIA_DEVICE_PROD_ID12("DIGITAL", "DEPCM-XX", 0x69616cb3, 0xe600e76e),
1720 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-650", 0x1a424a1c, 0xf28c8398),
1721 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660", 0x1a424a1c, 0xd9a1d05b),
1722 PCMCIA_DEVICE_PROD_ID12("D-Link", "DFE-650", 0x1a424a1c, 0x0f0073f9),
1723 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 PC Card", 0x725b842d, 0xf1efee84),
1724 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 Port Attached PC Card", 0x725b842d, 0x2db1f8e9),
1725 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L10BC", 0x55632fd5, 0xdc65f2b1),
1726 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10BC", 0x6a26d1cf, 0xdc65f2b1),
1727 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10C", 0x6a26d1cf, 0xc4f84efb),
1728 PCMCIA_DEVICE_PROD_ID12("E-CARD", "E-CARD", 0x6701da11, 0x6701da11),
1729 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet 10BaseT card", 0x53c864c6, 0xedd059f6),
1730 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet Combo card", 0x53c864c6, 0x929c486c),
1731 PCMCIA_DEVICE_PROD_ID12("Ethernet", "Adapter", 0x00b2e941, 0x4b0d829e),
1732 PCMCIA_DEVICE_PROD_ID12("Ethernet Adapter", "E2000 PCMCIA Ethernet", 0x96767301, 0x71fbbc61),
1733 PCMCIA_DEVICE_PROD_ID12("Ethernet PCMCIA adapter", "EP-210", 0x8dd86181, 0xf2b52517),
1734 PCMCIA_DEVICE_PROD_ID12("Fast Ethernet", "Adapter", 0xb4be14e3, 0x4b0d829e),
1735 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2000", 0x2a151fac, 0xf00555cb),
1736 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2220", 0x2a151fac, 0xc1b7e327),
1737 PCMCIA_DEVICE_PROD_ID12("GVC", "NIC-2000p", 0x76e171bd, 0x6eb1c947),
1738 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "Ethernet", 0xe3736c88, 0x00b2e941),
1739 PCMCIA_DEVICE_PROD_ID12("IC-CARD", "IC-CARD", 0x60cb09a6, 0x60cb09a6),
1740 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCETTX", 0x547e66dc, 0x6fc5459b),
1741 PCMCIA_DEVICE_PROD_ID12("iPort", "10/100 Ethernet Card", 0x56c538d2, 0x11b0ffc0),
1742 PCMCIA_DEVICE_PROD_ID12("KANSAI ELECTRIC CO.,LTD", "KLA-PCM/T", 0xb18dc3b4, 0xcc51a956),
1743 PCMCIA_DEVICE_PROD_ID12("KCI", "PE520 PCMCIA Ethernet Adapter", 0xa89b87d3, 0x1eb88e64),
1744 PCMCIA_DEVICE_PROD_ID12("KINGMAX", "EN10T2T", 0x7bcb459a, 0xa5c81fa5),
1745 PCMCIA_DEVICE_PROD_ID12("Kingston", "KNE-PC2", 0x1128e633, 0xce2a89b3),
1746 PCMCIA_DEVICE_PROD_ID12("Kingston Technology Corp.", "EtheRx PC Card Ethernet Adapter", 0x313c7be3, 0x0afb54a2),
1747 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-10/100CD", 0x1b7827b2, 0xcda71d1c),
1748 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDF", 0x1b7827b2, 0xfec71e40),
1749 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDL/T", 0x1b7827b2, 0x79fba4f7),
1750 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDS", 0x1b7827b2, 0x931afaab),
1751 PCMCIA_DEVICE_PROD_ID12("Linksys", "Combo PCMCIA EthernetCard (EC2T)", 0x0733cc81, 0x32ee8c78),
1752 PCMCIA_DEVICE_PROD_ID12("LINKSYS", "E-CARD", 0xf7cb0b07, 0x6701da11),
1753 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 Integrated PC Card (PCM100)", 0x0733cc81, 0x453c3f9d),
1754 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100)", 0x0733cc81, 0x66c5a389),
1755 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V2)", 0x0733cc81, 0x3a3b28e9),
1756 PCMCIA_DEVICE_PROD_ID12("Linksys", "HomeLink Phoneline ", 0x0733cc81, 0x5e07cfa0),
1757 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737),
1758 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922),
1759 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0),
1760 PCMCIA_DEVICE_PROD_ID12("MACNICA", "ME1-JEIDA", 0x20841b68, 0xaf8a3578),
1761 PCMCIA_DEVICE_PROD_ID12("Macsense", "MPC-10", 0xd830297f, 0xd265c307),
1762 PCMCIA_DEVICE_PROD_ID12("Matsushita Electric Industrial Co.,LTD.", "CF-VEL211", 0x44445376, 0x8ded41d4),
1763 PCMCIA_DEVICE_PROD_ID12("MAXTECH", "PCN2000", 0x78d64bc0, 0xca0ca4b8),
1764 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-T", 0x481e0094, 0xa2eb0cf3),
1765 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-TX", 0x481e0094, 0x41a6916c),
1766 PCMCIA_DEVICE_PROD_ID12("Microcom C.E.", "Travel Card LAN 10/100", 0x4b91cec7, 0xe70220d6),
1767 PCMCIA_DEVICE_PROD_ID12("Microdyne", "NE4200", 0x2e6da59b, 0x0478e472),
1768 PCMCIA_DEVICE_PROD_ID12("MIDORI ELEC.", "LT-PCMT", 0x648d55c1, 0xbde526c7),
1769 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover 4100", 0x36e1191f, 0x60c229b9),
1770 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover NE4100", 0x36e1191f, 0xa6617ec8),
1771 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J12", 0x18df0ba0, 0xbc912d76),
1772 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA410TX", 0x9aa79dc3, 0x60e5bc0e),
1773 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA411", 0x9aa79dc3, 0x40fad875),
1774 PCMCIA_DEVICE_PROD_ID12("Network Everywhere", "Fast Ethernet 10/100 PC Card", 0x820a67b6, 0x31ed1a5f),
1775 PCMCIA_DEVICE_PROD_ID12("NextCom K.K.", "Next Hawk", 0xaedaec74, 0xad050ef1),
1776 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100Mbps Ethernet Card", 0x281f1c5d, 0x6e41773b),
1777 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet", 0x281f1c5d, 0x00b2e941),
1778 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET", 0x281f1c5d, 0x3ff7175b),
1779 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet 10BaseT Card", 0x281f1c5d, 0x4de2f6c8),
1780 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Card", 0x281f1c5d, 0x5e9d92c0),
1781 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Combo card", 0x281f1c5d, 0x929c486c),
1782 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET V1.0", 0x281f1c5d, 0x4d8817c8),
1783 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEthernet", 0x281f1c5d, 0xfe871eeb),
1784 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast-Ethernet", 0x281f1c5d, 0x45f1f3b4),
1785 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FAST ETHERNET CARD", 0x281f1c5d, 0xec5dbca7),
1786 PCMCIA_DEVICE_PROD_ID12("PCMCIA LAN", "Ethernet", 0x7500e246, 0x00b2e941),
1787 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "LNT-10TN", 0x281f1c5d, 0xe707f641),
1788 PCMCIA_DEVICE_PROD_ID12("PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1789 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "UE2212", 0x281f1c5d, 0xbf17199b),
1790 PCMCIA_DEVICE_PROD_ID12("PCMCIA", " Ethernet NE2000 Compatible", 0x281f1c5d, 0x42d5d7e1),
1791 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10baseT 3.3V", 0xebf91155, 0x30074c80),
1792 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10BaseT 3.3V", 0xebf91155, 0x7f5a4f50),
1793 PCMCIA_DEVICE_PROD_ID12("Psion Dacom", "Gold Card Ethernet", 0xf5f025c2, 0x3a30e110),
1794 PCMCIA_DEVICE_PROD_ID12("=RELIA==", "Ethernet", 0xcdd0644a, 0x00b2e941),
1795 PCMCIA_DEVICE_PROD_ID12("RP", "1625B Ethernet NE2000 Compatible", 0xe3e66e22, 0xb96150df),
1796 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP400 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4a7e2ae0),
1797 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP401 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4bcbd7fd),
1798 PCMCIA_DEVICE_PROD_ID12("RPTI LTD.", "EP400", 0xc53ac515, 0x81e39388),
1799 PCMCIA_DEVICE_PROD_ID12("SCM", "Ethernet Combo card", 0xbdc3b102, 0x929c486c),
1800 PCMCIA_DEVICE_PROD_ID12("Seiko Epson Corp.", "Ethernet", 0x09928730, 0x00b2e941),
1801 PCMCIA_DEVICE_PROD_ID12("SMC", "EZCard-10-PCMCIA", 0xc4f8b18b, 0xfb21d265),
1802 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision D", 0xc70a4760, 0x2ade483e),
1803 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision E", 0xc70a4760, 0x5dd978a8),
1804 PCMCIA_DEVICE_PROD_ID12("TDK", "LAK-CD031 for PCMCIA", 0x1eae9475, 0x0ed386fa),
1805 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE450T", 0x466b05f0, 0x8b74bc4f),
1806 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE550T", 0x466b05f0, 0x33c8db2a),
1807 PCMCIA_DEVICE_PROD_ID13("Hypertec", "EP401", 0x8787bec7, 0xf6e4a31e),
1808 PCMCIA_DEVICE_PROD_ID13("KingMax Technology Inc.", "Ethernet Card", 0x932b7189, 0x5e9d92c0),
1809 PCMCIA_DEVICE_PROD_ID13("LONGSHINE", "EP401", 0xf866b0b0, 0xf6e4a31e),
1810 PCMCIA_DEVICE_PROD_ID13("Xircom", "CFE-10", 0x2e3ee845, 0x22a49f89),
1811 PCMCIA_DEVICE_PROD_ID1("CyQ've 10 Base-T LAN CARD", 0x94faf360),
1812 PCMCIA_DEVICE_PROD_ID1("EP-210 PCMCIA LAN CARD.", 0x8850b4de),
1813 PCMCIA_DEVICE_PROD_ID1("ETHER-C16", 0x06a8514f),
1814 PCMCIA_DEVICE_PROD_ID1("IC-CARD", 0x60cb09a6),
1815 PCMCIA_DEVICE_PROD_ID1("NE2000 Compatible", 0x75b8ad5a),
1816 PCMCIA_DEVICE_PROD_ID2("EN-6200P2", 0xa996d078),
1817 /* too generic! */
1818 /* PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100 Ethernet Card", 0x281f1c5d, 0x11b0ffc0), */
1819 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
1820 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
1821 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
1822 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "PCMLM28.cis"),
1823 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "PCMLM28.cis"),
1824 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(0, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "DP83903.cis"),
1825 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(0, "NSC MF LAN/Modem", 0x58fc6056, "DP83903.cis"),
1826 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0175, 0x0000, "DP83903.cis"),
1827 PCMCIA_DEVICE_CIS_MANF_CARD(0xc00f, 0x0002, "LA-PCM.cis"),
1828 PCMCIA_DEVICE_CIS_PROD_ID12("KTI", "PE520 PLUS", 0xad180345, 0x9d58d392, "PE520.cis"),
1829 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "NE2K.cis"),
1830 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "PE-200.cis"),
1831 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "tamarack.cis"),
1832 PCMCIA_DEVICE_NULL
1833};
1834MODULE_DEVICE_TABLE(pcmcia, pcnet_ids);
1835
1638static struct pcmcia_driver pcnet_driver = { 1836static struct pcmcia_driver pcnet_driver = {
1639 .drv = { 1837 .drv = {
1640 .name = "pcnet_cs", 1838 .name = "pcnet_cs",
1641 }, 1839 },
1642 .attach = pcnet_attach, 1840 .attach = pcnet_attach,
1841 .event = pcnet_event,
1643 .detach = pcnet_detach, 1842 .detach = pcnet_detach,
1644 .owner = THIS_MODULE, 1843 .owner = THIS_MODULE,
1844 .id_table = pcnet_ids,
1645}; 1845};
1646 1846
1647static int __init init_pcnet_cs(void) 1847static int __init init_pcnet_cs(void)
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 85a152173148..0d8bb4cccbb7 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -41,8 +41,8 @@
41#include <linux/ioport.h> 41#include <linux/ioport.h>
42#include <linux/ethtool.h> 42#include <linux/ethtool.h>
43#include <linux/mii.h> 43#include <linux/mii.h>
44#include <linux/jiffies.h>
44 45
45#include <pcmcia/version.h>
46#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
47#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
48#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
@@ -127,6 +127,12 @@ struct smc_private {
127 int rx_ovrn; 127 int rx_ovrn;
128}; 128};
129 129
130struct smc_cfg_mem {
131 tuple_t tuple;
132 cisparse_t parse;
133 u_char buf[255];
134};
135
130/* Special definitions for Megahertz multifunction cards */ 136/* Special definitions for Megahertz multifunction cards */
131#define MEGAHERTZ_ISR 0x0380 137#define MEGAHERTZ_ISR 0x0380
132 138
@@ -364,10 +370,6 @@ static dev_link_t *smc91c92_attach(void)
364 link->next = dev_list; 370 link->next = dev_list;
365 dev_list = link; 371 dev_list = link;
366 client_reg.dev_info = &dev_info; 372 client_reg.dev_info = &dev_info;
367 client_reg.EventMask = CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
368 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
369 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
370 client_reg.event_handler = &smc91c92_event;
371 client_reg.Version = 0x0210; 373 client_reg.Version = 0x0210;
372 client_reg.event_callback_args.client_data = link; 374 client_reg.event_callback_args.client_data = link;
373 ret = pcmcia_register_client(&link->handle, &client_reg); 375 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -498,14 +500,24 @@ static int mhz_mfc_config(dev_link_t *link)
498{ 500{
499 struct net_device *dev = link->priv; 501 struct net_device *dev = link->priv;
500 struct smc_private *smc = netdev_priv(dev); 502 struct smc_private *smc = netdev_priv(dev);
501 tuple_t tuple; 503 struct smc_cfg_mem *cfg_mem;
502 cisparse_t parse; 504 tuple_t *tuple;
503 u_char buf[255]; 505 cisparse_t *parse;
504 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 506 cistpl_cftable_entry_t *cf;
507 u_char *buf;
505 win_req_t req; 508 win_req_t req;
506 memreq_t mem; 509 memreq_t mem;
507 int i, k; 510 int i, k;
508 511
512 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
513 if (!cfg_mem)
514 return CS_OUT_OF_RESOURCE;
515
516 tuple = &cfg_mem->tuple;
517 parse = &cfg_mem->parse;
518 cf = &parse->cftable_entry;
519 buf = cfg_mem->buf;
520
509 link->conf.Attributes |= CONF_ENABLE_SPKR; 521 link->conf.Attributes |= CONF_ENABLE_SPKR;
510 link->conf.Status = CCSR_AUDIO_ENA; 522 link->conf.Status = CCSR_AUDIO_ENA;
511 link->irq.Attributes = 523 link->irq.Attributes =
@@ -514,12 +526,12 @@ static int mhz_mfc_config(dev_link_t *link)
514 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 526 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
515 link->io.NumPorts2 = 8; 527 link->io.NumPorts2 = 8;
516 528
517 tuple.Attributes = tuple.TupleOffset = 0; 529 tuple->Attributes = tuple->TupleOffset = 0;
518 tuple.TupleData = (cisdata_t *)buf; 530 tuple->TupleData = (cisdata_t *)buf;
519 tuple.TupleDataMax = sizeof(buf); 531 tuple->TupleDataMax = 255;
520 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 532 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
521 533
522 i = first_tuple(link->handle, &tuple, &parse); 534 i = first_tuple(link->handle, tuple, parse);
523 /* The Megahertz combo cards have modem-like CIS entries, so 535 /* The Megahertz combo cards have modem-like CIS entries, so
524 we have to explicitly try a bunch of port combinations. */ 536 we have to explicitly try a bunch of port combinations. */
525 while (i == CS_SUCCESS) { 537 while (i == CS_SUCCESS) {
@@ -532,10 +544,10 @@ static int mhz_mfc_config(dev_link_t *link)
532 if (i == CS_SUCCESS) break; 544 if (i == CS_SUCCESS) break;
533 } 545 }
534 if (i == CS_SUCCESS) break; 546 if (i == CS_SUCCESS) break;
535 i = next_tuple(link->handle, &tuple, &parse); 547 i = next_tuple(link->handle, tuple, parse);
536 } 548 }
537 if (i != CS_SUCCESS) 549 if (i != CS_SUCCESS)
538 return i; 550 goto free_cfg_mem;
539 dev->base_addr = link->io.BasePort1; 551 dev->base_addr = link->io.BasePort1;
540 552
541 /* Allocate a memory window, for accessing the ISR */ 553 /* Allocate a memory window, for accessing the ISR */
@@ -544,7 +556,7 @@ static int mhz_mfc_config(dev_link_t *link)
544 req.AccessSpeed = 0; 556 req.AccessSpeed = 0;
545 i = pcmcia_request_window(&link->handle, &req, &link->win); 557 i = pcmcia_request_window(&link->handle, &req, &link->win);
546 if (i != CS_SUCCESS) 558 if (i != CS_SUCCESS)
547 return i; 559 goto free_cfg_mem;
548 smc->base = ioremap(req.Base, req.Size); 560 smc->base = ioremap(req.Base, req.Size);
549 mem.CardOffset = mem.Page = 0; 561 mem.CardOffset = mem.Page = 0;
550 if (smc->manfid == MANFID_MOTOROLA) 562 if (smc->manfid == MANFID_MOTOROLA)
@@ -556,6 +568,8 @@ static int mhz_mfc_config(dev_link_t *link)
556 && (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 568 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
557 mhz_3288_power(link); 569 mhz_3288_power(link);
558 570
571free_cfg_mem:
572 kfree(cfg_mem);
559 return i; 573 return i;
560} 574}
561 575
@@ -563,39 +577,61 @@ static int mhz_setup(dev_link_t *link)
563{ 577{
564 client_handle_t handle = link->handle; 578 client_handle_t handle = link->handle;
565 struct net_device *dev = link->priv; 579 struct net_device *dev = link->priv;
566 tuple_t tuple; 580 struct smc_cfg_mem *cfg_mem;
567 cisparse_t parse; 581 tuple_t *tuple;
568 u_char buf[255], *station_addr; 582 cisparse_t *parse;
583 u_char *buf, *station_addr;
584 int rc;
585
586 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
587 if (!cfg_mem)
588 return -1;
589
590 tuple = &cfg_mem->tuple;
591 parse = &cfg_mem->parse;
592 buf = cfg_mem->buf;
569 593
570 tuple.Attributes = tuple.TupleOffset = 0; 594 tuple->Attributes = tuple->TupleOffset = 0;
571 tuple.TupleData = buf; 595 tuple->TupleData = (cisdata_t *)buf;
572 tuple.TupleDataMax = sizeof(buf); 596 tuple->TupleDataMax = 255;
573 597
574 /* Read the station address from the CIS. It is stored as the last 598 /* Read the station address from the CIS. It is stored as the last
575 (fourth) string in the Version 1 Version/ID tuple. */ 599 (fourth) string in the Version 1 Version/ID tuple. */
576 tuple.DesiredTuple = CISTPL_VERS_1; 600 tuple->DesiredTuple = CISTPL_VERS_1;
577 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS) 601 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
578 return -1; 602 rc = -1;
603 goto free_cfg_mem;
604 }
579 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 605 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
580 if (next_tuple(handle, &tuple, &parse) != CS_SUCCESS) 606 if (next_tuple(handle, tuple, parse) != CS_SUCCESS)
581 first_tuple(handle, &tuple, &parse); 607 first_tuple(handle, tuple, parse);
582 if (parse.version_1.ns > 3) { 608 if (parse->version_1.ns > 3) {
583 station_addr = parse.version_1.str + parse.version_1.ofs[3]; 609 station_addr = parse->version_1.str + parse->version_1.ofs[3];
584 if (cvt_ascii_address(dev, station_addr) == 0) 610 if (cvt_ascii_address(dev, station_addr) == 0) {
585 return 0; 611 rc = 0;
612 goto free_cfg_mem;
613 }
586 } 614 }
587 615
588 /* Another possibility: for the EM3288, in a special tuple */ 616 /* Another possibility: for the EM3288, in a special tuple */
589 tuple.DesiredTuple = 0x81; 617 tuple->DesiredTuple = 0x81;
590 if (pcmcia_get_first_tuple(handle, &tuple) != CS_SUCCESS) 618 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) {
591 return -1; 619 rc = -1;
592 if (pcmcia_get_tuple_data(handle, &tuple) != CS_SUCCESS) 620 goto free_cfg_mem;
593 return -1; 621 }
622 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) {
623 rc = -1;
624 goto free_cfg_mem;
625 }
594 buf[12] = '\0'; 626 buf[12] = '\0';
595 if (cvt_ascii_address(dev, buf) == 0) 627 if (cvt_ascii_address(dev, buf) == 0) {
596 return 0; 628 rc = 0;
597 629 goto free_cfg_mem;
598 return -1; 630 }
631 rc = -1;
632free_cfg_mem:
633 kfree(cfg_mem);
634 return rc;
599} 635}
600 636
601/*====================================================================== 637/*======================================================================
@@ -665,19 +701,29 @@ static int mot_setup(dev_link_t *link)
665static int smc_config(dev_link_t *link) 701static int smc_config(dev_link_t *link)
666{ 702{
667 struct net_device *dev = link->priv; 703 struct net_device *dev = link->priv;
668 tuple_t tuple; 704 struct smc_cfg_mem *cfg_mem;
669 cisparse_t parse; 705 tuple_t *tuple;
670 u_char buf[255]; 706 cisparse_t *parse;
671 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 707 cistpl_cftable_entry_t *cf;
708 u_char *buf;
672 int i; 709 int i;
673 710
674 tuple.Attributes = tuple.TupleOffset = 0; 711 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
675 tuple.TupleData = (cisdata_t *)buf; 712 if (!cfg_mem)
676 tuple.TupleDataMax = sizeof(buf); 713 return CS_OUT_OF_RESOURCE;
677 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 714
715 tuple = &cfg_mem->tuple;
716 parse = &cfg_mem->parse;
717 cf = &parse->cftable_entry;
718 buf = cfg_mem->buf;
719
720 tuple->Attributes = tuple->TupleOffset = 0;
721 tuple->TupleData = (cisdata_t *)buf;
722 tuple->TupleDataMax = 255;
723 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
678 724
679 link->io.NumPorts1 = 16; 725 link->io.NumPorts1 = 16;
680 i = first_tuple(link->handle, &tuple, &parse); 726 i = first_tuple(link->handle, tuple, parse);
681 while (i != CS_NO_MORE_ITEMS) { 727 while (i != CS_NO_MORE_ITEMS) {
682 if (i == CS_SUCCESS) { 728 if (i == CS_SUCCESS) {
683 link->conf.ConfigIndex = cf->index; 729 link->conf.ConfigIndex = cf->index;
@@ -686,10 +732,12 @@ static int smc_config(dev_link_t *link)
686 i = pcmcia_request_io(link->handle, &link->io); 732 i = pcmcia_request_io(link->handle, &link->io);
687 if (i == CS_SUCCESS) break; 733 if (i == CS_SUCCESS) break;
688 } 734 }
689 i = next_tuple(link->handle, &tuple, &parse); 735 i = next_tuple(link->handle, tuple, parse);
690 } 736 }
691 if (i == CS_SUCCESS) 737 if (i == CS_SUCCESS)
692 dev->base_addr = link->io.BasePort1; 738 dev->base_addr = link->io.BasePort1;
739
740 kfree(cfg_mem);
693 return i; 741 return i;
694} 742}
695 743
@@ -697,41 +745,58 @@ static int smc_setup(dev_link_t *link)
697{ 745{
698 client_handle_t handle = link->handle; 746 client_handle_t handle = link->handle;
699 struct net_device *dev = link->priv; 747 struct net_device *dev = link->priv;
700 tuple_t tuple; 748 struct smc_cfg_mem *cfg_mem;
701 cisparse_t parse; 749 tuple_t *tuple;
750 cisparse_t *parse;
702 cistpl_lan_node_id_t *node_id; 751 cistpl_lan_node_id_t *node_id;
703 u_char buf[255], *station_addr; 752 u_char *buf, *station_addr;
704 int i; 753 int i, rc;
754
755 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
756 if (!cfg_mem)
757 return CS_OUT_OF_RESOURCE;
705 758
706 tuple.Attributes = tuple.TupleOffset = 0; 759 tuple = &cfg_mem->tuple;
707 tuple.TupleData = buf; 760 parse = &cfg_mem->parse;
708 tuple.TupleDataMax = sizeof(buf); 761 buf = cfg_mem->buf;
762
763 tuple->Attributes = tuple->TupleOffset = 0;
764 tuple->TupleData = (cisdata_t *)buf;
765 tuple->TupleDataMax = 255;
709 766
710 /* Check for a LAN function extension tuple */ 767 /* Check for a LAN function extension tuple */
711 tuple.DesiredTuple = CISTPL_FUNCE; 768 tuple->DesiredTuple = CISTPL_FUNCE;
712 i = first_tuple(handle, &tuple, &parse); 769 i = first_tuple(handle, tuple, parse);
713 while (i == CS_SUCCESS) { 770 while (i == CS_SUCCESS) {
714 if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID) 771 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
715 break; 772 break;
716 i = next_tuple(handle, &tuple, &parse); 773 i = next_tuple(handle, tuple, parse);
717 } 774 }
718 if (i == CS_SUCCESS) { 775 if (i == CS_SUCCESS) {
719 node_id = (cistpl_lan_node_id_t *)parse.funce.data; 776 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
720 if (node_id->nb == 6) { 777 if (node_id->nb == 6) {
721 for (i = 0; i < 6; i++) 778 for (i = 0; i < 6; i++)
722 dev->dev_addr[i] = node_id->id[i]; 779 dev->dev_addr[i] = node_id->id[i];
723 return 0; 780 rc = 0;
781 goto free_cfg_mem;
724 } 782 }
725 } 783 }
726 /* Try the third string in the Version 1 Version/ID tuple. */ 784 /* Try the third string in the Version 1 Version/ID tuple. */
727 tuple.DesiredTuple = CISTPL_VERS_1; 785 tuple->DesiredTuple = CISTPL_VERS_1;
728 if (first_tuple(handle, &tuple, &parse) != CS_SUCCESS) 786 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) {
729 return -1; 787 rc = -1;
730 station_addr = parse.version_1.str + parse.version_1.ofs[2]; 788 goto free_cfg_mem;
731 if (cvt_ascii_address(dev, station_addr) == 0) 789 }
732 return 0; 790 station_addr = parse->version_1.str + parse->version_1.ofs[2];
791 if (cvt_ascii_address(dev, station_addr) == 0) {
792 rc = 0;
793 goto free_cfg_mem;
794 }
733 795
734 return -1; 796 rc = -1;
797free_cfg_mem:
798 kfree(cfg_mem);
799 return rc;
735} 800}
736 801
737/*====================================================================*/ 802/*====================================================================*/
@@ -773,26 +838,36 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
773{ 838{
774 client_handle_t handle = link->handle; 839 client_handle_t handle = link->handle;
775 struct net_device *dev = link->priv; 840 struct net_device *dev = link->priv;
776 tuple_t tuple; 841 struct smc_cfg_mem *cfg_mem;
777 u_char buf[255]; 842 tuple_t *tuple;
778 int i; 843 u_char *buf;
844 int i, rc;
845
846 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
847 if (!cfg_mem)
848 return -1;
849
850 tuple = &cfg_mem->tuple;
851 buf = cfg_mem->buf;
779 852
780 tuple.Attributes = TUPLE_RETURN_COMMON; 853 tuple->Attributes = TUPLE_RETURN_COMMON;
781 tuple.TupleData = buf; 854 tuple->TupleData = (cisdata_t *)buf;
782 tuple.TupleDataMax = sizeof(buf); 855 tuple->TupleDataMax = 255;
783 tuple.TupleOffset = 0; 856 tuple->TupleOffset = 0;
784 857
785 /* Read the station address from tuple 0x90, subtuple 0x04 */ 858 /* Read the station address from tuple 0x90, subtuple 0x04 */
786 tuple.DesiredTuple = 0x90; 859 tuple->DesiredTuple = 0x90;
787 i = pcmcia_get_first_tuple(handle, &tuple); 860 i = pcmcia_get_first_tuple(handle, tuple);
788 while (i == CS_SUCCESS) { 861 while (i == CS_SUCCESS) {
789 i = pcmcia_get_tuple_data(handle, &tuple); 862 i = pcmcia_get_tuple_data(handle, tuple);
790 if ((i != CS_SUCCESS) || (buf[0] == 0x04)) 863 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
791 break; 864 break;
792 i = pcmcia_get_next_tuple(handle, &tuple); 865 i = pcmcia_get_next_tuple(handle, tuple);
866 }
867 if (i != CS_SUCCESS) {
868 rc = -1;
869 goto free_cfg_mem;
793 } 870 }
794 if (i != CS_SUCCESS)
795 return -1;
796 for (i = 0; i < 6; i++) 871 for (i = 0; i < 6; i++)
797 dev->dev_addr[i] = buf[i+2]; 872 dev->dev_addr[i] = buf[i+2];
798 873
@@ -814,8 +889,10 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
814 inw(link->io.BasePort1 + OSITECH_AUI_PWR), 889 inw(link->io.BasePort1 + OSITECH_AUI_PWR),
815 inw(link->io.BasePort1 + OSITECH_RESET_ISR)); 890 inw(link->io.BasePort1 + OSITECH_RESET_ISR));
816 } 891 }
817 892 rc = 0;
818 return 0; 893free_cfg_mem:
894 kfree(cfg_mem);
895 return rc;
819} 896}
820 897
821/*====================================================================== 898/*======================================================================
@@ -887,9 +964,10 @@ static void smc91c92_config(dev_link_t *link)
887 client_handle_t handle = link->handle; 964 client_handle_t handle = link->handle;
888 struct net_device *dev = link->priv; 965 struct net_device *dev = link->priv;
889 struct smc_private *smc = netdev_priv(dev); 966 struct smc_private *smc = netdev_priv(dev);
890 tuple_t tuple; 967 struct smc_cfg_mem *cfg_mem;
891 cisparse_t parse; 968 tuple_t *tuple;
892 u_short buf[32]; 969 cisparse_t *parse;
970 u_char *buf;
893 char *name; 971 char *name;
894 int i, j, rev; 972 int i, j, rev;
895 kio_addr_t ioaddr; 973 kio_addr_t ioaddr;
@@ -897,21 +975,29 @@ static void smc91c92_config(dev_link_t *link)
897 975
898 DEBUG(0, "smc91c92_config(0x%p)\n", link); 976 DEBUG(0, "smc91c92_config(0x%p)\n", link);
899 977
900 tuple.Attributes = tuple.TupleOffset = 0; 978 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
901 tuple.TupleData = (cisdata_t *)buf; 979 if (!cfg_mem)
902 tuple.TupleDataMax = sizeof(buf); 980 goto config_failed;
903 981
904 tuple.DesiredTuple = CISTPL_CONFIG; 982 tuple = &cfg_mem->tuple;
905 i = first_tuple(handle, &tuple, &parse); 983 parse = &cfg_mem->parse;
906 CS_EXIT_TEST(i, ParseTuple, config_failed); 984 buf = cfg_mem->buf;
907 link->conf.ConfigBase = parse.config.base;
908 link->conf.Present = parse.config.rmask[0];
909 985
910 tuple.DesiredTuple = CISTPL_MANFID; 986 tuple->Attributes = tuple->TupleOffset = 0;
911 tuple.Attributes = TUPLE_RETURN_COMMON; 987 tuple->TupleData = (cisdata_t *)buf;
912 if (first_tuple(handle, &tuple, &parse) == CS_SUCCESS) { 988 tuple->TupleDataMax = 64;
913 smc->manfid = parse.manfid.manf; 989
914 smc->cardid = parse.manfid.card; 990 tuple->DesiredTuple = CISTPL_CONFIG;
991 i = first_tuple(handle, tuple, parse);
992 CS_EXIT_TEST(i, ParseTuple, config_failed);
993 link->conf.ConfigBase = parse->config.base;
994 link->conf.Present = parse->config.rmask[0];
995
996 tuple->DesiredTuple = CISTPL_MANFID;
997 tuple->Attributes = TUPLE_RETURN_COMMON;
998 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) {
999 smc->manfid = parse->manfid.manf;
1000 smc->cardid = parse->manfid.card;
915 } 1001 }
916 1002
917 /* Configure card */ 1003 /* Configure card */
@@ -1046,7 +1132,7 @@ static void smc91c92_config(dev_link_t *link)
1046 printk(KERN_NOTICE " No MII transceivers found!\n"); 1132 printk(KERN_NOTICE " No MII transceivers found!\n");
1047 } 1133 }
1048 } 1134 }
1049 1135 kfree(cfg_mem);
1050 return; 1136 return;
1051 1137
1052config_undo: 1138config_undo:
@@ -1054,6 +1140,7 @@ config_undo:
1054config_failed: /* CS_EXIT_TEST() calls jump to here... */ 1140config_failed: /* CS_EXIT_TEST() calls jump to here... */
1055 smc91c92_release(link); 1141 smc91c92_release(link);
1056 link->state &= ~DEV_CONFIG_PENDING; 1142 link->state &= ~DEV_CONFIG_PENDING;
1143 kfree(cfg_mem);
1057 1144
1058} /* smc91c92_config */ 1145} /* smc91c92_config */
1059 1146
@@ -2006,7 +2093,7 @@ static void media_check(u_long arg)
2006 } 2093 }
2007 2094
2008 /* Ignore collisions unless we've had no rx's recently */ 2095 /* Ignore collisions unless we've had no rx's recently */
2009 if (jiffies - dev->last_rx > HZ) { 2096 if (time_after(jiffies, dev->last_rx + HZ)) {
2010 if (smc->tx_err || (smc->media_status & EPH_16COL)) 2097 if (smc->tx_err || (smc->media_status & EPH_16COL))
2011 media |= EPH_16COL; 2098 media |= EPH_16COL;
2012 } 2099 }
@@ -2236,13 +2323,47 @@ static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
2236 return rc; 2323 return rc;
2237} 2324}
2238 2325
2326static struct pcmcia_device_id smc91c92_ids[] = {
2327 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2328 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2329 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2330 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2331 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2332 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2333 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2334 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2335 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2336 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2337 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2338 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2339 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2340 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2341 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2342 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2343 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2344 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2345 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2346 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2347 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
2348 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2349 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2350 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2351 /* These conflict with other cards! */
2352 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2353 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2354 PCMCIA_DEVICE_NULL,
2355};
2356MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2357
2239static struct pcmcia_driver smc91c92_cs_driver = { 2358static struct pcmcia_driver smc91c92_cs_driver = {
2240 .owner = THIS_MODULE, 2359 .owner = THIS_MODULE,
2241 .drv = { 2360 .drv = {
2242 .name = "smc91c92_cs", 2361 .name = "smc91c92_cs",
2243 }, 2362 },
2244 .attach = smc91c92_attach, 2363 .attach = smc91c92_attach,
2364 .event = smc91c92_event,
2245 .detach = smc91c92_detach, 2365 .detach = smc91c92_detach,
2366 .id_table = smc91c92_ids,
2246}; 2367};
2247 2368
2248static int __init init_smc91c92_cs(void) 2369static int __init init_smc91c92_cs(void)
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 58177d67ea12..9f33bad174e9 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -81,7 +81,6 @@
81#include <linux/ioport.h> 81#include <linux/ioport.h>
82#include <linux/bitops.h> 82#include <linux/bitops.h>
83 83
84#include <pcmcia/version.h>
85#include <pcmcia/cs_types.h> 84#include <pcmcia/cs_types.h>
86#include <pcmcia/cs.h> 85#include <pcmcia/cs.h>
87#include <pcmcia/cistpl.h> 86#include <pcmcia/cistpl.h>
@@ -619,11 +618,6 @@ xirc2ps_attach(void)
619 link->next = dev_list; 618 link->next = dev_list;
620 dev_list = link; 619 dev_list = link;
621 client_reg.dev_info = &dev_info; 620 client_reg.dev_info = &dev_info;
622 client_reg.EventMask =
623 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
624 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
625 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
626 client_reg.event_handler = &xirc2ps_event;
627 client_reg.Version = 0x0210; 621 client_reg.Version = 0x0210;
628 client_reg.event_callback_args.client_data = link; 622 client_reg.event_callback_args.client_data = link;
629 if ((err = pcmcia_register_client(&link->handle, &client_reg))) { 623 if ((err = pcmcia_register_client(&link->handle, &client_reg))) {
@@ -1983,13 +1977,42 @@ do_stop(struct net_device *dev)
1983 return 0; 1977 return 0;
1984} 1978}
1985 1979
1980static struct pcmcia_device_id xirc2ps_ids[] = {
1981 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
1982 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
1983 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
1984 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
1985 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
1986 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
1987 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
1988 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2),
1989 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1990 PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
1991 PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
1992 PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
1993 PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
1994 PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
1995 PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
1996 PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
1997 PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
1998 PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
1999 PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
2000 /* also matches CFE-10 cards! */
2001 /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
2002 PCMCIA_DEVICE_NULL,
2003};
2004MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
2005
2006
1986static struct pcmcia_driver xirc2ps_cs_driver = { 2007static struct pcmcia_driver xirc2ps_cs_driver = {
1987 .owner = THIS_MODULE, 2008 .owner = THIS_MODULE,
1988 .drv = { 2009 .drv = {
1989 .name = "xirc2ps_cs", 2010 .name = "xirc2ps_cs",
1990 }, 2011 },
1991 .attach = xirc2ps_attach, 2012 .attach = xirc2ps_attach,
2013 .event = xirc2ps_event,
1992 .detach = xirc2ps_detach, 2014 .detach = xirc2ps_detach,
2015 .id_table = xirc2ps_ids,
1993}; 2016};
1994 2017
1995static int __init 2018static int __init
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 13f114876965..113b68099216 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -850,7 +850,7 @@ static int pcnet32_phys_id(struct net_device *dev, u32 data)
850 if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))) 850 if ((!data) || (data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)))
851 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 851 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
852 852
853 schedule_timeout(data * HZ); 853 msleep_interruptible(data * 1000);
854 del_timer_sync(&lp->blink_timer); 854 del_timer_sync(&lp->blink_timer);
855 855
856 /* Restore the original value of the bcrs */ 856 /* Restore the original value of the bcrs */
@@ -1602,7 +1602,7 @@ pcnet32_init_ring(struct net_device *dev)
1602 1602
1603 rmb(); 1603 rmb();
1604 if (lp->rx_dma_addr[i] == 0) 1604 if (lp->rx_dma_addr[i] == 0)
1605 lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->tail, 1605 lp->rx_dma_addr[i] = pci_map_single(lp->pci_dev, rx_skbuff->data,
1606 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); 1606 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
1607 lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]); 1607 lp->rx_ring[i].base = (u32)le32_to_cpu(lp->rx_dma_addr[i]);
1608 lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ); 1608 lp->rx_ring[i].buf_length = le16_to_cpu(2-PKT_BUF_SZ);
@@ -1983,7 +1983,7 @@ pcnet32_rx(struct net_device *dev)
1983 lp->rx_skbuff[entry] = newskb; 1983 lp->rx_skbuff[entry] = newskb;
1984 newskb->dev = dev; 1984 newskb->dev = dev;
1985 lp->rx_dma_addr[entry] = 1985 lp->rx_dma_addr[entry] =
1986 pci_map_single(lp->pci_dev, newskb->tail, 1986 pci_map_single(lp->pci_dev, newskb->data,
1987 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE); 1987 PKT_BUF_SZ-2, PCI_DMA_FROMDEVICE);
1988 lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]); 1988 lp->rx_ring[entry].base = le32_to_cpu(lp->rx_dma_addr[entry]);
1989 rx_in_place = 1; 1989 rx_in_place = 1;
@@ -2020,7 +2020,7 @@ pcnet32_rx(struct net_device *dev)
2020 PKT_BUF_SZ-2, 2020 PKT_BUF_SZ-2,
2021 PCI_DMA_FROMDEVICE); 2021 PCI_DMA_FROMDEVICE);
2022 eth_copy_and_sum(skb, 2022 eth_copy_and_sum(skb,
2023 (unsigned char *)(lp->rx_skbuff[entry]->tail), 2023 (unsigned char *)(lp->rx_skbuff[entry]->data),
2024 pkt_len,0); 2024 pkt_len,0);
2025 pci_dma_sync_single_for_device(lp->pci_dev, 2025 pci_dma_sync_single_for_device(lp->pci_dev,
2026 lp->rx_dma_addr[entry], 2026 lp->rx_dma_addr[entry],
diff --git a/drivers/net/plip.c b/drivers/net/plip.c
index f4b62405d2e5..21537ee3a6a7 100644
--- a/drivers/net/plip.c
+++ b/drivers/net/plip.c
@@ -540,7 +540,7 @@ plip_receive(unsigned short nibble_timeout, struct net_device *dev,
540 * in far too many old systems not all even running Linux. 540 * in far too many old systems not all even running Linux.
541 */ 541 */
542 542
543static unsigned short plip_type_trans(struct sk_buff *skb, struct net_device *dev) 543static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
544{ 544{
545 struct ethhdr *eth; 545 struct ethhdr *eth;
546 unsigned char *rawp; 546 unsigned char *rawp;
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c
index 5e48b9ab3045..59e8183c639e 100644
--- a/drivers/net/ppp_async.c
+++ b/drivers/net/ppp_async.c
@@ -364,7 +364,7 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
364 spin_lock_irqsave(&ap->recv_lock, flags); 364 spin_lock_irqsave(&ap->recv_lock, flags);
365 ppp_async_input(ap, buf, cflags, count); 365 ppp_async_input(ap, buf, cflags, count);
366 spin_unlock_irqrestore(&ap->recv_lock, flags); 366 spin_unlock_irqrestore(&ap->recv_lock, flags);
367 if (skb_queue_len(&ap->rqueue)) 367 if (!skb_queue_empty(&ap->rqueue))
368 tasklet_schedule(&ap->tsk); 368 tasklet_schedule(&ap->tsk);
369 ap_put(ap); 369 ap_put(ap);
370 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 370 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags)
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index ab726ab43798..a32668e88e09 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1237,8 +1237,8 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1237 pch = list_entry(list, struct channel, clist); 1237 pch = list_entry(list, struct channel, clist);
1238 navail += pch->avail = (pch->chan != NULL); 1238 navail += pch->avail = (pch->chan != NULL);
1239 if (pch->avail) { 1239 if (pch->avail) {
1240 if (skb_queue_len(&pch->file.xq) == 0 1240 if (skb_queue_empty(&pch->file.xq) ||
1241 || !pch->had_frag) { 1241 !pch->had_frag) {
1242 pch->avail = 2; 1242 pch->avail = 2;
1243 ++nfree; 1243 ++nfree;
1244 } 1244 }
@@ -1374,8 +1374,8 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1374 1374
1375 /* try to send it down the channel */ 1375 /* try to send it down the channel */
1376 chan = pch->chan; 1376 chan = pch->chan;
1377 if (skb_queue_len(&pch->file.xq) 1377 if (!skb_queue_empty(&pch->file.xq) ||
1378 || !chan->ops->start_xmit(chan, frag)) 1378 !chan->ops->start_xmit(chan, frag))
1379 skb_queue_tail(&pch->file.xq, frag); 1379 skb_queue_tail(&pch->file.xq, frag);
1380 pch->had_frag = 1; 1380 pch->had_frag = 1;
1381 p += flen; 1381 p += flen;
@@ -1412,7 +1412,7 @@ ppp_channel_push(struct channel *pch)
1412 1412
1413 spin_lock_bh(&pch->downl); 1413 spin_lock_bh(&pch->downl);
1414 if (pch->chan != 0) { 1414 if (pch->chan != 0) {
1415 while (skb_queue_len(&pch->file.xq) > 0) { 1415 while (!skb_queue_empty(&pch->file.xq)) {
1416 skb = skb_dequeue(&pch->file.xq); 1416 skb = skb_dequeue(&pch->file.xq);
1417 if (!pch->chan->ops->start_xmit(pch->chan, skb)) { 1417 if (!pch->chan->ops->start_xmit(pch->chan, skb)) {
1418 /* put the packet back and try again later */ 1418 /* put the packet back and try again later */
@@ -1426,7 +1426,7 @@ ppp_channel_push(struct channel *pch)
1426 } 1426 }
1427 spin_unlock_bh(&pch->downl); 1427 spin_unlock_bh(&pch->downl);
1428 /* see if there is anything from the attached unit to be sent */ 1428 /* see if there is anything from the attached unit to be sent */
1429 if (skb_queue_len(&pch->file.xq) == 0) { 1429 if (skb_queue_empty(&pch->file.xq)) {
1430 read_lock_bh(&pch->upl); 1430 read_lock_bh(&pch->upl);
1431 ppp = pch->ppp; 1431 ppp = pch->ppp;
1432 if (ppp != 0) 1432 if (ppp != 0)
diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index fd9f50180355..4d51c0c8023d 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -406,7 +406,7 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
406 spin_lock_irqsave(&ap->recv_lock, flags); 406 spin_lock_irqsave(&ap->recv_lock, flags);
407 ppp_sync_input(ap, buf, cflags, count); 407 ppp_sync_input(ap, buf, cflags, count);
408 spin_unlock_irqrestore(&ap->recv_lock, flags); 408 spin_unlock_irqrestore(&ap->recv_lock, flags);
409 if (skb_queue_len(&ap->rqueue)) 409 if (!skb_queue_empty(&ap->rqueue))
410 tasklet_schedule(&ap->tsk); 410 tasklet_schedule(&ap->tsk);
411 sp_put(ap); 411 sp_put(ap);
412 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 412 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index ce449fe90e6d..d5afe05cd826 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1876,7 +1876,7 @@ static int rtl8169_alloc_rx_skb(struct pci_dev *pdev, struct sk_buff **sk_buff,
1876 skb_reserve(skb, NET_IP_ALIGN); 1876 skb_reserve(skb, NET_IP_ALIGN);
1877 *sk_buff = skb; 1877 *sk_buff = skb;
1878 1878
1879 mapping = pci_map_single(pdev, skb->tail, rx_buf_sz, 1879 mapping = pci_map_single(pdev, skb->data, rx_buf_sz,
1880 PCI_DMA_FROMDEVICE); 1880 PCI_DMA_FROMDEVICE);
1881 1881
1882 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); 1882 rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
@@ -2336,7 +2336,7 @@ static inline int rtl8169_try_rx_copy(struct sk_buff **sk_buff, int pkt_size,
2336 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); 2336 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
2337 if (skb) { 2337 if (skb) {
2338 skb_reserve(skb, NET_IP_ALIGN); 2338 skb_reserve(skb, NET_IP_ALIGN);
2339 eth_copy_and_sum(skb, sk_buff[0]->tail, pkt_size, 0); 2339 eth_copy_and_sum(skb, sk_buff[0]->data, pkt_size, 0);
2340 *sk_buff = skb; 2340 *sk_buff = skb;
2341 rtl8169_mark_to_asic(desc, rx_buf_sz); 2341 rtl8169_mark_to_asic(desc, rx_buf_sz);
2342 ret = 0; 2342 ret = 0;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 9c224eba057d..ea638b162d3f 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -42,6 +42,7 @@
42#include <linux/errno.h> 42#include <linux/errno.h>
43#include <linux/ioport.h> 43#include <linux/ioport.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/dma-mapping.h>
45#include <linux/kernel.h> 46#include <linux/kernel.h>
46#include <linux/netdevice.h> 47#include <linux/netdevice.h>
47#include <linux/etherdevice.h> 48#include <linux/etherdevice.h>
@@ -1698,11 +1699,9 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
1698#else 1699#else
1699 ba = &nic->ba[ring_no][block_no][off]; 1700 ba = &nic->ba[ring_no][block_no][off];
1700 skb_reserve(skb, BUF0_LEN); 1701 skb_reserve(skb, BUF0_LEN);
1701 tmp = (unsigned long) skb->data; 1702 tmp = ((unsigned long) skb->data & ALIGN_SIZE);
1702 tmp += ALIGN_SIZE; 1703 if (tmp)
1703 tmp &= ~ALIGN_SIZE; 1704 skb_reserve(skb, (ALIGN_SIZE + 1) - tmp);
1704 skb->data = (void *) tmp;
1705 skb->tail = (void *) tmp;
1706 1705
1707 memset(rxdp, 0, sizeof(RxD_t)); 1706 memset(rxdp, 0, sizeof(RxD_t));
1708 rxdp->Buffer2_ptr = pci_map_single 1707 rxdp->Buffer2_ptr = pci_map_single
@@ -4593,19 +4592,19 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
4593 return ret; 4592 return ret;
4594 } 4593 }
4595 4594
4596 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) { 4595 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
4597 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n"); 4596 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
4598 dma_flag = TRUE; 4597 dma_flag = TRUE;
4599 4598
4600 if (pci_set_consistent_dma_mask 4599 if (pci_set_consistent_dma_mask
4601 (pdev, 0xffffffffffffffffULL)) { 4600 (pdev, DMA_64BIT_MASK)) {
4602 DBG_PRINT(ERR_DBG, 4601 DBG_PRINT(ERR_DBG,
4603 "Unable to obtain 64bit DMA for \ 4602 "Unable to obtain 64bit DMA for \
4604 consistent allocations\n"); 4603 consistent allocations\n");
4605 pci_disable_device(pdev); 4604 pci_disable_device(pdev);
4606 return -ENOMEM; 4605 return -ENOMEM;
4607 } 4606 }
4608 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) { 4607 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
4609 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n"); 4608 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
4610 } else { 4609 } else {
4611 pci_disable_device(pdev); 4610 pci_disable_device(pdev);
diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c
index e15369c8d165..d6388e1533f0 100644
--- a/drivers/net/sb1000.c
+++ b/drivers/net/sb1000.c
@@ -90,7 +90,6 @@ static int sb1000_close(struct net_device *dev);
90 90
91 91
92/* SB1000 hardware routines to be used during open/configuration phases */ 92/* SB1000 hardware routines to be used during open/configuration phases */
93static inline void nicedelay(unsigned long usecs);
94static inline int card_wait_for_busy_clear(const int ioaddr[], 93static inline int card_wait_for_busy_clear(const int ioaddr[],
95 const char* name); 94 const char* name);
96static inline int card_wait_for_ready(const int ioaddr[], const char* name, 95static inline int card_wait_for_ready(const int ioaddr[], const char* name,
@@ -254,13 +253,6 @@ static struct pnp_driver sb1000_driver = {
254 253
255static const int TimeOutJiffies = (875 * HZ) / 100; 254static const int TimeOutJiffies = (875 * HZ) / 100;
256 255
257static inline void nicedelay(unsigned long usecs)
258{
259 current->state = TASK_INTERRUPTIBLE;
260 schedule_timeout(HZ);
261 return;
262}
263
264/* Card Wait For Busy Clear (cannot be used during an interrupt) */ 256/* Card Wait For Busy Clear (cannot be used during an interrupt) */
265static inline int 257static inline int
266card_wait_for_busy_clear(const int ioaddr[], const char* name) 258card_wait_for_busy_clear(const int ioaddr[], const char* name)
@@ -475,7 +467,7 @@ sb1000_reset(const int ioaddr[], const char* name)
475 udelay(1000); 467 udelay(1000);
476 outb(0x0, port); 468 outb(0x0, port);
477 inb(port); 469 inb(port);
478 nicedelay(60000); 470 ssleep(1);
479 outb(0x4, port); 471 outb(0x4, port);
480 inb(port); 472 inb(port);
481 udelay(1000); 473 udelay(1000);
@@ -537,7 +529,7 @@ sb1000_activate(const int ioaddr[], const char* name)
537 const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00}; 529 const unsigned char Command0[6] = {0x80, 0x11, 0x00, 0x00, 0x00, 0x00};
538 const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00}; 530 const unsigned char Command1[6] = {0x80, 0x16, 0x00, 0x00, 0x00, 0x00};
539 531
540 nicedelay(50000); 532 ssleep(1);
541 if ((status = card_send_command(ioaddr, name, Command0, st))) 533 if ((status = card_send_command(ioaddr, name, Command0, st)))
542 return status; 534 return status;
543 if ((status = card_send_command(ioaddr, name, Command1, st))) 535 if ((status = card_send_command(ioaddr, name, Command1, st)))
@@ -944,7 +936,7 @@ sb1000_open(struct net_device *dev)
944 /* initialize sb1000 */ 936 /* initialize sb1000 */
945 if ((status = sb1000_reset(ioaddr, name))) 937 if ((status = sb1000_reset(ioaddr, name)))
946 return status; 938 return status;
947 nicedelay(200000); 939 ssleep(1);
948 if ((status = sb1000_check_CRC(ioaddr, name))) 940 if ((status = sb1000_check_CRC(ioaddr, name)))
949 return status; 941 return status;
950 942
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index fd2e7c374906..7abd55a4fb21 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -963,11 +963,11 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
963 /* 963 /*
964 * Do not interrupt per DMA transfer. 964 * Do not interrupt per DMA transfer.
965 */ 965 */
966 dsc->dscr_a = virt_to_phys(sb_new->tail) | 966 dsc->dscr_a = virt_to_phys(sb_new->data) |
967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
968 0; 968 0;
969#else 969#else
970 dsc->dscr_a = virt_to_phys(sb_new->tail) | 970 dsc->dscr_a = virt_to_phys(sb_new->data) |
971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
972 M_DMA_DSCRA_INTERRUPT; 972 M_DMA_DSCRA_INTERRUPT;
973#endif 973#endif
diff --git a/drivers/net/shaper.c b/drivers/net/shaper.c
index 20edeb345792..3ad0b6751f6f 100644
--- a/drivers/net/shaper.c
+++ b/drivers/net/shaper.c
@@ -135,10 +135,8 @@ static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
135{ 135{
136 struct shaper *shaper = dev->priv; 136 struct shaper *shaper = dev->priv;
137 struct sk_buff *ptr; 137 struct sk_buff *ptr;
138 138
139 if (down_trylock(&shaper->sem)) 139 spin_lock(&shaper->lock);
140 return -1;
141
142 ptr=shaper->sendq.prev; 140 ptr=shaper->sendq.prev;
143 141
144 /* 142 /*
@@ -232,7 +230,7 @@ static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
232 shaper->stats.collisions++; 230 shaper->stats.collisions++;
233 } 231 }
234 shaper_kick(shaper); 232 shaper_kick(shaper);
235 up(&shaper->sem); 233 spin_unlock(&shaper->lock);
236 return 0; 234 return 0;
237} 235}
238 236
@@ -271,11 +269,9 @@ static void shaper_timer(unsigned long data)
271{ 269{
272 struct shaper *shaper = (struct shaper *)data; 270 struct shaper *shaper = (struct shaper *)data;
273 271
274 if (!down_trylock(&shaper->sem)) { 272 spin_lock(&shaper->lock);
275 shaper_kick(shaper); 273 shaper_kick(shaper);
276 up(&shaper->sem); 274 spin_unlock(&shaper->lock);
277 } else
278 mod_timer(&shaper->timer, jiffies);
279} 275}
280 276
281/* 277/*
@@ -332,21 +328,6 @@ static void shaper_kick(struct shaper *shaper)
332 328
333 329
334/* 330/*
335 * Flush the shaper queues on a closedown
336 */
337
338static void shaper_flush(struct shaper *shaper)
339{
340 struct sk_buff *skb;
341
342 down(&shaper->sem);
343 while((skb=skb_dequeue(&shaper->sendq))!=NULL)
344 dev_kfree_skb(skb);
345 shaper_kick(shaper);
346 up(&shaper->sem);
347}
348
349/*
350 * Bring the interface up. We just disallow this until a 331 * Bring the interface up. We just disallow this until a
351 * bind. 332 * bind.
352 */ 333 */
@@ -375,7 +356,15 @@ static int shaper_open(struct net_device *dev)
375static int shaper_close(struct net_device *dev) 356static int shaper_close(struct net_device *dev)
376{ 357{
377 struct shaper *shaper=dev->priv; 358 struct shaper *shaper=dev->priv;
378 shaper_flush(shaper); 359 struct sk_buff *skb;
360
361 while ((skb = skb_dequeue(&shaper->sendq)) != NULL)
362 dev_kfree_skb(skb);
363
364 spin_lock_bh(&shaper->lock);
365 shaper_kick(shaper);
366 spin_unlock_bh(&shaper->lock);
367
379 del_timer_sync(&shaper->timer); 368 del_timer_sync(&shaper->timer);
380 return 0; 369 return 0;
381} 370}
@@ -576,6 +565,7 @@ static void shaper_init_priv(struct net_device *dev)
576 init_timer(&sh->timer); 565 init_timer(&sh->timer);
577 sh->timer.function=shaper_timer; 566 sh->timer.function=shaper_timer;
578 sh->timer.data=(unsigned long)sh; 567 sh->timer.data=(unsigned long)sh;
568 spin_lock_init(&sh->lock);
579} 569}
580 570
581/* 571/*
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index 3107aed0fb51..23b713c700b3 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -66,6 +66,7 @@
66#include <linux/ethtool.h> 66#include <linux/ethtool.h>
67#include <linux/crc32.h> 67#include <linux/crc32.h>
68#include <linux/bitops.h> 68#include <linux/bitops.h>
69#include <linux/dma-mapping.h>
69 70
70#include <asm/processor.h> /* Processor type for cache alignment. */ 71#include <asm/processor.h> /* Processor type for cache alignment. */
71#include <asm/io.h> 72#include <asm/io.h>
@@ -93,8 +94,6 @@ static int sis900_debug = -1; /* Use SIS900_DEF_MSG as value */
93 94
94/* Time in jiffies before concluding the transmitter is hung. */ 95/* Time in jiffies before concluding the transmitter is hung. */
95#define TX_TIMEOUT (4*HZ) 96#define TX_TIMEOUT (4*HZ)
96/* SiS 900 is capable of 32 bits BM DMA */
97#define SIS900_DMA_MASK 0xffffffff
98 97
99enum { 98enum {
100 SIS_900 = 0, 99 SIS_900 = 0,
@@ -414,7 +413,7 @@ static int __devinit sis900_probe(struct pci_dev *pci_dev,
414 ret = pci_enable_device(pci_dev); 413 ret = pci_enable_device(pci_dev);
415 if(ret) return ret; 414 if(ret) return ret;
416 415
417 i = pci_set_dma_mask(pci_dev, SIS900_DMA_MASK); 416 i = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
418 if(i){ 417 if(i){
419 printk(KERN_ERR "sis900.c: architecture does not support" 418 printk(KERN_ERR "sis900.c: architecture does not support"
420 "32bit PCI busmaster DMA\n"); 419 "32bit PCI busmaster DMA\n");
@@ -1155,7 +1154,7 @@ sis900_init_rx_ring(struct net_device *net_dev)
1155 sis_priv->rx_skbuff[i] = skb; 1154 sis_priv->rx_skbuff[i] = skb;
1156 sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE; 1155 sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE;
1157 sis_priv->rx_ring[i].bufptr = pci_map_single(sis_priv->pci_dev, 1156 sis_priv->rx_ring[i].bufptr = pci_map_single(sis_priv->pci_dev,
1158 skb->tail, RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1157 skb->data, RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1159 } 1158 }
1160 sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC); 1159 sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC);
1161 1160
@@ -1777,7 +1776,7 @@ static int sis900_rx(struct net_device *net_dev)
1777 sis_priv->rx_skbuff[entry] = skb; 1776 sis_priv->rx_skbuff[entry] = skb;
1778 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE; 1777 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
1779 sis_priv->rx_ring[entry].bufptr = 1778 sis_priv->rx_ring[entry].bufptr =
1780 pci_map_single(sis_priv->pci_dev, skb->tail, 1779 pci_map_single(sis_priv->pci_dev, skb->data,
1781 RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1780 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1782 sis_priv->dirty_rx++; 1781 sis_priv->dirty_rx++;
1783 } 1782 }
@@ -1810,7 +1809,7 @@ static int sis900_rx(struct net_device *net_dev)
1810 sis_priv->rx_skbuff[entry] = skb; 1809 sis_priv->rx_skbuff[entry] = skb;
1811 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE; 1810 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
1812 sis_priv->rx_ring[entry].bufptr = 1811 sis_priv->rx_ring[entry].bufptr =
1813 pci_map_single(sis_priv->pci_dev, skb->tail, 1812 pci_map_single(sis_priv->pci_dev, skb->data,
1814 RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 1813 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
1815 } 1814 }
1816 } 1815 }
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 1ccb2989001c..82570ec44d8e 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -112,6 +112,7 @@
112#include <linux/moduleparam.h> 112#include <linux/moduleparam.h>
113#include <linux/init.h> 113#include <linux/init.h>
114#include <linux/proc_fs.h> 114#include <linux/proc_fs.h>
115#include <linux/dma-mapping.h>
115 116
116#include "h/skdrv1st.h" 117#include "h/skdrv1st.h"
117#include "h/skdrv2nd.h" 118#include "h/skdrv2nd.h"
@@ -4912,8 +4913,8 @@ static int __devinit skge_probe_one(struct pci_dev *pdev,
4912 goto out; 4913 goto out;
4913 4914
4914 /* Configure DMA attributes. */ 4915 /* Configure DMA attributes. */
4915 if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) && 4916 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4916 pci_set_dma_mask(pdev, (u64) 0xffffffff)) 4917 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
4917 goto out_disable_device; 4918 goto out_disable_device;
4918 4919
4919 4920
diff --git a/drivers/net/skfp/Makefile b/drivers/net/skfp/Makefile
index 6cfccfb7889f..cb23580fcffa 100644
--- a/drivers/net/skfp/Makefile
+++ b/drivers/net/skfp/Makefile
@@ -6,8 +6,8 @@ obj-$(CONFIG_SKFP) += skfp.o
6 6
7skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \ 7skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \
8 ecm.o pcmplc.o pmf.o queue.o rmt.o \ 8 ecm.o pcmplc.o pmf.o queue.o rmt.o \
9 smtdef.o smtinit.o smttimer.o srf.o lnkstat.o \ 9 smtdef.o smtinit.o smttimer.o srf.o hwt.o \
10 smtparse.o hwt.o drvfbi.o ess.o 10 drvfbi.o ess.o
11 11
12# NOTE: 12# NOTE:
13# Compiling this driver produces some warnings (and some more are 13# Compiling this driver produces some warnings (and some more are
diff --git a/drivers/net/skfp/drvfbi.c b/drivers/net/skfp/drvfbi.c
index 052e841ba187..5b475833f645 100644
--- a/drivers/net/skfp/drvfbi.c
+++ b/drivers/net/skfp/drvfbi.c
@@ -105,8 +105,8 @@ extern int AIX_vpdReadByte() ;
105#endif 105#endif
106 106
107 107
108/* Prototypes of local functions. */ 108/* Prototype of a local function. */
109void smt_stop_watchdog(struct s_smc *smc); 109static void smt_stop_watchdog(struct s_smc *smc);
110 110
111#ifdef MCA 111#ifdef MCA
112static int read_card_id() ; 112static int read_card_id() ;
@@ -631,7 +631,7 @@ void plc_clear_irq(struct s_smc *smc, int p)
631 * LED_Y_OFF just switch yellow LED off 631 * LED_Y_OFF just switch yellow LED off
632 * LED_Y_ON just switch yello LED on 632 * LED_Y_ON just switch yello LED on
633 */ 633 */
634void led_indication(struct s_smc *smc, int led_event) 634static void led_indication(struct s_smc *smc, int led_event)
635{ 635{
636 /* use smc->hw.mac_ring_is_up == TRUE 636 /* use smc->hw.mac_ring_is_up == TRUE
637 * as indication for Ring Operational 637 * as indication for Ring Operational
@@ -764,122 +764,6 @@ void llc_recover_tx(struct s_smc *smc)
764#endif 764#endif
765} 765}
766 766
767/*--------------------------- DMA init ----------------------------*/
768#ifdef ISA
769
770/*
771 * init DMA
772 */
773void init_dma(struct s_smc *smc, int dma)
774{
775 SK_UNUSED(smc) ;
776
777 /*
778 * set cascade mode,
779 * clear mask bit (enable DMA cannal)
780 */
781 if (dma > 3) {
782 outp(0xd6,(dma & 0x03) | 0xc0) ;
783 outp(0xd4, dma & 0x03) ;
784 }
785 else {
786 outp(0x0b,(dma & 0x03) | 0xc0) ;
787 outp(0x0a,dma & 0x03) ;
788 }
789}
790
791/*
792 * disable DMA
793 */
794void dis_dma(struct s_smc *smc, int dma)
795{
796 SK_UNUSED(smc) ;
797
798 /*
799 * set mask bit (disable DMA cannal)
800 */
801 if (dma > 3) {
802 outp(0xd4,(dma & 0x03) | 0x04) ;
803 }
804 else {
805 outp(0x0a,(dma & 0x03) | 0x04) ;
806 }
807}
808
809#endif /* ISA */
810
811#ifdef EISA
812
813/*arrays with io addresses of dma controller length and address registers*/
814static const int cntr[8] = { 0x001,0x003,0x005,0x007,0,0x0c6,0x0ca,0x0ce } ;
815static const int base[8] = { 0x000,0x002,0x004,0x006,0,0x0c4,0x0c8,0x0cc } ;
816static const int page[8] = { 0x087,0x083,0x081,0x082,0,0x08b,0x089,0x08a } ;
817
818void init_dma(struct s_smc *smc, int dma)
819{
820 /*
821 * extended mode register
822 * 32 bit IO
823 * type c
824 * TC output
825 * disable stop
826 */
827
828 /* mode read (write) demand */
829 smc->hw.dma_rmode = (dma & 3) | 0x08 | 0x0 ;
830 smc->hw.dma_wmode = (dma & 3) | 0x04 | 0x0 ;
831
832 /* 32 bit IO's, burst DMA mode (type "C") */
833 smc->hw.dma_emode = (dma & 3) | 0x08 | 0x30 ;
834
835 outp((dma < 4) ? 0x40b : 0x4d6,smc->hw.dma_emode) ;
836
837 /* disable chaining */
838 outp((dma < 4) ? 0x40a : 0x4d4,(dma&3)) ;
839
840 /*load dma controller addresses for fast access during set dma*/
841 smc->hw.dma_base_word_count = cntr[smc->hw.dma];
842 smc->hw.dma_base_address = base[smc->hw.dma];
843 smc->hw.dma_base_address_page = page[smc->hw.dma];
844
845}
846
847void dis_dma(struct s_smc *smc, int dma)
848{
849 SK_UNUSED(smc) ;
850
851 outp((dma < 4) ? 0x0a : 0xd4,(dma&3)|4) ;/* mask bit */
852}
853#endif /* EISA */
854
855#ifdef MCA
856void init_dma(struct s_smc *smc, int dma)
857{
858 SK_UNUSED(smc) ;
859 SK_UNUSED(dma) ;
860}
861
862void dis_dma(struct s_smc *smc, int dma)
863{
864 SK_UNUSED(smc) ;
865 SK_UNUSED(dma) ;
866}
867#endif
868
869#ifdef PCI
870void init_dma(struct s_smc *smc, int dma)
871{
872 SK_UNUSED(smc) ;
873 SK_UNUSED(dma) ;
874}
875
876void dis_dma(struct s_smc *smc, int dma)
877{
878 SK_UNUSED(smc) ;
879 SK_UNUSED(dma) ;
880}
881#endif
882
883#ifdef MULT_OEM 767#ifdef MULT_OEM
884static int is_equal_num(char comp1[], char comp2[], int num) 768static int is_equal_num(char comp1[], char comp2[], int num)
885{ 769{
@@ -1407,7 +1291,7 @@ void smt_start_watchdog(struct s_smc *smc)
1407#endif /* DEBUG */ 1291#endif /* DEBUG */
1408} 1292}
1409 1293
1410void smt_stop_watchdog(struct s_smc *smc) 1294static void smt_stop_watchdog(struct s_smc *smc)
1411{ 1295{
1412 SK_UNUSED(smc) ; /* Make LINT happy. */ 1296 SK_UNUSED(smc) ; /* Make LINT happy. */
1413#ifndef DEBUG 1297#ifndef DEBUG
@@ -1422,104 +1306,6 @@ void smt_stop_watchdog(struct s_smc *smc)
1422} 1306}
1423 1307
1424#ifdef PCI 1308#ifdef PCI
1425static char get_rom_byte(struct s_smc *smc, u_short addr)
1426{
1427 GET_PAGE(addr) ;
1428 return (READ_PROM(ADDR(B2_FDP))) ;
1429}
1430
1431/*
1432 * ROM image defines
1433 */
1434#define ROM_SIG_1 0
1435#define ROM_SIG_2 1
1436#define PCI_DATA_1 0x18
1437#define PCI_DATA_2 0x19
1438
1439/*
1440 * PCI data structure defines
1441 */
1442#define VPD_DATA_1 0x08
1443#define VPD_DATA_2 0x09
1444#define IMAGE_LEN_1 0x10
1445#define IMAGE_LEN_2 0x11
1446#define CODE_TYPE 0x14
1447#define INDICATOR 0x15
1448
1449/*
1450 * BEGIN_MANUAL_ENTRY(mac_drv_vpd_read)
1451 * mac_drv_vpd_read(smc,buf,size,image)
1452 *
1453 * function DOWNCALL (FDDIWARE)
1454 * reads the VPD data of the FPROM and writes it into the
1455 * buffer
1456 *
1457 * para buf points to the buffer for the VPD data
1458 * size size of the VPD data buffer
1459 * image boot image; code type of the boot image
1460 * image = 0 Intel x86, PC-AT compatible
1461 * 1 OPENBOOT standard for PCI
1462 * 2-FF reserved
1463 *
1464 * returns len number of VPD data bytes read form the FPROM
1465 * <0 number of read bytes
1466 * >0 error: data invalid
1467 *
1468 * END_MANUAL_ENTRY
1469 */
1470int mac_drv_vpd_read(struct s_smc *smc, char *buf, int size, char image)
1471{
1472 u_short ibase ;
1473 u_short pci_base ;
1474 u_short vpd ;
1475 int len ;
1476
1477 len = 0 ;
1478 ibase = 0 ;
1479 /*
1480 * as long images defined
1481 */
1482 while (get_rom_byte(smc,ibase+ROM_SIG_1) == 0x55 &&
1483 (u_char) get_rom_byte(smc,ibase+ROM_SIG_2) == 0xaa) {
1484 /*
1485 * get the pointer to the PCI data structure
1486 */
1487 pci_base = ibase + get_rom_byte(smc,ibase+PCI_DATA_1) +
1488 (get_rom_byte(smc,ibase+PCI_DATA_2) << 8) ;
1489
1490 if (image == get_rom_byte(smc,pci_base+CODE_TYPE)) {
1491 /*
1492 * we have the right image, read the VPD data
1493 */
1494 vpd = ibase + get_rom_byte(smc,pci_base+VPD_DATA_1) +
1495 (get_rom_byte(smc,pci_base+VPD_DATA_2) << 8) ;
1496 if (vpd == ibase) {
1497 break ; /* no VPD data */
1498 }
1499 for (len = 0; len < size; len++,buf++,vpd++) {
1500 *buf = get_rom_byte(smc,vpd) ;
1501 }
1502 break ;
1503 }
1504 else {
1505 /*
1506 * try the next image
1507 */
1508 if (get_rom_byte(smc,pci_base+INDICATOR) & 0x80) {
1509 break ; /* this was the last image */
1510 }
1511 ibase = ibase + get_rom_byte(smc,ibase+IMAGE_LEN_1) +
1512 (get_rom_byte(smc,ibase+IMAGE_LEN_2) << 8) ;
1513 }
1514 }
1515
1516 return(len) ;
1517}
1518
1519void mac_drv_pci_fix(struct s_smc *smc, u_long fix_value)
1520{
1521 smc->hw.pci_fix_value = fix_value ;
1522}
1523 1309
1524void mac_do_pci_fix(struct s_smc *smc) 1310void mac_do_pci_fix(struct s_smc *smc)
1525{ 1311{
diff --git a/drivers/net/skfp/ess.c b/drivers/net/skfp/ess.c
index fd39b4b2ef7d..62b01328c496 100644
--- a/drivers/net/skfp/ess.c
+++ b/drivers/net/skfp/ess.c
@@ -102,7 +102,7 @@ void ess_timer_poll(struct s_smc *smc);
102void ess_para_change(struct s_smc *smc); 102void ess_para_change(struct s_smc *smc);
103int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm, 103int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
104 int fs); 104 int fs);
105int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead); 105static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead);
106 106
107 107
108/* 108/*
@@ -375,7 +375,7 @@ int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
375 * determines the synchronous bandwidth, set the TSYNC register and the 375 * determines the synchronous bandwidth, set the TSYNC register and the
376 * mib variables SBAPayload, SBAOverhead and fddiMACT-NEG. 376 * mib variables SBAPayload, SBAOverhead and fddiMACT-NEG.
377 */ 377 */
378int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead) 378static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead)
379{ 379{
380 /* 380 /*
381 * determine the synchronous bandwidth (sync_bw) in bytes per T-NEG, 381 * determine the synchronous bandwidth (sync_bw) in bytes per T-NEG,
diff --git a/drivers/net/skfp/fplustm.c b/drivers/net/skfp/fplustm.c
index 76e78442fc24..a2ed47f1cc70 100644
--- a/drivers/net/skfp/fplustm.c
+++ b/drivers/net/skfp/fplustm.c
@@ -1117,30 +1117,6 @@ void mac_clear_multicast(struct s_smc *smc)
1117/* 1117/*
1118 BEGIN_MANUAL_ENTRY(if,func;others;2) 1118 BEGIN_MANUAL_ENTRY(if,func;others;2)
1119 1119
1120 int mac_set_func_addr(smc,f_addr)
1121 struct s_smc *smc ;
1122 u_long f_addr ;
1123
1124Function DOWNCALL (SMT, fplustm.c)
1125 Set a Token-Ring functional address, the address will
1126 be activated after calling mac_update_multicast()
1127
1128Para f_addr functional bits in non-canonical format
1129
1130Returns 0: always success
1131
1132 END_MANUAL_ENTRY()
1133 */
1134int mac_set_func_addr(struct s_smc *smc, u_long f_addr)
1135{
1136 smc->hw.fp.func_addr = f_addr ;
1137 return(0) ;
1138}
1139
1140
1141/*
1142 BEGIN_MANUAL_ENTRY(if,func;others;2)
1143
1144 int mac_add_multicast(smc,addr,can) 1120 int mac_add_multicast(smc,addr,can)
1145 struct s_smc *smc ; 1121 struct s_smc *smc ;
1146 struct fddi_addr *addr ; 1122 struct fddi_addr *addr ;
@@ -1203,52 +1179,6 @@ int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can)
1203} 1179}
1204 1180
1205/* 1181/*
1206 BEGIN_MANUAL_ENTRY(if,func;others;2)
1207
1208 void mac_del_multicast(smc,addr,can)
1209 struct s_smc *smc ;
1210 struct fddi_addr *addr ;
1211 int can ;
1212
1213Function DOWNCALL (SMT, fplustm.c)
1214 Delete an entry from the multicast table
1215
1216Para addr pointer to a multicast address
1217 can = 0: the multicast address has the physical format
1218 = 1: the multicast address has the canonical format
1219 | 0x80 permanent
1220
1221 END_MANUAL_ENTRY()
1222 */
1223void mac_del_multicast(struct s_smc *smc, struct fddi_addr *addr, int can)
1224{
1225 SK_LOC_DECL(struct fddi_addr,own) ;
1226 struct s_fpmc *tb ;
1227
1228 if (!(tb = mac_get_mc_table(smc,addr,&own,1,can & ~0x80)))
1229 return ;
1230 /*
1231 * permanent addresses must be deleted with perm bit
1232 * and vice versa
1233 */
1234 if (( tb->perm && (can & 0x80)) ||
1235 (!tb->perm && !(can & 0x80))) {
1236 /*
1237 * delete it
1238 */
1239 if (tb->n) {
1240 tb->n-- ;
1241 if (tb->perm) {
1242 smc->hw.fp.smt_slots_used-- ;
1243 }
1244 else {
1245 smc->hw.fp.os_slots_used-- ;
1246 }
1247 }
1248 }
1249}
1250
1251/*
1252 * mode 1182 * mode
1253 */ 1183 */
1254 1184
diff --git a/drivers/net/skfp/h/cmtdef.h b/drivers/net/skfp/h/cmtdef.h
index 603982debc71..f2f771d8be76 100644
--- a/drivers/net/skfp/h/cmtdef.h
+++ b/drivers/net/skfp/h/cmtdef.h
@@ -507,7 +507,6 @@ void pcm_status_state(struct s_smc *smc, int np, int *type, int *state,
507 int *remote, int *mac); 507 int *remote, int *mac);
508void plc_config_mux(struct s_smc *smc, int mux); 508void plc_config_mux(struct s_smc *smc, int mux);
509void sm_lem_evaluate(struct s_smc *smc); 509void sm_lem_evaluate(struct s_smc *smc);
510void smt_clear_una_dna(struct s_smc *smc);
511void mac_update_counter(struct s_smc *smc); 510void mac_update_counter(struct s_smc *smc);
512void sm_pm_ls_latch(struct s_smc *smc, int phy, int on_off); 511void sm_pm_ls_latch(struct s_smc *smc, int phy, int on_off);
513void sm_ma_control(struct s_smc *smc, int mode); 512void sm_ma_control(struct s_smc *smc, int mode);
@@ -541,11 +540,9 @@ void smt_timer_poll(struct s_smc *smc);
541u_long smt_get_time(void); 540u_long smt_get_time(void);
542u_long smt_get_tid(struct s_smc *smc); 541u_long smt_get_tid(struct s_smc *smc);
543void smt_timer_done(struct s_smc *smc); 542void smt_timer_done(struct s_smc *smc);
544void smt_set_defaults(struct s_smc *smc);
545void smt_fixup_mib(struct s_smc *smc); 543void smt_fixup_mib(struct s_smc *smc);
546void smt_reset_defaults(struct s_smc *smc, int level); 544void smt_reset_defaults(struct s_smc *smc, int level);
547void smt_agent_task(struct s_smc *smc); 545void smt_agent_task(struct s_smc *smc);
548void smt_please_reconnect(struct s_smc *smc, int reconn_time);
549int smt_check_para(struct s_smc *smc, struct smt_header *sm, 546int smt_check_para(struct s_smc *smc, struct smt_header *sm,
550 const u_short list[]); 547 const u_short list[]);
551void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr); 548void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr);
@@ -568,7 +565,6 @@ int pcm_get_s_port(struct s_smc *smc);
568int pcm_rooted_station(struct s_smc *smc); 565int pcm_rooted_station(struct s_smc *smc);
569int cfm_get_mac_input(struct s_smc *smc); 566int cfm_get_mac_input(struct s_smc *smc);
570int cfm_get_mac_output(struct s_smc *smc); 567int cfm_get_mac_output(struct s_smc *smc);
571int port_to_mib(struct s_smc *smc, int p);
572int cem_build_path(struct s_smc *smc, char *to, int path_index); 568int cem_build_path(struct s_smc *smc, char *to, int path_index);
573int sm_mac_get_tx_state(struct s_smc *smc); 569int sm_mac_get_tx_state(struct s_smc *smc);
574char *get_pcmstate(struct s_smc *smc, int np); 570char *get_pcmstate(struct s_smc *smc, int np);
@@ -580,8 +576,6 @@ void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local);
580void smt_set_timestamp(struct s_smc *smc, u_char *p); 576void smt_set_timestamp(struct s_smc *smc, u_char *p);
581void mac_set_rx_mode(struct s_smc *smc, int mode); 577void mac_set_rx_mode(struct s_smc *smc, int mode);
582int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can); 578int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can);
583int mac_set_func_addr(struct s_smc *smc, u_long f_addr);
584void mac_del_multicast(struct s_smc *smc, struct fddi_addr *addr, int can);
585void mac_update_multicast(struct s_smc *smc); 579void mac_update_multicast(struct s_smc *smc);
586void mac_clear_multicast(struct s_smc *smc); 580void mac_clear_multicast(struct s_smc *smc);
587void set_formac_tsync(struct s_smc *smc, long sync_bw); 581void set_formac_tsync(struct s_smc *smc, long sync_bw);
@@ -599,7 +593,6 @@ void plc_irq(struct s_smc *smc, int np, unsigned int cmd);
599int smt_set_mac_opvalues(struct s_smc *smc); 593int smt_set_mac_opvalues(struct s_smc *smc);
600 594
601#ifdef TAG_MODE 595#ifdef TAG_MODE
602void mac_drv_pci_fix(struct s_smc *smc, u_long fix_value);
603void mac_do_pci_fix(struct s_smc *smc); 596void mac_do_pci_fix(struct s_smc *smc);
604void mac_drv_clear_tx_queue(struct s_smc *smc); 597void mac_drv_clear_tx_queue(struct s_smc *smc);
605void mac_drv_repair_descr(struct s_smc *smc); 598void mac_drv_repair_descr(struct s_smc *smc);
diff --git a/drivers/net/skfp/h/hwmtm.h b/drivers/net/skfp/h/hwmtm.h
index 4e360af07d77..1a606d4bfe5e 100644
--- a/drivers/net/skfp/h/hwmtm.h
+++ b/drivers/net/skfp/h/hwmtm.h
@@ -262,31 +262,6 @@ struct os_debug {
262 (smc)->hw.fp.tx_q[queue].tx_curr_put 262 (smc)->hw.fp.tx_q[queue].tx_curr_put
263 263
264/* 264/*
265 * BEGIN_MANUAL_ENTRY(HWM_TX_CHECK)
266 * void HWM_TX_CHECK(smc,frame_status,low_water)
267 *
268 * function MACRO (hardware module, hwmtm.h)
269 * This macro is invoked by the OS-specific before it left it's
270 * driver_send function. This macro calls mac_drv_clear_txd
271 * if the free TxDs of the current transmit queue is equal or
272 * lower than the given low water mark.
273 *
274 * para frame_status status of the frame, see design description
275 * low_water low water mark of free TxD's
276 *
277 * END_MANUAL_ENTRY
278 */
279#ifndef HWM_NO_FLOW_CTL
280#define HWM_TX_CHECK(smc,frame_status,low_water) {\
281 if ((low_water)>=(smc)->hw.fp.tx_q[(frame_status)&QUEUE_A0].tx_free) {\
282 mac_drv_clear_txd(smc) ;\
283 }\
284}
285#else
286#define HWM_TX_CHECK(smc,frame_status,low_water) mac_drv_clear_txd(smc)
287#endif
288
289/*
290 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN) 265 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN)
291 * int HWM_GET_RX_FRAG_LEN(rxd) 266 * int HWM_GET_RX_FRAG_LEN(rxd)
292 * 267 *
diff --git a/drivers/net/skfp/h/osdef1st.h b/drivers/net/skfp/h/osdef1st.h
index 5359eb53008d..763ca18cbea8 100644
--- a/drivers/net/skfp/h/osdef1st.h
+++ b/drivers/net/skfp/h/osdef1st.h
@@ -20,6 +20,8 @@
20// HWM (HardWare Module) Definitions 20// HWM (HardWare Module) Definitions
21// ----------------------- 21// -----------------------
22 22
23#include <asm/byteorder.h>
24
23#ifdef __LITTLE_ENDIAN 25#ifdef __LITTLE_ENDIAN
24#define LITTLE_ENDIAN 26#define LITTLE_ENDIAN
25#else 27#else
diff --git a/drivers/net/skfp/hwmtm.c b/drivers/net/skfp/hwmtm.c
index 18d429021edb..438f424e6361 100644
--- a/drivers/net/skfp/hwmtm.c
+++ b/drivers/net/skfp/hwmtm.c
@@ -86,6 +86,7 @@ static u_long repair_txd_ring(struct s_smc *smc, struct s_smt_tx_queue *queue);
86static u_long repair_rxd_ring(struct s_smc *smc, struct s_smt_rx_queue *queue); 86static u_long repair_rxd_ring(struct s_smc *smc, struct s_smt_rx_queue *queue);
87static SMbuf* get_llc_rx(struct s_smc *smc); 87static SMbuf* get_llc_rx(struct s_smc *smc);
88static SMbuf* get_txd_mb(struct s_smc *smc); 88static SMbuf* get_txd_mb(struct s_smc *smc);
89static void mac_drv_clear_txd(struct s_smc *smc);
89 90
90/* 91/*
91 ------------------------------------------------------------- 92 -------------------------------------------------------------
@@ -146,7 +147,6 @@ extern int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
146*/ 147*/
147void process_receive(struct s_smc *smc); 148void process_receive(struct s_smc *smc);
148void fddi_isr(struct s_smc *smc); 149void fddi_isr(struct s_smc *smc);
149void mac_drv_clear_txd(struct s_smc *smc);
150void smt_free_mbuf(struct s_smc *smc, SMbuf *mb); 150void smt_free_mbuf(struct s_smc *smc, SMbuf *mb);
151void init_driver_fplus(struct s_smc *smc); 151void init_driver_fplus(struct s_smc *smc);
152void mac_drv_rx_mode(struct s_smc *smc, int mode); 152void mac_drv_rx_mode(struct s_smc *smc, int mode);
@@ -158,7 +158,6 @@ void hwm_tx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
158void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len, 158void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
159 int frame_status); 159 int frame_status);
160 160
161int mac_drv_rx_frag(struct s_smc *smc, void far *virt, int len);
162int mac_drv_init(struct s_smc *smc); 161int mac_drv_init(struct s_smc *smc);
163int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count, int frame_len, 162int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count, int frame_len,
164 int frame_status); 163 int frame_status);
@@ -1448,35 +1447,6 @@ void hwm_rx_frag(struct s_smc *smc, char far *virt, u_long phys, int len,
1448 NDD_TRACE("RHfE",r,AIX_REVERSE(r->rxd_rbadr),0) ; 1447 NDD_TRACE("RHfE",r,AIX_REVERSE(r->rxd_rbadr),0) ;
1449} 1448}
1450 1449
1451#ifndef NDIS_OS2
1452/*
1453 * BEGIN_MANUAL_ENTRY(mac_drv_rx_frag)
1454 * int mac_drv_rx_frag(smc,virt,len)
1455 *
1456 * function DOWNCALL (hwmtm.c)
1457 * mac_drv_rx_frag fills the fragment with a part of the frame.
1458 *
1459 * para virt the virtual address of the fragment
1460 * len the length in bytes of the fragment
1461 *
1462 * return 0: success code, no errors possible
1463 *
1464 * END_MANUAL_ENTRY
1465 */
1466int mac_drv_rx_frag(struct s_smc *smc, void far *virt, int len)
1467{
1468 NDD_TRACE("RHSB",virt,len,smc->os.hwm.r.mb_pos) ;
1469
1470 DB_RX("receive from queue: len/virt: = %d/%x",len,virt,4) ;
1471 memcpy((char far *)virt,smc->os.hwm.r.mb_pos,len) ;
1472 smc->os.hwm.r.mb_pos += len ;
1473
1474 NDD_TRACE("RHSE",smc->os.hwm.r.mb_pos,0,0) ;
1475 return(0) ;
1476}
1477#endif
1478
1479
1480/* 1450/*
1481 * BEGINN_MANUAL_ENTRY(mac_drv_clear_rx_queue) 1451 * BEGINN_MANUAL_ENTRY(mac_drv_clear_rx_queue)
1482 * 1452 *
@@ -1978,7 +1948,7 @@ void smt_send_mbuf(struct s_smc *smc, SMbuf *mb, int fc)
1978 * 1948 *
1979 * END_MANUAL_ENTRY 1949 * END_MANUAL_ENTRY
1980 */ 1950 */
1981void mac_drv_clear_txd(struct s_smc *smc) 1951static void mac_drv_clear_txd(struct s_smc *smc)
1982{ 1952{
1983 struct s_smt_tx_queue *queue ; 1953 struct s_smt_tx_queue *queue ;
1984 struct s_smt_fp_txd volatile *t1 ; 1954 struct s_smt_fp_txd volatile *t1 ;
diff --git a/drivers/net/skfp/lnkstat.c b/drivers/net/skfp/lnkstat.c
deleted file mode 100644
index 00a248044f86..000000000000
--- a/drivers/net/skfp/lnkstat.c
+++ /dev/null
@@ -1,204 +0,0 @@
1/******************************************************************************
2 *
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5 *
6 * See the file "skfddi.c" for further information.
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 * The information in this file is provided "AS IS" without warranty.
14 *
15 ******************************************************************************/
16
17/*
18 IBM FDDI read error log function
19*/
20
21#include "h/types.h"
22#include "h/fddi.h"
23#include "h/smc.h"
24#include "h/lnkstat.h"
25
26#ifndef lint
27static const char ID_sccs[] = "@(#)lnkstat.c 1.8 97/04/11 (C) SK " ;
28#endif
29
30#ifdef sun
31#define _far
32#endif
33
34#define EL_IS_OK(x,l) ((((int)&(((struct s_error_log *)0)->x)) + \
35 sizeof(er->x)) <= l)
36
37/*
38 BEGIN_MANUAL_ENTRY(if,func;others;11)
39
40 u_long smt_get_error_word(smc)
41 struct s_smc *smc ;
42
43Function DOWNCALL (SMT, lnkstat.c)
44 This functions returns the SMT error work for AIX events.
45
46Return smt_error_word These bits are supported:
47
48 SMT_ERL_ALC == [PS/PA].fddiPORTLerFlag
49 SMT_ERL_BLC == [PB].fddiPORTLerFlag
50 SMT_ERL_NCC == fddiMACNotCopiedFlag
51 SMT_ERL_FEC == fddiMACFrameErrorFlag
52
53 END_MANUAL_ENTRY()
54 */
55u_long smt_get_error_word(struct s_smc *smc)
56{
57 u_long st;
58
59 /*
60 * smt error word low
61 */
62 st = 0 ;
63 if (smc->s.sas == SMT_SAS) {
64 if (smc->mib.p[PS].fddiPORTLerFlag)
65 st |= SMT_ERL_ALC ;
66 }
67 else {
68 if (smc->mib.p[PA].fddiPORTLerFlag)
69 st |= SMT_ERL_ALC ;
70 if (smc->mib.p[PB].fddiPORTLerFlag)
71 st |= SMT_ERL_BLC ;
72 }
73 if (smc->mib.m[MAC0].fddiMACNotCopiedFlag)
74 st |= SMT_ERL_NCC ; /* not copied condition */
75 if (smc->mib.m[MAC0].fddiMACFrameErrorFlag)
76 st |= SMT_ERL_FEC ; /* frame error condition */
77
78 return st;
79}
80
81/*
82 BEGIN_MANUAL_ENTRY(if,func;others;11)
83
84 u_long smt_get_event_word(smc)
85 struct s_smc *smc ;
86
87Function DOWNCALL (SMT, lnkstat.c)
88 This functions returns the SMT event work for AIX events.
89
90Return smt_event_word always 0
91
92 END_MANUAL_ENTRY()
93 */
94u_long smt_get_event_word(struct s_smc *smc)
95{
96 return (u_long) 0;
97}
98
99/*
100 BEGIN_MANUAL_ENTRY(if,func;others;11)
101
102 u_long smt_get_port_event_word(smc)
103 struct s_smc *smc ;
104
105Function DOWNCALL (SMT, lnkstat.c)
106 This functions returns the SMT port event work for AIX events.
107
108Return smt_port_event_word always 0
109
110 END_MANUAL_ENTRY()
111 */
112u_long smt_get_port_event_word(struct s_smc *smc)
113{
114 return (u_long) 0;
115}
116
117/*
118 BEGIN_MANUAL_ENTRY(if,func;others;11)
119
120 u_long smt_read_errorlog(smc,p,len)
121 struct s_smc *smc ;
122 char _far *p ;
123 int len ;
124
125Function DOWNCALL (SMT, lnkstat.c)
126 This functions returns the SMT error log field for AIX events.
127
128Para p pointer to the error log field
129 len len of the error log field
130
131Return len used len of the error log field
132
133 END_MANUAL_ENTRY()
134 */
135int smt_read_errorlog(struct s_smc *smc, char _far *p, int len)
136{
137 int i ;
138 int st ;
139 struct s_error_log _far *er ;
140
141 er = (struct s_error_log _far *) p ;
142 if (len > sizeof(struct s_error_log))
143 len = sizeof(struct s_error_log) ;
144 for (i = 0 ; i < len ; i++)
145 *p++ = 0 ;
146 /*
147 * set count
148 */
149 if (EL_IS_OK(set_count_high,len)) {
150 er->set_count_low = (u_short)smc->mib.fddiSMTSetCount.count ;
151 er->set_count_high =
152 (u_short)(smc->mib.fddiSMTSetCount.count >> 16L) ;
153 }
154 /*
155 * aci
156 */
157 if (EL_IS_OK(aci_id_code,len)) {
158 er->aci_id_code = 0 ;
159 }
160 /*
161 * purge counter is missed frames; 16 bits only
162 */
163 if (EL_IS_OK(purge_frame_counter,len)) {
164 if (smc->mib.m[MAC0].fddiMACCopied_Ct > 0xffff)
165 er->purge_frame_counter = 0xffff ;
166 else
167 er->purge_frame_counter =
168 (u_short)smc->mib.m[MAC0].fddiMACCopied_Ct ;
169 }
170 /*
171 * CMT and RMT state machines
172 */
173 if (EL_IS_OK(ecm_state,len))
174 er->ecm_state = smc->mib.fddiSMTECMState ;
175
176 if (EL_IS_OK(pcm_b_state,len)) {
177 if (smc->s.sas == SMT_SAS) {
178 er->pcm_a_state = smc->y[PS].mib->fddiPORTPCMState ;
179 er->pcm_b_state = 0 ;
180 }
181 else {
182 er->pcm_a_state = smc->y[PA].mib->fddiPORTPCMState ;
183 er->pcm_b_state = smc->y[PB].mib->fddiPORTPCMState ;
184 }
185 }
186 if (EL_IS_OK(cfm_state,len))
187 er->cfm_state = smc->mib.fddiSMTCF_State ;
188 if (EL_IS_OK(rmt_state,len))
189 er->rmt_state = smc->mib.m[MAC0].fddiMACRMTState ;
190
191 /*
192 * smt error word low (we only need the low order 16 bits.)
193 */
194
195 st = smt_get_error_word(smc) & 0xffff ;
196
197 if (EL_IS_OK(smt_error_low,len))
198 er->smt_error_low = st ;
199
200 if (EL_IS_OK(ucode_version_level,len))
201 er->ucode_version_level = 0x0101 ;
202 return(len) ;
203}
204
diff --git a/drivers/net/skfp/pcmplc.c b/drivers/net/skfp/pcmplc.c
index 571f055c096b..cd0aa4c151b0 100644
--- a/drivers/net/skfp/pcmplc.c
+++ b/drivers/net/skfp/pcmplc.c
@@ -1861,13 +1861,6 @@ void plc_irq(struct s_smc *smc, int np, unsigned int cmd)
1861#endif 1861#endif
1862} 1862}
1863 1863
1864void pcm_set_lct_short(struct s_smc *smc, int n)
1865{
1866 if (n <= 0 || n > 1000)
1867 return ;
1868 smc->s.lct_short = n ;
1869}
1870
1871#ifdef DEBUG 1864#ifdef DEBUG
1872/* 1865/*
1873 * fill state struct 1866 * fill state struct
diff --git a/drivers/net/skfp/pmf.c b/drivers/net/skfp/pmf.c
index f2b446d8b0bf..efc639c013fd 100644
--- a/drivers/net/skfp/pmf.c
+++ b/drivers/net/skfp/pmf.c
@@ -36,12 +36,13 @@ static int smt_authorize(struct s_smc *smc, struct smt_header *sm);
36static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm); 36static int smt_check_set_count(struct s_smc *smc, struct smt_header *sm);
37static const struct s_p_tab* smt_get_ptab(u_short para); 37static const struct s_p_tab* smt_get_ptab(u_short para);
38static int smt_mib_phys(struct s_smc *smc); 38static int smt_mib_phys(struct s_smc *smc);
39int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index, int local, 39static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
40 int set); 40 int local, int set);
41void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para, 41void smt_add_para(struct s_smc *smc, struct s_pcon *pcon, u_short para,
42 int index, int local); 42 int index, int local);
43static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, 43static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
44 int set, int local); 44 int set, int local);
45static int port_to_mib(struct s_smc *smc, int p);
45 46
46#define MOFFSS(e) ((int)&(((struct fddi_mib *)0)->e)) 47#define MOFFSS(e) ((int)&(((struct fddi_mib *)0)->e))
47#define MOFFSA(e) ((int) (((struct fddi_mib *)0)->e)) 48#define MOFFSA(e) ((int) (((struct fddi_mib *)0)->e))
@@ -1078,8 +1079,8 @@ wrong_error:
1078/* 1079/*
1079 * set parameter 1080 * set parameter
1080 */ 1081 */
1081int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index, int local, 1082static int smt_set_para(struct s_smc *smc, struct smt_para *pa, int index,
1082 int set) 1083 int local, int set)
1083{ 1084{
1084#define IFSET(x) if (set) (x) 1085#define IFSET(x) if (set) (x)
1085 1086
@@ -1549,7 +1550,7 @@ static int smt_mib_phys(struct s_smc *smc)
1549#endif 1550#endif
1550} 1551}
1551 1552
1552int port_to_mib(struct s_smc *smc, int p) 1553static int port_to_mib(struct s_smc *smc, int p)
1553{ 1554{
1554#ifdef CONCENTRATOR 1555#ifdef CONCENTRATOR
1555 SK_UNUSED(smc) ; 1556 SK_UNUSED(smc) ;
diff --git a/drivers/net/skfp/skfddi.c b/drivers/net/skfp/skfddi.c
index c88aad6edd74..4b5ed2c63177 100644
--- a/drivers/net/skfp/skfddi.c
+++ b/drivers/net/skfp/skfddi.c
@@ -149,7 +149,6 @@ extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
149extern void mac_drv_rx_mode(struct s_smc *smc, int mode); 149extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
150extern void mac_drv_clear_rx_queue(struct s_smc *smc); 150extern void mac_drv_clear_rx_queue(struct s_smc *smc);
151extern void enable_tx_irq(struct s_smc *smc, u_short queue); 151extern void enable_tx_irq(struct s_smc *smc, u_short queue);
152extern void mac_drv_clear_txd(struct s_smc *smc);
153 152
154static struct pci_device_id skfddi_pci_tbl[] = { 153static struct pci_device_id skfddi_pci_tbl[] = {
155 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, }, 154 { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
diff --git a/drivers/net/skfp/smt.c b/drivers/net/skfp/smt.c
index 71935eaf9d4e..f17c05cbe44b 100644
--- a/drivers/net/skfp/smt.c
+++ b/drivers/net/skfp/smt.c
@@ -86,7 +86,7 @@ static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
86static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest, 86static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
87 u_long tid, int local); 87 u_long tid, int local);
88#ifdef LITTLE_ENDIAN 88#ifdef LITTLE_ENDIAN
89static void smt_string_swap(void); 89static void smt_string_swap(char *data, const char *format, int len);
90#endif 90#endif
91static void smt_add_frame_len(SMbuf *mb, int len); 91static void smt_add_frame_len(SMbuf *mb, int len);
92static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una); 92static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
@@ -110,7 +110,7 @@ static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount
110static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed, 110static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
111 int len); 111 int len);
112 112
113void smt_clear_una_dna(struct s_smc *smc); 113static void smt_clear_una_dna(struct s_smc *smc);
114static void smt_clear_old_una_dna(struct s_smc *smc); 114static void smt_clear_old_una_dna(struct s_smc *smc);
115#ifdef CONCENTRATOR 115#ifdef CONCENTRATOR
116static int entity_to_index(void); 116static int entity_to_index(void);
@@ -118,7 +118,7 @@ static int entity_to_index(void);
118static void update_dac(struct s_smc *smc, int report); 118static void update_dac(struct s_smc *smc, int report);
119static int div_ratio(u_long upper, u_long lower); 119static int div_ratio(u_long upper, u_long lower);
120#ifdef USE_CAN_ADDR 120#ifdef USE_CAN_ADDR
121void hwm_conv_can(struct s_smc *smc, char *data, int len); 121static void hwm_conv_can(struct s_smc *smc, char *data, int len);
122#else 122#else
123#define hwm_conv_can(smc,data,len) 123#define hwm_conv_can(smc,data,len)
124#endif 124#endif
@@ -216,24 +216,6 @@ void smt_agent_task(struct s_smc *smc)
216 DB_SMT("SMT agent task\n",0,0) ; 216 DB_SMT("SMT agent task\n",0,0) ;
217} 217}
218 218
219void smt_please_reconnect(struct s_smc *smc, int reconn_time)
220/* struct s_smc *smc; Pointer to SMT context */
221/* int reconn_time; Wait for reconnect time in seconds */
222{
223 /*
224 * The please reconnect variable is used as a timer.
225 * It is decremented each time smt_event is called.
226 * This happens every second or when smt_force_irq is called.
227 * Note: smt_force_irq () is called on some packet receives and
228 * when a multicast address is changed. Since nothing
229 * is received during the disconnect and the multicast
230 * address changes can be viewed as not very often and
231 * the timer runs out close to its given value
232 * (reconn_time).
233 */
234 smc->sm.please_reconnect = reconn_time ;
235}
236
237#ifndef SMT_REAL_TOKEN_CT 219#ifndef SMT_REAL_TOKEN_CT
238void smt_emulate_token_ct(struct s_smc *smc, int mac_index) 220void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
239{ 221{
@@ -1574,7 +1556,7 @@ static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long see
1574 * clear DNA and UNA 1556 * clear DNA and UNA
1575 * called from CFM if configuration changes 1557 * called from CFM if configuration changes
1576 */ 1558 */
1577void smt_clear_una_dna(struct s_smc *smc) 1559static void smt_clear_una_dna(struct s_smc *smc)
1578{ 1560{
1579 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ; 1561 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1580 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ; 1562 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
@@ -2058,30 +2040,10 @@ int smt_action(struct s_smc *smc, int class, int code, int index)
2058} 2040}
2059 2041
2060/* 2042/*
2061 * change tneg
2062 * set T_Req in MIB (Path Attribute)
2063 * calculate new values for MAC
2064 * if change required
2065 * disconnect
2066 * set reconnect
2067 * end
2068 */
2069void smt_change_t_neg(struct s_smc *smc, u_long tneg)
2070{
2071 smc->mib.a[PATH0].fddiPATHMaxT_Req = tneg ;
2072
2073 if (smt_set_mac_opvalues(smc)) {
2074 RS_SET(smc,RS_EVENT) ;
2075 smc->sm.please_reconnect = 1 ;
2076 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
2077 }
2078}
2079
2080/*
2081 * canonical conversion of <len> bytes beginning form *data 2043 * canonical conversion of <len> bytes beginning form *data
2082 */ 2044 */
2083#ifdef USE_CAN_ADDR 2045#ifdef USE_CAN_ADDR
2084void hwm_conv_can(struct s_smc *smc, char *data, int len) 2046static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2085{ 2047{
2086 int i ; 2048 int i ;
2087 2049
diff --git a/drivers/net/skfp/smtdef.c b/drivers/net/skfp/smtdef.c
index 5a0c8db816d8..4e07ff7073f1 100644
--- a/drivers/net/skfp/smtdef.c
+++ b/drivers/net/skfp/smtdef.c
@@ -76,11 +76,6 @@ void smt_reset_defaults(struct s_smc *smc, int level);
76static void smt_init_mib(struct s_smc *smc, int level); 76static void smt_init_mib(struct s_smc *smc, int level);
77static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper); 77static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper);
78 78
79void smt_set_defaults(struct s_smc *smc)
80{
81 smt_reset_defaults(smc,0) ;
82}
83
84#define MS2BCLK(x) ((x)*12500L) 79#define MS2BCLK(x) ((x)*12500L)
85#define US2BCLK(x) ((x)*1250L) 80#define US2BCLK(x) ((x)*1250L)
86 81
diff --git a/drivers/net/skfp/smtparse.c b/drivers/net/skfp/smtparse.c
deleted file mode 100644
index d5779e414dbe..000000000000
--- a/drivers/net/skfp/smtparse.c
+++ /dev/null
@@ -1,467 +0,0 @@
1/******************************************************************************
2 *
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5 *
6 * See the file "skfddi.c" for further information.
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 * The information in this file is provided "AS IS" without warranty.
14 *
15 ******************************************************************************/
16
17
18/*
19 parser for SMT parameters
20*/
21
22#include "h/types.h"
23#include "h/fddi.h"
24#include "h/smc.h"
25#include "h/smt_p.h"
26
27#define KERNEL
28#include "h/smtstate.h"
29
30#ifndef lint
31static const char ID_sccs[] = "@(#)smtparse.c 1.12 98/10/06 (C) SK " ;
32#endif
33
34#ifdef sun
35#define _far
36#endif
37
38/*
39 * convert to BCLK units
40 */
41#define MS2BCLK(x) ((x)*12500L)
42#define US2BCLK(x) ((x/10)*125L)
43
44/*
45 * parameter table
46 */
47static struct s_ptab {
48 char *pt_name ;
49 u_short pt_num ;
50 u_short pt_type ;
51 u_long pt_min ;
52 u_long pt_max ;
53} ptab[] = {
54 { "PMFPASSWD",0, 0 } ,
55 { "USERDATA",1, 0 } ,
56 { "LERCUTOFFA",2, 1, 4, 15 } ,
57 { "LERCUTOFFB",3, 1, 4, 15 } ,
58 { "LERALARMA",4, 1, 4, 15 } ,
59 { "LERALARMB",5, 1, 4, 15 } ,
60 { "TMAX",6, 1, 5, 165 } ,
61 { "TMIN",7, 1, 5, 165 } ,
62 { "TREQ",8, 1, 5, 165 } ,
63 { "TVX",9, 1, 2500, 10000 } ,
64#ifdef ESS
65 { "SBAPAYLOAD",10, 1, 0, 1562 } ,
66 { "SBAOVERHEAD",11, 1, 50, 5000 } ,
67 { "MAXTNEG",12, 1, 5, 165 } ,
68 { "MINSEGMENTSIZE",13, 1, 0, 4478 } ,
69 { "SBACATEGORY",14, 1, 0, 0xffff } ,
70 { "SYNCHTXMODE",15, 0 } ,
71#endif
72#ifdef SBA
73 { "SBACOMMAND",16, 0 } ,
74 { "SBAAVAILABLE",17, 1, 0, 100 } ,
75#endif
76 { NULL }
77} ;
78
79/* Define maximum string size for values and keybuffer */
80#define MAX_VAL 40
81
82/*
83 * local function declarations
84 */
85static u_long parse_num(int type, char _far *value, char *v, u_long mn,
86 u_long mx, int scale);
87static int parse_word(char *buf, char _far *text);
88
89#ifdef SIM
90#define DB_MAIN(a,b,c) printf(a,b,c)
91#else
92#define DB_MAIN(a,b,c)
93#endif
94
95/*
96 * BEGIN_MANUAL_ENTRY()
97 *
98 * int smt_parse_arg(struct s_smc *,char _far *keyword,int type,
99 char _far *value)
100 *
101 * parse SMT parameter
102 * *keyword
103 * pointer to keyword, must be \0, \n or \r terminated
104 * *value pointer to value, either char * or u_long *
105 * if char *
106 * pointer to value, must be \0, \n or \r terminated
107 * if u_long *
108 * contains binary value
109 *
110 * type 0: integer
111 * 1: string
112 * return
113 * 0 parameter parsed ok
114 * != 0 error
115 * NOTE:
116 * function can be called with DS != SS
117 *
118 *
119 * END_MANUAL_ENTRY()
120 */
121int smt_parse_arg(struct s_smc *smc, char _far *keyword, int type,
122 char _far *value)
123{
124 char keybuf[MAX_VAL+1];
125 char valbuf[MAX_VAL+1];
126 char c ;
127 char *p ;
128 char *v ;
129 char *d ;
130 u_long val = 0 ;
131 struct s_ptab *pt ;
132 int st ;
133 int i ;
134
135 /*
136 * parse keyword
137 */
138 if ((st = parse_word(keybuf,keyword)))
139 return(st) ;
140 /*
141 * parse value if given as string
142 */
143 if (type == 1) {
144 if ((st = parse_word(valbuf,value)))
145 return(st) ;
146 }
147 /*
148 * search in table
149 */
150 st = 0 ;
151 for (pt = ptab ; (v = pt->pt_name) ; pt++) {
152 for (p = keybuf ; (c = *p) ; p++,v++) {
153 if (c != *v)
154 break ;
155 }
156 if (!c && !*v)
157 break ;
158 }
159 if (!v)
160 return(-1) ;
161#if 0
162 printf("=>%s<==>%s<=\n",pt->pt_name,valbuf) ;
163#endif
164 /*
165 * set value in MIB
166 */
167 if (pt->pt_type)
168 val = parse_num(type,value,valbuf,pt->pt_min,pt->pt_max,1) ;
169 switch (pt->pt_num) {
170 case 0 :
171 v = valbuf ;
172 d = (char *) smc->mib.fddiPRPMFPasswd ;
173 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiPRPMFPasswd) ; i++)
174 *d++ = *v++ ;
175 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiPRPMFPasswd) ;
176 break ;
177 case 1 :
178 v = valbuf ;
179 d = (char *) smc->mib.fddiSMTUserData ;
180 for (i = 0 ; i < (signed)sizeof(smc->mib.fddiSMTUserData) ; i++)
181 *d++ = *v++ ;
182 DB_MAIN("SET %s = %s\n",pt->pt_name,smc->mib.fddiSMTUserData) ;
183 break ;
184 case 2 :
185 smc->mib.p[PA].fddiPORTLer_Cutoff = (u_char) val ;
186 DB_MAIN("SET %s = %d\n",
187 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Cutoff) ;
188 break ;
189 case 3 :
190 smc->mib.p[PB].fddiPORTLer_Cutoff = (u_char) val ;
191 DB_MAIN("SET %s = %d\n",
192 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Cutoff) ;
193 break ;
194 case 4 :
195 smc->mib.p[PA].fddiPORTLer_Alarm = (u_char) val ;
196 DB_MAIN("SET %s = %d\n",
197 pt->pt_name,smc->mib.p[PA].fddiPORTLer_Alarm) ;
198 break ;
199 case 5 :
200 smc->mib.p[PB].fddiPORTLer_Alarm = (u_char) val ;
201 DB_MAIN("SET %s = %d\n",
202 pt->pt_name,smc->mib.p[PB].fddiPORTLer_Alarm) ;
203 break ;
204 case 6 : /* TMAX */
205 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
206 smc->mib.a[PATH0].fddiPATHT_MaxLowerBound =
207 (u_long) -MS2BCLK((long)val) ;
208 break ;
209 case 7 : /* TMIN */
210 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
211 smc->mib.m[MAC0].fddiMACT_Min =
212 (u_long) -MS2BCLK((long)val) ;
213 break ;
214 case 8 : /* TREQ */
215 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
216 smc->mib.a[PATH0].fddiPATHMaxT_Req =
217 (u_long) -MS2BCLK((long)val) ;
218 break ;
219 case 9 : /* TVX */
220 DB_MAIN("SET %s = %d \n",pt->pt_name,val) ;
221 smc->mib.a[PATH0].fddiPATHTVXLowerBound =
222 (u_long) -US2BCLK((long)val) ;
223 break ;
224#ifdef ESS
225 case 10 : /* SBAPAYLOAD */
226 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
227 if (smc->mib.fddiESSPayload != val) {
228 smc->ess.raf_act_timer_poll = TRUE ;
229 smc->mib.fddiESSPayload = val ;
230 }
231 break ;
232 case 11 : /* SBAOVERHEAD */
233 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
234 smc->mib.fddiESSOverhead = val ;
235 break ;
236 case 12 : /* MAXTNEG */
237 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
238 smc->mib.fddiESSMaxTNeg = (u_long) -MS2BCLK((long)val) ;
239 break ;
240 case 13 : /* MINSEGMENTSIZE */
241 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
242 smc->mib.fddiESSMinSegmentSize = val ;
243 break ;
244 case 14 : /* SBACATEGORY */
245 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
246 smc->mib.fddiESSCategory =
247 (smc->mib.fddiESSCategory & 0xffff) |
248 ((u_long)(val << 16)) ;
249 break ;
250 case 15 : /* SYNCHTXMODE */
251 /* do not use memcmp(valbuf,"ALL",3) because DS != SS */
252 if (valbuf[0] == 'A' && valbuf[1] == 'L' && valbuf[2] == 'L') {
253 smc->mib.fddiESSSynchTxMode = TRUE ;
254 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
255 }
256 /* if (!memcmp(valbuf,"SPLIT",5)) { */
257 if (valbuf[0] == 'S' && valbuf[1] == 'P' && valbuf[2] == 'L' &&
258 valbuf[3] == 'I' && valbuf[4] == 'T') {
259 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
260 smc->mib.fddiESSSynchTxMode = FALSE ;
261 }
262 break ;
263#endif
264#ifdef SBA
265 case 16 : /* SBACOMMAND */
266 /* if (!memcmp(valbuf,"START",5)) { */
267 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'A' &&
268 valbuf[3] == 'R' && valbuf[4] == 'T') {
269 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
270 smc->mib.fddiSBACommand = SB_START ;
271 }
272 /* if (!memcmp(valbuf,"STOP",4)) { */
273 if (valbuf[0] == 'S' && valbuf[1] == 'T' && valbuf[2] == 'O' &&
274 valbuf[3] == 'P') {
275 DB_MAIN("SET %s = %s\n",pt->pt_name,valbuf) ;
276 smc->mib.fddiSBACommand = SB_STOP ;
277 }
278 break ;
279 case 17 : /* SBAAVAILABLE */
280 DB_MAIN("SET %s = %d\n",pt->pt_name,val) ;
281 smc->mib.fddiSBAAvailable = (u_char) val ;
282 break ;
283#endif
284 }
285 return(0) ;
286}
287
288static int parse_word(char *buf, char _far *text)
289{
290 char c ;
291 char *p ;
292 int p_len ;
293 int quote ;
294 int i ;
295 int ok ;
296
297 /*
298 * skip leading white space
299 */
300 p = buf ;
301 for (i = 0 ; i < MAX_VAL ; i++)
302 *p++ = 0 ;
303 p = buf ;
304 p_len = 0 ;
305 ok = 0 ;
306 while ( (c = *text++) && (c != '\n') && (c != '\r')) {
307 if ((c != ' ') && (c != '\t')) {
308 ok = 1 ;
309 break ;
310 }
311 }
312 if (!ok)
313 return(-1) ;
314 if (c == '"') {
315 quote = 1 ;
316 }
317 else {
318 quote = 0 ;
319 text-- ;
320 }
321 /*
322 * parse valbuf
323 */
324 ok = 0 ;
325 while (!ok && p_len < MAX_VAL-1 && (c = *text++) && (c != '\n')
326 && (c != '\r')) {
327 switch (quote) {
328 case 0 :
329 if ((c == ' ') || (c == '\t') || (c == '=')) {
330 ok = 1 ;
331 break ;
332 }
333 *p++ = c ;
334 p_len++ ;
335 break ;
336 case 2 :
337 *p++ = c ;
338 p_len++ ;
339 quote = 1 ;
340 break ;
341 case 1 :
342 switch (c) {
343 case '"' :
344 ok = 1 ;
345 break ;
346 case '\\' :
347 quote = 2 ;
348 break ;
349 default :
350 *p++ = c ;
351 p_len++ ;
352 }
353 }
354 }
355 *p++ = 0 ;
356 for (p = buf ; (c = *p) ; p++) {
357 if (c >= 'a' && c <= 'z')
358 *p = c + 'A' - 'a' ;
359 }
360 return(0) ;
361}
362
363static u_long parse_num(int type, char _far *value, char *v, u_long mn,
364 u_long mx, int scale)
365{
366 u_long x = 0 ;
367 char c ;
368
369 if (type == 0) { /* integer */
370 u_long _far *l ;
371 u_long u1 ;
372
373 l = (u_long _far *) value ;
374 u1 = *l ;
375 /*
376 * if the value is negative take the lower limit
377 */
378 if ((long)u1 < 0) {
379 if (- ((long)u1) > (long) mx) {
380 u1 = 0 ;
381 }
382 else {
383 u1 = (u_long) - ((long)u1) ;
384 }
385 }
386 x = u1 ;
387 }
388 else { /* string */
389 int sign = 0 ;
390
391 if (*v == '-') {
392 sign = 1 ;
393 }
394 while ((c = *v++) && (c >= '0') && (c <= '9')) {
395 x = x * 10 + c - '0' ;
396 }
397 if (scale == 10) {
398 x *= 10 ;
399 if (c == '.') {
400 if ((c = *v++) && (c >= '0') && (c <= '9')) {
401 x += c - '0' ;
402 }
403 }
404 }
405 if (sign)
406 x = (u_long) - ((long)x) ;
407 }
408 /*
409 * if the value is negative
410 * and the absolute value is outside the limits
411 * take the lower limit
412 * else
413 * take the absoute value
414 */
415 if ((long)x < 0) {
416 if (- ((long)x) > (long) mx) {
417 x = 0 ;
418 }
419 else {
420 x = (u_long) - ((long)x) ;
421 }
422 }
423 if (x < mn)
424 return(mn) ;
425 else if (x > mx)
426 return(mx) ;
427 return(x) ;
428}
429
430#if 0
431struct s_smc SMC ;
432main()
433{
434 char *p ;
435 char *v ;
436 char buf[100] ;
437 int toggle = 0 ;
438
439 while (gets(buf)) {
440 p = buf ;
441 while (*p && ((*p == ' ') || (*p == '\t')))
442 p++ ;
443
444 while (*p && ((*p != ' ') && (*p != '\t')))
445 p++ ;
446
447 v = p ;
448 while (*v && ((*v == ' ') || (*v == '\t')))
449 v++ ;
450 if ((*v >= '0') && (*v <= '9')) {
451 toggle = !toggle ;
452 if (toggle) {
453 u_long l ;
454 l = atol(v) ;
455 smt_parse_arg(&SMC,buf,0,(char _far *)&l) ;
456 }
457 else
458 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;
459 }
460 else {
461 smt_parse_arg(&SMC,buf,1,(char _far *)p) ;
462 }
463 }
464 exit(0) ;
465}
466#endif
467
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 30e8d589d167..5cacc7ad9e79 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -7,7 +7,7 @@
7 * of the original driver such as link fail-over and link management because 7 * of the original driver such as link fail-over and link management because
8 * those should be done at higher levels. 8 * those should be done at higher levels.
9 * 9 *
10 * Copyright (C) 2004, Stephen Hemminger <shemminger@osdl.org> 10 * Copyright (C) 2004, 2005 Stephen Hemminger <shemminger@osdl.org>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 12 * 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 13 * it under the terms of the GNU General Public License as published by
@@ -42,19 +42,20 @@
42#include "skge.h" 42#include "skge.h"
43 43
44#define DRV_NAME "skge" 44#define DRV_NAME "skge"
45#define DRV_VERSION "0.6" 45#define DRV_VERSION "0.7"
46#define PFX DRV_NAME " " 46#define PFX DRV_NAME " "
47 47
48#define DEFAULT_TX_RING_SIZE 128 48#define DEFAULT_TX_RING_SIZE 128
49#define DEFAULT_RX_RING_SIZE 512 49#define DEFAULT_RX_RING_SIZE 512
50#define MAX_TX_RING_SIZE 1024 50#define MAX_TX_RING_SIZE 1024
51#define MAX_RX_RING_SIZE 4096 51#define MAX_RX_RING_SIZE 4096
52#define RX_COPY_THRESHOLD 128
53#define RX_BUF_SIZE 1536
52#define PHY_RETRIES 1000 54#define PHY_RETRIES 1000
53#define ETH_JUMBO_MTU 9000 55#define ETH_JUMBO_MTU 9000
54#define TX_WATCHDOG (5 * HZ) 56#define TX_WATCHDOG (5 * HZ)
55#define NAPI_WEIGHT 64 57#define NAPI_WEIGHT 64
56#define BLINK_HZ (HZ/4) 58#define BLINK_HZ (HZ/4)
57#define LINK_POLL_HZ (HZ/10)
58 59
59MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 60MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
60MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 61MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
@@ -70,28 +71,17 @@ module_param(debug, int, 0);
70MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 71MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
71 72
72static const struct pci_device_id skge_id_table[] = { 73static const struct pci_device_id skge_id_table[] = {
73 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940, 74 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) },
74 PCI_ANY_ID, PCI_ANY_ID }, 75 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
75 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B, 76 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
76 PCI_ANY_ID, PCI_ANY_ID }, 77 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
77 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE, 78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
78 PCI_ANY_ID, PCI_ANY_ID }, 79 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), },
79 { PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU, 80 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
80 PCI_ANY_ID, PCI_ANY_ID }, 81 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
81 { PCI_VENDOR_ID_SYSKONNECT, 0x9E00, /* SK-9Exx */ 82 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
82 PCI_ANY_ID, PCI_ANY_ID }, 83 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1032) },
83 { PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T, 84 { PCI_DEVICE(PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064) },
84 PCI_ANY_ID, PCI_ANY_ID },
85 { PCI_VENDOR_ID_MARVELL, 0x4320, /* Gigabit Ethernet Controller */
86 PCI_ANY_ID, PCI_ANY_ID },
87 { PCI_VENDOR_ID_MARVELL, 0x5005, /* Marvell (11ab), Belkin */
88 PCI_ANY_ID, PCI_ANY_ID },
89 { PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD,
90 PCI_ANY_ID, PCI_ANY_ID },
91 { PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1032,
92 PCI_ANY_ID, PCI_ANY_ID },
93 { PCI_VENDOR_ID_LINKSYS, PCI_DEVICE_ID_LINKSYS_EG1064,
94 PCI_ANY_ID, PCI_ANY_ID },
95 { 0 } 85 { 0 }
96}; 86};
97MODULE_DEVICE_TABLE(pci, skge_id_table); 87MODULE_DEVICE_TABLE(pci, skge_id_table);
@@ -99,19 +89,22 @@ MODULE_DEVICE_TABLE(pci, skge_id_table);
99static int skge_up(struct net_device *dev); 89static int skge_up(struct net_device *dev);
100static int skge_down(struct net_device *dev); 90static int skge_down(struct net_device *dev);
101static void skge_tx_clean(struct skge_port *skge); 91static void skge_tx_clean(struct skge_port *skge);
102static void skge_xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 92static void xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
103static void skge_gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val); 93static void gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val);
104static void genesis_get_stats(struct skge_port *skge, u64 *data); 94static void genesis_get_stats(struct skge_port *skge, u64 *data);
105static void yukon_get_stats(struct skge_port *skge, u64 *data); 95static void yukon_get_stats(struct skge_port *skge, u64 *data);
106static void yukon_init(struct skge_hw *hw, int port); 96static void yukon_init(struct skge_hw *hw, int port);
107static void yukon_reset(struct skge_hw *hw, int port); 97static void yukon_reset(struct skge_hw *hw, int port);
108static void genesis_mac_init(struct skge_hw *hw, int port); 98static void genesis_mac_init(struct skge_hw *hw, int port);
109static void genesis_reset(struct skge_hw *hw, int port); 99static void genesis_reset(struct skge_hw *hw, int port);
100static void genesis_link_up(struct skge_port *skge);
110 101
102/* Avoid conditionals by using array */
111static const int txqaddr[] = { Q_XA1, Q_XA2 }; 103static const int txqaddr[] = { Q_XA1, Q_XA2 };
112static const int rxqaddr[] = { Q_R1, Q_R2 }; 104static const int rxqaddr[] = { Q_R1, Q_R2 };
113static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F }; 105static const u32 rxirqmask[] = { IS_R1_F, IS_R2_F };
114static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F }; 106static const u32 txirqmask[] = { IS_XA1_F, IS_XA2_F };
107static const u32 portirqmask[] = { IS_PORT_1, IS_PORT_2 };
115 108
116/* Don't need to look at whole 16K. 109/* Don't need to look at whole 16K.
117 * last interesting register is descriptor poll timer. 110 * last interesting register is descriptor poll timer.
@@ -154,7 +147,7 @@ static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
154static int wol_supported(const struct skge_hw *hw) 147static int wol_supported(const struct skge_hw *hw)
155{ 148{
156 return !((hw->chip_id == CHIP_ID_GENESIS || 149 return !((hw->chip_id == CHIP_ID_GENESIS ||
157 (hw->chip_id == CHIP_ID_YUKON && chip_rev(hw) == 0))); 150 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)));
158} 151}
159 152
160static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 153static void skge_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
@@ -170,7 +163,7 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
170 struct skge_port *skge = netdev_priv(dev); 163 struct skge_port *skge = netdev_priv(dev);
171 struct skge_hw *hw = skge->hw; 164 struct skge_hw *hw = skge->hw;
172 165
173 if(wol->wolopts != WAKE_MAGIC && wol->wolopts != 0) 166 if (wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
174 return -EOPNOTSUPP; 167 return -EOPNOTSUPP;
175 168
176 if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw)) 169 if (wol->wolopts == WAKE_MAGIC && !wol_supported(hw))
@@ -190,6 +183,36 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
190 return 0; 183 return 0;
191} 184}
192 185
186/* Determine supported/adverised modes based on hardware.
187 * Note: ethtoool ADVERTISED_xxx == SUPPORTED_xxx
188 */
189static u32 skge_supported_modes(const struct skge_hw *hw)
190{
191 u32 supported;
192
193 if (iscopper(hw)) {
194 supported = SUPPORTED_10baseT_Half
195 | SUPPORTED_10baseT_Full
196 | SUPPORTED_100baseT_Half
197 | SUPPORTED_100baseT_Full
198 | SUPPORTED_1000baseT_Half
199 | SUPPORTED_1000baseT_Full
200 | SUPPORTED_Autoneg| SUPPORTED_TP;
201
202 if (hw->chip_id == CHIP_ID_GENESIS)
203 supported &= ~(SUPPORTED_10baseT_Half
204 | SUPPORTED_10baseT_Full
205 | SUPPORTED_100baseT_Half
206 | SUPPORTED_100baseT_Full);
207
208 else if (hw->chip_id == CHIP_ID_YUKON)
209 supported &= ~SUPPORTED_1000baseT_Half;
210 } else
211 supported = SUPPORTED_1000baseT_Full | SUPPORTED_FIBRE
212 | SUPPORTED_Autoneg;
213
214 return supported;
215}
193 216
194static int skge_get_settings(struct net_device *dev, 217static int skge_get_settings(struct net_device *dev,
195 struct ethtool_cmd *ecmd) 218 struct ethtool_cmd *ecmd)
@@ -198,38 +221,13 @@ static int skge_get_settings(struct net_device *dev,
198 struct skge_hw *hw = skge->hw; 221 struct skge_hw *hw = skge->hw;
199 222
200 ecmd->transceiver = XCVR_INTERNAL; 223 ecmd->transceiver = XCVR_INTERNAL;
224 ecmd->supported = skge_supported_modes(hw);
201 225
202 if (iscopper(hw)) { 226 if (iscopper(hw)) {
203 if (hw->chip_id == CHIP_ID_GENESIS)
204 ecmd->supported = SUPPORTED_1000baseT_Full
205 | SUPPORTED_1000baseT_Half
206 | SUPPORTED_Autoneg | SUPPORTED_TP;
207 else {
208 ecmd->supported = SUPPORTED_10baseT_Half
209 | SUPPORTED_10baseT_Full
210 | SUPPORTED_100baseT_Half
211 | SUPPORTED_100baseT_Full
212 | SUPPORTED_1000baseT_Half
213 | SUPPORTED_1000baseT_Full
214 | SUPPORTED_Autoneg| SUPPORTED_TP;
215
216 if (hw->chip_id == CHIP_ID_YUKON)
217 ecmd->supported &= ~SUPPORTED_1000baseT_Half;
218
219 else if (hw->chip_id == CHIP_ID_YUKON_FE)
220 ecmd->supported &= ~(SUPPORTED_1000baseT_Half
221 | SUPPORTED_1000baseT_Full);
222 }
223
224 ecmd->port = PORT_TP; 227 ecmd->port = PORT_TP;
225 ecmd->phy_address = hw->phy_addr; 228 ecmd->phy_address = hw->phy_addr;
226 } else { 229 } else
227 ecmd->supported = SUPPORTED_1000baseT_Full
228 | SUPPORTED_FIBRE
229 | SUPPORTED_Autoneg;
230
231 ecmd->port = PORT_FIBRE; 230 ecmd->port = PORT_FIBRE;
232 }
233 231
234 ecmd->advertising = skge->advertising; 232 ecmd->advertising = skge->advertising;
235 ecmd->autoneg = skge->autoneg; 233 ecmd->autoneg = skge->autoneg;
@@ -238,65 +236,57 @@ static int skge_get_settings(struct net_device *dev,
238 return 0; 236 return 0;
239} 237}
240 238
241static u32 skge_modes(const struct skge_hw *hw)
242{
243 u32 modes = ADVERTISED_Autoneg
244 | ADVERTISED_1000baseT_Full | ADVERTISED_1000baseT_Half
245 | ADVERTISED_100baseT_Full | ADVERTISED_100baseT_Half
246 | ADVERTISED_10baseT_Full | ADVERTISED_10baseT_Half;
247
248 if (iscopper(hw)) {
249 modes |= ADVERTISED_TP;
250 switch(hw->chip_id) {
251 case CHIP_ID_GENESIS:
252 modes &= ~(ADVERTISED_100baseT_Full
253 | ADVERTISED_100baseT_Half
254 | ADVERTISED_10baseT_Full
255 | ADVERTISED_10baseT_Half);
256 break;
257
258 case CHIP_ID_YUKON:
259 modes &= ~ADVERTISED_1000baseT_Half;
260 break;
261
262 case CHIP_ID_YUKON_FE:
263 modes &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
264 break;
265 }
266 } else {
267 modes |= ADVERTISED_FIBRE;
268 modes &= ~ADVERTISED_1000baseT_Half;
269 }
270 return modes;
271}
272
273static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) 239static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
274{ 240{
275 struct skge_port *skge = netdev_priv(dev); 241 struct skge_port *skge = netdev_priv(dev);
276 const struct skge_hw *hw = skge->hw; 242 const struct skge_hw *hw = skge->hw;
243 u32 supported = skge_supported_modes(hw);
277 244
278 if (ecmd->autoneg == AUTONEG_ENABLE) { 245 if (ecmd->autoneg == AUTONEG_ENABLE) {
279 if (ecmd->advertising & skge_modes(hw)) 246 ecmd->advertising = supported;
280 return -EINVAL; 247 skge->duplex = -1;
248 skge->speed = -1;
281 } else { 249 } else {
250 u32 setting;
251
282 switch(ecmd->speed) { 252 switch(ecmd->speed) {
283 case SPEED_1000: 253 case SPEED_1000:
284 if (hw->chip_id == CHIP_ID_YUKON_FE) 254 if (ecmd->duplex == DUPLEX_FULL)
255 setting = SUPPORTED_1000baseT_Full;
256 else if (ecmd->duplex == DUPLEX_HALF)
257 setting = SUPPORTED_1000baseT_Half;
258 else
285 return -EINVAL; 259 return -EINVAL;
286 break; 260 break;
287 case SPEED_100: 261 case SPEED_100:
262 if (ecmd->duplex == DUPLEX_FULL)
263 setting = SUPPORTED_100baseT_Full;
264 else if (ecmd->duplex == DUPLEX_HALF)
265 setting = SUPPORTED_100baseT_Half;
266 else
267 return -EINVAL;
268 break;
269
288 case SPEED_10: 270 case SPEED_10:
289 if (iscopper(hw) || hw->chip_id == CHIP_ID_GENESIS) 271 if (ecmd->duplex == DUPLEX_FULL)
272 setting = SUPPORTED_10baseT_Full;
273 else if (ecmd->duplex == DUPLEX_HALF)
274 setting = SUPPORTED_10baseT_Half;
275 else
290 return -EINVAL; 276 return -EINVAL;
291 break; 277 break;
292 default: 278 default:
293 return -EINVAL; 279 return -EINVAL;
294 } 280 }
281
282 if ((setting & supported) == 0)
283 return -EINVAL;
284
285 skge->speed = ecmd->speed;
286 skge->duplex = ecmd->duplex;
295 } 287 }
296 288
297 skge->autoneg = ecmd->autoneg; 289 skge->autoneg = ecmd->autoneg;
298 skge->speed = ecmd->speed;
299 skge->duplex = ecmd->duplex;
300 skge->advertising = ecmd->advertising; 290 skge->advertising = ecmd->advertising;
301 291
302 if (netif_running(dev)) { 292 if (netif_running(dev)) {
@@ -393,7 +383,7 @@ static void skge_get_strings(struct net_device *dev, u32 stringset, u8 *data)
393{ 383{
394 int i; 384 int i;
395 385
396 switch(stringset) { 386 switch (stringset) {
397 case ETH_SS_STATS: 387 case ETH_SS_STATS:
398 for (i = 0; i < ARRAY_SIZE(skge_stats); i++) 388 for (i = 0; i < ARRAY_SIZE(skge_stats); i++)
399 memcpy(data + i * ETH_GSTRING_LEN, 389 memcpy(data + i * ETH_GSTRING_LEN,
@@ -511,14 +501,6 @@ static int skge_set_rx_csum(struct net_device *dev, u32 data)
511 return 0; 501 return 0;
512} 502}
513 503
514/* Only Yukon II supports TSO (not implemented yet) */
515static int skge_set_tso(struct net_device *dev, u32 data)
516{
517 if (data)
518 return -EOPNOTSUPP;
519 return 0;
520}
521
522static void skge_get_pauseparam(struct net_device *dev, 504static void skge_get_pauseparam(struct net_device *dev,
523 struct ethtool_pauseparam *ecmd) 505 struct ethtool_pauseparam *ecmd)
524{ 506{
@@ -540,9 +522,9 @@ static int skge_set_pauseparam(struct net_device *dev,
540 skge->autoneg = ecmd->autoneg; 522 skge->autoneg = ecmd->autoneg;
541 if (ecmd->rx_pause && ecmd->tx_pause) 523 if (ecmd->rx_pause && ecmd->tx_pause)
542 skge->flow_control = FLOW_MODE_SYMMETRIC; 524 skge->flow_control = FLOW_MODE_SYMMETRIC;
543 else if(ecmd->rx_pause && !ecmd->tx_pause) 525 else if (ecmd->rx_pause && !ecmd->tx_pause)
544 skge->flow_control = FLOW_MODE_REM_SEND; 526 skge->flow_control = FLOW_MODE_REM_SEND;
545 else if(!ecmd->rx_pause && ecmd->tx_pause) 527 else if (!ecmd->rx_pause && ecmd->tx_pause)
546 skge->flow_control = FLOW_MODE_LOC_SEND; 528 skge->flow_control = FLOW_MODE_LOC_SEND;
547 else 529 else
548 skge->flow_control = FLOW_MODE_NONE; 530 skge->flow_control = FLOW_MODE_NONE;
@@ -559,8 +541,6 @@ static inline u32 hwkhz(const struct skge_hw *hw)
559{ 541{
560 if (hw->chip_id == CHIP_ID_GENESIS) 542 if (hw->chip_id == CHIP_ID_GENESIS)
561 return 53215; /* or: 53.125 MHz */ 543 return 53215; /* or: 53.125 MHz */
562 else if (hw->chip_id == CHIP_ID_YUKON_EC)
563 return 125000; /* or: 125.000 MHz */
564 else 544 else
565 return 78215; /* or: 78.125 MHz */ 545 return 78215; /* or: 78.125 MHz */
566} 546}
@@ -643,30 +623,18 @@ static int skge_set_coalesce(struct net_device *dev,
643static void skge_led_on(struct skge_hw *hw, int port) 623static void skge_led_on(struct skge_hw *hw, int port)
644{ 624{
645 if (hw->chip_id == CHIP_ID_GENESIS) { 625 if (hw->chip_id == CHIP_ID_GENESIS) {
646 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_ON); 626 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
647 skge_write8(hw, B0_LED, LED_STAT_ON); 627 skge_write8(hw, B0_LED, LED_STAT_ON);
648 628
649 skge_write8(hw, SKGEMAC_REG(port, RX_LED_TST), LED_T_ON); 629 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
650 skge_write32(hw, SKGEMAC_REG(port, RX_LED_VAL), 100); 630 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
651 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_START); 631 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
652 632
653 switch (hw->phy_type) { 633 /* For Broadcom Phy only */
654 case SK_PHY_BCOM: 634 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
655 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL,
656 PHY_B_PEC_LED_ON);
657 break;
658 case SK_PHY_LONE:
659 skge_xm_phy_write(hw, port, PHY_LONE_LED_CFG,
660 0x0800);
661 break;
662 default:
663 skge_write8(hw, SKGEMAC_REG(port, TX_LED_TST), LED_T_ON);
664 skge_write32(hw, SKGEMAC_REG(port, TX_LED_VAL), 100);
665 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_START);
666 }
667 } else { 635 } else {
668 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 636 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
669 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, 637 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
670 PHY_M_LED_MO_DUP(MO_LED_ON) | 638 PHY_M_LED_MO_DUP(MO_LED_ON) |
671 PHY_M_LED_MO_10(MO_LED_ON) | 639 PHY_M_LED_MO_10(MO_LED_ON) |
672 PHY_M_LED_MO_100(MO_LED_ON) | 640 PHY_M_LED_MO_100(MO_LED_ON) |
@@ -678,28 +646,17 @@ static void skge_led_on(struct skge_hw *hw, int port)
678static void skge_led_off(struct skge_hw *hw, int port) 646static void skge_led_off(struct skge_hw *hw, int port)
679{ 647{
680 if (hw->chip_id == CHIP_ID_GENESIS) { 648 if (hw->chip_id == CHIP_ID_GENESIS) {
681 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_OFF); 649 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
682 skge_write8(hw, B0_LED, LED_STAT_OFF); 650 skge_write8(hw, B0_LED, LED_STAT_OFF);
683 651
684 skge_write32(hw, SKGEMAC_REG(port, RX_LED_VAL), 0); 652 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
685 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_T_OFF); 653 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
686 654
687 switch (hw->phy_type) { 655 /* Broadcom only */
688 case SK_PHY_BCOM: 656 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
689 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL,
690 PHY_B_PEC_LED_OFF);
691 break;
692 case SK_PHY_LONE:
693 skge_xm_phy_write(hw, port, PHY_LONE_LED_CFG,
694 PHY_L_LC_LEDT);
695 break;
696 default:
697 skge_write32(hw, SKGEMAC_REG(port, TX_LED_VAL), 0);
698 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_T_OFF);
699 }
700 } else { 657 } else {
701 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 658 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
702 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, 659 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
703 PHY_M_LED_MO_DUP(MO_LED_OFF) | 660 PHY_M_LED_MO_DUP(MO_LED_OFF) |
704 PHY_M_LED_MO_10(MO_LED_OFF) | 661 PHY_M_LED_MO_10(MO_LED_OFF) |
705 PHY_M_LED_MO_100(MO_LED_OFF) | 662 PHY_M_LED_MO_100(MO_LED_OFF) |
@@ -730,7 +687,7 @@ static int skge_phys_id(struct net_device *dev, u32 data)
730{ 687{
731 struct skge_port *skge = netdev_priv(dev); 688 struct skge_port *skge = netdev_priv(dev);
732 689
733 if(!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)) 690 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
734 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 691 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
735 692
736 /* start blinking */ 693 /* start blinking */
@@ -763,8 +720,6 @@ static struct ethtool_ops skge_ethtool_ops = {
763 .set_pauseparam = skge_set_pauseparam, 720 .set_pauseparam = skge_set_pauseparam,
764 .get_coalesce = skge_get_coalesce, 721 .get_coalesce = skge_get_coalesce,
765 .set_coalesce = skge_set_coalesce, 722 .set_coalesce = skge_set_coalesce,
766 .get_tso = ethtool_op_get_tso,
767 .set_tso = skge_set_tso,
768 .get_sg = ethtool_op_get_sg, 723 .get_sg = ethtool_op_get_sg,
769 .set_sg = skge_set_sg, 724 .set_sg = skge_set_sg,
770 .get_tx_csum = ethtool_op_get_tx_csum, 725 .get_tx_csum = ethtool_op_get_tx_csum,
@@ -793,6 +748,7 @@ static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base)
793 748
794 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) { 749 for (i = 0, e = ring->start, d = vaddr; i < ring->count; i++, e++, d++) {
795 e->desc = d; 750 e->desc = d;
751 e->skb = NULL;
796 if (i == ring->count - 1) { 752 if (i == ring->count - 1) {
797 e->next = ring->start; 753 e->next = ring->start;
798 d->next_offset = base; 754 d->next_offset = base;
@@ -806,24 +762,23 @@ static int skge_ring_alloc(struct skge_ring *ring, void *vaddr, u64 base)
806 return 0; 762 return 0;
807} 763}
808 764
809/* Setup buffer for receiving */ 765static struct sk_buff *skge_rx_alloc(struct net_device *dev, unsigned int size)
810static inline int skge_rx_alloc(struct skge_port *skge,
811 struct skge_element *e)
812{ 766{
813 unsigned long bufsize = skge->netdev->mtu + ETH_HLEN; /* VLAN? */ 767 struct sk_buff *skb = dev_alloc_skb(size);
814 struct skge_rx_desc *rd = e->desc;
815 struct sk_buff *skb;
816 u64 map;
817 768
818 skb = dev_alloc_skb(bufsize + NET_IP_ALIGN); 769 if (likely(skb)) {
819 if (unlikely(!skb)) { 770 skb->dev = dev;
820 printk(KERN_DEBUG PFX "%s: out of memory for receive\n", 771 skb_reserve(skb, NET_IP_ALIGN);
821 skge->netdev->name);
822 return -ENOMEM;
823 } 772 }
773 return skb;
774}
824 775
825 skb->dev = skge->netdev; 776/* Allocate and setup a new buffer for receiving */
826 skb_reserve(skb, NET_IP_ALIGN); 777static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
778 struct sk_buff *skb, unsigned int bufsize)
779{
780 struct skge_rx_desc *rd = e->desc;
781 u64 map;
827 782
828 map = pci_map_single(skge->hw->pdev, skb->data, bufsize, 783 map = pci_map_single(skge->hw->pdev, skb->data, bufsize,
829 PCI_DMA_FROMDEVICE); 784 PCI_DMA_FROMDEVICE);
@@ -841,55 +796,69 @@ static inline int skge_rx_alloc(struct skge_port *skge,
841 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize; 796 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | bufsize;
842 pci_unmap_addr_set(e, mapaddr, map); 797 pci_unmap_addr_set(e, mapaddr, map);
843 pci_unmap_len_set(e, maplen, bufsize); 798 pci_unmap_len_set(e, maplen, bufsize);
844 return 0;
845} 799}
846 800
847/* Free all unused buffers in receive ring, assumes receiver stopped */ 801/* Resume receiving using existing skb,
802 * Note: DMA address is not changed by chip.
803 * MTU not changed while receiver active.
804 */
805static void skge_rx_reuse(struct skge_element *e, unsigned int size)
806{
807 struct skge_rx_desc *rd = e->desc;
808
809 rd->csum2 = 0;
810 rd->csum2_start = ETH_HLEN;
811
812 wmb();
813
814 rd->control = BMU_OWN | BMU_STF | BMU_IRQ_EOF | BMU_TCP_CHECK | size;
815}
816
817
818/* Free all buffers in receive ring, assumes receiver stopped */
848static void skge_rx_clean(struct skge_port *skge) 819static void skge_rx_clean(struct skge_port *skge)
849{ 820{
850 struct skge_hw *hw = skge->hw; 821 struct skge_hw *hw = skge->hw;
851 struct skge_ring *ring = &skge->rx_ring; 822 struct skge_ring *ring = &skge->rx_ring;
852 struct skge_element *e; 823 struct skge_element *e;
853 824
854 for (e = ring->to_clean; e != ring->to_use; e = e->next) { 825 e = ring->start;
826 do {
855 struct skge_rx_desc *rd = e->desc; 827 struct skge_rx_desc *rd = e->desc;
856 rd->control = 0; 828 rd->control = 0;
857 829 if (e->skb) {
858 pci_unmap_single(hw->pdev, 830 pci_unmap_single(hw->pdev,
859 pci_unmap_addr(e, mapaddr), 831 pci_unmap_addr(e, mapaddr),
860 pci_unmap_len(e, maplen), 832 pci_unmap_len(e, maplen),
861 PCI_DMA_FROMDEVICE); 833 PCI_DMA_FROMDEVICE);
862 dev_kfree_skb(e->skb); 834 dev_kfree_skb(e->skb);
863 e->skb = NULL; 835 e->skb = NULL;
864 } 836 }
865 ring->to_clean = e; 837 } while ((e = e->next) != ring->start);
866} 838}
867 839
840
868/* Allocate buffers for receive ring 841/* Allocate buffers for receive ring
869 * For receive: to_use is refill location 842 * For receive: to_clean is next received frame.
870 * to_clean is next received frame.
871 *
872 * if (to_use == to_clean)
873 * then ring all frames in ring need buffers
874 * if (to_use->next == to_clean)
875 * then ring all frames in ring have buffers
876 */ 843 */
877static int skge_rx_fill(struct skge_port *skge) 844static int skge_rx_fill(struct skge_port *skge)
878{ 845{
879 struct skge_ring *ring = &skge->rx_ring; 846 struct skge_ring *ring = &skge->rx_ring;
880 struct skge_element *e; 847 struct skge_element *e;
881 int ret = 0; 848 unsigned int bufsize = skge->rx_buf_size;
882 849
883 for (e = ring->to_use; e->next != ring->to_clean; e = e->next) { 850 e = ring->start;
884 if (skge_rx_alloc(skge, e)) { 851 do {
885 ret = 1; 852 struct sk_buff *skb = skge_rx_alloc(skge->netdev, bufsize);
886 break;
887 }
888 853
889 } 854 if (!skb)
890 ring->to_use = e; 855 return -ENOMEM;
856
857 skge_rx_setup(skge, e, skb, bufsize);
858 } while ( (e = e->next) != ring->start);
891 859
892 return ret; 860 ring->to_clean = ring->start;
861 return 0;
893} 862}
894 863
895static void skge_link_up(struct skge_port *skge) 864static void skge_link_up(struct skge_port *skge)
@@ -919,50 +888,50 @@ static void skge_link_down(struct skge_port *skge)
919 printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name); 888 printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name);
920} 889}
921 890
922static u16 skge_xm_phy_read(struct skge_hw *hw, int port, u16 reg) 891static u16 xm_phy_read(struct skge_hw *hw, int port, u16 reg)
923{ 892{
924 int i; 893 int i;
925 u16 v; 894 u16 v;
926 895
927 skge_xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 896 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
928 v = skge_xm_read16(hw, port, XM_PHY_DATA); 897 v = xm_read16(hw, port, XM_PHY_DATA);
929 if (hw->phy_type != SK_PHY_XMAC) {
930 for (i = 0; i < PHY_RETRIES; i++) {
931 udelay(1);
932 if (skge_xm_read16(hw, port, XM_MMU_CMD)
933 & XM_MMU_PHY_RDY)
934 goto ready;
935 }
936 898
937 printk(KERN_WARNING PFX "%s: phy read timed out\n", 899 /* Need to wait for external PHY */
938 hw->dev[port]->name); 900 for (i = 0; i < PHY_RETRIES; i++) {
939 return 0; 901 udelay(1);
940 ready: 902 if (xm_read16(hw, port, XM_MMU_CMD)
941 v = skge_xm_read16(hw, port, XM_PHY_DATA); 903 & XM_MMU_PHY_RDY)
904 goto ready;
942 } 905 }
943 906
907 printk(KERN_WARNING PFX "%s: phy read timed out\n",
908 hw->dev[port]->name);
909 return 0;
910 ready:
911 v = xm_read16(hw, port, XM_PHY_DATA);
912
944 return v; 913 return v;
945} 914}
946 915
947static void skge_xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 916static void xm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
948{ 917{
949 int i; 918 int i;
950 919
951 skge_xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr); 920 xm_write16(hw, port, XM_PHY_ADDR, reg | hw->phy_addr);
952 for (i = 0; i < PHY_RETRIES; i++) { 921 for (i = 0; i < PHY_RETRIES; i++) {
953 if (!(skge_xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 922 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
954 goto ready; 923 goto ready;
955 cpu_relax(); 924 udelay(1);
956 } 925 }
957 printk(KERN_WARNING PFX "%s: phy write failed to come ready\n", 926 printk(KERN_WARNING PFX "%s: phy write failed to come ready\n",
958 hw->dev[port]->name); 927 hw->dev[port]->name);
959 928
960 929
961 ready: 930 ready:
962 skge_xm_write16(hw, port, XM_PHY_DATA, val); 931 xm_write16(hw, port, XM_PHY_DATA, val);
963 for (i = 0; i < PHY_RETRIES; i++) { 932 for (i = 0; i < PHY_RETRIES; i++) {
964 udelay(1); 933 udelay(1);
965 if (!(skge_xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY)) 934 if (!(xm_read16(hw, port, XM_MMU_CMD) & XM_MMU_PHY_BUSY))
966 return; 935 return;
967 } 936 }
968 printk(KERN_WARNING PFX "%s: phy write timed out\n", 937 printk(KERN_WARNING PFX "%s: phy write timed out\n",
@@ -999,34 +968,112 @@ static void genesis_init(struct skge_hw *hw)
999 968
1000static void genesis_reset(struct skge_hw *hw, int port) 969static void genesis_reset(struct skge_hw *hw, int port)
1001{ 970{
1002 int i; 971 const u8 zero[8] = { 0 };
1003 u64 zero = 0;
1004 972
1005 /* reset the statistics module */ 973 /* reset the statistics module */
1006 skge_xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT); 974 xm_write32(hw, port, XM_GP_PORT, XM_GP_RES_STAT);
1007 skge_xm_write16(hw, port, XM_IMSK, 0xffff); /* disable XMAC IRQs */ 975 xm_write16(hw, port, XM_IMSK, 0xffff); /* disable XMAC IRQs */
1008 skge_xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */ 976 xm_write32(hw, port, XM_MODE, 0); /* clear Mode Reg */
1009 skge_xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */ 977 xm_write16(hw, port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1010 skge_xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */ 978 xm_write16(hw, port, XM_RX_CMD, 0); /* reset RX CMD Reg */
1011 979
1012 /* disable all PHY IRQs */ 980 /* disable Broadcom PHY IRQ */
1013 if (hw->phy_type == SK_PHY_BCOM) 981 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
1014 skge_xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
1015 982
1016 skge_xm_outhash(hw, port, XM_HSM, (u8 *) &zero); 983 xm_outhash(hw, port, XM_HSM, zero);
1017 for (i = 0; i < 15; i++)
1018 skge_xm_outaddr(hw, port, XM_EXM(i), (u8 *) &zero);
1019 skge_xm_outhash(hw, port, XM_SRC_CHK, (u8 *) &zero);
1020} 984}
1021 985
1022 986
1023static void genesis_mac_init(struct skge_hw *hw, int port) 987/* Convert mode to MII values */
988static const u16 phy_pause_map[] = {
989 [FLOW_MODE_NONE] = 0,
990 [FLOW_MODE_LOC_SEND] = PHY_AN_PAUSE_ASYM,
991 [FLOW_MODE_SYMMETRIC] = PHY_AN_PAUSE_CAP,
992 [FLOW_MODE_REM_SEND] = PHY_AN_PAUSE_CAP | PHY_AN_PAUSE_ASYM,
993};
994
995
996/* Check status of Broadcom phy link */
997static void bcom_check_link(struct skge_hw *hw, int port)
1024{ 998{
1025 struct skge_port *skge = netdev_priv(hw->dev[port]); 999 struct net_device *dev = hw->dev[port];
1000 struct skge_port *skge = netdev_priv(dev);
1001 u16 status;
1002
1003 /* read twice because of latch */
1004 (void) xm_phy_read(hw, port, PHY_BCOM_STAT);
1005 status = xm_phy_read(hw, port, PHY_BCOM_STAT);
1006
1007 pr_debug("bcom_check_link status=0x%x\n", status);
1008
1009 if ((status & PHY_ST_LSYNC) == 0) {
1010 u16 cmd = xm_read16(hw, port, XM_MMU_CMD);
1011 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1012 xm_write16(hw, port, XM_MMU_CMD, cmd);
1013 /* dummy read to ensure writing */
1014 (void) xm_read16(hw, port, XM_MMU_CMD);
1015
1016 if (netif_carrier_ok(dev))
1017 skge_link_down(skge);
1018 } else {
1019 if (skge->autoneg == AUTONEG_ENABLE &&
1020 (status & PHY_ST_AN_OVER)) {
1021 u16 lpa = xm_phy_read(hw, port, PHY_BCOM_AUNE_LP);
1022 u16 aux = xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1023
1024 if (lpa & PHY_B_AN_RF) {
1025 printk(KERN_NOTICE PFX "%s: remote fault\n",
1026 dev->name);
1027 return;
1028 }
1029
1030 /* Check Duplex mismatch */
1031 switch(aux & PHY_B_AS_AN_RES_MSK) {
1032 case PHY_B_RES_1000FD:
1033 skge->duplex = DUPLEX_FULL;
1034 break;
1035 case PHY_B_RES_1000HD:
1036 skge->duplex = DUPLEX_HALF;
1037 break;
1038 default:
1039 printk(KERN_NOTICE PFX "%s: duplex mismatch\n",
1040 dev->name);
1041 return;
1042 }
1043
1044
1045 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
1046 switch (aux & PHY_B_AS_PAUSE_MSK) {
1047 case PHY_B_AS_PAUSE_MSK:
1048 skge->flow_control = FLOW_MODE_SYMMETRIC;
1049 break;
1050 case PHY_B_AS_PRR:
1051 skge->flow_control = FLOW_MODE_REM_SEND;
1052 break;
1053 case PHY_B_AS_PRT:
1054 skge->flow_control = FLOW_MODE_LOC_SEND;
1055 break;
1056 default:
1057 skge->flow_control = FLOW_MODE_NONE;
1058 }
1059
1060 skge->speed = SPEED_1000;
1061 }
1062
1063 if (!netif_carrier_ok(dev))
1064 genesis_link_up(skge);
1065 }
1066}
1067
1068/* Broadcom 5400 only supports giagabit! SysKonnect did not put an additional
1069 * Phy on for 100 or 10Mbit operation
1070 */
1071static void bcom_phy_init(struct skge_port *skge, int jumbo)
1072{
1073 struct skge_hw *hw = skge->hw;
1074 int port = skge->port;
1026 int i; 1075 int i;
1027 u32 r; 1076 u16 id1, r, ext, ctl;
1028 u16 id1;
1029 u16 ctrl1, ctrl2, ctrl3, ctrl4, ctrl5;
1030 1077
1031 /* magic workaround patterns for Broadcom */ 1078 /* magic workaround patterns for Broadcom */
1032 static const struct { 1079 static const struct {
@@ -1042,16 +1089,120 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1042 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 }, 1089 { 0x17, 0x0013 }, { 0x15, 0x0A04 }, { 0x18, 0x0420 },
1043 }; 1090 };
1044 1091
1092 pr_debug("bcom_phy_init\n");
1093
1094 /* read Id from external PHY (all have the same address) */
1095 id1 = xm_phy_read(hw, port, PHY_XMAC_ID1);
1096
1097 /* Optimize MDIO transfer by suppressing preamble. */
1098 r = xm_read16(hw, port, XM_MMU_CMD);
1099 r |= XM_MMU_NO_PRE;
1100 xm_write16(hw, port, XM_MMU_CMD,r);
1101
1102 switch(id1) {
1103 case PHY_BCOM_ID1_C0:
1104 /*
1105 * Workaround BCOM Errata for the C0 type.
1106 * Write magic patterns to reserved registers.
1107 */
1108 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1109 xm_phy_write(hw, port,
1110 C0hack[i].reg, C0hack[i].val);
1111
1112 break;
1113 case PHY_BCOM_ID1_A1:
1114 /*
1115 * Workaround BCOM Errata for the A1 type.
1116 * Write magic patterns to reserved registers.
1117 */
1118 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1119 xm_phy_write(hw, port,
1120 A1hack[i].reg, A1hack[i].val);
1121 break;
1122 }
1123
1124 /*
1125 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1126 * Disable Power Management after reset.
1127 */
1128 r = xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1129 r |= PHY_B_AC_DIS_PM;
1130 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r);
1131
1132 /* Dummy read */
1133 xm_read16(hw, port, XM_ISRC);
1134
1135 ext = PHY_B_PEC_EN_LTR; /* enable tx led */
1136 ctl = PHY_CT_SP1000; /* always 1000mbit */
1137
1138 if (skge->autoneg == AUTONEG_ENABLE) {
1139 /*
1140 * Workaround BCOM Errata #1 for the C5 type.
1141 * 1000Base-T Link Acquisition Failure in Slave Mode
1142 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1143 */
1144 u16 adv = PHY_B_1000C_RD;
1145 if (skge->advertising & ADVERTISED_1000baseT_Half)
1146 adv |= PHY_B_1000C_AHD;
1147 if (skge->advertising & ADVERTISED_1000baseT_Full)
1148 adv |= PHY_B_1000C_AFD;
1149 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, adv);
1150
1151 ctl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1152 } else {
1153 if (skge->duplex == DUPLEX_FULL)
1154 ctl |= PHY_CT_DUP_MD;
1155 /* Force to slave */
1156 xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, PHY_B_1000C_MSE);
1157 }
1158
1159 /* Set autonegotiation pause parameters */
1160 xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV,
1161 phy_pause_map[skge->flow_control] | PHY_AN_CSMA);
1162
1163 /* Handle Jumbo frames */
1164 if (jumbo) {
1165 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1166 PHY_B_AC_TX_TST | PHY_B_AC_LONG_PACK);
1167
1168 ext |= PHY_B_PEC_HIGH_LA;
1169
1170 }
1171
1172 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ext);
1173 xm_phy_write(hw, port, PHY_BCOM_CTRL, ctl);
1174
1175 /* Use link status change interrrupt */
1176 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1177
1178 bcom_check_link(hw, port);
1179}
1180
1181static void genesis_mac_init(struct skge_hw *hw, int port)
1182{
1183 struct net_device *dev = hw->dev[port];
1184 struct skge_port *skge = netdev_priv(dev);
1185 int jumbo = hw->dev[port]->mtu > ETH_DATA_LEN;
1186 int i;
1187 u32 r;
1188 const u8 zero[6] = { 0 };
1189
1190 /* Clear MIB counters */
1191 xm_write16(hw, port, XM_STAT_CMD,
1192 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1193 /* Clear two times according to Errata #3 */
1194 xm_write16(hw, port, XM_STAT_CMD,
1195 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1045 1196
1046 /* initialize Rx, Tx and Link LED */ 1197 /* initialize Rx, Tx and Link LED */
1047 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_ON); 1198 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
1048 skge_write8(hw, SKGEMAC_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON); 1199 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
1049 1200
1050 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_START); 1201 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
1051 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_START); 1202 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
1052 1203
1053 /* Unreset the XMAC. */ 1204 /* Unreset the XMAC. */
1054 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); 1205 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1055 1206
1056 /* 1207 /*
1057 * Perform additional initialization for external PHYs, 1208 * Perform additional initialization for external PHYs,
@@ -1059,67 +1210,56 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1059 * GMII mode. 1210 * GMII mode.
1060 */ 1211 */
1061 spin_lock_bh(&hw->phy_lock); 1212 spin_lock_bh(&hw->phy_lock);
1062 if (hw->phy_type != SK_PHY_XMAC) { 1213 /* Take external Phy out of reset */
1063 /* Take PHY out of reset. */ 1214 r = skge_read32(hw, B2_GP_IO);
1064 r = skge_read32(hw, B2_GP_IO); 1215 if (port == 0)
1065 if (port == 0) 1216 r |= GP_DIR_0|GP_IO_0;
1066 r |= GP_DIR_0|GP_IO_0; 1217 else
1067 else 1218 r |= GP_DIR_2|GP_IO_2;
1068 r |= GP_DIR_2|GP_IO_2;
1069
1070 skge_write32(hw, B2_GP_IO, r);
1071 skge_read32(hw, B2_GP_IO);
1072
1073 /* Enable GMII mode on the XMAC. */
1074 skge_xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1075
1076 id1 = skge_xm_phy_read(hw, port, PHY_XMAC_ID1);
1077
1078 /* Optimize MDIO transfer by suppressing preamble. */
1079 skge_xm_write16(hw, port, XM_MMU_CMD,
1080 skge_xm_read16(hw, port, XM_MMU_CMD)
1081 | XM_MMU_NO_PRE);
1082
1083 if (id1 == PHY_BCOM_ID1_C0) {
1084 /*
1085 * Workaround BCOM Errata for the C0 type.
1086 * Write magic patterns to reserved registers.
1087 */
1088 for (i = 0; i < ARRAY_SIZE(C0hack); i++)
1089 skge_xm_phy_write(hw, port,
1090 C0hack[i].reg, C0hack[i].val);
1091
1092 } else if (id1 == PHY_BCOM_ID1_A1) {
1093 /*
1094 * Workaround BCOM Errata for the A1 type.
1095 * Write magic patterns to reserved registers.
1096 */
1097 for (i = 0; i < ARRAY_SIZE(A1hack); i++)
1098 skge_xm_phy_write(hw, port,
1099 A1hack[i].reg, A1hack[i].val);
1100 }
1101 1219
1102 /* 1220 skge_write32(hw, B2_GP_IO, r);
1103 * Workaround BCOM Errata (#10523) for all BCom PHYs. 1221 skge_read32(hw, B2_GP_IO);
1104 * Disable Power Management after reset. 1222 spin_unlock_bh(&hw->phy_lock);
1105 */
1106 r = skge_xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL);
1107 skge_xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, r | PHY_B_AC_DIS_PM);
1108 }
1109 1223
1110 /* Dummy read */ 1224 /* Enable GMII interfac */
1111 skge_xm_read16(hw, port, XM_ISRC); 1225 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
1226
1227 bcom_phy_init(skge, jumbo);
1228
1229 /* Set Station Address */
1230 xm_outaddr(hw, port, XM_SA, dev->dev_addr);
1231
1232 /* We don't use match addresses so clear */
1233 for (i = 1; i < 16; i++)
1234 xm_outaddr(hw, port, XM_EXM(i), zero);
1112 1235
1113 r = skge_xm_read32(hw, port, XM_MODE); 1236 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1114 skge_xm_write32(hw, port, XM_MODE, r|XM_MD_CSA); 1237 xm_write16(hw, port, XM_RX_HI_WM, 1450);
1115 1238
1116 /* We don't need the FCS appended to the packet. */ 1239 /* We don't need the FCS appended to the packet. */
1117 r = skge_xm_read16(hw, port, XM_RX_CMD); 1240 r = XM_RX_LENERR_OK | XM_RX_STRIP_FCS;
1118 skge_xm_write16(hw, port, XM_RX_CMD, r | XM_RX_STRIP_FCS); 1241 if (jumbo)
1242 r |= XM_RX_BIG_PK_OK;
1243
1244 if (skge->duplex == DUPLEX_HALF) {
1245 /*
1246 * If in manual half duplex mode the other side might be in
1247 * full duplex mode, so ignore if a carrier extension is not seen
1248 * on frames received
1249 */
1250 r |= XM_RX_DIS_CEXT;
1251 }
1252 xm_write16(hw, port, XM_RX_CMD, r);
1253
1119 1254
1120 /* We want short frames padded to 60 bytes. */ 1255 /* We want short frames padded to 60 bytes. */
1121 r = skge_xm_read16(hw, port, XM_TX_CMD); 1256 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1122 skge_xm_write16(hw, port, XM_TX_CMD, r | XM_TX_AUTO_PAD); 1257
1258 /*
1259 * Bump up the transmit threshold. This helps hold off transmit
1260 * underruns when we're blasting traffic from both ports at once.
1261 */
1262 xm_write16(hw, port, XM_TX_THR, 512);
1123 1263
1124 /* 1264 /*
1125 * Enable the reception of all error frames. This is is 1265 * Enable the reception of all error frames. This is is
@@ -1135,19 +1275,22 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1135 * case the XMAC will start transfering frames out of the 1275 * case the XMAC will start transfering frames out of the
1136 * RX FIFO as soon as the FIFO threshold is reached. 1276 * RX FIFO as soon as the FIFO threshold is reached.
1137 */ 1277 */
1138 r = skge_xm_read32(hw, port, XM_MODE); 1278 xm_write32(hw, port, XM_MODE, XM_DEF_MODE);
1139 skge_xm_write32(hw, port, XM_MODE,
1140 XM_MD_RX_CRCE|XM_MD_RX_LONG|XM_MD_RX_RUNT|
1141 XM_MD_RX_ERR|XM_MD_RX_IRLE);
1142 1279
1143 skge_xm_outaddr(hw, port, XM_SA, hw->dev[port]->dev_addr);
1144 skge_xm_outaddr(hw, port, XM_EXM(0), hw->dev[port]->dev_addr);
1145 1280
1146 /* 1281 /*
1147 * Bump up the transmit threshold. This helps hold off transmit 1282 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1148 * underruns when we're blasting traffic from both ports at once. 1283 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1284 * and 'Octets Rx OK Hi Cnt Ov'.
1149 */ 1285 */
1150 skge_xm_write16(hw, port, XM_TX_THR, 512); 1286 xm_write32(hw, port, XM_RX_EV_MSK, XMR_DEF_MSK);
1287
1288 /*
1289 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1290 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1291 * and 'Octets Tx OK Hi Cnt Ov'.
1292 */
1293 xm_write32(hw, port, XM_TX_EV_MSK, XMT_DEF_MSK);
1151 1294
1152 /* Configure MAC arbiter */ 1295 /* Configure MAC arbiter */
1153 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR); 1296 skge_write16(hw, B3_MA_TO_CTRL, MA_RST_CLR);
@@ -1164,137 +1307,30 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1164 skge_write8(hw, B3_MA_RCINI_TX2, 0); 1307 skge_write8(hw, B3_MA_RCINI_TX2, 0);
1165 1308
1166 /* Configure Rx MAC FIFO */ 1309 /* Configure Rx MAC FIFO */
1167 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_RST_CLR); 1310 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_CLR);
1168 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT); 1311 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_TIM_PAT);
1169 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD); 1312 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
1170 1313
1171 /* Configure Tx MAC FIFO */ 1314 /* Configure Tx MAC FIFO */
1172 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_RST_CLR); 1315 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_CLR);
1173 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF); 1316 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
1174 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD); 1317 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
1175 1318
1176 if (hw->dev[port]->mtu > ETH_DATA_LEN) { 1319 if (jumbo) {
1177 /* Enable frame flushing if jumbo frames used */ 1320 /* Enable frame flushing if jumbo frames used */
1178 skge_write16(hw, SKGEMAC_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH); 1321 skge_write16(hw, SK_REG(port,RX_MFF_CTRL1), MFF_ENA_FLUSH);
1179 } else { 1322 } else {
1180 /* enable timeout timers if normal frames */ 1323 /* enable timeout timers if normal frames */
1181 skge_write16(hw, B3_PA_CTRL, 1324 skge_write16(hw, B3_PA_CTRL,
1182 port == 0 ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2); 1325 (port == 0) ? PA_ENA_TO_TX1 : PA_ENA_TO_TX2);
1183 } 1326 }
1184
1185
1186 r = skge_xm_read16(hw, port, XM_RX_CMD);
1187 if (hw->dev[port]->mtu > ETH_DATA_LEN)
1188 skge_xm_write16(hw, port, XM_RX_CMD, r | XM_RX_BIG_PK_OK);
1189 else
1190 skge_xm_write16(hw, port, XM_RX_CMD, r & ~(XM_RX_BIG_PK_OK));
1191
1192 switch (hw->phy_type) {
1193 case SK_PHY_XMAC:
1194 if (skge->autoneg == AUTONEG_ENABLE) {
1195 ctrl1 = PHY_X_AN_FD | PHY_X_AN_HD;
1196
1197 switch (skge->flow_control) {
1198 case FLOW_MODE_NONE:
1199 ctrl1 |= PHY_X_P_NO_PAUSE;
1200 break;
1201 case FLOW_MODE_LOC_SEND:
1202 ctrl1 |= PHY_X_P_ASYM_MD;
1203 break;
1204 case FLOW_MODE_SYMMETRIC:
1205 ctrl1 |= PHY_X_P_SYM_MD;
1206 break;
1207 case FLOW_MODE_REM_SEND:
1208 ctrl1 |= PHY_X_P_BOTH_MD;
1209 break;
1210 }
1211
1212 skge_xm_phy_write(hw, port, PHY_XMAC_AUNE_ADV, ctrl1);
1213 ctrl2 = PHY_CT_ANE | PHY_CT_RE_CFG;
1214 } else {
1215 ctrl2 = 0;
1216 if (skge->duplex == DUPLEX_FULL)
1217 ctrl2 |= PHY_CT_DUP_MD;
1218 }
1219
1220 skge_xm_phy_write(hw, port, PHY_XMAC_CTRL, ctrl2);
1221 break;
1222
1223 case SK_PHY_BCOM:
1224 ctrl1 = PHY_CT_SP1000;
1225 ctrl2 = 0;
1226 ctrl3 = PHY_SEL_TYPE;
1227 ctrl4 = PHY_B_PEC_EN_LTR;
1228 ctrl5 = PHY_B_AC_TX_TST;
1229
1230 if (skge->autoneg == AUTONEG_ENABLE) {
1231 /*
1232 * Workaround BCOM Errata #1 for the C5 type.
1233 * 1000Base-T Link Acquisition Failure in Slave Mode
1234 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
1235 */
1236 ctrl2 |= PHY_B_1000C_RD;
1237 if (skge->advertising & ADVERTISED_1000baseT_Half)
1238 ctrl2 |= PHY_B_1000C_AHD;
1239 if (skge->advertising & ADVERTISED_1000baseT_Full)
1240 ctrl2 |= PHY_B_1000C_AFD;
1241
1242 /* Set Flow-control capabilities */
1243 switch (skge->flow_control) {
1244 case FLOW_MODE_NONE:
1245 ctrl3 |= PHY_B_P_NO_PAUSE;
1246 break;
1247 case FLOW_MODE_LOC_SEND:
1248 ctrl3 |= PHY_B_P_ASYM_MD;
1249 break;
1250 case FLOW_MODE_SYMMETRIC:
1251 ctrl3 |= PHY_B_P_SYM_MD;
1252 break;
1253 case FLOW_MODE_REM_SEND:
1254 ctrl3 |= PHY_B_P_BOTH_MD;
1255 break;
1256 }
1257
1258 /* Restart Auto-negotiation */
1259 ctrl1 |= PHY_CT_ANE | PHY_CT_RE_CFG;
1260 } else {
1261 if (skge->duplex == DUPLEX_FULL)
1262 ctrl1 |= PHY_CT_DUP_MD;
1263
1264 ctrl2 |= PHY_B_1000C_MSE; /* set it to Slave */
1265 }
1266
1267 skge_xm_phy_write(hw, port, PHY_BCOM_1000T_CTRL, ctrl2);
1268 skge_xm_phy_write(hw, port, PHY_BCOM_AUNE_ADV, ctrl3);
1269
1270 if (skge->netdev->mtu > ETH_DATA_LEN) {
1271 ctrl4 |= PHY_B_PEC_HIGH_LA;
1272 ctrl5 |= PHY_B_AC_LONG_PACK;
1273
1274 skge_xm_phy_write(hw, port,PHY_BCOM_AUX_CTRL, ctrl5);
1275 }
1276
1277 skge_xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, ctrl4);
1278 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, ctrl1);
1279 break;
1280 }
1281 spin_unlock_bh(&hw->phy_lock);
1282
1283 /* Clear MIB counters */
1284 skge_xm_write16(hw, port, XM_STAT_CMD,
1285 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1286 /* Clear two times according to Errata #3 */
1287 skge_xm_write16(hw, port, XM_STAT_CMD,
1288 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1289
1290 /* Start polling for link status */
1291 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1292} 1327}
1293 1328
1294static void genesis_stop(struct skge_port *skge) 1329static void genesis_stop(struct skge_port *skge)
1295{ 1330{
1296 struct skge_hw *hw = skge->hw; 1331 struct skge_hw *hw = skge->hw;
1297 int port = skge->port; 1332 int port = skge->port;
1333 u32 reg;
1298 1334
1299 /* Clear Tx packet arbiter timeout IRQ */ 1335 /* Clear Tx packet arbiter timeout IRQ */
1300 skge_write16(hw, B3_PA_CTRL, 1336 skge_write16(hw, B3_PA_CTRL,
@@ -1304,33 +1340,30 @@ static void genesis_stop(struct skge_port *skge)
1304 * If the transfer stucks at the MAC the STOP command will not 1340 * If the transfer stucks at the MAC the STOP command will not
1305 * terminate if we don't flush the XMAC's transmit FIFO ! 1341 * terminate if we don't flush the XMAC's transmit FIFO !
1306 */ 1342 */
1307 skge_xm_write32(hw, port, XM_MODE, 1343 xm_write32(hw, port, XM_MODE,
1308 skge_xm_read32(hw, port, XM_MODE)|XM_MD_FTF); 1344 xm_read32(hw, port, XM_MODE)|XM_MD_FTF);
1309 1345
1310 1346
1311 /* Reset the MAC */ 1347 /* Reset the MAC */
1312 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); 1348 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1313 1349
1314 /* For external PHYs there must be special handling */ 1350 /* For external PHYs there must be special handling */
1315 if (hw->phy_type != SK_PHY_XMAC) { 1351 reg = skge_read32(hw, B2_GP_IO);
1316 u32 reg = skge_read32(hw, B2_GP_IO); 1352 if (port == 0) {
1317 1353 reg |= GP_DIR_0;
1318 if (port == 0) { 1354 reg &= ~GP_IO_0;
1319 reg |= GP_DIR_0; 1355 } else {
1320 reg &= ~GP_IO_0; 1356 reg |= GP_DIR_2;
1321 } else { 1357 reg &= ~GP_IO_2;
1322 reg |= GP_DIR_2;
1323 reg &= ~GP_IO_2;
1324 }
1325 skge_write32(hw, B2_GP_IO, reg);
1326 skge_read32(hw, B2_GP_IO);
1327 } 1358 }
1359 skge_write32(hw, B2_GP_IO, reg);
1360 skge_read32(hw, B2_GP_IO);
1328 1361
1329 skge_xm_write16(hw, port, XM_MMU_CMD, 1362 xm_write16(hw, port, XM_MMU_CMD,
1330 skge_xm_read16(hw, port, XM_MMU_CMD) 1363 xm_read16(hw, port, XM_MMU_CMD)
1331 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX)); 1364 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1332 1365
1333 skge_xm_read16(hw, port, XM_MMU_CMD); 1366 xm_read16(hw, port, XM_MMU_CMD);
1334} 1367}
1335 1368
1336 1369
@@ -1341,11 +1374,11 @@ static void genesis_get_stats(struct skge_port *skge, u64 *data)
1341 int i; 1374 int i;
1342 unsigned long timeout = jiffies + HZ; 1375 unsigned long timeout = jiffies + HZ;
1343 1376
1344 skge_xm_write16(hw, port, 1377 xm_write16(hw, port,
1345 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC); 1378 XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
1346 1379
1347 /* wait for update to complete */ 1380 /* wait for update to complete */
1348 while (skge_xm_read16(hw, port, XM_STAT_CMD) 1381 while (xm_read16(hw, port, XM_STAT_CMD)
1349 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) { 1382 & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) {
1350 if (time_after(jiffies, timeout)) 1383 if (time_after(jiffies, timeout))
1351 break; 1384 break;
@@ -1353,68 +1386,60 @@ static void genesis_get_stats(struct skge_port *skge, u64 *data)
1353 } 1386 }
1354 1387
1355 /* special case for 64 bit octet counter */ 1388 /* special case for 64 bit octet counter */
1356 data[0] = (u64) skge_xm_read32(hw, port, XM_TXO_OK_HI) << 32 1389 data[0] = (u64) xm_read32(hw, port, XM_TXO_OK_HI) << 32
1357 | skge_xm_read32(hw, port, XM_TXO_OK_LO); 1390 | xm_read32(hw, port, XM_TXO_OK_LO);
1358 data[1] = (u64) skge_xm_read32(hw, port, XM_RXO_OK_HI) << 32 1391 data[1] = (u64) xm_read32(hw, port, XM_RXO_OK_HI) << 32
1359 | skge_xm_read32(hw, port, XM_RXO_OK_LO); 1392 | xm_read32(hw, port, XM_RXO_OK_LO);
1360 1393
1361 for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 1394 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
1362 data[i] = skge_xm_read32(hw, port, skge_stats[i].xmac_offset); 1395 data[i] = xm_read32(hw, port, skge_stats[i].xmac_offset);
1363} 1396}
1364 1397
1365static void genesis_mac_intr(struct skge_hw *hw, int port) 1398static void genesis_mac_intr(struct skge_hw *hw, int port)
1366{ 1399{
1367 struct skge_port *skge = netdev_priv(hw->dev[port]); 1400 struct skge_port *skge = netdev_priv(hw->dev[port]);
1368 u16 status = skge_xm_read16(hw, port, XM_ISRC); 1401 u16 status = xm_read16(hw, port, XM_ISRC);
1369 1402
1370 pr_debug("genesis_intr status %x\n", status); 1403 if (netif_msg_intr(skge))
1371 if (hw->phy_type == SK_PHY_XMAC) { 1404 printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
1372 /* LInk down, start polling for state change */ 1405 skge->netdev->name, status);
1373 if (status & XM_IS_INP_ASS) {
1374 skge_xm_write16(hw, port, XM_IMSK,
1375 skge_xm_read16(hw, port, XM_IMSK) | XM_IS_INP_ASS);
1376 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1377 }
1378 else if (status & XM_IS_AND)
1379 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1380 }
1381 1406
1382 if (status & XM_IS_TXF_UR) { 1407 if (status & XM_IS_TXF_UR) {
1383 skge_xm_write32(hw, port, XM_MODE, XM_MD_FTF); 1408 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
1384 ++skge->net_stats.tx_fifo_errors; 1409 ++skge->net_stats.tx_fifo_errors;
1385 } 1410 }
1386 if (status & XM_IS_RXF_OV) { 1411 if (status & XM_IS_RXF_OV) {
1387 skge_xm_write32(hw, port, XM_MODE, XM_MD_FRF); 1412 xm_write32(hw, port, XM_MODE, XM_MD_FRF);
1388 ++skge->net_stats.rx_fifo_errors; 1413 ++skge->net_stats.rx_fifo_errors;
1389 } 1414 }
1390} 1415}
1391 1416
1392static void skge_gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val) 1417static void gm_phy_write(struct skge_hw *hw, int port, u16 reg, u16 val)
1393{ 1418{
1394 int i; 1419 int i;
1395 1420
1396 skge_gma_write16(hw, port, GM_SMI_DATA, val); 1421 gma_write16(hw, port, GM_SMI_DATA, val);
1397 skge_gma_write16(hw, port, GM_SMI_CTRL, 1422 gma_write16(hw, port, GM_SMI_CTRL,
1398 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg)); 1423 GM_SMI_CT_PHY_AD(hw->phy_addr) | GM_SMI_CT_REG_AD(reg));
1399 for (i = 0; i < PHY_RETRIES; i++) { 1424 for (i = 0; i < PHY_RETRIES; i++) {
1400 udelay(1); 1425 udelay(1);
1401 1426
1402 if (!(skge_gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY)) 1427 if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
1403 break; 1428 break;
1404 } 1429 }
1405} 1430}
1406 1431
1407static u16 skge_gm_phy_read(struct skge_hw *hw, int port, u16 reg) 1432static u16 gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1408{ 1433{
1409 int i; 1434 int i;
1410 1435
1411 skge_gma_write16(hw, port, GM_SMI_CTRL, 1436 gma_write16(hw, port, GM_SMI_CTRL,
1412 GM_SMI_CT_PHY_AD(hw->phy_addr) 1437 GM_SMI_CT_PHY_AD(hw->phy_addr)
1413 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD); 1438 | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
1414 1439
1415 for (i = 0; i < PHY_RETRIES; i++) { 1440 for (i = 0; i < PHY_RETRIES; i++) {
1416 udelay(1); 1441 udelay(1);
1417 if (skge_gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) 1442 if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL)
1418 goto ready; 1443 goto ready;
1419 } 1444 }
1420 1445
@@ -1422,24 +1447,7 @@ static u16 skge_gm_phy_read(struct skge_hw *hw, int port, u16 reg)
1422 hw->dev[port]->name); 1447 hw->dev[port]->name);
1423 return 0; 1448 return 0;
1424 ready: 1449 ready:
1425 return skge_gma_read16(hw, port, GM_SMI_DATA); 1450 return gma_read16(hw, port, GM_SMI_DATA);
1426}
1427
1428static void genesis_link_down(struct skge_port *skge)
1429{
1430 struct skge_hw *hw = skge->hw;
1431 int port = skge->port;
1432
1433 pr_debug("genesis_link_down\n");
1434
1435 skge_xm_write16(hw, port, XM_MMU_CMD,
1436 skge_xm_read16(hw, port, XM_MMU_CMD)
1437 & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
1438
1439 /* dummy read to ensure writing */
1440 (void) skge_xm_read16(hw, port, XM_MMU_CMD);
1441
1442 skge_link_down(skge);
1443} 1451}
1444 1452
1445static void genesis_link_up(struct skge_port *skge) 1453static void genesis_link_up(struct skge_port *skge)
@@ -1450,7 +1458,7 @@ static void genesis_link_up(struct skge_port *skge)
1450 u32 mode, msk; 1458 u32 mode, msk;
1451 1459
1452 pr_debug("genesis_link_up\n"); 1460 pr_debug("genesis_link_up\n");
1453 cmd = skge_xm_read16(hw, port, XM_MMU_CMD); 1461 cmd = xm_read16(hw, port, XM_MMU_CMD);
1454 1462
1455 /* 1463 /*
1456 * enabling pause frame reception is required for 1000BT 1464 * enabling pause frame reception is required for 1000BT
@@ -1458,14 +1466,15 @@ static void genesis_link_up(struct skge_port *skge)
1458 */ 1466 */
1459 if (skge->flow_control == FLOW_MODE_NONE || 1467 if (skge->flow_control == FLOW_MODE_NONE ||
1460 skge->flow_control == FLOW_MODE_LOC_SEND) 1468 skge->flow_control == FLOW_MODE_LOC_SEND)
1469 /* Disable Pause Frame Reception */
1461 cmd |= XM_MMU_IGN_PF; 1470 cmd |= XM_MMU_IGN_PF;
1462 else 1471 else
1463 /* Enable Pause Frame Reception */ 1472 /* Enable Pause Frame Reception */
1464 cmd &= ~XM_MMU_IGN_PF; 1473 cmd &= ~XM_MMU_IGN_PF;
1465 1474
1466 skge_xm_write16(hw, port, XM_MMU_CMD, cmd); 1475 xm_write16(hw, port, XM_MMU_CMD, cmd);
1467 1476
1468 mode = skge_xm_read32(hw, port, XM_MODE); 1477 mode = xm_read32(hw, port, XM_MODE);
1469 if (skge->flow_control == FLOW_MODE_SYMMETRIC || 1478 if (skge->flow_control == FLOW_MODE_SYMMETRIC ||
1470 skge->flow_control == FLOW_MODE_LOC_SEND) { 1479 skge->flow_control == FLOW_MODE_LOC_SEND) {
1471 /* 1480 /*
@@ -1479,10 +1488,10 @@ static void genesis_link_up(struct skge_port *skge)
1479 /* XM_PAUSE_DA = '010000C28001' (default) */ 1488 /* XM_PAUSE_DA = '010000C28001' (default) */
1480 /* XM_MAC_PTIME = 0xffff (maximum) */ 1489 /* XM_MAC_PTIME = 0xffff (maximum) */
1481 /* remember this value is defined in big endian (!) */ 1490 /* remember this value is defined in big endian (!) */
1482 skge_xm_write16(hw, port, XM_MAC_PTIME, 0xffff); 1491 xm_write16(hw, port, XM_MAC_PTIME, 0xffff);
1483 1492
1484 mode |= XM_PAUSE_MODE; 1493 mode |= XM_PAUSE_MODE;
1485 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE); 1494 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
1486 } else { 1495 } else {
1487 /* 1496 /*
1488 * disable pause frame generation is required for 1000BT 1497 * disable pause frame generation is required for 1000BT
@@ -1491,125 +1500,68 @@ static void genesis_link_up(struct skge_port *skge)
1491 /* Disable Pause Mode in Mode Register */ 1500 /* Disable Pause Mode in Mode Register */
1492 mode &= ~XM_PAUSE_MODE; 1501 mode &= ~XM_PAUSE_MODE;
1493 1502
1494 skge_write16(hw, SKGEMAC_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE); 1503 skge_write16(hw, SK_REG(port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
1495 } 1504 }
1496 1505
1497 skge_xm_write32(hw, port, XM_MODE, mode); 1506 xm_write32(hw, port, XM_MODE, mode);
1498 1507
1499 msk = XM_DEF_MSK; 1508 msk = XM_DEF_MSK;
1500 if (hw->phy_type != SK_PHY_XMAC) 1509 /* disable GP0 interrupt bit for external Phy */
1501 msk |= XM_IS_INP_ASS; /* disable GP0 interrupt bit */ 1510 msk |= XM_IS_INP_ASS;
1502 1511
1503 skge_xm_write16(hw, port, XM_IMSK, msk); 1512 xm_write16(hw, port, XM_IMSK, msk);
1504 skge_xm_read16(hw, port, XM_ISRC); 1513 xm_read16(hw, port, XM_ISRC);
1505 1514
1506 /* get MMU Command Reg. */ 1515 /* get MMU Command Reg. */
1507 cmd = skge_xm_read16(hw, port, XM_MMU_CMD); 1516 cmd = xm_read16(hw, port, XM_MMU_CMD);
1508 if (hw->phy_type != SK_PHY_XMAC && skge->duplex == DUPLEX_FULL) 1517 if (skge->duplex == DUPLEX_FULL)
1509 cmd |= XM_MMU_GMII_FD; 1518 cmd |= XM_MMU_GMII_FD;
1510 1519
1511 if (hw->phy_type == SK_PHY_BCOM) { 1520 /*
1512 /* 1521 * Workaround BCOM Errata (#10523) for all BCom Phys
1513 * Workaround BCOM Errata (#10523) for all BCom Phys 1522 * Enable Power Management after link up
1514 * Enable Power Management after link up 1523 */
1515 */ 1524 xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL,
1516 skge_xm_phy_write(hw, port, PHY_BCOM_AUX_CTRL, 1525 xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL)
1517 skge_xm_phy_read(hw, port, PHY_BCOM_AUX_CTRL) 1526 & ~PHY_B_AC_DIS_PM);
1518 & ~PHY_B_AC_DIS_PM); 1527 xm_phy_write(hw, port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
1519 skge_xm_phy_write(hw, port, PHY_BCOM_INT_MASK,
1520 PHY_B_DEF_MSK);
1521 }
1522 1528
1523 /* enable Rx/Tx */ 1529 /* enable Rx/Tx */
1524 skge_xm_write16(hw, port, XM_MMU_CMD, 1530 xm_write16(hw, port, XM_MMU_CMD,
1525 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX); 1531 cmd | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1526 skge_link_up(skge); 1532 skge_link_up(skge);
1527} 1533}
1528 1534
1529 1535
1530static void genesis_bcom_intr(struct skge_port *skge) 1536static inline void bcom_phy_intr(struct skge_port *skge)
1531{ 1537{
1532 struct skge_hw *hw = skge->hw; 1538 struct skge_hw *hw = skge->hw;
1533 int port = skge->port; 1539 int port = skge->port;
1534 u16 stat = skge_xm_phy_read(hw, port, PHY_BCOM_INT_STAT); 1540 u16 isrc;
1541
1542 isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
1543 if (netif_msg_intr(skge))
1544 printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x\n",
1545 skge->netdev->name, isrc);
1535 1546
1536 pr_debug("genesis_bcom intr stat=%x\n", stat); 1547 if (isrc & PHY_B_IS_PSE)
1548 printk(KERN_ERR PFX "%s: uncorrectable pair swap error\n",
1549 hw->dev[port]->name);
1537 1550
1538 /* Workaround BCom Errata: 1551 /* Workaround BCom Errata:
1539 * enable and disable loopback mode if "NO HCD" occurs. 1552 * enable and disable loopback mode if "NO HCD" occurs.
1540 */ 1553 */
1541 if (stat & PHY_B_IS_NO_HDCL) { 1554 if (isrc & PHY_B_IS_NO_HDCL) {
1542 u16 ctrl = skge_xm_phy_read(hw, port, PHY_BCOM_CTRL); 1555 u16 ctrl = xm_phy_read(hw, port, PHY_BCOM_CTRL);
1543 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, 1556 xm_phy_write(hw, port, PHY_BCOM_CTRL,
1544 ctrl | PHY_CT_LOOP); 1557 ctrl | PHY_CT_LOOP);
1545 skge_xm_phy_write(hw, port, PHY_BCOM_CTRL, 1558 xm_phy_write(hw, port, PHY_BCOM_CTRL,
1546 ctrl & ~PHY_CT_LOOP); 1559 ctrl & ~PHY_CT_LOOP);
1547 } 1560 }
1548 1561
1549 stat = skge_xm_phy_read(hw, port, PHY_BCOM_STAT); 1562 if (isrc & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE))
1550 if (stat & (PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) { 1563 bcom_check_link(hw, port);
1551 u16 aux = skge_xm_phy_read(hw, port, PHY_BCOM_AUX_STAT);
1552 if ( !(aux & PHY_B_AS_LS) && netif_carrier_ok(skge->netdev))
1553 genesis_link_down(skge);
1554
1555 else if (stat & PHY_B_IS_LST_CHANGE) {
1556 if (aux & PHY_B_AS_AN_C) {
1557 switch (aux & PHY_B_AS_AN_RES_MSK) {
1558 case PHY_B_RES_1000FD:
1559 skge->duplex = DUPLEX_FULL;
1560 break;
1561 case PHY_B_RES_1000HD:
1562 skge->duplex = DUPLEX_HALF;
1563 break;
1564 }
1565
1566 switch (aux & PHY_B_AS_PAUSE_MSK) {
1567 case PHY_B_AS_PAUSE_MSK:
1568 skge->flow_control = FLOW_MODE_SYMMETRIC;
1569 break;
1570 case PHY_B_AS_PRR:
1571 skge->flow_control = FLOW_MODE_REM_SEND;
1572 break;
1573 case PHY_B_AS_PRT:
1574 skge->flow_control = FLOW_MODE_LOC_SEND;
1575 break;
1576 default:
1577 skge->flow_control = FLOW_MODE_NONE;
1578 }
1579 skge->speed = SPEED_1000;
1580 }
1581 genesis_link_up(skge);
1582 }
1583 else
1584 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1585 }
1586}
1587 1564
1588/* Perodic poll of phy status to check for link transistion */
1589static void skge_link_timer(unsigned long __arg)
1590{
1591 struct skge_port *skge = (struct skge_port *) __arg;
1592 struct skge_hw *hw = skge->hw;
1593 int port = skge->port;
1594
1595 if (hw->chip_id != CHIP_ID_GENESIS || !netif_running(skge->netdev))
1596 return;
1597
1598 spin_lock_bh(&hw->phy_lock);
1599 if (hw->phy_type == SK_PHY_BCOM)
1600 genesis_bcom_intr(skge);
1601 else {
1602 int i;
1603 for (i = 0; i < 3; i++)
1604 if (skge_xm_read16(hw, port, XM_ISRC) & XM_IS_INP_ASS)
1605 break;
1606
1607 if (i == 3)
1608 mod_timer(&skge->link_check, jiffies + LINK_POLL_HZ);
1609 else
1610 genesis_link_up(skge);
1611 }
1612 spin_unlock_bh(&hw->phy_lock);
1613} 1565}
1614 1566
1615/* Marvell Phy Initailization */ 1567/* Marvell Phy Initailization */
@@ -1621,31 +1573,27 @@ static void yukon_init(struct skge_hw *hw, int port)
1621 1573
1622 pr_debug("yukon_init\n"); 1574 pr_debug("yukon_init\n");
1623 if (skge->autoneg == AUTONEG_ENABLE) { 1575 if (skge->autoneg == AUTONEG_ENABLE) {
1624 u16 ectrl = skge_gm_phy_read(hw, port, PHY_MARV_EXT_CTRL); 1576 u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
1625 1577
1626 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK | 1578 ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
1627 PHY_M_EC_MAC_S_MSK); 1579 PHY_M_EC_MAC_S_MSK);
1628 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); 1580 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
1629 1581
1630 /* on PHY 88E1111 there is a change for downshift control */ 1582 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
1631 if (hw->chip_id == CHIP_ID_YUKON_EC)
1632 ectrl |= PHY_M_EC_M_DSC_2(0) | PHY_M_EC_DOWN_S_ENA;
1633 else
1634 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
1635 1583
1636 skge_gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); 1584 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
1637 } 1585 }
1638 1586
1639 ctrl = skge_gm_phy_read(hw, port, PHY_MARV_CTRL); 1587 ctrl = gm_phy_read(hw, port, PHY_MARV_CTRL);
1640 if (skge->autoneg == AUTONEG_DISABLE) 1588 if (skge->autoneg == AUTONEG_DISABLE)
1641 ctrl &= ~PHY_CT_ANE; 1589 ctrl &= ~PHY_CT_ANE;
1642 1590
1643 ctrl |= PHY_CT_RESET; 1591 ctrl |= PHY_CT_RESET;
1644 skge_gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 1592 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
1645 1593
1646 ctrl = 0; 1594 ctrl = 0;
1647 ct1000 = 0; 1595 ct1000 = 0;
1648 adv = PHY_SEL_TYPE; 1596 adv = PHY_AN_CSMA;
1649 1597
1650 if (skge->autoneg == AUTONEG_ENABLE) { 1598 if (skge->autoneg == AUTONEG_ENABLE) {
1651 if (iscopper(hw)) { 1599 if (iscopper(hw)) {
@@ -1661,41 +1609,12 @@ static void yukon_init(struct skge_hw *hw, int port)
1661 adv |= PHY_M_AN_10_FD; 1609 adv |= PHY_M_AN_10_FD;
1662 if (skge->advertising & ADVERTISED_10baseT_Half) 1610 if (skge->advertising & ADVERTISED_10baseT_Half)
1663 adv |= PHY_M_AN_10_HD; 1611 adv |= PHY_M_AN_10_HD;
1664 1612 } else /* special defines for FIBER (88E1011S only) */
1665 /* Set Flow-control capabilities */
1666 switch (skge->flow_control) {
1667 case FLOW_MODE_NONE:
1668 adv |= PHY_B_P_NO_PAUSE;
1669 break;
1670 case FLOW_MODE_LOC_SEND:
1671 adv |= PHY_B_P_ASYM_MD;
1672 break;
1673 case FLOW_MODE_SYMMETRIC:
1674 adv |= PHY_B_P_SYM_MD;
1675 break;
1676 case FLOW_MODE_REM_SEND:
1677 adv |= PHY_B_P_BOTH_MD;
1678 break;
1679 }
1680 } else { /* special defines for FIBER (88E1011S only) */
1681 adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD; 1613 adv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD;
1682 1614
1683 /* Set Flow-control capabilities */ 1615 /* Set Flow-control capabilities */
1684 switch (skge->flow_control) { 1616 adv |= phy_pause_map[skge->flow_control];
1685 case FLOW_MODE_NONE: 1617
1686 adv |= PHY_M_P_NO_PAUSE_X;
1687 break;
1688 case FLOW_MODE_LOC_SEND:
1689 adv |= PHY_M_P_ASYM_MD_X;
1690 break;
1691 case FLOW_MODE_SYMMETRIC:
1692 adv |= PHY_M_P_SYM_MD_X;
1693 break;
1694 case FLOW_MODE_REM_SEND:
1695 adv |= PHY_M_P_BOTH_MD_X;
1696 break;
1697 }
1698 }
1699 /* Restart Auto-negotiation */ 1618 /* Restart Auto-negotiation */
1700 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG; 1619 ctrl |= PHY_CT_ANE | PHY_CT_RE_CFG;
1701 } else { 1620 } else {
@@ -1717,36 +1636,23 @@ static void yukon_init(struct skge_hw *hw, int port)
1717 ctrl |= PHY_CT_RESET; 1636 ctrl |= PHY_CT_RESET;
1718 } 1637 }
1719 1638
1720 if (hw->chip_id != CHIP_ID_YUKON_FE) 1639 gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
1721 skge_gm_phy_write(hw, port, PHY_MARV_1000T_CTRL, ct1000);
1722 1640
1723 skge_gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); 1641 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
1724 skge_gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 1642 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
1725 1643
1726 /* Setup Phy LED's */ 1644 /* Setup Phy LED's */
1727 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS); 1645 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
1728 ledover = 0; 1646 ledover = 0;
1729 1647
1730 if (hw->chip_id == CHIP_ID_YUKON_FE) { 1648 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
1731 /* on 88E3082 these bits are at 11..9 (shifted left) */
1732 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) << 1;
1733
1734 skge_gm_phy_write(hw, port, PHY_MARV_FE_LED_PAR,
1735 ((skge_gm_phy_read(hw, port, PHY_MARV_FE_LED_PAR)
1736
1737 & ~PHY_M_FELP_LED1_MSK)
1738 | PHY_M_FELP_LED1_CTRL(LED_PAR_CTRL_ACT_BL)));
1739 } else {
1740 /* set Tx LED (LED_TX) to blink mode on Rx OR Tx activity */
1741 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
1742 1649
1743 /* turn off the Rx LED (LED_RX) */ 1650 /* turn off the Rx LED (LED_RX) */
1744 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF); 1651 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
1745 }
1746 1652
1747 /* disable blink mode (LED_DUPLEX) on collisions */ 1653 /* disable blink mode (LED_DUPLEX) on collisions */
1748 ctrl |= PHY_M_LEDC_DP_CTRL; 1654 ctrl |= PHY_M_LEDC_DP_CTRL;
1749 skge_gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl); 1655 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
1750 1656
1751 if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) { 1657 if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) {
1752 /* turn on 100 Mbps LED (LED_LINK100) */ 1658 /* turn on 100 Mbps LED (LED_LINK100) */
@@ -1754,25 +1660,25 @@ static void yukon_init(struct skge_hw *hw, int port)
1754 } 1660 }
1755 1661
1756 if (ledover) 1662 if (ledover)
1757 skge_gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover); 1663 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
1758 1664
1759 /* Enable phy interrupt on autonegotiation complete (or link up) */ 1665 /* Enable phy interrupt on autonegotiation complete (or link up) */
1760 if (skge->autoneg == AUTONEG_ENABLE) 1666 if (skge->autoneg == AUTONEG_ENABLE)
1761 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); 1667 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL);
1762 else 1668 else
1763 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1669 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1764} 1670}
1765 1671
1766static void yukon_reset(struct skge_hw *hw, int port) 1672static void yukon_reset(struct skge_hw *hw, int port)
1767{ 1673{
1768 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */ 1674 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);/* disable PHY IRQs */
1769 skge_gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */ 1675 gma_write16(hw, port, GM_MC_ADDR_H1, 0); /* clear MC hash */
1770 skge_gma_write16(hw, port, GM_MC_ADDR_H2, 0); 1676 gma_write16(hw, port, GM_MC_ADDR_H2, 0);
1771 skge_gma_write16(hw, port, GM_MC_ADDR_H3, 0); 1677 gma_write16(hw, port, GM_MC_ADDR_H3, 0);
1772 skge_gma_write16(hw, port, GM_MC_ADDR_H4, 0); 1678 gma_write16(hw, port, GM_MC_ADDR_H4, 0);
1773 1679
1774 skge_gma_write16(hw, port, GM_RX_CTRL, 1680 gma_write16(hw, port, GM_RX_CTRL,
1775 skge_gma_read16(hw, port, GM_RX_CTRL) 1681 gma_read16(hw, port, GM_RX_CTRL)
1776 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA); 1682 | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
1777} 1683}
1778 1684
@@ -1785,17 +1691,17 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1785 1691
1786 /* WA code for COMA mode -- set PHY reset */ 1692 /* WA code for COMA mode -- set PHY reset */
1787 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1693 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1788 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1694 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1789 skge_write32(hw, B2_GP_IO, 1695 skge_write32(hw, B2_GP_IO,
1790 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9)); 1696 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9));
1791 1697
1792 /* hard reset */ 1698 /* hard reset */
1793 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), GPC_RST_SET); 1699 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1794 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_RST_SET); 1700 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1795 1701
1796 /* WA code for COMA mode -- clear PHY reset */ 1702 /* WA code for COMA mode -- clear PHY reset */
1797 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1703 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1798 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1704 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1799 skge_write32(hw, B2_GP_IO, 1705 skge_write32(hw, B2_GP_IO,
1800 (skge_read32(hw, B2_GP_IO) | GP_DIR_9) 1706 (skge_read32(hw, B2_GP_IO) | GP_DIR_9)
1801 & ~GP_IO_9); 1707 & ~GP_IO_9);
@@ -1806,13 +1712,13 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1806 reg |= iscopper(hw) ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB; 1712 reg |= iscopper(hw) ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB;
1807 1713
1808 /* Clear GMC reset */ 1714 /* Clear GMC reset */
1809 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), reg | GPC_RST_SET); 1715 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_SET);
1810 skge_write32(hw, SKGEMAC_REG(port, GPHY_CTRL), reg | GPC_RST_CLR); 1716 skge_write32(hw, SK_REG(port, GPHY_CTRL), reg | GPC_RST_CLR);
1811 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR); 1717 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
1812 if (skge->autoneg == AUTONEG_DISABLE) { 1718 if (skge->autoneg == AUTONEG_DISABLE) {
1813 reg = GM_GPCR_AU_ALL_DIS; 1719 reg = GM_GPCR_AU_ALL_DIS;
1814 skge_gma_write16(hw, port, GM_GP_CTRL, 1720 gma_write16(hw, port, GM_GP_CTRL,
1815 skge_gma_read16(hw, port, GM_GP_CTRL) | reg); 1721 gma_read16(hw, port, GM_GP_CTRL) | reg);
1816 1722
1817 switch (skge->speed) { 1723 switch (skge->speed) {
1818 case SPEED_1000: 1724 case SPEED_1000:
@@ -1828,7 +1734,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1828 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL; 1734 reg = GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100 | GM_GPCR_DUP_FULL;
1829 switch (skge->flow_control) { 1735 switch (skge->flow_control) {
1830 case FLOW_MODE_NONE: 1736 case FLOW_MODE_NONE:
1831 skge_write32(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1737 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
1832 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 1738 reg |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
1833 break; 1739 break;
1834 case FLOW_MODE_LOC_SEND: 1740 case FLOW_MODE_LOC_SEND:
@@ -1836,7 +1742,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1836 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; 1742 reg |= GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS;
1837 } 1743 }
1838 1744
1839 skge_gma_write16(hw, port, GM_GP_CTRL, reg); 1745 gma_write16(hw, port, GM_GP_CTRL, reg);
1840 skge_read16(hw, GMAC_IRQ_SRC); 1746 skge_read16(hw, GMAC_IRQ_SRC);
1841 1747
1842 spin_lock_bh(&hw->phy_lock); 1748 spin_lock_bh(&hw->phy_lock);
@@ -1844,25 +1750,25 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1844 spin_unlock_bh(&hw->phy_lock); 1750 spin_unlock_bh(&hw->phy_lock);
1845 1751
1846 /* MIB clear */ 1752 /* MIB clear */
1847 reg = skge_gma_read16(hw, port, GM_PHY_ADDR); 1753 reg = gma_read16(hw, port, GM_PHY_ADDR);
1848 skge_gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); 1754 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
1849 1755
1850 for (i = 0; i < GM_MIB_CNT_SIZE; i++) 1756 for (i = 0; i < GM_MIB_CNT_SIZE; i++)
1851 skge_gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i); 1757 gma_read16(hw, port, GM_MIB_CNT_BASE + 8*i);
1852 skge_gma_write16(hw, port, GM_PHY_ADDR, reg); 1758 gma_write16(hw, port, GM_PHY_ADDR, reg);
1853 1759
1854 /* transmit control */ 1760 /* transmit control */
1855 skge_gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF)); 1761 gma_write16(hw, port, GM_TX_CTRL, TX_COL_THR(TX_COL_DEF));
1856 1762
1857 /* receive control reg: unicast + multicast + no FCS */ 1763 /* receive control reg: unicast + multicast + no FCS */
1858 skge_gma_write16(hw, port, GM_RX_CTRL, 1764 gma_write16(hw, port, GM_RX_CTRL,
1859 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA); 1765 GM_RXCR_UCF_ENA | GM_RXCR_CRC_DIS | GM_RXCR_MCF_ENA);
1860 1766
1861 /* transmit flow control */ 1767 /* transmit flow control */
1862 skge_gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff); 1768 gma_write16(hw, port, GM_TX_FLOW_CTRL, 0xffff);
1863 1769
1864 /* transmit parameter */ 1770 /* transmit parameter */
1865 skge_gma_write16(hw, port, GM_TX_PARAM, 1771 gma_write16(hw, port, GM_TX_PARAM,
1866 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) | 1772 TX_JAM_LEN_VAL(TX_JAM_LEN_DEF) |
1867 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | 1773 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
1868 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); 1774 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
@@ -1872,33 +1778,33 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1872 if (hw->dev[port]->mtu > 1500) 1778 if (hw->dev[port]->mtu > 1500)
1873 reg |= GM_SMOD_JUMBO_ENA; 1779 reg |= GM_SMOD_JUMBO_ENA;
1874 1780
1875 skge_gma_write16(hw, port, GM_SERIAL_MODE, reg); 1781 gma_write16(hw, port, GM_SERIAL_MODE, reg);
1876 1782
1877 /* physical address: used for pause frames */ 1783 /* physical address: used for pause frames */
1878 skge_gm_set_addr(hw, port, GM_SRC_ADDR_1L, addr); 1784 gma_set_addr(hw, port, GM_SRC_ADDR_1L, addr);
1879 /* virtual address for data */ 1785 /* virtual address for data */
1880 skge_gm_set_addr(hw, port, GM_SRC_ADDR_2L, addr); 1786 gma_set_addr(hw, port, GM_SRC_ADDR_2L, addr);
1881 1787
1882 /* enable interrupt mask for counter overflows */ 1788 /* enable interrupt mask for counter overflows */
1883 skge_gma_write16(hw, port, GM_TX_IRQ_MSK, 0); 1789 gma_write16(hw, port, GM_TX_IRQ_MSK, 0);
1884 skge_gma_write16(hw, port, GM_RX_IRQ_MSK, 0); 1790 gma_write16(hw, port, GM_RX_IRQ_MSK, 0);
1885 skge_gma_write16(hw, port, GM_TR_IRQ_MSK, 0); 1791 gma_write16(hw, port, GM_TR_IRQ_MSK, 0);
1886 1792
1887 /* Initialize Mac Fifo */ 1793 /* Initialize Mac Fifo */
1888 1794
1889 /* Configure Rx MAC FIFO */ 1795 /* Configure Rx MAC FIFO */
1890 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK); 1796 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
1891 reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 1797 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
1892 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1798 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1893 chip_rev(hw) == CHIP_REV_YU_LITE_A3) 1799 hw->chip_rev == CHIP_REV_YU_LITE_A3)
1894 reg &= ~GMF_RX_F_FL_ON; 1800 reg &= ~GMF_RX_F_FL_ON;
1895 skge_write8(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 1801 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
1896 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), reg); 1802 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
1897 skge_write16(hw, SKGEMAC_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF); 1803 skge_write16(hw, SK_REG(port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
1898 1804
1899 /* Configure Tx MAC FIFO */ 1805 /* Configure Tx MAC FIFO */
1900 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR); 1806 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
1901 skge_write16(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON); 1807 skge_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
1902} 1808}
1903 1809
1904static void yukon_stop(struct skge_port *skge) 1810static void yukon_stop(struct skge_port *skge)
@@ -1907,19 +1813,19 @@ static void yukon_stop(struct skge_port *skge)
1907 int port = skge->port; 1813 int port = skge->port;
1908 1814
1909 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1815 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1910 chip_rev(hw) == CHIP_REV_YU_LITE_A3) { 1816 hw->chip_rev == CHIP_REV_YU_LITE_A3) {
1911 skge_write32(hw, B2_GP_IO, 1817 skge_write32(hw, B2_GP_IO,
1912 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9); 1818 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9);
1913 } 1819 }
1914 1820
1915 skge_gma_write16(hw, port, GM_GP_CTRL, 1821 gma_write16(hw, port, GM_GP_CTRL,
1916 skge_gma_read16(hw, port, GM_GP_CTRL) 1822 gma_read16(hw, port, GM_GP_CTRL)
1917 & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA)); 1823 & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA));
1918 skge_gma_read16(hw, port, GM_GP_CTRL); 1824 gma_read16(hw, port, GM_GP_CTRL);
1919 1825
1920 /* set GPHY Control reset */ 1826 /* set GPHY Control reset */
1921 skge_gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET); 1827 gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET);
1922 skge_gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET); 1828 gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET);
1923} 1829}
1924 1830
1925static void yukon_get_stats(struct skge_port *skge, u64 *data) 1831static void yukon_get_stats(struct skge_port *skge, u64 *data)
@@ -1928,39 +1834,40 @@ static void yukon_get_stats(struct skge_port *skge, u64 *data)
1928 int port = skge->port; 1834 int port = skge->port;
1929 int i; 1835 int i;
1930 1836
1931 data[0] = (u64) skge_gma_read32(hw, port, GM_TXO_OK_HI) << 32 1837 data[0] = (u64) gma_read32(hw, port, GM_TXO_OK_HI) << 32
1932 | skge_gma_read32(hw, port, GM_TXO_OK_LO); 1838 | gma_read32(hw, port, GM_TXO_OK_LO);
1933 data[1] = (u64) skge_gma_read32(hw, port, GM_RXO_OK_HI) << 32 1839 data[1] = (u64) gma_read32(hw, port, GM_RXO_OK_HI) << 32
1934 | skge_gma_read32(hw, port, GM_RXO_OK_LO); 1840 | gma_read32(hw, port, GM_RXO_OK_LO);
1935 1841
1936 for (i = 2; i < ARRAY_SIZE(skge_stats); i++) 1842 for (i = 2; i < ARRAY_SIZE(skge_stats); i++)
1937 data[i] = skge_gma_read32(hw, port, 1843 data[i] = gma_read32(hw, port,
1938 skge_stats[i].gma_offset); 1844 skge_stats[i].gma_offset);
1939} 1845}
1940 1846
1941static void yukon_mac_intr(struct skge_hw *hw, int port) 1847static void yukon_mac_intr(struct skge_hw *hw, int port)
1942{ 1848{
1943 struct skge_port *skge = netdev_priv(hw->dev[port]); 1849 struct net_device *dev = hw->dev[port];
1944 u8 status = skge_read8(hw, SKGEMAC_REG(port, GMAC_IRQ_SRC)); 1850 struct skge_port *skge = netdev_priv(dev);
1851 u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
1852
1853 if (netif_msg_intr(skge))
1854 printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
1855 dev->name, status);
1945 1856
1946 pr_debug("yukon_intr status %x\n", status);
1947 if (status & GM_IS_RX_FF_OR) { 1857 if (status & GM_IS_RX_FF_OR) {
1948 ++skge->net_stats.rx_fifo_errors; 1858 ++skge->net_stats.rx_fifo_errors;
1949 skge_gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO); 1859 gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO);
1950 } 1860 }
1951 if (status & GM_IS_TX_FF_UR) { 1861 if (status & GM_IS_TX_FF_UR) {
1952 ++skge->net_stats.tx_fifo_errors; 1862 ++skge->net_stats.tx_fifo_errors;
1953 skge_gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU); 1863 gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU);
1954 } 1864 }
1955 1865
1956} 1866}
1957 1867
1958static u16 yukon_speed(const struct skge_hw *hw, u16 aux) 1868static u16 yukon_speed(const struct skge_hw *hw, u16 aux)
1959{ 1869{
1960 if (hw->chip_id == CHIP_ID_YUKON_FE) 1870 switch (aux & PHY_M_PS_SPEED_MSK) {
1961 return (aux & PHY_M_PS_SPEED_100) ? SPEED_100 : SPEED_10;
1962
1963 switch(aux & PHY_M_PS_SPEED_MSK) {
1964 case PHY_M_PS_SPEED_1000: 1871 case PHY_M_PS_SPEED_1000:
1965 return SPEED_1000; 1872 return SPEED_1000;
1966 case PHY_M_PS_SPEED_100: 1873 case PHY_M_PS_SPEED_100:
@@ -1981,15 +1888,15 @@ static void yukon_link_up(struct skge_port *skge)
1981 /* Enable Transmit FIFO Underrun */ 1888 /* Enable Transmit FIFO Underrun */
1982 skge_write8(hw, GMAC_IRQ_MSK, GMAC_DEF_MSK); 1889 skge_write8(hw, GMAC_IRQ_MSK, GMAC_DEF_MSK);
1983 1890
1984 reg = skge_gma_read16(hw, port, GM_GP_CTRL); 1891 reg = gma_read16(hw, port, GM_GP_CTRL);
1985 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE) 1892 if (skge->duplex == DUPLEX_FULL || skge->autoneg == AUTONEG_ENABLE)
1986 reg |= GM_GPCR_DUP_FULL; 1893 reg |= GM_GPCR_DUP_FULL;
1987 1894
1988 /* enable Rx/Tx */ 1895 /* enable Rx/Tx */
1989 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; 1896 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
1990 skge_gma_write16(hw, port, GM_GP_CTRL, reg); 1897 gma_write16(hw, port, GM_GP_CTRL, reg);
1991 1898
1992 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1899 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
1993 skge_link_up(skge); 1900 skge_link_up(skge);
1994} 1901}
1995 1902
@@ -1999,16 +1906,15 @@ static void yukon_link_down(struct skge_port *skge)
1999 int port = skge->port; 1906 int port = skge->port;
2000 1907
2001 pr_debug("yukon_link_down\n"); 1908 pr_debug("yukon_link_down\n");
2002 skge_gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); 1909 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
2003 skge_gm_phy_write(hw, port, GM_GP_CTRL, 1910 gm_phy_write(hw, port, GM_GP_CTRL,
2004 skge_gm_phy_read(hw, port, GM_GP_CTRL) 1911 gm_phy_read(hw, port, GM_GP_CTRL)
2005 & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA)); 1912 & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA));
2006 1913
2007 if (hw->chip_id != CHIP_ID_YUKON_FE && 1914 if (skge->flow_control == FLOW_MODE_REM_SEND) {
2008 skge->flow_control == FLOW_MODE_REM_SEND) {
2009 /* restore Asymmetric Pause bit */ 1915 /* restore Asymmetric Pause bit */
2010 skge_gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, 1916 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
2011 skge_gm_phy_read(hw, port, 1917 gm_phy_read(hw, port,
2012 PHY_MARV_AUNE_ADV) 1918 PHY_MARV_AUNE_ADV)
2013 | PHY_M_AN_ASP); 1919 | PHY_M_AN_ASP);
2014 1920
@@ -2027,20 +1933,21 @@ static void yukon_phy_intr(struct skge_port *skge)
2027 const char *reason = NULL; 1933 const char *reason = NULL;
2028 u16 istatus, phystat; 1934 u16 istatus, phystat;
2029 1935
2030 istatus = skge_gm_phy_read(hw, port, PHY_MARV_INT_STAT); 1936 istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
2031 phystat = skge_gm_phy_read(hw, port, PHY_MARV_PHY_STAT); 1937 phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
2032 pr_debug("yukon phy intr istat=%x phy_stat=%x\n", istatus, phystat); 1938
1939 if (netif_msg_intr(skge))
1940 printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x 0x%x\n",
1941 skge->netdev->name, istatus, phystat);
2033 1942
2034 if (istatus & PHY_M_IS_AN_COMPL) { 1943 if (istatus & PHY_M_IS_AN_COMPL) {
2035 if (skge_gm_phy_read(hw, port, PHY_MARV_AUNE_LP) 1944 if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
2036 & PHY_M_AN_RF) { 1945 & PHY_M_AN_RF) {
2037 reason = "remote fault"; 1946 reason = "remote fault";
2038 goto failed; 1947 goto failed;
2039 } 1948 }
2040 1949
2041 if (!(hw->chip_id == CHIP_ID_YUKON_FE || hw->chip_id == CHIP_ID_YUKON_EC) 1950 if (gm_phy_read(hw, port, PHY_MARV_1000T_STAT) & PHY_B_1000S_MSF) {
2042 && (skge_gm_phy_read(hw, port, PHY_MARV_1000T_STAT)
2043 & PHY_B_1000S_MSF)) {
2044 reason = "master/slave fault"; 1951 reason = "master/slave fault";
2045 goto failed; 1952 goto failed;
2046 } 1953 }
@@ -2054,10 +1961,6 @@ static void yukon_phy_intr(struct skge_port *skge)
2054 ? DUPLEX_FULL : DUPLEX_HALF; 1961 ? DUPLEX_FULL : DUPLEX_HALF;
2055 skge->speed = yukon_speed(hw, phystat); 1962 skge->speed = yukon_speed(hw, phystat);
2056 1963
2057 /* Tx & Rx Pause Enabled bits are at 9..8 */
2058 if (hw->chip_id == CHIP_ID_YUKON_XL)
2059 phystat >>= 6;
2060
2061 /* We are using IEEE 802.3z/D5.0 Table 37-4 */ 1964 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2062 switch (phystat & PHY_M_PS_PAUSE_MSK) { 1965 switch (phystat & PHY_M_PS_PAUSE_MSK) {
2063 case PHY_M_PS_PAUSE_MSK: 1966 case PHY_M_PS_PAUSE_MSK:
@@ -2075,9 +1978,9 @@ static void yukon_phy_intr(struct skge_port *skge)
2075 1978
2076 if (skge->flow_control == FLOW_MODE_NONE || 1979 if (skge->flow_control == FLOW_MODE_NONE ||
2077 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF)) 1980 (skge->speed < SPEED_1000 && skge->duplex == DUPLEX_HALF))
2078 skge_write8(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1981 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
2079 else 1982 else
2080 skge_write8(hw, SKGEMAC_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 1983 skge_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
2081 yukon_link_up(skge); 1984 yukon_link_up(skge);
2082 return; 1985 return;
2083 } 1986 }
@@ -2161,6 +2064,12 @@ static int skge_up(struct net_device *dev)
2161 if (netif_msg_ifup(skge)) 2064 if (netif_msg_ifup(skge))
2162 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); 2065 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
2163 2066
2067 if (dev->mtu > RX_BUF_SIZE)
2068 skge->rx_buf_size = dev->mtu + ETH_HLEN + NET_IP_ALIGN;
2069 else
2070 skge->rx_buf_size = RX_BUF_SIZE;
2071
2072
2164 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc); 2073 rx_size = skge->rx_ring.count * sizeof(struct skge_rx_desc);
2165 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc); 2074 tx_size = skge->tx_ring.count * sizeof(struct skge_tx_desc);
2166 skge->mem_size = tx_size + rx_size; 2075 skge->mem_size = tx_size + rx_size;
@@ -2173,7 +2082,8 @@ static int skge_up(struct net_device *dev)
2173 if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma))) 2082 if ((err = skge_ring_alloc(&skge->rx_ring, skge->mem, skge->dma)))
2174 goto free_pci_mem; 2083 goto free_pci_mem;
2175 2084
2176 if (skge_rx_fill(skge)) 2085 err = skge_rx_fill(skge);
2086 if (err)
2177 goto free_rx_ring; 2087 goto free_rx_ring;
2178 2088
2179 if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size, 2089 if ((err = skge_ring_alloc(&skge->tx_ring, skge->mem + rx_size,
@@ -2182,6 +2092,10 @@ static int skge_up(struct net_device *dev)
2182 2092
2183 skge->tx_avail = skge->tx_ring.count - 1; 2093 skge->tx_avail = skge->tx_ring.count - 1;
2184 2094
2095 /* Enable IRQ from port */
2096 hw->intr_mask |= portirqmask[port];
2097 skge_write32(hw, B0_IMSK, hw->intr_mask);
2098
2185 /* Initialze MAC */ 2099 /* Initialze MAC */
2186 if (hw->chip_id == CHIP_ID_GENESIS) 2100 if (hw->chip_id == CHIP_ID_GENESIS)
2187 genesis_mac_init(hw, port); 2101 genesis_mac_init(hw, port);
@@ -2189,7 +2103,7 @@ static int skge_up(struct net_device *dev)
2189 yukon_mac_init(hw, port); 2103 yukon_mac_init(hw, port);
2190 2104
2191 /* Configure RAMbuffers */ 2105 /* Configure RAMbuffers */
2192 chunk = hw->ram_size / (isdualport(hw) ? 4 : 2); 2106 chunk = hw->ram_size / ((hw->ports + 1)*2);
2193 ram_addr = hw->ram_offset + 2 * chunk * port; 2107 ram_addr = hw->ram_offset + 2 * chunk * port;
2194 2108
2195 skge_ramset(hw, rxqaddr[port], ram_addr, chunk); 2109 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
@@ -2227,7 +2141,6 @@ static int skge_down(struct net_device *dev)
2227 netif_stop_queue(dev); 2141 netif_stop_queue(dev);
2228 2142
2229 del_timer_sync(&skge->led_blink); 2143 del_timer_sync(&skge->led_blink);
2230 del_timer_sync(&skge->link_check);
2231 2144
2232 /* Stop transmitter */ 2145 /* Stop transmitter */
2233 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); 2146 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
@@ -2240,12 +2153,12 @@ static int skge_down(struct net_device *dev)
2240 yukon_stop(skge); 2153 yukon_stop(skge);
2241 2154
2242 /* Disable Force Sync bit and Enable Alloc bit */ 2155 /* Disable Force Sync bit and Enable Alloc bit */
2243 skge_write8(hw, SKGEMAC_REG(port, TXA_CTRL), 2156 skge_write8(hw, SK_REG(port, TXA_CTRL),
2244 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC); 2157 TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
2245 2158
2246 /* Stop Interval Timer and Limit Counter of Tx Arbiter */ 2159 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
2247 skge_write32(hw, SKGEMAC_REG(port, TXA_ITI_INI), 0L); 2160 skge_write32(hw, SK_REG(port, TXA_ITI_INI), 0L);
2248 skge_write32(hw, SKGEMAC_REG(port, TXA_LIM_INI), 0L); 2161 skge_write32(hw, SK_REG(port, TXA_LIM_INI), 0L);
2249 2162
2250 /* Reset PCI FIFO */ 2163 /* Reset PCI FIFO */
2251 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET); 2164 skge_write32(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_SET_RESET);
@@ -2260,13 +2173,13 @@ static int skge_down(struct net_device *dev)
2260 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET); 2173 skge_write32(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_SET_RESET);
2261 2174
2262 if (hw->chip_id == CHIP_ID_GENESIS) { 2175 if (hw->chip_id == CHIP_ID_GENESIS) {
2263 skge_write8(hw, SKGEMAC_REG(port, TX_MFF_CTRL2), MFF_RST_SET); 2176 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2264 skge_write8(hw, SKGEMAC_REG(port, RX_MFF_CTRL2), MFF_RST_SET); 2177 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
2265 skge_write8(hw, SKGEMAC_REG(port, TX_LED_CTRL), LED_STOP); 2178 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_STOP);
2266 skge_write8(hw, SKGEMAC_REG(port, RX_LED_CTRL), LED_STOP); 2179 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_STOP);
2267 } else { 2180 } else {
2268 skge_write8(hw, SKGEMAC_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 2181 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2269 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 2182 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
2270 } 2183 }
2271 2184
2272 /* turn off led's */ 2185 /* turn off led's */
@@ -2299,10 +2212,10 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2299 2212
2300 local_irq_save(flags); 2213 local_irq_save(flags);
2301 if (!spin_trylock(&skge->tx_lock)) { 2214 if (!spin_trylock(&skge->tx_lock)) {
2302 /* Collision - tell upper layer to requeue */ 2215 /* Collision - tell upper layer to requeue */
2303 local_irq_restore(flags); 2216 local_irq_restore(flags);
2304 return NETDEV_TX_LOCKED; 2217 return NETDEV_TX_LOCKED;
2305 } 2218 }
2306 2219
2307 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) { 2220 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) {
2308 netif_stop_queue(dev); 2221 netif_stop_queue(dev);
@@ -2333,7 +2246,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2333 * does. Looks like hardware is wrong? 2246 * does. Looks like hardware is wrong?
2334 */ 2247 */
2335 if (ip->protocol == IPPROTO_UDP 2248 if (ip->protocol == IPPROTO_UDP
2336 && chip_rev(hw) == 0 && hw->chip_id == CHIP_ID_YUKON) 2249 && hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
2337 control = BMU_TCP_CHECK; 2250 control = BMU_TCP_CHECK;
2338 else 2251 else
2339 control = BMU_UDP_CHECK; 2252 control = BMU_UDP_CHECK;
@@ -2394,6 +2307,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2394 2307
2395static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e) 2308static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e)
2396{ 2309{
2310 /* This ring element can be skb or fragment */
2397 if (e->skb) { 2311 if (e->skb) {
2398 pci_unmap_single(hw->pdev, 2312 pci_unmap_single(hw->pdev,
2399 pci_unmap_addr(e, mapaddr), 2313 pci_unmap_addr(e, mapaddr),
@@ -2438,16 +2352,17 @@ static void skge_tx_timeout(struct net_device *dev)
2438static int skge_change_mtu(struct net_device *dev, int new_mtu) 2352static int skge_change_mtu(struct net_device *dev, int new_mtu)
2439{ 2353{
2440 int err = 0; 2354 int err = 0;
2355 int running = netif_running(dev);
2441 2356
2442 if(new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) 2357 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
2443 return -EINVAL; 2358 return -EINVAL;
2444 2359
2445 dev->mtu = new_mtu;
2446 2360
2447 if (netif_running(dev)) { 2361 if (running)
2448 skge_down(dev); 2362 skge_down(dev);
2363 dev->mtu = new_mtu;
2364 if (running)
2449 skge_up(dev); 2365 skge_up(dev);
2450 }
2451 2366
2452 return err; 2367 return err;
2453} 2368}
@@ -2462,7 +2377,9 @@ static void genesis_set_multicast(struct net_device *dev)
2462 u32 mode; 2377 u32 mode;
2463 u8 filter[8]; 2378 u8 filter[8];
2464 2379
2465 mode = skge_xm_read32(hw, port, XM_MODE); 2380 pr_debug("genesis_set_multicast flags=%x count=%d\n", dev->flags, dev->mc_count);
2381
2382 mode = xm_read32(hw, port, XM_MODE);
2466 mode |= XM_MD_ENA_HASH; 2383 mode |= XM_MD_ENA_HASH;
2467 if (dev->flags & IFF_PROMISC) 2384 if (dev->flags & IFF_PROMISC)
2468 mode |= XM_MD_ENA_PROM; 2385 mode |= XM_MD_ENA_PROM;
@@ -2473,17 +2390,16 @@ static void genesis_set_multicast(struct net_device *dev)
2473 memset(filter, 0xff, sizeof(filter)); 2390 memset(filter, 0xff, sizeof(filter));
2474 else { 2391 else {
2475 memset(filter, 0, sizeof(filter)); 2392 memset(filter, 0, sizeof(filter));
2476 for(i = 0; list && i < count; i++, list = list->next) { 2393 for (i = 0; list && i < count; i++, list = list->next) {
2477 u32 crc = crc32_le(~0, list->dmi_addr, ETH_ALEN); 2394 u32 crc, bit;
2478 u8 bit = 63 - (crc & 63); 2395 crc = ether_crc_le(ETH_ALEN, list->dmi_addr);
2479 2396 bit = ~crc & 0x3f;
2480 filter[bit/8] |= 1 << (bit%8); 2397 filter[bit/8] |= 1 << (bit%8);
2481 } 2398 }
2482 } 2399 }
2483 2400
2484 skge_xm_outhash(hw, port, XM_HSM, filter); 2401 xm_write32(hw, port, XM_MODE, mode);
2485 2402 xm_outhash(hw, port, XM_HSM, filter);
2486 skge_xm_write32(hw, port, XM_MODE, mode);
2487} 2403}
2488 2404
2489static void yukon_set_multicast(struct net_device *dev) 2405static void yukon_set_multicast(struct net_device *dev)
@@ -2497,7 +2413,7 @@ static void yukon_set_multicast(struct net_device *dev)
2497 2413
2498 memset(filter, 0, sizeof(filter)); 2414 memset(filter, 0, sizeof(filter));
2499 2415
2500 reg = skge_gma_read16(hw, port, GM_RX_CTRL); 2416 reg = gma_read16(hw, port, GM_RX_CTRL);
2501 reg |= GM_RXCR_UCF_ENA; 2417 reg |= GM_RXCR_UCF_ENA;
2502 2418
2503 if (dev->flags & IFF_PROMISC) /* promiscious */ 2419 if (dev->flags & IFF_PROMISC) /* promiscious */
@@ -2510,23 +2426,23 @@ static void yukon_set_multicast(struct net_device *dev)
2510 int i; 2426 int i;
2511 reg |= GM_RXCR_MCF_ENA; 2427 reg |= GM_RXCR_MCF_ENA;
2512 2428
2513 for(i = 0; list && i < dev->mc_count; i++, list = list->next) { 2429 for (i = 0; list && i < dev->mc_count; i++, list = list->next) {
2514 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f; 2430 u32 bit = ether_crc(ETH_ALEN, list->dmi_addr) & 0x3f;
2515 filter[bit/8] |= 1 << (bit%8); 2431 filter[bit/8] |= 1 << (bit%8);
2516 } 2432 }
2517 } 2433 }
2518 2434
2519 2435
2520 skge_gma_write16(hw, port, GM_MC_ADDR_H1, 2436 gma_write16(hw, port, GM_MC_ADDR_H1,
2521 (u16)filter[0] | ((u16)filter[1] << 8)); 2437 (u16)filter[0] | ((u16)filter[1] << 8));
2522 skge_gma_write16(hw, port, GM_MC_ADDR_H2, 2438 gma_write16(hw, port, GM_MC_ADDR_H2,
2523 (u16)filter[2] | ((u16)filter[3] << 8)); 2439 (u16)filter[2] | ((u16)filter[3] << 8));
2524 skge_gma_write16(hw, port, GM_MC_ADDR_H3, 2440 gma_write16(hw, port, GM_MC_ADDR_H3,
2525 (u16)filter[4] | ((u16)filter[5] << 8)); 2441 (u16)filter[4] | ((u16)filter[5] << 8));
2526 skge_gma_write16(hw, port, GM_MC_ADDR_H4, 2442 gma_write16(hw, port, GM_MC_ADDR_H4,
2527 (u16)filter[6] | ((u16)filter[7] << 8)); 2443 (u16)filter[6] | ((u16)filter[7] << 8));
2528 2444
2529 skge_gma_write16(hw, port, GM_RX_CTRL, reg); 2445 gma_write16(hw, port, GM_RX_CTRL, reg);
2530} 2446}
2531 2447
2532static inline int bad_phy_status(const struct skge_hw *hw, u32 status) 2448static inline int bad_phy_status(const struct skge_hw *hw, u32 status)
@@ -2545,28 +2461,76 @@ static void skge_rx_error(struct skge_port *skge, int slot,
2545 printk(KERN_DEBUG PFX "%s: rx err, slot %d control 0x%x status 0x%x\n", 2461 printk(KERN_DEBUG PFX "%s: rx err, slot %d control 0x%x status 0x%x\n",
2546 skge->netdev->name, slot, control, status); 2462 skge->netdev->name, slot, control, status);
2547 2463
2548 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) 2464 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF))
2549 || (control & BMU_BBC) > skge->netdev->mtu + VLAN_ETH_HLEN)
2550 skge->net_stats.rx_length_errors++; 2465 skge->net_stats.rx_length_errors++;
2551 else { 2466 else if (skge->hw->chip_id == CHIP_ID_GENESIS) {
2552 if (skge->hw->chip_id == CHIP_ID_GENESIS) { 2467 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
2553 if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR)) 2468 skge->net_stats.rx_length_errors++;
2554 skge->net_stats.rx_length_errors++; 2469 if (status & XMR_FS_FRA_ERR)
2555 if (status & XMR_FS_FRA_ERR) 2470 skge->net_stats.rx_frame_errors++;
2556 skge->net_stats.rx_frame_errors++; 2471 if (status & XMR_FS_FCS_ERR)
2557 if (status & XMR_FS_FCS_ERR) 2472 skge->net_stats.rx_crc_errors++;
2558 skge->net_stats.rx_crc_errors++; 2473 } else {
2559 } else { 2474 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE))
2560 if (status & (GMR_FS_LONG_ERR|GMR_FS_UN_SIZE)) 2475 skge->net_stats.rx_length_errors++;
2561 skge->net_stats.rx_length_errors++; 2476 if (status & GMR_FS_FRAGMENT)
2562 if (status & GMR_FS_FRAGMENT) 2477 skge->net_stats.rx_frame_errors++;
2563 skge->net_stats.rx_frame_errors++; 2478 if (status & GMR_FS_CRC_ERR)
2564 if (status & GMR_FS_CRC_ERR) 2479 skge->net_stats.rx_crc_errors++;
2565 skge->net_stats.rx_crc_errors++; 2480 }
2481}
2482
2483/* Get receive buffer from descriptor.
2484 * Handles copy of small buffers and reallocation failures
2485 */
2486static inline struct sk_buff *skge_rx_get(struct skge_port *skge,
2487 struct skge_element *e,
2488 unsigned int len)
2489{
2490 struct sk_buff *nskb, *skb;
2491
2492 if (len < RX_COPY_THRESHOLD) {
2493 nskb = skge_rx_alloc(skge->netdev, len + NET_IP_ALIGN);
2494 if (unlikely(!nskb))
2495 return NULL;
2496
2497 pci_dma_sync_single_for_cpu(skge->hw->pdev,
2498 pci_unmap_addr(e, mapaddr),
2499 len, PCI_DMA_FROMDEVICE);
2500 memcpy(nskb->data, e->skb->data, len);
2501 pci_dma_sync_single_for_device(skge->hw->pdev,
2502 pci_unmap_addr(e, mapaddr),
2503 len, PCI_DMA_FROMDEVICE);
2504
2505 if (skge->rx_csum) {
2506 struct skge_rx_desc *rd = e->desc;
2507 nskb->csum = le16_to_cpu(rd->csum2);
2508 nskb->ip_summed = CHECKSUM_HW;
2566 } 2509 }
2510 skge_rx_reuse(e, skge->rx_buf_size);
2511 return nskb;
2512 } else {
2513 nskb = skge_rx_alloc(skge->netdev, skge->rx_buf_size);
2514 if (unlikely(!nskb))
2515 return NULL;
2516
2517 pci_unmap_single(skge->hw->pdev,
2518 pci_unmap_addr(e, mapaddr),
2519 pci_unmap_len(e, maplen),
2520 PCI_DMA_FROMDEVICE);
2521 skb = e->skb;
2522 if (skge->rx_csum) {
2523 struct skge_rx_desc *rd = e->desc;
2524 skb->csum = le16_to_cpu(rd->csum2);
2525 skb->ip_summed = CHECKSUM_HW;
2526 }
2527
2528 skge_rx_setup(skge, e, nskb, skge->rx_buf_size);
2529 return skb;
2567 } 2530 }
2568} 2531}
2569 2532
2533
2570static int skge_poll(struct net_device *dev, int *budget) 2534static int skge_poll(struct net_device *dev, int *budget)
2571{ 2535{
2572 struct skge_port *skge = netdev_priv(dev); 2536 struct skge_port *skge = netdev_priv(dev);
@@ -2575,13 +2539,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2575 struct skge_element *e; 2539 struct skge_element *e;
2576 unsigned int to_do = min(dev->quota, *budget); 2540 unsigned int to_do = min(dev->quota, *budget);
2577 unsigned int work_done = 0; 2541 unsigned int work_done = 0;
2578 int done;
2579 static const u32 irqmask[] = { IS_PORT_1, IS_PORT_2 };
2580 2542
2581 for (e = ring->to_clean; e != ring->to_use && work_done < to_do; 2543 pr_debug("skge_poll\n");
2582 e = e->next) { 2544
2545 for (e = ring->to_clean; work_done < to_do; e = e->next) {
2583 struct skge_rx_desc *rd = e->desc; 2546 struct skge_rx_desc *rd = e->desc;
2584 struct sk_buff *skb = e->skb; 2547 struct sk_buff *skb;
2585 u32 control, len, status; 2548 u32 control, len, status;
2586 2549
2587 rmb(); 2550 rmb();
@@ -2590,19 +2553,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2590 break; 2553 break;
2591 2554
2592 len = control & BMU_BBC; 2555 len = control & BMU_BBC;
2593 e->skb = NULL;
2594
2595 pci_unmap_single(hw->pdev,
2596 pci_unmap_addr(e, mapaddr),
2597 pci_unmap_len(e, maplen),
2598 PCI_DMA_FROMDEVICE);
2599
2600 status = rd->status; 2556 status = rd->status;
2601 if ((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF) 2557
2602 || len > dev->mtu + VLAN_ETH_HLEN 2558 if (unlikely((control & (BMU_EOF|BMU_STF)) != (BMU_STF|BMU_EOF)
2603 || bad_phy_status(hw, status)) { 2559 || bad_phy_status(hw, status))) {
2604 skge_rx_error(skge, e - ring->start, control, status); 2560 skge_rx_error(skge, e - ring->start, control, status);
2605 dev_kfree_skb(skb); 2561 skge_rx_reuse(e, skge->rx_buf_size);
2606 continue; 2562 continue;
2607 } 2563 }
2608 2564
@@ -2610,43 +2566,37 @@ static int skge_poll(struct net_device *dev, int *budget)
2610 printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n", 2566 printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n",
2611 dev->name, e - ring->start, rd->status, len); 2567 dev->name, e - ring->start, rd->status, len);
2612 2568
2613 skb_put(skb, len); 2569 skb = skge_rx_get(skge, e, len);
2614 skb->protocol = eth_type_trans(skb, dev); 2570 if (likely(skb)) {
2615 2571 skb_put(skb, len);
2616 if (skge->rx_csum) { 2572 skb->protocol = eth_type_trans(skb, dev);
2617 skb->csum = le16_to_cpu(rd->csum2);
2618 skb->ip_summed = CHECKSUM_HW;
2619 }
2620 2573
2621 dev->last_rx = jiffies; 2574 dev->last_rx = jiffies;
2622 netif_receive_skb(skb); 2575 netif_receive_skb(skb);
2623 2576
2624 ++work_done; 2577 ++work_done;
2578 } else
2579 skge_rx_reuse(e, skge->rx_buf_size);
2625 } 2580 }
2626 ring->to_clean = e; 2581 ring->to_clean = e;
2627 2582
2628 *budget -= work_done;
2629 dev->quota -= work_done;
2630 done = work_done < to_do;
2631
2632 if (skge_rx_fill(skge))
2633 done = 0;
2634
2635 /* restart receiver */ 2583 /* restart receiver */
2636 wmb(); 2584 wmb();
2637 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR), 2585 skge_write8(hw, Q_ADDR(rxqaddr[skge->port], Q_CSR),
2638 CSR_START | CSR_IRQ_CL_F); 2586 CSR_START | CSR_IRQ_CL_F);
2639 2587
2640 if (done) { 2588 *budget -= work_done;
2641 local_irq_disable(); 2589 dev->quota -= work_done;
2642 hw->intr_mask |= irqmask[skge->port];
2643 /* Order is important since data can get interrupted */
2644 skge_write32(hw, B0_IMSK, hw->intr_mask);
2645 __netif_rx_complete(dev);
2646 local_irq_enable();
2647 }
2648 2590
2649 return !done; 2591 if (work_done >= to_do)
2592 return 1; /* not done */
2593
2594 local_irq_disable();
2595 __netif_rx_complete(dev);
2596 hw->intr_mask |= portirqmask[skge->port];
2597 skge_write32(hw, B0_IMSK, hw->intr_mask);
2598 local_irq_enable();
2599 return 0;
2650} 2600}
2651 2601
2652static inline void skge_tx_intr(struct net_device *dev) 2602static inline void skge_tx_intr(struct net_device *dev)
@@ -2657,7 +2607,7 @@ static inline void skge_tx_intr(struct net_device *dev)
2657 struct skge_element *e; 2607 struct skge_element *e;
2658 2608
2659 spin_lock(&skge->tx_lock); 2609 spin_lock(&skge->tx_lock);
2660 for(e = ring->to_clean; e != ring->to_use; e = e->next) { 2610 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
2661 struct skge_tx_desc *td = e->desc; 2611 struct skge_tx_desc *td = e->desc;
2662 u32 control; 2612 u32 control;
2663 2613
@@ -2690,12 +2640,12 @@ static void skge_mac_parity(struct skge_hw *hw, int port)
2690 : (port == 0 ? "(port A)": "(port B")); 2640 : (port == 0 ? "(port A)": "(port B"));
2691 2641
2692 if (hw->chip_id == CHIP_ID_GENESIS) 2642 if (hw->chip_id == CHIP_ID_GENESIS)
2693 skge_write16(hw, SKGEMAC_REG(port, TX_MFF_CTRL1), 2643 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
2694 MFF_CLR_PERR); 2644 MFF_CLR_PERR);
2695 else 2645 else
2696 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */ 2646 /* HW-Bug #8: cleared by GMF_CLI_TX_FC instead of GMF_CLI_TX_PE */
2697 skge_write8(hw, SKGEMAC_REG(port, TX_GMF_CTRL_T), 2647 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T),
2698 (hw->chip_id == CHIP_ID_YUKON && chip_rev(hw) == 0) 2648 (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
2699 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE); 2649 ? GMF_CLI_TX_FC : GMF_CLI_TX_PE);
2700} 2650}
2701 2651
@@ -2703,16 +2653,16 @@ static void skge_pci_clear(struct skge_hw *hw)
2703{ 2653{
2704 u16 status; 2654 u16 status;
2705 2655
2706 status = skge_read16(hw, SKGEPCI_REG(PCI_STATUS)); 2656 pci_read_config_word(hw->pdev, PCI_STATUS, &status);
2707 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 2657 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2708 skge_write16(hw, SKGEPCI_REG(PCI_STATUS), 2658 pci_write_config_word(hw->pdev, PCI_STATUS,
2709 status | PCI_STATUS_ERROR_BITS); 2659 status | PCI_STATUS_ERROR_BITS);
2710 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF); 2660 skge_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2711} 2661}
2712 2662
2713static void skge_mac_intr(struct skge_hw *hw, int port) 2663static void skge_mac_intr(struct skge_hw *hw, int port)
2714{ 2664{
2715 if (hw->chip_id == CHIP_ID_GENESIS) 2665 if (hw->chip_id == CHIP_ID_GENESIS)
2716 genesis_mac_intr(hw, port); 2666 genesis_mac_intr(hw, port);
2717 else 2667 else
2718 yukon_mac_intr(hw, port); 2668 yukon_mac_intr(hw, port);
@@ -2726,9 +2676,9 @@ static void skge_error_irq(struct skge_hw *hw)
2726 if (hw->chip_id == CHIP_ID_GENESIS) { 2676 if (hw->chip_id == CHIP_ID_GENESIS) {
2727 /* clear xmac errors */ 2677 /* clear xmac errors */
2728 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1)) 2678 if (hwstatus & (IS_NO_STAT_M1|IS_NO_TIST_M1))
2729 skge_write16(hw, SKGEMAC_REG(0, RX_MFF_CTRL1), MFF_CLR_INSTAT); 2679 skge_write16(hw, SK_REG(0, RX_MFF_CTRL1), MFF_CLR_INSTAT);
2730 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2)) 2680 if (hwstatus & (IS_NO_STAT_M2|IS_NO_TIST_M2))
2731 skge_write16(hw, SKGEMAC_REG(0, RX_MFF_CTRL2), MFF_CLR_INSTAT); 2681 skge_write16(hw, SK_REG(0, RX_MFF_CTRL2), MFF_CLR_INSTAT);
2732 } else { 2682 } else {
2733 /* Timestamp (unused) overflow */ 2683 /* Timestamp (unused) overflow */
2734 if (hwstatus & IS_IRQ_TIST_OV) 2684 if (hwstatus & IS_IRQ_TIST_OV)
@@ -2803,8 +2753,8 @@ static void skge_extirq(unsigned long data)
2803 2753
2804 if (hw->chip_id != CHIP_ID_GENESIS) 2754 if (hw->chip_id != CHIP_ID_GENESIS)
2805 yukon_phy_intr(skge); 2755 yukon_phy_intr(skge);
2806 else if (hw->phy_type == SK_PHY_BCOM) 2756 else
2807 genesis_bcom_intr(skge); 2757 bcom_phy_intr(skge);
2808 } 2758 }
2809 } 2759 }
2810 spin_unlock(&hw->phy_lock); 2760 spin_unlock(&hw->phy_lock);
@@ -2824,19 +2774,14 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2824 return IRQ_NONE; 2774 return IRQ_NONE;
2825 2775
2826 status &= hw->intr_mask; 2776 status &= hw->intr_mask;
2827 2777 if (status & IS_R1_F) {
2828 if ((status & IS_R1_F) && netif_rx_schedule_prep(hw->dev[0])) {
2829 status &= ~IS_R1_F;
2830 hw->intr_mask &= ~IS_R1_F; 2778 hw->intr_mask &= ~IS_R1_F;
2831 skge_write32(hw, B0_IMSK, hw->intr_mask); 2779 netif_rx_schedule(hw->dev[0]);
2832 __netif_rx_schedule(hw->dev[0]);
2833 } 2780 }
2834 2781
2835 if ((status & IS_R2_F) && netif_rx_schedule_prep(hw->dev[1])) { 2782 if (status & IS_R2_F) {
2836 status &= ~IS_R2_F;
2837 hw->intr_mask &= ~IS_R2_F; 2783 hw->intr_mask &= ~IS_R2_F;
2838 skge_write32(hw, B0_IMSK, hw->intr_mask); 2784 netif_rx_schedule(hw->dev[1]);
2839 __netif_rx_schedule(hw->dev[1]);
2840 } 2785 }
2841 2786
2842 if (status & IS_XA1_F) 2787 if (status & IS_XA1_F)
@@ -2845,9 +2790,27 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2845 if (status & IS_XA2_F) 2790 if (status & IS_XA2_F)
2846 skge_tx_intr(hw->dev[1]); 2791 skge_tx_intr(hw->dev[1]);
2847 2792
2793 if (status & IS_PA_TO_RX1) {
2794 struct skge_port *skge = netdev_priv(hw->dev[0]);
2795 ++skge->net_stats.rx_over_errors;
2796 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX1);
2797 }
2798
2799 if (status & IS_PA_TO_RX2) {
2800 struct skge_port *skge = netdev_priv(hw->dev[1]);
2801 ++skge->net_stats.rx_over_errors;
2802 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_RX2);
2803 }
2804
2805 if (status & IS_PA_TO_TX1)
2806 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX1);
2807
2808 if (status & IS_PA_TO_TX2)
2809 skge_write16(hw, B3_PA_CTRL, PA_CLR_TO_TX2);
2810
2848 if (status & IS_MAC1) 2811 if (status & IS_MAC1)
2849 skge_mac_intr(hw, 0); 2812 skge_mac_intr(hw, 0);
2850 2813
2851 if (status & IS_MAC2) 2814 if (status & IS_MAC2)
2852 skge_mac_intr(hw, 1); 2815 skge_mac_intr(hw, 1);
2853 2816
@@ -2859,8 +2822,7 @@ static irqreturn_t skge_intr(int irq, void *dev_id, struct pt_regs *regs)
2859 tasklet_schedule(&hw->ext_tasklet); 2822 tasklet_schedule(&hw->ext_tasklet);
2860 } 2823 }
2861 2824
2862 if (status) 2825 skge_write32(hw, B0_IMSK, hw->intr_mask);
2863 skge_write32(hw, B0_IMSK, hw->intr_mask);
2864 2826
2865 return IRQ_HANDLED; 2827 return IRQ_HANDLED;
2866} 2828}
@@ -2904,9 +2866,6 @@ static const struct {
2904 { CHIP_ID_YUKON, "Yukon" }, 2866 { CHIP_ID_YUKON, "Yukon" },
2905 { CHIP_ID_YUKON_LITE, "Yukon-Lite"}, 2867 { CHIP_ID_YUKON_LITE, "Yukon-Lite"},
2906 { CHIP_ID_YUKON_LP, "Yukon-LP"}, 2868 { CHIP_ID_YUKON_LP, "Yukon-LP"},
2907 { CHIP_ID_YUKON_XL, "Yukon-2 XL"},
2908 { CHIP_ID_YUKON_EC, "YUKON-2 EC"},
2909 { CHIP_ID_YUKON_FE, "YUKON-2 FE"},
2910}; 2869};
2911 2870
2912static const char *skge_board_name(const struct skge_hw *hw) 2871static const char *skge_board_name(const struct skge_hw *hw)
@@ -2930,8 +2889,8 @@ static const char *skge_board_name(const struct skge_hw *hw)
2930static int skge_reset(struct skge_hw *hw) 2889static int skge_reset(struct skge_hw *hw)
2931{ 2890{
2932 u16 ctst; 2891 u16 ctst;
2933 u8 t8; 2892 u8 t8, mac_cfg;
2934 int i, ports; 2893 int i;
2935 2894
2936 ctst = skge_read16(hw, B0_CTST); 2895 ctst = skge_read16(hw, B0_CTST);
2937 2896
@@ -2952,12 +2911,9 @@ static int skge_reset(struct skge_hw *hw)
2952 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf; 2911 hw->phy_type = skge_read8(hw, B2_E_1) & 0xf;
2953 hw->pmd_type = skge_read8(hw, B2_PMD_TYP); 2912 hw->pmd_type = skge_read8(hw, B2_PMD_TYP);
2954 2913
2955 switch(hw->chip_id) { 2914 switch (hw->chip_id) {
2956 case CHIP_ID_GENESIS: 2915 case CHIP_ID_GENESIS:
2957 switch (hw->phy_type) { 2916 switch (hw->phy_type) {
2958 case SK_PHY_XMAC:
2959 hw->phy_addr = PHY_ADDR_XMAC;
2960 break;
2961 case SK_PHY_BCOM: 2917 case SK_PHY_BCOM:
2962 hw->phy_addr = PHY_ADDR_BCOM; 2918 hw->phy_addr = PHY_ADDR_BCOM;
2963 break; 2919 break;
@@ -2986,8 +2942,9 @@ static int skge_reset(struct skge_hw *hw)
2986 return -EOPNOTSUPP; 2942 return -EOPNOTSUPP;
2987 } 2943 }
2988 2944
2989 hw->mac_cfg = skge_read8(hw, B2_MAC_CFG); 2945 mac_cfg = skge_read8(hw, B2_MAC_CFG);
2990 ports = isdualport(hw) ? 2 : 1; 2946 hw->ports = (mac_cfg & CFG_SNG_MAC) ? 1 : 2;
2947 hw->chip_rev = (mac_cfg & CFG_CHIP_R_MSK) >> 4;
2991 2948
2992 /* read the adapters RAM size */ 2949 /* read the adapters RAM size */
2993 t8 = skge_read8(hw, B2_E_0); 2950 t8 = skge_read8(hw, B2_E_0);
@@ -3010,9 +2967,9 @@ static int skge_reset(struct skge_hw *hw)
3010 /* switch power to VCC (WA for VAUX problem) */ 2967 /* switch power to VCC (WA for VAUX problem) */
3011 skge_write8(hw, B0_POWER_CTRL, 2968 skge_write8(hw, B0_POWER_CTRL,
3012 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON); 2969 PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
3013 for (i = 0; i < ports; i++) { 2970 for (i = 0; i < hw->ports; i++) {
3014 skge_write16(hw, SKGEMAC_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET); 2971 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
3015 skge_write16(hw, SKGEMAC_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR); 2972 skge_write16(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
3016 } 2973 }
3017 } 2974 }
3018 2975
@@ -3022,8 +2979,8 @@ static int skge_reset(struct skge_hw *hw)
3022 skge_write8(hw, B0_LED, LED_STAT_ON); 2979 skge_write8(hw, B0_LED, LED_STAT_ON);
3023 2980
3024 /* enable the Tx Arbiters */ 2981 /* enable the Tx Arbiters */
3025 for (i = 0; i < ports; i++) 2982 for (i = 0; i < hw->ports; i++)
3026 skge_write8(hw, SKGEMAC_REG(i, TXA_CTRL), TXA_ENA_ARB); 2983 skge_write8(hw, SK_REG(i, TXA_CTRL), TXA_ENA_ARB);
3027 2984
3028 /* Initialize ram interface */ 2985 /* Initialize ram interface */
3029 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR); 2986 skge_write16(hw, B3_RI_CTRL, RI_RST_CLR);
@@ -3050,16 +3007,14 @@ static int skge_reset(struct skge_hw *hw)
3050 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100)); 3007 skge_write32(hw, B2_IRQM_INI, skge_usecs2clk(hw, 100));
3051 skge_write32(hw, B2_IRQM_CTRL, TIM_START); 3008 skge_write32(hw, B2_IRQM_CTRL, TIM_START);
3052 3009
3053 hw->intr_mask = IS_HW_ERR | IS_EXT_REG | IS_PORT_1; 3010 hw->intr_mask = IS_HW_ERR | IS_EXT_REG;
3054 if (isdualport(hw))
3055 hw->intr_mask |= IS_PORT_2;
3056 skge_write32(hw, B0_IMSK, hw->intr_mask); 3011 skge_write32(hw, B0_IMSK, hw->intr_mask);
3057 3012
3058 if (hw->chip_id != CHIP_ID_GENESIS) 3013 if (hw->chip_id != CHIP_ID_GENESIS)
3059 skge_write8(hw, GMAC_IRQ_MSK, 0); 3014 skge_write8(hw, GMAC_IRQ_MSK, 0);
3060 3015
3061 spin_lock_bh(&hw->phy_lock); 3016 spin_lock_bh(&hw->phy_lock);
3062 for (i = 0; i < ports; i++) { 3017 for (i = 0; i < hw->ports; i++) {
3063 if (hw->chip_id == CHIP_ID_GENESIS) 3018 if (hw->chip_id == CHIP_ID_GENESIS)
3064 genesis_reset(hw, i); 3019 genesis_reset(hw, i);
3065 else 3020 else
@@ -3071,7 +3026,8 @@ static int skge_reset(struct skge_hw *hw)
3071} 3026}
3072 3027
3073/* Initialize network device */ 3028/* Initialize network device */
3074static struct net_device *skge_devinit(struct skge_hw *hw, int port) 3029static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3030 int highmem)
3075{ 3031{
3076 struct skge_port *skge; 3032 struct skge_port *skge;
3077 struct net_device *dev = alloc_etherdev(sizeof(*skge)); 3033 struct net_device *dev = alloc_etherdev(sizeof(*skge));
@@ -3104,6 +3060,8 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3104#endif 3060#endif
3105 dev->irq = hw->pdev->irq; 3061 dev->irq = hw->pdev->irq;
3106 dev->features = NETIF_F_LLTX; 3062 dev->features = NETIF_F_LLTX;
3063 if (highmem)
3064 dev->features |= NETIF_F_HIGHDMA;
3107 3065
3108 skge = netdev_priv(dev); 3066 skge = netdev_priv(dev);
3109 skge->netdev = dev; 3067 skge->netdev = dev;
@@ -3117,7 +3075,7 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3117 skge->flow_control = FLOW_MODE_SYMMETRIC; 3075 skge->flow_control = FLOW_MODE_SYMMETRIC;
3118 skge->duplex = -1; 3076 skge->duplex = -1;
3119 skge->speed = -1; 3077 skge->speed = -1;
3120 skge->advertising = skge_modes(hw); 3078 skge->advertising = skge_supported_modes(hw);
3121 3079
3122 hw->dev[port] = dev; 3080 hw->dev[port] = dev;
3123 3081
@@ -3125,10 +3083,6 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port)
3125 3083
3126 spin_lock_init(&skge->tx_lock); 3084 spin_lock_init(&skge->tx_lock);
3127 3085
3128 init_timer(&skge->link_check);
3129 skge->link_check.function = skge_link_timer;
3130 skge->link_check.data = (unsigned long) skge;
3131
3132 init_timer(&skge->led_blink); 3086 init_timer(&skge->led_blink);
3133 skge->led_blink.function = skge_blink_timer; 3087 skge->led_blink.function = skge_blink_timer;
3134 skge->led_blink.data = (unsigned long) skge; 3088 skge->led_blink.data = (unsigned long) skge;
@@ -3232,14 +3186,11 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3232 3186
3233 printk(KERN_INFO PFX "addr 0x%lx irq %d chip %s rev %d\n", 3187 printk(KERN_INFO PFX "addr 0x%lx irq %d chip %s rev %d\n",
3234 pci_resource_start(pdev, 0), pdev->irq, 3188 pci_resource_start(pdev, 0), pdev->irq,
3235 skge_board_name(hw), chip_rev(hw)); 3189 skge_board_name(hw), hw->chip_rev);
3236 3190
3237 if ((dev = skge_devinit(hw, 0)) == NULL) 3191 if ((dev = skge_devinit(hw, 0, using_dac)) == NULL)
3238 goto err_out_led_off; 3192 goto err_out_led_off;
3239 3193
3240 if (using_dac)
3241 dev->features |= NETIF_F_HIGHDMA;
3242
3243 if ((err = register_netdev(dev))) { 3194 if ((err = register_netdev(dev))) {
3244 printk(KERN_ERR PFX "%s: cannot register net device\n", 3195 printk(KERN_ERR PFX "%s: cannot register net device\n",
3245 pci_name(pdev)); 3196 pci_name(pdev));
@@ -3248,10 +3199,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3248 3199
3249 skge_show_addr(dev); 3200 skge_show_addr(dev);
3250 3201
3251 if (isdualport(hw) && (dev1 = skge_devinit(hw, 1))) { 3202 if (hw->ports > 1 && (dev1 = skge_devinit(hw, 1, using_dac))) {
3252 if (using_dac)
3253 dev1->features |= NETIF_F_HIGHDMA;
3254
3255 if (register_netdev(dev1) == 0) 3203 if (register_netdev(dev1) == 0)
3256 skge_show_addr(dev1); 3204 skge_show_addr(dev1);
3257 else { 3205 else {
@@ -3288,7 +3236,7 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3288 struct skge_hw *hw = pci_get_drvdata(pdev); 3236 struct skge_hw *hw = pci_get_drvdata(pdev);
3289 struct net_device *dev0, *dev1; 3237 struct net_device *dev0, *dev1;
3290 3238
3291 if(!hw) 3239 if (!hw)
3292 return; 3240 return;
3293 3241
3294 if ((dev1 = hw->dev[1])) 3242 if ((dev1 = hw->dev[1]))
@@ -3311,12 +3259,12 @@ static void __devexit skge_remove(struct pci_dev *pdev)
3311} 3259}
3312 3260
3313#ifdef CONFIG_PM 3261#ifdef CONFIG_PM
3314static int skge_suspend(struct pci_dev *pdev, u32 state) 3262static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
3315{ 3263{
3316 struct skge_hw *hw = pci_get_drvdata(pdev); 3264 struct skge_hw *hw = pci_get_drvdata(pdev);
3317 int i, wol = 0; 3265 int i, wol = 0;
3318 3266
3319 for(i = 0; i < 2; i++) { 3267 for (i = 0; i < 2; i++) {
3320 struct net_device *dev = hw->dev[i]; 3268 struct net_device *dev = hw->dev[i];
3321 3269
3322 if (dev) { 3270 if (dev) {
@@ -3331,7 +3279,7 @@ static int skge_suspend(struct pci_dev *pdev, u32 state)
3331 } 3279 }
3332 3280
3333 pci_save_state(pdev); 3281 pci_save_state(pdev);
3334 pci_enable_wake(pdev, state, wol); 3282 pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
3335 pci_disable_device(pdev); 3283 pci_disable_device(pdev);
3336 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 3284 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3337 3285
@@ -3349,11 +3297,11 @@ static int skge_resume(struct pci_dev *pdev)
3349 3297
3350 skge_reset(hw); 3298 skge_reset(hw);
3351 3299
3352 for(i = 0; i < 2; i++) { 3300 for (i = 0; i < 2; i++) {
3353 struct net_device *dev = hw->dev[i]; 3301 struct net_device *dev = hw->dev[i];
3354 if (dev) { 3302 if (dev) {
3355 netif_device_attach(dev); 3303 netif_device_attach(dev);
3356 if(netif_running(dev)) 3304 if (netif_running(dev))
3357 skge_up(dev); 3305 skge_up(dev);
3358 } 3306 }
3359 } 3307 }
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 36c62b68fab4..fced3d2bc072 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -7,31 +7,7 @@
7/* PCI config registers */ 7/* PCI config registers */
8#define PCI_DEV_REG1 0x40 8#define PCI_DEV_REG1 0x40
9#define PCI_DEV_REG2 0x44 9#define PCI_DEV_REG2 0x44
10#ifndef PCI_VPD 10#define PCI_REV_DESC 0x4
11#define PCI_VPD 0x50
12#endif
13
14/* PCI_OUR_REG_2 32 bit Our Register 2 */
15enum {
16 PCI_VPD_WR_THR = 0xff<<24, /* Bit 31..24: VPD Write Threshold */
17 PCI_DEV_SEL = 0x7f<<17, /* Bit 23..17: EEPROM Device Select */
18 PCI_VPD_ROM_SZ = 7 <<14, /* Bit 16..14: VPD ROM Size */
19 /* Bit 13..12: reserved */
20 PCI_EN_DUMMY_RD = 1<<3, /* Enable Dummy Read */
21 PCI_REV_DESC = 1<<2, /* Reverse Desc. Bytes */
22 PCI_USEDATA64 = 1<<0, /* Use 64Bit Data bus ext */
23};
24
25/* PCI_VPD_ADR_REG 16 bit VPD Address Register */
26enum {
27 PCI_VPD_FLAG = 1<<15, /* starts VPD rd/wr cycle */
28 PCI_VPD_ADR_MSK =0x7fffL, /* Bit 14.. 0: VPD Address Mask */
29 VPD_RES_ID = 0x82,
30 VPD_RES_READ = 0x90,
31 VPD_RES_WRITE = 0x81,
32 VPD_RES_END = 0x78,
33};
34
35 11
36#define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \ 12#define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \
37 PCI_STATUS_SIG_SYSTEM_ERROR | \ 13 PCI_STATUS_SIG_SYSTEM_ERROR | \
@@ -39,7 +15,6 @@ enum {
39 PCI_STATUS_REC_TARGET_ABORT | \ 15 PCI_STATUS_REC_TARGET_ABORT | \
40 PCI_STATUS_PARITY) 16 PCI_STATUS_PARITY)
41 17
42
43enum csr_regs { 18enum csr_regs {
44 B0_RAP = 0x0000, 19 B0_RAP = 0x0000,
45 B0_CTST = 0x0004, 20 B0_CTST = 0x0004,
@@ -229,8 +204,11 @@ enum {
229 IS_XA2_F = 1<<1, /* Q_XA2 End of Frame */ 204 IS_XA2_F = 1<<1, /* Q_XA2 End of Frame */
230 IS_XA2_C = 1<<0, /* Q_XA2 Encoding Error */ 205 IS_XA2_C = 1<<0, /* Q_XA2 Encoding Error */
231 206
232 IS_PORT_1 = IS_XA1_F| IS_R1_F| IS_MAC1, 207 IS_TO_PORT1 = IS_PA_TO_RX1 | IS_PA_TO_TX1,
233 IS_PORT_2 = IS_XA2_F| IS_R2_F| IS_MAC2, 208 IS_TO_PORT2 = IS_PA_TO_RX2 | IS_PA_TO_TX2,
209
210 IS_PORT_1 = IS_XA1_F| IS_R1_F | IS_TO_PORT1 | IS_MAC1,
211 IS_PORT_2 = IS_XA2_F| IS_R2_F | IS_TO_PORT2 | IS_MAC2,
234}; 212};
235 213
236 214
@@ -288,14 +266,6 @@ enum {
288 CHIP_REV_YU_LITE_A3 = 7, /* Chip Rev. for YUKON-Lite A3 */ 266 CHIP_REV_YU_LITE_A3 = 7, /* Chip Rev. for YUKON-Lite A3 */
289}; 267};
290 268
291/* B2_LD_TEST 8 bit EPROM loader test register */
292enum {
293 LD_T_ON = 1<<3, /* Loader Test mode on */
294 LD_T_OFF = 1<<2, /* Loader Test mode off */
295 LD_T_STEP = 1<<1, /* Decrement FPROM addr. Counter */
296 LD_START = 1<<0, /* Start loading FPROM */
297};
298
299/* B2_TI_CTRL 8 bit Timer control */ 269/* B2_TI_CTRL 8 bit Timer control */
300/* B2_IRQM_CTRL 8 bit IRQ Moderation Timer Control */ 270/* B2_IRQM_CTRL 8 bit IRQ Moderation Timer Control */
301enum { 271enum {
@@ -313,16 +283,6 @@ enum {
313 TIM_T_STEP = 1<<0, /* Test step */ 283 TIM_T_STEP = 1<<0, /* Test step */
314}; 284};
315 285
316/* B28_DPT_INI 32 bit Descriptor Poll Timer Init Val */
317/* B28_DPT_VAL 32 bit Descriptor Poll Timer Curr Val */
318/* B28_DPT_CTRL 8 bit Descriptor Poll Timer Ctrl Reg */
319enum {
320 DPT_MSK = 0x00ffffffL, /* Bit 23.. 0: Desc Poll Timer Bits */
321
322 DPT_START = 1<<1, /* Start Descriptor Poll Timer */
323 DPT_STOP = 1<<0, /* Stop Descriptor Poll Timer */
324};
325
326/* B2_GP_IO 32 bit General Purpose I/O Register */ 286/* B2_GP_IO 32 bit General Purpose I/O Register */
327enum { 287enum {
328 GP_DIR_9 = 1<<25, /* IO_9 direct, 0=In/1=Out */ 288 GP_DIR_9 = 1<<25, /* IO_9 direct, 0=In/1=Out */
@@ -348,30 +308,6 @@ enum {
348 GP_IO_0 = 1<<0, /* IO_0 pin */ 308 GP_IO_0 = 1<<0, /* IO_0 pin */
349}; 309};
350 310
351/* Rx/Tx Path related Arbiter Test Registers */
352/* B3_MA_TO_TEST 16 bit MAC Arbiter Timeout Test Reg */
353/* B3_MA_RC_TEST 16 bit MAC Arbiter Recovery Test Reg */
354/* B3_PA_TEST 16 bit Packet Arbiter Test Register */
355/* Bit 15, 11, 7, and 3 are reserved in B3_PA_TEST */
356enum {
357 TX2_T_EV = 1<<15,/* TX2 Timeout/Recv Event occured */
358 TX2_T_ON = 1<<14,/* TX2 Timeout/Recv Timer Test On */
359 TX2_T_OFF = 1<<13,/* TX2 Timeout/Recv Timer Tst Off */
360 TX2_T_STEP = 1<<12,/* TX2 Timeout/Recv Timer Step */
361 TX1_T_EV = 1<<11,/* TX1 Timeout/Recv Event occured */
362 TX1_T_ON = 1<<10,/* TX1 Timeout/Recv Timer Test On */
363 TX1_T_OFF = 1<<9, /* TX1 Timeout/Recv Timer Tst Off */
364 TX1_T_STEP = 1<<8, /* TX1 Timeout/Recv Timer Step */
365 RX2_T_EV = 1<<7, /* RX2 Timeout/Recv Event occured */
366 RX2_T_ON = 1<<6, /* RX2 Timeout/Recv Timer Test On */
367 RX2_T_OFF = 1<<5, /* RX2 Timeout/Recv Timer Tst Off */
368 RX2_T_STEP = 1<<4, /* RX2 Timeout/Recv Timer Step */
369 RX1_T_EV = 1<<3, /* RX1 Timeout/Recv Event occured */
370 RX1_T_ON = 1<<2, /* RX1 Timeout/Recv Timer Test On */
371 RX1_T_OFF = 1<<1, /* RX1 Timeout/Recv Timer Tst Off */
372 RX1_T_STEP = 1<<0, /* RX1 Timeout/Recv Timer Step */
373};
374
375/* Descriptor Bit Definition */ 311/* Descriptor Bit Definition */
376/* TxCtrl Transmit Buffer Control Field */ 312/* TxCtrl Transmit Buffer Control Field */
377/* RxCtrl Receive Buffer Control Field */ 313/* RxCtrl Receive Buffer Control Field */
@@ -428,14 +364,6 @@ enum {
428 RI_RST_SET = 1<<0, /* Set RAM Interface Reset */ 364 RI_RST_SET = 1<<0, /* Set RAM Interface Reset */
429}; 365};
430 366
431/* B3_RI_TEST 8 bit RAM Iface Test Register */
432enum {
433 RI_T_EV = 1<<3, /* Timeout Event occured */
434 RI_T_ON = 1<<2, /* Timeout Timer Test On */
435 RI_T_OFF = 1<<1, /* Timeout Timer Test Off */
436 RI_T_STEP = 1<<0, /* Timeout Timer Step */
437};
438
439/* MAC Arbiter Registers */ 367/* MAC Arbiter Registers */
440/* B3_MA_TO_CTRL 16 bit MAC Arbiter Timeout Ctrl Reg */ 368/* B3_MA_TO_CTRL 16 bit MAC Arbiter Timeout Ctrl Reg */
441enum { 369enum {
@@ -452,19 +380,6 @@ enum {
452#define SK_PKT_TO_MAX 0xffff /* Maximum value */ 380#define SK_PKT_TO_MAX 0xffff /* Maximum value */
453#define SK_RI_TO_53 36 /* RAM interface timeout */ 381#define SK_RI_TO_53 36 /* RAM interface timeout */
454 382
455
456/* B3_MA_RC_CTRL 16 bit MAC Arbiter Recovery Ctrl Reg */
457enum {
458 MA_ENA_REC_TX2 = 1<<7, /* Enable Recovery Timer TX2 */
459 MA_DIS_REC_TX2 = 1<<6, /* Disable Recovery Timer TX2 */
460 MA_ENA_REC_TX1 = 1<<5, /* Enable Recovery Timer TX1 */
461 MA_DIS_REC_TX1 = 1<<4, /* Disable Recovery Timer TX1 */
462 MA_ENA_REC_RX2 = 1<<3, /* Enable Recovery Timer RX2 */
463 MA_DIS_REC_RX2 = 1<<2, /* Disable Recovery Timer RX2 */
464 MA_ENA_REC_RX1 = 1<<1, /* Enable Recovery Timer RX1 */
465 MA_DIS_REC_RX1 = 1<<0, /* Disable Recovery Timer RX1 */
466};
467
468/* Packet Arbiter Registers */ 383/* Packet Arbiter Registers */
469/* B3_PA_CTRL 16 bit Packet Arbiter Ctrl Register */ 384/* B3_PA_CTRL 16 bit Packet Arbiter Ctrl Register */
470enum { 385enum {
@@ -488,7 +403,7 @@ enum {
488 PA_ENA_TO_TX1 | PA_ENA_TO_TX2) 403 PA_ENA_TO_TX1 | PA_ENA_TO_TX2)
489 404
490 405
491/* Transmit Arbiter Registers MAC 1 and 2, use MR_ADDR() to access */ 406/* Transmit Arbiter Registers MAC 1 and 2, use SK_REG() to access */
492/* TXA_ITI_INI 32 bit Tx Arb Interval Timer Init Val */ 407/* TXA_ITI_INI 32 bit Tx Arb Interval Timer Init Val */
493/* TXA_ITI_VAL 32 bit Tx Arb Interval Timer Value */ 408/* TXA_ITI_VAL 32 bit Tx Arb Interval Timer Value */
494/* TXA_LIM_INI 32 bit Tx Arb Limit Counter Init Val */ 409/* TXA_LIM_INI 32 bit Tx Arb Limit Counter Init Val */
@@ -511,7 +426,7 @@ enum {
511/* 426/*
512 * Bank 4 - 5 427 * Bank 4 - 5
513 */ 428 */
514/* Transmit Arbiter Registers MAC 1 and 2, use MR_ADDR() to access */ 429/* Transmit Arbiter Registers MAC 1 and 2, use SK_REG() to access */
515enum { 430enum {
516 TXA_ITI_INI = 0x0200,/* 32 bit Tx Arb Interval Timer Init Val*/ 431 TXA_ITI_INI = 0x0200,/* 32 bit Tx Arb Interval Timer Init Val*/
517 TXA_ITI_VAL = 0x0204,/* 32 bit Tx Arb Interval Timer Value */ 432 TXA_ITI_VAL = 0x0204,/* 32 bit Tx Arb Interval Timer Value */
@@ -537,7 +452,7 @@ enum {
537 452
538/* Queue Register Offsets, use Q_ADDR() to access */ 453/* Queue Register Offsets, use Q_ADDR() to access */
539enum { 454enum {
540 B8_Q_REGS = 0x0400, /* base of Queue registers */ 455 B8_Q_REGS = 0x0400, /* base of Queue registers */
541 Q_D = 0x00, /* 8*32 bit Current Descriptor */ 456 Q_D = 0x00, /* 8*32 bit Current Descriptor */
542 Q_DA_L = 0x20, /* 32 bit Current Descriptor Address Low dWord */ 457 Q_DA_L = 0x20, /* 32 bit Current Descriptor Address Low dWord */
543 Q_DA_H = 0x24, /* 32 bit Current Descriptor Address High dWord */ 458 Q_DA_H = 0x24, /* 32 bit Current Descriptor Address High dWord */
@@ -618,8 +533,7 @@ enum {
618enum { 533enum {
619 PHY_ADDR_XMAC = 0<<8, 534 PHY_ADDR_XMAC = 0<<8,
620 PHY_ADDR_BCOM = 1<<8, 535 PHY_ADDR_BCOM = 1<<8,
621 PHY_ADDR_LONE = 3<<8, 536
622 PHY_ADDR_NAT = 0<<8,
623/* GPHY address (bits 15..11 of SMI control reg) */ 537/* GPHY address (bits 15..11 of SMI control reg) */
624 PHY_ADDR_MARV = 0, 538 PHY_ADDR_MARV = 0,
625}; 539};
@@ -986,7 +900,7 @@ enum {
986 LINKLED_BLINK_OFF = 0x10, 900 LINKLED_BLINK_OFF = 0x10,
987 LINKLED_BLINK_ON = 0x20, 901 LINKLED_BLINK_ON = 0x20,
988}; 902};
989 903
990/* GMAC and GPHY Control Registers (YUKON only) */ 904/* GMAC and GPHY Control Registers (YUKON only) */
991enum { 905enum {
992 GMAC_CTRL = 0x0f00,/* 32 bit GMAC Control Reg */ 906 GMAC_CTRL = 0x0f00,/* 32 bit GMAC Control Reg */
@@ -1151,54 +1065,6 @@ enum {
1151 PHY_MARV_FE_SPEC_2 = 0x1c,/* 16 bit r/w Specific Control Reg. 2 */ 1065 PHY_MARV_FE_SPEC_2 = 0x1c,/* 16 bit r/w Specific Control Reg. 2 */
1152}; 1066};
1153 1067
1154/* Level One-PHY Registers, indirect addressed over XMAC */
1155enum {
1156 PHY_LONE_CTRL = 0x00,/* 16 bit r/w PHY Control Register */
1157 PHY_LONE_STAT = 0x01,/* 16 bit r/o PHY Status Register */
1158 PHY_LONE_ID0 = 0x02,/* 16 bit r/o PHY ID0 Register */
1159 PHY_LONE_ID1 = 0x03,/* 16 bit r/o PHY ID1 Register */
1160 PHY_LONE_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */
1161 PHY_LONE_AUNE_LP = 0x05,/* 16 bit r/o Link Part Ability Reg */
1162 PHY_LONE_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */
1163 PHY_LONE_NEPG = 0x07,/* 16 bit r/w Next Page Register */
1164 PHY_LONE_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner */
1165 /* Level One-specific registers */
1166 PHY_LONE_1000T_CTRL = 0x09,/* 16 bit r/w 1000Base-T Control Reg */
1167 PHY_LONE_1000T_STAT = 0x0a,/* 16 bit r/o 1000Base-T Status Reg */
1168 PHY_LONE_EXT_STAT = 0x0f,/* 16 bit r/o Extended Status Reg */
1169 PHY_LONE_PORT_CFG = 0x10,/* 16 bit r/w Port Configuration Reg*/
1170 PHY_LONE_Q_STAT = 0x11,/* 16 bit r/o Quick Status Reg */
1171 PHY_LONE_INT_ENAB = 0x12,/* 16 bit r/w Interrupt Enable Reg */
1172 PHY_LONE_INT_STAT = 0x13,/* 16 bit r/o Interrupt Status Reg */
1173 PHY_LONE_LED_CFG = 0x14,/* 16 bit r/w LED Configuration Reg */
1174 PHY_LONE_PORT_CTRL = 0x15,/* 16 bit r/w Port Control Reg */
1175 PHY_LONE_CIM = 0x16,/* 16 bit r/o CIM Reg */
1176};
1177
1178/* National-PHY Registers, indirect addressed over XMAC */
1179enum {
1180 PHY_NAT_CTRL = 0x00,/* 16 bit r/w PHY Control Register */
1181 PHY_NAT_STAT = 0x01,/* 16 bit r/w PHY Status Register */
1182 PHY_NAT_ID0 = 0x02,/* 16 bit r/o PHY ID0 Register */
1183 PHY_NAT_ID1 = 0x03,/* 16 bit r/o PHY ID1 Register */
1184 PHY_NAT_AUNE_ADV = 0x04,/* 16 bit r/w Auto-Neg. Advertisement */
1185 PHY_NAT_AUNE_LP = 0x05,/* 16 bit r/o Link Partner Ability Reg */
1186 PHY_NAT_AUNE_EXP = 0x06,/* 16 bit r/o Auto-Neg. Expansion Reg */
1187 PHY_NAT_NEPG = 0x07,/* 16 bit r/w Next Page Register */
1188 PHY_NAT_NEPG_LP = 0x08,/* 16 bit r/o Next Page Link Partner Reg */
1189 /* National-specific registers */
1190 PHY_NAT_1000T_CTRL = 0x09,/* 16 bit r/w 1000Base-T Control Reg */
1191 PHY_NAT_1000T_STAT = 0x0a,/* 16 bit r/o 1000Base-T Status Reg */
1192 PHY_NAT_EXT_STAT = 0x0f,/* 16 bit r/o Extended Status Register */
1193 PHY_NAT_EXT_CTRL1 = 0x10,/* 16 bit r/o Extended Control Reg1 */
1194 PHY_NAT_Q_STAT1 = 0x11,/* 16 bit r/o Quick Status Reg1 */
1195 PHY_NAT_10B_OP = 0x12,/* 16 bit r/o 10Base-T Operations Reg */
1196 PHY_NAT_EXT_CTRL2 = 0x13,/* 16 bit r/o Extended Control Reg1 */
1197 PHY_NAT_Q_STAT2 = 0x14,/* 16 bit r/o Quick Status Reg2 */
1198
1199 PHY_NAT_PHY_ADDR = 0x19,/* 16 bit r/o PHY Address Register */
1200};
1201
1202enum { 1068enum {
1203 PHY_CT_RESET = 1<<15, /* Bit 15: (sc) clear all PHY related regs */ 1069 PHY_CT_RESET = 1<<15, /* Bit 15: (sc) clear all PHY related regs */
1204 PHY_CT_LOOP = 1<<14, /* Bit 14: enable Loopback over PHY */ 1070 PHY_CT_LOOP = 1<<14, /* Bit 14: enable Loopback over PHY */
@@ -1253,8 +1119,29 @@ enum {
1253 PHY_MARV_ID1_Y2 = 0x0C91, /* Yukon-2 (PHY 88E1112) */ 1119 PHY_MARV_ID1_Y2 = 0x0C91, /* Yukon-2 (PHY 88E1112) */
1254}; 1120};
1255 1121
1122/* Advertisement register bits */
1256enum { 1123enum {
1257 PHY_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */ 1124 PHY_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */
1125 PHY_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */
1126 PHY_AN_RF = 1<<13, /* Bit 13: Remote Fault Bits */
1127
1128 PHY_AN_PAUSE_ASYM = 1<<11,/* Bit 11: Try for asymmetric */
1129 PHY_AN_PAUSE_CAP = 1<<10, /* Bit 10: Try for pause */
1130 PHY_AN_100BASE4 = 1<<9, /* Bit 9: Try for 100mbps 4k packets */
1131 PHY_AN_100FULL = 1<<8, /* Bit 8: Try for 100mbps full-duplex */
1132 PHY_AN_100HALF = 1<<7, /* Bit 7: Try for 100mbps half-duplex */
1133 PHY_AN_10FULL = 1<<6, /* Bit 6: Try for 10mbps full-duplex */
1134 PHY_AN_10HALF = 1<<5, /* Bit 5: Try for 10mbps half-duplex */
1135 PHY_AN_CSMA = 1<<0, /* Bit 0: Only selector supported */
1136 PHY_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1137 PHY_AN_FULL = PHY_AN_100FULL | PHY_AN_10FULL | PHY_AN_CSMA,
1138 PHY_AN_ALL = PHY_AN_10HALF | PHY_AN_10FULL |
1139 PHY_AN_100HALF | PHY_AN_100FULL,
1140};
1141
1142/* Xmac Specific */
1143enum {
1144 PHY_X_AN_NXT_PG = 1<<15, /* Bit 15: Request Next Page */
1258 PHY_X_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */ 1145 PHY_X_AN_ACK = 1<<14, /* Bit 14: (ro) Acknowledge Received */
1259 PHY_X_AN_RFB = 3<<12,/* Bit 13..12: Remote Fault Bits */ 1146 PHY_X_AN_RFB = 3<<12,/* Bit 13..12: Remote Fault Bits */
1260 1147
@@ -1263,82 +1150,6 @@ enum {
1263 PHY_X_AN_FD = 1<<5, /* Bit 5: Full Duplex */ 1150 PHY_X_AN_FD = 1<<5, /* Bit 5: Full Duplex */
1264}; 1151};
1265 1152
1266enum {
1267 PHY_B_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1268
1269 PHY_B_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1270 PHY_B_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1271 PHY_B_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1272};
1273
1274enum {
1275 PHY_L_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1276 /* Bit 12: reserved */
1277 PHY_L_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1278 PHY_L_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1279
1280 PHY_L_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1281};
1282
1283/* PHY_NAT_AUNE_ADV 16 bit r/w Auto-Negotiation Advertisement */
1284/* PHY_NAT_AUNE_LP 16 bit r/o Link Partner Ability Reg *****/
1285/* PHY_AN_NXT_PG (see XMAC) Bit 15: Request Next Page */
1286enum {
1287 PHY_N_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1288
1289 PHY_N_AN_100F = 1<<11, /* Bit 11: 100Base-T2 FD Support */
1290 PHY_N_AN_100H = 1<<10, /* Bit 10: 100Base-T2 HD Support */
1291
1292 PHY_N_AN_SEL = 0x1f, /* Bit 4..0: Selector Field, 00001=Ethernet*/
1293};
1294
1295/* field type definition for PHY_x_AN_SEL */
1296enum {
1297 PHY_SEL_TYPE = 1, /* 00001 = Ethernet */
1298};
1299
1300enum {
1301 PHY_ANE_LP_NP = 1<<3, /* Bit 3: Link Partner can Next Page */
1302 PHY_ANE_LOC_NP = 1<<2, /* Bit 2: Local PHY can Next Page */
1303 PHY_ANE_RX_PG = 1<<1, /* Bit 1: Page Received */
1304};
1305
1306enum {
1307 PHY_ANE_PAR_DF = 1<<4, /* Bit 4: Parallel Detection Fault */
1308
1309 PHY_ANE_LP_CAP = 1<<0, /* Bit 0: Link Partner Auto-Neg. Cap. */
1310};
1311
1312enum {
1313 PHY_NP_MORE = 1<<15, /* Bit 15: More, Next Pages to follow */
1314 PHY_NP_ACK1 = 1<<14, /* Bit 14: (ro) Ack1, for receiving a message */
1315 PHY_NP_MSG_VAL = 1<<13, /* Bit 13: Message Page valid */
1316 PHY_NP_ACK2 = 1<<12, /* Bit 12: Ack2, comply with msg content */
1317 PHY_NP_TOG = 1<<11, /* Bit 11: Toggle Bit, ensure sync */
1318 PHY_NP_MSG = 0x07ff, /* Bit 10..0: Message from/to Link Partner */
1319};
1320
1321enum {
1322 PHY_X_EX_FD = 1<<15, /* Bit 15: Device Supports Full Duplex */
1323 PHY_X_EX_HD = 1<<14, /* Bit 14: Device Supports Half Duplex */
1324};
1325
1326enum {
1327 PHY_X_RS_PAUSE = 3<<7,/* Bit 8..7: selected Pause Mode */
1328 PHY_X_RS_HD = 1<<6, /* Bit 6: Half Duplex Mode selected */
1329 PHY_X_RS_FD = 1<<5, /* Bit 5: Full Duplex Mode selected */
1330 PHY_X_RS_ABLMIS = 1<<4, /* Bit 4: duplex or pause cap mismatch */
1331 PHY_X_RS_PAUMIS = 1<<3, /* Bit 3: pause capability mismatch */
1332};
1333
1334/** Remote Fault Bits (PHY_X_AN_RFB) encoding */
1335enum {
1336 X_RFB_OK = 0<<12,/* Bit 13..12 No errors, Link OK */
1337 X_RFB_LF = 1<<12, /* Bit 13..12 Link Failure */
1338 X_RFB_OFF = 2<<12,/* Bit 13..12 Offline */
1339 X_RFB_AN_ERR = 3<<12,/* Bit 13..12 Auto-Negotiation Error */
1340};
1341
1342/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */ 1153/* Pause Bits (PHY_X_AN_PAUSE and PHY_X_RS_PAUSE) encoding */
1343enum { 1154enum {
1344 PHY_X_P_NO_PAUSE = 0<<7,/* Bit 8..7: no Pause Mode */ 1155 PHY_X_P_NO_PAUSE = 0<<7,/* Bit 8..7: no Pause Mode */
@@ -1418,6 +1229,16 @@ enum {
1418 PHY_B_PES_MLT3_ER = 1<<0, /* Bit 0: MLT3 code Error */ 1229 PHY_B_PES_MLT3_ER = 1<<0, /* Bit 0: MLT3 code Error */
1419}; 1230};
1420 1231
1232/* PHY_BCOM_AUNE_ADV 16 bit r/w Auto-Negotiation Advertisement *****/
1233/* PHY_BCOM_AUNE_LP 16 bit r/o Link Partner Ability Reg *****/
1234enum {
1235 PHY_B_AN_RF = 1<<13, /* Bit 13: Remote Fault */
1236
1237 PHY_B_AN_ASP = 1<<11, /* Bit 11: Asymmetric Pause */
1238 PHY_B_AN_PC = 1<<10, /* Bit 10: Pause Capable */
1239};
1240
1241
1421/***** PHY_BCOM_FC_CTR 16 bit r/w False Carrier Counter *****/ 1242/***** PHY_BCOM_FC_CTR 16 bit r/w False Carrier Counter *****/
1422enum { 1243enum {
1423 PHY_B_FC_CTR = 0xff, /* Bit 7..0: False Carrier Counter */ 1244 PHY_B_FC_CTR = 0xff, /* Bit 7..0: False Carrier Counter */
@@ -1478,7 +1299,9 @@ enum {
1478 PHY_B_IS_LST_CHANGE = 1<<1, /* Bit 1: Link Status Changed */ 1299 PHY_B_IS_LST_CHANGE = 1<<1, /* Bit 1: Link Status Changed */
1479 PHY_B_IS_CRC_ER = 1<<0, /* Bit 0: CRC Error */ 1300 PHY_B_IS_CRC_ER = 1<<0, /* Bit 0: CRC Error */
1480}; 1301};
1481#define PHY_B_DEF_MSK (~(PHY_B_IS_AN_PR | PHY_B_IS_LST_CHANGE)) 1302#define PHY_B_DEF_MSK \
1303 (~(PHY_B_IS_PSE | PHY_B_IS_AN_PR | PHY_B_IS_DUP_CHANGE | \
1304 PHY_B_IS_LSP_CHANGE | PHY_B_IS_LST_CHANGE))
1482 1305
1483/* Pause Bits (PHY_B_AN_ASP and PHY_B_AN_PC) encoding */ 1306/* Pause Bits (PHY_B_AN_ASP and PHY_B_AN_PC) encoding */
1484enum { 1307enum {
@@ -1495,166 +1318,6 @@ enum {
1495 PHY_B_RES_1000HD = 6<<8,/* Bit 10..8: 1000Base-T Half Dup. */ 1318 PHY_B_RES_1000HD = 6<<8,/* Bit 10..8: 1000Base-T Half Dup. */
1496}; 1319};
1497 1320
1498/*
1499 * Level One-Specific
1500 */
1501/***** PHY_LONE_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/
1502enum {
1503 PHY_L_1000C_TEST = 7<<13,/* Bit 15..13: Test Modes */
1504 PHY_L_1000C_MSE = 1<<12, /* Bit 12: Master/Slave Enable */
1505 PHY_L_1000C_MSC = 1<<11, /* Bit 11: M/S Configuration */
1506 PHY_L_1000C_RD = 1<<10, /* Bit 10: Repeater/DTE */
1507 PHY_L_1000C_AFD = 1<<9, /* Bit 9: Advertise Full Duplex */
1508 PHY_L_1000C_AHD = 1<<8, /* Bit 8: Advertise Half Duplex */
1509};
1510
1511/***** PHY_LONE_1000T_STAT 16 bit r/o 1000Base-T Status Reg *****/
1512enum {
1513 PHY_L_1000S_MSF = 1<<15, /* Bit 15: Master/Slave Fault */
1514 PHY_L_1000S_MSR = 1<<14, /* Bit 14: Master/Slave Result */
1515 PHY_L_1000S_LRS = 1<<13, /* Bit 13: Local Receiver Status */
1516 PHY_L_1000S_RRS = 1<<12, /* Bit 12: Remote Receiver Status */
1517 PHY_L_1000S_LP_FD = 1<<11, /* Bit 11: Link Partner can FD */
1518 PHY_L_1000S_LP_HD = 1<<10, /* Bit 10: Link Partner can HD */
1519
1520 PHY_L_1000S_IEC = 0xff, /* Bit 7..0: Idle Error Count */
1521
1522/***** PHY_LONE_EXT_STAT 16 bit r/o Extended Status Register *****/
1523 PHY_L_ES_X_FD_CAP = 1<<15, /* Bit 15: 1000Base-X FD capable */
1524 PHY_L_ES_X_HD_CAP = 1<<14, /* Bit 14: 1000Base-X HD capable */
1525 PHY_L_ES_T_FD_CAP = 1<<13, /* Bit 13: 1000Base-T FD capable */
1526 PHY_L_ES_T_HD_CAP = 1<<12, /* Bit 12: 1000Base-T HD capable */
1527};
1528
1529/***** PHY_LONE_PORT_CFG 16 bit r/w Port Configuration Reg *****/
1530enum {
1531 PHY_L_PC_REP_MODE = 1<<15, /* Bit 15: Repeater Mode */
1532
1533 PHY_L_PC_TX_DIS = 1<<13, /* Bit 13: Tx output Disabled */
1534 PHY_L_PC_BY_SCR = 1<<12, /* Bit 12: Bypass Scrambler */
1535 PHY_L_PC_BY_45 = 1<<11, /* Bit 11: Bypass 4B5B-Decoder */
1536 PHY_L_PC_JAB_DIS = 1<<10, /* Bit 10: Jabber Disabled */
1537 PHY_L_PC_SQE = 1<<9, /* Bit 9: Enable Heartbeat */
1538 PHY_L_PC_TP_LOOP = 1<<8, /* Bit 8: TP Loopback */
1539 PHY_L_PC_SSS = 1<<7, /* Bit 7: Smart Speed Selection */
1540 PHY_L_PC_FIFO_SIZE = 1<<6, /* Bit 6: FIFO Size */
1541 PHY_L_PC_PRE_EN = 1<<5, /* Bit 5: Preamble Enable */
1542 PHY_L_PC_CIM = 1<<4, /* Bit 4: Carrier Integrity Mon */
1543 PHY_L_PC_10_SER = 1<<3, /* Bit 3: Use Serial Output */
1544 PHY_L_PC_ANISOL = 1<<2, /* Bit 2: Unisolate Port */
1545 PHY_L_PC_TEN_BIT = 1<<1, /* Bit 1: 10bit iface mode on */
1546 PHY_L_PC_ALTCLOCK = 1<<0, /* Bit 0: (ro) ALTCLOCK Mode on */
1547};
1548
1549/***** PHY_LONE_Q_STAT 16 bit r/o Quick Status Reg *****/
1550enum {
1551 PHY_L_QS_D_RATE = 3<<14,/* Bit 15..14: Data Rate */
1552 PHY_L_QS_TX_STAT = 1<<13, /* Bit 13: Transmitting */
1553 PHY_L_QS_RX_STAT = 1<<12, /* Bit 12: Receiving */
1554 PHY_L_QS_COL_STAT = 1<<11, /* Bit 11: Collision */
1555 PHY_L_QS_L_STAT = 1<<10, /* Bit 10: Link is up */
1556 PHY_L_QS_DUP_MOD = 1<<9, /* Bit 9: Full/Half Duplex */
1557 PHY_L_QS_AN = 1<<8, /* Bit 8: AutoNeg is On */
1558 PHY_L_QS_AN_C = 1<<7, /* Bit 7: AN is Complete */
1559 PHY_L_QS_LLE = 7<<4,/* Bit 6..4: Line Length Estim. */
1560 PHY_L_QS_PAUSE = 1<<3, /* Bit 3: LP advertised Pause */
1561 PHY_L_QS_AS_PAUSE = 1<<2, /* Bit 2: LP adv. asym. Pause */
1562 PHY_L_QS_ISOLATE = 1<<1, /* Bit 1: CIM Isolated */
1563 PHY_L_QS_EVENT = 1<<0, /* Bit 0: Event has occurred */
1564};
1565
1566/***** PHY_LONE_INT_ENAB 16 bit r/w Interrupt Enable Reg *****/
1567/***** PHY_LONE_INT_STAT 16 bit r/o Interrupt Status Reg *****/
1568enum {
1569 PHY_L_IS_AN_F = 1<<13, /* Bit 13: Auto-Negotiation fault */
1570 PHY_L_IS_CROSS = 1<<11, /* Bit 11: Crossover used */
1571 PHY_L_IS_POL = 1<<10, /* Bit 10: Polarity correct. used */
1572 PHY_L_IS_SS = 1<<9, /* Bit 9: Smart Speed Downgrade */
1573 PHY_L_IS_CFULL = 1<<8, /* Bit 8: Counter Full */
1574 PHY_L_IS_AN_C = 1<<7, /* Bit 7: AutoNeg Complete */
1575 PHY_L_IS_SPEED = 1<<6, /* Bit 6: Speed Changed */
1576 PHY_L_IS_DUP = 1<<5, /* Bit 5: Duplex Changed */
1577 PHY_L_IS_LS = 1<<4, /* Bit 4: Link Status Changed */
1578 PHY_L_IS_ISOL = 1<<3, /* Bit 3: Isolate Occured */
1579 PHY_L_IS_MDINT = 1<<2, /* Bit 2: (ro) STAT: MII Int Pending */
1580 PHY_L_IS_INTEN = 1<<1, /* Bit 1: ENAB: Enable IRQs */
1581 PHY_L_IS_FORCE = 1<<0, /* Bit 0: ENAB: Force Interrupt */
1582};
1583
1584/* int. mask */
1585#define PHY_L_DEF_MSK (PHY_L_IS_LS | PHY_L_IS_ISOL | PHY_L_IS_INTEN)
1586
1587/***** PHY_LONE_LED_CFG 16 bit r/w LED Configuration Reg *****/
1588enum {
1589 PHY_L_LC_LEDC = 3<<14,/* Bit 15..14: Col/Blink/On/Off */
1590 PHY_L_LC_LEDR = 3<<12,/* Bit 13..12: Rx/Blink/On/Off */
1591 PHY_L_LC_LEDT = 3<<10,/* Bit 11..10: Tx/Blink/On/Off */
1592 PHY_L_LC_LEDG = 3<<8,/* Bit 9..8: Giga/Blink/On/Off */
1593 PHY_L_LC_LEDS = 3<<6,/* Bit 7..6: 10-100/Blink/On/Off */
1594 PHY_L_LC_LEDL = 3<<4,/* Bit 5..4: Link/Blink/On/Off */
1595 PHY_L_LC_LEDF = 3<<2,/* Bit 3..2: Duplex/Blink/On/Off */
1596 PHY_L_LC_PSTRECH= 1<<1, /* Bit 1: Strech LED Pulses */
1597 PHY_L_LC_FREQ = 1<<0, /* Bit 0: 30/100 ms */
1598};
1599
1600/***** PHY_LONE_PORT_CTRL 16 bit r/w Port Control Reg *****/
1601enum {
1602 PHY_L_PC_TX_TCLK = 1<<15, /* Bit 15: Enable TX_TCLK */
1603 PHY_L_PC_ALT_NP = 1<<13, /* Bit 14: Alternate Next Page */
1604 PHY_L_PC_GMII_ALT= 1<<12, /* Bit 13: Alternate GMII driver */
1605 PHY_L_PC_TEN_CRS = 1<<10, /* Bit 10: Extend CRS*/
1606};
1607
1608/***** PHY_LONE_CIM 16 bit r/o CIM Reg *****/
1609enum {
1610 PHY_L_CIM_ISOL = 0xff<<8,/* Bit 15..8: Isolate Count */
1611 PHY_L_CIM_FALSE_CAR = 0xff, /* Bit 7..0: False Carrier Count */
1612};
1613
1614/*
1615 * Pause Bits (PHY_L_AN_ASP and PHY_L_AN_PC) encoding
1616 */
1617enum {
1618 PHY_L_P_NO_PAUSE= 0<<10,/* Bit 11..10: no Pause Mode */
1619 PHY_L_P_SYM_MD = 1<<10, /* Bit 11..10: symmetric Pause Mode */
1620 PHY_L_P_ASYM_MD = 2<<10,/* Bit 11..10: asymmetric Pause Mode */
1621 PHY_L_P_BOTH_MD = 3<<10,/* Bit 11..10: both Pause Mode */
1622};
1623
1624/*
1625 * National-Specific
1626 */
1627/***** PHY_NAT_1000T_CTRL 16 bit r/w 1000Base-T Control Reg *****/
1628enum {
1629 PHY_N_1000C_TEST= 7<<13,/* Bit 15..13: Test Modes */
1630 PHY_N_1000C_MSE = 1<<12, /* Bit 12: Master/Slave Enable */
1631 PHY_N_1000C_MSC = 1<<11, /* Bit 11: M/S Configuration */
1632 PHY_N_1000C_RD = 1<<10, /* Bit 10: Repeater/DTE */
1633 PHY_N_1000C_AFD = 1<<9, /* Bit 9: Advertise Full Duplex */
1634 PHY_N_1000C_AHD = 1<<8, /* Bit 8: Advertise Half Duplex */
1635 PHY_N_1000C_APC = 1<<7, /* Bit 7: Asymmetric Pause Cap. */};
1636
1637
1638/***** PHY_NAT_1000T_STAT 16 bit r/o 1000Base-T Status Reg *****/
1639enum {
1640 PHY_N_1000S_MSF = 1<<15, /* Bit 15: Master/Slave Fault */
1641 PHY_N_1000S_MSR = 1<<14, /* Bit 14: Master/Slave Result */
1642 PHY_N_1000S_LRS = 1<<13, /* Bit 13: Local Receiver Status */
1643 PHY_N_1000S_RRS = 1<<12, /* Bit 12: Remote Receiver Status*/
1644 PHY_N_1000S_LP_FD= 1<<11, /* Bit 11: Link Partner can FD */
1645 PHY_N_1000S_LP_HD= 1<<10, /* Bit 10: Link Partner can HD */
1646 PHY_N_1000C_LP_APC= 1<<9, /* Bit 9: LP Asym. Pause Cap. */
1647 PHY_N_1000S_IEC = 0xff, /* Bit 7..0: Idle Error Count */
1648};
1649
1650/***** PHY_NAT_EXT_STAT 16 bit r/o Extended Status Register *****/
1651enum {
1652 PHY_N_ES_X_FD_CAP= 1<<15, /* Bit 15: 1000Base-X FD capable */
1653 PHY_N_ES_X_HD_CAP= 1<<14, /* Bit 14: 1000Base-X HD capable */
1654 PHY_N_ES_T_FD_CAP= 1<<13, /* Bit 13: 1000Base-T FD capable */
1655 PHY_N_ES_T_HD_CAP= 1<<12, /* Bit 12: 1000Base-T HD capable */
1656};
1657
1658/** Marvell-Specific */ 1321/** Marvell-Specific */
1659enum { 1322enum {
1660 PHY_M_AN_NXT_PG = 1<<15, /* Request Next Page */ 1323 PHY_M_AN_NXT_PG = 1<<15, /* Request Next Page */
@@ -1718,7 +1381,7 @@ enum {
1718 PHY_M_PC_EN_DET_PLUS = 3<<8, /* Energy Detect Plus (Mode 2) */ 1381 PHY_M_PC_EN_DET_PLUS = 3<<8, /* Energy Detect Plus (Mode 2) */
1719}; 1382};
1720 1383
1721#define PHY_M_PC_MDI_XMODE(x) (((x)<<5) & PHY_M_PC_MDIX_MSK) 1384#define PHY_M_PC_MDI_XMODE(x) (((x)<<5) & PHY_M_PC_MDIX_MSK)
1722 1385
1723enum { 1386enum {
1724 PHY_M_PC_MAN_MDI = 0, /* 00 = Manual MDI configuration */ 1387 PHY_M_PC_MAN_MDI = 0, /* 00 = Manual MDI configuration */
@@ -2105,7 +1768,7 @@ enum {
2105 GM_GPSR_FC_RX_DIS = 1<<2, /* Bit 2: Rx Flow-Control Mode Disabled */ 1768 GM_GPSR_FC_RX_DIS = 1<<2, /* Bit 2: Rx Flow-Control Mode Disabled */
2106 GM_GPSR_PROM_EN = 1<<1, /* Bit 1: Promiscuous Mode Enabled */ 1769 GM_GPSR_PROM_EN = 1<<1, /* Bit 1: Promiscuous Mode Enabled */
2107}; 1770};
2108 1771
2109/* GM_GP_CTRL 16 bit r/w General Purpose Control Register */ 1772/* GM_GP_CTRL 16 bit r/w General Purpose Control Register */
2110enum { 1773enum {
2111 GM_GPCR_PROM_ENA = 1<<14, /* Bit 14: Enable Promiscuous Mode */ 1774 GM_GPCR_PROM_ENA = 1<<14, /* Bit 14: Enable Promiscuous Mode */
@@ -2127,7 +1790,7 @@ enum {
2127 1790
2128#define GM_GPCR_SPEED_1000 (GM_GPCR_GIGS_ENA | GM_GPCR_SPEED_100) 1791#define GM_GPCR_SPEED_1000 (GM_GPCR_GIGS_ENA | GM_GPCR_SPEED_100)
2129#define GM_GPCR_AU_ALL_DIS (GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS|GM_GPCR_AU_SPD_DIS) 1792#define GM_GPCR_AU_ALL_DIS (GM_GPCR_AU_DUP_DIS | GM_GPCR_AU_FCT_DIS|GM_GPCR_AU_SPD_DIS)
2130 1793
2131/* GM_TX_CTRL 16 bit r/w Transmit Control Register */ 1794/* GM_TX_CTRL 16 bit r/w Transmit Control Register */
2132enum { 1795enum {
2133 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */ 1796 GM_TXCR_FORCE_JAM = 1<<15, /* Bit 15: Force Jam / Flow-Control */
@@ -2138,7 +1801,7 @@ enum {
2138 1801
2139#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK) 1802#define TX_COL_THR(x) (((x)<<10) & GM_TXCR_COL_THR_MSK)
2140#define TX_COL_DEF 0x04 1803#define TX_COL_DEF 0x04
2141 1804
2142/* GM_RX_CTRL 16 bit r/w Receive Control Register */ 1805/* GM_RX_CTRL 16 bit r/w Receive Control Register */
2143enum { 1806enum {
2144 GM_RXCR_UCF_ENA = 1<<15, /* Bit 15: Enable Unicast filtering */ 1807 GM_RXCR_UCF_ENA = 1<<15, /* Bit 15: Enable Unicast filtering */
@@ -2146,7 +1809,7 @@ enum {
2146 GM_RXCR_CRC_DIS = 1<<13, /* Bit 13: Remove 4-byte CRC */ 1809 GM_RXCR_CRC_DIS = 1<<13, /* Bit 13: Remove 4-byte CRC */
2147 GM_RXCR_PASS_FC = 1<<12, /* Bit 12: Pass FC packets to FIFO */ 1810 GM_RXCR_PASS_FC = 1<<12, /* Bit 12: Pass FC packets to FIFO */
2148}; 1811};
2149 1812
2150/* GM_TX_PARAM 16 bit r/w Transmit Parameter Register */ 1813/* GM_TX_PARAM 16 bit r/w Transmit Parameter Register */
2151enum { 1814enum {
2152 GM_TXPA_JAMLEN_MSK = 0x03<<14, /* Bit 15..14: Jam Length */ 1815 GM_TXPA_JAMLEN_MSK = 0x03<<14, /* Bit 15..14: Jam Length */
@@ -2171,7 +1834,7 @@ enum {
2171 GM_SMOD_JUMBO_ENA = 1<<8, /* Bit 8: Enable Jumbo (Max. Frame Len) */ 1834 GM_SMOD_JUMBO_ENA = 1<<8, /* Bit 8: Enable Jumbo (Max. Frame Len) */
2172 GM_SMOD_IPG_MSK = 0x1f /* Bit 4..0: Inter-Packet Gap (IPG) */ 1835 GM_SMOD_IPG_MSK = 0x1f /* Bit 4..0: Inter-Packet Gap (IPG) */
2173}; 1836};
2174 1837
2175#define DATA_BLIND_VAL(x) (((x)<<11) & GM_SMOD_DATABL_MSK) 1838#define DATA_BLIND_VAL(x) (((x)<<11) & GM_SMOD_DATABL_MSK)
2176#define DATA_BLIND_DEF 0x04 1839#define DATA_BLIND_DEF 0x04
2177 1840
@@ -2186,7 +1849,7 @@ enum {
2186 GM_SMI_CT_RD_VAL = 1<<4, /* Bit 4: Read Valid (Read completed) */ 1849 GM_SMI_CT_RD_VAL = 1<<4, /* Bit 4: Read Valid (Read completed) */
2187 GM_SMI_CT_BUSY = 1<<3, /* Bit 3: Busy (Operation in progress) */ 1850 GM_SMI_CT_BUSY = 1<<3, /* Bit 3: Busy (Operation in progress) */
2188}; 1851};
2189 1852
2190#define GM_SMI_CT_PHY_AD(x) (((x)<<11) & GM_SMI_CT_PHY_A_MSK) 1853#define GM_SMI_CT_PHY_AD(x) (((x)<<11) & GM_SMI_CT_PHY_A_MSK)
2191#define GM_SMI_CT_REG_AD(x) (((x)<<6) & GM_SMI_CT_REG_A_MSK) 1854#define GM_SMI_CT_REG_AD(x) (((x)<<6) & GM_SMI_CT_REG_A_MSK)
2192 1855
@@ -2195,7 +1858,7 @@ enum {
2195 GM_PAR_MIB_CLR = 1<<5, /* Bit 5: Set MIB Clear Counter Mode */ 1858 GM_PAR_MIB_CLR = 1<<5, /* Bit 5: Set MIB Clear Counter Mode */
2196 GM_PAR_MIB_TST = 1<<4, /* Bit 4: MIB Load Counter (Test Mode) */ 1859 GM_PAR_MIB_TST = 1<<4, /* Bit 4: MIB Load Counter (Test Mode) */
2197}; 1860};
2198 1861
2199/* Receive Frame Status Encoding */ 1862/* Receive Frame Status Encoding */
2200enum { 1863enum {
2201 GMR_FS_LEN = 0xffff<<16, /* Bit 31..16: Rx Frame Length */ 1864 GMR_FS_LEN = 0xffff<<16, /* Bit 31..16: Rx Frame Length */
@@ -2217,12 +1880,12 @@ enum {
2217/* 1880/*
2218 * GMR_FS_ANY_ERR (analogous to XMR_FS_ANY_ERR) 1881 * GMR_FS_ANY_ERR (analogous to XMR_FS_ANY_ERR)
2219 */ 1882 */
2220 GMR_FS_ANY_ERR = GMR_FS_CRC_ERR | GMR_FS_LONG_ERR | 1883 GMR_FS_ANY_ERR = GMR_FS_CRC_ERR | GMR_FS_LONG_ERR |
2221 GMR_FS_MII_ERR | GMR_FS_BAD_FC | GMR_FS_GOOD_FC | 1884 GMR_FS_MII_ERR | GMR_FS_BAD_FC | GMR_FS_GOOD_FC |
2222 GMR_FS_JABBER, 1885 GMR_FS_JABBER,
2223/* Rx GMAC FIFO Flush Mask (default) */ 1886/* Rx GMAC FIFO Flush Mask (default) */
2224 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR | 1887 RX_FF_FL_DEF_MSK = GMR_FS_CRC_ERR | GMR_FS_RX_FF_OV |GMR_FS_MII_ERR |
2225 GMR_FS_BAD_FC | GMR_FS_GOOD_FC | GMR_FS_UN_SIZE | 1888 GMR_FS_BAD_FC | GMR_FS_GOOD_FC | GMR_FS_UN_SIZE |
2226 GMR_FS_JABBER, 1889 GMR_FS_JABBER,
2227}; 1890};
2228 1891
@@ -2540,10 +2203,6 @@ enum {
2540}; 2203};
2541 2204
2542 2205
2543/* XM_PHY_ADDR 16 bit r/w PHY Address Register */
2544#define XM_PHY_ADDR_SZ 0x1f /* Bit 4..0: PHY Address bits */
2545
2546
2547/* XM_GP_PORT 32 bit r/w General Purpose Port Register */ 2206/* XM_GP_PORT 32 bit r/w General Purpose Port Register */
2548enum { 2207enum {
2549 XM_GP_ANIP = 1<<6, /* Bit 6: (ro) Auto-Neg. in progress */ 2208 XM_GP_ANIP = 1<<6, /* Bit 6: (ro) Auto-Neg. in progress */
@@ -2662,8 +2321,8 @@ enum {
2662}; 2321};
2663 2322
2664#define XM_PAUSE_MODE (XM_MD_SPOE_E | XM_MD_SPOL_I | XM_MD_SPOH_I) 2323#define XM_PAUSE_MODE (XM_MD_SPOE_E | XM_MD_SPOL_I | XM_MD_SPOH_I)
2665#define XM_DEF_MODE (XM_MD_RX_RUNT | XM_MD_RX_IRLE | XM_MD_RX_LONG |\ 2324#define XM_DEF_MODE (XM_MD_RX_RUNT | XM_MD_RX_IRLE | XM_MD_RX_LONG |\
2666 XM_MD_RX_CRCE | XM_MD_RX_ERR | XM_MD_CSA | XM_MD_CAA) 2325 XM_MD_RX_CRCE | XM_MD_RX_ERR | XM_MD_CSA)
2667 2326
2668/* XM_STAT_CMD 16 bit r/w Statistics Command Register */ 2327/* XM_STAT_CMD 16 bit r/w Statistics Command Register */
2669enum { 2328enum {
@@ -2793,28 +2452,20 @@ struct skge_hw {
2793 u32 intr_mask; 2452 u32 intr_mask;
2794 struct net_device *dev[2]; 2453 struct net_device *dev[2];
2795 2454
2796 u8 mac_cfg;
2797 u8 chip_id; 2455 u8 chip_id;
2456 u8 chip_rev;
2798 u8 phy_type; 2457 u8 phy_type;
2799 u8 pmd_type; 2458 u8 pmd_type;
2800 u16 phy_addr; 2459 u16 phy_addr;
2460 u8 ports;
2801 2461
2802 u32 ram_size; 2462 u32 ram_size;
2803 u32 ram_offset; 2463 u32 ram_offset;
2804 2464
2805 struct tasklet_struct ext_tasklet; 2465 struct tasklet_struct ext_tasklet;
2806 spinlock_t phy_lock; 2466 spinlock_t phy_lock;
2807}; 2467};
2808 2468
2809static inline int isdualport(const struct skge_hw *hw)
2810{
2811 return !(hw->mac_cfg & CFG_SNG_MAC);
2812}
2813
2814static inline u8 chip_rev(const struct skge_hw *hw)
2815{
2816 return (hw->mac_cfg & CFG_CHIP_R_MSK) >> 4;
2817}
2818 2469
2819static inline int iscopper(const struct skge_hw *hw) 2470static inline int iscopper(const struct skge_hw *hw)
2820{ 2471{
@@ -2827,7 +2478,7 @@ enum {
2827 FLOW_MODE_REM_SEND = 2, /* Symmetric or just remote */ 2478 FLOW_MODE_REM_SEND = 2, /* Symmetric or just remote */
2828 FLOW_MODE_SYMMETRIC = 3, /* Both stations may send PAUSE */ 2479 FLOW_MODE_SYMMETRIC = 3, /* Both stations may send PAUSE */
2829}; 2480};
2830 2481
2831struct skge_port { 2482struct skge_port {
2832 u32 msg_enable; 2483 u32 msg_enable;
2833 struct skge_hw *hw; 2484 struct skge_hw *hw;
@@ -2853,8 +2504,8 @@ struct skge_port {
2853 void *mem; /* PCI memory for rings */ 2504 void *mem; /* PCI memory for rings */
2854 dma_addr_t dma; 2505 dma_addr_t dma;
2855 unsigned long mem_size; 2506 unsigned long mem_size;
2507 unsigned int rx_buf_size;
2856 2508
2857 struct timer_list link_check;
2858 struct timer_list led_blink; 2509 struct timer_list led_blink;
2859}; 2510};
2860 2511
@@ -2863,7 +2514,6 @@ struct skge_port {
2863static inline u32 skge_read32(const struct skge_hw *hw, int reg) 2514static inline u32 skge_read32(const struct skge_hw *hw, int reg)
2864{ 2515{
2865 return readl(hw->regs + reg); 2516 return readl(hw->regs + reg);
2866
2867} 2517}
2868 2518
2869static inline u16 skge_read16(const struct skge_hw *hw, int reg) 2519static inline u16 skge_read16(const struct skge_hw *hw, int reg)
@@ -2892,114 +2542,87 @@ static inline void skge_write8(const struct skge_hw *hw, int reg, u8 val)
2892} 2542}
2893 2543
2894/* MAC Related Registers inside the device. */ 2544/* MAC Related Registers inside the device. */
2895#define SKGEMAC_REG(port,reg) (((port)<<7)+(reg)) 2545#define SK_REG(port,reg) (((port)<<7)+(reg))
2896 2546#define SK_XMAC_REG(port, reg) \
2897/* PCI config space can be accessed via memory mapped space */
2898#define SKGEPCI_REG(reg) ((reg)+ 0x380)
2899
2900#define SKGEXM_REG(port, reg) \
2901 ((BASE_XMAC_1 + (port) * (BASE_XMAC_2 - BASE_XMAC_1)) | (reg) << 1) 2547 ((BASE_XMAC_1 + (port) * (BASE_XMAC_2 - BASE_XMAC_1)) | (reg) << 1)
2902 2548
2903static inline u32 skge_xm_read32(const struct skge_hw *hw, int port, int reg) 2549static inline u32 xm_read32(const struct skge_hw *hw, int port, int reg)
2904{
2905 return skge_read32(hw, SKGEXM_REG(port,reg));
2906}
2907
2908static inline u16 skge_xm_read16(const struct skge_hw *hw, int port, int reg)
2909{ 2550{
2910 return skge_read16(hw, SKGEXM_REG(port,reg)); 2551 u32 v;
2552 v = skge_read16(hw, SK_XMAC_REG(port, reg));
2553 v |= (u32)skge_read16(hw, SK_XMAC_REG(port, reg+2)) << 16;
2554 return v;
2911} 2555}
2912 2556
2913static inline u8 skge_xm_read8(const struct skge_hw *hw, int port, int reg) 2557static inline u16 xm_read16(const struct skge_hw *hw, int port, int reg)
2914{ 2558{
2915 return skge_read8(hw, SKGEXM_REG(port,reg)); 2559 return skge_read16(hw, SK_XMAC_REG(port,reg));
2916} 2560}
2917 2561
2918static inline void skge_xm_write32(const struct skge_hw *hw, int port, int r, u32 v) 2562static inline void xm_write32(const struct skge_hw *hw, int port, int r, u32 v)
2919{ 2563{
2920 skge_write32(hw, SKGEXM_REG(port,r), v); 2564 skge_write16(hw, SK_XMAC_REG(port,r), v & 0xffff);
2565 skge_write16(hw, SK_XMAC_REG(port,r+2), v >> 16);
2921} 2566}
2922 2567
2923static inline void skge_xm_write16(const struct skge_hw *hw, int port, int r, u16 v) 2568static inline void xm_write16(const struct skge_hw *hw, int port, int r, u16 v)
2924{ 2569{
2925 skge_write16(hw, SKGEXM_REG(port,r), v); 2570 skge_write16(hw, SK_XMAC_REG(port,r), v);
2926} 2571}
2927 2572
2928static inline void skge_xm_write8(const struct skge_hw *hw, int port, int r, u8 v) 2573static inline void xm_outhash(const struct skge_hw *hw, int port, int reg,
2929{
2930 skge_write8(hw, SKGEXM_REG(port,r), v);
2931}
2932
2933static inline void skge_xm_outhash(const struct skge_hw *hw, int port, int reg,
2934 const u8 *hash) 2574 const u8 *hash)
2935{ 2575{
2936 skge_xm_write16(hw, port, reg, 2576 xm_write16(hw, port, reg, (u16)hash[0] | ((u16)hash[1] << 8));
2937 (u16)hash[0] | ((u16)hash[1] << 8)); 2577 xm_write16(hw, port, reg+2, (u16)hash[2] | ((u16)hash[3] << 8));
2938 skge_xm_write16(hw, port, reg+2, 2578 xm_write16(hw, port, reg+4, (u16)hash[4] | ((u16)hash[5] << 8));
2939 (u16)hash[2] | ((u16)hash[3] << 8)); 2579 xm_write16(hw, port, reg+6, (u16)hash[6] | ((u16)hash[7] << 8));
2940 skge_xm_write16(hw, port, reg+4,
2941 (u16)hash[4] | ((u16)hash[5] << 8));
2942 skge_xm_write16(hw, port, reg+6,
2943 (u16)hash[6] | ((u16)hash[7] << 8));
2944} 2580}
2945 2581
2946static inline void skge_xm_outaddr(const struct skge_hw *hw, int port, int reg, 2582static inline void xm_outaddr(const struct skge_hw *hw, int port, int reg,
2947 const u8 *addr) 2583 const u8 *addr)
2948{ 2584{
2949 skge_xm_write16(hw, port, reg, 2585 xm_write16(hw, port, reg, (u16)addr[0] | ((u16)addr[1] << 8));
2950 (u16)addr[0] | ((u16)addr[1] << 8)); 2586 xm_write16(hw, port, reg+2, (u16)addr[2] | ((u16)addr[3] << 8));
2951 skge_xm_write16(hw, port, reg, 2587 xm_write16(hw, port, reg+4, (u16)addr[4] | ((u16)addr[5] << 8));
2952 (u16)addr[2] | ((u16)addr[3] << 8));
2953 skge_xm_write16(hw, port, reg,
2954 (u16)addr[4] | ((u16)addr[5] << 8));
2955} 2588}
2956 2589
2590#define SK_GMAC_REG(port,reg) \
2591 (BASE_GMAC_1 + (port) * (BASE_GMAC_2-BASE_GMAC_1) + (reg))
2957 2592
2958#define SKGEGMA_REG(port,reg) \ 2593static inline u16 gma_read16(const struct skge_hw *hw, int port, int reg)
2959 ((reg) + BASE_GMAC_1 + \
2960 (port) * (BASE_GMAC_2-BASE_GMAC_1))
2961
2962static inline u16 skge_gma_read16(const struct skge_hw *hw, int port, int reg)
2963{ 2594{
2964 return skge_read16(hw, SKGEGMA_REG(port,reg)); 2595 return skge_read16(hw, SK_GMAC_REG(port,reg));
2965} 2596}
2966 2597
2967static inline u32 skge_gma_read32(const struct skge_hw *hw, int port, int reg) 2598static inline u32 gma_read32(const struct skge_hw *hw, int port, int reg)
2968{ 2599{
2969 return (u32) skge_read16(hw, SKGEGMA_REG(port,reg)) 2600 return (u32) skge_read16(hw, SK_GMAC_REG(port,reg))
2970 | ((u32)skge_read16(hw, SKGEGMA_REG(port,reg+4)) << 16); 2601 | ((u32)skge_read16(hw, SK_GMAC_REG(port,reg+4)) << 16);
2971} 2602}
2972 2603
2973static inline u8 skge_gma_read8(const struct skge_hw *hw, int port, int reg) 2604static inline void gma_write16(const struct skge_hw *hw, int port, int r, u16 v)
2974{ 2605{
2975 return skge_read8(hw, SKGEGMA_REG(port,reg)); 2606 skge_write16(hw, SK_GMAC_REG(port,r), v);
2976} 2607}
2977 2608
2978static inline void skge_gma_write16(const struct skge_hw *hw, int port, int r, u16 v) 2609static inline void gma_write32(const struct skge_hw *hw, int port, int r, u32 v)
2979{ 2610{
2980 skge_write16(hw, SKGEGMA_REG(port,r), v); 2611 skge_write16(hw, SK_GMAC_REG(port, r), (u16) v);
2612 skge_write32(hw, SK_GMAC_REG(port, r+4), (u16)(v >> 16));
2981} 2613}
2982 2614
2983static inline void skge_gma_write32(const struct skge_hw *hw, int port, int r, u32 v) 2615static inline void gma_write8(const struct skge_hw *hw, int port, int r, u8 v)
2984{ 2616{
2985 skge_write16(hw, SKGEGMA_REG(port, r), (u16) v); 2617 skge_write8(hw, SK_GMAC_REG(port,r), v);
2986 skge_write32(hw, SKGEGMA_REG(port, r+4), (u16)(v >> 16));
2987} 2618}
2988 2619
2989static inline void skge_gma_write8(const struct skge_hw *hw, int port, int r, u8 v) 2620static inline void gma_set_addr(struct skge_hw *hw, int port, int reg,
2990{
2991 skge_write8(hw, SKGEGMA_REG(port,r), v);
2992}
2993
2994static inline void skge_gm_set_addr(struct skge_hw *hw, int port, int reg,
2995 const u8 *addr) 2621 const u8 *addr)
2996{ 2622{
2997 skge_gma_write16(hw, port, reg, 2623 gma_write16(hw, port, reg, (u16) addr[0] | ((u16) addr[1] << 8));
2998 (u16) addr[0] | ((u16) addr[1] << 8)); 2624 gma_write16(hw, port, reg+4,(u16) addr[2] | ((u16) addr[3] << 8));
2999 skge_gma_write16(hw, port, reg+4, 2625 gma_write16(hw, port, reg+8,(u16) addr[4] | ((u16) addr[5] << 8));
3000 (u16) addr[2] | ((u16) addr[3] << 8));
3001 skge_gma_write16(hw, port, reg+8,
3002 (u16) addr[4] | ((u16) addr[5] << 8));
3003} 2626}
3004 2627
3005#endif 2628#endif
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index c79e0ad4ba02..404ea4297e32 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -74,6 +74,7 @@
74#include <linux/rtnetlink.h> 74#include <linux/rtnetlink.h>
75#include <linux/if_arp.h> 75#include <linux/if_arp.h>
76#include <linux/if_slip.h> 76#include <linux/if_slip.h>
77#include <linux/delay.h>
77#include <linux/init.h> 78#include <linux/init.h>
78#include "slip.h" 79#include "slip.h"
79#ifdef CONFIG_INET 80#ifdef CONFIG_INET
@@ -1383,10 +1384,8 @@ static void __exit slip_exit(void)
1383 /* First of all: check for active disciplines and hangup them. 1384 /* First of all: check for active disciplines and hangup them.
1384 */ 1385 */
1385 do { 1386 do {
1386 if (busy) { 1387 if (busy)
1387 set_current_state(TASK_INTERRUPTIBLE); 1388 msleep_interruptible(100);
1388 schedule_timeout(HZ / 10);
1389 }
1390 1389
1391 busy = 0; 1390 busy = 0;
1392 for (i = 0; i < slip_maxdev; i++) { 1391 for (i = 0; i < slip_maxdev; i++) {
diff --git a/drivers/net/smc-mca.c b/drivers/net/smc-mca.c
index 990201f42ba0..f00c476064f0 100644
--- a/drivers/net/smc-mca.c
+++ b/drivers/net/smc-mca.c
@@ -49,7 +49,6 @@
49#include <asm/system.h> 49#include <asm/system.h>
50 50
51#include "8390.h" 51#include "8390.h"
52#include "smc-mca.h"
53 52
54#define DRV_NAME "smc-mca" 53#define DRV_NAME "smc-mca"
55 54
@@ -100,6 +99,63 @@ module_param_array(ultra_irq, int, NULL, 0);
100MODULE_PARM_DESC(ultra_io, "SMC Ultra/EtherEZ MCA I/O base address(es)"); 99MODULE_PARM_DESC(ultra_io, "SMC Ultra/EtherEZ MCA I/O base address(es)");
101MODULE_PARM_DESC(ultra_irq, "SMC Ultra/EtherEZ MCA IRQ number(s)"); 100MODULE_PARM_DESC(ultra_irq, "SMC Ultra/EtherEZ MCA IRQ number(s)");
102 101
102static const struct {
103 unsigned int base_addr;
104} addr_table[] = {
105 { 0x0800 },
106 { 0x1800 },
107 { 0x2800 },
108 { 0x3800 },
109 { 0x4800 },
110 { 0x5800 },
111 { 0x6800 },
112 { 0x7800 },
113 { 0x8800 },
114 { 0x9800 },
115 { 0xa800 },
116 { 0xb800 },
117 { 0xc800 },
118 { 0xd800 },
119 { 0xe800 },
120 { 0xf800 }
121};
122
123#define MEM_MASK 64
124
125static const struct {
126 unsigned char mem_index;
127 unsigned long mem_start;
128 unsigned char num_pages;
129} mem_table[] = {
130 { 16, 0x0c0000, 40 },
131 { 18, 0x0c4000, 40 },
132 { 20, 0x0c8000, 40 },
133 { 22, 0x0cc000, 40 },
134 { 24, 0x0d0000, 40 },
135 { 26, 0x0d4000, 40 },
136 { 28, 0x0d8000, 40 },
137 { 30, 0x0dc000, 40 },
138 {144, 0xfc0000, 40 },
139 {148, 0xfc8000, 40 },
140 {154, 0xfd0000, 40 },
141 {156, 0xfd8000, 40 },
142 { 0, 0x0c0000, 20 },
143 { 1, 0x0c2000, 20 },
144 { 2, 0x0c4000, 20 },
145 { 3, 0x0c6000, 20 }
146};
147
148#define IRQ_MASK 243
149static const struct {
150 unsigned char new_irq;
151 unsigned char old_irq;
152} irq_table[] = {
153 { 3, 3 },
154 { 4, 4 },
155 { 10, 10 },
156 { 14, 15 }
157};
158
103static short smc_mca_adapter_ids[] __initdata = { 159static short smc_mca_adapter_ids[] __initdata = {
104 0x61c8, 160 0x61c8,
105 0x61c9, 161 0x61c9,
@@ -126,7 +182,7 @@ static char *smc_mca_adapter_names[] __initdata = {
126 182
127static int ultra_found = 0; 183static int ultra_found = 0;
128 184
129int __init ultramca_probe(struct device *gen_dev) 185static int __init ultramca_probe(struct device *gen_dev)
130{ 186{
131 unsigned short ioaddr; 187 unsigned short ioaddr;
132 struct net_device *dev; 188 struct net_device *dev;
diff --git a/drivers/net/smc-mca.h b/drivers/net/smc-mca.h
deleted file mode 100644
index ac50117a7e84..000000000000
--- a/drivers/net/smc-mca.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * djweis weisd3458@uni.edu
3 * most of this file was taken from ps2esdi.h
4 */
5
6struct {
7 unsigned int base_addr;
8} addr_table[] = {
9 { 0x0800 },
10 { 0x1800 },
11 { 0x2800 },
12 { 0x3800 },
13 { 0x4800 },
14 { 0x5800 },
15 { 0x6800 },
16 { 0x7800 },
17 { 0x8800 },
18 { 0x9800 },
19 { 0xa800 },
20 { 0xb800 },
21 { 0xc800 },
22 { 0xd800 },
23 { 0xe800 },
24 { 0xf800 }
25};
26
27#define MEM_MASK 64
28
29struct {
30 unsigned char mem_index;
31 unsigned long mem_start;
32 unsigned char num_pages;
33} mem_table[] = {
34 { 16, 0x0c0000, 40 },
35 { 18, 0x0c4000, 40 },
36 { 20, 0x0c8000, 40 },
37 { 22, 0x0cc000, 40 },
38 { 24, 0x0d0000, 40 },
39 { 26, 0x0d4000, 40 },
40 { 28, 0x0d8000, 40 },
41 { 30, 0x0dc000, 40 },
42 {144, 0xfc0000, 40 },
43 {148, 0xfc8000, 40 },
44 {154, 0xfd0000, 40 },
45 {156, 0xfd8000, 40 },
46 { 0, 0x0c0000, 20 },
47 { 1, 0x0c2000, 20 },
48 { 2, 0x0c4000, 20 },
49 { 3, 0x0c6000, 20 }
50};
51
52#define IRQ_MASK 243
53struct {
54 unsigned char new_irq;
55 unsigned char old_irq;
56} irq_table[] = {
57 { 3, 3 },
58 { 4, 4 },
59 { 10, 10 },
60 { 14, 15 }
61};
diff --git a/drivers/net/smc-ultra.c b/drivers/net/smc-ultra.c
index b564c677c6d2..6d9dae60a697 100644
--- a/drivers/net/smc-ultra.c
+++ b/drivers/net/smc-ultra.c
@@ -194,12 +194,7 @@ struct net_device * __init ultra_probe(int unit)
194 err = do_ultra_probe(dev); 194 err = do_ultra_probe(dev);
195 if (err) 195 if (err)
196 goto out; 196 goto out;
197 err = register_netdev(dev);
198 if (err)
199 goto out1;
200 return dev; 197 return dev;
201out1:
202 cleanup_card(dev);
203out: 198out:
204 free_netdev(dev); 199 free_netdev(dev);
205 return ERR_PTR(err); 200 return ERR_PTR(err);
@@ -325,6 +320,9 @@ static int __init ultra_probe1(struct net_device *dev, int ioaddr)
325#endif 320#endif
326 NS8390_init(dev, 0); 321 NS8390_init(dev, 0);
327 322
323 retval = register_netdev(dev);
324 if (retval)
325 goto out;
328 return 0; 326 return 0;
329out: 327out:
330 release_region(ioaddr, ULTRA_IO_EXTENT); 328 release_region(ioaddr, ULTRA_IO_EXTENT);
@@ -583,11 +581,8 @@ init_module(void)
583 dev->irq = irq[this_dev]; 581 dev->irq = irq[this_dev];
584 dev->base_addr = io[this_dev]; 582 dev->base_addr = io[this_dev];
585 if (do_ultra_probe(dev) == 0) { 583 if (do_ultra_probe(dev) == 0) {
586 if (register_netdev(dev) == 0) { 584 dev_ultra[found++] = dev;
587 dev_ultra[found++] = dev; 585 continue;
588 continue;
589 }
590 cleanup_card(dev);
591 } 586 }
592 free_netdev(dev); 587 free_netdev(dev);
593 printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]); 588 printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index fd80048f7f7a..1438fdd20826 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -315,15 +315,25 @@ static void smc_reset(struct net_device *dev)
315 struct smc_local *lp = netdev_priv(dev); 315 struct smc_local *lp = netdev_priv(dev);
316 void __iomem *ioaddr = lp->base; 316 void __iomem *ioaddr = lp->base;
317 unsigned int ctl, cfg; 317 unsigned int ctl, cfg;
318 struct sk_buff *pending_skb;
318 319
319 DBG(2, "%s: %s\n", dev->name, __FUNCTION__); 320 DBG(2, "%s: %s\n", dev->name, __FUNCTION__);
320 321
321 /* Disable all interrupts */ 322 /* Disable all interrupts, block TX tasklet */
322 spin_lock(&lp->lock); 323 spin_lock(&lp->lock);
323 SMC_SELECT_BANK(2); 324 SMC_SELECT_BANK(2);
324 SMC_SET_INT_MASK(0); 325 SMC_SET_INT_MASK(0);
326 pending_skb = lp->pending_tx_skb;
327 lp->pending_tx_skb = NULL;
325 spin_unlock(&lp->lock); 328 spin_unlock(&lp->lock);
326 329
330 /* free any pending tx skb */
331 if (pending_skb) {
332 dev_kfree_skb(pending_skb);
333 lp->stats.tx_errors++;
334 lp->stats.tx_aborted_errors++;
335 }
336
327 /* 337 /*
328 * This resets the registers mostly to defaults, but doesn't 338 * This resets the registers mostly to defaults, but doesn't
329 * affect EEPROM. That seems unnecessary 339 * affect EEPROM. That seems unnecessary
@@ -389,14 +399,6 @@ static void smc_reset(struct net_device *dev)
389 SMC_SELECT_BANK(2); 399 SMC_SELECT_BANK(2);
390 SMC_SET_MMU_CMD(MC_RESET); 400 SMC_SET_MMU_CMD(MC_RESET);
391 SMC_WAIT_MMU_BUSY(); 401 SMC_WAIT_MMU_BUSY();
392
393 /* clear anything saved */
394 if (lp->pending_tx_skb != NULL) {
395 dev_kfree_skb (lp->pending_tx_skb);
396 lp->pending_tx_skb = NULL;
397 lp->stats.tx_errors++;
398 lp->stats.tx_aborted_errors++;
399 }
400} 402}
401 403
402/* 404/*
@@ -440,6 +442,7 @@ static void smc_shutdown(struct net_device *dev)
440{ 442{
441 struct smc_local *lp = netdev_priv(dev); 443 struct smc_local *lp = netdev_priv(dev);
442 void __iomem *ioaddr = lp->base; 444 void __iomem *ioaddr = lp->base;
445 struct sk_buff *pending_skb;
443 446
444 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__); 447 DBG(2, "%s: %s\n", CARDNAME, __FUNCTION__);
445 448
@@ -447,7 +450,11 @@ static void smc_shutdown(struct net_device *dev)
447 spin_lock(&lp->lock); 450 spin_lock(&lp->lock);
448 SMC_SELECT_BANK(2); 451 SMC_SELECT_BANK(2);
449 SMC_SET_INT_MASK(0); 452 SMC_SET_INT_MASK(0);
453 pending_skb = lp->pending_tx_skb;
454 lp->pending_tx_skb = NULL;
450 spin_unlock(&lp->lock); 455 spin_unlock(&lp->lock);
456 if (pending_skb)
457 dev_kfree_skb(pending_skb);
451 458
452 /* and tell the card to stay away from that nasty outside world */ 459 /* and tell the card to stay away from that nasty outside world */
453 SMC_SELECT_BANK(0); 460 SMC_SELECT_BANK(0);
@@ -627,7 +634,12 @@ static void smc_hardware_send_pkt(unsigned long data)
627 } 634 }
628 635
629 skb = lp->pending_tx_skb; 636 skb = lp->pending_tx_skb;
637 if (unlikely(!skb)) {
638 smc_special_unlock(&lp->lock);
639 return;
640 }
630 lp->pending_tx_skb = NULL; 641 lp->pending_tx_skb = NULL;
642
631 packet_no = SMC_GET_AR(); 643 packet_no = SMC_GET_AR();
632 if (unlikely(packet_no & AR_FAILED)) { 644 if (unlikely(packet_no & AR_FAILED)) {
633 printk("%s: Memory allocation failed.\n", dev->name); 645 printk("%s: Memory allocation failed.\n", dev->name);
@@ -702,7 +714,6 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
702 DBG(3, "%s: %s\n", dev->name, __FUNCTION__); 714 DBG(3, "%s: %s\n", dev->name, __FUNCTION__);
703 715
704 BUG_ON(lp->pending_tx_skb != NULL); 716 BUG_ON(lp->pending_tx_skb != NULL);
705 lp->pending_tx_skb = skb;
706 717
707 /* 718 /*
708 * The MMU wants the number of pages to be the number of 256 bytes 719 * The MMU wants the number of pages to be the number of 256 bytes
@@ -718,7 +729,6 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
718 numPages = ((skb->len & ~1) + (6 - 1)) >> 8; 729 numPages = ((skb->len & ~1) + (6 - 1)) >> 8;
719 if (unlikely(numPages > 7)) { 730 if (unlikely(numPages > 7)) {
720 printk("%s: Far too big packet error.\n", dev->name); 731 printk("%s: Far too big packet error.\n", dev->name);
721 lp->pending_tx_skb = NULL;
722 lp->stats.tx_errors++; 732 lp->stats.tx_errors++;
723 lp->stats.tx_dropped++; 733 lp->stats.tx_dropped++;
724 dev_kfree_skb(skb); 734 dev_kfree_skb(skb);
@@ -745,6 +755,7 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
745 755
746 smc_special_unlock(&lp->lock); 756 smc_special_unlock(&lp->lock);
747 757
758 lp->pending_tx_skb = skb;
748 if (!poll_count) { 759 if (!poll_count) {
749 /* oh well, wait until the chip finds memory later */ 760 /* oh well, wait until the chip finds memory later */
750 netif_stop_queue(dev); 761 netif_stop_queue(dev);
@@ -1062,7 +1073,7 @@ static void smc_phy_powerdown(struct net_device *dev)
1062 above). linkwatch_event() also wants the netlink semaphore. 1073 above). linkwatch_event() also wants the netlink semaphore.
1063 */ 1074 */
1064 while(lp->work_pending) 1075 while(lp->work_pending)
1065 schedule(); 1076 yield();
1066 1077
1067 bmcr = smc_phy_read(dev, phy, MII_BMCR); 1078 bmcr = smc_phy_read(dev, phy, MII_BMCR);
1068 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN); 1079 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN);
@@ -1606,14 +1617,8 @@ static int smc_close(struct net_device *dev)
1606 1617
1607 /* clear everything */ 1618 /* clear everything */
1608 smc_shutdown(dev); 1619 smc_shutdown(dev);
1609 1620 tasklet_kill(&lp->tx_task);
1610 smc_phy_powerdown(dev); 1621 smc_phy_powerdown(dev);
1611
1612 if (lp->pending_tx_skb) {
1613 dev_kfree_skb(lp->pending_tx_skb);
1614 lp->pending_tx_skb = NULL;
1615 }
1616
1617 return 0; 1622 return 0;
1618} 1623}
1619 1624
@@ -1993,7 +1998,7 @@ static int __init smc_probe(struct net_device *dev, void __iomem *ioaddr)
1993 if (retval) 1998 if (retval)
1994 goto err_out; 1999 goto err_out;
1995 2000
1996 set_irq_type(dev->irq, IRQT_RISING); 2001 set_irq_type(dev->irq, SMC_IRQ_TRIGGER_TYPE);
1997 2002
1998#ifdef SMC_USE_PXA_DMA 2003#ifdef SMC_USE_PXA_DMA
1999 { 2004 {
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 946528e6b742..7089d86e857a 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -182,6 +182,16 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
182#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l) 182#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
183#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l) 183#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
184 184
185#include <asm/mach-types.h>
186#include <asm/arch/cpu.h>
187
188#define SMC_IRQ_TRIGGER_TYPE (( \
189 machine_is_omap_h2() \
190 || machine_is_omap_h3() \
191 || (machine_is_omap_innovator() && !cpu_is_omap150()) \
192 ) ? IRQT_FALLING : IRQT_RISING)
193
194
185#elif defined(CONFIG_SH_SH4202_MICRODEV) 195#elif defined(CONFIG_SH_SH4202_MICRODEV)
186 196
187#define SMC_CAN_USE_8BIT 0 197#define SMC_CAN_USE_8BIT 0
@@ -300,6 +310,9 @@ static inline void SMC_outsw (unsigned long a, int r, unsigned char* p, int l)
300 310
301#endif 311#endif
302 312
313#ifndef SMC_IRQ_TRIGGER_TYPE
314#define SMC_IRQ_TRIGGER_TYPE IRQT_RISING
315#endif
303 316
304#ifdef SMC_USE_PXA_DMA 317#ifdef SMC_USE_PXA_DMA
305/* 318/*
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 12e2b6826fa3..88b89dc95c77 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1286,7 +1286,7 @@ static void init_ring(struct net_device *dev)
1286 np->rx_info[i].skb = skb; 1286 np->rx_info[i].skb = skb;
1287 if (skb == NULL) 1287 if (skb == NULL)
1288 break; 1288 break;
1289 np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1289 np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1290 skb->dev = dev; /* Mark as being used by this device. */ 1290 skb->dev = dev; /* Mark as being used by this device. */
1291 /* Grrr, we cannot offset to correctly align the IP header. */ 1291 /* Grrr, we cannot offset to correctly align the IP header. */
1292 np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid); 1292 np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid);
@@ -1572,7 +1572,7 @@ static int __netdev_rx(struct net_device *dev, int *quota)
1572 pci_dma_sync_single_for_cpu(np->pci_dev, 1572 pci_dma_sync_single_for_cpu(np->pci_dev,
1573 np->rx_info[entry].mapping, 1573 np->rx_info[entry].mapping,
1574 pkt_len, PCI_DMA_FROMDEVICE); 1574 pkt_len, PCI_DMA_FROMDEVICE);
1575 eth_copy_and_sum(skb, np->rx_info[entry].skb->tail, pkt_len, 0); 1575 eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0);
1576 pci_dma_sync_single_for_device(np->pci_dev, 1576 pci_dma_sync_single_for_device(np->pci_dev,
1577 np->rx_info[entry].mapping, 1577 np->rx_info[entry].mapping,
1578 pkt_len, PCI_DMA_FROMDEVICE); 1578 pkt_len, PCI_DMA_FROMDEVICE);
@@ -1696,7 +1696,7 @@ static void refill_rx_ring(struct net_device *dev)
1696 if (skb == NULL) 1696 if (skb == NULL)
1697 break; /* Better luck next round. */ 1697 break; /* Better luck next round. */
1698 np->rx_info[entry].mapping = 1698 np->rx_info[entry].mapping =
1699 pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE); 1699 pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1700 skb->dev = dev; /* Mark as being used by this device. */ 1700 skb->dev = dev; /* Mark as being used by this device. */
1701 np->rx_ring[entry].rxaddr = 1701 np->rx_ring[entry].rxaddr =
1702 cpu_to_dma(np->rx_info[entry].mapping | RxDescValid); 1702 cpu_to_dma(np->rx_info[entry].mapping | RxDescValid);
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index 08cb7177a175..d500a5771dbc 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -1028,7 +1028,7 @@ static void init_ring(struct net_device *dev)
1028 skb->dev = dev; /* Mark as being used by this device. */ 1028 skb->dev = dev; /* Mark as being used by this device. */
1029 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 1029 skb_reserve(skb, 2); /* 16 byte align the IP header. */
1030 np->rx_ring[i].frag[0].addr = cpu_to_le32( 1030 np->rx_ring[i].frag[0].addr = cpu_to_le32(
1031 pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, 1031 pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz,
1032 PCI_DMA_FROMDEVICE)); 1032 PCI_DMA_FROMDEVICE));
1033 np->rx_ring[i].frag[0].length = cpu_to_le32(np->rx_buf_sz | LastFrag); 1033 np->rx_ring[i].frag[0].length = cpu_to_le32(np->rx_buf_sz | LastFrag);
1034 } 1034 }
@@ -1341,7 +1341,7 @@ static void rx_poll(unsigned long data)
1341 np->rx_buf_sz, 1341 np->rx_buf_sz,
1342 PCI_DMA_FROMDEVICE); 1342 PCI_DMA_FROMDEVICE);
1343 1343
1344 eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0); 1344 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0);
1345 pci_dma_sync_single_for_device(np->pci_dev, 1345 pci_dma_sync_single_for_device(np->pci_dev,
1346 desc->frag[0].addr, 1346 desc->frag[0].addr,
1347 np->rx_buf_sz, 1347 np->rx_buf_sz,
@@ -1400,7 +1400,7 @@ static void refill_rx (struct net_device *dev)
1400 skb->dev = dev; /* Mark as being used by this device. */ 1400 skb->dev = dev; /* Mark as being used by this device. */
1401 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1401 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1402 np->rx_ring[entry].frag[0].addr = cpu_to_le32( 1402 np->rx_ring[entry].frag[0].addr = cpu_to_le32(
1403 pci_map_single(np->pci_dev, skb->tail, 1403 pci_map_single(np->pci_dev, skb->data,
1404 np->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1404 np->rx_buf_sz, PCI_DMA_FROMDEVICE));
1405 } 1405 }
1406 /* Perhaps we need not reset this field. */ 1406 /* Perhaps we need not reset this field. */
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 5cd50fd53c12..2608e7a3d214 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -44,6 +44,7 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/dma-mapping.h>
47#include <linux/netdevice.h> 48#include <linux/netdevice.h>
48#include <linux/etherdevice.h> 49#include <linux/etherdevice.h>
49#include <linux/skbuff.h> 50#include <linux/skbuff.h>
@@ -2989,10 +2990,10 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
2989 */ 2990 */
2990 if (pdev->vendor == PCI_VENDOR_ID_SUN && 2991 if (pdev->vendor == PCI_VENDOR_ID_SUN &&
2991 pdev->device == PCI_DEVICE_ID_SUN_GEM && 2992 pdev->device == PCI_DEVICE_ID_SUN_GEM &&
2992 !pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL)) { 2993 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
2993 pci_using_dac = 1; 2994 pci_using_dac = 1;
2994 } else { 2995 } else {
2995 err = pci_set_dma_mask(pdev, (u64) 0xffffffff); 2996 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2996 if (err) { 2997 if (err) {
2997 printk(KERN_ERR PFX "No usable DMA configuration, " 2998 printk(KERN_ERR PFX "No usable DMA configuration, "
2998 "aborting.\n"); 2999 "aborting.\n");
@@ -3078,7 +3079,9 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
3078 gp->phy_mii.dev = dev; 3079 gp->phy_mii.dev = dev;
3079 gp->phy_mii.mdio_read = _phy_read; 3080 gp->phy_mii.mdio_read = _phy_read;
3080 gp->phy_mii.mdio_write = _phy_write; 3081 gp->phy_mii.mdio_write = _phy_write;
3081 3082#ifdef CONFIG_PPC_PMAC
3083 gp->phy_mii.platform_data = gp->of_node;
3084#endif
3082 /* By default, we start with autoneg */ 3085 /* By default, we start with autoneg */
3083 gp->want_autoneg = 1; 3086 gp->want_autoneg = 1;
3084 3087
diff --git a/drivers/net/sungem_phy.c b/drivers/net/sungem_phy.c
index 0fca414d3657..d3ddb41d6e5c 100644
--- a/drivers/net/sungem_phy.c
+++ b/drivers/net/sungem_phy.c
@@ -32,6 +32,10 @@
32#include <linux/ethtool.h> 32#include <linux/ethtool.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34 34
35#ifdef CONFIG_PPC_PMAC
36#include <asm/prom.h>
37#endif
38
35#include "sungem_phy.h" 39#include "sungem_phy.h"
36 40
37/* Link modes of the BCM5400 PHY */ 41/* Link modes of the BCM5400 PHY */
@@ -281,10 +285,12 @@ static int bcm5411_suspend(struct mii_phy* phy)
281static int bcm5421_init(struct mii_phy* phy) 285static int bcm5421_init(struct mii_phy* phy)
282{ 286{
283 u16 data; 287 u16 data;
284 int rev; 288 unsigned int id;
285 289
286 rev = phy_read(phy, MII_PHYSID2) & 0x000f; 290 id = (phy_read(phy, MII_PHYSID1) << 16 | phy_read(phy, MII_PHYSID2));
287 if (rev == 0) { 291
292 /* Revision 0 of 5421 needs some fixups */
293 if (id == 0x002060e0) {
288 /* This is borrowed from MacOS 294 /* This is borrowed from MacOS
289 */ 295 */
290 phy_write(phy, 0x18, 0x1007); 296 phy_write(phy, 0x18, 0x1007);
@@ -297,21 +303,28 @@ static int bcm5421_init(struct mii_phy* phy)
297 data = phy_read(phy, 0x15); 303 data = phy_read(phy, 0x15);
298 phy_write(phy, 0x15, data | 0x0200); 304 phy_write(phy, 0x15, data | 0x0200);
299 } 305 }
300#if 0
301 /* This has to be verified before I enable it */
302 /* Enable automatic low-power */
303 phy_write(phy, 0x1c, 0x9002);
304 phy_write(phy, 0x1c, 0xa821);
305 phy_write(phy, 0x1c, 0x941d);
306#endif
307 return 0;
308}
309 306
310static int bcm5421k2_init(struct mii_phy* phy) 307 /* Pick up some init code from OF for K2 version */
311{ 308 if ((id & 0xfffffff0) == 0x002062e0) {
312 /* Init code borrowed from OF */ 309 phy_write(phy, 4, 0x01e1);
313 phy_write(phy, 4, 0x01e1); 310 phy_write(phy, 9, 0x0300);
314 phy_write(phy, 9, 0x0300); 311 }
312
313 /* Check if we can enable automatic low power */
314#ifdef CONFIG_PPC_PMAC
315 if (phy->platform_data) {
316 struct device_node *np = of_get_parent(phy->platform_data);
317 int can_low_power = 1;
318 if (np == NULL || get_property(np, "no-autolowpower", NULL))
319 can_low_power = 0;
320 if (can_low_power) {
321 /* Enable automatic low-power */
322 phy_write(phy, 0x1c, 0x9002);
323 phy_write(phy, 0x1c, 0xa821);
324 phy_write(phy, 0x1c, 0x941d);
325 }
326 }
327#endif /* CONFIG_PPC_PMAC */
315 328
316 return 0; 329 return 0;
317} 330}
@@ -762,7 +775,7 @@ static struct mii_phy_def bcm5421_phy_def = {
762 775
763/* Broadcom BCM 5421 built-in K2 */ 776/* Broadcom BCM 5421 built-in K2 */
764static struct mii_phy_ops bcm5421k2_phy_ops = { 777static struct mii_phy_ops bcm5421k2_phy_ops = {
765 .init = bcm5421k2_init, 778 .init = bcm5421_init,
766 .suspend = bcm5411_suspend, 779 .suspend = bcm5411_suspend,
767 .setup_aneg = bcm54xx_setup_aneg, 780 .setup_aneg = bcm54xx_setup_aneg,
768 .setup_forced = bcm54xx_setup_forced, 781 .setup_forced = bcm54xx_setup_forced,
@@ -779,6 +792,25 @@ static struct mii_phy_def bcm5421k2_phy_def = {
779 .ops = &bcm5421k2_phy_ops 792 .ops = &bcm5421k2_phy_ops
780}; 793};
781 794
795/* Broadcom BCM 5462 built-in Vesta */
796static struct mii_phy_ops bcm5462V_phy_ops = {
797 .init = bcm5421_init,
798 .suspend = bcm5411_suspend,
799 .setup_aneg = bcm54xx_setup_aneg,
800 .setup_forced = bcm54xx_setup_forced,
801 .poll_link = genmii_poll_link,
802 .read_link = bcm54xx_read_link,
803};
804
805static struct mii_phy_def bcm5462V_phy_def = {
806 .phy_id = 0x002060d0,
807 .phy_id_mask = 0xfffffff0,
808 .name = "BCM5462-Vesta",
809 .features = MII_GBIT_FEATURES,
810 .magic_aneg = 1,
811 .ops = &bcm5462V_phy_ops
812};
813
782/* Marvell 88E1101 (Apple seem to deal with 2 different revs, 814/* Marvell 88E1101 (Apple seem to deal with 2 different revs,
783 * I masked out the 8 last bits to get both, but some specs 815 * I masked out the 8 last bits to get both, but some specs
784 * would be useful here) --BenH. 816 * would be useful here) --BenH.
@@ -824,6 +856,7 @@ static struct mii_phy_def* mii_phy_table[] = {
824 &bcm5411_phy_def, 856 &bcm5411_phy_def,
825 &bcm5421_phy_def, 857 &bcm5421_phy_def,
826 &bcm5421k2_phy_def, 858 &bcm5421k2_phy_def,
859 &bcm5462V_phy_def,
827 &marvell_phy_def, 860 &marvell_phy_def,
828 &genmii_phy_def, 861 &genmii_phy_def,
829 NULL 862 NULL
diff --git a/drivers/net/sungem_phy.h b/drivers/net/sungem_phy.h
index 822cb58174ea..430544496c52 100644
--- a/drivers/net/sungem_phy.h
+++ b/drivers/net/sungem_phy.h
@@ -43,9 +43,10 @@ struct mii_phy
43 int pause; 43 int pause;
44 44
45 /* Provided by host chip */ 45 /* Provided by host chip */
46 struct net_device* dev; 46 struct net_device *dev;
47 int (*mdio_read) (struct net_device *dev, int mii_id, int reg); 47 int (*mdio_read) (struct net_device *dev, int mii_id, int reg);
48 void (*mdio_write) (struct net_device *dev, int mii_id, int reg, int val); 48 void (*mdio_write) (struct net_device *dev, int mii_id, int reg, int val);
49 void *platform_data;
49}; 50};
50 51
51/* Pass in a struct mii_phy with dev, mdio_read and mdio_write 52/* Pass in a struct mii_phy with dev, mdio_read and mdio_write
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 7e371b1209a1..54640686e983 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -66,8 +66,8 @@
66 66
67#define DRV_MODULE_NAME "tg3" 67#define DRV_MODULE_NAME "tg3"
68#define PFX DRV_MODULE_NAME ": " 68#define PFX DRV_MODULE_NAME ": "
69#define DRV_MODULE_VERSION "3.32" 69#define DRV_MODULE_VERSION "3.33"
70#define DRV_MODULE_RELDATE "June 24, 2005" 70#define DRV_MODULE_RELDATE "July 5, 2005"
71 71
72#define TG3_DEF_MAC_MODE 0 72#define TG3_DEF_MAC_MODE 0
73#define TG3_DEF_RX_MODE 0 73#define TG3_DEF_RX_MODE 0
@@ -5117,7 +5117,7 @@ static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr,
5117} 5117}
5118 5118
5119static void __tg3_set_rx_mode(struct net_device *); 5119static void __tg3_set_rx_mode(struct net_device *);
5120static void tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) 5120static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec)
5121{ 5121{
5122 tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); 5122 tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs);
5123 tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); 5123 tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs);
@@ -5460,7 +5460,7 @@ static int tg3_reset_hw(struct tg3 *tp)
5460 udelay(10); 5460 udelay(10);
5461 } 5461 }
5462 5462
5463 tg3_set_coalesce(tp, &tp->coal); 5463 __tg3_set_coalesce(tp, &tp->coal);
5464 5464
5465 /* set status block DMA address */ 5465 /* set status block DMA address */
5466 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, 5466 tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH,
@@ -7821,6 +7821,60 @@ static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
7821 return 0; 7821 return 0;
7822} 7822}
7823 7823
7824static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
7825{
7826 struct tg3 *tp = netdev_priv(dev);
7827 u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0;
7828 u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0;
7829
7830 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) {
7831 max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT;
7832 max_txcoal_tick_int = MAX_TXCOAL_TICK_INT;
7833 max_stat_coal_ticks = MAX_STAT_COAL_TICKS;
7834 min_stat_coal_ticks = MIN_STAT_COAL_TICKS;
7835 }
7836
7837 if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) ||
7838 (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) ||
7839 (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) ||
7840 (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) ||
7841 (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) ||
7842 (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) ||
7843 (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) ||
7844 (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) ||
7845 (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) ||
7846 (ec->stats_block_coalesce_usecs < min_stat_coal_ticks))
7847 return -EINVAL;
7848
7849 /* No rx interrupts will be generated if both are zero */
7850 if ((ec->rx_coalesce_usecs == 0) &&
7851 (ec->rx_max_coalesced_frames == 0))
7852 return -EINVAL;
7853
7854 /* No tx interrupts will be generated if both are zero */
7855 if ((ec->tx_coalesce_usecs == 0) &&
7856 (ec->tx_max_coalesced_frames == 0))
7857 return -EINVAL;
7858
7859 /* Only copy relevant parameters, ignore all others. */
7860 tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs;
7861 tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs;
7862 tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames;
7863 tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames;
7864 tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq;
7865 tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq;
7866 tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq;
7867 tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq;
7868 tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs;
7869
7870 if (netif_running(dev)) {
7871 tg3_full_lock(tp, 0);
7872 __tg3_set_coalesce(tp, &tp->coal);
7873 tg3_full_unlock(tp);
7874 }
7875 return 0;
7876}
7877
7824static struct ethtool_ops tg3_ethtool_ops = { 7878static struct ethtool_ops tg3_ethtool_ops = {
7825 .get_settings = tg3_get_settings, 7879 .get_settings = tg3_get_settings,
7826 .set_settings = tg3_set_settings, 7880 .set_settings = tg3_set_settings,
@@ -7856,6 +7910,7 @@ static struct ethtool_ops tg3_ethtool_ops = {
7856 .get_stats_count = tg3_get_stats_count, 7910 .get_stats_count = tg3_get_stats_count,
7857 .get_ethtool_stats = tg3_get_ethtool_stats, 7911 .get_ethtool_stats = tg3_get_ethtool_stats,
7858 .get_coalesce = tg3_get_coalesce, 7912 .get_coalesce = tg3_get_coalesce,
7913 .set_coalesce = tg3_set_coalesce,
7859}; 7914};
7860 7915
7861static void __devinit tg3_get_eeprom_size(struct tg3 *tp) 7916static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
@@ -9800,6 +9855,12 @@ static void __devinit tg3_init_coal(struct tg3 *tp)
9800 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; 9855 ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS;
9801 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; 9856 ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS;
9802 } 9857 }
9858
9859 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
9860 ec->rx_coalesce_usecs_irq = 0;
9861 ec->tx_coalesce_usecs_irq = 0;
9862 ec->stats_block_coalesce_usecs = 0;
9863 }
9803} 9864}
9804 9865
9805static int __devinit tg3_init_one(struct pci_dev *pdev, 9866static int __devinit tg3_init_one(struct pci_dev *pdev,
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 99c5f9675a56..70ad450733e6 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -879,31 +879,41 @@
879#define LOW_RXCOL_TICKS_CLRTCKS 0x00000014 879#define LOW_RXCOL_TICKS_CLRTCKS 0x00000014
880#define DEFAULT_RXCOL_TICKS 0x00000048 880#define DEFAULT_RXCOL_TICKS 0x00000048
881#define HIGH_RXCOL_TICKS 0x00000096 881#define HIGH_RXCOL_TICKS 0x00000096
882#define MAX_RXCOL_TICKS 0x000003ff
882#define HOSTCC_TXCOL_TICKS 0x00003c0c 883#define HOSTCC_TXCOL_TICKS 0x00003c0c
883#define LOW_TXCOL_TICKS 0x00000096 884#define LOW_TXCOL_TICKS 0x00000096
884#define LOW_TXCOL_TICKS_CLRTCKS 0x00000048 885#define LOW_TXCOL_TICKS_CLRTCKS 0x00000048
885#define DEFAULT_TXCOL_TICKS 0x0000012c 886#define DEFAULT_TXCOL_TICKS 0x0000012c
886#define HIGH_TXCOL_TICKS 0x00000145 887#define HIGH_TXCOL_TICKS 0x00000145
888#define MAX_TXCOL_TICKS 0x000003ff
887#define HOSTCC_RXMAX_FRAMES 0x00003c10 889#define HOSTCC_RXMAX_FRAMES 0x00003c10
888#define LOW_RXMAX_FRAMES 0x00000005 890#define LOW_RXMAX_FRAMES 0x00000005
889#define DEFAULT_RXMAX_FRAMES 0x00000008 891#define DEFAULT_RXMAX_FRAMES 0x00000008
890#define HIGH_RXMAX_FRAMES 0x00000012 892#define HIGH_RXMAX_FRAMES 0x00000012
893#define MAX_RXMAX_FRAMES 0x000000ff
891#define HOSTCC_TXMAX_FRAMES 0x00003c14 894#define HOSTCC_TXMAX_FRAMES 0x00003c14
892#define LOW_TXMAX_FRAMES 0x00000035 895#define LOW_TXMAX_FRAMES 0x00000035
893#define DEFAULT_TXMAX_FRAMES 0x0000004b 896#define DEFAULT_TXMAX_FRAMES 0x0000004b
894#define HIGH_TXMAX_FRAMES 0x00000052 897#define HIGH_TXMAX_FRAMES 0x00000052
898#define MAX_TXMAX_FRAMES 0x000000ff
895#define HOSTCC_RXCOAL_TICK_INT 0x00003c18 899#define HOSTCC_RXCOAL_TICK_INT 0x00003c18
896#define DEFAULT_RXCOAL_TICK_INT 0x00000019 900#define DEFAULT_RXCOAL_TICK_INT 0x00000019
897#define DEFAULT_RXCOAL_TICK_INT_CLRTCKS 0x00000014 901#define DEFAULT_RXCOAL_TICK_INT_CLRTCKS 0x00000014
902#define MAX_RXCOAL_TICK_INT 0x000003ff
898#define HOSTCC_TXCOAL_TICK_INT 0x00003c1c 903#define HOSTCC_TXCOAL_TICK_INT 0x00003c1c
899#define DEFAULT_TXCOAL_TICK_INT 0x00000019 904#define DEFAULT_TXCOAL_TICK_INT 0x00000019
900#define DEFAULT_TXCOAL_TICK_INT_CLRTCKS 0x00000014 905#define DEFAULT_TXCOAL_TICK_INT_CLRTCKS 0x00000014
906#define MAX_TXCOAL_TICK_INT 0x000003ff
901#define HOSTCC_RXCOAL_MAXF_INT 0x00003c20 907#define HOSTCC_RXCOAL_MAXF_INT 0x00003c20
902#define DEFAULT_RXCOAL_MAXF_INT 0x00000005 908#define DEFAULT_RXCOAL_MAXF_INT 0x00000005
909#define MAX_RXCOAL_MAXF_INT 0x000000ff
903#define HOSTCC_TXCOAL_MAXF_INT 0x00003c24 910#define HOSTCC_TXCOAL_MAXF_INT 0x00003c24
904#define DEFAULT_TXCOAL_MAXF_INT 0x00000005 911#define DEFAULT_TXCOAL_MAXF_INT 0x00000005
912#define MAX_TXCOAL_MAXF_INT 0x000000ff
905#define HOSTCC_STAT_COAL_TICKS 0x00003c28 913#define HOSTCC_STAT_COAL_TICKS 0x00003c28
906#define DEFAULT_STAT_COAL_TICKS 0x000f4240 914#define DEFAULT_STAT_COAL_TICKS 0x000f4240
915#define MAX_STAT_COAL_TICKS 0xd693d400
916#define MIN_STAT_COAL_TICKS 0x00000064
907/* 0x3c2c --> 0x3c30 unused */ 917/* 0x3c2c --> 0x3c30 unused */
908#define HOSTCC_STATS_BLK_HOST_ADDR 0x00003c30 /* 64-bit */ 918#define HOSTCC_STATS_BLK_HOST_ADDR 0x00003c30 /* 64-bit */
909#define HOSTCC_STATUS_BLK_HOST_ADDR 0x00003c38 /* 64-bit */ 919#define HOSTCC_STATUS_BLK_HOST_ADDR 0x00003c38 /* 64-bit */
diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c
index cf31c0629852..942fae0f2130 100644
--- a/drivers/net/tlan.c
+++ b/drivers/net/tlan.c
@@ -171,6 +171,7 @@
171#include <linux/ioport.h> 171#include <linux/ioport.h>
172#include <linux/eisa.h> 172#include <linux/eisa.h>
173#include <linux/pci.h> 173#include <linux/pci.h>
174#include <linux/dma-mapping.h>
174#include <linux/netdevice.h> 175#include <linux/netdevice.h>
175#include <linux/etherdevice.h> 176#include <linux/etherdevice.h>
176#include <linux/delay.h> 177#include <linux/delay.h>
@@ -566,7 +567,7 @@ static int __devinit TLan_probe1(struct pci_dev *pdev,
566 567
567 priv->adapter = &board_info[ent->driver_data]; 568 priv->adapter = &board_info[ent->driver_data];
568 569
569 rc = pci_set_dma_mask(pdev, 0xFFFFFFFF); 570 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
570 if (rc) { 571 if (rc) {
571 printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n"); 572 printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n");
572 goto err_out_free_dev; 573 goto err_out_free_dev;
diff --git a/drivers/net/tokenring/3c359.c b/drivers/net/tokenring/3c359.c
index 0d1dcf421771..41e0cd8f4786 100644
--- a/drivers/net/tokenring/3c359.c
+++ b/drivers/net/tokenring/3c359.c
@@ -276,7 +276,8 @@ static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value)
276 return ; 276 return ;
277} 277}
278 278
279int __devinit xl_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 279static int __devinit xl_probe(struct pci_dev *pdev,
280 const struct pci_device_id *ent)
280{ 281{
281 struct net_device *dev ; 282 struct net_device *dev ;
282 struct xl_private *xl_priv ; 283 struct xl_private *xl_priv ;
diff --git a/drivers/net/tokenring/3c359_microcode.h b/drivers/net/tokenring/3c359_microcode.h
index 81354afa3d34..0400c029c077 100644
--- a/drivers/net/tokenring/3c359_microcode.h
+++ b/drivers/net/tokenring/3c359_microcode.h
@@ -22,7 +22,7 @@
22 22
23static int mc_size = 24880 ; 23static int mc_size = 24880 ;
24 24
25u8 microcode[] = { 25static const u8 microcode[] = {
26 0xfe,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 26 0xfe,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
index bd4a2bccf867..87103c400999 100644
--- a/drivers/net/tokenring/abyss.c
+++ b/drivers/net/tokenring/abyss.c
@@ -468,14 +468,3 @@ static void __exit abyss_rmmod (void)
468module_init(abyss_init); 468module_init(abyss_init);
469module_exit(abyss_rmmod); 469module_exit(abyss_rmmod);
470 470
471
472/*
473 * Local variables:
474 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c abyss.c"
475 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c abyss.c"
476 * c-set-style "K&R"
477 * c-indent-level: 8
478 * c-basic-offset: 8
479 * tab-width: 8
480 * End:
481 */
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 3873917a9c22..e7b001017b9a 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -151,7 +151,7 @@ static char version[] __initdata =
151 151
152/* this allows displaying full adapter information */ 152/* this allows displaying full adapter information */
153 153
154char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" }; 154static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
155 155
156static char pcchannelid[] __devinitdata = { 156static char pcchannelid[] __devinitdata = {
157 0x05, 0x00, 0x04, 0x09, 157 0x05, 0x00, 0x04, 0x09,
@@ -171,7 +171,7 @@ static char mcchannelid[] __devinitdata = {
171 0x03, 0x08, 0x02, 0x00 171 0x03, 0x08, 0x02, 0x00
172}; 172};
173 173
174char __devinit *adapter_def(char type) 174static char __devinit *adapter_def(char type)
175{ 175{
176 switch (type) { 176 switch (type) {
177 case 0xF: return "PC Adapter | PC Adapter II | Adapter/A"; 177 case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
@@ -184,7 +184,7 @@ char __devinit *adapter_def(char type)
184 184
185#define TRC_INIT 0x01 /* Trace initialization & PROBEs */ 185#define TRC_INIT 0x01 /* Trace initialization & PROBEs */
186#define TRC_INITV 0x02 /* verbose init trace points */ 186#define TRC_INITV 0x02 /* verbose init trace points */
187unsigned char ibmtr_debug_trace = 0; 187static unsigned char ibmtr_debug_trace = 0;
188 188
189static int ibmtr_probe(struct net_device *dev); 189static int ibmtr_probe(struct net_device *dev);
190static int ibmtr_probe1(struct net_device *dev, int ioaddr); 190static int ibmtr_probe1(struct net_device *dev, int ioaddr);
@@ -192,20 +192,20 @@ static unsigned char get_sram_size(struct tok_info *adapt_info);
192static int trdev_init(struct net_device *dev); 192static int trdev_init(struct net_device *dev);
193static int tok_open(struct net_device *dev); 193static int tok_open(struct net_device *dev);
194static int tok_init_card(struct net_device *dev); 194static int tok_init_card(struct net_device *dev);
195void tok_open_adapter(unsigned long dev_addr); 195static void tok_open_adapter(unsigned long dev_addr);
196static void open_sap(unsigned char type, struct net_device *dev); 196static void open_sap(unsigned char type, struct net_device *dev);
197static void tok_set_multicast_list(struct net_device *dev); 197static void tok_set_multicast_list(struct net_device *dev);
198static int tok_send_packet(struct sk_buff *skb, struct net_device *dev); 198static int tok_send_packet(struct sk_buff *skb, struct net_device *dev);
199static int tok_close(struct net_device *dev); 199static int tok_close(struct net_device *dev);
200irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs); 200static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs);
201static void initial_tok_int(struct net_device *dev); 201static void initial_tok_int(struct net_device *dev);
202static void tr_tx(struct net_device *dev); 202static void tr_tx(struct net_device *dev);
203static void tr_rx(struct net_device *dev); 203static void tr_rx(struct net_device *dev);
204void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev); 204static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
205static void tok_rerun(unsigned long dev_addr); 205static void tok_rerun(unsigned long dev_addr);
206void ibmtr_readlog(struct net_device *dev); 206static void ibmtr_readlog(struct net_device *dev);
207static struct net_device_stats *tok_get_stats(struct net_device *dev); 207static struct net_device_stats *tok_get_stats(struct net_device *dev);
208int ibmtr_change_mtu(struct net_device *dev, int mtu); 208static int ibmtr_change_mtu(struct net_device *dev, int mtu);
209static void find_turbo_adapters(int *iolist); 209static void find_turbo_adapters(int *iolist);
210 210
211static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = { 211static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
@@ -928,7 +928,7 @@ static int tok_open(struct net_device *dev)
928#define DLC_MAX_SAP_OFST 32 928#define DLC_MAX_SAP_OFST 32
929#define DLC_MAX_STA_OFST 33 929#define DLC_MAX_STA_OFST 33
930 930
931void tok_open_adapter(unsigned long dev_addr) 931static void tok_open_adapter(unsigned long dev_addr)
932{ 932{
933 struct net_device *dev = (struct net_device *) dev_addr; 933 struct net_device *dev = (struct net_device *) dev_addr;
934 struct tok_info *ti; 934 struct tok_info *ti;
@@ -1099,7 +1099,7 @@ static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page
1099 return ti->sram_virt + index; 1099 return ti->sram_virt + index;
1100} 1100}
1101 1101
1102void dir_open_adapter (struct net_device *dev) 1102static void dir_open_adapter (struct net_device *dev)
1103{ 1103{
1104 struct tok_info *ti = (struct tok_info *) dev->priv; 1104 struct tok_info *ti = (struct tok_info *) dev->priv;
1105 unsigned char ret_code; 1105 unsigned char ret_code;
@@ -1172,7 +1172,7 @@ void dir_open_adapter (struct net_device *dev)
1172 1172
1173/******************************************************************************/ 1173/******************************************************************************/
1174 1174
1175irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1175static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1176{ 1176{
1177 unsigned char status; 1177 unsigned char status;
1178 /* unsigned char status_even ; */ 1178 /* unsigned char status_even ; */
@@ -1840,7 +1840,7 @@ static void tr_rx(struct net_device *dev)
1840 1840
1841/*****************************************************************************/ 1841/*****************************************************************************/
1842 1842
1843void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev) 1843static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
1844{ 1844{
1845 tmr->expires = jiffies + TR_RETRY_INTERVAL; 1845 tmr->expires = jiffies + TR_RETRY_INTERVAL;
1846 tmr->data = (unsigned long) dev; 1846 tmr->data = (unsigned long) dev;
@@ -1872,7 +1872,7 @@ void tok_rerun(unsigned long dev_addr){
1872 1872
1873/*****************************************************************************/ 1873/*****************************************************************************/
1874 1874
1875void ibmtr_readlog(struct net_device *dev) 1875static void ibmtr_readlog(struct net_device *dev)
1876{ 1876{
1877 struct tok_info *ti; 1877 struct tok_info *ti;
1878 1878
@@ -1905,7 +1905,7 @@ static struct net_device_stats *tok_get_stats(struct net_device *dev)
1905 1905
1906/*****************************************************************************/ 1906/*****************************************************************************/
1907 1907
1908int ibmtr_change_mtu(struct net_device *dev, int mtu) 1908static int ibmtr_change_mtu(struct net_device *dev, int mtu)
1909{ 1909{
1910 struct tok_info *ti = (struct tok_info *) dev->priv; 1910 struct tok_info *ti = (struct tok_info *) dev->priv;
1911 1911
diff --git a/drivers/net/tokenring/lanstreamer.c b/drivers/net/tokenring/lanstreamer.c
index 99e0b03b69a8..97712c3c4e07 100644
--- a/drivers/net/tokenring/lanstreamer.c
+++ b/drivers/net/tokenring/lanstreamer.c
@@ -118,6 +118,7 @@
118#include <linux/stddef.h> 118#include <linux/stddef.h>
119#include <linux/init.h> 119#include <linux/init.h>
120#include <linux/pci.h> 120#include <linux/pci.h>
121#include <linux/dma-mapping.h>
121#include <linux/spinlock.h> 122#include <linux/spinlock.h>
122#include <linux/version.h> 123#include <linux/version.h>
123#include <linux/bitops.h> 124#include <linux/bitops.h>
@@ -257,7 +258,7 @@ static int __devinit streamer_init_one(struct pci_dev *pdev,
257#endif 258#endif
258#endif 259#endif
259 260
260 rc = pci_set_dma_mask(pdev, 0xFFFFFFFFULL); 261 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
261 if (rc) { 262 if (rc) {
262 printk(KERN_ERR "%s: No suitable PCI mapping available.\n", 263 printk(KERN_ERR "%s: No suitable PCI mapping available.\n",
263 dev->name); 264 dev->name);
@@ -454,8 +455,7 @@ static int streamer_reset(struct net_device *dev)
454 writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL); 455 writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL);
455 t = jiffies; 456 t = jiffies;
456 /* Hold soft reset bit for a while */ 457 /* Hold soft reset bit for a while */
457 current->state = TASK_UNINTERRUPTIBLE; 458 ssleep(1);
458 schedule_timeout(HZ);
459 459
460 writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET, 460 writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET,
461 streamer_mmio + BCTL); 461 streamer_mmio + BCTL);
@@ -511,8 +511,7 @@ static int streamer_reset(struct net_device *dev)
511 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM); 511 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM);
512 512
513 while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) { 513 while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) {
514 current->state = TASK_INTERRUPTIBLE; 514 msleep_interruptible(100);
515 schedule_timeout(HZ/10);
516 if (jiffies - t > 40 * HZ) { 515 if (jiffies - t > 40 * HZ) {
517 printk(KERN_ERR 516 printk(KERN_ERR
518 "IBM PCI tokenring card not responding\n"); 517 "IBM PCI tokenring card not responding\n");
diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
index cfae2bbf2167..659cbdbef7f3 100644
--- a/drivers/net/tokenring/madgemc.c
+++ b/drivers/net/tokenring/madgemc.c
@@ -625,7 +625,7 @@ static int madgemc_chipset_init(struct net_device *dev)
625/* 625/*
626 * Disable the board, and put back into power-up state. 626 * Disable the board, and put back into power-up state.
627 */ 627 */
628void madgemc_chipset_close(struct net_device *dev) 628static void madgemc_chipset_close(struct net_device *dev)
629{ 629{
630 /* disable interrupts */ 630 /* disable interrupts */
631 madgemc_setint(dev, 0); 631 madgemc_setint(dev, 0);
@@ -786,15 +786,3 @@ module_exit(madgemc_exit);
786 786
787MODULE_LICENSE("GPL"); 787MODULE_LICENSE("GPL");
788 788
789
790/*
791 * Local variables:
792 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c madgemc.c"
793 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c madgemc.c"
794 * c-set-style "K&R"
795 * c-indent-level: 8
796 * c-basic-offset: 8
797 * tab-width: 8
798 * End:
799 */
800
diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
index 675b063508e3..40ad0fde28af 100644
--- a/drivers/net/tokenring/proteon.c
+++ b/drivers/net/tokenring/proteon.c
@@ -419,14 +419,3 @@ void cleanup_module(void)
419} 419}
420#endif /* MODULE */ 420#endif /* MODULE */
421 421
422
423/*
424 * Local variables:
425 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
426 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
427 * c-set-style "K&R"
428 * c-indent-level: 8
429 * c-basic-offset: 8
430 * tab-width: 8
431 * End:
432 */
diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
index 3fab54a26466..f26796e2d0e5 100644
--- a/drivers/net/tokenring/skisa.c
+++ b/drivers/net/tokenring/skisa.c
@@ -429,14 +429,3 @@ void cleanup_module(void)
429} 429}
430#endif /* MODULE */ 430#endif /* MODULE */
431 431
432
433/*
434 * Local variables:
435 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c skisa.c"
436 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c skisa.c"
437 * c-set-style "K&R"
438 * c-indent-level: 8
439 * c-basic-offset: 8
440 * tab-width: 8
441 * End:
442 */
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c
index 5c8aeacb8318..67d2b596ce22 100644
--- a/drivers/net/tokenring/smctr.c
+++ b/drivers/net/tokenring/smctr.c
@@ -77,7 +77,7 @@ static int ringspeed;
77 77
78/* SMC Name of the Adapter. */ 78/* SMC Name of the Adapter. */
79static char smctr_name[] = "SMC TokenCard"; 79static char smctr_name[] = "SMC TokenCard";
80char *smctr_model = "Unknown"; 80static char *smctr_model = "Unknown";
81 81
82/* Use 0 for production, 1 for verification, 2 for debug, and 82/* Use 0 for production, 1 for verification, 2 for debug, and
83 * 3 for very verbose debug. 83 * 3 for very verbose debug.
diff --git a/drivers/net/tokenring/smctr_firmware.h b/drivers/net/tokenring/smctr_firmware.h
index 53f2cbc817c9..48994b043b7c 100644
--- a/drivers/net/tokenring/smctr_firmware.h
+++ b/drivers/net/tokenring/smctr_firmware.h
@@ -21,7 +21,7 @@
21 21
22#if defined(CONFIG_SMCTR) || defined(CONFIG_SMCTR_MODULE) 22#if defined(CONFIG_SMCTR) || defined(CONFIG_SMCTR_MODULE)
23 23
24unsigned char smctr_code[] = { 24static const unsigned char smctr_code[] = {
25 0x0BC, 0x01D, 0x012, 0x03B, 0x063, 0x0B4, 0x0E9, 0x000, 25 0x0BC, 0x01D, 0x012, 0x03B, 0x063, 0x0B4, 0x0E9, 0x000,
26 0x000, 0x01F, 0x000, 0x001, 0x001, 0x000, 0x002, 0x005, 26 0x000, 0x01F, 0x000, 0x001, 0x001, 0x000, 0x002, 0x005,
27 0x001, 0x000, 0x006, 0x003, 0x001, 0x000, 0x004, 0x009, 27 0x001, 0x000, 0x006, 0x003, 0x001, 0x000, 0x004, 0x009,
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c
index df43b449e429..5e0b0ce98ed7 100644
--- a/drivers/net/tokenring/tms380tr.c
+++ b/drivers/net/tokenring/tms380tr.c
@@ -2379,7 +2379,7 @@ EXPORT_SYMBOL(tmsdev_init);
2379EXPORT_SYMBOL(tmsdev_term); 2379EXPORT_SYMBOL(tmsdev_term);
2380EXPORT_SYMBOL(tms380tr_wait); 2380EXPORT_SYMBOL(tms380tr_wait);
2381 2381
2382struct module *TMS380_module = NULL; 2382static struct module *TMS380_module = NULL;
2383 2383
2384int init_module(void) 2384int init_module(void)
2385{ 2385{
@@ -2397,14 +2397,3 @@ void cleanup_module(void)
2397 2397
2398MODULE_LICENSE("GPL"); 2398MODULE_LICENSE("GPL");
2399 2399
2400
2401/*
2402 * Local variables:
2403 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tms380tr.c"
2404 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tms380tr.c"
2405 * c-set-style "K&R"
2406 * c-indent-level: 8
2407 * c-basic-offset: 8
2408 * tab-width: 8
2409 * End:
2410 */
diff --git a/drivers/net/tokenring/tmspci.c b/drivers/net/tokenring/tmspci.c
index 37ddb5c2bec3..2e18c0a46482 100644
--- a/drivers/net/tokenring/tmspci.c
+++ b/drivers/net/tokenring/tmspci.c
@@ -254,14 +254,3 @@ static void __exit tms_pci_rmmod (void)
254module_init(tms_pci_init); 254module_init(tms_pci_init);
255module_exit(tms_pci_rmmod); 255module_exit(tms_pci_rmmod);
256 256
257
258/*
259 * Local variables:
260 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tmspci.c"
261 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c tmspci.c"
262 * c-set-style "K&R"
263 * c-indent-level: 8
264 * c-basic-offset: 8
265 * tab-width: 8
266 * End:
267 */
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index dd357dd8c370..fc353e348f9a 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -446,13 +446,13 @@ static void de_rx (struct de_private *de)
446 446
447 mapping = 447 mapping =
448 de->rx_skb[rx_tail].mapping = 448 de->rx_skb[rx_tail].mapping =
449 pci_map_single(de->pdev, copy_skb->tail, 449 pci_map_single(de->pdev, copy_skb->data,
450 buflen, PCI_DMA_FROMDEVICE); 450 buflen, PCI_DMA_FROMDEVICE);
451 de->rx_skb[rx_tail].skb = copy_skb; 451 de->rx_skb[rx_tail].skb = copy_skb;
452 } else { 452 } else {
453 pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); 453 pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
454 skb_reserve(copy_skb, RX_OFFSET); 454 skb_reserve(copy_skb, RX_OFFSET);
455 memcpy(skb_put(copy_skb, len), skb->tail, len); 455 memcpy(skb_put(copy_skb, len), skb->data, len);
456 456
457 pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); 457 pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
458 458
@@ -1269,7 +1269,7 @@ static int de_refill_rx (struct de_private *de)
1269 skb->dev = de->dev; 1269 skb->dev = de->dev;
1270 1270
1271 de->rx_skb[i].mapping = pci_map_single(de->pdev, 1271 de->rx_skb[i].mapping = pci_map_single(de->pdev,
1272 skb->tail, de->rx_buf_sz, PCI_DMA_FROMDEVICE); 1272 skb->data, de->rx_buf_sz, PCI_DMA_FROMDEVICE);
1273 de->rx_skb[i].skb = skb; 1273 de->rx_skb[i].skb = skb;
1274 1274
1275 de->rx_ring[i].opts1 = cpu_to_le32(DescOwn); 1275 de->rx_ring[i].opts1 = cpu_to_le32(DescOwn);
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index e25f33df223e..74e9075d9c48 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -78,6 +78,7 @@
78#include <linux/slab.h> 78#include <linux/slab.h>
79#include <linux/interrupt.h> 79#include <linux/interrupt.h>
80#include <linux/pci.h> 80#include <linux/pci.h>
81#include <linux/dma-mapping.h>
81#include <linux/init.h> 82#include <linux/init.h>
82#include <linux/netdevice.h> 83#include <linux/netdevice.h>
83#include <linux/etherdevice.h> 84#include <linux/etherdevice.h>
@@ -354,7 +355,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
354 SET_MODULE_OWNER(dev); 355 SET_MODULE_OWNER(dev);
355 SET_NETDEV_DEV(dev, &pdev->dev); 356 SET_NETDEV_DEV(dev, &pdev->dev);
356 357
357 if (pci_set_dma_mask(pdev, 0xffffffff)) { 358 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
358 printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n"); 359 printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n");
359 err = -ENODEV; 360 err = -ENODEV;
360 goto err_out_free; 361 goto err_out_free;
@@ -743,11 +744,6 @@ static irqreturn_t dmfe_interrupt(int irq, void *dev_id, struct pt_regs *regs)
743 744
744 DMFE_DBUG(0, "dmfe_interrupt()", 0); 745 DMFE_DBUG(0, "dmfe_interrupt()", 0);
745 746
746 if (!dev) {
747 DMFE_DBUG(1, "dmfe_interrupt() without DEVICE arg", 0);
748 return IRQ_NONE;
749 }
750
751 spin_lock_irqsave(&db->lock, flags); 747 spin_lock_irqsave(&db->lock, flags);
752 748
753 /* Got DM910X status */ 749 /* Got DM910X status */
@@ -949,8 +945,8 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
949 945
950 /* Received Packet CRC check need or not */ 946 /* Received Packet CRC check need or not */
951 if ( (db->dm910x_chk_mode & 1) && 947 if ( (db->dm910x_chk_mode & 1) &&
952 (cal_CRC(skb->tail, rxlen, 1) != 948 (cal_CRC(skb->data, rxlen, 1) !=
953 (*(u32 *) (skb->tail+rxlen) ))) { /* FIXME (?) */ 949 (*(u32 *) (skb->data+rxlen) ))) { /* FIXME (?) */
954 /* Found a error received packet */ 950 /* Found a error received packet */
955 dmfe_reuse_skb(db, rxptr->rx_skb_ptr); 951 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
956 db->dm910x_chk_mode = 3; 952 db->dm910x_chk_mode = 3;
@@ -963,7 +959,7 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
963 /* size less than COPY_SIZE, allocate a rxlen SKB */ 959 /* size less than COPY_SIZE, allocate a rxlen SKB */
964 skb->dev = dev; 960 skb->dev = dev;
965 skb_reserve(skb, 2); /* 16byte align */ 961 skb_reserve(skb, 2); /* 16byte align */
966 memcpy(skb_put(skb, rxlen), rxptr->rx_skb_ptr->tail, rxlen); 962 memcpy(skb_put(skb, rxlen), rxptr->rx_skb_ptr->data, rxlen);
967 dmfe_reuse_skb(db, rxptr->rx_skb_ptr); 963 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
968 } else { 964 } else {
969 skb->dev = dev; 965 skb->dev = dev;
@@ -1256,7 +1252,7 @@ static void dmfe_reuse_skb(struct dmfe_board_info *db, struct sk_buff * skb)
1256 1252
1257 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) { 1253 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
1258 rxptr->rx_skb_ptr = skb; 1254 rxptr->rx_skb_ptr = skb;
1259 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->tail, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1255 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1260 wmb(); 1256 wmb();
1261 rxptr->rdes0 = cpu_to_le32(0x80000000); 1257 rxptr->rdes0 = cpu_to_le32(0x80000000);
1262 db->rx_avail_cnt++; 1258 db->rx_avail_cnt++;
@@ -1467,7 +1463,7 @@ static void allocate_rx_buffer(struct dmfe_board_info *db)
1467 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL ) 1463 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL )
1468 break; 1464 break;
1469 rxptr->rx_skb_ptr = skb; /* FIXME (?) */ 1465 rxptr->rx_skb_ptr = skb; /* FIXME (?) */
1470 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->tail, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); 1466 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1471 wmb(); 1467 wmb();
1472 rxptr->rdes0 = cpu_to_le32(0x80000000); 1468 rxptr->rdes0 = cpu_to_le32(0x80000000);
1473 rxptr = rxptr->next_rx_desc; 1469 rxptr = rxptr->next_rx_desc;
@@ -1806,7 +1802,7 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
1806 if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) { 1802 if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) {
1807 /* SROM V4.01 */ 1803 /* SROM V4.01 */
1808 /* Get NIC support media mode */ 1804 /* Get NIC support media mode */
1809 db->NIC_capability = le16_to_cpup(srom + 34); 1805 db->NIC_capability = le16_to_cpup((__le16 *)srom + 34/2);
1810 db->PHY_reg4 = 0; 1806 db->PHY_reg4 = 0;
1811 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) { 1807 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
1812 switch( db->NIC_capability & tmp_reg ) { 1808 switch( db->NIC_capability & tmp_reg ) {
@@ -1818,7 +1814,8 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
1818 } 1814 }
1819 1815
1820 /* Media Mode Force or not check */ 1816 /* Media Mode Force or not check */
1821 dmfe_mode = le32_to_cpup(srom + 34) & le32_to_cpup(srom + 36); 1817 dmfe_mode = le32_to_cpup((__le32 *)srom + 34/4) &
1818 le32_to_cpup((__le32 *)srom + 36/4);
1822 switch(dmfe_mode) { 1819 switch(dmfe_mode) {
1823 case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */ 1820 case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */
1824 case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */ 1821 case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */
diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
index ac5bf49ff60f..fbd9ab60b052 100644
--- a/drivers/net/tulip/eeprom.c
+++ b/drivers/net/tulip/eeprom.c
@@ -63,6 +63,22 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
63 */ 63 */
64 { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 } 64 { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 }
65 }, 65 },
66 {"Cobalt Microserver", 0, 0x10, 0xE0, {0x1e00, /* 0 == controller #, 1e == offset */
67 0x0000, /* 0 == high offset, 0 == gap */
68 0x0800, /* Default Autoselect */
69 0x8001, /* 1 leaf, extended type, bogus len */
70 0x0003, /* Type 3 (MII), PHY #0 */
71 0x0400, /* 0 init instr, 4 reset instr */
72 0x0801, /* Set control mode, GP0 output */
73 0x0000, /* Drive GP0 Low (RST is active low) */
74 0x0800, /* control mode, GP0 input (undriven) */
75 0x0000, /* clear control mode */
76 0x7800, /* 100TX FDX + HDX, 10bT FDX + HDX */
77 0x01e0, /* Advertise all above */
78 0x5000, /* FDX all above */
79 0x1800, /* Set fast TTM in 100bt modes */
80 0x0000, /* PHY cannot be unplugged */
81 }},
66 {NULL}}; 82 {NULL}};
67 83
68 84
diff --git a/drivers/net/tulip/interrupt.c b/drivers/net/tulip/interrupt.c
index afb5cda9d8e1..bb3558164a5b 100644
--- a/drivers/net/tulip/interrupt.c
+++ b/drivers/net/tulip/interrupt.c
@@ -78,7 +78,7 @@ int tulip_refill_rx(struct net_device *dev)
78 if (skb == NULL) 78 if (skb == NULL)
79 break; 79 break;
80 80
81 mapping = pci_map_single(tp->pdev, skb->tail, PKT_BUF_SZ, 81 mapping = pci_map_single(tp->pdev, skb->data, PKT_BUF_SZ,
82 PCI_DMA_FROMDEVICE); 82 PCI_DMA_FROMDEVICE);
83 tp->rx_buffers[entry].mapping = mapping; 83 tp->rx_buffers[entry].mapping = mapping;
84 84
@@ -199,12 +199,12 @@ int tulip_poll(struct net_device *dev, int *budget)
199 tp->rx_buffers[entry].mapping, 199 tp->rx_buffers[entry].mapping,
200 pkt_len, PCI_DMA_FROMDEVICE); 200 pkt_len, PCI_DMA_FROMDEVICE);
201#if ! defined(__alpha__) 201#if ! defined(__alpha__)
202 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->tail, 202 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data,
203 pkt_len, 0); 203 pkt_len, 0);
204 skb_put(skb, pkt_len); 204 skb_put(skb, pkt_len);
205#else 205#else
206 memcpy(skb_put(skb, pkt_len), 206 memcpy(skb_put(skb, pkt_len),
207 tp->rx_buffers[entry].skb->tail, 207 tp->rx_buffers[entry].skb->data,
208 pkt_len); 208 pkt_len);
209#endif 209#endif
210 pci_dma_sync_single_for_device(tp->pdev, 210 pci_dma_sync_single_for_device(tp->pdev,
@@ -423,12 +423,12 @@ static int tulip_rx(struct net_device *dev)
423 tp->rx_buffers[entry].mapping, 423 tp->rx_buffers[entry].mapping,
424 pkt_len, PCI_DMA_FROMDEVICE); 424 pkt_len, PCI_DMA_FROMDEVICE);
425#if ! defined(__alpha__) 425#if ! defined(__alpha__)
426 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->tail, 426 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data,
427 pkt_len, 0); 427 pkt_len, 0);
428 skb_put(skb, pkt_len); 428 skb_put(skb, pkt_len);
429#else 429#else
430 memcpy(skb_put(skb, pkt_len), 430 memcpy(skb_put(skb, pkt_len),
431 tp->rx_buffers[entry].skb->tail, 431 tp->rx_buffers[entry].skb->data,
432 pkt_len); 432 pkt_len);
433#endif 433#endif
434 pci_dma_sync_single_for_device(tp->pdev, 434 pci_dma_sync_single_for_device(tp->pdev,
diff --git a/drivers/net/tulip/media.c b/drivers/net/tulip/media.c
index 919c40cd635c..e26c31f944bf 100644
--- a/drivers/net/tulip/media.c
+++ b/drivers/net/tulip/media.c
@@ -400,6 +400,9 @@ void tulip_select_media(struct net_device *dev, int startup)
400 } 400 }
401 401
402 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0); 402 tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);
403
404 mdelay(1);
405
403 return; 406 return;
404} 407}
405 408
diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c
index e0ae3ed6e578..d45d8f56e5b4 100644
--- a/drivers/net/tulip/tulip_core.c
+++ b/drivers/net/tulip/tulip_core.c
@@ -242,6 +242,7 @@ static struct pci_device_id tulip_pci_tbl[] = {
242 { 0x10b9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */ 242 { 0x10b9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */
243 { 0x10b9, 0x5263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */ 243 { 0x10b9, 0x5263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ULI526X }, /* ALi 1563 integrated ethernet */
244 { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */ 244 { 0x10b7, 0x9300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* 3Com 3CSOHO100B-TX */
245 { 0x14ea, 0xab08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET }, /* Planex FNW-3602-TX */
245 { } /* terminate list */ 246 { } /* terminate list */
246}; 247};
247MODULE_DEVICE_TABLE(pci, tulip_pci_tbl); 248MODULE_DEVICE_TABLE(pci, tulip_pci_tbl);
@@ -624,7 +625,7 @@ static void tulip_init_ring(struct net_device *dev)
624 tp->rx_buffers[i].skb = skb; 625 tp->rx_buffers[i].skb = skb;
625 if (skb == NULL) 626 if (skb == NULL)
626 break; 627 break;
627 mapping = pci_map_single(tp->pdev, skb->tail, 628 mapping = pci_map_single(tp->pdev, skb->data,
628 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 629 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
629 tp->rx_buffers[i].mapping = mapping; 630 tp->rx_buffers[i].mapping = mapping;
630 skb->dev = dev; /* Mark as being used by this device. */ 631 skb->dev = dev; /* Mark as being used by this device. */
@@ -1514,8 +1515,8 @@ static int __devinit tulip_init_one (struct pci_dev *pdev,
1514 (PCI_SLOT(pdev->devfn) == 12))) { 1515 (PCI_SLOT(pdev->devfn) == 12))) {
1515 /* Cobalt MAC address in first EEPROM locations. */ 1516 /* Cobalt MAC address in first EEPROM locations. */
1516 sa_offset = 0; 1517 sa_offset = 0;
1517 /* No media table either */ 1518 /* Ensure our media table fixup get's applied */
1518 tp->flags &= ~HAS_MEDIA_TABLE; 1519 memcpy(ee_data + 16, ee_data, 8);
1519 } 1520 }
1520#endif 1521#endif
1521#ifdef CONFIG_GSC 1522#ifdef CONFIG_GSC
@@ -1756,11 +1757,19 @@ static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
1756{ 1757{
1757 struct net_device *dev = pci_get_drvdata(pdev); 1758 struct net_device *dev = pci_get_drvdata(pdev);
1758 1759
1759 if (dev && netif_running (dev) && netif_device_present (dev)) { 1760 if (!dev)
1760 netif_device_detach (dev); 1761 return -EINVAL;
1761 tulip_down (dev); 1762
1762 /* pci_power_off(pdev, -1); */ 1763 if (netif_running(dev))
1763 } 1764 tulip_down(dev);
1765
1766 netif_device_detach(dev);
1767 free_irq(dev->irq, dev);
1768
1769 pci_save_state(pdev);
1770 pci_disable_device(pdev);
1771 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1772
1764 return 0; 1773 return 0;
1765} 1774}
1766 1775
@@ -1768,15 +1777,26 @@ static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
1768static int tulip_resume(struct pci_dev *pdev) 1777static int tulip_resume(struct pci_dev *pdev)
1769{ 1778{
1770 struct net_device *dev = pci_get_drvdata(pdev); 1779 struct net_device *dev = pci_get_drvdata(pdev);
1780 int retval;
1771 1781
1772 if (dev && netif_running (dev) && !netif_device_present (dev)) { 1782 if (!dev)
1773#if 1 1783 return -EINVAL;
1774 pci_enable_device (pdev); 1784
1775#endif 1785 pci_set_power_state(pdev, PCI_D0);
1776 /* pci_power_on(pdev); */ 1786 pci_restore_state(pdev);
1777 tulip_up (dev); 1787
1778 netif_device_attach (dev); 1788 pci_enable_device(pdev);
1789
1790 if ((retval = request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev))) {
1791 printk (KERN_ERR "tulip: request_irq failed in resume\n");
1792 return retval;
1779 } 1793 }
1794
1795 netif_device_attach(dev);
1796
1797 if (netif_running(dev))
1798 tulip_up(dev);
1799
1780 return 0; 1800 return 0;
1781} 1801}
1782 1802
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index caff2f590165..5b1af3986abf 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -121,6 +121,7 @@ static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
121#include <linux/slab.h> 121#include <linux/slab.h>
122#include <linux/interrupt.h> 122#include <linux/interrupt.h>
123#include <linux/pci.h> 123#include <linux/pci.h>
124#include <linux/dma-mapping.h>
124#include <linux/netdevice.h> 125#include <linux/netdevice.h>
125#include <linux/etherdevice.h> 126#include <linux/etherdevice.h>
126#include <linux/skbuff.h> 127#include <linux/skbuff.h>
@@ -394,7 +395,7 @@ static int __devinit w840_probe1 (struct pci_dev *pdev,
394 395
395 irq = pdev->irq; 396 irq = pdev->irq;
396 397
397 if (pci_set_dma_mask(pdev,0xFFFFffff)) { 398 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
398 printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n", 399 printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n",
399 pci_name(pdev)); 400 pci_name(pdev));
400 return -EIO; 401 return -EIO;
@@ -848,7 +849,7 @@ static void init_rxtx_rings(struct net_device *dev)
848 if (skb == NULL) 849 if (skb == NULL)
849 break; 850 break;
850 skb->dev = dev; /* Mark as being used by this device. */ 851 skb->dev = dev; /* Mark as being used by this device. */
851 np->rx_addr[i] = pci_map_single(np->pci_dev,skb->tail, 852 np->rx_addr[i] = pci_map_single(np->pci_dev,skb->data,
852 skb->len,PCI_DMA_FROMDEVICE); 853 skb->len,PCI_DMA_FROMDEVICE);
853 854
854 np->rx_ring[i].buffer1 = np->rx_addr[i]; 855 np->rx_ring[i].buffer1 = np->rx_addr[i];
@@ -1268,7 +1269,7 @@ static int netdev_rx(struct net_device *dev)
1268 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry], 1269 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry],
1269 np->rx_skbuff[entry]->len, 1270 np->rx_skbuff[entry]->len,
1270 PCI_DMA_FROMDEVICE); 1271 PCI_DMA_FROMDEVICE);
1271 eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0); 1272 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0);
1272 skb_put(skb, pkt_len); 1273 skb_put(skb, pkt_len);
1273 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry], 1274 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry],
1274 np->rx_skbuff[entry]->len, 1275 np->rx_skbuff[entry]->len,
@@ -1314,7 +1315,7 @@ static int netdev_rx(struct net_device *dev)
1314 break; /* Better luck next round. */ 1315 break; /* Better luck next round. */
1315 skb->dev = dev; /* Mark as being used by this device. */ 1316 skb->dev = dev; /* Mark as being used by this device. */
1316 np->rx_addr[entry] = pci_map_single(np->pci_dev, 1317 np->rx_addr[entry] = pci_map_single(np->pci_dev,
1317 skb->tail, 1318 skb->data,
1318 skb->len, PCI_DMA_FROMDEVICE); 1319 skb->len, PCI_DMA_FROMDEVICE);
1319 np->rx_ring[entry].buffer1 = np->rx_addr[entry]; 1320 np->rx_ring[entry].buffer1 = np->rx_addr[entry];
1320 } 1321 }
diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c
index b8a9b395c5ea..887d7245fe7b 100644
--- a/drivers/net/tulip/xircom_tulip_cb.c
+++ b/drivers/net/tulip/xircom_tulip_cb.c
@@ -899,7 +899,7 @@ static void xircom_init_ring(struct net_device *dev)
899 break; 899 break;
900 skb->dev = dev; /* Mark as being used by this device. */ 900 skb->dev = dev; /* Mark as being used by this device. */
901 tp->rx_ring[i].status = Rx0DescOwned; /* Owned by Xircom chip */ 901 tp->rx_ring[i].status = Rx0DescOwned; /* Owned by Xircom chip */
902 tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail); 902 tp->rx_ring[i].buffer1 = virt_to_bus(skb->data);
903 } 903 }
904 tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 904 tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
905 905
@@ -1291,7 +1291,7 @@ xircom_rx(struct net_device *dev)
1291 if (skb == NULL) 1291 if (skb == NULL)
1292 break; 1292 break;
1293 skb->dev = dev; /* Mark as being used by this device. */ 1293 skb->dev = dev; /* Mark as being used by this device. */
1294 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail); 1294 tp->rx_ring[entry].buffer1 = virt_to_bus(skb->data);
1295 work_done++; 1295 work_done++;
1296 } 1296 }
1297 tp->rx_ring[entry].status = Rx0DescOwned; 1297 tp->rx_ring[entry].status = Rx0DescOwned;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 7bfee366297b..effab0b9adca 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -215,7 +215,7 @@ static unsigned int tun_chr_poll(struct file *file, poll_table * wait)
215 215
216 poll_wait(file, &tun->read_wait, wait); 216 poll_wait(file, &tun->read_wait, wait);
217 217
218 if (skb_queue_len(&tun->readq)) 218 if (!skb_queue_empty(&tun->readq))
219 mask |= POLLIN | POLLRDNORM; 219 mask |= POLLIN | POLLRDNORM;
220 220
221 return mask; 221 return mask;
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 8f3392989a06..ecfa6f8805ce 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -1661,7 +1661,7 @@ typhoon_alloc_rx_skb(struct typhoon *tp, u32 idx)
1661#endif 1661#endif
1662 1662
1663 skb->dev = tp->dev; 1663 skb->dev = tp->dev;
1664 dma_addr = pci_map_single(tp->pdev, skb->tail, 1664 dma_addr = pci_map_single(tp->pdev, skb->data,
1665 PKT_BUF_SZ, PCI_DMA_FROMDEVICE); 1665 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
1666 1666
1667 /* Since no card does 64 bit DAC, the high bits will never 1667 /* Since no card does 64 bit DAC, the high bits will never
@@ -1721,7 +1721,7 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
1721 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, 1721 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
1722 PKT_BUF_SZ, 1722 PKT_BUF_SZ,
1723 PCI_DMA_FROMDEVICE); 1723 PCI_DMA_FROMDEVICE);
1724 eth_copy_and_sum(new_skb, skb->tail, pkt_len, 0); 1724 eth_copy_and_sum(new_skb, skb->data, pkt_len, 0);
1725 pci_dma_sync_single_for_device(tp->pdev, dma_addr, 1725 pci_dma_sync_single_for_device(tp->pdev, dma_addr,
1726 PKT_BUF_SZ, 1726 PKT_BUF_SZ,
1727 PCI_DMA_FROMDEVICE); 1727 PCI_DMA_FROMDEVICE);
@@ -1906,9 +1906,9 @@ typhoon_sleep(struct typhoon *tp, pci_power_t state, u16 events)
1906 */ 1906 */
1907 netif_carrier_off(tp->dev); 1907 netif_carrier_off(tp->dev);
1908 1908
1909 pci_enable_wake(tp->pdev, pci_choose_state(pdev, state), 1); 1909 pci_enable_wake(tp->pdev, state, 1);
1910 pci_disable_device(pdev); 1910 pci_disable_device(pdev);
1911 return pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1911 return pci_set_power_state(pdev, state);
1912} 1912}
1913 1913
1914static int 1914static int
@@ -2274,7 +2274,7 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
2274 goto need_resume; 2274 goto need_resume;
2275 } 2275 }
2276 2276
2277 if(typhoon_sleep(tp, state, tp->wol_events) < 0) { 2277 if(typhoon_sleep(tp, pci_choose_state(pdev, state), tp->wol_events) < 0) {
2278 printk(KERN_ERR "%s: unable to put card to sleep\n", dev->name); 2278 printk(KERN_ERR "%s: unable to put card to sleep\n", dev->name);
2279 goto need_resume; 2279 goto need_resume;
2280 } 2280 }
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 7b57d552094a..fc7738ffbfff 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -186,6 +186,7 @@ static const int multicast_filter_limit = 32;
186#include <linux/slab.h> 186#include <linux/slab.h>
187#include <linux/interrupt.h> 187#include <linux/interrupt.h>
188#include <linux/pci.h> 188#include <linux/pci.h>
189#include <linux/dma-mapping.h>
189#include <linux/netdevice.h> 190#include <linux/netdevice.h>
190#include <linux/etherdevice.h> 191#include <linux/etherdevice.h>
191#include <linux/skbuff.h> 192#include <linux/skbuff.h>
@@ -506,7 +507,7 @@ static struct net_device_stats *rhine_get_stats(struct net_device *dev);
506static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 507static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
507static struct ethtool_ops netdev_ethtool_ops; 508static struct ethtool_ops netdev_ethtool_ops;
508static int rhine_close(struct net_device *dev); 509static int rhine_close(struct net_device *dev);
509static void rhine_shutdown (struct device *gdev); 510static void rhine_shutdown (struct pci_dev *pdev);
510 511
511#define RHINE_WAIT_FOR(condition) do { \ 512#define RHINE_WAIT_FOR(condition) do { \
512 int i=1024; \ 513 int i=1024; \
@@ -740,7 +741,7 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
740 goto err_out; 741 goto err_out;
741 742
742 /* this should always be supported */ 743 /* this should always be supported */
743 rc = pci_set_dma_mask(pdev, 0xffffffff); 744 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
744 if (rc) { 745 if (rc) {
745 printk(KERN_ERR "32-bit PCI DMA addresses not supported by " 746 printk(KERN_ERR "32-bit PCI DMA addresses not supported by "
746 "the card!?\n"); 747 "the card!?\n");
@@ -989,7 +990,7 @@ static void alloc_rbufs(struct net_device *dev)
989 skb->dev = dev; /* Mark as being used by this device. */ 990 skb->dev = dev; /* Mark as being used by this device. */
990 991
991 rp->rx_skbuff_dma[i] = 992 rp->rx_skbuff_dma[i] =
992 pci_map_single(rp->pdev, skb->tail, rp->rx_buf_sz, 993 pci_map_single(rp->pdev, skb->data, rp->rx_buf_sz,
993 PCI_DMA_FROMDEVICE); 994 PCI_DMA_FROMDEVICE);
994 995
995 rp->rx_ring[i].addr = cpu_to_le32(rp->rx_skbuff_dma[i]); 996 rp->rx_ring[i].addr = cpu_to_le32(rp->rx_skbuff_dma[i]);
@@ -1397,7 +1398,7 @@ static void rhine_tx(struct net_device *dev)
1397 while (rp->dirty_tx != rp->cur_tx) { 1398 while (rp->dirty_tx != rp->cur_tx) {
1398 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status); 1399 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status);
1399 if (debug > 6) 1400 if (debug > 6)
1400 printk(KERN_DEBUG " Tx scavenge %d status %8.8x.\n", 1401 printk(KERN_DEBUG "Tx scavenge %d status %8.8x.\n",
1401 entry, txstatus); 1402 entry, txstatus);
1402 if (txstatus & DescOwn) 1403 if (txstatus & DescOwn)
1403 break; 1404 break;
@@ -1468,7 +1469,7 @@ static void rhine_rx(struct net_device *dev)
1468 int data_size = desc_status >> 16; 1469 int data_size = desc_status >> 16;
1469 1470
1470 if (debug > 4) 1471 if (debug > 4)
1471 printk(KERN_DEBUG " rhine_rx() status is %8.8x.\n", 1472 printk(KERN_DEBUG "rhine_rx() status is %8.8x.\n",
1472 desc_status); 1473 desc_status);
1473 if (--boguscnt < 0) 1474 if (--boguscnt < 0)
1474 break; 1475 break;
@@ -1486,7 +1487,7 @@ static void rhine_rx(struct net_device *dev)
1486 } else if (desc_status & RxErr) { 1487 } else if (desc_status & RxErr) {
1487 /* There was a error. */ 1488 /* There was a error. */
1488 if (debug > 2) 1489 if (debug > 2)
1489 printk(KERN_DEBUG " rhine_rx() Rx " 1490 printk(KERN_DEBUG "rhine_rx() Rx "
1490 "error was %8.8x.\n", 1491 "error was %8.8x.\n",
1491 desc_status); 1492 desc_status);
1492 rp->stats.rx_errors++; 1493 rp->stats.rx_errors++;
@@ -1517,7 +1518,7 @@ static void rhine_rx(struct net_device *dev)
1517 PCI_DMA_FROMDEVICE); 1518 PCI_DMA_FROMDEVICE);
1518 1519
1519 eth_copy_and_sum(skb, 1520 eth_copy_and_sum(skb,
1520 rp->rx_skbuff[entry]->tail, 1521 rp->rx_skbuff[entry]->data,
1521 pkt_len, 0); 1522 pkt_len, 0);
1522 skb_put(skb, pkt_len); 1523 skb_put(skb, pkt_len);
1523 pci_dma_sync_single_for_device(rp->pdev, 1524 pci_dma_sync_single_for_device(rp->pdev,
@@ -1560,7 +1561,7 @@ static void rhine_rx(struct net_device *dev)
1560 break; /* Better luck next round. */ 1561 break; /* Better luck next round. */
1561 skb->dev = dev; /* Mark as being used by this device. */ 1562 skb->dev = dev; /* Mark as being used by this device. */
1562 rp->rx_skbuff_dma[entry] = 1563 rp->rx_skbuff_dma[entry] =
1563 pci_map_single(rp->pdev, skb->tail, 1564 pci_map_single(rp->pdev, skb->data,
1564 rp->rx_buf_sz, 1565 rp->rx_buf_sz,
1565 PCI_DMA_FROMDEVICE); 1566 PCI_DMA_FROMDEVICE);
1566 rp->rx_ring[entry].addr = cpu_to_le32(rp->rx_skbuff_dma[entry]); 1567 rp->rx_ring[entry].addr = cpu_to_le32(rp->rx_skbuff_dma[entry]);
@@ -1894,9 +1895,8 @@ static void __devexit rhine_remove_one(struct pci_dev *pdev)
1894 pci_set_drvdata(pdev, NULL); 1895 pci_set_drvdata(pdev, NULL);
1895} 1896}
1896 1897
1897static void rhine_shutdown (struct device *gendev) 1898static void rhine_shutdown (struct pci_dev *pdev)
1898{ 1899{
1899 struct pci_dev *pdev = to_pci_dev(gendev);
1900 struct net_device *dev = pci_get_drvdata(pdev); 1900 struct net_device *dev = pci_get_drvdata(pdev);
1901 struct rhine_private *rp = netdev_priv(dev); 1901 struct rhine_private *rp = netdev_priv(dev);
1902 void __iomem *ioaddr = rp->base; 1902 void __iomem *ioaddr = rp->base;
@@ -1955,7 +1955,7 @@ static int rhine_suspend(struct pci_dev *pdev, pm_message_t state)
1955 pci_save_state(pdev); 1955 pci_save_state(pdev);
1956 1956
1957 spin_lock_irqsave(&rp->lock, flags); 1957 spin_lock_irqsave(&rp->lock, flags);
1958 rhine_shutdown(&pdev->dev); 1958 rhine_shutdown(pdev);
1959 spin_unlock_irqrestore(&rp->lock, flags); 1959 spin_unlock_irqrestore(&rp->lock, flags);
1960 1960
1961 free_irq(dev->irq, dev); 1961 free_irq(dev->irq, dev);
@@ -2009,9 +2009,7 @@ static struct pci_driver rhine_driver = {
2009 .suspend = rhine_suspend, 2009 .suspend = rhine_suspend,
2010 .resume = rhine_resume, 2010 .resume = rhine_resume,
2011#endif /* CONFIG_PM */ 2011#endif /* CONFIG_PM */
2012 .driver = { 2012 .shutdown = rhine_shutdown,
2013 .shutdown = rhine_shutdown,
2014 }
2015}; 2013};
2016 2014
2017 2015
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 15e710283493..abc5cee6eedc 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -1335,7 +1335,7 @@ static inline int velocity_rx_copy(struct sk_buff **rx_skb, int pkt_size,
1335 if (vptr->flags & VELOCITY_FLAGS_IP_ALIGN) 1335 if (vptr->flags & VELOCITY_FLAGS_IP_ALIGN)
1336 skb_reserve(new_skb, 2); 1336 skb_reserve(new_skb, 2);
1337 1337
1338 memcpy(new_skb->data, rx_skb[0]->tail, pkt_size); 1338 memcpy(new_skb->data, rx_skb[0]->data, pkt_size);
1339 *rx_skb = new_skb; 1339 *rx_skb = new_skb;
1340 ret = 0; 1340 ret = 0;
1341 } 1341 }
@@ -1456,9 +1456,9 @@ static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx)
1456 * Do the gymnastics to get the buffer head for data at 1456 * Do the gymnastics to get the buffer head for data at
1457 * 64byte alignment. 1457 * 64byte alignment.
1458 */ 1458 */
1459 skb_reserve(rd_info->skb, (unsigned long) rd_info->skb->tail & 63); 1459 skb_reserve(rd_info->skb, (unsigned long) rd_info->skb->data & 63);
1460 rd_info->skb->dev = vptr->dev; 1460 rd_info->skb->dev = vptr->dev;
1461 rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->tail, vptr->rx_buf_sz, PCI_DMA_FROMDEVICE); 1461 rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->data, vptr->rx_buf_sz, PCI_DMA_FROMDEVICE);
1462 1462
1463 /* 1463 /*
1464 * Fill in the descriptor to match 1464 * Fill in the descriptor to match
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 7575b799ce53..2c83cca34b86 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -861,8 +861,7 @@ fst_tx_dma_complete(struct fst_card_info *card, struct fst_port_info *port,
861/* 861/*
862 * Mark it for our own raw sockets interface 862 * Mark it for our own raw sockets interface
863 */ 863 */
864static unsigned short farsync_type_trans(struct sk_buff *skb, 864static __be16 farsync_type_trans(struct sk_buff *skb, struct net_device *dev)
865 struct net_device *dev)
866{ 865{
867 skb->dev = dev; 866 skb->dev = dev;
868 skb->mac.raw = skb->data; 867 skb->mac.raw = skb->data;
@@ -981,6 +980,7 @@ fst_issue_cmd(struct fst_port_info *port, unsigned short cmd)
981 /* Wait for any previous command to complete */ 980 /* Wait for any previous command to complete */
982 while (mbval > NAK) { 981 while (mbval > NAK) {
983 spin_unlock_irqrestore(&card->card_lock, flags); 982 spin_unlock_irqrestore(&card->card_lock, flags);
983 set_current_state(TASK_UNINTERRUPTIBLE);
984 schedule_timeout(1); 984 schedule_timeout(1);
985 spin_lock_irqsave(&card->card_lock, flags); 985 spin_lock_irqsave(&card->card_lock, flags);
986 986
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index c1b6896d7007..48c03c11cd9a 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -72,7 +72,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
72 } 72 }
73 skb_reserve(skb, 4); 73 skb_reserve(skb, 4);
74 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0); 74 cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0);
75 data = (cisco_packet*)skb->tail; 75 data = (cisco_packet*)skb->data;
76 76
77 data->type = htonl(type); 77 data->type = htonl(type);
78 data->par1 = htonl(par1); 78 data->par1 = htonl(par1);
@@ -91,8 +91,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
91 91
92 92
93 93
94static unsigned short cisco_type_trans(struct sk_buff *skb, 94static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev)
95 struct net_device *dev)
96{ 95{
97 hdlc_header *data = (hdlc_header*)skb->data; 96 hdlc_header *data = (hdlc_header*)skb->data;
98 97
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index 7cd6195a2e46..b81263eaede0 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -66,8 +66,7 @@ static void ppp_close(struct net_device *dev)
66 66
67 67
68 68
69static unsigned short ppp_type_trans(struct sk_buff *skb, 69static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev)
70 struct net_device *dev)
71{ 70{
72 return __constant_htons(ETH_P_WAN_PPP); 71 return __constant_htons(ETH_P_WAN_PPP);
73} 72}
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index c41fb70b6929..9456d31cb1c1 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -24,8 +24,7 @@
24#include <linux/hdlc.h> 24#include <linux/hdlc.h>
25 25
26 26
27static unsigned short raw_type_trans(struct sk_buff *skb, 27static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
28 struct net_device *dev)
29{ 28{
30 return __constant_htons(ETH_P_IP); 29 return __constant_htons(ETH_P_IP);
31} 30}
diff --git a/drivers/net/wan/sdla_fr.c b/drivers/net/wan/sdla_fr.c
index 2efccb0554c0..c5f5e62aab8b 100644
--- a/drivers/net/wan/sdla_fr.c
+++ b/drivers/net/wan/sdla_fr.c
@@ -152,6 +152,7 @@
152#include <asm/io.h> /* for inb(), outb(), etc. */ 152#include <asm/io.h> /* for inb(), outb(), etc. */
153#include <linux/time.h> /* for do_gettimeofday */ 153#include <linux/time.h> /* for do_gettimeofday */
154#include <linux/in.h> /* sockaddr_in */ 154#include <linux/in.h> /* sockaddr_in */
155#include <linux/jiffies.h> /* time_after() macro */
155#include <asm/errno.h> 156#include <asm/errno.h>
156 157
157#include <linux/ip.h> 158#include <linux/ip.h>
@@ -773,7 +774,7 @@ static int update(struct wan_device* wandev)
773 for(;;) { 774 for(;;) {
774 if(card->u.f.update_comms_stats == 0) 775 if(card->u.f.update_comms_stats == 0)
775 break; 776 break;
776 if ((jiffies - timeout) > (1 * HZ)){ 777 if (time_after(jiffies, timeout + 1 * HZ)){
777 card->u.f.update_comms_stats = 0; 778 card->u.f.update_comms_stats = 0;
778 return -EAGAIN; 779 return -EAGAIN;
779 } 780 }
@@ -4799,7 +4800,7 @@ static void trigger_unconfig_fr(struct net_device *dev)
4799{ 4800{
4800 fr_channel_t *chan = dev->priv; 4801 fr_channel_t *chan = dev->priv;
4801 volatile sdla_t *card = chan->card; 4802 volatile sdla_t *card = chan->card;
4802 u32 timeout; 4803 unsigned long timeout;
4803 fr508_flags_t* flags = card->flags; 4804 fr508_flags_t* flags = card->flags;
4804 int reset_critical=0; 4805 int reset_critical=0;
4805 4806
@@ -4821,7 +4822,7 @@ static void trigger_unconfig_fr(struct net_device *dev)
4821 if(!(card->u.f.timer_int_enabled & TMR_INT_ENABLED_UNCONFIG)) 4822 if(!(card->u.f.timer_int_enabled & TMR_INT_ENABLED_UNCONFIG))
4822 break; 4823 break;
4823 4824
4824 if ((jiffies - timeout) > (1 * HZ)){ 4825 if (time_after(jiffies, timeout + 1 * HZ)){
4825 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UNCONFIG; 4826 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UNCONFIG;
4826 printk(KERN_INFO "%s: Failed to delete DLCI %i\n", 4827 printk(KERN_INFO "%s: Failed to delete DLCI %i\n",
4827 card->devname,chan->dlci); 4828 card->devname,chan->dlci);
diff --git a/drivers/net/wan/sdla_ft1.c b/drivers/net/wan/sdla_ft1.c
index 5e3124856eb0..9d6528a50f7b 100644
--- a/drivers/net/wan/sdla_ft1.c
+++ b/drivers/net/wan/sdla_ft1.c
@@ -29,6 +29,7 @@
29#include <linux/wanrouter.h> /* WAN router definitions */ 29#include <linux/wanrouter.h> /* WAN router definitions */
30#include <linux/wanpipe.h> /* WANPIPE common user API definitions */ 30#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
31#include <linux/if_arp.h> /* ARPHRD_* defines */ 31#include <linux/if_arp.h> /* ARPHRD_* defines */
32#include <linux/jiffies.h> /* time_after() macro */
32 33
33#include <linux/inetdevice.h> 34#include <linux/inetdevice.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -164,7 +165,7 @@ int wpft1_init (sdla_t* card, wandev_conf_t* conf)
164 165
165 timeout = jiffies; 166 timeout = jiffies;
166 while (mb->return_code != 'I') /* Wait 1s for board to initialize */ 167 while (mb->return_code != 'I') /* Wait 1s for board to initialize */
167 if ((jiffies - timeout) > 1*HZ) break; 168 if (time_after(jiffies, timeout + 1*HZ)) break;
168 169
169 if (mb->return_code != 'I') { 170 if (mb->return_code != 'I') {
170 printk(KERN_INFO 171 printk(KERN_INFO
diff --git a/drivers/net/wan/sdla_ppp.c b/drivers/net/wan/sdla_ppp.c
index 1761cb68ab48..a4b489cccbbf 100644
--- a/drivers/net/wan/sdla_ppp.c
+++ b/drivers/net/wan/sdla_ppp.c
@@ -101,6 +101,7 @@
101#include <linux/if_arp.h> /* ARPHRD_* defines */ 101#include <linux/if_arp.h> /* ARPHRD_* defines */
102#include <asm/byteorder.h> /* htons(), etc. */ 102#include <asm/byteorder.h> /* htons(), etc. */
103#include <linux/in.h> /* sockaddr_in */ 103#include <linux/in.h> /* sockaddr_in */
104#include <linux/jiffies.h> /* time_after() macro */
104 105
105 106
106#include <asm/uaccess.h> 107#include <asm/uaccess.h>
@@ -482,7 +483,7 @@ static int update(struct wan_device *wandev)
482 if(ppp_priv_area->update_comms_stats == 0){ 483 if(ppp_priv_area->update_comms_stats == 0){
483 break; 484 break;
484 } 485 }
485 if ((jiffies - timeout) > (1 * HZ)){ 486 if (time_after(jiffies, timeout + 1 * HZ)){
486 ppp_priv_area->update_comms_stats = 0; 487 ppp_priv_area->update_comms_stats = 0;
487 ppp_priv_area->timer_int_enabled &= 488 ppp_priv_area->timer_int_enabled &=
488 ~TMR_INT_ENABLED_UPDATE; 489 ~TMR_INT_ENABLED_UPDATE;
diff --git a/drivers/net/wan/sdla_x25.c b/drivers/net/wan/sdla_x25.c
index 3a93d2fd4fbf..8a95d61a2f8f 100644
--- a/drivers/net/wan/sdla_x25.c
+++ b/drivers/net/wan/sdla_x25.c
@@ -91,6 +91,7 @@
91#include <linux/wanrouter.h> /* WAN router definitions */ 91#include <linux/wanrouter.h> /* WAN router definitions */
92#include <linux/wanpipe.h> /* WANPIPE common user API definitions */ 92#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
93#include <linux/workqueue.h> 93#include <linux/workqueue.h>
94#include <linux/jiffies.h> /* time_after() macro */
94#include <asm/byteorder.h> /* htons(), etc. */ 95#include <asm/byteorder.h> /* htons(), etc. */
95#include <asm/atomic.h> 96#include <asm/atomic.h>
96#include <linux/delay.h> /* Experimental delay */ 97#include <linux/delay.h> /* Experimental delay */
@@ -867,7 +868,7 @@ static int update(struct wan_device* wandev)
867 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_UPDATE)){ 868 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_UPDATE)){
868 break; 869 break;
869 } 870 }
870 if ((jiffies-timeout) > 1*HZ){ 871 if (time_after(jiffies, timeout + 1*HZ)){
871 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE; 872 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE;
872 return -EAGAIN; 873 return -EAGAIN;
873 } 874 }
diff --git a/drivers/net/wan/wanpipe_multppp.c b/drivers/net/wan/wanpipe_multppp.c
index 6aa6987d96cb..812a1183c502 100644
--- a/drivers/net/wan/wanpipe_multppp.c
+++ b/drivers/net/wan/wanpipe_multppp.c
@@ -26,6 +26,7 @@
26#include <linux/wanrouter.h> /* WAN router definitions */ 26#include <linux/wanrouter.h> /* WAN router definitions */
27#include <linux/wanpipe.h> /* WANPIPE common user API definitions */ 27#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
28#include <linux/if_arp.h> /* ARPHRD_* defines */ 28#include <linux/if_arp.h> /* ARPHRD_* defines */
29#include <linux/jiffies.h> /* time_after() macro */
29 30
30#include <linux/in.h> /* sockaddr_in */ 31#include <linux/in.h> /* sockaddr_in */
31#include <linux/inet.h> 32#include <linux/inet.h>
@@ -270,9 +271,9 @@ int wsppp_init (sdla_t* card, wandev_conf_t* conf)
270 ready to accept commands. We expect this to be completed in less 271 ready to accept commands. We expect this to be completed in less
271 than 1 second. */ 272 than 1 second. */
272 273
273 timeout = jiffies; 274 timeout = jiffies + 1 * HZ;
274 while (mb->return_code != 'I') /* Wait 1s for board to initialize */ 275 while (mb->return_code != 'I') /* Wait 1s for board to initialize */
275 if ((jiffies - timeout) > 1*HZ) break; 276 if (time_after(jiffies, timeout)) break;
276 277
277 if (mb->return_code != 'I') { 278 if (mb->return_code != 'I') {
278 printk(KERN_INFO 279 printk(KERN_INFO
@@ -493,11 +494,11 @@ static int update(struct wan_device* wandev)
493 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UPDATE; 494 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UPDATE;
494 495
495 /* wait a maximum of 1 second for the statistics to be updated */ 496 /* wait a maximum of 1 second for the statistics to be updated */
496 timeout = jiffies; 497 timeout = jiffies + 1 * HZ;
497 for(;;) { 498 for(;;) {
498 if(chdlc_priv_area->update_comms_stats == 0) 499 if(chdlc_priv_area->update_comms_stats == 0)
499 break; 500 break;
500 if ((jiffies - timeout) > (1 * HZ)){ 501 if (time_after(jiffies, timeout)){
501 chdlc_priv_area->update_comms_stats = 0; 502 chdlc_priv_area->update_comms_stats = 0;
502 chdlc_priv_area->timer_int_enabled &= 503 chdlc_priv_area->timer_int_enabled &=
503 ~TMR_INT_ENABLED_UPDATE; 504 ~TMR_INT_ENABLED_UPDATE;
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index 1e7b47704ad9..9c1e10602f2b 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -26,6 +26,7 @@
26#include <linux/netdevice.h> 26#include <linux/netdevice.h>
27#include <linux/hdlc.h> 27#include <linux/hdlc.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/dma-mapping.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/delay.h> 31#include <asm/delay.h>
31 32
@@ -624,8 +625,8 @@ static int __devinit wanxl_pci_init_one(struct pci_dev *pdev,
624 /* FIXME when PCI/DMA subsystems are fixed. 625 /* FIXME when PCI/DMA subsystems are fixed.
625 We set both dma_mask and consistent_dma_mask back to 32 bits 626 We set both dma_mask and consistent_dma_mask back to 32 bits
626 to indicate the card can do 32-bit DMA addressing */ 627 to indicate the card can do 32-bit DMA addressing */
627 if (pci_set_consistent_dma_mask(pdev, 0xFFFFFFFF) || 628 if (pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) ||
628 pci_set_dma_mask(pdev, 0xFFFFFFFF)) { 629 pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
629 printk(KERN_ERR "wanXL: No usable DMA configuration\n"); 630 printk(KERN_ERR "wanXL: No usable DMA configuration\n");
630 wanxl_pci_remove_one(pdev); 631 wanxl_pci_remove_one(pdev);
631 return -EIO; 632 return -EIO;
diff --git a/drivers/net/wd.c b/drivers/net/wd.c
index 1f05d9bd05e4..b03feae459fc 100644
--- a/drivers/net/wd.c
+++ b/drivers/net/wd.c
@@ -149,12 +149,7 @@ struct net_device * __init wd_probe(int unit)
149 err = do_wd_probe(dev); 149 err = do_wd_probe(dev);
150 if (err) 150 if (err)
151 goto out; 151 goto out;
152 err = register_netdev(dev);
153 if (err)
154 goto out1;
155 return dev; 152 return dev;
156out1:
157 cleanup_card(dev);
158out: 153out:
159 free_netdev(dev); 154 free_netdev(dev);
160 return ERR_PTR(err); 155 return ERR_PTR(err);
@@ -164,6 +159,7 @@ out:
164static int __init wd_probe1(struct net_device *dev, int ioaddr) 159static int __init wd_probe1(struct net_device *dev, int ioaddr)
165{ 160{
166 int i; 161 int i;
162 int err;
167 int checksum = 0; 163 int checksum = 0;
168 int ancient = 0; /* An old card without config registers. */ 164 int ancient = 0; /* An old card without config registers. */
169 int word16 = 0; /* 0 = 8 bit, 1 = 16 bit */ 165 int word16 = 0; /* 0 = 8 bit, 1 = 16 bit */
@@ -356,7 +352,10 @@ static int __init wd_probe1(struct net_device *dev, int ioaddr)
356 outb(inb(ioaddr+4)|0x80, ioaddr+4); 352 outb(inb(ioaddr+4)|0x80, ioaddr+4);
357#endif 353#endif
358 354
359 return 0; 355 err = register_netdev(dev);
356 if (err)
357 free_irq(dev->irq, dev);
358 return err;
360} 359}
361 360
362static int 361static int
@@ -527,11 +526,8 @@ init_module(void)
527 dev->mem_start = mem[this_dev]; 526 dev->mem_start = mem[this_dev];
528 dev->mem_end = mem_end[this_dev]; 527 dev->mem_end = mem_end[this_dev];
529 if (do_wd_probe(dev) == 0) { 528 if (do_wd_probe(dev) == 0) {
530 if (register_netdev(dev) == 0) { 529 dev_wd[found++] = dev;
531 dev_wd[found++] = dev; 530 continue;
532 continue;
533 }
534 cleanup_card(dev);
535 } 531 }
536 free_netdev(dev); 532 free_netdev(dev);
537 printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]); 533 printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]);
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index d72e0385e4f2..47f3c5d0203d 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -900,7 +900,7 @@ typedef struct aironet_ioctl {
900 unsigned char __user *data; // d-data 900 unsigned char __user *data; // d-data
901} aironet_ioctl; 901} aironet_ioctl;
902 902
903static char *swversion = "2.1"; 903static char swversion[] = "2.1";
904#endif /* CISCO_EXT */ 904#endif /* CISCO_EXT */
905 905
906#define NUM_MODULES 2 906#define NUM_MODULES 2
@@ -1209,7 +1209,7 @@ struct airo_info {
1209 unsigned char __iomem *pciaux; 1209 unsigned char __iomem *pciaux;
1210 unsigned char *shared; 1210 unsigned char *shared;
1211 dma_addr_t shared_dma; 1211 dma_addr_t shared_dma;
1212 int power; 1212 pm_message_t power;
1213 SsidRid *SSID; 1213 SsidRid *SSID;
1214 APListRid *APList; 1214 APListRid *APList;
1215#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE 1215#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
@@ -2374,7 +2374,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
2374 /* 2374 /*
2375 * Clean out tx queue 2375 * Clean out tx queue
2376 */ 2376 */
2377 if (test_bit(FLAG_MPI, &ai->flags) && skb_queue_len (&ai->txq) > 0) { 2377 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2378 struct sk_buff *skb = NULL; 2378 struct sk_buff *skb = NULL;
2379 for (;(skb = skb_dequeue(&ai->txq));) 2379 for (;(skb = skb_dequeue(&ai->txq));)
2380 dev_kfree_skb(skb); 2380 dev_kfree_skb(skb);
@@ -3287,7 +3287,7 @@ exitrx:
3287 if (status & EV_TXEXC) 3287 if (status & EV_TXEXC)
3288 get_tx_error(apriv, -1); 3288 get_tx_error(apriv, -1);
3289 spin_lock_irqsave(&apriv->aux_lock, flags); 3289 spin_lock_irqsave(&apriv->aux_lock, flags);
3290 if (skb_queue_len (&apriv->txq)) { 3290 if (!skb_queue_empty(&apriv->txq)) {
3291 spin_unlock_irqrestore(&apriv->aux_lock,flags); 3291 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3292 mpi_send_packet (dev); 3292 mpi_send_packet (dev);
3293 } else { 3293 } else {
@@ -5499,9 +5499,9 @@ static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5499 cmd.cmd=HOSTSLEEP; 5499 cmd.cmd=HOSTSLEEP;
5500 issuecommand(ai, &cmd, &rsp); 5500 issuecommand(ai, &cmd, &rsp);
5501 5501
5502 pci_enable_wake(pdev, state, 1); 5502 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5503 pci_save_state(pdev); 5503 pci_save_state(pdev);
5504 return pci_set_power_state(pdev, state); 5504 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
5505} 5505}
5506 5506
5507static int airo_pci_resume(struct pci_dev *pdev) 5507static int airo_pci_resume(struct pci_dev *pdev)
@@ -5512,7 +5512,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
5512 5512
5513 pci_set_power_state(pdev, 0); 5513 pci_set_power_state(pdev, 0);
5514 pci_restore_state(pdev); 5514 pci_restore_state(pdev);
5515 pci_enable_wake(pdev, ai->power, 0); 5515 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0);
5516 5516
5517 if (ai->power > 1) { 5517 if (ai->power > 1) {
5518 reset_card(dev, 0); 5518 reset_card(dev, 0);
@@ -5541,7 +5541,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
5541 } 5541 }
5542 writeConfigRid(ai, 0); 5542 writeConfigRid(ai, 0);
5543 enable_MAC(ai, &rsp, 0); 5543 enable_MAC(ai, &rsp, 0);
5544 ai->power = 0; 5544 ai->power = PMSG_ON;
5545 netif_device_attach(dev); 5545 netif_device_attach(dev);
5546 netif_wake_queue(dev); 5546 netif_wake_queue(dev);
5547 enable_interrupts(ai); 5547 enable_interrupts(ai);
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index fbf53af6cda4..bf25584d68d3 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -33,7 +33,6 @@
33#include <linux/timer.h> 33#include <linux/timer.h>
34#include <linux/netdevice.h> 34#include <linux/netdevice.h>
35 35
36#include <pcmcia/version.h>
37#include <pcmcia/cs_types.h> 36#include <pcmcia/cs_types.h>
38#include <pcmcia/cs.h> 37#include <pcmcia/cs.h>
39#include <pcmcia/cistpl.h> 38#include <pcmcia/cistpl.h>
@@ -210,11 +209,6 @@ static dev_link_t *airo_attach(void)
210 link->next = dev_list; 209 link->next = dev_list;
211 dev_list = link; 210 dev_list = link;
212 client_reg.dev_info = &dev_info; 211 client_reg.dev_info = &dev_info;
213 client_reg.EventMask =
214 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
215 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
216 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
217 client_reg.event_handler = &airo_event;
218 client_reg.Version = 0x0210; 212 client_reg.Version = 0x0210;
219 client_reg.event_callback_args.client_data = link; 213 client_reg.event_callback_args.client_data = link;
220 ret = pcmcia_register_client(&link->handle, &client_reg); 214 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -559,13 +553,24 @@ static int airo_event(event_t event, int priority,
559 return 0; 553 return 0;
560} /* airo_event */ 554} /* airo_event */
561 555
556static struct pcmcia_device_id airo_ids[] = {
557 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
558 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005),
559 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0007),
560 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0007),
561 PCMCIA_DEVICE_NULL,
562};
563MODULE_DEVICE_TABLE(pcmcia, airo_ids);
564
562static struct pcmcia_driver airo_driver = { 565static struct pcmcia_driver airo_driver = {
563 .owner = THIS_MODULE, 566 .owner = THIS_MODULE,
564 .drv = { 567 .drv = {
565 .name = "airo_cs", 568 .name = "airo_cs",
566 }, 569 },
567 .attach = airo_attach, 570 .attach = airo_attach,
571 .event = airo_event,
568 .detach = airo_detach, 572 .detach = airo_detach,
573 .id_table = airo_ids,
569}; 574};
570 575
571static int airo_cs_init(void) 576static int airo_cs_init(void)
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/airport.c
index b4f4bd7956a2..9d496703c465 100644
--- a/drivers/net/wireless/airport.c
+++ b/drivers/net/wireless/airport.c
@@ -184,7 +184,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
184} 184}
185 185
186static int 186static int
187airport_attach(struct macio_dev *mdev, const struct of_match *match) 187airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
188{ 188{
189 struct orinoco_private *priv; 189 struct orinoco_private *priv;
190 struct net_device *dev; 190 struct net_device *dev;
@@ -266,16 +266,16 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
266MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); 266MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
267MODULE_LICENSE("Dual MPL/GPL"); 267MODULE_LICENSE("Dual MPL/GPL");
268 268
269static struct of_match airport_match[] = 269static struct of_device_id airport_match[] =
270{ 270{
271 { 271 {
272 .name = "radio", 272 .name = "radio",
273 .type = OF_ANY_MATCH,
274 .compatible = OF_ANY_MATCH
275 }, 273 },
276 {}, 274 {},
277}; 275};
278 276
277MODULE_DEVICE_TABLE (of, airport_match);
278
279static struct macio_driver airport_driver = 279static struct macio_driver airport_driver =
280{ 280{
281 .name = DRIVER_NAME, 281 .name = DRIVER_NAME,
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/net/wireless/arlan-main.c
index 4f304c6e693a..0e1ac338cac1 100644
--- a/drivers/net/wireless/arlan-main.c
+++ b/drivers/net/wireless/arlan-main.c
@@ -33,8 +33,6 @@ static int arlan_EEPROM_bad;
33 33
34#ifdef ARLAN_DEBUGGING 34#ifdef ARLAN_DEBUGGING
35 35
36static int arlan_entry_debug;
37static int arlan_exit_debug;
38static int testMemory = testMemoryUNKNOWN; 36static int testMemory = testMemoryUNKNOWN;
39static int irq = irqUNKNOWN; 37static int irq = irqUNKNOWN;
40static int txScrambled = 1; 38static int txScrambled = 1;
@@ -43,15 +41,13 @@ static int mdebug;
43module_param(irq, int, 0); 41module_param(irq, int, 0);
44module_param(mdebug, int, 0); 42module_param(mdebug, int, 0);
45module_param(testMemory, int, 0); 43module_param(testMemory, int, 0);
46module_param(arlan_entry_debug, int, 0);
47module_param(arlan_exit_debug, int, 0);
48module_param(txScrambled, int, 0); 44module_param(txScrambled, int, 0);
49MODULE_PARM_DESC(irq, "(unused)"); 45MODULE_PARM_DESC(irq, "(unused)");
50MODULE_PARM_DESC(testMemory, "(unused)"); 46MODULE_PARM_DESC(testMemory, "(unused)");
51MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)"); 47MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
52#endif 48#endif
53 49
54module_param(arlan_debug, int, 0); 50module_param_named(debug, arlan_debug, int, 0);
55module_param(spreadingCode, int, 0); 51module_param(spreadingCode, int, 0);
56module_param(channelNumber, int, 0); 52module_param(channelNumber, int, 0);
57module_param(channelSet, int, 0); 53module_param(channelSet, int, 0);
@@ -63,17 +59,19 @@ module_param(keyStart, int, 0);
63module_param(tx_delay_ms, int, 0); 59module_param(tx_delay_ms, int, 0);
64module_param(retries, int, 0); 60module_param(retries, int, 0);
65module_param(tx_queue_len, int, 0); 61module_param(tx_queue_len, int, 0);
66module_param(arlan_EEPROM_bad, int, 0); 62module_param_named(EEPROM_bad, arlan_EEPROM_bad, int, 0);
67MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)"); 63MODULE_PARM_DESC(debug, "Arlan debug enable (0-1)");
68MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions"); 64MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
69#ifdef ARLAN_ENTRY_EXIT_DEBUGGING 65#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
70MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging"); 66static int arlan_entry_debug;
71MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging"); 67static int arlan_exit_debug;
72MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging"); 68static int arlan_entry_and_exit_debug;
73#else 69module_param_named(entry_debug, arlan_entry_debug, int, 0);
74MODULE_PARM_DESC(arlan_entry_debug, "(ignored)"); 70module_param_named(exit_debug, arlan_exit_debug, int, 0);
75MODULE_PARM_DESC(arlan_exit_debug, "(ignored)"); 71module_param_named(entry_and_exit_debug, arlan_entry_and_exit_debug, int, 0);
76MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)"); 72MODULE_PARM_DESC(entry_debug, "Arlan driver function entry debugging");
73MODULE_PARM_DESC(exit_debug, "Arlan driver function exit debugging");
74MODULE_PARM_DESC(entry_and_exit_debug, "Arlan driver function entry and exit debugging");
77#endif 75#endif
78 76
79struct arlan_conf_stru arlan_conf[MAX_ARLANS]; 77struct arlan_conf_stru arlan_conf[MAX_ARLANS];
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index a4ed28d9c783..ff031a3985b3 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -43,7 +43,6 @@
43#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
44#include <linux/device.h> 44#include <linux/device.h>
45 45
46#include <pcmcia/version.h>
47#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
48#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
@@ -218,11 +217,6 @@ static dev_link_t *atmel_attach(void)
218 link->next = dev_list; 217 link->next = dev_list;
219 dev_list = link; 218 dev_list = link;
220 client_reg.dev_info = &dev_info; 219 client_reg.dev_info = &dev_info;
221 client_reg.EventMask =
222 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
223 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
224 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
225 client_reg.event_handler = &atmel_event;
226 client_reg.Version = 0x0210; 220 client_reg.Version = 0x0210;
227 client_reg.event_callback_args.client_data = link; 221 client_reg.event_callback_args.client_data = link;
228 ret = pcmcia_register_client(&link->handle, &client_reg); 222 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -646,13 +640,36 @@ static int atmel_event(event_t event, int priority,
646} /* atmel_event */ 640} /* atmel_event */
647 641
648/*====================================================================*/ 642/*====================================================================*/
643static struct pcmcia_device_id atmel_ids[] = {
644 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0620),
645 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0696),
646 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3302),
647 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0007),
648 PCMCIA_DEVICE_PROD_ID12("11WAVE", "11WP611AL-E", 0x9eb2da1f, 0xc9a0d3f9),
649 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C502AR", 0xabda4164, 0x41b37e1f),
650 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C504", 0xabda4164, 0x5040670a),
651 PCMCIA_DEVICE_PROD_ID12("ATMEL", "AT76C504A", 0xabda4164, 0xe15ed87f),
652 PCMCIA_DEVICE_PROD_ID12("BT", "Voyager 1020 Laptop Adapter", 0xae49b86a, 0x1e957cd5),
653 PCMCIA_DEVICE_PROD_ID12("CNet", "CNWLC 11Mbps Wireless PC Card V-5", 0xbc477dde, 0x502fae6b),
654 PCMCIA_DEVICE_PROD_ID12("IEEE 802.11b", "Wireless LAN PC Card", 0x5b878724, 0x122f1df6),
655 PCMCIA_DEVICE_PROD_ID12("OEM", "11Mbps Wireless LAN PC Card V-3", 0xfea54c90, 0x1c5b0f68),
656 PCMCIA_DEVICE_PROD_ID12("SMC", "2632W", 0xc4f8b18b, 0x30f38774),
657 PCMCIA_DEVICE_PROD_ID12("SMC", "2632W-V2", 0xc4f8b18b, 0x172d1377),
658 PCMCIA_DEVICE_PROD_ID12("Wireless", "PC", 0xa407ecdd, 0x556e4d7e),
659 PCMCIA_DEVICE_PROD_ID12("WLAN", "802.11b PC CARD", 0x575c516c, 0xb1f6dbc4),
660 PCMCIA_DEVICE_NULL
661};
662MODULE_DEVICE_TABLE(pcmcia, atmel_ids);
663
649static struct pcmcia_driver atmel_driver = { 664static struct pcmcia_driver atmel_driver = {
650 .owner = THIS_MODULE, 665 .owner = THIS_MODULE,
651 .drv = { 666 .drv = {
652 .name = "atmel_cs", 667 .name = "atmel_cs",
653 }, 668 },
654 .attach = atmel_attach, 669 .attach = atmel_attach,
655 .detach = atmel_detach, 670 .event = atmel_event,
671 .detach = atmel_detach,
672 .id_table = atmel_ids,
656}; 673};
657 674
658static int atmel_cs_init(void) 675static int atmel_cs_init(void)
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 382241e7edbb..5f507c49907b 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -62,7 +62,6 @@
62#endif /* WIRELESS_EXT > 12 */ 62#endif /* WIRELESS_EXT > 12 */
63#endif 63#endif
64 64
65#include <pcmcia/version.h>
66#include <pcmcia/cs_types.h> 65#include <pcmcia/cs_types.h>
67#include <pcmcia/cs.h> 66#include <pcmcia/cs.h>
68#include <pcmcia/cistpl.h> 67#include <pcmcia/cistpl.h>
@@ -491,11 +490,6 @@ static dev_link_t *netwave_attach(void)
491 link->next = dev_list; 490 link->next = dev_list;
492 dev_list = link; 491 dev_list = link;
493 client_reg.dev_info = &dev_info; 492 client_reg.dev_info = &dev_info;
494 client_reg.EventMask =
495 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
496 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
497 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
498 client_reg.event_handler = &netwave_event;
499 client_reg.Version = 0x0210; 493 client_reg.Version = 0x0210;
500 client_reg.event_callback_args.client_data = link; 494 client_reg.event_callback_args.client_data = link;
501 ret = pcmcia_register_client(&link->handle, &client_reg); 495 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -1668,13 +1662,21 @@ static int netwave_close(struct net_device *dev) {
1668 return 0; 1662 return 0;
1669} 1663}
1670 1664
1665static struct pcmcia_device_id netwave_ids[] = {
1666 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1667 PCMCIA_DEVICE_NULL,
1668};
1669MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1670
1671static struct pcmcia_driver netwave_driver = { 1671static struct pcmcia_driver netwave_driver = {
1672 .owner = THIS_MODULE, 1672 .owner = THIS_MODULE,
1673 .drv = { 1673 .drv = {
1674 .name = "netwave_cs", 1674 .name = "netwave_cs",
1675 }, 1675 },
1676 .attach = netwave_attach, 1676 .attach = netwave_attach,
1677 .event = netwave_event,
1677 .detach = netwave_detach, 1678 .detach = netwave_detach,
1679 .id_table = netwave_ids,
1678}; 1680};
1679 1681
1680static int __init init_netwave_cs(void) 1682static int __init init_netwave_cs(void)
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index b1078baa1d5e..aabcdc2be05e 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -46,382 +46,9 @@
46 * under either the MPL or the GPL. */ 46 * under either the MPL or the GPL. */
47 47
48/* 48/*
49 * v0.01 -> v0.02 - 21/3/2001 - Jean II
50 * o Allow to use regular ethX device name instead of dldwdX
51 * o Warning on IBSS with ESSID=any for firmware 6.06
52 * o Put proper range.throughput values (optimistic)
53 * o IWSPY support (IOCTL and stat gather in Rx path)
54 * o Allow setting frequency in Ad-Hoc mode
55 * o Disable WEP setting if !has_wep to work on old firmware
56 * o Fix txpower range
57 * o Start adding support for Samsung/Compaq firmware
58 *
59 * v0.02 -> v0.03 - 23/3/2001 - Jean II
60 * o Start adding Symbol support - need to check all that
61 * o Fix Prism2/Symbol WEP to accept 128 bits keys
62 * o Add Symbol WEP (add authentication type)
63 * o Add Prism2/Symbol rate
64 * o Add PM timeout (holdover duration)
65 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
66 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
67 * o Try with an Intel card. It report firmware 1.01, behave like
68 * an antiquated firmware, however on windows it says 2.00. Yuck !
69 * o Workaround firmware bug in allocate buffer (Intel 1.01)
70 * o Finish external renaming to orinoco...
71 * o Testing with various Wavelan firmwares
72 *
73 * v0.03 -> v0.04 - 30/3/2001 - Jean II
74 * o Update to Wireless 11 -> add retry limit/lifetime support
75 * o Tested with a D-Link DWL 650 card, fill in firmware support
76 * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
77 * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
78 * It works on D-Link *only* after a tcpdump. Weird...
79 * And still doesn't work on Intel card. Grrrr...
80 * o Update the mode after a setport3
81 * o Add preamble setting for Symbol cards (not yet enabled)
82 * o Don't complain as much about Symbol cards...
83 *
84 * v0.04 -> v0.04b - 22/4/2001 - David Gibson
85 * o Removed the 'eth' parameter - always use ethXX as the
86 * interface name instead of dldwdXX. The other was racy
87 * anyway.
88 * o Clean up RID definitions in hermes.h, other cleanups
89 *
90 * v0.04b -> v0.04c - 24/4/2001 - Jean II
91 * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
92 * with vendor 02 and firmware 0.08. Added in the capabilities...
93 * o Tested Lucent firmware 7.28, everything works...
94 *
95 * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
96 * o Spin-off Pcmcia code. This file is renamed orinoco.c,
97 * and orinoco_cs.c now contains only the Pcmcia specific stuff
98 * o Add Airport driver support on top of orinoco.c (see airport.c)
99 *
100 * v0.05 -> v0.05a - 4/5/2001 - Jean II
101 * o Revert to old Pcmcia code to fix breakage of Ben's changes...
102 *
103 * v0.05a -> v0.05b - 4/5/2001 - Jean II
104 * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
105 * o D-Link firmware doesn't support multicast. We just print a few
106 * error messages, but otherwise everything works...
107 * o For David : set/getport3 works fine, just upgrade iwpriv...
108 *
109 * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
110 * o Adapt airport.c to latest changes in orinoco.c
111 * o Remove deferred power enabling code
112 *
113 * v0.05c -> v0.05d - 5/5/2001 - Jean II
114 * o Workaround to SNAP decapsulate frame from Linksys AP
115 * original patch from : Dong Liu <dliu AT research.bell-labs.com>
116 * (note : the memcmp bug was mine - fixed)
117 * o Remove set_retry stuff, no firmware support it (bloat--).
118 *
119 * v0.05d -> v0.06 - 25/5/2001 - Jean II
120 * Original patch from "Hong Lin" <alin AT redhat.com>,
121 * "Ian Kinner" <ikinner AT redhat.com>
122 * and "David Smith" <dsmith AT redhat.com>
123 * o Init of priv->tx_rate_ctrl in firmware specific section.
124 * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
125 * o Spectrum card always need cor_reset (for every reset)
126 * o Fix cor_reset to not lose bit 7 in the register
127 * o flush_stale_links to remove zombie Pcmcia instances
128 * o Ack previous hermes event before reset
129 * Me (with my little hands)
130 * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
131 * o Add priv->need_card_reset to toggle this feature
132 * o Fix various buglets when setting WEP in Symbol firmware
133 * Now, encryption is fully functional on Symbol cards. Youpi !
134 *
135 * v0.06 -> v0.06b - 25/5/2001 - Jean II
136 * o IBSS on Symbol use port_mode = 4. Please don't ask...
137 *
138 * v0.06b -> v0.06c - 29/5/2001 - Jean II
139 * o Show first spy address in /proc/net/wireless for IBSS mode as well
140 *
141 * v0.06c -> v0.06d - 6/7/2001 - David Gibson
142 * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
143 * wishes to reduce the number of unnecessary messages.
144 * o Removed bogus message on CRC error.
145 * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
146 * <willwaghorn AT yahoo.co.uk>
147 * o Slight cleanup/re-arrangement of firmware detection code.
148 *
149 * v0.06d -> v0.06e - 1/8/2001 - David Gibson
150 * o Removed some redundant global initializers (orinoco_cs.c).
151 * o Added some module metadata
152 *
153 * v0.06e -> v0.06f - 14/8/2001 - David Gibson
154 * o Wording fix to license
155 * o Added a 'use_alternate_encaps' module parameter for APs which need an
156 * oui of 00:00:00. We really need a better way of handling this, but
157 * the module flag is better than nothing for now.
158 *
159 * v0.06f -> v0.07 - 20/8/2001 - David Gibson
160 * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
161 * let the upper layers handle the retry, we retry explicitly in the
162 * Rx path, but don't make as much noise about it.
163 * o Firmware detection cleanups.
164 *
165 * v0.07 -> v0.07a - 1/10/3001 - Jean II
166 * o Add code to read Symbol firmware revision, inspired by latest code
167 * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
168 * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
169 * a 3Com card with a recent firmware, fill out Symbol firmware
170 * capabilities of latest rev (2.20), as well as older Symbol cards.
171 * o Disable Power Management in newer Symbol firmware, the API
172 * has changed (documentation needed).
173 *
174 * v0.07a -> v0.08 - 3/10/2001 - David Gibson
175 * o Fixed a possible buffer overrun found by the Stanford checker (in
176 * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
177 * a big problem.
178 * o Turned has_big_wep on for Intersil cards. That's not true for all of
179 * them but we should at least let the capable ones try.
180 * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
181 * realized that my assumption that the driver's serialization
182 * would prevent the BAP being busy on entry was possibly false, because
183 * things other than seeks may make the BAP busy.
184 * o Use "alternate" (oui 00:00:00) encapsulation by default.
185 * Setting use_old_encaps will mimic the old behaviour, but I think we
186 * will be able to eliminate this.
187 * o Don't try to make __initdata const (the version string). This can't
188 * work because of the way the __initdata sectioning works.
189 * o Added MODULE_LICENSE tags.
190 * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
191 * o Changed to using the new type-fascist min/max.
192 *
193 * v0.08 -> v0.08a - 9/10/2001 - David Gibson
194 * o Inserted some missing acknowledgements/info into the Changelog.
195 * o Fixed some bugs in the normalization of signal level reporting.
196 * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
197 * which led to an instant crash on big-endian machines.
198 *
199 * v0.08a -> v0.08b - 20/11/2001 - David Gibson
200 * o Lots of cleanup and bugfixes in orinoco_plx.c
201 * o Cleanup to handling of Tx rate setting.
202 * o Removed support for old encapsulation method.
203 * o Removed old "dldwd" names.
204 * o Split RID constants into a new file hermes_rid.h
205 * o Renamed RID constants to match linux-wlan-ng and prism2.o
206 * o Bugfixes in hermes.c
207 * o Poke the PLX's INTCSR register, so it actually starts
208 * generating interrupts. These cards might actually work now.
209 * o Update to wireless extensions v12 (Jean II)
210 * o Support for tallies and inquire command (Jean II)
211 * o Airport updates for newer PPC kernels (BenH)
212 *
213 * v0.08b -> v0.09 - 21/12/2001 - David Gibson
214 * o Some new PCI IDs for PLX cards.
215 * o Removed broken attempt to do ALLMULTI reception. Just use
216 * promiscuous mode instead
217 * o Preliminary work for list-AP (Jean II)
218 * o Airport updates from (BenH)
219 * o Eliminated racy hw_ready stuff
220 * o Fixed generation of fake events in irq handler. This should
221 * finally kill the EIO problems (Jean II & dgibson)
222 * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
223 *
224 * v0.09 -> v0.09a - 2/1/2002 - David Gibson
225 * o Fixed stupid mistake in multicast list handling, triggering
226 * a BUG()
227 *
228 * v0.09a -> v0.09b - 16/1/2002 - David Gibson
229 * o Fixed even stupider mistake in new interrupt handling, which
230 * seriously broke things on big-endian machines.
231 * o Removed a bunch of redundant includes and exports.
232 * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
233 * o Don't attempt to do hardware level multicast reception on
234 * Intersil firmware, just go promisc instead.
235 * o Typo fixed in hermes_issue_cmd()
236 * o Eliminated WIRELESS_SPY #ifdefs
237 * o Status code reported on Tx exceptions
238 * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
239 * interrupts, which should fix the timeouts we're seeing.
240 *
241 * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
242 * o Removed nested structures used for header parsing, so the
243 * driver should now work without hackery on ARM
244 * o Fix for WEP handling on Intersil (Hawk Newton)
245 * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
246 * was never very useful.
247 * o Make Rx errors less noisy.
248 *
249 * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
250 * o Laid the groundwork in hermes.[ch] for devices which map
251 * into PCI memory space rather than IO space.
252 * o Fixed bug in multicast handling (cleared multicast list when
253 * leaving promiscuous mode).
254 * o Relegated Tx error messages to debug.
255 * o Cleaned up / corrected handling of allocation lengths.
256 * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
257 * o Change to using alloc_etherdev() for structure allocations.
258 * o Check for and drop undersized packets.
259 * o Fixed a race in stopping/waking the queue. This should fix
260 * the timeout problems (Pavel Roskin)
261 * o Reverted to netif_wake_queue() on the ALLOC event.
262 * o Fixes for recent Symbol firmwares which lack AP density
263 * (Pavel Roskin).
264 *
265 * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
266 * o Handle different register spacing, necessary for Prism 2.5
267 * PCI adaptors (Steve Hill).
268 * o Cleaned up initialization of card structures in orinoco_cs
269 * and airport. Removed card->priv field.
270 * o Make response structure optional for hermes_docmd_wait()
271 * Pavel Roskin)
272 * o Added PCI id for Nortel emobility to orinoco_plx.c.
273 * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
274 * o Cleanups to firmware capability detection.
275 * o Arrange for orinoco_pci.c to override firmware detection.
276 * We should be able to support the PCI Intersil cards now.
277 * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
278 * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
279 * Malinen).
280 * o Makefile changes for better integration into David Hinds
281 * pcmcia-cs package.
282 *
283 * v0.11a -> v0.11b - 1 May 2002 - David Gibson
284 * o Better error reporting in orinoco_plx_init_one()
285 * o Fixed multiple bad kfree() bugs introduced by the
286 * alloc_orinocodev() changes.
287 *
288 * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
289 * o Support changing the MAC address.
290 * o Correct display of Intersil firmware revision numbers.
291 * o Entirely revised locking scheme. Should be both simpler and
292 * better.
293 * o Merged some common code in orinoco_plx, orinoco_pci and
294 * airport by creating orinoco_default_{open,stop,reset}()
295 * which are used as the dev->open, dev->stop, priv->reset
296 * callbacks if none are specified when alloc_orinocodev() is
297 * called.
298 * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
299 * They didn't do anything.
300 *
301 * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
302 * o Some rearrangement of code.
303 * o Numerous fixups to locking and rest handling, particularly
304 * for PCMCIA.
305 * o This allows open and stop net_device methods to be in
306 * orinoco.c now, rather than in the init modules.
307 * o In orinoco_cs.c link->priv now points to the struct
308 * net_device not to the struct orinoco_private.
309 * o Added a check for undersized SNAP frames, which could cause
310 * crashes.
311 *
312 * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
313 * o Fix hw->num_init testing code, so num_init is actually
314 * incremented.
315 * o Fix very stupid bug in orinoco_cs which broke compile with
316 * CONFIG_SMP.
317 * o Squashed a warning.
318 *
319 * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
320 * o Change to C9X style designated initializers.
321 * o Add support for 3Com AirConnect PCI.
322 * o No longer ignore the hard_reset argument to
323 * alloc_orinocodev(). Oops.
324 *
325 * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
326 * o Revert the broken 0.12* locking scheme and go to a new yet
327 * simpler scheme.
328 * o Do firmware resets only in orinoco_init() and when waking
329 * the card from hard sleep.
330 *
331 * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
332 * o Re-introduced full resets (via schedule_task()) on Tx
333 * timeout.
334 *
335 * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
336 * o Minor cleanups to info frame handling. Add basic support
337 * for linkstatus info frames.
338 * o Include required kernel headers in orinoco.h, to avoid
339 * compile problems.
340 *
341 * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
342 * o Implemented hard reset for Airport cards
343 * o Experimental suspend/resume implementation for orinoco_pci
344 * o Abolished /proc debugging support, replaced with a debugging
345 * iwpriv. Now it's ugly and simple instead of ugly and complex.
346 * o Bugfix in hermes.c if the firmware returned a record length
347 * of 0, we could go clobbering memory.
348 * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
349 * was set, which was usually true on PCMCIA hot removes.
350 * o Track LINKSTATUS messages, silently drop Tx packets before
351 * we are connected (avoids confusing the firmware), and only
352 * give LINKSTATUS printk()s if the status has changed.
353 *
354 * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
355 * o Cleanup: use dev instead of priv in various places.
356 * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
357 * if we're in the middle of a (driver initiated) hard reset.
358 * o Bug fix: ETH_ZLEN is supposed to include the header
359 * (Dionysus Blazakis & Manish Karir)
360 * o Convert to using workqueues instead of taskqueues (and
361 * backwards compatibility macros for pre 2.5.41 kernels).
362 * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
363 * airport.c
364 * o New orinoco_tmd.c init module from Joerg Dorchain for
365 * TMD7160 based PCI to PCMCIA bridges (similar to
366 * orinoco_plx.c).
367 *
368 * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
369 * o Make hw_unavailable a counter, rather than just a flag, this
370 * is necessary to avoid some races (such as a card being
371 * removed in the middle of orinoco_reset().
372 * o Restore Release/RequestConfiguration in the PCMCIA event handler
373 * when dealing with a driver initiated hard reset. This is
374 * necessary to prevent hangs due to a spurious interrupt while
375 * the reset is in progress.
376 * o Clear the 802.11 header when transmitting, even though we
377 * don't use it. This fixes a long standing bug on some
378 * firmwares, which seem to get confused if that isn't done.
379 * o Be less eager to de-encapsulate SNAP frames, only do so if
380 * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
381 * behaviour broke CDP (Cisco Discovery Protocol).
382 * o Use dev instead of priv for free_irq() as well as
383 * request_irq() (oops).
384 * o Attempt to reset rather than giving up if we get too many
385 * IRQs.
386 * o Changed semantics of __orinoco_down() so it can be called
387 * safely with hw_unavailable set. It also now clears the
388 * linkstatus (since we're going to have to reassociate).
389 *
390 * v0.13d -> v0.13e - 12 May 2003 - David Gibson
391 * o Support for post-2.5.68 return values from irq handler.
392 * o Fixed bug where underlength packets would be double counted
393 * in the rx_dropped statistics.
394 * o Provided a module parameter to suppress linkstatus messages.
395 *
396 * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
397 * o Replaced priv->connected logic with netif_carrier_on/off()
398 * calls.
399 * o Remove has_ibss_any and never set the CREATEIBSS RID when
400 * the ESSID is empty. Too many firmwares break if we do.
401 * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
402 * __devinitdata from PCI ID tables, use free_netdev().
403 * o Enabled shared-key authentication for Agere firmware (from
404 * Robert J. Moore <Robert.J.Moore AT allanbank.com>
405 * o Move netif_wake_queue() (back) to the Tx completion from the
406 * ALLOC event. This seems to prevent/mitigate the rolling
407 * error -110 problems at least on some Intersil firmwares.
408 * Theoretically reduces performance, but I can't measure it.
409 * Patch from Andrew Tridgell <tridge AT samba.org>
410 *
411 * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
412 * o Correctly turn off shared-key authentication when requested
413 * (bugfix from Robert J. Moore).
414 * o Correct airport sleep interfaces for current 2.6 kernels.
415 * o Add code for key change without disabling/enabling the MAC
416 * port. This is supposed to allow 802.1x to work sanely, but
417 * doesn't seem to yet.
418 *
419 * TODO 49 * TODO
420 * o New wireless extensions API (patch from Moustafa
421 * Youssef, updated by Jim Carter and Pavel Roskin).
422 * o Handle de-encapsulation within network layer, provide 802.11 50 * o Handle de-encapsulation within network layer, provide 802.11
423 * headers (patch from Thomas 'Dent' Mirlacher) 51 * headers (patch from Thomas 'Dent' Mirlacher)
424 * o RF monitor mode support
425 * o Fix possible races in SPY handling. 52 * o Fix possible races in SPY handling.
426 * o Disconnect wireless extensions from fundamental configuration. 53 * o Disconnect wireless extensions from fundamental configuration.
427 * o (maybe) Software WEP support (patch from Stano Meduna). 54 * o (maybe) Software WEP support (patch from Stano Meduna).
@@ -462,7 +89,10 @@
462#include <linux/netdevice.h> 89#include <linux/netdevice.h>
463#include <linux/if_arp.h> 90#include <linux/if_arp.h>
464#include <linux/etherdevice.h> 91#include <linux/etherdevice.h>
92#include <linux/ethtool.h>
465#include <linux/wireless.h> 93#include <linux/wireless.h>
94#include <net/iw_handler.h>
95#include <net/ieee80211.h>
466 96
467#include <asm/uaccess.h> 97#include <asm/uaccess.h>
468#include <asm/io.h> 98#include <asm/io.h>
@@ -496,6 +126,10 @@ static int ignore_disconnect; /* = 0 */
496module_param(ignore_disconnect, int, 0644); 126module_param(ignore_disconnect, int, 0644);
497MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer"); 127MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
498 128
129static int force_monitor; /* = 0 */
130module_param(force_monitor, int, 0644);
131MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
132
499/********************************************************************/ 133/********************************************************************/
500/* Compile time configuration and compatibility stuff */ 134/* Compile time configuration and compatibility stuff */
501/********************************************************************/ 135/********************************************************************/
@@ -511,6 +145,10 @@ MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer
511/* Internal constants */ 145/* Internal constants */
512/********************************************************************/ 146/********************************************************************/
513 147
148/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
149static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
150#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
151
514#define ORINOCO_MIN_MTU 256 152#define ORINOCO_MIN_MTU 256
515#define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD) 153#define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
516 154
@@ -537,6 +175,11 @@ MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer
537 | HERMES_EV_WTERR | HERMES_EV_INFO \ 175 | HERMES_EV_WTERR | HERMES_EV_INFO \
538 | HERMES_EV_INFDROP ) 176 | HERMES_EV_INFDROP )
539 177
178#define MAX_RID_LEN 1024
179
180static const struct iw_handler_def orinoco_handler_def;
181static struct ethtool_ops orinoco_ethtool_ops;
182
540/********************************************************************/ 183/********************************************************************/
541/* Data tables */ 184/* Data tables */
542/********************************************************************/ 185/********************************************************************/
@@ -571,26 +214,45 @@ static struct {
571/* Data types */ 214/* Data types */
572/********************************************************************/ 215/********************************************************************/
573 216
574struct header_struct { 217/* Used in Event handling.
575 /* 802.3 */ 218 * We avoid nested structres as they break on ARM -- Moustafa */
576 u8 dest[ETH_ALEN]; 219struct hermes_tx_descriptor_802_11 {
577 u8 src[ETH_ALEN]; 220 /* hermes_tx_descriptor */
578 u16 len; 221 u16 status;
579 /* 802.2 */ 222 u16 reserved1;
223 u16 reserved2;
224 u32 sw_support;
225 u8 retry_count;
226 u8 tx_rate;
227 u16 tx_control;
228
229 /* ieee802_11_hdr */
230 u16 frame_ctl;
231 u16 duration_id;
232 u8 addr1[ETH_ALEN];
233 u8 addr2[ETH_ALEN];
234 u8 addr3[ETH_ALEN];
235 u16 seq_ctl;
236 u8 addr4[ETH_ALEN];
237 u16 data_len;
238
239 /* ethhdr */
240 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
241 unsigned char h_source[ETH_ALEN]; /* source ether addr */
242 unsigned short h_proto; /* packet type ID field */
243
244 /* p8022_hdr */
580 u8 dsap; 245 u8 dsap;
581 u8 ssap; 246 u8 ssap;
582 u8 ctrl; 247 u8 ctrl;
583 /* SNAP */
584 u8 oui[3]; 248 u8 oui[3];
249
585 u16 ethertype; 250 u16 ethertype;
586} __attribute__ ((packed)); 251} __attribute__ ((packed));
587 252
588/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ 253/* Rx frame header except compatibility 802.3 header */
589u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
590
591#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
592
593struct hermes_rx_descriptor { 254struct hermes_rx_descriptor {
255 /* Control */
594 u16 status; 256 u16 status;
595 u32 time; 257 u32 time;
596 u8 silence; 258 u8 silence;
@@ -598,13 +260,24 @@ struct hermes_rx_descriptor {
598 u8 rate; 260 u8 rate;
599 u8 rxflow; 261 u8 rxflow;
600 u32 reserved; 262 u32 reserved;
263
264 /* 802.11 header */
265 u16 frame_ctl;
266 u16 duration_id;
267 u8 addr1[ETH_ALEN];
268 u8 addr2[ETH_ALEN];
269 u8 addr3[ETH_ALEN];
270 u16 seq_ctl;
271 u8 addr4[ETH_ALEN];
272
273 /* Data length */
274 u16 data_len;
601} __attribute__ ((packed)); 275} __attribute__ ((packed));
602 276
603/********************************************************************/ 277/********************************************************************/
604/* Function prototypes */ 278/* Function prototypes */
605/********************************************************************/ 279/********************************************************************/
606 280
607static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
608static int __orinoco_program_rids(struct net_device *dev); 281static int __orinoco_program_rids(struct net_device *dev);
609static void __orinoco_set_multicast_list(struct net_device *dev); 282static void __orinoco_set_multicast_list(struct net_device *dev);
610 283
@@ -628,6 +301,10 @@ static inline void set_port_type(struct orinoco_private *priv)
628 priv->createibss = 1; 301 priv->createibss = 1;
629 } 302 }
630 break; 303 break;
304 case IW_MODE_MONITOR:
305 priv->port_type = 3;
306 priv->createibss = 0;
307 break;
631 default: 308 default:
632 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", 309 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
633 priv->ndev->name); 310 priv->ndev->name);
@@ -814,7 +491,7 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
814 return 1; 491 return 1;
815 } 492 }
816 493
817 if (! netif_carrier_ok(dev)) { 494 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
818 /* Oops, the firmware hasn't established a connection, 495 /* Oops, the firmware hasn't established a connection,
819 silently drop the packet (this seems to be the 496 silently drop the packet (this seems to be the
820 safest approach). */ 497 safest approach). */
@@ -951,26 +628,55 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
951 struct orinoco_private *priv = netdev_priv(dev); 628 struct orinoco_private *priv = netdev_priv(dev);
952 struct net_device_stats *stats = &priv->stats; 629 struct net_device_stats *stats = &priv->stats;
953 u16 fid = hermes_read_regn(hw, TXCOMPLFID); 630 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
954 struct hermes_tx_descriptor desc; 631 struct hermes_tx_descriptor_802_11 hdr;
955 int err = 0; 632 int err = 0;
956 633
957 if (fid == DUMMY_FID) 634 if (fid == DUMMY_FID)
958 return; /* Nothing's really happened */ 635 return; /* Nothing's really happened */
959 636
960 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0); 637 /* Read the frame header */
638 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
639 sizeof(struct hermes_tx_descriptor) +
640 sizeof(struct ieee80211_hdr),
641 fid, 0);
642
643 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
644 stats->tx_errors++;
645
961 if (err) { 646 if (err) {
962 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " 647 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
963 "(FID=%04X error %d)\n", 648 "(FID=%04X error %d)\n",
964 dev->name, fid, err); 649 dev->name, fid, err);
965 } else { 650 return;
966 DEBUG(1, "%s: Tx error, status %d\n",
967 dev->name, le16_to_cpu(desc.status));
968 } 651 }
969 652
970 stats->tx_errors++; 653 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
654 err, fid);
655
656 /* We produce a TXDROP event only for retry or lifetime
657 * exceeded, because that's the only status that really mean
658 * that this particular node went away.
659 * Other errors means that *we* screwed up. - Jean II */
660 hdr.status = le16_to_cpu(hdr.status);
661 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
662 union iwreq_data wrqu;
663
664 /* Copy 802.11 dest address.
665 * We use the 802.11 header because the frame may
666 * not be 802.3 or may be mangled...
667 * In Ad-Hoc mode, it will be the node address.
668 * In managed mode, it will be most likely the AP addr
669 * User space will figure out how to convert it to
670 * whatever it needs (IP address or else).
671 * - Jean II */
672 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
673 wrqu.addr.sa_family = ARPHRD_ETHER;
674
675 /* Send event to user space */
676 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
677 }
971 678
972 netif_wake_queue(dev); 679 netif_wake_queue(dev);
973 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
974} 680}
975 681
976static void orinoco_tx_timeout(struct net_device *dev) 682static void orinoco_tx_timeout(struct net_device *dev)
@@ -1047,18 +753,127 @@ static void orinoco_stat_gather(struct net_device *dev,
1047 } 753 }
1048} 754}
1049 755
756/*
757 * orinoco_rx_monitor - handle received monitor frames.
758 *
759 * Arguments:
760 * dev network device
761 * rxfid received FID
762 * desc rx descriptor of the frame
763 *
764 * Call context: interrupt
765 */
766static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
767 struct hermes_rx_descriptor *desc)
768{
769 u32 hdrlen = 30; /* return full header by default */
770 u32 datalen = 0;
771 u16 fc;
772 int err;
773 int len;
774 struct sk_buff *skb;
775 struct orinoco_private *priv = netdev_priv(dev);
776 struct net_device_stats *stats = &priv->stats;
777 hermes_t *hw = &priv->hw;
778
779 len = le16_to_cpu(desc->data_len);
780
781 /* Determine the size of the header and the data */
782 fc = le16_to_cpu(desc->frame_ctl);
783 switch (fc & IEEE80211_FCTL_FTYPE) {
784 case IEEE80211_FTYPE_DATA:
785 if ((fc & IEEE80211_FCTL_TODS)
786 && (fc & IEEE80211_FCTL_FROMDS))
787 hdrlen = 30;
788 else
789 hdrlen = 24;
790 datalen = len;
791 break;
792 case IEEE80211_FTYPE_MGMT:
793 hdrlen = 24;
794 datalen = len;
795 break;
796 case IEEE80211_FTYPE_CTL:
797 switch (fc & IEEE80211_FCTL_STYPE) {
798 case IEEE80211_STYPE_PSPOLL:
799 case IEEE80211_STYPE_RTS:
800 case IEEE80211_STYPE_CFEND:
801 case IEEE80211_STYPE_CFENDACK:
802 hdrlen = 16;
803 break;
804 case IEEE80211_STYPE_CTS:
805 case IEEE80211_STYPE_ACK:
806 hdrlen = 10;
807 break;
808 }
809 break;
810 default:
811 /* Unknown frame type */
812 break;
813 }
814
815 /* sanity check the length */
816 if (datalen > IEEE80211_DATA_LEN + 12) {
817 printk(KERN_DEBUG "%s: oversized monitor frame, "
818 "data length = %d\n", dev->name, datalen);
819 err = -EIO;
820 stats->rx_length_errors++;
821 goto update_stats;
822 }
823
824 skb = dev_alloc_skb(hdrlen + datalen);
825 if (!skb) {
826 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
827 dev->name);
828 err = -ENOMEM;
829 goto drop;
830 }
831
832 /* Copy the 802.11 header to the skb */
833 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
834 skb->mac.raw = skb->data;
835
836 /* If any, copy the data from the card to the skb */
837 if (datalen > 0) {
838 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
839 ALIGN(datalen, 2), rxfid,
840 HERMES_802_2_OFFSET);
841 if (err) {
842 printk(KERN_ERR "%s: error %d reading monitor frame\n",
843 dev->name, err);
844 goto drop;
845 }
846 }
847
848 skb->dev = dev;
849 skb->ip_summed = CHECKSUM_NONE;
850 skb->pkt_type = PACKET_OTHERHOST;
851 skb->protocol = __constant_htons(ETH_P_802_2);
852
853 dev->last_rx = jiffies;
854 stats->rx_packets++;
855 stats->rx_bytes += skb->len;
856
857 netif_rx(skb);
858 return;
859
860 drop:
861 dev_kfree_skb_irq(skb);
862 update_stats:
863 stats->rx_errors++;
864 stats->rx_dropped++;
865}
866
1050static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) 867static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1051{ 868{
1052 struct orinoco_private *priv = netdev_priv(dev); 869 struct orinoco_private *priv = netdev_priv(dev);
1053 struct net_device_stats *stats = &priv->stats; 870 struct net_device_stats *stats = &priv->stats;
1054 struct iw_statistics *wstats = &priv->wstats; 871 struct iw_statistics *wstats = &priv->wstats;
1055 struct sk_buff *skb = NULL; 872 struct sk_buff *skb = NULL;
1056 u16 rxfid, status; 873 u16 rxfid, status, fc;
1057 int length, data_len, data_off; 874 int length;
1058 char *p;
1059 struct hermes_rx_descriptor desc; 875 struct hermes_rx_descriptor desc;
1060 struct header_struct hdr; 876 struct ethhdr *hdr;
1061 struct ethhdr *eh;
1062 int err; 877 int err;
1063 878
1064 rxfid = hermes_read_regn(hw, RXFID); 879 rxfid = hermes_read_regn(hw, RXFID);
@@ -1068,53 +883,46 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1068 if (err) { 883 if (err) {
1069 printk(KERN_ERR "%s: error %d reading Rx descriptor. " 884 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1070 "Frame dropped.\n", dev->name, err); 885 "Frame dropped.\n", dev->name, err);
1071 stats->rx_errors++; 886 goto update_stats;
1072 goto drop;
1073 } 887 }
1074 888
1075 status = le16_to_cpu(desc.status); 889 status = le16_to_cpu(desc.status);
1076 890
1077 if (status & HERMES_RXSTAT_ERR) { 891 if (status & HERMES_RXSTAT_BADCRC) {
1078 if (status & HERMES_RXSTAT_UNDECRYPTABLE) { 892 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1079 wstats->discard.code++; 893 dev->name);
1080 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", 894 stats->rx_crc_errors++;
1081 dev->name); 895 goto update_stats;
1082 } else {
1083 stats->rx_crc_errors++;
1084 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
1085 }
1086 stats->rx_errors++;
1087 goto drop;
1088 } 896 }
1089 897
1090 /* For now we ignore the 802.11 header completely, assuming 898 /* Handle frames in monitor mode */
1091 that the card's firmware has handled anything vital */ 899 if (priv->iw_mode == IW_MODE_MONITOR) {
900 orinoco_rx_monitor(dev, rxfid, &desc);
901 return;
902 }
1092 903
1093 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr), 904 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1094 rxfid, HERMES_802_3_OFFSET); 905 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1095 if (err) { 906 dev->name);
1096 printk(KERN_ERR "%s: error %d reading frame header. " 907 wstats->discard.code++;
1097 "Frame dropped.\n", dev->name, err); 908 goto update_stats;
1098 stats->rx_errors++;
1099 goto drop;
1100 } 909 }
1101 910
1102 length = ntohs(hdr.len); 911 length = le16_to_cpu(desc.data_len);
1103 912 fc = le16_to_cpu(desc.frame_ctl);
913
1104 /* Sanity checks */ 914 /* Sanity checks */
1105 if (length < 3) { /* No for even an 802.2 LLC header */ 915 if (length < 3) { /* No for even an 802.2 LLC header */
1106 /* At least on Symbol firmware with PCF we get quite a 916 /* At least on Symbol firmware with PCF we get quite a
1107 lot of these legitimately - Poll frames with no 917 lot of these legitimately - Poll frames with no
1108 data. */ 918 data. */
1109 stats->rx_dropped++; 919 return;
1110 goto drop;
1111 } 920 }
1112 if (length > IEEE802_11_DATA_LEN) { 921 if (length > IEEE802_11_DATA_LEN) {
1113 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", 922 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1114 dev->name, length); 923 dev->name, length);
1115 stats->rx_length_errors++; 924 stats->rx_length_errors++;
1116 stats->rx_errors++; 925 goto update_stats;
1117 goto drop;
1118 } 926 }
1119 927
1120 /* We need space for the packet data itself, plus an ethernet 928 /* We need space for the packet data itself, plus an ethernet
@@ -1126,60 +934,53 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1126 if (!skb) { 934 if (!skb) {
1127 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", 935 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1128 dev->name); 936 dev->name);
1129 goto drop; 937 goto update_stats;
1130 } 938 }
1131 939
1132 skb_reserve(skb, 2); /* This way the IP header is aligned */ 940 /* We'll prepend the header, so reserve space for it. The worst
941 case is no decapsulation, when 802.3 header is prepended and
942 nothing is removed. 2 is for aligning the IP header. */
943 skb_reserve(skb, ETH_HLEN + 2);
944
945 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
946 ALIGN(length, 2), rxfid,
947 HERMES_802_2_OFFSET);
948 if (err) {
949 printk(KERN_ERR "%s: error %d reading frame. "
950 "Frame dropped.\n", dev->name, err);
951 goto drop;
952 }
1133 953
1134 /* Handle decapsulation 954 /* Handle decapsulation
1135 * In most cases, the firmware tell us about SNAP frames. 955 * In most cases, the firmware tell us about SNAP frames.
1136 * For some reason, the SNAP frames sent by LinkSys APs 956 * For some reason, the SNAP frames sent by LinkSys APs
1137 * are not properly recognised by most firmwares. 957 * are not properly recognised by most firmwares.
1138 * So, check ourselves */ 958 * So, check ourselves */
1139 if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || 959 if (length >= ENCAPS_OVERHEAD &&
1140 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || 960 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1141 is_ethersnap(&hdr)) { 961 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
962 is_ethersnap(skb->data))) {
1142 /* These indicate a SNAP within 802.2 LLC within 963 /* These indicate a SNAP within 802.2 LLC within
1143 802.11 frame which we'll need to de-encapsulate to 964 802.11 frame which we'll need to de-encapsulate to
1144 the original EthernetII frame. */ 965 the original EthernetII frame. */
1145 966 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1146 if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
1147 stats->rx_length_errors++;
1148 goto drop;
1149 }
1150
1151 /* Remove SNAP header, reconstruct EthernetII frame */
1152 data_len = length - ENCAPS_OVERHEAD;
1153 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
1154
1155 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1156
1157 memcpy(eh, &hdr, 2 * ETH_ALEN);
1158 eh->h_proto = hdr.ethertype;
1159 } else { 967 } else {
1160 /* All other cases indicate a genuine 802.3 frame. No 968 /* 802.3 frame - prepend 802.3 header as is */
1161 decapsulation needed. We just throw the whole 969 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1162 thing in, and hope the protocol layer can deal with 970 hdr->h_proto = htons(length);
1163 it as 802.3 */
1164 data_len = length;
1165 data_off = HERMES_802_3_OFFSET;
1166 /* FIXME: we re-read from the card data we already read here */
1167 }
1168
1169 p = skb_put(skb, data_len);
1170 err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
1171 rxfid, data_off);
1172 if (err) {
1173 printk(KERN_ERR "%s: error %d reading frame. "
1174 "Frame dropped.\n", dev->name, err);
1175 stats->rx_errors++;
1176 goto drop;
1177 } 971 }
972 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
973 if (fc & IEEE80211_FCTL_FROMDS)
974 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
975 else
976 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1178 977
1179 dev->last_rx = jiffies; 978 dev->last_rx = jiffies;
1180 skb->dev = dev; 979 skb->dev = dev;
1181 skb->protocol = eth_type_trans(skb, dev); 980 skb->protocol = eth_type_trans(skb, dev);
1182 skb->ip_summed = CHECKSUM_NONE; 981 skb->ip_summed = CHECKSUM_NONE;
982 if (fc & IEEE80211_FCTL_TODS)
983 skb->pkt_type = PACKET_OTHERHOST;
1183 984
1184 /* Process the wireless stats if needed */ 985 /* Process the wireless stats if needed */
1185 orinoco_stat_gather(dev, skb, &desc); 986 orinoco_stat_gather(dev, skb, &desc);
@@ -1192,11 +993,10 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1192 return; 993 return;
1193 994
1194 drop: 995 drop:
996 dev_kfree_skb_irq(skb);
997 update_stats:
998 stats->rx_errors++;
1195 stats->rx_dropped++; 999 stats->rx_dropped++;
1196
1197 if (skb)
1198 dev_kfree_skb_irq(skb);
1199 return;
1200} 1000}
1201 1001
1202/********************************************************************/ 1002/********************************************************************/
@@ -1240,6 +1040,99 @@ static void print_linkstatus(struct net_device *dev, u16 status)
1240 dev->name, s, status); 1040 dev->name, s, status);
1241} 1041}
1242 1042
1043/* Search scan results for requested BSSID, join it if found */
1044static void orinoco_join_ap(struct net_device *dev)
1045{
1046 struct orinoco_private *priv = netdev_priv(dev);
1047 struct hermes *hw = &priv->hw;
1048 int err;
1049 unsigned long flags;
1050 struct join_req {
1051 u8 bssid[ETH_ALEN];
1052 u16 channel;
1053 } __attribute__ ((packed)) req;
1054 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1055 struct prism2_scan_apinfo *atom;
1056 int offset = 4;
1057 u8 *buf;
1058 u16 len;
1059
1060 /* Allocate buffer for scan results */
1061 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1062 if (! buf)
1063 return;
1064
1065 if (orinoco_lock(priv, &flags) != 0)
1066 goto out;
1067
1068 /* Sanity checks in case user changed something in the meantime */
1069 if (! priv->bssid_fixed)
1070 goto out;
1071
1072 if (strlen(priv->desired_essid) == 0)
1073 goto out;
1074
1075 /* Read scan results from the firmware */
1076 err = hermes_read_ltv(hw, USER_BAP,
1077 HERMES_RID_SCANRESULTSTABLE,
1078 MAX_SCAN_LEN, &len, buf);
1079 if (err) {
1080 printk(KERN_ERR "%s: Cannot read scan results\n",
1081 dev->name);
1082 goto out;
1083 }
1084
1085 len = HERMES_RECLEN_TO_BYTES(len);
1086
1087 /* Go through the scan results looking for the channel of the AP
1088 * we were requested to join */
1089 for (; offset + atom_len <= len; offset += atom_len) {
1090 atom = (struct prism2_scan_apinfo *) (buf + offset);
1091 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0)
1092 goto found;
1093 }
1094
1095 DEBUG(1, "%s: Requested AP not found in scan results\n",
1096 dev->name);
1097 goto out;
1098
1099 found:
1100 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1101 req.channel = atom->channel; /* both are little-endian */
1102 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1103 &req);
1104 if (err)
1105 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1106
1107 out:
1108 kfree(buf);
1109 orinoco_unlock(priv, &flags);
1110}
1111
1112/* Send new BSSID to userspace */
1113static void orinoco_send_wevents(struct net_device *dev)
1114{
1115 struct orinoco_private *priv = netdev_priv(dev);
1116 struct hermes *hw = &priv->hw;
1117 union iwreq_data wrqu;
1118 int err;
1119 unsigned long flags;
1120
1121 if (orinoco_lock(priv, &flags) != 0)
1122 return;
1123
1124 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1125 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1126 if (err != 0)
1127 return;
1128
1129 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1130
1131 /* Send event to user space */
1132 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1133 orinoco_unlock(priv, &flags);
1134}
1135
1243static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) 1136static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1244{ 1137{
1245 struct orinoco_private *priv = netdev_priv(dev); 1138 struct orinoco_private *priv = netdev_priv(dev);
@@ -1307,6 +1200,9 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1307 u16 newstatus; 1200 u16 newstatus;
1308 int connected; 1201 int connected;
1309 1202
1203 if (priv->iw_mode == IW_MODE_MONITOR)
1204 break;
1205
1310 if (len != sizeof(linkstatus)) { 1206 if (len != sizeof(linkstatus)) {
1311 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", 1207 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1312 dev->name, len); 1208 dev->name, len);
@@ -1319,6 +1215,15 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1319 break; 1215 break;
1320 newstatus = le16_to_cpu(linkstatus.linkstatus); 1216 newstatus = le16_to_cpu(linkstatus.linkstatus);
1321 1217
1218 /* Symbol firmware uses "out of range" to signal that
1219 * the hostscan frame can be requested. */
1220 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1221 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1222 priv->has_hostscan && priv->scan_inprogress) {
1223 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1224 break;
1225 }
1226
1322 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) 1227 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1323 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) 1228 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1324 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); 1229 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
@@ -1328,12 +1233,89 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1328 else if (!ignore_disconnect) 1233 else if (!ignore_disconnect)
1329 netif_carrier_off(dev); 1234 netif_carrier_off(dev);
1330 1235
1331 if (newstatus != priv->last_linkstatus) 1236 if (newstatus != priv->last_linkstatus) {
1237 priv->last_linkstatus = newstatus;
1332 print_linkstatus(dev, newstatus); 1238 print_linkstatus(dev, newstatus);
1239 /* The info frame contains only one word which is the
1240 * status (see hermes.h). The status is pretty boring
1241 * in itself, that's why we export the new BSSID...
1242 * Jean II */
1243 schedule_work(&priv->wevent_work);
1244 }
1245 }
1246 break;
1247 case HERMES_INQ_SCAN:
1248 if (!priv->scan_inprogress && priv->bssid_fixed &&
1249 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1250 schedule_work(&priv->join_work);
1251 break;
1252 }
1253 /* fall through */
1254 case HERMES_INQ_HOSTSCAN:
1255 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1256 /* Result of a scanning. Contains information about
1257 * cells in the vicinity - Jean II */
1258 union iwreq_data wrqu;
1259 unsigned char *buf;
1260
1261 /* Sanity check */
1262 if (len > 4096) {
1263 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1264 dev->name, len);
1265 break;
1266 }
1333 1267
1334 priv->last_linkstatus = newstatus; 1268 /* We are a strict producer. If the previous scan results
1269 * have not been consumed, we just have to drop this
1270 * frame. We can't remove the previous results ourselves,
1271 * that would be *very* racy... Jean II */
1272 if (priv->scan_result != NULL) {
1273 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1274 break;
1275 }
1276
1277 /* Allocate buffer for results */
1278 buf = kmalloc(len, GFP_ATOMIC);
1279 if (buf == NULL)
1280 /* No memory, so can't printk()... */
1281 break;
1282
1283 /* Read scan data */
1284 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1285 infofid, sizeof(info));
1286 if (err)
1287 break;
1288
1289#ifdef ORINOCO_DEBUG
1290 {
1291 int i;
1292 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1293 for(i = 1; i < (len * 2); i++)
1294 printk(":%02X", buf[i]);
1295 printk("]\n");
1296 }
1297#endif /* ORINOCO_DEBUG */
1298
1299 /* Allow the clients to access the results */
1300 priv->scan_len = len;
1301 priv->scan_result = buf;
1302
1303 /* Send an empty event to user space.
1304 * We don't send the received data on the event because
1305 * it would require us to do complex transcoding, and
1306 * we want to minimise the work done in the irq handler
1307 * Use a request to extract the data - Jean II */
1308 wrqu.data.length = 0;
1309 wrqu.data.flags = 0;
1310 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1335 } 1311 }
1336 break; 1312 break;
1313 case HERMES_INQ_SEC_STAT_AGERE:
1314 /* Security status (Agere specific) */
1315 /* Ignore this frame for now */
1316 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1317 break;
1318 /* fall through */
1337 default: 1319 default:
1338 printk(KERN_DEBUG "%s: Unknown information frame received: " 1320 printk(KERN_DEBUG "%s: Unknown information frame received: "
1339 "type 0x%04x, length %d\n", dev->name, type, len); 1321 "type 0x%04x, length %d\n", dev->name, type, len);
@@ -1470,6 +1452,36 @@ static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1470 return err; 1452 return err;
1471} 1453}
1472 1454
1455/* Set fixed AP address */
1456static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1457{
1458 int roaming_flag;
1459 int err = 0;
1460 hermes_t *hw = &priv->hw;
1461
1462 switch (priv->firmware_type) {
1463 case FIRMWARE_TYPE_AGERE:
1464 /* not supported */
1465 break;
1466 case FIRMWARE_TYPE_INTERSIL:
1467 if (priv->bssid_fixed)
1468 roaming_flag = 2;
1469 else
1470 roaming_flag = 1;
1471
1472 err = hermes_write_wordrec(hw, USER_BAP,
1473 HERMES_RID_CNFROAMINGMODE,
1474 roaming_flag);
1475 break;
1476 case FIRMWARE_TYPE_SYMBOL:
1477 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1478 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1479 &priv->desired_bssid);
1480 break;
1481 }
1482 return err;
1483}
1484
1473/* Change the WEP keys and/or the current keys. Can be called 1485/* Change the WEP keys and/or the current keys. Can be called
1474 * either from __orinoco_hw_setup_wep() or directly from 1486 * either from __orinoco_hw_setup_wep() or directly from
1475 * orinoco_ioctl_setiwencode(). In the later case the association 1487 * orinoco_ioctl_setiwencode(). In the later case the association
@@ -1655,6 +1667,13 @@ static int __orinoco_program_rids(struct net_device *dev)
1655 } 1667 }
1656 } 1668 }
1657 1669
1670 /* Set the desired BSSID */
1671 err = __orinoco_hw_set_wap(priv);
1672 if (err) {
1673 printk(KERN_ERR "%s: Error %d setting AP address\n",
1674 dev->name, err);
1675 return err;
1676 }
1658 /* Set the desired ESSID */ 1677 /* Set the desired ESSID */
1659 idbuf.len = cpu_to_le16(strlen(priv->desired_essid)); 1678 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1660 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val)); 1679 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
@@ -1793,6 +1812,20 @@ static int __orinoco_program_rids(struct net_device *dev)
1793 } 1812 }
1794 } 1813 }
1795 1814
1815 if (priv->iw_mode == IW_MODE_MONITOR) {
1816 /* Enable monitor mode */
1817 dev->type = ARPHRD_IEEE80211;
1818 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1819 HERMES_TEST_MONITOR, 0, NULL);
1820 } else {
1821 /* Disable monitor mode */
1822 dev->type = ARPHRD_ETHER;
1823 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1824 HERMES_TEST_STOP, 0, NULL);
1825 }
1826 if (err)
1827 return err;
1828
1796 /* Set promiscuity / multicast*/ 1829 /* Set promiscuity / multicast*/
1797 priv->promiscuous = 0; 1830 priv->promiscuous = 0;
1798 priv->mc_count = 0; 1831 priv->mc_count = 0;
@@ -1869,55 +1902,6 @@ __orinoco_set_multicast_list(struct net_device *dev)
1869 dev->flags &= ~IFF_PROMISC; 1902 dev->flags &= ~IFF_PROMISC;
1870} 1903}
1871 1904
1872static int orinoco_reconfigure(struct net_device *dev)
1873{
1874 struct orinoco_private *priv = netdev_priv(dev);
1875 struct hermes *hw = &priv->hw;
1876 unsigned long flags;
1877 int err = 0;
1878
1879 if (priv->broken_disableport) {
1880 schedule_work(&priv->reset_work);
1881 return 0;
1882 }
1883
1884 if (orinoco_lock(priv, &flags) != 0)
1885 return -EBUSY;
1886
1887 err = hermes_disable_port(hw, 0);
1888 if (err) {
1889 printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
1890 dev->name);
1891 priv->broken_disableport = 1;
1892 goto out;
1893 }
1894
1895 err = __orinoco_program_rids(dev);
1896 if (err) {
1897 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1898 dev->name);
1899 goto out;
1900 }
1901
1902 err = hermes_enable_port(hw, 0);
1903 if (err) {
1904 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1905 dev->name);
1906 goto out;
1907 }
1908
1909 out:
1910 if (err) {
1911 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1912 schedule_work(&priv->reset_work);
1913 err = 0;
1914 }
1915
1916 orinoco_unlock(priv, &flags);
1917 return err;
1918
1919}
1920
1921/* This must be called from user context, without locks held - use 1905/* This must be called from user context, without locks held - use
1922 * schedule_work() */ 1906 * schedule_work() */
1923static void orinoco_reset(struct net_device *dev) 1907static void orinoco_reset(struct net_device *dev)
@@ -1946,6 +1930,11 @@ static void orinoco_reset(struct net_device *dev)
1946 1930
1947 orinoco_unlock(priv, &flags); 1931 orinoco_unlock(priv, &flags);
1948 1932
1933 /* Scanning support: Cleanup of driver struct */
1934 kfree(priv->scan_result);
1935 priv->scan_result = NULL;
1936 priv->scan_inprogress = 0;
1937
1949 if (priv->hard_reset) { 1938 if (priv->hard_reset) {
1950 err = (*priv->hard_reset)(priv); 1939 err = (*priv->hard_reset)(priv);
1951 if (err) { 1940 if (err) {
@@ -2184,6 +2173,8 @@ static int determine_firmware(struct net_device *dev)
2184 priv->has_mwo = (firmver >= 0x60000); 2173 priv->has_mwo = (firmver >= 0x60000);
2185 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */ 2174 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2186 priv->ibss_port = 1; 2175 priv->ibss_port = 1;
2176 priv->has_hostscan = (firmver >= 0x8000a);
2177 priv->broken_monitor = (firmver >= 0x80000);
2187 2178
2188 /* Tested with Agere firmware : 2179 /* Tested with Agere firmware :
2189 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II 2180 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
@@ -2229,6 +2220,8 @@ static int determine_firmware(struct net_device *dev)
2229 priv->ibss_port = 4; 2220 priv->ibss_port = 4;
2230 priv->broken_disableport = (firmver == 0x25013) || 2221 priv->broken_disableport = (firmver == 0x25013) ||
2231 (firmver >= 0x30000 && firmver <= 0x31000); 2222 (firmver >= 0x30000 && firmver <= 0x31000);
2223 priv->has_hostscan = (firmver >= 0x31001) ||
2224 (firmver >= 0x29057 && firmver < 0x30000);
2232 /* Tested with Intel firmware : 0x20015 => Jean II */ 2225 /* Tested with Intel firmware : 0x20015 => Jean II */
2233 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */ 2226 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2234 break; 2227 break;
@@ -2248,6 +2241,7 @@ static int determine_firmware(struct net_device *dev)
2248 priv->has_ibss = (firmver >= 0x000700); /* FIXME */ 2241 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2249 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800); 2242 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2250 priv->has_pm = (firmver >= 0x000700); 2243 priv->has_pm = (firmver >= 0x000700);
2244 priv->has_hostscan = (firmver >= 0x010301);
2251 2245
2252 if (firmver >= 0x000800) 2246 if (firmver >= 0x000800)
2253 priv->ibss_port = 0; 2247 priv->ibss_port = 0;
@@ -2456,8 +2450,9 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2456 dev->tx_timeout = orinoco_tx_timeout; 2450 dev->tx_timeout = orinoco_tx_timeout;
2457 dev->watchdog_timeo = HZ; /* 1 second timeout */ 2451 dev->watchdog_timeo = HZ; /* 1 second timeout */
2458 dev->get_stats = orinoco_get_stats; 2452 dev->get_stats = orinoco_get_stats;
2453 dev->ethtool_ops = &orinoco_ethtool_ops;
2459 dev->get_wireless_stats = orinoco_get_wireless_stats; 2454 dev->get_wireless_stats = orinoco_get_wireless_stats;
2460 dev->do_ioctl = orinoco_ioctl; 2455 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2461 dev->change_mtu = orinoco_change_mtu; 2456 dev->change_mtu = orinoco_change_mtu;
2462 dev->set_multicast_list = orinoco_set_multicast_list; 2457 dev->set_multicast_list = orinoco_set_multicast_list;
2463 /* we use the default eth_mac_addr for setting the MAC addr */ 2458 /* we use the default eth_mac_addr for setting the MAC addr */
@@ -2473,6 +2468,8 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2473 * before anything else touches the 2468 * before anything else touches the
2474 * hardware */ 2469 * hardware */
2475 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev); 2470 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2471 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2472 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2476 2473
2477 netif_carrier_off(dev); 2474 netif_carrier_off(dev);
2478 priv->last_linkstatus = 0xffff; 2475 priv->last_linkstatus = 0xffff;
@@ -2483,6 +2480,9 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2483 2480
2484void free_orinocodev(struct net_device *dev) 2481void free_orinocodev(struct net_device *dev)
2485{ 2482{
2483 struct orinoco_private *priv = netdev_priv(dev);
2484
2485 kfree(priv->scan_result);
2486 free_netdev(dev); 2486 free_netdev(dev);
2487} 2487}
2488 2488
@@ -2490,24 +2490,6 @@ void free_orinocodev(struct net_device *dev)
2490/* Wireless extensions */ 2490/* Wireless extensions */
2491/********************************************************************/ 2491/********************************************************************/
2492 2492
2493static int orinoco_hw_get_bssid(struct orinoco_private *priv,
2494 char buf[ETH_ALEN])
2495{
2496 hermes_t *hw = &priv->hw;
2497 int err = 0;
2498 unsigned long flags;
2499
2500 if (orinoco_lock(priv, &flags) != 0)
2501 return -EBUSY;
2502
2503 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2504 ETH_ALEN, NULL, buf);
2505
2506 orinoco_unlock(priv, &flags);
2507
2508 return err;
2509}
2510
2511static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active, 2493static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2512 char buf[IW_ESSID_MAX_SIZE+1]) 2494 char buf[IW_ESSID_MAX_SIZE+1])
2513{ 2495{
@@ -2633,140 +2615,271 @@ static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2633 return 0; 2615 return 0;
2634} 2616}
2635 2617
2636static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq) 2618static int orinoco_ioctl_getname(struct net_device *dev,
2619 struct iw_request_info *info,
2620 char *name,
2621 char *extra)
2637{ 2622{
2638 struct orinoco_private *priv = netdev_priv(dev); 2623 struct orinoco_private *priv = netdev_priv(dev);
2639 int err = 0;
2640 int mode;
2641 struct iw_range range;
2642 int numrates; 2624 int numrates;
2643 int i, k; 2625 int err;
2626
2627 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2628
2629 if (!err && (numrates > 2))
2630 strcpy(name, "IEEE 802.11b");
2631 else
2632 strcpy(name, "IEEE 802.11-DS");
2633
2634 return 0;
2635}
2636
2637static int orinoco_ioctl_setwap(struct net_device *dev,
2638 struct iw_request_info *info,
2639 struct sockaddr *ap_addr,
2640 char *extra)
2641{
2642 struct orinoco_private *priv = netdev_priv(dev);
2643 int err = -EINPROGRESS; /* Call commit handler */
2644 unsigned long flags; 2644 unsigned long flags;
2645 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2646 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2645 2647
2646 TRACE_ENTER(dev->name); 2648 if (orinoco_lock(priv, &flags) != 0)
2649 return -EBUSY;
2650
2651 /* Enable automatic roaming - no sanity checks are needed */
2652 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2653 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2654 priv->bssid_fixed = 0;
2655 memset(priv->desired_bssid, 0, ETH_ALEN);
2656
2657 /* "off" means keep existing connection */
2658 if (ap_addr->sa_data[0] == 0) {
2659 __orinoco_hw_set_wap(priv);
2660 err = 0;
2661 }
2662 goto out;
2663 }
2664
2665 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2666 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2667 "support manual roaming\n",
2668 dev->name);
2669 err = -EOPNOTSUPP;
2670 goto out;
2671 }
2672
2673 if (priv->iw_mode != IW_MODE_INFRA) {
2674 printk(KERN_WARNING "%s: Manual roaming supported only in "
2675 "managed mode\n", dev->name);
2676 err = -EOPNOTSUPP;
2677 goto out;
2678 }
2679
2680 /* Intersil firmware hangs without Desired ESSID */
2681 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2682 strlen(priv->desired_essid) == 0) {
2683 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2684 "manual roaming\n", dev->name);
2685 err = -EOPNOTSUPP;
2686 goto out;
2687 }
2688
2689 /* Finally, enable manual roaming */
2690 priv->bssid_fixed = 1;
2691 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2692
2693 out:
2694 orinoco_unlock(priv, &flags);
2695 return err;
2696}
2697
2698static int orinoco_ioctl_getwap(struct net_device *dev,
2699 struct iw_request_info *info,
2700 struct sockaddr *ap_addr,
2701 char *extra)
2702{
2703 struct orinoco_private *priv = netdev_priv(dev);
2704
2705 hermes_t *hw = &priv->hw;
2706 int err = 0;
2707 unsigned long flags;
2708
2709 if (orinoco_lock(priv, &flags) != 0)
2710 return -EBUSY;
2711
2712 ap_addr->sa_family = ARPHRD_ETHER;
2713 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2714 ETH_ALEN, NULL, ap_addr->sa_data);
2715
2716 orinoco_unlock(priv, &flags);
2717
2718 return err;
2719}
2647 2720
2648 if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range))) 2721static int orinoco_ioctl_setmode(struct net_device *dev,
2649 return -EFAULT; 2722 struct iw_request_info *info,
2723 u32 *mode,
2724 char *extra)
2725{
2726 struct orinoco_private *priv = netdev_priv(dev);
2727 int err = -EINPROGRESS; /* Call commit handler */
2728 unsigned long flags;
2650 2729
2651 rrq->length = sizeof(range); 2730 if (priv->iw_mode == *mode)
2731 return 0;
2652 2732
2653 if (orinoco_lock(priv, &flags) != 0) 2733 if (orinoco_lock(priv, &flags) != 0)
2654 return -EBUSY; 2734 return -EBUSY;
2655 2735
2656 mode = priv->iw_mode; 2736 switch (*mode) {
2737 case IW_MODE_ADHOC:
2738 if (!priv->has_ibss && !priv->has_port3)
2739 err = -EOPNOTSUPP;
2740 break;
2741
2742 case IW_MODE_INFRA:
2743 break;
2744
2745 case IW_MODE_MONITOR:
2746 if (priv->broken_monitor && !force_monitor) {
2747 printk(KERN_WARNING "%s: Monitor mode support is "
2748 "buggy in this firmware, not enabling\n",
2749 dev->name);
2750 err = -EOPNOTSUPP;
2751 }
2752 break;
2753
2754 default:
2755 err = -EOPNOTSUPP;
2756 break;
2757 }
2758
2759 if (err == -EINPROGRESS) {
2760 priv->iw_mode = *mode;
2761 set_port_type(priv);
2762 }
2763
2657 orinoco_unlock(priv, &flags); 2764 orinoco_unlock(priv, &flags);
2658 2765
2659 memset(&range, 0, sizeof(range)); 2766 return err;
2767}
2768
2769static int orinoco_ioctl_getmode(struct net_device *dev,
2770 struct iw_request_info *info,
2771 u32 *mode,
2772 char *extra)
2773{
2774 struct orinoco_private *priv = netdev_priv(dev);
2775
2776 *mode = priv->iw_mode;
2777 return 0;
2778}
2779
2780static int orinoco_ioctl_getiwrange(struct net_device *dev,
2781 struct iw_request_info *info,
2782 struct iw_point *rrq,
2783 char *extra)
2784{
2785 struct orinoco_private *priv = netdev_priv(dev);
2786 int err = 0;
2787 struct iw_range *range = (struct iw_range *) extra;
2788 int numrates;
2789 int i, k;
2790
2791 TRACE_ENTER(dev->name);
2660 2792
2661 /* Much of this shamelessly taken from wvlan_cs.c. No idea 2793 rrq->length = sizeof(struct iw_range);
2662 * what it all means -dgibson */ 2794 memset(range, 0, sizeof(struct iw_range));
2663 range.we_version_compiled = WIRELESS_EXT;
2664 range.we_version_source = 11;
2665 2795
2666 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */ 2796 range->we_version_compiled = WIRELESS_EXT;
2797 range->we_version_source = 14;
2667 2798
2668 /* Set available channels/frequencies */ 2799 /* Set available channels/frequencies */
2669 range.num_channels = NUM_CHANNELS; 2800 range->num_channels = NUM_CHANNELS;
2670 k = 0; 2801 k = 0;
2671 for (i = 0; i < NUM_CHANNELS; i++) { 2802 for (i = 0; i < NUM_CHANNELS; i++) {
2672 if (priv->channel_mask & (1 << i)) { 2803 if (priv->channel_mask & (1 << i)) {
2673 range.freq[k].i = i + 1; 2804 range->freq[k].i = i + 1;
2674 range.freq[k].m = channel_frequency[i] * 100000; 2805 range->freq[k].m = channel_frequency[i] * 100000;
2675 range.freq[k].e = 1; 2806 range->freq[k].e = 1;
2676 k++; 2807 k++;
2677 } 2808 }
2678 2809
2679 if (k >= IW_MAX_FREQUENCIES) 2810 if (k >= IW_MAX_FREQUENCIES)
2680 break; 2811 break;
2681 } 2812 }
2682 range.num_frequency = k; 2813 range->num_frequency = k;
2814 range->sensitivity = 3;
2683 2815
2684 range.sensitivity = 3; 2816 if (priv->has_wep) {
2817 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2818 range->encoding_size[0] = SMALL_KEY_SIZE;
2819 range->num_encoding_sizes = 1;
2685 2820
2686 if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){ 2821 if (priv->has_big_wep) {
2822 range->encoding_size[1] = LARGE_KEY_SIZE;
2823 range->num_encoding_sizes = 2;
2824 }
2825 }
2826
2827 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2687 /* Quality stats meaningless in ad-hoc mode */ 2828 /* Quality stats meaningless in ad-hoc mode */
2688 range.max_qual.qual = 0;
2689 range.max_qual.level = 0;
2690 range.max_qual.noise = 0;
2691 range.avg_qual.qual = 0;
2692 range.avg_qual.level = 0;
2693 range.avg_qual.noise = 0;
2694 } else { 2829 } else {
2695 range.max_qual.qual = 0x8b - 0x2f; 2830 range->max_qual.qual = 0x8b - 0x2f;
2696 range.max_qual.level = 0x2f - 0x95 - 1; 2831 range->max_qual.level = 0x2f - 0x95 - 1;
2697 range.max_qual.noise = 0x2f - 0x95 - 1; 2832 range->max_qual.noise = 0x2f - 0x95 - 1;
2698 /* Need to get better values */ 2833 /* Need to get better values */
2699 range.avg_qual.qual = 0x24; 2834 range->avg_qual.qual = 0x24;
2700 range.avg_qual.level = 0xC2; 2835 range->avg_qual.level = 0xC2;
2701 range.avg_qual.noise = 0x9E; 2836 range->avg_qual.noise = 0x9E;
2702 } 2837 }
2703 2838
2704 err = orinoco_hw_get_bitratelist(priv, &numrates, 2839 err = orinoco_hw_get_bitratelist(priv, &numrates,
2705 range.bitrate, IW_MAX_BITRATES); 2840 range->bitrate, IW_MAX_BITRATES);
2706 if (err) 2841 if (err)
2707 return err; 2842 return err;
2708 range.num_bitrates = numrates; 2843 range->num_bitrates = numrates;
2709 2844
2710 /* Set an indication of the max TCP throughput in bit/s that we can 2845 /* Set an indication of the max TCP throughput in bit/s that we can
2711 * expect using this interface. May be use for QoS stuff... 2846 * expect using this interface. May be use for QoS stuff...
2712 * Jean II */ 2847 * Jean II */
2713 if(numrates > 2) 2848 if (numrates > 2)
2714 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */ 2849 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2715 else 2850 else
2716 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */ 2851 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2717 2852
2718 range.min_rts = 0; 2853 range->min_rts = 0;
2719 range.max_rts = 2347; 2854 range->max_rts = 2347;
2720 range.min_frag = 256; 2855 range->min_frag = 256;
2721 range.max_frag = 2346; 2856 range->max_frag = 2346;
2722 2857
2723 if (orinoco_lock(priv, &flags) != 0) 2858 range->min_pmp = 0;
2724 return -EBUSY; 2859 range->max_pmp = 65535000;
2725 if (priv->has_wep) { 2860 range->min_pmt = 0;
2726 range.max_encoding_tokens = ORINOCO_MAX_KEYS; 2861 range->max_pmt = 65535 * 1000; /* ??? */
2727 2862 range->pmp_flags = IW_POWER_PERIOD;
2728 range.encoding_size[0] = SMALL_KEY_SIZE; 2863 range->pmt_flags = IW_POWER_TIMEOUT;
2729 range.num_encoding_sizes = 1; 2864 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2730 2865
2731 if (priv->has_big_wep) { 2866 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2732 range.encoding_size[1] = LARGE_KEY_SIZE; 2867 range->retry_flags = IW_RETRY_LIMIT;
2733 range.num_encoding_sizes = 2; 2868 range->r_time_flags = IW_RETRY_LIFETIME;
2734 } 2869 range->min_retry = 0;
2735 } else { 2870 range->max_retry = 65535; /* ??? */
2736 range.num_encoding_sizes = 0; 2871 range->min_r_time = 0;
2737 range.max_encoding_tokens = 0; 2872 range->max_r_time = 65535 * 1000; /* ??? */
2738 }
2739 orinoco_unlock(priv, &flags);
2740
2741 range.min_pmp = 0;
2742 range.max_pmp = 65535000;
2743 range.min_pmt = 0;
2744 range.max_pmt = 65535 * 1000; /* ??? */
2745 range.pmp_flags = IW_POWER_PERIOD;
2746 range.pmt_flags = IW_POWER_TIMEOUT;
2747 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2748
2749 range.num_txpower = 1;
2750 range.txpower[0] = 15; /* 15dBm */
2751 range.txpower_capa = IW_TXPOW_DBM;
2752
2753 range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2754 range.retry_flags = IW_RETRY_LIMIT;
2755 range.r_time_flags = IW_RETRY_LIFETIME;
2756 range.min_retry = 0;
2757 range.max_retry = 65535; /* ??? */
2758 range.min_r_time = 0;
2759 range.max_r_time = 65535 * 1000; /* ??? */
2760
2761 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
2762 return -EFAULT;
2763 2873
2764 TRACE_EXIT(dev->name); 2874 TRACE_EXIT(dev->name);
2765 2875
2766 return 0; 2876 return 0;
2767} 2877}
2768 2878
2769static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq) 2879static int orinoco_ioctl_setiwencode(struct net_device *dev,
2880 struct iw_request_info *info,
2881 struct iw_point *erq,
2882 char *keybuf)
2770{ 2883{
2771 struct orinoco_private *priv = netdev_priv(dev); 2884 struct orinoco_private *priv = netdev_priv(dev);
2772 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 2885 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
@@ -2774,8 +2887,7 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2774 int enable = priv->wep_on; 2887 int enable = priv->wep_on;
2775 int restricted = priv->wep_restrict; 2888 int restricted = priv->wep_restrict;
2776 u16 xlen = 0; 2889 u16 xlen = 0;
2777 int err = 0; 2890 int err = -EINPROGRESS; /* Call commit handler */
2778 char keybuf[ORINOCO_MAX_KEY_SIZE];
2779 unsigned long flags; 2891 unsigned long flags;
2780 2892
2781 if (! priv->has_wep) 2893 if (! priv->has_wep)
@@ -2788,9 +2900,6 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2788 2900
2789 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep ) 2901 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2790 return -E2BIG; 2902 return -E2BIG;
2791
2792 if (copy_from_user(keybuf, erq->pointer, erq->length))
2793 return -EFAULT;
2794 } 2903 }
2795 2904
2796 if (orinoco_lock(priv, &flags) != 0) 2905 if (orinoco_lock(priv, &flags) != 0)
@@ -2864,12 +2973,14 @@ static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *er
2864 return err; 2973 return err;
2865} 2974}
2866 2975
2867static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq) 2976static int orinoco_ioctl_getiwencode(struct net_device *dev,
2977 struct iw_request_info *info,
2978 struct iw_point *erq,
2979 char *keybuf)
2868{ 2980{
2869 struct orinoco_private *priv = netdev_priv(dev); 2981 struct orinoco_private *priv = netdev_priv(dev);
2870 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 2982 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2871 u16 xlen = 0; 2983 u16 xlen = 0;
2872 char keybuf[ORINOCO_MAX_KEY_SIZE];
2873 unsigned long flags; 2984 unsigned long flags;
2874 2985
2875 if (! priv->has_wep) 2986 if (! priv->has_wep)
@@ -2898,51 +3009,47 @@ static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *er
2898 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE); 3009 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2899 3010
2900 orinoco_unlock(priv, &flags); 3011 orinoco_unlock(priv, &flags);
2901
2902 if (erq->pointer) {
2903 if (copy_to_user(erq->pointer, keybuf, xlen))
2904 return -EFAULT;
2905 }
2906
2907 return 0; 3012 return 0;
2908} 3013}
2909 3014
2910static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq) 3015static int orinoco_ioctl_setessid(struct net_device *dev,
3016 struct iw_request_info *info,
3017 struct iw_point *erq,
3018 char *essidbuf)
2911{ 3019{
2912 struct orinoco_private *priv = netdev_priv(dev); 3020 struct orinoco_private *priv = netdev_priv(dev);
2913 char essidbuf[IW_ESSID_MAX_SIZE+1];
2914 unsigned long flags; 3021 unsigned long flags;
2915 3022
2916 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it 3023 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2917 * anyway... - Jean II */ 3024 * anyway... - Jean II */
2918 3025
2919 memset(&essidbuf, 0, sizeof(essidbuf)); 3026 /* Hum... Should not use Wireless Extension constant (may change),
2920 3027 * should use our own... - Jean II */
2921 if (erq->flags) { 3028 if (erq->length > IW_ESSID_MAX_SIZE)
2922 /* iwconfig includes the NUL in the specified length */ 3029 return -E2BIG;
2923 if (erq->length > IW_ESSID_MAX_SIZE+1)
2924 return -E2BIG;
2925
2926 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2927 return -EFAULT;
2928
2929 essidbuf[IW_ESSID_MAX_SIZE] = '\0';
2930 }
2931 3030
2932 if (orinoco_lock(priv, &flags) != 0) 3031 if (orinoco_lock(priv, &flags) != 0)
2933 return -EBUSY; 3032 return -EBUSY;
2934 3033
2935 memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid)); 3034 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3035 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3036
3037 /* If not ANY, get the new ESSID */
3038 if (erq->flags) {
3039 memcpy(priv->desired_essid, essidbuf, erq->length);
3040 }
2936 3041
2937 orinoco_unlock(priv, &flags); 3042 orinoco_unlock(priv, &flags);
2938 3043
2939 return 0; 3044 return -EINPROGRESS; /* Call commit handler */
2940} 3045}
2941 3046
2942static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq) 3047static int orinoco_ioctl_getessid(struct net_device *dev,
3048 struct iw_request_info *info,
3049 struct iw_point *erq,
3050 char *essidbuf)
2943{ 3051{
2944 struct orinoco_private *priv = netdev_priv(dev); 3052 struct orinoco_private *priv = netdev_priv(dev);
2945 char essidbuf[IW_ESSID_MAX_SIZE+1];
2946 int active; 3053 int active;
2947 int err = 0; 3054 int err = 0;
2948 unsigned long flags; 3055 unsigned long flags;
@@ -2956,51 +3063,46 @@ static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2956 } else { 3063 } else {
2957 if (orinoco_lock(priv, &flags) != 0) 3064 if (orinoco_lock(priv, &flags) != 0)
2958 return -EBUSY; 3065 return -EBUSY;
2959 memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf)); 3066 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
2960 orinoco_unlock(priv, &flags); 3067 orinoco_unlock(priv, &flags);
2961 } 3068 }
2962 3069
2963 erq->flags = 1; 3070 erq->flags = 1;
2964 erq->length = strlen(essidbuf) + 1; 3071 erq->length = strlen(essidbuf) + 1;
2965 if (erq->pointer)
2966 if (copy_to_user(erq->pointer, essidbuf, erq->length))
2967 return -EFAULT;
2968 3072
2969 TRACE_EXIT(dev->name); 3073 TRACE_EXIT(dev->name);
2970 3074
2971 return 0; 3075 return 0;
2972} 3076}
2973 3077
2974static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq) 3078static int orinoco_ioctl_setnick(struct net_device *dev,
3079 struct iw_request_info *info,
3080 struct iw_point *nrq,
3081 char *nickbuf)
2975{ 3082{
2976 struct orinoco_private *priv = netdev_priv(dev); 3083 struct orinoco_private *priv = netdev_priv(dev);
2977 char nickbuf[IW_ESSID_MAX_SIZE+1];
2978 unsigned long flags; 3084 unsigned long flags;
2979 3085
2980 if (nrq->length > IW_ESSID_MAX_SIZE) 3086 if (nrq->length > IW_ESSID_MAX_SIZE)
2981 return -E2BIG; 3087 return -E2BIG;
2982 3088
2983 memset(nickbuf, 0, sizeof(nickbuf));
2984
2985 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2986 return -EFAULT;
2987
2988 nickbuf[nrq->length] = '\0';
2989
2990 if (orinoco_lock(priv, &flags) != 0) 3089 if (orinoco_lock(priv, &flags) != 0)
2991 return -EBUSY; 3090 return -EBUSY;
2992 3091
2993 memcpy(priv->nick, nickbuf, sizeof(priv->nick)); 3092 memset(priv->nick, 0, sizeof(priv->nick));
3093 memcpy(priv->nick, nickbuf, nrq->length);
2994 3094
2995 orinoco_unlock(priv, &flags); 3095 orinoco_unlock(priv, &flags);
2996 3096
2997 return 0; 3097 return -EINPROGRESS; /* Call commit handler */
2998} 3098}
2999 3099
3000static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq) 3100static int orinoco_ioctl_getnick(struct net_device *dev,
3101 struct iw_request_info *info,
3102 struct iw_point *nrq,
3103 char *nickbuf)
3001{ 3104{
3002 struct orinoco_private *priv = netdev_priv(dev); 3105 struct orinoco_private *priv = netdev_priv(dev);
3003 char nickbuf[IW_ESSID_MAX_SIZE+1];
3004 unsigned long flags; 3106 unsigned long flags;
3005 3107
3006 if (orinoco_lock(priv, &flags) != 0) 3108 if (orinoco_lock(priv, &flags) != 0)
@@ -3011,23 +3113,22 @@ static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
3011 3113
3012 nrq->length = strlen(nickbuf)+1; 3114 nrq->length = strlen(nickbuf)+1;
3013 3115
3014 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
3015 return -EFAULT;
3016
3017 return 0; 3116 return 0;
3018} 3117}
3019 3118
3020static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq) 3119static int orinoco_ioctl_setfreq(struct net_device *dev,
3120 struct iw_request_info *info,
3121 struct iw_freq *frq,
3122 char *extra)
3021{ 3123{
3022 struct orinoco_private *priv = netdev_priv(dev); 3124 struct orinoco_private *priv = netdev_priv(dev);
3023 int chan = -1; 3125 int chan = -1;
3024 unsigned long flags; 3126 unsigned long flags;
3127 int err = -EINPROGRESS; /* Call commit handler */
3025 3128
3026 /* We can only use this in Ad-Hoc demo mode to set the operating 3129 /* In infrastructure mode the AP sets the channel */
3027 * frequency, or in IBSS mode to set the frequency where the IBSS 3130 if (priv->iw_mode == IW_MODE_INFRA)
3028 * will be created - Jean II */ 3131 return -EBUSY;
3029 if (priv->iw_mode != IW_MODE_ADHOC)
3030 return -EOPNOTSUPP;
3031 3132
3032 if ( (frq->e == 0) && (frq->m <= 1000) ) { 3133 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3033 /* Setting by channel number */ 3134 /* Setting by channel number */
@@ -3051,13 +3152,44 @@ static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
3051 3152
3052 if (orinoco_lock(priv, &flags) != 0) 3153 if (orinoco_lock(priv, &flags) != 0)
3053 return -EBUSY; 3154 return -EBUSY;
3155
3054 priv->channel = chan; 3156 priv->channel = chan;
3157 if (priv->iw_mode == IW_MODE_MONITOR) {
3158 /* Fast channel change - no commit if successful */
3159 hermes_t *hw = &priv->hw;
3160 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3161 HERMES_TEST_SET_CHANNEL,
3162 chan, NULL);
3163 }
3055 orinoco_unlock(priv, &flags); 3164 orinoco_unlock(priv, &flags);
3056 3165
3166 return err;
3167}
3168
3169static int orinoco_ioctl_getfreq(struct net_device *dev,
3170 struct iw_request_info *info,
3171 struct iw_freq *frq,
3172 char *extra)
3173{
3174 struct orinoco_private *priv = netdev_priv(dev);
3175 int tmp;
3176
3177 /* Locking done in there */
3178 tmp = orinoco_hw_get_freq(priv);
3179 if (tmp < 0) {
3180 return tmp;
3181 }
3182
3183 frq->m = tmp;
3184 frq->e = 1;
3185
3057 return 0; 3186 return 0;
3058} 3187}
3059 3188
3060static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq) 3189static int orinoco_ioctl_getsens(struct net_device *dev,
3190 struct iw_request_info *info,
3191 struct iw_param *srq,
3192 char *extra)
3061{ 3193{
3062 struct orinoco_private *priv = netdev_priv(dev); 3194 struct orinoco_private *priv = netdev_priv(dev);
3063 hermes_t *hw = &priv->hw; 3195 hermes_t *hw = &priv->hw;
@@ -3083,7 +3215,10 @@ static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
3083 return 0; 3215 return 0;
3084} 3216}
3085 3217
3086static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq) 3218static int orinoco_ioctl_setsens(struct net_device *dev,
3219 struct iw_request_info *info,
3220 struct iw_param *srq,
3221 char *extra)
3087{ 3222{
3088 struct orinoco_private *priv = netdev_priv(dev); 3223 struct orinoco_private *priv = netdev_priv(dev);
3089 int val = srq->value; 3224 int val = srq->value;
@@ -3100,10 +3235,13 @@ static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
3100 priv->ap_density = val; 3235 priv->ap_density = val;
3101 orinoco_unlock(priv, &flags); 3236 orinoco_unlock(priv, &flags);
3102 3237
3103 return 0; 3238 return -EINPROGRESS; /* Call commit handler */
3104} 3239}
3105 3240
3106static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq) 3241static int orinoco_ioctl_setrts(struct net_device *dev,
3242 struct iw_request_info *info,
3243 struct iw_param *rrq,
3244 char *extra)
3107{ 3245{
3108 struct orinoco_private *priv = netdev_priv(dev); 3246 struct orinoco_private *priv = netdev_priv(dev);
3109 int val = rrq->value; 3247 int val = rrq->value;
@@ -3121,13 +3259,30 @@ static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
3121 priv->rts_thresh = val; 3259 priv->rts_thresh = val;
3122 orinoco_unlock(priv, &flags); 3260 orinoco_unlock(priv, &flags);
3123 3261
3262 return -EINPROGRESS; /* Call commit handler */
3263}
3264
3265static int orinoco_ioctl_getrts(struct net_device *dev,
3266 struct iw_request_info *info,
3267 struct iw_param *rrq,
3268 char *extra)
3269{
3270 struct orinoco_private *priv = netdev_priv(dev);
3271
3272 rrq->value = priv->rts_thresh;
3273 rrq->disabled = (rrq->value == 2347);
3274 rrq->fixed = 1;
3275
3124 return 0; 3276 return 0;
3125} 3277}
3126 3278
3127static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq) 3279static int orinoco_ioctl_setfrag(struct net_device *dev,
3280 struct iw_request_info *info,
3281 struct iw_param *frq,
3282 char *extra)
3128{ 3283{
3129 struct orinoco_private *priv = netdev_priv(dev); 3284 struct orinoco_private *priv = netdev_priv(dev);
3130 int err = 0; 3285 int err = -EINPROGRESS; /* Call commit handler */
3131 unsigned long flags; 3286 unsigned long flags;
3132 3287
3133 if (orinoco_lock(priv, &flags) != 0) 3288 if (orinoco_lock(priv, &flags) != 0)
@@ -3159,11 +3314,14 @@ static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
3159 return err; 3314 return err;
3160} 3315}
3161 3316
3162static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq) 3317static int orinoco_ioctl_getfrag(struct net_device *dev,
3318 struct iw_request_info *info,
3319 struct iw_param *frq,
3320 char *extra)
3163{ 3321{
3164 struct orinoco_private *priv = netdev_priv(dev); 3322 struct orinoco_private *priv = netdev_priv(dev);
3165 hermes_t *hw = &priv->hw; 3323 hermes_t *hw = &priv->hw;
3166 int err = 0; 3324 int err;
3167 u16 val; 3325 u16 val;
3168 unsigned long flags; 3326 unsigned long flags;
3169 3327
@@ -3196,10 +3354,12 @@ static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
3196 return err; 3354 return err;
3197} 3355}
3198 3356
3199static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq) 3357static int orinoco_ioctl_setrate(struct net_device *dev,
3358 struct iw_request_info *info,
3359 struct iw_param *rrq,
3360 char *extra)
3200{ 3361{
3201 struct orinoco_private *priv = netdev_priv(dev); 3362 struct orinoco_private *priv = netdev_priv(dev);
3202 int err = 0;
3203 int ratemode = -1; 3363 int ratemode = -1;
3204 int bitrate; /* 100s of kilobits */ 3364 int bitrate; /* 100s of kilobits */
3205 int i; 3365 int i;
@@ -3235,10 +3395,13 @@ static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
3235 priv->bitratemode = ratemode; 3395 priv->bitratemode = ratemode;
3236 orinoco_unlock(priv, &flags); 3396 orinoco_unlock(priv, &flags);
3237 3397
3238 return err; 3398 return -EINPROGRESS;
3239} 3399}
3240 3400
3241static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq) 3401static int orinoco_ioctl_getrate(struct net_device *dev,
3402 struct iw_request_info *info,
3403 struct iw_param *rrq,
3404 char *extra)
3242{ 3405{
3243 struct orinoco_private *priv = netdev_priv(dev); 3406 struct orinoco_private *priv = netdev_priv(dev);
3244 hermes_t *hw = &priv->hw; 3407 hermes_t *hw = &priv->hw;
@@ -3303,10 +3466,13 @@ static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
3303 return err; 3466 return err;
3304} 3467}
3305 3468
3306static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq) 3469static int orinoco_ioctl_setpower(struct net_device *dev,
3470 struct iw_request_info *info,
3471 struct iw_param *prq,
3472 char *extra)
3307{ 3473{
3308 struct orinoco_private *priv = netdev_priv(dev); 3474 struct orinoco_private *priv = netdev_priv(dev);
3309 int err = 0; 3475 int err = -EINPROGRESS; /* Call commit handler */
3310 unsigned long flags; 3476 unsigned long flags;
3311 3477
3312 if (orinoco_lock(priv, &flags) != 0) 3478 if (orinoco_lock(priv, &flags) != 0)
@@ -3355,7 +3521,10 @@ static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
3355 return err; 3521 return err;
3356} 3522}
3357 3523
3358static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq) 3524static int orinoco_ioctl_getpower(struct net_device *dev,
3525 struct iw_request_info *info,
3526 struct iw_param *prq,
3527 char *extra)
3359{ 3528{
3360 struct orinoco_private *priv = netdev_priv(dev); 3529 struct orinoco_private *priv = netdev_priv(dev);
3361 hermes_t *hw = &priv->hw; 3530 hermes_t *hw = &priv->hw;
@@ -3403,7 +3572,10 @@ static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
3403 return err; 3572 return err;
3404} 3573}
3405 3574
3406static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq) 3575static int orinoco_ioctl_getretry(struct net_device *dev,
3576 struct iw_request_info *info,
3577 struct iw_param *rrq,
3578 char *extra)
3407{ 3579{
3408 struct orinoco_private *priv = netdev_priv(dev); 3580 struct orinoco_private *priv = netdev_priv(dev);
3409 hermes_t *hw = &priv->hw; 3581 hermes_t *hw = &priv->hw;
@@ -3454,10 +3626,38 @@ static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
3454 return err; 3626 return err;
3455} 3627}
3456 3628
3457static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq) 3629static int orinoco_ioctl_reset(struct net_device *dev,
3630 struct iw_request_info *info,
3631 void *wrqu,
3632 char *extra)
3458{ 3633{
3459 struct orinoco_private *priv = netdev_priv(dev); 3634 struct orinoco_private *priv = netdev_priv(dev);
3460 int val = *( (int *) wrq->u.name ); 3635
3636 if (! capable(CAP_NET_ADMIN))
3637 return -EPERM;
3638
3639 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3640 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3641
3642 /* Firmware reset */
3643 orinoco_reset(dev);
3644 } else {
3645 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3646
3647 schedule_work(&priv->reset_work);
3648 }
3649
3650 return 0;
3651}
3652
3653static int orinoco_ioctl_setibssport(struct net_device *dev,
3654 struct iw_request_info *info,
3655 void *wrqu,
3656 char *extra)
3657
3658{
3659 struct orinoco_private *priv = netdev_priv(dev);
3660 int val = *( (int *) extra );
3461 unsigned long flags; 3661 unsigned long flags;
3462 3662
3463 if (orinoco_lock(priv, &flags) != 0) 3663 if (orinoco_lock(priv, &flags) != 0)
@@ -3469,28 +3669,28 @@ static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
3469 set_port_type(priv); 3669 set_port_type(priv);
3470 3670
3471 orinoco_unlock(priv, &flags); 3671 orinoco_unlock(priv, &flags);
3472 return 0; 3672 return -EINPROGRESS; /* Call commit handler */
3473} 3673}
3474 3674
3475static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq) 3675static int orinoco_ioctl_getibssport(struct net_device *dev,
3676 struct iw_request_info *info,
3677 void *wrqu,
3678 char *extra)
3476{ 3679{
3477 struct orinoco_private *priv = netdev_priv(dev); 3680 struct orinoco_private *priv = netdev_priv(dev);
3478 int *val = (int *)wrq->u.name; 3681 int *val = (int *) extra;
3479 unsigned long flags;
3480
3481 if (orinoco_lock(priv, &flags) != 0)
3482 return -EBUSY;
3483 3682
3484 *val = priv->ibss_port; 3683 *val = priv->ibss_port;
3485 orinoco_unlock(priv, &flags);
3486
3487 return 0; 3684 return 0;
3488} 3685}
3489 3686
3490static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq) 3687static int orinoco_ioctl_setport3(struct net_device *dev,
3688 struct iw_request_info *info,
3689 void *wrqu,
3690 char *extra)
3491{ 3691{
3492 struct orinoco_private *priv = netdev_priv(dev); 3692 struct orinoco_private *priv = netdev_priv(dev);
3493 int val = *( (int *) wrq->u.name ); 3693 int val = *( (int *) extra );
3494 int err = 0; 3694 int err = 0;
3495 unsigned long flags; 3695 unsigned long flags;
3496 3696
@@ -3519,51 +3719,131 @@ static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
3519 err = -EINVAL; 3719 err = -EINVAL;
3520 } 3720 }
3521 3721
3522 if (! err) 3722 if (! err) {
3523 /* Actually update the mode we are using */ 3723 /* Actually update the mode we are using */
3524 set_port_type(priv); 3724 set_port_type(priv);
3725 err = -EINPROGRESS;
3726 }
3525 3727
3526 orinoco_unlock(priv, &flags); 3728 orinoco_unlock(priv, &flags);
3527 3729
3528 return err; 3730 return err;
3529} 3731}
3530 3732
3531static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq) 3733static int orinoco_ioctl_getport3(struct net_device *dev,
3734 struct iw_request_info *info,
3735 void *wrqu,
3736 char *extra)
3737{
3738 struct orinoco_private *priv = netdev_priv(dev);
3739 int *val = (int *) extra;
3740
3741 *val = priv->prefer_port3;
3742 return 0;
3743}
3744
3745static int orinoco_ioctl_setpreamble(struct net_device *dev,
3746 struct iw_request_info *info,
3747 void *wrqu,
3748 char *extra)
3532{ 3749{
3533 struct orinoco_private *priv = netdev_priv(dev); 3750 struct orinoco_private *priv = netdev_priv(dev);
3534 int *val = (int *)wrq->u.name;
3535 unsigned long flags; 3751 unsigned long flags;
3752 int val;
3753
3754 if (! priv->has_preamble)
3755 return -EOPNOTSUPP;
3756
3757 /* 802.11b has recently defined some short preamble.
3758 * Basically, the Phy header has been reduced in size.
3759 * This increase performance, especially at high rates
3760 * (the preamble is transmitted at 1Mb/s), unfortunately
3761 * this give compatibility troubles... - Jean II */
3762 val = *( (int *) extra );
3536 3763
3537 if (orinoco_lock(priv, &flags) != 0) 3764 if (orinoco_lock(priv, &flags) != 0)
3538 return -EBUSY; 3765 return -EBUSY;
3539 3766
3540 *val = priv->prefer_port3; 3767 if (val)
3768 priv->preamble = 1;
3769 else
3770 priv->preamble = 0;
3771
3541 orinoco_unlock(priv, &flags); 3772 orinoco_unlock(priv, &flags);
3773
3774 return -EINPROGRESS; /* Call commit handler */
3775}
3776
3777static int orinoco_ioctl_getpreamble(struct net_device *dev,
3778 struct iw_request_info *info,
3779 void *wrqu,
3780 char *extra)
3781{
3782 struct orinoco_private *priv = netdev_priv(dev);
3783 int *val = (int *) extra;
3784
3785 if (! priv->has_preamble)
3786 return -EOPNOTSUPP;
3787
3788 *val = priv->preamble;
3542 return 0; 3789 return 0;
3543} 3790}
3544 3791
3792/* ioctl interface to hermes_read_ltv()
3793 * To use with iwpriv, pass the RID as the token argument, e.g.
3794 * iwpriv get_rid [0xfc00]
3795 * At least Wireless Tools 25 is required to use iwpriv.
3796 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3797static int orinoco_ioctl_getrid(struct net_device *dev,
3798 struct iw_request_info *info,
3799 struct iw_point *data,
3800 char *extra)
3801{
3802 struct orinoco_private *priv = netdev_priv(dev);
3803 hermes_t *hw = &priv->hw;
3804 int rid = data->flags;
3805 u16 length;
3806 int err;
3807 unsigned long flags;
3808
3809 /* It's a "get" function, but we don't want users to access the
3810 * WEP key and other raw firmware data */
3811 if (! capable(CAP_NET_ADMIN))
3812 return -EPERM;
3813
3814 if (rid < 0xfc00 || rid > 0xffff)
3815 return -EINVAL;
3816
3817 if (orinoco_lock(priv, &flags) != 0)
3818 return -EBUSY;
3819
3820 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3821 extra);
3822 if (err)
3823 goto out;
3824
3825 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3826 MAX_RID_LEN);
3827
3828 out:
3829 orinoco_unlock(priv, &flags);
3830 return err;
3831}
3832
3545/* Spy is used for link quality/strength measurements in Ad-Hoc mode 3833/* Spy is used for link quality/strength measurements in Ad-Hoc mode
3546 * Jean II */ 3834 * Jean II */
3547static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq) 3835static int orinoco_ioctl_setspy(struct net_device *dev,
3836 struct iw_request_info *info,
3837 struct iw_point *srq,
3838 char *extra)
3839
3548{ 3840{
3549 struct orinoco_private *priv = netdev_priv(dev); 3841 struct orinoco_private *priv = netdev_priv(dev);
3550 struct sockaddr address[IW_MAX_SPY]; 3842 struct sockaddr *address = (struct sockaddr *) extra;
3551 int number = srq->length; 3843 int number = srq->length;
3552 int i; 3844 int i;
3553 int err = 0;
3554 unsigned long flags; 3845 unsigned long flags;
3555 3846
3556 /* Check the number of addresses */
3557 if (number > IW_MAX_SPY)
3558 return -E2BIG;
3559
3560 /* Get the data in the driver */
3561 if (srq->pointer) {
3562 if (copy_from_user(address, srq->pointer,
3563 sizeof(struct sockaddr) * number))
3564 return -EFAULT;
3565 }
3566
3567 /* Make sure nobody mess with the structure while we do */ 3847 /* Make sure nobody mess with the structure while we do */
3568 if (orinoco_lock(priv, &flags) != 0) 3848 if (orinoco_lock(priv, &flags) != 0)
3569 return -EBUSY; 3849 return -EBUSY;
@@ -3587,14 +3867,17 @@ static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
3587 /* Now, let the others play */ 3867 /* Now, let the others play */
3588 orinoco_unlock(priv, &flags); 3868 orinoco_unlock(priv, &flags);
3589 3869
3590 return err; 3870 /* Do NOT call commit handler */
3871 return 0;
3591} 3872}
3592 3873
3593static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq) 3874static int orinoco_ioctl_getspy(struct net_device *dev,
3875 struct iw_request_info *info,
3876 struct iw_point *srq,
3877 char *extra)
3594{ 3878{
3595 struct orinoco_private *priv = netdev_priv(dev); 3879 struct orinoco_private *priv = netdev_priv(dev);
3596 struct sockaddr address[IW_MAX_SPY]; 3880 struct sockaddr *address = (struct sockaddr *) extra;
3597 struct iw_quality spy_stat[IW_MAX_SPY];
3598 int number; 3881 int number;
3599 int i; 3882 int i;
3600 unsigned long flags; 3883 unsigned long flags;
@@ -3603,7 +3886,12 @@ static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3603 return -EBUSY; 3886 return -EBUSY;
3604 3887
3605 number = priv->spy_number; 3888 number = priv->spy_number;
3606 if ((number > 0) && (srq->pointer)) { 3889 /* Create address struct */
3890 for (i = 0; i < number; i++) {
3891 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3892 address[i].sa_family = AF_UNIX;
3893 }
3894 if (number > 0) {
3607 /* Create address struct */ 3895 /* Create address struct */
3608 for (i = 0; i < number; i++) { 3896 for (i = 0; i < number; i++) {
3609 memcpy(address[i].sa_data, priv->spy_address[i], 3897 memcpy(address[i].sa_data, priv->spy_address[i],
@@ -3614,344 +3902,503 @@ static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3614 /* In theory, we should disable irqs while copying the stats 3902 /* In theory, we should disable irqs while copying the stats
3615 * because the rx path might update it in the middle... 3903 * because the rx path might update it in the middle...
3616 * Bah, who care ? - Jean II */ 3904 * Bah, who care ? - Jean II */
3617 memcpy(&spy_stat, priv->spy_stat, 3905 memcpy(extra + (sizeof(struct sockaddr) * number),
3618 sizeof(struct iw_quality) * IW_MAX_SPY); 3906 priv->spy_stat, sizeof(struct iw_quality) * number);
3619 for (i=0; i < number; i++)
3620 priv->spy_stat[i].updated = 0;
3621 } 3907 }
3908 /* Reset updated flags. */
3909 for (i = 0; i < number; i++)
3910 priv->spy_stat[i].updated = 0;
3622 3911
3623 orinoco_unlock(priv, &flags); 3912 orinoco_unlock(priv, &flags);
3624 3913
3625 /* Push stuff to user space */
3626 srq->length = number; 3914 srq->length = number;
3627 if(copy_to_user(srq->pointer, address,
3628 sizeof(struct sockaddr) * number))
3629 return -EFAULT;
3630 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
3631 &spy_stat, sizeof(struct iw_quality) * number))
3632 return -EFAULT;
3633 3915
3634 return 0; 3916 return 0;
3635} 3917}
3636 3918
3637static int 3919/* Trigger a scan (look for other cells in the vicinity */
3638orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 3920static int orinoco_ioctl_setscan(struct net_device *dev,
3921 struct iw_request_info *info,
3922 struct iw_param *srq,
3923 char *extra)
3639{ 3924{
3640 struct orinoco_private *priv = netdev_priv(dev); 3925 struct orinoco_private *priv = netdev_priv(dev);
3641 struct iwreq *wrq = (struct iwreq *)rq; 3926 hermes_t *hw = &priv->hw;
3642 int err = 0; 3927 int err = 0;
3643 int tmp;
3644 int changed = 0;
3645 unsigned long flags; 3928 unsigned long flags;
3646 3929
3647 TRACE_ENTER(dev->name); 3930 /* Note : you may have realised that, as this is a SET operation,
3931 * this is priviledged and therefore a normal user can't
3932 * perform scanning.
3933 * This is not an error, while the device perform scanning,
3934 * traffic doesn't flow, so it's a perfect DoS...
3935 * Jean II */
3648 3936
3649 /* In theory, we could allow most of the the SET stuff to be 3937 if (orinoco_lock(priv, &flags) != 0)
3650 * done. In practice, the lapse of time at startup when the 3938 return -EBUSY;
3651 * card is not ready is very short, so why bother... Note
3652 * that netif_device_present is different from up/down
3653 * (ifconfig), when the device is not yet up, it is usually
3654 * already ready... Jean II */
3655 if (! netif_device_present(dev))
3656 return -ENODEV;
3657 3939
3658 switch (cmd) { 3940 /* Scanning with port 0 disabled would fail */
3659 case SIOCGIWNAME: 3941 if (!netif_running(dev)) {
3660 strcpy(wrq->u.name, "IEEE 802.11-DS"); 3942 err = -ENETDOWN;
3661 break; 3943 goto out;
3662 3944 }
3663 case SIOCGIWAP:
3664 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
3665 err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
3666 break;
3667 3945
3668 case SIOCGIWRANGE: 3946 /* In monitor mode, the scan results are always empty.
3669 err = orinoco_ioctl_getiwrange(dev, &wrq->u.data); 3947 * Probe responses are passed to the driver as received
3670 break; 3948 * frames and could be processed in software. */
3949 if (priv->iw_mode == IW_MODE_MONITOR) {
3950 err = -EOPNOTSUPP;
3951 goto out;
3952 }
3671 3953
3672 case SIOCSIWMODE: 3954 /* Note : because we don't lock out the irq handler, the way
3673 if (orinoco_lock(priv, &flags) != 0) 3955 * we access scan variables in priv is critical.
3674 return -EBUSY; 3956 * o scan_inprogress : not touched by irq handler
3675 switch (wrq->u.mode) { 3957 * o scan_mode : not touched by irq handler
3676 case IW_MODE_ADHOC: 3958 * o scan_result : irq is strict producer, non-irq is strict
3677 if (! (priv->has_ibss || priv->has_port3) ) 3959 * consumer.
3678 err = -EINVAL; 3960 * o scan_len : synchronised with scan_result
3679 else { 3961 * Before modifying anything on those variables, please think hard !
3680 priv->iw_mode = IW_MODE_ADHOC; 3962 * Jean II */
3681 changed = 1;
3682 }
3683 break;
3684 3963
3685 case IW_MODE_INFRA: 3964 /* If there is still some left-over scan results, get rid of it */
3686 priv->iw_mode = IW_MODE_INFRA; 3965 if (priv->scan_result != NULL) {
3687 changed = 1; 3966 /* What's likely is that a client did crash or was killed
3688 break; 3967 * between triggering the scan request and reading the
3968 * results, so we need to reset everything.
3969 * Some clients that are too slow may suffer from that...
3970 * Jean II */
3971 kfree(priv->scan_result);
3972 priv->scan_result = NULL;
3973 }
3689 3974
3690 default: 3975 /* Save flags */
3691 err = -EINVAL; 3976 priv->scan_mode = srq->flags;
3692 break;
3693 }
3694 set_port_type(priv);
3695 orinoco_unlock(priv, &flags);
3696 break;
3697 3977
3698 case SIOCGIWMODE: 3978 /* Always trigger scanning, even if it's in progress.
3699 if (orinoco_lock(priv, &flags) != 0) 3979 * This way, if the info frame get lost, we will recover somewhat
3700 return -EBUSY; 3980 * gracefully - Jean II */
3701 wrq->u.mode = priv->iw_mode;
3702 orinoco_unlock(priv, &flags);
3703 break;
3704 3981
3705 case SIOCSIWENCODE: 3982 if (priv->has_hostscan) {
3706 err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding); 3983 switch (priv->firmware_type) {
3707 if (! err) 3984 case FIRMWARE_TYPE_SYMBOL:
3708 changed = 1; 3985 err = hermes_write_wordrec(hw, USER_BAP,
3986 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3987 HERMES_HOSTSCAN_SYMBOL_ONCE |
3988 HERMES_HOSTSCAN_SYMBOL_BCAST);
3989 break;
3990 case FIRMWARE_TYPE_INTERSIL: {
3991 u16 req[3];
3992
3993 req[0] = cpu_to_le16(0x3fff); /* All channels */
3994 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3995 req[2] = 0; /* Any ESSID */
3996 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3997 HERMES_RID_CNFHOSTSCAN, &req);
3998 }
3709 break; 3999 break;
4000 case FIRMWARE_TYPE_AGERE:
4001 err = hermes_write_wordrec(hw, USER_BAP,
4002 HERMES_RID_CNFSCANSSID_AGERE,
4003 0); /* Any ESSID */
4004 if (err)
4005 break;
3710 4006
3711 case SIOCGIWENCODE: 4007 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3712 if (! capable(CAP_NET_ADMIN)) {
3713 err = -EPERM;
3714 break; 4008 break;
3715 } 4009 }
4010 } else
4011 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3716 4012
3717 err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding); 4013 /* One more client */
3718 break; 4014 if (! err)
3719 4015 priv->scan_inprogress = 1;
3720 case SIOCSIWESSID:
3721 err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
3722 if (! err)
3723 changed = 1;
3724 break;
3725 4016
3726 case SIOCGIWESSID: 4017 out:
3727 err = orinoco_ioctl_getessid(dev, &wrq->u.essid); 4018 orinoco_unlock(priv, &flags);
3728 break; 4019 return err;
4020}
3729 4021
3730 case SIOCSIWNICKN: 4022/* Translate scan data returned from the card to a card independant
3731 err = orinoco_ioctl_setnick(dev, &wrq->u.data); 4023 * format that the Wireless Tools will understand - Jean II */
3732 if (! err) 4024static inline int orinoco_translate_scan(struct net_device *dev,
3733 changed = 1; 4025 char *buffer,
3734 break; 4026 char *scan,
4027 int scan_len)
4028{
4029 struct orinoco_private *priv = netdev_priv(dev);
4030 int offset; /* In the scan data */
4031 union hermes_scan_info *atom;
4032 int atom_len;
4033 u16 capabilities;
4034 u16 channel;
4035 struct iw_event iwe; /* Temporary buffer */
4036 char * current_ev = buffer;
4037 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3735 4038
3736 case SIOCGIWNICKN: 4039 switch (priv->firmware_type) {
3737 err = orinoco_ioctl_getnick(dev, &wrq->u.data); 4040 case FIRMWARE_TYPE_AGERE:
4041 atom_len = sizeof(struct agere_scan_apinfo);
4042 offset = 0;
3738 break; 4043 break;
3739 4044 case FIRMWARE_TYPE_SYMBOL:
3740 case SIOCGIWFREQ: 4045 /* Lack of documentation necessitates this hack.
3741 tmp = orinoco_hw_get_freq(priv); 4046 * Different firmwares have 68 or 76 byte long atoms.
3742 if (tmp < 0) { 4047 * We try modulo first. If the length divides by both,
3743 err = tmp; 4048 * we check what would be the channel in the second
3744 } else { 4049 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3745 wrq->u.freq.m = tmp; 4050 * Valid channel cannot be 0. */
3746 wrq->u.freq.e = 1; 4051 if (scan_len % 76)
3747 } 4052 atom_len = 68;
4053 else if (scan_len % 68)
4054 atom_len = 76;
4055 else if (scan_len >= 1292 && scan[68] == 0)
4056 atom_len = 76;
4057 else
4058 atom_len = 68;
4059 offset = 0;
3748 break; 4060 break;
3749 4061 case FIRMWARE_TYPE_INTERSIL:
3750 case SIOCSIWFREQ: 4062 offset = 4;
3751 err = orinoco_ioctl_setfreq(dev, &wrq->u.freq); 4063 if (priv->has_hostscan)
3752 if (! err) 4064 atom_len = scan[0] + (scan[1] << 8);
3753 changed = 1; 4065 else
4066 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3754 break; 4067 break;
4068 default:
4069 return 0;
4070 }
3755 4071
3756 case SIOCGIWSENS: 4072 /* Check that we got an whole number of atoms */
3757 err = orinoco_ioctl_getsens(dev, &wrq->u.sens); 4073 if ((scan_len - offset) % atom_len) {
3758 break; 4074 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4075 "atom_len %d, offset %d\n", dev->name, scan_len,
4076 atom_len, offset);
4077 return 0;
4078 }
3759 4079
3760 case SIOCSIWSENS: 4080 /* Read the entries one by one */
3761 err = orinoco_ioctl_setsens(dev, &wrq->u.sens); 4081 for (; offset + atom_len <= scan_len; offset += atom_len) {
3762 if (! err) 4082 /* Get next atom */
3763 changed = 1; 4083 atom = (union hermes_scan_info *) (scan + offset);
3764 break; 4084
4085 /* First entry *MUST* be the AP MAC address */
4086 iwe.cmd = SIOCGIWAP;
4087 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4088 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4089 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4090
4091 /* Other entries will be displayed in the order we give them */
4092
4093 /* Add the ESSID */
4094 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4095 if (iwe.u.data.length > 32)
4096 iwe.u.data.length = 32;
4097 iwe.cmd = SIOCGIWESSID;
4098 iwe.u.data.flags = 1;
4099 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4100
4101 /* Add mode */
4102 iwe.cmd = SIOCGIWMODE;
4103 capabilities = le16_to_cpu(atom->a.capabilities);
4104 if (capabilities & 0x3) {
4105 if (capabilities & 0x1)
4106 iwe.u.mode = IW_MODE_MASTER;
4107 else
4108 iwe.u.mode = IW_MODE_ADHOC;
4109 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4110 }
3765 4111
3766 case SIOCGIWRTS: 4112 channel = atom->s.channel;
3767 wrq->u.rts.value = priv->rts_thresh; 4113 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
3768 wrq->u.rts.disabled = (wrq->u.rts.value == 2347); 4114 /* Add frequency */
3769 wrq->u.rts.fixed = 1; 4115 iwe.cmd = SIOCGIWFREQ;
3770 break; 4116 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4117 iwe.u.freq.e = 1;
4118 current_ev = iwe_stream_add_event(current_ev, end_buf,
4119 &iwe, IW_EV_FREQ_LEN);
4120 }
3771 4121
3772 case SIOCSIWRTS: 4122 /* Add quality statistics */
3773 err = orinoco_ioctl_setrts(dev, &wrq->u.rts); 4123 iwe.cmd = IWEVQUAL;
3774 if (! err) 4124 iwe.u.qual.updated = 0x10; /* no link quality */
3775 changed = 1; 4125 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
3776 break; 4126 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4127 /* Wireless tools prior to 27.pre22 will show link quality
4128 * anyway, so we provide a reasonable value. */
4129 if (iwe.u.qual.level > iwe.u.qual.noise)
4130 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4131 else
4132 iwe.u.qual.qual = 0;
4133 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
3777 4134
3778 case SIOCSIWFRAG: 4135 /* Add encryption capability */
3779 err = orinoco_ioctl_setfrag(dev, &wrq->u.frag); 4136 iwe.cmd = SIOCGIWENCODE;
3780 if (! err) 4137 if (capabilities & 0x10)
3781 changed = 1; 4138 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3782 break; 4139 else
4140 iwe.u.data.flags = IW_ENCODE_DISABLED;
4141 iwe.u.data.length = 0;
4142 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4143
4144 /* Bit rate is not available in Lucent/Agere firmwares */
4145 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4146 char * current_val = current_ev + IW_EV_LCP_LEN;
4147 int i;
4148 int step;
4149
4150 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4151 step = 2;
4152 else
4153 step = 1;
4154
4155 iwe.cmd = SIOCGIWRATE;
4156 /* Those two flags are ignored... */
4157 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4158 /* Max 10 values */
4159 for (i = 0; i < 10; i += step) {
4160 /* NULL terminated */
4161 if (atom->p.rates[i] == 0x0)
4162 break;
4163 /* Bit rate given in 500 kb/s units (+ 0x80) */
4164 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4165 current_val = iwe_stream_add_value(current_ev, current_val,
4166 end_buf, &iwe,
4167 IW_EV_PARAM_LEN);
4168 }
4169 /* Check if we added any event */
4170 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4171 current_ev = current_val;
4172 }
3783 4173
3784 case SIOCGIWFRAG: 4174 /* The other data in the scan result are not really
3785 err = orinoco_ioctl_getfrag(dev, &wrq->u.frag); 4175 * interesting, so for now drop it - Jean II */
3786 break; 4176 }
4177 return current_ev - buffer;
4178}
3787 4179
3788 case SIOCSIWRATE: 4180/* Return results of a scan */
3789 err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate); 4181static int orinoco_ioctl_getscan(struct net_device *dev,
3790 if (! err) 4182 struct iw_request_info *info,
3791 changed = 1; 4183 struct iw_point *srq,
3792 break; 4184 char *extra)
4185{
4186 struct orinoco_private *priv = netdev_priv(dev);
4187 int err = 0;
4188 unsigned long flags;
3793 4189
3794 case SIOCGIWRATE: 4190 if (orinoco_lock(priv, &flags) != 0)
3795 err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate); 4191 return -EBUSY;
3796 break;
3797 4192
3798 case SIOCSIWPOWER: 4193 /* If no results yet, ask to try again later */
3799 err = orinoco_ioctl_setpower(dev, &wrq->u.power); 4194 if (priv->scan_result == NULL) {
3800 if (! err) 4195 if (priv->scan_inprogress)
3801 changed = 1; 4196 /* Important note : we don't want to block the caller
3802 break; 4197 * until results are ready for various reasons.
4198 * First, managing wait queues is complex and racy.
4199 * Second, we grab some rtnetlink lock before comming
4200 * here (in dev_ioctl()).
4201 * Third, we generate an Wireless Event, so the
4202 * caller can wait itself on that - Jean II */
4203 err = -EAGAIN;
4204 else
4205 /* Client error, no scan results...
4206 * The caller need to restart the scan. */
4207 err = -ENODATA;
4208 } else {
4209 /* We have some results to push back to user space */
4210
4211 /* Translate to WE format */
4212 srq->length = orinoco_translate_scan(dev, extra,
4213 priv->scan_result,
4214 priv->scan_len);
4215
4216 /* Return flags */
4217 srq->flags = (__u16) priv->scan_mode;
4218
4219 /* Results are here, so scan no longer in progress */
4220 priv->scan_inprogress = 0;
4221
4222 /* In any case, Scan results will be cleaned up in the
4223 * reset function and when exiting the driver.
4224 * The person triggering the scanning may never come to
4225 * pick the results, so we need to do it in those places.
4226 * Jean II */
4227
4228#ifdef SCAN_SINGLE_READ
4229 /* If you enable this option, only one client (the first
4230 * one) will be able to read the result (and only one
4231 * time). If there is multiple concurent clients that
4232 * want to read scan results, this behavior is not
4233 * advisable - Jean II */
4234 kfree(priv->scan_result);
4235 priv->scan_result = NULL;
4236#endif /* SCAN_SINGLE_READ */
4237 /* Here, if too much time has elapsed since last scan,
4238 * we may want to clean up scan results... - Jean II */
4239 }
4240
4241 orinoco_unlock(priv, &flags);
4242 return err;
4243}
3803 4244
3804 case SIOCGIWPOWER: 4245/* Commit handler, called after set operations */
3805 err = orinoco_ioctl_getpower(dev, &wrq->u.power); 4246static int orinoco_ioctl_commit(struct net_device *dev,
3806 break; 4247 struct iw_request_info *info,
4248 void *wrqu,
4249 char *extra)
4250{
4251 struct orinoco_private *priv = netdev_priv(dev);
4252 struct hermes *hw = &priv->hw;
4253 unsigned long flags;
4254 int err = 0;
3807 4255
3808 case SIOCGIWTXPOW: 4256 if (!priv->open)
3809 /* The card only supports one tx power, so this is easy */ 4257 return 0;
3810 wrq->u.txpower.value = 15; /* dBm */
3811 wrq->u.txpower.fixed = 1;
3812 wrq->u.txpower.disabled = 0;
3813 wrq->u.txpower.flags = IW_TXPOW_DBM;
3814 break;
3815 4258
3816 case SIOCSIWRETRY: 4259 if (priv->broken_disableport) {
3817 err = -EOPNOTSUPP; 4260 orinoco_reset(dev);
3818 break; 4261 return 0;
4262 }
3819 4263
3820 case SIOCGIWRETRY: 4264 if (orinoco_lock(priv, &flags) != 0)
3821 err = orinoco_ioctl_getretry(dev, &wrq->u.retry); 4265 return err;
3822 break;
3823 4266
3824 case SIOCSIWSPY: 4267 err = hermes_disable_port(hw, 0);
3825 err = orinoco_ioctl_setspy(dev, &wrq->u.data); 4268 if (err) {
3826 break; 4269 printk(KERN_WARNING "%s: Unable to disable port "
4270 "while reconfiguring card\n", dev->name);
4271 priv->broken_disableport = 1;
4272 goto out;
4273 }
3827 4274
3828 case SIOCGIWSPY: 4275 err = __orinoco_program_rids(dev);
3829 err = orinoco_ioctl_getspy(dev, &wrq->u.data); 4276 if (err) {
3830 break; 4277 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4278 dev->name);
4279 goto out;
4280 }
3831 4281
3832 case SIOCGIWPRIV: 4282 err = hermes_enable_port(hw, 0);
3833 if (wrq->u.data.pointer) { 4283 if (err) {
3834 struct iw_priv_args privtab[] = { 4284 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
3835 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, 4285 dev->name);
3836 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, 4286 goto out;
3837 { SIOCIWFIRSTPRIV + 0x2, 4287 }
3838 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3839 0, "set_port3" },
3840 { SIOCIWFIRSTPRIV + 0x3, 0,
3841 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3842 "get_port3" },
3843 { SIOCIWFIRSTPRIV + 0x4,
3844 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3845 0, "set_preamble" },
3846 { SIOCIWFIRSTPRIV + 0x5, 0,
3847 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3848 "get_preamble" },
3849 { SIOCIWFIRSTPRIV + 0x6,
3850 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3851 0, "set_ibssport" },
3852 { SIOCIWFIRSTPRIV + 0x7, 0,
3853 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3854 "get_ibssport" },
3855 };
3856
3857 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
3858 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
3859 err = -EFAULT;
3860 }
3861 break;
3862
3863 case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
3864 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
3865 if (! capable(CAP_NET_ADMIN)) {
3866 err = -EPERM;
3867 break;
3868 }
3869
3870 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3871 4288
4289 out:
4290 if (err) {
4291 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
3872 schedule_work(&priv->reset_work); 4292 schedule_work(&priv->reset_work);
3873 break; 4293 err = 0;
3874 4294 }
3875 case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
3876 if (! capable(CAP_NET_ADMIN)) {
3877 err = -EPERM;
3878 break;
3879 }
3880
3881 err = orinoco_ioctl_setport3(dev, wrq);
3882 if (! err)
3883 changed = 1;
3884 break;
3885 4295
3886 case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */ 4296 orinoco_unlock(priv, &flags);
3887 err = orinoco_ioctl_getport3(dev, wrq); 4297 return err;
3888 break; 4298}
3889 4299
3890 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */ 4300static const struct iw_priv_args orinoco_privtab[] = {
3891 if (! capable(CAP_NET_ADMIN)) { 4301 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
3892 err = -EPERM; 4302 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
3893 break; 4303 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3894 } 4304 0, "set_port3" },
4305 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4306 "get_port3" },
4307 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4308 0, "set_preamble" },
4309 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4310 "get_preamble" },
4311 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4312 0, "set_ibssport" },
4313 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4314 "get_ibssport" },
4315 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4316 "get_rid" },
4317};
3895 4318
3896 /* 802.11b has recently defined some short preamble.
3897 * Basically, the Phy header has been reduced in size.
3898 * This increase performance, especially at high rates
3899 * (the preamble is transmitted at 1Mb/s), unfortunately
3900 * this give compatibility troubles... - Jean II */
3901 if(priv->has_preamble) {
3902 int val = *( (int *) wrq->u.name );
3903
3904 if (orinoco_lock(priv, &flags) != 0)
3905 return -EBUSY;
3906 if (val)
3907 priv->preamble = 1;
3908 else
3909 priv->preamble = 0;
3910 orinoco_unlock(priv, &flags);
3911 changed = 1;
3912 } else
3913 err = -EOPNOTSUPP;
3914 break;
3915 4319
3916 case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */ 4320/*
3917 if(priv->has_preamble) { 4321 * Structures to export the Wireless Handlers
3918 int *val = (int *)wrq->u.name; 4322 */
3919 4323
3920 if (orinoco_lock(priv, &flags) != 0) 4324static const iw_handler orinoco_handler[] = {
3921 return -EBUSY; 4325 [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit,
3922 *val = priv->preamble; 4326 [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname,
3923 orinoco_unlock(priv, &flags); 4327 [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq,
3924 } else 4328 [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq,
3925 err = -EOPNOTSUPP; 4329 [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode,
3926 break; 4330 [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode,
3927 case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */ 4331 [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens,
3928 if (! capable(CAP_NET_ADMIN)) { 4332 [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens,
3929 err = -EPERM; 4333 [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange,
3930 break; 4334 [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy,
3931 } 4335 [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy,
4336 [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap,
4337 [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap,
4338 [SIOCSIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setscan,
4339 [SIOCGIWSCAN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getscan,
4340 [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid,
4341 [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid,
4342 [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick,
4343 [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick,
4344 [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate,
4345 [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate,
4346 [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts,
4347 [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts,
4348 [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag,
4349 [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag,
4350 [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry,
4351 [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode,
4352 [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode,
4353 [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower,
4354 [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower,
4355};
3932 4356
3933 err = orinoco_ioctl_setibssport(dev, wrq);
3934 if (! err)
3935 changed = 1;
3936 break;
3937 4357
3938 case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */ 4358/*
3939 err = orinoco_ioctl_getibssport(dev, wrq); 4359 Added typecasting since we no longer use iwreq_data -- Moustafa
3940 break; 4360 */
4361static const iw_handler orinoco_private_handler[] = {
4362 [0] (iw_handler) orinoco_ioctl_reset,
4363 [1] (iw_handler) orinoco_ioctl_reset,
4364 [2] (iw_handler) orinoco_ioctl_setport3,
4365 [3] (iw_handler) orinoco_ioctl_getport3,
4366 [4] (iw_handler) orinoco_ioctl_setpreamble,
4367 [5] (iw_handler) orinoco_ioctl_getpreamble,
4368 [6] (iw_handler) orinoco_ioctl_setibssport,
4369 [7] (iw_handler) orinoco_ioctl_getibssport,
4370 [9] (iw_handler) orinoco_ioctl_getrid,
4371};
3941 4372
3942 default: 4373static const struct iw_handler_def orinoco_handler_def = {
3943 err = -EOPNOTSUPP; 4374 .num_standard = ARRAY_SIZE(orinoco_handler),
3944 } 4375 .num_private = ARRAY_SIZE(orinoco_private_handler),
3945 4376 .num_private_args = ARRAY_SIZE(orinoco_privtab),
3946 if (! err && changed && netif_running(dev)) { 4377 .standard = orinoco_handler,
3947 err = orinoco_reconfigure(dev); 4378 .private = orinoco_private_handler,
3948 } 4379 .private_args = orinoco_privtab,
4380};
3949 4381
3950 TRACE_EXIT(dev->name); 4382static void orinoco_get_drvinfo(struct net_device *dev,
4383 struct ethtool_drvinfo *info)
4384{
4385 struct orinoco_private *priv = netdev_priv(dev);
3951 4386
3952 return err; 4387 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4388 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4389 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4390 if (dev->class_dev.dev)
4391 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4392 sizeof(info->bus_info) - 1);
4393 else
4394 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4395 "PCMCIA %p", priv->hw.iobase);
3953} 4396}
3954 4397
4398static struct ethtool_ops orinoco_ethtool_ops = {
4399 .get_drvinfo = orinoco_get_drvinfo,
4400 .get_link = ethtool_op_get_link,
4401};
3955 4402
3956/********************************************************************/ 4403/********************************************************************/
3957/* Debugging */ 4404/* Debugging */
diff --git a/drivers/net/wireless/orinoco.h b/drivers/net/wireless/orinoco.h
index f749b50d1088..2f213a7103fe 100644
--- a/drivers/net/wireless/orinoco.h
+++ b/drivers/net/wireless/orinoco.h
@@ -7,7 +7,7 @@
7#ifndef _ORINOCO_H 7#ifndef _ORINOCO_H
8#define _ORINOCO_H 8#define _ORINOCO_H
9 9
10#define DRIVER_VERSION "0.14alpha2" 10#define DRIVER_VERSION "0.15rc2"
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
@@ -22,6 +22,8 @@
22 22
23#define WIRELESS_SPY // enable iwspy support 23#define WIRELESS_SPY // enable iwspy support
24 24
25#define MAX_SCAN_LEN 4096
26
25#define ORINOCO_MAX_KEY_SIZE 14 27#define ORINOCO_MAX_KEY_SIZE 14
26#define ORINOCO_MAX_KEYS 4 28#define ORINOCO_MAX_KEYS 4
27 29
@@ -30,6 +32,20 @@ struct orinoco_key {
30 char data[ORINOCO_MAX_KEY_SIZE]; 32 char data[ORINOCO_MAX_KEY_SIZE];
31} __attribute__ ((packed)); 33} __attribute__ ((packed));
32 34
35struct header_struct {
36 /* 802.3 */
37 u8 dest[ETH_ALEN];
38 u8 src[ETH_ALEN];
39 u16 len;
40 /* 802.2 */
41 u8 dsap;
42 u8 ssap;
43 u8 ctrl;
44 /* SNAP */
45 u8 oui[3];
46 u16 ethertype;
47} __attribute__ ((packed));
48
33typedef enum { 49typedef enum {
34 FIRMWARE_TYPE_AGERE, 50 FIRMWARE_TYPE_AGERE,
35 FIRMWARE_TYPE_INTERSIL, 51 FIRMWARE_TYPE_INTERSIL,
@@ -48,6 +64,8 @@ struct orinoco_private {
48 /* driver state */ 64 /* driver state */
49 int open; 65 int open;
50 u16 last_linkstatus; 66 u16 last_linkstatus;
67 struct work_struct join_work;
68 struct work_struct wevent_work;
51 69
52 /* Net device stuff */ 70 /* Net device stuff */
53 struct net_device *ndev; 71 struct net_device *ndev;
@@ -74,7 +92,9 @@ struct orinoco_private {
74 unsigned int has_pm:1; 92 unsigned int has_pm:1;
75 unsigned int has_preamble:1; 93 unsigned int has_preamble:1;
76 unsigned int has_sensitivity:1; 94 unsigned int has_sensitivity:1;
95 unsigned int has_hostscan:1;
77 unsigned int broken_disableport:1; 96 unsigned int broken_disableport:1;
97 unsigned int broken_monitor:1;
78 98
79 /* Configuration paramaters */ 99 /* Configuration paramaters */
80 u32 iw_mode; 100 u32 iw_mode;
@@ -84,6 +104,8 @@ struct orinoco_private {
84 int bitratemode; 104 int bitratemode;
85 char nick[IW_ESSID_MAX_SIZE+1]; 105 char nick[IW_ESSID_MAX_SIZE+1];
86 char desired_essid[IW_ESSID_MAX_SIZE+1]; 106 char desired_essid[IW_ESSID_MAX_SIZE+1];
107 char desired_bssid[ETH_ALEN];
108 int bssid_fixed;
87 u16 frag_thresh, mwo_robust; 109 u16 frag_thresh, mwo_robust;
88 u16 channel; 110 u16 channel;
89 u16 ap_density, rts_thresh; 111 u16 ap_density, rts_thresh;
@@ -98,6 +120,12 @@ struct orinoco_private {
98 /* Configuration dependent variables */ 120 /* Configuration dependent variables */
99 int port_type, createibss; 121 int port_type, createibss;
100 int promiscuous, mc_count; 122 int promiscuous, mc_count;
123
124 /* Scanning support */
125 int scan_inprogress; /* Scan pending... */
126 u32 scan_mode; /* Type of scan done */
127 char * scan_result; /* Result of previous scan */
128 int scan_len; /* Lenght of result */
101}; 129};
102 130
103#ifdef ORINOCO_DEBUG 131#ifdef ORINOCO_DEBUG
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index 74a8227256aa..368d2f962f67 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -31,7 +31,6 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/wireless.h> 32#include <linux/wireless.h>
33 33
34#include <pcmcia/version.h>
35#include <pcmcia/cs_types.h> 34#include <pcmcia/cs_types.h>
36#include <pcmcia/cs.h> 35#include <pcmcia/cs.h>
37#include <pcmcia/cistpl.h> 36#include <pcmcia/cistpl.h>
@@ -186,11 +185,6 @@ orinoco_cs_attach(void)
186 dev_list = link; 185 dev_list = link;
187 186
188 client_reg.dev_info = &dev_info; 187 client_reg.dev_info = &dev_info;
189 client_reg.EventMask =
190 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
191 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
192 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
193 client_reg.event_handler = &orinoco_cs_event;
194 client_reg.Version = 0x0210; /* FIXME: what does this mean? */ 188 client_reg.Version = 0x0210; /* FIXME: what does this mean? */
195 client_reg.event_callback_args.client_data = link; 189 client_reg.event_callback_args.client_data = link;
196 190
@@ -608,13 +602,65 @@ static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
608 " (David Gibson <hermes@gibson.dropbear.id.au>, " 602 " (David Gibson <hermes@gibson.dropbear.id.au>, "
609 "Pavel Roskin <proski@gnu.org>, et al)"; 603 "Pavel Roskin <proski@gnu.org>, et al)";
610 604
605static struct pcmcia_device_id orinoco_cs_ids[] = {
606 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
607 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001),
608 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
609 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
610 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a),
611 PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002),
612 PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001),
613 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305),
614 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
615 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
616 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673),
617 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
618 PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002),
619 PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001),
620 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
621 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021),
622 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
623 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
624 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
625 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
626 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
627 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3),
628 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0),
629 PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5),
630 PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169),
631 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3),
632 PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90),
633 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584),
634 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9),
635 PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac),
636 PCMCIA_DEVICE_PROD_ID12("D", "Link DWL-650 11Mbps WLAN Card", 0x71b18589, 0xb6f1b0ab),
637 PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3),
638 PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c),
639 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18),
640 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a),
641 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410),
642 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3),
643 PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01),
644 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a),
645 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1),
646 PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264),
647 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9),
648 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26),
649 PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b),
650 PCMCIA_DEVICE_PROD_ID1("Symbol Technologies", 0x3f02b4d6),
651 PCMCIA_DEVICE_NULL,
652};
653MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids);
654
611static struct pcmcia_driver orinoco_driver = { 655static struct pcmcia_driver orinoco_driver = {
612 .owner = THIS_MODULE, 656 .owner = THIS_MODULE,
613 .drv = { 657 .drv = {
614 .name = DRIVER_NAME, 658 .name = DRIVER_NAME,
615 }, 659 },
616 .attach = orinoco_cs_attach, 660 .attach = orinoco_cs_attach,
661 .event = orinoco_cs_event,
617 .detach = orinoco_cs_detach, 662 .detach = orinoco_cs_detach,
663 .id_table = orinoco_cs_ids,
618}; 664};
619 665
620static int __init 666static int __init
diff --git a/drivers/net/wireless/prism54/isl_38xx.c b/drivers/net/wireless/prism54/isl_38xx.c
index 4481ec18c5a0..adc7499136dc 100644
--- a/drivers/net/wireless/prism54/isl_38xx.c
+++ b/drivers/net/wireless/prism54/isl_38xx.c
@@ -112,10 +112,10 @@ isl38xx_handle_wakeup(isl38xx_control_block *control_block,
112void 112void
113isl38xx_trigger_device(int asleep, void __iomem *device_base) 113isl38xx_trigger_device(int asleep, void __iomem *device_base)
114{ 114{
115 struct timeval current_time;
116 u32 reg, counter = 0; 115 u32 reg, counter = 0;
117 116
118#if VERBOSE > SHOW_ERROR_MESSAGES 117#if VERBOSE > SHOW_ERROR_MESSAGES
118 struct timeval current_time;
119 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n"); 119 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
120#endif 120#endif
121 121
@@ -126,11 +126,11 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
126 do_gettimeofday(&current_time); 126 do_gettimeofday(&current_time);
127 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n", 127 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
128 current_time.tv_sec, (long)current_time.tv_usec); 128 current_time.tv_sec, (long)current_time.tv_usec);
129#endif
130 129
131 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n", 130 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
132 current_time.tv_sec, (long)current_time.tv_usec, 131 current_time.tv_sec, (long)current_time.tv_usec,
133 readl(device_base + ISL38XX_CTRL_STAT_REG)); 132 readl(device_base + ISL38XX_CTRL_STAT_REG));
133#endif
134 udelay(ISL38XX_WRITEIO_DELAY); 134 udelay(ISL38XX_WRITEIO_DELAY);
135 135
136 reg = readl(device_base + ISL38XX_INT_IDENT_REG); 136 reg = readl(device_base + ISL38XX_INT_IDENT_REG);
@@ -148,10 +148,12 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
148 counter++; 148 counter++;
149 } 149 }
150 150
151#if VERBOSE > SHOW_ERROR_MESSAGES
151 DEBUG(SHOW_TRACING, 152 DEBUG(SHOW_TRACING,
152 "%08li.%08li Device register read %08x\n", 153 "%08li.%08li Device register read %08x\n",
153 current_time.tv_sec, (long)current_time.tv_usec, 154 current_time.tv_sec, (long)current_time.tv_usec,
154 readl(device_base + ISL38XX_CTRL_STAT_REG)); 155 readl(device_base + ISL38XX_CTRL_STAT_REG));
156#endif
155 udelay(ISL38XX_WRITEIO_DELAY); 157 udelay(ISL38XX_WRITEIO_DELAY);
156 158
157#if VERBOSE > SHOW_ERROR_MESSAGES 159#if VERBOSE > SHOW_ERROR_MESSAGES
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 6e5bda56b8f8..0e0ba614259a 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -46,7 +46,6 @@
46#include <linux/skbuff.h> 46#include <linux/skbuff.h>
47#include <linux/ethtool.h> 47#include <linux/ethtool.h>
48 48
49#include <pcmcia/version.h>
50#include <pcmcia/cs_types.h> 49#include <pcmcia/cs_types.h>
51#include <pcmcia/cs.h> 50#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
@@ -393,11 +392,6 @@ static dev_link_t *ray_attach(void)
393 link->next = dev_list; 392 link->next = dev_list;
394 dev_list = link; 393 dev_list = link;
395 client_reg.dev_info = &dev_info; 394 client_reg.dev_info = &dev_info;
396 client_reg.EventMask =
397 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
398 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
399 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
400 client_reg.event_handler = &ray_event;
401 client_reg.Version = 0x0210; 395 client_reg.Version = 0x0210;
402 client_reg.event_callback_args.client_data = link; 396 client_reg.event_callback_args.client_data = link;
403 397
@@ -2904,13 +2898,21 @@ static int write_int(struct file *file, const char __user *buffer, unsigned long
2904} 2898}
2905#endif 2899#endif
2906 2900
2901static struct pcmcia_device_id ray_ids[] = {
2902 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2903 PCMCIA_DEVICE_NULL,
2904};
2905MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2906
2907static struct pcmcia_driver ray_driver = { 2907static struct pcmcia_driver ray_driver = {
2908 .owner = THIS_MODULE, 2908 .owner = THIS_MODULE,
2909 .drv = { 2909 .drv = {
2910 .name = "ray_cs", 2910 .name = "ray_cs",
2911 }, 2911 },
2912 .attach = ray_attach, 2912 .attach = ray_attach,
2913 .event = ray_event,
2913 .detach = ray_detach, 2914 .detach = ray_detach,
2915 .id_table = ray_ids,
2914}; 2916};
2915 2917
2916static int __init init_ray_cs(void) 2918static int __init init_ray_cs(void)
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index ec8329788e49..f6130a53b796 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -4684,12 +4684,6 @@ wavelan_attach(void)
4684 4684
4685 /* Register with Card Services */ 4685 /* Register with Card Services */
4686 client_reg.dev_info = &dev_info; 4686 client_reg.dev_info = &dev_info;
4687 client_reg.EventMask =
4688 CS_EVENT_REGISTRATION_COMPLETE |
4689 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
4690 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
4691 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
4692 client_reg.event_handler = &wavelan_event;
4693 client_reg.Version = 0x0210; 4687 client_reg.Version = 0x0210;
4694 client_reg.event_callback_args.client_data = link; 4688 client_reg.event_callback_args.client_data = link;
4695 4689
@@ -4889,13 +4883,24 @@ wavelan_event(event_t event, /* The event received */
4889 return 0; 4883 return 0;
4890} 4884}
4891 4885
4886static struct pcmcia_device_id wavelan_ids[] = {
4887 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4888 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
4889 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
4890 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
4891 PCMCIA_DEVICE_NULL,
4892};
4893MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
4894
4892static struct pcmcia_driver wavelan_driver = { 4895static struct pcmcia_driver wavelan_driver = {
4893 .owner = THIS_MODULE, 4896 .owner = THIS_MODULE,
4894 .drv = { 4897 .drv = {
4895 .name = "wavelan_cs", 4898 .name = "wavelan_cs",
4896 }, 4899 },
4897 .attach = wavelan_attach, 4900 .attach = wavelan_attach,
4901 .event = wavelan_event,
4898 .detach = wavelan_detach, 4902 .detach = wavelan_detach,
4903 .id_table = wavelan_ids,
4899}; 4904};
4900 4905
4901static int __init 4906static int __init
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index ea2ef8dddb92..677ff71883cb 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -452,7 +452,6 @@
452#include <pcmcia/cistpl.h> 452#include <pcmcia/cistpl.h>
453#include <pcmcia/cisreg.h> 453#include <pcmcia/cisreg.h>
454#include <pcmcia/ds.h> 454#include <pcmcia/ds.h>
455#include <pcmcia/version.h>
456 455
457/* Wavelan declarations */ 456/* Wavelan declarations */
458#include "i82593.h" /* Definitions for the Intel chip */ 457#include "i82593.h" /* Definitions for the Intel chip */
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 1433e5aaf1b4..dd902126d018 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -49,7 +49,6 @@
49 49
50#include <net/iw_handler.h> 50#include <net/iw_handler.h>
51 51
52#include <pcmcia/version.h>
53#include <pcmcia/cs_types.h> 52#include <pcmcia/cs_types.h>
54#include <pcmcia/cs.h> 53#include <pcmcia/cs.h>
55#include <pcmcia/cistpl.h> 54#include <pcmcia/cistpl.h>
@@ -2005,13 +2004,6 @@ static dev_link_t *wl3501_attach(void)
2005 link->next = wl3501_dev_list; 2004 link->next = wl3501_dev_list;
2006 wl3501_dev_list = link; 2005 wl3501_dev_list = link;
2007 client_reg.dev_info = &wl3501_dev_info; 2006 client_reg.dev_info = &wl3501_dev_info;
2008 client_reg.EventMask = CS_EVENT_CARD_INSERTION |
2009 CS_EVENT_RESET_PHYSICAL |
2010 CS_EVENT_CARD_RESET |
2011 CS_EVENT_CARD_REMOVAL |
2012 CS_EVENT_PM_SUSPEND |
2013 CS_EVENT_PM_RESUME;
2014 client_reg.event_handler = wl3501_event;
2015 client_reg.Version = 0x0210; 2007 client_reg.Version = 0x0210;
2016 client_reg.event_callback_args.client_data = link; 2008 client_reg.event_callback_args.client_data = link;
2017 ret = pcmcia_register_client(&link->handle, &client_reg); 2009 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -2239,13 +2231,21 @@ static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
2239 return 0; 2231 return 0;
2240} 2232}
2241 2233
2234static struct pcmcia_device_id wl3501_ids[] = {
2235 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2236 PCMCIA_DEVICE_NULL
2237};
2238MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2239
2242static struct pcmcia_driver wl3501_driver = { 2240static struct pcmcia_driver wl3501_driver = {
2243 .owner = THIS_MODULE, 2241 .owner = THIS_MODULE,
2244 .drv = { 2242 .drv = {
2245 .name = "wl3501_cs", 2243 .name = "wl3501_cs",
2246 }, 2244 },
2247 .attach = wl3501_attach, 2245 .attach = wl3501_attach,
2248 .detach = wl3501_detach, 2246 .event = wl3501_event,
2247 .detach = wl3501_detach,
2248 .id_table = wl3501_ids,
2249}; 2249};
2250 2250
2251static int __init wl3501_init_module(void) 2251static int __init wl3501_init_module(void)
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 9da925430109..1c2506535f7e 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -786,7 +786,7 @@ static void yellowfin_init_ring(struct net_device *dev)
786 skb->dev = dev; /* Mark as being used by this device. */ 786 skb->dev = dev; /* Mark as being used by this device. */
787 skb_reserve(skb, 2); /* 16 byte align the IP header. */ 787 skb_reserve(skb, 2); /* 16 byte align the IP header. */
788 yp->rx_ring[i].addr = cpu_to_le32(pci_map_single(yp->pci_dev, 788 yp->rx_ring[i].addr = cpu_to_le32(pci_map_single(yp->pci_dev,
789 skb->tail, yp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 789 skb->data, yp->rx_buf_sz, PCI_DMA_FROMDEVICE));
790 } 790 }
791 yp->rx_ring[i-1].dbdma_cmd = cpu_to_le32(CMD_STOP); 791 yp->rx_ring[i-1].dbdma_cmd = cpu_to_le32(CMD_STOP);
792 yp->dirty_rx = (unsigned int)(i - RX_RING_SIZE); 792 yp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
@@ -1111,7 +1111,7 @@ static int yellowfin_rx(struct net_device *dev)
1111 pci_dma_sync_single_for_cpu(yp->pci_dev, desc->addr, 1111 pci_dma_sync_single_for_cpu(yp->pci_dev, desc->addr,
1112 yp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1112 yp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1113 desc_status = le32_to_cpu(desc->result_status) >> 16; 1113 desc_status = le32_to_cpu(desc->result_status) >> 16;
1114 buf_addr = rx_skb->tail; 1114 buf_addr = rx_skb->data;
1115 data_size = (le32_to_cpu(desc->dbdma_cmd) - 1115 data_size = (le32_to_cpu(desc->dbdma_cmd) -
1116 le32_to_cpu(desc->result_status)) & 0xffff; 1116 le32_to_cpu(desc->result_status)) & 0xffff;
1117 frame_status = le16_to_cpu(get_unaligned((s16*)&(buf_addr[data_size - 2]))); 1117 frame_status = le16_to_cpu(get_unaligned((s16*)&(buf_addr[data_size - 2])));
@@ -1185,7 +1185,7 @@ static int yellowfin_rx(struct net_device *dev)
1185 break; 1185 break;
1186 skb->dev = dev; 1186 skb->dev = dev;
1187 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1187 skb_reserve(skb, 2); /* 16 byte align the IP header */
1188 eth_copy_and_sum(skb, rx_skb->tail, pkt_len, 0); 1188 eth_copy_and_sum(skb, rx_skb->data, pkt_len, 0);
1189 skb_put(skb, pkt_len); 1189 skb_put(skb, pkt_len);
1190 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr, 1190 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr,
1191 yp->rx_buf_sz, 1191 yp->rx_buf_sz,
@@ -1211,7 +1211,7 @@ static int yellowfin_rx(struct net_device *dev)
1211 skb->dev = dev; /* Mark as being used by this device. */ 1211 skb->dev = dev; /* Mark as being used by this device. */
1212 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 1212 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1213 yp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(yp->pci_dev, 1213 yp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(yp->pci_dev,
1214 skb->tail, yp->rx_buf_sz, PCI_DMA_FROMDEVICE)); 1214 skb->data, yp->rx_buf_sz, PCI_DMA_FROMDEVICE));
1215 } 1215 }
1216 yp->rx_ring[entry].dbdma_cmd = cpu_to_le32(CMD_STOP); 1216 yp->rx_ring[entry].dbdma_cmd = cpu_to_le32(CMD_STOP);
1217 yp->rx_ring[entry].result_status = 0; /* Clear complete bit. */ 1217 yp->rx_ring[entry].result_status = 0; /* Clear complete bit. */
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index b0d2a73d1d47..2f2dbef2c3b7 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -993,6 +993,7 @@ dino_driver_callback(struct parisc_device *dev)
993 bus = pci_scan_bus_parented(&dev->dev, dino_current_bus, 993 bus = pci_scan_bus_parented(&dev->dev, dino_current_bus,
994 &dino_cfg_ops, NULL); 994 &dino_cfg_ops, NULL);
995 if(bus) { 995 if(bus) {
996 pci_bus_add_devices(bus);
996 /* This code *depends* on scanning being single threaded 997 /* This code *depends* on scanning being single threaded
997 * if it isn't, this global bus number count will fail 998 * if it isn't, this global bus number count will fail
998 */ 999 */
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index dc838804c0dd..7fdd80b7eb47 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1570,6 +1570,8 @@ lba_driver_probe(struct parisc_device *dev)
1570 lba_bus = lba_dev->hba.hba_bus = 1570 lba_bus = lba_dev->hba.hba_bus =
1571 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start, 1571 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start,
1572 cfg_ops, NULL); 1572 cfg_ops, NULL);
1573 if (lba_bus)
1574 pci_bus_add_devices(lba_bus);
1573 1575
1574 /* This is in lieu of calling pci_assign_unassigned_resources() */ 1576 /* This is in lieu of calling pci_assign_unassigned_resources() */
1575 if (is_pdc_pat()) { 1577 if (is_pdc_pat()) {
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index a3fa8185af2a..24e6aacddb74 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -48,7 +48,6 @@
48#include <linux/parport.h> 48#include <linux/parport.h>
49#include <linux/parport_pc.h> 49#include <linux/parport_pc.h>
50 50
51#include <pcmcia/version.h>
52#include <pcmcia/cs_types.h> 51#include <pcmcia/cs_types.h>
53#include <pcmcia/cs.h> 52#include <pcmcia/cs.h>
54#include <pcmcia/cistpl.h> 53#include <pcmcia/cistpl.h>
@@ -133,11 +132,6 @@ static dev_link_t *parport_attach(void)
133 link->next = dev_list; 132 link->next = dev_list;
134 dev_list = link; 133 dev_list = link;
135 client_reg.dev_info = &dev_info; 134 client_reg.dev_info = &dev_info;
136 client_reg.EventMask =
137 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
138 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
139 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
140 client_reg.event_handler = &parport_event;
141 client_reg.Version = 0x0210; 135 client_reg.Version = 0x0210;
142 client_reg.event_callback_args.client_data = link; 136 client_reg.event_callback_args.client_data = link;
143 ret = pcmcia_register_client(&link->handle, &client_reg); 137 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -373,13 +367,23 @@ int parport_event(event_t event, int priority,
373 return 0; 367 return 0;
374} /* parport_event */ 368} /* parport_event */
375 369
370static struct pcmcia_device_id parport_ids[] = {
371 PCMCIA_DEVICE_FUNC_ID(3),
372 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0003),
373 PCMCIA_DEVICE_NULL
374};
375MODULE_DEVICE_TABLE(pcmcia, parport_ids);
376
376static struct pcmcia_driver parport_cs_driver = { 377static struct pcmcia_driver parport_cs_driver = {
377 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
378 .drv = { 379 .drv = {
379 .name = "parport_cs", 380 .name = "parport_cs",
380 }, 381 },
381 .attach = parport_attach, 382 .attach = parport_attach,
383 .event = parport_event,
382 .detach = parport_detach, 384 .detach = parport_detach,
385 .id_table = parport_ids,
386
383}; 387};
384 388
385static int __init init_parport_cs(void) 389static int __init init_parport_cs(void)
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 80edfa3abd29..4598c6a9212d 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -3008,7 +3008,7 @@ static int __init parport_pc_init_superio (int autoirq, int autodma)
3008 int ret = 0; 3008 int ret = 0;
3009 3009
3010 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) { 3010 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3011 id = pci_match_device (parport_pc_pci_tbl, pdev); 3011 id = pci_match_id(parport_pc_pci_tbl, pdev);
3012 if (id == NULL || id->driver_data >= last_sio) 3012 if (id == NULL || id->driver_data >= last_sio)
3013 continue; 3013 continue;
3014 3014
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 7dea494c0d7b..3657f6199c48 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_HOTPLUG_PCI) += hotplug/
19# 19#
20# Some architectures use the generic PCI setup functions 20# Some architectures use the generic PCI setup functions
21# 21#
22obj-$(CONFIG_X86) += setup-bus.o
22obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o 23obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o
23obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o 24obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o
24obj-$(CONFIG_PARISC) += setup-bus.o 25obj-$(CONFIG_PARISC) += setup-bus.o
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index dbd33605cc10..fedae89d8f7d 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -121,10 +121,13 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
121 * If there is an unattached subordinate bus, attach 121 * If there is an unattached subordinate bus, attach
122 * it and then scan for unattached PCI devices. 122 * it and then scan for unattached PCI devices.
123 */ 123 */
124 if (dev->subordinate && list_empty(&dev->subordinate->node)) { 124 if (dev->subordinate) {
125 spin_lock(&pci_bus_lock); 125 if (list_empty(&dev->subordinate->node)) {
126 list_add_tail(&dev->subordinate->node, &dev->bus->children); 126 spin_lock(&pci_bus_lock);
127 spin_unlock(&pci_bus_lock); 127 list_add_tail(&dev->subordinate->node,
128 &dev->bus->children);
129 spin_unlock(&pci_bus_lock);
130 }
128 pci_bus_add_devices(dev->subordinate); 131 pci_bus_add_devices(dev->subordinate);
129 132
130 sysfs_create_link(&dev->subordinate->class_dev.kobj, &dev->dev.kobj, "bridge"); 133 sysfs_create_link(&dev->subordinate->class_dev.kobj, &dev->dev.kobj, "bridge");
diff --git a/drivers/pci/hotplug.c b/drivers/pci/hotplug.c
index 3903f8c559b6..b844bc972324 100644
--- a/drivers/pci/hotplug.c
+++ b/drivers/pci/hotplug.c
@@ -54,7 +54,7 @@ int pci_hotplug (struct device *dev, char **envp, int num_envp,
54 54
55 envp[i++] = scratch; 55 envp[i++] = scratch;
56 length += scnprintf (scratch, buffer_size - length, 56 length += scnprintf (scratch, buffer_size - length,
57 "MODALIAS=pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n", 57 "MODALIAS=pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x",
58 pdev->vendor, pdev->device, 58 pdev->vendor, pdev->device,
59 pdev->subsystem_vendor, pdev->subsystem_device, 59 pdev->subsystem_vendor, pdev->subsystem_device,
60 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8), 60 (u8)(pdev->class >> 16), (u8)(pdev->class >> 8),
diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index 1a4d4ca2a4dc..9c4a39ee89b5 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -187,9 +187,10 @@ config HOTPLUG_PCI_RPA_DLPAR
187 187
188config HOTPLUG_PCI_SGI 188config HOTPLUG_PCI_SGI
189 tristate "SGI PCI Hotplug Support" 189 tristate "SGI PCI Hotplug Support"
190 depends on HOTPLUG_PCI && IA64_SGI_SN2 190 depends on HOTPLUG_PCI && (IA64_SGI_SN2 || IA64_GENERIC)
191 help 191 help
192 Say Y here if you have an SGI IA64 Altix system. 192 Say Y here if you want to use the SGI Altix Hotplug
193 Driver for PCI devices.
193 194
194 When in doubt, say N. 195 When in doubt, say N.
195 196
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 93c120ddbd39..31a307004b94 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_HOTPLUG_PCI_PCIE) += pciehp.o
14obj-$(CONFIG_HOTPLUG_PCI_SHPC) += shpchp.o 14obj-$(CONFIG_HOTPLUG_PCI_SHPC) += shpchp.o
15obj-$(CONFIG_HOTPLUG_PCI_RPA) += rpaphp.o 15obj-$(CONFIG_HOTPLUG_PCI_RPA) += rpaphp.o
16obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR) += rpadlpar_io.o 16obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR) += rpadlpar_io.o
17obj-$(CONFIG_HOTPLUG_PCI_SGI) += sgi_hotplug.o
17 18
18pci_hotplug-objs := pci_hotplug_core.o 19pci_hotplug-objs := pci_hotplug_core.o
19 20
@@ -36,9 +37,7 @@ ibmphp-objs := ibmphp_core.o \
36 ibmphp_hpc.o 37 ibmphp_hpc.o
37 38
38acpiphp-objs := acpiphp_core.o \ 39acpiphp-objs := acpiphp_core.o \
39 acpiphp_glue.o \ 40 acpiphp_glue.o
40 acpiphp_pci.o \
41 acpiphp_res.o
42 41
43rpaphp-objs := rpaphp_core.o \ 42rpaphp-objs := rpaphp_core.o \
44 rpaphp_pci.o \ 43 rpaphp_pci.o \
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index d9499874c8a9..293603e1b7c3 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -7,6 +7,8 @@
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002,2003 NEC Corporation 9 * Copyright (C) 2002,2003 NEC Corporation
10 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
11 * Copyright (C) 2003-2005 Hewlett Packard
10 * 12 *
11 * All rights reserved. 13 * All rights reserved.
12 * 14 *
@@ -52,7 +54,6 @@
52 54
53struct acpiphp_bridge; 55struct acpiphp_bridge;
54struct acpiphp_slot; 56struct acpiphp_slot;
55struct pci_resource;
56 57
57/* 58/*
58 * struct slot - slot information for each *physical* slot 59 * struct slot - slot information for each *physical* slot
@@ -65,15 +66,6 @@ struct slot {
65 struct acpiphp_slot *acpi_slot; 66 struct acpiphp_slot *acpi_slot;
66}; 67};
67 68
68/*
69 * struct pci_resource - describes pci resource (mem, pfmem, io, bus)
70 */
71struct pci_resource {
72 struct pci_resource * next;
73 u64 base;
74 u32 length;
75};
76
77/** 69/**
78 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters 70 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters
79 * @cache_line_size in DWORD 71 * @cache_line_size in DWORD
@@ -101,10 +93,6 @@ struct acpiphp_bridge {
101 int type; 93 int type;
102 int nr_slots; 94 int nr_slots;
103 95
104 u8 seg;
105 u8 bus;
106 u8 sub;
107
108 u32 flags; 96 u32 flags;
109 97
110 /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */ 98 /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
@@ -117,12 +105,6 @@ struct acpiphp_bridge {
117 struct hpp_param hpp; 105 struct hpp_param hpp;
118 106
119 spinlock_t res_lock; 107 spinlock_t res_lock;
120
121 /* available resources on this bus */
122 struct pci_resource *mem_head;
123 struct pci_resource *p_mem_head;
124 struct pci_resource *io_head;
125 struct pci_resource *bus_head;
126}; 108};
127 109
128 110
@@ -163,12 +145,6 @@ struct acpiphp_func {
163 145
164 u8 function; /* pci function# */ 146 u8 function; /* pci function# */
165 u32 flags; /* see below */ 147 u32 flags; /* see below */
166
167 /* resources used for this function */
168 struct pci_resource *mem_head;
169 struct pci_resource *p_mem_head;
170 struct pci_resource *io_head;
171 struct pci_resource *bus_head;
172}; 148};
173 149
174/** 150/**
@@ -243,25 +219,6 @@ extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
243extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 219extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
244extern u32 acpiphp_get_address (struct acpiphp_slot *slot); 220extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
245 221
246/* acpiphp_pci.c */
247extern struct pci_dev *acpiphp_allocate_pcidev (struct pci_bus *pbus, int dev, int fn);
248extern int acpiphp_configure_slot (struct acpiphp_slot *slot);
249extern int acpiphp_configure_function (struct acpiphp_func *func);
250extern void acpiphp_unconfigure_function (struct acpiphp_func *func);
251extern int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge);
252extern int acpiphp_init_func_resource (struct acpiphp_func *func);
253
254/* acpiphp_res.c */
255extern struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size);
256extern struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size);
257extern struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size);
258extern int acpiphp_resource_sort_and_combine (struct pci_resource **head);
259extern struct pci_resource *acpiphp_make_resource (u64 base, u32 length);
260extern void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to);
261extern void acpiphp_free_resource (struct pci_resource **res);
262extern void acpiphp_dump_resource (struct acpiphp_bridge *bridge); /* debug */
263extern void acpiphp_dump_func_resource (struct acpiphp_func *func); /* debug */
264
265/* variables */ 222/* variables */
266extern int acpiphp_debug; 223extern int acpiphp_debug;
267 224
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 4539e61a3dc1..60c4c38047a3 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -7,6 +7,8 @@
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002,2003 NEC Corporation 9 * Copyright (C) 2002,2003 NEC Corporation
10 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
11 * Copyright (C) 2003-2005 Hewlett Packard
10 * 12 *
11 * All rights reserved. 13 * All rights reserved.
12 * 14 *
@@ -53,8 +55,8 @@ int acpiphp_debug;
53static int num_slots; 55static int num_slots;
54static struct acpiphp_attention_info *attention_info; 56static struct acpiphp_attention_info *attention_info;
55 57
56#define DRIVER_VERSION "0.4" 58#define DRIVER_VERSION "0.5"
57#define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>" 59#define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>, Matthew Wilcox <willy@hp.com>"
58#define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver" 60#define DRIVER_DESC "ACPI Hot Plug PCI Controller Driver"
59 61
60MODULE_AUTHOR(DRIVER_AUTHOR); 62MODULE_AUTHOR(DRIVER_AUTHOR);
@@ -281,8 +283,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
281/** 283/**
282 * get_address - get pci address of a slot 284 * get_address - get pci address of a slot
283 * @hotplug_slot: slot to get status 285 * @hotplug_slot: slot to get status
284 * @busdev: pointer to struct pci_busdev (seg, bus, dev) 286 * @value: pointer to struct pci_busdev (seg, bus, dev)
285 *
286 */ 287 */
287static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) 288static int get_address(struct hotplug_slot *hotplug_slot, u32 *value)
288{ 289{
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index e7f41294f811..424e7de181ae 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -4,6 +4,10 @@
4 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 4 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
5 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 5 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
6 * Copyright (C) 2002,2003 NEC Corporation 6 * Copyright (C) 2002,2003 NEC Corporation
7 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
8 * Copyright (C) 2003-2005 Hewlett Packard
9 * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
10 * Copyright (C) 2005 Intel Corporation
7 * 11 *
8 * All rights reserved. 12 * All rights reserved.
9 * 13 *
@@ -26,6 +30,16 @@
26 * 30 *
27 */ 31 */
28 32
33/*
34 * Lifetime rules for pci_dev:
35 * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
36 * when the driver is loaded or when an insertion event occurs. It loses
37 * a refcount when its ejected or the driver unloads.
38 * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
39 * when the bridge is scanned and it loses a refcount when the bridge
40 * is removed.
41 */
42
29#include <linux/init.h> 43#include <linux/init.h>
30#include <linux/module.h> 44#include <linux/module.h>
31 45
@@ -178,21 +192,18 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
178 192
179 bridge->nr_slots++; 193 bridge->nr_slots++;
180 194
181 dbg("found ACPI PCI Hotplug slot at PCI %02x:%02x Slot:%d\n", 195 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
182 slot->bridge->bus, slot->device, slot->sun); 196 slot->sun, pci_domain_nr(bridge->pci_bus),
197 bridge->pci_bus->number, slot->device);
183 } 198 }
184 199
185 newfunc->slot = slot; 200 newfunc->slot = slot;
186 list_add_tail(&newfunc->sibling, &slot->funcs); 201 list_add_tail(&newfunc->sibling, &slot->funcs);
187 202
188 /* associate corresponding pci_dev */ 203 /* associate corresponding pci_dev */
189 newfunc->pci_dev = pci_find_slot(bridge->bus, 204 newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
190 PCI_DEVFN(device, function)); 205 PCI_DEVFN(device, function));
191 if (newfunc->pci_dev) { 206 if (newfunc->pci_dev) {
192 if (acpiphp_init_func_resource(newfunc) < 0) {
193 kfree(newfunc);
194 return AE_ERROR;
195 }
196 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); 207 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
197 } 208 }
198 209
@@ -227,62 +238,6 @@ static int detect_ejectable_slots(acpi_handle *bridge_handle)
227} 238}
228 239
229 240
230/* decode ACPI _CRS data and convert into our internal resource list
231 * TBD: _TRA, etc.
232 */
233static acpi_status
234decode_acpi_resource(struct acpi_resource *resource, void *context)
235{
236 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *) context;
237 struct acpi_resource_address64 address;
238 struct pci_resource *res;
239
240 if (resource->id != ACPI_RSTYPE_ADDRESS16 &&
241 resource->id != ACPI_RSTYPE_ADDRESS32 &&
242 resource->id != ACPI_RSTYPE_ADDRESS64)
243 return AE_OK;
244
245 acpi_resource_to_address64(resource, &address);
246
247 if (address.producer_consumer == ACPI_PRODUCER && address.address_length > 0) {
248 dbg("resource type: %d: 0x%llx - 0x%llx\n", address.resource_type,
249 (unsigned long long)address.min_address_range,
250 (unsigned long long)address.max_address_range);
251 res = acpiphp_make_resource(address.min_address_range,
252 address.address_length);
253 if (!res) {
254 err("out of memory\n");
255 return AE_OK;
256 }
257
258 switch (address.resource_type) {
259 case ACPI_MEMORY_RANGE:
260 if (address.attribute.memory.cache_attribute == ACPI_PREFETCHABLE_MEMORY) {
261 res->next = bridge->p_mem_head;
262 bridge->p_mem_head = res;
263 } else {
264 res->next = bridge->mem_head;
265 bridge->mem_head = res;
266 }
267 break;
268 case ACPI_IO_RANGE:
269 res->next = bridge->io_head;
270 bridge->io_head = res;
271 break;
272 case ACPI_BUS_NUMBER_RANGE:
273 res->next = bridge->bus_head;
274 bridge->bus_head = res;
275 break;
276 default:
277 /* invalid type */
278 kfree(res);
279 break;
280 }
281 }
282
283 return AE_OK;
284}
285
286/* decode ACPI 2.0 _HPP hot plug parameters */ 241/* decode ACPI 2.0 _HPP hot plug parameters */
287static void decode_hpp(struct acpiphp_bridge *bridge) 242static void decode_hpp(struct acpiphp_bridge *bridge)
288{ 243{
@@ -346,34 +301,29 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
346 /* decode ACPI 2.0 _HPP (hot plug parameters) */ 301 /* decode ACPI 2.0 _HPP (hot plug parameters) */
347 decode_hpp(bridge); 302 decode_hpp(bridge);
348 303
349 /* subtract all resources already allocated */
350 acpiphp_detect_pci_resource(bridge);
351
352 /* register all slot objects under this bridge */ 304 /* register all slot objects under this bridge */
353 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1, 305 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
354 register_slot, bridge, NULL); 306 register_slot, bridge, NULL);
355 307
356 /* install notify handler */ 308 /* install notify handler */
357 status = acpi_install_notify_handler(bridge->handle, 309 if (bridge->type != BRIDGE_TYPE_HOST) {
310 status = acpi_install_notify_handler(bridge->handle,
358 ACPI_SYSTEM_NOTIFY, 311 ACPI_SYSTEM_NOTIFY,
359 handle_hotplug_event_bridge, 312 handle_hotplug_event_bridge,
360 bridge); 313 bridge);
361 314
362 if (ACPI_FAILURE(status)) { 315 if (ACPI_FAILURE(status)) {
363 err("failed to register interrupt notify handler\n"); 316 err("failed to register interrupt notify handler\n");
317 }
364 } 318 }
365 319
366 list_add(&bridge->list, &bridge_list); 320 list_add(&bridge->list, &bridge_list);
367
368 dbg("Bridge resource:\n");
369 acpiphp_dump_resource(bridge);
370} 321}
371 322
372 323
373/* allocate and initialize host bridge data structure */ 324/* allocate and initialize host bridge data structure */
374static void add_host_bridge(acpi_handle *handle, int seg, int bus) 325static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
375{ 326{
376 acpi_status status;
377 struct acpiphp_bridge *bridge; 327 struct acpiphp_bridge *bridge;
378 328
379 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 329 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
@@ -384,52 +334,19 @@ static void add_host_bridge(acpi_handle *handle, int seg, int bus)
384 334
385 bridge->type = BRIDGE_TYPE_HOST; 335 bridge->type = BRIDGE_TYPE_HOST;
386 bridge->handle = handle; 336 bridge->handle = handle;
387 bridge->seg = seg;
388 bridge->bus = bus;
389 337
390 bridge->pci_bus = pci_find_bus(seg, bus); 338 bridge->pci_bus = pci_bus;
391 339
392 spin_lock_init(&bridge->res_lock); 340 spin_lock_init(&bridge->res_lock);
393 341
394 /* to be overridden when we decode _CRS */
395 bridge->sub = bridge->bus;
396
397 /* decode resources */
398
399 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
400 decode_acpi_resource, bridge);
401
402 if (ACPI_FAILURE(status)) {
403 err("failed to decode bridge resources\n");
404 kfree(bridge);
405 return;
406 }
407
408 acpiphp_resource_sort_and_combine(&bridge->io_head);
409 acpiphp_resource_sort_and_combine(&bridge->mem_head);
410 acpiphp_resource_sort_and_combine(&bridge->p_mem_head);
411 acpiphp_resource_sort_and_combine(&bridge->bus_head);
412
413 dbg("ACPI _CRS resource:\n");
414 acpiphp_dump_resource(bridge);
415
416 if (bridge->bus_head) {
417 bridge->bus = bridge->bus_head->base;
418 bridge->sub = bridge->bus_head->base + bridge->bus_head->length - 1;
419 }
420
421 init_bridge_misc(bridge); 342 init_bridge_misc(bridge);
422} 343}
423 344
424 345
425/* allocate and initialize PCI-to-PCI bridge data structure */ 346/* allocate and initialize PCI-to-PCI bridge data structure */
426static void add_p2p_bridge(acpi_handle *handle, int seg, int bus, int dev, int fn) 347static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
427{ 348{
428 struct acpiphp_bridge *bridge; 349 struct acpiphp_bridge *bridge;
429 u8 tmp8;
430 u16 tmp16;
431 u64 base64, limit64;
432 u32 base, limit, base32u, limit32u;
433 350
434 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 351 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
435 if (bridge == NULL) { 352 if (bridge == NULL) {
@@ -441,133 +358,22 @@ static void add_p2p_bridge(acpi_handle *handle, int seg, int bus, int dev, int f
441 358
442 bridge->type = BRIDGE_TYPE_P2P; 359 bridge->type = BRIDGE_TYPE_P2P;
443 bridge->handle = handle; 360 bridge->handle = handle;
444 bridge->seg = seg;
445
446 bridge->pci_dev = pci_find_slot(bus, PCI_DEVFN(dev, fn));
447 if (!bridge->pci_dev) {
448 err("Can't get pci_dev\n");
449 kfree(bridge);
450 return;
451 }
452 361
453 bridge->pci_bus = bridge->pci_dev->subordinate; 362 bridge->pci_dev = pci_dev_get(pci_dev);
363 bridge->pci_bus = pci_dev->subordinate;
454 if (!bridge->pci_bus) { 364 if (!bridge->pci_bus) {
455 err("This is not a PCI-to-PCI bridge!\n"); 365 err("This is not a PCI-to-PCI bridge!\n");
456 kfree(bridge); 366 goto err;
457 return;
458 } 367 }
459 368
460 spin_lock_init(&bridge->res_lock); 369 spin_lock_init(&bridge->res_lock);
461 370
462 bridge->bus = bridge->pci_bus->number;
463 bridge->sub = bridge->pci_bus->subordinate;
464
465 /*
466 * decode resources under this P2P bridge
467 */
468
469 /* I/O resources */
470 pci_read_config_byte(bridge->pci_dev, PCI_IO_BASE, &tmp8);
471 base = tmp8;
472 pci_read_config_byte(bridge->pci_dev, PCI_IO_LIMIT, &tmp8);
473 limit = tmp8;
474
475 switch (base & PCI_IO_RANGE_TYPE_MASK) {
476 case PCI_IO_RANGE_TYPE_16:
477 base = (base << 8) & 0xf000;
478 limit = ((limit << 8) & 0xf000) + 0xfff;
479 bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
480 if (!bridge->io_head) {
481 err("out of memory\n");
482 kfree(bridge);
483 return;
484 }
485 dbg("16bit I/O range: %04x-%04x\n",
486 (u32)bridge->io_head->base,
487 (u32)(bridge->io_head->base + bridge->io_head->length - 1));
488 break;
489 case PCI_IO_RANGE_TYPE_32:
490 pci_read_config_word(bridge->pci_dev, PCI_IO_BASE_UPPER16, &tmp16);
491 base = ((u32)tmp16 << 16) | ((base << 8) & 0xf000);
492 pci_read_config_word(bridge->pci_dev, PCI_IO_LIMIT_UPPER16, &tmp16);
493 limit = (((u32)tmp16 << 16) | ((limit << 8) & 0xf000)) + 0xfff;
494 bridge->io_head = acpiphp_make_resource((u64)base, limit - base + 1);
495 if (!bridge->io_head) {
496 err("out of memory\n");
497 kfree(bridge);
498 return;
499 }
500 dbg("32bit I/O range: %08x-%08x\n",
501 (u32)bridge->io_head->base,
502 (u32)(bridge->io_head->base + bridge->io_head->length - 1));
503 break;
504 case 0x0f:
505 dbg("I/O space unsupported\n");
506 break;
507 default:
508 warn("Unknown I/O range type\n");
509 }
510
511 /* Memory resources (mandatory for P2P bridge) */
512 pci_read_config_word(bridge->pci_dev, PCI_MEMORY_BASE, &tmp16);
513 base = (tmp16 & 0xfff0) << 16;
514 pci_read_config_word(bridge->pci_dev, PCI_MEMORY_LIMIT, &tmp16);
515 limit = ((tmp16 & 0xfff0) << 16) | 0xfffff;
516 bridge->mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
517 if (!bridge->mem_head) {
518 err("out of memory\n");
519 kfree(bridge);
520 return;
521 }
522 dbg("32bit Memory range: %08x-%08x\n",
523 (u32)bridge->mem_head->base,
524 (u32)(bridge->mem_head->base + bridge->mem_head->length-1));
525
526 /* Prefetchable Memory resources (optional) */
527 pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_BASE, &tmp16);
528 base = tmp16;
529 pci_read_config_word(bridge->pci_dev, PCI_PREF_MEMORY_LIMIT, &tmp16);
530 limit = tmp16;
531
532 switch (base & PCI_MEMORY_RANGE_TYPE_MASK) {
533 case PCI_PREF_RANGE_TYPE_32:
534 base = (base & 0xfff0) << 16;
535 limit = ((limit & 0xfff0) << 16) | 0xfffff;
536 bridge->p_mem_head = acpiphp_make_resource((u64)base, limit - base + 1);
537 if (!bridge->p_mem_head) {
538 err("out of memory\n");
539 kfree(bridge);
540 return;
541 }
542 dbg("32bit Prefetchable memory range: %08x-%08x\n",
543 (u32)bridge->p_mem_head->base,
544 (u32)(bridge->p_mem_head->base + bridge->p_mem_head->length - 1));
545 break;
546 case PCI_PREF_RANGE_TYPE_64:
547 pci_read_config_dword(bridge->pci_dev, PCI_PREF_BASE_UPPER32, &base32u);
548 pci_read_config_dword(bridge->pci_dev, PCI_PREF_LIMIT_UPPER32, &limit32u);
549 base64 = ((u64)base32u << 32) | ((base & 0xfff0) << 16);
550 limit64 = (((u64)limit32u << 32) | ((limit & 0xfff0) << 16)) + 0xfffff;
551
552 bridge->p_mem_head = acpiphp_make_resource(base64, limit64 - base64 + 1);
553 if (!bridge->p_mem_head) {
554 err("out of memory\n");
555 kfree(bridge);
556 return;
557 }
558 dbg("64bit Prefetchable memory range: %08x%08x-%08x%08x\n",
559 (u32)(bridge->p_mem_head->base >> 32),
560 (u32)(bridge->p_mem_head->base & 0xffffffff),
561 (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) >> 32),
562 (u32)((bridge->p_mem_head->base + bridge->p_mem_head->length - 1) & 0xffffffff));
563 break;
564 case 0x0f:
565 break;
566 default:
567 warn("Unknown prefetchale memory type\n");
568 }
569
570 init_bridge_misc(bridge); 371 init_bridge_misc(bridge);
372 return;
373 err:
374 pci_dev_put(pci_dev);
375 kfree(bridge);
376 return;
571} 377}
572 378
573 379
@@ -577,14 +383,10 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
577{ 383{
578 acpi_status status; 384 acpi_status status;
579 acpi_handle dummy_handle; 385 acpi_handle dummy_handle;
580 unsigned long *segbus = context;
581 unsigned long tmp; 386 unsigned long tmp;
582 int seg, bus, device, function; 387 int device, function;
583 struct pci_dev *dev; 388 struct pci_dev *dev;
584 389 struct pci_bus *pci_bus = context;
585 /* get PCI address */
586 seg = (*segbus >> 8) & 0xff;
587 bus = *segbus & 0xff;
588 390
589 status = acpi_get_handle(handle, "_ADR", &dummy_handle); 391 status = acpi_get_handle(handle, "_ADR", &dummy_handle);
590 if (ACPI_FAILURE(status)) 392 if (ACPI_FAILURE(status))
@@ -599,20 +401,19 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
599 device = (tmp >> 16) & 0xffff; 401 device = (tmp >> 16) & 0xffff;
600 function = tmp & 0xffff; 402 function = tmp & 0xffff;
601 403
602 dev = pci_find_slot(bus, PCI_DEVFN(device, function)); 404 dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
603 405
604 if (!dev) 406 if (!dev || !dev->subordinate)
605 return AE_OK; 407 goto out;
606
607 if (!dev->subordinate)
608 return AE_OK;
609 408
610 /* check if this bridge has ejectable slots */ 409 /* check if this bridge has ejectable slots */
611 if (detect_ejectable_slots(handle) > 0) { 410 if (detect_ejectable_slots(handle) > 0) {
612 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); 411 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
613 add_p2p_bridge(handle, seg, bus, device, function); 412 add_p2p_bridge(handle, dev);
614 } 413 }
615 414
415 out:
416 pci_dev_put(dev);
616 return AE_OK; 417 return AE_OK;
617} 418}
618 419
@@ -624,6 +425,7 @@ static int add_bridge(acpi_handle handle)
624 unsigned long tmp; 425 unsigned long tmp;
625 int seg, bus; 426 int seg, bus;
626 acpi_handle dummy_handle; 427 acpi_handle dummy_handle;
428 struct pci_bus *pci_bus;
627 429
628 /* if the bridge doesn't have _STA, we assume it is always there */ 430 /* if the bridge doesn't have _STA, we assume it is always there */
629 status = acpi_get_handle(handle, "_STA", &dummy_handle); 431 status = acpi_get_handle(handle, "_STA", &dummy_handle);
@@ -653,18 +455,22 @@ static int add_bridge(acpi_handle handle)
653 bus = 0; 455 bus = 0;
654 } 456 }
655 457
458 pci_bus = pci_find_bus(seg, bus);
459 if (!pci_bus) {
460 err("Can't find bus %04x:%02x\n", seg, bus);
461 return 0;
462 }
463
656 /* check if this bridge has ejectable slots */ 464 /* check if this bridge has ejectable slots */
657 if (detect_ejectable_slots(handle) > 0) { 465 if (detect_ejectable_slots(handle) > 0) {
658 dbg("found PCI host-bus bridge with hot-pluggable slots\n"); 466 dbg("found PCI host-bus bridge with hot-pluggable slots\n");
659 add_host_bridge(handle, seg, bus); 467 add_host_bridge(handle, pci_bus);
660 return 0; 468 return 0;
661 } 469 }
662 470
663 tmp = seg << 8 | bus;
664
665 /* search P2P bridges under this host bridge */ 471 /* search P2P bridges under this host bridge */
666 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, 472 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
667 find_p2p_bridge, &tmp, NULL); 473 find_p2p_bridge, pci_bus, NULL);
668 474
669 if (ACPI_FAILURE(status)) 475 if (ACPI_FAILURE(status))
670 warn("find_p2p_bridge faied (error code = 0x%x)\n",status); 476 warn("find_p2p_bridge faied (error code = 0x%x)\n",status);
@@ -672,12 +478,205 @@ static int add_bridge(acpi_handle handle)
672 return 0; 478 return 0;
673} 479}
674 480
481static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
482{
483 struct list_head *head;
484 list_for_each(head, &bridge_list) {
485 struct acpiphp_bridge *bridge = list_entry(head,
486 struct acpiphp_bridge, list);
487 if (bridge->handle == handle)
488 return bridge;
489 }
490
491 return NULL;
492}
493
494static void cleanup_bridge(struct acpiphp_bridge *bridge)
495{
496 struct list_head *list, *tmp;
497 struct acpiphp_slot *slot;
498 acpi_status status;
499 acpi_handle handle = bridge->handle;
500
501 status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
502 handle_hotplug_event_bridge);
503 if (ACPI_FAILURE(status))
504 err("failed to remove notify handler\n");
505
506 slot = bridge->slots;
507 while (slot) {
508 struct acpiphp_slot *next = slot->next;
509 list_for_each_safe (list, tmp, &slot->funcs) {
510 struct acpiphp_func *func;
511 func = list_entry(list, struct acpiphp_func, sibling);
512 status = acpi_remove_notify_handler(func->handle,
513 ACPI_SYSTEM_NOTIFY,
514 handle_hotplug_event_func);
515 if (ACPI_FAILURE(status))
516 err("failed to remove notify handler\n");
517 pci_dev_put(func->pci_dev);
518 list_del(list);
519 kfree(func);
520 }
521 kfree(slot);
522 slot = next;
523 }
524
525 pci_dev_put(bridge->pci_dev);
526 list_del(&bridge->list);
527 kfree(bridge);
528}
529
530static acpi_status
531cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
532{
533 struct acpiphp_bridge *bridge;
534
535 if (!(bridge = acpiphp_handle_to_bridge(handle)))
536 return AE_OK;
537 cleanup_bridge(bridge);
538 return AE_OK;
539}
675 540
676static void remove_bridge(acpi_handle handle) 541static void remove_bridge(acpi_handle handle)
677{ 542{
678 /* No-op for now .. */ 543 struct acpiphp_bridge *bridge;
544
545 bridge = acpiphp_handle_to_bridge(handle);
546 if (bridge) {
547 cleanup_bridge(bridge);
548 } else {
549 /* clean-up p2p bridges under this host bridge */
550 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
551 (u32)1, cleanup_p2p_bridge, NULL, NULL);
552 }
553}
554
555static struct pci_dev * get_apic_pci_info(acpi_handle handle)
556{
557 struct acpi_pci_id id;
558 struct pci_bus *bus;
559 struct pci_dev *dev;
560
561 if (ACPI_FAILURE(acpi_get_pci_id(handle, &id)))
562 return NULL;
563
564 bus = pci_find_bus(id.segment, id.bus);
565 if (!bus)
566 return NULL;
567
568 dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function));
569 if (!dev)
570 return NULL;
571
572 if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) &&
573 (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC))
574 {
575 pci_dev_put(dev);
576 return NULL;
577 }
578
579 return dev;
580}
581
582static int get_gsi_base(acpi_handle handle, u32 *gsi_base)
583{
584 acpi_status status;
585 int result = -1;
586 unsigned long gsb;
587 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
588 union acpi_object *obj;
589 void *table;
590
591 status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb);
592 if (ACPI_SUCCESS(status)) {
593 *gsi_base = (u32)gsb;
594 return 0;
595 }
596
597 status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer);
598 if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer)
599 return -1;
600
601 obj = buffer.pointer;
602 if (obj->type != ACPI_TYPE_BUFFER)
603 goto out;
604
605 table = obj->buffer.pointer;
606 switch (((acpi_table_entry_header *)table)->type) {
607 case ACPI_MADT_IOSAPIC:
608 *gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base;
609 result = 0;
610 break;
611 case ACPI_MADT_IOAPIC:
612 *gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base;
613 result = 0;
614 break;
615 default:
616 break;
617 }
618 out:
619 acpi_os_free(buffer.pointer);
620 return result;
621}
622
623static acpi_status
624ioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv)
625{
626 acpi_status status;
627 unsigned long sta;
628 acpi_handle tmp;
629 struct pci_dev *pdev;
630 u32 gsi_base;
631 u64 phys_addr;
632
633 /* Evaluate _STA if present */
634 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
635 if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)
636 return AE_CTRL_DEPTH;
637
638 /* Scan only PCI bus scope */
639 status = acpi_get_handle(handle, "_HID", &tmp);
640 if (ACPI_SUCCESS(status))
641 return AE_CTRL_DEPTH;
642
643 if (get_gsi_base(handle, &gsi_base))
644 return AE_OK;
645
646 pdev = get_apic_pci_info(handle);
647 if (!pdev)
648 return AE_OK;
649
650 if (pci_enable_device(pdev)) {
651 pci_dev_put(pdev);
652 return AE_OK;
653 }
654
655 pci_set_master(pdev);
656
657 if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) {
658 pci_disable_device(pdev);
659 pci_dev_put(pdev);
660 return AE_OK;
661 }
662
663 phys_addr = pci_resource_start(pdev, 0);
664 if (acpi_register_ioapic(handle, phys_addr, gsi_base)) {
665 pci_release_region(pdev, 0);
666 pci_disable_device(pdev);
667 pci_dev_put(pdev);
668 return AE_OK;
669 }
670
671 return AE_OK;
679} 672}
680 673
674static int acpiphp_configure_ioapics(acpi_handle handle)
675{
676 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
677 ACPI_UINT32_MAX, ioapic_add, NULL, NULL);
678 return 0;
679}
681 680
682static int power_on_slot(struct acpiphp_slot *slot) 681static int power_on_slot(struct acpiphp_slot *slot)
683{ 682{
@@ -719,8 +718,6 @@ static int power_off_slot(struct acpiphp_slot *slot)
719 acpi_status status; 718 acpi_status status;
720 struct acpiphp_func *func; 719 struct acpiphp_func *func;
721 struct list_head *l; 720 struct list_head *l;
722 struct acpi_object_list arg_list;
723 union acpi_object arg;
724 721
725 int retval = 0; 722 int retval = 0;
726 723
@@ -731,7 +728,7 @@ static int power_off_slot(struct acpiphp_slot *slot)
731 list_for_each (l, &slot->funcs) { 728 list_for_each (l, &slot->funcs) {
732 func = list_entry(l, struct acpiphp_func, sibling); 729 func = list_entry(l, struct acpiphp_func, sibling);
733 730
734 if (func->pci_dev && (func->flags & FUNC_HAS_PS3)) { 731 if (func->flags & FUNC_HAS_PS3) {
735 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL); 732 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
736 if (ACPI_FAILURE(status)) { 733 if (ACPI_FAILURE(status)) {
737 warn("%s: _PS3 failed\n", __FUNCTION__); 734 warn("%s: _PS3 failed\n", __FUNCTION__);
@@ -742,27 +739,6 @@ static int power_off_slot(struct acpiphp_slot *slot)
742 } 739 }
743 } 740 }
744 741
745 list_for_each (l, &slot->funcs) {
746 func = list_entry(l, struct acpiphp_func, sibling);
747
748 /* We don't want to call _EJ0 on non-existing functions. */
749 if (func->pci_dev && (func->flags & FUNC_HAS_EJ0)) {
750 /* _EJ0 method take one argument */
751 arg_list.count = 1;
752 arg_list.pointer = &arg;
753 arg.type = ACPI_TYPE_INTEGER;
754 arg.integer.value = 1;
755
756 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
757 if (ACPI_FAILURE(status)) {
758 warn("%s: _EJ0 failed\n", __FUNCTION__);
759 retval = -1;
760 goto err_exit;
761 } else
762 break;
763 }
764 }
765
766 /* TBD: evaluate _STA to check if the slot is disabled */ 742 /* TBD: evaluate _STA to check if the slot is disabled */
767 743
768 slot->flags &= (~SLOT_POWEREDON); 744 slot->flags &= (~SLOT_POWEREDON);
@@ -782,70 +758,56 @@ static int power_off_slot(struct acpiphp_slot *slot)
782 */ 758 */
783static int enable_device(struct acpiphp_slot *slot) 759static int enable_device(struct acpiphp_slot *slot)
784{ 760{
785 u8 bus;
786 struct pci_dev *dev; 761 struct pci_dev *dev;
787 struct pci_bus *child; 762 struct pci_bus *bus = slot->bridge->pci_bus;
788 struct list_head *l; 763 struct list_head *l;
789 struct acpiphp_func *func; 764 struct acpiphp_func *func;
790 int retval = 0; 765 int retval = 0;
791 int num; 766 int num, max, pass;
792 767
793 if (slot->flags & SLOT_ENABLED) 768 if (slot->flags & SLOT_ENABLED)
794 goto err_exit; 769 goto err_exit;
795 770
796 /* sanity check: dev should be NULL when hot-plugged in */ 771 /* sanity check: dev should be NULL when hot-plugged in */
797 dev = pci_find_slot(slot->bridge->bus, PCI_DEVFN(slot->device, 0)); 772 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
798 if (dev) { 773 if (dev) {
799 /* This case shouldn't happen */ 774 /* This case shouldn't happen */
800 err("pci_dev structure already exists.\n"); 775 err("pci_dev structure already exists.\n");
776 pci_dev_put(dev);
801 retval = -1; 777 retval = -1;
802 goto err_exit; 778 goto err_exit;
803 } 779 }
804 780
805 /* allocate resources to device */ 781 num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
806 retval = acpiphp_configure_slot(slot); 782 if (num == 0) {
807 if (retval)
808 goto err_exit;
809
810 /* returned `dev' is the *first function* only! */
811 num = pci_scan_slot(slot->bridge->pci_bus, PCI_DEVFN(slot->device, 0));
812 if (num)
813 pci_bus_add_devices(slot->bridge->pci_bus);
814 dev = pci_find_slot(slot->bridge->bus, PCI_DEVFN(slot->device, 0));
815
816 if (!dev) {
817 err("No new device found\n"); 783 err("No new device found\n");
818 retval = -1; 784 retval = -1;
819 goto err_exit; 785 goto err_exit;
820 } 786 }
821 787
822 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { 788 max = bus->secondary;
823 pci_read_config_byte(dev, PCI_SECONDARY_BUS, &bus); 789 for (pass = 0; pass < 2; pass++) {
824 child = (struct pci_bus*) pci_add_new_bus(dev->bus, dev, bus); 790 list_for_each_entry(dev, &bus->devices, bus_list) {
825 pci_do_scan_bus(child); 791 if (PCI_SLOT(dev->devfn) != slot->device)
792 continue;
793 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
794 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
795 max = pci_scan_bridge(bus, dev, max, pass);
796 }
826 } 797 }
827 798
799 pci_bus_assign_resources(bus);
800 pci_bus_add_devices(bus);
801
828 /* associate pci_dev to our representation */ 802 /* associate pci_dev to our representation */
829 list_for_each (l, &slot->funcs) { 803 list_for_each (l, &slot->funcs) {
830 func = list_entry(l, struct acpiphp_func, sibling); 804 func = list_entry(l, struct acpiphp_func, sibling);
831 805 func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
832 func->pci_dev = pci_find_slot(slot->bridge->bus,
833 PCI_DEVFN(slot->device,
834 func->function)); 806 func->function));
835 if (!func->pci_dev)
836 continue;
837
838 /* configure device */
839 retval = acpiphp_configure_function(func);
840 if (retval)
841 goto err_exit;
842 } 807 }
843 808
844 slot->flags |= SLOT_ENABLED; 809 slot->flags |= SLOT_ENABLED;
845 810
846 dbg("Available resources:\n");
847 acpiphp_dump_resource(slot->bridge);
848
849 err_exit: 811 err_exit:
850 return retval; 812 return retval;
851} 813}
@@ -866,9 +828,12 @@ static int disable_device(struct acpiphp_slot *slot)
866 828
867 list_for_each (l, &slot->funcs) { 829 list_for_each (l, &slot->funcs) {
868 func = list_entry(l, struct acpiphp_func, sibling); 830 func = list_entry(l, struct acpiphp_func, sibling);
831 if (!func->pci_dev)
832 continue;
869 833
870 if (func->pci_dev) 834 pci_remove_bus_device(func->pci_dev);
871 acpiphp_unconfigure_function(func); 835 pci_dev_put(func->pci_dev);
836 func->pci_dev = NULL;
872 } 837 }
873 838
874 slot->flags &= (~SLOT_ENABLED); 839 slot->flags &= (~SLOT_ENABLED);
@@ -920,6 +885,39 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
920} 885}
921 886
922/** 887/**
888 * acpiphp_eject_slot - physically eject the slot
889 */
890static int acpiphp_eject_slot(struct acpiphp_slot *slot)
891{
892 acpi_status status;
893 struct acpiphp_func *func;
894 struct list_head *l;
895 struct acpi_object_list arg_list;
896 union acpi_object arg;
897
898 list_for_each (l, &slot->funcs) {
899 func = list_entry(l, struct acpiphp_func, sibling);
900
901 /* We don't want to call _EJ0 on non-existing functions. */
902 if ((func->flags & FUNC_HAS_EJ0)) {
903 /* _EJ0 method take one argument */
904 arg_list.count = 1;
905 arg_list.pointer = &arg;
906 arg.type = ACPI_TYPE_INTEGER;
907 arg.integer.value = 1;
908
909 status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
910 if (ACPI_FAILURE(status)) {
911 warn("%s: _EJ0 failed\n", __FUNCTION__);
912 return -1;
913 } else
914 break;
915 }
916 }
917 return 0;
918}
919
920/**
923 * acpiphp_check_bridge - re-enumerate devices 921 * acpiphp_check_bridge - re-enumerate devices
924 * 922 *
925 * Iterate over all slots under this bridge and make sure that if a 923 * Iterate over all slots under this bridge and make sure that if a
@@ -942,6 +940,8 @@ static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
942 if (retval) { 940 if (retval) {
943 err("Error occurred in disabling\n"); 941 err("Error occurred in disabling\n");
944 goto err_exit; 942 goto err_exit;
943 } else {
944 acpiphp_eject_slot(slot);
945 } 945 }
946 disabled++; 946 disabled++;
947 } else { 947 } else {
@@ -962,6 +962,144 @@ static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
962 return retval; 962 return retval;
963} 963}
964 964
965static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
966{
967 u16 pci_cmd, pci_bctl;
968 struct pci_dev *cdev;
969
970 /* Program hpp values for this device */
971 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
972 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
973 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
974 return;
975 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
976 bridge->hpp.cache_line_size);
977 pci_write_config_byte(dev, PCI_LATENCY_TIMER,
978 bridge->hpp.latency_timer);
979 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
980 if (bridge->hpp.enable_SERR)
981 pci_cmd |= PCI_COMMAND_SERR;
982 else
983 pci_cmd &= ~PCI_COMMAND_SERR;
984 if (bridge->hpp.enable_PERR)
985 pci_cmd |= PCI_COMMAND_PARITY;
986 else
987 pci_cmd &= ~PCI_COMMAND_PARITY;
988 pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
989
990 /* Program bridge control value and child devices */
991 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
992 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
993 bridge->hpp.latency_timer);
994 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
995 if (bridge->hpp.enable_SERR)
996 pci_bctl |= PCI_BRIDGE_CTL_SERR;
997 else
998 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
999 if (bridge->hpp.enable_PERR)
1000 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
1001 else
1002 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
1003 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
1004 if (dev->subordinate) {
1005 list_for_each_entry(cdev, &dev->subordinate->devices,
1006 bus_list)
1007 program_hpp(cdev, bridge);
1008 }
1009 }
1010}
1011
1012static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
1013{
1014 struct acpiphp_bridge bridge;
1015 struct pci_dev *dev;
1016
1017 memset(&bridge, 0, sizeof(bridge));
1018 bridge.handle = handle;
1019 decode_hpp(&bridge);
1020 list_for_each_entry(dev, &bus->devices, bus_list)
1021 program_hpp(dev, &bridge);
1022
1023}
1024
1025/*
1026 * Remove devices for which we could not assign resources, call
1027 * arch specific code to fix-up the bus
1028 */
1029static void acpiphp_sanitize_bus(struct pci_bus *bus)
1030{
1031 struct pci_dev *dev;
1032 int i;
1033 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
1034
1035 list_for_each_entry(dev, &bus->devices, bus_list) {
1036 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
1037 struct resource *res = &dev->resource[i];
1038 if ((res->flags & type_mask) && !res->start &&
1039 res->end) {
1040 /* Could not assign a required resources
1041 * for this device, remove it */
1042 pci_remove_bus_device(dev);
1043 break;
1044 }
1045 }
1046 }
1047}
1048
1049/* Program resources in newly inserted bridge */
1050static int acpiphp_configure_bridge (acpi_handle handle)
1051{
1052 struct acpi_pci_id pci_id;
1053 struct pci_bus *bus;
1054
1055 if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {
1056 err("cannot get PCI domain and bus number for bridge\n");
1057 return -EINVAL;
1058 }
1059 bus = pci_find_bus(pci_id.segment, pci_id.bus);
1060 if (!bus) {
1061 err("cannot find bus %d:%d\n",
1062 pci_id.segment, pci_id.bus);
1063 return -EINVAL;
1064 }
1065
1066 pci_bus_size_bridges(bus);
1067 pci_bus_assign_resources(bus);
1068 acpiphp_sanitize_bus(bus);
1069 acpiphp_set_hpp_values(handle, bus);
1070 pci_enable_bridges(bus);
1071 acpiphp_configure_ioapics(handle);
1072 return 0;
1073}
1074
1075static void handle_bridge_insertion(acpi_handle handle, u32 type)
1076{
1077 struct acpi_device *device, *pdevice;
1078 acpi_handle phandle;
1079
1080 if ((type != ACPI_NOTIFY_BUS_CHECK) &&
1081 (type != ACPI_NOTIFY_DEVICE_CHECK)) {
1082 err("unexpected notification type %d\n", type);
1083 return;
1084 }
1085
1086 acpi_get_parent(handle, &phandle);
1087 if (acpi_bus_get_device(phandle, &pdevice)) {
1088 dbg("no parent device, assuming NULL\n");
1089 pdevice = NULL;
1090 }
1091 if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
1092 err("cannot add bridge to acpi list\n");
1093 return;
1094 }
1095 if (!acpiphp_configure_bridge(handle) &&
1096 !acpi_bus_start(device))
1097 add_bridge(handle);
1098 else
1099 err("cannot configure and start bridge\n");
1100
1101}
1102
965/* 1103/*
966 * ACPI event handlers 1104 * ACPI event handlers
967 */ 1105 */
@@ -982,8 +1120,19 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
982 char objname[64]; 1120 char objname[64];
983 struct acpi_buffer buffer = { .length = sizeof(objname), 1121 struct acpi_buffer buffer = { .length = sizeof(objname),
984 .pointer = objname }; 1122 .pointer = objname };
1123 struct acpi_device *device;
985 1124
986 bridge = (struct acpiphp_bridge *)context; 1125 if (acpi_bus_get_device(handle, &device)) {
1126 /* This bridge must have just been physically inserted */
1127 handle_bridge_insertion(handle, type);
1128 return;
1129 }
1130
1131 bridge = acpiphp_handle_to_bridge(handle);
1132 if (!bridge) {
1133 err("cannot get bridge info\n");
1134 return;
1135 }
987 1136
988 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 1137 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
989 1138
@@ -1031,7 +1180,6 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
1031 } 1180 }
1032} 1181}
1033 1182
1034
1035/** 1183/**
1036 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) 1184 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1037 * 1185 *
@@ -1074,7 +1222,8 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
1074 case ACPI_NOTIFY_EJECT_REQUEST: 1222 case ACPI_NOTIFY_EJECT_REQUEST:
1075 /* request device eject */ 1223 /* request device eject */
1076 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname); 1224 dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
1077 acpiphp_disable_slot(func->slot); 1225 if (!(acpiphp_disable_slot(func->slot)))
1226 acpiphp_eject_slot(func->slot);
1078 break; 1227 break;
1079 1228
1080 default: 1229 default:
@@ -1083,6 +1232,47 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
1083 } 1232 }
1084} 1233}
1085 1234
1235static int is_root_bridge(acpi_handle handle)
1236{
1237 acpi_status status;
1238 struct acpi_device_info *info;
1239 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1240 int i;
1241
1242 status = acpi_get_object_info(handle, &buffer);
1243 if (ACPI_SUCCESS(status)) {
1244 info = buffer.pointer;
1245 if ((info->valid & ACPI_VALID_HID) &&
1246 !strcmp(PCI_ROOT_HID_STRING,
1247 info->hardware_id.value)) {
1248 acpi_os_free(buffer.pointer);
1249 return 1;
1250 }
1251 if (info->valid & ACPI_VALID_CID) {
1252 for (i=0; i < info->compatibility_id.count; i++) {
1253 if (!strcmp(PCI_ROOT_HID_STRING,
1254 info->compatibility_id.id[i].value)) {
1255 acpi_os_free(buffer.pointer);
1256 return 1;
1257 }
1258 }
1259 }
1260 }
1261 return 0;
1262}
1263
1264static acpi_status
1265find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1266{
1267 int *count = (int *)context;
1268
1269 if (is_root_bridge(handle)) {
1270 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1271 handle_hotplug_event_bridge, NULL);
1272 (*count)++;
1273 }
1274 return AE_OK ;
1275}
1086 1276
1087static struct acpi_pci_driver acpi_pci_hp_driver = { 1277static struct acpi_pci_driver acpi_pci_hp_driver = {
1088 .add = add_bridge, 1278 .add = add_bridge,
@@ -1095,15 +1285,15 @@ static struct acpi_pci_driver acpi_pci_hp_driver = {
1095 */ 1285 */
1096int __init acpiphp_glue_init(void) 1286int __init acpiphp_glue_init(void)
1097{ 1287{
1098 int num; 1288 int num = 0;
1099
1100 if (list_empty(&pci_root_buses))
1101 return -1;
1102 1289
1103 num = acpi_pci_register_driver(&acpi_pci_hp_driver); 1290 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1291 ACPI_UINT32_MAX, find_root_bridges, &num, NULL);
1104 1292
1105 if (num <= 0) 1293 if (num <= 0)
1106 return -1; 1294 return -1;
1295 else
1296 acpi_pci_register_driver(&acpi_pci_hp_driver);
1107 1297
1108 return 0; 1298 return 0;
1109} 1299}
@@ -1116,46 +1306,6 @@ int __init acpiphp_glue_init(void)
1116 */ 1306 */
1117void __exit acpiphp_glue_exit(void) 1307void __exit acpiphp_glue_exit(void)
1118{ 1308{
1119 struct list_head *l1, *l2, *n1, *n2;
1120 struct acpiphp_bridge *bridge;
1121 struct acpiphp_slot *slot, *next;
1122 struct acpiphp_func *func;
1123 acpi_status status;
1124
1125 list_for_each_safe (l1, n1, &bridge_list) {
1126 bridge = (struct acpiphp_bridge *)l1;
1127 slot = bridge->slots;
1128 while (slot) {
1129 next = slot->next;
1130 list_for_each_safe (l2, n2, &slot->funcs) {
1131 func = list_entry(l2, struct acpiphp_func, sibling);
1132 acpiphp_free_resource(&func->io_head);
1133 acpiphp_free_resource(&func->mem_head);
1134 acpiphp_free_resource(&func->p_mem_head);
1135 acpiphp_free_resource(&func->bus_head);
1136 status = acpi_remove_notify_handler(func->handle,
1137 ACPI_SYSTEM_NOTIFY,
1138 handle_hotplug_event_func);
1139 if (ACPI_FAILURE(status))
1140 err("failed to remove notify handler\n");
1141 kfree(func);
1142 }
1143 kfree(slot);
1144 slot = next;
1145 }
1146 status = acpi_remove_notify_handler(bridge->handle, ACPI_SYSTEM_NOTIFY,
1147 handle_hotplug_event_bridge);
1148 if (ACPI_FAILURE(status))
1149 err("failed to remove notify handler\n");
1150
1151 acpiphp_free_resource(&bridge->io_head);
1152 acpiphp_free_resource(&bridge->mem_head);
1153 acpiphp_free_resource(&bridge->p_mem_head);
1154 acpiphp_free_resource(&bridge->bus_head);
1155
1156 kfree(bridge);
1157 }
1158
1159 acpi_pci_unregister_driver(&acpi_pci_hp_driver); 1309 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1160} 1310}
1161 1311
@@ -1173,11 +1323,14 @@ int __init acpiphp_get_num_slots(void)
1173 1323
1174 list_for_each (node, &bridge_list) { 1324 list_for_each (node, &bridge_list) {
1175 bridge = (struct acpiphp_bridge *)node; 1325 bridge = (struct acpiphp_bridge *)node;
1176 dbg("Bus%d %dslot(s)\n", bridge->bus, bridge->nr_slots); 1326 dbg("Bus %04x:%02x has %d slot%s\n",
1327 pci_domain_nr(bridge->pci_bus),
1328 bridge->pci_bus->number, bridge->nr_slots,
1329 bridge->nr_slots == 1 ? "" : "s");
1177 num_slots += bridge->nr_slots; 1330 num_slots += bridge->nr_slots;
1178 } 1331 }
1179 1332
1180 dbg("Total %dslots\n", num_slots); 1333 dbg("Total %d slots\n", num_slots);
1181 return num_slots; 1334 return num_slots;
1182} 1335}
1183 1336
@@ -1254,7 +1407,6 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot)
1254 return retval; 1407 return retval;
1255} 1408}
1256 1409
1257
1258/** 1410/**
1259 * acpiphp_disable_slot - power off slot 1411 * acpiphp_disable_slot - power off slot
1260 */ 1412 */
@@ -1274,13 +1426,6 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1274 if (retval) 1426 if (retval)
1275 goto err_exit; 1427 goto err_exit;
1276 1428
1277 acpiphp_resource_sort_and_combine(&slot->bridge->io_head);
1278 acpiphp_resource_sort_and_combine(&slot->bridge->mem_head);
1279 acpiphp_resource_sort_and_combine(&slot->bridge->p_mem_head);
1280 acpiphp_resource_sort_and_combine(&slot->bridge->bus_head);
1281 dbg("Available resources:\n");
1282 acpiphp_dump_resource(slot->bridge);
1283
1284 err_exit: 1429 err_exit:
1285 up(&slot->crit_sect); 1430 up(&slot->crit_sect);
1286 return retval; 1431 return retval;
@@ -1293,11 +1438,7 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1293 */ 1438 */
1294u8 acpiphp_get_power_status(struct acpiphp_slot *slot) 1439u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1295{ 1440{
1296 unsigned int sta; 1441 return (slot->flags & SLOT_POWEREDON);
1297
1298 sta = get_slot_status(slot);
1299
1300 return (sta & ACPI_STA_ENABLED) ? 1 : 0;
1301} 1442}
1302 1443
1303 1444
@@ -1335,9 +1476,10 @@ u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1335u32 acpiphp_get_address(struct acpiphp_slot *slot) 1476u32 acpiphp_get_address(struct acpiphp_slot *slot)
1336{ 1477{
1337 u32 address; 1478 u32 address;
1479 struct pci_bus *pci_bus = slot->bridge->pci_bus;
1338 1480
1339 address = ((slot->bridge->seg) << 16) | 1481 address = (pci_domain_nr(pci_bus) << 16) |
1340 ((slot->bridge->bus) << 8) | 1482 (pci_bus->number << 8) |
1341 slot->device; 1483 slot->device;
1342 1484
1343 return address; 1485 return address;
diff --git a/drivers/pci/hotplug/acpiphp_pci.c b/drivers/pci/hotplug/acpiphp_pci.c
deleted file mode 100644
index 54d97c9d1dff..000000000000
--- a/drivers/pci/hotplug/acpiphp_pci.c
+++ /dev/null
@@ -1,449 +0,0 @@
1/*
2 * ACPI PCI HotPlug PCI configuration space management
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001,2002 IBM Corp.
7 * Copyright (C) 2002 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
8 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
9 * Copyright (C) 2002 NEC Corporation
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or (at
16 * your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21 * NON INFRINGEMENT. See the GNU General Public License for more
22 * details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Send feedback to <t-kochi@bq.jp.nec.com>
29 *
30 */
31
32#include <linux/init.h>
33#include <linux/module.h>
34
35#include <linux/kernel.h>
36#include <linux/pci.h>
37#include <linux/acpi.h>
38#include "../pci.h"
39#include "pci_hotplug.h"
40#include "acpiphp.h"
41
42#define MY_NAME "acpiphp_pci"
43
44
45/* allocate mem/pmem/io resource to a new function */
46static int init_config_space (struct acpiphp_func *func)
47{
48 u32 bar, len;
49 u32 address[] = {
50 PCI_BASE_ADDRESS_0,
51 PCI_BASE_ADDRESS_1,
52 PCI_BASE_ADDRESS_2,
53 PCI_BASE_ADDRESS_3,
54 PCI_BASE_ADDRESS_4,
55 PCI_BASE_ADDRESS_5,
56 0
57 };
58 int count;
59 struct acpiphp_bridge *bridge;
60 struct pci_resource *res;
61 struct pci_bus *pbus;
62 int bus, device, function;
63 unsigned int devfn;
64 u16 tmp;
65
66 bridge = func->slot->bridge;
67 pbus = bridge->pci_bus;
68 bus = bridge->bus;
69 device = func->slot->device;
70 function = func->function;
71 devfn = PCI_DEVFN(device, function);
72
73 for (count = 0; address[count]; count++) { /* for 6 BARs */
74 pci_bus_write_config_dword(pbus, devfn,
75 address[count], 0xFFFFFFFF);
76 pci_bus_read_config_dword(pbus, devfn, address[count], &bar);
77
78 if (!bar) /* This BAR is not implemented */
79 continue;
80
81 dbg("Device %02x.%02x BAR %d wants %x\n", device, function, count, bar);
82
83 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
84 /* This is IO */
85
86 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
87 len = len & ~(len - 1);
88
89 dbg("len in IO %x, BAR %d\n", len, count);
90
91 spin_lock(&bridge->res_lock);
92 res = acpiphp_get_io_resource(&bridge->io_head, len);
93 spin_unlock(&bridge->res_lock);
94
95 if (!res) {
96 err("cannot allocate requested io for %02x:%02x.%d len %x\n",
97 bus, device, function, len);
98 return -1;
99 }
100 pci_bus_write_config_dword(pbus, devfn,
101 address[count],
102 (u32)res->base);
103 res->next = func->io_head;
104 func->io_head = res;
105
106 } else {
107 /* This is Memory */
108 if (bar & PCI_BASE_ADDRESS_MEM_PREFETCH) {
109 /* pfmem */
110
111 len = bar & 0xFFFFFFF0;
112 len = ~len + 1;
113
114 dbg("len in PFMEM %x, BAR %d\n", len, count);
115
116 spin_lock(&bridge->res_lock);
117 res = acpiphp_get_resource(&bridge->p_mem_head, len);
118 spin_unlock(&bridge->res_lock);
119
120 if (!res) {
121 err("cannot allocate requested pfmem for %02x:%02x.%d len %x\n",
122 bus, device, function, len);
123 return -1;
124 }
125
126 pci_bus_write_config_dword(pbus, devfn,
127 address[count],
128 (u32)res->base);
129
130 if (bar & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
131 dbg("inside the pfmem 64 case, count %d\n", count);
132 count += 1;
133 pci_bus_write_config_dword(pbus, devfn,
134 address[count],
135 (u32)(res->base >> 32));
136 }
137
138 res->next = func->p_mem_head;
139 func->p_mem_head = res;
140
141 } else {
142 /* regular memory */
143
144 len = bar & 0xFFFFFFF0;
145 len = ~len + 1;
146
147 dbg("len in MEM %x, BAR %d\n", len, count);
148
149 spin_lock(&bridge->res_lock);
150 res = acpiphp_get_resource(&bridge->mem_head, len);
151 spin_unlock(&bridge->res_lock);
152
153 if (!res) {
154 err("cannot allocate requested pfmem for %02x:%02x.%d len %x\n",
155 bus, device, function, len);
156 return -1;
157 }
158
159 pci_bus_write_config_dword(pbus, devfn,
160 address[count],
161 (u32)res->base);
162
163 if (bar & PCI_BASE_ADDRESS_MEM_TYPE_64) {
164 /* takes up another dword */
165 dbg("inside mem 64 case, reg. mem, count %d\n", count);
166 count += 1;
167 pci_bus_write_config_dword(pbus, devfn,
168 address[count],
169 (u32)(res->base >> 32));
170 }
171
172 res->next = func->mem_head;
173 func->mem_head = res;
174
175 }
176 }
177 }
178
179 /* disable expansion rom */
180 pci_bus_write_config_dword(pbus, devfn, PCI_ROM_ADDRESS, 0x00000000);
181
182 /* set PCI parameters from _HPP */
183 pci_bus_write_config_byte(pbus, devfn, PCI_CACHE_LINE_SIZE,
184 bridge->hpp.cache_line_size);
185 pci_bus_write_config_byte(pbus, devfn, PCI_LATENCY_TIMER,
186 bridge->hpp.latency_timer);
187
188 pci_bus_read_config_word(pbus, devfn, PCI_COMMAND, &tmp);
189 if (bridge->hpp.enable_SERR)
190 tmp |= PCI_COMMAND_SERR;
191 if (bridge->hpp.enable_PERR)
192 tmp |= PCI_COMMAND_PARITY;
193 pci_bus_write_config_word(pbus, devfn, PCI_COMMAND, tmp);
194
195 return 0;
196}
197
198/* detect_used_resource - subtract resource under dev from bridge */
199static int detect_used_resource (struct acpiphp_bridge *bridge, struct pci_dev *dev)
200{
201 int count;
202
203 dbg("Device %s\n", pci_name(dev));
204
205 for (count = 0; count < DEVICE_COUNT_RESOURCE; count++) {
206 struct pci_resource *res;
207 struct pci_resource **head;
208 unsigned long base = dev->resource[count].start;
209 unsigned long len = dev->resource[count].end - base + 1;
210 unsigned long flags = dev->resource[count].flags;
211
212 if (!flags)
213 continue;
214
215 dbg("BAR[%d] 0x%lx - 0x%lx (0x%lx)\n", count, base,
216 base + len - 1, flags);
217
218 if (flags & IORESOURCE_IO) {
219 head = &bridge->io_head;
220 } else if (flags & IORESOURCE_PREFETCH) {
221 head = &bridge->p_mem_head;
222 } else {
223 head = &bridge->mem_head;
224 }
225
226 spin_lock(&bridge->res_lock);
227 res = acpiphp_get_resource_with_base(head, base, len);
228 spin_unlock(&bridge->res_lock);
229 if (res)
230 kfree(res);
231 }
232
233 return 0;
234}
235
236
237/**
238 * acpiphp_detect_pci_resource - detect resources under bridge
239 * @bridge: detect all resources already used under this bridge
240 *
241 * collect all resources already allocated for all devices under a bridge.
242 */
243int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge)
244{
245 struct list_head *l;
246 struct pci_dev *dev;
247
248 list_for_each (l, &bridge->pci_bus->devices) {
249 dev = pci_dev_b(l);
250 detect_used_resource(bridge, dev);
251 }
252
253 return 0;
254}
255
256
257/**
258 * acpiphp_init_slot_resource - gather resource usage information of a slot
259 * @slot: ACPI slot object to be checked, should have valid pci_dev member
260 *
261 * TBD: PCI-to-PCI bridge case
262 * use pci_dev->resource[]
263 */
264int acpiphp_init_func_resource (struct acpiphp_func *func)
265{
266 u64 base;
267 u32 bar, len;
268 u32 address[] = {
269 PCI_BASE_ADDRESS_0,
270 PCI_BASE_ADDRESS_1,
271 PCI_BASE_ADDRESS_2,
272 PCI_BASE_ADDRESS_3,
273 PCI_BASE_ADDRESS_4,
274 PCI_BASE_ADDRESS_5,
275 0
276 };
277 int count;
278 struct pci_resource *res;
279 struct pci_dev *dev;
280
281 dev = func->pci_dev;
282 dbg("Hot-pluggable device %s\n", pci_name(dev));
283
284 for (count = 0; address[count]; count++) { /* for 6 BARs */
285 pci_read_config_dword(dev, address[count], &bar);
286
287 if (!bar) /* This BAR is not implemented */
288 continue;
289
290 pci_write_config_dword(dev, address[count], 0xFFFFFFFF);
291 pci_read_config_dword(dev, address[count], &len);
292
293 if (len & PCI_BASE_ADDRESS_SPACE_IO) {
294 /* This is IO */
295 base = bar & 0xFFFFFFFC;
296 len = len & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
297 len = len & ~(len - 1);
298
299 dbg("BAR[%d] %08x - %08x (IO)\n", count, (u32)base, (u32)base + len - 1);
300
301 res = acpiphp_make_resource(base, len);
302 if (!res)
303 goto no_memory;
304
305 res->next = func->io_head;
306 func->io_head = res;
307
308 } else {
309 /* This is Memory */
310 base = bar & 0xFFFFFFF0;
311 if (len & PCI_BASE_ADDRESS_MEM_PREFETCH) {
312 /* pfmem */
313
314 len &= 0xFFFFFFF0;
315 len = ~len + 1;
316
317 if (len & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
318 dbg("prefetch mem 64\n");
319 count += 1;
320 }
321 dbg("BAR[%d] %08x - %08x (PMEM)\n", count, (u32)base, (u32)base + len - 1);
322 res = acpiphp_make_resource(base, len);
323 if (!res)
324 goto no_memory;
325
326 res->next = func->p_mem_head;
327 func->p_mem_head = res;
328
329 } else {
330 /* regular memory */
331
332 len &= 0xFFFFFFF0;
333 len = ~len + 1;
334
335 if (len & PCI_BASE_ADDRESS_MEM_TYPE_64) {
336 /* takes up another dword */
337 dbg("mem 64\n");
338 count += 1;
339 }
340 dbg("BAR[%d] %08x - %08x (MEM)\n", count, (u32)base, (u32)base + len - 1);
341 res = acpiphp_make_resource(base, len);
342 if (!res)
343 goto no_memory;
344
345 res->next = func->mem_head;
346 func->mem_head = res;
347
348 }
349 }
350
351 pci_write_config_dword(dev, address[count], bar);
352 }
353#if 1
354 acpiphp_dump_func_resource(func);
355#endif
356
357 return 0;
358
359 no_memory:
360 err("out of memory\n");
361 acpiphp_free_resource(&func->io_head);
362 acpiphp_free_resource(&func->mem_head);
363 acpiphp_free_resource(&func->p_mem_head);
364
365 return -1;
366}
367
368
369/**
370 * acpiphp_configure_slot - allocate PCI resources
371 * @slot: slot to be configured
372 *
373 * initializes a PCI functions on a device inserted
374 * into the slot
375 *
376 */
377int acpiphp_configure_slot (struct acpiphp_slot *slot)
378{
379 struct acpiphp_func *func;
380 struct list_head *l;
381 u8 hdr;
382 u32 dvid;
383 int retval = 0;
384 int is_multi = 0;
385
386 pci_bus_read_config_byte(slot->bridge->pci_bus,
387 PCI_DEVFN(slot->device, 0),
388 PCI_HEADER_TYPE, &hdr);
389
390 if (hdr & 0x80)
391 is_multi = 1;
392
393 list_for_each (l, &slot->funcs) {
394 func = list_entry(l, struct acpiphp_func, sibling);
395 if (is_multi || func->function == 0) {
396 pci_bus_read_config_dword(slot->bridge->pci_bus,
397 PCI_DEVFN(slot->device,
398 func->function),
399 PCI_VENDOR_ID, &dvid);
400 if (dvid != 0xffffffff) {
401 retval = init_config_space(func);
402 if (retval)
403 break;
404 }
405 }
406 }
407
408 return retval;
409}
410
411/**
412 * acpiphp_configure_function - configure PCI function
413 * @func: function to be configured
414 *
415 * initializes a PCI functions on a device inserted
416 * into the slot
417 *
418 */
419int acpiphp_configure_function (struct acpiphp_func *func)
420{
421 /* all handled by the pci core now */
422 return 0;
423}
424
425/**
426 * acpiphp_unconfigure_function - unconfigure PCI function
427 * @func: function to be unconfigured
428 *
429 */
430void acpiphp_unconfigure_function (struct acpiphp_func *func)
431{
432 struct acpiphp_bridge *bridge;
433
434 /* if pci_dev is NULL, ignore it */
435 if (!func->pci_dev)
436 return;
437
438 pci_remove_bus_device(func->pci_dev);
439
440 /* free all resources */
441 bridge = func->slot->bridge;
442
443 spin_lock(&bridge->res_lock);
444 acpiphp_move_resource(&func->io_head, &bridge->io_head);
445 acpiphp_move_resource(&func->mem_head, &bridge->mem_head);
446 acpiphp_move_resource(&func->p_mem_head, &bridge->p_mem_head);
447 acpiphp_move_resource(&func->bus_head, &bridge->bus_head);
448 spin_unlock(&bridge->res_lock);
449}
diff --git a/drivers/pci/hotplug/acpiphp_res.c b/drivers/pci/hotplug/acpiphp_res.c
deleted file mode 100644
index f54b1fa7b75a..000000000000
--- a/drivers/pci/hotplug/acpiphp_res.c
+++ /dev/null
@@ -1,700 +0,0 @@
1/*
2 * ACPI PCI HotPlug Utility functions
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8 * Copyright (C) 2002 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9 * Copyright (C) 2002 NEC Corporation
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or (at
16 * your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21 * NON INFRINGEMENT. See the GNU General Public License for more
22 * details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Send feedback to <gregkh@us.ibm.com>, <t-kochi@bq.jp.nec.com>
29 *
30 */
31
32#include <linux/init.h>
33#include <linux/module.h>
34
35#include <linux/kernel.h>
36#include <linux/types.h>
37#include <linux/proc_fs.h>
38#include <linux/sysctl.h>
39#include <linux/pci.h>
40#include <linux/smp.h>
41#include <linux/smp_lock.h>
42
43#include <linux/string.h>
44#include <linux/mm.h>
45#include <linux/errno.h>
46#include <linux/ioport.h>
47#include <linux/slab.h>
48#include <linux/interrupt.h>
49#include <linux/timer.h>
50
51#include <linux/ioctl.h>
52#include <linux/fcntl.h>
53
54#include <linux/list.h>
55
56#include "pci_hotplug.h"
57#include "acpiphp.h"
58
59#define MY_NAME "acpiphp_res"
60
61
62/*
63 * sort_by_size - sort nodes by their length, smallest first
64 */
65static int sort_by_size(struct pci_resource **head)
66{
67 struct pci_resource *current_res;
68 struct pci_resource *next_res;
69 int out_of_order = 1;
70
71 if (!(*head))
72 return 1;
73
74 if (!((*head)->next))
75 return 0;
76
77 while (out_of_order) {
78 out_of_order = 0;
79
80 /* Special case for swapping list head */
81 if (((*head)->next) &&
82 ((*head)->length > (*head)->next->length)) {
83 out_of_order++;
84 current_res = *head;
85 *head = (*head)->next;
86 current_res->next = (*head)->next;
87 (*head)->next = current_res;
88 }
89
90 current_res = *head;
91
92 while (current_res->next && current_res->next->next) {
93 if (current_res->next->length > current_res->next->next->length) {
94 out_of_order++;
95 next_res = current_res->next;
96 current_res->next = current_res->next->next;
97 current_res = current_res->next;
98 next_res->next = current_res->next;
99 current_res->next = next_res;
100 } else
101 current_res = current_res->next;
102 }
103 } /* End of out_of_order loop */
104
105 return 0;
106}
107
108#if 0
109/*
110 * sort_by_max_size - sort nodes by their length, largest first
111 */
112static int sort_by_max_size(struct pci_resource **head)
113{
114 struct pci_resource *current_res;
115 struct pci_resource *next_res;
116 int out_of_order = 1;
117
118 if (!(*head))
119 return 1;
120
121 if (!((*head)->next))
122 return 0;
123
124 while (out_of_order) {
125 out_of_order = 0;
126
127 /* Special case for swapping list head */
128 if (((*head)->next) &&
129 ((*head)->length < (*head)->next->length)) {
130 out_of_order++;
131 current_res = *head;
132 *head = (*head)->next;
133 current_res->next = (*head)->next;
134 (*head)->next = current_res;
135 }
136
137 current_res = *head;
138
139 while (current_res->next && current_res->next->next) {
140 if (current_res->next->length < current_res->next->next->length) {
141 out_of_order++;
142 next_res = current_res->next;
143 current_res->next = current_res->next->next;
144 current_res = current_res->next;
145 next_res->next = current_res->next;
146 current_res->next = next_res;
147 } else
148 current_res = current_res->next;
149 }
150 } /* End of out_of_order loop */
151
152 return 0;
153}
154#endif
155
156/**
157 * get_io_resource - get resource for I/O ports
158 *
159 * this function sorts the resource list by size and then
160 * returns the first node of "size" length that is not in the
161 * ISA aliasing window. If it finds a node larger than "size"
162 * it will split it up.
163 *
164 * size must be a power of two.
165 *
166 * difference from get_resource is handling of ISA aliasing space.
167 *
168 */
169struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size)
170{
171 struct pci_resource *prevnode;
172 struct pci_resource *node;
173 struct pci_resource *split_node;
174 u64 temp_qword;
175
176 if (!(*head))
177 return NULL;
178
179 if (acpiphp_resource_sort_and_combine(head))
180 return NULL;
181
182 if (sort_by_size(head))
183 return NULL;
184
185 for (node = *head; node; node = node->next) {
186 if (node->length < size)
187 continue;
188
189 if (node->base & (size - 1)) {
190 /* this one isn't base aligned properly
191 so we'll make a new entry and split it up */
192 temp_qword = (node->base | (size-1)) + 1;
193
194 /* Short circuit if adjusted size is too small */
195 if ((node->length - (temp_qword - node->base)) < size)
196 continue;
197
198 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
199
200 if (!split_node)
201 return NULL;
202
203 node->base = temp_qword;
204 node->length -= split_node->length;
205
206 /* Put it in the list */
207 split_node->next = node->next;
208 node->next = split_node;
209 } /* End of non-aligned base */
210
211 /* Don't need to check if too small since we already did */
212 if (node->length > size) {
213 /* this one is longer than we need
214 so we'll make a new entry and split it up */
215 split_node = acpiphp_make_resource(node->base + size, node->length - size);
216
217 if (!split_node)
218 return NULL;
219
220 node->length = size;
221
222 /* Put it in the list */
223 split_node->next = node->next;
224 node->next = split_node;
225 } /* End of too big on top end */
226
227 /* For IO make sure it's not in the ISA aliasing space */
228 if ((node->base & 0x300L) && !(node->base & 0xfffff000))
229 continue;
230
231 /* If we got here, then it is the right size
232 Now take it out of the list */
233 if (*head == node) {
234 *head = node->next;
235 } else {
236 prevnode = *head;
237 while (prevnode->next != node)
238 prevnode = prevnode->next;
239
240 prevnode->next = node->next;
241 }
242 node->next = NULL;
243 /* Stop looping */
244 break;
245 }
246
247 return node;
248}
249
250
251#if 0
252/**
253 * get_max_resource - get the largest resource
254 *
255 * Gets the largest node that is at least "size" big from the
256 * list pointed to by head. It aligns the node on top and bottom
257 * to "size" alignment before returning it.
258 */
259static struct pci_resource *acpiphp_get_max_resource (struct pci_resource **head, u32 size)
260{
261 struct pci_resource *max;
262 struct pci_resource *temp;
263 struct pci_resource *split_node;
264 u64 temp_qword;
265
266 if (!(*head))
267 return NULL;
268
269 if (acpiphp_resource_sort_and_combine(head))
270 return NULL;
271
272 if (sort_by_max_size(head))
273 return NULL;
274
275 for (max = *head;max; max = max->next) {
276
277 /* If not big enough we could probably just bail,
278 instead we'll continue to the next. */
279 if (max->length < size)
280 continue;
281
282 if (max->base & (size - 1)) {
283 /* this one isn't base aligned properly
284 so we'll make a new entry and split it up */
285 temp_qword = (max->base | (size-1)) + 1;
286
287 /* Short circuit if adjusted size is too small */
288 if ((max->length - (temp_qword - max->base)) < size)
289 continue;
290
291 split_node = acpiphp_make_resource(max->base, temp_qword - max->base);
292
293 if (!split_node)
294 return NULL;
295
296 max->base = temp_qword;
297 max->length -= split_node->length;
298
299 /* Put it next in the list */
300 split_node->next = max->next;
301 max->next = split_node;
302 }
303
304 if ((max->base + max->length) & (size - 1)) {
305 /* this one isn't end aligned properly at the top
306 so we'll make a new entry and split it up */
307 temp_qword = ((max->base + max->length) & ~(size - 1));
308
309 split_node = acpiphp_make_resource(temp_qword,
310 max->length + max->base - temp_qword);
311
312 if (!split_node)
313 return NULL;
314
315 max->length -= split_node->length;
316
317 /* Put it in the list */
318 split_node->next = max->next;
319 max->next = split_node;
320 }
321
322 /* Make sure it didn't shrink too much when we aligned it */
323 if (max->length < size)
324 continue;
325
326 /* Now take it out of the list */
327 temp = (struct pci_resource*) *head;
328 if (temp == max) {
329 *head = max->next;
330 } else {
331 while (temp && temp->next != max) {
332 temp = temp->next;
333 }
334
335 temp->next = max->next;
336 }
337
338 max->next = NULL;
339 return max;
340 }
341
342 /* If we get here, we couldn't find one */
343 return NULL;
344}
345#endif
346
347/**
348 * get_resource - get resource (mem, pfmem)
349 *
350 * this function sorts the resource list by size and then
351 * returns the first node of "size" length. If it finds a node
352 * larger than "size" it will split it up.
353 *
354 * size must be a power of two.
355 *
356 */
357struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size)
358{
359 struct pci_resource *prevnode;
360 struct pci_resource *node;
361 struct pci_resource *split_node;
362 u64 temp_qword;
363
364 if (!(*head))
365 return NULL;
366
367 if (acpiphp_resource_sort_and_combine(head))
368 return NULL;
369
370 if (sort_by_size(head))
371 return NULL;
372
373 for (node = *head; node; node = node->next) {
374 dbg("%s: req_size =%x node=%p, base=%x, length=%x\n",
375 __FUNCTION__, size, node, (u32)node->base, node->length);
376 if (node->length < size)
377 continue;
378
379 if (node->base & (size - 1)) {
380 dbg("%s: not aligned\n", __FUNCTION__);
381 /* this one isn't base aligned properly
382 so we'll make a new entry and split it up */
383 temp_qword = (node->base | (size-1)) + 1;
384
385 /* Short circuit if adjusted size is too small */
386 if ((node->length - (temp_qword - node->base)) < size)
387 continue;
388
389 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
390
391 if (!split_node)
392 return NULL;
393
394 node->base = temp_qword;
395 node->length -= split_node->length;
396
397 /* Put it in the list */
398 split_node->next = node->next;
399 node->next = split_node;
400 } /* End of non-aligned base */
401
402 /* Don't need to check if too small since we already did */
403 if (node->length > size) {
404 dbg("%s: too big\n", __FUNCTION__);
405 /* this one is longer than we need
406 so we'll make a new entry and split it up */
407 split_node = acpiphp_make_resource(node->base + size, node->length - size);
408
409 if (!split_node)
410 return NULL;
411
412 node->length = size;
413
414 /* Put it in the list */
415 split_node->next = node->next;
416 node->next = split_node;
417 } /* End of too big on top end */
418
419 dbg("%s: got one!!!\n", __FUNCTION__);
420 /* If we got here, then it is the right size
421 Now take it out of the list */
422 if (*head == node) {
423 *head = node->next;
424 } else {
425 prevnode = *head;
426 while (prevnode->next != node)
427 prevnode = prevnode->next;
428
429 prevnode->next = node->next;
430 }
431 node->next = NULL;
432 /* Stop looping */
433 break;
434 }
435 return node;
436}
437
438/**
439 * get_resource_with_base - get resource with specific base address
440 *
441 * this function
442 * returns the first node of "size" length located at specified base address.
443 * If it finds a node larger than "size" it will split it up.
444 *
445 * size must be a power of two.
446 *
447 */
448struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size)
449{
450 struct pci_resource *prevnode;
451 struct pci_resource *node;
452 struct pci_resource *split_node;
453 u64 temp_qword;
454
455 if (!(*head))
456 return NULL;
457
458 if (acpiphp_resource_sort_and_combine(head))
459 return NULL;
460
461 for (node = *head; node; node = node->next) {
462 dbg(": 1st req_base=%x req_size =%x node=%p, base=%x, length=%x\n",
463 (u32)base, size, node, (u32)node->base, node->length);
464 if (node->base > base)
465 continue;
466
467 if ((node->base + node->length) < (base + size))
468 continue;
469
470 if (node->base < base) {
471 dbg(": split 1\n");
472 /* this one isn't base aligned properly
473 so we'll make a new entry and split it up */
474 temp_qword = base;
475
476 /* Short circuit if adjusted size is too small */
477 if ((node->length - (temp_qword - node->base)) < size)
478 continue;
479
480 split_node = acpiphp_make_resource(node->base, temp_qword - node->base);
481
482 if (!split_node)
483 return NULL;
484
485 node->base = temp_qword;
486 node->length -= split_node->length;
487
488 /* Put it in the list */
489 split_node->next = node->next;
490 node->next = split_node;
491 }
492
493 dbg(": 2nd req_base=%x req_size =%x node=%p, base=%x, length=%x\n",
494 (u32)base, size, node, (u32)node->base, node->length);
495
496 /* Don't need to check if too small since we already did */
497 if (node->length > size) {
498 dbg(": split 2\n");
499 /* this one is longer than we need
500 so we'll make a new entry and split it up */
501 split_node = acpiphp_make_resource(node->base + size, node->length - size);
502
503 if (!split_node)
504 return NULL;
505
506 node->length = size;
507
508 /* Put it in the list */
509 split_node->next = node->next;
510 node->next = split_node;
511 } /* End of too big on top end */
512
513 dbg(": got one!!!\n");
514 /* If we got here, then it is the right size
515 Now take it out of the list */
516 if (*head == node) {
517 *head = node->next;
518 } else {
519 prevnode = *head;
520 while (prevnode->next != node)
521 prevnode = prevnode->next;
522
523 prevnode->next = node->next;
524 }
525 node->next = NULL;
526 /* Stop looping */
527 break;
528 }
529 return node;
530}
531
532
533/**
534 * acpiphp_resource_sort_and_combine
535 *
536 * Sorts all of the nodes in the list in ascending order by
537 * their base addresses. Also does garbage collection by
538 * combining adjacent nodes.
539 *
540 * returns 0 if success
541 */
542int acpiphp_resource_sort_and_combine (struct pci_resource **head)
543{
544 struct pci_resource *node1;
545 struct pci_resource *node2;
546 int out_of_order = 1;
547
548 if (!(*head))
549 return 1;
550
551 dbg("*head->next = %p\n",(*head)->next);
552
553 if (!(*head)->next)
554 return 0; /* only one item on the list, already sorted! */
555
556 dbg("*head->base = 0x%x\n",(u32)(*head)->base);
557 dbg("*head->next->base = 0x%x\n", (u32)(*head)->next->base);
558 while (out_of_order) {
559 out_of_order = 0;
560
561 /* Special case for swapping list head */
562 if (((*head)->next) &&
563 ((*head)->base > (*head)->next->base)) {
564 node1 = *head;
565 (*head) = (*head)->next;
566 node1->next = (*head)->next;
567 (*head)->next = node1;
568 out_of_order++;
569 }
570
571 node1 = (*head);
572
573 while (node1->next && node1->next->next) {
574 if (node1->next->base > node1->next->next->base) {
575 out_of_order++;
576 node2 = node1->next;
577 node1->next = node1->next->next;
578 node1 = node1->next;
579 node2->next = node1->next;
580 node1->next = node2;
581 } else
582 node1 = node1->next;
583 }
584 } /* End of out_of_order loop */
585
586 node1 = *head;
587
588 while (node1 && node1->next) {
589 if ((node1->base + node1->length) == node1->next->base) {
590 /* Combine */
591 dbg("8..\n");
592 node1->length += node1->next->length;
593 node2 = node1->next;
594 node1->next = node1->next->next;
595 kfree(node2);
596 } else
597 node1 = node1->next;
598 }
599
600 return 0;
601}
602
603
604/**
605 * acpiphp_make_resource - make resource structure
606 * @base: base address of a resource
607 * @length: length of a resource
608 */
609struct pci_resource *acpiphp_make_resource (u64 base, u32 length)
610{
611 struct pci_resource *res;
612
613 res = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
614 if (res) {
615 memset(res, 0, sizeof(struct pci_resource));
616 res->base = base;
617 res->length = length;
618 }
619
620 return res;
621}
622
623
624/**
625 * acpiphp_move_resource - move linked resources from one to another
626 * @from: head of linked resource list
627 * @to: head of linked resource list
628 */
629void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to)
630{
631 struct pci_resource *tmp;
632
633 while (*from) {
634 tmp = (*from)->next;
635 (*from)->next = *to;
636 *to = *from;
637 *from = tmp;
638 }
639
640 /* *from = NULL is guaranteed */
641}
642
643
644/**
645 * acpiphp_free_resource - free all linked resources
646 * @res: head of linked resource list
647 */
648void acpiphp_free_resource (struct pci_resource **res)
649{
650 struct pci_resource *tmp;
651
652 while (*res) {
653 tmp = (*res)->next;
654 kfree(*res);
655 *res = tmp;
656 }
657
658 /* *res = NULL is guaranteed */
659}
660
661
662/* debug support functions; will go away sometime :) */
663static void dump_resource(struct pci_resource *head)
664{
665 struct pci_resource *p;
666 int cnt;
667
668 p = head;
669 cnt = 0;
670
671 while (p) {
672 dbg("[%02d] %08x - %08x\n",
673 cnt++, (u32)p->base, (u32)p->base + p->length - 1);
674 p = p->next;
675 }
676}
677
678void acpiphp_dump_resource(struct acpiphp_bridge *bridge)
679{
680 dbg("I/O resource:\n");
681 dump_resource(bridge->io_head);
682 dbg("MEM resource:\n");
683 dump_resource(bridge->mem_head);
684 dbg("PMEM resource:\n");
685 dump_resource(bridge->p_mem_head);
686 dbg("BUS resource:\n");
687 dump_resource(bridge->bus_head);
688}
689
690void acpiphp_dump_func_resource(struct acpiphp_func *func)
691{
692 dbg("I/O resource:\n");
693 dump_resource(func->io_head);
694 dbg("MEM resource:\n");
695 dump_resource(func->mem_head);
696 dbg("PMEM resource:\n");
697 dump_resource(func->p_mem_head);
698 dbg("BUS resource:\n");
699 dump_resource(func->bus_head);
700}
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index afbccfa5217d..8c6d3987d461 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -60,6 +60,7 @@ static void __iomem *smbios_start;
60static void __iomem *cpqhp_rom_start; 60static void __iomem *cpqhp_rom_start;
61static int power_mode; 61static int power_mode;
62static int debug; 62static int debug;
63static int initialized;
63 64
64#define DRIVER_VERSION "0.9.8" 65#define DRIVER_VERSION "0.9.8"
65#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>" 66#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
@@ -1271,7 +1272,6 @@ static int one_time_init(void)
1271{ 1272{
1272 int loop; 1273 int loop;
1273 int retval = 0; 1274 int retval = 0;
1274 static int initialized = 0;
1275 1275
1276 if (initialized) 1276 if (initialized)
1277 return 0; 1277 return 0;
@@ -1441,7 +1441,8 @@ static void __exit unload_cpqphpd(void)
1441 } 1441 }
1442 1442
1443 // Stop the notification mechanism 1443 // Stop the notification mechanism
1444 cpqhp_event_stop_thread(); 1444 if (initialized)
1445 cpqhp_event_stop_thread();
1445 1446
1446 //unmap the rom address 1447 //unmap the rom address
1447 if (cpqhp_rom_start) 1448 if (cpqhp_rom_start)
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
new file mode 100644
index 000000000000..323041fd41dc
--- /dev/null
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -0,0 +1,611 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2005 Silicon Graphics, Inc. All rights reserved.
7 *
8 * This work was based on the 2.4/2.6 kernel development by Dick Reigner.
9 * Work to add BIOS PROM support was completed by Mike Habeck.
10 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/pci.h>
16#include <linux/proc_fs.h>
17#include <linux/types.h>
18
19#include <asm/sn/addrs.h>
20#include <asm/sn/l1.h>
21#include <asm/sn/module.h>
22#include <asm/sn/pcibr_provider.h>
23#include <asm/sn/pcibus_provider_defs.h>
24#include <asm/sn/pcidev.h>
25#include <asm/sn/sn_sal.h>
26#include <asm/sn/types.h>
27
28#include "../pci.h"
29#include "pci_hotplug.h"
30
31MODULE_LICENSE("GPL");
32MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)");
33MODULE_DESCRIPTION("SGI Altix Hot Plug PCI Controller Driver");
34
35#define PCIIO_ASIC_TYPE_TIOCA 4
36#define PCI_SLOT_ALREADY_UP 2 /* slot already up */
37#define PCI_SLOT_ALREADY_DOWN 3 /* slot already down */
38#define PCI_L1_ERR 7 /* L1 console command error */
39#define PCI_EMPTY_33MHZ 15 /* empty 33 MHz bus */
40#define PCI_L1_QSIZE 128 /* our L1 message buffer size */
41#define SN_MAX_HP_SLOTS 32 /* max number of hotplug slots */
42#define SGI_HOTPLUG_PROM_REV 0x0420 /* Min. required PROM version */
43
44/* internal list head */
45static struct list_head sn_hp_list;
46
47/* hotplug_slot struct's private pointer */
48struct slot {
49 int device_num;
50 struct pci_bus *pci_bus;
51 /* this struct for glue internal only */
52 struct hotplug_slot *hotplug_slot;
53 struct list_head hp_list;
54};
55
56struct pcibr_slot_enable_resp {
57 int resp_sub_errno;
58 char resp_l1_msg[PCI_L1_QSIZE + 1];
59};
60
61struct pcibr_slot_disable_resp {
62 int resp_sub_errno;
63 char resp_l1_msg[PCI_L1_QSIZE + 1];
64};
65
66enum sn_pci_req_e {
67 PCI_REQ_SLOT_ELIGIBLE,
68 PCI_REQ_SLOT_DISABLE
69};
70
71static int enable_slot(struct hotplug_slot *slot);
72static int disable_slot(struct hotplug_slot *slot);
73static int get_power_status(struct hotplug_slot *slot, u8 *value);
74
75static struct hotplug_slot_ops sn_hotplug_slot_ops = {
76 .owner = THIS_MODULE,
77 .enable_slot = enable_slot,
78 .disable_slot = disable_slot,
79 .get_power_status = get_power_status,
80};
81
82static DECLARE_MUTEX(sn_hotplug_sem);
83
84static int sn_pci_slot_valid(struct pci_bus *pci_bus, int device)
85{
86 struct pcibus_info *pcibus_info;
87 int bricktype;
88 int bus_num;
89
90 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus);
91
92 /* Check to see if this is a valid slot on 'pci_bus' */
93 if (!(pcibus_info->pbi_valid_devices & (1 << device)))
94 return -EPERM;
95
96 bricktype = MODULE_GET_BTYPE(pcibus_info->pbi_moduleid);
97 bus_num = pcibus_info->pbi_buscommon.bs_persist_busnum & 0xf;
98
99 /* Do not allow hotplug operations on base I/O cards */
100 if ((bricktype == L1_BRICKTYPE_IX || bricktype == L1_BRICKTYPE_IA) &&
101 (bus_num == 1 && device != 1))
102 return -EPERM;
103
104 return 1;
105}
106
107static int sn_pci_bus_valid(struct pci_bus *pci_bus)
108{
109 struct pcibus_info *pcibus_info;
110 int asic_type;
111 int bricktype;
112
113 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus);
114
115 /* Don't register slots hanging off the TIOCA bus */
116 asic_type = pcibus_info->pbi_buscommon.bs_asic_type;
117 if (asic_type == PCIIO_ASIC_TYPE_TIOCA)
118 return -EPERM;
119
120 /* Only register slots in I/O Bricks that support hotplug */
121 bricktype = MODULE_GET_BTYPE(pcibus_info->pbi_moduleid);
122 switch (bricktype) {
123 case L1_BRICKTYPE_IX:
124 case L1_BRICKTYPE_PX:
125 case L1_BRICKTYPE_IA:
126 case L1_BRICKTYPE_PA:
127 return 1;
128 break;
129 default:
130 return -EPERM;
131 break;
132 }
133
134 return -EIO;
135}
136
137static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot,
138 struct pci_bus *pci_bus, int device)
139{
140 struct pcibus_info *pcibus_info;
141 struct slot *slot;
142
143 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus);
144
145 bss_hotplug_slot->private = kcalloc(1, sizeof(struct slot),
146 GFP_KERNEL);
147 if (!bss_hotplug_slot->private)
148 return -ENOMEM;
149 slot = (struct slot *)bss_hotplug_slot->private;
150
151 bss_hotplug_slot->name = kmalloc(33, GFP_KERNEL);
152 if (!bss_hotplug_slot->name) {
153 kfree(bss_hotplug_slot->private);
154 return -ENOMEM;
155 }
156
157 slot->device_num = device;
158 slot->pci_bus = pci_bus;
159
160 sprintf(bss_hotplug_slot->name, "module_%c%c%c%c%.2d_b_%d_s_%d",
161 '0'+RACK_GET_CLASS(MODULE_GET_RACK(pcibus_info->pbi_moduleid)),
162 '0'+RACK_GET_GROUP(MODULE_GET_RACK(pcibus_info->pbi_moduleid)),
163 '0'+RACK_GET_NUM(MODULE_GET_RACK(pcibus_info->pbi_moduleid)),
164 MODULE_GET_BTCHAR(pcibus_info->pbi_moduleid),
165 MODULE_GET_BPOS(pcibus_info->pbi_moduleid),
166 ((int)pcibus_info->pbi_buscommon.bs_persist_busnum) & 0xf,
167 device + 1);
168
169 slot->hotplug_slot = bss_hotplug_slot;
170 list_add(&slot->hp_list, &sn_hp_list);
171
172 return 0;
173}
174
175static struct hotplug_slot * sn_hp_destroy(void)
176{
177 struct slot *slot;
178 struct list_head *list;
179 struct hotplug_slot *bss_hotplug_slot = NULL;
180
181 list_for_each(list, &sn_hp_list) {
182 slot = list_entry(list, struct slot, hp_list);
183 bss_hotplug_slot = slot->hotplug_slot;
184 list_del(&((struct slot *)bss_hotplug_slot->private)->
185 hp_list);
186 break;
187 }
188 return bss_hotplug_slot;
189}
190
191static void sn_bus_alloc_data(struct pci_dev *dev)
192{
193 struct list_head *node;
194 struct pci_bus *subordinate_bus;
195 struct pci_dev *child;
196
197 sn_pci_fixup_slot(dev);
198
199 /* Recursively sets up the sn_irq_info structs */
200 if (dev->subordinate) {
201 subordinate_bus = dev->subordinate;
202 list_for_each(node, &subordinate_bus->devices) {
203 child = list_entry(node, struct pci_dev, bus_list);
204 sn_bus_alloc_data(child);
205 }
206 }
207}
208
209static void sn_bus_free_data(struct pci_dev *dev)
210{
211 struct list_head *node;
212 struct pci_bus *subordinate_bus;
213 struct pci_dev *child;
214
215 /* Recursively clean up sn_irq_info structs */
216 if (dev->subordinate) {
217 subordinate_bus = dev->subordinate;
218 list_for_each(node, &subordinate_bus->devices) {
219 child = list_entry(node, struct pci_dev, bus_list);
220 sn_bus_free_data(child);
221 }
222 }
223 sn_pci_unfixup_slot(dev);
224}
225
226static u8 sn_power_status_get(struct hotplug_slot *bss_hotplug_slot)
227{
228 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
229 struct pcibus_info *pcibus_info;
230 u8 retval;
231
232 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
233 retval = pcibus_info->pbi_enabled_devices & (1 << slot->device_num);
234
235 return retval ? 1 : 0;
236}
237
238static void sn_slot_mark_enable(struct hotplug_slot *bss_hotplug_slot,
239 int device_num)
240{
241 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
242 struct pcibus_info *pcibus_info;
243
244 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
245 pcibus_info->pbi_enabled_devices |= (1 << device_num);
246}
247
248static void sn_slot_mark_disable(struct hotplug_slot *bss_hotplug_slot,
249 int device_num)
250{
251 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
252 struct pcibus_info *pcibus_info;
253
254 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
255 pcibus_info->pbi_enabled_devices &= ~(1 << device_num);
256}
257
258static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
259 int device_num)
260{
261 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
262 struct pcibus_info *pcibus_info;
263 struct pcibr_slot_enable_resp resp;
264 int rc;
265
266 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
267
268 /*
269 * Power-on and initialize the slot in the SN
270 * PCI infrastructure.
271 */
272 rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp);
273
274 if (rc == PCI_SLOT_ALREADY_UP) {
275 dev_dbg(slot->pci_bus->self, "is already active\n");
276 return -EPERM;
277 }
278
279 if (rc == PCI_L1_ERR) {
280 dev_dbg(slot->pci_bus->self,
281 "L1 failure %d with message: %s",
282 resp.resp_sub_errno, resp.resp_l1_msg);
283 return -EPERM;
284 }
285
286 if (rc) {
287 dev_dbg(slot->pci_bus->self,
288 "insert failed with error %d sub-error %d\n",
289 rc, resp.resp_sub_errno);
290 return -EIO;
291 }
292
293 sn_slot_mark_enable(bss_hotplug_slot, device_num);
294
295 return 0;
296}
297
298static int sn_slot_disable(struct hotplug_slot *bss_hotplug_slot,
299 int device_num, int action)
300{
301 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
302 struct pcibus_info *pcibus_info;
303 struct pcibr_slot_disable_resp resp;
304 int rc;
305
306 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
307
308 rc = sal_pcibr_slot_disable(pcibus_info, device_num, action, &resp);
309
310 if (action == PCI_REQ_SLOT_ELIGIBLE && rc == PCI_SLOT_ALREADY_DOWN) {
311 dev_dbg(slot->pci_bus->self, "Slot %s already inactive\n");
312 return -ENODEV;
313 }
314
315 if (action == PCI_REQ_SLOT_ELIGIBLE && rc == PCI_EMPTY_33MHZ) {
316 dev_dbg(slot->pci_bus->self,
317 "Cannot remove last 33MHz card\n");
318 return -EPERM;
319 }
320
321 if (action == PCI_REQ_SLOT_ELIGIBLE && rc == PCI_L1_ERR) {
322 dev_dbg(slot->pci_bus->self,
323 "L1 failure %d with message \n%s\n",
324 resp.resp_sub_errno, resp.resp_l1_msg);
325 return -EPERM;
326 }
327
328 if (action == PCI_REQ_SLOT_ELIGIBLE && rc) {
329 dev_dbg(slot->pci_bus->self,
330 "remove failed with error %d sub-error %d\n",
331 rc, resp.resp_sub_errno);
332 return -EIO;
333 }
334
335 if (action == PCI_REQ_SLOT_ELIGIBLE && !rc)
336 return 0;
337
338 if (action == PCI_REQ_SLOT_DISABLE && !rc) {
339 sn_slot_mark_disable(bss_hotplug_slot, device_num);
340 dev_dbg(slot->pci_bus->self, "remove successful\n");
341 return 0;
342 }
343
344 if (action == PCI_REQ_SLOT_DISABLE && rc) {
345 dev_dbg(slot->pci_bus->self,"remove failed rc = %d\n", rc);
346 return rc;
347 }
348
349 return rc;
350}
351
352static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
353{
354 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
355 struct pci_bus *new_bus = NULL;
356 struct pci_dev *dev;
357 int func, num_funcs;
358 int new_ppb = 0;
359 int rc;
360
361 /* Serialize the Linux PCI infrastructure */
362 down(&sn_hotplug_sem);
363
364 /*
365 * Power-on and initialize the slot in the SN
366 * PCI infrastructure.
367 */
368 rc = sn_slot_enable(bss_hotplug_slot, slot->device_num);
369 if (rc) {
370 up(&sn_hotplug_sem);
371 return rc;
372 }
373
374 num_funcs = pci_scan_slot(slot->pci_bus, PCI_DEVFN(slot->device_num+1,
375 PCI_FUNC(0)));
376 if (!num_funcs) {
377 dev_dbg(slot->pci_bus->self, "no device in slot\n");
378 up(&sn_hotplug_sem);
379 return -ENODEV;
380 }
381
382 sn_pci_controller_fixup(pci_domain_nr(slot->pci_bus),
383 slot->pci_bus->number,
384 slot->pci_bus);
385 /*
386 * Map SN resources for all functions on the card
387 * to the Linux PCI interface and tell the drivers
388 * about them.
389 */
390 for (func = 0; func < num_funcs; func++) {
391 dev = pci_get_slot(slot->pci_bus,
392 PCI_DEVFN(slot->device_num + 1,
393 PCI_FUNC(func)));
394
395
396 if (dev) {
397 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
398 unsigned char sec_bus;
399 pci_read_config_byte(dev, PCI_SECONDARY_BUS,
400 &sec_bus);
401 new_bus = pci_add_new_bus(dev->bus, dev,
402 sec_bus);
403 pci_scan_child_bus(new_bus);
404 sn_pci_controller_fixup(pci_domain_nr(new_bus),
405 new_bus->number,
406 new_bus);
407 new_ppb = 1;
408 }
409 sn_bus_alloc_data(dev);
410 pci_dev_put(dev);
411 }
412 }
413
414 /* Call the driver for the new device */
415 pci_bus_add_devices(slot->pci_bus);
416 /* Call the drivers for the new devices subordinate to PPB */
417 if (new_ppb)
418 pci_bus_add_devices(new_bus);
419
420 up(&sn_hotplug_sem);
421
422 if (rc == 0)
423 dev_dbg(slot->pci_bus->self,
424 "insert operation successful\n");
425 else
426 dev_dbg(slot->pci_bus->self,
427 "insert operation failed rc = %d\n", rc);
428
429 return rc;
430}
431
432static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
433{
434 struct slot *slot = (struct slot *)bss_hotplug_slot->private;
435 struct pci_dev *dev;
436 int func;
437 int rc;
438
439 /* Acquire update access to the bus */
440 down(&sn_hotplug_sem);
441
442 /* is it okay to bring this slot down? */
443 rc = sn_slot_disable(bss_hotplug_slot, slot->device_num,
444 PCI_REQ_SLOT_ELIGIBLE);
445 if (rc)
446 goto leaving;
447
448 /* Free the SN resources assigned to the Linux device.*/
449 for (func = 0; func < 8; func++) {
450 dev = pci_get_slot(slot->pci_bus,
451 PCI_DEVFN(slot->device_num+1,
452 PCI_FUNC(func)));
453 if (dev) {
454 /*
455 * Some drivers may use dma accesses during the
456 * driver remove function. We release the sysdata
457 * areas after the driver remove functions have
458 * been called.
459 */
460 sn_bus_store_sysdata(dev);
461 sn_bus_free_data(dev);
462 pci_remove_bus_device(dev);
463 pci_dev_put(dev);
464 }
465 }
466
467 /* free the collected sysdata pointers */
468 sn_bus_free_sysdata();
469
470 /* Deactivate slot */
471 rc = sn_slot_disable(bss_hotplug_slot, slot->device_num,
472 PCI_REQ_SLOT_DISABLE);
473 leaving:
474 /* Release the bus lock */
475 up(&sn_hotplug_sem);
476
477 return rc;
478}
479
480static int get_power_status(struct hotplug_slot *bss_hotplug_slot, u8 *value)
481{
482 down(&sn_hotplug_sem);
483 *value = sn_power_status_get(bss_hotplug_slot);
484 up(&sn_hotplug_sem);
485 return 0;
486}
487
488static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot)
489{
490 kfree(bss_hotplug_slot->info);
491 kfree(bss_hotplug_slot->name);
492 kfree(bss_hotplug_slot->private);
493 kfree(bss_hotplug_slot);
494}
495
496static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
497{
498 int device;
499 struct hotplug_slot *bss_hotplug_slot;
500 int rc = 0;
501
502 /*
503 * Currently only four devices are supported,
504 * in the future there maybe more -- up to 32.
505 */
506
507 for (device = 0; device < SN_MAX_HP_SLOTS ; device++) {
508 if (sn_pci_slot_valid(pci_bus, device) != 1)
509 continue;
510
511 bss_hotplug_slot = kcalloc(1,sizeof(struct hotplug_slot),
512 GFP_KERNEL);
513 if (!bss_hotplug_slot) {
514 rc = -ENOMEM;
515 goto alloc_err;
516 }
517
518 bss_hotplug_slot->info =
519 kcalloc(1,sizeof(struct hotplug_slot_info),
520 GFP_KERNEL);
521 if (!bss_hotplug_slot->info) {
522 rc = -ENOMEM;
523 goto alloc_err;
524 }
525
526 if (sn_hp_slot_private_alloc(bss_hotplug_slot,
527 pci_bus, device)) {
528 rc = -ENOMEM;
529 goto alloc_err;
530 }
531
532 bss_hotplug_slot->ops = &sn_hotplug_slot_ops;
533 bss_hotplug_slot->release = &sn_release_slot;
534
535 rc = pci_hp_register(bss_hotplug_slot);
536 if (rc)
537 goto register_err;
538 }
539 dev_dbg(pci_bus->self, "Registered bus with hotplug\n");
540 return rc;
541
542register_err:
543 dev_dbg(pci_bus->self, "bus failed to register with err = %d\n",
544 rc);
545
546alloc_err:
547 if (rc == -ENOMEM)
548 dev_dbg(pci_bus->self, "Memory allocation error\n");
549
550 /* destroy THIS element */
551 if (bss_hotplug_slot)
552 sn_release_slot(bss_hotplug_slot);
553
554 /* destroy anything else on the list */
555 while ((bss_hotplug_slot = sn_hp_destroy()))
556 pci_hp_deregister(bss_hotplug_slot);
557
558 return rc;
559}
560
561static int sn_pci_hotplug_init(void)
562{
563 struct pci_bus *pci_bus = NULL;
564 int rc;
565 int registered = 0;
566
567 INIT_LIST_HEAD(&sn_hp_list);
568
569 if (sn_sal_rev() < SGI_HOTPLUG_PROM_REV) {
570 printk(KERN_ERR "%s: PROM version must be greater than 4.05\n",
571 __FUNCTION__);
572 return -EPERM;
573 }
574
575 while ((pci_bus = pci_find_next_bus(pci_bus))) {
576 if (!pci_bus->sysdata)
577 continue;
578
579 rc = sn_pci_bus_valid(pci_bus);
580 if (rc != 1) {
581 dev_dbg(pci_bus->self, "not a valid hotplug bus\n");
582 continue;
583 }
584 dev_dbg(pci_bus->self, "valid hotplug bus\n");
585
586 rc = sn_hotplug_slot_register(pci_bus);
587 if (!rc)
588 registered = 1;
589 else {
590 registered = 0;
591 break;
592 }
593 }
594
595 return registered == 1 ? 0 : -ENODEV;
596}
597
598static void sn_pci_hotplug_exit(void)
599{
600 struct hotplug_slot *bss_hotplug_slot;
601
602 while ((bss_hotplug_slot = sn_hp_destroy())) {
603 pci_hp_deregister(bss_hotplug_slot);
604 }
605
606 if (!list_empty(&sn_hp_list))
607 printk(KERN_ERR "%s: internal list is not empty\n", __FILE__);
608}
609
610module_init(sn_pci_hotplug_init);
611module_exit(sn_pci_hotplug_exit);
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 30206ac43c44..b5ab9aa6ff7c 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -28,10 +28,10 @@ static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL };
28static kmem_cache_t* msi_cachep; 28static kmem_cache_t* msi_cachep;
29 29
30static int pci_msi_enable = 1; 30static int pci_msi_enable = 1;
31static int last_alloc_vector = 0; 31static int last_alloc_vector;
32static int nr_released_vectors = 0; 32static int nr_released_vectors;
33static int nr_reserved_vectors = NR_HP_RESERVED_VECTORS; 33static int nr_reserved_vectors = NR_HP_RESERVED_VECTORS;
34static int nr_msix_devices = 0; 34static int nr_msix_devices;
35 35
36#ifndef CONFIG_X86_IO_APIC 36#ifndef CONFIG_X86_IO_APIC
37int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1}; 37int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1};
@@ -170,44 +170,30 @@ static unsigned int startup_msi_irq_wo_maskbit(unsigned int vector)
170 return 0; /* never anything pending */ 170 return 0; /* never anything pending */
171} 171}
172 172
173static void release_msi(unsigned int vector); 173static unsigned int startup_msi_irq_w_maskbit(unsigned int vector)
174static void shutdown_msi_irq(unsigned int vector)
175{
176 release_msi(vector);
177}
178
179#define shutdown_msi_irq_wo_maskbit shutdown_msi_irq
180static void enable_msi_irq_wo_maskbit(unsigned int vector) {}
181static void disable_msi_irq_wo_maskbit(unsigned int vector) {}
182static void ack_msi_irq_wo_maskbit(unsigned int vector) {}
183static void end_msi_irq_wo_maskbit(unsigned int vector)
184{ 174{
185 move_msi(vector); 175 startup_msi_irq_wo_maskbit(vector);
186 ack_APIC_irq(); 176 unmask_MSI_irq(vector);
177 return 0; /* never anything pending */
187} 178}
188 179
189static unsigned int startup_msi_irq_w_maskbit(unsigned int vector) 180static void shutdown_msi_irq(unsigned int vector)
190{ 181{
191 struct msi_desc *entry; 182 struct msi_desc *entry;
192 unsigned long flags; 183 unsigned long flags;
193 184
194 spin_lock_irqsave(&msi_lock, flags); 185 spin_lock_irqsave(&msi_lock, flags);
195 entry = msi_desc[vector]; 186 entry = msi_desc[vector];
196 if (!entry || !entry->dev) { 187 if (entry && entry->dev)
197 spin_unlock_irqrestore(&msi_lock, flags); 188 entry->msi_attrib.state = 0; /* Mark it not active */
198 return 0;
199 }
200 entry->msi_attrib.state = 1; /* Mark it active */
201 spin_unlock_irqrestore(&msi_lock, flags); 189 spin_unlock_irqrestore(&msi_lock, flags);
202
203 unmask_MSI_irq(vector);
204 return 0; /* never anything pending */
205} 190}
206 191
207#define shutdown_msi_irq_w_maskbit shutdown_msi_irq 192static void end_msi_irq_wo_maskbit(unsigned int vector)
208#define enable_msi_irq_w_maskbit unmask_MSI_irq 193{
209#define disable_msi_irq_w_maskbit mask_MSI_irq 194 move_msi(vector);
210#define ack_msi_irq_w_maskbit mask_MSI_irq 195 ack_APIC_irq();
196}
211 197
212static void end_msi_irq_w_maskbit(unsigned int vector) 198static void end_msi_irq_w_maskbit(unsigned int vector)
213{ 199{
@@ -216,6 +202,10 @@ static void end_msi_irq_w_maskbit(unsigned int vector)
216 ack_APIC_irq(); 202 ack_APIC_irq();
217} 203}
218 204
205static void do_nothing(unsigned int vector)
206{
207}
208
219/* 209/*
220 * Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices, 210 * Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices,
221 * which implement the MSI-X Capability Structure. 211 * which implement the MSI-X Capability Structure.
@@ -223,10 +213,10 @@ static void end_msi_irq_w_maskbit(unsigned int vector)
223static struct hw_interrupt_type msix_irq_type = { 213static struct hw_interrupt_type msix_irq_type = {
224 .typename = "PCI-MSI-X", 214 .typename = "PCI-MSI-X",
225 .startup = startup_msi_irq_w_maskbit, 215 .startup = startup_msi_irq_w_maskbit,
226 .shutdown = shutdown_msi_irq_w_maskbit, 216 .shutdown = shutdown_msi_irq,
227 .enable = enable_msi_irq_w_maskbit, 217 .enable = unmask_MSI_irq,
228 .disable = disable_msi_irq_w_maskbit, 218 .disable = mask_MSI_irq,
229 .ack = ack_msi_irq_w_maskbit, 219 .ack = mask_MSI_irq,
230 .end = end_msi_irq_w_maskbit, 220 .end = end_msi_irq_w_maskbit,
231 .set_affinity = set_msi_irq_affinity 221 .set_affinity = set_msi_irq_affinity
232}; 222};
@@ -239,10 +229,10 @@ static struct hw_interrupt_type msix_irq_type = {
239static struct hw_interrupt_type msi_irq_w_maskbit_type = { 229static struct hw_interrupt_type msi_irq_w_maskbit_type = {
240 .typename = "PCI-MSI", 230 .typename = "PCI-MSI",
241 .startup = startup_msi_irq_w_maskbit, 231 .startup = startup_msi_irq_w_maskbit,
242 .shutdown = shutdown_msi_irq_w_maskbit, 232 .shutdown = shutdown_msi_irq,
243 .enable = enable_msi_irq_w_maskbit, 233 .enable = unmask_MSI_irq,
244 .disable = disable_msi_irq_w_maskbit, 234 .disable = mask_MSI_irq,
245 .ack = ack_msi_irq_w_maskbit, 235 .ack = mask_MSI_irq,
246 .end = end_msi_irq_w_maskbit, 236 .end = end_msi_irq_w_maskbit,
247 .set_affinity = set_msi_irq_affinity 237 .set_affinity = set_msi_irq_affinity
248}; 238};
@@ -255,10 +245,10 @@ static struct hw_interrupt_type msi_irq_w_maskbit_type = {
255static struct hw_interrupt_type msi_irq_wo_maskbit_type = { 245static struct hw_interrupt_type msi_irq_wo_maskbit_type = {
256 .typename = "PCI-MSI", 246 .typename = "PCI-MSI",
257 .startup = startup_msi_irq_wo_maskbit, 247 .startup = startup_msi_irq_wo_maskbit,
258 .shutdown = shutdown_msi_irq_wo_maskbit, 248 .shutdown = shutdown_msi_irq,
259 .enable = enable_msi_irq_wo_maskbit, 249 .enable = do_nothing,
260 .disable = disable_msi_irq_wo_maskbit, 250 .disable = do_nothing,
261 .ack = ack_msi_irq_wo_maskbit, 251 .ack = do_nothing,
262 .end = end_msi_irq_wo_maskbit, 252 .end = end_msi_irq_wo_maskbit,
263 .set_affinity = set_msi_irq_affinity 253 .set_affinity = set_msi_irq_affinity
264}; 254};
@@ -407,7 +397,7 @@ static struct msi_desc* alloc_msi_entry(void)
407{ 397{
408 struct msi_desc *entry; 398 struct msi_desc *entry;
409 399
410 entry = (struct msi_desc*) kmem_cache_alloc(msi_cachep, SLAB_KERNEL); 400 entry = kmem_cache_alloc(msi_cachep, SLAB_KERNEL);
411 if (!entry) 401 if (!entry)
412 return NULL; 402 return NULL;
413 403
@@ -796,18 +786,6 @@ void pci_disable_msi(struct pci_dev* dev)
796 } 786 }
797} 787}
798 788
799static void release_msi(unsigned int vector)
800{
801 struct msi_desc *entry;
802 unsigned long flags;
803
804 spin_lock_irqsave(&msi_lock, flags);
805 entry = msi_desc[vector];
806 if (entry && entry->dev)
807 entry->msi_attrib.state = 0; /* Mark it not active */
808 spin_unlock_irqrestore(&msi_lock, flags);
809}
810
811static int msi_free_vector(struct pci_dev* dev, int vector, int reassign) 789static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
812{ 790{
813 struct msi_desc *entry; 791 struct msi_desc *entry;
@@ -924,7 +902,7 @@ static int reroute_msix_table(int head, struct msix_entry *entries, int *nvec)
924/** 902/**
925 * pci_enable_msix - configure device's MSI-X capability structure 903 * pci_enable_msix - configure device's MSI-X capability structure
926 * @dev: pointer to the pci_dev data structure of MSI-X device function 904 * @dev: pointer to the pci_dev data structure of MSI-X device function
927 * @data: pointer to an array of MSI-X entries 905 * @entries: pointer to an array of MSI-X entries
928 * @nvec: number of MSI-X vectors requested for allocation by device driver 906 * @nvec: number of MSI-X vectors requested for allocation by device driver
929 * 907 *
930 * Setup the MSI-X capability structure of device function with the number 908 * Setup the MSI-X capability structure of device function with the number
diff --git a/drivers/pci/msi.h b/drivers/pci/msi.h
index bef21ae3cbd0..390f1851c0f1 100644
--- a/drivers/pci/msi.h
+++ b/drivers/pci/msi.h
@@ -41,11 +41,11 @@ static inline void move_msi(int vector) {}
41#define PCI_MSIX_FLAGS_BIRMASK (7 << 0) 41#define PCI_MSIX_FLAGS_BIRMASK (7 << 0)
42#define PCI_MSIX_FLAGS_BITMASK (1 << 0) 42#define PCI_MSIX_FLAGS_BITMASK (1 << 0)
43 43
44#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
45#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
46#define PCI_MSIX_ENTRY_DATA_OFFSET 8
47#define PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET 12
48#define PCI_MSIX_ENTRY_SIZE 16 44#define PCI_MSIX_ENTRY_SIZE 16
45#define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
46#define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
47#define PCI_MSIX_ENTRY_DATA_OFFSET 8
48#define PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET 12
49 49
50#define msi_control_reg(base) (base + PCI_MSI_FLAGS) 50#define msi_control_reg(base) (base + PCI_MSI_FLAGS)
51#define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO) 51#define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO)
@@ -64,7 +64,6 @@ static inline void move_msi(int vector) {}
64#define msi_enable(control, num) multi_msi_enable(control, num); \ 64#define msi_enable(control, num) multi_msi_enable(control, num); \
65 control |= PCI_MSI_FLAGS_ENABLE 65 control |= PCI_MSI_FLAGS_ENABLE
66 66
67#define msix_control_reg msi_control_reg
68#define msix_table_offset_reg(base) (base + 0x04) 67#define msix_table_offset_reg(base) (base + 0x04)
69#define msix_pba_offset_reg(base) (base + 0x08) 68#define msix_pba_offset_reg(base) (base + 0x08)
70#define msix_enable(control) control |= PCI_MSIX_FLAGS_ENABLE 69#define msix_enable(control) control |= PCI_MSIX_FLAGS_ENABLE
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index bc01d34e2634..e9e37abe1f76 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * File: pci-acpi.c 2 * File: pci-acpi.c
3 * Purpose: Provide PCI supports in ACPI 3 * Purpose: Provide PCI support in ACPI
4 * 4 *
5 * Copyright (C) 2004 Intel 5 * Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) 6 * Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com>
7 * Copyright (C) 2004 Intel Corp.
7 */ 8 */
8 9
9#include <linux/delay.h> 10#include <linux/delay.h>
@@ -16,6 +17,7 @@
16#include <acpi/acpi_bus.h> 17#include <acpi/acpi_bus.h>
17 18
18#include <linux/pci-acpi.h> 19#include <linux/pci-acpi.h>
20#include "pci.h"
19 21
20static u32 ctrlset_buf[3] = {0, 0, 0}; 22static u32 ctrlset_buf[3] = {0, 0, 0};
21static u32 global_ctrlsets = 0; 23static u32 global_ctrlsets = 0;
@@ -207,3 +209,105 @@ acpi_status pci_osc_control_set(u32 flags)
207 return status; 209 return status;
208} 210}
209EXPORT_SYMBOL(pci_osc_control_set); 211EXPORT_SYMBOL(pci_osc_control_set);
212
213/*
214 * _SxD returns the D-state with the highest power
215 * (lowest D-state number) supported in the S-state "x".
216 *
217 * If the devices does not have a _PRW
218 * (Power Resources for Wake) supporting system wakeup from "x"
219 * then the OS is free to choose a lower power (higher number
220 * D-state) than the return value from _SxD.
221 *
222 * But if _PRW is enabled at S-state "x", the OS
223 * must not choose a power lower than _SxD --
224 * unless the device has an _SxW method specifying
225 * the lowest power (highest D-state number) the device
226 * may enter while still able to wake the system.
227 *
228 * ie. depending on global OS policy:
229 *
230 * if (_PRW at S-state x)
231 * choose from highest power _SxD to lowest power _SxW
232 * else // no _PRW at S-state x
233 * choose highest power _SxD or any lower power
234 *
235 * currently we simply return _SxD, if present.
236 */
237
238static int acpi_pci_choose_state(struct pci_dev *pdev, pm_message_t state)
239{
240 /* TBD */
241
242 return -ENODEV;
243}
244
245static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
246{
247 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
248 static int state_conv[] = {
249 [0] = 0,
250 [1] = 1,
251 [2] = 2,
252 [3] = 3,
253 [4] = 3
254 };
255 int acpi_state = state_conv[(int __force) state];
256
257 if (!handle)
258 return -ENODEV;
259 return acpi_bus_set_power(handle, acpi_state);
260}
261
262
263/* ACPI bus type */
264static int pci_acpi_find_device(struct device *dev, acpi_handle *handle)
265{
266 struct pci_dev * pci_dev;
267 acpi_integer addr;
268
269 pci_dev = to_pci_dev(dev);
270 /* Please ref to ACPI spec for the syntax of _ADR */
271 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
272 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
273 if (!*handle)
274 return -ENODEV;
275 return 0;
276}
277
278static int pci_acpi_find_root_bridge(struct device *dev, acpi_handle *handle)
279{
280 int num;
281 unsigned int seg, bus;
282
283 /*
284 * The string should be the same as root bridge's name
285 * Please look at 'pci_scan_bus_parented'
286 */
287 num = sscanf(dev->bus_id, "pci%04x:%02x", &seg, &bus);
288 if (num != 2)
289 return -ENODEV;
290 *handle = acpi_get_pci_rootbridge_handle(seg, bus);
291 if (!*handle)
292 return -ENODEV;
293 return 0;
294}
295
296static struct acpi_bus_type pci_acpi_bus = {
297 .bus = &pci_bus_type,
298 .find_device = pci_acpi_find_device,
299 .find_bridge = pci_acpi_find_root_bridge,
300};
301
302static int __init pci_acpi_init(void)
303{
304 int ret;
305
306 ret = register_acpi_bus_type(&pci_acpi_bus);
307 if (ret)
308 return 0;
309 platform_pci_choose_state = acpi_pci_choose_state;
310 platform_pci_set_power_state = acpi_pci_set_power_state;
311 return 0;
312}
313arch_initcall(pci_acpi_init);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e65bf2b395aa..e4115a0d5ba6 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -7,7 +7,6 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/device.h> 9#include <linux/device.h>
10#include <linux/pci-dynids.h>
11#include "pci.h" 10#include "pci.h"
12 11
13/* 12/*
@@ -18,36 +17,12 @@
18 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG 17 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG
19 */ 18 */
20 19
21#ifdef CONFIG_HOTPLUG 20struct pci_dynid {
22/** 21 struct list_head node;
23 * pci_device_probe_dynamic() 22 struct pci_device_id id;
24 * 23};
25 * Walk the dynamic ID list looking for a match.
26 * returns 0 and sets pci_dev->driver when drv claims pci_dev, else error.
27 */
28static int
29pci_device_probe_dynamic(struct pci_driver *drv, struct pci_dev *pci_dev)
30{
31 int error = -ENODEV;
32 struct list_head *pos;
33 struct dynid *dynid;
34 24
35 spin_lock(&drv->dynids.lock); 25#ifdef CONFIG_HOTPLUG
36 list_for_each(pos, &drv->dynids.list) {
37 dynid = list_entry(pos, struct dynid, node);
38 if (pci_match_one_device(&dynid->id, pci_dev)) {
39 spin_unlock(&drv->dynids.lock);
40 error = drv->probe(pci_dev, &dynid->id);
41 if (error >= 0) {
42 pci_dev->driver = drv;
43 return 0;
44 }
45 return error;
46 }
47 }
48 spin_unlock(&drv->dynids.lock);
49 return error;
50}
51 26
52/** 27/**
53 * store_new_id 28 * store_new_id
@@ -58,8 +33,7 @@ pci_device_probe_dynamic(struct pci_driver *drv, struct pci_dev *pci_dev)
58static inline ssize_t 33static inline ssize_t
59store_new_id(struct device_driver *driver, const char *buf, size_t count) 34store_new_id(struct device_driver *driver, const char *buf, size_t count)
60{ 35{
61 struct dynid *dynid; 36 struct pci_dynid *dynid;
62 struct bus_type * bus;
63 struct pci_driver *pdrv = to_pci_driver(driver); 37 struct pci_driver *pdrv = to_pci_driver(driver);
64 __u32 vendor=PCI_ANY_ID, device=PCI_ANY_ID, subvendor=PCI_ANY_ID, 38 __u32 vendor=PCI_ANY_ID, device=PCI_ANY_ID, subvendor=PCI_ANY_ID,
65 subdevice=PCI_ANY_ID, class=0, class_mask=0; 39 subdevice=PCI_ANY_ID, class=0, class_mask=0;
@@ -91,37 +65,22 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
91 list_add_tail(&pdrv->dynids.list, &dynid->node); 65 list_add_tail(&pdrv->dynids.list, &dynid->node);
92 spin_unlock(&pdrv->dynids.lock); 66 spin_unlock(&pdrv->dynids.lock);
93 67
94 bus = get_bus(pdrv->driver.bus); 68 if (get_driver(&pdrv->driver)) {
95 if (bus) { 69 driver_attach(&pdrv->driver);
96 if (get_driver(&pdrv->driver)) { 70 put_driver(&pdrv->driver);
97 down_write(&bus->subsys.rwsem);
98 driver_attach(&pdrv->driver);
99 up_write(&bus->subsys.rwsem);
100 put_driver(&pdrv->driver);
101 }
102 put_bus(bus);
103 } 71 }
104 72
105 return count; 73 return count;
106} 74}
107
108static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 75static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
109static inline void
110pci_init_dynids(struct pci_dynids *dynids)
111{
112 spin_lock_init(&dynids->lock);
113 INIT_LIST_HEAD(&dynids->list);
114}
115 76
116static void 77static void
117pci_free_dynids(struct pci_driver *drv) 78pci_free_dynids(struct pci_driver *drv)
118{ 79{
119 struct list_head *pos, *n; 80 struct pci_dynid *dynid, *n;
120 struct dynid *dynid;
121 81
122 spin_lock(&drv->dynids.lock); 82 spin_lock(&drv->dynids.lock);
123 list_for_each_safe(pos, n, &drv->dynids.list) { 83 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
124 dynid = list_entry(pos, struct dynid, node);
125 list_del(&dynid->node); 84 list_del(&dynid->node);
126 kfree(dynid); 85 kfree(dynid);
127 } 86 }
@@ -138,83 +97,70 @@ pci_create_newid_file(struct pci_driver *drv)
138 return error; 97 return error;
139} 98}
140 99
141static int
142pci_bus_match_dynids(const struct pci_dev *pci_dev, struct pci_driver *pci_drv)
143{
144 struct list_head *pos;
145 struct dynid *dynid;
146
147 spin_lock(&pci_drv->dynids.lock);
148 list_for_each(pos, &pci_drv->dynids.list) {
149 dynid = list_entry(pos, struct dynid, node);
150 if (pci_match_one_device(&dynid->id, pci_dev)) {
151 spin_unlock(&pci_drv->dynids.lock);
152 return 1;
153 }
154 }
155 spin_unlock(&pci_drv->dynids.lock);
156 return 0;
157}
158
159#else /* !CONFIG_HOTPLUG */ 100#else /* !CONFIG_HOTPLUG */
160static inline int pci_device_probe_dynamic(struct pci_driver *drv, struct pci_dev *pci_dev)
161{
162 return -ENODEV;
163}
164static inline void pci_init_dynids(struct pci_dynids *dynids) {}
165static inline void pci_free_dynids(struct pci_driver *drv) {} 101static inline void pci_free_dynids(struct pci_driver *drv) {}
166static inline int pci_create_newid_file(struct pci_driver *drv) 102static inline int pci_create_newid_file(struct pci_driver *drv)
167{ 103{
168 return 0; 104 return 0;
169} 105}
170static inline int pci_bus_match_dynids(const struct pci_dev *pci_dev, struct pci_driver *pci_drv)
171{
172 return 0;
173}
174#endif 106#endif
175 107
176/** 108/**
177 * pci_match_device - Tell if a PCI device structure has a matching 109 * pci_match_id - See if a pci device matches a given pci_id table
178 * PCI device id structure
179 * @ids: array of PCI device id structures to search in 110 * @ids: array of PCI device id structures to search in
180 * @dev: the PCI device structure to match against 111 * @dev: the PCI device structure to match against.
181 * 112 *
182 * Used by a driver to check whether a PCI device present in the 113 * Used by a driver to check whether a PCI device present in the
183 * system is in its list of supported devices.Returns the matching 114 * system is in its list of supported devices. Returns the matching
184 * pci_device_id structure or %NULL if there is no match. 115 * pci_device_id structure or %NULL if there is no match.
116 *
117 * Depreciated, don't use this as it will not catch any dynamic ids
118 * that a driver might want to check for.
185 */ 119 */
186const struct pci_device_id * 120const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
187pci_match_device(const struct pci_device_id *ids, const struct pci_dev *dev) 121 struct pci_dev *dev)
188{ 122{
189 while (ids->vendor || ids->subvendor || ids->class_mask) { 123 if (ids) {
190 if (pci_match_one_device(ids, dev)) 124 while (ids->vendor || ids->subvendor || ids->class_mask) {
191 return ids; 125 if (pci_match_one_device(ids, dev))
192 ids++; 126 return ids;
127 ids++;
128 }
193 } 129 }
194 return NULL; 130 return NULL;
195} 131}
196 132
197/** 133/**
198 * pci_device_probe_static() 134 * pci_match_device - Tell if a PCI device structure has a matching
199 * 135 * PCI device id structure
200 * returns 0 and sets pci_dev->driver when drv claims pci_dev, else error. 136 * @ids: array of PCI device id structures to search in
137 * @dev: the PCI device structure to match against
138 * @drv: the PCI driver to match against
139 *
140 * Used by a driver to check whether a PCI device present in the
141 * system is in its list of supported devices. Returns the matching
142 * pci_device_id structure or %NULL if there is no match.
201 */ 143 */
202static int 144const struct pci_device_id *pci_match_device(struct pci_driver *drv,
203pci_device_probe_static(struct pci_driver *drv, struct pci_dev *pci_dev) 145 struct pci_dev *dev)
204{ 146{
205 int error = -ENODEV;
206 const struct pci_device_id *id; 147 const struct pci_device_id *id;
148 struct pci_dynid *dynid;
207 149
208 if (!drv->id_table) 150 id = pci_match_id(drv->id_table, dev);
209 return error;
210 id = pci_match_device(drv->id_table, pci_dev);
211 if (id) 151 if (id)
212 error = drv->probe(pci_dev, id); 152 return id;
213 if (error >= 0) { 153
214 pci_dev->driver = drv; 154 /* static ids didn't match, lets look at the dynamic ones */
215 error = 0; 155 spin_lock(&drv->dynids.lock);
156 list_for_each_entry(dynid, &drv->dynids.list, node) {
157 if (pci_match_one_device(&dynid->id, dev)) {
158 spin_unlock(&drv->dynids.lock);
159 return &dynid->id;
160 }
216 } 161 }
217 return error; 162 spin_unlock(&drv->dynids.lock);
163 return NULL;
218} 164}
219 165
220/** 166/**
@@ -225,13 +171,20 @@ pci_device_probe_static(struct pci_driver *drv, struct pci_dev *pci_dev)
225 */ 171 */
226static int 172static int
227__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) 173__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
228{ 174{
175 const struct pci_device_id *id;
229 int error = 0; 176 int error = 0;
230 177
231 if (!pci_dev->driver && drv->probe) { 178 if (!pci_dev->driver && drv->probe) {
232 error = pci_device_probe_static(drv, pci_dev); 179 error = -ENODEV;
233 if (error == -ENODEV) 180
234 error = pci_device_probe_dynamic(drv, pci_dev); 181 id = pci_match_device(drv, pci_dev);
182 if (id)
183 error = drv->probe(pci_dev, id);
184 if (error >= 0) {
185 pci_dev->driver = drv;
186 error = 0;
187 }
235 } 188 }
236 return error; 189 return error;
237} 190}
@@ -371,12 +324,6 @@ static struct kobj_type pci_driver_kobj_type = {
371 .sysfs_ops = &pci_driver_sysfs_ops, 324 .sysfs_ops = &pci_driver_sysfs_ops,
372}; 325};
373 326
374static int
375pci_populate_driver_dir(struct pci_driver *drv)
376{
377 return pci_create_newid_file(drv);
378}
379
380/** 327/**
381 * pci_register_driver - register a new pci driver 328 * pci_register_driver - register a new pci driver
382 * @drv: the driver structure to register 329 * @drv: the driver structure to register
@@ -401,13 +348,15 @@ int pci_register_driver(struct pci_driver *drv)
401 drv->driver.shutdown = pci_device_shutdown; 348 drv->driver.shutdown = pci_device_shutdown;
402 drv->driver.owner = drv->owner; 349 drv->driver.owner = drv->owner;
403 drv->driver.kobj.ktype = &pci_driver_kobj_type; 350 drv->driver.kobj.ktype = &pci_driver_kobj_type;
404 pci_init_dynids(&drv->dynids); 351
352 spin_lock_init(&drv->dynids.lock);
353 INIT_LIST_HEAD(&drv->dynids.list);
405 354
406 /* register with core */ 355 /* register with core */
407 error = driver_register(&drv->driver); 356 error = driver_register(&drv->driver);
408 357
409 if (!error) 358 if (!error)
410 pci_populate_driver_dir(drv); 359 error = pci_create_newid_file(drv);
411 360
412 return error; 361 return error;
413} 362}
@@ -463,21 +412,17 @@ pci_dev_driver(const struct pci_dev *dev)
463 * system is in its list of supported devices.Returns the matching 412 * system is in its list of supported devices.Returns the matching
464 * pci_device_id structure or %NULL if there is no match. 413 * pci_device_id structure or %NULL if there is no match.
465 */ 414 */
466static int pci_bus_match(struct device * dev, struct device_driver * drv) 415static int pci_bus_match(struct device *dev, struct device_driver *drv)
467{ 416{
468 const struct pci_dev * pci_dev = to_pci_dev(dev); 417 struct pci_dev *pci_dev = to_pci_dev(dev);
469 struct pci_driver * pci_drv = to_pci_driver(drv); 418 struct pci_driver *pci_drv = to_pci_driver(drv);
470 const struct pci_device_id * ids = pci_drv->id_table;
471 const struct pci_device_id *found_id; 419 const struct pci_device_id *found_id;
472 420
473 if (!ids) 421 found_id = pci_match_device(pci_drv, pci_dev);
474 return 0;
475
476 found_id = pci_match_device(ids, pci_dev);
477 if (found_id) 422 if (found_id)
478 return 1; 423 return 1;
479 424
480 return pci_bus_match_dynids(pci_dev, pci_drv); 425 return 0;
481} 426}
482 427
483/** 428/**
@@ -536,6 +481,7 @@ static int __init pci_driver_init(void)
536 481
537postcore_initcall(pci_driver_init); 482postcore_initcall(pci_driver_init);
538 483
484EXPORT_SYMBOL(pci_match_id);
539EXPORT_SYMBOL(pci_match_device); 485EXPORT_SYMBOL(pci_match_device);
540EXPORT_SYMBOL(pci_register_driver); 486EXPORT_SYMBOL(pci_register_driver);
541EXPORT_SYMBOL(pci_unregister_driver); 487EXPORT_SYMBOL(pci_unregister_driver);
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index a15f94072a6f..cc9d65388e62 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -60,15 +60,18 @@ resource_show(struct device * dev, struct device_attribute *attr, char * buf)
60 char * str = buf; 60 char * str = buf;
61 int i; 61 int i;
62 int max = 7; 62 int max = 7;
63 u64 start, end;
63 64
64 if (pci_dev->subordinate) 65 if (pci_dev->subordinate)
65 max = DEVICE_COUNT_RESOURCE; 66 max = DEVICE_COUNT_RESOURCE;
66 67
67 for (i = 0; i < max; i++) { 68 for (i = 0; i < max; i++) {
68 str += sprintf(str,"0x%016lx 0x%016lx 0x%016lx\n", 69 struct resource *res = &pci_dev->resource[i];
69 pci_resource_start(pci_dev,i), 70 pci_resource_to_user(pci_dev, i, res, &start, &end);
70 pci_resource_end(pci_dev,i), 71 str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n",
71 pci_resource_flags(pci_dev,i)); 72 (unsigned long long)start,
73 (unsigned long long)end,
74 (unsigned long long)res->flags);
72 } 75 }
73 return (str - buf); 76 return (str - buf);
74} 77}
@@ -313,8 +316,21 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
313 struct device, kobj)); 316 struct device, kobj));
314 struct resource *res = (struct resource *)attr->private; 317 struct resource *res = (struct resource *)attr->private;
315 enum pci_mmap_state mmap_type; 318 enum pci_mmap_state mmap_type;
319 u64 start, end;
320 int i;
316 321
317 vma->vm_pgoff += res->start >> PAGE_SHIFT; 322 for (i = 0; i < PCI_ROM_RESOURCE; i++)
323 if (res == &pdev->resource[i])
324 break;
325 if (i >= PCI_ROM_RESOURCE)
326 return -ENODEV;
327
328 /* pci_mmap_page_range() expects the same kind of entry as coming
329 * from /proc/bus/pci/ which is a "user visible" value. If this is
330 * different from the resource itself, arch will do necessary fixup.
331 */
332 pci_resource_to_user(pdev, i, res, &start, &end);
333 vma->vm_pgoff += start >> PAGE_SHIFT;
318 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; 334 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
319 335
320 return pci_mmap_page_range(pdev, vma, mmap_type, 0); 336 return pci_mmap_page_range(pdev, vma, mmap_type, 0);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index f04b9ffe4153..1b34fc56067e 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -235,7 +235,7 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
235 * -EIO if device does not support PCI PM. 235 * -EIO if device does not support PCI PM.
236 * 0 if we can successfully change the power state. 236 * 0 if we can successfully change the power state.
237 */ 237 */
238 238int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
239int 239int
240pci_set_power_state(struct pci_dev *dev, pci_power_t state) 240pci_set_power_state(struct pci_dev *dev, pci_power_t state)
241{ 241{
@@ -299,11 +299,20 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
299 msleep(10); 299 msleep(10);
300 else if (state == PCI_D2 || dev->current_state == PCI_D2) 300 else if (state == PCI_D2 || dev->current_state == PCI_D2)
301 udelay(200); 301 udelay(200);
302 dev->current_state = state;
303 302
303 /*
304 * Give firmware a chance to be called, such as ACPI _PRx, _PSx
305 * Firmware method after natice method ?
306 */
307 if (platform_pci_set_power_state)
308 platform_pci_set_power_state(dev, state);
309
310 dev->current_state = state;
304 return 0; 311 return 0;
305} 312}
306 313
314int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
315
307/** 316/**
308 * pci_choose_state - Choose the power state of a PCI device 317 * pci_choose_state - Choose the power state of a PCI device
309 * @dev: PCI device to be suspended 318 * @dev: PCI device to be suspended
@@ -316,10 +325,17 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
316 325
317pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) 326pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
318{ 327{
328 int ret;
329
319 if (!pci_find_capability(dev, PCI_CAP_ID_PM)) 330 if (!pci_find_capability(dev, PCI_CAP_ID_PM))
320 return PCI_D0; 331 return PCI_D0;
321 332
322 switch (state) { 333 if (platform_pci_choose_state) {
334 ret = platform_pci_choose_state(dev, state);
335 if (ret >= 0)
336 state = ret;
337 }
338 switch (state) {
323 case 0: return PCI_D0; 339 case 0: return PCI_D0;
324 case 3: return PCI_D3hot; 340 case 3: return PCI_D3hot;
325 default: 341 default:
@@ -334,10 +350,6 @@ EXPORT_SYMBOL(pci_choose_state);
334/** 350/**
335 * pci_save_state - save the PCI configuration space of a device before suspending 351 * pci_save_state - save the PCI configuration space of a device before suspending
336 * @dev: - PCI device that we're dealing with 352 * @dev: - PCI device that we're dealing with
337 * @buffer: - buffer to hold config space context
338 *
339 * @buffer must be large enough to hold the entire PCI 2.2 config space
340 * (>= 64 bytes).
341 */ 353 */
342int 354int
343pci_save_state(struct pci_dev *dev) 355pci_save_state(struct pci_dev *dev)
@@ -352,8 +364,6 @@ pci_save_state(struct pci_dev *dev)
352/** 364/**
353 * pci_restore_state - Restore the saved state of a PCI device 365 * pci_restore_state - Restore the saved state of a PCI device
354 * @dev: - PCI device that we're dealing with 366 * @dev: - PCI device that we're dealing with
355 * @buffer: - saved PCI config space
356 *
357 */ 367 */
358int 368int
359pci_restore_state(struct pci_dev *dev) 369pci_restore_state(struct pci_dev *dev)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 744da0d4ae5f..d94d7af4f7a0 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -11,6 +11,10 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
11 void (*alignf)(void *, struct resource *, 11 void (*alignf)(void *, struct resource *,
12 unsigned long, unsigned long), 12 unsigned long, unsigned long),
13 void *alignf_data); 13 void *alignf_data);
14/* Firmware callbacks */
15extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
16extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
17
14/* PCI /proc functions */ 18/* PCI /proc functions */
15#ifdef CONFIG_PROC_FS 19#ifdef CONFIG_PROC_FS
16extern int pci_proc_attach_device(struct pci_dev *dev); 20extern int pci_proc_attach_device(struct pci_dev *dev);
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index 537b372dc340..a63bd8f72601 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -27,6 +27,11 @@
27 27
28#define get_descriptor_id(type, service) (((type - 4) << 4) | service) 28#define get_descriptor_id(type, service) (((type - 4) << 4) | service)
29 29
30struct pcie_port_device_ext {
31 int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */
32 unsigned int saved_msi_config_space[5];
33};
34
30extern struct bus_type pcie_port_bus_type; 35extern struct bus_type pcie_port_bus_type;
31extern int pcie_port_device_probe(struct pci_dev *dev); 36extern int pcie_port_device_probe(struct pci_dev *dev);
32extern int pcie_port_device_register(struct pci_dev *dev); 37extern int pcie_port_device_register(struct pci_dev *dev);
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index f5c5f10a3d2f..393e0cee91a9 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -275,10 +275,17 @@ int pcie_port_device_probe(struct pci_dev *dev)
275 275
276int pcie_port_device_register(struct pci_dev *dev) 276int pcie_port_device_register(struct pci_dev *dev)
277{ 277{
278 struct pcie_port_device_ext *p_ext;
278 int status, type, capabilities, irq_mode, i; 279 int status, type, capabilities, irq_mode, i;
279 int vectors[PCIE_PORT_DEVICE_MAXSERVICES]; 280 int vectors[PCIE_PORT_DEVICE_MAXSERVICES];
280 u16 reg16; 281 u16 reg16;
281 282
283 /* Allocate port device extension */
284 if (!(p_ext = kmalloc(sizeof(struct pcie_port_device_ext), GFP_KERNEL)))
285 return -ENOMEM;
286
287 pci_set_drvdata(dev, p_ext);
288
282 /* Get port type */ 289 /* Get port type */
283 pci_read_config_word(dev, 290 pci_read_config_word(dev,
284 pci_find_capability(dev, PCI_CAP_ID_EXP) + 291 pci_find_capability(dev, PCI_CAP_ID_EXP) +
@@ -288,6 +295,7 @@ int pcie_port_device_register(struct pci_dev *dev)
288 /* Now get port services */ 295 /* Now get port services */
289 capabilities = get_port_device_capability(dev); 296 capabilities = get_port_device_capability(dev);
290 irq_mode = assign_interrupt_mode(dev, vectors, capabilities); 297 irq_mode = assign_interrupt_mode(dev, vectors, capabilities);
298 p_ext->interrupt_mode = irq_mode;
291 299
292 /* Allocate child services if any */ 300 /* Allocate child services if any */
293 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) { 301 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
@@ -317,7 +325,7 @@ int pcie_port_device_register(struct pci_dev *dev)
317static int suspend_iter(struct device *dev, void *data) 325static int suspend_iter(struct device *dev, void *data)
318{ 326{
319 struct pcie_port_service_driver *service_driver; 327 struct pcie_port_service_driver *service_driver;
320 u32 state = (u32)data; 328 pm_message_t state = * (pm_message_t *) data;
321 329
322 if ((dev->bus == &pcie_port_bus_type) && 330 if ((dev->bus == &pcie_port_bus_type) &&
323 (dev->driver)) { 331 (dev->driver)) {
@@ -328,9 +336,9 @@ static int suspend_iter(struct device *dev, void *data)
328 return 0; 336 return 0;
329} 337}
330 338
331int pcie_port_device_suspend(struct pci_dev *dev, u32 state) 339int pcie_port_device_suspend(struct pci_dev *dev, pm_message_t state)
332{ 340{
333 device_for_each_child(&dev->dev, (void *)state, suspend_iter); 341 device_for_each_child(&dev->dev, &state, suspend_iter);
334 return 0; 342 return 0;
335} 343}
336 344
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index e9095ee508e3..30bac7ed7c16 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -29,6 +29,78 @@ MODULE_LICENSE("GPL");
29/* global data */ 29/* global data */
30static const char device_name[] = "pcieport-driver"; 30static const char device_name[] = "pcieport-driver";
31 31
32static void pci_save_msi_state(struct pci_dev *dev)
33{
34 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
35 int i = 0, pos;
36 u16 control;
37
38 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
39 return;
40
41 pci_read_config_dword(dev, pos, &p_ext->saved_msi_config_space[i++]);
42 control = p_ext->saved_msi_config_space[0] >> 16;
43 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
44 &p_ext->saved_msi_config_space[i++]);
45 if (control & PCI_MSI_FLAGS_64BIT) {
46 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
47 &p_ext->saved_msi_config_space[i++]);
48 pci_read_config_dword(dev, pos + PCI_MSI_DATA_64,
49 &p_ext->saved_msi_config_space[i++]);
50 } else
51 pci_read_config_dword(dev, pos + PCI_MSI_DATA_32,
52 &p_ext->saved_msi_config_space[i++]);
53 if (control & PCI_MSI_FLAGS_MASKBIT)
54 pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT,
55 &p_ext->saved_msi_config_space[i++]);
56}
57
58static void pci_restore_msi_state(struct pci_dev *dev)
59{
60 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
61 int i = 0, pos;
62 u16 control;
63
64 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
65 return;
66
67 control = p_ext->saved_msi_config_space[i++] >> 16;
68 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
69 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
70 p_ext->saved_msi_config_space[i++]);
71 if (control & PCI_MSI_FLAGS_64BIT) {
72 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
73 p_ext->saved_msi_config_space[i++]);
74 pci_write_config_dword(dev, pos + PCI_MSI_DATA_64,
75 p_ext->saved_msi_config_space[i++]);
76 } else
77 pci_write_config_dword(dev, pos + PCI_MSI_DATA_32,
78 p_ext->saved_msi_config_space[i++]);
79 if (control & PCI_MSI_FLAGS_MASKBIT)
80 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT,
81 p_ext->saved_msi_config_space[i++]);
82}
83
84static void pcie_portdrv_save_config(struct pci_dev *dev)
85{
86 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
87
88 pci_save_state(dev);
89 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
90 pci_save_msi_state(dev);
91}
92
93static void pcie_portdrv_restore_config(struct pci_dev *dev)
94{
95 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
96
97 pci_restore_state(dev);
98 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
99 pci_restore_msi_state(dev);
100 pci_enable_device(dev);
101 pci_set_master(dev);
102}
103
32/* 104/*
33 * pcie_portdrv_probe - Probe PCI-Express port devices 105 * pcie_portdrv_probe - Probe PCI-Express port devices
34 * @dev: PCI-Express port device being probed 106 * @dev: PCI-Express port device being probed
@@ -64,16 +136,21 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
64static void pcie_portdrv_remove (struct pci_dev *dev) 136static void pcie_portdrv_remove (struct pci_dev *dev)
65{ 137{
66 pcie_port_device_remove(dev); 138 pcie_port_device_remove(dev);
139 kfree(pci_get_drvdata(dev));
67} 140}
68 141
69#ifdef CONFIG_PM 142#ifdef CONFIG_PM
70static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state) 143static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
71{ 144{
72 return pcie_port_device_suspend(dev, state); 145 int ret = pcie_port_device_suspend(dev, state);
146
147 pcie_portdrv_save_config(dev);
148 return ret;
73} 149}
74 150
75static int pcie_portdrv_resume (struct pci_dev *dev) 151static int pcie_portdrv_resume (struct pci_dev *dev)
76{ 152{
153 pcie_portdrv_restore_config(dev);
77 return pcie_port_device_resume(dev); 154 return pcie_port_device_resume(dev);
78} 155}
79#endif 156#endif
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index fd48b201eb53..df3bdae2040f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -239,9 +239,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
239 239
240 if (dev->transparent) { 240 if (dev->transparent) {
241 printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev)); 241 printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev));
242 for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) 242 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
243 child->resource[i] = child->parent->resource[i]; 243 child->resource[i] = child->parent->resource[i - 3];
244 return;
245 } 244 }
246 245
247 for(i=0; i<3; i++) 246 for(i=0; i<3; i++)
@@ -374,8 +373,11 @@ struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_de
374 struct pci_bus *child; 373 struct pci_bus *child;
375 374
376 child = pci_alloc_child_bus(parent, dev, busnr); 375 child = pci_alloc_child_bus(parent, dev, busnr);
377 if (child) 376 if (child) {
377 spin_lock(&pci_bus_lock);
378 list_add_tail(&child->node, &parent->children); 378 list_add_tail(&child->node, &parent->children);
379 spin_unlock(&pci_bus_lock);
380 }
379 return child; 381 return child;
380} 382}
381 383
@@ -395,6 +397,16 @@ static void pci_enable_crs(struct pci_dev *dev)
395 pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl); 397 pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl);
396} 398}
397 399
400static void __devinit pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
401{
402 struct pci_bus *parent = child->parent;
403 while (parent->parent && parent->subordinate < max) {
404 parent->subordinate = max;
405 pci_write_config_byte(parent->self, PCI_SUBORDINATE_BUS, max);
406 parent = parent->parent;
407 }
408}
409
398unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus); 410unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus);
399 411
400/* 412/*
@@ -411,7 +423,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
411{ 423{
412 struct pci_bus *child; 424 struct pci_bus *child;
413 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); 425 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
414 u32 buses; 426 u32 buses, i;
415 u16 bctl; 427 u16 bctl;
416 428
417 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 429 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
@@ -447,7 +459,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
447 return max; 459 return max;
448 } 460 }
449 461
450 child = pci_alloc_child_bus(bus, dev, busnr); 462 child = pci_add_new_bus(bus, dev, busnr);
451 if (!child) 463 if (!child)
452 return max; 464 return max;
453 child->primary = buses & 0xFF; 465 child->primary = buses & 0xFF;
@@ -470,7 +482,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
470 /* Clear errors */ 482 /* Clear errors */
471 pci_write_config_word(dev, PCI_STATUS, 0xffff); 483 pci_write_config_word(dev, PCI_STATUS, 0xffff);
472 484
473 child = pci_alloc_child_bus(bus, dev, ++max); 485 /* Prevent assigning a bus number that already exists.
486 * This can happen when a bridge is hot-plugged */
487 if (pci_find_bus(pci_domain_nr(bus), max+1))
488 return max;
489 child = pci_add_new_bus(bus, dev, ++max);
474 buses = (buses & 0xff000000) 490 buses = (buses & 0xff000000)
475 | ((unsigned int)(child->primary) << 0) 491 | ((unsigned int)(child->primary) << 0)
476 | ((unsigned int)(child->secondary) << 8) 492 | ((unsigned int)(child->secondary) << 8)
@@ -492,7 +508,13 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
492 508
493 if (!is_cardbus) { 509 if (!is_cardbus) {
494 child->bridge_ctl = PCI_BRIDGE_CTL_NO_ISA; 510 child->bridge_ctl = PCI_BRIDGE_CTL_NO_ISA;
495 511 /*
512 * Adjust subordinate busnr in parent buses.
513 * We do this before scanning for children because
514 * some devices may not be detected if the bios
515 * was lazy.
516 */
517 pci_fixup_parent_subordinate_busnr(child, max);
496 /* Now we can scan all subordinate buses... */ 518 /* Now we can scan all subordinate buses... */
497 max = pci_scan_child_bus(child); 519 max = pci_scan_child_bus(child);
498 } else { 520 } else {
@@ -501,7 +523,12 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
501 * as cards with a PCI-to-PCI bridge can be 523 * as cards with a PCI-to-PCI bridge can be
502 * inserted later. 524 * inserted later.
503 */ 525 */
504 max += CARDBUS_RESERVE_BUSNR; 526 for (i=0; i<CARDBUS_RESERVE_BUSNR; i++)
527 if (pci_find_bus(pci_domain_nr(bus),
528 max+i+1))
529 break;
530 max += i;
531 pci_fixup_parent_subordinate_busnr(child, max);
505 } 532 }
506 /* 533 /*
507 * Set the subordinate bus number to its real value. 534 * Set the subordinate bus number to its real value.
@@ -757,7 +784,9 @@ pci_scan_single_device(struct pci_bus *bus, int devfn)
757 * and the bus list for fixup functions, etc. 784 * and the bus list for fixup functions, etc.
758 */ 785 */
759 INIT_LIST_HEAD(&dev->global_list); 786 INIT_LIST_HEAD(&dev->global_list);
787 spin_lock(&pci_bus_lock);
760 list_add_tail(&dev->bus_list, &bus->devices); 788 list_add_tail(&dev->bus_list, &bus->devices);
789 spin_unlock(&pci_bus_lock);
761 790
762 return dev; 791 return dev;
763} 792}
@@ -878,7 +907,9 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
878 pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus); 907 pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus);
879 goto err_out; 908 goto err_out;
880 } 909 }
910 spin_lock(&pci_bus_lock);
881 list_add_tail(&b->node, &pci_root_buses); 911 list_add_tail(&b->node, &pci_root_buses);
912 spin_unlock(&pci_bus_lock);
882 913
883 memset(dev, 0, sizeof(*dev)); 914 memset(dev, 0, sizeof(*dev));
884 dev->parent = parent; 915 dev->parent = parent;
@@ -911,8 +942,6 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus,
911 942
912 b->subordinate = pci_scan_child_bus(b); 943 b->subordinate = pci_scan_child_bus(b);
913 944
914 pci_bus_add_devices(b);
915
916 return b; 945 return b;
917 946
918sys_create_link_err: 947sys_create_link_err:
@@ -922,7 +951,9 @@ class_dev_create_file_err:
922class_dev_reg_err: 951class_dev_reg_err:
923 device_unregister(dev); 952 device_unregister(dev);
924dev_reg_err: 953dev_reg_err:
954 spin_lock(&pci_bus_lock);
925 list_del(&b->node); 955 list_del(&b->node);
956 spin_unlock(&pci_bus_lock);
926err_out: 957err_out:
927 kfree(dev); 958 kfree(dev);
928 kfree(b); 959 kfree(b);
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index e68bbfb1e7c3..7988fc8df3fd 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -355,14 +355,20 @@ static int show_device(struct seq_file *m, void *v)
355 dev->device, 355 dev->device,
356 dev->irq); 356 dev->irq);
357 /* Here should be 7 and not PCI_NUM_RESOURCES as we need to preserve compatibility */ 357 /* Here should be 7 and not PCI_NUM_RESOURCES as we need to preserve compatibility */
358 for(i=0; i<7; i++) 358 for (i=0; i<7; i++) {
359 u64 start, end;
360 pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
359 seq_printf(m, LONG_FORMAT, 361 seq_printf(m, LONG_FORMAT,
360 dev->resource[i].start | 362 ((unsigned long)start) |
361 (dev->resource[i].flags & PCI_REGION_FLAG_MASK)); 363 (dev->resource[i].flags & PCI_REGION_FLAG_MASK));
362 for(i=0; i<7; i++) 364 }
365 for (i=0; i<7; i++) {
366 u64 start, end;
367 pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
363 seq_printf(m, LONG_FORMAT, 368 seq_printf(m, LONG_FORMAT,
364 dev->resource[i].start < dev->resource[i].end ? 369 dev->resource[i].start < dev->resource[i].end ?
365 dev->resource[i].end - dev->resource[i].start + 1 : 0); 370 (unsigned long)(end - start) + 1 : 0);
371 }
366 seq_putc(m, '\t'); 372 seq_putc(m, '\t');
367 if (drv) 373 if (drv)
368 seq_printf(m, "%s", drv->name); 374 seq_printf(m, "%s", drv->name);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 968033fd29f0..1521fd5d95cc 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -767,6 +767,7 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
767 if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) { 767 if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
768 if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB) 768 if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB)
769 switch(dev->subsystem_device) { 769 switch(dev->subsystem_device) {
770 case 0x8025: /* P4B-LX */
770 case 0x8070: /* P4B */ 771 case 0x8070: /* P4B */
771 case 0x8088: /* P4B533 */ 772 case 0x8088: /* P4B533 */
772 case 0x1626: /* L3C notebook */ 773 case 0x1626: /* L3C notebook */
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 96f077f9a659..27a294b6965d 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -18,17 +18,21 @@ static void pci_free_resources(struct pci_dev *dev)
18 18
19static void pci_destroy_dev(struct pci_dev *dev) 19static void pci_destroy_dev(struct pci_dev *dev)
20{ 20{
21 pci_proc_detach_device(dev); 21 if (!list_empty(&dev->global_list)) {
22 pci_remove_sysfs_dev_files(dev); 22 pci_proc_detach_device(dev);
23 device_unregister(&dev->dev); 23 pci_remove_sysfs_dev_files(dev);
24 device_unregister(&dev->dev);
25 spin_lock(&pci_bus_lock);
26 list_del(&dev->global_list);
27 dev->global_list.next = dev->global_list.prev = NULL;
28 spin_unlock(&pci_bus_lock);
29 }
24 30
25 /* Remove the device from the device lists, and prevent any further 31 /* Remove the device from the device lists, and prevent any further
26 * list accesses from this device */ 32 * list accesses from this device */
27 spin_lock(&pci_bus_lock); 33 spin_lock(&pci_bus_lock);
28 list_del(&dev->bus_list); 34 list_del(&dev->bus_list);
29 list_del(&dev->global_list);
30 dev->bus_list.next = dev->bus_list.prev = NULL; 35 dev->bus_list.next = dev->bus_list.prev = NULL;
31 dev->global_list.next = dev->global_list.prev = NULL;
32 spin_unlock(&pci_bus_lock); 36 spin_unlock(&pci_bus_lock);
33 37
34 pci_free_resources(dev); 38 pci_free_resources(dev);
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index a90a533eba0f..05fa91a31c62 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -379,6 +379,7 @@ exit:
379EXPORT_SYMBOL(pci_dev_present); 379EXPORT_SYMBOL(pci_dev_present);
380 380
381EXPORT_SYMBOL(pci_find_bus); 381EXPORT_SYMBOL(pci_find_bus);
382EXPORT_SYMBOL(pci_find_next_bus);
382EXPORT_SYMBOL(pci_find_device); 383EXPORT_SYMBOL(pci_find_device);
383EXPORT_SYMBOL(pci_find_device_reverse); 384EXPORT_SYMBOL(pci_find_device_reverse);
384EXPORT_SYMBOL(pci_find_slot); 385EXPORT_SYMBOL(pci_find_slot);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1ba84be0b4c0..9fe48f712be9 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -72,7 +72,11 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
72 for (list = head.next; list;) { 72 for (list = head.next; list;) {
73 res = list->res; 73 res = list->res;
74 idx = res - &list->dev->resource[0]; 74 idx = res - &list->dev->resource[0];
75 pci_assign_resource(list->dev, idx); 75 if (pci_assign_resource(list->dev, idx)) {
76 res->start = 0;
77 res->end = 0;
78 res->flags = 0;
79 }
76 tmp = list; 80 tmp = list;
77 list = list->next; 81 list = list->next;
78 kfree(tmp); 82 kfree(tmp);
@@ -270,6 +274,8 @@ find_free_bus_resource(struct pci_bus *bus, unsigned long type)
270 274
271 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 275 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
272 r = bus->resource[i]; 276 r = bus->resource[i];
277 if (r == &ioport_resource || r == &iomem_resource)
278 continue;
273 if (r && (r->flags & type_mask) == type && !r->parent) 279 if (r && (r->flags & type_mask) == type && !r->parent)
274 return r; 280 return r;
275 } 281 }
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 14e4124e1523..6485f75d2fb3 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -1,8 +1,5 @@
1# 1#
2# PCMCIA bus subsystem configuration 2# PCCARD (PCMCIA/CardBus) bus subsystem configuration
3#
4# Right now the non-CardBus choices are not supported
5# by the integrated kernel driver.
6# 3#
7 4
8menu "PCCARD (PCMCIA/CardBus) support" 5menu "PCCARD (PCMCIA/CardBus) support"
@@ -14,8 +11,8 @@ config PCCARD
14 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux 11 Say Y here if you want to attach PCMCIA- or PC-cards to your Linux
15 computer. These are credit-card size devices such as network cards, 12 computer. These are credit-card size devices such as network cards,
16 modems or hard drives often used with laptops computers. There are 13 modems or hard drives often used with laptops computers. There are
17 actually two varieties of these cards: the older 16 bit PCMCIA cards 14 actually two varieties of these cards: 16 bit PCMCIA and 32 bit
18 and the newer 32 bit CardBus cards. 15 CardBus cards.
19 16
20 To compile this driver as modules, choose M here: the 17 To compile this driver as modules, choose M here: the
21 module will be called pcmcia_core. 18 module will be called pcmcia_core.
@@ -32,7 +29,7 @@ config PCMCIA_DEBUG
32 29
33 The kernel command line options are: 30 The kernel command line options are:
34 pcmcia_core.pc_debug=N 31 pcmcia_core.pc_debug=N
35 ds.pc_debug=N 32 pcmcia.pc_debug=N
36 sa11xx_core.pc_debug=N 33 sa11xx_core.pc_debug=N
37 34
38 The module option is called pc_debug=N 35 The module option is called pc_debug=N
@@ -42,22 +39,50 @@ config PCMCIA_DEBUG
42 39
43config PCMCIA 40config PCMCIA
44 tristate "16-bit PCMCIA support" 41 tristate "16-bit PCMCIA support"
42 select CRC32
45 default y 43 default y
46 ---help--- 44 ---help---
47 This option enables support for 16-bit PCMCIA cards. Most older 45 This option enables support for 16-bit PCMCIA cards. Most older
48 PC-cards are such 16-bit PCMCIA cards, so unless you know you're 46 PC-cards are such 16-bit PCMCIA cards, so unless you know you're
49 only using 32-bit CardBus cards, say Y or M here. 47 only using 32-bit CardBus cards, say Y or M here.
50 48
51 To use 16-bit PCMCIA cards, you will need supporting software from 49 To use 16-bit PCMCIA cards, you will need supporting software in
52 David Hinds' pcmcia-cs package (see the file <file:Documentation/Changes> 50 most cases. (see the file <file:Documentation/Changes> for
53 for location). Please also read the PCMCIA-HOWTO, available from 51 location and details).
54 <http://www.tldp.org/docs.html#howto>.
55 52
56 To compile this driver as modules, choose M here: the 53 To compile this driver as modules, choose M here: the
57 module will be called pcmcia. 54 module will be called pcmcia.
58 55
59 If unsure, say Y. 56 If unsure, say Y.
60 57
58config PCMCIA_LOAD_CIS
59 bool "Load CIS updates from userspace (EXPERIMENTAL)"
60 depends on PCMCIA && EXPERIMENTAL
61 select FW_LOADER
62 default y
63 help
64 Some PCMCIA cards require an updated Card Information Structure (CIS)
65 to be loaded from userspace to work correctly. If you say Y here,
66 and your userspace is arranged correctly, this will be loaded
67 automatically using the in-kernel firmware loader and the hotplug
68 subsystem, instead of relying on cardmgr from pcmcia-cs to do so.
69
70 If unsure, say Y.
71
72config PCMCIA_IOCTL
73 bool "PCMCIA control ioctl (obsolete)"
74 depends on PCMCIA
75 default y
76 help
77 If you say Y here, the deprecated ioctl interface to the PCMCIA
78 subsystem will be built. It is needed by cardmgr and cardctl
79 (pcmcia-cs) to function properly.
80
81 You should use the new pcmciautils package instead (see
82 <file:Documentation/Changes> for location and details).
83
84 If unsure, say Y.
85
61config CARDBUS 86config CARDBUS
62 bool "32-bit CardBus support" 87 bool "32-bit CardBus support"
63 depends on PCI 88 depends on PCI
@@ -78,8 +103,7 @@ comment "PC-card bridges"
78config YENTA 103config YENTA
79 tristate "CardBus yenta-compatible bridge support" 104 tristate "CardBus yenta-compatible bridge support"
80 depends on PCI 105 depends on PCI
81#fixme: remove dependendcy on CARDBUS 106 select CARDBUS if !EMBEDDED
82 depends on CARDBUS
83 select PCCARD_NONSTATIC 107 select PCCARD_NONSTATIC
84 ---help--- 108 ---help---
85 This option enables support for CardBus host bridges. Virtually 109 This option enables support for CardBus host bridges. Virtually
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 50c29361bc5f..ef694c74dfb7 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -10,7 +10,8 @@ pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
11obj-$(CONFIG_PCCARD) += pcmcia_core.o 11obj-$(CONFIG_PCCARD) += pcmcia_core.o
12 12
13pcmcia-y += ds.o pcmcia_compat.o 13pcmcia-y += ds.o pcmcia_compat.o pcmcia_resource.o
14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
14obj-$(CONFIG_PCMCIA) += pcmcia.o 15obj-$(CONFIG_PCMCIA) += pcmcia.o
15 16
16obj-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o 17obj-$(CONFIG_PCCARD_NONSTATIC) += rsrc_nonstatic.o
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h
index 417bc1500bad..d5122b1ea94b 100644
--- a/drivers/pcmcia/au1000_generic.h
+++ b/drivers/pcmcia/au1000_generic.h
@@ -22,7 +22,6 @@
22#define __ASM_AU1000_PCMCIA_H 22#define __ASM_AU1000_PCMCIA_H
23 23
24/* include the world */ 24/* include the world */
25#include <pcmcia/version.h>
26#include <pcmcia/cs_types.h> 25#include <pcmcia/cs_types.h>
27#include <pcmcia/cs.h> 26#include <pcmcia/cs.h>
28#include <pcmcia/ss.h> 27#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c
index df19ce1ea4f3..d414a3bb50b9 100644
--- a/drivers/pcmcia/au1000_pb1x00.c
+++ b/drivers/pcmcia/au1000_pb1x00.c
@@ -33,7 +33,6 @@
33#include <linux/version.h> 33#include <linux/version.h>
34#include <linux/types.h> 34#include <linux/types.h>
35 35
36#include <pcmcia/version.h>
37#include <pcmcia/cs_types.h> 36#include <pcmcia/cs_types.h>
38#include <pcmcia/cs.h> 37#include <pcmcia/cs.h>
39#include <pcmcia/ss.h> 38#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c
index 1dfc77653660..f113b69d699b 100644
--- a/drivers/pcmcia/au1000_xxs1500.c
+++ b/drivers/pcmcia/au1000_xxs1500.c
@@ -38,7 +38,6 @@
38#include <linux/version.h> 38#include <linux/version.h>
39#include <linux/types.h> 39#include <linux/types.h>
40 40
41#include <pcmcia/version.h>
42#include <pcmcia/cs_types.h> 41#include <pcmcia/cs_types.h>
43#include <pcmcia/cs.h> 42#include <pcmcia/cs.h>
44#include <pcmcia/ss.h> 43#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 3ccb5247ec50..1d755e20880c 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -31,7 +31,6 @@
31#include <asm/io.h> 31#include <asm/io.h>
32 32
33#define IN_CARD_SERVICES 33#define IN_CARD_SERVICES
34#include <pcmcia/version.h>
35#include <pcmcia/cs_types.h> 34#include <pcmcia/cs_types.h>
36#include <pcmcia/ss.h> 35#include <pcmcia/ss.h>
37#include <pcmcia/cs.h> 36#include <pcmcia/cs.h>
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index e29a6ddf2fd7..dd7651ff5b43 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -89,8 +89,10 @@ static void __iomem *
89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) 89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags)
90{ 90{
91 pccard_mem_map *mem = &s->cis_mem; 91 pccard_mem_map *mem = &s->cis_mem;
92 int ret;
93
92 if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) { 94 if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) {
93 mem->res = find_mem_region(0, s->map_size, s->map_size, 0, s); 95 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s);
94 if (mem->res == NULL) { 96 if (mem->res == NULL) {
95 printk(KERN_NOTICE "cs: unable to map card memory!\n"); 97 printk(KERN_NOTICE "cs: unable to map card memory!\n");
96 return NULL; 98 return NULL;
@@ -99,7 +101,12 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
99 } 101 }
100 mem->card_start = card_offset; 102 mem->card_start = card_offset;
101 mem->flags = flags; 103 mem->flags = flags;
102 s->ops->set_mem_map(s, mem); 104 ret = s->ops->set_mem_map(s, mem);
105 if (ret) {
106 iounmap(s->cis_virt);
107 return NULL;
108 }
109
103 if (s->features & SS_CAP_STATIC_MAP) { 110 if (s->features & SS_CAP_STATIC_MAP) {
104 if (s->cis_virt) 111 if (s->cis_virt)
105 iounmap(s->cis_virt); 112 iounmap(s->cis_virt);
@@ -119,13 +126,13 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
119#define IS_ATTR 1 126#define IS_ATTR 1
120#define IS_INDIRECT 8 127#define IS_INDIRECT 8
121 128
122int read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 129int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
123 u_int len, void *ptr) 130 u_int len, void *ptr)
124{ 131{
125 void __iomem *sys, *end; 132 void __iomem *sys, *end;
126 unsigned char *buf = ptr; 133 unsigned char *buf = ptr;
127 134
128 cs_dbg(s, 3, "read_cis_mem(%d, %#x, %u)\n", attr, addr, len); 135 cs_dbg(s, 3, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
129 136
130 if (attr & IS_INDIRECT) { 137 if (attr & IS_INDIRECT) {
131 /* Indirect accesses use a bunch of special registers at fixed 138 /* Indirect accesses use a bunch of special registers at fixed
@@ -182,14 +189,16 @@ int read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
182 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 189 *(u_char *)(ptr+2), *(u_char *)(ptr+3));
183 return 0; 190 return 0;
184} 191}
192EXPORT_SYMBOL(pcmcia_read_cis_mem);
193
185 194
186void write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 195void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
187 u_int len, void *ptr) 196 u_int len, void *ptr)
188{ 197{
189 void __iomem *sys, *end; 198 void __iomem *sys, *end;
190 unsigned char *buf = ptr; 199 unsigned char *buf = ptr;
191 200
192 cs_dbg(s, 3, "write_cis_mem(%d, %#x, %u)\n", attr, addr, len); 201 cs_dbg(s, 3, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
193 202
194 if (attr & IS_INDIRECT) { 203 if (attr & IS_INDIRECT) {
195 /* Indirect accesses use a bunch of special registers at fixed 204 /* Indirect accesses use a bunch of special registers at fixed
@@ -239,6 +248,8 @@ void write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
239 } 248 }
240 } 249 }
241} 250}
251EXPORT_SYMBOL(pcmcia_write_cis_mem);
252
242 253
243/*====================================================================== 254/*======================================================================
244 255
@@ -274,7 +285,7 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
274 ret = read_cb_mem(s, attr, addr, len, ptr); 285 ret = read_cb_mem(s, attr, addr, len, ptr);
275 else 286 else
276#endif 287#endif
277 ret = read_cis_mem(s, attr, addr, len, ptr); 288 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
278 289
279 if (ret == 0) { 290 if (ret == 0) {
280 /* Copy data into the cache */ 291 /* Copy data into the cache */
@@ -348,7 +359,7 @@ int verify_cis_cache(struct pcmcia_socket *s)
348 read_cb_mem(s, cis->attr, cis->addr, len, buf); 359 read_cb_mem(s, cis->attr, cis->addr, len, buf);
349 else 360 else
350#endif 361#endif
351 read_cis_mem(s, cis->attr, cis->addr, len, buf); 362 pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
352 363
353 if (memcmp(buf, cis->cache, len) != 0) { 364 if (memcmp(buf, cis->cache, len) != 0) {
354 kfree(buf); 365 kfree(buf);
@@ -381,6 +392,7 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis)
381 memcpy(s->fake_cis, cis->Data, cis->Length); 392 memcpy(s->fake_cis, cis->Data, cis->Length);
382 return CS_SUCCESS; 393 return CS_SUCCESS;
383} 394}
395EXPORT_SYMBOL(pcmcia_replace_cis);
384 396
385/*====================================================================== 397/*======================================================================
386 398
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 48e4f04530d8..e39178fc59d0 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -33,7 +33,6 @@
33#include <asm/irq.h> 33#include <asm/irq.h>
34 34
35#define IN_CARD_SERVICES 35#define IN_CARD_SERVICES
36#include <pcmcia/version.h>
37#include <pcmcia/cs_types.h> 36#include <pcmcia/cs_types.h>
38#include <pcmcia/ss.h> 37#include <pcmcia/ss.h>
39#include <pcmcia/cs.h> 38#include <pcmcia/cs.h>
@@ -43,36 +42,11 @@
43#include <pcmcia/ds.h> 42#include <pcmcia/ds.h>
44#include "cs_internal.h" 43#include "cs_internal.h"
45 44
46#ifdef CONFIG_PCI
47#define PCI_OPT " [pci]"
48#else
49#define PCI_OPT ""
50#endif
51#ifdef CONFIG_CARDBUS
52#define CB_OPT " [cardbus]"
53#else
54#define CB_OPT ""
55#endif
56#ifdef CONFIG_PM
57#define PM_OPT " [pm]"
58#else
59#define PM_OPT ""
60#endif
61#if !defined(CONFIG_CARDBUS) && !defined(CONFIG_PCI) && !defined(CONFIG_PM)
62#define OPTIONS " none"
63#else
64#define OPTIONS PCI_OPT CB_OPT PM_OPT
65#endif
66
67static const char *release = "Linux Kernel Card Services";
68static const char *options = "options: " OPTIONS;
69
70/*====================================================================*/
71 45
72/* Module parameters */ 46/* Module parameters */
73 47
74MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); 48MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
75MODULE_DESCRIPTION("Linux Kernel Card Services\noptions:" OPTIONS); 49MODULE_DESCRIPTION("Linux Kernel Card Services");
76MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
77 51
78#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) 52#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
@@ -89,9 +63,6 @@ INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
89/* Access speed for attribute memory windows */ 63/* Access speed for attribute memory windows */
90INT_MODULE_PARM(cis_speed, 300); /* ns */ 64INT_MODULE_PARM(cis_speed, 300); /* ns */
91 65
92/* Access speed for IO windows */
93INT_MODULE_PARM(io_speed, 0); /* ns */
94
95#ifdef DEBUG 66#ifdef DEBUG
96static int pc_debug; 67static int pc_debug;
97 68
@@ -103,34 +74,26 @@ int cs_debug_level(int level)
103} 74}
104#endif 75#endif
105 76
106/*====================================================================*/
107 77
108socket_state_t dead_socket = { 78socket_state_t dead_socket = {
109 .csc_mask = SS_DETECT, 79 .csc_mask = SS_DETECT,
110}; 80};
81EXPORT_SYMBOL(dead_socket);
111 82
112 83
113/* List of all sockets, protected by a rwsem */ 84/* List of all sockets, protected by a rwsem */
114LIST_HEAD(pcmcia_socket_list); 85LIST_HEAD(pcmcia_socket_list);
115DECLARE_RWSEM(pcmcia_socket_list_rwsem);
116EXPORT_SYMBOL(pcmcia_socket_list); 86EXPORT_SYMBOL(pcmcia_socket_list);
117EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
118
119 87
120#ifdef CONFIG_PCMCIA_PROBE 88DECLARE_RWSEM(pcmcia_socket_list_rwsem);
121/* mask ofIRQs already reserved by other cards, we should avoid using them */ 89EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
122static u8 pcmcia_used_irq[NR_IRQS];
123#endif
124
125/*====================================================================
126 90
127 Low-level PC Card interface drivers need to register with Card
128 Services using these calls.
129
130======================================================================*/
131 91
132/** 92/**
133 * socket drivers are expected to use the following callbacks in their 93 * Low-level PCMCIA socket drivers need to register with the PCCard
94 * core using pcmcia_register_socket.
95 *
96 * socket drivers are expected to use the following callbacks in their
134 * .drv struct: 97 * .drv struct:
135 * - pcmcia_socket_dev_suspend 98 * - pcmcia_socket_dev_suspend
136 * - pcmcia_socket_dev_resume 99 * - pcmcia_socket_dev_resume
@@ -230,8 +193,8 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
230 } 193 }
231 194
232 /* try to obtain a socket number [yes, it gets ugly if we 195 /* try to obtain a socket number [yes, it gets ugly if we
233 * register more than 2^sizeof(unsigned int) pcmcia 196 * register more than 2^sizeof(unsigned int) pcmcia
234 * sockets... but the socket number is deprecated 197 * sockets... but the socket number is deprecated
235 * anyways, so I don't care] */ 198 * anyways, so I don't care] */
236 down_write(&pcmcia_socket_list_rwsem); 199 down_write(&pcmcia_socket_list_rwsem);
237 if (list_empty(&pcmcia_socket_list)) 200 if (list_empty(&pcmcia_socket_list))
@@ -252,6 +215,13 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
252 list_add_tail(&socket->socket_list, &pcmcia_socket_list); 215 list_add_tail(&socket->socket_list, &pcmcia_socket_list);
253 up_write(&pcmcia_socket_list_rwsem); 216 up_write(&pcmcia_socket_list_rwsem);
254 217
218#ifndef CONFIG_CARDBUS
219 /*
220 * If we do not support Cardbus, ensure that
221 * the Cardbus socket capability is disabled.
222 */
223 socket->features &= ~SS_CAP_CARDBUS;
224#endif
255 225
256 /* set proper values in socket->dev */ 226 /* set proper values in socket->dev */
257 socket->dev.class_data = socket; 227 socket->dev.class_data = socket;
@@ -340,54 +310,49 @@ struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr)
340EXPORT_SYMBOL(pcmcia_get_socket_by_nr); 310EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
341 311
342 312
343/*====================================================================== 313/**
344 314 * socket_setup() and shutdown_socket() are called by the main event
345 socket_setup() and shutdown_socket() are called by the main event 315 * handler when card insertion and removal events are received.
346 handler when card insertion and removal events are received. 316 * socket_setup() turns on socket power and resets the socket, in two stages.
347 socket_setup() turns on socket power and resets the socket, in two stages. 317 * shutdown_socket() unconfigures a socket and turns off socket power.
348 shutdown_socket() unconfigures a socket and turns off socket power. 318 */
349
350======================================================================*/
351
352static void shutdown_socket(struct pcmcia_socket *s) 319static void shutdown_socket(struct pcmcia_socket *s)
353{ 320{
354 cs_dbg(s, 1, "shutdown_socket\n"); 321 cs_dbg(s, 1, "shutdown_socket\n");
355 322
356 /* Blank out the socket state */ 323 /* Blank out the socket state */
357 s->socket = dead_socket; 324 s->socket = dead_socket;
358 s->ops->init(s); 325 s->ops->init(s);
359 s->ops->set_socket(s, &s->socket); 326 s->ops->set_socket(s, &s->socket);
360 s->irq.AssignedIRQ = s->irq.Config = 0; 327 s->irq.AssignedIRQ = s->irq.Config = 0;
361 s->lock_count = 0; 328 s->lock_count = 0;
362 destroy_cis_cache(s); 329 destroy_cis_cache(s);
363#ifdef CONFIG_CARDBUS 330#ifdef CONFIG_CARDBUS
364 cb_free(s); 331 cb_free(s);
365#endif 332#endif
366 s->functions = 0; 333 s->functions = 0;
367 if (s->config) { 334 if (s->config) {
368 kfree(s->config); 335 kfree(s->config);
369 s->config = NULL; 336 s->config = NULL;
370 }
371
372 {
373 int status;
374 s->ops->get_status(s, &status);
375 if (status & SS_POWERON) {
376 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
377 } 337 }
378 }
379} /* shutdown_socket */
380 338
381/*====================================================================== 339 {
340 int status;
341 s->ops->get_status(s, &status);
342 if (status & SS_POWERON) {
343 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
344 }
345 }
346} /* shutdown_socket */
382 347
383 The central event handler. Send_event() sends an event to the
384 16-bit subsystem, which then calls the relevant device drivers.
385 Parse_events() interprets the event bits from
386 a card status change report. Do_shutdown() handles the high
387 priority stuff associated with a card removal.
388
389======================================================================*/
390 348
349/**
350 * The central event handler. Send_event() sends an event to the
351 * 16-bit subsystem, which then calls the relevant device drivers.
352 * Parse_events() interprets the event bits from
353 * a card status change report. Do_shutdown() handles the high
354 * priority stuff associated with a card removal.
355 */
391 356
392/* NOTE: send_event needs to be called with skt->sem held. */ 357/* NOTE: send_event needs to be called with skt->sem held. */
393 358
@@ -490,11 +455,11 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
490 } 455 }
491 456
492 if (status & SS_CARDBUS) { 457 if (status & SS_CARDBUS) {
458 if (!(skt->features & SS_CAP_CARDBUS)) {
459 cs_err(skt, "cardbus cards are not supported.\n");
460 return CS_BAD_TYPE;
461 }
493 skt->state |= SOCKET_CARDBUS; 462 skt->state |= SOCKET_CARDBUS;
494#ifndef CONFIG_CARDBUS
495 cs_err(skt, "cardbus cards are not supported.\n");
496 return CS_BAD_TYPE;
497#endif
498 } 463 }
499 464
500 /* 465 /*
@@ -746,420 +711,9 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
746 wake_up(&s->thread_wait); 711 wake_up(&s->thread_wait);
747 } 712 }
748} /* pcmcia_parse_events */ 713} /* pcmcia_parse_events */
714EXPORT_SYMBOL(pcmcia_parse_events);
749 715
750 716
751/*======================================================================
752
753 Special stuff for managing IO windows, because they are scarce.
754
755======================================================================*/
756
757static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
758 ioaddr_t num, u_int lines)
759{
760 int i;
761 kio_addr_t try, align;
762
763 align = (*base) ? (lines ? 1<<lines : 0) : 1;
764 if (align && (align < num)) {
765 if (*base) {
766 cs_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
767 num, align);
768 align = 0;
769 } else
770 while (align && (align < num)) align <<= 1;
771 }
772 if (*base & ~(align-1)) {
773 cs_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
774 *base, align);
775 align = 0;
776 }
777 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
778 *base = s->io_offset | (*base & 0x0fff);
779 return 0;
780 }
781 /* Check for an already-allocated window that must conflict with
782 what was asked for. It is a hack because it does not catch all
783 potential conflicts, just the most obvious ones. */
784 for (i = 0; i < MAX_IO_WIN; i++)
785 if ((s->io[i].NumPorts != 0) &&
786 ((s->io[i].BasePort & (align-1)) == *base))
787 return 1;
788 for (i = 0; i < MAX_IO_WIN; i++) {
789 if (s->io[i].NumPorts == 0) {
790 s->io[i].res = find_io_region(*base, num, align, s);
791 if (s->io[i].res) {
792 s->io[i].Attributes = attr;
793 s->io[i].BasePort = *base = s->io[i].res->start;
794 s->io[i].NumPorts = s->io[i].InUse = num;
795 break;
796 } else
797 return 1;
798 } else if (s->io[i].Attributes != attr)
799 continue;
800 /* Try to extend top of window */
801 try = s->io[i].BasePort + s->io[i].NumPorts;
802 if ((*base == 0) || (*base == try))
803 if (adjust_io_region(s->io[i].res, s->io[i].res->start,
804 s->io[i].res->end + num, s) == 0) {
805 *base = try;
806 s->io[i].NumPorts += num;
807 s->io[i].InUse += num;
808 break;
809 }
810 /* Try to extend bottom of window */
811 try = s->io[i].BasePort - num;
812 if ((*base == 0) || (*base == try))
813 if (adjust_io_region(s->io[i].res, s->io[i].res->start - num,
814 s->io[i].res->end, s) == 0) {
815 s->io[i].BasePort = *base = try;
816 s->io[i].NumPorts += num;
817 s->io[i].InUse += num;
818 break;
819 }
820 }
821 return (i == MAX_IO_WIN);
822} /* alloc_io_space */
823
824static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
825 ioaddr_t num)
826{
827 int i;
828
829 for (i = 0; i < MAX_IO_WIN; i++) {
830 if ((s->io[i].BasePort <= base) &&
831 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) {
832 s->io[i].InUse -= num;
833 /* Free the window if no one else is using it */
834 if (s->io[i].InUse == 0) {
835 s->io[i].NumPorts = 0;
836 release_resource(s->io[i].res);
837 kfree(s->io[i].res);
838 s->io[i].res = NULL;
839 }
840 }
841 }
842}
843
844/*======================================================================
845
846 Access_configuration_register() reads and writes configuration
847 registers in attribute memory. Memory window 0 is reserved for
848 this and the tuple reading services.
849
850======================================================================*/
851
852int pccard_access_configuration_register(struct pcmcia_socket *s,
853 unsigned int function,
854 conf_reg_t *reg)
855{
856 config_t *c;
857 int addr;
858 u_char val;
859
860 if (!s || !s->config)
861 return CS_NO_CARD;
862
863 c = &s->config[function];
864
865 if (c == NULL)
866 return CS_NO_CARD;
867
868 if (!(c->state & CONFIG_LOCKED))
869 return CS_CONFIGURATION_LOCKED;
870
871 addr = (c->ConfigBase + reg->Offset) >> 1;
872
873 switch (reg->Action) {
874 case CS_READ:
875 read_cis_mem(s, 1, addr, 1, &val);
876 reg->Value = val;
877 break;
878 case CS_WRITE:
879 val = reg->Value;
880 write_cis_mem(s, 1, addr, 1, &val);
881 break;
882 default:
883 return CS_BAD_ARGS;
884 break;
885 }
886 return CS_SUCCESS;
887} /* access_configuration_register */
888EXPORT_SYMBOL(pccard_access_configuration_register);
889
890
891/*====================================================================*/
892
893int pccard_get_configuration_info(struct pcmcia_socket *s,
894 unsigned int function,
895 config_info_t *config)
896{
897 config_t *c;
898
899 if (!(s->state & SOCKET_PRESENT))
900 return CS_NO_CARD;
901
902 config->Function = function;
903
904#ifdef CONFIG_CARDBUS
905 if (s->state & SOCKET_CARDBUS) {
906 memset(config, 0, sizeof(config_info_t));
907 config->Vcc = s->socket.Vcc;
908 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
909 config->Option = s->cb_dev->subordinate->number;
910 if (s->state & SOCKET_CARDBUS_CONFIG) {
911 config->Attributes = CONF_VALID_CLIENT;
912 config->IntType = INT_CARDBUS;
913 config->AssignedIRQ = s->irq.AssignedIRQ;
914 if (config->AssignedIRQ)
915 config->Attributes |= CONF_ENABLE_IRQ;
916 config->BasePort1 = s->io[0].BasePort;
917 config->NumPorts1 = s->io[0].NumPorts;
918 }
919 return CS_SUCCESS;
920 }
921#endif
922
923 c = (s->config != NULL) ? &s->config[function] : NULL;
924
925 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
926 config->Attributes = 0;
927 config->Vcc = s->socket.Vcc;
928 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
929 return CS_SUCCESS;
930 }
931
932 /* !!! This is a hack !!! */
933 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
934 config->Attributes |= CONF_VALID_CLIENT;
935 config->CardValues = c->CardValues;
936 config->IRQAttributes = c->irq.Attributes;
937 config->AssignedIRQ = s->irq.AssignedIRQ;
938 config->BasePort1 = c->io.BasePort1;
939 config->NumPorts1 = c->io.NumPorts1;
940 config->Attributes1 = c->io.Attributes1;
941 config->BasePort2 = c->io.BasePort2;
942 config->NumPorts2 = c->io.NumPorts2;
943 config->Attributes2 = c->io.Attributes2;
944 config->IOAddrLines = c->io.IOAddrLines;
945
946 return CS_SUCCESS;
947} /* get_configuration_info */
948EXPORT_SYMBOL(pccard_get_configuration_info);
949
950/*======================================================================
951
952 Return information about this version of Card Services.
953
954======================================================================*/
955
956int pcmcia_get_card_services_info(servinfo_t *info)
957{
958 unsigned int socket_count = 0;
959 struct list_head *tmp;
960 info->Signature[0] = 'C';
961 info->Signature[1] = 'S';
962 down_read(&pcmcia_socket_list_rwsem);
963 list_for_each(tmp, &pcmcia_socket_list)
964 socket_count++;
965 up_read(&pcmcia_socket_list_rwsem);
966 info->Count = socket_count;
967 info->Revision = CS_RELEASE_CODE;
968 info->CSLevel = 0x0210;
969 info->VendorString = (char *)release;
970 return CS_SUCCESS;
971} /* get_card_services_info */
972
973
974/*====================================================================*/
975
976int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req)
977{
978 window_t *win;
979 int w;
980
981 if (!s || !(s->state & SOCKET_PRESENT))
982 return CS_NO_CARD;
983 for (w = idx; w < MAX_WIN; w++)
984 if (s->state & SOCKET_WIN_REQ(w)) break;
985 if (w == MAX_WIN)
986 return CS_NO_MORE_ITEMS;
987 win = &s->win[w];
988 req->Base = win->ctl.res->start;
989 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
990 req->AccessSpeed = win->ctl.speed;
991 req->Attributes = 0;
992 if (win->ctl.flags & MAP_ATTRIB)
993 req->Attributes |= WIN_MEMORY_TYPE_AM;
994 if (win->ctl.flags & MAP_ACTIVE)
995 req->Attributes |= WIN_ENABLE;
996 if (win->ctl.flags & MAP_16BIT)
997 req->Attributes |= WIN_DATA_WIDTH_16;
998 if (win->ctl.flags & MAP_USE_WAIT)
999 req->Attributes |= WIN_USE_WAIT;
1000 *handle = win;
1001 return CS_SUCCESS;
1002} /* get_window */
1003EXPORT_SYMBOL(pcmcia_get_window);
1004
1005/*=====================================================================
1006
1007 Return the PCI device associated with a card..
1008
1009======================================================================*/
1010
1011#ifdef CONFIG_CARDBUS
1012
1013struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
1014{
1015 if (!s || !(s->state & SOCKET_CARDBUS))
1016 return NULL;
1017
1018 return s->cb_dev->subordinate;
1019}
1020
1021EXPORT_SYMBOL(pcmcia_lookup_bus);
1022
1023#endif
1024
1025/*======================================================================
1026
1027 Get the current socket state bits. We don't support the latched
1028 SocketState yet: I haven't seen any point for it.
1029
1030======================================================================*/
1031
1032int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status)
1033{
1034 config_t *c;
1035 int val;
1036
1037 s->ops->get_status(s, &val);
1038 status->CardState = status->SocketState = 0;
1039 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
1040 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
1041 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
1042 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
1043 if (s->state & SOCKET_SUSPEND)
1044 status->CardState |= CS_EVENT_PM_SUSPEND;
1045 if (!(s->state & SOCKET_PRESENT))
1046 return CS_NO_CARD;
1047
1048 c = (s->config != NULL) ? &s->config[function] : NULL;
1049 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
1050 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
1051 u_char reg;
1052 if (c->Present & PRESENT_PIN_REPLACE) {
1053 read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
1054 status->CardState |=
1055 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
1056 status->CardState |=
1057 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
1058 status->CardState |=
1059 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
1060 status->CardState |=
1061 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
1062 } else {
1063 /* No PRR? Then assume we're always ready */
1064 status->CardState |= CS_EVENT_READY_CHANGE;
1065 }
1066 if (c->Present & PRESENT_EXT_STATUS) {
1067 read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
1068 status->CardState |=
1069 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
1070 }
1071 return CS_SUCCESS;
1072 }
1073 status->CardState |=
1074 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
1075 status->CardState |=
1076 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
1077 status->CardState |=
1078 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
1079 status->CardState |=
1080 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
1081 return CS_SUCCESS;
1082} /* get_status */
1083EXPORT_SYMBOL(pccard_get_status);
1084
1085/*======================================================================
1086
1087 Change the card address of an already open memory window.
1088
1089======================================================================*/
1090
1091int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
1092{
1093 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1094 return CS_BAD_HANDLE;
1095 req->Page = 0;
1096 req->CardOffset = win->ctl.card_start;
1097 return CS_SUCCESS;
1098} /* get_mem_page */
1099
1100int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
1101{
1102 struct pcmcia_socket *s;
1103 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1104 return CS_BAD_HANDLE;
1105 if (req->Page != 0)
1106 return CS_BAD_PAGE;
1107 s = win->sock;
1108 win->ctl.card_start = req->CardOffset;
1109 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1110 return CS_BAD_OFFSET;
1111 return CS_SUCCESS;
1112} /* map_mem_page */
1113
1114/*======================================================================
1115
1116 Modify a locked socket configuration
1117
1118======================================================================*/
1119
1120int pcmcia_modify_configuration(client_handle_t handle,
1121 modconf_t *mod)
1122{
1123 struct pcmcia_socket *s;
1124 config_t *c;
1125
1126 if (CHECK_HANDLE(handle))
1127 return CS_BAD_HANDLE;
1128 s = SOCKET(handle); c = CONFIG(handle);
1129 if (!(s->state & SOCKET_PRESENT))
1130 return CS_NO_CARD;
1131 if (!(c->state & CONFIG_LOCKED))
1132 return CS_CONFIGURATION_LOCKED;
1133
1134 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
1135 if (mod->Attributes & CONF_ENABLE_IRQ) {
1136 c->Attributes |= CONF_ENABLE_IRQ;
1137 s->socket.io_irq = s->irq.AssignedIRQ;
1138 } else {
1139 c->Attributes &= ~CONF_ENABLE_IRQ;
1140 s->socket.io_irq = 0;
1141 }
1142 s->ops->set_socket(s, &s->socket);
1143 }
1144
1145 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
1146 return CS_BAD_VCC;
1147
1148 /* We only allow changing Vpp1 and Vpp2 to the same value */
1149 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
1150 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
1151 if (mod->Vpp1 != mod->Vpp2)
1152 return CS_BAD_VPP;
1153 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1;
1154 if (s->ops->set_socket(s, &s->socket))
1155 return CS_BAD_VPP;
1156 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
1157 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
1158 return CS_BAD_VPP;
1159
1160 return CS_SUCCESS;
1161} /* modify_configuration */
1162
1163/* register pcmcia_callback */ 717/* register pcmcia_callback */
1164int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) 718int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1165{ 719{
@@ -1188,543 +742,16 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1188} 742}
1189EXPORT_SYMBOL(pccard_register_pcmcia); 743EXPORT_SYMBOL(pccard_register_pcmcia);
1190 744
1191/*====================================================================*/
1192
1193int pcmcia_release_configuration(client_handle_t handle)
1194{
1195 pccard_io_map io = { 0, 0, 0, 0, 1 };
1196 struct pcmcia_socket *s;
1197 int i;
1198
1199 if (CHECK_HANDLE(handle) ||
1200 !(handle->state & CLIENT_CONFIG_LOCKED))
1201 return CS_BAD_HANDLE;
1202 handle->state &= ~CLIENT_CONFIG_LOCKED;
1203 s = SOCKET(handle);
1204
1205#ifdef CONFIG_CARDBUS
1206 if (handle->state & CLIENT_CARDBUS)
1207 return CS_SUCCESS;
1208#endif
1209
1210 if (!(handle->state & CLIENT_STALE)) {
1211 config_t *c = CONFIG(handle);
1212 if (--(s->lock_count) == 0) {
1213 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
1214 s->socket.Vpp = 0;
1215 s->socket.io_irq = 0;
1216 s->ops->set_socket(s, &s->socket);
1217 }
1218 if (c->state & CONFIG_IO_REQ)
1219 for (i = 0; i < MAX_IO_WIN; i++) {
1220 if (s->io[i].NumPorts == 0)
1221 continue;
1222 s->io[i].Config--;
1223 if (s->io[i].Config != 0)
1224 continue;
1225 io.map = i;
1226 s->ops->set_io_map(s, &io);
1227 }
1228 c->state &= ~CONFIG_LOCKED;
1229 }
1230
1231 return CS_SUCCESS;
1232} /* release_configuration */
1233
1234/*======================================================================
1235 745
1236 Release_io() releases the I/O ranges allocated by a client. This 746/* I'm not sure which "reset" function this is supposed to use,
1237 may be invoked some time after a card ejection has already dumped 747 * but for now, it uses the low-level interface's reset, not the
1238 the actual socket configuration, so if the client is "stale", we 748 * CIS register.
1239 don't bother checking the port ranges against the current socket 749 */
1240 values.
1241
1242======================================================================*/
1243
1244int pcmcia_release_io(client_handle_t handle, io_req_t *req)
1245{
1246 struct pcmcia_socket *s;
1247
1248 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ))
1249 return CS_BAD_HANDLE;
1250 handle->state &= ~CLIENT_IO_REQ;
1251 s = SOCKET(handle);
1252
1253#ifdef CONFIG_CARDBUS
1254 if (handle->state & CLIENT_CARDBUS)
1255 return CS_SUCCESS;
1256#endif
1257
1258 if (!(handle->state & CLIENT_STALE)) {
1259 config_t *c = CONFIG(handle);
1260 if (c->state & CONFIG_LOCKED)
1261 return CS_CONFIGURATION_LOCKED;
1262 if ((c->io.BasePort1 != req->BasePort1) ||
1263 (c->io.NumPorts1 != req->NumPorts1) ||
1264 (c->io.BasePort2 != req->BasePort2) ||
1265 (c->io.NumPorts2 != req->NumPorts2))
1266 return CS_BAD_ARGS;
1267 c->state &= ~CONFIG_IO_REQ;
1268 }
1269
1270 release_io_space(s, req->BasePort1, req->NumPorts1);
1271 if (req->NumPorts2)
1272 release_io_space(s, req->BasePort2, req->NumPorts2);
1273
1274 return CS_SUCCESS;
1275} /* release_io */
1276
1277/*====================================================================*/
1278
1279int pcmcia_release_irq(client_handle_t handle, irq_req_t *req)
1280{
1281 struct pcmcia_socket *s;
1282 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ))
1283 return CS_BAD_HANDLE;
1284 handle->state &= ~CLIENT_IRQ_REQ;
1285 s = SOCKET(handle);
1286
1287 if (!(handle->state & CLIENT_STALE)) {
1288 config_t *c = CONFIG(handle);
1289 if (c->state & CONFIG_LOCKED)
1290 return CS_CONFIGURATION_LOCKED;
1291 if (c->irq.Attributes != req->Attributes)
1292 return CS_BAD_ATTRIBUTE;
1293 if (s->irq.AssignedIRQ != req->AssignedIRQ)
1294 return CS_BAD_IRQ;
1295 if (--s->irq.Config == 0) {
1296 c->state &= ~CONFIG_IRQ_REQ;
1297 s->irq.AssignedIRQ = 0;
1298 }
1299 }
1300
1301 if (req->Attributes & IRQ_HANDLE_PRESENT) {
1302 free_irq(req->AssignedIRQ, req->Instance);
1303 }
1304
1305#ifdef CONFIG_PCMCIA_PROBE
1306 pcmcia_used_irq[req->AssignedIRQ]--;
1307#endif
1308
1309 return CS_SUCCESS;
1310} /* cs_release_irq */
1311
1312/*====================================================================*/
1313
1314int pcmcia_release_window(window_handle_t win)
1315{
1316 struct pcmcia_socket *s;
1317
1318 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1319 return CS_BAD_HANDLE;
1320 s = win->sock;
1321 if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
1322 return CS_BAD_HANDLE;
1323
1324 /* Shut down memory window */
1325 win->ctl.flags &= ~MAP_ACTIVE;
1326 s->ops->set_mem_map(s, &win->ctl);
1327 s->state &= ~SOCKET_WIN_REQ(win->index);
1328
1329 /* Release system memory */
1330 if (win->ctl.res) {
1331 release_resource(win->ctl.res);
1332 kfree(win->ctl.res);
1333 win->ctl.res = NULL;
1334 }
1335 win->handle->state &= ~CLIENT_WIN_REQ(win->index);
1336
1337 win->magic = 0;
1338
1339 return CS_SUCCESS;
1340} /* release_window */
1341
1342/*====================================================================*/
1343
1344int pcmcia_request_configuration(client_handle_t handle,
1345 config_req_t *req)
1346{
1347 int i;
1348 u_int base;
1349 struct pcmcia_socket *s;
1350 config_t *c;
1351 pccard_io_map iomap;
1352
1353 if (CHECK_HANDLE(handle))
1354 return CS_BAD_HANDLE;
1355 s = SOCKET(handle);
1356 if (!(s->state & SOCKET_PRESENT))
1357 return CS_NO_CARD;
1358
1359#ifdef CONFIG_CARDBUS
1360 if (handle->state & CLIENT_CARDBUS)
1361 return CS_UNSUPPORTED_MODE;
1362#endif
1363
1364 if (req->IntType & INT_CARDBUS)
1365 return CS_UNSUPPORTED_MODE;
1366 c = CONFIG(handle);
1367 if (c->state & CONFIG_LOCKED)
1368 return CS_CONFIGURATION_LOCKED;
1369
1370 /* Do power control. We don't allow changes in Vcc. */
1371 if (s->socket.Vcc != req->Vcc)
1372 return CS_BAD_VCC;
1373 if (req->Vpp1 != req->Vpp2)
1374 return CS_BAD_VPP;
1375 s->socket.Vpp = req->Vpp1;
1376 if (s->ops->set_socket(s, &s->socket))
1377 return CS_BAD_VPP;
1378
1379 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
1380
1381 /* Pick memory or I/O card, DMA mode, interrupt */
1382 c->IntType = req->IntType;
1383 c->Attributes = req->Attributes;
1384 if (req->IntType & INT_MEMORY_AND_IO)
1385 s->socket.flags |= SS_IOCARD;
1386 if (req->IntType & INT_ZOOMED_VIDEO)
1387 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
1388 if (req->Attributes & CONF_ENABLE_DMA)
1389 s->socket.flags |= SS_DMA_MODE;
1390 if (req->Attributes & CONF_ENABLE_SPKR)
1391 s->socket.flags |= SS_SPKR_ENA;
1392 if (req->Attributes & CONF_ENABLE_IRQ)
1393 s->socket.io_irq = s->irq.AssignedIRQ;
1394 else
1395 s->socket.io_irq = 0;
1396 s->ops->set_socket(s, &s->socket);
1397 s->lock_count++;
1398
1399 /* Set up CIS configuration registers */
1400 base = c->ConfigBase = req->ConfigBase;
1401 c->Present = c->CardValues = req->Present;
1402 if (req->Present & PRESENT_COPY) {
1403 c->Copy = req->Copy;
1404 write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
1405 }
1406 if (req->Present & PRESENT_OPTION) {
1407 if (s->functions == 1) {
1408 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
1409 } else {
1410 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
1411 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
1412 if (req->Present & PRESENT_IOBASE_0)
1413 c->Option |= COR_ADDR_DECODE;
1414 }
1415 if (c->state & CONFIG_IRQ_REQ)
1416 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
1417 c->Option |= COR_LEVEL_REQ;
1418 write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
1419 mdelay(40);
1420 }
1421 if (req->Present & PRESENT_STATUS) {
1422 c->Status = req->Status;
1423 write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
1424 }
1425 if (req->Present & PRESENT_PIN_REPLACE) {
1426 c->Pin = req->Pin;
1427 write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
1428 }
1429 if (req->Present & PRESENT_EXT_STATUS) {
1430 c->ExtStatus = req->ExtStatus;
1431 write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
1432 }
1433 if (req->Present & PRESENT_IOBASE_0) {
1434 u_char b = c->io.BasePort1 & 0xff;
1435 write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
1436 b = (c->io.BasePort1 >> 8) & 0xff;
1437 write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
1438 }
1439 if (req->Present & PRESENT_IOSIZE) {
1440 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
1441 write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
1442 }
1443
1444 /* Configure I/O windows */
1445 if (c->state & CONFIG_IO_REQ) {
1446 iomap.speed = io_speed;
1447 for (i = 0; i < MAX_IO_WIN; i++)
1448 if (s->io[i].NumPorts != 0) {
1449 iomap.map = i;
1450 iomap.flags = MAP_ACTIVE;
1451 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) {
1452 case IO_DATA_PATH_WIDTH_16:
1453 iomap.flags |= MAP_16BIT; break;
1454 case IO_DATA_PATH_WIDTH_AUTO:
1455 iomap.flags |= MAP_AUTOSZ; break;
1456 default:
1457 break;
1458 }
1459 iomap.start = s->io[i].BasePort;
1460 iomap.stop = iomap.start + s->io[i].NumPorts - 1;
1461 s->ops->set_io_map(s, &iomap);
1462 s->io[i].Config++;
1463 }
1464 }
1465
1466 c->state |= CONFIG_LOCKED;
1467 handle->state |= CLIENT_CONFIG_LOCKED;
1468 return CS_SUCCESS;
1469} /* request_configuration */
1470
1471/*======================================================================
1472
1473 Request_io() reserves ranges of port addresses for a socket.
1474 I have not implemented range sharing or alias addressing.
1475
1476======================================================================*/
1477
1478int pcmcia_request_io(client_handle_t handle, io_req_t *req)
1479{
1480 struct pcmcia_socket *s;
1481 config_t *c;
1482
1483 if (CHECK_HANDLE(handle))
1484 return CS_BAD_HANDLE;
1485 s = SOCKET(handle);
1486 if (!(s->state & SOCKET_PRESENT))
1487 return CS_NO_CARD;
1488
1489 if (handle->state & CLIENT_CARDBUS) {
1490#ifdef CONFIG_CARDBUS
1491 handle->state |= CLIENT_IO_REQ;
1492 return CS_SUCCESS;
1493#else
1494 return CS_UNSUPPORTED_FUNCTION;
1495#endif
1496 }
1497
1498 if (!req)
1499 return CS_UNSUPPORTED_MODE;
1500 c = CONFIG(handle);
1501 if (c->state & CONFIG_LOCKED)
1502 return CS_CONFIGURATION_LOCKED;
1503 if (c->state & CONFIG_IO_REQ)
1504 return CS_IN_USE;
1505 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
1506 return CS_BAD_ATTRIBUTE;
1507 if ((req->NumPorts2 > 0) &&
1508 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
1509 return CS_BAD_ATTRIBUTE;
1510
1511 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
1512 req->NumPorts1, req->IOAddrLines))
1513 return CS_IN_USE;
1514
1515 if (req->NumPorts2) {
1516 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
1517 req->NumPorts2, req->IOAddrLines)) {
1518 release_io_space(s, req->BasePort1, req->NumPorts1);
1519 return CS_IN_USE;
1520 }
1521 }
1522
1523 c->io = *req;
1524 c->state |= CONFIG_IO_REQ;
1525 handle->state |= CLIENT_IO_REQ;
1526 return CS_SUCCESS;
1527} /* request_io */
1528
1529/*======================================================================
1530
1531 Request_irq() reserves an irq for this client.
1532
1533 Also, since Linux only reserves irq's when they are actually
1534 hooked, we don't guarantee that an irq will still be available
1535 when the configuration is locked. Now that I think about it,
1536 there might be a way to fix this using a dummy handler.
1537
1538======================================================================*/
1539
1540#ifdef CONFIG_PCMCIA_PROBE
1541static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
1542{
1543 return IRQ_NONE;
1544}
1545#endif
1546
1547int pcmcia_request_irq(client_handle_t handle, irq_req_t *req)
1548{
1549 struct pcmcia_socket *s;
1550 config_t *c;
1551 int ret = CS_IN_USE, irq = 0;
1552 struct pcmcia_device *p_dev = handle_to_pdev(handle);
1553
1554 if (CHECK_HANDLE(handle))
1555 return CS_BAD_HANDLE;
1556 s = SOCKET(handle);
1557 if (!(s->state & SOCKET_PRESENT))
1558 return CS_NO_CARD;
1559 c = CONFIG(handle);
1560 if (c->state & CONFIG_LOCKED)
1561 return CS_CONFIGURATION_LOCKED;
1562 if (c->state & CONFIG_IRQ_REQ)
1563 return CS_IN_USE;
1564
1565#ifdef CONFIG_PCMCIA_PROBE
1566 if (s->irq.AssignedIRQ != 0) {
1567 /* If the interrupt is already assigned, it must be the same */
1568 irq = s->irq.AssignedIRQ;
1569 } else {
1570 int try;
1571 u32 mask = s->irq_mask;
1572 void *data = NULL;
1573
1574 for (try = 0; try < 64; try++) {
1575 irq = try % 32;
1576
1577 /* marked as available by driver, and not blocked by userspace? */
1578 if (!((mask >> irq) & 1))
1579 continue;
1580
1581 /* avoid an IRQ which is already used by a PCMCIA card */
1582 if ((try < 32) && pcmcia_used_irq[irq])
1583 continue;
1584
1585 /* register the correct driver, if possible, of check whether
1586 * registering a dummy handle works, i.e. if the IRQ isn't
1587 * marked as used by the kernel resource management core */
1588 ret = request_irq(irq,
1589 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
1590 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1591 (s->functions > 1) ||
1592 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1593 p_dev->dev.bus_id,
1594 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
1595 if (!ret) {
1596 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
1597 free_irq(irq, data);
1598 break;
1599 }
1600 }
1601 }
1602#endif
1603 if (ret) {
1604 if (!s->pci_irq)
1605 return ret;
1606 irq = s->pci_irq;
1607 }
1608
1609 if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
1610 if (request_irq(irq, req->Handler,
1611 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1612 (s->functions > 1) ||
1613 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1614 p_dev->dev.bus_id, req->Instance))
1615 return CS_IN_USE;
1616 }
1617
1618 c->irq.Attributes = req->Attributes;
1619 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
1620 s->irq.Config++;
1621
1622 c->state |= CONFIG_IRQ_REQ;
1623 handle->state |= CLIENT_IRQ_REQ;
1624
1625#ifdef CONFIG_PCMCIA_PROBE
1626 pcmcia_used_irq[irq]++;
1627#endif
1628
1629 return CS_SUCCESS;
1630} /* pcmcia_request_irq */
1631
1632/*======================================================================
1633
1634 Request_window() establishes a mapping between card memory space
1635 and system memory space.
1636
1637======================================================================*/
1638
1639int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh)
1640{
1641 struct pcmcia_socket *s;
1642 window_t *win;
1643 u_long align;
1644 int w;
1645
1646 if (CHECK_HANDLE(*handle))
1647 return CS_BAD_HANDLE;
1648 s = (*handle)->Socket;
1649 if (!(s->state & SOCKET_PRESENT))
1650 return CS_NO_CARD;
1651 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
1652 return CS_BAD_ATTRIBUTE;
1653
1654 /* Window size defaults to smallest available */
1655 if (req->Size == 0)
1656 req->Size = s->map_size;
1657 align = (((s->features & SS_CAP_MEM_ALIGN) ||
1658 (req->Attributes & WIN_STRICT_ALIGN)) ?
1659 req->Size : s->map_size);
1660 if (req->Size & (s->map_size-1))
1661 return CS_BAD_SIZE;
1662 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
1663 (req->Base & (align-1)))
1664 return CS_BAD_BASE;
1665 if (req->Base)
1666 align = 0;
1667
1668 /* Allocate system memory window */
1669 for (w = 0; w < MAX_WIN; w++)
1670 if (!(s->state & SOCKET_WIN_REQ(w))) break;
1671 if (w == MAX_WIN)
1672 return CS_OUT_OF_RESOURCE;
1673
1674 win = &s->win[w];
1675 win->magic = WINDOW_MAGIC;
1676 win->index = w;
1677 win->handle = *handle;
1678 win->sock = s;
1679
1680 if (!(s->features & SS_CAP_STATIC_MAP)) {
1681 win->ctl.res = find_mem_region(req->Base, req->Size, align,
1682 (req->Attributes & WIN_MAP_BELOW_1MB), s);
1683 if (!win->ctl.res)
1684 return CS_IN_USE;
1685 }
1686 (*handle)->state |= CLIENT_WIN_REQ(w);
1687
1688 /* Configure the socket controller */
1689 win->ctl.map = w+1;
1690 win->ctl.flags = 0;
1691 win->ctl.speed = req->AccessSpeed;
1692 if (req->Attributes & WIN_MEMORY_TYPE)
1693 win->ctl.flags |= MAP_ATTRIB;
1694 if (req->Attributes & WIN_ENABLE)
1695 win->ctl.flags |= MAP_ACTIVE;
1696 if (req->Attributes & WIN_DATA_WIDTH_16)
1697 win->ctl.flags |= MAP_16BIT;
1698 if (req->Attributes & WIN_USE_WAIT)
1699 win->ctl.flags |= MAP_USE_WAIT;
1700 win->ctl.card_start = 0;
1701 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1702 return CS_BAD_ARGS;
1703 s->state |= SOCKET_WIN_REQ(w);
1704
1705 /* Return window handle */
1706 if (s->features & SS_CAP_STATIC_MAP) {
1707 req->Base = win->ctl.static_start;
1708 } else {
1709 req->Base = win->ctl.res->start;
1710 }
1711 *wh = win;
1712
1713 return CS_SUCCESS;
1714} /* request_window */
1715
1716/*======================================================================
1717
1718 I'm not sure which "reset" function this is supposed to use,
1719 but for now, it uses the low-level interface's reset, not the
1720 CIS register.
1721
1722======================================================================*/
1723 750
1724int pccard_reset_card(struct pcmcia_socket *skt) 751int pccard_reset_card(struct pcmcia_socket *skt)
1725{ 752{
1726 int ret; 753 int ret;
1727 754
1728 cs_dbg(skt, 1, "resetting socket\n"); 755 cs_dbg(skt, 1, "resetting socket\n");
1729 756
1730 down(&skt->skt_sem); 757 down(&skt->skt_sem);
@@ -1757,17 +784,14 @@ int pccard_reset_card(struct pcmcia_socket *skt)
1757} /* reset_card */ 784} /* reset_card */
1758EXPORT_SYMBOL(pccard_reset_card); 785EXPORT_SYMBOL(pccard_reset_card);
1759 786
1760/*======================================================================
1761
1762 These shut down or wake up a socket. They are sort of user
1763 initiated versions of the APM suspend and resume actions.
1764
1765======================================================================*/
1766 787
788/* These shut down or wake up a socket. They are sort of user
789 * initiated versions of the APM suspend and resume actions.
790 */
1767int pcmcia_suspend_card(struct pcmcia_socket *skt) 791int pcmcia_suspend_card(struct pcmcia_socket *skt)
1768{ 792{
1769 int ret; 793 int ret;
1770 794
1771 cs_dbg(skt, 1, "suspending socket\n"); 795 cs_dbg(skt, 1, "suspending socket\n");
1772 796
1773 down(&skt->skt_sem); 797 down(&skt->skt_sem);
@@ -1786,6 +810,8 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
1786 810
1787 return ret; 811 return ret;
1788} /* suspend_card */ 812} /* suspend_card */
813EXPORT_SYMBOL(pcmcia_suspend_card);
814
1789 815
1790int pcmcia_resume_card(struct pcmcia_socket *skt) 816int pcmcia_resume_card(struct pcmcia_socket *skt)
1791{ 817{
@@ -1809,13 +835,10 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
1809 835
1810 return ret; 836 return ret;
1811} /* resume_card */ 837} /* resume_card */
838EXPORT_SYMBOL(pcmcia_resume_card);
1812 839
1813/*======================================================================
1814
1815 These handle user requests to eject or insert a card.
1816
1817======================================================================*/
1818 840
841/* These handle user requests to eject or insert a card. */
1819int pcmcia_eject_card(struct pcmcia_socket *skt) 842int pcmcia_eject_card(struct pcmcia_socket *skt)
1820{ 843{
1821 int ret; 844 int ret;
@@ -1842,6 +865,8 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
1842 865
1843 return ret; 866 return ret;
1844} /* eject_card */ 867} /* eject_card */
868EXPORT_SYMBOL(pcmcia_eject_card);
869
1845 870
1846int pcmcia_insert_card(struct pcmcia_socket *skt) 871int pcmcia_insert_card(struct pcmcia_socket *skt)
1847{ 872{
@@ -1865,37 +890,38 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
1865 890
1866 return ret; 891 return ret;
1867} /* insert_card */ 892} /* insert_card */
893EXPORT_SYMBOL(pcmcia_insert_card);
1868 894
1869/*======================================================================
1870 895
1871 OS-specific module glue goes here 896static int pcmcia_socket_hotplug(struct class_device *dev, char **envp,
1872 897 int num_envp, char *buffer, int buffer_size)
1873======================================================================*/ 898{
1874/* in alpha order */ 899 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
1875EXPORT_SYMBOL(pcmcia_eject_card); 900 int i = 0, length = 0;
1876EXPORT_SYMBOL(pcmcia_get_card_services_info); 901
1877EXPORT_SYMBOL(pcmcia_get_mem_page); 902 if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size,
1878EXPORT_SYMBOL(pcmcia_insert_card); 903 &length, "SOCKET_NO=%u", s->sock))
1879EXPORT_SYMBOL(pcmcia_map_mem_page); 904 return -ENOMEM;
1880EXPORT_SYMBOL(pcmcia_modify_configuration); 905
1881EXPORT_SYMBOL(pcmcia_release_configuration); 906 envp[i] = NULL;
1882EXPORT_SYMBOL(pcmcia_release_io); 907
1883EXPORT_SYMBOL(pcmcia_release_irq); 908 return 0;
1884EXPORT_SYMBOL(pcmcia_release_window); 909}
1885EXPORT_SYMBOL(pcmcia_replace_cis); 910
1886EXPORT_SYMBOL(pcmcia_request_configuration); 911
1887EXPORT_SYMBOL(pcmcia_request_io); 912static struct completion pcmcia_unload;
1888EXPORT_SYMBOL(pcmcia_request_irq); 913
1889EXPORT_SYMBOL(pcmcia_request_window); 914static void pcmcia_release_socket_class(struct class *data)
1890EXPORT_SYMBOL(pcmcia_resume_card); 915{
1891EXPORT_SYMBOL(pcmcia_suspend_card); 916 complete(&pcmcia_unload);
917}
1892 918
1893EXPORT_SYMBOL(dead_socket);
1894EXPORT_SYMBOL(pcmcia_parse_events);
1895 919
1896struct class pcmcia_socket_class = { 920struct class pcmcia_socket_class = {
1897 .name = "pcmcia_socket", 921 .name = "pcmcia_socket",
922 .hotplug = pcmcia_socket_hotplug,
1898 .release = pcmcia_release_socket, 923 .release = pcmcia_release_socket,
924 .class_release = pcmcia_release_socket_class,
1899}; 925};
1900EXPORT_SYMBOL(pcmcia_socket_class); 926EXPORT_SYMBOL(pcmcia_socket_class);
1901 927
@@ -1903,9 +929,8 @@ EXPORT_SYMBOL(pcmcia_socket_class);
1903static int __init init_pcmcia_cs(void) 929static int __init init_pcmcia_cs(void)
1904{ 930{
1905 int ret; 931 int ret;
1906 printk(KERN_INFO "%s\n", release);
1907 printk(KERN_INFO " %s\n", options);
1908 932
933 init_completion(&pcmcia_unload);
1909 ret = class_register(&pcmcia_socket_class); 934 ret = class_register(&pcmcia_socket_class);
1910 if (ret) 935 if (ret)
1911 return (ret); 936 return (ret);
@@ -1914,13 +939,12 @@ static int __init init_pcmcia_cs(void)
1914 939
1915static void __exit exit_pcmcia_cs(void) 940static void __exit exit_pcmcia_cs(void)
1916{ 941{
1917 printk(KERN_INFO "unloading Kernel Card Services\n"); 942 class_interface_unregister(&pccard_sysfs_interface);
1918 class_interface_unregister(&pccard_sysfs_interface); 943 class_unregister(&pcmcia_socket_class);
1919 class_unregister(&pcmcia_socket_class); 944
945 wait_for_completion(&pcmcia_unload);
1920} 946}
1921 947
1922subsys_initcall(init_pcmcia_cs); 948subsys_initcall(init_pcmcia_cs);
1923module_exit(exit_pcmcia_cs); 949module_exit(exit_pcmcia_cs);
1924 950
1925/*====================================================================*/
1926
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 7933a7db49d3..6bbfbd0e02a5 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -99,23 +99,11 @@ static inline void cs_socket_put(struct pcmcia_socket *skt)
99 } 99 }
100} 100}
101 101
102#define CHECK_HANDLE(h) \
103 (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
104
105#define CHECK_SOCKET(s) \ 102#define CHECK_SOCKET(s) \
106 (((s) >= sockets) || (socket_table[s]->ops == NULL)) 103 (((s) >= sockets) || (socket_table[s]->ops == NULL))
107 104
108#define SOCKET(h) (h->Socket) 105#define SOCKET(h) (h->socket)
109#define CONFIG(h) (&SOCKET(h)->config[(h)->Function]) 106#define CONFIG(h) (&SOCKET(h)->config[(h)->func])
110
111#define CHECK_REGION(r) \
112 (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
113
114#define CHECK_ERASEQ(q) \
115 (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
116
117#define EVENT(h, e, p) \
118 ((h)->event_handler((e), (p), &(h)->event_callback_args))
119 107
120/* In cardbus.c */ 108/* In cardbus.c */
121int cb_alloc(struct pcmcia_socket *s); 109int cb_alloc(struct pcmcia_socket *s);
@@ -123,9 +111,9 @@ void cb_free(struct pcmcia_socket *s);
123int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr); 111int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
124 112
125/* In cistpl.c */ 113/* In cistpl.c */
126int read_cis_mem(struct pcmcia_socket *s, int attr, 114int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
127 u_int addr, u_int len, void *ptr); 115 u_int addr, u_int len, void *ptr);
128void write_cis_mem(struct pcmcia_socket *s, int attr, 116void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
129 u_int addr, u_int len, void *ptr); 117 u_int addr, u_int len, void *ptr);
130void release_cis_mem(struct pcmcia_socket *s); 118void release_cis_mem(struct pcmcia_socket *s);
131void destroy_cis_cache(struct pcmcia_socket *s); 119void destroy_cis_cache(struct pcmcia_socket *s);
@@ -134,13 +122,12 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t
134 122
135/* In rsrc_mgr */ 123/* In rsrc_mgr */
136void pcmcia_validate_mem(struct pcmcia_socket *s); 124void pcmcia_validate_mem(struct pcmcia_socket *s);
137struct resource *find_io_region(unsigned long base, int num, unsigned long align, 125struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
138 struct pcmcia_socket *s); 126 struct pcmcia_socket *s);
139int adjust_io_region(struct resource *res, unsigned long r_start, 127int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
140 unsigned long r_end, struct pcmcia_socket *s); 128 unsigned long r_end, struct pcmcia_socket *s);
141struct resource *find_mem_region(u_long base, u_long num, u_long align, 129struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
142 int low, struct pcmcia_socket *s); 130 int low, struct pcmcia_socket *s);
143int adjust_resource_info(client_handle_t handle, adjust_t *adj);
144void release_resource_db(struct pcmcia_socket *s); 131void release_resource_db(struct pcmcia_socket *s);
145 132
146/* In socket_sysfs.c */ 133/* In socket_sysfs.c */
@@ -159,7 +146,7 @@ int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int f
159struct pcmcia_callback{ 146struct pcmcia_callback{
160 struct module *owner; 147 struct module *owner;
161 int (*event) (struct pcmcia_socket *s, event_t event, int priority); 148 int (*event) (struct pcmcia_socket *s, event_t event, int priority);
162 int (*resources_done) (struct pcmcia_socket *s); 149 void (*requery) (struct pcmcia_socket *s);
163}; 150};
164 151
165int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 152int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 569e55feecfd..3e3c6f12bbe6 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -10,44 +10,29 @@
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 * 11 *
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2004 Dominik Brodowski 13 * (C) 2003 - 2005 Dominik Brodowski
14 */ 14 */
15 15
16#include <linux/config.h> 16#include <linux/config.h>
17#include <linux/kernel.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/major.h>
22#include <linux/string.h>
23#include <linux/errno.h> 20#include <linux/errno.h>
24#include <linux/slab.h>
25#include <linux/mm.h>
26#include <linux/fcntl.h>
27#include <linux/sched.h>
28#include <linux/smp_lock.h>
29#include <linux/timer.h>
30#include <linux/ioctl.h>
31#include <linux/proc_fs.h>
32#include <linux/poll.h>
33#include <linux/pci.h>
34#include <linux/list.h> 21#include <linux/list.h>
35#include <linux/delay.h> 22#include <linux/delay.h>
36#include <linux/kref.h>
37#include <linux/workqueue.h> 23#include <linux/workqueue.h>
38 24#include <linux/crc32.h>
39#include <asm/atomic.h> 25#include <linux/firmware.h>
40 26
41#define IN_CARD_SERVICES 27#define IN_CARD_SERVICES
42#include <pcmcia/version.h>
43#include <pcmcia/cs_types.h> 28#include <pcmcia/cs_types.h>
44#include <pcmcia/cs.h> 29#include <pcmcia/cs.h>
45#include <pcmcia/bulkmem.h>
46#include <pcmcia/cistpl.h> 30#include <pcmcia/cistpl.h>
47#include <pcmcia/ds.h> 31#include <pcmcia/ds.h>
48#include <pcmcia/ss.h> 32#include <pcmcia/ss.h>
49 33
50#include "cs_internal.h" 34#include "cs_internal.h"
35#include "ds_internal.h"
51 36
52/*====================================================================*/ 37/*====================================================================*/
53 38
@@ -70,49 +55,9 @@ module_param_named(pc_debug, ds_pc_debug, int, 0644);
70#define ds_dbg(lvl, fmt, arg...) do { } while (0) 55#define ds_dbg(lvl, fmt, arg...) do { } while (0)
71#endif 56#endif
72 57
73/*====================================================================*/ 58spinlock_t pcmcia_dev_list_lock;
74 59
75/* Device user information */ 60static int unbind_request(struct pcmcia_socket *s);
76#define MAX_EVENTS 32
77#define USER_MAGIC 0x7ea4
78#define CHECK_USER(u) \
79 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
80typedef struct user_info_t {
81 u_int user_magic;
82 int event_head, event_tail;
83 event_t event[MAX_EVENTS];
84 struct user_info_t *next;
85 struct pcmcia_bus_socket *socket;
86} user_info_t;
87
88/* Socket state information */
89struct pcmcia_bus_socket {
90 struct kref refcount;
91 struct pcmcia_callback callback;
92 int state;
93 user_info_t *user;
94 wait_queue_head_t queue;
95 struct pcmcia_socket *parent;
96
97 /* the PCMCIA devices connected to this socket (normally one, more
98 * for multifunction devices: */
99 struct list_head devices_list;
100 u8 device_count; /* the number of devices, used
101 * only internally and subject
102 * to incorrectness and change */
103};
104static spinlock_t pcmcia_dev_list_lock;
105
106#define DS_SOCKET_PRESENT 0x01
107#define DS_SOCKET_BUSY 0x02
108#define DS_SOCKET_REMOVAL_PENDING 0x10
109#define DS_SOCKET_DEAD 0x80
110
111/*====================================================================*/
112
113static int major_dev = -1;
114
115static int unbind_request(struct pcmcia_bus_socket *s);
116 61
117/*====================================================================*/ 62/*====================================================================*/
118 63
@@ -213,17 +158,15 @@ static const lookup_t service_table[] = {
213}; 158};
214 159
215 160
216int pcmcia_report_error(client_handle_t handle, error_info_t *err) 161static int pcmcia_report_error(struct pcmcia_device *p_dev, error_info_t *err)
217{ 162{
218 int i; 163 int i;
219 char *serv; 164 char *serv;
220 165
221 if (CHECK_HANDLE(handle)) 166 if (!p_dev)
222 printk(KERN_NOTICE); 167 printk(KERN_NOTICE);
223 else { 168 else
224 struct pcmcia_device *p_dev = handle_to_pdev(handle);
225 printk(KERN_NOTICE "%s: ", p_dev->dev.bus_id); 169 printk(KERN_NOTICE "%s: ", p_dev->dev.bus_id);
226 }
227 170
228 for (i = 0; i < ARRAY_SIZE(service_table); i++) 171 for (i = 0; i < ARRAY_SIZE(service_table); i++)
229 if (service_table[i].key == err->func) 172 if (service_table[i].key == err->func)
@@ -243,42 +186,117 @@ int pcmcia_report_error(client_handle_t handle, error_info_t *err)
243 186
244 return CS_SUCCESS; 187 return CS_SUCCESS;
245} /* report_error */ 188} /* report_error */
246EXPORT_SYMBOL(pcmcia_report_error);
247 189
248/* end of code which was in cs.c before */ 190/* end of code which was in cs.c before */
249 191
250/*======================================================================*/ 192/*======================================================================*/
251 193
252void cs_error(client_handle_t handle, int func, int ret) 194void cs_error(struct pcmcia_device *p_dev, int func, int ret)
253{ 195{
254 error_info_t err = { func, ret }; 196 error_info_t err = { func, ret };
255 pcmcia_report_error(handle, &err); 197 pcmcia_report_error(p_dev, &err);
256} 198}
257EXPORT_SYMBOL(cs_error); 199EXPORT_SYMBOL(cs_error);
258 200
259/*======================================================================*/
260
261static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info);
262static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr);
263 201
264static void pcmcia_release_bus_socket(struct kref *refcount) 202static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
265{ 203{
266 struct pcmcia_bus_socket *s = container_of(refcount, struct pcmcia_bus_socket, refcount); 204 struct pcmcia_device_id *did = p_drv->id_table;
267 pcmcia_put_socket(s->parent); 205 unsigned int i;
268 kfree(s); 206 u32 hash;
207
208 if (!p_drv->attach || !p_drv->event || !p_drv->detach)
209 printk(KERN_DEBUG "pcmcia: %s does misses a callback function",
210 p_drv->drv.name);
211
212 while (did && did->match_flags) {
213 for (i=0; i<4; i++) {
214 if (!did->prod_id[i])
215 continue;
216
217 hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i]));
218 if (hash == did->prod_id_hash[i])
219 continue;
220
221 printk(KERN_DEBUG "pcmcia: %s: invalid hash for "
222 "product string \"%s\": is 0x%x, should "
223 "be 0x%x\n", p_drv->drv.name, did->prod_id[i],
224 did->prod_id_hash[i], hash);
225 printk(KERN_DEBUG "pcmcia: see "
226 "Documentation/pcmcia/devicetable.txt for "
227 "details\n");
228 }
229 did++;
230 }
231
232 return;
269} 233}
270 234
271static void pcmcia_put_bus_socket(struct pcmcia_bus_socket *s) 235
236#ifdef CONFIG_PCMCIA_LOAD_CIS
237
238/**
239 * pcmcia_load_firmware - load CIS from userspace if device-provided is broken
240 * @dev - the pcmcia device which needs a CIS override
241 * @filename - requested filename in /lib/firmware/cis/
242 *
243 * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if
244 * the one provided by the card is broken. The firmware files reside in
245 * /lib/firmware/cis/ in userspace.
246 */
247static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
272{ 248{
273 kref_put(&s->refcount, pcmcia_release_bus_socket); 249 struct pcmcia_socket *s = dev->socket;
250 const struct firmware *fw;
251 char path[20];
252 int ret=-ENOMEM;
253 cisdump_t *cis;
254
255 if (!filename)
256 return -EINVAL;
257
258 ds_dbg(1, "trying to load firmware %s\n", filename);
259
260 if (strlen(filename) > 14)
261 return -EINVAL;
262
263 snprintf(path, 20, "%s", filename);
264
265 if (request_firmware(&fw, path, &dev->dev) == 0) {
266 if (fw->size >= CISTPL_MAX_CIS_SIZE)
267 goto release;
268
269 cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL);
270 if (!cis)
271 goto release;
272
273 memset(cis, 0, sizeof(cisdump_t));
274
275 cis->Length = fw->size + 1;
276 memcpy(cis->Data, fw->data, fw->size);
277
278 if (!pcmcia_replace_cis(s, cis))
279 ret = 0;
280 }
281 release:
282 release_firmware(fw);
283
284 return (ret);
274} 285}
275 286
276static struct pcmcia_bus_socket *pcmcia_get_bus_socket(struct pcmcia_bus_socket *s) 287#else /* !CONFIG_PCMCIA_LOAD_CIS */
288
289static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
277{ 290{
278 kref_get(&s->refcount); 291 return -ENODEV;
279 return (s);
280} 292}
281 293
294#endif
295
296
297/*======================================================================*/
298
299
282/** 300/**
283 * pcmcia_register_driver - register a PCMCIA driver with the bus core 301 * pcmcia_register_driver - register a PCMCIA driver with the bus core
284 * 302 *
@@ -292,6 +310,8 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
292 if (!driver) 310 if (!driver)
293 return -EINVAL; 311 return -EINVAL;
294 312
313 pcmcia_check_driver(driver);
314
295 /* initialize common fields */ 315 /* initialize common fields */
296 driver->drv.bus = &pcmcia_bus_type; 316 driver->drv.bus = &pcmcia_bus_type;
297 driver->drv.owner = driver->owner; 317 driver->drv.owner = driver->owner;
@@ -311,42 +331,10 @@ void pcmcia_unregister_driver(struct pcmcia_driver *driver)
311} 331}
312EXPORT_SYMBOL(pcmcia_unregister_driver); 332EXPORT_SYMBOL(pcmcia_unregister_driver);
313 333
314#ifdef CONFIG_PROC_FS
315static struct proc_dir_entry *proc_pccard = NULL;
316
317static int proc_read_drivers_callback(struct device_driver *driver, void *d)
318{
319 char **p = d;
320 struct pcmcia_driver *p_drv = container_of(driver,
321 struct pcmcia_driver, drv);
322
323 *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name,
324#ifdef CONFIG_MODULE_UNLOAD
325 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
326#else
327 1
328#endif
329 );
330 d = (void *) p;
331
332 return 0;
333}
334
335static int proc_read_drivers(char *buf, char **start, off_t pos,
336 int count, int *eof, void *data)
337{
338 char *p = buf;
339
340 bus_for_each_drv(&pcmcia_bus_type, NULL,
341 (void *) &p, proc_read_drivers_callback);
342
343 return (p - buf);
344}
345#endif
346 334
347/* pcmcia_device handling */ 335/* pcmcia_device handling */
348 336
349static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) 337struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
350{ 338{
351 struct device *tmp_dev; 339 struct device *tmp_dev;
352 tmp_dev = get_device(&p_dev->dev); 340 tmp_dev = get_device(&p_dev->dev);
@@ -355,7 +343,7 @@ static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
355 return to_pcmcia_dev(tmp_dev); 343 return to_pcmcia_dev(tmp_dev);
356} 344}
357 345
358static void pcmcia_put_dev(struct pcmcia_device *p_dev) 346void pcmcia_put_dev(struct pcmcia_device *p_dev)
359{ 347{
360 if (p_dev) 348 if (p_dev)
361 put_device(&p_dev->dev); 349 put_device(&p_dev->dev);
@@ -365,7 +353,7 @@ static void pcmcia_release_dev(struct device *dev)
365{ 353{
366 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 354 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
367 ds_dbg(1, "releasing dev %p\n", p_dev); 355 ds_dbg(1, "releasing dev %p\n", p_dev);
368 pcmcia_put_bus_socket(p_dev->socket->pcmcia); 356 pcmcia_put_socket(p_dev->socket);
369 kfree(p_dev); 357 kfree(p_dev);
370} 358}
371 359
@@ -390,7 +378,7 @@ static int pcmcia_device_probe(struct device * dev)
390 378
391 if (p_drv->attach) { 379 if (p_drv->attach) {
392 p_dev->instance = p_drv->attach(); 380 p_dev->instance = p_drv->attach();
393 if ((!p_dev->instance) || (p_dev->client.state & CLIENT_UNBOUND)) { 381 if ((!p_dev->instance) || (p_dev->state & CLIENT_UNBOUND)) {
394 printk(KERN_NOTICE "ds: unable to create instance " 382 printk(KERN_NOTICE "ds: unable to create instance "
395 "of '%s'!\n", p_drv->drv.name); 383 "of '%s'!\n", p_drv->drv.name);
396 ret = -EINVAL; 384 ret = -EINVAL;
@@ -500,42 +488,45 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
500 */ 488 */
501static DECLARE_MUTEX(device_add_lock); 489static DECLARE_MUTEX(device_add_lock);
502 490
503static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, unsigned int function) 491struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
504{ 492{
505 struct pcmcia_device *p_dev; 493 struct pcmcia_device *p_dev;
506 unsigned long flags; 494 unsigned long flags;
507 495
508 s = pcmcia_get_bus_socket(s); 496 s = pcmcia_get_socket(s);
509 if (!s) 497 if (!s)
510 return NULL; 498 return NULL;
511 499
512 down(&device_add_lock); 500 down(&device_add_lock);
513 501
502 /* max of 2 devices per card */
503 if (s->device_count == 2)
504 goto err_put;
505
514 p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); 506 p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
515 if (!p_dev) 507 if (!p_dev)
516 goto err_put; 508 goto err_put;
517 memset(p_dev, 0, sizeof(struct pcmcia_device)); 509 memset(p_dev, 0, sizeof(struct pcmcia_device));
518 510
519 p_dev->socket = s->parent; 511 p_dev->socket = s;
520 p_dev->device_no = (s->device_count++); 512 p_dev->device_no = (s->device_count++);
521 p_dev->func = function; 513 p_dev->func = function;
522 514
523 p_dev->dev.bus = &pcmcia_bus_type; 515 p_dev->dev.bus = &pcmcia_bus_type;
524 p_dev->dev.parent = s->parent->dev.dev; 516 p_dev->dev.parent = s->dev.dev;
525 p_dev->dev.release = pcmcia_release_dev; 517 p_dev->dev.release = pcmcia_release_dev;
526 sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no); 518 sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
527 519
528 /* compat */ 520 /* compat */
529 p_dev->client.client_magic = CLIENT_MAGIC; 521 p_dev->state = CLIENT_UNBOUND;
530 p_dev->client.Socket = s->parent;
531 p_dev->client.Function = function;
532 p_dev->client.state = CLIENT_UNBOUND;
533 522
534 /* Add to the list in pcmcia_bus_socket */ 523 /* Add to the list in pcmcia_bus_socket */
535 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 524 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
536 list_add_tail(&p_dev->socket_device_list, &s->devices_list); 525 list_add_tail(&p_dev->socket_device_list, &s->devices_list);
537 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 526 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
538 527
528 pcmcia_device_query(p_dev);
529
539 if (device_register(&p_dev->dev)) { 530 if (device_register(&p_dev->dev)) {
540 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 531 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
541 list_del(&p_dev->socket_device_list); 532 list_del(&p_dev->socket_device_list);
@@ -553,7 +544,7 @@ static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, uns
553 s->device_count--; 544 s->device_count--;
554 err_put: 545 err_put:
555 up(&device_add_lock); 546 up(&device_add_lock);
556 pcmcia_put_bus_socket(s); 547 pcmcia_put_socket(s);
557 548
558 return NULL; 549 return NULL;
559} 550}
@@ -581,26 +572,253 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
581 else 572 else
582 no_funcs = 1; 573 no_funcs = 1;
583 574
584 /* this doesn't handle multifunction devices on one pcmcia function
585 * yet. */
586 for (i=0; i < no_funcs; i++) 575 for (i=0; i < no_funcs; i++)
587 pcmcia_device_add(s->pcmcia, i); 576 pcmcia_device_add(s, i);
588 577
589 return (ret); 578 return (ret);
590} 579}
591 580
592 581
582static void pcmcia_delayed_add_pseudo_device(void *data)
583{
584 struct pcmcia_socket *s = data;
585 pcmcia_device_add(s, 0);
586 s->pcmcia_state.device_add_pending = 0;
587}
588
589static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
590{
591 if (!s->pcmcia_state.device_add_pending) {
592 schedule_work(&s->device_add);
593 s->pcmcia_state.device_add_pending = 1;
594 }
595 return;
596}
597
598static int pcmcia_requery(struct device *dev, void * _data)
599{
600 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
601 if (!p_dev->dev.driver)
602 pcmcia_device_query(p_dev);
603
604 return 0;
605}
606
607static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
608{
609 int no_devices=0;
610 unsigned long flags;
611
612 /* must be called with skt_sem held */
613 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
614 if (list_empty(&skt->devices_list))
615 no_devices=1;
616 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
617
618 /* if no devices were added for this socket yet because of
619 * missing resource information or other trouble, we need to
620 * do this now. */
621 if (no_devices) {
622 int ret = pcmcia_card_add(skt);
623 if (ret)
624 return;
625 }
626
627 /* some device information might have changed because of a CIS
628 * update or because we can finally read it correctly... so
629 * determine it again, overwriting old values if necessary. */
630 bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery);
631
632 /* we re-scan all devices, not just the ones connected to this
633 * socket. This does not matter, though. */
634 bus_rescan_devices(&pcmcia_bus_type);
635}
636
637static inline int pcmcia_devmatch(struct pcmcia_device *dev,
638 struct pcmcia_device_id *did)
639{
640 if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) {
641 if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id))
642 return 0;
643 }
644
645 if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) {
646 if ((!dev->has_card_id) || (dev->card_id != did->card_id))
647 return 0;
648 }
649
650 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) {
651 if (dev->func != did->function)
652 return 0;
653 }
654
655 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) {
656 if (!dev->prod_id[0])
657 return 0;
658 if (strcmp(did->prod_id[0], dev->prod_id[0]))
659 return 0;
660 }
661
662 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) {
663 if (!dev->prod_id[1])
664 return 0;
665 if (strcmp(did->prod_id[1], dev->prod_id[1]))
666 return 0;
667 }
668
669 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) {
670 if (!dev->prod_id[2])
671 return 0;
672 if (strcmp(did->prod_id[2], dev->prod_id[2]))
673 return 0;
674 }
675
676 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) {
677 if (!dev->prod_id[3])
678 return 0;
679 if (strcmp(did->prod_id[3], dev->prod_id[3]))
680 return 0;
681 }
682
683 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
684 /* handle pseudo multifunction devices:
685 * there are at most two pseudo multifunction devices.
686 * if we're matching against the first, schedule a
687 * call which will then check whether there are two
688 * pseudo devices, and if not, add the second one.
689 */
690 if (dev->device_no == 0)
691 pcmcia_add_pseudo_device(dev->socket);
692
693 if (dev->device_no != did->device_no)
694 return 0;
695 }
696
697 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
698 if ((!dev->has_func_id) || (dev->func_id != did->func_id))
699 return 0;
700
701 /* if this is a pseudo-multi-function device,
702 * we need explicit matches */
703 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO)
704 return 0;
705 if (dev->device_no)
706 return 0;
707
708 /* also, FUNC_ID matching needs to be activated by userspace
709 * after it has re-checked that there is no possible module
710 * with a prod_id/manf_id/card_id match.
711 */
712 if (!dev->allow_func_id_match)
713 return 0;
714 }
715
716 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
717 if (!dev->socket->fake_cis)
718 pcmcia_load_firmware(dev, did->cisfile);
719
720 if (!dev->socket->fake_cis)
721 return 0;
722 }
723
724 if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) {
725 int i;
726 for (i=0; i<4; i++)
727 if (dev->prod_id[i])
728 return 0;
729 if (dev->has_manf_id || dev->has_card_id || dev->has_func_id)
730 return 0;
731 }
732
733 dev->dev.driver_data = (void *) did;
734
735 return 1;
736}
737
738
593static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) { 739static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
594 struct pcmcia_device * p_dev = to_pcmcia_dev(dev); 740 struct pcmcia_device * p_dev = to_pcmcia_dev(dev);
595 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); 741 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
742 struct pcmcia_device_id *did = p_drv->id_table;
596 743
597 /* matching by cardmgr */ 744 /* matching by cardmgr */
598 if (p_dev->cardmgr == p_drv) 745 if (p_dev->cardmgr == p_drv)
599 return 1; 746 return 1;
600 747
748 while (did && did->match_flags) {
749 if (pcmcia_devmatch(p_dev, did))
750 return 1;
751 did++;
752 }
753
754 return 0;
755}
756
757#ifdef CONFIG_HOTPLUG
758
759static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
760 char *buffer, int buffer_size)
761{
762 struct pcmcia_device *p_dev;
763 int i, length = 0;
764 u32 hash[4] = { 0, 0, 0, 0};
765
766 if (!dev)
767 return -ENODEV;
768
769 p_dev = to_pcmcia_dev(dev);
770
771 /* calculate hashes */
772 for (i=0; i<4; i++) {
773 if (!p_dev->prod_id[i])
774 continue;
775 hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i]));
776 }
777
778 i = 0;
779
780 if (add_hotplug_env_var(envp, num_envp, &i,
781 buffer, buffer_size, &length,
782 "SOCKET_NO=%u",
783 p_dev->socket->sock))
784 return -ENOMEM;
785
786 if (add_hotplug_env_var(envp, num_envp, &i,
787 buffer, buffer_size, &length,
788 "DEVICE_NO=%02X",
789 p_dev->device_no))
790 return -ENOMEM;
791
792 if (add_hotplug_env_var(envp, num_envp, &i,
793 buffer, buffer_size, &length,
794 "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
795 "pa%08Xpb%08Xpc%08Xpd%08X",
796 p_dev->has_manf_id ? p_dev->manf_id : 0,
797 p_dev->has_card_id ? p_dev->card_id : 0,
798 p_dev->has_func_id ? p_dev->func_id : 0,
799 p_dev->func,
800 p_dev->device_no,
801 hash[0],
802 hash[1],
803 hash[2],
804 hash[3]))
805 return -ENOMEM;
806
807 envp[i] = NULL;
808
601 return 0; 809 return 0;
602} 810}
603 811
812#else
813
814static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
815 char *buffer, int buffer_size)
816{
817 return -ENODEV;
818}
819
820#endif
821
604/************************ per-device sysfs output ***************************/ 822/************************ per-device sysfs output ***************************/
605 823
606#define pcmcia_device_attr(field, test, format) \ 824#define pcmcia_device_attr(field, test, format) \
@@ -626,6 +844,43 @@ pcmcia_device_stringattr(prod_id2, prod_id[1]);
626pcmcia_device_stringattr(prod_id3, prod_id[2]); 844pcmcia_device_stringattr(prod_id3, prod_id[2]);
627pcmcia_device_stringattr(prod_id4, prod_id[3]); 845pcmcia_device_stringattr(prod_id4, prod_id[3]);
628 846
847static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
848{
849 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
850 int i;
851 u32 hash[4] = { 0, 0, 0, 0};
852
853 /* calculate hashes */
854 for (i=0; i<4; i++) {
855 if (!p_dev->prod_id[i])
856 continue;
857 hash[i] = crc32(0,p_dev->prod_id[i],strlen(p_dev->prod_id[i]));
858 }
859 return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
860 "pa%08Xpb%08Xpc%08Xpd%08X\n",
861 p_dev->has_manf_id ? p_dev->manf_id : 0,
862 p_dev->has_card_id ? p_dev->card_id : 0,
863 p_dev->has_func_id ? p_dev->func_id : 0,
864 p_dev->func, p_dev->device_no,
865 hash[0], hash[1], hash[2], hash[3]);
866}
867
868static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
869 struct device_attribute *attr, const char *buf, size_t count)
870{
871 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
872 if (!count)
873 return -EINVAL;
874
875 down(&p_dev->socket->skt_sem);
876 p_dev->allow_func_id_match = 1;
877 up(&p_dev->socket->skt_sem);
878
879 bus_rescan_devices(&pcmcia_bus_type);
880
881 return count;
882}
883
629static struct device_attribute pcmcia_dev_attrs[] = { 884static struct device_attribute pcmcia_dev_attrs[] = {
630 __ATTR(function, 0444, func_show, NULL), 885 __ATTR(function, 0444, func_show, NULL),
631 __ATTR_RO(func_id), 886 __ATTR_RO(func_id),
@@ -635,46 +890,14 @@ static struct device_attribute pcmcia_dev_attrs[] = {
635 __ATTR_RO(prod_id2), 890 __ATTR_RO(prod_id2),
636 __ATTR_RO(prod_id3), 891 __ATTR_RO(prod_id3),
637 __ATTR_RO(prod_id4), 892 __ATTR_RO(prod_id4),
893 __ATTR_RO(modalias),
894 __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match),
638 __ATTR_NULL, 895 __ATTR_NULL,
639}; 896};
640 897
641 898
642/*====================================================================== 899/*======================================================================
643 900
644 These manage a ring buffer of events pending for one user process
645
646======================================================================*/
647
648static int queue_empty(user_info_t *user)
649{
650 return (user->event_head == user->event_tail);
651}
652
653static event_t get_queued_event(user_info_t *user)
654{
655 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
656 return user->event[user->event_tail];
657}
658
659static void queue_event(user_info_t *user, event_t event)
660{
661 user->event_head = (user->event_head+1) % MAX_EVENTS;
662 if (user->event_head == user->event_tail)
663 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
664 user->event[user->event_head] = event;
665}
666
667static void handle_event(struct pcmcia_bus_socket *s, event_t event)
668{
669 user_info_t *user;
670 for (user = s->user; user; user = user->next)
671 queue_event(user, event);
672 wake_up_interruptible(&s->queue);
673}
674
675
676/*======================================================================
677
678 The card status event handler. 901 The card status event handler.
679 902
680======================================================================*/ 903======================================================================*/
@@ -688,6 +911,7 @@ struct send_event_data {
688static int send_event_callback(struct device *dev, void * _data) 911static int send_event_callback(struct device *dev, void * _data)
689{ 912{
690 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 913 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
914 struct pcmcia_driver *p_drv;
691 struct send_event_data *data = _data; 915 struct send_event_data *data = _data;
692 916
693 /* we get called for all sockets, but may only pass the event 917 /* we get called for all sockets, but may only pass the event
@@ -695,32 +919,29 @@ static int send_event_callback(struct device *dev, void * _data)
695 if (p_dev->socket != data->skt) 919 if (p_dev->socket != data->skt)
696 return 0; 920 return 0;
697 921
698 if (p_dev->client.state & (CLIENT_UNBOUND|CLIENT_STALE)) 922 p_drv = to_pcmcia_drv(p_dev->dev.driver);
923 if (!p_drv)
699 return 0; 924 return 0;
700 925
701 if (p_dev->client.EventMask & data->event) 926 if (p_dev->state & (CLIENT_UNBOUND|CLIENT_STALE))
702 return EVENT(&p_dev->client, data->event, data->priority); 927 return 0;
928
929 if (p_drv->event)
930 return p_drv->event(data->event, data->priority,
931 &p_dev->event_callback_args);
703 932
704 return 0; 933 return 0;
705} 934}
706 935
707static int send_event(struct pcmcia_socket *s, event_t event, int priority) 936static int send_event(struct pcmcia_socket *s, event_t event, int priority)
708{ 937{
709 int ret = 0;
710 struct send_event_data private; 938 struct send_event_data private;
711 struct pcmcia_bus_socket *skt = pcmcia_get_bus_socket(s->pcmcia);
712
713 if (!skt)
714 return 0;
715 939
716 private.skt = s; 940 private.skt = s;
717 private.event = event; 941 private.event = event;
718 private.priority = priority; 942 private.priority = priority;
719 943
720 ret = bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback); 944 return bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback);
721
722 pcmcia_put_bus_socket(skt);
723 return ret;
724} /* send_event */ 945} /* send_event */
725 946
726 947
@@ -731,25 +952,25 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority)
731 952
732static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) 953static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
733{ 954{
734 struct pcmcia_bus_socket *s = skt->pcmcia; 955 struct pcmcia_socket *s = pcmcia_get_socket(skt);
735 int ret = 0; 956 int ret = 0;
736 957
737 ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", 958 ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n",
738 event, priority, s); 959 event, priority, skt);
739 960
740 switch (event) { 961 switch (event) {
741 962
742 case CS_EVENT_CARD_REMOVAL: 963 case CS_EVENT_CARD_REMOVAL:
743 s->state &= ~DS_SOCKET_PRESENT; 964 s->pcmcia_state.present = 0;
744 send_event(skt, event, priority); 965 send_event(skt, event, priority);
745 unbind_request(s); 966 unbind_request(skt);
746 handle_event(s, event); 967 handle_event(skt, event);
747 break; 968 break;
748 969
749 case CS_EVENT_CARD_INSERTION: 970 case CS_EVENT_CARD_INSERTION:
750 s->state |= DS_SOCKET_PRESENT; 971 s->pcmcia_state.present = 1;
751 pcmcia_card_add(skt); 972 pcmcia_card_add(skt);
752 handle_event(s, event); 973 handle_event(skt, event);
753 break; 974 break;
754 975
755 case CS_EVENT_EJECTION_REQUEST: 976 case CS_EVENT_EJECTION_REQUEST:
@@ -757,138 +978,23 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
757 break; 978 break;
758 979
759 default: 980 default:
760 handle_event(s, event); 981 handle_event(skt, event);
761 send_event(skt, event, priority); 982 send_event(skt, event, priority);
762 break; 983 break;
763 } 984 }
764 985
986 pcmcia_put_socket(s);
987
765 return 0; 988 return 0;
766} /* ds_event */ 989} /* ds_event */
767 990
768 991
769/*======================================================================
770
771 bind_request() and bind_device() are merged by now. Register_client()
772 is called right at the end of bind_request(), during the driver's
773 ->attach() call. Individual descriptions:
774
775 bind_request() connects a socket to a particular client driver.
776 It looks up the specified device ID in the list of registered
777 drivers, binds it to the socket, and tries to create an instance
778 of the device. unbind_request() deletes a driver instance.
779
780 Bind_device() associates a device driver with a particular socket.
781 It is normally called by Driver Services after it has identified
782 a newly inserted card. An instance of that driver will then be
783 eligible to register as a client of this socket.
784
785 Register_client() uses the dev_info_t handle to match the
786 caller with a socket. The driver must have already been bound
787 to a socket with bind_device() -- in fact, bind_device()
788 allocates the client structure that will be used.
789 992
790======================================================================*/ 993int pcmcia_register_client(struct pcmcia_device **handle, client_reg_t *req)
791
792static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info)
793{
794 struct pcmcia_driver *p_drv;
795 struct pcmcia_device *p_dev;
796 int ret = 0;
797 unsigned long flags;
798
799 s = pcmcia_get_bus_socket(s);
800 if (!s)
801 return -EINVAL;
802
803 ds_dbg(2, "bind_request(%d, '%s')\n", s->parent->sock,
804 (char *)bind_info->dev_info);
805
806 p_drv = get_pcmcia_driver(&bind_info->dev_info);
807 if (!p_drv) {
808 ret = -EINVAL;
809 goto err_put;
810 }
811
812 if (!try_module_get(p_drv->owner)) {
813 ret = -EINVAL;
814 goto err_put_driver;
815 }
816
817 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
818 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
819 if (p_dev->func == bind_info->function) {
820 if ((p_dev->dev.driver == &p_drv->drv)) {
821 if (p_dev->cardmgr) {
822 /* if there's already a device
823 * registered, and it was registered
824 * by userspace before, we need to
825 * return the "instance". */
826 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
827 bind_info->instance = p_dev->instance;
828 ret = -EBUSY;
829 goto err_put_module;
830 } else {
831 /* the correct driver managed to bind
832 * itself magically to the correct
833 * device. */
834 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
835 p_dev->cardmgr = p_drv;
836 ret = 0;
837 goto err_put_module;
838 }
839 } else if (!p_dev->dev.driver) {
840 /* there's already a device available where
841 * no device has been bound to yet. So we don't
842 * need to register a device! */
843 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
844 goto rescan;
845 }
846 }
847 }
848 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
849
850 p_dev = pcmcia_device_add(s, bind_info->function);
851 if (!p_dev) {
852 ret = -EIO;
853 goto err_put_module;
854 }
855
856rescan:
857 p_dev->cardmgr = p_drv;
858
859 pcmcia_device_query(p_dev);
860
861 /*
862 * Prevent this racing with a card insertion.
863 */
864 down(&s->parent->skt_sem);
865 bus_rescan_devices(&pcmcia_bus_type);
866 up(&s->parent->skt_sem);
867
868 /* check whether the driver indeed matched. I don't care if this
869 * is racy or not, because it can only happen on cardmgr access
870 * paths...
871 */
872 if (!(p_dev->dev.driver == &p_drv->drv))
873 p_dev->cardmgr = NULL;
874
875 err_put_module:
876 module_put(p_drv->owner);
877 err_put_driver:
878 put_driver(&p_drv->drv);
879 err_put:
880 pcmcia_put_bus_socket(s);
881
882 return (ret);
883} /* bind_request */
884
885
886int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
887{ 994{
888 client_t *client = NULL; 995 struct pcmcia_socket *s = NULL;
889 struct pcmcia_socket *s;
890 struct pcmcia_bus_socket *skt = NULL;
891 struct pcmcia_device *p_dev = NULL; 996 struct pcmcia_device *p_dev = NULL;
997 struct pcmcia_driver *p_drv = NULL;
892 998
893 /* Look for unbound client with matching dev_info */ 999 /* Look for unbound client with matching dev_info */
894 down_read(&pcmcia_socket_list_rwsem); 1000 down_read(&pcmcia_socket_list_rwsem);
@@ -898,56 +1004,45 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
898 if (s->state & SOCKET_CARDBUS) 1004 if (s->state & SOCKET_CARDBUS)
899 continue; 1005 continue;
900 1006
901 skt = s->pcmcia; 1007 s = pcmcia_get_socket(s);
902 if (!skt) 1008 if (!s)
903 continue;
904 skt = pcmcia_get_bus_socket(skt);
905 if (!skt)
906 continue; 1009 continue;
907 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 1010 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
908 list_for_each_entry(p_dev, &skt->devices_list, socket_device_list) { 1011 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
909 struct pcmcia_driver *p_drv;
910 p_dev = pcmcia_get_dev(p_dev); 1012 p_dev = pcmcia_get_dev(p_dev);
911 if (!p_dev) 1013 if (!p_dev)
912 continue; 1014 continue;
913 if (!(p_dev->client.state & CLIENT_UNBOUND) || 1015 if (!(p_dev->state & CLIENT_UNBOUND) ||
914 (!p_dev->dev.driver)) { 1016 (!p_dev->dev.driver)) {
915 pcmcia_put_dev(p_dev); 1017 pcmcia_put_dev(p_dev);
916 continue; 1018 continue;
917 } 1019 }
918 p_drv = to_pcmcia_drv(p_dev->dev.driver); 1020 p_drv = to_pcmcia_drv(p_dev->dev.driver);
919 if (!strncmp(p_drv->drv.name, (char *)req->dev_info, DEV_NAME_LEN)) { 1021 if (!strncmp(p_drv->drv.name, (char *)req->dev_info, DEV_NAME_LEN)) {
920 client = &p_dev->client;
921 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 1022 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
922 goto found; 1023 goto found;
923 } 1024 }
924 pcmcia_put_dev(p_dev); 1025 pcmcia_put_dev(p_dev);
925 } 1026 }
926 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 1027 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
927 pcmcia_put_bus_socket(skt); 1028 pcmcia_put_socket(s);
928 } 1029 }
929 found: 1030 found:
930 up_read(&pcmcia_socket_list_rwsem); 1031 up_read(&pcmcia_socket_list_rwsem);
931 if (!p_dev || !client) 1032 if (!p_dev)
932 return -ENODEV; 1033 return -ENODEV;
933 1034
934 pcmcia_put_bus_socket(skt); /* safe, as we already hold a reference from bind_device */ 1035 pcmcia_put_socket(s); /* safe, as we already hold a reference from bind_device */
935 1036
936 *handle = client; 1037 *handle = p_dev;
937 client->state &= ~CLIENT_UNBOUND; 1038 p_dev->state &= ~CLIENT_UNBOUND;
938 client->Socket = s; 1039 p_dev->event_callback_args = req->event_callback_args;
939 client->EventMask = req->EventMask; 1040 p_dev->event_callback_args.client_handle = p_dev;
940 client->event_handler = req->event_handler;
941 client->event_callback_args = req->event_callback_args;
942 client->event_callback_args.client_handle = client;
943 1041
944 if (s->state & SOCKET_CARDBUS)
945 client->state |= CLIENT_CARDBUS;
946 1042
947 if ((!(s->state & SOCKET_CARDBUS)) && (s->functions == 0) && 1043 if (!s->functions) {
948 (client->Function != BIND_FN_ALL)) {
949 cistpl_longlink_mfc_t mfc; 1044 cistpl_longlink_mfc_t mfc;
950 if (pccard_read_tuple(s, client->Function, CISTPL_LONGLINK_MFC, &mfc) 1045 if (pccard_read_tuple(s, p_dev->func, CISTPL_LONGLINK_MFC, &mfc)
951 == CS_SUCCESS) 1046 == CS_SUCCESS)
952 s->functions = mfc.nfn; 1047 s->functions = mfc.nfn;
953 else 1048 else
@@ -960,13 +1055,13 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
960 } 1055 }
961 1056
962 ds_dbg(1, "register_client(): client 0x%p, dev %s\n", 1057 ds_dbg(1, "register_client(): client 0x%p, dev %s\n",
963 client, p_dev->dev.bus_id); 1058 p_dev, p_dev->dev.bus_id);
964 if (client->EventMask & CS_EVENT_REGISTRATION_COMPLETE)
965 EVENT(client, CS_EVENT_REGISTRATION_COMPLETE, CS_EVENT_PRI_LOW);
966 1059
967 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) { 1060 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) {
968 if (client->EventMask & CS_EVENT_CARD_INSERTION) 1061 if (p_drv->event)
969 EVENT(client, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); 1062 p_drv->event(CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW,
1063 &p_dev->event_callback_args);
1064
970 } 1065 }
971 1066
972 return CS_SUCCESS; 1067 return CS_SUCCESS;
@@ -978,106 +1073,15 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
978EXPORT_SYMBOL(pcmcia_register_client); 1073EXPORT_SYMBOL(pcmcia_register_client);
979 1074
980 1075
981/*====================================================================*/
982
983extern struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s);
984
985static int get_device_info(struct pcmcia_bus_socket *s, bind_info_t *bind_info, int first)
986{
987 dev_node_t *node;
988 struct pcmcia_device *p_dev;
989 unsigned long flags;
990 int ret = 0;
991
992#ifdef CONFIG_CARDBUS
993 /*
994 * Some unbelievably ugly code to associate the PCI cardbus
995 * device and its driver with the PCMCIA "bind" information.
996 */
997 {
998 struct pci_bus *bus;
999
1000 bus = pcmcia_lookup_bus(s->parent);
1001 if (bus) {
1002 struct list_head *list;
1003 struct pci_dev *dev = NULL;
1004
1005 list = bus->devices.next;
1006 while (list != &bus->devices) {
1007 struct pci_dev *pdev = pci_dev_b(list);
1008 list = list->next;
1009
1010 if (first) {
1011 dev = pdev;
1012 break;
1013 }
1014
1015 /* Try to handle "next" here some way? */
1016 }
1017 if (dev && dev->driver) {
1018 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
1019 bind_info->major = 0;
1020 bind_info->minor = 0;
1021 bind_info->next = NULL;
1022 return 0;
1023 }
1024 }
1025 }
1026#endif
1027
1028 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
1029 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
1030 if (p_dev->func == bind_info->function) {
1031 p_dev = pcmcia_get_dev(p_dev);
1032 if (!p_dev)
1033 continue;
1034 goto found;
1035 }
1036 }
1037 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
1038 return -ENODEV;
1039
1040 found:
1041 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
1042
1043 if ((!p_dev->instance) ||
1044 (p_dev->instance->state & DEV_CONFIG_PENDING)) {
1045 ret = -EAGAIN;
1046 goto err_put;
1047 }
1048
1049 if (first)
1050 node = p_dev->instance->dev;
1051 else
1052 for (node = p_dev->instance->dev; node; node = node->next)
1053 if (node == bind_info->next)
1054 break;
1055 if (!node) {
1056 ret = -ENODEV;
1057 goto err_put;
1058 }
1059
1060 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
1061 bind_info->major = node->major;
1062 bind_info->minor = node->minor;
1063 bind_info->next = node->next;
1064
1065 err_put:
1066 pcmcia_put_dev(p_dev);
1067 return (ret);
1068} /* get_device_info */
1069
1070/*====================================================================*/
1071
1072/* unbind _all_ devices attached to a given pcmcia_bus_socket. The 1076/* unbind _all_ devices attached to a given pcmcia_bus_socket. The
1073 * drivers have been called with EVENT_CARD_REMOVAL before. 1077 * drivers have been called with EVENT_CARD_REMOVAL before.
1074 */ 1078 */
1075static int unbind_request(struct pcmcia_bus_socket *s) 1079static int unbind_request(struct pcmcia_socket *s)
1076{ 1080{
1077 struct pcmcia_device *p_dev; 1081 struct pcmcia_device *p_dev;
1078 unsigned long flags; 1082 unsigned long flags;
1079 1083
1080 ds_dbg(2, "unbind_request(%d)\n", s->parent->sock); 1084 ds_dbg(2, "unbind_request(%d)\n", s->sock);
1081 1085
1082 s->device_count = 0; 1086 s->device_count = 0;
1083 1087
@@ -1090,7 +1094,7 @@ static int unbind_request(struct pcmcia_bus_socket *s)
1090 } 1094 }
1091 p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list); 1095 p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
1092 list_del(&p_dev->socket_device_list); 1096 list_del(&p_dev->socket_device_list);
1093 p_dev->client.state |= CLIENT_STALE; 1097 p_dev->state |= CLIENT_STALE;
1094 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 1098 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
1095 1099
1096 device_unregister(&p_dev->dev); 1100 device_unregister(&p_dev->dev);
@@ -1099,31 +1103,25 @@ static int unbind_request(struct pcmcia_bus_socket *s)
1099 return 0; 1103 return 0;
1100} /* unbind_request */ 1104} /* unbind_request */
1101 1105
1102int pcmcia_deregister_client(client_handle_t handle) 1106int pcmcia_deregister_client(struct pcmcia_device *p_dev)
1103{ 1107{
1104 struct pcmcia_socket *s; 1108 struct pcmcia_socket *s;
1105 int i; 1109 int i;
1106 struct pcmcia_device *p_dev = handle_to_pdev(handle);
1107 1110
1108 if (CHECK_HANDLE(handle)) 1111 s = p_dev->socket;
1109 return CS_BAD_HANDLE; 1112 ds_dbg(1, "deregister_client(%p)\n", p_dev);
1110 1113
1111 s = SOCKET(handle); 1114 if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED))
1112 ds_dbg(1, "deregister_client(%p)\n", handle);
1113
1114 if (handle->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED))
1115 goto warn_out; 1115 goto warn_out;
1116 for (i = 0; i < MAX_WIN; i++) 1116 for (i = 0; i < MAX_WIN; i++)
1117 if (handle->state & CLIENT_WIN_REQ(i)) 1117 if (p_dev->state & CLIENT_WIN_REQ(i))
1118 goto warn_out; 1118 goto warn_out;
1119 1119
1120 if (handle->state & CLIENT_STALE) { 1120 if (p_dev->state & CLIENT_STALE) {
1121 handle->client_magic = 0; 1121 p_dev->state &= ~CLIENT_STALE;
1122 handle->state &= ~CLIENT_STALE;
1123 pcmcia_put_dev(p_dev); 1122 pcmcia_put_dev(p_dev);
1124 } else { 1123 } else {
1125 handle->state = CLIENT_UNBOUND; 1124 p_dev->state = CLIENT_UNBOUND;
1126 handle->event_handler = NULL;
1127 } 1125 }
1128 1126
1129 return CS_SUCCESS; 1127 return CS_SUCCESS;
@@ -1133,433 +1131,58 @@ int pcmcia_deregister_client(client_handle_t handle)
1133} /* deregister_client */ 1131} /* deregister_client */
1134EXPORT_SYMBOL(pcmcia_deregister_client); 1132EXPORT_SYMBOL(pcmcia_deregister_client);
1135 1133
1136 1134static struct pcmcia_callback pcmcia_bus_callback = {
1137/*====================================================================== 1135 .owner = THIS_MODULE,
1138 1136 .event = ds_event,
1139 The user-mode PC Card device interface 1137 .requery = pcmcia_bus_rescan,
1140
1141======================================================================*/
1142
1143static int ds_open(struct inode *inode, struct file *file)
1144{
1145 socket_t i = iminor(inode);
1146 struct pcmcia_bus_socket *s;
1147 user_info_t *user;
1148
1149 ds_dbg(0, "ds_open(socket %d)\n", i);
1150
1151 s = get_socket_info_by_nr(i);
1152 if (!s)
1153 return -ENODEV;
1154 s = pcmcia_get_bus_socket(s);
1155 if (!s)
1156 return -ENODEV;
1157
1158 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1159 if (s->state & DS_SOCKET_BUSY) {
1160 pcmcia_put_bus_socket(s);
1161 return -EBUSY;
1162 }
1163 else
1164 s->state |= DS_SOCKET_BUSY;
1165 }
1166
1167 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
1168 if (!user) {
1169 pcmcia_put_bus_socket(s);
1170 return -ENOMEM;
1171 }
1172 user->event_tail = user->event_head = 0;
1173 user->next = s->user;
1174 user->user_magic = USER_MAGIC;
1175 user->socket = s;
1176 s->user = user;
1177 file->private_data = user;
1178
1179 if (s->state & DS_SOCKET_PRESENT)
1180 queue_event(user, CS_EVENT_CARD_INSERTION);
1181 return 0;
1182} /* ds_open */
1183
1184/*====================================================================*/
1185
1186static int ds_release(struct inode *inode, struct file *file)
1187{
1188 struct pcmcia_bus_socket *s;
1189 user_info_t *user, **link;
1190
1191 ds_dbg(0, "ds_release(socket %d)\n", iminor(inode));
1192
1193 user = file->private_data;
1194 if (CHECK_USER(user))
1195 goto out;
1196
1197 s = user->socket;
1198
1199 /* Unlink user data structure */
1200 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1201 s->state &= ~DS_SOCKET_BUSY;
1202 }
1203 file->private_data = NULL;
1204 for (link = &s->user; *link; link = &(*link)->next)
1205 if (*link == user) break;
1206 if (link == NULL)
1207 goto out;
1208 *link = user->next;
1209 user->user_magic = 0;
1210 kfree(user);
1211 pcmcia_put_bus_socket(s);
1212out:
1213 return 0;
1214} /* ds_release */
1215
1216/*====================================================================*/
1217
1218static ssize_t ds_read(struct file *file, char __user *buf,
1219 size_t count, loff_t *ppos)
1220{
1221 struct pcmcia_bus_socket *s;
1222 user_info_t *user;
1223 int ret;
1224
1225 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode));
1226
1227 if (count < 4)
1228 return -EINVAL;
1229
1230 user = file->private_data;
1231 if (CHECK_USER(user))
1232 return -EIO;
1233
1234 s = user->socket;
1235 if (s->state & DS_SOCKET_DEAD)
1236 return -EIO;
1237
1238 ret = wait_event_interruptible(s->queue, !queue_empty(user));
1239 if (ret == 0)
1240 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
1241
1242 return ret;
1243} /* ds_read */
1244
1245/*====================================================================*/
1246
1247static ssize_t ds_write(struct file *file, const char __user *buf,
1248 size_t count, loff_t *ppos)
1249{
1250 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode));
1251
1252 if (count != 4)
1253 return -EINVAL;
1254 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
1255 return -EBADF;
1256
1257 return -EIO;
1258} /* ds_write */
1259
1260/*====================================================================*/
1261
1262/* No kernel lock - fine */
1263static u_int ds_poll(struct file *file, poll_table *wait)
1264{
1265 struct pcmcia_bus_socket *s;
1266 user_info_t *user;
1267
1268 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode));
1269
1270 user = file->private_data;
1271 if (CHECK_USER(user))
1272 return POLLERR;
1273 s = user->socket;
1274 /*
1275 * We don't check for a dead socket here since that
1276 * will send cardmgr into an endless spin.
1277 */
1278 poll_wait(file, &s->queue, wait);
1279 if (!queue_empty(user))
1280 return POLLIN | POLLRDNORM;
1281 return 0;
1282} /* ds_poll */
1283
1284/*====================================================================*/
1285
1286extern int pcmcia_adjust_resource_info(adjust_t *adj);
1287
1288static int ds_ioctl(struct inode * inode, struct file * file,
1289 u_int cmd, u_long arg)
1290{
1291 struct pcmcia_bus_socket *s;
1292 void __user *uarg = (char __user *)arg;
1293 u_int size;
1294 int ret, err;
1295 ds_ioctl_arg_t *buf;
1296 user_info_t *user;
1297
1298 ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
1299
1300 user = file->private_data;
1301 if (CHECK_USER(user))
1302 return -EIO;
1303
1304 s = user->socket;
1305 if (s->state & DS_SOCKET_DEAD)
1306 return -EIO;
1307
1308 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
1309 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
1310
1311 /* Permission check */
1312 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
1313 return -EPERM;
1314
1315 if (cmd & IOC_IN) {
1316 if (!access_ok(VERIFY_READ, uarg, size)) {
1317 ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT);
1318 return -EFAULT;
1319 }
1320 }
1321 if (cmd & IOC_OUT) {
1322 if (!access_ok(VERIFY_WRITE, uarg, size)) {
1323 ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT);
1324 return -EFAULT;
1325 }
1326 }
1327 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
1328 if (!buf)
1329 return -ENOMEM;
1330
1331 err = ret = 0;
1332
1333 if (cmd & IOC_IN) __copy_from_user((char *)buf, uarg, size);
1334
1335 switch (cmd) {
1336 case DS_ADJUST_RESOURCE_INFO:
1337 ret = pcmcia_adjust_resource_info(&buf->adjust);
1338 break;
1339 case DS_GET_CARD_SERVICES_INFO:
1340 ret = pcmcia_get_card_services_info(&buf->servinfo);
1341 break;
1342 case DS_GET_CONFIGURATION_INFO:
1343 if (buf->config.Function &&
1344 (buf->config.Function >= s->parent->functions))
1345 ret = CS_BAD_ARGS;
1346 else
1347 ret = pccard_get_configuration_info(s->parent,
1348 buf->config.Function, &buf->config);
1349 break;
1350 case DS_GET_FIRST_TUPLE:
1351 down(&s->parent->skt_sem);
1352 pcmcia_validate_mem(s->parent);
1353 up(&s->parent->skt_sem);
1354 ret = pccard_get_first_tuple(s->parent, BIND_FN_ALL, &buf->tuple);
1355 break;
1356 case DS_GET_NEXT_TUPLE:
1357 ret = pccard_get_next_tuple(s->parent, BIND_FN_ALL, &buf->tuple);
1358 break;
1359 case DS_GET_TUPLE_DATA:
1360 buf->tuple.TupleData = buf->tuple_parse.data;
1361 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
1362 ret = pccard_get_tuple_data(s->parent, &buf->tuple);
1363 break;
1364 case DS_PARSE_TUPLE:
1365 buf->tuple.TupleData = buf->tuple_parse.data;
1366 ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
1367 break;
1368 case DS_RESET_CARD:
1369 ret = pccard_reset_card(s->parent);
1370 break;
1371 case DS_GET_STATUS:
1372 if (buf->status.Function &&
1373 (buf->status.Function >= s->parent->functions))
1374 ret = CS_BAD_ARGS;
1375 else
1376 ret = pccard_get_status(s->parent, buf->status.Function, &buf->status);
1377 break;
1378 case DS_VALIDATE_CIS:
1379 down(&s->parent->skt_sem);
1380 pcmcia_validate_mem(s->parent);
1381 up(&s->parent->skt_sem);
1382 ret = pccard_validate_cis(s->parent, BIND_FN_ALL, &buf->cisinfo);
1383 break;
1384 case DS_SUSPEND_CARD:
1385 ret = pcmcia_suspend_card(s->parent);
1386 break;
1387 case DS_RESUME_CARD:
1388 ret = pcmcia_resume_card(s->parent);
1389 break;
1390 case DS_EJECT_CARD:
1391 err = pcmcia_eject_card(s->parent);
1392 break;
1393 case DS_INSERT_CARD:
1394 err = pcmcia_insert_card(s->parent);
1395 break;
1396 case DS_ACCESS_CONFIGURATION_REGISTER:
1397 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
1398 err = -EPERM;
1399 goto free_out;
1400 }
1401 if (buf->conf_reg.Function &&
1402 (buf->conf_reg.Function >= s->parent->functions))
1403 ret = CS_BAD_ARGS;
1404 else
1405 ret = pccard_access_configuration_register(s->parent,
1406 buf->conf_reg.Function, &buf->conf_reg);
1407 break;
1408 case DS_GET_FIRST_REGION:
1409 case DS_GET_NEXT_REGION:
1410 case DS_BIND_MTD:
1411 if (!capable(CAP_SYS_ADMIN)) {
1412 err = -EPERM;
1413 goto free_out;
1414 } else {
1415 static int printed = 0;
1416 if (!printed) {
1417 printk(KERN_WARNING "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
1418 printk(KERN_WARNING "MTD handling any more.\n");
1419 printed++;
1420 }
1421 }
1422 err = -EINVAL;
1423 goto free_out;
1424 break;
1425 case DS_GET_FIRST_WINDOW:
1426 ret = pcmcia_get_window(s->parent, &buf->win_info.handle, 0,
1427 &buf->win_info.window);
1428 break;
1429 case DS_GET_NEXT_WINDOW:
1430 ret = pcmcia_get_window(s->parent, &buf->win_info.handle,
1431 buf->win_info.handle->index + 1, &buf->win_info.window);
1432 break;
1433 case DS_GET_MEM_PAGE:
1434 ret = pcmcia_get_mem_page(buf->win_info.handle,
1435 &buf->win_info.map);
1436 break;
1437 case DS_REPLACE_CIS:
1438 ret = pcmcia_replace_cis(s->parent, &buf->cisdump);
1439 break;
1440 case DS_BIND_REQUEST:
1441 if (!capable(CAP_SYS_ADMIN)) {
1442 err = -EPERM;
1443 goto free_out;
1444 }
1445 err = bind_request(s, &buf->bind_info);
1446 break;
1447 case DS_GET_DEVICE_INFO:
1448 err = get_device_info(s, &buf->bind_info, 1);
1449 break;
1450 case DS_GET_NEXT_DEVICE:
1451 err = get_device_info(s, &buf->bind_info, 0);
1452 break;
1453 case DS_UNBIND_REQUEST:
1454 err = 0;
1455 break;
1456 default:
1457 err = -EINVAL;
1458 }
1459
1460 if ((err == 0) && (ret != CS_SUCCESS)) {
1461 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
1462 switch (ret) {
1463 case CS_BAD_SOCKET: case CS_NO_CARD:
1464 err = -ENODEV; break;
1465 case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ:
1466 case CS_BAD_TUPLE:
1467 err = -EINVAL; break;
1468 case CS_IN_USE:
1469 err = -EBUSY; break;
1470 case CS_OUT_OF_RESOURCE:
1471 err = -ENOSPC; break;
1472 case CS_NO_MORE_ITEMS:
1473 err = -ENODATA; break;
1474 case CS_UNSUPPORTED_FUNCTION:
1475 err = -ENOSYS; break;
1476 default:
1477 err = -EIO; break;
1478 }
1479 }
1480
1481 if (cmd & IOC_OUT) {
1482 if (__copy_to_user(uarg, (char *)buf, size))
1483 err = -EFAULT;
1484 }
1485
1486free_out:
1487 kfree(buf);
1488 return err;
1489} /* ds_ioctl */
1490
1491/*====================================================================*/
1492
1493static struct file_operations ds_fops = {
1494 .owner = THIS_MODULE,
1495 .open = ds_open,
1496 .release = ds_release,
1497 .ioctl = ds_ioctl,
1498 .read = ds_read,
1499 .write = ds_write,
1500 .poll = ds_poll,
1501}; 1138};
1502 1139
1503static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev) 1140static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
1504{ 1141{
1505 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1142 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1506 struct pcmcia_bus_socket *s;
1507 int ret; 1143 int ret;
1508 1144
1509 s = kmalloc(sizeof(struct pcmcia_bus_socket), GFP_KERNEL); 1145 socket = pcmcia_get_socket(socket);
1510 if(!s) 1146 if (!socket) {
1511 return -ENOMEM;
1512 memset(s, 0, sizeof(struct pcmcia_bus_socket));
1513
1514 /* get reference to parent socket */
1515 s->parent = pcmcia_get_socket(socket);
1516 if (!s->parent) {
1517 printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket); 1147 printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
1518 kfree (s);
1519 return -ENODEV; 1148 return -ENODEV;
1520 } 1149 }
1521 1150
1522 kref_init(&s->refcount);
1523
1524 /* 1151 /*
1525 * Ugly. But we want to wait for the socket threads to have started up. 1152 * Ugly. But we want to wait for the socket threads to have started up.
1526 * We really should let the drivers themselves drive some of this.. 1153 * We really should let the drivers themselves drive some of this..
1527 */ 1154 */
1528 msleep(250); 1155 msleep(250);
1529 1156
1530 init_waitqueue_head(&s->queue); 1157#ifdef CONFIG_PCMCIA_IOCTL
1531 INIT_LIST_HEAD(&s->devices_list); 1158 init_waitqueue_head(&socket->queue);
1532 1159#endif
1533 /* Set up hotline to Card Services */ 1160 INIT_LIST_HEAD(&socket->devices_list);
1534 s->callback.owner = THIS_MODULE; 1161 INIT_WORK(&socket->device_add, pcmcia_delayed_add_pseudo_device, socket);
1535 s->callback.event = &ds_event; 1162 memset(&socket->pcmcia_state, 0, sizeof(u8));
1536 s->callback.resources_done = &pcmcia_card_add; 1163 socket->device_count = 0;
1537 socket->pcmcia = s;
1538 1164
1539 ret = pccard_register_pcmcia(socket, &s->callback); 1165 ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback);
1540 if (ret) { 1166 if (ret) {
1541 printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket); 1167 printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket);
1542 pcmcia_put_bus_socket(s); 1168 pcmcia_put_socket(socket);
1543 socket->pcmcia = NULL;
1544 return (ret); 1169 return (ret);
1545 } 1170 }
1546 1171
1547 return 0; 1172 return 0;
1548} 1173}
1549 1174
1550
1551static void pcmcia_bus_remove_socket(struct class_device *class_dev) 1175static void pcmcia_bus_remove_socket(struct class_device *class_dev)
1552{ 1176{
1553 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1177 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1554 1178
1555 if (!socket || !socket->pcmcia) 1179 if (!socket)
1556 return; 1180 return;
1557 1181
1182 socket->pcmcia_state.dead = 1;
1558 pccard_register_pcmcia(socket, NULL); 1183 pccard_register_pcmcia(socket, NULL);
1559 1184
1560 socket->pcmcia->state |= DS_SOCKET_DEAD; 1185 pcmcia_put_socket(socket);
1561 pcmcia_put_bus_socket(socket->pcmcia);
1562 socket->pcmcia = NULL;
1563 1186
1564 return; 1187 return;
1565} 1188}
@@ -1575,34 +1198,20 @@ static struct class_interface pcmcia_bus_interface = {
1575 1198
1576struct bus_type pcmcia_bus_type = { 1199struct bus_type pcmcia_bus_type = {
1577 .name = "pcmcia", 1200 .name = "pcmcia",
1201 .hotplug = pcmcia_bus_hotplug,
1578 .match = pcmcia_bus_match, 1202 .match = pcmcia_bus_match,
1579 .dev_attrs = pcmcia_dev_attrs, 1203 .dev_attrs = pcmcia_dev_attrs,
1580}; 1204};
1581EXPORT_SYMBOL(pcmcia_bus_type);
1582 1205
1583 1206
1584static int __init init_pcmcia_bus(void) 1207static int __init init_pcmcia_bus(void)
1585{ 1208{
1586 int i;
1587
1588 spin_lock_init(&pcmcia_dev_list_lock); 1209 spin_lock_init(&pcmcia_dev_list_lock);
1589 1210
1590 bus_register(&pcmcia_bus_type); 1211 bus_register(&pcmcia_bus_type);
1591 class_interface_register(&pcmcia_bus_interface); 1212 class_interface_register(&pcmcia_bus_interface);
1592 1213
1593 /* Set up character device for user mode clients */ 1214 pcmcia_setup_ioctl();
1594 i = register_chrdev(0, "pcmcia", &ds_fops);
1595 if (i < 0)
1596 printk(KERN_NOTICE "unable to find a free device # for "
1597 "Driver Services (error=%d)\n", i);
1598 else
1599 major_dev = i;
1600
1601#ifdef CONFIG_PROC_FS
1602 proc_pccard = proc_mkdir("pccard", proc_bus);
1603 if (proc_pccard)
1604 create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL);
1605#endif
1606 1215
1607 return 0; 1216 return 0;
1608} 1217}
@@ -1612,48 +1221,13 @@ fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that
1612 1221
1613static void __exit exit_pcmcia_bus(void) 1222static void __exit exit_pcmcia_bus(void)
1614{ 1223{
1615 class_interface_unregister(&pcmcia_bus_interface); 1224 pcmcia_cleanup_ioctl();
1616 1225
1617#ifdef CONFIG_PROC_FS 1226 class_interface_unregister(&pcmcia_bus_interface);
1618 if (proc_pccard) {
1619 remove_proc_entry("drivers", proc_pccard);
1620 remove_proc_entry("pccard", proc_bus);
1621 }
1622#endif
1623 if (major_dev != -1)
1624 unregister_chrdev(major_dev, "pcmcia");
1625 1227
1626 bus_unregister(&pcmcia_bus_type); 1228 bus_unregister(&pcmcia_bus_type);
1627} 1229}
1628module_exit(exit_pcmcia_bus); 1230module_exit(exit_pcmcia_bus);
1629 1231
1630 1232
1631
1632/* helpers for backwards-compatible functions */
1633
1634static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr)
1635{
1636 struct pcmcia_socket * s = pcmcia_get_socket_by_nr(nr);
1637 if (s && s->pcmcia)
1638 return s->pcmcia;
1639 else
1640 return NULL;
1641}
1642
1643/* backwards-compatible accessing of driver --- by name! */
1644
1645static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
1646{
1647 struct device_driver *drv;
1648 struct pcmcia_driver *p_drv;
1649
1650 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
1651 if (!drv)
1652 return NULL;
1653
1654 p_drv = container_of(drv, struct pcmcia_driver, drv);
1655
1656 return (p_drv);
1657}
1658
1659MODULE_ALIAS("ds"); 1233MODULE_ALIAS("ds");
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
new file mode 100644
index 000000000000..d359bd25a51c
--- /dev/null
+++ b/drivers/pcmcia/ds_internal.h
@@ -0,0 +1,21 @@
1/* ds_internal.h - internal header for 16-bit PCMCIA devices management */
2
3extern spinlock_t pcmcia_dev_list_lock;
4extern struct bus_type pcmcia_bus_type;
5
6extern struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev);
7extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
8
9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
10
11#ifdef CONFIG_PCMCIA_IOCTL
12extern void __init pcmcia_setup_ioctl(void);
13extern void __exit pcmcia_cleanup_ioctl(void);
14extern void handle_event(struct pcmcia_socket *s, event_t event);
15extern int handle_request(struct pcmcia_socket *s, event_t event);
16#else
17static inline void __init pcmcia_setup_ioctl(void) { return; }
18static inline void __init pcmcia_cleanup_ioctl(void) { return; }
19static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
20static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
21#endif
diff --git a/drivers/pcmcia/hd64465_ss.c b/drivers/pcmcia/hd64465_ss.c
index 5ab55ae0ac36..316f8bcc878b 100644
--- a/drivers/pcmcia/hd64465_ss.c
+++ b/drivers/pcmcia/hd64465_ss.c
@@ -43,7 +43,6 @@
43#include <asm/hd64465/hd64465.h> 43#include <asm/hd64465/hd64465.h>
44#include <asm/hd64465/io.h> 44#include <asm/hd64465/io.h>
45 45
46#include <pcmcia/version.h>
47#include <pcmcia/cs_types.h> 46#include <pcmcia/cs_types.h>
48#include <pcmcia/cs.h> 47#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 90a335a5d9fa..a713015e8228 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -53,7 +53,6 @@
53#include <asm/io.h> 53#include <asm/io.h>
54#include <asm/system.h> 54#include <asm/system.h>
55 55
56#include <pcmcia/version.h>
57#include <pcmcia/cs_types.h> 56#include <pcmcia/cs_types.h>
58#include <pcmcia/ss.h> 57#include <pcmcia/ss.h>
59#include <pcmcia/cs.h> 58#include <pcmcia/cs.h>
@@ -669,11 +668,13 @@ static int __init is_alive(u_short sock)
669 if ((stat & I365_CS_DETECT) && (stat & I365_CS_POWERON) && 668 if ((stat & I365_CS_DETECT) && (stat & I365_CS_POWERON) &&
670 (i365_get(sock, I365_INTCTL) & I365_PC_IOCARD) && 669 (i365_get(sock, I365_INTCTL) & I365_PC_IOCARD) &&
671 (i365_get(sock, I365_ADDRWIN) & I365_ENA_IO(0)) && 670 (i365_get(sock, I365_ADDRWIN) & I365_ENA_IO(0)) &&
672 (check_region(start, stop-start+1) != 0) && 671 ((start & 0xfeef) != 0x02e8)) {
673 ((start & 0xfeef) != 0x02e8)) 672 if (!request_region(start, stop-start+1, "i82365"))
674 return 1; 673 return 1;
675 else 674 release_region(start, stop-start+1);
676 return 0; 675 }
676
677 return 0;
677} 678}
678 679
679/*====================================================================*/ 680/*====================================================================*/
@@ -696,8 +697,6 @@ static void __init add_pcic(int ns, int type)
696 struct i82365_socket *t = &socket[sockets-ns]; 697 struct i82365_socket *t = &socket[sockets-ns];
697 698
698 base = sockets-ns; 699 base = sockets-ns;
699 if (t->ioaddr > 0) request_region(t->ioaddr, 2, "i82365");
700
701 if (base == 0) printk("\n"); 700 if (base == 0) printk("\n");
702 printk(KERN_INFO " %s", pcic[type].name); 701 printk(KERN_INFO " %s", pcic[type].name);
703 printk(" ISA-to-PCMCIA at port %#lx ofs 0x%02x", 702 printk(" ISA-to-PCMCIA at port %#lx ofs 0x%02x",
@@ -803,7 +802,7 @@ static void __init isa_probe(void)
803 } 802 }
804#endif 803#endif
805 804
806 if (check_region(i365_base, 2) != 0) { 805 if (!request_region(i365_base, 2, "i82365")) {
807 if (sockets == 0) 806 if (sockets == 0)
808 printk("port conflict at %#lx\n", i365_base); 807 printk("port conflict at %#lx\n", i365_base);
809 return; 808 return;
@@ -1441,6 +1440,7 @@ static void __exit exit_i82365(void)
1441 i365_set(i, I365_CSCINT, 0); 1440 i365_set(i, I365_CSCINT, 0);
1442 release_region(socket[i].ioaddr, 2); 1441 release_region(socket[i].ioaddr, 2);
1443 } 1442 }
1443 release_region(i365_base, 2);
1444#ifdef CONFIG_PNP 1444#ifdef CONFIG_PNP
1445 if (i82365_pnpdev) 1445 if (i82365_pnpdev)
1446 pnp_disable_dev(i82365_pnpdev); 1446 pnp_disable_dev(i82365_pnpdev);
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index b1111c6bf062..65f3ee3d4d3c 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -29,7 +29,6 @@
29#include <asm/io.h> 29#include <asm/io.h>
30#include <asm/system.h> 30#include <asm/system.h>
31 31
32#include <pcmcia/version.h>
33#include <pcmcia/cs_types.h> 32#include <pcmcia/cs_types.h>
34#include <pcmcia/ss.h> 33#include <pcmcia/ss.h>
35#include <pcmcia/cs.h> 34#include <pcmcia/cs.h>
diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
index c0997c4714f0..7b14d7efd68c 100644
--- a/drivers/pcmcia/m32r_pcc.c
+++ b/drivers/pcmcia/m32r_pcc.c
@@ -30,7 +30,6 @@
30#include <asm/system.h> 30#include <asm/system.h>
31#include <asm/addrspace.h> 31#include <asm/addrspace.h>
32 32
33#include <pcmcia/version.h>
34#include <pcmcia/cs_types.h> 33#include <pcmcia/cs_types.h>
35#include <pcmcia/ss.h> 34#include <pcmcia/ss.h>
36#include <pcmcia/cs.h> 35#include <pcmcia/cs.h>
diff --git a/drivers/pcmcia/pcmcia_compat.c b/drivers/pcmcia/pcmcia_compat.c
index 68b80084f83f..ebb161c4f819 100644
--- a/drivers/pcmcia/pcmcia_compat.c
+++ b/drivers/pcmcia/pcmcia_compat.c
@@ -18,7 +18,6 @@
18#include <linux/init.h> 18#include <linux/init.h>
19 19
20#define IN_CARD_SERVICES 20#define IN_CARD_SERVICES
21#include <pcmcia/version.h>
22#include <pcmcia/cs_types.h> 21#include <pcmcia/cs_types.h>
23#include <pcmcia/cs.h> 22#include <pcmcia/cs.h>
24#include <pcmcia/bulkmem.h> 23#include <pcmcia/bulkmem.h>
@@ -28,98 +27,39 @@
28 27
29#include "cs_internal.h" 28#include "cs_internal.h"
30 29
31int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple) 30int pcmcia_get_first_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
32{ 31{
33 struct pcmcia_socket *s; 32 return pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple);
34 if (CHECK_HANDLE(handle))
35 return CS_BAD_HANDLE;
36 s = SOCKET(handle);
37 return pccard_get_first_tuple(s, handle->Function, tuple);
38} 33}
39EXPORT_SYMBOL(pcmcia_get_first_tuple); 34EXPORT_SYMBOL(pcmcia_get_first_tuple);
40 35
41int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple) 36int pcmcia_get_next_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
42{ 37{
43 struct pcmcia_socket *s; 38 return pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple);
44 if (CHECK_HANDLE(handle))
45 return CS_BAD_HANDLE;
46 s = SOCKET(handle);
47 return pccard_get_next_tuple(s, handle->Function, tuple);
48} 39}
49EXPORT_SYMBOL(pcmcia_get_next_tuple); 40EXPORT_SYMBOL(pcmcia_get_next_tuple);
50 41
51int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple) 42int pcmcia_get_tuple_data(struct pcmcia_device *p_dev, tuple_t *tuple)
52{ 43{
53 struct pcmcia_socket *s; 44 return pccard_get_tuple_data(p_dev->socket, tuple);
54 if (CHECK_HANDLE(handle))
55 return CS_BAD_HANDLE;
56 s = SOCKET(handle);
57 return pccard_get_tuple_data(s, tuple);
58} 45}
59EXPORT_SYMBOL(pcmcia_get_tuple_data); 46EXPORT_SYMBOL(pcmcia_get_tuple_data);
60 47
61int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 48int pcmcia_parse_tuple(struct pcmcia_device *p_dev, tuple_t *tuple, cisparse_t *parse)
62{ 49{
63 return pccard_parse_tuple(tuple, parse); 50 return pccard_parse_tuple(tuple, parse);
64} 51}
65EXPORT_SYMBOL(pcmcia_parse_tuple); 52EXPORT_SYMBOL(pcmcia_parse_tuple);
66 53
67int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info) 54int pcmcia_validate_cis(struct pcmcia_device *p_dev, cisinfo_t *info)
68{ 55{
69 struct pcmcia_socket *s; 56 return pccard_validate_cis(p_dev->socket, p_dev->func, info);
70 if (CHECK_HANDLE(handle))
71 return CS_BAD_HANDLE;
72 s = SOCKET(handle);
73 return pccard_validate_cis(s, handle->Function, info);
74} 57}
75EXPORT_SYMBOL(pcmcia_validate_cis); 58EXPORT_SYMBOL(pcmcia_validate_cis);
76 59
77int pcmcia_get_configuration_info(client_handle_t handle,
78 config_info_t *config)
79{
80 struct pcmcia_socket *s;
81
82 if ((CHECK_HANDLE(handle)) || !config)
83 return CS_BAD_HANDLE;
84 s = SOCKET(handle);
85 if (!s)
86 return CS_BAD_HANDLE;
87 return pccard_get_configuration_info(s, handle->Function, config);
88}
89EXPORT_SYMBOL(pcmcia_get_configuration_info);
90 60
91int pcmcia_reset_card(client_handle_t handle, client_req_t *req) 61int pcmcia_reset_card(struct pcmcia_device *p_dev, client_req_t *req)
92{ 62{
93 struct pcmcia_socket *skt; 63 return pccard_reset_card(p_dev->socket);
94
95 if (CHECK_HANDLE(handle))
96 return CS_BAD_HANDLE;
97 skt = SOCKET(handle);
98 if (!skt)
99 return CS_BAD_HANDLE;
100
101 return pccard_reset_card(skt);
102} 64}
103EXPORT_SYMBOL(pcmcia_reset_card); 65EXPORT_SYMBOL(pcmcia_reset_card);
104
105int pcmcia_get_status(client_handle_t handle, cs_status_t *status)
106{
107 struct pcmcia_socket *s;
108 if (CHECK_HANDLE(handle))
109 return CS_BAD_HANDLE;
110 s = SOCKET(handle);
111 return pccard_get_status(s, handle->Function, status);
112}
113EXPORT_SYMBOL(pcmcia_get_status);
114
115int pcmcia_access_configuration_register(client_handle_t handle,
116 conf_reg_t *reg)
117{
118 struct pcmcia_socket *s;
119 if (CHECK_HANDLE(handle))
120 return CS_BAD_HANDLE;
121 s = SOCKET(handle);
122 return pccard_access_configuration_register(s, handle->Function, reg);
123}
124EXPORT_SYMBOL(pcmcia_access_configuration_register);
125
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
new file mode 100644
index 000000000000..39ba6406fd54
--- /dev/null
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -0,0 +1,759 @@
1/*
2 * pcmcia_ioctl.c -- ioctl interface for cardmgr and cardctl
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 version 2 as
6 * published by the Free Software Foundation.
7 *
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 *
12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2004 Dominik Brodowski
14 */
15
16/*
17 * This file will go away soon.
18 */
19
20
21#include <linux/config.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/major.h>
26#include <linux/errno.h>
27#include <linux/ioctl.h>
28#include <linux/proc_fs.h>
29#include <linux/poll.h>
30#include <linux/pci.h>
31#include <linux/workqueue.h>
32
33#define IN_CARD_SERVICES
34#include <pcmcia/cs_types.h>
35#include <pcmcia/cs.h>
36#include <pcmcia/cistpl.h>
37#include <pcmcia/ds.h>
38#include <pcmcia/ss.h>
39
40#include "cs_internal.h"
41#include "ds_internal.h"
42
43static int major_dev = -1;
44
45
46/* Device user information */
47#define MAX_EVENTS 32
48#define USER_MAGIC 0x7ea4
49#define CHECK_USER(u) \
50 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
51
52typedef struct user_info_t {
53 u_int user_magic;
54 int event_head, event_tail;
55 event_t event[MAX_EVENTS];
56 struct user_info_t *next;
57 struct pcmcia_socket *socket;
58} user_info_t;
59
60
61#ifdef DEBUG
62extern int ds_pc_debug;
63#define cs_socket_name(skt) ((skt)->dev.class_id)
64
65#define ds_dbg(lvl, fmt, arg...) do { \
66 if (ds_pc_debug >= lvl) \
67 printk(KERN_DEBUG "ds: " fmt , ## arg); \
68} while (0)
69#else
70#define ds_dbg(lvl, fmt, arg...) do { } while (0)
71#endif
72
73
74/* backwards-compatible accessing of driver --- by name! */
75
76static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info)
77{
78 struct device_driver *drv;
79 struct pcmcia_driver *p_drv;
80
81 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
82 if (!drv)
83 return NULL;
84
85 p_drv = container_of(drv, struct pcmcia_driver, drv);
86
87 return (p_drv);
88}
89
90
91#ifdef CONFIG_PROC_FS
92static struct proc_dir_entry *proc_pccard = NULL;
93
94static int proc_read_drivers_callback(struct device_driver *driver, void *d)
95{
96 char **p = d;
97 struct pcmcia_driver *p_drv = container_of(driver,
98 struct pcmcia_driver, drv);
99
100 *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name,
101#ifdef CONFIG_MODULE_UNLOAD
102 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
103#else
104 1
105#endif
106 );
107 d = (void *) p;
108
109 return 0;
110}
111
112static int proc_read_drivers(char *buf, char **start, off_t pos,
113 int count, int *eof, void *data)
114{
115 char *p = buf;
116
117 bus_for_each_drv(&pcmcia_bus_type, NULL,
118 (void *) &p, proc_read_drivers_callback);
119
120 return (p - buf);
121}
122#endif
123
124/*======================================================================
125
126 These manage a ring buffer of events pending for one user process
127
128======================================================================*/
129
130
131static int queue_empty(user_info_t *user)
132{
133 return (user->event_head == user->event_tail);
134}
135
136static event_t get_queued_event(user_info_t *user)
137{
138 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
139 return user->event[user->event_tail];
140}
141
142static void queue_event(user_info_t *user, event_t event)
143{
144 user->event_head = (user->event_head+1) % MAX_EVENTS;
145 if (user->event_head == user->event_tail)
146 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
147 user->event[user->event_head] = event;
148}
149
150void handle_event(struct pcmcia_socket *s, event_t event)
151{
152 user_info_t *user;
153 for (user = s->user; user; user = user->next)
154 queue_event(user, event);
155 wake_up_interruptible(&s->queue);
156}
157
158
159/*======================================================================
160
161 bind_request() and bind_device() are merged by now. Register_client()
162 is called right at the end of bind_request(), during the driver's
163 ->attach() call. Individual descriptions:
164
165 bind_request() connects a socket to a particular client driver.
166 It looks up the specified device ID in the list of registered
167 drivers, binds it to the socket, and tries to create an instance
168 of the device. unbind_request() deletes a driver instance.
169
170 Bind_device() associates a device driver with a particular socket.
171 It is normally called by Driver Services after it has identified
172 a newly inserted card. An instance of that driver will then be
173 eligible to register as a client of this socket.
174
175 Register_client() uses the dev_info_t handle to match the
176 caller with a socket. The driver must have already been bound
177 to a socket with bind_device() -- in fact, bind_device()
178 allocates the client structure that will be used.
179
180======================================================================*/
181
182static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
183{
184 struct pcmcia_driver *p_drv;
185 struct pcmcia_device *p_dev;
186 int ret = 0;
187 unsigned long flags;
188
189 s = pcmcia_get_socket(s);
190 if (!s)
191 return -EINVAL;
192
193 ds_dbg(2, "bind_request(%d, '%s')\n", s->sock,
194 (char *)bind_info->dev_info);
195
196 p_drv = get_pcmcia_driver(&bind_info->dev_info);
197 if (!p_drv) {
198 ret = -EINVAL;
199 goto err_put;
200 }
201
202 if (!try_module_get(p_drv->owner)) {
203 ret = -EINVAL;
204 goto err_put_driver;
205 }
206
207 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
208 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
209 if (p_dev->func == bind_info->function) {
210 if ((p_dev->dev.driver == &p_drv->drv)) {
211 if (p_dev->cardmgr) {
212 /* if there's already a device
213 * registered, and it was registered
214 * by userspace before, we need to
215 * return the "instance". */
216 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
217 bind_info->instance = p_dev->instance;
218 ret = -EBUSY;
219 goto err_put_module;
220 } else {
221 /* the correct driver managed to bind
222 * itself magically to the correct
223 * device. */
224 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
225 p_dev->cardmgr = p_drv;
226 ret = 0;
227 goto err_put_module;
228 }
229 } else if (!p_dev->dev.driver) {
230 /* there's already a device available where
231 * no device has been bound to yet. So we don't
232 * need to register a device! */
233 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
234 goto rescan;
235 }
236 }
237 }
238 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
239
240 p_dev = pcmcia_device_add(s, bind_info->function);
241 if (!p_dev) {
242 ret = -EIO;
243 goto err_put_module;
244 }
245
246rescan:
247 p_dev->cardmgr = p_drv;
248
249 /* if a driver is already running, we can abort */
250 if (p_dev->dev.driver)
251 goto err_put_module;
252
253 /*
254 * Prevent this racing with a card insertion.
255 */
256 down(&s->skt_sem);
257 bus_rescan_devices(&pcmcia_bus_type);
258 up(&s->skt_sem);
259
260 /* check whether the driver indeed matched. I don't care if this
261 * is racy or not, because it can only happen on cardmgr access
262 * paths...
263 */
264 if (!(p_dev->dev.driver == &p_drv->drv))
265 p_dev->cardmgr = NULL;
266
267 err_put_module:
268 module_put(p_drv->owner);
269 err_put_driver:
270 put_driver(&p_drv->drv);
271 err_put:
272 pcmcia_put_socket(s);
273
274 return (ret);
275} /* bind_request */
276
277#ifdef CONFIG_CARDBUS
278
279static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
280{
281 if (!s || !(s->state & SOCKET_CARDBUS))
282 return NULL;
283
284 return s->cb_dev->subordinate;
285}
286#endif
287
288static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first)
289{
290 dev_node_t *node;
291 struct pcmcia_device *p_dev;
292 unsigned long flags;
293 int ret = 0;
294
295#ifdef CONFIG_CARDBUS
296 /*
297 * Some unbelievably ugly code to associate the PCI cardbus
298 * device and its driver with the PCMCIA "bind" information.
299 */
300 {
301 struct pci_bus *bus;
302
303 bus = pcmcia_lookup_bus(s);
304 if (bus) {
305 struct list_head *list;
306 struct pci_dev *dev = NULL;
307
308 list = bus->devices.next;
309 while (list != &bus->devices) {
310 struct pci_dev *pdev = pci_dev_b(list);
311 list = list->next;
312
313 if (first) {
314 dev = pdev;
315 break;
316 }
317
318 /* Try to handle "next" here some way? */
319 }
320 if (dev && dev->driver) {
321 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
322 bind_info->major = 0;
323 bind_info->minor = 0;
324 bind_info->next = NULL;
325 return 0;
326 }
327 }
328 }
329#endif
330
331 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
332 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
333 if (p_dev->func == bind_info->function) {
334 p_dev = pcmcia_get_dev(p_dev);
335 if (!p_dev)
336 continue;
337 goto found;
338 }
339 }
340 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
341 return -ENODEV;
342
343 found:
344 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
345
346 if ((!p_dev->instance) ||
347 (p_dev->instance->state & DEV_CONFIG_PENDING)) {
348 ret = -EAGAIN;
349 goto err_put;
350 }
351
352 if (first)
353 node = p_dev->instance->dev;
354 else
355 for (node = p_dev->instance->dev; node; node = node->next)
356 if (node == bind_info->next)
357 break;
358 if (!node) {
359 ret = -ENODEV;
360 goto err_put;
361 }
362
363 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
364 bind_info->major = node->major;
365 bind_info->minor = node->minor;
366 bind_info->next = node->next;
367
368 err_put:
369 pcmcia_put_dev(p_dev);
370 return (ret);
371} /* get_device_info */
372
373
374static int ds_open(struct inode *inode, struct file *file)
375{
376 socket_t i = iminor(inode);
377 struct pcmcia_socket *s;
378 user_info_t *user;
379
380 ds_dbg(0, "ds_open(socket %d)\n", i);
381
382 s = pcmcia_get_socket_by_nr(i);
383 if (!s)
384 return -ENODEV;
385 s = pcmcia_get_socket(s);
386 if (!s)
387 return -ENODEV;
388
389 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
390 if (s->pcmcia_state.busy) {
391 pcmcia_put_socket(s);
392 return -EBUSY;
393 }
394 else
395 s->pcmcia_state.busy = 1;
396 }
397
398 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
399 if (!user) {
400 pcmcia_put_socket(s);
401 return -ENOMEM;
402 }
403 user->event_tail = user->event_head = 0;
404 user->next = s->user;
405 user->user_magic = USER_MAGIC;
406 user->socket = s;
407 s->user = user;
408 file->private_data = user;
409
410 if (s->pcmcia_state.present)
411 queue_event(user, CS_EVENT_CARD_INSERTION);
412 return 0;
413} /* ds_open */
414
415/*====================================================================*/
416
417static int ds_release(struct inode *inode, struct file *file)
418{
419 struct pcmcia_socket *s;
420 user_info_t *user, **link;
421
422 ds_dbg(0, "ds_release(socket %d)\n", iminor(inode));
423
424 user = file->private_data;
425 if (CHECK_USER(user))
426 goto out;
427
428 s = user->socket;
429
430 /* Unlink user data structure */
431 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
432 s->pcmcia_state.busy = 0;
433 }
434 file->private_data = NULL;
435 for (link = &s->user; *link; link = &(*link)->next)
436 if (*link == user) break;
437 if (link == NULL)
438 goto out;
439 *link = user->next;
440 user->user_magic = 0;
441 kfree(user);
442 pcmcia_put_socket(s);
443out:
444 return 0;
445} /* ds_release */
446
447/*====================================================================*/
448
449static ssize_t ds_read(struct file *file, char __user *buf,
450 size_t count, loff_t *ppos)
451{
452 struct pcmcia_socket *s;
453 user_info_t *user;
454 int ret;
455
456 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode));
457
458 if (count < 4)
459 return -EINVAL;
460
461 user = file->private_data;
462 if (CHECK_USER(user))
463 return -EIO;
464
465 s = user->socket;
466 if (s->pcmcia_state.dead)
467 return -EIO;
468
469 ret = wait_event_interruptible(s->queue, !queue_empty(user));
470 if (ret == 0)
471 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
472
473 return ret;
474} /* ds_read */
475
476/*====================================================================*/
477
478static ssize_t ds_write(struct file *file, const char __user *buf,
479 size_t count, loff_t *ppos)
480{
481 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode));
482
483 if (count != 4)
484 return -EINVAL;
485 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
486 return -EBADF;
487
488 return -EIO;
489} /* ds_write */
490
491/*====================================================================*/
492
493/* No kernel lock - fine */
494static u_int ds_poll(struct file *file, poll_table *wait)
495{
496 struct pcmcia_socket *s;
497 user_info_t *user;
498
499 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode));
500
501 user = file->private_data;
502 if (CHECK_USER(user))
503 return POLLERR;
504 s = user->socket;
505 /*
506 * We don't check for a dead socket here since that
507 * will send cardmgr into an endless spin.
508 */
509 poll_wait(file, &s->queue, wait);
510 if (!queue_empty(user))
511 return POLLIN | POLLRDNORM;
512 return 0;
513} /* ds_poll */
514
515/*====================================================================*/
516
517extern int pcmcia_adjust_resource_info(adjust_t *adj);
518
519static int ds_ioctl(struct inode * inode, struct file * file,
520 u_int cmd, u_long arg)
521{
522 struct pcmcia_socket *s;
523 void __user *uarg = (char __user *)arg;
524 u_int size;
525 int ret, err;
526 ds_ioctl_arg_t *buf;
527 user_info_t *user;
528
529 ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
530
531 user = file->private_data;
532 if (CHECK_USER(user))
533 return -EIO;
534
535 s = user->socket;
536 if (s->pcmcia_state.dead)
537 return -EIO;
538
539 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
540 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
541
542 /* Permission check */
543 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
544 return -EPERM;
545
546 if (cmd & IOC_IN) {
547 if (!access_ok(VERIFY_READ, uarg, size)) {
548 ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT);
549 return -EFAULT;
550 }
551 }
552 if (cmd & IOC_OUT) {
553 if (!access_ok(VERIFY_WRITE, uarg, size)) {
554 ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT);
555 return -EFAULT;
556 }
557 }
558 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
559 if (!buf)
560 return -ENOMEM;
561
562 err = ret = 0;
563
564 if (cmd & IOC_IN) __copy_from_user((char *)buf, uarg, size);
565
566 switch (cmd) {
567 case DS_ADJUST_RESOURCE_INFO:
568 ret = pcmcia_adjust_resource_info(&buf->adjust);
569 break;
570 case DS_GET_CONFIGURATION_INFO:
571 if (buf->config.Function &&
572 (buf->config.Function >= s->functions))
573 ret = CS_BAD_ARGS;
574 else
575 ret = pccard_get_configuration_info(s,
576 buf->config.Function, &buf->config);
577 break;
578 case DS_GET_FIRST_TUPLE:
579 down(&s->skt_sem);
580 pcmcia_validate_mem(s);
581 up(&s->skt_sem);
582 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
583 break;
584 case DS_GET_NEXT_TUPLE:
585 ret = pccard_get_next_tuple(s, BIND_FN_ALL, &buf->tuple);
586 break;
587 case DS_GET_TUPLE_DATA:
588 buf->tuple.TupleData = buf->tuple_parse.data;
589 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
590 ret = pccard_get_tuple_data(s, &buf->tuple);
591 break;
592 case DS_PARSE_TUPLE:
593 buf->tuple.TupleData = buf->tuple_parse.data;
594 ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
595 break;
596 case DS_RESET_CARD:
597 ret = pccard_reset_card(s);
598 break;
599 case DS_GET_STATUS:
600 if (buf->status.Function &&
601 (buf->status.Function >= s->functions))
602 ret = CS_BAD_ARGS;
603 else
604 ret = pccard_get_status(s, buf->status.Function, &buf->status);
605 break;
606 case DS_VALIDATE_CIS:
607 down(&s->skt_sem);
608 pcmcia_validate_mem(s);
609 up(&s->skt_sem);
610 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
611 break;
612 case DS_SUSPEND_CARD:
613 ret = pcmcia_suspend_card(s);
614 break;
615 case DS_RESUME_CARD:
616 ret = pcmcia_resume_card(s);
617 break;
618 case DS_EJECT_CARD:
619 err = pcmcia_eject_card(s);
620 break;
621 case DS_INSERT_CARD:
622 err = pcmcia_insert_card(s);
623 break;
624 case DS_ACCESS_CONFIGURATION_REGISTER:
625 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
626 err = -EPERM;
627 goto free_out;
628 }
629 if (buf->conf_reg.Function &&
630 (buf->conf_reg.Function >= s->functions))
631 ret = CS_BAD_ARGS;
632 else
633 ret = pccard_access_configuration_register(s,
634 buf->conf_reg.Function, &buf->conf_reg);
635 break;
636 case DS_GET_FIRST_REGION:
637 case DS_GET_NEXT_REGION:
638 case DS_BIND_MTD:
639 if (!capable(CAP_SYS_ADMIN)) {
640 err = -EPERM;
641 goto free_out;
642 } else {
643 static int printed = 0;
644 if (!printed) {
645 printk(KERN_WARNING "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
646 printk(KERN_WARNING "MTD handling any more.\n");
647 printed++;
648 }
649 }
650 err = -EINVAL;
651 goto free_out;
652 break;
653 case DS_GET_FIRST_WINDOW:
654 ret = pcmcia_get_window(s, &buf->win_info.handle, 0,
655 &buf->win_info.window);
656 break;
657 case DS_GET_NEXT_WINDOW:
658 ret = pcmcia_get_window(s, &buf->win_info.handle,
659 buf->win_info.handle->index + 1, &buf->win_info.window);
660 break;
661 case DS_GET_MEM_PAGE:
662 ret = pcmcia_get_mem_page(buf->win_info.handle,
663 &buf->win_info.map);
664 break;
665 case DS_REPLACE_CIS:
666 ret = pcmcia_replace_cis(s, &buf->cisdump);
667 break;
668 case DS_BIND_REQUEST:
669 if (!capable(CAP_SYS_ADMIN)) {
670 err = -EPERM;
671 goto free_out;
672 }
673 err = bind_request(s, &buf->bind_info);
674 break;
675 case DS_GET_DEVICE_INFO:
676 err = get_device_info(s, &buf->bind_info, 1);
677 break;
678 case DS_GET_NEXT_DEVICE:
679 err = get_device_info(s, &buf->bind_info, 0);
680 break;
681 case DS_UNBIND_REQUEST:
682 err = 0;
683 break;
684 default:
685 err = -EINVAL;
686 }
687
688 if ((err == 0) && (ret != CS_SUCCESS)) {
689 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
690 switch (ret) {
691 case CS_BAD_SOCKET: case CS_NO_CARD:
692 err = -ENODEV; break;
693 case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ:
694 case CS_BAD_TUPLE:
695 err = -EINVAL; break;
696 case CS_IN_USE:
697 err = -EBUSY; break;
698 case CS_OUT_OF_RESOURCE:
699 err = -ENOSPC; break;
700 case CS_NO_MORE_ITEMS:
701 err = -ENODATA; break;
702 case CS_UNSUPPORTED_FUNCTION:
703 err = -ENOSYS; break;
704 default:
705 err = -EIO; break;
706 }
707 }
708
709 if (cmd & IOC_OUT) {
710 if (__copy_to_user(uarg, (char *)buf, size))
711 err = -EFAULT;
712 }
713
714free_out:
715 kfree(buf);
716 return err;
717} /* ds_ioctl */
718
719/*====================================================================*/
720
721static struct file_operations ds_fops = {
722 .owner = THIS_MODULE,
723 .open = ds_open,
724 .release = ds_release,
725 .ioctl = ds_ioctl,
726 .read = ds_read,
727 .write = ds_write,
728 .poll = ds_poll,
729};
730
731void __init pcmcia_setup_ioctl(void) {
732 int i;
733
734 /* Set up character device for user mode clients */
735 i = register_chrdev(0, "pcmcia", &ds_fops);
736 if (i < 0)
737 printk(KERN_NOTICE "unable to find a free device # for "
738 "Driver Services (error=%d)\n", i);
739 else
740 major_dev = i;
741
742#ifdef CONFIG_PROC_FS
743 proc_pccard = proc_mkdir("pccard", proc_bus);
744 if (proc_pccard)
745 create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL);
746#endif
747}
748
749
750void __exit pcmcia_cleanup_ioctl(void) {
751#ifdef CONFIG_PROC_FS
752 if (proc_pccard) {
753 remove_proc_entry("drivers", proc_pccard);
754 remove_proc_entry("pccard", proc_bus);
755 }
756#endif
757 if (major_dev != -1)
758 unregister_chrdev(major_dev, "pcmcia");
759}
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
new file mode 100644
index 000000000000..184f4f88b2a0
--- /dev/null
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -0,0 +1,943 @@
1/*
2 * PCMCIA 16-bit resource management functions
3 *
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 *
8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski
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 version 2 as
13 * published by the Free Software Foundation.
14 *
15 */
16
17#include <linux/config.h>
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <linux/pci.h>
23#include <linux/device.h>
24
25#define IN_CARD_SERVICES
26#include <pcmcia/cs_types.h>
27#include <pcmcia/ss.h>
28#include <pcmcia/cs.h>
29#include <pcmcia/bulkmem.h>
30#include <pcmcia/cistpl.h>
31#include <pcmcia/cisreg.h>
32#include <pcmcia/ds.h>
33
34#include "cs_internal.h"
35#include "ds_internal.h"
36
37
38/* Access speed for IO windows */
39static int io_speed = 0;
40module_param(io_speed, int, 0444);
41
42
43#ifdef CONFIG_PCMCIA_PROBE
44/* mask of IRQs already reserved by other cards, we should avoid using them */
45static u8 pcmcia_used_irq[NR_IRQS];
46#endif
47
48
49#ifdef DEBUG
50extern int ds_pc_debug;
51#define cs_socket_name(skt) ((skt)->dev.class_id)
52
53#define ds_dbg(skt, lvl, fmt, arg...) do { \
54 if (ds_pc_debug >= lvl) \
55 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
56 cs_socket_name(skt) , ## arg); \
57} while (0)
58#else
59#define ds_dbg(lvl, fmt, arg...) do { } while (0)
60#endif
61
62
63
64/** alloc_io_space
65 *
66 * Special stuff for managing IO windows, because they are scarce
67 */
68
69static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
70 ioaddr_t num, u_int lines)
71{
72 int i;
73 kio_addr_t try, align;
74
75 align = (*base) ? (lines ? 1<<lines : 0) : 1;
76 if (align && (align < num)) {
77 if (*base) {
78 ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
79 num, align);
80 align = 0;
81 } else
82 while (align && (align < num)) align <<= 1;
83 }
84 if (*base & ~(align-1)) {
85 ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
86 *base, align);
87 align = 0;
88 }
89 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
90 *base = s->io_offset | (*base & 0x0fff);
91 s->io[0].Attributes = attr;
92 return 0;
93 }
94 /* Check for an already-allocated window that must conflict with
95 * what was asked for. It is a hack because it does not catch all
96 * potential conflicts, just the most obvious ones.
97 */
98 for (i = 0; i < MAX_IO_WIN; i++)
99 if ((s->io[i].NumPorts != 0) &&
100 ((s->io[i].BasePort & (align-1)) == *base))
101 return 1;
102 for (i = 0; i < MAX_IO_WIN; i++) {
103 if (s->io[i].NumPorts == 0) {
104 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
105 if (s->io[i].res) {
106 s->io[i].Attributes = attr;
107 s->io[i].BasePort = *base = s->io[i].res->start;
108 s->io[i].NumPorts = s->io[i].InUse = num;
109 break;
110 } else
111 return 1;
112 } else if (s->io[i].Attributes != attr)
113 continue;
114 /* Try to extend top of window */
115 try = s->io[i].BasePort + s->io[i].NumPorts;
116 if ((*base == 0) || (*base == try))
117 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
118 s->io[i].res->end + num, s) == 0) {
119 *base = try;
120 s->io[i].NumPorts += num;
121 s->io[i].InUse += num;
122 break;
123 }
124 /* Try to extend bottom of window */
125 try = s->io[i].BasePort - num;
126 if ((*base == 0) || (*base == try))
127 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
128 s->io[i].res->end, s) == 0) {
129 s->io[i].BasePort = *base = try;
130 s->io[i].NumPorts += num;
131 s->io[i].InUse += num;
132 break;
133 }
134 }
135 return (i == MAX_IO_WIN);
136} /* alloc_io_space */
137
138
139static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
140 ioaddr_t num)
141{
142 int i;
143
144 for (i = 0; i < MAX_IO_WIN; i++) {
145 if ((s->io[i].BasePort <= base) &&
146 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) {
147 s->io[i].InUse -= num;
148 /* Free the window if no one else is using it */
149 if (s->io[i].InUse == 0) {
150 s->io[i].NumPorts = 0;
151 release_resource(s->io[i].res);
152 kfree(s->io[i].res);
153 s->io[i].res = NULL;
154 }
155 }
156 }
157} /* release_io_space */
158
159
160/** pccard_access_configuration_register
161 *
162 * Access_configuration_register() reads and writes configuration
163 * registers in attribute memory. Memory window 0 is reserved for
164 * this and the tuple reading services.
165 */
166
167int pccard_access_configuration_register(struct pcmcia_socket *s,
168 unsigned int function,
169 conf_reg_t *reg)
170{
171 config_t *c;
172 int addr;
173 u_char val;
174
175 if (!s || !s->config)
176 return CS_NO_CARD;
177
178 c = &s->config[function];
179
180 if (c == NULL)
181 return CS_NO_CARD;
182
183 if (!(c->state & CONFIG_LOCKED))
184 return CS_CONFIGURATION_LOCKED;
185
186 addr = (c->ConfigBase + reg->Offset) >> 1;
187
188 switch (reg->Action) {
189 case CS_READ:
190 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
191 reg->Value = val;
192 break;
193 case CS_WRITE:
194 val = reg->Value;
195 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
196 break;
197 default:
198 return CS_BAD_ARGS;
199 break;
200 }
201 return CS_SUCCESS;
202} /* pccard_access_configuration_register */
203
204int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
205 conf_reg_t *reg)
206{
207 return pccard_access_configuration_register(p_dev->socket,
208 p_dev->func, reg);
209}
210EXPORT_SYMBOL(pcmcia_access_configuration_register);
211
212
213
214int pccard_get_configuration_info(struct pcmcia_socket *s,
215 unsigned int function,
216 config_info_t *config)
217{
218 config_t *c;
219
220 if (!(s->state & SOCKET_PRESENT))
221 return CS_NO_CARD;
222
223 config->Function = function;
224
225#ifdef CONFIG_CARDBUS
226 if (s->state & SOCKET_CARDBUS) {
227 memset(config, 0, sizeof(config_info_t));
228 config->Vcc = s->socket.Vcc;
229 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
230 config->Option = s->cb_dev->subordinate->number;
231 if (s->state & SOCKET_CARDBUS_CONFIG) {
232 config->Attributes = CONF_VALID_CLIENT;
233 config->IntType = INT_CARDBUS;
234 config->AssignedIRQ = s->irq.AssignedIRQ;
235 if (config->AssignedIRQ)
236 config->Attributes |= CONF_ENABLE_IRQ;
237 config->BasePort1 = s->io[0].BasePort;
238 config->NumPorts1 = s->io[0].NumPorts;
239 }
240 return CS_SUCCESS;
241 }
242#endif
243
244 c = (s->config != NULL) ? &s->config[function] : NULL;
245
246 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
247 config->Attributes = 0;
248 config->Vcc = s->socket.Vcc;
249 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
250 return CS_SUCCESS;
251 }
252
253 /* !!! This is a hack !!! */
254 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
255 config->Attributes |= CONF_VALID_CLIENT;
256 config->CardValues = c->CardValues;
257 config->IRQAttributes = c->irq.Attributes;
258 config->AssignedIRQ = s->irq.AssignedIRQ;
259 config->BasePort1 = c->io.BasePort1;
260 config->NumPorts1 = c->io.NumPorts1;
261 config->Attributes1 = c->io.Attributes1;
262 config->BasePort2 = c->io.BasePort2;
263 config->NumPorts2 = c->io.NumPorts2;
264 config->Attributes2 = c->io.Attributes2;
265 config->IOAddrLines = c->io.IOAddrLines;
266
267 return CS_SUCCESS;
268} /* pccard_get_configuration_info */
269
270int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
271 config_info_t *config)
272{
273 return pccard_get_configuration_info(p_dev->socket, p_dev->func,
274 config);
275}
276EXPORT_SYMBOL(pcmcia_get_configuration_info);
277
278
279/** pcmcia_get_window
280 */
281int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
282 int idx, win_req_t *req)
283{
284 window_t *win;
285 int w;
286
287 if (!s || !(s->state & SOCKET_PRESENT))
288 return CS_NO_CARD;
289 for (w = idx; w < MAX_WIN; w++)
290 if (s->state & SOCKET_WIN_REQ(w))
291 break;
292 if (w == MAX_WIN)
293 return CS_NO_MORE_ITEMS;
294 win = &s->win[w];
295 req->Base = win->ctl.res->start;
296 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
297 req->AccessSpeed = win->ctl.speed;
298 req->Attributes = 0;
299 if (win->ctl.flags & MAP_ATTRIB)
300 req->Attributes |= WIN_MEMORY_TYPE_AM;
301 if (win->ctl.flags & MAP_ACTIVE)
302 req->Attributes |= WIN_ENABLE;
303 if (win->ctl.flags & MAP_16BIT)
304 req->Attributes |= WIN_DATA_WIDTH_16;
305 if (win->ctl.flags & MAP_USE_WAIT)
306 req->Attributes |= WIN_USE_WAIT;
307 *handle = win;
308 return CS_SUCCESS;
309} /* pcmcia_get_window */
310EXPORT_SYMBOL(pcmcia_get_window);
311
312
313/** pccard_get_status
314 *
315 * Get the current socket state bits. We don't support the latched
316 * SocketState yet: I haven't seen any point for it.
317 */
318
319int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
320 cs_status_t *status)
321{
322 config_t *c;
323 int val;
324
325 s->ops->get_status(s, &val);
326 status->CardState = status->SocketState = 0;
327 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
328 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
329 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
330 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
331 if (s->state & SOCKET_SUSPEND)
332 status->CardState |= CS_EVENT_PM_SUSPEND;
333 if (!(s->state & SOCKET_PRESENT))
334 return CS_NO_CARD;
335
336 c = (s->config != NULL) ? &s->config[function] : NULL;
337 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
338 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
339 u_char reg;
340 if (c->Present & PRESENT_PIN_REPLACE) {
341 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
342 status->CardState |=
343 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
344 status->CardState |=
345 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
346 status->CardState |=
347 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
348 status->CardState |=
349 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
350 } else {
351 /* No PRR? Then assume we're always ready */
352 status->CardState |= CS_EVENT_READY_CHANGE;
353 }
354 if (c->Present & PRESENT_EXT_STATUS) {
355 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
356 status->CardState |=
357 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
358 }
359 return CS_SUCCESS;
360 }
361 status->CardState |=
362 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
363 status->CardState |=
364 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
365 status->CardState |=
366 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
367 status->CardState |=
368 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
369 return CS_SUCCESS;
370} /* pccard_get_status */
371
372int pcmcia_get_status(client_handle_t handle, cs_status_t *status)
373{
374 struct pcmcia_socket *s;
375 s = SOCKET(handle);
376 return pccard_get_status(s, handle->func, status);
377}
378EXPORT_SYMBOL(pcmcia_get_status);
379
380
381
382/** pcmcia_get_mem_page
383 *
384 * Change the card address of an already open memory window.
385 */
386int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
387{
388 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
389 return CS_BAD_HANDLE;
390 req->Page = 0;
391 req->CardOffset = win->ctl.card_start;
392 return CS_SUCCESS;
393} /* pcmcia_get_mem_page */
394EXPORT_SYMBOL(pcmcia_get_mem_page);
395
396
397int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
398{
399 struct pcmcia_socket *s;
400 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
401 return CS_BAD_HANDLE;
402 if (req->Page != 0)
403 return CS_BAD_PAGE;
404 s = win->sock;
405 win->ctl.card_start = req->CardOffset;
406 if (s->ops->set_mem_map(s, &win->ctl) != 0)
407 return CS_BAD_OFFSET;
408 return CS_SUCCESS;
409} /* pcmcia_map_mem_page */
410EXPORT_SYMBOL(pcmcia_map_mem_page);
411
412
413/** pcmcia_modify_configuration
414 *
415 * Modify a locked socket configuration
416 */
417int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
418 modconf_t *mod)
419{
420 struct pcmcia_socket *s;
421 config_t *c;
422
423 s = p_dev->socket;
424 c = CONFIG(p_dev);
425 if (!(s->state & SOCKET_PRESENT))
426 return CS_NO_CARD;
427 if (!(c->state & CONFIG_LOCKED))
428 return CS_CONFIGURATION_LOCKED;
429
430 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
431 if (mod->Attributes & CONF_ENABLE_IRQ) {
432 c->Attributes |= CONF_ENABLE_IRQ;
433 s->socket.io_irq = s->irq.AssignedIRQ;
434 } else {
435 c->Attributes &= ~CONF_ENABLE_IRQ;
436 s->socket.io_irq = 0;
437 }
438 s->ops->set_socket(s, &s->socket);
439 }
440
441 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
442 return CS_BAD_VCC;
443
444 /* We only allow changing Vpp1 and Vpp2 to the same value */
445 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
446 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
447 if (mod->Vpp1 != mod->Vpp2)
448 return CS_BAD_VPP;
449 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1;
450 if (s->ops->set_socket(s, &s->socket))
451 return CS_BAD_VPP;
452 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
453 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
454 return CS_BAD_VPP;
455
456 return CS_SUCCESS;
457} /* modify_configuration */
458EXPORT_SYMBOL(pcmcia_modify_configuration);
459
460
461int pcmcia_release_configuration(struct pcmcia_device *p_dev)
462{
463 pccard_io_map io = { 0, 0, 0, 0, 1 };
464 struct pcmcia_socket *s = p_dev->socket;
465 int i;
466
467 if (!(p_dev->state & CLIENT_CONFIG_LOCKED))
468 return CS_BAD_HANDLE;
469 p_dev->state &= ~CLIENT_CONFIG_LOCKED;
470
471 if (!(p_dev->state & CLIENT_STALE)) {
472 config_t *c = CONFIG(p_dev);
473 if (--(s->lock_count) == 0) {
474 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
475 s->socket.Vpp = 0;
476 s->socket.io_irq = 0;
477 s->ops->set_socket(s, &s->socket);
478 }
479 if (c->state & CONFIG_IO_REQ)
480 for (i = 0; i < MAX_IO_WIN; i++) {
481 if (s->io[i].NumPorts == 0)
482 continue;
483 s->io[i].Config--;
484 if (s->io[i].Config != 0)
485 continue;
486 io.map = i;
487 s->ops->set_io_map(s, &io);
488 }
489 c->state &= ~CONFIG_LOCKED;
490 }
491
492 return CS_SUCCESS;
493} /* pcmcia_release_configuration */
494EXPORT_SYMBOL(pcmcia_release_configuration);
495
496
497/** pcmcia_release_io
498 *
499 * Release_io() releases the I/O ranges allocated by a client. This
500 * may be invoked some time after a card ejection has already dumped
501 * the actual socket configuration, so if the client is "stale", we
502 * don't bother checking the port ranges against the current socket
503 * values.
504 */
505int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
506{
507 struct pcmcia_socket *s = p_dev->socket;
508
509 if (!(p_dev->state & CLIENT_IO_REQ))
510 return CS_BAD_HANDLE;
511 p_dev->state &= ~CLIENT_IO_REQ;
512
513 if (!(p_dev->state & CLIENT_STALE)) {
514 config_t *c = CONFIG(p_dev);
515 if (c->state & CONFIG_LOCKED)
516 return CS_CONFIGURATION_LOCKED;
517 if ((c->io.BasePort1 != req->BasePort1) ||
518 (c->io.NumPorts1 != req->NumPorts1) ||
519 (c->io.BasePort2 != req->BasePort2) ||
520 (c->io.NumPorts2 != req->NumPorts2))
521 return CS_BAD_ARGS;
522 c->state &= ~CONFIG_IO_REQ;
523 }
524
525 release_io_space(s, req->BasePort1, req->NumPorts1);
526 if (req->NumPorts2)
527 release_io_space(s, req->BasePort2, req->NumPorts2);
528
529 return CS_SUCCESS;
530} /* pcmcia_release_io */
531EXPORT_SYMBOL(pcmcia_release_io);
532
533
534int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
535{
536 struct pcmcia_socket *s = p_dev->socket;
537 if (!(p_dev->state & CLIENT_IRQ_REQ))
538 return CS_BAD_HANDLE;
539 p_dev->state &= ~CLIENT_IRQ_REQ;
540
541 if (!(p_dev->state & CLIENT_STALE)) {
542 config_t *c = CONFIG(p_dev);
543 if (c->state & CONFIG_LOCKED)
544 return CS_CONFIGURATION_LOCKED;
545 if (c->irq.Attributes != req->Attributes)
546 return CS_BAD_ATTRIBUTE;
547 if (s->irq.AssignedIRQ != req->AssignedIRQ)
548 return CS_BAD_IRQ;
549 if (--s->irq.Config == 0) {
550 c->state &= ~CONFIG_IRQ_REQ;
551 s->irq.AssignedIRQ = 0;
552 }
553 }
554
555 if (req->Attributes & IRQ_HANDLE_PRESENT) {
556 free_irq(req->AssignedIRQ, req->Instance);
557 }
558
559#ifdef CONFIG_PCMCIA_PROBE
560 pcmcia_used_irq[req->AssignedIRQ]--;
561#endif
562
563 return CS_SUCCESS;
564} /* pcmcia_release_irq */
565EXPORT_SYMBOL(pcmcia_release_irq);
566
567
568int pcmcia_release_window(window_handle_t win)
569{
570 struct pcmcia_socket *s;
571
572 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
573 return CS_BAD_HANDLE;
574 s = win->sock;
575 if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
576 return CS_BAD_HANDLE;
577
578 /* Shut down memory window */
579 win->ctl.flags &= ~MAP_ACTIVE;
580 s->ops->set_mem_map(s, &win->ctl);
581 s->state &= ~SOCKET_WIN_REQ(win->index);
582
583 /* Release system memory */
584 if (win->ctl.res) {
585 release_resource(win->ctl.res);
586 kfree(win->ctl.res);
587 win->ctl.res = NULL;
588 }
589 win->handle->state &= ~CLIENT_WIN_REQ(win->index);
590
591 win->magic = 0;
592
593 return CS_SUCCESS;
594} /* pcmcia_release_window */
595EXPORT_SYMBOL(pcmcia_release_window);
596
597
598int pcmcia_request_configuration(struct pcmcia_device *p_dev,
599 config_req_t *req)
600{
601 int i;
602 u_int base;
603 struct pcmcia_socket *s = p_dev->socket;
604 config_t *c;
605 pccard_io_map iomap;
606
607 if (!(s->state & SOCKET_PRESENT))
608 return CS_NO_CARD;
609
610 if (req->IntType & INT_CARDBUS)
611 return CS_UNSUPPORTED_MODE;
612 c = CONFIG(p_dev);
613 if (c->state & CONFIG_LOCKED)
614 return CS_CONFIGURATION_LOCKED;
615
616 /* Do power control. We don't allow changes in Vcc. */
617 if (s->socket.Vcc != req->Vcc)
618 return CS_BAD_VCC;
619 if (req->Vpp1 != req->Vpp2)
620 return CS_BAD_VPP;
621 s->socket.Vpp = req->Vpp1;
622 if (s->ops->set_socket(s, &s->socket))
623 return CS_BAD_VPP;
624
625 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
626
627 /* Pick memory or I/O card, DMA mode, interrupt */
628 c->IntType = req->IntType;
629 c->Attributes = req->Attributes;
630 if (req->IntType & INT_MEMORY_AND_IO)
631 s->socket.flags |= SS_IOCARD;
632 if (req->IntType & INT_ZOOMED_VIDEO)
633 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
634 if (req->Attributes & CONF_ENABLE_DMA)
635 s->socket.flags |= SS_DMA_MODE;
636 if (req->Attributes & CONF_ENABLE_SPKR)
637 s->socket.flags |= SS_SPKR_ENA;
638 if (req->Attributes & CONF_ENABLE_IRQ)
639 s->socket.io_irq = s->irq.AssignedIRQ;
640 else
641 s->socket.io_irq = 0;
642 s->ops->set_socket(s, &s->socket);
643 s->lock_count++;
644
645 /* Set up CIS configuration registers */
646 base = c->ConfigBase = req->ConfigBase;
647 c->Present = c->CardValues = req->Present;
648 if (req->Present & PRESENT_COPY) {
649 c->Copy = req->Copy;
650 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
651 }
652 if (req->Present & PRESENT_OPTION) {
653 if (s->functions == 1) {
654 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
655 } else {
656 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
657 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
658 if (req->Present & PRESENT_IOBASE_0)
659 c->Option |= COR_ADDR_DECODE;
660 }
661 if (c->state & CONFIG_IRQ_REQ)
662 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
663 c->Option |= COR_LEVEL_REQ;
664 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
665 mdelay(40);
666 }
667 if (req->Present & PRESENT_STATUS) {
668 c->Status = req->Status;
669 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
670 }
671 if (req->Present & PRESENT_PIN_REPLACE) {
672 c->Pin = req->Pin;
673 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
674 }
675 if (req->Present & PRESENT_EXT_STATUS) {
676 c->ExtStatus = req->ExtStatus;
677 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
678 }
679 if (req->Present & PRESENT_IOBASE_0) {
680 u_char b = c->io.BasePort1 & 0xff;
681 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
682 b = (c->io.BasePort1 >> 8) & 0xff;
683 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
684 }
685 if (req->Present & PRESENT_IOSIZE) {
686 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
687 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
688 }
689
690 /* Configure I/O windows */
691 if (c->state & CONFIG_IO_REQ) {
692 iomap.speed = io_speed;
693 for (i = 0; i < MAX_IO_WIN; i++)
694 if (s->io[i].NumPorts != 0) {
695 iomap.map = i;
696 iomap.flags = MAP_ACTIVE;
697 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) {
698 case IO_DATA_PATH_WIDTH_16:
699 iomap.flags |= MAP_16BIT; break;
700 case IO_DATA_PATH_WIDTH_AUTO:
701 iomap.flags |= MAP_AUTOSZ; break;
702 default:
703 break;
704 }
705 iomap.start = s->io[i].BasePort;
706 iomap.stop = iomap.start + s->io[i].NumPorts - 1;
707 s->ops->set_io_map(s, &iomap);
708 s->io[i].Config++;
709 }
710 }
711
712 c->state |= CONFIG_LOCKED;
713 p_dev->state |= CLIENT_CONFIG_LOCKED;
714 return CS_SUCCESS;
715} /* pcmcia_request_configuration */
716EXPORT_SYMBOL(pcmcia_request_configuration);
717
718
719/** pcmcia_request_io
720 *
721 * Request_io() reserves ranges of port addresses for a socket.
722 * I have not implemented range sharing or alias addressing.
723 */
724int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
725{
726 struct pcmcia_socket *s = p_dev->socket;
727 config_t *c;
728
729 if (!(s->state & SOCKET_PRESENT))
730 return CS_NO_CARD;
731
732 if (!req)
733 return CS_UNSUPPORTED_MODE;
734 c = CONFIG(p_dev);
735 if (c->state & CONFIG_LOCKED)
736 return CS_CONFIGURATION_LOCKED;
737 if (c->state & CONFIG_IO_REQ)
738 return CS_IN_USE;
739 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
740 return CS_BAD_ATTRIBUTE;
741 if ((req->NumPorts2 > 0) &&
742 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
743 return CS_BAD_ATTRIBUTE;
744
745 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
746 req->NumPorts1, req->IOAddrLines))
747 return CS_IN_USE;
748
749 if (req->NumPorts2) {
750 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
751 req->NumPorts2, req->IOAddrLines)) {
752 release_io_space(s, req->BasePort1, req->NumPorts1);
753 return CS_IN_USE;
754 }
755 }
756
757 c->io = *req;
758 c->state |= CONFIG_IO_REQ;
759 p_dev->state |= CLIENT_IO_REQ;
760 return CS_SUCCESS;
761} /* pcmcia_request_io */
762EXPORT_SYMBOL(pcmcia_request_io);
763
764
765/** pcmcia_request_irq
766 *
767 * Request_irq() reserves an irq for this client.
768 *
769 * Also, since Linux only reserves irq's when they are actually
770 * hooked, we don't guarantee that an irq will still be available
771 * when the configuration is locked. Now that I think about it,
772 * there might be a way to fix this using a dummy handler.
773 */
774
775#ifdef CONFIG_PCMCIA_PROBE
776static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
777{
778 return IRQ_NONE;
779}
780#endif
781
782int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
783{
784 struct pcmcia_socket *s = p_dev->socket;
785 config_t *c;
786 int ret = CS_IN_USE, irq = 0;
787
788 if (!(s->state & SOCKET_PRESENT))
789 return CS_NO_CARD;
790 c = CONFIG(p_dev);
791 if (c->state & CONFIG_LOCKED)
792 return CS_CONFIGURATION_LOCKED;
793 if (c->state & CONFIG_IRQ_REQ)
794 return CS_IN_USE;
795
796#ifdef CONFIG_PCMCIA_PROBE
797 if (s->irq.AssignedIRQ != 0) {
798 /* If the interrupt is already assigned, it must be the same */
799 irq = s->irq.AssignedIRQ;
800 } else {
801 int try;
802 u32 mask = s->irq_mask;
803 void *data = NULL;
804
805 for (try = 0; try < 64; try++) {
806 irq = try % 32;
807
808 /* marked as available by driver, and not blocked by userspace? */
809 if (!((mask >> irq) & 1))
810 continue;
811
812 /* avoid an IRQ which is already used by a PCMCIA card */
813 if ((try < 32) && pcmcia_used_irq[irq])
814 continue;
815
816 /* register the correct driver, if possible, of check whether
817 * registering a dummy handle works, i.e. if the IRQ isn't
818 * marked as used by the kernel resource management core */
819 ret = request_irq(irq,
820 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
821 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
822 (s->functions > 1) ||
823 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
824 p_dev->dev.bus_id,
825 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
826 if (!ret) {
827 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
828 free_irq(irq, data);
829 break;
830 }
831 }
832 }
833#endif
834 if (ret) {
835 if (!s->pci_irq)
836 return ret;
837 irq = s->pci_irq;
838 }
839
840 if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
841 if (request_irq(irq, req->Handler,
842 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
843 (s->functions > 1) ||
844 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
845 p_dev->dev.bus_id, req->Instance))
846 return CS_IN_USE;
847 }
848
849 c->irq.Attributes = req->Attributes;
850 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
851 s->irq.Config++;
852
853 c->state |= CONFIG_IRQ_REQ;
854 p_dev->state |= CLIENT_IRQ_REQ;
855
856#ifdef CONFIG_PCMCIA_PROBE
857 pcmcia_used_irq[irq]++;
858#endif
859
860 return CS_SUCCESS;
861} /* pcmcia_request_irq */
862EXPORT_SYMBOL(pcmcia_request_irq);
863
864
865/** pcmcia_request_window
866 *
867 * Request_window() establishes a mapping between card memory space
868 * and system memory space.
869 */
870int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
871{
872 struct pcmcia_socket *s = (*p_dev)->socket;
873 window_t *win;
874 u_long align;
875 int w;
876
877 if (!(s->state & SOCKET_PRESENT))
878 return CS_NO_CARD;
879 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
880 return CS_BAD_ATTRIBUTE;
881
882 /* Window size defaults to smallest available */
883 if (req->Size == 0)
884 req->Size = s->map_size;
885 align = (((s->features & SS_CAP_MEM_ALIGN) ||
886 (req->Attributes & WIN_STRICT_ALIGN)) ?
887 req->Size : s->map_size);
888 if (req->Size & (s->map_size-1))
889 return CS_BAD_SIZE;
890 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
891 (req->Base & (align-1)))
892 return CS_BAD_BASE;
893 if (req->Base)
894 align = 0;
895
896 /* Allocate system memory window */
897 for (w = 0; w < MAX_WIN; w++)
898 if (!(s->state & SOCKET_WIN_REQ(w))) break;
899 if (w == MAX_WIN)
900 return CS_OUT_OF_RESOURCE;
901
902 win = &s->win[w];
903 win->magic = WINDOW_MAGIC;
904 win->index = w;
905 win->handle = *p_dev;
906 win->sock = s;
907
908 if (!(s->features & SS_CAP_STATIC_MAP)) {
909 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
910 (req->Attributes & WIN_MAP_BELOW_1MB), s);
911 if (!win->ctl.res)
912 return CS_IN_USE;
913 }
914 (*p_dev)->state |= CLIENT_WIN_REQ(w);
915
916 /* Configure the socket controller */
917 win->ctl.map = w+1;
918 win->ctl.flags = 0;
919 win->ctl.speed = req->AccessSpeed;
920 if (req->Attributes & WIN_MEMORY_TYPE)
921 win->ctl.flags |= MAP_ATTRIB;
922 if (req->Attributes & WIN_ENABLE)
923 win->ctl.flags |= MAP_ACTIVE;
924 if (req->Attributes & WIN_DATA_WIDTH_16)
925 win->ctl.flags |= MAP_16BIT;
926 if (req->Attributes & WIN_USE_WAIT)
927 win->ctl.flags |= MAP_USE_WAIT;
928 win->ctl.card_start = 0;
929 if (s->ops->set_mem_map(s, &win->ctl) != 0)
930 return CS_BAD_ARGS;
931 s->state |= SOCKET_WIN_REQ(w);
932
933 /* Return window handle */
934 if (s->features & SS_CAP_STATIC_MAP) {
935 req->Base = win->ctl.static_start;
936 } else {
937 req->Base = win->ctl.res->start;
938 }
939 *wh = win;
940
941 return CS_SUCCESS;
942} /* pcmcia_request_window */
943EXPORT_SYMBOL(pcmcia_request_window);
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index b6843f8d300d..0668384ebc8b 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -72,7 +72,7 @@ int pcmcia_adjust_resource_info(adjust_t *adj)
72 /* you can't use the old interface if the new 72 /* you can't use the old interface if the new
73 * one was used before */ 73 * one was used before */
74 spin_lock_irqsave(&s->lock, flags); 74 spin_lock_irqsave(&s->lock, flags);
75 if ((s->resource_setup_done) && 75 if ((s->resource_setup_new) &&
76 !(s->resource_setup_old)) { 76 !(s->resource_setup_old)) {
77 spin_unlock_irqrestore(&s->lock, flags); 77 spin_unlock_irqrestore(&s->lock, flags);
78 continue; 78 continue;
@@ -105,29 +105,32 @@ void pcmcia_validate_mem(struct pcmcia_socket *s)
105} 105}
106EXPORT_SYMBOL(pcmcia_validate_mem); 106EXPORT_SYMBOL(pcmcia_validate_mem);
107 107
108int adjust_io_region(struct resource *res, unsigned long r_start, 108int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
109 unsigned long r_end, struct pcmcia_socket *s) 109 unsigned long r_end, struct pcmcia_socket *s)
110{ 110{
111 if (s->resource_ops->adjust_io_region) 111 if (s->resource_ops->adjust_io_region)
112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s); 112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
113 return -ENOMEM; 113 return -ENOMEM;
114} 114}
115EXPORT_SYMBOL(pcmcia_adjust_io_region);
115 116
116struct resource *find_io_region(unsigned long base, int num, 117struct resource *pcmcia_find_io_region(unsigned long base, int num,
117 unsigned long align, struct pcmcia_socket *s) 118 unsigned long align, struct pcmcia_socket *s)
118{ 119{
119 if (s->resource_ops->find_io) 120 if (s->resource_ops->find_io)
120 return s->resource_ops->find_io(base, num, align, s); 121 return s->resource_ops->find_io(base, num, align, s);
121 return NULL; 122 return NULL;
122} 123}
124EXPORT_SYMBOL(pcmcia_find_io_region);
123 125
124struct resource *find_mem_region(u_long base, u_long num, u_long align, 126struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
125 int low, struct pcmcia_socket *s) 127 int low, struct pcmcia_socket *s)
126{ 128{
127 if (s->resource_ops->find_mem) 129 if (s->resource_ops->find_mem)
128 return s->resource_ops->find_mem(base, num, align, low, s); 130 return s->resource_ops->find_mem(base, num, align, low, s);
129 return NULL; 131 return NULL;
130} 132}
133EXPORT_SYMBOL(pcmcia_find_mem_region);
131 134
132void release_resource_db(struct pcmcia_socket *s) 135void release_resource_db(struct pcmcia_socket *s)
133{ 136{
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 5876bab7c14c..c42455d20eb6 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -372,6 +372,9 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
372 base, base+num-1); 372 base, base+num-1);
373 bad = fail = 0; 373 bad = fail = 0;
374 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff); 374 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff);
375 /* don't allow too large steps */
376 if (step > 0x800000)
377 step = 0x800000;
375 /* cis_readable wants to map 2x map_size */ 378 /* cis_readable wants to map 2x map_size */
376 if (step < 2 * s->map_size) 379 if (step < 2 * s->map_size)
377 step = 2 * s->map_size; 380 step = 2 * s->map_size;
@@ -465,8 +468,7 @@ static void validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
465 468
466 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { 469 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) {
467 mm = *m; 470 mm = *m;
468 if (do_mem_probe(mm.base, mm.num, s)) 471 do_mem_probe(mm.base, mm.num, s);
469 break;
470 } 472 }
471} 473}
472 474
@@ -601,7 +603,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
601 603
602======================================================================*/ 604======================================================================*/
603 605
604struct resource *nonstatic_find_io_region(unsigned long base, int num, 606static struct resource *nonstatic_find_io_region(unsigned long base, int num,
605 unsigned long align, struct pcmcia_socket *s) 607 unsigned long align, struct pcmcia_socket *s)
606{ 608{
607 struct resource *res = make_resource(0, num, IORESOURCE_IO, s->dev.class_id); 609 struct resource *res = make_resource(0, num, IORESOURCE_IO, s->dev.class_id);
@@ -635,8 +637,8 @@ struct resource *nonstatic_find_io_region(unsigned long base, int num,
635 return res; 637 return res;
636} 638}
637 639
638struct resource * nonstatic_find_mem_region(u_long base, u_long num, u_long align, 640static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
639 int low, struct pcmcia_socket *s) 641 u_long align, int low, struct pcmcia_socket *s)
640{ 642{
641 struct resource *res = make_resource(0, num, IORESOURCE_MEM, s->dev.class_id); 643 struct resource *res = make_resource(0, num, IORESOURCE_MEM, s->dev.class_id);
642 struct socket_data *s_data = s->resource_data; 644 struct socket_data *s_data = s->resource_data;
@@ -683,27 +685,23 @@ struct resource * nonstatic_find_mem_region(u_long base, u_long num, u_long alig
683} 685}
684 686
685 687
686static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj) 688static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end)
687{ 689{
688 u_long base, num;
689 struct socket_data *data = s->resource_data; 690 struct socket_data *data = s->resource_data;
690 int ret; 691 unsigned long size = end - start + 1;
691 692 int ret = 0;
692 base = adj->resource.memory.Base;
693 num = adj->resource.memory.Size;
694 if ((num == 0) || (base+num-1 < base))
695 return CS_BAD_SIZE;
696 693
697 ret = CS_SUCCESS; 694 if (end <= start)
695 return -EINVAL;
698 696
699 down(&rsrc_sem); 697 down(&rsrc_sem);
700 switch (adj->Action) { 698 switch (action) {
701 case ADD_MANAGED_RESOURCE: 699 case ADD_MANAGED_RESOURCE:
702 ret = add_interval(&data->mem_db, base, num); 700 ret = add_interval(&data->mem_db, start, size);
703 break; 701 break;
704 case REMOVE_MANAGED_RESOURCE: 702 case REMOVE_MANAGED_RESOURCE:
705 ret = sub_interval(&data->mem_db, base, num); 703 ret = sub_interval(&data->mem_db, start, size);
706 if (ret == CS_SUCCESS) { 704 if (!ret) {
707 struct pcmcia_socket *socket; 705 struct pcmcia_socket *socket;
708 down_read(&pcmcia_socket_list_rwsem); 706 down_read(&pcmcia_socket_list_rwsem);
709 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) 707 list_for_each_entry(socket, &pcmcia_socket_list, socket_list)
@@ -712,7 +710,7 @@ static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj)
712 } 710 }
713 break; 711 break;
714 default: 712 default:
715 ret = CS_UNSUPPORTED_FUNCTION; 713 ret = -EINVAL;
716 } 714 }
717 up(&rsrc_sem); 715 up(&rsrc_sem);
718 716
@@ -720,36 +718,35 @@ static int adjust_memory(struct pcmcia_socket *s, adjust_t *adj)
720} 718}
721 719
722 720
723static int adjust_io(struct pcmcia_socket *s, adjust_t *adj) 721static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end)
724{ 722{
725 struct socket_data *data = s->resource_data; 723 struct socket_data *data = s->resource_data;
726 kio_addr_t base, num; 724 unsigned long size = end - start + 1;
727 int ret = CS_SUCCESS; 725 int ret = 0;
728 726
729 base = adj->resource.io.BasePort; 727 if (end <= start)
730 num = adj->resource.io.NumPorts; 728 return -EINVAL;
731 if ((base < 0) || (base > 0xffff)) 729
732 return CS_BAD_BASE; 730 if (end > IO_SPACE_LIMIT)
733 if ((num <= 0) || (base+num > 0x10000) || (base+num <= base)) 731 return -EINVAL;
734 return CS_BAD_SIZE;
735 732
736 down(&rsrc_sem); 733 down(&rsrc_sem);
737 switch (adj->Action) { 734 switch (action) {
738 case ADD_MANAGED_RESOURCE: 735 case ADD_MANAGED_RESOURCE:
739 if (add_interval(&data->io_db, base, num) != 0) { 736 if (add_interval(&data->io_db, start, size) != 0) {
740 ret = CS_IN_USE; 737 ret = -EBUSY;
741 break; 738 break;
742 } 739 }
743#ifdef CONFIG_PCMCIA_PROBE 740#ifdef CONFIG_PCMCIA_PROBE
744 if (probe_io) 741 if (probe_io)
745 do_io_probe(s, base, num); 742 do_io_probe(s, start, size);
746#endif 743#endif
747 break; 744 break;
748 case REMOVE_MANAGED_RESOURCE: 745 case REMOVE_MANAGED_RESOURCE:
749 sub_interval(&data->io_db, base, num); 746 sub_interval(&data->io_db, start, size);
750 break; 747 break;
751 default: 748 default:
752 ret = CS_UNSUPPORTED_FUNCTION; 749 ret = -EINVAL;
753 break; 750 break;
754 } 751 }
755 up(&rsrc_sem); 752 up(&rsrc_sem);
@@ -760,15 +757,82 @@ static int adjust_io(struct pcmcia_socket *s, adjust_t *adj)
760 757
761static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj) 758static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj)
762{ 759{
760 unsigned long end;
761
763 switch (adj->Resource) { 762 switch (adj->Resource) {
764 case RES_MEMORY_RANGE: 763 case RES_MEMORY_RANGE:
765 return adjust_memory(s, adj); 764 end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
765 return adjust_memory(s, adj->Action, adj->resource.memory.Base, end);
766 case RES_IO_RANGE: 766 case RES_IO_RANGE:
767 return adjust_io(s, adj); 767 end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
768 return adjust_io(s, adj->Action, adj->resource.io.BasePort, end);
768 } 769 }
769 return CS_UNSUPPORTED_FUNCTION; 770 return CS_UNSUPPORTED_FUNCTION;
770} 771}
771 772
773#ifdef CONFIG_PCI
774static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
775{
776 struct resource *res;
777 int i, done = 0;
778
779 if (!s->cb_dev || !s->cb_dev->bus)
780 return -ENODEV;
781
782#if defined(CONFIG_X86) || defined(CONFIG_X86_64)
783 /* If this is the root bus, the risk of hitting
784 * some strange system devices which aren't protected
785 * by either ACPI resource tables or properly requested
786 * resources is too big. Therefore, don't do auto-adding
787 * of resources at the moment.
788 */
789 if (s->cb_dev->bus->number == 0)
790 return -EINVAL;
791#endif
792
793 for (i=0; i < PCI_BUS_NUM_RESOURCES; i++) {
794 res = s->cb_dev->bus->resource[i];
795 if (!res)
796 continue;
797
798 if (res->flags & IORESOURCE_IO) {
799 if (res == &ioport_resource)
800 continue;
801 printk(KERN_INFO "pcmcia: parent PCI bridge I/O window: 0x%lx - 0x%lx\n",
802 res->start, res->end);
803 if (!adjust_io(s, ADD_MANAGED_RESOURCE, res->start, res->end))
804 done |= IORESOURCE_IO;
805
806 }
807
808 if (res->flags & IORESOURCE_MEM) {
809 if (res == &iomem_resource)
810 continue;
811 printk(KERN_INFO "pcmcia: parent PCI bridge Memory window: 0x%lx - 0x%lx\n",
812 res->start, res->end);
813 if (!adjust_memory(s, ADD_MANAGED_RESOURCE, res->start, res->end))
814 done |= IORESOURCE_MEM;
815 }
816 }
817
818 /* if we got at least one of IO, and one of MEM, we can be glad and
819 * activate the PCMCIA subsystem */
820 if (done & (IORESOURCE_MEM | IORESOURCE_IO))
821 s->resource_setup_done = 1;
822
823 return 0;
824}
825
826#else
827
828static inline int nonstatic_autoadd_resources(struct pcmcia_socket *s)
829{
830 return -ENODEV;
831}
832
833#endif
834
835
772static int nonstatic_init(struct pcmcia_socket *s) 836static int nonstatic_init(struct pcmcia_socket *s)
773{ 837{
774 struct socket_data *data; 838 struct socket_data *data;
@@ -783,6 +847,8 @@ static int nonstatic_init(struct pcmcia_socket *s)
783 847
784 s->resource_data = (void *) data; 848 s->resource_data = (void *) data;
785 849
850 nonstatic_autoadd_resources(s);
851
786 return 0; 852 return 0;
787} 853}
788 854
@@ -845,17 +911,16 @@ static ssize_t store_io_db(struct class_device *class_dev, const char *buf, size
845{ 911{
846 struct pcmcia_socket *s = class_get_devdata(class_dev); 912 struct pcmcia_socket *s = class_get_devdata(class_dev);
847 unsigned long start_addr, end_addr; 913 unsigned long start_addr, end_addr;
848 unsigned int add = 1; 914 unsigned int add = ADD_MANAGED_RESOURCE;
849 adjust_t adj;
850 ssize_t ret = 0; 915 ssize_t ret = 0;
851 916
852 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr); 917 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr);
853 if (ret != 2) { 918 if (ret != 2) {
854 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr); 919 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr);
855 add = 0; 920 add = REMOVE_MANAGED_RESOURCE;
856 if (ret != 2) { 921 if (ret != 2) {
857 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr); 922 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr);
858 add = 1; 923 add = ADD_MANAGED_RESOURCE;
859 if (ret != 2) 924 if (ret != 2)
860 return -EINVAL; 925 return -EINVAL;
861 } 926 }
@@ -863,12 +928,9 @@ static ssize_t store_io_db(struct class_device *class_dev, const char *buf, size
863 if (end_addr <= start_addr) 928 if (end_addr <= start_addr)
864 return -EINVAL; 929 return -EINVAL;
865 930
866 adj.Action = add ? ADD_MANAGED_RESOURCE : REMOVE_MANAGED_RESOURCE; 931 ret = adjust_io(s, add, start_addr, end_addr);
867 adj.Resource = RES_IO_RANGE; 932 if (!ret)
868 adj.resource.io.BasePort = start_addr; 933 s->resource_setup_new = 1;
869 adj.resource.io.NumPorts = end_addr - start_addr + 1;
870
871 ret = adjust_io(s, &adj);
872 934
873 return ret ? ret : count; 935 return ret ? ret : count;
874} 936}
@@ -901,17 +963,16 @@ static ssize_t store_mem_db(struct class_device *class_dev, const char *buf, siz
901{ 963{
902 struct pcmcia_socket *s = class_get_devdata(class_dev); 964 struct pcmcia_socket *s = class_get_devdata(class_dev);
903 unsigned long start_addr, end_addr; 965 unsigned long start_addr, end_addr;
904 unsigned int add = 1; 966 unsigned int add = ADD_MANAGED_RESOURCE;
905 adjust_t adj;
906 ssize_t ret = 0; 967 ssize_t ret = 0;
907 968
908 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr); 969 ret = sscanf (buf, "+ 0x%lx - 0x%lx", &start_addr, &end_addr);
909 if (ret != 2) { 970 if (ret != 2) {
910 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr); 971 ret = sscanf (buf, "- 0x%lx - 0x%lx", &start_addr, &end_addr);
911 add = 0; 972 add = REMOVE_MANAGED_RESOURCE;
912 if (ret != 2) { 973 if (ret != 2) {
913 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr); 974 ret = sscanf (buf, "0x%lx - 0x%lx", &start_addr, &end_addr);
914 add = 1; 975 add = ADD_MANAGED_RESOURCE;
915 if (ret != 2) 976 if (ret != 2)
916 return -EINVAL; 977 return -EINVAL;
917 } 978 }
@@ -919,12 +980,9 @@ static ssize_t store_mem_db(struct class_device *class_dev, const char *buf, siz
919 if (end_addr <= start_addr) 980 if (end_addr <= start_addr)
920 return -EINVAL; 981 return -EINVAL;
921 982
922 adj.Action = add ? ADD_MANAGED_RESOURCE : REMOVE_MANAGED_RESOURCE; 983 ret = adjust_memory(s, add, start_addr, end_addr);
923 adj.Resource = RES_MEMORY_RANGE; 984 if (!ret)
924 adj.resource.memory.Base = start_addr; 985 s->resource_setup_new = 1;
925 adj.resource.memory.Size = end_addr - start_addr + 1;
926
927 ret = adjust_memory(s, &adj);
928 986
929 return ret ? ret : count; 987 return ret ? ret : count;
930} 988}
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index f1bb79153021..e98bb3d80e7c 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -34,7 +34,6 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/config.h> 35#include <linux/config.h>
36 36
37#include <pcmcia/version.h>
38#include <pcmcia/cs_types.h> 37#include <pcmcia/cs_types.h>
39#include <pcmcia/cs.h> 38#include <pcmcia/cs.h>
40#include <pcmcia/ss.h> 39#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/soc_common.h b/drivers/pcmcia/soc_common.h
index 700a155fbc78..6f14126889b3 100644
--- a/drivers/pcmcia/soc_common.h
+++ b/drivers/pcmcia/soc_common.h
@@ -11,7 +11,6 @@
11 11
12/* include the world */ 12/* include the world */
13#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
14#include <pcmcia/version.h>
15#include <pcmcia/cs_types.h> 14#include <pcmcia/cs_types.h>
16#include <pcmcia/cs.h> 15#include <pcmcia/cs.h>
17#include <pcmcia/ss.h> 16#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 8eed03938214..1040a6c1a8a4 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -29,7 +29,6 @@
29#include <asm/irq.h> 29#include <asm/irq.h>
30 30
31#define IN_CARD_SERVICES 31#define IN_CARD_SERVICES
32#include <pcmcia/version.h>
33#include <pcmcia/cs_types.h> 32#include <pcmcia/cs_types.h>
34#include <pcmcia/ss.h> 33#include <pcmcia/ss.h>
35#include <pcmcia/cs.h> 34#include <pcmcia/cs.h>
@@ -163,28 +162,164 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
163 return -EINVAL; 162 return -EINVAL;
164 163
165 spin_lock_irqsave(&s->lock, flags); 164 spin_lock_irqsave(&s->lock, flags);
166 if (!s->resource_setup_done) { 165 if (!s->resource_setup_done)
167 s->resource_setup_done = 1; 166 s->resource_setup_done = 1;
168 spin_unlock_irqrestore(&s->lock, flags); 167 spin_unlock_irqrestore(&s->lock, flags);
168
169 down(&s->skt_sem);
170 if ((s->callback) &&
171 (s->state & SOCKET_PRESENT) &&
172 !(s->state & SOCKET_CARDBUS)) {
173 if (try_module_get(s->callback->owner)) {
174 s->callback->requery(s);
175 module_put(s->callback->owner);
176 }
177 }
178 up(&s->skt_sem);
179
180 return count;
181}
182static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
183
184
185static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count)
186{
187 tuple_t tuple;
188 int status, i;
189 loff_t pointer = 0;
190 ssize_t ret = 0;
191 u_char *tuplebuffer;
192 u_char *tempbuffer;
193
194 tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
195 if (!tuplebuffer)
196 return -ENOMEM;
197
198 tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
199 if (!tempbuffer) {
200 ret = -ENOMEM;
201 goto free_tuple;
202 }
203
204 memset(&tuple, 0, sizeof(tuple_t));
205
206 tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
207 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
208 tuple.TupleOffset = 0;
209
210 status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple);
211 while (!status) {
212 tuple.TupleData = tuplebuffer;
213 tuple.TupleDataMax = 255;
214 memset(tuplebuffer, 0, sizeof(u_char) * 255);
169 215
216 status = pccard_get_tuple_data(s, &tuple);
217 if (status)
218 break;
219
220 if (off < (pointer + 2 + tuple.TupleDataLen)) {
221 tempbuffer[0] = tuple.TupleCode & 0xff;
222 tempbuffer[1] = tuple.TupleLink & 0xff;
223 for (i = 0; i < tuple.TupleDataLen; i++)
224 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
225
226 for (i = 0; i < (2 + tuple.TupleDataLen); i++) {
227 if (((i + pointer) >= off) &&
228 (i + pointer) < (off + count)) {
229 buf[ret] = tempbuffer[i];
230 ret++;
231 }
232 }
233 }
234
235 pointer += 2 + tuple.TupleDataLen;
236
237 if (pointer >= (off + count))
238 break;
239
240 if (tuple.TupleCode == CISTPL_END)
241 break;
242 status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple);
243 }
244
245 kfree(tempbuffer);
246 free_tuple:
247 kfree(tuplebuffer);
248
249 return (ret);
250}
251
252static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
253{
254 unsigned int size = 0x200;
255
256 if (off >= size)
257 count = 0;
258 else {
259 struct pcmcia_socket *s;
260 cisinfo_t cisinfo;
261
262 if (off + count > size)
263 count = size - off;
264
265 s = to_socket(container_of(kobj, struct class_device, kobj));
266
267 if (!(s->state & SOCKET_PRESENT))
268 return -ENODEV;
269 if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo))
270 return -EIO;
271 if (!cisinfo.Chains)
272 return -ENODATA;
273
274 count = pccard_extract_cis(s, buf, off, count);
275 }
276
277 return (count);
278}
279
280static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, size_t count)
281{
282 struct pcmcia_socket *s = to_socket(container_of(kobj, struct class_device, kobj));
283 cisdump_t *cis;
284 ssize_t ret = count;
285
286 if (off)
287 return -EINVAL;
288
289 if (count >= 0x200)
290 return -EINVAL;
291
292 if (!(s->state & SOCKET_PRESENT))
293 return -ENODEV;
294
295 cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL);
296 if (!cis)
297 return -ENOMEM;
298 memset(cis, 0, sizeof(cisdump_t));
299
300 cis->Length = count + 1;
301 memcpy(cis->Data, buf, count);
302
303 if (pcmcia_replace_cis(s, cis))
304 ret = -EIO;
305
306 kfree(cis);
307
308 if (!ret) {
170 down(&s->skt_sem); 309 down(&s->skt_sem);
171 if ((s->callback) && 310 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
172 (s->state & SOCKET_PRESENT) &&
173 !(s->state & SOCKET_CARDBUS)) { 311 !(s->state & SOCKET_CARDBUS)) {
174 if (try_module_get(s->callback->owner)) { 312 if (try_module_get(s->callback->owner)) {
175 s->callback->resources_done(s); 313 s->callback->requery(s);
176 module_put(s->callback->owner); 314 module_put(s->callback->owner);
177 } 315 }
178 } 316 }
179 up(&s->skt_sem); 317 up(&s->skt_sem);
180
181 return count;
182 } 318 }
183 spin_unlock_irqrestore(&s->lock, flags);
184 319
185 return count; 320
321 return (ret);
186} 322}
187static CLASS_DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
188 323
189 324
190static struct class_device_attribute *pccard_socket_attributes[] = { 325static struct class_device_attribute *pccard_socket_attributes[] = {
@@ -199,6 +334,13 @@ static struct class_device_attribute *pccard_socket_attributes[] = {
199 NULL, 334 NULL,
200}; 335};
201 336
337static struct bin_attribute pccard_cis_attr = {
338 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR, .owner = THIS_MODULE},
339 .size = 0x200,
340 .read = pccard_show_cis,
341 .write = pccard_store_cis,
342};
343
202static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) 344static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
203{ 345{
204 struct class_device_attribute **attr; 346 struct class_device_attribute **attr;
@@ -209,6 +351,8 @@ static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
209 if (ret) 351 if (ret)
210 break; 352 break;
211 } 353 }
354 if (!ret)
355 ret = sysfs_create_bin_file(&class_dev->kobj, &pccard_cis_attr);
212 356
213 return ret; 357 return ret;
214} 358}
@@ -217,6 +361,7 @@ static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev)
217{ 361{
218 struct class_device_attribute **attr; 362 struct class_device_attribute **attr;
219 363
364 sysfs_remove_bin_file(&class_dev->kobj, &pccard_cis_attr);
220 for (attr = pccard_socket_attributes; *attr; attr++) 365 for (attr = pccard_socket_attributes; *attr; attr++)
221 class_device_remove_file(class_dev, *attr); 366 class_device_remove_file(class_dev, *attr);
222} 367}
diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
index aacbbb5f055d..d5a61eae6119 100644
--- a/drivers/pcmcia/tcic.c
+++ b/drivers/pcmcia/tcic.c
@@ -50,7 +50,6 @@
50#include <asm/io.h> 50#include <asm/io.h>
51#include <asm/system.h> 51#include <asm/system.h>
52 52
53#include <pcmcia/version.h>
54#include <pcmcia/cs_types.h> 53#include <pcmcia/cs_types.h>
55#include <pcmcia/cs.h> 54#include <pcmcia/cs.h>
56#include <pcmcia/ss.h> 55#include <pcmcia/ss.h>
diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h
index c7ba99871aca..fbe233e19ceb 100644
--- a/drivers/pcmcia/ti113x.h
+++ b/drivers/pcmcia/ti113x.h
@@ -154,8 +154,6 @@
154#define ENE_TEST_C9 0xc9 /* 8bit */ 154#define ENE_TEST_C9 0xc9 /* 8bit */
155#define ENE_TEST_C9_TLTENABLE 0x02 155#define ENE_TEST_C9_TLTENABLE 0x02
156 156
157#ifdef CONFIG_CARDBUS
158
159/* 157/*
160 * Texas Instruments CardBus controller overrides. 158 * Texas Instruments CardBus controller overrides.
161 */ 159 */
@@ -843,7 +841,5 @@ static int ti1250_override(struct yenta_socket *socket)
843 return ti12xx_override(socket); 841 return ti12xx_override(socket);
844} 842}
845 843
846#endif /* CONFIG_CARDBUS */
847
848#endif /* _LINUX_TI113X_H */ 844#endif /* _LINUX_TI113X_H */
849 845
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index bee05362fd24..6837491f021c 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -18,7 +18,6 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include <pcmcia/version.h>
22#include <pcmcia/cs_types.h> 21#include <pcmcia/cs_types.h>
23#include <pcmcia/ss.h> 22#include <pcmcia/ss.h>
24#include <pcmcia/cs.h> 23#include <pcmcia/cs.h>
@@ -528,60 +527,29 @@ static int yenta_sock_suspend(struct pcmcia_socket *sock)
528 * Use an adaptive allocation for the memory resource, 527 * Use an adaptive allocation for the memory resource,
529 * sometimes the memory behind pci bridges is limited: 528 * sometimes the memory behind pci bridges is limited:
530 * 1/8 of the size of the io window of the parent. 529 * 1/8 of the size of the io window of the parent.
531 * max 4 MB, min 16 kB. 530 * max 4 MB, min 16 kB. We try very hard to not get below
531 * the "ACC" values, though.
532 */ 532 */
533#define BRIDGE_MEM_MAX 4*1024*1024 533#define BRIDGE_MEM_MAX 4*1024*1024
534#define BRIDGE_MEM_ACC 128*1024
534#define BRIDGE_MEM_MIN 16*1024 535#define BRIDGE_MEM_MIN 16*1024
535 536
536#define BRIDGE_IO_MAX 256 537#define BRIDGE_IO_MAX 512
538#define BRIDGE_IO_ACC 256
537#define BRIDGE_IO_MIN 32 539#define BRIDGE_IO_MIN 32
538 540
539#ifndef PCIBIOS_MIN_CARDBUS_IO 541#ifndef PCIBIOS_MIN_CARDBUS_IO
540#define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO 542#define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO
541#endif 543#endif
542 544
543static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type) 545static int yenta_search_one_res(struct resource *root, struct resource *res,
546 u32 min)
544{ 547{
545 struct pci_bus *bus; 548 u32 align, size, start, end;
546 struct resource *root, *res;
547 u32 start, end;
548 u32 align, size, min;
549 unsigned offset;
550 unsigned mask;
551
552 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
553 mask = ~0xfff;
554 if (type & IORESOURCE_IO)
555 mask = ~3;
556
557 offset = 0x1c + 8*nr;
558 bus = socket->dev->subordinate;
559 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
560 res->name = bus->name;
561 res->flags = type;
562 res->start = 0;
563 res->end = 0;
564 root = pci_find_parent_resource(socket->dev, res);
565
566 if (!root)
567 return;
568 549
569 start = config_readl(socket, offset) & mask; 550 if (res->flags & IORESOURCE_IO) {
570 end = config_readl(socket, offset+4) | ~mask;
571 if (start && end > start && !override_bios) {
572 res->start = start;
573 res->end = end;
574 if (request_resource(root, res) == 0)
575 return;
576 printk(KERN_INFO "yenta %s: Preassigned resource %d busy, reconfiguring...\n",
577 pci_name(socket->dev), nr);
578 res->start = res->end = 0;
579 }
580
581 if (type & IORESOURCE_IO) {
582 align = 1024; 551 align = 1024;
583 size = BRIDGE_IO_MAX; 552 size = BRIDGE_IO_MAX;
584 min = BRIDGE_IO_MIN;
585 start = PCIBIOS_MIN_CARDBUS_IO; 553 start = PCIBIOS_MIN_CARDBUS_IO;
586 end = ~0U; 554 end = ~0U;
587 } else { 555 } else {
@@ -596,26 +564,107 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
596 i++; 564 i++;
597 size = 1 << i; 565 size = 1 << i;
598 } 566 }
599 if (size < BRIDGE_MEM_MIN) 567 if (size < min)
600 size = BRIDGE_MEM_MIN; 568 size = min;
601 min = BRIDGE_MEM_MIN;
602 align = size; 569 align = size;
603 start = PCIBIOS_MIN_MEM; 570 start = PCIBIOS_MIN_MEM;
604 end = ~0U; 571 end = ~0U;
605 } 572 }
606 573
607 do { 574 do {
608 if (allocate_resource(root, res, size, start, end, align, NULL, NULL)==0) { 575 if (allocate_resource(root, res, size, start, end, align,
609 config_writel(socket, offset, res->start); 576 NULL, NULL)==0) {
610 config_writel(socket, offset+4, res->end); 577 return 1;
611 return;
612 } 578 }
613 size = size/2; 579 size = size/2;
614 align = size; 580 align = size;
615 } while (size >= min); 581 } while (size >= min);
582
583 return 0;
584}
585
586
587static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
588 u32 min)
589{
590 int i;
591 for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
592 struct resource * root = socket->dev->bus->resource[i];
593 if (!root)
594 continue;
595
596 if ((res->flags ^ root->flags) &
597 (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH))
598 continue; /* Wrong type */
599
600 if (yenta_search_one_res(root, res, min))
601 return 1;
602 }
603 return 0;
604}
605
606static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end)
607{
608 struct pci_bus *bus;
609 struct resource *root, *res;
610 u32 start, end;
611 unsigned mask;
612
613 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
614 /* Already allocated? */
615 if (res->parent)
616 return;
617
618 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
619 mask = ~0xfff;
620 if (type & IORESOURCE_IO)
621 mask = ~3;
622
623 bus = socket->dev->subordinate;
624 res->name = bus->name;
625 res->flags = type;
626
627 start = config_readl(socket, addr_start) & mask;
628 end = config_readl(socket, addr_end) | ~mask;
629 if (start && end > start && !override_bios) {
630 res->start = start;
631 res->end = end;
632 root = pci_find_parent_resource(socket->dev, res);
633 if (root && (request_resource(root, res) == 0))
634 return;
635 printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n",
636 pci_name(socket->dev), nr);
637 }
638
639 if (type & IORESOURCE_IO) {
640 if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) ||
641 (yenta_search_res(socket, res, BRIDGE_IO_ACC)) ||
642 (yenta_search_res(socket, res, BRIDGE_IO_MIN))) {
643 config_writel(socket, addr_start, res->start);
644 config_writel(socket, addr_end, res->end);
645 }
646 } else {
647 if (type & IORESOURCE_PREFETCH) {
648 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
649 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
650 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
651 config_writel(socket, addr_start, res->start);
652 config_writel(socket, addr_end, res->end);
653 }
654 /* Approximating prefetchable by non-prefetchable */
655 res->flags = IORESOURCE_MEM;
656 }
657 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
658 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
659 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
660 config_writel(socket, addr_start, res->start);
661 config_writel(socket, addr_end, res->end);
662 }
663 }
664
616 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n", 665 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n",
617 pci_name(socket->dev), type); 666 pci_name(socket->dev), type);
618 res->start = res->end = 0; 667 res->start = res->end = res->flags = 0;
619} 668}
620 669
621/* 670/*
@@ -623,10 +672,14 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
623 */ 672 */
624static void yenta_allocate_resources(struct yenta_socket *socket) 673static void yenta_allocate_resources(struct yenta_socket *socket)
625{ 674{
626 yenta_allocate_res(socket, 0, IORESOURCE_MEM|IORESOURCE_PREFETCH); 675 yenta_allocate_res(socket, 0, IORESOURCE_IO,
627 yenta_allocate_res(socket, 1, IORESOURCE_MEM); 676 PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0);
628 yenta_allocate_res(socket, 2, IORESOURCE_IO); 677 yenta_allocate_res(socket, 1, IORESOURCE_IO,
629 yenta_allocate_res(socket, 3, IORESOURCE_IO); /* PCI isn't clever enough to use this one yet */ 678 PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1);
679 yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH,
680 PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0);
681 yenta_allocate_res(socket, 3, IORESOURCE_MEM,
682 PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1);
630} 683}
631 684
632 685
@@ -865,14 +918,11 @@ static int yenta_probe_cb_irq(struct yenta_socket *socket)
865 */ 918 */
866static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_irq_mask) 919static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_irq_mask)
867{ 920{
868 socket->socket.features |= SS_CAP_PAGE_REGS | SS_CAP_PCCARD | SS_CAP_CARDBUS;
869 socket->socket.map_size = 0x1000;
870 socket->socket.pci_irq = socket->cb_irq; 921 socket->socket.pci_irq = socket->cb_irq;
871 if (isa_probe) 922 if (isa_probe)
872 socket->socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask); 923 socket->socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask);
873 else 924 else
874 socket->socket.irq_mask = 0; 925 socket->socket.irq_mask = 0;
875 socket->socket.cb_dev = socket->dev;
876 926
877 printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n", 927 printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n",
878 socket->socket.irq_mask, socket->cb_irq); 928 socket->socket.irq_mask, socket->cb_irq);
@@ -938,6 +988,9 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
938 socket->socket.dev.dev = &dev->dev; 988 socket->socket.dev.dev = &dev->dev;
939 socket->socket.driver_data = socket; 989 socket->socket.driver_data = socket;
940 socket->socket.owner = THIS_MODULE; 990 socket->socket.owner = THIS_MODULE;
991 socket->socket.features = SS_CAP_PAGE_REGS | SS_CAP_PCCARD;
992 socket->socket.map_size = 0x1000;
993 socket->socket.cb_dev = dev;
941 994
942 /* prepare struct yenta_socket */ 995 /* prepare struct yenta_socket */
943 socket->dev = dev; 996 socket->dev = dev;
@@ -1008,6 +1061,10 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1008 socket->poll_timer.data = (unsigned long)socket; 1061 socket->poll_timer.data = (unsigned long)socket;
1009 socket->poll_timer.expires = jiffies + HZ; 1062 socket->poll_timer.expires = jiffies + HZ;
1010 add_timer(&socket->poll_timer); 1063 add_timer(&socket->poll_timer);
1064 printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n"
1065 KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n");
1066 } else {
1067 socket->socket.features |= SS_CAP_CARDBUS;
1011 } 1068 }
1012 1069
1013 /* Figure out what the dang thing can do for the PCMCIA layer... */ 1070 /* Figure out what the dang thing can do for the PCMCIA layer... */
@@ -1048,6 +1105,7 @@ static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state)
1048 pci_save_state(dev); 1105 pci_save_state(dev);
1049 pci_read_config_dword(dev, 16*4, &socket->saved_state[0]); 1106 pci_read_config_dword(dev, 16*4, &socket->saved_state[0]);
1050 pci_read_config_dword(dev, 17*4, &socket->saved_state[1]); 1107 pci_read_config_dword(dev, 17*4, &socket->saved_state[1]);
1108 pci_disable_device(dev);
1051 1109
1052 /* 1110 /*
1053 * Some laptops (IBM T22) do not like us putting the Cardbus 1111 * Some laptops (IBM T22) do not like us putting the Cardbus
@@ -1071,6 +1129,8 @@ static int yenta_dev_resume (struct pci_dev *dev)
1071 pci_restore_state(dev); 1129 pci_restore_state(dev);
1072 pci_write_config_dword(dev, 16*4, socket->saved_state[0]); 1130 pci_write_config_dword(dev, 16*4, socket->saved_state[0]);
1073 pci_write_config_dword(dev, 17*4, socket->saved_state[1]); 1131 pci_write_config_dword(dev, 17*4, socket->saved_state[1]);
1132 pci_enable_device(dev);
1133 pci_set_master(dev);
1074 1134
1075 if (socket->type && socket->type->restore_state) 1135 if (socket->type && socket->type->restore_state)
1076 socket->type->restore_state(socket); 1136 socket->type->restore_state(socket);
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index dd61e09029b1..75575f6c349c 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -160,7 +160,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
160 acpi_register_gsi(res->data.irq.interrupts[0], 160 acpi_register_gsi(res->data.irq.interrupts[0],
161 res->data.irq.edge_level, 161 res->data.irq.edge_level,
162 res->data.irq.active_high_low)); 162 res->data.irq.active_high_low));
163 pcibios_penalize_isa_irq(res->data.irq.interrupts[0]); 163 pcibios_penalize_isa_irq(res->data.irq.interrupts[0], 1);
164 } 164 }
165 break; 165 break;
166 166
@@ -171,7 +171,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
171 acpi_register_gsi(res->data.extended_irq.interrupts[0], 171 acpi_register_gsi(res->data.extended_irq.interrupts[0],
172 res->data.extended_irq.edge_level, 172 res->data.extended_irq.edge_level,
173 res->data.extended_irq.active_high_low)); 173 res->data.extended_irq.active_high_low));
174 pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0]); 174 pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0], 1);
175 } 175 }
176 break; 176 break;
177 case ACPI_RSTYPE_DMA: 177 case ACPI_RSTYPE_DMA:
@@ -444,6 +444,7 @@ pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
444 444
445struct acpipnp_parse_option_s { 445struct acpipnp_parse_option_s {
446 struct pnp_option *option; 446 struct pnp_option *option;
447 struct pnp_option *option_independent;
447 struct pnp_dev *dev; 448 struct pnp_dev *dev;
448}; 449};
449 450
@@ -507,7 +508,14 @@ static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
507 parse_data->option = option; 508 parse_data->option = option;
508 break; 509 break;
509 case ACPI_RSTYPE_END_DPF: 510 case ACPI_RSTYPE_END_DPF:
510 return AE_CTRL_TERMINATE; 511 /*only one EndDependentFn is allowed*/
512 if (!parse_data->option_independent) {
513 pnp_warn("PnPACPI: more than one EndDependentFn");
514 return AE_ERROR;
515 }
516 parse_data->option = parse_data->option_independent;
517 parse_data->option_independent = NULL;
518 break;
511 default: 519 default:
512 pnp_warn("PnPACPI: unknown resource type %d", res->id); 520 pnp_warn("PnPACPI: unknown resource type %d", res->id);
513 return AE_ERROR; 521 return AE_ERROR;
@@ -525,6 +533,7 @@ acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
525 parse_data.option = pnp_register_independent_option(dev); 533 parse_data.option = pnp_register_independent_option(dev);
526 if (!parse_data.option) 534 if (!parse_data.option)
527 return AE_ERROR; 535 return AE_ERROR;
536 parse_data.option_independent = parse_data.option;
528 parse_data.dev = dev; 537 parse_data.dev = dev;
529 status = acpi_walk_resources(handle, METHOD_NAME__PRS, 538 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
530 pnpacpi_option_resource, &parse_data); 539 pnpacpi_option_resource, &parse_data);
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 79bce7b75740..9001b6f0204d 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -64,7 +64,7 @@ pnpbios_parse_allocated_irqresource(struct pnp_resource_table * res, int irq)
64 } 64 }
65 res->irq_resource[i].start = 65 res->irq_resource[i].start =
66 res->irq_resource[i].end = (unsigned long) irq; 66 res->irq_resource[i].end = (unsigned long) irq;
67 pcibios_penalize_isa_irq(irq); 67 pcibios_penalize_isa_irq(irq, 1);
68 } 68 }
69} 69}
70 70
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 2d1322dd7e19..887ad8939349 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -102,7 +102,7 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
102 102
103 for (i = 0; i < 16; i++) 103 for (i = 0; i < 16; i++)
104 if (test_bit(i, data->map)) 104 if (test_bit(i, data->map))
105 pcibios_penalize_isa_irq(i); 105 pcibios_penalize_isa_irq(i, 0);
106 } 106 }
107#endif 107#endif
108 return 0; 108 return 0;
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 60440dbe3a27..24c0af49c25c 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -428,7 +428,7 @@ claw_pack_skb(struct claw_privbk *privptr)
428 new_skb = NULL; /* assume no dice */ 428 new_skb = NULL; /* assume no dice */
429 pkt_cnt = 0; 429 pkt_cnt = 0;
430 CLAW_DBF_TEXT(4,trace,"PackSKBe"); 430 CLAW_DBF_TEXT(4,trace,"PackSKBe");
431 if (skb_queue_len(&p_ch->collect_queue) > 0) { 431 if (!skb_queue_empty(&p_ch->collect_queue)) {
432 /* some data */ 432 /* some data */
433 held_skb = skb_dequeue(&p_ch->collect_queue); 433 held_skb = skb_dequeue(&p_ch->collect_queue);
434 if (p_env->packing != DO_PACKED) 434 if (p_env->packing != DO_PACKED)
@@ -1254,7 +1254,7 @@ claw_write_next ( struct chbk * p_ch )
1254 privptr = (struct claw_privbk *) dev->priv; 1254 privptr = (struct claw_privbk *) dev->priv;
1255 claw_free_wrt_buf( dev ); 1255 claw_free_wrt_buf( dev );
1256 if ((privptr->write_free_count > 0) && 1256 if ((privptr->write_free_count > 0) &&
1257 (skb_queue_len(&p_ch->collect_queue) > 0)) { 1257 !skb_queue_empty(&p_ch->collect_queue)) {
1258 pk_skb = claw_pack_skb(privptr); 1258 pk_skb = claw_pack_skb(privptr);
1259 while (pk_skb != NULL) { 1259 while (pk_skb != NULL) {
1260 rc = claw_hw_tx( pk_skb, dev,1); 1260 rc = claw_hw_tx( pk_skb, dev,1);
diff --git a/drivers/s390/net/ctctty.c b/drivers/s390/net/ctctty.c
index 3080393e823d..968f2c113efe 100644
--- a/drivers/s390/net/ctctty.c
+++ b/drivers/s390/net/ctctty.c
@@ -156,7 +156,7 @@ ctc_tty_readmodem(ctc_tty_info *info)
156 skb_queue_head(&info->rx_queue, skb); 156 skb_queue_head(&info->rx_queue, skb);
157 else { 157 else {
158 kfree_skb(skb); 158 kfree_skb(skb);
159 ret = skb_queue_len(&info->rx_queue); 159 ret = !skb_queue_empty(&info->rx_queue);
160 } 160 }
161 } 161 }
162 } 162 }
@@ -530,7 +530,7 @@ ctc_tty_write(struct tty_struct *tty, const u_char * buf, int count)
530 total += c; 530 total += c;
531 count -= c; 531 count -= c;
532 } 532 }
533 if (skb_queue_len(&info->tx_queue)) { 533 if (!skb_queue_empty(&info->tx_queue)) {
534 info->lsr &= ~UART_LSR_TEMT; 534 info->lsr &= ~UART_LSR_TEMT;
535 tasklet_schedule(&info->tasklet); 535 tasklet_schedule(&info->tasklet);
536 } 536 }
@@ -594,7 +594,7 @@ ctc_tty_flush_chars(struct tty_struct *tty)
594 return; 594 return;
595 if (ctc_tty_paranoia_check(info, tty->name, "ctc_tty_flush_chars")) 595 if (ctc_tty_paranoia_check(info, tty->name, "ctc_tty_flush_chars"))
596 return; 596 return;
597 if (tty->stopped || tty->hw_stopped || (!skb_queue_len(&info->tx_queue))) 597 if (tty->stopped || tty->hw_stopped || skb_queue_empty(&info->tx_queue))
598 return; 598 return;
599 tasklet_schedule(&info->tasklet); 599 tasklet_schedule(&info->tasklet);
600} 600}
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 3cb88c770037..8f4d2999af8e 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -2210,7 +2210,7 @@ no_mem:
2210 return NULL; 2210 return NULL;
2211} 2211}
2212 2212
2213static inline unsigned short 2213static inline __be16
2214qeth_type_trans(struct sk_buff *skb, struct net_device *dev) 2214qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2215{ 2215{
2216 struct qeth_card *card; 2216 struct qeth_card *card;
diff --git a/drivers/sbus/char/Kconfig b/drivers/sbus/char/Kconfig
index 90d8ef1f0bcc..a41778a490d6 100644
--- a/drivers/sbus/char/Kconfig
+++ b/drivers/sbus/char/Kconfig
@@ -71,20 +71,6 @@ config SUN_JSFLASH
71 71
72# XXX Why don't we do "source drivers/char/Config.in" somewhere? 72# XXX Why don't we do "source drivers/char/Config.in" somewhere?
73# no shit 73# no shit
74config APM_RTC_IS_GMT
75 bool
76 depends on EXPERIMENTAL && SPARC32 && PCI
77 default y
78 help
79 Say Y here if your RTC (Real Time Clock a.k.a. hardware clock)
80 stores the time in GMT (Greenwich Mean Time). Say N if your RTC
81 stores localtime.
82
83 It is in fact recommended to store GMT in your RTC, because then you
84 don't have to worry about daylight savings time changes. The only
85 reason not to use GMT in your RTC is if you also run a broken OS
86 that doesn't understand GMT.
87
88config RTC 74config RTC
89 tristate "PC-style Real Time Clock Support" 75 tristate "PC-style Real Time Clock Support"
90 depends on PCI && EXPERIMENTAL && SPARC32 76 depends on PCI && EXPERIMENTAL && SPARC32
diff --git a/drivers/sbus/char/aurora.c b/drivers/sbus/char/aurora.c
index 650d5e924f47..d96cc47de566 100644
--- a/drivers/sbus/char/aurora.c
+++ b/drivers/sbus/char/aurora.c
@@ -1515,8 +1515,7 @@ static void aurora_close(struct tty_struct * tty, struct file * filp)
1515 */ 1515 */
1516 timeout = jiffies+HZ; 1516 timeout = jiffies+HZ;
1517 while(port->SRER & SRER_TXEMPTY) { 1517 while(port->SRER & SRER_TXEMPTY) {
1518 current->state = TASK_INTERRUPTIBLE; 1518 msleep_interruptible(jiffies_to_msecs(port->timeout));
1519 schedule_timeout(port->timeout);
1520 if (time_after(jiffies, timeout)) 1519 if (time_after(jiffies, timeout))
1521 break; 1520 break;
1522 } 1521 }
@@ -1533,8 +1532,7 @@ static void aurora_close(struct tty_struct * tty, struct file * filp)
1533 port->tty = 0; 1532 port->tty = 0;
1534 if (port->blocked_open) { 1533 if (port->blocked_open) {
1535 if (port->close_delay) { 1534 if (port->close_delay) {
1536 current->state = TASK_INTERRUPTIBLE; 1535 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1537 schedule_timeout(port->close_delay);
1538 } 1536 }
1539 wake_up_interruptible(&port->open_wait); 1537 wake_up_interruptible(&port->open_wait);
1540 } 1538 }
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index d5259f7fee6d..b8a2c7353b0a 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -4,13 +4,14 @@
4 * Copyright (C) 2001 David S. Miller (davem@redhat.com) 4 * Copyright (C) 2001 David S. Miller (davem@redhat.com)
5 */ 5 */
6 6
7#define __KERNEL_SYSCALLS__
8
7#include <linux/kernel.h> 9#include <linux/kernel.h>
8#include <linux/sched.h> 10#include <linux/sched.h>
9#include <linux/slab.h> 11#include <linux/slab.h>
10#include <linux/delay.h> 12#include <linux/delay.h>
11#include <asm/oplib.h> 13#include <asm/oplib.h>
12#include <asm/ebus.h> 14#include <asm/ebus.h>
13#define __KERNEL_SYSCALLS__
14static int errno; 15static int errno;
15#include <asm/unistd.h> 16#include <asm/unistd.h>
16 17
diff --git a/drivers/sbus/char/bpp.c b/drivers/sbus/char/bpp.c
index 8f0f46907a81..87302fb14885 100644
--- a/drivers/sbus/char/bpp.c
+++ b/drivers/sbus/char/bpp.c
@@ -79,10 +79,6 @@ struct inst {
79 79
80 unsigned char run_length; 80 unsigned char run_length;
81 unsigned char repeat_byte; 81 unsigned char repeat_byte;
82
83 /* These members manage timeouts for programmed delays */
84 wait_queue_head_t wait_queue;
85 struct timer_list timer_list;
86}; 82};
87 83
88static struct inst instances[BPP_NO]; 84static struct inst instances[BPP_NO];
@@ -297,16 +293,10 @@ static unsigned short get_pins(unsigned minor)
297 293
298#endif /* __sparc__ */ 294#endif /* __sparc__ */
299 295
300static void bpp_wake_up(unsigned long val)
301{ wake_up(&instances[val].wait_queue); }
302
303static void snooze(unsigned long snooze_time, unsigned minor) 296static void snooze(unsigned long snooze_time, unsigned minor)
304{ 297{
305 init_timer(&instances[minor].timer_list); 298 set_current_state(TASK_UNINTERRUPTIBLE);
306 instances[minor].timer_list.expires = jiffies + snooze_time + 1; 299 schedule_timeout(snooze_time + 1);
307 instances[minor].timer_list.data = minor;
308 add_timer(&instances[minor].timer_list);
309 sleep_on (&instances[minor].wait_queue);
310} 300}
311 301
312static int wait_for(unsigned short set, unsigned short clr, 302static int wait_for(unsigned short set, unsigned short clr,
@@ -880,11 +870,8 @@ static void probeLptPort(unsigned idx)
880 instances[idx].enhanced = 0; 870 instances[idx].enhanced = 0;
881 instances[idx].direction = 0; 871 instances[idx].direction = 0;
882 instances[idx].mode = COMPATIBILITY; 872 instances[idx].mode = COMPATIBILITY;
883 instances[idx].wait_queue = 0;
884 instances[idx].run_length = 0; 873 instances[idx].run_length = 0;
885 instances[idx].run_flag = 0; 874 instances[idx].run_flag = 0;
886 init_timer(&instances[idx].timer_list);
887 instances[idx].timer_list.function = bpp_wake_up;
888 if (!request_region(lpAddr,3, dev_name)) return; 875 if (!request_region(lpAddr,3, dev_name)) return;
889 876
890 /* 877 /*
@@ -977,11 +964,8 @@ static void probeLptPort(unsigned idx)
977 instances[idx].enhanced = 0; 964 instances[idx].enhanced = 0;
978 instances[idx].direction = 0; 965 instances[idx].direction = 0;
979 instances[idx].mode = COMPATIBILITY; 966 instances[idx].mode = COMPATIBILITY;
980 init_waitqueue_head(&instances[idx].wait_queue);
981 instances[idx].run_length = 0; 967 instances[idx].run_length = 0;
982 instances[idx].run_flag = 0; 968 instances[idx].run_flag = 0;
983 init_timer(&instances[idx].timer_list);
984 instances[idx].timer_list.function = bpp_wake_up;
985 969
986 if (!rp) return; 970 if (!rp) return;
987 971
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index f6ed35b24f43..9a8c572554f5 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -19,6 +19,8 @@
19 * Daniele Bellucci <bellucda@tiscali.it> 19 * Daniele Bellucci <bellucda@tiscali.it>
20 */ 20 */
21 21
22#define __KERNEL_SYSCALLS__
23
22#include <linux/config.h> 24#include <linux/config.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/sched.h> 26#include <linux/sched.h>
@@ -35,7 +37,6 @@
35#include <asm/uaccess.h> 37#include <asm/uaccess.h>
36#include <asm/envctrl.h> 38#include <asm/envctrl.h>
37 39
38#define __KERNEL_SYSCALLS__
39static int errno; 40static int errno;
40#include <asm/unistd.h> 41#include <asm/unistd.h>
41 42
@@ -1007,7 +1008,7 @@ static int kenvctrld(void *__unused)
1007 return -ENODEV; 1008 return -ENODEV;
1008 } 1009 }
1009 1010
1010 poll_interval = 5 * HZ; /* TODO env_mon_interval */ 1011 poll_interval = 5000; /* TODO env_mon_interval */
1011 1012
1012 daemonize("kenvctrld"); 1013 daemonize("kenvctrld");
1013 allow_signal(SIGKILL); 1014 allow_signal(SIGKILL);
@@ -1016,10 +1017,7 @@ static int kenvctrld(void *__unused)
1016 1017
1017 printk(KERN_INFO "envctrl: %s starting...\n", current->comm); 1018 printk(KERN_INFO "envctrl: %s starting...\n", current->comm);
1018 for (;;) { 1019 for (;;) {
1019 current->state = TASK_INTERRUPTIBLE; 1020 if(msleep_interruptible(poll_interval))
1020 schedule_timeout(poll_interval);
1021
1022 if(signal_pending(current))
1023 break; 1021 break;
1024 1022
1025 for (whichcpu = 0; whichcpu < ENVCTRL_MAX_CPU; ++whichcpu) { 1023 for (whichcpu = 0; whichcpu < ENVCTRL_MAX_CPU; ++whichcpu) {
diff --git a/drivers/sbus/char/vfc_i2c.c b/drivers/sbus/char/vfc_i2c.c
index 95e3cebf792c..1faf1e75f71f 100644
--- a/drivers/sbus/char/vfc_i2c.c
+++ b/drivers/sbus/char/vfc_i2c.c
@@ -88,14 +88,16 @@ void vfc_i2c_delay_wakeup(struct vfc_dev *dev)
88 88
89void vfc_i2c_delay_no_busy(struct vfc_dev *dev, unsigned long usecs) 89void vfc_i2c_delay_no_busy(struct vfc_dev *dev, unsigned long usecs)
90{ 90{
91 DEFINE_WAIT(wait);
91 init_timer(&dev->poll_timer); 92 init_timer(&dev->poll_timer);
92 dev->poll_timer.expires = jiffies + 93 dev->poll_timer.expires = jiffies + usecs_to_jiffies(usecs);
93 ((unsigned long)usecs*(HZ))/1000000;
94 dev->poll_timer.data=(unsigned long)dev; 94 dev->poll_timer.data=(unsigned long)dev;
95 dev->poll_timer.function=(void *)(unsigned long)vfc_i2c_delay_wakeup; 95 dev->poll_timer.function=(void *)(unsigned long)vfc_i2c_delay_wakeup;
96 add_timer(&dev->poll_timer); 96 add_timer(&dev->poll_timer);
97 sleep_on(&dev->poll_wait); 97 prepare_to_wait(&dev->poll_wait, &wait, TASK_UNINTERRUPTIBLE);
98 schedule();
98 del_timer(&dev->poll_timer); 99 del_timer(&dev->poll_timer);
100 finish_wait(&dev->poll_wait, &wait);
99} 101}
100 102
101void inline vfc_i2c_delay(struct vfc_dev *dev) 103void inline vfc_i2c_delay(struct vfc_dev *dev)
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 34dbc37a79d4..bc6e4627c7a1 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1916,9 +1916,9 @@ static void __twa_shutdown(TW_Device_Extension *tw_dev)
1916} /* End __twa_shutdown() */ 1916} /* End __twa_shutdown() */
1917 1917
1918/* Wrapper for __twa_shutdown */ 1918/* Wrapper for __twa_shutdown */
1919static void twa_shutdown(struct device *dev) 1919static void twa_shutdown(struct pci_dev *pdev)
1920{ 1920{
1921 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 1921 struct Scsi_Host *host = pci_get_drvdata(pdev);
1922 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; 1922 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
1923 1923
1924 __twa_shutdown(tw_dev); 1924 __twa_shutdown(tw_dev);
@@ -2140,9 +2140,7 @@ static struct pci_driver twa_driver = {
2140 .id_table = twa_pci_tbl, 2140 .id_table = twa_pci_tbl,
2141 .probe = twa_probe, 2141 .probe = twa_probe,
2142 .remove = twa_remove, 2142 .remove = twa_remove,
2143 .driver = { 2143 .shutdown = twa_shutdown
2144 .shutdown = twa_shutdown
2145 }
2146}; 2144};
2147 2145
2148/* This function is called on driver initialization */ 2146/* This function is called on driver initialization */
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index b6dc576da430..973c51fb0fe2 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -2264,9 +2264,9 @@ static void __tw_shutdown(TW_Device_Extension *tw_dev)
2264} /* End __tw_shutdown() */ 2264} /* End __tw_shutdown() */
2265 2265
2266/* Wrapper for __tw_shutdown */ 2266/* Wrapper for __tw_shutdown */
2267static void tw_shutdown(struct device *dev) 2267static void tw_shutdown(struct pci_dev *pdev)
2268{ 2268{
2269 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 2269 struct Scsi_Host *host = pci_get_drvdata(pdev);
2270 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; 2270 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2271 2271
2272 __tw_shutdown(tw_dev); 2272 __tw_shutdown(tw_dev);
@@ -2451,9 +2451,7 @@ static struct pci_driver tw_driver = {
2451 .id_table = tw_pci_tbl, 2451 .id_table = tw_pci_tbl,
2452 .probe = tw_probe, 2452 .probe = tw_probe,
2453 .remove = tw_remove, 2453 .remove = tw_remove,
2454 .driver = { 2454 .shutdown = tw_shutdown,
2455 .shutdown = tw_shutdown
2456 }
2457}; 2455};
2458 2456
2459/* This function is called on driver initialization */ 2457/* This function is called on driver initialization */
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index d005ad77378d..85387099aab2 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -469,7 +469,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
469 goto cleanup; 469 goto cleanup;
470 } 470 }
471 471
472 user_srbcmd = kmalloc(GFP_KERNEL, fibsize); 472 user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
473 if (!user_srbcmd) { 473 if (!user_srbcmd) {
474 dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n")); 474 dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
475 rcode = -ENOMEM; 475 rcode = -ENOMEM;
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 9a547ca9c864..c5623694d10f 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -304,26 +304,19 @@ static int ahci_port_start(struct ata_port *ap)
304 struct device *dev = ap->host_set->dev; 304 struct device *dev = ap->host_set->dev;
305 struct ahci_host_priv *hpriv = ap->host_set->private_data; 305 struct ahci_host_priv *hpriv = ap->host_set->private_data;
306 struct ahci_port_priv *pp; 306 struct ahci_port_priv *pp;
307 int rc;
308 void *mem, *mmio = ap->host_set->mmio_base; 307 void *mem, *mmio = ap->host_set->mmio_base;
309 void *port_mmio = ahci_port_base(mmio, ap->port_no); 308 void *port_mmio = ahci_port_base(mmio, ap->port_no);
310 dma_addr_t mem_dma; 309 dma_addr_t mem_dma;
311 310
312 rc = ata_port_start(ap);
313 if (rc)
314 return rc;
315
316 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 311 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
317 if (!pp) { 312 if (!pp)
318 rc = -ENOMEM; 313 return -ENOMEM;
319 goto err_out;
320 }
321 memset(pp, 0, sizeof(*pp)); 314 memset(pp, 0, sizeof(*pp));
322 315
323 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 316 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL);
324 if (!mem) { 317 if (!mem) {
325 rc = -ENOMEM; 318 kfree(pp);
326 goto err_out_kfree; 319 return -ENOMEM;
327 } 320 }
328 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ); 321 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
329 322
@@ -373,12 +366,6 @@ static int ahci_port_start(struct ata_port *ap)
373 readl(port_mmio + PORT_CMD); /* flush */ 366 readl(port_mmio + PORT_CMD); /* flush */
374 367
375 return 0; 368 return 0;
376
377err_out_kfree:
378 kfree(pp);
379err_out:
380 ata_port_stop(ap);
381 return rc;
382} 369}
383 370
384 371
@@ -404,7 +391,6 @@ static void ahci_port_stop(struct ata_port *ap)
404 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, 391 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
405 pp->cmd_slot, pp->cmd_slot_dma); 392 pp->cmd_slot, pp->cmd_slot_dma);
406 kfree(pp); 393 kfree(pp);
407 ata_port_stop(ap);
408} 394}
409 395
410static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 396static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 80d022625c82..babd48363402 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -6012,7 +6012,7 @@ static int __devinit ipr_probe(struct pci_dev *pdev,
6012 6012
6013/** 6013/**
6014 * ipr_shutdown - Shutdown handler. 6014 * ipr_shutdown - Shutdown handler.
6015 * @dev: device struct 6015 * @pdev: pci device struct
6016 * 6016 *
6017 * This function is invoked upon system shutdown/reboot. It will issue 6017 * This function is invoked upon system shutdown/reboot. It will issue
6018 * an adapter shutdown to the adapter to flush the write cache. 6018 * an adapter shutdown to the adapter to flush the write cache.
@@ -6020,9 +6020,9 @@ static int __devinit ipr_probe(struct pci_dev *pdev,
6020 * Return value: 6020 * Return value:
6021 * none 6021 * none
6022 **/ 6022 **/
6023static void ipr_shutdown(struct device *dev) 6023static void ipr_shutdown(struct pci_dev *pdev)
6024{ 6024{
6025 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(to_pci_dev(dev)); 6025 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6026 unsigned long lock_flags = 0; 6026 unsigned long lock_flags = 0;
6027 6027
6028 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 6028 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -6068,9 +6068,7 @@ static struct pci_driver ipr_driver = {
6068 .id_table = ipr_pci_table, 6068 .id_table = ipr_pci_table,
6069 .probe = ipr_probe, 6069 .probe = ipr_probe,
6070 .remove = ipr_remove, 6070 .remove = ipr_remove,
6071 .driver = { 6071 .shutdown = ipr_shutdown,
6072 .shutdown = ipr_shutdown,
6073 },
6074}; 6072};
6075 6073
6076/** 6074/**
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index fe1c72981f5a..73b1f72b7e43 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1408,7 +1408,9 @@ void __sata_phy_reset(struct ata_port *ap)
1408 if (ap->flags & ATA_FLAG_SATA_RESET) { 1408 if (ap->flags & ATA_FLAG_SATA_RESET) {
1409 /* issue phy wake/reset */ 1409 /* issue phy wake/reset */
1410 scr_write_flush(ap, SCR_CONTROL, 0x301); 1410 scr_write_flush(ap, SCR_CONTROL, 0x301);
1411 udelay(400); /* FIXME: a guess */ 1411 /* Couldn't find anything in SATA I/II specs, but
1412 * AHCI-1.1 10.4.2 says at least 1 ms. */
1413 mdelay(1);
1412 } 1414 }
1413 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */ 1415 scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */
1414 1416
@@ -1920,6 +1922,7 @@ static const char * ata_dma_blacklist [] = {
1920 "HITACHI CDR-8335", 1922 "HITACHI CDR-8335",
1921 "HITACHI CDR-8435", 1923 "HITACHI CDR-8435",
1922 "Toshiba CD-ROM XM-6202B", 1924 "Toshiba CD-ROM XM-6202B",
1925 "TOSHIBA CD-ROM XM-1702BC",
1923 "CD-532E-A", 1926 "CD-532E-A",
1924 "E-IDE CD-ROM CR-840", 1927 "E-IDE CD-ROM CR-840",
1925 "CD-ROM Drive/F5A", 1928 "CD-ROM Drive/F5A",
@@ -1927,7 +1930,6 @@ static const char * ata_dma_blacklist [] = {
1927 "SAMSUNG CD-ROM SC-148C", 1930 "SAMSUNG CD-ROM SC-148C",
1928 "SAMSUNG CD-ROM SC", 1931 "SAMSUNG CD-ROM SC",
1929 "SanDisk SDP3B-64", 1932 "SanDisk SDP3B-64",
1930 "SAMSUNG CD-ROM SN-124",
1931 "ATAPI CD-ROM DRIVE 40X MAXIMUM", 1933 "ATAPI CD-ROM DRIVE 40X MAXIMUM",
1932 "_NEC DV5800A", 1934 "_NEC DV5800A",
1933}; 1935};
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 7a4adc4c8f09..794fb559efb0 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -1176,8 +1176,12 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf,
1176 n_sectors = ata_id_u32(args->id, 60); 1176 n_sectors = ata_id_u32(args->id, 60);
1177 n_sectors--; /* ATA TotalUserSectors - 1 */ 1177 n_sectors--; /* ATA TotalUserSectors - 1 */
1178 1178
1179 tmp = n_sectors; /* note: truncates, if lba48 */
1180 if (args->cmd->cmnd[0] == READ_CAPACITY) { 1179 if (args->cmd->cmnd[0] == READ_CAPACITY) {
1180 if( n_sectors >= 0xffffffffULL )
1181 tmp = 0xffffffff ; /* Return max count on overflow */
1182 else
1183 tmp = n_sectors ;
1184
1181 /* sector count, 32-bit */ 1185 /* sector count, 32-bit */
1182 rbuf[0] = tmp >> (8 * 3); 1186 rbuf[0] = tmp >> (8 * 3);
1183 rbuf[1] = tmp >> (8 * 2); 1187 rbuf[1] = tmp >> (8 * 2);
@@ -1191,10 +1195,12 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf,
1191 1195
1192 } else { 1196 } else {
1193 /* sector count, 64-bit */ 1197 /* sector count, 64-bit */
1194 rbuf[2] = n_sectors >> (8 * 7); 1198 tmp = n_sectors >> (8 * 4);
1195 rbuf[3] = n_sectors >> (8 * 6); 1199 rbuf[2] = tmp >> (8 * 3);
1196 rbuf[4] = n_sectors >> (8 * 5); 1200 rbuf[3] = tmp >> (8 * 2);
1197 rbuf[5] = n_sectors >> (8 * 4); 1201 rbuf[4] = tmp >> (8 * 1);
1202 rbuf[5] = tmp;
1203 tmp = n_sectors;
1198 rbuf[6] = tmp >> (8 * 3); 1204 rbuf[6] = tmp >> (8 * 3);
1199 rbuf[7] = tmp >> (8 * 2); 1205 rbuf[7] = tmp >> (8 * 2);
1200 rbuf[8] = tmp >> (8 * 1); 1206 rbuf[8] = tmp >> (8 * 1);
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index edd47d1f0b17..932dcf0366eb 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -424,7 +424,7 @@ static struct scsi_host_template mac53c94_template = {
424 .use_clustering = DISABLE_CLUSTERING, 424 .use_clustering = DISABLE_CLUSTERING,
425}; 425};
426 426
427static int mac53c94_probe(struct macio_dev *mdev, const struct of_match *match) 427static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *match)
428{ 428{
429 struct device_node *node = macio_get_of_node(mdev); 429 struct device_node *node = macio_get_of_node(mdev);
430 struct pci_dev *pdev = macio_get_pci_dev(mdev); 430 struct pci_dev *pdev = macio_get_pci_dev(mdev);
@@ -544,15 +544,14 @@ static int mac53c94_remove(struct macio_dev *mdev)
544} 544}
545 545
546 546
547static struct of_match mac53c94_match[] = 547static struct of_device_id mac53c94_match[] =
548{ 548{
549 { 549 {
550 .name = "53c94", 550 .name = "53c94",
551 .type = OF_ANY_MATCH,
552 .compatible = OF_ANY_MATCH
553 }, 551 },
554 {}, 552 {},
555}; 553};
554MODULE_DEVICE_TABLE (of, mac53c94_match);
556 555
557static struct macio_driver mac53c94_driver = 556static struct macio_driver mac53c94_driver =
558{ 557{
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 6fe884a2d00d..6f308ebe3e79 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -5005,9 +5005,9 @@ megaraid_remove_one(struct pci_dev *pdev)
5005} 5005}
5006 5006
5007static void 5007static void
5008megaraid_shutdown(struct device *dev) 5008megaraid_shutdown(struct pci_dev *pdev)
5009{ 5009{
5010 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev)); 5010 struct Scsi_Host *host = pci_get_drvdata(pdev);
5011 adapter_t *adapter = (adapter_t *)host->hostdata; 5011 adapter_t *adapter = (adapter_t *)host->hostdata;
5012 5012
5013 __megaraid_shutdown(adapter); 5013 __megaraid_shutdown(adapter);
@@ -5039,9 +5039,7 @@ static struct pci_driver megaraid_pci_driver = {
5039 .id_table = megaraid_pci_tbl, 5039 .id_table = megaraid_pci_tbl,
5040 .probe = megaraid_probe_one, 5040 .probe = megaraid_probe_one,
5041 .remove = __devexit_p(megaraid_remove_one), 5041 .remove = __devexit_p(megaraid_remove_one),
5042 .driver = { 5042 .shutdown = megaraid_shutdown,
5043 .shutdown = megaraid_shutdown,
5044 },
5045}; 5043};
5046 5044
5047static int __init megaraid_init(void) 5045static int __init megaraid_init(void)
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index b05737ae5eff..ff1933298da6 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1847,7 +1847,7 @@ static struct scsi_host_template mesh_template = {
1847 .use_clustering = DISABLE_CLUSTERING, 1847 .use_clustering = DISABLE_CLUSTERING,
1848}; 1848};
1849 1849
1850static int mesh_probe(struct macio_dev *mdev, const struct of_match *match) 1850static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match)
1851{ 1851{
1852 struct device_node *mesh = macio_get_of_node(mdev); 1852 struct device_node *mesh = macio_get_of_node(mdev);
1853 struct pci_dev* pdev = macio_get_pci_dev(mdev); 1853 struct pci_dev* pdev = macio_get_pci_dev(mdev);
@@ -2012,20 +2012,18 @@ static int mesh_remove(struct macio_dev *mdev)
2012} 2012}
2013 2013
2014 2014
2015static struct of_match mesh_match[] = 2015static struct of_device_id mesh_match[] =
2016{ 2016{
2017 { 2017 {
2018 .name = "mesh", 2018 .name = "mesh",
2019 .type = OF_ANY_MATCH,
2020 .compatible = OF_ANY_MATCH
2021 }, 2019 },
2022 { 2020 {
2023 .name = OF_ANY_MATCH,
2024 .type = "scsi", 2021 .type = "scsi",
2025 .compatible = "chrp,mesh0" 2022 .compatible = "chrp,mesh0"
2026 }, 2023 },
2027 {}, 2024 {},
2028}; 2025};
2026MODULE_DEVICE_TABLE (of, mesh_match);
2029 2027
2030static struct macio_driver mesh_driver = 2028static struct macio_driver mesh_driver =
2031{ 2029{
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index e60b4c0a8427..7c5306499832 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -50,7 +50,6 @@
50#include <scsi/scsi_host.h> 50#include <scsi/scsi_host.h>
51#include "aha152x.h" 51#include "aha152x.h"
52 52
53#include <pcmcia/version.h>
54#include <pcmcia/cs_types.h> 53#include <pcmcia/cs_types.h>
55#include <pcmcia/cs.h> 54#include <pcmcia/cs.h>
56#include <pcmcia/cistpl.h> 55#include <pcmcia/cistpl.h>
@@ -134,11 +133,6 @@ static dev_link_t *aha152x_attach(void)
134 link->next = dev_list; 133 link->next = dev_list;
135 dev_list = link; 134 dev_list = link;
136 client_reg.dev_info = &dev_info; 135 client_reg.dev_info = &dev_info;
137 client_reg.event_handler = &aha152x_event;
138 client_reg.EventMask =
139 CS_EVENT_RESET_REQUEST | CS_EVENT_CARD_RESET |
140 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
141 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
142 client_reg.Version = 0x0210; 136 client_reg.Version = 0x0210;
143 client_reg.event_callback_args.client_data = link; 137 client_reg.event_callback_args.client_data = link;
144 ret = pcmcia_register_client(&link->handle, &client_reg); 138 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -318,13 +312,25 @@ static int aha152x_event(event_t event, int priority,
318 return 0; 312 return 0;
319} 313}
320 314
315static struct pcmcia_device_id aha152x_ids[] = {
316 PCMCIA_DEVICE_PROD_ID123("New Media", "SCSI", "Bus Toaster", 0xcdf7e4cc, 0x35f26476, 0xa8851d6e),
317 PCMCIA_DEVICE_PROD_ID123("NOTEWORTHY", "SCSI", "Bus Toaster", 0xad89c6e8, 0x35f26476, 0xa8851d6e),
318 PCMCIA_DEVICE_PROD_ID12("Adaptec, Inc.", "APA-1460 SCSI Host Adapter", 0x24ba9738, 0x3a3c3d20),
319 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Multimedia Sound/SCSI", 0x085a850b, 0x80a6535c),
320 PCMCIA_DEVICE_PROD_ID12("NOTEWORTHY", "NWCOMB02 SCSI/AUDIO COMBO CARD", 0xad89c6e8, 0x5f9a615b),
321 PCMCIA_DEVICE_NULL,
322};
323MODULE_DEVICE_TABLE(pcmcia, aha152x_ids);
324
321static struct pcmcia_driver aha152x_cs_driver = { 325static struct pcmcia_driver aha152x_cs_driver = {
322 .owner = THIS_MODULE, 326 .owner = THIS_MODULE,
323 .drv = { 327 .drv = {
324 .name = "aha152x_cs", 328 .name = "aha152x_cs",
325 }, 329 },
326 .attach = aha152x_attach, 330 .attach = aha152x_attach,
331 .event = aha152x_event,
327 .detach = aha152x_detach, 332 .detach = aha152x_detach,
333 .id_table = aha152x_ids,
328}; 334};
329 335
330static int __init init_aha152x_cs(void) 336static int __init init_aha152x_cs(void)
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 3df7bc72e354..db8f5cd85ffe 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -47,7 +47,6 @@
47#include <scsi/scsi_host.h> 47#include <scsi/scsi_host.h>
48#include "fdomain.h" 48#include "fdomain.h"
49 49
50#include <pcmcia/version.h>
51#include <pcmcia/cs_types.h> 50#include <pcmcia/cs_types.h>
52#include <pcmcia/cs.h> 51#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
@@ -120,11 +119,6 @@ static dev_link_t *fdomain_attach(void)
120 link->next = dev_list; 119 link->next = dev_list;
121 dev_list = link; 120 dev_list = link;
122 client_reg.dev_info = &dev_info; 121 client_reg.dev_info = &dev_info;
123 client_reg.event_handler = &fdomain_event;
124 client_reg.EventMask =
125 CS_EVENT_RESET_REQUEST | CS_EVENT_CARD_RESET |
126 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
127 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
128 client_reg.Version = 0x0210; 122 client_reg.Version = 0x0210;
129 client_reg.event_callback_args.client_data = link; 123 client_reg.event_callback_args.client_data = link;
130 ret = pcmcia_register_client(&link->handle, &client_reg); 124 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -299,13 +293,24 @@ static int fdomain_event(event_t event, int priority,
299 return 0; 293 return 0;
300} /* fdomain_event */ 294} /* fdomain_event */
301 295
296
297static struct pcmcia_device_id fdomain_ids[] = {
298 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "SCSI PCMCIA Card", 0xe3736c88, 0x859cad20),
299 PCMCIA_DEVICE_PROD_ID1("SCSI PCMCIA Adapter Card", 0x8dacb57e),
300 PCMCIA_DEVICE_PROD_ID12(" SIMPLE TECHNOLOGY Corporation", "SCSI PCMCIA Credit Card Controller", 0x182bdafe, 0xc80d106f),
301 PCMCIA_DEVICE_NULL,
302};
303MODULE_DEVICE_TABLE(pcmcia, fdomain_ids);
304
302static struct pcmcia_driver fdomain_cs_driver = { 305static struct pcmcia_driver fdomain_cs_driver = {
303 .owner = THIS_MODULE, 306 .owner = THIS_MODULE,
304 .drv = { 307 .drv = {
305 .name = "fdomain_cs", 308 .name = "fdomain_cs",
306 }, 309 },
307 .attach = fdomain_attach, 310 .attach = fdomain_attach,
311 .event = fdomain_event,
308 .detach = fdomain_detach, 312 .detach = fdomain_detach,
313 .id_table = fdomain_ids,
309}; 314};
310 315
311static int __init init_fdomain_cs(void) 316static int __init init_fdomain_cs(void)
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 3dddb323e718..3cd3b40b1a4c 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -51,7 +51,6 @@
51#include <scsi/scsi.h> 51#include <scsi/scsi.h>
52#include <scsi/scsi_ioctl.h> 52#include <scsi/scsi_ioctl.h>
53 53
54#include <pcmcia/version.h>
55#include <pcmcia/cs_types.h> 54#include <pcmcia/cs_types.h>
56#include <pcmcia/cs.h> 55#include <pcmcia/cs.h>
57#include <pcmcia/cistpl.h> 56#include <pcmcia/cistpl.h>
@@ -1642,11 +1641,6 @@ static dev_link_t *nsp_cs_attach(void)
1642 link->next = dev_list; 1641 link->next = dev_list;
1643 dev_list = link; 1642 dev_list = link;
1644 client_reg.dev_info = &dev_info; 1643 client_reg.dev_info = &dev_info;
1645 client_reg.EventMask =
1646 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
1647 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
1648 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME ;
1649 client_reg.event_handler = &nsp_cs_event;
1650 client_reg.Version = 0x0210; 1644 client_reg.Version = 0x0210;
1651 client_reg.event_callback_args.client_data = link; 1645 client_reg.event_callback_args.client_data = link;
1652 ret = pcmcia_register_client(&link->handle, &client_reg); 1646 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -2125,13 +2119,27 @@ static int nsp_cs_event(event_t event,
2125 * module entry point 2119 * module entry point
2126 *====================================================================*/ 2120 *====================================================================*/
2127#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68)) 2121#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
2122static struct pcmcia_device_id nsp_cs_ids[] = {
2123 PCMCIA_DEVICE_PROD_ID123("IO DATA", "CBSC16 ", "1", 0x547e66dc, 0x0d63a3fd, 0x51de003a),
2124 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-001", "1", 0x534c02bc, 0x52008408, 0x51de003a),
2125 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-002", "1", 0x534c02bc, 0xcb09d5b2, 0x51de003a),
2126 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-003", "1", 0x534c02bc, 0xbc0ee524, 0x51de003a),
2127 PCMCIA_DEVICE_PROD_ID123("KME ", "SCSI-CARD-004", "1", 0x534c02bc, 0x226a7087, 0x51de003a),
2128 PCMCIA_DEVICE_PROD_ID123("WBT", "NinjaSCSI-3", "R1.0", 0xc7ba805f, 0xfdc7c97d, 0x6973710e),
2129 PCMCIA_DEVICE_PROD_ID123("WORKBIT", "UltraNinja-16", "1", 0x28191418, 0xb70f4b09, 0x51de003a),
2130 PCMCIA_DEVICE_NULL
2131};
2132MODULE_DEVICE_TABLE(pcmcia, nsp_cs_ids);
2133
2128static struct pcmcia_driver nsp_driver = { 2134static struct pcmcia_driver nsp_driver = {
2129 .owner = THIS_MODULE, 2135 .owner = THIS_MODULE,
2130 .drv = { 2136 .drv = {
2131 .name = "nsp_cs", 2137 .name = "nsp_cs",
2132 }, 2138 },
2133 .attach = nsp_cs_attach, 2139 .attach = nsp_cs_attach,
2134 .detach = nsp_cs_detach, 2140 .event = nsp_cs_event,
2141 .detach = nsp_cs_detach,
2142 .id_table = nsp_cs_ids,
2135}; 2143};
2136#endif 2144#endif
2137 2145
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index a0175f5d11cd..7a516f35834e 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -49,7 +49,6 @@
49#include <scsi/scsi_host.h> 49#include <scsi/scsi_host.h>
50#include "../qlogicfas408.h" 50#include "../qlogicfas408.h"
51 51
52#include <pcmcia/version.h>
53#include <pcmcia/cs_types.h> 52#include <pcmcia/cs_types.h>
54#include <pcmcia/cs.h> 53#include <pcmcia/cs.h>
55#include <pcmcia/cistpl.h> 54#include <pcmcia/cistpl.h>
@@ -194,8 +193,6 @@ static dev_link_t *qlogic_attach(void)
194 link->next = dev_list; 193 link->next = dev_list;
195 dev_list = link; 194 dev_list = link;
196 client_reg.dev_info = &dev_info; 195 client_reg.dev_info = &dev_info;
197 client_reg.event_handler = &qlogic_event;
198 client_reg.EventMask = CS_EVENT_RESET_REQUEST | CS_EVENT_CARD_RESET | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
199 client_reg.Version = 0x0210; 196 client_reg.Version = 0x0210;
200 client_reg.event_callback_args.client_data = link; 197 client_reg.event_callback_args.client_data = link;
201 ret = pcmcia_register_client(&link->handle, &client_reg); 198 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -395,6 +392,27 @@ static int qlogic_event(event_t event, int priority, event_callback_args_t * arg
395 return 0; 392 return 0;
396} /* qlogic_event */ 393} /* qlogic_event */
397 394
395static struct pcmcia_device_id qlogic_ids[] = {
396 PCMCIA_DEVICE_PROD_ID12("EIger Labs", "PCMCIA-to-SCSI Adapter", 0x88395fa7, 0x33b7a5e6),
397 PCMCIA_DEVICE_PROD_ID12("EPSON", "SCSI-2 PC Card SC200", 0xd361772f, 0x299d1751),
398 PCMCIA_DEVICE_PROD_ID12("MACNICA", "MIRACLE SCSI-II mPS110", 0x20841b68, 0xab3c3b6d),
399 PCMCIA_DEVICE_PROD_ID12("MIDORI ELECTRONICS ", "CN-SC43", 0x6534382a, 0xd67eee79),
400 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J03R", 0x18df0ba0, 0x24662e8a),
401 PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC003", 0x82375a27, 0xf68e5bf7),
402 PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC004", 0x82375a27, 0x68eace54),
403 PCMCIA_DEVICE_PROD_ID12("KME", "KXLC101", 0x3faee676, 0x194250ec),
404 PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05", 0xd77b2930, 0xa85b2735),
405 PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05 rev 1.10", 0xd77b2930, 0x70f8b5f8),
406 PCMCIA_DEVICE_PROD_ID123("KME", "KXLC002", "00", 0x3faee676, 0x81896b61, 0xf99f065f),
407 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "SCSI2 CARD 37", 0x85c10e17, 0x1a2640c1),
408 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200A PC CARD SCSI", 0xb4585a1a, 0xa6f06ebe),
409 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200B PC CARD SCSI-10", 0xb4585a1a, 0x0a88dea0),
410 /* these conflict with other cards! */
411 /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
412 /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
413 PCMCIA_DEVICE_NULL,
414};
415MODULE_DEVICE_TABLE(pcmcia, qlogic_ids);
398 416
399static struct pcmcia_driver qlogic_cs_driver = { 417static struct pcmcia_driver qlogic_cs_driver = {
400 .owner = THIS_MODULE, 418 .owner = THIS_MODULE,
@@ -402,7 +420,9 @@ static struct pcmcia_driver qlogic_cs_driver = {
402 .name = "qlogic_cs", 420 .name = "qlogic_cs",
403 }, 421 },
404 .attach = qlogic_attach, 422 .attach = qlogic_attach,
423 .event = qlogic_event,
405 .detach = qlogic_detach, 424 .detach = qlogic_detach,
425 .id_table = qlogic_ids,
406}; 426};
407 427
408static int __init init_qlogic_cs(void) 428static int __init init_qlogic_cs(void)
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 1667da9508b4..b4b3a1a8a0c7 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -979,10 +979,6 @@ SYM53C500_attach(void)
979 link->next = dev_list; 979 link->next = dev_list;
980 dev_list = link; 980 dev_list = link;
981 client_reg.dev_info = &dev_info; 981 client_reg.dev_info = &dev_info;
982 client_reg.event_handler = &SYM53C500_event;
983 client_reg.EventMask = CS_EVENT_RESET_REQUEST | CS_EVENT_CARD_RESET |
984 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
985 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
986 client_reg.Version = 0x0210; 982 client_reg.Version = 0x0210;
987 client_reg.event_callback_args.client_data = link; 983 client_reg.event_callback_args.client_data = link;
988 ret = pcmcia_register_client(&link->handle, &client_reg); 984 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -999,13 +995,23 @@ MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
999MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver"); 995MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver");
1000MODULE_LICENSE("GPL"); 996MODULE_LICENSE("GPL");
1001 997
998static struct pcmcia_device_id sym53c500_ids[] = {
999 PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7),
1000 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8),
1001 PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44),
1002 PCMCIA_DEVICE_NULL,
1003};
1004MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids);
1005
1002static struct pcmcia_driver sym53c500_cs_driver = { 1006static struct pcmcia_driver sym53c500_cs_driver = {
1003 .owner = THIS_MODULE, 1007 .owner = THIS_MODULE,
1004 .drv = { 1008 .drv = {
1005 .name = "sym53c500_cs", 1009 .name = "sym53c500_cs",
1006 }, 1010 },
1007 .attach = SYM53C500_attach, 1011 .attach = SYM53C500_attach,
1012 .event = SYM53C500_event,
1008 .detach = SYM53C500_detach, 1013 .detach = SYM53C500_detach,
1014 .id_table = sym53c500_ids,
1009}; 1015};
1010 1016
1011static int __init 1017static int __init
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index cab535809d0d..7a91ca3d32a6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -621,7 +621,7 @@ static void scsi_free_sgtable(struct scatterlist *sgl, int index)
621{ 621{
622 struct scsi_host_sg_pool *sgp; 622 struct scsi_host_sg_pool *sgp;
623 623
624 BUG_ON(index > SG_MEMPOOL_NR); 624 BUG_ON(index >= SG_MEMPOOL_NR);
625 625
626 sgp = scsi_sg_pools + index; 626 sgp = scsi_sg_pools + index;
627 mempool_free(sgl, sgp->pool); 627 mempool_free(sgl, sgp->pool);
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index feb8e73fc1c9..d27fb4c881d2 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -1497,23 +1497,6 @@ rs68328_init(void)
1497 return 0; 1497 return 0;
1498} 1498}
1499 1499
1500
1501
1502/*
1503 * register_serial and unregister_serial allows for serial ports to be
1504 * configured at run-time, to support PCMCIA modems.
1505 */
1506/* SPARC: Unused at this time, just here to make things link. */
1507int register_serial(struct serial_struct *req)
1508{
1509 return -1;
1510}
1511
1512void unregister_serial(int line)
1513{
1514 return;
1515}
1516
1517module_init(rs68328_init); 1500module_init(rs68328_init);
1518 1501
1519 1502
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index d8b9d2b8c200..7e8fc7c1d4cc 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -77,23 +77,9 @@ static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
77 */ 77 */
78#define is_real_interrupt(irq) ((irq) != 0) 78#define is_real_interrupt(irq) ((irq) != 0)
79 79
80/*
81 * This converts from our new CONFIG_ symbols to the symbols
82 * that asm/serial.h expects. You _NEED_ to comment out the
83 * linux/config.h include contained inside asm/serial.h for
84 * this to work.
85 */
86#undef CONFIG_SERIAL_MANY_PORTS
87#undef CONFIG_SERIAL_DETECT_IRQ
88#undef CONFIG_SERIAL_MULTIPORT
89#undef CONFIG_HUB6
90
91#ifdef CONFIG_SERIAL_8250_DETECT_IRQ 80#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
92#define CONFIG_SERIAL_DETECT_IRQ 1 81#define CONFIG_SERIAL_DETECT_IRQ 1
93#endif 82#endif
94#ifdef CONFIG_SERIAL_8250_MULTIPORT
95#define CONFIG_SERIAL_MULTIPORT 1
96#endif
97#ifdef CONFIG_SERIAL_8250_MANY_PORTS 83#ifdef CONFIG_SERIAL_8250_MANY_PORTS
98#define CONFIG_SERIAL_MANY_PORTS 1 84#define CONFIG_SERIAL_MANY_PORTS 1
99#endif 85#endif
@@ -119,7 +105,7 @@ static struct old_serial_port old_serial_port[] = {
119 SERIAL_PORT_DFNS /* defined in asm/serial.h */ 105 SERIAL_PORT_DFNS /* defined in asm/serial.h */
120}; 106};
121 107
122#define UART_NR (ARRAY_SIZE(old_serial_port) + CONFIG_SERIAL_8250_NR_UARTS) 108#define UART_NR CONFIG_SERIAL_8250_NR_UARTS
123 109
124#ifdef CONFIG_SERIAL_8250_RSA 110#ifdef CONFIG_SERIAL_8250_RSA
125 111
@@ -1007,21 +993,24 @@ static void autoconfig_irq(struct uart_8250_port *up)
1007 up->port.irq = (irq > 0) ? irq : 0; 993 up->port.irq = (irq > 0) ? irq : 0;
1008} 994}
1009 995
996static inline void __stop_tx(struct uart_8250_port *p)
997{
998 if (p->ier & UART_IER_THRI) {
999 p->ier &= ~UART_IER_THRI;
1000 serial_out(p, UART_IER, p->ier);
1001 }
1002}
1003
1010static void serial8250_stop_tx(struct uart_port *port, unsigned int tty_stop) 1004static void serial8250_stop_tx(struct uart_port *port, unsigned int tty_stop)
1011{ 1005{
1012 struct uart_8250_port *up = (struct uart_8250_port *)port; 1006 struct uart_8250_port *up = (struct uart_8250_port *)port;
1013 1007
1014 if (up->ier & UART_IER_THRI) { 1008 __stop_tx(up);
1015 up->ier &= ~UART_IER_THRI;
1016 serial_out(up, UART_IER, up->ier);
1017 }
1018 1009
1019 /* 1010 /*
1020 * We only do this from uart_stop - if we run out of 1011 * We really want to stop the transmitter from sending.
1021 * characters to send, we don't want to prevent the
1022 * FIFO from emptying.
1023 */ 1012 */
1024 if (up->port.type == PORT_16C950 && tty_stop) { 1013 if (up->port.type == PORT_16C950) {
1025 up->acr |= UART_ACR_TXDIS; 1014 up->acr |= UART_ACR_TXDIS;
1026 serial_icr_write(up, UART_ACR, up->acr); 1015 serial_icr_write(up, UART_ACR, up->acr);
1027 } 1016 }
@@ -1045,10 +1034,11 @@ static void serial8250_start_tx(struct uart_port *port, unsigned int tty_start)
1045 transmit_chars(up); 1034 transmit_chars(up);
1046 } 1035 }
1047 } 1036 }
1037
1048 /* 1038 /*
1049 * We only do this from uart_start 1039 * Re-enable the transmitter if we disabled it.
1050 */ 1040 */
1051 if (tty_start && up->port.type == PORT_16C950) { 1041 if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
1052 up->acr &= ~UART_ACR_TXDIS; 1042 up->acr &= ~UART_ACR_TXDIS;
1053 serial_icr_write(up, UART_ACR, up->acr); 1043 serial_icr_write(up, UART_ACR, up->acr);
1054 } 1044 }
@@ -1169,7 +1159,7 @@ static _INLINE_ void transmit_chars(struct uart_8250_port *up)
1169 return; 1159 return;
1170 } 1160 }
1171 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { 1161 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
1172 serial8250_stop_tx(&up->port, 0); 1162 __stop_tx(up);
1173 return; 1163 return;
1174 } 1164 }
1175 1165
@@ -1188,7 +1178,7 @@ static _INLINE_ void transmit_chars(struct uart_8250_port *up)
1188 DEBUG_INTR("THRE..."); 1178 DEBUG_INTR("THRE...");
1189 1179
1190 if (uart_circ_empty(xmit)) 1180 if (uart_circ_empty(xmit))
1191 serial8250_stop_tx(&up->port, 0); 1181 __stop_tx(up);
1192} 1182}
1193 1183
1194static _INLINE_ void check_modem_status(struct uart_8250_port *up) 1184static _INLINE_ void check_modem_status(struct uart_8250_port *up)
@@ -1390,13 +1380,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
1390static unsigned int serial8250_get_mctrl(struct uart_port *port) 1380static unsigned int serial8250_get_mctrl(struct uart_port *port)
1391{ 1381{
1392 struct uart_8250_port *up = (struct uart_8250_port *)port; 1382 struct uart_8250_port *up = (struct uart_8250_port *)port;
1393 unsigned long flags;
1394 unsigned char status; 1383 unsigned char status;
1395 unsigned int ret; 1384 unsigned int ret;
1396 1385
1397 spin_lock_irqsave(&up->port.lock, flags);
1398 status = serial_in(up, UART_MSR); 1386 status = serial_in(up, UART_MSR);
1399 spin_unlock_irqrestore(&up->port.lock, flags);
1400 1387
1401 ret = 0; 1388 ret = 0;
1402 if (status & UART_MSR_DCD) 1389 if (status & UART_MSR_DCD)
@@ -2074,7 +2061,8 @@ static void __init serial8250_isa_init_ports(void)
2074 up->port.ops = &serial8250_pops; 2061 up->port.ops = &serial8250_pops;
2075 } 2062 }
2076 2063
2077 for (i = 0, up = serial8250_ports; i < ARRAY_SIZE(old_serial_port); 2064 for (i = 0, up = serial8250_ports;
2065 i < ARRAY_SIZE(old_serial_port) && i < UART_NR;
2078 i++, up++) { 2066 i++, up++) {
2079 up->port.iobase = old_serial_port[i].port; 2067 up->port.iobase = old_serial_port[i].port;
2080 up->port.irq = irq_canonicalize(old_serial_port[i].irq); 2068 up->port.irq = irq_canonicalize(old_serial_port[i].irq);
@@ -2323,10 +2311,11 @@ static int __devinit serial8250_probe(struct device *dev)
2323{ 2311{
2324 struct plat_serial8250_port *p = dev->platform_data; 2312 struct plat_serial8250_port *p = dev->platform_data;
2325 struct uart_port port; 2313 struct uart_port port;
2314 int ret, i;
2326 2315
2327 memset(&port, 0, sizeof(struct uart_port)); 2316 memset(&port, 0, sizeof(struct uart_port));
2328 2317
2329 for (; p && p->flags != 0; p++) { 2318 for (i = 0; p && p->flags != 0; p++, i++) {
2330 port.iobase = p->iobase; 2319 port.iobase = p->iobase;
2331 port.membase = p->membase; 2320 port.membase = p->membase;
2332 port.irq = p->irq; 2321 port.irq = p->irq;
@@ -2335,10 +2324,16 @@ static int __devinit serial8250_probe(struct device *dev)
2335 port.iotype = p->iotype; 2324 port.iotype = p->iotype;
2336 port.flags = p->flags; 2325 port.flags = p->flags;
2337 port.mapbase = p->mapbase; 2326 port.mapbase = p->mapbase;
2327 port.hub6 = p->hub6;
2338 port.dev = dev; 2328 port.dev = dev;
2339 if (share_irqs) 2329 if (share_irqs)
2340 port.flags |= UPF_SHARE_IRQ; 2330 port.flags |= UPF_SHARE_IRQ;
2341 serial8250_register_port(&port); 2331 ret = serial8250_register_port(&port);
2332 if (ret < 0) {
2333 dev_err(dev, "unable to register port at index %d "
2334 "(IO%lx MEM%lx IRQ%d): %d\n", i,
2335 p->iobase, p->mapbase, p->irq, ret);
2336 }
2342 } 2337 }
2343 return 0; 2338 return 0;
2344} 2339}
diff --git a/drivers/serial/8250_accent.c b/drivers/serial/8250_accent.c
new file mode 100644
index 000000000000..1f2c276063ef
--- /dev/null
+++ b/drivers/serial/8250_accent.c
@@ -0,0 +1,47 @@
1/*
2 * linux/drivers/serial/8250_accent.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
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#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 }
23
24static struct plat_serial8250_port accent_data[] = {
25 PORT(0x330, 4),
26 PORT(0x338, 4),
27 { },
28};
29
30static struct platform_device accent_device = {
31 .name = "serial8250",
32 .id = 2,
33 .dev = {
34 .platform_data = accent_data,
35 },
36};
37
38static int __init accent_init(void)
39{
40 return platform_device_register(&accent_device);
41}
42
43module_init(accent_init);
44
45MODULE_AUTHOR("Russell King");
46MODULE_DESCRIPTION("8250 serial probe module for Accent Async cards");
47MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_boca.c b/drivers/serial/8250_boca.c
new file mode 100644
index 000000000000..465c9ea1e7a3
--- /dev/null
+++ b/drivers/serial/8250_boca.c
@@ -0,0 +1,61 @@
1/*
2 * linux/drivers/serial/8250_boca.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
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#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 }
23
24static struct plat_serial8250_port boca_data[] = {
25 PORT(0x100, 12),
26 PORT(0x108, 12),
27 PORT(0x110, 12),
28 PORT(0x118, 12),
29 PORT(0x120, 12),
30 PORT(0x128, 12),
31 PORT(0x130, 12),
32 PORT(0x138, 12),
33 PORT(0x140, 12),
34 PORT(0x148, 12),
35 PORT(0x150, 12),
36 PORT(0x158, 12),
37 PORT(0x160, 12),
38 PORT(0x168, 12),
39 PORT(0x170, 12),
40 PORT(0x178, 12),
41 { },
42};
43
44static struct platform_device boca_device = {
45 .name = "serial8250",
46 .id = 3,
47 .dev = {
48 .platform_data = boca_data,
49 },
50};
51
52static int __init boca_init(void)
53{
54 return platform_device_register(&boca_device);
55}
56
57module_init(boca_init);
58
59MODULE_AUTHOR("Russell King");
60MODULE_DESCRIPTION("8250 serial probe module for Boca cards");
61MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_fourport.c b/drivers/serial/8250_fourport.c
new file mode 100644
index 000000000000..e9b4d908ef42
--- /dev/null
+++ b/drivers/serial/8250_fourport.c
@@ -0,0 +1,53 @@
1/*
2 * linux/drivers/serial/8250_fourport.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
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#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define PORT(_base,_irq) \
16 { \
17 .iobase = _base, \
18 .irq = _irq, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_PORT, \
21 .flags = UPF_BOOT_AUTOCONF | UPF_FOURPORT, \
22 }
23
24static struct plat_serial8250_port fourport_data[] = {
25 PORT(0x1a0, 9),
26 PORT(0x1a8, 9),
27 PORT(0x1b0, 9),
28 PORT(0x1b8, 9),
29 PORT(0x2a0, 5),
30 PORT(0x2a8, 5),
31 PORT(0x2b0, 5),
32 PORT(0x2b8, 5),
33 { },
34};
35
36static struct platform_device fourport_device = {
37 .name = "serial8250",
38 .id = 1,
39 .dev = {
40 .platform_data = fourport_data,
41 },
42};
43
44static int __init fourport_init(void)
45{
46 return platform_device_register(&fourport_device);
47}
48
49module_init(fourport_init);
50
51MODULE_AUTHOR("Russell King");
52MODULE_DESCRIPTION("8250 serial probe module for AST Fourport cards");
53MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_hub6.c b/drivers/serial/8250_hub6.c
new file mode 100644
index 000000000000..77f396f84b4c
--- /dev/null
+++ b/drivers/serial/8250_hub6.c
@@ -0,0 +1,58 @@
1/*
2 * linux/drivers/serial/8250_hub6.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
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#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/serial_8250.h>
14
15#define HUB6(card,port) \
16 { \
17 .iobase = 0x302, \
18 .irq = 3, \
19 .uartclk = 1843200, \
20 .iotype = UPIO_HUB6, \
21 .flags = UPF_BOOT_AUTOCONF, \
22 .hub6 = (card) << 6 | (port) << 3 | 1, \
23 }
24
25static struct plat_serial8250_port hub6_data[] = {
26 HUB6(0,0),
27 HUB6(0,1),
28 HUB6(0,2),
29 HUB6(0,3),
30 HUB6(0,4),
31 HUB6(0,5),
32 HUB6(1,0),
33 HUB6(1,1),
34 HUB6(1,2),
35 HUB6(1,3),
36 HUB6(1,4),
37 HUB6(1,5),
38 { },
39};
40
41static struct platform_device hub6_device = {
42 .name = "serial8250",
43 .id = 4,
44 .dev = {
45 .platform_data = hub6_data,
46 },
47};
48
49static int __init hub6_init(void)
50{
51 return platform_device_register(&hub6_device);
52}
53
54module_init(hub6_init);
55
56MODULE_AUTHOR("Russell King");
57MODULE_DESCRIPTION("8250 serial probe module for Hub6 cards");
58MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_mca.c b/drivers/serial/8250_mca.c
new file mode 100644
index 000000000000..f0c40d68b8c1
--- /dev/null
+++ b/drivers/serial/8250_mca.c
@@ -0,0 +1,64 @@
1/*
2 * linux/drivers/serial/8250_mca.c
3 *
4 * Copyright (C) 2005 Russell King.
5 * Data taken from include/asm-i386/serial.h
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#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/mca.h>
15#include <linux/serial_8250.h>
16
17/*
18 * FIXME: Should we be doing AUTO_IRQ here?
19 */
20#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
21#define MCA_FLAGS UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_AUTO_IRQ
22#else
23#define MCA_FLAGS UPF_BOOT_AUTOCONF | UPF_SKIP_TEST
24#endif
25
26#define PORT(_base,_irq) \
27 { \
28 .iobase = _base, \
29 .irq = _irq, \
30 .uartclk = 1843200, \
31 .iotype = UPIO_PORT, \
32 .flags = MCA_FLAGS, \
33 }
34
35static struct plat_serial8250_port mca_data[] = {
36 PORT(0x3220, 3),
37 PORT(0x3228, 3),
38 PORT(0x4220, 3),
39 PORT(0x4228, 3),
40 PORT(0x5220, 3),
41 PORT(0x5228, 3),
42 { },
43};
44
45static struct platform_device mca_device = {
46 .name = "serial8250",
47 .id = 5,
48 .dev = {
49 .platform_data = mca_data,
50 },
51};
52
53static int __init mca_init(void)
54{
55 if (!MCA_bus)
56 return -ENODEV;
57 return platform_device_register(&mca_device);
58}
59
60module_init(mca_init);
61
62MODULE_AUTHOR("Russell King");
63MODULE_DESCRIPTION("8250 serial probe module for MCA ports");
64MODULE_LICENSE("GPL");
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index de54bdc5398b..356f5556759a 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -389,6 +389,9 @@ static void __devexit sbs_exit(struct pci_dev *dev)
389 * - 10x cards have control registers in IO and/or memory space; 389 * - 10x cards have control registers in IO and/or memory space;
390 * - 20x cards have control registers in standard PCI configuration space. 390 * - 20x cards have control registers in standard PCI configuration space.
391 * 391 *
392 * There are also Quartet Serial cards which use Oxford Semiconductor
393 * 16954 quad UART PCI chip clocked by 18.432 MHz quartz.
394 *
392 * Note: some SIIG cards are probed by the parport_serial object. 395 * Note: some SIIG cards are probed by the parport_serial object.
393 */ 396 */
394 397
@@ -1026,6 +1029,8 @@ enum pci_board_num_t {
1026 pbn_b0_2_921600, 1029 pbn_b0_2_921600,
1027 pbn_b0_4_921600, 1030 pbn_b0_4_921600,
1028 1031
1032 pbn_b0_4_1152000,
1033
1029 pbn_b0_bt_1_115200, 1034 pbn_b0_bt_1_115200,
1030 pbn_b0_bt_2_115200, 1035 pbn_b0_bt_2_115200,
1031 pbn_b0_bt_8_115200, 1036 pbn_b0_bt_8_115200,
@@ -1158,6 +1163,12 @@ static struct pci_board pci_boards[] __devinitdata = {
1158 .base_baud = 921600, 1163 .base_baud = 921600,
1159 .uart_offset = 8, 1164 .uart_offset = 8,
1160 }, 1165 },
1166 [pbn_b0_4_1152000] = {
1167 .flags = FL_BASE0,
1168 .num_ports = 4,
1169 .base_baud = 1152000,
1170 .uart_offset = 8,
1171 },
1161 1172
1162 [pbn_b0_bt_1_115200] = { 1173 [pbn_b0_bt_1_115200] = {
1163 .flags = FL_BASE0|FL_BASE_BARS, 1174 .flags = FL_BASE0|FL_BASE_BARS,
@@ -1755,33 +1766,30 @@ pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1755static void __devexit pciserial_remove_one(struct pci_dev *dev) 1766static void __devexit pciserial_remove_one(struct pci_dev *dev)
1756{ 1767{
1757 struct serial_private *priv = pci_get_drvdata(dev); 1768 struct serial_private *priv = pci_get_drvdata(dev);
1769 struct pci_serial_quirk *quirk;
1770 int i;
1758 1771
1759 pci_set_drvdata(dev, NULL); 1772 pci_set_drvdata(dev, NULL);
1760 1773
1761 if (priv) { 1774 for (i = 0; i < priv->nr; i++)
1762 struct pci_serial_quirk *quirk; 1775 serial8250_unregister_port(priv->line[i]);
1763 int i;
1764
1765 for (i = 0; i < priv->nr; i++)
1766 serial8250_unregister_port(priv->line[i]);
1767 1776
1768 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) { 1777 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
1769 if (priv->remapped_bar[i]) 1778 if (priv->remapped_bar[i])
1770 iounmap(priv->remapped_bar[i]); 1779 iounmap(priv->remapped_bar[i]);
1771 priv->remapped_bar[i] = NULL; 1780 priv->remapped_bar[i] = NULL;
1772 } 1781 }
1773 1782
1774 /* 1783 /*
1775 * Find the exit quirks. 1784 * Find the exit quirks.
1776 */ 1785 */
1777 quirk = find_quirk(dev); 1786 quirk = find_quirk(dev);
1778 if (quirk->exit) 1787 if (quirk->exit)
1779 quirk->exit(dev); 1788 quirk->exit(dev);
1780 1789
1781 pci_disable_device(dev); 1790 pci_disable_device(dev);
1782 1791
1783 kfree(priv); 1792 kfree(priv);
1784 }
1785} 1793}
1786 1794
1787static int pciserial_suspend_one(struct pci_dev *dev, pm_message_t state) 1795static int pciserial_suspend_one(struct pci_dev *dev, pm_message_t state)
@@ -1978,6 +1986,9 @@ static struct pci_device_id serial_pci_tbl[] = {
1978 PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4, 0, 0, 1986 PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4, 0, 0,
1979 pbn_b0_4_921600 }, 1987 pbn_b0_4_921600 },
1980 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, 1988 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
1989 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL, 0, 0,
1990 pbn_b0_4_1152000 },
1991 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
1981 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1992 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1982 pbn_b0_4_115200 }, 1993 pbn_b0_4_115200 },
1983 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952, 1994 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952,
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 25fcef2c42de..97034d3937fd 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -86,14 +86,14 @@ config SERIAL_8250_ACPI
86 namespace, say Y here. If unsure, say N. 86 namespace, say Y here. If unsure, say N.
87 87
88config SERIAL_8250_NR_UARTS 88config SERIAL_8250_NR_UARTS
89 int "Maximum number of non-legacy 8250/16550 serial ports" 89 int "Maximum number of 8250/16550 serial ports"
90 depends on SERIAL_8250 90 depends on SERIAL_8250
91 default "4" 91 default "4"
92 ---help--- 92 help
93 Set this to the number of non-legacy serial ports you want 93 Set this to the number of serial ports you want the driver
94 the driver to support. This includes any ports discovered 94 to support. This includes any ports discovered via ACPI or
95 via ACPI or PCI enumeration and any ports that may be added 95 PCI enumeration and any ports that may be added at run-time
96 at run-time via hot-plug. 96 via hot-plug, or any ISA multi-port serial cards.
97 97
98config SERIAL_8250_EXTENDED 98config SERIAL_8250_EXTENDED
99 bool "Extended 8250/16550 serial driver options" 99 bool "Extended 8250/16550 serial driver options"
@@ -141,31 +141,74 @@ config SERIAL_8250_DETECT_IRQ
141 141
142 If unsure, say N. 142 If unsure, say N.
143 143
144config SERIAL_8250_MULTIPORT
145 bool "Support special multiport boards"
146 depends on SERIAL_8250_EXTENDED
147 help
148 Some multiport serial ports have special ports which are used to
149 signal when there are any serial ports on the board which need
150 servicing. Say Y here to enable the serial driver to take advantage
151 of those special I/O ports.
152
153config SERIAL_8250_RSA 144config SERIAL_8250_RSA
154 bool "Support RSA serial ports" 145 bool "Support RSA serial ports"
155 depends on SERIAL_8250_EXTENDED 146 depends on SERIAL_8250_EXTENDED
156 help 147 help
157 ::: To be written ::: 148 ::: To be written :::
158 149
159comment "Non-8250 serial port support" 150#
151# Multi-port serial cards
152#
153
154config SERIAL_8250_FOURPORT
155 tristate "Support Fourport cards"
156 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
157 help
158 Say Y here if you have an AST FourPort serial board.
159
160 To compile this driver as a module, choose M here: the module
161 will be called 8250_fourport.
162
163config SERIAL_8250_ACCENT
164 tristate "Support Accent cards"
165 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
166 help
167 Say Y here if you have an Accent Async serial board.
168
169 To compile this driver as a module, choose M here: the module
170 will be called 8250_accent.
171
172
173config SERIAL_8250_BOCA
174 tristate "Support Boca cards"
175 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
176 help
177 Say Y here if you have a Boca serial board. Please read the Boca
178 mini-HOWTO, avaialble from <http://www.tldp.org/docs.html#howto>
179
180 To compile this driver as a module, choose M here: the module
181 will be called 8250_boca.
182
183
184config SERIAL_8250_HUB6
185 tristate "Support Hub6 cards"
186 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
187 help
188 Say Y here if you have a HUB6 serial board.
189
190 To compile this driver as a module, choose M here: the module
191 will be called 8250_hub6.
192
193config SERIAL_8250_MCA
194 tristate "Support 8250-type ports on MCA buses"
195 depends on SERIAL_8250 != n && MCA
196 help
197 Say Y here if you have a MCA serial ports.
198
199 To compile this driver as a module, choose M here: the module
200 will be called 8250_mca.
160 201
161config SERIAL_8250_ACORN 202config SERIAL_8250_ACORN
162 tristate "Acorn expansion card serial port support" 203 tristate "Acorn expansion card serial port support"
163 depends on ARM && ARCH_ACORN && SERIAL_8250 204 depends on ARCH_ACORN && SERIAL_8250
164 help 205 help
165 If you have an Atomwide Serial card or Serial Port card for an Acorn 206 If you have an Atomwide Serial card or Serial Port card for an Acorn
166 system, say Y to this option. The driver can handle 1, 2, or 3 port 207 system, say Y to this option. The driver can handle 1, 2, or 3 port
167 cards. If unsure, say N. 208 cards. If unsure, say N.
168 209
210comment "Non-8250 serial port support"
211
169config SERIAL_AMBA_PL010 212config SERIAL_AMBA_PL010
170 tristate "ARM AMBA PL010 serial port support" 213 tristate "ARM AMBA PL010 serial port support"
171 depends on ARM_AMBA 214 depends on ARM_AMBA
@@ -263,13 +306,6 @@ config SERIAL_S3C2410_CONSOLE
263 your boot loader about how to pass options to the kernel at 306 your boot loader about how to pass options to the kernel at
264 boot time.) 307 boot time.)
265 308
266config SERIAL_BAST_SIO
267 bool "Support for BAST SuperIO serial ports"
268 depends on ARCH_BAST && SERIAL_8250=y
269 help
270 Support for registerin the SuperIO chip on BAST board with
271 the 8250/16550 uart code.
272
273config SERIAL_DZ 309config SERIAL_DZ
274 bool "DECstation DZ serial driver" 310 bool "DECstation DZ serial driver"
275 depends on MACH_DECSTATION && MIPS32 311 depends on MACH_DECSTATION && MIPS32
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 8f1cdde7dbed..11c7dc483f93 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -17,6 +17,11 @@ obj-$(CONFIG_SERIAL_8250) += 8250.o $(serial-8250-y)
17obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o 17obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
18obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o 18obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
19obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o 19obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
20obj-$(CONFIG_SERIAL_8250_FOURPORT) += 8250_fourport.o
21obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o
22obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o
23obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o
24obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o
20obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 25obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
21obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o 26obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
22obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o 27obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
@@ -39,7 +44,6 @@ obj-$(CONFIG_SERIAL_LH7A40X) += serial_lh7a40x.o
39obj-$(CONFIG_SERIAL_AU1X00) += au1x00_uart.o 44obj-$(CONFIG_SERIAL_AU1X00) += au1x00_uart.o
40obj-$(CONFIG_SERIAL_DZ) += dz.o 45obj-$(CONFIG_SERIAL_DZ) += dz.o
41obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o 46obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
42obj-$(CONFIG_SERIAL_BAST_SIO) += bast_sio.o
43obj-$(CONFIG_SERIAL_SGI_L1_CONSOLE) += sn_console.o 47obj-$(CONFIG_SERIAL_SGI_L1_CONSOLE) += sn_console.o
44obj-$(CONFIG_SERIAL_CPM) += cpm_uart/ 48obj-$(CONFIG_SERIAL_CPM) += cpm_uart/
45obj-$(CONFIG_SERIAL_IMX) += imx.o 49obj-$(CONFIG_SERIAL_IMX) += imx.o
diff --git a/drivers/serial/au1x00_uart.c b/drivers/serial/au1x00_uart.c
index 5400dc2c087e..6104aeef1243 100644
--- a/drivers/serial/au1x00_uart.c
+++ b/drivers/serial/au1x00_uart.c
@@ -556,13 +556,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
556static unsigned int serial8250_get_mctrl(struct uart_port *port) 556static unsigned int serial8250_get_mctrl(struct uart_port *port)
557{ 557{
558 struct uart_8250_port *up = (struct uart_8250_port *)port; 558 struct uart_8250_port *up = (struct uart_8250_port *)port;
559 unsigned long flags;
560 unsigned char status; 559 unsigned char status;
561 unsigned int ret; 560 unsigned int ret;
562 561
563 spin_lock_irqsave(&up->port.lock, flags);
564 status = serial_in(up, UART_MSR); 562 status = serial_in(up, UART_MSR);
565 spin_unlock_irqrestore(&up->port.lock, flags);
566 563
567 ret = 0; 564 ret = 0;
568 if (status & UART_MSR_DCD) 565 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/bast_sio.c b/drivers/serial/bast_sio.c
deleted file mode 100644
index 2b48fab6f0c6..000000000000
--- a/drivers/serial/bast_sio.c
+++ /dev/null
@@ -1,80 +0,0 @@
1/* linux/drivers/serial/bast_sio.c
2 *
3 * Copyright (c) 2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://www.simtec.co.uk/products/EB2410ITX/
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 * Modifications:
13 * 23-Sep-2004 BJD Added copyright header
14 * 23-Sep-2004 BJD Added serial port remove code
15*/
16
17#include <linux/module.h>
18#include <linux/config.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/tty.h>
22#include <linux/serial.h>
23#include <linux/serial_core.h>
24#include <linux/types.h>
25
26#include <asm/io.h>
27#include <asm/serial.h>
28#include <asm/mach-types.h>
29
30#include <asm/arch/map.h>
31#include <asm/arch/irqs.h>
32#include <asm/arch/bast-map.h>
33#include <asm/arch/bast-irq.h>
34
35static int __init serial_bast_register(unsigned long port, unsigned int irq)
36{
37 struct serial_struct serial_req;
38
39 serial_req.flags = UPF_AUTOPROBE | UPF_SHARE_IRQ;
40 serial_req.baud_base = BASE_BAUD;
41 serial_req.irq = irq;
42 serial_req.io_type = UPIO_MEM;
43 serial_req.iomap_base = port;
44 serial_req.iomem_base = ioremap(port, 0x10);
45 serial_req.iomem_reg_shift = 0;
46
47 return register_serial(&serial_req);
48}
49
50#define SERIAL_BASE (S3C2410_CS2 + BAST_PA_SUPERIO)
51
52static int port[2] = { -1, -1 };
53
54static int __init serial_bast_init(void)
55{
56 if (machine_is_bast()) {
57 port[0] = serial_bast_register(SERIAL_BASE + 0x2f8, IRQ_PCSERIAL1);
58 port[1] = serial_bast_register(SERIAL_BASE + 0x3f8, IRQ_PCSERIAL2);
59 }
60
61 return 0;
62}
63
64static void __exit serial_bast_exit(void)
65{
66 if (port[0] != -1)
67 unregister_serial(port[0]);
68 if (port[1] != -1)
69 unregister_serial(port[1]);
70}
71
72
73module_init(serial_bast_init);
74module_exit(serial_bast_exit);
75
76MODULE_LICENSE("GPL");
77MODULE_AUTHOR("Ben Dooks, ben@simtec.co.uk");
78MODULE_DESCRIPTION("BAST Onboard Serial setup");
79
80
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index de26cf7b003c..7911912f50c7 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -94,12 +94,42 @@ void smc1_lineif(struct uart_cpm_port *pinfo)
94 ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits; 94 ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits;
95 } 95 }
96 96
97#ifdef CONFIG_MPC885ADS
98 /* Enable SMC1 transceivers */
99 {
100 volatile uint __iomem *bcsr1 = ioremap(BCSR1, 4);
101 uint tmp;
102
103 tmp = in_be32(bcsr1);
104 tmp &= ~BCSR1_RS232EN_1;
105 out_be32(bcsr1, tmp);
106 iounmap(bcsr1);
107 }
108#endif
109
97 pinfo->brg = 1; 110 pinfo->brg = 1;
98} 111}
99 112
100void smc2_lineif(struct uart_cpm_port *pinfo) 113void smc2_lineif(struct uart_cpm_port *pinfo)
101{ 114{
102 /* XXX SMC2: insert port configuration here */ 115#ifdef CONFIG_MPC885ADS
116 volatile cpm8xx_t *cp = cpmp;
117 volatile uint __iomem *bcsr1;
118 uint tmp;
119
120 cp->cp_pepar |= 0x00000c00;
121 cp->cp_pedir &= ~0x00000c00;
122 cp->cp_peso &= ~0x00000400;
123 cp->cp_peso |= 0x00000800;
124
125 /* Enable SMC2 transceivers */
126 bcsr1 = ioremap(BCSR1, 4);
127 tmp = in_be32(bcsr1);
128 tmp &= ~BCSR1_RS232EN_2;
129 out_be32(bcsr1, tmp);
130 iounmap(bcsr1);
131#endif
132
103 pinfo->brg = 2; 133 pinfo->brg = 2;
104} 134}
105 135
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 3da5494953af..23b8871e74cc 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -426,8 +426,6 @@
426static char *serial_version = "$Revision: 1.25 $"; 426static char *serial_version = "$Revision: 1.25 $";
427 427
428#include <linux/config.h> 428#include <linux/config.h>
429#include <linux/version.h>
430
431#include <linux/types.h> 429#include <linux/types.h>
432#include <linux/errno.h> 430#include <linux/errno.h>
433#include <linux/signal.h> 431#include <linux/signal.h>
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 546a0bc77e1e..c112b32764e8 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -25,7 +25,6 @@
25#define SERIAL_DO_RESTART 25#define SERIAL_DO_RESTART
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/config.h> 27#include <linux/config.h>
28#include <linux/version.h>
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/signal.h> 30#include <linux/signal.h>
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index 3ea46c069f6f..ea5bf4d4daa3 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -518,27 +518,28 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id, struct pt_regs *re
518static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port) 518static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
519{ 519{
520 struct zilog_channel *channel; 520 struct zilog_channel *channel;
521 unsigned long flags;
522 unsigned char status; 521 unsigned char status;
523 522
524 spin_lock_irqsave(&port->lock, flags);
525
526 channel = ZILOG_CHANNEL_FROM_PORT(port); 523 channel = ZILOG_CHANNEL_FROM_PORT(port);
527 status = readb(&channel->control); 524 status = readb(&channel->control);
528 ZSDELAY(); 525 ZSDELAY();
529 526
530 spin_unlock_irqrestore(&port->lock, flags);
531
532 return status; 527 return status;
533} 528}
534 529
535/* The port lock is not held. */ 530/* The port lock is not held. */
536static unsigned int ip22zilog_tx_empty(struct uart_port *port) 531static unsigned int ip22zilog_tx_empty(struct uart_port *port)
537{ 532{
533 unsigned long flags;
538 unsigned char status; 534 unsigned char status;
539 unsigned int ret; 535 unsigned int ret;
540 536
537 spin_lock_irqsave(&port->lock, flags);
538
541 status = ip22zilog_read_channel_status(port); 539 status = ip22zilog_read_channel_status(port);
540
541 spin_unlock_irqrestore(&port->lock, flags);
542
542 if (status & Tx_BUF_EMP) 543 if (status & Tx_BUF_EMP)
543 ret = TIOCSER_TEMT; 544 ret = TIOCSER_TEMT;
544 else 545 else
@@ -547,7 +548,7 @@ static unsigned int ip22zilog_tx_empty(struct uart_port *port)
547 return ret; 548 return ret;
548} 549}
549 550
550/* The port lock is not held. */ 551/* The port lock is held and interrupts are disabled. */
551static unsigned int ip22zilog_get_mctrl(struct uart_port *port) 552static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
552{ 553{
553 unsigned char status; 554 unsigned char status;
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h
index 777829fa3300..5bf3c45521f4 100644
--- a/drivers/serial/jsm/jsm.h
+++ b/drivers/serial/jsm/jsm.h
@@ -28,7 +28,6 @@
28#define __JSM_DRIVER_H 28#define __JSM_DRIVER_H
29 29
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/version.h>
32#include <linux/types.h> /* To pick up the varions Linux types */ 31#include <linux/types.h> /* To pick up the varions Linux types */
33#include <linux/tty.h> 32#include <linux/tty.h>
34#include <linux/serial_core.h> 33#include <linux/serial_core.h>
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index a2a643318002..e43276c6a954 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1058,12 +1058,9 @@ mpsc_get_mctrl(struct uart_port *port)
1058{ 1058{
1059 struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1059 struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1060 u32 mflags, status; 1060 u32 mflags, status;
1061 ulong iflags;
1062 1061
1063 spin_lock_irqsave(&pi->port.lock, iflags);
1064 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m : 1062 status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m :
1065 readl(pi->mpsc_base + MPSC_CHR_10); 1063 readl(pi->mpsc_base + MPSC_CHR_10);
1066 spin_unlock_irqrestore(&pi->port.lock, iflags);
1067 1064
1068 mflags = 0; 1065 mflags = 0;
1069 if (status & 0x1) 1066 if (status & 0x1)
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 85abd8a045e0..7db2f37532cf 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -604,7 +604,7 @@ static void pmz_set_mctrl(struct uart_port *port, unsigned int mctrl)
604/* 604/*
605 * Get Modem Control bits (only the input ones, the core will 605 * Get Modem Control bits (only the input ones, the core will
606 * or that with a cached value of the control ones) 606 * or that with a cached value of the control ones)
607 * The port lock is not held. 607 * The port lock is held and interrupts are disabled.
608 */ 608 */
609static unsigned int pmz_get_mctrl(struct uart_port *port) 609static unsigned int pmz_get_mctrl(struct uart_port *port)
610{ 610{
@@ -615,7 +615,7 @@ static unsigned int pmz_get_mctrl(struct uart_port *port)
615 if (ZS_IS_ASLEEP(uap) || uap->node == NULL) 615 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
616 return 0; 616 return 0;
617 617
618 status = pmz_peek_status(to_pmz(port)); 618 status = read_zsreg(uap, R0);
619 619
620 ret = 0; 620 ret = 0;
621 if (status & DCD) 621 if (status & DCD)
@@ -1545,7 +1545,7 @@ static void pmz_dispose_port(struct uart_pmac_port *uap)
1545/* 1545/*
1546 * Called upon match with an escc node in the devive-tree. 1546 * Called upon match with an escc node in the devive-tree.
1547 */ 1547 */
1548static int pmz_attach(struct macio_dev *mdev, const struct of_match *match) 1548static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match)
1549{ 1549{
1550 int i; 1550 int i;
1551 1551
@@ -1850,20 +1850,17 @@ err_out:
1850 return rc; 1850 return rc;
1851} 1851}
1852 1852
1853static struct of_match pmz_match[] = 1853static struct of_device_id pmz_match[] =
1854{ 1854{
1855 { 1855 {
1856 .name = "ch-a", 1856 .name = "ch-a",
1857 .type = OF_ANY_MATCH,
1858 .compatible = OF_ANY_MATCH
1859 }, 1857 },
1860 { 1858 {
1861 .name = "ch-b", 1859 .name = "ch-b",
1862 .type = OF_ANY_MATCH,
1863 .compatible = OF_ANY_MATCH
1864 }, 1860 },
1865 {}, 1861 {},
1866}; 1862};
1863MODULE_DEVICE_TABLE (of, pmz_match);
1867 1864
1868static struct macio_driver pmz_driver = 1865static struct macio_driver pmz_driver =
1869{ 1866{
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index 08b08d6ae904..461c81c93207 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -274,14 +274,11 @@ static unsigned int serial_pxa_tx_empty(struct uart_port *port)
274static unsigned int serial_pxa_get_mctrl(struct uart_port *port) 274static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
275{ 275{
276 struct uart_pxa_port *up = (struct uart_pxa_port *)port; 276 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
277 unsigned long flags;
278 unsigned char status; 277 unsigned char status;
279 unsigned int ret; 278 unsigned int ret;
280 279
281return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; 280return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
282 spin_lock_irqsave(&up->port.lock, flags);
283 status = serial_in(up, UART_MSR); 281 status = serial_in(up, UART_MSR);
284 spin_unlock_irqrestore(&up->port.lock, flags);
285 282
286 ret = 0; 283 ret = 0;
287 if (status & UART_MSR_DCD) 284 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 5c4678478b1d..7365d4b50b95 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -522,14 +522,11 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
522static int s3c24xx_serial_startup(struct uart_port *port) 522static int s3c24xx_serial_startup(struct uart_port *port)
523{ 523{
524 struct s3c24xx_uart_port *ourport = to_ourport(port); 524 struct s3c24xx_uart_port *ourport = to_ourport(port);
525 unsigned long flags;
526 int ret; 525 int ret;
527 526
528 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n", 527 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
529 port->mapbase, port->membase); 528 port->mapbase, port->membase);
530 529
531 local_irq_save(flags);
532
533 rx_enabled(port) = 1; 530 rx_enabled(port) = 1;
534 531
535 ret = request_irq(RX_IRQ(port), 532 ret = request_irq(RX_IRQ(port),
@@ -563,12 +560,10 @@ static int s3c24xx_serial_startup(struct uart_port *port)
563 /* the port reset code should have done the correct 560 /* the port reset code should have done the correct
564 * register setup for the port controls */ 561 * register setup for the port controls */
565 562
566 local_irq_restore(flags);
567 return ret; 563 return ret;
568 564
569 err: 565 err:
570 s3c24xx_serial_shutdown(port); 566 s3c24xx_serial_shutdown(port);
571 local_irq_restore(flags);
572 return ret; 567 return ret;
573} 568}
574 569
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 36b1ae083fb7..54699c3a00ab 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -182,6 +182,13 @@ static int uart_startup(struct uart_state *state, int init_hw)
182 uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR); 182 uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
183 } 183 }
184 184
185 if (info->flags & UIF_CTS_FLOW) {
186 spin_lock_irq(&port->lock);
187 if (!(port->ops->get_mctrl(port) & TIOCM_CTS))
188 info->tty->hw_stopped = 1;
189 spin_unlock_irq(&port->lock);
190 }
191
185 info->flags |= UIF_INITIALIZED; 192 info->flags |= UIF_INITIALIZED;
186 193
187 clear_bit(TTY_IO_ERROR, &info->tty->flags); 194 clear_bit(TTY_IO_ERROR, &info->tty->flags);
@@ -828,7 +835,10 @@ static int uart_tiocmget(struct tty_struct *tty, struct file *file)
828 if ((!file || !tty_hung_up_p(file)) && 835 if ((!file || !tty_hung_up_p(file)) &&
829 !(tty->flags & (1 << TTY_IO_ERROR))) { 836 !(tty->flags & (1 << TTY_IO_ERROR))) {
830 result = port->mctrl; 837 result = port->mctrl;
838
839 spin_lock_irq(&port->lock);
831 result |= port->ops->get_mctrl(port); 840 result |= port->ops->get_mctrl(port);
841 spin_unlock_irq(&port->lock);
832 } 842 }
833 up(&state->sem); 843 up(&state->sem);
834 844
@@ -1131,6 +1141,16 @@ static void uart_set_termios(struct tty_struct *tty, struct termios *old_termios
1131 spin_unlock_irqrestore(&state->port->lock, flags); 1141 spin_unlock_irqrestore(&state->port->lock, flags);
1132 } 1142 }
1133 1143
1144 /* Handle turning on CRTSCTS */
1145 if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
1146 spin_lock_irqsave(&state->port->lock, flags);
1147 if (!(state->port->ops->get_mctrl(state->port) & TIOCM_CTS)) {
1148 tty->hw_stopped = 1;
1149 state->port->ops->stop_tx(state->port, 0);
1150 }
1151 spin_unlock_irqrestore(&state->port->lock, flags);
1152 }
1153
1134#if 0 1154#if 0
1135 /* 1155 /*
1136 * No need to wake up processes in open wait, since they 1156 * No need to wake up processes in open wait, since they
@@ -1369,6 +1389,7 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1369 DECLARE_WAITQUEUE(wait, current); 1389 DECLARE_WAITQUEUE(wait, current);
1370 struct uart_info *info = state->info; 1390 struct uart_info *info = state->info;
1371 struct uart_port *port = state->port; 1391 struct uart_port *port = state->port;
1392 unsigned int mctrl;
1372 1393
1373 info->blocked_open++; 1394 info->blocked_open++;
1374 state->count--; 1395 state->count--;
@@ -1416,7 +1437,10 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1416 * and wait for the carrier to indicate that the 1437 * and wait for the carrier to indicate that the
1417 * modem is ready for us. 1438 * modem is ready for us.
1418 */ 1439 */
1419 if (port->ops->get_mctrl(port) & TIOCM_CAR) 1440 spin_lock_irq(&port->lock);
1441 mctrl = port->ops->get_mctrl(port);
1442 spin_unlock_irq(&port->lock);
1443 if (mctrl & TIOCM_CAR)
1420 break; 1444 break;
1421 1445
1422 up(&state->sem); 1446 up(&state->sem);
@@ -1618,7 +1642,9 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
1618 1642
1619 if(capable(CAP_SYS_ADMIN)) 1643 if(capable(CAP_SYS_ADMIN))
1620 { 1644 {
1645 spin_lock_irq(&port->lock);
1621 status = port->ops->get_mctrl(port); 1646 status = port->ops->get_mctrl(port);
1647 spin_unlock_irq(&port->lock);
1622 1648
1623 ret += sprintf(buf + ret, " tx:%d rx:%d", 1649 ret += sprintf(buf + ret, " tx:%d rx:%d",
1624 port->icount.tx, port->icount.rx); 1650 port->icount.tx, port->icount.rx);
@@ -1782,6 +1808,12 @@ uart_set_options(struct uart_port *port, struct console *co,
1782 struct termios termios; 1808 struct termios termios;
1783 int i; 1809 int i;
1784 1810
1811 /*
1812 * Ensure that the serial console lock is initialised
1813 * early.
1814 */
1815 spin_lock_init(&port->lock);
1816
1785 memset(&termios, 0, sizeof(struct termios)); 1817 memset(&termios, 0, sizeof(struct termios));
1786 1818
1787 termios.c_cflag = CREAD | HUPCL | CLOCAL; 1819 termios.c_cflag = CREAD | HUPCL | CLOCAL;
@@ -2170,10 +2202,16 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
2170 2202
2171 state->port = port; 2203 state->port = port;
2172 2204
2173 spin_lock_init(&port->lock);
2174 port->cons = drv->cons; 2205 port->cons = drv->cons;
2175 port->info = state->info; 2206 port->info = state->info;
2176 2207
2208 /*
2209 * If this port is a console, then the spinlock is already
2210 * initialised.
2211 */
2212 if (!uart_console(port))
2213 spin_lock_init(&port->lock);
2214
2177 uart_configure_port(drv, state, port); 2215 uart_configure_port(drv, state, port);
2178 2216
2179 /* 2217 /*
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 0d7b65f93e8d..de0136cc5938 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -45,7 +45,6 @@
45#include <asm/io.h> 45#include <asm/io.h>
46#include <asm/system.h> 46#include <asm/system.h>
47 47
48#include <pcmcia/version.h>
49#include <pcmcia/cs_types.h> 48#include <pcmcia/cs_types.h>
50#include <pcmcia/cs.h> 49#include <pcmcia/cs.h>
51#include <pcmcia/cistpl.h> 50#include <pcmcia/cistpl.h>
@@ -232,11 +231,6 @@ static dev_link_t *serial_attach(void)
232 link->next = dev_list; 231 link->next = dev_list;
233 dev_list = link; 232 dev_list = link;
234 client_reg.dev_info = &dev_info; 233 client_reg.dev_info = &dev_info;
235 client_reg.EventMask =
236 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
237 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
238 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
239 client_reg.event_handler = &serial_event;
240 client_reg.Version = 0x0210; 234 client_reg.Version = 0x0210;
241 client_reg.event_callback_args.client_data = link; 235 client_reg.event_callback_args.client_data = link;
242 ret = pcmcia_register_client(&link->handle, &client_reg); 236 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -772,13 +766,120 @@ serial_event(event_t event, int priority, event_callback_args_t * args)
772 return 0; 766 return 0;
773} 767}
774 768
769static struct pcmcia_device_id serial_ids[] = {
770 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021),
771 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a),
772 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0104, 0x000a),
773 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0xea15),
774 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0109, 0x0501),
775 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0138, 0x110a),
776 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0140, 0x000a),
777 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0x3341),
778 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0xc0ab),
779 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x016c, 0x0081),
780 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x021b, 0x0101),
781 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x08a1, 0xc0ab),
782 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0d0a),
783 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0e0a),
784 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
785 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
786 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
787 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
788 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
789 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
790 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
791 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
792 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
793 PCMCIA_PFC_DEVICE_PROD_ID12(1, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e),
794 PCMCIA_PFC_DEVICE_PROD_ID12(1, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
795 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
796 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
797 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
798 PCMCIA_PFC_DEVICE_PROD_ID12(1, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
799 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
800 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
801 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f),
802 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
803 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
804 PCMCIA_PFC_DEVICE_PROD_ID12(1, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
805 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2),
806 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0104, 0x0070),
807 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0101, 0x0562),
808 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0104, 0x0070),
809 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x016c, 0x0020),
810 PCMCIA_MFC_DEVICE_PROD_ID123(1, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
811 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
812 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
813 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
814 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77),
815 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
816 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301),
817 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039),
818 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006),
819 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a),
820 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d50),
821 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d51),
822 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d52),
823 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d53),
824 PCMCIA_DEVICE_MANF_CARD(0x010b, 0xd180),
825 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x000e),
826 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x001b),
827 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0025),
828 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0045),
829 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0052),
830 PCMCIA_DEVICE_PROD_ID134("ADV", "TECH", "COMpad-32/85", 0x67459937, 0x916d02ba, 0x8fbe92ae),
831 PCMCIA_DEVICE_PROD_ID124("GATEWAY2000", "CC3144", "PCMCIA MODEM", 0x506bccae, 0xcb3685f1, 0xbd6c43ef),
832 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef),
833 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef),
834 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0),
835 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a),
836 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02),
837 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa),
838 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 28800 FAX/DATA MODEM", 0xa3a3062c, 0x8cbd7c76),
839 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 33600 FAX/DATA MODEM", 0xa3a3062c, 0x5a00ce95),
840 PCMCIA_DEVICE_PROD_ID12("Computerboards, Inc.", "PCM-COM422", 0xd0b78f51, 0x7e2d49ed),
841 PCMCIA_DEVICE_PROD_ID12("Dr. Neuhaus", "FURY CARD 14K4", 0x76942813, 0x8b96ce65),
842 PCMCIA_DEVICE_PROD_ID12("Intelligent", "ANGIA FAX/MODEM", 0xb496e65e, 0xf31602a6),
843 PCMCIA_DEVICE_PROD_ID12("Intel", "MODEM 2400", 0x816cc815, 0x23539b80),
844 PCMCIA_DEVICE_PROD_ID12("IOTech Inc ", "PCMCIA Dual RS-232 Serial Port Card", 0x3bd2d898, 0x92abc92f),
845 PCMCIA_DEVICE_PROD_ID12("MACRONIX", "FAX/MODEM", 0x668388b3, 0x3f9bdf2f),
846 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT1432LT", 0x5f73be51, 0x0b3e2383),
847 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT2834LT", 0x5f73be51, 0x4cd7c09e),
848 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
849 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
850 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
851 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
852 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
853 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
854 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "PCMLM28.cis"),
855 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "PCMLM28.cis"),
856 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(1, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "DP83903.cis"),
857 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(1, "NSC MF LAN/Modem", 0x58fc6056, "DP83903.cis"),
858 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0556, "3CCFEM556.cis"),
859 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0175, 0x0000, "DP83903.cis"),
860 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0035, "3CXEM556.cis"),
861 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x003d, "3CXEM556.cis"),
862 PCMCIA_DEVICE_CIS_PROD_ID12("MultiTech", "PCMCIA 56K DataFax", 0x842047ee, 0xc2efcf03, "MT5634ZLX.cis"),
863 PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-4", 0x96913a85, 0xcec8f102, "COMpad4.cis"),
864 PCMCIA_DEVICE_CIS_PROD_ID123("ADVANTECH", "COMpad-32/85", "1.0", 0x96913a85, 0x8fbe92ae, 0x0877b627, "COMpad2.cis"),
865 PCMCIA_DEVICE_CIS_PROD_ID2("RS-COM 2P", 0xad20b156, "RS-COM-2P.cis"),
866 /* too generic */
867 /* PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0160, 0x0002), */
868 /* PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0160, 0x0002), */
869 PCMCIA_DEVICE_FUNC_ID(2),
870 PCMCIA_DEVICE_NULL,
871};
872MODULE_DEVICE_TABLE(pcmcia, serial_ids);
873
775static struct pcmcia_driver serial_cs_driver = { 874static struct pcmcia_driver serial_cs_driver = {
776 .owner = THIS_MODULE, 875 .owner = THIS_MODULE,
777 .drv = { 876 .drv = {
778 .name = "serial_cs", 877 .name = "serial_cs",
779 }, 878 },
780 .attach = serial_attach, 879 .attach = serial_attach,
880 .event = serial_event,
781 .detach = serial_detach, 881 .detach = serial_detach,
882 .id_table = serial_ids,
782}; 883};
783 884
784static int __init init_serial_cs(void) 885static int __init init_serial_cs(void)
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 3f1051a4a13f..d085030df70b 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -442,13 +442,10 @@ static unsigned int serial_txx9_tx_empty(struct uart_port *port)
442static unsigned int serial_txx9_get_mctrl(struct uart_port *port) 442static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
443{ 443{
444 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 444 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
445 unsigned long flags;
446 unsigned int ret; 445 unsigned int ret;
447 446
448 spin_lock_irqsave(&up->port.lock, flags);
449 ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS) 447 ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
450 | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS); 448 | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
451 spin_unlock_irqrestore(&up->port.lock, flags);
452 449
453 return ret; 450 return ret;
454} 451}
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 10e2990a40d4..8d198880756a 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -426,18 +426,15 @@ static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl)
426 sunsab_tx_idle(up); 426 sunsab_tx_idle(up);
427} 427}
428 428
429/* port->lock is not held. */ 429/* port->lock is held by caller and interrupts are disabled. */
430static unsigned int sunsab_get_mctrl(struct uart_port *port) 430static unsigned int sunsab_get_mctrl(struct uart_port *port)
431{ 431{
432 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 432 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
433 unsigned long flags;
434 unsigned char val; 433 unsigned char val;
435 unsigned int result; 434 unsigned int result;
436 435
437 result = 0; 436 result = 0;
438 437
439 spin_lock_irqsave(&up->port.lock, flags);
440
441 val = readb(&up->regs->r.pvr); 438 val = readb(&up->regs->r.pvr);
442 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR; 439 result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR;
443 440
@@ -447,8 +444,6 @@ static unsigned int sunsab_get_mctrl(struct uart_port *port)
447 val = readb(&up->regs->r.star); 444 val = readb(&up->regs->r.star);
448 result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0; 445 result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0;
449 446
450 spin_unlock_irqrestore(&up->port.lock, flags);
451
452 return result; 447 return result;
453} 448}
454 449
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index ddc97c905e14..d57a3553aea3 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -572,13 +572,10 @@ static unsigned int sunsu_tx_empty(struct uart_port *port)
572static unsigned int sunsu_get_mctrl(struct uart_port *port) 572static unsigned int sunsu_get_mctrl(struct uart_port *port)
573{ 573{
574 struct uart_sunsu_port *up = (struct uart_sunsu_port *) port; 574 struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
575 unsigned long flags;
576 unsigned char status; 575 unsigned char status;
577 unsigned int ret; 576 unsigned int ret;
578 577
579 spin_lock_irqsave(&up->port.lock, flags);
580 status = serial_in(up, UART_MSR); 578 status = serial_in(up, UART_MSR);
581 spin_unlock_irqrestore(&up->port.lock, flags);
582 579
583 ret = 0; 580 ret = 0;
584 if (status & UART_MSR_DCD) 581 if (status & UART_MSR_DCD)
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 8e65206d3d76..bff42a7b89d0 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -610,27 +610,28 @@ static irqreturn_t sunzilog_interrupt(int irq, void *dev_id, struct pt_regs *reg
610static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port) 610static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
611{ 611{
612 struct zilog_channel __iomem *channel; 612 struct zilog_channel __iomem *channel;
613 unsigned long flags;
614 unsigned char status; 613 unsigned char status;
615 614
616 spin_lock_irqsave(&port->lock, flags);
617
618 channel = ZILOG_CHANNEL_FROM_PORT(port); 615 channel = ZILOG_CHANNEL_FROM_PORT(port);
619 status = sbus_readb(&channel->control); 616 status = sbus_readb(&channel->control);
620 ZSDELAY(); 617 ZSDELAY();
621 618
622 spin_unlock_irqrestore(&port->lock, flags);
623
624 return status; 619 return status;
625} 620}
626 621
627/* The port lock is not held. */ 622/* The port lock is not held. */
628static unsigned int sunzilog_tx_empty(struct uart_port *port) 623static unsigned int sunzilog_tx_empty(struct uart_port *port)
629{ 624{
625 unsigned long flags;
630 unsigned char status; 626 unsigned char status;
631 unsigned int ret; 627 unsigned int ret;
632 628
629 spin_lock_irqsave(&port->lock, flags);
630
633 status = sunzilog_read_channel_status(port); 631 status = sunzilog_read_channel_status(port);
632
633 spin_unlock_irqrestore(&port->lock, flags);
634
634 if (status & Tx_BUF_EMP) 635 if (status & Tx_BUF_EMP)
635 ret = TIOCSER_TEMT; 636 ret = TIOCSER_TEMT;
636 else 637 else
@@ -639,7 +640,7 @@ static unsigned int sunzilog_tx_empty(struct uart_port *port)
639 return ret; 640 return ret;
640} 641}
641 642
642/* The port lock is not held. */ 643/* The port lock is held and interrupts are disabled. */
643static unsigned int sunzilog_get_mctrl(struct uart_port *port) 644static unsigned int sunzilog_get_mctrl(struct uart_port *port)
644{ 645{
645 unsigned char status; 646 unsigned char status;
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index e1ef0d7ee8d1..57c0c6e3fbed 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -9,7 +9,6 @@
9#include <linux/errno.h> /* error codes */ 9#include <linux/errno.h> /* error codes */
10#include <linux/slab.h> 10#include <linux/slab.h>
11 11
12#include <pcmcia/version.h>
13#include <pcmcia/cs_types.h> 12#include <pcmcia/cs_types.h>
14#include <pcmcia/cs.h> 13#include <pcmcia/cs.h>
15#include <pcmcia/cistpl.h> 14#include <pcmcia/cistpl.h>
@@ -69,11 +68,6 @@ static dev_link_t *ixj_attach(void)
69 link->next = dev_list; 68 link->next = dev_list;
70 dev_list = link; 69 dev_list = link;
71 client_reg.dev_info = &dev_info; 70 client_reg.dev_info = &dev_info;
72 client_reg.EventMask =
73 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
74 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
75 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
76 client_reg.event_handler = &ixj_event;
77 client_reg.Version = 0x0210; 71 client_reg.Version = 0x0210;
78 client_reg.event_callback_args.client_data = link; 72 client_reg.event_callback_args.client_data = link;
79 ret = pcmcia_register_client(&link->handle, &client_reg); 73 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -295,13 +289,21 @@ static int ixj_event(event_t event, int priority, event_callback_args_t * args)
295 return 0; 289 return 0;
296} 290}
297 291
292static struct pcmcia_device_id ixj_ids[] = {
293 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
294 PCMCIA_DEVICE_NULL
295};
296MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
297
298static struct pcmcia_driver ixj_driver = { 298static struct pcmcia_driver ixj_driver = {
299 .owner = THIS_MODULE, 299 .owner = THIS_MODULE,
300 .drv = { 300 .drv = {
301 .name = "ixj_cs", 301 .name = "ixj_cs",
302 }, 302 },
303 .attach = ixj_attach, 303 .attach = ixj_attach,
304 .event = ixj_event,
304 .detach = ixj_detach, 305 .detach = ixj_detach,
306 .id_table = ixj_ids,
305}; 307};
306 308
307static int __init ixj_pcmcia_init(void) 309static int __init ixj_pcmcia_init(void)
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index a61d4433a989..df014c2a7c54 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB) += core/
9obj-$(CONFIG_USB_MON) += mon/ 9obj-$(CONFIG_USB_MON) += mon/
10 10
11obj-$(CONFIG_USB_EHCI_HCD) += host/ 11obj-$(CONFIG_USB_EHCI_HCD) += host/
12obj-$(CONFIG_USB_ISP116X_HCD) += host/
12obj-$(CONFIG_USB_OHCI_HCD) += host/ 13obj-$(CONFIG_USB_OHCI_HCD) += host/
13obj-$(CONFIG_USB_UHCI_HCD) += host/ 14obj-$(CONFIG_USB_UHCI_HCD) += host/
14obj-$(CONFIG_USB_SL811_HCD) += host/ 15obj-$(CONFIG_USB_SL811_HCD) += host/
@@ -31,6 +32,7 @@ obj-$(CONFIG_USB_MOUSE) += input/
31obj-$(CONFIG_USB_MTOUCH) += input/ 32obj-$(CONFIG_USB_MTOUCH) += input/
32obj-$(CONFIG_USB_POWERMATE) += input/ 33obj-$(CONFIG_USB_POWERMATE) += input/
33obj-$(CONFIG_USB_WACOM) += input/ 34obj-$(CONFIG_USB_WACOM) += input/
35obj-$(CONFIG_USB_ACECAD) += input/
34obj-$(CONFIG_USB_XPAD) += input/ 36obj-$(CONFIG_USB_XPAD) += input/
35 37
36obj-$(CONFIG_USB_DABUSB) += media/ 38obj-$(CONFIG_USB_DABUSB) += media/
@@ -63,12 +65,14 @@ obj-$(CONFIG_USB_EMI26) += misc/
63obj-$(CONFIG_USB_EMI62) += misc/ 65obj-$(CONFIG_USB_EMI62) += misc/
64obj-$(CONFIG_USB_IDMOUSE) += misc/ 66obj-$(CONFIG_USB_IDMOUSE) += misc/
65obj-$(CONFIG_USB_LCD) += misc/ 67obj-$(CONFIG_USB_LCD) += misc/
68obj-$(CONFIG_USB_LD) += misc/
66obj-$(CONFIG_USB_LED) += misc/ 69obj-$(CONFIG_USB_LED) += misc/
67obj-$(CONFIG_USB_LEGOTOWER) += misc/ 70obj-$(CONFIG_USB_LEGOTOWER) += misc/
68obj-$(CONFIG_USB_RIO500) += misc/ 71obj-$(CONFIG_USB_RIO500) += misc/
69obj-$(CONFIG_USB_TEST) += misc/ 72obj-$(CONFIG_USB_TEST) += misc/
70obj-$(CONFIG_USB_USS720) += misc/ 73obj-$(CONFIG_USB_USS720) += misc/
71obj-$(CONFIG_USB_PHIDGETSERVO) += misc/ 74obj-$(CONFIG_USB_PHIDGETSERVO) += misc/
75obj-$(CONFIG_USB_SISUSBVGA) += misc/
72 76
73obj-$(CONFIG_USB_ATM) += atm/ 77obj-$(CONFIG_USB_ATM) += atm/
74obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 78obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig
index 0d9f5379b8cf..f429862e0974 100644
--- a/drivers/usb/atm/Kconfig
+++ b/drivers/usb/atm/Kconfig
@@ -1,30 +1,60 @@
1# 1#
2# USB ATM driver configuration 2# USB/ATM DSL configuration
3# 3#
4comment "USB ATM/DSL drivers" 4
5menu "USB DSL modem support"
5 depends on USB 6 depends on USB
6 7
7config USB_ATM 8config USB_ATM
8 tristate "Generic USB ATM/DSL core I/O support" 9 tristate "USB DSL modem support"
9 depends on USB && ATM 10 depends on USB && ATM
10 select CRC32 11 select CRC32
11 default n 12 default n
12 help 13 help
13 This provides a library which is used for packet I/O by USB DSL 14 Say Y here if you want to connect a USB Digital Subscriber Line (DSL)
14 modems, such as the SpeedTouch driver below. 15 modem to your computer's USB port. You will then need to choose your
16 modem from the list below.
15 17
16 To compile this driver as a module, choose M here: the 18 To compile this driver as a module, choose M here: the
17 module will be called usb_atm. 19 module will be called usbatm.
18 20
19config USB_SPEEDTOUCH 21config USB_SPEEDTOUCH
20 tristate "Alcatel Speedtouch USB support" 22 tristate "Speedtouch USB support"
21 depends on USB && ATM 23 depends on USB_ATM
22 select USB_ATM 24 select FW_LOADER
23 help 25 help
24 Say Y here if you have an Alcatel SpeedTouch USB or SpeedTouch 330 26 Say Y here if you have an SpeedTouch USB or SpeedTouch 330
25 modem. In order to use your modem you will need to install the 27 modem. In order to use your modem you will need to install the
26 two parts of the firmware, extracted by the user space tools; see 28 two parts of the firmware, extracted by the user space tools; see
27 <http://www.linux-usb.org/SpeedTouch/> for details. 29 <http://www.linux-usb.org/SpeedTouch/> for details.
28 30
29 To compile this driver as a module, choose M here: the 31 To compile this driver as a module, choose M here: the
30 module will be called speedtch. 32 module will be called speedtch.
33
34config USB_CXACRU
35 tristate "Conexant AccessRunner USB support"
36 depends on USB_ATM
37 select FW_LOADER
38 help
39 Say Y here if you have an ADSL USB modem based on the Conexant
40 AccessRunner chipset. In order to use your modem you will need to
41 install the firmware, extracted by the user space tools; see
42 <http://accessrunner.sourceforge.net/> for details.
43
44 To compile this driver as a module, choose M here: the
45 module will be called cxacru.
46
47config USB_XUSBATM
48 tristate "Other USB DSL modem support"
49 depends on USB_ATM
50 help
51 Say Y here if you have a DSL USB modem not explicitly supported by
52 another USB DSL drivers. In order to use your modem you will need to
53 pass the vendor ID, product ID, and endpoint numbers for transmission
54 and reception as module parameters. You may need to initialize the
55 the modem using a user space utility (a firmware loader for example).
56
57 To compile this driver as a module, choose M here: the
58 module will be called xusbatm.
59
60endmenu
diff --git a/drivers/usb/atm/Makefile b/drivers/usb/atm/Makefile
index 9213b8b97587..751f297be2ef 100644
--- a/drivers/usb/atm/Makefile
+++ b/drivers/usb/atm/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# Makefile for the rest of the USB drivers 2# Makefile for USB ATM/xDSL drivers
3# (the ones that don't fit into any other categories)
4# 3#
5 4
6obj-$(CONFIG_USB_ATM) += usb_atm.o 5obj-$(CONFIG_USB_CXACRU) += cxacru.o
7obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o 6obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o
7obj-$(CONFIG_USB_ATM) += usbatm.o
8obj-$(CONFIG_USB_XUSBATM) += xusbatm.o
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
new file mode 100644
index 000000000000..8e184e2641cb
--- /dev/null
+++ b/drivers/usb/atm/cxacru.c
@@ -0,0 +1,878 @@
1/******************************************************************************
2 * cxacru.c - driver for USB ADSL modems based on
3 * Conexant AccessRunner chipset
4 *
5 * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
6 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Credit is due for Josep Comas, who created the original patch to speedtch.c
26 * to support the different padding used by the AccessRunner (now generalized
27 * into usbatm), and the userspace firmware loading utility.
28 */
29
30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h>
33#include <linux/timer.h>
34#include <linux/errno.h>
35#include <linux/slab.h>
36#include <linux/init.h>
37#include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */
38#include <linux/firmware.h>
39
40#include "usbatm.h"
41
42#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands"
43#define DRIVER_VERSION "0.2"
44#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
45
46static const char cxacru_driver_name[] = "cxacru";
47
48#define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
49#define CXACRU_EP_DATA 0x02 /* Bulk in/out */
50
51#define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
52
53/* Addresses */
54#define PLLFCLK_ADDR 0x00350068
55#define PLLBCLK_ADDR 0x0035006c
56#define SDRAMEN_ADDR 0x00350010
57#define FW_ADDR 0x00801000
58#define BR_ADDR 0x00180600
59#define SIG_ADDR 0x00180500
60#define BR_STACK_ADDR 0x00187f10
61
62/* Values */
63#define SDRAM_ENA 0x1
64
65#define CMD_TIMEOUT 2000 /* msecs */
66#define POLL_INTERVAL 5000 /* msecs */
67
68/* commands for interaction with the modem through the control channel before
69 * firmware is loaded */
70enum cxacru_fw_request {
71 FW_CMD_ERR,
72 FW_GET_VER,
73 FW_READ_MEM,
74 FW_WRITE_MEM,
75 FW_RMW_MEM,
76 FW_CHECKSUM_MEM,
77 FW_GOTO_MEM,
78};
79
80/* commands for interaction with the modem through the control channel once
81 * firmware is loaded */
82enum cxacru_cm_request {
83 CM_REQUEST_UNDEFINED = 0x80,
84 CM_REQUEST_TEST,
85 CM_REQUEST_CHIP_GET_MAC_ADDRESS,
86 CM_REQUEST_CHIP_GET_DP_VERSIONS,
87 CM_REQUEST_CHIP_ADSL_LINE_START,
88 CM_REQUEST_CHIP_ADSL_LINE_STOP,
89 CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
90 CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
91 CM_REQUEST_CARD_INFO_GET,
92 CM_REQUEST_CARD_DATA_GET,
93 CM_REQUEST_CARD_DATA_SET,
94 CM_REQUEST_COMMAND_HW_IO,
95 CM_REQUEST_INTERFACE_HW_IO,
96 CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
97 CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
98 CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
99 CM_REQUEST_CARD_GET_STATUS,
100 CM_REQUEST_CARD_GET_MAC_ADDRESS,
101 CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
102 CM_REQUEST_MAX,
103};
104
105/* reply codes to the commands above */
106enum cxacru_cm_status {
107 CM_STATUS_UNDEFINED,
108 CM_STATUS_SUCCESS,
109 CM_STATUS_ERROR,
110 CM_STATUS_UNSUPPORTED,
111 CM_STATUS_UNIMPLEMENTED,
112 CM_STATUS_PARAMETER_ERROR,
113 CM_STATUS_DBG_LOOPBACK,
114 CM_STATUS_MAX,
115};
116
117/* indices into CARD_INFO_GET return array */
118enum cxacru_info_idx {
119 CXINF_DOWNSTREAM_RATE,
120 CXINF_UPSTREAM_RATE,
121 CXINF_LINK_STATUS,
122 CXINF_LINE_STATUS,
123 CXINF_MAC_ADDRESS_HIGH,
124 CXINF_MAC_ADDRESS_LOW,
125 CXINF_UPSTREAM_SNR_MARGIN,
126 CXINF_DOWNSTREAM_SNR_MARGIN,
127 CXINF_UPSTREAM_ATTENUATION,
128 CXINF_DOWNSTREAM_ATTENUATION,
129 CXINF_TRANSMITTER_POWER,
130 CXINF_UPSTREAM_BITS_PER_FRAME,
131 CXINF_DOWNSTREAM_BITS_PER_FRAME,
132 CXINF_STARTUP_ATTEMPTS,
133 CXINF_UPSTREAM_CRC_ERRORS,
134 CXINF_DOWNSTREAM_CRC_ERRORS,
135 CXINF_UPSTREAM_FEC_ERRORS,
136 CXINF_DOWNSTREAM_FEC_ERRORS,
137 CXINF_UPSTREAM_HEC_ERRORS,
138 CXINF_DOWNSTREAM_HEC_ERRORS,
139 CXINF_LINE_STARTABLE,
140 CXINF_MODULATION,
141 CXINF_ADSL_HEADEND,
142 CXINF_ADSL_HEADEND_ENVIRONMENT,
143 CXINF_CONTROLLER_VERSION,
144 /* dunno what the missing two mean */
145 CXINF_MAX = 0x1c,
146};
147
148struct cxacru_modem_type {
149 u32 pll_f_clk;
150 u32 pll_b_clk;
151 int boot_rom_patch;
152};
153
154struct cxacru_data {
155 struct usbatm_data *usbatm;
156
157 const struct cxacru_modem_type *modem_type;
158
159 int line_status;
160 struct work_struct poll_work;
161
162 /* contol handles */
163 struct semaphore cm_serialize;
164 u8 *rcv_buf;
165 u8 *snd_buf;
166 struct urb *rcv_urb;
167 struct urb *snd_urb;
168 struct completion rcv_done;
169 struct completion snd_done;
170};
171
172/* the following three functions are stolen from drivers/usb/core/message.c */
173static void cxacru_blocking_completion(struct urb *urb, struct pt_regs *regs)
174{
175 complete((struct completion *)urb->context);
176}
177
178static void cxacru_timeout_kill(unsigned long data)
179{
180 usb_unlink_urb((struct urb *) data);
181}
182
183static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
184 int* actual_length)
185{
186 struct timer_list timer;
187 int status;
188
189 init_timer(&timer);
190 timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
191 timer.data = (unsigned long) urb;
192 timer.function = cxacru_timeout_kill;
193 add_timer(&timer);
194 wait_for_completion(done);
195 status = urb->status;
196 if (status == -ECONNRESET)
197 status = -ETIMEDOUT;
198 del_timer_sync(&timer);
199
200 if (actual_length)
201 *actual_length = urb->actual_length;
202 return status;
203}
204
205static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
206 u8 *wdata, int wsize, u8 *rdata, int rsize)
207{
208 int ret, actlen;
209 int offb, offd;
210 const int stride = CMD_PACKET_SIZE - 4;
211 u8 *wbuf = instance->snd_buf;
212 u8 *rbuf = instance->rcv_buf;
213 int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
214 int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
215
216 if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
217 dbg("too big transfer requested");
218 ret = -ENOMEM;
219 goto fail;
220 }
221
222 down(&instance->cm_serialize);
223
224 /* submit reading urb before the writing one */
225 init_completion(&instance->rcv_done);
226 ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
227 if (ret < 0) {
228 dbg("submitting read urb for cm %#x failed", cm);
229 ret = ret;
230 goto fail;
231 }
232
233 memset(wbuf, 0, wbuflen);
234 /* handle wsize == 0 */
235 wbuf[0] = cm;
236 for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
237 wbuf[offb] = cm;
238 memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
239 }
240
241 instance->snd_urb->transfer_buffer_length = wbuflen;
242 init_completion(&instance->snd_done);
243 ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
244 if (ret < 0) {
245 dbg("submitting write urb for cm %#x failed", cm);
246 ret = ret;
247 goto fail;
248 }
249
250 ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
251 if (ret < 0) {
252 dbg("sending cm %#x failed", cm);
253 ret = ret;
254 goto fail;
255 }
256
257 ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
258 if (ret < 0) {
259 dbg("receiving cm %#x failed", cm);
260 ret = ret;
261 goto fail;
262 }
263 if (actlen % CMD_PACKET_SIZE || !actlen) {
264 dbg("response is not a positive multiple of %d: %#x",
265 CMD_PACKET_SIZE, actlen);
266 ret = -EIO;
267 goto fail;
268 }
269
270 /* check the return status and copy the data to the output buffer, if needed */
271 for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
272 if (rbuf[offb] != cm) {
273 dbg("wrong cm %#x in response", rbuf[offb]);
274 ret = -EIO;
275 goto fail;
276 }
277 if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
278 dbg("response failed: %#x", rbuf[offb + 1]);
279 ret = -EIO;
280 goto fail;
281 }
282 if (offd >= rsize)
283 break;
284 memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
285 offd += stride;
286 }
287
288 ret = offd;
289 dbg("cm %#x", cm);
290fail:
291 up(&instance->cm_serialize);
292 return ret;
293}
294
295static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
296 u32 *data, int size)
297{
298 int ret, len;
299 u32 *buf;
300 int offb, offd;
301 const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
302 int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
303
304 buf = kmalloc(buflen, GFP_KERNEL);
305 if (!buf)
306 return -ENOMEM;
307
308 ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
309 if (ret < 0)
310 goto cleanup;
311
312 /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
313 len = ret / 4;
314 for (offb = 0; offb < len; ) {
315 int l = le32_to_cpu(buf[offb++]);
316 if (l > stride || l > (len - offb) / 2) {
317 dbg("wrong data length %#x in response", l);
318 ret = -EIO;
319 goto cleanup;
320 }
321 while (l--) {
322 offd = le32_to_cpu(buf[offb++]);
323 if (offd >= size) {
324 dbg("wrong index %#x in response", offd);
325 ret = -EIO;
326 goto cleanup;
327 }
328 data[offd] = le32_to_cpu(buf[offb++]);
329 }
330 }
331
332 ret = 0;
333
334cleanup:
335 kfree(buf);
336 return ret;
337}
338
339static int cxacru_card_status(struct cxacru_data *instance)
340{
341 int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
342 if (ret < 0) { /* firmware not loaded */
343 dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
344 return ret;
345 }
346 return 0;
347}
348
349static void cxacru_poll_status(struct cxacru_data *instance);
350
351static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
352 struct atm_dev *atm_dev)
353{
354 struct cxacru_data *instance = usbatm_instance->driver_data;
355 struct device *dev = &usbatm_instance->usb_intf->dev;
356 /*
357 struct atm_dev *atm_dev = usbatm_instance->atm_dev;
358 */
359 int ret;
360
361 dbg("cxacru_atm_start");
362
363 /* Read MAC address */
364 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
365 atm_dev->esi, sizeof(atm_dev->esi));
366 if (ret < 0) {
367 dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
368 return ret;
369 }
370
371 /* start ADSL */
372 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
373 if (ret < 0) {
374 dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
375 return ret;
376 }
377
378 /* Start status polling */
379 cxacru_poll_status(instance);
380 return 0;
381}
382
383static void cxacru_poll_status(struct cxacru_data *instance)
384{
385 u32 buf[CXINF_MAX] = {};
386 struct device *dev = &instance->usbatm->usb_intf->dev;
387 struct atm_dev *atm_dev = instance->usbatm->atm_dev;
388 int ret;
389
390 ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
391 if (ret < 0) {
392 dev_warn(dev, "poll status: error %d\n", ret);
393 goto reschedule;
394 }
395
396 if (instance->line_status == buf[CXINF_LINE_STATUS])
397 goto reschedule;
398
399 instance->line_status = buf[CXINF_LINE_STATUS];
400 switch (instance->line_status) {
401 case 0:
402 atm_dev->signal = ATM_PHY_SIG_LOST;
403 dev_info(dev, "ADSL line: down\n");
404 break;
405
406 case 1:
407 atm_dev->signal = ATM_PHY_SIG_LOST;
408 dev_info(dev, "ADSL line: attemtping to activate\n");
409 break;
410
411 case 2:
412 atm_dev->signal = ATM_PHY_SIG_LOST;
413 dev_info(dev, "ADSL line: training\n");
414 break;
415
416 case 3:
417 atm_dev->signal = ATM_PHY_SIG_LOST;
418 dev_info(dev, "ADSL line: channel analysis\n");
419 break;
420
421 case 4:
422 atm_dev->signal = ATM_PHY_SIG_LOST;
423 dev_info(dev, "ADSL line: exchange\n");
424 break;
425
426 case 5:
427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
428 atm_dev->signal = ATM_PHY_SIG_FOUND;
429
430 dev_info(dev, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
432 break;
433
434 case 6:
435 atm_dev->signal = ATM_PHY_SIG_LOST;
436 dev_info(dev, "ADSL line: waiting\n");
437 break;
438
439 case 7:
440 atm_dev->signal = ATM_PHY_SIG_LOST;
441 dev_info(dev, "ADSL line: initializing\n");
442 break;
443
444 default:
445 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
446 dev_info(dev, "Unknown line state %02x\n", instance->line_status);
447 break;
448 }
449reschedule:
450 schedule_delayed_work(&instance->poll_work, msecs_to_jiffies(POLL_INTERVAL));
451}
452
453static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
454 u8 code1, u8 code2, u32 addr, u8 *data, int size)
455{
456 int ret;
457 u8 *buf;
458 int offd, offb;
459 const int stride = CMD_PACKET_SIZE - 8;
460
461 buf = (u8 *) __get_free_page(GFP_KERNEL);
462 if (!buf)
463 return -ENOMEM;
464
465 offb = offd = 0;
466 do {
467 int l = min_t(int, stride, size - offd);
468 buf[offb++] = fw;
469 buf[offb++] = l;
470 buf[offb++] = code1;
471 buf[offb++] = code2;
472 *((u32 *) (buf + offb)) = cpu_to_le32(addr);
473 offb += 4;
474 addr += l;
475 if(l)
476 memcpy(buf + offb, data + offd, l);
477 if (l < stride)
478 memset(buf + offb + l, 0, stride - l);
479 offb += stride;
480 offd += stride;
481 if ((offb >= PAGE_SIZE) || (offd >= size)) {
482 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
483 buf, offb, NULL, CMD_TIMEOUT);
484 if (ret < 0) {
485 dbg("sending fw %#x failed", fw);
486 goto cleanup;
487 }
488 offb = 0;
489 }
490 } while(offd < size);
491 dbg("sent fw %#x", fw);
492
493 ret = 0;
494
495cleanup:
496 free_page((unsigned long) buf);
497 return ret;
498}
499
500static void cxacru_upload_firmware(struct cxacru_data *instance,
501 const struct firmware *fw,
502 const struct firmware *bp,
503 const struct firmware *cf)
504{
505 int ret;
506 int off;
507 struct usb_device *usb_dev = instance->usbatm->usb_dev;
508 struct device *dev = &instance->usbatm->usb_intf->dev;
509 u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };
510 u32 val;
511
512 dbg("cxacru_upload_firmware");
513
514 /* FirmwarePllFClkValue */
515 val = cpu_to_le32(instance->modem_type->pll_f_clk);
516 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
517 if (ret) {
518 dev_err(dev, "FirmwarePllFClkValue failed: %d\n", ret);
519 return;
520 }
521
522 /* FirmwarePllBClkValue */
523 val = cpu_to_le32(instance->modem_type->pll_b_clk);
524 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
525 if (ret) {
526 dev_err(dev, "FirmwarePllBClkValue failed: %d\n", ret);
527 return;
528 }
529
530 /* Enable SDRAM */
531 val = cpu_to_le32(SDRAM_ENA);
532 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
533 if (ret) {
534 dev_err(dev, "Enable SDRAM failed: %d\n", ret);
535 return;
536 }
537
538 /* Firmware */
539 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
540 if (ret) {
541 dev_err(dev, "Firmware upload failed: %d\n", ret);
542 return;
543 }
544
545 /* Boot ROM patch */
546 if (instance->modem_type->boot_rom_patch) {
547 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
548 if (ret) {
549 dev_err(dev, "Boot ROM patching failed: %d\n", ret);
550 return;
551 }
552 }
553
554 /* Signature */
555 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
556 if (ret) {
557 dev_err(dev, "Signature storing failed: %d\n", ret);
558 return;
559 }
560
561 if (instance->modem_type->boot_rom_patch) {
562 val = cpu_to_le32(BR_ADDR);
563 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
564 }
565 else {
566 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
567 }
568 if (ret) {
569 dev_err(dev, "Passing control to firmware failed: %d\n", ret);
570 return;
571 }
572
573 /* Delay to allow firmware to start up. */
574 msleep_interruptible(1000);
575
576 usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
577 usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
578 usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
579 usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
580
581 ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
582 if (ret < 0) {
583 dev_err(dev, "modem failed to initialize: %d\n", ret);
584 return;
585 }
586
587 /* Load config data (le32), doing one packet at a time */
588 if (cf)
589 for (off = 0; off < cf->size / 4; ) {
590 u32 buf[CMD_PACKET_SIZE / 4 - 1];
591 int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
592 buf[0] = cpu_to_le32(len);
593 for (i = 0; i < len; i++, off++) {
594 buf[i * 2 + 1] = cpu_to_le32(off);
595 memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
596 }
597 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
598 (u8 *) buf, len, NULL, 0);
599 if (ret < 0) {
600 dev_err(dev, "load config data failed: %d\n", ret);
601 return;
602 }
603 }
604
605 msleep_interruptible(4000);
606}
607
608static int cxacru_find_firmware(struct cxacru_data *instance,
609 char* phase, const struct firmware **fw_p)
610{
611 struct device *dev = &instance->usbatm->usb_intf->dev;
612 char buf[16];
613
614 sprintf(buf, "cxacru-%s.bin", phase);
615 dbg("cxacru_find_firmware: looking for %s", buf);
616
617 if (request_firmware(fw_p, buf, dev)) {
618 dev_dbg(dev, "no stage %s firmware found\n", phase);
619 return -ENOENT;
620 }
621
622 dev_info(dev, "found firmware %s\n", buf);
623
624 return 0;
625}
626
627static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
628 struct usb_interface *usb_intf)
629{
630 struct device *dev = &usbatm_instance->usb_intf->dev;
631 const struct firmware *fw, *bp, *cf;
632 struct cxacru_data *instance = usbatm_instance->driver_data;
633
634 int ret = cxacru_find_firmware(instance, "fw", &fw);
635 if (ret) {
636 dev_warn(dev, "firmware (cxacru-fw.bin) unavailable (hotplug misconfiguration?)\n");
637 return ret;
638 }
639
640 if (instance->modem_type->boot_rom_patch) {
641 ret = cxacru_find_firmware(instance, "bp", &bp);
642 if (ret) {
643 dev_warn(dev, "boot ROM patch (cxacru-bp.bin) unavailable (hotplug misconfiguration?)\n");
644 release_firmware(fw);
645 return ret;
646 }
647 }
648
649 if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
650 cf = NULL;
651
652 cxacru_upload_firmware(instance, fw, bp, cf);
653
654 if (cf)
655 release_firmware(cf);
656 if (instance->modem_type->boot_rom_patch)
657 release_firmware(bp);
658 release_firmware(fw);
659
660 ret = cxacru_card_status(instance);
661 if (ret)
662 dbg("modem initialisation failed");
663 else
664 dbg("done setting up the modem");
665
666 return ret;
667}
668
669static int cxacru_bind(struct usbatm_data *usbatm_instance,
670 struct usb_interface *intf, const struct usb_device_id *id,
671 int *need_heavy_init)
672{
673 struct cxacru_data *instance;
674 struct usb_device *usb_dev = interface_to_usbdev(intf);
675 int ret;
676
677 /* instance init */
678 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
679 if (!instance) {
680 dbg("cxacru_bind: no memory for instance data");
681 return -ENOMEM;
682 }
683
684 memset(instance, 0, sizeof(*instance));
685
686 instance->usbatm = usbatm_instance;
687 instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
688
689 instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
690 if (!instance->rcv_buf) {
691 dbg("cxacru_bind: no memory for rcv_buf");
692 ret = -ENOMEM;
693 goto fail;
694 }
695 instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
696 if (!instance->snd_buf) {
697 dbg("cxacru_bind: no memory for snd_buf");
698 ret = -ENOMEM;
699 goto fail;
700 }
701 instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
702 if (!instance->rcv_urb) {
703 dbg("cxacru_bind: no memory for rcv_urb");
704 ret = -ENOMEM;
705 goto fail;
706 }
707 instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
708 if (!instance->snd_urb) {
709 dbg("cxacru_bind: no memory for snd_urb");
710 ret = -ENOMEM;
711 goto fail;
712 }
713
714 usb_fill_int_urb(instance->rcv_urb,
715 usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
716 instance->rcv_buf, PAGE_SIZE,
717 cxacru_blocking_completion, &instance->rcv_done, 1);
718 instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK;
719
720 usb_fill_int_urb(instance->snd_urb,
721 usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
722 instance->snd_buf, PAGE_SIZE,
723 cxacru_blocking_completion, &instance->snd_done, 4);
724 instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK;
725
726 init_MUTEX(&instance->cm_serialize);
727
728 INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
729
730 usbatm_instance->driver_data = instance;
731
732 *need_heavy_init = cxacru_card_status(instance);
733
734 return 0;
735
736 fail:
737 free_page((unsigned long) instance->snd_buf);
738 free_page((unsigned long) instance->rcv_buf);
739 usb_free_urb(instance->snd_urb);
740 usb_free_urb(instance->rcv_urb);
741 kfree(instance);
742
743 return ret;
744}
745
746static void cxacru_unbind(struct usbatm_data *usbatm_instance,
747 struct usb_interface *intf)
748{
749 struct cxacru_data *instance = usbatm_instance->driver_data;
750
751 dbg("cxacru_unbind entered");
752
753 if (!instance) {
754 dbg("cxacru_unbind: NULL instance!");
755 return;
756 }
757
758 while (!cancel_delayed_work(&instance->poll_work))
759 flush_scheduled_work();
760
761 usb_kill_urb(instance->snd_urb);
762 usb_kill_urb(instance->rcv_urb);
763 usb_free_urb(instance->snd_urb);
764 usb_free_urb(instance->rcv_urb);
765
766 free_page((unsigned long) instance->snd_buf);
767 free_page((unsigned long) instance->rcv_buf);
768 kfree(instance);
769
770 usbatm_instance->driver_data = NULL;
771}
772
773static const struct cxacru_modem_type cxacru_cafe = {
774 .pll_f_clk = 0x02d874df,
775 .pll_b_clk = 0x0196a51a,
776 .boot_rom_patch = 1,
777};
778
779static const struct cxacru_modem_type cxacru_cb00 = {
780 .pll_f_clk = 0x5,
781 .pll_b_clk = 0x3,
782 .boot_rom_patch = 0,
783};
784
785static const struct usb_device_id cxacru_usb_ids[] = {
786 { /* V = Conexant P = ADSL modem (Euphrates project) */
787 USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
788 },
789 { /* V = Conexant P = ADSL modem (Hasbani project) */
790 USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
791 },
792 { /* V = Conexant P = ADSL modem */
793 USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
794 },
795 { /* V = Conexant P = ADSL modem */
796 USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
797 },
798 { /* V = Olitec P = ADSL modem version 2 */
799 USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
800 },
801 { /* V = Olitec P = ADSL modem version 3 */
802 USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
803 },
804 { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
805 USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
806 },
807 { /* V = Zoom P = 5510 */
808 USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
809 },
810 { /* V = Draytek P = Vigor 318 */
811 USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
812 },
813 { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
814 USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
815 },
816 { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
817 USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
818 },
819 { /* V = Aethra P = Starmodem UM1020 */
820 USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
821 },
822 { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
823 USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
824 },
825 { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
826 USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
827 },
828 { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
829 USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
830 },
831 {}
832};
833
834MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
835
836static struct usbatm_driver cxacru_driver = {
837 .owner = THIS_MODULE,
838 .driver_name = cxacru_driver_name,
839 .bind = cxacru_bind,
840 .heavy_init = cxacru_heavy_init,
841 .unbind = cxacru_unbind,
842 .atm_start = cxacru_atm_start,
843 .in = CXACRU_EP_DATA,
844 .out = CXACRU_EP_DATA,
845 .rx_padding = 3,
846 .tx_padding = 11,
847};
848
849static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
850{
851 return usbatm_usb_probe(intf, id, &cxacru_driver);
852}
853
854static struct usb_driver cxacru_usb_driver = {
855 .owner = THIS_MODULE,
856 .name = cxacru_driver_name,
857 .probe = cxacru_usb_probe,
858 .disconnect = usbatm_usb_disconnect,
859 .id_table = cxacru_usb_ids
860};
861
862static int __init cxacru_init(void)
863{
864 return usb_register(&cxacru_usb_driver);
865}
866
867static void __exit cxacru_cleanup(void)
868{
869 usb_deregister(&cxacru_usb_driver);
870}
871
872module_init(cxacru_init);
873module_exit(cxacru_cleanup);
874
875MODULE_AUTHOR(DRIVER_AUTHOR);
876MODULE_DESCRIPTION(DRIVER_DESC);
877MODULE_LICENSE("GPL");
878MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 2a1697bfd695..6bd581e69afd 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -5,6 +5,8 @@
5 * Copyright (C) 2003, Duncan Sands 5 * Copyright (C) 2003, Duncan Sands
6 * Copyright (C) 2004, David Woodhouse 6 * Copyright (C) 2004, David Woodhouse
7 * 7 *
8 * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault
9 *
8 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option) 12 * Software Foundation; either version 2 of the License, or (at your option)
@@ -21,467 +23,191 @@
21 * 23 *
22 ******************************************************************************/ 24 ******************************************************************************/
23 25
24#include <linux/module.h> 26#include <asm/page.h>
25#include <linux/moduleparam.h> 27#include <linux/device.h>
28#include <linux/errno.h>
29#include <linux/firmware.h>
26#include <linux/gfp.h> 30#include <linux/gfp.h>
31#include <linux/init.h>
27#include <linux/kernel.h> 32#include <linux/kernel.h>
28#include <linux/sched.h> 33#include <linux/module.h>
29#include <linux/timer.h> 34#include <linux/moduleparam.h>
30#include <linux/errno.h>
31#include <linux/proc_fs.h>
32#include <linux/slab.h> 35#include <linux/slab.h>
33#include <linux/wait.h> 36#include <linux/stat.h>
34#include <linux/list.h> 37#include <linux/timer.h>
35#include <asm/processor.h> 38#include <linux/workqueue.h>
36#include <asm/uaccess.h>
37#include <linux/smp_lock.h>
38#include <linux/interrupt.h>
39#include <linux/atm.h>
40#include <linux/atmdev.h>
41#include <linux/crc32.h>
42#include <linux/init.h>
43#include <linux/firmware.h>
44
45#include "usb_atm.h"
46 39
47#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) 40#include "usbatm.h"
48# define USE_FW_LOADER
49#endif
50 41
51#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 42#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
52#define DRIVER_VERSION "1.8" 43#define DRIVER_VERSION "1.9"
53#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION 44#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION
54 45
55static const char speedtch_driver_name[] = "speedtch"; 46static const char speedtch_driver_name[] = "speedtch";
56 47
57#define SPEEDTOUCH_VENDORID 0x06b9 48#define CTRL_TIMEOUT 2000 /* milliseconds */
58#define SPEEDTOUCH_PRODUCTID 0x4061 49#define DATA_TIMEOUT 2000 /* milliseconds */
59 50
60/* Timeout in jiffies */ 51#define OFFSET_7 0 /* size 1 */
61#define CTRL_TIMEOUT 2000 52#define OFFSET_b 1 /* size 8 */
62#define DATA_TIMEOUT 2000 53#define OFFSET_d 9 /* size 4 */
54#define OFFSET_e 13 /* size 1 */
55#define OFFSET_f 14 /* size 1 */
56#define TOTAL 15
63 57
64#define OFFSET_7 0 /* size 1 */ 58#define SIZE_7 1
65#define OFFSET_b 1 /* size 8 */ 59#define SIZE_b 8
66#define OFFSET_d 9 /* size 4 */ 60#define SIZE_d 4
67#define OFFSET_e 13 /* size 1 */ 61#define SIZE_e 1
68#define OFFSET_f 14 /* size 1 */ 62#define SIZE_f 1
69#define TOTAL 15
70 63
71#define SIZE_7 1 64#define MIN_POLL_DELAY 5000 /* milliseconds */
72#define SIZE_b 8 65#define MAX_POLL_DELAY 60000 /* milliseconds */
73#define SIZE_d 4
74#define SIZE_e 1
75#define SIZE_f 1
76 66
77static int dl_512_first = 0; 67#define RESUBMIT_DELAY 1000 /* milliseconds */
78static int sw_buffering = 0;
79 68
80module_param(dl_512_first, bool, 0444); 69#define DEFAULT_ALTSETTING 1
81MODULE_PARM_DESC(dl_512_first, "Read 512 bytes before sending firmware"); 70#define DEFAULT_DL_512_FIRST 0
71#define DEFAULT_SW_BUFFERING 0
82 72
83module_param(sw_buffering, uint, 0444); 73static int altsetting = DEFAULT_ALTSETTING;
84MODULE_PARM_DESC(sw_buffering, "Enable software buffering"); 74static int dl_512_first = DEFAULT_DL_512_FIRST;
75static int sw_buffering = DEFAULT_SW_BUFFERING;
85 76
86#define UDSL_IOCTL_LINE_UP 1 77module_param(altsetting, int, S_IRUGO | S_IWUSR);
87#define UDSL_IOCTL_LINE_DOWN 2 78MODULE_PARM_DESC(altsetting,
79 "Alternative setting for data interface (default: "
80 __MODULE_STRING(DEFAULT_ALTSETTING) ")");
88 81
89#define SPEEDTCH_ENDPOINT_INT 0x81 82module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
90#define SPEEDTCH_ENDPOINT_DATA 0x07 83MODULE_PARM_DESC(dl_512_first,
91#define SPEEDTCH_ENDPOINT_FIRMWARE 0x05 84 "Read 512 bytes before sending firmware (default: "
85 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
92 86
93#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) 87module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
88MODULE_PARM_DESC(sw_buffering,
89 "Enable software buffering (default: "
90 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")");
94 91
95static struct usb_device_id speedtch_usb_ids[] = { 92#define ENDPOINT_INT 0x81
96 {USB_DEVICE(SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID)}, 93#define ENDPOINT_DATA 0x07
97 {} 94#define ENDPOINT_FIRMWARE 0x05
98};
99 95
100MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); 96#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
101 97
102struct speedtch_instance_data { 98struct speedtch_instance_data {
103 struct udsl_instance_data u; 99 struct usbatm_data *usbatm;
100
101 struct work_struct status_checker;
102
103 unsigned char last_status;
104
105 int poll_delay; /* milliseconds */
104 106
105 /* Status */ 107 struct timer_list resubmit_timer;
106 struct urb *int_urb; 108 struct urb *int_urb;
107 unsigned char int_data[16]; 109 unsigned char int_data[16];
108 struct work_struct poll_work;
109 struct timer_list poll_timer;
110};
111/* USB */
112
113static int speedtch_usb_probe(struct usb_interface *intf,
114 const struct usb_device_id *id);
115static void speedtch_usb_disconnect(struct usb_interface *intf);
116static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code,
117 void *user_data);
118static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs);
119static void speedtch_poll_status(struct speedtch_instance_data *instance);
120 110
121static struct usb_driver speedtch_usb_driver = { 111 unsigned char scratch_buffer[TOTAL];
122 .owner = THIS_MODULE,
123 .name = speedtch_driver_name,
124 .probe = speedtch_usb_probe,
125 .disconnect = speedtch_usb_disconnect,
126 .ioctl = speedtch_usb_ioctl,
127 .id_table = speedtch_usb_ids,
128}; 112};
129 113
130/*************** 114/***************
131** firmware ** 115** firmware **
132***************/ 116***************/
133 117
134static void speedtch_got_firmware(struct speedtch_instance_data *instance, 118static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state)
135 int got_it)
136{
137 int err;
138 struct usb_interface *intf;
139
140 down(&instance->u.serialize); /* vs self, speedtch_firmware_start */
141 if (instance->u.status == UDSL_LOADED_FIRMWARE)
142 goto out;
143 if (!got_it) {
144 instance->u.status = UDSL_NO_FIRMWARE;
145 goto out;
146 }
147 if ((err = usb_set_interface(instance->u.usb_dev, 1, 1)) < 0) {
148 dbg("speedtch_got_firmware: usb_set_interface returned %d!", err);
149 instance->u.status = UDSL_NO_FIRMWARE;
150 goto out;
151 }
152
153 /* Set up interrupt endpoint */
154 intf = usb_ifnum_to_if(instance->u.usb_dev, 0);
155 if (intf && !usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) {
156
157 instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
158 if (instance->int_urb) {
159
160 usb_fill_int_urb(instance->int_urb, instance->u.usb_dev,
161 usb_rcvintpipe(instance->u.usb_dev, SPEEDTCH_ENDPOINT_INT),
162 instance->int_data,
163 sizeof(instance->int_data),
164 speedtch_handle_int, instance, 50);
165 err = usb_submit_urb(instance->int_urb, GFP_KERNEL);
166 if (err) {
167 /* Doesn't matter; we'll poll anyway */
168 dbg("speedtch_got_firmware: Submission of interrupt URB failed %d", err);
169 usb_free_urb(instance->int_urb);
170 instance->int_urb = NULL;
171 usb_driver_release_interface(&speedtch_usb_driver, intf);
172 }
173 }
174 }
175 /* Start status polling */
176 mod_timer(&instance->poll_timer, jiffies + (1 * HZ));
177
178 instance->u.status = UDSL_LOADED_FIRMWARE;
179 tasklet_schedule(&instance->u.receive_tasklet);
180 out:
181 up(&instance->u.serialize);
182 wake_up_interruptible(&instance->u.firmware_waiters);
183}
184
185static int speedtch_set_swbuff(struct speedtch_instance_data *instance,
186 int state)
187{ 119{
188 struct usb_device *dev = instance->u.usb_dev; 120 struct usbatm_data *usbatm = instance->usbatm;
121 struct usb_device *usb_dev = usbatm->usb_dev;
189 int ret; 122 int ret;
190 123
191 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 124 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
192 0x32, 0x40, state ? 0x01 : 0x00, 125 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT);
193 0x00, NULL, 0, 100); 126 if (ret < 0)
194 if (ret < 0) { 127 usb_warn(usbatm,
195 printk("Warning: %sabling SW buffering: usb_control_msg returned %d\n", 128 "%sabling SW buffering: usb_control_msg returned %d\n",
196 state ? "En" : "Dis", ret); 129 state ? "En" : "Dis", ret);
197 return ret; 130 else
198 } 131 dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis");
199
200 dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis");
201 return 0;
202} 132}
203 133
204static void speedtch_test_sequence(struct speedtch_instance_data *instance) 134static void speedtch_test_sequence(struct speedtch_instance_data *instance)
205{ 135{
206 struct usb_device *dev = instance->u.usb_dev; 136 struct usbatm_data *usbatm = instance->usbatm;
207 unsigned char buf[10]; 137 struct usb_device *usb_dev = usbatm->usb_dev;
138 unsigned char *buf = instance->scratch_buffer;
208 int ret; 139 int ret;
209 140
210 /* URB 147 */ 141 /* URB 147 */
211 buf[0] = 0x1c; 142 buf[0] = 0x1c;
212 buf[1] = 0x50; 143 buf[1] = 0x50;
213 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 144 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
214 0x01, 0x40, 0x0b, 0x00, buf, 2, 100); 145 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT);
215 if (ret < 0) 146 if (ret < 0)
216 printk(KERN_WARNING "%s failed on URB147: %d\n", __func__, ret); 147 usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret);
217 148
218 /* URB 148 */ 149 /* URB 148 */
219 buf[0] = 0x32; 150 buf[0] = 0x32;
220 buf[1] = 0x00; 151 buf[1] = 0x00;
221 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 152 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
222 0x01, 0x40, 0x02, 0x00, buf, 2, 100); 153 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT);
223 if (ret < 0) 154 if (ret < 0)
224 printk(KERN_WARNING "%s failed on URB148: %d\n", __func__, ret); 155 usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret);
225 156
226 /* URB 149 */ 157 /* URB 149 */
227 buf[0] = 0x01; 158 buf[0] = 0x01;
228 buf[1] = 0x00; 159 buf[1] = 0x00;
229 buf[2] = 0x01; 160 buf[2] = 0x01;
230 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 161 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
231 0x01, 0x40, 0x03, 0x00, buf, 3, 100); 162 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT);
232 if (ret < 0) 163 if (ret < 0)
233 printk(KERN_WARNING "%s failed on URB149: %d\n", __func__, ret); 164 usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret);
234 165
235 /* URB 150 */ 166 /* URB 150 */
236 buf[0] = 0x01; 167 buf[0] = 0x01;
237 buf[1] = 0x00; 168 buf[1] = 0x00;
238 buf[2] = 0x01; 169 buf[2] = 0x01;
239 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 170 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
240 0x01, 0x40, 0x04, 0x00, buf, 3, 100); 171 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT);
241 if (ret < 0) 172 if (ret < 0)
242 printk(KERN_WARNING "%s failed on URB150: %d\n", __func__, ret); 173 usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret);
243}
244
245static int speedtch_start_synchro(struct speedtch_instance_data *instance)
246{
247 struct usb_device *dev = instance->u.usb_dev;
248 unsigned char buf[2];
249 int ret;
250
251 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
252 0x12, 0xc0, 0x04, 0x00,
253 buf, sizeof(buf), CTRL_TIMEOUT);
254 if (ret < 0) {
255 printk(KERN_WARNING "SpeedTouch: Failed to start ADSL synchronisation: %d\n", ret);
256 return ret;
257 }
258
259 dbg("speedtch_start_synchro: modem prodded. %d Bytes returned: %02x %02x", ret, buf[0], buf[1]);
260 return 0;
261}
262
263static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs)
264{
265 struct speedtch_instance_data *instance = urb->context;
266 unsigned int count = urb->actual_length;
267 int ret;
268
269 /* The magic interrupt for "up state" */
270 const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
271 /* The magic interrupt for "down state" */
272 const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
273
274 switch (urb->status) {
275 case 0:
276 /* success */
277 break;
278 case -ECONNRESET:
279 case -ENOENT:
280 case -ESHUTDOWN:
281 /* this urb is terminated; clean up */
282 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
283 return;
284 default:
285 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
286 goto exit;
287 }
288
289 if (count < 6) {
290 dbg("%s - int packet too short", __func__);
291 goto exit;
292 }
293
294 if (!memcmp(up_int, instance->int_data, 6)) {
295 del_timer(&instance->poll_timer);
296 printk(KERN_NOTICE "DSL line goes up\n");
297 } else if (!memcmp(down_int, instance->int_data, 6)) {
298 printk(KERN_NOTICE "DSL line goes down\n");
299 } else {
300 int i;
301
302 printk(KERN_DEBUG "Unknown interrupt packet of %d bytes:", count);
303 for (i = 0; i < count; i++)
304 printk(" %02x", instance->int_data[i]);
305 printk("\n");
306 }
307 schedule_work(&instance->poll_work);
308
309 exit:
310 rmb();
311 if (!instance->int_urb)
312 return;
313
314 ret = usb_submit_urb(urb, GFP_ATOMIC);
315 if (ret)
316 err("%s - usb_submit_urb failed with result %d", __func__, ret);
317}
318
319static int speedtch_get_status(struct speedtch_instance_data *instance,
320 unsigned char *buf)
321{
322 struct usb_device *dev = instance->u.usb_dev;
323 int ret;
324
325 memset(buf, 0, TOTAL);
326
327 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
328 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
329 CTRL_TIMEOUT);
330 if (ret < 0) {
331 dbg("MSG 7 failed");
332 return ret;
333 }
334
335 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
336 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
337 CTRL_TIMEOUT);
338 if (ret < 0) {
339 dbg("MSG B failed");
340 return ret;
341 }
342
343 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
344 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
345 CTRL_TIMEOUT);
346 if (ret < 0) {
347 dbg("MSG D failed");
348 return ret;
349 }
350
351 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
352 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
353 CTRL_TIMEOUT);
354 if (ret < 0) {
355 dbg("MSG E failed");
356 return ret;
357 }
358
359 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
360 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
361 CTRL_TIMEOUT);
362 if (ret < 0) {
363 dbg("MSG F failed");
364 return ret;
365 }
366
367 return 0;
368} 174}
369 175
370static void speedtch_poll_status(struct speedtch_instance_data *instance) 176static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
371{
372 unsigned char buf[TOTAL];
373 int ret;
374
375 ret = speedtch_get_status(instance, buf);
376 if (ret) {
377 printk(KERN_WARNING
378 "SpeedTouch: Error %d fetching device status\n", ret);
379 return;
380 }
381
382 dbg("Line state %02x", buf[OFFSET_7]);
383
384 switch (buf[OFFSET_7]) {
385 case 0:
386 if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) {
387 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
388 printk(KERN_NOTICE "ADSL line is down\n");
389 /* It'll never resync again unless we ask it to... */
390 speedtch_start_synchro(instance);
391 }
392 break;
393
394 case 0x08:
395 if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
396 instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
397 printk(KERN_NOTICE "ADSL line is blocked?\n");
398 }
399 break;
400
401 case 0x10:
402 if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) {
403 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST;
404 printk(KERN_NOTICE "ADSL line is synchronising\n");
405 }
406 break;
407
408 case 0x20:
409 if (instance->u.atm_dev->signal != ATM_PHY_SIG_FOUND) {
410 int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
411 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
412 int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
413 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
414
415 if (!(down_speed & 0x0000ffff) &&
416 !(up_speed & 0x0000ffff)) {
417 down_speed >>= 16;
418 up_speed >>= 16;
419 }
420 instance->u.atm_dev->link_rate = down_speed * 1000 / 424;
421 instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND;
422
423 printk(KERN_NOTICE
424 "ADSL line is up (%d Kib/s down | %d Kib/s up)\n",
425 down_speed, up_speed);
426 }
427 break;
428
429 default:
430 if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
431 instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
432 printk(KERN_NOTICE "Unknown line state %02x\n", buf[OFFSET_7]);
433 }
434 break;
435 }
436}
437
438static void speedtch_timer_poll(unsigned long data)
439{
440 struct speedtch_instance_data *instance = (void *)data;
441
442 schedule_work(&instance->poll_work);
443 mod_timer(&instance->poll_timer, jiffies + (5 * HZ));
444}
445
446#ifdef USE_FW_LOADER
447static void speedtch_upload_firmware(struct speedtch_instance_data *instance,
448 const struct firmware *fw1, 177 const struct firmware *fw1,
449 const struct firmware *fw2) 178 const struct firmware *fw2)
450{ 179{
451 unsigned char *buffer; 180 unsigned char *buffer;
452 struct usb_device *usb_dev = instance->u.usb_dev; 181 struct usbatm_data *usbatm = instance->usbatm;
453 struct usb_interface *intf; 182 struct usb_interface *intf;
454 int actual_length, ret; 183 struct usb_device *usb_dev = usbatm->usb_dev;
184 int actual_length;
185 int ret = 0;
455 int offset; 186 int offset;
456 187
457 dbg("speedtch_upload_firmware"); 188 usb_dbg(usbatm, "%s entered\n", __func__);
458
459 if (!(intf = usb_ifnum_to_if(usb_dev, 2))) {
460 dbg("speedtch_upload_firmware: interface not found!");
461 goto fail;
462 }
463 189
464 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { 190 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) {
465 dbg("speedtch_upload_firmware: no memory for buffer!"); 191 ret = -ENOMEM;
466 goto fail; 192 usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__);
193 goto out;
467 } 194 }
468 195
469 /* A user-space firmware loader may already have claimed interface #2 */ 196 if (!(intf = usb_ifnum_to_if(usb_dev, 2))) {
470 if ((ret = 197 ret = -ENODEV;
471 usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) < 0) { 198 usb_dbg(usbatm, "%s: interface not found!\n", __func__);
472 dbg("speedtch_upload_firmware: interface in use (%d)!", ret); 199 goto out_free;
473 goto fail_free;
474 } 200 }
475 201
476 /* URB 7 */ 202 /* URB 7 */
477 if (dl_512_first) { /* some modems need a read before writing the firmware */ 203 if (dl_512_first) { /* some modems need a read before writing the firmware */
478 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 204 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
479 buffer, 0x200, &actual_length, 2000); 205 buffer, 0x200, &actual_length, 2000);
480 206
481 if (ret < 0 && ret != -ETIMEDOUT) 207 if (ret < 0 && ret != -ETIMEDOUT)
482 dbg("speedtch_upload_firmware: read BLOCK0 from modem failed (%d)!", ret); 208 usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret);
483 else 209 else
484 dbg("speedtch_upload_firmware: BLOCK0 downloaded (%d bytes)", ret); 210 usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret);
485 } 211 }
486 212
487 /* URB 8 : both leds are static green */ 213 /* URB 8 : both leds are static green */
@@ -489,60 +215,60 @@ static void speedtch_upload_firmware(struct speedtch_instance_data *instance,
489 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); 215 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset);
490 memcpy(buffer, fw1->data + offset, thislen); 216 memcpy(buffer, fw1->data + offset, thislen);
491 217
492 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 218 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
493 buffer, thislen, &actual_length, DATA_TIMEOUT); 219 buffer, thislen, &actual_length, DATA_TIMEOUT);
494 220
495 if (ret < 0) { 221 if (ret < 0) {
496 dbg("speedtch_upload_firmware: write BLOCK1 to modem failed (%d)!", ret); 222 usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret);
497 goto fail_release; 223 goto out_free;
498 } 224 }
499 dbg("speedtch_upload_firmware: BLOCK1 uploaded (%zu bytes)", fw1->size); 225 usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size);
500 } 226 }
501 227
502 /* USB led blinking green, ADSL led off */ 228 /* USB led blinking green, ADSL led off */
503 229
504 /* URB 11 */ 230 /* URB 11 */
505 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 231 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
506 buffer, 0x200, &actual_length, DATA_TIMEOUT); 232 buffer, 0x200, &actual_length, DATA_TIMEOUT);
507 233
508 if (ret < 0) { 234 if (ret < 0) {
509 dbg("speedtch_upload_firmware: read BLOCK2 from modem failed (%d)!", ret); 235 usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret);
510 goto fail_release; 236 goto out_free;
511 } 237 }
512 dbg("speedtch_upload_firmware: BLOCK2 downloaded (%d bytes)", actual_length); 238 usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length);
513 239
514 /* URBs 12 to 139 - USB led blinking green, ADSL led off */ 240 /* URBs 12 to 139 - USB led blinking green, ADSL led off */
515 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { 241 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) {
516 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); 242 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset);
517 memcpy(buffer, fw2->data + offset, thislen); 243 memcpy(buffer, fw2->data + offset, thislen);
518 244
519 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 245 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
520 buffer, thislen, &actual_length, DATA_TIMEOUT); 246 buffer, thislen, &actual_length, DATA_TIMEOUT);
521 247
522 if (ret < 0) { 248 if (ret < 0) {
523 dbg("speedtch_upload_firmware: write BLOCK3 to modem failed (%d)!", ret); 249 usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret);
524 goto fail_release; 250 goto out_free;
525 } 251 }
526 } 252 }
527 dbg("speedtch_upload_firmware: BLOCK3 uploaded (%zu bytes)", fw2->size); 253 usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size);
528 254
529 /* USB led static green, ADSL led static red */ 255 /* USB led static green, ADSL led static red */
530 256
531 /* URB 142 */ 257 /* URB 142 */
532 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 258 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
533 buffer, 0x200, &actual_length, DATA_TIMEOUT); 259 buffer, 0x200, &actual_length, DATA_TIMEOUT);
534 260
535 if (ret < 0) { 261 if (ret < 0) {
536 dbg("speedtch_upload_firmware: read BLOCK4 from modem failed (%d)!", ret); 262 usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret);
537 goto fail_release; 263 goto out_free;
538 } 264 }
539 265
540 /* success */ 266 /* success */
541 dbg("speedtch_upload_firmware: BLOCK4 downloaded (%d bytes)", actual_length); 267 usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length);
542 268
543 /* Delay to allow firmware to start up. We can do this here 269 /* Delay to allow firmware to start up. We can do this here
544 because we're in our own kernel thread anyway. */ 270 because we're in our own kernel thread anyway. */
545 msleep(1000); 271 msleep_interruptible(1000);
546 272
547 /* Enable software buffering, if requested */ 273 /* Enable software buffering, if requested */
548 if (sw_buffering) 274 if (sw_buffering)
@@ -551,291 +277,543 @@ static void speedtch_upload_firmware(struct speedtch_instance_data *instance,
551 /* Magic spell; don't ask us what this does */ 277 /* Magic spell; don't ask us what this does */
552 speedtch_test_sequence(instance); 278 speedtch_test_sequence(instance);
553 279
554 /* Start modem synchronisation */ 280 ret = 0;
555 if (speedtch_start_synchro(instance))
556 dbg("speedtch_start_synchro: failed");
557
558 speedtch_got_firmware(instance, 1);
559
560 free_page((unsigned long)buffer);
561 return;
562 281
563 fail_release: 282out_free:
564 /* Only release interface #2 if uploading failed; we don't release it
565 we succeeded. This prevents the userspace tools from trying to load
566 the firmware themselves */
567 usb_driver_release_interface(&speedtch_usb_driver, intf);
568 fail_free:
569 free_page((unsigned long)buffer); 283 free_page((unsigned long)buffer);
570 fail: 284out:
571 speedtch_got_firmware(instance, 0); 285 return ret;
572} 286}
573 287
574static int speedtch_find_firmware(struct speedtch_instance_data 288static int speedtch_find_firmware(struct usb_interface *intf, int phase,
575 *instance, int phase,
576 const struct firmware **fw_p) 289 const struct firmware **fw_p)
577{ 290{
578 char buf[24]; 291 struct device *dev = &intf->dev;
579 const u16 bcdDevice = le16_to_cpu(instance->u.usb_dev->descriptor.bcdDevice); 292 const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice);
580 const u8 major_revision = bcdDevice >> 8; 293 const u8 major_revision = bcdDevice >> 8;
581 const u8 minor_revision = bcdDevice & 0xff; 294 const u8 minor_revision = bcdDevice & 0xff;
295 char buf[24];
582 296
583 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); 297 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
584 dbg("speedtch_find_firmware: looking for %s", buf); 298 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
585 299
586 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 300 if (request_firmware(fw_p, buf, dev)) {
587 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); 301 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
588 dbg("speedtch_find_firmware: looking for %s", buf); 302 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
589 303
590 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 304 if (request_firmware(fw_p, buf, dev)) {
591 sprintf(buf, "speedtch-%d.bin", phase); 305 sprintf(buf, "speedtch-%d.bin", phase);
592 dbg("speedtch_find_firmware: looking for %s", buf); 306 dev_dbg(dev, "%s: looking for %s\n", __func__, buf);
593 307
594 if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 308 if (request_firmware(fw_p, buf, dev)) {
595 dev_warn(&instance->u.usb_dev->dev, "no stage %d firmware found!", phase); 309 dev_warn(dev, "no stage %d firmware found!\n", phase);
596 return -ENOENT; 310 return -ENOENT;
597 } 311 }
598 } 312 }
599 } 313 }
600 314
601 dev_info(&instance->u.usb_dev->dev, "found stage %d firmware %s\n", phase, buf); 315 dev_info(dev, "found stage %d firmware %s\n", phase, buf);
602 316
603 return 0; 317 return 0;
604} 318}
605 319
606static int speedtch_load_firmware(void *arg) 320static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
607{ 321{
608 const struct firmware *fw1, *fw2; 322 const struct firmware *fw1, *fw2;
609 struct speedtch_instance_data *instance = arg; 323 struct speedtch_instance_data *instance = usbatm->driver_data;
610 324 int ret;
611 BUG_ON(!instance);
612 325
613 daemonize("firmware/speedtch"); 326 if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0)
327 return ret;
614 328
615 if (!speedtch_find_firmware(instance, 1, &fw1)) { 329 if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) {
616 if (!speedtch_find_firmware(instance, 2, &fw2)) {
617 speedtch_upload_firmware(instance, fw1, fw2);
618 release_firmware(fw2);
619 }
620 release_firmware(fw1); 330 release_firmware(fw1);
331 return ret;
621 } 332 }
622 333
623 /* In case we failed, set state back to NO_FIRMWARE so that 334 ret = speedtch_upload_firmware(instance, fw1, fw2);
624 another later attempt may work. Otherwise, we never actually
625 manage to recover if, for example, the firmware is on /usr and
626 we look for it too early. */
627 speedtch_got_firmware(instance, 0);
628 335
629 module_put(THIS_MODULE); 336 release_firmware(fw2);
630 udsl_put_instance(&instance->u); 337 release_firmware(fw1);
631 return 0; 338
339 return ret;
632} 340}
633#endif /* USE_FW_LOADER */
634 341
635static void speedtch_firmware_start(struct speedtch_instance_data *instance) 342
343/**********
344** ATM **
345**********/
346
347static int speedtch_read_status(struct speedtch_instance_data *instance)
636{ 348{
637#ifdef USE_FW_LOADER 349 struct usbatm_data *usbatm = instance->usbatm;
350 struct usb_device *usb_dev = usbatm->usb_dev;
351 unsigned char *buf = instance->scratch_buffer;
638 int ret; 352 int ret;
639#endif
640 353
641 dbg("speedtch_firmware_start"); 354 memset(buf, 0, TOTAL);
642 355
643 down(&instance->u.serialize); /* vs self, speedtch_got_firmware */ 356 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
357 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
358 CTRL_TIMEOUT);
359 if (ret < 0) {
360 atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__);
361 return ret;
362 }
644 363
645 if (instance->u.status >= UDSL_LOADING_FIRMWARE) { 364 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
646 up(&instance->u.serialize); 365 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
647 return; 366 CTRL_TIMEOUT);
367 if (ret < 0) {
368 atm_dbg(usbatm, "%s: MSG B failed\n", __func__);
369 return ret;
648 } 370 }
649 371
650 instance->u.status = UDSL_LOADING_FIRMWARE; 372 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
651 up(&instance->u.serialize); 373 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
374 CTRL_TIMEOUT);
375 if (ret < 0) {
376 atm_dbg(usbatm, "%s: MSG D failed\n", __func__);
377 return ret;
378 }
652 379
653#ifdef USE_FW_LOADER 380 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
654 udsl_get_instance(&instance->u); 381 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
655 try_module_get(THIS_MODULE); 382 CTRL_TIMEOUT);
383 if (ret < 0) {
384 atm_dbg(usbatm, "%s: MSG E failed\n", __func__);
385 return ret;
386 }
656 387
657 ret = kernel_thread(speedtch_load_firmware, instance, 388 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
658 CLONE_FS | CLONE_FILES); 389 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
390 CTRL_TIMEOUT);
391 if (ret < 0) {
392 atm_dbg(usbatm, "%s: MSG F failed\n", __func__);
393 return ret;
394 }
659 395
660 if (ret >= 0) 396 return 0;
661 return; /* OK */ 397}
662 398
663 dbg("speedtch_firmware_start: kernel_thread failed (%d)!", ret); 399static int speedtch_start_synchro(struct speedtch_instance_data *instance)
400{
401 struct usbatm_data *usbatm = instance->usbatm;
402 struct usb_device *usb_dev = usbatm->usb_dev;
403 unsigned char *buf = instance->scratch_buffer;
404 int ret;
664 405
665 module_put(THIS_MODULE); 406 atm_dbg(usbatm, "%s entered\n", __func__);
666 udsl_put_instance(&instance->u);
667 /* Just pretend it never happened... hope modem_run happens */
668#endif /* USE_FW_LOADER */
669 407
670 speedtch_got_firmware(instance, 0); 408 memset(buf, 0, 2);
671}
672 409
673static int speedtch_firmware_wait(struct udsl_instance_data *instance) 410 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
674{ 411 0x12, 0xc0, 0x04, 0x00,
675 speedtch_firmware_start((void *)instance); 412 buf, 2, CTRL_TIMEOUT);
676 413
677 if (wait_event_interruptible(instance->firmware_waiters, instance->status != UDSL_LOADING_FIRMWARE) < 0) 414 if (ret < 0)
678 return -ERESTARTSYS; 415 atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret);
416 else
417 atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n",
418 __func__, ret, buf[0], buf[1]);
679 419
680 return (instance->status == UDSL_LOADED_FIRMWARE) ? 0 : -EAGAIN; 420 return ret;
681} 421}
682 422
683/********** 423static void speedtch_check_status(struct speedtch_instance_data *instance)
684** USB **
685**********/
686
687static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code,
688 void *user_data)
689{ 424{
690 struct speedtch_instance_data *instance = usb_get_intfdata(intf); 425 struct usbatm_data *usbatm = instance->usbatm;
426 struct atm_dev *atm_dev = usbatm->atm_dev;
427 unsigned char *buf = instance->scratch_buffer;
428 int down_speed, up_speed, ret;
429 unsigned char status;
691 430
692 dbg("speedtch_usb_ioctl entered"); 431 atm_dbg(usbatm, "%s entered\n", __func__);
693 432
694 if (!instance) { 433 ret = speedtch_read_status(instance);
695 dbg("speedtch_usb_ioctl: NULL instance!"); 434 if (ret < 0) {
696 return -ENODEV; 435 atm_warn(usbatm, "error %d fetching device status\n", ret);
436 instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY);
437 return;
697 } 438 }
698 439
699 switch (code) { 440 instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY);
700 case UDSL_IOCTL_LINE_UP: 441
701 instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND; 442 status = buf[OFFSET_7];
702 speedtch_got_firmware(instance, 1); 443
703 return (instance->u.status == UDSL_LOADED_FIRMWARE) ? 0 : -EIO; 444 atm_dbg(usbatm, "%s: line state %02x\n", __func__, status);
704 case UDSL_IOCTL_LINE_DOWN: 445
705 instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 446 if ((status != instance->last_status) || !status) {
706 return 0; 447 switch (status) {
707 default: 448 case 0:
708 return -ENOTTY; 449 atm_dev->signal = ATM_PHY_SIG_LOST;
450 if (instance->last_status)
451 atm_info(usbatm, "%s\n", "ADSL line is down");
452 /* It may never resync again unless we ask it to... */
453 ret = speedtch_start_synchro(instance);
454 break;
455
456 case 0x08:
457 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
458 atm_info(usbatm, "%s\n", "ADSL line is blocked?");
459 break;
460
461 case 0x10:
462 atm_dev->signal = ATM_PHY_SIG_LOST;
463 atm_info(usbatm, "%s\n", "ADSL line is synchronising");
464 break;
465
466 case 0x20:
467 down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
468 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
469 up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
470 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
471
472 if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
473 down_speed >>= 16;
474 up_speed >>= 16;
475 }
476
477 atm_dev->link_rate = down_speed * 1000 / 424;
478 atm_dev->signal = ATM_PHY_SIG_FOUND;
479
480 atm_info(usbatm,
481 "ADSL line is up (%d kb/s down | %d kb/s up)\n",
482 down_speed, up_speed);
483 break;
484
485 default:
486 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
487 atm_info(usbatm, "Unknown line state %02x\n", status);
488 break;
489 }
490
491 instance->last_status = status;
709 } 492 }
710} 493}
711 494
712static int speedtch_usb_probe(struct usb_interface *intf, 495static void speedtch_status_poll(unsigned long data)
713 const struct usb_device_id *id)
714{ 496{
715 struct usb_device *dev = interface_to_usbdev(intf); 497 struct speedtch_instance_data *instance = (void *)data;
716 int ifnum = intf->altsetting->desc.bInterfaceNumber;
717 struct speedtch_instance_data *instance;
718 unsigned char mac_str[13];
719 int ret, i;
720 char buf7[SIZE_7];
721 498
722 dbg("speedtch_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d", 499 schedule_work(&instance->status_checker);
723 le16_to_cpu(dev->descriptor.idVendor),
724 le16_to_cpu(dev->descriptor.idProduct), ifnum);
725 500
726 if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) || 501 /* The following check is racy, but the race is harmless */
727 (ifnum != 1)) 502 if (instance->poll_delay < MAX_POLL_DELAY)
728 return -ENODEV; 503 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay));
504 else
505 atm_warn(instance->usbatm, "%s\n", "Too many failures - disabling line status polling");
506}
729 507
730 dbg("speedtch_usb_probe: device accepted"); 508static void speedtch_resubmit_int(unsigned long data)
509{
510 struct speedtch_instance_data *instance = (void *)data;
511 struct urb *int_urb = instance->int_urb;
512 int ret;
731 513
732 /* instance init */ 514 atm_dbg(instance->usbatm, "%s entered\n", __func__);
733 instance = kmalloc(sizeof(*instance), GFP_KERNEL); 515
734 if (!instance) { 516 if (int_urb) {
735 dbg("speedtch_usb_probe: no memory for instance data!"); 517 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
736 return -ENOMEM; 518 if (!ret)
519 schedule_work(&instance->status_checker);
520 else {
521 atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
522 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
523 }
737 } 524 }
525}
738 526
739 memset(instance, 0, sizeof(struct speedtch_instance_data)); 527static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs)
528{
529 struct speedtch_instance_data *instance = int_urb->context;
530 struct usbatm_data *usbatm = instance->usbatm;
531 unsigned int count = int_urb->actual_length;
532 int ret = int_urb->status;
740 533
741 if ((ret = usb_set_interface(dev, 0, 0)) < 0) 534 /* The magic interrupt for "up state" */
742 goto fail; 535 const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
536 /* The magic interrupt for "down state" */
537 const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
743 538
744 if ((ret = usb_set_interface(dev, 2, 0)) < 0) 539 atm_dbg(usbatm, "%s entered\n", __func__);
540
541 if (ret < 0) {
542 atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret);
745 goto fail; 543 goto fail;
544 }
746 545
747 instance->u.data_endpoint = SPEEDTCH_ENDPOINT_DATA; 546 if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) {
748 instance->u.firmware_wait = speedtch_firmware_wait; 547 del_timer(&instance->status_checker.timer);
749 instance->u.driver_name = speedtch_driver_name; 548 atm_info(usbatm, "%s\n", "DSL line goes up");
549 } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) {
550 atm_info(usbatm, "%s\n", "DSL line goes down");
551 } else {
552 int i;
750 553
751 ret = udsl_instance_setup(dev, &instance->u); 554 atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count);
752 if (ret) 555 for (i = 0; i < count; i++)
556 printk(" %02x", instance->int_data[i]);
557 printk("\n");
753 goto fail; 558 goto fail;
559 }
560
561 if ((int_urb = instance->int_urb)) {
562 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
563 schedule_work(&instance->status_checker);
564 if (ret < 0) {
565 atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
566 goto fail;
567 }
568 }
569
570 return;
571
572fail:
573 if ((int_urb = instance->int_urb))
574 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
575}
754 576
755 init_timer(&instance->poll_timer); 577static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
756 instance->poll_timer.function = speedtch_timer_poll; 578{
757 instance->poll_timer.data = (unsigned long)instance; 579 struct usb_device *usb_dev = usbatm->usb_dev;
580 struct speedtch_instance_data *instance = usbatm->driver_data;
581 int i, ret;
582 unsigned char mac_str[13];
758 583
759 INIT_WORK(&instance->poll_work, (void *)speedtch_poll_status, instance); 584 atm_dbg(usbatm, "%s entered\n", __func__);
760 585
761 /* set MAC address, it is stored in the serial number */ 586 if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) {
762 memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi)); 587 atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret);
763 if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { 588 return ret;
589 }
590
591 /* Set MAC address, it is stored in the serial number */
592 memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
593 if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
764 for (i = 0; i < 6; i++) 594 for (i = 0; i < 6; i++)
765 instance->u.atm_dev->esi[i] = 595 atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
766 (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
767 } 596 }
768 597
769 /* First check whether the modem already seems to be alive */ 598 /* Start modem synchronisation */
770 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 599 ret = speedtch_start_synchro(instance);
771 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500);
772 600
773 if (ret == SIZE_7) { 601 /* Set up interrupt endpoint */
774 dbg("firmware appears to be already loaded"); 602 if (instance->int_urb) {
775 speedtch_got_firmware(instance, 1); 603 ret = usb_submit_urb(instance->int_urb, GFP_KERNEL);
776 speedtch_poll_status(instance); 604 if (ret < 0) {
777 } else { 605 /* Doesn't matter; we'll poll anyway */
778 speedtch_firmware_start(instance); 606 atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret);
607 usb_free_urb(instance->int_urb);
608 instance->int_urb = NULL;
609 }
779 } 610 }
780 611
781 usb_set_intfdata(intf, instance); 612 /* Start status polling */
613 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000));
782 614
783 return 0; 615 return 0;
616}
784 617
785 fail: 618static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
786 kfree(instance); 619{
620 struct speedtch_instance_data *instance = usbatm->driver_data;
621 struct urb *int_urb = instance->int_urb;
622
623 atm_dbg(usbatm, "%s entered\n", __func__);
624
625 del_timer_sync(&instance->status_checker.timer);
626
627 /*
628 * Since resubmit_timer and int_urb can schedule themselves and
629 * each other, shutting them down correctly takes some care
630 */
631 instance->int_urb = NULL; /* signal shutdown */
632 mb();
633 usb_kill_urb(int_urb);
634 del_timer_sync(&instance->resubmit_timer);
635 /*
636 * At this point, speedtch_handle_int and speedtch_resubmit_int
637 * can run or be running, but instance->int_urb == NULL means that
638 * they will not reschedule
639 */
640 usb_kill_urb(int_urb);
641 del_timer_sync(&instance->resubmit_timer);
642 usb_free_urb(int_urb);
787 643
788 return -ENOMEM; 644 flush_scheduled_work();
789} 645}
790 646
791static void speedtch_usb_disconnect(struct usb_interface *intf) 647
648/**********
649** USB **
650**********/
651
652static struct usb_device_id speedtch_usb_ids[] = {
653 {USB_DEVICE(0x06b9, 0x4061)},
654 {}
655};
656
657MODULE_DEVICE_TABLE(usb, speedtch_usb_ids);
658
659static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *);
660
661static struct usb_driver speedtch_usb_driver = {
662 .owner = THIS_MODULE,
663 .name = speedtch_driver_name,
664 .probe = speedtch_usb_probe,
665 .disconnect = usbatm_usb_disconnect,
666 .id_table = speedtch_usb_ids
667};
668
669static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) {
670 struct usb_interface *cur_intf;
671 int i;
672
673 for(i = 0; i < num_interfaces; i++)
674 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) {
675 usb_set_intfdata(cur_intf, NULL);
676 usb_driver_release_interface(&speedtch_usb_driver, cur_intf);
677 }
678}
679
680static int speedtch_bind(struct usbatm_data *usbatm,
681 struct usb_interface *intf,
682 const struct usb_device_id *id,
683 int *need_heavy_init)
792{ 684{
793 struct speedtch_instance_data *instance = usb_get_intfdata(intf); 685 struct usb_device *usb_dev = interface_to_usbdev(intf);
686 struct usb_interface *cur_intf;
687 struct speedtch_instance_data *instance;
688 int ifnum = intf->altsetting->desc.bInterfaceNumber;
689 int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
690 int i, ret;
794 691
795 dbg("speedtch_usb_disconnect entered"); 692 usb_dbg(usbatm, "%s entered\n", __func__);
796 693
797 if (!instance) { 694 if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
798 dbg("speedtch_usb_disconnect: NULL instance!"); 695 usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass);
799 return; 696 return -ENODEV;
800 } 697 }
801 698
802/*QQ need to handle disconnects on interface #2 while uploading firmware */ 699 /* claim all interfaces */
803/*QQ and what about interface #1? */
804 700
805 if (instance->int_urb) { 701 for (i=0; i < num_interfaces; i++) {
806 struct urb *int_urb = instance->int_urb; 702 cur_intf = usb_ifnum_to_if(usb_dev, i);
807 instance->int_urb = NULL; 703
808 wmb(); 704 if ((i != ifnum) && cur_intf) {
809 usb_unlink_urb(int_urb); 705 ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm);
810 usb_free_urb(int_urb); 706
707 if (ret < 0) {
708 usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret);
709 speedtch_release_interfaces(usb_dev, i);
710 return ret;
711 }
712 }
811 } 713 }
812 714
813 instance->int_data[0] = 1; 715 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
814 del_timer_sync(&instance->poll_timer); 716
815 wmb(); 717 if (!instance) {
816 flush_scheduled_work(); 718 usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__);
719 ret = -ENOMEM;
720 goto fail_release;
721 }
722
723 memset(instance, 0, sizeof(struct speedtch_instance_data));
724
725 instance->usbatm = usbatm;
726
727 INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance);
728
729 instance->status_checker.timer.function = speedtch_status_poll;
730 instance->status_checker.timer.data = (unsigned long)instance;
731 instance->last_status = 0xff;
732 instance->poll_delay = MIN_POLL_DELAY;
733
734 init_timer(&instance->resubmit_timer);
735 instance->resubmit_timer.function = speedtch_resubmit_int;
736 instance->resubmit_timer.data = (unsigned long)instance;
817 737
818 udsl_instance_disconnect(&instance->u); 738 instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
819 739
820 /* clean up */ 740 if (instance->int_urb)
821 usb_set_intfdata(intf, NULL); 741 usb_fill_int_urb(instance->int_urb, usb_dev,
822 udsl_put_instance(&instance->u); 742 usb_rcvintpipe(usb_dev, ENDPOINT_INT),
743 instance->int_data, sizeof(instance->int_data),
744 speedtch_handle_int, instance, 50);
745 else
746 usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__);
747
748 /* check whether the modem already seems to be alive */
749 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
750 0x12, 0xc0, 0x07, 0x00,
751 instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
752
753 *need_heavy_init = (ret != SIZE_7);
754
755 usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already");
756
757 if (*need_heavy_init)
758 if ((ret = usb_reset_device(usb_dev)) < 0)
759 goto fail_free;
760
761 usbatm->driver_data = instance;
762
763 return 0;
764
765fail_free:
766 usb_free_urb(instance->int_urb);
767 kfree(instance);
768fail_release:
769 speedtch_release_interfaces(usb_dev, num_interfaces);
770 return ret;
771}
772
773static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
774{
775 struct usb_device *usb_dev = interface_to_usbdev(intf);
776 struct speedtch_instance_data *instance = usbatm->driver_data;
777
778 usb_dbg(usbatm, "%s entered\n", __func__);
779
780 speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces);
781 usb_free_urb(instance->int_urb);
782 kfree(instance);
823} 783}
824 784
785
825/*********** 786/***********
826** init ** 787** init **
827***********/ 788***********/
828 789
790static struct usbatm_driver speedtch_usbatm_driver = {
791 .owner = THIS_MODULE,
792 .driver_name = speedtch_driver_name,
793 .bind = speedtch_bind,
794 .heavy_init = speedtch_heavy_init,
795 .unbind = speedtch_unbind,
796 .atm_start = speedtch_atm_start,
797 .atm_stop = speedtch_atm_stop,
798 .in = ENDPOINT_DATA,
799 .out = ENDPOINT_DATA
800};
801
802static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
803{
804 return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver);
805}
806
829static int __init speedtch_usb_init(void) 807static int __init speedtch_usb_init(void)
830{ 808{
831 dbg("speedtch_usb_init: driver version " DRIVER_VERSION); 809 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
832 810
833 return usb_register(&speedtch_usb_driver); 811 return usb_register(&speedtch_usb_driver);
834} 812}
835 813
836static void __exit speedtch_usb_cleanup(void) 814static void __exit speedtch_usb_cleanup(void)
837{ 815{
838 dbg("speedtch_usb_cleanup entered"); 816 dbg("%s", __func__);
839 817
840 usb_deregister(&speedtch_usb_driver); 818 usb_deregister(&speedtch_usb_driver);
841} 819}
diff --git a/drivers/usb/atm/usb_atm.c b/drivers/usb/atm/usb_atm.c
deleted file mode 100644
index a4cd4476d49a..000000000000
--- a/drivers/usb/atm/usb_atm.c
+++ /dev/null
@@ -1,1188 +0,0 @@
1/******************************************************************************
2 * usb_atm.c - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Written by Johan Verrept, maintained by Duncan Sands (duncan.sands@free.fr)
26 *
27 * 1.7+: - See the check-in logs
28 *
29 * 1.6: - No longer opens a connection if the firmware is not loaded
30 * - Added support for the speedtouch 330
31 * - Removed the limit on the number of devices
32 * - Module now autoloads on device plugin
33 * - Merged relevant parts of sarlib
34 * - Replaced the kernel thread with a tasklet
35 * - New packet transmission code
36 * - Changed proc file contents
37 * - Fixed all known SMP races
38 * - Many fixes and cleanups
39 * - Various fixes by Oliver Neukum (oliver@neukum.name)
40 *
41 * 1.5A: - Version for inclusion in 2.5 series kernel
42 * - Modifications by Richard Purdie (rpurdie@rpsys.net)
43 * - made compatible with kernel 2.5.6 onwards by changing
44 * udsl_usb_send_data_context->urb to a pointer and adding code
45 * to alloc and free it
46 * - remove_wait_queue() added to udsl_atm_processqueue_thread()
47 *
48 * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
49 * (reported by stephen.robinson@zen.co.uk)
50 *
51 * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave()
52 * - unlink all active send urbs of a vcc that is being closed.
53 *
54 * 1.3.1: - added the version number
55 *
56 * 1.3: - Added multiple send urb support
57 * - fixed memory leak and vcc->tx_inuse starvation bug
58 * when not enough memory left in vcc.
59 *
60 * 1.2: - Fixed race condition in udsl_usb_send_data()
61 * 1.1: - Turned off packet debugging
62 *
63 */
64
65#include <linux/module.h>
66#include <linux/moduleparam.h>
67#include <linux/kernel.h>
68#include <linux/sched.h>
69#include <linux/timer.h>
70#include <linux/errno.h>
71#include <linux/proc_fs.h>
72#include <linux/slab.h>
73#include <linux/wait.h>
74#include <linux/list.h>
75#include <asm/uaccess.h>
76#include <linux/smp_lock.h>
77#include <linux/interrupt.h>
78#include <linux/atm.h>
79#include <linux/atmdev.h>
80#include <linux/crc32.h>
81#include <linux/init.h>
82#include <linux/firmware.h>
83
84#include "usb_atm.h"
85
86#ifdef VERBOSE_DEBUG
87static int udsl_print_packet(const unsigned char *data, int len);
88#define PACKETDEBUG(arg...) udsl_print_packet (arg)
89#define vdbg(arg...) dbg (arg)
90#else
91#define PACKETDEBUG(arg...)
92#define vdbg(arg...)
93#endif
94
95#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
96#define DRIVER_VERSION "1.8"
97#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
98
99static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
100static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
101static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS;
102static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS;
103static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
104static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
105
106module_param(num_rcv_urbs, uint, 0444);
107MODULE_PARM_DESC(num_rcv_urbs,
108 "Number of urbs used for reception (range: 0-"
109 __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
110 __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
111
112module_param(num_snd_urbs, uint, 0444);
113MODULE_PARM_DESC(num_snd_urbs,
114 "Number of urbs used for transmission (range: 0-"
115 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
116 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
117
118module_param(num_rcv_bufs, uint, 0444);
119MODULE_PARM_DESC(num_rcv_bufs,
120 "Number of buffers used for reception (range: 0-"
121 __MODULE_STRING(UDSL_MAX_RCV_BUFS) ", default: "
122 __MODULE_STRING(UDSL_DEFAULT_RCV_BUFS) ")");
123
124module_param(num_snd_bufs, uint, 0444);
125MODULE_PARM_DESC(num_snd_bufs,
126 "Number of buffers used for transmission (range: 0-"
127 __MODULE_STRING(UDSL_MAX_SND_BUFS) ", default: "
128 __MODULE_STRING(UDSL_DEFAULT_SND_BUFS) ")");
129
130module_param(rcv_buf_size, uint, 0444);
131MODULE_PARM_DESC(rcv_buf_size,
132 "Size of the buffers used for reception (range: 0-"
133 __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
134 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
135
136module_param(snd_buf_size, uint, 0444);
137MODULE_PARM_DESC(snd_buf_size,
138 "Size of the buffers used for transmission (range: 0-"
139 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
140 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
141
142/* ATM */
143
144static void udsl_atm_dev_close(struct atm_dev *dev);
145static int udsl_atm_open(struct atm_vcc *vcc);
146static void udsl_atm_close(struct atm_vcc *vcc);
147static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
148static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
149static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
150
151static struct atmdev_ops udsl_atm_devops = {
152 .dev_close = udsl_atm_dev_close,
153 .open = udsl_atm_open,
154 .close = udsl_atm_close,
155 .ioctl = udsl_atm_ioctl,
156 .send = udsl_atm_send,
157 .proc_read = udsl_atm_proc_read,
158 .owner = THIS_MODULE,
159};
160
161/***********
162** misc **
163***********/
164
165static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb)
166{
167 if (vcc->pop)
168 vcc->pop(vcc, skb);
169 else
170 dev_kfree_skb(skb);
171}
172
173/*************
174** decode **
175*************/
176
177static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *instance,
178 short vpi, int vci)
179{
180 struct udsl_vcc_data *vcc;
181
182 list_for_each_entry(vcc, &instance->vcc_list, list)
183 if ((vcc->vci == vci) && (vcc->vpi == vpi))
184 return vcc;
185 return NULL;
186}
187
188static void udsl_extract_cells(struct udsl_instance_data *instance,
189 unsigned char *source, unsigned int howmany)
190{
191 struct udsl_vcc_data *cached_vcc = NULL;
192 struct atm_vcc *vcc;
193 struct sk_buff *sarb;
194 struct udsl_vcc_data *vcc_data;
195 int cached_vci = 0;
196 unsigned int i;
197 int pti;
198 int vci;
199 short cached_vpi = 0;
200 short vpi;
201
202 for (i = 0; i < howmany;
203 i++, source += ATM_CELL_SIZE + instance->rcv_padding) {
204 vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
205 vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
206 pti = (source[3] & 0x2) != 0;
207
208 vdbg("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti);
209
210 if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
211 vcc_data = cached_vcc;
212 else if ((vcc_data = udsl_find_vcc(instance, vpi, vci))) {
213 cached_vcc = vcc_data;
214 cached_vpi = vpi;
215 cached_vci = vci;
216 } else {
217 dbg("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, vci);
218 continue;
219 }
220
221 vcc = vcc_data->vcc;
222 sarb = vcc_data->sarb;
223
224 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
225 dbg("udsl_extract_cells: buffer overrun (sarb->len %u, vcc: 0x%p)!", sarb->len, vcc);
226 /* discard cells already received */
227 skb_trim(sarb, 0);
228 }
229
230 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
231 __skb_put(sarb, ATM_CELL_PAYLOAD);
232
233 if (pti) {
234 struct sk_buff *skb;
235 unsigned int length;
236 unsigned int pdu_length;
237
238 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
239
240 /* guard against overflow */
241 if (length > ATM_MAX_AAL5_PDU) {
242 dbg("udsl_extract_cells: bogus length %u (vcc: 0x%p)!", length, vcc);
243 atomic_inc(&vcc->stats->rx_err);
244 goto out;
245 }
246
247 pdu_length = UDSL_NUM_CELLS(length) * ATM_CELL_PAYLOAD;
248
249 if (sarb->len < pdu_length) {
250 dbg("udsl_extract_cells: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!", pdu_length, sarb->len, vcc);
251 atomic_inc(&vcc->stats->rx_err);
252 goto out;
253 }
254
255 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
256 dbg("udsl_extract_cells: packet failed crc check (vcc: 0x%p)!", vcc);
257 atomic_inc(&vcc->stats->rx_err);
258 goto out;
259 }
260
261 vdbg("udsl_extract_cells: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", length, pdu_length, vcc);
262
263 if (!(skb = dev_alloc_skb(length))) {
264 dbg("udsl_extract_cells: no memory for skb (length: %u)!", length);
265 atomic_inc(&vcc->stats->rx_drop);
266 goto out;
267 }
268
269 vdbg("udsl_extract_cells: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", skb, skb->truesize);
270
271 if (!atm_charge(vcc, skb->truesize)) {
272 dbg("udsl_extract_cells: failed atm_charge (skb->truesize: %u)!", skb->truesize);
273 dev_kfree_skb(skb);
274 goto out; /* atm_charge increments rx_drop */
275 }
276
277 memcpy(skb->data, sarb->tail - pdu_length, length);
278 __skb_put(skb, length);
279
280 vdbg("udsl_extract_cells: sending skb 0x%p, skb->len %u, skb->truesize %u", skb, skb->len, skb->truesize);
281
282 PACKETDEBUG(skb->data, skb->len);
283
284 vcc->push(vcc, skb);
285
286 atomic_inc(&vcc->stats->rx);
287 out:
288 skb_trim(sarb, 0);
289 }
290 }
291}
292
293/*************
294** encode **
295*************/
296
297static inline void udsl_fill_cell_header(unsigned char *target, struct atm_vcc *vcc)
298{
299 target[0] = vcc->vpi >> 4;
300 target[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
301 target[2] = vcc->vci >> 4;
302 target[3] = vcc->vci << 4;
303 target[4] = 0xec;
304}
305
306static const unsigned char zeros[ATM_CELL_PAYLOAD];
307
308static void udsl_groom_skb(struct atm_vcc *vcc, struct sk_buff *skb)
309{
310 struct udsl_control *ctrl = UDSL_SKB(skb);
311 unsigned int zero_padding;
312 u32 crc;
313
314 ctrl->atm_data.vcc = vcc;
315
316 ctrl->num_cells = UDSL_NUM_CELLS(skb->len);
317 ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD;
318
319 zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - ATM_AAL5_TRAILER;
320
321 if (ctrl->num_entire + 1 < ctrl->num_cells)
322 ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
323 else
324 ctrl->pdu_padding = zero_padding;
325
326 ctrl->aal5_trailer[0] = 0; /* UU = 0 */
327 ctrl->aal5_trailer[1] = 0; /* CPI = 0 */
328 ctrl->aal5_trailer[2] = skb->len >> 8;
329 ctrl->aal5_trailer[3] = skb->len;
330
331 crc = crc32_be(~0, skb->data, skb->len);
332 crc = crc32_be(crc, zeros, zero_padding);
333 crc = crc32_be(crc, ctrl->aal5_trailer, 4);
334 crc = ~crc;
335
336 ctrl->aal5_trailer[4] = crc >> 24;
337 ctrl->aal5_trailer[5] = crc >> 16;
338 ctrl->aal5_trailer[6] = crc >> 8;
339 ctrl->aal5_trailer[7] = crc;
340}
341
342static unsigned int udsl_write_cells(struct udsl_instance_data *instance,
343 unsigned int howmany, struct sk_buff *skb,
344 unsigned char **target_p)
345{
346 struct udsl_control *ctrl = UDSL_SKB(skb);
347 unsigned char *target = *target_p;
348 unsigned int nc, ne, i;
349
350 vdbg("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, ctrl->pdu_padding);
351
352 nc = ctrl->num_cells;
353 ne = min(howmany, ctrl->num_entire);
354
355 for (i = 0; i < ne; i++) {
356 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
357 target += ATM_CELL_HEADER;
358 memcpy(target, skb->data, ATM_CELL_PAYLOAD);
359 target += ATM_CELL_PAYLOAD;
360 if (instance->snd_padding) {
361 memset(target, 0, instance->snd_padding);
362 target += instance->snd_padding;
363 }
364 __skb_pull(skb, ATM_CELL_PAYLOAD);
365 }
366
367 ctrl->num_entire -= ne;
368
369 if (!(ctrl->num_cells -= ne) || !(howmany -= ne))
370 goto out;
371
372 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
373 target += ATM_CELL_HEADER;
374 memcpy(target, skb->data, skb->len);
375 target += skb->len;
376 __skb_pull(skb, skb->len);
377 memset(target, 0, ctrl->pdu_padding);
378 target += ctrl->pdu_padding;
379
380 if (--ctrl->num_cells) {
381 if (!--howmany) {
382 ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
383 goto out;
384 }
385
386 if (instance->snd_padding) {
387 memset(target, 0, instance->snd_padding);
388 target += instance->snd_padding;
389 }
390 udsl_fill_cell_header(target, ctrl->atm_data.vcc);
391 target += ATM_CELL_HEADER;
392 memset(target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
393 target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
394
395 --ctrl->num_cells;
396 UDSL_ASSERT(!ctrl->num_cells);
397 }
398
399 memcpy(target, ctrl->aal5_trailer, ATM_AAL5_TRAILER);
400 target += ATM_AAL5_TRAILER;
401 /* set pti bit in last cell */
402 *(target + 3 - ATM_CELL_SIZE) |= 0x2;
403 if (instance->snd_padding) {
404 memset(target, 0, instance->snd_padding);
405 target += instance->snd_padding;
406 }
407 out:
408 *target_p = target;
409 return nc - ctrl->num_cells;
410}
411
412/**************
413** receive **
414**************/
415
416static void udsl_complete_receive(struct urb *urb, struct pt_regs *regs)
417{
418 struct udsl_receive_buffer *buf;
419 struct udsl_instance_data *instance;
420 struct udsl_receiver *rcv;
421 unsigned long flags;
422
423 if (!urb || !(rcv = urb->context)) {
424 dbg("udsl_complete_receive: bad urb!");
425 return;
426 }
427
428 instance = rcv->instance;
429 buf = rcv->buffer;
430
431 buf->filled_cells = urb->actual_length / (ATM_CELL_SIZE + instance->rcv_padding);
432
433 vdbg("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, buf->filled_cells, rcv, buf);
434
435 UDSL_ASSERT(buf->filled_cells <= rcv_buf_size);
436
437 /* may not be in_interrupt() */
438 spin_lock_irqsave(&instance->receive_lock, flags);
439 list_add(&rcv->list, &instance->spare_receivers);
440 list_add_tail(&buf->list, &instance->filled_receive_buffers);
441 if (likely(!urb->status))
442 tasklet_schedule(&instance->receive_tasklet);
443 spin_unlock_irqrestore(&instance->receive_lock, flags);
444}
445
446static void udsl_process_receive(unsigned long data)
447{
448 struct udsl_receive_buffer *buf;
449 struct udsl_instance_data *instance = (struct udsl_instance_data *)data;
450 struct udsl_receiver *rcv;
451 int err;
452
453 made_progress:
454 while (!list_empty(&instance->spare_receive_buffers)) {
455 spin_lock_irq(&instance->receive_lock);
456 if (list_empty(&instance->spare_receivers)) {
457 spin_unlock_irq(&instance->receive_lock);
458 break;
459 }
460 rcv = list_entry(instance->spare_receivers.next,
461 struct udsl_receiver, list);
462 list_del(&rcv->list);
463 spin_unlock_irq(&instance->receive_lock);
464
465 buf = list_entry(instance->spare_receive_buffers.next,
466 struct udsl_receive_buffer, list);
467 list_del(&buf->list);
468
469 rcv->buffer = buf;
470
471 usb_fill_bulk_urb(rcv->urb, instance->usb_dev,
472 usb_rcvbulkpipe(instance->usb_dev, instance->data_endpoint),
473 buf->base,
474 rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding),
475 udsl_complete_receive, rcv);
476
477 vdbg("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p",
478 rcv->urb, rcv, buf);
479
480 if ((err = usb_submit_urb(rcv->urb, GFP_ATOMIC)) < 0) {
481 dbg("udsl_process_receive: urb submission failed (%d)!", err);
482 list_add(&buf->list, &instance->spare_receive_buffers);
483 spin_lock_irq(&instance->receive_lock);
484 list_add(&rcv->list, &instance->spare_receivers);
485 spin_unlock_irq(&instance->receive_lock);
486 break;
487 }
488 }
489
490 spin_lock_irq(&instance->receive_lock);
491 if (list_empty(&instance->filled_receive_buffers)) {
492 spin_unlock_irq(&instance->receive_lock);
493 return; /* done - no more buffers */
494 }
495 buf = list_entry(instance->filled_receive_buffers.next,
496 struct udsl_receive_buffer, list);
497 list_del(&buf->list);
498 spin_unlock_irq(&instance->receive_lock);
499
500 vdbg("udsl_process_receive: processing buf 0x%p", buf);
501 udsl_extract_cells(instance, buf->base, buf->filled_cells);
502 list_add(&buf->list, &instance->spare_receive_buffers);
503 goto made_progress;
504}
505
506/***********
507** send **
508***********/
509
510static void udsl_complete_send(struct urb *urb, struct pt_regs *regs)
511{
512 struct udsl_instance_data *instance;
513 struct udsl_sender *snd;
514 unsigned long flags;
515
516 if (!urb || !(snd = urb->context) || !(instance = snd->instance)) {
517 dbg("udsl_complete_send: bad urb!");
518 return;
519 }
520
521 vdbg("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb,
522 urb->status, snd, snd->buffer);
523
524 /* may not be in_interrupt() */
525 spin_lock_irqsave(&instance->send_lock, flags);
526 list_add(&snd->list, &instance->spare_senders);
527 list_add(&snd->buffer->list, &instance->spare_send_buffers);
528 tasklet_schedule(&instance->send_tasklet);
529 spin_unlock_irqrestore(&instance->send_lock, flags);
530}
531
532static void udsl_process_send(unsigned long data)
533{
534 struct udsl_send_buffer *buf;
535 struct udsl_instance_data *instance = (struct udsl_instance_data *)data;
536 struct sk_buff *skb;
537 struct udsl_sender *snd;
538 int err;
539 unsigned int num_written;
540
541 made_progress:
542 spin_lock_irq(&instance->send_lock);
543 while (!list_empty(&instance->spare_senders)) {
544 if (!list_empty(&instance->filled_send_buffers)) {
545 buf = list_entry(instance->filled_send_buffers.next,
546 struct udsl_send_buffer, list);
547 list_del(&buf->list);
548 } else if ((buf = instance->current_buffer)) {
549 instance->current_buffer = NULL;
550 } else /* all buffers empty */
551 break;
552
553 snd = list_entry(instance->spare_senders.next,
554 struct udsl_sender, list);
555 list_del(&snd->list);
556 spin_unlock_irq(&instance->send_lock);
557
558 snd->buffer = buf;
559 usb_fill_bulk_urb(snd->urb, instance->usb_dev,
560 usb_sndbulkpipe(instance->usb_dev, instance->data_endpoint),
561 buf->base,
562 (snd_buf_size - buf->free_cells) * (ATM_CELL_SIZE + instance->snd_padding),
563 udsl_complete_send, snd);
564
565 vdbg("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, buf 0x%p",
566 snd->urb, snd_buf_size - buf->free_cells, snd, buf);
567
568 if ((err = usb_submit_urb(snd->urb, GFP_ATOMIC)) < 0) {
569 dbg("udsl_process_send: urb submission failed (%d)!", err);
570 spin_lock_irq(&instance->send_lock);
571 list_add(&snd->list, &instance->spare_senders);
572 spin_unlock_irq(&instance->send_lock);
573 list_add(&buf->list, &instance->filled_send_buffers);
574 return; /* bail out */
575 }
576
577 spin_lock_irq(&instance->send_lock);
578 } /* while */
579 spin_unlock_irq(&instance->send_lock);
580
581 if (!instance->current_skb)
582 instance->current_skb = skb_dequeue(&instance->sndqueue);
583 if (!instance->current_skb)
584 return; /* done - no more skbs */
585
586 skb = instance->current_skb;
587
588 if (!(buf = instance->current_buffer)) {
589 spin_lock_irq(&instance->send_lock);
590 if (list_empty(&instance->spare_send_buffers)) {
591 instance->current_buffer = NULL;
592 spin_unlock_irq(&instance->send_lock);
593 return; /* done - no more buffers */
594 }
595 buf = list_entry(instance->spare_send_buffers.next,
596 struct udsl_send_buffer, list);
597 list_del(&buf->list);
598 spin_unlock_irq(&instance->send_lock);
599
600 buf->free_start = buf->base;
601 buf->free_cells = snd_buf_size;
602
603 instance->current_buffer = buf;
604 }
605
606 num_written = udsl_write_cells(instance, buf->free_cells, skb, &buf->free_start);
607
608 vdbg("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p",
609 num_written, skb, buf);
610
611 if (!(buf->free_cells -= num_written)) {
612 list_add_tail(&buf->list, &instance->filled_send_buffers);
613 instance->current_buffer = NULL;
614 }
615
616 vdbg("udsl_process_send: buffer contains %d cells, %d left",
617 snd_buf_size - buf->free_cells, buf->free_cells);
618
619 if (!UDSL_SKB(skb)->num_cells) {
620 struct atm_vcc *vcc = UDSL_SKB(skb)->atm_data.vcc;
621
622 udsl_pop(vcc, skb);
623 instance->current_skb = NULL;
624
625 atomic_inc(&vcc->stats->tx);
626 }
627
628 goto made_progress;
629}
630
631static void udsl_cancel_send(struct udsl_instance_data *instance,
632 struct atm_vcc *vcc)
633{
634 struct sk_buff *skb, *n;
635
636 dbg("udsl_cancel_send entered");
637 spin_lock_irq(&instance->sndqueue.lock);
638 for (skb = instance->sndqueue.next, n = skb->next;
639 skb != (struct sk_buff *)&instance->sndqueue;
640 skb = n, n = skb->next)
641 if (UDSL_SKB(skb)->atm_data.vcc == vcc) {
642 dbg("udsl_cancel_send: popping skb 0x%p", skb);
643 __skb_unlink(skb, &instance->sndqueue);
644 udsl_pop(vcc, skb);
645 }
646 spin_unlock_irq(&instance->sndqueue.lock);
647
648 tasklet_disable(&instance->send_tasklet);
649 if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm_data.vcc == vcc)) {
650 dbg("udsl_cancel_send: popping current skb (0x%p)", skb);
651 instance->current_skb = NULL;
652 udsl_pop(vcc, skb);
653 }
654 tasklet_enable(&instance->send_tasklet);
655 dbg("udsl_cancel_send done");
656}
657
658static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
659{
660 struct udsl_instance_data *instance = vcc->dev->dev_data;
661 int err;
662
663 vdbg("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len);
664
665 if (!instance) {
666 dbg("udsl_atm_send: NULL data!");
667 err = -ENODEV;
668 goto fail;
669 }
670
671 if (vcc->qos.aal != ATM_AAL5) {
672 dbg("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal);
673 err = -EINVAL;
674 goto fail;
675 }
676
677 if (skb->len > ATM_MAX_AAL5_PDU) {
678 dbg("udsl_atm_send: packet too long (%d vs %d)!", skb->len,
679 ATM_MAX_AAL5_PDU);
680 err = -EINVAL;
681 goto fail;
682 }
683
684 PACKETDEBUG(skb->data, skb->len);
685
686 udsl_groom_skb(vcc, skb);
687 skb_queue_tail(&instance->sndqueue, skb);
688 tasklet_schedule(&instance->send_tasklet);
689
690 return 0;
691
692 fail:
693 udsl_pop(vcc, skb);
694 return err;
695}
696
697/********************
698** bean counting **
699********************/
700
701static void udsl_destroy_instance(struct kref *kref)
702{
703 struct udsl_instance_data *instance =
704 container_of(kref, struct udsl_instance_data, refcount);
705
706 tasklet_kill(&instance->receive_tasklet);
707 tasklet_kill(&instance->send_tasklet);
708 usb_put_dev(instance->usb_dev);
709 kfree(instance);
710}
711
712void udsl_get_instance(struct udsl_instance_data *instance)
713{
714 kref_get(&instance->refcount);
715}
716
717void udsl_put_instance(struct udsl_instance_data *instance)
718{
719 kref_put(&instance->refcount, udsl_destroy_instance);
720}
721
722/**********
723** ATM **
724**********/
725
726static void udsl_atm_dev_close(struct atm_dev *dev)
727{
728 struct udsl_instance_data *instance = dev->dev_data;
729
730 dev->dev_data = NULL;
731 udsl_put_instance(instance);
732}
733
734static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
735{
736 struct udsl_instance_data *instance = atm_dev->dev_data;
737 int left = *pos;
738
739 if (!instance) {
740 dbg("udsl_atm_proc_read: NULL instance!");
741 return -ENODEV;
742 }
743
744 if (!left--)
745 return sprintf(page, "%s\n", instance->description);
746
747 if (!left--)
748 return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
749 atm_dev->esi[0], atm_dev->esi[1],
750 atm_dev->esi[2], atm_dev->esi[3],
751 atm_dev->esi[4], atm_dev->esi[5]);
752
753 if (!left--)
754 return sprintf(page,
755 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
756 atomic_read(&atm_dev->stats.aal5.tx),
757 atomic_read(&atm_dev->stats.aal5.tx_err),
758 atomic_read(&atm_dev->stats.aal5.rx),
759 atomic_read(&atm_dev->stats.aal5.rx_err),
760 atomic_read(&atm_dev->stats.aal5.rx_drop));
761
762 if (!left--) {
763 switch (atm_dev->signal) {
764 case ATM_PHY_SIG_FOUND:
765 sprintf(page, "Line up");
766 break;
767 case ATM_PHY_SIG_LOST:
768 sprintf(page, "Line down");
769 break;
770 default:
771 sprintf(page, "Line state unknown");
772 break;
773 }
774
775 if (instance->usb_dev->state == USB_STATE_NOTATTACHED)
776 strcat(page, ", disconnected\n");
777 else {
778 if (instance->status == UDSL_LOADED_FIRMWARE)
779 strcat(page, ", firmware loaded\n");
780 else if (instance->status == UDSL_LOADING_FIRMWARE)
781 strcat(page, ", firmware loading\n");
782 else
783 strcat(page, ", no firmware\n");
784 }
785
786 return strlen(page);
787 }
788
789 return 0;
790}
791
792static int udsl_atm_open(struct atm_vcc *vcc)
793{
794 struct udsl_instance_data *instance = vcc->dev->dev_data;
795 struct udsl_vcc_data *new;
796 unsigned int max_pdu;
797 int vci = vcc->vci;
798 short vpi = vcc->vpi;
799 int err;
800
801 dbg("udsl_atm_open: vpi %hd, vci %d", vpi, vci);
802
803 if (!instance) {
804 dbg("udsl_atm_open: NULL data!");
805 return -ENODEV;
806 }
807
808 /* only support AAL5 */
809 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0)
810 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
811 dbg("udsl_atm_open: unsupported ATM type %d!", vcc->qos.aal);
812 return -EINVAL;
813 }
814
815 if (instance->firmware_wait &&
816 (err = instance->firmware_wait(instance)) < 0) {
817 dbg("udsl_atm_open: firmware not loaded (%d)!", err);
818 return err;
819 }
820
821 down(&instance->serialize); /* vs self, udsl_atm_close */
822
823 if (udsl_find_vcc(instance, vpi, vci)) {
824 dbg("udsl_atm_open: %hd/%d already in use!", vpi, vci);
825 up(&instance->serialize);
826 return -EADDRINUSE;
827 }
828
829 if (!(new = kmalloc(sizeof(struct udsl_vcc_data), GFP_KERNEL))) {
830 dbg("udsl_atm_open: no memory for vcc_data!");
831 up(&instance->serialize);
832 return -ENOMEM;
833 }
834
835 memset(new, 0, sizeof(struct udsl_vcc_data));
836 new->vcc = vcc;
837 new->vpi = vpi;
838 new->vci = vci;
839
840 /* udsl_extract_cells requires at least one cell */
841 max_pdu = max(1, UDSL_NUM_CELLS(vcc->qos.rxtp.max_sdu)) * ATM_CELL_PAYLOAD;
842 if (!(new->sarb = alloc_skb(max_pdu, GFP_KERNEL))) {
843 dbg("udsl_atm_open: no memory for SAR buffer!");
844 kfree(new);
845 up(&instance->serialize);
846 return -ENOMEM;
847 }
848
849 vcc->dev_data = new;
850
851 tasklet_disable(&instance->receive_tasklet);
852 list_add(&new->list, &instance->vcc_list);
853 tasklet_enable(&instance->receive_tasklet);
854
855 set_bit(ATM_VF_ADDR, &vcc->flags);
856 set_bit(ATM_VF_PARTIAL, &vcc->flags);
857 set_bit(ATM_VF_READY, &vcc->flags);
858
859 up(&instance->serialize);
860
861 tasklet_schedule(&instance->receive_tasklet);
862
863 dbg("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, max_pdu);
864
865 return 0;
866}
867
868static void udsl_atm_close(struct atm_vcc *vcc)
869{
870 struct udsl_instance_data *instance = vcc->dev->dev_data;
871 struct udsl_vcc_data *vcc_data = vcc->dev_data;
872
873 dbg("udsl_atm_close called");
874
875 if (!instance || !vcc_data) {
876 dbg("udsl_atm_close: NULL data!");
877 return;
878 }
879
880 dbg("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d",
881 vcc_data, vcc_data->vpi, vcc_data->vci);
882
883 udsl_cancel_send(instance, vcc);
884
885 down(&instance->serialize); /* vs self, udsl_atm_open */
886
887 tasklet_disable(&instance->receive_tasklet);
888 list_del(&vcc_data->list);
889 tasklet_enable(&instance->receive_tasklet);
890
891 kfree_skb(vcc_data->sarb);
892 vcc_data->sarb = NULL;
893
894 kfree(vcc_data);
895 vcc->dev_data = NULL;
896
897 vcc->vpi = ATM_VPI_UNSPEC;
898 vcc->vci = ATM_VCI_UNSPEC;
899 clear_bit(ATM_VF_READY, &vcc->flags);
900 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
901 clear_bit(ATM_VF_ADDR, &vcc->flags);
902
903 up(&instance->serialize);
904
905 dbg("udsl_atm_close successful");
906}
907
908static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
909 void __user * arg)
910{
911 switch (cmd) {
912 case ATM_QUERYLOOP:
913 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
914 default:
915 return -ENOIOCTLCMD;
916 }
917}
918
919/**********
920** USB **
921**********/
922
923int udsl_instance_setup(struct usb_device *dev,
924 struct udsl_instance_data *instance)
925{
926 char *buf;
927 int i, length;
928
929 kref_init(&instance->refcount); /* one for USB */
930 udsl_get_instance(instance); /* one for ATM */
931
932 init_MUTEX(&instance->serialize);
933
934 instance->usb_dev = dev;
935
936 INIT_LIST_HEAD(&instance->vcc_list);
937
938 instance->status = UDSL_NO_FIRMWARE;
939 init_waitqueue_head(&instance->firmware_waiters);
940
941 spin_lock_init(&instance->receive_lock);
942 INIT_LIST_HEAD(&instance->spare_receivers);
943 INIT_LIST_HEAD(&instance->filled_receive_buffers);
944
945 tasklet_init(&instance->receive_tasklet, udsl_process_receive, (unsigned long)instance);
946 INIT_LIST_HEAD(&instance->spare_receive_buffers);
947
948 skb_queue_head_init(&instance->sndqueue);
949
950 spin_lock_init(&instance->send_lock);
951 INIT_LIST_HEAD(&instance->spare_senders);
952 INIT_LIST_HEAD(&instance->spare_send_buffers);
953
954 tasklet_init(&instance->send_tasklet, udsl_process_send,
955 (unsigned long)instance);
956 INIT_LIST_HEAD(&instance->filled_send_buffers);
957
958 /* receive init */
959 for (i = 0; i < num_rcv_urbs; i++) {
960 struct udsl_receiver *rcv = &(instance->receivers[i]);
961
962 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
963 dbg("udsl_usb_probe: no memory for receive urb %d!", i);
964 goto fail;
965 }
966
967 rcv->instance = instance;
968
969 list_add(&rcv->list, &instance->spare_receivers);
970 }
971
972 for (i = 0; i < num_rcv_bufs; i++) {
973 struct udsl_receive_buffer *buf =
974 &(instance->receive_buffers[i]);
975
976 buf->base = kmalloc(rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding),
977 GFP_KERNEL);
978 if (!buf->base) {
979 dbg("udsl_usb_probe: no memory for receive buffer %d!", i);
980 goto fail;
981 }
982
983 list_add(&buf->list, &instance->spare_receive_buffers);
984 }
985
986 /* send init */
987 for (i = 0; i < num_snd_urbs; i++) {
988 struct udsl_sender *snd = &(instance->senders[i]);
989
990 if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) {
991 dbg("udsl_usb_probe: no memory for send urb %d!", i);
992 goto fail;
993 }
994
995 snd->instance = instance;
996
997 list_add(&snd->list, &instance->spare_senders);
998 }
999
1000 for (i = 0; i < num_snd_bufs; i++) {
1001 struct udsl_send_buffer *buf = &(instance->send_buffers[i]);
1002
1003 buf->base = kmalloc(snd_buf_size * (ATM_CELL_SIZE + instance->snd_padding),
1004 GFP_KERNEL);
1005 if (!buf->base) {
1006 dbg("udsl_usb_probe: no memory for send buffer %d!", i);
1007 goto fail;
1008 }
1009
1010 list_add(&buf->list, &instance->spare_send_buffers);
1011 }
1012
1013 /* ATM init */
1014 instance->atm_dev = atm_dev_register(instance->driver_name,
1015 &udsl_atm_devops, -1, NULL);
1016 if (!instance->atm_dev) {
1017 dbg("udsl_usb_probe: failed to register ATM device!");
1018 goto fail;
1019 }
1020
1021 instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
1022 instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX;
1023 instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
1024
1025 /* temp init ATM device, set to 128kbit */
1026 instance->atm_dev->link_rate = 128 * 1000 / 424;
1027
1028 /* device description */
1029 buf = instance->description;
1030 length = sizeof(instance->description);
1031
1032 if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0)
1033 goto finish;
1034
1035 buf += i;
1036 length -= i;
1037
1038 i = scnprintf(buf, length, " (");
1039 buf += i;
1040 length -= i;
1041
1042 if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0)
1043 goto finish;
1044
1045 buf += i;
1046 length -= i;
1047
1048 snprintf(buf, length, ")");
1049
1050 finish:
1051 /* ready for ATM callbacks */
1052 wmb();
1053 instance->atm_dev->dev_data = instance;
1054
1055 usb_get_dev(dev);
1056
1057 return 0;
1058
1059 fail:
1060 for (i = 0; i < num_snd_bufs; i++)
1061 kfree(instance->send_buffers[i].base);
1062
1063 for (i = 0; i < num_snd_urbs; i++)
1064 usb_free_urb(instance->senders[i].urb);
1065
1066 for (i = 0; i < num_rcv_bufs; i++)
1067 kfree(instance->receive_buffers[i].base);
1068
1069 for (i = 0; i < num_rcv_urbs; i++)
1070 usb_free_urb(instance->receivers[i].urb);
1071
1072 return -ENOMEM;
1073}
1074
1075void udsl_instance_disconnect(struct udsl_instance_data *instance)
1076{
1077 int i;
1078
1079 dbg("udsl_instance_disconnect entered");
1080
1081 if (!instance) {
1082 dbg("udsl_instance_disconnect: NULL instance!");
1083 return;
1084 }
1085
1086 /* receive finalize */
1087 tasklet_disable(&instance->receive_tasklet);
1088
1089 for (i = 0; i < num_rcv_urbs; i++)
1090 usb_kill_urb(instance->receivers[i].urb);
1091
1092 /* no need to take the spinlock */
1093 INIT_LIST_HEAD(&instance->filled_receive_buffers);
1094 INIT_LIST_HEAD(&instance->spare_receive_buffers);
1095
1096 tasklet_enable(&instance->receive_tasklet);
1097
1098 for (i = 0; i < num_rcv_urbs; i++)
1099 usb_free_urb(instance->receivers[i].urb);
1100
1101 for (i = 0; i < num_rcv_bufs; i++)
1102 kfree(instance->receive_buffers[i].base);
1103
1104 /* send finalize */
1105 tasklet_disable(&instance->send_tasklet);
1106
1107 for (i = 0; i < num_snd_urbs; i++)
1108 usb_kill_urb(instance->senders[i].urb);
1109
1110 /* no need to take the spinlock */
1111 INIT_LIST_HEAD(&instance->spare_senders);
1112 INIT_LIST_HEAD(&instance->spare_send_buffers);
1113 instance->current_buffer = NULL;
1114
1115 tasklet_enable(&instance->send_tasklet);
1116
1117 for (i = 0; i < num_snd_urbs; i++)
1118 usb_free_urb(instance->senders[i].urb);
1119
1120 for (i = 0; i < num_snd_bufs; i++)
1121 kfree(instance->send_buffers[i].base);
1122
1123 /* ATM finalize */
1124 shutdown_atm_dev(instance->atm_dev);
1125}
1126
1127EXPORT_SYMBOL_GPL(udsl_get_instance);
1128EXPORT_SYMBOL_GPL(udsl_put_instance);
1129EXPORT_SYMBOL_GPL(udsl_instance_setup);
1130EXPORT_SYMBOL_GPL(udsl_instance_disconnect);
1131
1132/***********
1133** init **
1134***********/
1135
1136static int __init udsl_usb_init(void)
1137{
1138 dbg("udsl_usb_init: driver version " DRIVER_VERSION);
1139
1140 if (sizeof(struct udsl_control) > sizeof(((struct sk_buff *) 0)->cb)) {
1141 printk(KERN_ERR __FILE__ ": unusable with this kernel!\n");
1142 return -EIO;
1143 }
1144
1145 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
1146 || (num_snd_urbs > UDSL_MAX_SND_URBS)
1147 || (num_rcv_bufs > UDSL_MAX_RCV_BUFS)
1148 || (num_snd_bufs > UDSL_MAX_SND_BUFS)
1149 || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
1150 || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
1151 return -EINVAL;
1152
1153 return 0;
1154}
1155
1156static void __exit udsl_usb_exit(void)
1157{
1158}
1159
1160module_init(udsl_usb_init);
1161module_exit(udsl_usb_exit);
1162
1163MODULE_AUTHOR(DRIVER_AUTHOR);
1164MODULE_DESCRIPTION(DRIVER_DESC);
1165MODULE_LICENSE("GPL");
1166MODULE_VERSION(DRIVER_VERSION);
1167
1168/************
1169** debug **
1170************/
1171
1172#ifdef VERBOSE_DEBUG
1173static int udsl_print_packet(const unsigned char *data, int len)
1174{
1175 unsigned char buffer[256];
1176 int i = 0, j = 0;
1177
1178 for (i = 0; i < len;) {
1179 buffer[0] = '\0';
1180 sprintf(buffer, "%.3d :", i);
1181 for (j = 0; (j < 16) && (i < len); j++, i++) {
1182 sprintf(buffer, "%s %2.2x", buffer, data[i]);
1183 }
1184 dbg("%s", buffer);
1185 }
1186 return i;
1187}
1188#endif
diff --git a/drivers/usb/atm/usb_atm.h b/drivers/usb/atm/usb_atm.h
deleted file mode 100644
index cf8c53283530..000000000000
--- a/drivers/usb/atm/usb_atm.h
+++ /dev/null
@@ -1,176 +0,0 @@
1/******************************************************************************
2 * usb_atm.h - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24#include <linux/config.h>
25#include <linux/list.h>
26#include <linux/kref.h>
27#include <linux/atm.h>
28#include <linux/atmdev.h>
29#include <asm/semaphore.h>
30
31/*
32#define DEBUG
33#define VERBOSE_DEBUG
34*/
35
36#if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
37# define DEBUG
38#endif
39
40#include <linux/usb.h>
41
42#ifdef DEBUG
43#define UDSL_ASSERT(x) BUG_ON(!(x))
44#else
45#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '" #x "' at line %d", __LINE__); } while(0)
46#endif
47
48#define UDSL_MAX_RCV_URBS 4
49#define UDSL_MAX_SND_URBS 4
50#define UDSL_MAX_RCV_BUFS 8
51#define UDSL_MAX_SND_BUFS 8
52#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
53#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
54#define UDSL_DEFAULT_RCV_URBS 2
55#define UDSL_DEFAULT_SND_URBS 2
56#define UDSL_DEFAULT_RCV_BUFS 4
57#define UDSL_DEFAULT_SND_BUFS 4
58#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
59#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
60
61#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
62#define UDSL_NUM_CELLS(x) (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD)
63
64/* receive */
65
66struct udsl_receive_buffer {
67 struct list_head list;
68 unsigned char *base;
69 unsigned int filled_cells;
70};
71
72struct udsl_receiver {
73 struct list_head list;
74 struct udsl_receive_buffer *buffer;
75 struct urb *urb;
76 struct udsl_instance_data *instance;
77};
78
79struct udsl_vcc_data {
80 /* vpi/vci lookup */
81 struct list_head list;
82 short vpi;
83 int vci;
84 struct atm_vcc *vcc;
85
86 /* raw cell reassembly */
87 struct sk_buff *sarb;
88};
89
90/* send */
91
92struct udsl_send_buffer {
93 struct list_head list;
94 unsigned char *base;
95 unsigned char *free_start;
96 unsigned int free_cells;
97};
98
99struct udsl_sender {
100 struct list_head list;
101 struct udsl_send_buffer *buffer;
102 struct urb *urb;
103 struct udsl_instance_data *instance;
104};
105
106struct udsl_control {
107 struct atm_skb_data atm_data;
108 unsigned int num_cells;
109 unsigned int num_entire;
110 unsigned int pdu_padding;
111 unsigned char aal5_trailer[ATM_AAL5_TRAILER];
112};
113
114#define UDSL_SKB(x) ((struct udsl_control *)(x)->cb)
115
116/* main driver data */
117
118enum udsl_status {
119 UDSL_NO_FIRMWARE,
120 UDSL_LOADING_FIRMWARE,
121 UDSL_LOADED_FIRMWARE
122};
123
124struct udsl_instance_data {
125 struct kref refcount;
126 struct semaphore serialize;
127
128 /* USB device part */
129 struct usb_device *usb_dev;
130 char description[64];
131 int data_endpoint;
132 int snd_padding;
133 int rcv_padding;
134 const char *driver_name;
135
136 /* ATM device part */
137 struct atm_dev *atm_dev;
138 struct list_head vcc_list;
139
140 /* firmware */
141 int (*firmware_wait) (struct udsl_instance_data *);
142 enum udsl_status status;
143 wait_queue_head_t firmware_waiters;
144
145 /* receive */
146 struct udsl_receiver receivers[UDSL_MAX_RCV_URBS];
147 struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS];
148
149 spinlock_t receive_lock;
150 struct list_head spare_receivers;
151 struct list_head filled_receive_buffers;
152
153 struct tasklet_struct receive_tasklet;
154 struct list_head spare_receive_buffers;
155
156 /* send */
157 struct udsl_sender senders[UDSL_MAX_SND_URBS];
158 struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS];
159
160 struct sk_buff_head sndqueue;
161
162 spinlock_t send_lock;
163 struct list_head spare_senders;
164 struct list_head spare_send_buffers;
165
166 struct tasklet_struct send_tasklet;
167 struct sk_buff *current_skb; /* being emptied */
168 struct udsl_send_buffer *current_buffer; /* being filled */
169 struct list_head filled_send_buffers;
170};
171
172extern int udsl_instance_setup(struct usb_device *dev,
173 struct udsl_instance_data *instance);
174extern void udsl_instance_disconnect(struct udsl_instance_data *instance);
175extern void udsl_get_instance(struct udsl_instance_data *instance);
176extern void udsl_put_instance(struct udsl_instance_data *instance);
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
new file mode 100644
index 000000000000..bb1db1959854
--- /dev/null
+++ b/drivers/usb/atm/usbatm.c
@@ -0,0 +1,1230 @@
1/******************************************************************************
2 * usbatm.c - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse, Roman Kagan
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24/*
25 * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse
26 *
27 * 1.7+: - See the check-in logs
28 *
29 * 1.6: - No longer opens a connection if the firmware is not loaded
30 * - Added support for the speedtouch 330
31 * - Removed the limit on the number of devices
32 * - Module now autoloads on device plugin
33 * - Merged relevant parts of sarlib
34 * - Replaced the kernel thread with a tasklet
35 * - New packet transmission code
36 * - Changed proc file contents
37 * - Fixed all known SMP races
38 * - Many fixes and cleanups
39 * - Various fixes by Oliver Neukum (oliver@neukum.name)
40 *
41 * 1.5A: - Version for inclusion in 2.5 series kernel
42 * - Modifications by Richard Purdie (rpurdie@rpsys.net)
43 * - made compatible with kernel 2.5.6 onwards by changing
44 * usbatm_usb_send_data_context->urb to a pointer and adding code
45 * to alloc and free it
46 * - remove_wait_queue() added to usbatm_atm_processqueue_thread()
47 *
48 * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
49 * (reported by stephen.robinson@zen.co.uk)
50 *
51 * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave()
52 * - unlink all active send urbs of a vcc that is being closed.
53 *
54 * 1.3.1: - added the version number
55 *
56 * 1.3: - Added multiple send urb support
57 * - fixed memory leak and vcc->tx_inuse starvation bug
58 * when not enough memory left in vcc.
59 *
60 * 1.2: - Fixed race condition in usbatm_usb_send_data()
61 * 1.1: - Turned off packet debugging
62 *
63 */
64
65#include "usbatm.h"
66
67#include <asm/uaccess.h>
68#include <linux/crc32.h>
69#include <linux/errno.h>
70#include <linux/init.h>
71#include <linux/interrupt.h>
72#include <linux/kernel.h>
73#include <linux/module.h>
74#include <linux/moduleparam.h>
75#include <linux/proc_fs.h>
76#include <linux/sched.h>
77#include <linux/signal.h>
78#include <linux/slab.h>
79#include <linux/smp_lock.h>
80#include <linux/stat.h>
81#include <linux/timer.h>
82#include <linux/wait.h>
83
84#ifdef VERBOSE_DEBUG
85static int usbatm_print_packet(const unsigned char *data, int len);
86#define PACKETDEBUG(arg...) usbatm_print_packet (arg)
87#define vdbg(arg...) dbg (arg)
88#else
89#define PACKETDEBUG(arg...)
90#define vdbg(arg...)
91#endif
92
93#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
94#define DRIVER_VERSION "1.9"
95#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
96
97static const char usbatm_driver_name[] = "usbatm";
98
99#define UDSL_MAX_RCV_URBS 16
100#define UDSL_MAX_SND_URBS 16
101#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
102#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
103#define UDSL_DEFAULT_RCV_URBS 4
104#define UDSL_DEFAULT_SND_URBS 4
105#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
106#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
107
108#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
109
110#define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */
111
112static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
113static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
114static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
115static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
116
117module_param(num_rcv_urbs, uint, S_IRUGO);
118MODULE_PARM_DESC(num_rcv_urbs,
119 "Number of urbs used for reception (range: 0-"
120 __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
121 __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
122
123module_param(num_snd_urbs, uint, S_IRUGO);
124MODULE_PARM_DESC(num_snd_urbs,
125 "Number of urbs used for transmission (range: 0-"
126 __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
127 __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
128
129module_param(rcv_buf_size, uint, S_IRUGO);
130MODULE_PARM_DESC(rcv_buf_size,
131 "Size of the buffers used for reception in ATM cells (range: 1-"
132 __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
133 __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
134
135module_param(snd_buf_size, uint, S_IRUGO);
136MODULE_PARM_DESC(snd_buf_size,
137 "Size of the buffers used for transmission in ATM cells (range: 1-"
138 __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
139 __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
140
141
142/* receive */
143
144struct usbatm_vcc_data {
145 /* vpi/vci lookup */
146 struct list_head list;
147 short vpi;
148 int vci;
149 struct atm_vcc *vcc;
150
151 /* raw cell reassembly */
152 struct sk_buff *sarb;
153};
154
155
156/* send */
157
158struct usbatm_control {
159 struct atm_skb_data atm;
160 u32 len;
161 u32 crc;
162};
163
164#define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb)
165
166
167/* ATM */
168
169static void usbatm_atm_dev_close(struct atm_dev *dev);
170static int usbatm_atm_open(struct atm_vcc *vcc);
171static void usbatm_atm_close(struct atm_vcc *vcc);
172static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
175
176static struct atmdev_ops usbatm_atm_devops = {
177 .dev_close = usbatm_atm_dev_close,
178 .open = usbatm_atm_open,
179 .close = usbatm_atm_close,
180 .ioctl = usbatm_atm_ioctl,
181 .send = usbatm_atm_send,
182 .proc_read = usbatm_atm_proc_read,
183 .owner = THIS_MODULE,
184};
185
186
187/***********
188** misc **
189***********/
190
191static inline unsigned int usbatm_pdu_length(unsigned int length)
192{
193 length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER;
194 return length - length % ATM_CELL_PAYLOAD;
195}
196
197static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
198{
199 if (vcc->pop)
200 vcc->pop(vcc, skb);
201 else
202 dev_kfree_skb(skb);
203}
204
205
206/***********
207** urbs **
208************/
209
210static inline struct urb *usbatm_pop_urb(struct usbatm_channel *channel)
211{
212 struct urb *urb;
213
214 spin_lock_irq(&channel->lock);
215 if (list_empty(&channel->list)) {
216 spin_unlock_irq(&channel->lock);
217 return NULL;
218 }
219
220 urb = list_entry(channel->list.next, struct urb, urb_list);
221 list_del(&urb->urb_list);
222 spin_unlock_irq(&channel->lock);
223
224 return urb;
225}
226
227static inline int usbatm_submit_urb(struct urb *urb)
228{
229 struct usbatm_channel *channel = urb->context;
230 int ret;
231
232 vdbg("%s: submitting urb 0x%p, size %u",
233 __func__, urb, urb->transfer_buffer_length);
234
235 ret = usb_submit_urb(urb, GFP_ATOMIC);
236 if (ret) {
237 atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
238 __func__, urb, ret);
239
240 /* consider all errors transient and return the buffer back to the queue */
241 urb->status = -EAGAIN;
242 spin_lock_irq(&channel->lock);
243
244 /* must add to the front when sending; doesn't matter when receiving */
245 list_add(&urb->urb_list, &channel->list);
246
247 spin_unlock_irq(&channel->lock);
248
249 /* make sure the channel doesn't stall */
250 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
251 }
252
253 return ret;
254}
255
256static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
257{
258 struct usbatm_channel *channel = urb->context;
259 unsigned long flags;
260
261 vdbg("%s: urb 0x%p, status %d, actual_length %d",
262 __func__, urb, urb->status, urb->actual_length);
263
264 /* usually in_interrupt(), but not always */
265 spin_lock_irqsave(&channel->lock, flags);
266
267 /* must add to the back when receiving; doesn't matter when sending */
268 list_add_tail(&urb->urb_list, &channel->list);
269
270 spin_unlock_irqrestore(&channel->lock, flags);
271
272 if (unlikely(urb->status))
273 /* throttle processing in case of an error */
274 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
275 else
276 tasklet_schedule(&channel->tasklet);
277}
278
279
280/*************
281** decode **
282*************/
283
284static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
285 short vpi, int vci)
286{
287 struct usbatm_vcc_data *vcc;
288
289 list_for_each_entry(vcc, &instance->vcc_list, list)
290 if ((vcc->vci == vci) && (vcc->vpi == vpi))
291 return vcc;
292 return NULL;
293}
294
295static void usbatm_extract_cells(struct usbatm_data *instance,
296 unsigned char *source, unsigned int avail_data)
297{
298 struct usbatm_vcc_data *cached_vcc = NULL;
299 struct atm_vcc *vcc;
300 struct sk_buff *sarb;
301 unsigned int stride = instance->rx_channel.stride;
302 int vci, cached_vci = 0;
303 short vpi, cached_vpi = 0;
304 u8 pti;
305
306 for (; avail_data >= stride; avail_data -= stride, source += stride) {
307 vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
308 vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
309 pti = ((source[3] & 0xe) >> 1);
310
311 vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
312
313 if ((vci != cached_vci) || (vpi != cached_vpi)) {
314 cached_vpi = vpi;
315 cached_vci = vci;
316
317 cached_vcc = usbatm_find_vcc(instance, vpi, vci);
318
319 if (!cached_vcc)
320 atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
321 }
322
323 if (!cached_vcc)
324 continue;
325
326 vcc = cached_vcc->vcc;
327
328 /* OAM F5 end-to-end */
329 if (pti == ATM_PTI_E2EF5) {
330 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci);
331 atomic_inc(&vcc->stats->rx_err);
332 continue;
333 }
334
335 sarb = cached_vcc->sarb;
336
337 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
338 atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
339 __func__, sarb->len, vcc);
340 /* discard cells already received */
341 skb_trim(sarb, 0);
342 UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
343 }
344
345 memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
346 __skb_put(sarb, ATM_CELL_PAYLOAD);
347
348 if (pti & 1) {
349 struct sk_buff *skb;
350 unsigned int length;
351 unsigned int pdu_length;
352
353 length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
354
355 /* guard against overflow */
356 if (length > ATM_MAX_AAL5_PDU) {
357 atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
358 __func__, length, vcc);
359 atomic_inc(&vcc->stats->rx_err);
360 goto out;
361 }
362
363 pdu_length = usbatm_pdu_length(length);
364
365 if (sarb->len < pdu_length) {
366 atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
367 __func__, pdu_length, sarb->len, vcc);
368 atomic_inc(&vcc->stats->rx_err);
369 goto out;
370 }
371
372 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
373 atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
374 __func__, vcc);
375 atomic_inc(&vcc->stats->rx_err);
376 goto out;
377 }
378
379 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
380
381 if (!(skb = dev_alloc_skb(length))) {
382 atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length);
383 atomic_inc(&vcc->stats->rx_drop);
384 goto out;
385 }
386
387 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
388
389 if (!atm_charge(vcc, skb->truesize)) {
390 atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize);
391 dev_kfree_skb(skb);
392 goto out; /* atm_charge increments rx_drop */
393 }
394
395 memcpy(skb->data, sarb->tail - pdu_length, length);
396 __skb_put(skb, length);
397
398 vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u",
399 __func__, skb, skb->len, skb->truesize);
400
401 PACKETDEBUG(skb->data, skb->len);
402
403 vcc->push(vcc, skb);
404
405 atomic_inc(&vcc->stats->rx);
406 out:
407 skb_trim(sarb, 0);
408 }
409 }
410}
411
412
413/*************
414** encode **
415*************/
416
417static unsigned int usbatm_write_cells(struct usbatm_data *instance,
418 struct sk_buff *skb,
419 u8 *target, unsigned int avail_space)
420{
421 struct usbatm_control *ctrl = UDSL_SKB(skb);
422 struct atm_vcc *vcc = ctrl->atm.vcc;
423 unsigned int num_written;
424 unsigned int stride = instance->tx_channel.stride;
425
426 vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space);
427 UDSL_ASSERT(!(avail_space % stride));
428
429 for (num_written = 0; num_written < avail_space && ctrl->len;
430 num_written += stride, target += stride) {
431 unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
432 unsigned int left = ATM_CELL_PAYLOAD - data_len;
433 u8 *ptr = target;
434
435 ptr[0] = vcc->vpi >> 4;
436 ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
437 ptr[2] = vcc->vci >> 4;
438 ptr[3] = vcc->vci << 4;
439 ptr[4] = 0xec;
440 ptr += ATM_CELL_HEADER;
441
442 memcpy(ptr, skb->data, data_len);
443 ptr += data_len;
444 __skb_pull(skb, data_len);
445
446 if(!left)
447 continue;
448
449 memset(ptr, 0, left);
450
451 if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */
452 u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER;
453 /* trailer[0] = 0; UU = 0 */
454 /* trailer[1] = 0; CPI = 0 */
455 trailer[2] = ctrl->len >> 8;
456 trailer[3] = ctrl->len;
457
458 ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4);
459
460 trailer[4] = ctrl->crc >> 24;
461 trailer[5] = ctrl->crc >> 16;
462 trailer[6] = ctrl->crc >> 8;
463 trailer[7] = ctrl->crc;
464
465 target[3] |= 0x2; /* adjust PTI */
466
467 ctrl->len = 0; /* tag this skb finished */
468 }
469 else
470 ctrl->crc = crc32_be(ctrl->crc, ptr, left);
471 }
472
473 return num_written;
474}
475
476
477/**************
478** receive **
479**************/
480
481static void usbatm_rx_process(unsigned long data)
482{
483 struct usbatm_data *instance = (struct usbatm_data *)data;
484 struct urb *urb;
485
486 while ((urb = usbatm_pop_urb(&instance->rx_channel))) {
487 vdbg("%s: processing urb 0x%p", __func__, urb);
488
489 if (usb_pipeisoc(urb->pipe)) {
490 int i;
491 for (i = 0; i < urb->number_of_packets; i++)
492 if (!urb->iso_frame_desc[i].status)
493 usbatm_extract_cells(instance,
494 (u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset,
495 urb->iso_frame_desc[i].actual_length);
496 }
497 else
498 if (!urb->status)
499 usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length);
500
501 if (usbatm_submit_urb(urb))
502 return;
503 }
504}
505
506
507/***********
508** send **
509***********/
510
511static void usbatm_tx_process(unsigned long data)
512{
513 struct usbatm_data *instance = (struct usbatm_data *)data;
514 struct sk_buff *skb = instance->current_skb;
515 struct urb *urb = NULL;
516 const unsigned int buf_size = instance->tx_channel.buf_size;
517 unsigned int num_written = 0;
518 u8 *buffer = NULL;
519
520 if (!skb)
521 skb = skb_dequeue(&instance->sndqueue);
522
523 while (skb) {
524 if (!urb) {
525 urb = usbatm_pop_urb(&instance->tx_channel);
526 if (!urb)
527 break; /* no more senders */
528 buffer = urb->transfer_buffer;
529 num_written = (urb->status == -EAGAIN) ?
530 urb->transfer_buffer_length : 0;
531 }
532
533 num_written += usbatm_write_cells(instance, skb,
534 buffer + num_written,
535 buf_size - num_written);
536
537 vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p",
538 __func__, num_written, skb, urb);
539
540 if (!UDSL_SKB(skb)->len) {
541 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
542
543 usbatm_pop(vcc, skb);
544 atomic_inc(&vcc->stats->tx);
545
546 skb = skb_dequeue(&instance->sndqueue);
547 }
548
549 if (num_written == buf_size || (!skb && num_written)) {
550 urb->transfer_buffer_length = num_written;
551
552 if (usbatm_submit_urb(urb))
553 break;
554 urb = NULL;
555 }
556 }
557
558 instance->current_skb = skb;
559}
560
561static void usbatm_cancel_send(struct usbatm_data *instance,
562 struct atm_vcc *vcc)
563{
564 struct sk_buff *skb, *n;
565
566 atm_dbg(instance, "%s entered\n", __func__);
567 spin_lock_irq(&instance->sndqueue.lock);
568 for (skb = instance->sndqueue.next, n = skb->next;
569 skb != (struct sk_buff *)&instance->sndqueue;
570 skb = n, n = skb->next)
571 if (UDSL_SKB(skb)->atm.vcc == vcc) {
572 atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb);
573 __skb_unlink(skb, &instance->sndqueue);
574 usbatm_pop(vcc, skb);
575 }
576 spin_unlock_irq(&instance->sndqueue.lock);
577
578 tasklet_disable(&instance->tx_channel.tasklet);
579 if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) {
580 atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb);
581 instance->current_skb = NULL;
582 usbatm_pop(vcc, skb);
583 }
584 tasklet_enable(&instance->tx_channel.tasklet);
585 atm_dbg(instance, "%s done\n", __func__);
586}
587
588static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
589{
590 struct usbatm_data *instance = vcc->dev->dev_data;
591 struct usbatm_control *ctrl = UDSL_SKB(skb);
592 int err;
593
594 vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len);
595
596 if (!instance) {
597 dbg("%s: NULL data!", __func__);
598 err = -ENODEV;
599 goto fail;
600 }
601
602 if (vcc->qos.aal != ATM_AAL5) {
603 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
604 err = -EINVAL;
605 goto fail;
606 }
607
608 if (skb->len > ATM_MAX_AAL5_PDU) {
609 atm_dbg(instance, "%s: packet too long (%d vs %d)!\n",
610 __func__, skb->len, ATM_MAX_AAL5_PDU);
611 err = -EINVAL;
612 goto fail;
613 }
614
615 PACKETDEBUG(skb->data, skb->len);
616
617 /* initialize the control block */
618 ctrl->atm.vcc = vcc;
619 ctrl->len = skb->len;
620 ctrl->crc = crc32_be(~0, skb->data, skb->len);
621
622 skb_queue_tail(&instance->sndqueue, skb);
623 tasklet_schedule(&instance->tx_channel.tasklet);
624
625 return 0;
626
627 fail:
628 usbatm_pop(vcc, skb);
629 return err;
630}
631
632
633/********************
634** bean counting **
635********************/
636
637static void usbatm_destroy_instance(struct kref *kref)
638{
639 struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount);
640
641 dbg("%s", __func__);
642
643 tasklet_kill(&instance->rx_channel.tasklet);
644 tasklet_kill(&instance->tx_channel.tasklet);
645 usb_put_dev(instance->usb_dev);
646 kfree(instance);
647}
648
649void usbatm_get_instance(struct usbatm_data *instance)
650{
651 dbg("%s", __func__);
652
653 kref_get(&instance->refcount);
654}
655
656void usbatm_put_instance(struct usbatm_data *instance)
657{
658 dbg("%s", __func__);
659
660 kref_put(&instance->refcount, usbatm_destroy_instance);
661}
662
663
664/**********
665** ATM **
666**********/
667
668static void usbatm_atm_dev_close(struct atm_dev *dev)
669{
670 struct usbatm_data *instance = dev->dev_data;
671
672 dbg("%s", __func__);
673
674 if (!instance)
675 return;
676
677 dev->dev_data = NULL;
678 usbatm_put_instance(instance); /* taken in usbatm_atm_init */
679}
680
681static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
682{
683 struct usbatm_data *instance = atm_dev->dev_data;
684 int left = *pos;
685
686 if (!instance) {
687 dbg("%s: NULL instance!", __func__);
688 return -ENODEV;
689 }
690
691 if (!left--)
692 return sprintf(page, "%s\n", instance->description);
693
694 if (!left--)
695 return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
696 atm_dev->esi[0], atm_dev->esi[1],
697 atm_dev->esi[2], atm_dev->esi[3],
698 atm_dev->esi[4], atm_dev->esi[5]);
699
700 if (!left--)
701 return sprintf(page,
702 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
703 atomic_read(&atm_dev->stats.aal5.tx),
704 atomic_read(&atm_dev->stats.aal5.tx_err),
705 atomic_read(&atm_dev->stats.aal5.rx),
706 atomic_read(&atm_dev->stats.aal5.rx_err),
707 atomic_read(&atm_dev->stats.aal5.rx_drop));
708
709 if (!left--)
710 switch (atm_dev->signal) {
711 case ATM_PHY_SIG_FOUND:
712 return sprintf(page, "Line up\n");
713 case ATM_PHY_SIG_LOST:
714 return sprintf(page, "Line down\n");
715 default:
716 return sprintf(page, "Line state unknown\n");
717 }
718
719 return 0;
720}
721
722static int usbatm_atm_open(struct atm_vcc *vcc)
723{
724 struct usbatm_data *instance = vcc->dev->dev_data;
725 struct usbatm_vcc_data *new = NULL;
726 int ret;
727 int vci = vcc->vci;
728 short vpi = vcc->vpi;
729
730 if (!instance) {
731 dbg("%s: NULL data!", __func__);
732 return -ENODEV;
733 }
734
735 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
736
737 /* only support AAL5 */
738 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0)
739 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
740 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
741 return -EINVAL;
742 }
743
744 down(&instance->serialize); /* vs self, usbatm_atm_close */
745
746 if (usbatm_find_vcc(instance, vpi, vci)) {
747 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
748 ret = -EADDRINUSE;
749 goto fail;
750 }
751
752 if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
753 atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__);
754 ret = -ENOMEM;
755 goto fail;
756 }
757
758 memset(new, 0, sizeof(struct usbatm_vcc_data));
759 new->vcc = vcc;
760 new->vpi = vpi;
761 new->vci = vci;
762
763 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
764 if (!new->sarb) {
765 atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__);
766 ret = -ENOMEM;
767 goto fail;
768 }
769
770 vcc->dev_data = new;
771
772 tasklet_disable(&instance->rx_channel.tasklet);
773 list_add(&new->list, &instance->vcc_list);
774 tasklet_enable(&instance->rx_channel.tasklet);
775
776 set_bit(ATM_VF_ADDR, &vcc->flags);
777 set_bit(ATM_VF_PARTIAL, &vcc->flags);
778 set_bit(ATM_VF_READY, &vcc->flags);
779
780 up(&instance->serialize);
781
782 atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new);
783
784 return 0;
785
786fail:
787 kfree(new);
788 up(&instance->serialize);
789 return ret;
790}
791
792static void usbatm_atm_close(struct atm_vcc *vcc)
793{
794 struct usbatm_data *instance = vcc->dev->dev_data;
795 struct usbatm_vcc_data *vcc_data = vcc->dev_data;
796
797 if (!instance || !vcc_data) {
798 dbg("%s: NULL data!", __func__);
799 return;
800 }
801
802 atm_dbg(instance, "%s entered\n", __func__);
803
804 atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n",
805 __func__, vcc_data, vcc_data->vpi, vcc_data->vci);
806
807 usbatm_cancel_send(instance, vcc);
808
809 down(&instance->serialize); /* vs self, usbatm_atm_open */
810
811 tasklet_disable(&instance->rx_channel.tasklet);
812 list_del(&vcc_data->list);
813 tasklet_enable(&instance->rx_channel.tasklet);
814
815 kfree_skb(vcc_data->sarb);
816 vcc_data->sarb = NULL;
817
818 kfree(vcc_data);
819 vcc->dev_data = NULL;
820
821 vcc->vpi = ATM_VPI_UNSPEC;
822 vcc->vci = ATM_VCI_UNSPEC;
823 clear_bit(ATM_VF_READY, &vcc->flags);
824 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
825 clear_bit(ATM_VF_ADDR, &vcc->flags);
826
827 up(&instance->serialize);
828
829 atm_dbg(instance, "%s successful\n", __func__);
830}
831
832static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
833 void __user * arg)
834{
835 switch (cmd) {
836 case ATM_QUERYLOOP:
837 return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0;
838 default:
839 return -ENOIOCTLCMD;
840 }
841}
842
843static int usbatm_atm_init(struct usbatm_data *instance)
844{
845 struct atm_dev *atm_dev;
846 int ret, i;
847
848 /* ATM init */
849 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
850 if (!atm_dev) {
851 usb_dbg(instance, "%s: failed to register ATM device!\n", __func__);
852 return -1;
853 }
854
855 instance->atm_dev = atm_dev;
856
857 atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
858 atm_dev->ci_range.vci_bits = ATM_CI_MAX;
859 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
860
861 /* temp init ATM device, set to 128kbit */
862 atm_dev->link_rate = 128 * 1000 / 424;
863
864 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
865 atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret);
866 goto fail;
867 }
868
869 /* ready for ATM callbacks */
870 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
871 mb();
872 atm_dev->dev_data = instance;
873
874 /* submit all rx URBs */
875 for (i = 0; i < num_rcv_urbs; i++)
876 usbatm_submit_urb(instance->urbs[i]);
877
878 return 0;
879
880 fail:
881 instance->atm_dev = NULL;
882 shutdown_atm_dev(atm_dev); /* usbatm_atm_dev_close will eventually be called */
883 return ret;
884}
885
886
887/**********
888** USB **
889**********/
890
891static int usbatm_do_heavy_init(void *arg)
892{
893 struct usbatm_data *instance = arg;
894 int ret;
895
896 daemonize(instance->driver->driver_name);
897 allow_signal(SIGTERM);
898
899 complete(&instance->thread_started);
900
901 ret = instance->driver->heavy_init(instance, instance->usb_intf);
902
903 if (!ret)
904 ret = usbatm_atm_init(instance);
905
906 down(&instance->serialize);
907 instance->thread_pid = -1;
908 up(&instance->serialize);
909
910 complete_and_exit(&instance->thread_exited, ret);
911}
912
913static int usbatm_heavy_init(struct usbatm_data *instance)
914{
915 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
916
917 if (ret < 0) {
918 usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
919 return ret;
920 }
921
922 down(&instance->serialize);
923 instance->thread_pid = ret;
924 up(&instance->serialize);
925
926 wait_for_completion(&instance->thread_started);
927
928 return 0;
929}
930
931static void usbatm_tasklet_schedule(unsigned long data)
932{
933 tasklet_schedule((struct tasklet_struct *) data);
934}
935
936static inline void usbatm_init_channel(struct usbatm_channel *channel)
937{
938 spin_lock_init(&channel->lock);
939 INIT_LIST_HEAD(&channel->list);
940 channel->delay.function = usbatm_tasklet_schedule;
941 channel->delay.data = (unsigned long) &channel->tasklet;
942 init_timer(&channel->delay);
943}
944
945int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
946 struct usbatm_driver *driver)
947{
948 struct device *dev = &intf->dev;
949 struct usb_device *usb_dev = interface_to_usbdev(intf);
950 struct usbatm_data *instance;
951 char *buf;
952 int error = -ENOMEM;
953 int i, length;
954 int need_heavy;
955
956 dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n",
957 __func__, driver->driver_name,
958 le16_to_cpu(usb_dev->descriptor.idVendor),
959 le16_to_cpu(usb_dev->descriptor.idProduct),
960 intf->altsetting->desc.bInterfaceNumber);
961
962 /* instance init */
963 instance = kcalloc(1, sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
964 if (!instance) {
965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__);
966 return -ENOMEM;
967 }
968
969 /* public fields */
970
971 instance->driver = driver;
972 snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name);
973
974 instance->usb_dev = usb_dev;
975 instance->usb_intf = intf;
976
977 buf = instance->description;
978 length = sizeof(instance->description);
979
980 if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0)
981 goto bind;
982
983 buf += i;
984 length -= i;
985
986 i = scnprintf(buf, length, " (");
987 buf += i;
988 length -= i;
989
990 if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0)
991 goto bind;
992
993 buf += i;
994 length -= i;
995
996 snprintf(buf, length, ")");
997
998 bind:
999 need_heavy = 1;
1000 if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) {
1001 dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error);
1002 goto fail_free;
1003 }
1004
1005 /* private fields */
1006
1007 kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
1008 init_MUTEX(&instance->serialize);
1009
1010 instance->thread_pid = -1;
1011 init_completion(&instance->thread_started);
1012 init_completion(&instance->thread_exited);
1013
1014 INIT_LIST_HEAD(&instance->vcc_list);
1015
1016 usbatm_init_channel(&instance->rx_channel);
1017 usbatm_init_channel(&instance->tx_channel);
1018 tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance);
1019 tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance);
1020 instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in);
1021 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out);
1022 instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding;
1023 instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding;
1024 instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride;
1025 instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride;
1026 instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance;
1027
1028 skb_queue_head_init(&instance->sndqueue);
1029
1030 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1031 struct urb *urb;
1032 u8 *buffer;
1033 unsigned int iso_packets = 0, iso_size = 0;
1034 struct usbatm_channel *channel = i < num_rcv_urbs ?
1035 &instance->rx_channel : &instance->tx_channel;
1036
1037 if (usb_pipeisoc(channel->endpoint)) {
1038 /* don't expect iso out endpoints */
1039 iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0);
1040 iso_size -= iso_size % channel->stride; /* alignment */
1041 BUG_ON(!iso_size);
1042 iso_packets = (channel->buf_size - 1) / iso_size + 1;
1043 }
1044
1045 urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
1046 if (!urb) {
1047 dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i);
1048 goto fail_unbind;
1049 }
1050
1051 instance->urbs[i] = urb;
1052
1053 buffer = kmalloc(channel->buf_size, GFP_KERNEL);
1054 if (!buffer) {
1055 dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i);
1056 goto fail_unbind;
1057 }
1058 memset(buffer, 0, channel->buf_size);
1059
1060 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,
1061 buffer, channel->buf_size, usbatm_complete, channel);
1062 if (iso_packets) {
1063 int j;
1064 urb->interval = 1;
1065 urb->transfer_flags = URB_ISO_ASAP;
1066 urb->number_of_packets = iso_packets;
1067 for (j = 0; j < iso_packets; j++) {
1068 urb->iso_frame_desc[j].offset = iso_size * j;
1069 urb->iso_frame_desc[j].length = min_t(int, iso_size,
1070 channel->buf_size - urb->iso_frame_desc[j].offset);
1071 }
1072 }
1073
1074 /* put all tx URBs on the list of spares */
1075 if (i >= num_rcv_urbs)
1076 list_add_tail(&urb->urb_list, &channel->list);
1077
1078 vdbg("%s: alloced buffer 0x%p buf size %u urb 0x%p",
1079 __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb);
1080 }
1081
1082 if (need_heavy && driver->heavy_init) {
1083 error = usbatm_heavy_init(instance);
1084 } else {
1085 complete(&instance->thread_exited); /* pretend that heavy_init was run */
1086 error = usbatm_atm_init(instance);
1087 }
1088
1089 if (error < 0)
1090 goto fail_unbind;
1091
1092 usb_get_dev(usb_dev);
1093 usb_set_intfdata(intf, instance);
1094
1095 return 0;
1096
1097 fail_unbind:
1098 if (instance->driver->unbind)
1099 instance->driver->unbind(instance, intf);
1100 fail_free:
1101 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1102 if (instance->urbs[i])
1103 kfree(instance->urbs[i]->transfer_buffer);
1104 usb_free_urb(instance->urbs[i]);
1105 }
1106
1107 kfree (instance);
1108
1109 return error;
1110}
1111EXPORT_SYMBOL_GPL(usbatm_usb_probe);
1112
1113void usbatm_usb_disconnect(struct usb_interface *intf)
1114{
1115 struct device *dev = &intf->dev;
1116 struct usbatm_data *instance = usb_get_intfdata(intf);
1117 int i;
1118
1119 dev_dbg(dev, "%s entered\n", __func__);
1120
1121 if (!instance) {
1122 dev_dbg(dev, "%s: NULL instance!\n", __func__);
1123 return;
1124 }
1125
1126 usb_set_intfdata(intf, NULL);
1127
1128 down(&instance->serialize);
1129 if (instance->thread_pid >= 0)
1130 kill_proc(instance->thread_pid, SIGTERM, 1);
1131 up(&instance->serialize);
1132
1133 wait_for_completion(&instance->thread_exited);
1134
1135 tasklet_disable(&instance->rx_channel.tasklet);
1136 tasklet_disable(&instance->tx_channel.tasklet);
1137
1138 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++)
1139 usb_kill_urb(instance->urbs[i]);
1140
1141 del_timer_sync(&instance->rx_channel.delay);
1142 del_timer_sync(&instance->tx_channel.delay);
1143
1144 if (instance->atm_dev && instance->driver->atm_stop)
1145 instance->driver->atm_stop(instance, instance->atm_dev);
1146
1147 if (instance->driver->unbind)
1148 instance->driver->unbind(instance, intf);
1149
1150 instance->driver_data = NULL;
1151
1152 /* turn usbatm_[rt]x_process into noop */
1153 /* no need to take the spinlock */
1154 INIT_LIST_HEAD(&instance->rx_channel.list);
1155 INIT_LIST_HEAD(&instance->tx_channel.list);
1156
1157 tasklet_enable(&instance->rx_channel.tasklet);
1158 tasklet_enable(&instance->tx_channel.tasklet);
1159
1160 for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
1161 kfree(instance->urbs[i]->transfer_buffer);
1162 usb_free_urb(instance->urbs[i]);
1163 }
1164
1165 /* ATM finalize */
1166 if (instance->atm_dev)
1167 shutdown_atm_dev(instance->atm_dev);
1168
1169 usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
1170}
1171EXPORT_SYMBOL_GPL(usbatm_usb_disconnect);
1172
1173
1174/***********
1175** init **
1176***********/
1177
1178static int __init usbatm_usb_init(void)
1179{
1180 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
1181
1182 if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) {
1183 printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name);
1184 return -EIO;
1185 }
1186
1187 if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
1188 || (num_snd_urbs > UDSL_MAX_SND_URBS)
1189 || (rcv_buf_size < 1)
1190 || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
1191 || (snd_buf_size < 1)
1192 || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
1193 return -EINVAL;
1194
1195 return 0;
1196}
1197module_init(usbatm_usb_init);
1198
1199static void __exit usbatm_usb_exit(void)
1200{
1201 dbg("%s", __func__);
1202}
1203module_exit(usbatm_usb_exit);
1204
1205MODULE_AUTHOR(DRIVER_AUTHOR);
1206MODULE_DESCRIPTION(DRIVER_DESC);
1207MODULE_LICENSE("GPL");
1208MODULE_VERSION(DRIVER_VERSION);
1209
1210/************
1211** debug **
1212************/
1213
1214#ifdef VERBOSE_DEBUG
1215static int usbatm_print_packet(const unsigned char *data, int len)
1216{
1217 unsigned char buffer[256];
1218 int i = 0, j = 0;
1219
1220 for (i = 0; i < len;) {
1221 buffer[0] = '\0';
1222 sprintf(buffer, "%.3d :", i);
1223 for (j = 0; (j < 16) && (i < len); j++, i++) {
1224 sprintf(buffer, "%s %2.2x", buffer, data[i]);
1225 }
1226 dbg("%s", buffer);
1227 }
1228 return i;
1229}
1230#endif
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
new file mode 100644
index 000000000000..936646457935
--- /dev/null
+++ b/drivers/usb/atm/usbatm.h
@@ -0,0 +1,184 @@
1/******************************************************************************
2 * usbatm.h - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24#ifndef _USBATM_H_
25#define _USBATM_H_
26
27#include <linux/config.h>
28
29/*
30#define DEBUG
31#define VERBOSE_DEBUG
32*/
33
34#if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
35# define DEBUG
36#endif
37
38#include <asm/semaphore.h>
39#include <linux/atm.h>
40#include <linux/atmdev.h>
41#include <linux/completion.h>
42#include <linux/device.h>
43#include <linux/kref.h>
44#include <linux/list.h>
45#include <linux/stringify.h>
46#include <linux/usb.h>
47
48#ifdef DEBUG
49#define UDSL_ASSERT(x) BUG_ON(!(x))
50#else
51#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
52#endif
53
54#define usb_err(instance, format, arg...) \
55 dev_err(&(instance)->usb_intf->dev , format , ## arg)
56#define usb_info(instance, format, arg...) \
57 dev_info(&(instance)->usb_intf->dev , format , ## arg)
58#define usb_warn(instance, format, arg...) \
59 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
60#define usb_dbg(instance, format, arg...) \
61 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
62
63/* FIXME: move to dev_* once ATM is driver model aware */
64#define atm_printk(level, instance, format, arg...) \
65 printk(level "ATM dev %d: " format , \
66 (instance)->atm_dev->number , ## arg)
67
68#define atm_err(instance, format, arg...) \
69 atm_printk(KERN_ERR, instance , format , ## arg)
70#define atm_info(instance, format, arg...) \
71 atm_printk(KERN_INFO, instance , format , ## arg)
72#define atm_warn(instance, format, arg...) \
73 atm_printk(KERN_WARNING, instance , format , ## arg)
74#ifdef DEBUG
75#define atm_dbg(instance, format, arg...) \
76 atm_printk(KERN_DEBUG, instance , format , ## arg)
77#else
78#define atm_dbg(instance, format, arg...) \
79 do {} while (0)
80#endif
81
82
83/* mini driver */
84
85struct usbatm_data;
86
87/*
88* Assuming all methods exist and succeed, they are called in this order:
89*
90* bind, heavy_init, atm_start, ..., atm_stop, unbind
91*/
92
93struct usbatm_driver {
94 struct module *owner;
95
96 const char *driver_name;
97
98 /*
99 * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init
100 * method can avoid having it called by setting need_heavy_init to zero.
101 */
102 int (*bind) (struct usbatm_data *, struct usb_interface *,
103 const struct usb_device_id *id, int *need_heavy_init);
104
105 /* additional device initialization that is too slow to be done in probe() */
106 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
107
108 /* cleanup device ... can sleep, but can't fail */
109 void (*unbind) (struct usbatm_data *, struct usb_interface *);
110
111 /* init ATM device ... can sleep, or cause ATM initialization failure */
112 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
113
114 /* cleanup ATM device ... can sleep, but can't fail */
115 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
116
117 int in; /* rx endpoint */
118 int out; /* tx endpoint */
119
120 unsigned rx_padding;
121 unsigned tx_padding;
122};
123
124extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
125 struct usbatm_driver *driver);
126extern void usbatm_usb_disconnect(struct usb_interface *intf);
127
128
129struct usbatm_channel {
130 int endpoint; /* usb pipe */
131 unsigned int stride; /* ATM cell size + padding */
132 unsigned int buf_size; /* urb buffer size */
133 spinlock_t lock;
134 struct list_head list;
135 struct tasklet_struct tasklet;
136 struct timer_list delay;
137 struct usbatm_data *usbatm;
138};
139
140/* main driver data */
141
142struct usbatm_data {
143 /******************
144 * public fields *
145 ******************/
146
147 /* mini driver */
148 struct usbatm_driver *driver;
149 void *driver_data;
150 char driver_name[16];
151
152 /* USB device */
153 struct usb_device *usb_dev;
154 struct usb_interface *usb_intf;
155 char description[64];
156
157 /* ATM device */
158 struct atm_dev *atm_dev;
159
160 /********************************
161 * private fields - do not use *
162 ********************************/
163
164 struct kref refcount;
165 struct semaphore serialize;
166
167 /* heavy init */
168 int thread_pid;
169 struct completion thread_started;
170 struct completion thread_exited;
171
172 /* ATM device */
173 struct list_head vcc_list;
174
175 struct usbatm_channel rx_channel;
176 struct usbatm_channel tx_channel;
177
178 struct sk_buff_head sndqueue;
179 struct sk_buff *current_skb; /* being emptied */
180
181 struct urb *urbs[0];
182};
183
184#endif /* _USBATM_H_ */
diff --git a/drivers/usb/atm/xusbatm.c b/drivers/usb/atm/xusbatm.c
new file mode 100644
index 000000000000..7fe7fb484d10
--- /dev/null
+++ b/drivers/usb/atm/xusbatm.c
@@ -0,0 +1,196 @@
1/******************************************************************************
2 * xusbatm.c - dumb usbatm-based driver for modems initialized in userspace
3 *
4 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
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 as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ******************************************************************************/
21
22#include <linux/module.h>
23#include <linux/netdevice.h> /* FIXME: required by linux/etherdevice.h */
24#include <linux/etherdevice.h> /* for random_ether_addr() */
25
26#include "usbatm.h"
27
28
29#define XUSBATM_DRIVERS_MAX 8
30
31#define XUSBATM_PARM(name, type, parmtype, desc) \
32 static type name[XUSBATM_DRIVERS_MAX]; \
33 static int num_##name; \
34 module_param_array(name, parmtype, &num_##name, 0444); \
35 MODULE_PARM_DESC(name, desc)
36
37XUSBATM_PARM(vendor, unsigned short, ushort, "USB device vendor");
38XUSBATM_PARM(product, unsigned short, ushort, "USB device product");
39
40XUSBATM_PARM(rx_endpoint, unsigned char, byte, "rx endpoint number");
41XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number");
42XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)");
43XUSBATM_PARM(tx_padding, unsigned char, byte, "tx padding (default 0)");
44
45static const char xusbatm_driver_name[] = "xusbatm";
46
47static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX];
48static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1];
49static struct usb_driver xusbatm_usb_driver;
50
51static int usb_intf_has_ep(const struct usb_interface *intf, u8 ep)
52{
53 int i, j;
54
55 for (i = 0; i < intf->num_altsetting; i++) {
56 struct usb_host_interface *alt = intf->altsetting;
57 for (j = 0; j < alt->desc.bNumEndpoints; j++)
58 if ((alt->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) == ep)
59 return 1;
60 }
61 return 0;
62}
63
64static int xusbatm_bind(struct usbatm_data *usbatm_instance,
65 struct usb_interface *intf, const struct usb_device_id *id,
66 int *need_heavy_init)
67{
68 struct usb_device *usb_dev = interface_to_usbdev(intf);
69 int drv_ix = id - xusbatm_usb_ids;
70 int rx_ep_present = usb_intf_has_ep(intf, rx_endpoint[drv_ix]);
71 int tx_ep_present = usb_intf_has_ep(intf, tx_endpoint[drv_ix]);
72 u8 searched_ep = rx_ep_present ? tx_endpoint[drv_ix] : rx_endpoint[drv_ix];
73 int i, ret;
74
75 usb_dbg(usbatm_instance, "%s: binding driver %d: vendor %#x product %#x"
76 " rx: ep %#x padd %d tx: ep %#x padd %d\n",
77 __func__, drv_ix, vendor[drv_ix], product[drv_ix],
78 rx_endpoint[drv_ix], rx_padding[drv_ix],
79 tx_endpoint[drv_ix], tx_padding[drv_ix]);
80
81 if (!rx_ep_present && !tx_ep_present) {
82 usb_dbg(usbatm_instance, "%s: intf #%d has neither rx (%#x) nor tx (%#x) endpoint\n",
83 __func__, intf->altsetting->desc.bInterfaceNumber,
84 rx_endpoint[drv_ix], tx_endpoint[drv_ix]);
85 return -ENODEV;
86 }
87
88 if (rx_ep_present && tx_ep_present)
89 return 0;
90
91 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
92 struct usb_interface *cur_if = usb_dev->actconfig->interface[i];
93
94 if (cur_if != intf && usb_intf_has_ep(cur_if, searched_ep)) {
95 ret = usb_driver_claim_interface(&xusbatm_usb_driver,
96 cur_if, usbatm_instance);
97 if (!ret)
98 usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n",
99 __func__, cur_if->altsetting->desc.bInterfaceNumber, ret);
100 return ret;
101 }
102 }
103
104 usb_err(usbatm_instance, "%s: no interface has endpoint %#x\n",
105 __func__, searched_ep);
106 return -ENODEV;
107}
108
109static void xusbatm_unbind(struct usbatm_data *usbatm_instance,
110 struct usb_interface *intf)
111{
112 struct usb_device *usb_dev = interface_to_usbdev(intf);
113 int i;
114 usb_dbg(usbatm_instance, "%s entered\n", __func__);
115
116 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
117 struct usb_interface *cur_if = usb_dev->actconfig->interface[i];
118 usb_set_intfdata(cur_if, NULL);
119 usb_driver_release_interface(&xusbatm_usb_driver, cur_if);
120 }
121}
122
123static int xusbatm_atm_start(struct usbatm_data *usbatm_instance,
124 struct atm_dev *atm_dev)
125{
126 atm_dbg(usbatm_instance, "%s entered\n", __func__);
127
128 /* use random MAC as we've no way to get it from the device */
129 random_ether_addr(atm_dev->esi);
130
131 return 0;
132}
133
134
135static int xusbatm_usb_probe(struct usb_interface *intf,
136 const struct usb_device_id *id)
137{
138 return usbatm_usb_probe(intf, id,
139 xusbatm_drivers + (id - xusbatm_usb_ids));
140}
141
142static struct usb_driver xusbatm_usb_driver = {
143 .owner = THIS_MODULE,
144 .name = xusbatm_driver_name,
145 .probe = xusbatm_usb_probe,
146 .disconnect = usbatm_usb_disconnect,
147 .id_table = xusbatm_usb_ids
148};
149
150static int __init xusbatm_init(void)
151{
152 int i;
153
154 dbg("xusbatm_init");
155
156 if (!num_vendor ||
157 num_vendor != num_product ||
158 num_vendor != num_rx_endpoint ||
159 num_vendor != num_tx_endpoint) {
160 warn("malformed module parameters");
161 return -EINVAL;
162 }
163
164 for (i = 0; i < num_vendor; i++) {
165 xusbatm_usb_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
166 xusbatm_usb_ids[i].idVendor = vendor[i];
167 xusbatm_usb_ids[i].idProduct = product[i];
168
169
170 xusbatm_drivers[i].owner = THIS_MODULE;
171 xusbatm_drivers[i].driver_name = xusbatm_driver_name;
172 xusbatm_drivers[i].bind = xusbatm_bind;
173 xusbatm_drivers[i].unbind = xusbatm_unbind;
174 xusbatm_drivers[i].atm_start = xusbatm_atm_start;
175 xusbatm_drivers[i].in = rx_endpoint[i];
176 xusbatm_drivers[i].out = tx_endpoint[i];
177 xusbatm_drivers[i].rx_padding = rx_padding[i];
178 xusbatm_drivers[i].tx_padding = tx_padding[i];
179 }
180
181 return usb_register(&xusbatm_usb_driver);
182}
183module_init(xusbatm_init);
184
185static void __exit xusbatm_exit(void)
186{
187 dbg("xusbatm_exit entered");
188
189 usb_deregister(&xusbatm_usb_driver);
190}
191module_exit(xusbatm_exit);
192
193MODULE_AUTHOR("Roman Kagan, Duncan Sands");
194MODULE_DESCRIPTION("Driver for USB ADSL modems initialized in userspace");
195MODULE_LICENSE("GPL");
196MODULE_VERSION("0.1");
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6d1f9b6aecff..adff5a77e31f 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -106,6 +106,111 @@ static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int
106 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) 106 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
107 107
108/* 108/*
109 * Write buffer management.
110 * All of these assume proper locks taken by the caller.
111 */
112
113static int acm_wb_alloc(struct acm *acm)
114{
115 int i, wbn;
116 struct acm_wb *wb;
117
118 wbn = acm->write_current;
119 i = 0;
120 for (;;) {
121 wb = &acm->wb[wbn];
122 if (!wb->use) {
123 wb->use = 1;
124 return wbn;
125 }
126 wbn = (wbn + 1) % ACM_NWB;
127 if (++i >= ACM_NWB)
128 return -1;
129 }
130}
131
132static void acm_wb_free(struct acm *acm, int wbn)
133{
134 acm->wb[wbn].use = 0;
135}
136
137static int acm_wb_is_avail(struct acm *acm)
138{
139 int i, n;
140
141 n = 0;
142 for (i = 0; i < ACM_NWB; i++) {
143 if (!acm->wb[i].use)
144 n++;
145 }
146 return n;
147}
148
149static inline int acm_wb_is_used(struct acm *acm, int wbn)
150{
151 return acm->wb[wbn].use;
152}
153
154/*
155 * Finish write.
156 */
157static void acm_write_done(struct acm *acm)
158{
159 unsigned long flags;
160 int wbn;
161
162 spin_lock_irqsave(&acm->write_lock, flags);
163 acm->write_ready = 1;
164 wbn = acm->write_current;
165 acm_wb_free(acm, wbn);
166 acm->write_current = (wbn + 1) % ACM_NWB;
167 spin_unlock_irqrestore(&acm->write_lock, flags);
168}
169
170/*
171 * Poke write.
172 */
173static int acm_write_start(struct acm *acm)
174{
175 unsigned long flags;
176 int wbn;
177 struct acm_wb *wb;
178 int rc;
179
180 spin_lock_irqsave(&acm->write_lock, flags);
181 if (!acm->dev) {
182 spin_unlock_irqrestore(&acm->write_lock, flags);
183 return -ENODEV;
184 }
185
186 if (!acm->write_ready) {
187 spin_unlock_irqrestore(&acm->write_lock, flags);
188 return 0; /* A white lie */
189 }
190
191 wbn = acm->write_current;
192 if (!acm_wb_is_used(acm, wbn)) {
193 spin_unlock_irqrestore(&acm->write_lock, flags);
194 return 0;
195 }
196 wb = &acm->wb[wbn];
197
198 acm->write_ready = 0;
199 spin_unlock_irqrestore(&acm->write_lock, flags);
200
201 acm->writeurb->transfer_buffer = wb->buf;
202 acm->writeurb->transfer_dma = wb->dmah;
203 acm->writeurb->transfer_buffer_length = wb->len;
204 acm->writeurb->dev = acm->dev;
205
206 if ((rc = usb_submit_urb(acm->writeurb, GFP_ATOMIC)) < 0) {
207 dbg("usb_submit_urb(write bulk) failed: %d", rc);
208 acm_write_done(acm);
209 }
210 return rc;
211}
212
213/*
109 * Interrupt handlers for various ACM device responses 214 * Interrupt handlers for various ACM device responses
110 */ 215 */
111 216
@@ -237,17 +342,13 @@ static void acm_rx_tasklet(unsigned long _acm)
237static void acm_write_bulk(struct urb *urb, struct pt_regs *regs) 342static void acm_write_bulk(struct urb *urb, struct pt_regs *regs)
238{ 343{
239 struct acm *acm = (struct acm *)urb->context; 344 struct acm *acm = (struct acm *)urb->context;
240 dbg("Entering acm_write_bulk with status %d\n", urb->status);
241
242 if (!ACM_READY(acm))
243 goto out;
244 345
245 if (urb->status) 346 dbg("Entering acm_write_bulk with status %d\n", urb->status);
246 dbg("nonzero write bulk status received: %d", urb->status);
247 347
248 schedule_work(&acm->work); 348 acm_write_done(acm);
249out: 349 acm_write_start(acm);
250 acm->ready_for_write = 1; 350 if (ACM_READY(acm))
351 schedule_work(&acm->work);
251} 352}
252 353
253static void acm_softint(void *private) 354static void acm_softint(void *private)
@@ -321,6 +422,17 @@ bail_out:
321 return -EIO; 422 return -EIO;
322} 423}
323 424
425static void acm_tty_unregister(struct acm *acm)
426{
427 tty_unregister_device(acm_tty_driver, acm->minor);
428 usb_put_intf(acm->control);
429 acm_table[acm->minor] = NULL;
430 usb_free_urb(acm->ctrlurb);
431 usb_free_urb(acm->readurb);
432 usb_free_urb(acm->writeurb);
433 kfree(acm);
434}
435
324static void acm_tty_close(struct tty_struct *tty, struct file *filp) 436static void acm_tty_close(struct tty_struct *tty, struct file *filp)
325{ 437{
326 struct acm *acm = tty->driver_data; 438 struct acm *acm = tty->driver_data;
@@ -335,14 +447,8 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
335 usb_kill_urb(acm->ctrlurb); 447 usb_kill_urb(acm->ctrlurb);
336 usb_kill_urb(acm->writeurb); 448 usb_kill_urb(acm->writeurb);
337 usb_kill_urb(acm->readurb); 449 usb_kill_urb(acm->readurb);
338 } else { 450 } else
339 tty_unregister_device(acm_tty_driver, acm->minor); 451 acm_tty_unregister(acm);
340 acm_table[acm->minor] = NULL;
341 usb_free_urb(acm->ctrlurb);
342 usb_free_urb(acm->readurb);
343 usb_free_urb(acm->writeurb);
344 kfree(acm);
345 }
346 } 452 }
347 up(&open_sem); 453 up(&open_sem);
348} 454}
@@ -351,32 +457,33 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
351{ 457{
352 struct acm *acm = tty->driver_data; 458 struct acm *acm = tty->driver_data;
353 int stat; 459 int stat;
460 unsigned long flags;
461 int wbn;
462 struct acm_wb *wb;
463
354 dbg("Entering acm_tty_write to write %d bytes,\n", count); 464 dbg("Entering acm_tty_write to write %d bytes,\n", count);
355 465
356 if (!ACM_READY(acm)) 466 if (!ACM_READY(acm))
357 return -EINVAL; 467 return -EINVAL;
358 if (!acm->ready_for_write)
359 return 0;
360 if (!count) 468 if (!count)
361 return 0; 469 return 0;
362 470
363 count = (count > acm->writesize) ? acm->writesize : count; 471 spin_lock_irqsave(&acm->write_lock, flags);
472 if ((wbn = acm_wb_alloc(acm)) < 0) {
473 spin_unlock_irqrestore(&acm->write_lock, flags);
474 acm_write_start(acm);
475 return 0;
476 }
477 wb = &acm->wb[wbn];
364 478
479 count = (count > acm->writesize) ? acm->writesize : count;
365 dbg("Get %d bytes...", count); 480 dbg("Get %d bytes...", count);
366 memcpy(acm->write_buffer, buf, count); 481 memcpy(wb->buf, buf, count);
367 dbg(" Successfully copied.\n"); 482 wb->len = count;
483 spin_unlock_irqrestore(&acm->write_lock, flags);
368 484
369 acm->writeurb->transfer_buffer_length = count; 485 if ((stat = acm_write_start(acm)) < 0)
370 acm->writeurb->dev = acm->dev;
371
372 acm->ready_for_write = 0;
373 stat = usb_submit_urb(acm->writeurb, GFP_ATOMIC);
374 if (stat < 0) {
375 dbg("usb_submit_urb(write bulk) failed");
376 acm->ready_for_write = 1;
377 return stat; 486 return stat;
378 }
379
380 return count; 487 return count;
381} 488}
382 489
@@ -385,7 +492,11 @@ static int acm_tty_write_room(struct tty_struct *tty)
385 struct acm *acm = tty->driver_data; 492 struct acm *acm = tty->driver_data;
386 if (!ACM_READY(acm)) 493 if (!ACM_READY(acm))
387 return -EINVAL; 494 return -EINVAL;
388 return !acm->ready_for_write ? 0 : acm->writesize; 495 /*
496 * Do not let the line discipline to know that we have a reserve,
497 * or it might get too enthusiastic.
498 */
499 return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0;
389} 500}
390 501
391static int acm_tty_chars_in_buffer(struct tty_struct *tty) 502static int acm_tty_chars_in_buffer(struct tty_struct *tty)
@@ -393,7 +504,10 @@ static int acm_tty_chars_in_buffer(struct tty_struct *tty)
393 struct acm *acm = tty->driver_data; 504 struct acm *acm = tty->driver_data;
394 if (!ACM_READY(acm)) 505 if (!ACM_READY(acm))
395 return -EINVAL; 506 return -EINVAL;
396 return !acm->ready_for_write ? acm->writeurb->transfer_buffer_length : 0; 507 /*
508 * This is inaccurate (overcounts), but it works.
509 */
510 return (ACM_NWB - acm_wb_is_avail(acm)) * acm->writesize;
397} 511}
398 512
399static void acm_tty_throttle(struct tty_struct *tty) 513static void acm_tty_throttle(struct tty_struct *tty)
@@ -526,6 +640,39 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct termios *termios_
526 * USB probe and disconnect routines. 640 * USB probe and disconnect routines.
527 */ 641 */
528 642
643/* Little helper: write buffers free */
644static void acm_write_buffers_free(struct acm *acm)
645{
646 int i;
647 struct acm_wb *wb;
648
649 for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) {
650 usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah);
651 }
652}
653
654/* Little helper: write buffers allocate */
655static int acm_write_buffers_alloc(struct acm *acm)
656{
657 int i;
658 struct acm_wb *wb;
659
660 for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) {
661 wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL,
662 &wb->dmah);
663 if (!wb->buf) {
664 while (i != 0) {
665 --i;
666 --wb;
667 usb_buffer_free(acm->dev, acm->writesize,
668 wb->buf, wb->dmah);
669 }
670 return -ENOMEM;
671 }
672 }
673 return 0;
674}
675
529static int acm_probe (struct usb_interface *intf, 676static int acm_probe (struct usb_interface *intf,
530 const struct usb_device_id *id) 677 const struct usb_device_id *id)
531{ 678{
@@ -700,7 +847,8 @@ skip_normal_probe:
700 acm->bh.data = (unsigned long) acm; 847 acm->bh.data = (unsigned long) acm;
701 INIT_WORK(&acm->work, acm_softint, acm); 848 INIT_WORK(&acm->work, acm_softint, acm);
702 spin_lock_init(&acm->throttle_lock); 849 spin_lock_init(&acm->throttle_lock);
703 acm->ready_for_write = 1; 850 spin_lock_init(&acm->write_lock);
851 acm->write_ready = 1;
704 852
705 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 853 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
706 if (!buf) { 854 if (!buf) {
@@ -716,12 +864,10 @@ skip_normal_probe:
716 } 864 }
717 acm->read_buffer = buf; 865 acm->read_buffer = buf;
718 866
719 buf = usb_buffer_alloc(usb_dev, acm->writesize, GFP_KERNEL, &acm->write_dma); 867 if (acm_write_buffers_alloc(acm) < 0) {
720 if (!buf) {
721 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); 868 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n");
722 goto alloc_fail4; 869 goto alloc_fail4;
723 } 870 }
724 acm->write_buffer = buf;
725 871
726 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 872 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
727 if (!acm->ctrlurb) { 873 if (!acm->ctrlurb) {
@@ -750,9 +896,9 @@ skip_normal_probe:
750 acm->readurb->transfer_dma = acm->read_dma; 896 acm->readurb->transfer_dma = acm->read_dma;
751 897
752 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 898 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
753 acm->write_buffer, acm->writesize, acm_write_bulk, acm); 899 NULL, acm->writesize, acm_write_bulk, acm);
754 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP; 900 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;
755 acm->writeurb->transfer_dma = acm->write_dma; 901 /* acm->writeurb->transfer_dma = 0; */
756 902
757 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); 903 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
758 904
@@ -764,7 +910,8 @@ skip_normal_probe:
764 910
765 usb_driver_claim_interface(&acm_driver, data_interface, acm); 911 usb_driver_claim_interface(&acm_driver, data_interface, acm);
766 912
767 tty_register_device(acm_tty_driver, minor, &intf->dev); 913 usb_get_intf(control_interface);
914 tty_register_device(acm_tty_driver, minor, &control_interface->dev);
768 915
769 acm_table[minor] = acm; 916 acm_table[minor] = acm;
770 usb_set_intfdata (intf, acm); 917 usb_set_intfdata (intf, acm);
@@ -775,7 +922,7 @@ alloc_fail7:
775alloc_fail6: 922alloc_fail6:
776 usb_free_urb(acm->ctrlurb); 923 usb_free_urb(acm->ctrlurb);
777alloc_fail5: 924alloc_fail5:
778 usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 925 acm_write_buffers_free(acm);
779alloc_fail4: 926alloc_fail4:
780 usb_buffer_free(usb_dev, readsize, acm->read_buffer, acm->read_dma); 927 usb_buffer_free(usb_dev, readsize, acm->read_buffer, acm->read_dma);
781alloc_fail3: 928alloc_fail3:
@@ -806,19 +953,14 @@ static void acm_disconnect(struct usb_interface *intf)
806 953
807 flush_scheduled_work(); /* wait for acm_softint */ 954 flush_scheduled_work(); /* wait for acm_softint */
808 955
809 usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 956 acm_write_buffers_free(acm);
810 usb_buffer_free(usb_dev, acm->readsize, acm->read_buffer, acm->read_dma); 957 usb_buffer_free(usb_dev, acm->readsize, acm->read_buffer, acm->read_dma);
811 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 958 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
812 959
813 usb_driver_release_interface(&acm_driver, acm->data); 960 usb_driver_release_interface(&acm_driver, acm->data);
814 961
815 if (!acm->used) { 962 if (!acm->used) {
816 tty_unregister_device(acm_tty_driver, acm->minor); 963 acm_tty_unregister(acm);
817 acm_table[acm->minor] = NULL;
818 usb_free_urb(acm->ctrlurb);
819 usb_free_urb(acm->readurb);
820 usb_free_urb(acm->writeurb);
821 kfree(acm);
822 up(&open_sem); 964 up(&open_sem);
823 return; 965 return;
824 } 966 }
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 9009114e311b..963a5dfd2096 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -51,14 +51,34 @@
51 * Internal driver structures. 51 * Internal driver structures.
52 */ 52 */
53 53
54/*
55 * The only reason to have several buffers is to accomodate assumptions
56 * in line disciplines. They ask for empty space amount, receive our URB size,
57 * and proceed to issue several 1-character writes, assuming they will fit.
58 * The very first write takes a complete URB. Fortunately, this only happens
59 * when processing onlcr, so we only need 2 buffers.
60 */
61#define ACM_NWB 2
62struct acm_wb {
63 unsigned char *buf;
64 dma_addr_t dmah;
65 int len;
66 int use;
67};
68
54struct acm { 69struct acm {
55 struct usb_device *dev; /* the corresponding usb device */ 70 struct usb_device *dev; /* the corresponding usb device */
56 struct usb_interface *control; /* control interface */ 71 struct usb_interface *control; /* control interface */
57 struct usb_interface *data; /* data interface */ 72 struct usb_interface *data; /* data interface */
58 struct tty_struct *tty; /* the corresponding tty */ 73 struct tty_struct *tty; /* the corresponding tty */
59 struct urb *ctrlurb, *readurb, *writeurb; /* urbs */ 74 struct urb *ctrlurb, *readurb, *writeurb; /* urbs */
60 u8 *ctrl_buffer, *read_buffer, *write_buffer; /* buffers of urbs */ 75 u8 *ctrl_buffer, *read_buffer; /* buffers of urbs */
61 dma_addr_t ctrl_dma, read_dma, write_dma; /* dma handles of buffers */ 76 dma_addr_t ctrl_dma, read_dma; /* dma handles of buffers */
77 struct acm_wb wb[ACM_NWB];
78 int write_current; /* current write buffer */
79 int write_used; /* number of non-empty write buffers */
80 int write_ready; /* write urb is not running */
81 spinlock_t write_lock;
62 struct usb_cdc_line_coding line; /* bits, stop, parity */ 82 struct usb_cdc_line_coding line; /* bits, stop, parity */
63 struct work_struct work; /* work queue entry for line discipline waking up */ 83 struct work_struct work; /* work queue entry for line discipline waking up */
64 struct tasklet_struct bh; /* rx processing */ 84 struct tasklet_struct bh; /* rx processing */
@@ -71,7 +91,6 @@ struct acm {
71 unsigned int minor; /* acm minor number */ 91 unsigned int minor; /* acm minor number */
72 unsigned char throttle; /* throttled by tty layer */ 92 unsigned char throttle; /* throttled by tty layer */
73 unsigned char clocal; /* termios CLOCAL */ 93 unsigned char clocal; /* termios CLOCAL */
74 unsigned char ready_for_write; /* write urb can be used */
75 unsigned char resubmit_to_unthrottle; /* throtteling has disabled the read urb */ 94 unsigned char resubmit_to_unthrottle; /* throtteling has disabled the read urb */
76 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 95 unsigned int ctrl_caps; /* control capabilities from the class specific header */
77}; 96};
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index bba22e97ea0f..7ce43fb8118a 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -379,6 +379,8 @@ static int usblp_open(struct inode *inode, struct file *file)
379 usblp->writeurb->transfer_buffer_length = 0; 379 usblp->writeurb->transfer_buffer_length = 0;
380 usblp->wcomplete = 1; /* we begin writeable */ 380 usblp->wcomplete = 1; /* we begin writeable */
381 usblp->rcomplete = 0; 381 usblp->rcomplete = 0;
382 usblp->writeurb->status = 0;
383 usblp->readurb->status = 0;
382 384
383 if (usblp->bidir) { 385 if (usblp->bidir) {
384 usblp->readcount = 0; 386 usblp->readcount = 0;
@@ -751,6 +753,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
751 schedule(); 753 schedule();
752 } else { 754 } else {
753 set_current_state(TASK_RUNNING); 755 set_current_state(TASK_RUNNING);
756 down(&usblp->sem);
754 break; 757 break;
755 } 758 }
756 down (&usblp->sem); 759 down (&usblp->sem);
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index b7827df21f48..fc15b4acc8af 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -106,7 +106,7 @@ void hcd_buffer_destroy (struct usb_hcd *hcd)
106void *hcd_buffer_alloc ( 106void *hcd_buffer_alloc (
107 struct usb_bus *bus, 107 struct usb_bus *bus,
108 size_t size, 108 size_t size,
109 int mem_flags, 109 unsigned mem_flags,
110 dma_addr_t *dma 110 dma_addr_t *dma
111) 111)
112{ 112{
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6bfab4bcaa9e..787c27a63c51 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -784,16 +784,16 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
784 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { 784 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) {
785 if (usb_interface_claimed(actconfig->interface[i])) { 785 if (usb_interface_claimed(actconfig->interface[i])) {
786 dev_warn (&ps->dev->dev, 786 dev_warn (&ps->dev->dev,
787 "usbfs: interface %d claimed " 787 "usbfs: interface %d claimed by %s "
788 "while '%s' sets config #%d\n", 788 "while '%s' sets config #%d\n",
789 actconfig->interface[i] 789 actconfig->interface[i]
790 ->cur_altsetting 790 ->cur_altsetting
791 ->desc.bInterfaceNumber, 791 ->desc.bInterfaceNumber,
792 actconfig->interface[i]
793 ->dev.driver->name,
792 current->comm, u); 794 current->comm, u);
793#if 0 /* FIXME: enable in 2.6.10 or so */
794 status = -EBUSY; 795 status = -EBUSY;
795 break; 796 break;
796#endif
797 } 797 }
798 } 798 }
799 } 799 }
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 71b4a8d66318..fc056062c960 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -380,6 +380,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
380 usb_hc_died (hcd); 380 usb_hc_died (hcd);
381 } 381 }
382 382
383 pci_enable_device(dev);
383 return retval; 384 return retval;
384} 385}
385EXPORT_SYMBOL (usb_hcd_pci_resume); 386EXPORT_SYMBOL (usb_hcd_pci_resume);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0da23732e807..8616356f55e8 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -519,119 +519,120 @@ error:
519/*-------------------------------------------------------------------------*/ 519/*-------------------------------------------------------------------------*/
520 520
521/* 521/*
522 * Root Hub interrupt transfers are synthesized with a timer. 522 * Root Hub interrupt transfers are polled using a timer if the
523 * Completions are called in_interrupt() but not in_irq(). 523 * driver requests it; otherwise the driver is responsible for
524 * calling usb_hcd_poll_rh_status() when an event occurs.
524 * 525 *
525 * Note: some root hubs (including common UHCI based designs) can't 526 * Completions are called in_interrupt(), but they may or may not
526 * correctly issue port change IRQs. They're the ones that _need_ a 527 * be in_irq().
527 * timer; most other root hubs don't. Some systems could save a
528 * lot of battery power by eliminating these root hub timer IRQs.
529 */ 528 */
529void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
530{
531 struct urb *urb;
532 int length;
533 unsigned long flags;
534 char buffer[4]; /* Any root hubs with > 31 ports? */
530 535
531static void rh_report_status (unsigned long ptr); 536 if (!hcd->uses_new_polling && !hcd->status_urb)
537 return;
532 538
533static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb) 539 length = hcd->driver->hub_status_data(hcd, buffer);
534{ 540 if (length > 0) {
535 int len = 1 + (urb->dev->maxchild / 8);
536 541
537 /* rh_timer protected by hcd_data_lock */ 542 /* try to complete the status urb */
538 if (hcd->rh_timer.data || urb->transfer_buffer_length < len) { 543 local_irq_save (flags);
539 dev_dbg (hcd->self.controller, 544 spin_lock(&hcd_root_hub_lock);
540 "not queuing rh status urb, stat %d\n", 545 urb = hcd->status_urb;
541 urb->status); 546 if (urb) {
542 return -EINVAL; 547 spin_lock(&urb->lock);
548 if (urb->status == -EINPROGRESS) {
549 hcd->poll_pending = 0;
550 hcd->status_urb = NULL;
551 urb->status = 0;
552 urb->hcpriv = NULL;
553 urb->actual_length = length;
554 memcpy(urb->transfer_buffer, buffer, length);
555 } else /* urb has been unlinked */
556 length = 0;
557 spin_unlock(&urb->lock);
558 } else
559 length = 0;
560 spin_unlock(&hcd_root_hub_lock);
561
562 /* local irqs are always blocked in completions */
563 if (length > 0)
564 usb_hcd_giveback_urb (hcd, urb, NULL);
565 else
566 hcd->poll_pending = 1;
567 local_irq_restore (flags);
543 } 568 }
544 569
545 init_timer (&hcd->rh_timer); 570 /* The USB 2.0 spec says 256 ms. This is close enough and won't
546 hcd->rh_timer.function = rh_report_status; 571 * exceed that limit if HZ is 100. */
547 hcd->rh_timer.data = (unsigned long) urb; 572 if (hcd->uses_new_polling ? hcd->poll_rh :
548 /* USB 2.0 spec says 256msec; this is close enough */ 573 (length == 0 && hcd->status_urb != NULL))
549 hcd->rh_timer.expires = jiffies + HZ/4; 574 mod_timer (&hcd->rh_timer, jiffies + msecs_to_jiffies(250));
550 add_timer (&hcd->rh_timer);
551 urb->hcpriv = hcd; /* nonzero to indicate it's queued */
552 return 0;
553} 575}
576EXPORT_SYMBOL_GPL(usb_hcd_poll_rh_status);
554 577
555/* timer callback */ 578/* timer callback */
579static void rh_timer_func (unsigned long _hcd)
580{
581 usb_hcd_poll_rh_status((struct usb_hcd *) _hcd);
582}
556 583
557static void rh_report_status (unsigned long ptr) 584/*-------------------------------------------------------------------------*/
585
586static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
558{ 587{
559 struct urb *urb; 588 int retval;
560 struct usb_hcd *hcd;
561 int length = 0;
562 unsigned long flags; 589 unsigned long flags;
590 int len = 1 + (urb->dev->maxchild / 8);
563 591
564 urb = (struct urb *) ptr; 592 spin_lock_irqsave (&hcd_root_hub_lock, flags);
565 local_irq_save (flags); 593 if (urb->status != -EINPROGRESS) /* already unlinked */
566 spin_lock (&urb->lock); 594 retval = urb->status;
595 else if (hcd->status_urb || urb->transfer_buffer_length < len) {
596 dev_dbg (hcd->self.controller, "not queuing rh status urb\n");
597 retval = -EINVAL;
598 } else {
599 hcd->status_urb = urb;
600 urb->hcpriv = hcd; /* indicate it's queued */
567 601
568 /* do nothing if the urb's been unlinked */ 602 if (!hcd->uses_new_polling)
569 if (!urb->dev 603 mod_timer (&hcd->rh_timer, jiffies +
570 || urb->status != -EINPROGRESS 604 msecs_to_jiffies(250));
571 || (hcd = urb->dev->bus->hcpriv) == NULL) {
572 spin_unlock (&urb->lock);
573 local_irq_restore (flags);
574 return;
575 }
576 605
577 /* complete the status urb, or retrigger the timer */ 606 /* If a status change has already occurred, report it ASAP */
578 spin_lock (&hcd_data_lock); 607 else if (hcd->poll_pending)
579 if (urb->dev->state == USB_STATE_CONFIGURED) { 608 mod_timer (&hcd->rh_timer, jiffies);
580 length = hcd->driver->hub_status_data ( 609 retval = 0;
581 hcd, urb->transfer_buffer);
582 if (length > 0) {
583 hcd->rh_timer.data = 0;
584 urb->actual_length = length;
585 urb->status = 0;
586 urb->hcpriv = NULL;
587 } else
588 mod_timer (&hcd->rh_timer, jiffies + HZ/4);
589 } 610 }
590 spin_unlock (&hcd_data_lock); 611 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
591 spin_unlock (&urb->lock); 612 return retval;
592
593 /* local irqs are always blocked in completions */
594 if (length > 0)
595 usb_hcd_giveback_urb (hcd, urb, NULL);
596 local_irq_restore (flags);
597} 613}
598 614
599/*-------------------------------------------------------------------------*/
600
601static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) 615static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
602{ 616{
603 if (usb_pipeint (urb->pipe)) { 617 if (usb_pipeint (urb->pipe))
604 int retval; 618 return rh_queue_status (hcd, urb);
605 unsigned long flags;
606
607 spin_lock_irqsave (&hcd_data_lock, flags);
608 retval = rh_status_urb (hcd, urb);
609 spin_unlock_irqrestore (&hcd_data_lock, flags);
610 return retval;
611 }
612 if (usb_pipecontrol (urb->pipe)) 619 if (usb_pipecontrol (urb->pipe))
613 return rh_call_control (hcd, urb); 620 return rh_call_control (hcd, urb);
614 else 621 return -EINVAL;
615 return -EINVAL;
616} 622}
617 623
618/*-------------------------------------------------------------------------*/ 624/*-------------------------------------------------------------------------*/
619 625
626/* Asynchronous unlinks of root-hub control URBs are legal, but they
627 * don't do anything. Status URB unlinks must be made in process context
628 * with interrupts enabled.
629 */
620static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 630static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
621{ 631{
622 unsigned long flags; 632 if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */
633 if (in_interrupt())
634 return 0; /* nothing to do */
623 635
624 /* note: always a synchronous unlink */
625 if ((unsigned long) urb == hcd->rh_timer.data) {
626 del_timer_sync (&hcd->rh_timer);
627 hcd->rh_timer.data = 0;
628
629 local_irq_save (flags);
630 urb->hcpriv = NULL;
631 usb_hcd_giveback_urb (hcd, urb, NULL);
632 local_irq_restore (flags);
633
634 } else if (usb_pipeendpoint(urb->pipe) == 0) {
635 spin_lock_irq(&urb->lock); /* from usb_kill_urb */ 636 spin_lock_irq(&urb->lock); /* from usb_kill_urb */
636 ++urb->reject; 637 ++urb->reject;
637 spin_unlock_irq(&urb->lock); 638 spin_unlock_irq(&urb->lock);
@@ -642,8 +643,22 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
642 spin_lock_irq(&urb->lock); 643 spin_lock_irq(&urb->lock);
643 --urb->reject; 644 --urb->reject;
644 spin_unlock_irq(&urb->lock); 645 spin_unlock_irq(&urb->lock);
645 } else 646
646 return -EINVAL; 647 } else { /* Status URB */
648 if (!hcd->uses_new_polling)
649 del_timer_sync (&hcd->rh_timer);
650 local_irq_disable ();
651 spin_lock (&hcd_root_hub_lock);
652 if (urb == hcd->status_urb) {
653 hcd->status_urb = NULL;
654 urb->hcpriv = NULL;
655 } else
656 urb = NULL; /* wasn't fully queued */
657 spin_unlock (&hcd_root_hub_lock);
658 if (urb)
659 usb_hcd_giveback_urb (hcd, urb, NULL);
660 local_irq_enable ();
661 }
647 662
648 return 0; 663 return 0;
649} 664}
@@ -817,30 +832,22 @@ static void usb_deregister_bus (struct usb_bus *bus)
817} 832}
818 833
819/** 834/**
820 * usb_hcd_register_root_hub - called by HCD to register its root hub 835 * register_root_hub - called by usb_add_hcd() to register a root hub
821 * @usb_dev: the usb root hub device to be registered. 836 * @usb_dev: the usb root hub device to be registered.
822 * @hcd: host controller for this root hub 837 * @hcd: host controller for this root hub
823 * 838 *
824 * The USB host controller calls this function to register the root hub 839 * This function registers the root hub with the USB subsystem. It sets up
825 * properly with the USB subsystem. It sets up the device properly in 840 * the device properly in the device tree and stores the root_hub pointer
826 * the device tree and stores the root_hub pointer in the bus structure, 841 * in the bus structure, then calls usb_new_device() to register the usb
827 * then calls usb_new_device() to register the usb device. It also 842 * device. It also assigns the root hub's USB address (always 1).
828 * assigns the root hub's USB address (always 1).
829 */ 843 */
830int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd) 844static int register_root_hub (struct usb_device *usb_dev,
845 struct usb_hcd *hcd)
831{ 846{
832 struct device *parent_dev = hcd->self.controller; 847 struct device *parent_dev = hcd->self.controller;
833 const int devnum = 1; 848 const int devnum = 1;
834 int retval; 849 int retval;
835 850
836 /* hcd->driver->start() reported can_wakeup, probably with
837 * assistance from board's boot firmware.
838 * NOTE: normal devices won't enable wakeup by default.
839 */
840 if (hcd->can_wakeup)
841 dev_dbg (parent_dev, "supports USB remote wakeup\n");
842 hcd->remote_wakeup = hcd->can_wakeup;
843
844 usb_dev->devnum = devnum; 851 usb_dev->devnum = devnum;
845 usb_dev->bus->devnum_next = devnum + 1; 852 usb_dev->bus->devnum_next = devnum + 1;
846 memset (&usb_dev->bus->devmap.devicemap, 0, 853 memset (&usb_dev->bus->devmap.devicemap, 0,
@@ -883,7 +890,16 @@ int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd)
883 890
884 return retval; 891 return retval;
885} 892}
886EXPORT_SYMBOL_GPL(usb_hcd_register_root_hub); 893
894void usb_enable_root_hub_irq (struct usb_bus *bus)
895{
896 struct usb_hcd *hcd;
897
898 hcd = container_of (bus, struct usb_hcd, self);
899 if (hcd->driver->hub_irq_enable && !hcd->poll_rh &&
900 hcd->state != HC_STATE_HALT)
901 hcd->driver->hub_irq_enable (hcd);
902}
887 903
888 904
889/*-------------------------------------------------------------------------*/ 905/*-------------------------------------------------------------------------*/
@@ -1096,7 +1112,7 @@ static void urb_unlink (struct urb *urb)
1096 * expects usb_submit_urb() to have sanity checked and conditioned all 1112 * expects usb_submit_urb() to have sanity checked and conditioned all
1097 * inputs in the urb 1113 * inputs in the urb
1098 */ 1114 */
1099static int hcd_submit_urb (struct urb *urb, int mem_flags) 1115static int hcd_submit_urb (struct urb *urb, unsigned mem_flags)
1100{ 1116{
1101 int status; 1117 int status;
1102 struct usb_hcd *hcd = urb->dev->bus->hcpriv; 1118 struct usb_hcd *hcd = urb->dev->bus->hcpriv;
@@ -1348,7 +1364,8 @@ hcd_endpoint_disable (struct usb_device *udev, struct usb_host_endpoint *ep)
1348 1364
1349 hcd = udev->bus->hcpriv; 1365 hcd = udev->bus->hcpriv;
1350 1366
1351 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT); 1367 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT &&
1368 udev->state != USB_STATE_NOTATTACHED);
1352 1369
1353 local_irq_disable (); 1370 local_irq_disable ();
1354 1371
@@ -1612,6 +1629,8 @@ void usb_hc_died (struct usb_hcd *hcd)
1612 1629
1613 spin_lock_irqsave (&hcd_root_hub_lock, flags); 1630 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1614 if (hcd->rh_registered) { 1631 if (hcd->rh_registered) {
1632 hcd->poll_rh = 0;
1633 del_timer(&hcd->rh_timer);
1615 1634
1616 /* make khubd clean up old urbs and devices */ 1635 /* make khubd clean up old urbs and devices */
1617 usb_set_device_state (hcd->self.root_hub, 1636 usb_set_device_state (hcd->self.root_hub,
@@ -1665,6 +1684,8 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1665 hcd->self.bus_name = bus_name; 1684 hcd->self.bus_name = bus_name;
1666 1685
1667 init_timer(&hcd->rh_timer); 1686 init_timer(&hcd->rh_timer);
1687 hcd->rh_timer.function = rh_timer_func;
1688 hcd->rh_timer.data = (unsigned long) hcd;
1668 1689
1669 hcd->driver = driver; 1690 hcd->driver = driver;
1670 hcd->product_desc = (driver->product_desc) ? driver->product_desc : 1691 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
@@ -1694,7 +1715,8 @@ EXPORT_SYMBOL (usb_put_hcd);
1694int usb_add_hcd(struct usb_hcd *hcd, 1715int usb_add_hcd(struct usb_hcd *hcd,
1695 unsigned int irqnum, unsigned long irqflags) 1716 unsigned int irqnum, unsigned long irqflags)
1696{ 1717{
1697 int retval; 1718 int retval;
1719 struct usb_device *rhdev;
1698 1720
1699 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); 1721 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
1700 1722
@@ -1710,7 +1732,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
1710 } 1732 }
1711 1733
1712 if ((retval = usb_register_bus(&hcd->self)) < 0) 1734 if ((retval = usb_register_bus(&hcd->self)) < 0)
1713 goto err1; 1735 goto err_register_bus;
1714 1736
1715 if (hcd->driver->irq) { 1737 if (hcd->driver->irq) {
1716 char buf[8], *bufp = buf; 1738 char buf[8], *bufp = buf;
@@ -1727,7 +1749,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
1727 hcd->irq_descr, hcd)) != 0) { 1749 hcd->irq_descr, hcd)) != 0) {
1728 dev_err(hcd->self.controller, 1750 dev_err(hcd->self.controller,
1729 "request interrupt %s failed\n", bufp); 1751 "request interrupt %s failed\n", bufp);
1730 goto err2; 1752 goto err_request_irq;
1731 } 1753 }
1732 hcd->irq = irqnum; 1754 hcd->irq = irqnum;
1733 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp, 1755 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp,
@@ -1743,19 +1765,55 @@ int usb_add_hcd(struct usb_hcd *hcd,
1743 (unsigned long long)hcd->rsrc_start); 1765 (unsigned long long)hcd->rsrc_start);
1744 } 1766 }
1745 1767
1768 /* Allocate the root hub before calling hcd->driver->start(),
1769 * but don't register it until afterward so that the hardware
1770 * is running.
1771 */
1772 if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
1773 dev_err(hcd->self.controller, "unable to allocate root hub\n");
1774 retval = -ENOMEM;
1775 goto err_allocate_root_hub;
1776 }
1777 rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
1778 USB_SPEED_FULL;
1779
1780 /* Although in principle hcd->driver->start() might need to use rhdev,
1781 * none of the current drivers do.
1782 */
1746 if ((retval = hcd->driver->start(hcd)) < 0) { 1783 if ((retval = hcd->driver->start(hcd)) < 0) {
1747 dev_err(hcd->self.controller, "startup error %d\n", retval); 1784 dev_err(hcd->self.controller, "startup error %d\n", retval);
1748 goto err3; 1785 goto err_hcd_driver_start;
1749 } 1786 }
1750 1787
1788 /* hcd->driver->start() reported can_wakeup, probably with
1789 * assistance from board's boot firmware.
1790 * NOTE: normal devices won't enable wakeup by default.
1791 */
1792 if (hcd->can_wakeup)
1793 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
1794 hcd->remote_wakeup = hcd->can_wakeup;
1795
1796 if ((retval = register_root_hub(rhdev, hcd)) != 0)
1797 goto err_register_root_hub;
1798
1799 if (hcd->uses_new_polling && hcd->poll_rh)
1800 usb_hcd_poll_rh_status(hcd);
1751 return retval; 1801 return retval;
1752 1802
1753 err3: 1803 err_register_root_hub:
1804 hcd->driver->stop(hcd);
1805
1806 err_hcd_driver_start:
1807 usb_put_dev(rhdev);
1808
1809 err_allocate_root_hub:
1754 if (hcd->irq >= 0) 1810 if (hcd->irq >= 0)
1755 free_irq(irqnum, hcd); 1811 free_irq(irqnum, hcd);
1756 err2: 1812
1813 err_request_irq:
1757 usb_deregister_bus(&hcd->self); 1814 usb_deregister_bus(&hcd->self);
1758 err1: 1815
1816 err_register_bus:
1759 hcd_buffer_destroy(hcd); 1817 hcd_buffer_destroy(hcd);
1760 return retval; 1818 return retval;
1761} 1819}
@@ -1782,6 +1840,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1782 spin_unlock_irq (&hcd_root_hub_lock); 1840 spin_unlock_irq (&hcd_root_hub_lock);
1783 usb_disconnect(&hcd->self.root_hub); 1841 usb_disconnect(&hcd->self.root_hub);
1784 1842
1843 hcd->poll_rh = 0;
1844 del_timer_sync(&hcd->rh_timer);
1845
1785 hcd->driver->stop(hcd); 1846 hcd->driver->stop(hcd);
1786 hcd->state = HC_STATE_HALT; 1847 hcd->state = HC_STATE_HALT;
1787 1848
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 325a51656c3f..67db4a999b93 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -65,7 +65,8 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
65 const char *product_desc; /* product/vendor string */ 65 const char *product_desc; /* product/vendor string */
66 char irq_descr[24]; /* driver + bus # */ 66 char irq_descr[24]; /* driver + bus # */
67 67
68 struct timer_list rh_timer; /* drives root hub */ 68 struct timer_list rh_timer; /* drives root-hub polling */
69 struct urb *status_urb; /* the current status urb */
69 70
70 /* 71 /*
71 * hardware info/state 72 * hardware info/state
@@ -76,10 +77,17 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */
76 unsigned remote_wakeup:1;/* sw should use wakeup? */ 77 unsigned remote_wakeup:1;/* sw should use wakeup? */
77 unsigned rh_registered:1;/* is root hub registered? */ 78 unsigned rh_registered:1;/* is root hub registered? */
78 79
80 /* The next flag is a stopgap, to be removed when all the HCDs
81 * support the new root-hub polling mechanism. */
82 unsigned uses_new_polling:1;
83 unsigned poll_rh:1; /* poll for rh status? */
84 unsigned poll_pending:1; /* status has changed? */
85
79 int irq; /* irq allocated */ 86 int irq; /* irq allocated */
80 void __iomem *regs; /* device memory/io */ 87 void __iomem *regs; /* device memory/io */
81 u64 rsrc_start; /* memory/io resource start */ 88 u64 rsrc_start; /* memory/io resource start */
82 u64 rsrc_len; /* memory/io resource length */ 89 u64 rsrc_len; /* memory/io resource length */
90 unsigned power_budget; /* in mA, 0 = no limit */
83 91
84#define HCD_BUFFER_POOLS 4 92#define HCD_BUFFER_POOLS 4
85 struct dma_pool *pool [HCD_BUFFER_POOLS]; 93 struct dma_pool *pool [HCD_BUFFER_POOLS];
@@ -134,12 +142,12 @@ struct hcd_timeout { /* timeouts we allocate */
134 142
135struct usb_operations { 143struct usb_operations {
136 int (*get_frame_number) (struct usb_device *usb_dev); 144 int (*get_frame_number) (struct usb_device *usb_dev);
137 int (*submit_urb) (struct urb *urb, int mem_flags); 145 int (*submit_urb) (struct urb *urb, unsigned mem_flags);
138 int (*unlink_urb) (struct urb *urb, int status); 146 int (*unlink_urb) (struct urb *urb, int status);
139 147
140 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */ 148 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */
141 void *(*buffer_alloc)(struct usb_bus *bus, size_t size, 149 void *(*buffer_alloc)(struct usb_bus *bus, size_t size,
142 int mem_flags, 150 unsigned mem_flags,
143 dma_addr_t *dma); 151 dma_addr_t *dma);
144 void (*buffer_free)(struct usb_bus *bus, size_t size, 152 void (*buffer_free)(struct usb_bus *bus, size_t size,
145 void *addr, dma_addr_t dma); 153 void *addr, dma_addr_t dma);
@@ -192,7 +200,7 @@ struct hc_driver {
192 int (*urb_enqueue) (struct usb_hcd *hcd, 200 int (*urb_enqueue) (struct usb_hcd *hcd,
193 struct usb_host_endpoint *ep, 201 struct usb_host_endpoint *ep,
194 struct urb *urb, 202 struct urb *urb,
195 int mem_flags); 203 unsigned mem_flags);
196 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb); 204 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
197 205
198 /* hw synch, freeing endpoint resources that urb_dequeue can't */ 206 /* hw synch, freeing endpoint resources that urb_dequeue can't */
@@ -207,6 +215,8 @@ struct hc_driver {
207 int (*hub_suspend)(struct usb_hcd *); 215 int (*hub_suspend)(struct usb_hcd *);
208 int (*hub_resume)(struct usb_hcd *); 216 int (*hub_resume)(struct usb_hcd *);
209 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 217 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
218 void (*hub_irq_enable)(struct usb_hcd *);
219 /* Needed only if port-change IRQs are level-triggered */
210}; 220};
211 221
212extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs); 222extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs);
@@ -237,13 +247,15 @@ int hcd_buffer_create (struct usb_hcd *hcd);
237void hcd_buffer_destroy (struct usb_hcd *hcd); 247void hcd_buffer_destroy (struct usb_hcd *hcd);
238 248
239void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, 249void *hcd_buffer_alloc (struct usb_bus *bus, size_t size,
240 int mem_flags, dma_addr_t *dma); 250 unsigned mem_flags, dma_addr_t *dma);
241void hcd_buffer_free (struct usb_bus *bus, size_t size, 251void hcd_buffer_free (struct usb_bus *bus, size_t size,
242 void *addr, dma_addr_t dma); 252 void *addr, dma_addr_t dma);
243 253
244/* generic bus glue, needed for host controllers that don't use PCI */ 254/* generic bus glue, needed for host controllers that don't use PCI */
245extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r); 255extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r);
256
246extern void usb_hc_died (struct usb_hcd *hcd); 257extern void usb_hc_died (struct usb_hcd *hcd);
258extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd);
247 259
248/* -------------------------------------------------------------------------- */ 260/* -------------------------------------------------------------------------- */
249 261
@@ -341,9 +353,6 @@ extern long usb_calc_bus_time (int speed, int is_input,
341 353
342extern struct usb_bus *usb_alloc_bus (struct usb_operations *); 354extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
343 355
344extern int usb_hcd_register_root_hub (struct usb_device *usb_dev,
345 struct usb_hcd *hcd);
346
347extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 356extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
348 357
349extern void usb_set_device_state(struct usb_device *udev, 358extern void usb_set_device_state(struct usb_device *udev,
@@ -360,6 +369,8 @@ extern wait_queue_head_t usb_kill_urb_queue;
360extern struct usb_bus *usb_bus_get (struct usb_bus *bus); 369extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
361extern void usb_bus_put (struct usb_bus *bus); 370extern void usb_bus_put (struct usb_bus *bus);
362 371
372extern void usb_enable_root_hub_irq (struct usb_bus *bus);
373
363extern int usb_find_interface_driver (struct usb_device *dev, 374extern int usb_find_interface_driver (struct usb_device *dev,
364 struct usb_interface *interface); 375 struct usb_interface *interface);
365 376
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a8d879a85d04..c3e46d24a37e 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -26,6 +26,7 @@
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usbdevice_fs.h> 28#include <linux/usbdevice_fs.h>
29#include <linux/kthread.h>
29 30
30#include <asm/semaphore.h> 31#include <asm/semaphore.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -47,8 +48,7 @@ static LIST_HEAD(hub_event_list); /* List of hubs needing servicing */
47/* Wakes up khubd */ 48/* Wakes up khubd */
48static DECLARE_WAIT_QUEUE_HEAD(khubd_wait); 49static DECLARE_WAIT_QUEUE_HEAD(khubd_wait);
49 50
50static pid_t khubd_pid = 0; /* PID of khubd */ 51static struct task_struct *khubd_task;
51static DECLARE_COMPLETION(khubd_exited);
52 52
53/* cycle leds on hubs that aren't blinking for attention */ 53/* cycle leds on hubs that aren't blinking for attention */
54static int blinkenlights = 0; 54static int blinkenlights = 0;
@@ -643,15 +643,21 @@ static int hub_configure(struct usb_hub *hub,
643 message = "can't get hub status"; 643 message = "can't get hub status";
644 goto fail; 644 goto fail;
645 } 645 }
646 cpu_to_le16s(&hubstatus); 646 le16_to_cpus(&hubstatus);
647 if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 647 if (hdev == hdev->bus->root_hub) {
648 struct usb_hcd *hcd =
649 container_of(hdev->bus, struct usb_hcd, self);
650
651 hub->power_budget = min(500u, hcd->power_budget) / 2;
652 } else if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
648 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", 653 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",
649 hub->descriptor->bHubContrCurrent); 654 hub->descriptor->bHubContrCurrent);
650 hub->power_budget = (501 - hub->descriptor->bHubContrCurrent) 655 hub->power_budget = (501 - hub->descriptor->bHubContrCurrent)
651 / 2; 656 / 2;
657 }
658 if (hub->power_budget)
652 dev_dbg(hub_dev, "%dmA bus power budget for children\n", 659 dev_dbg(hub_dev, "%dmA bus power budget for children\n",
653 hub->power_budget * 2); 660 hub->power_budget * 2);
654 }
655 661
656 662
657 ret = hub_hub_status(hub, &hubstatus, &hubchange); 663 ret = hub_hub_status(hub, &hubstatus, &hubchange);
@@ -1727,7 +1733,7 @@ static int finish_port_resume(struct usb_device *udev)
1727 struct usb_driver *driver; 1733 struct usb_driver *driver;
1728 1734
1729 intf = udev->actconfig->interface[i]; 1735 intf = udev->actconfig->interface[i];
1730 if (intf->dev.power.power_state == PMSG_SUSPEND) 1736 if (intf->dev.power.power_state == PMSG_ON)
1731 continue; 1737 continue;
1732 if (!intf->dev.driver) { 1738 if (!intf->dev.driver) {
1733 /* FIXME maybe force to alt 0 */ 1739 /* FIXME maybe force to alt 0 */
@@ -2787,6 +2793,11 @@ static void hub_events(void)
2787 2793
2788 hub->activating = 0; 2794 hub->activating = 0;
2789 2795
2796 /* If this is a root hub, tell the HCD it's okay to
2797 * re-enable port-change interrupts now. */
2798 if (!hdev->parent)
2799 usb_enable_root_hub_irq(hdev->bus);
2800
2790loop: 2801loop:
2791 usb_unlock_device(hdev); 2802 usb_unlock_device(hdev);
2792 usb_put_intf(intf); 2803 usb_put_intf(intf);
@@ -2796,23 +2807,16 @@ loop:
2796 2807
2797static int hub_thread(void *__unused) 2808static int hub_thread(void *__unused)
2798{ 2809{
2799 /*
2800 * This thread doesn't need any user-level access,
2801 * so get rid of all our resources
2802 */
2803
2804 daemonize("khubd");
2805 allow_signal(SIGKILL);
2806
2807 /* Send me a signal to get me die (for debugging) */
2808 do { 2810 do {
2809 hub_events(); 2811 hub_events();
2810 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 2812 wait_event_interruptible(khubd_wait,
2813 !list_empty(&hub_event_list) ||
2814 kthread_should_stop());
2811 try_to_freeze(); 2815 try_to_freeze();
2812 } while (!signal_pending(current)); 2816 } while (!kthread_should_stop() || !list_empty(&hub_event_list));
2813 2817
2814 pr_debug ("%s: khubd exiting\n", usbcore_name); 2818 pr_debug("%s: khubd exiting\n", usbcore_name);
2815 complete_and_exit(&khubd_exited, 0); 2819 return 0;
2816} 2820}
2817 2821
2818static struct usb_device_id hub_id_table [] = { 2822static struct usb_device_id hub_id_table [] = {
@@ -2838,20 +2842,15 @@ static struct usb_driver hub_driver = {
2838 2842
2839int usb_hub_init(void) 2843int usb_hub_init(void)
2840{ 2844{
2841 pid_t pid;
2842
2843 if (usb_register(&hub_driver) < 0) { 2845 if (usb_register(&hub_driver) < 0) {
2844 printk(KERN_ERR "%s: can't register hub driver\n", 2846 printk(KERN_ERR "%s: can't register hub driver\n",
2845 usbcore_name); 2847 usbcore_name);
2846 return -1; 2848 return -1;
2847 } 2849 }
2848 2850
2849 pid = kernel_thread(hub_thread, NULL, CLONE_KERNEL); 2851 khubd_task = kthread_run(hub_thread, NULL, "khubd");
2850 if (pid >= 0) { 2852 if (!IS_ERR(khubd_task))
2851 khubd_pid = pid;
2852
2853 return 0; 2853 return 0;
2854 }
2855 2854
2856 /* Fall through if kernel_thread failed */ 2855 /* Fall through if kernel_thread failed */
2857 usb_deregister(&hub_driver); 2856 usb_deregister(&hub_driver);
@@ -2862,12 +2861,7 @@ int usb_hub_init(void)
2862 2861
2863void usb_hub_cleanup(void) 2862void usb_hub_cleanup(void)
2864{ 2863{
2865 int ret; 2864 kthread_stop(khubd_task);
2866
2867 /* Kill the thread */
2868 ret = kill_proc(khubd_pid, SIGKILL, 1);
2869
2870 wait_for_completion(&khubd_exited);
2871 2865
2872 /* 2866 /*
2873 * Hub resources are freed for us by usb_deregister. It calls 2867 * Hub resources are freed for us by usb_deregister. It calls
@@ -2879,7 +2873,6 @@ void usb_hub_cleanup(void)
2879 usb_deregister(&hub_driver); 2873 usb_deregister(&hub_driver);
2880} /* usb_hub_cleanup() */ 2874} /* usb_hub_cleanup() */
2881 2875
2882
2883static int config_descriptors_changed(struct usb_device *udev) 2876static int config_descriptors_changed(struct usb_device *udev)
2884{ 2877{
2885 unsigned index; 2878 unsigned index;
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index d114b847d56f..53bf5649621e 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -224,15 +224,4 @@ struct usb_hub {
224 struct work_struct leds; 224 struct work_struct leds;
225}; 225};
226 226
227/* use this for low-powered root hubs */
228static inline void
229hub_set_power_budget (struct usb_device *hubdev, unsigned mA)
230{
231 struct usb_hub *hub;
232
233 hub = (struct usb_hub *)
234 usb_get_intfdata (hubdev->actconfig->interface[0]);
235 hub->power_budget = min(mA,(unsigned)500)/2;
236}
237
238#endif /* __LINUX_HUB_H */ 227#endif /* __LINUX_HUB_H */
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index f50aaf25c98e..a428ef479bd7 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -320,7 +320,7 @@ int usb_sg_init (
320 struct scatterlist *sg, 320 struct scatterlist *sg,
321 int nents, 321 int nents,
322 size_t length, 322 size_t length,
323 int mem_flags 323 unsigned mem_flags
324) 324)
325{ 325{
326 int i; 326 int i;
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 740cb4c668df..00297f113849 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -196,6 +196,7 @@ usb_descriptor_attr (bDeviceClass, "%02x\n")
196usb_descriptor_attr (bDeviceSubClass, "%02x\n") 196usb_descriptor_attr (bDeviceSubClass, "%02x\n")
197usb_descriptor_attr (bDeviceProtocol, "%02x\n") 197usb_descriptor_attr (bDeviceProtocol, "%02x\n")
198usb_descriptor_attr (bNumConfigurations, "%d\n") 198usb_descriptor_attr (bNumConfigurations, "%d\n")
199usb_descriptor_attr (bMaxPacketSize0, "%d\n")
199 200
200static struct attribute *dev_attrs[] = { 201static struct attribute *dev_attrs[] = {
201 /* current configuration's attributes */ 202 /* current configuration's attributes */
@@ -211,6 +212,7 @@ static struct attribute *dev_attrs[] = {
211 &dev_attr_bDeviceSubClass.attr, 212 &dev_attr_bDeviceSubClass.attr,
212 &dev_attr_bDeviceProtocol.attr, 213 &dev_attr_bDeviceProtocol.attr,
213 &dev_attr_bNumConfigurations.attr, 214 &dev_attr_bNumConfigurations.attr,
215 &dev_attr_bMaxPacketSize0.attr,
214 &dev_attr_speed.attr, 216 &dev_attr_speed.attr,
215 &dev_attr_devnum.attr, 217 &dev_attr_devnum.attr,
216 &dev_attr_version.attr, 218 &dev_attr_version.attr,
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 0faf18d511de..c0feee25ff0a 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -60,7 +60,7 @@ void usb_init_urb(struct urb *urb)
60 * 60 *
61 * The driver must call usb_free_urb() when it is finished with the urb. 61 * The driver must call usb_free_urb() when it is finished with the urb.
62 */ 62 */
63struct urb *usb_alloc_urb(int iso_packets, int mem_flags) 63struct urb *usb_alloc_urb(int iso_packets, unsigned mem_flags)
64{ 64{
65 struct urb *urb; 65 struct urb *urb;
66 66
@@ -224,7 +224,7 @@ struct urb * usb_get_urb(struct urb *urb)
224 * GFP_NOIO, unless b) or c) apply 224 * GFP_NOIO, unless b) or c) apply
225 * 225 *
226 */ 226 */
227int usb_submit_urb(struct urb *urb, int mem_flags) 227int usb_submit_urb(struct urb *urb, unsigned mem_flags)
228{ 228{
229 int pipe, temp, max; 229 int pipe, temp, max;
230 struct usb_device *dev; 230 struct usb_device *dev;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a3c42203213a..99c85d2f92da 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1129,7 +1129,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
1129void *usb_buffer_alloc ( 1129void *usb_buffer_alloc (
1130 struct usb_device *dev, 1130 struct usb_device *dev,
1131 size_t size, 1131 size_t size,
1132 int mem_flags, 1132 unsigned mem_flags,
1133 dma_addr_t *dma 1133 dma_addr_t *dma
1134) 1134)
1135{ 1135{
@@ -1532,6 +1532,9 @@ EXPORT_SYMBOL(usb_register);
1532EXPORT_SYMBOL(usb_deregister); 1532EXPORT_SYMBOL(usb_deregister);
1533EXPORT_SYMBOL(usb_disabled); 1533EXPORT_SYMBOL(usb_disabled);
1534 1534
1535EXPORT_SYMBOL_GPL(usb_get_intf);
1536EXPORT_SYMBOL_GPL(usb_put_intf);
1537
1535EXPORT_SYMBOL(usb_alloc_dev); 1538EXPORT_SYMBOL(usb_alloc_dev);
1536EXPORT_SYMBOL(usb_put_dev); 1539EXPORT_SYMBOL(usb_put_dev);
1537EXPORT_SYMBOL(usb_get_dev); 1540EXPORT_SYMBOL(usb_get_dev);
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3b24f9f2c234..ff075a53c8d6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -53,6 +53,9 @@ config USB_GADGET_DEBUG_FILES
53 driver on a new board. Enable these files by choosing "Y" 53 driver on a new board. Enable these files by choosing "Y"
54 here. If in doubt, or to conserve kernel memory, say "N". 54 here. If in doubt, or to conserve kernel memory, say "N".
55 55
56config USB_GADGET_SELECTED
57 boolean
58
56# 59#
57# USB Peripheral Controller Support 60# USB Peripheral Controller Support
58# 61#
@@ -85,6 +88,7 @@ config USB_NET2280
85 tristate 88 tristate
86 depends on USB_GADGET_NET2280 89 depends on USB_GADGET_NET2280
87 default USB_GADGET 90 default USB_GADGET
91 select USB_GADGET_SELECTED
88 92
89config USB_GADGET_PXA2XX 93config USB_GADGET_PXA2XX
90 boolean "PXA 25x or IXP 4xx" 94 boolean "PXA 25x or IXP 4xx"
@@ -105,6 +109,7 @@ config USB_PXA2XX
105 tristate 109 tristate
106 depends on USB_GADGET_PXA2XX 110 depends on USB_GADGET_PXA2XX
107 default USB_GADGET 111 default USB_GADGET
112 select USB_GADGET_SELECTED
108 113
109# if there's only one gadget driver, using only two bulk endpoints, 114# if there's only one gadget driver, using only two bulk endpoints,
110# don't waste memory for the other endpoints 115# don't waste memory for the other endpoints
@@ -134,6 +139,7 @@ config USB_GOKU
134 tristate 139 tristate
135 depends on USB_GADGET_GOKU 140 depends on USB_GADGET_GOKU
136 default USB_GADGET 141 default USB_GADGET
142 select USB_GADGET_SELECTED
137 143
138 144
139config USB_GADGET_LH7A40X 145config USB_GADGET_LH7A40X
@@ -146,6 +152,7 @@ config USB_LH7A40X
146 tristate 152 tristate
147 depends on USB_GADGET_LH7A40X 153 depends on USB_GADGET_LH7A40X
148 default USB_GADGET 154 default USB_GADGET
155 select USB_GADGET_SELECTED
149 156
150 157
151config USB_GADGET_OMAP 158config USB_GADGET_OMAP
@@ -167,6 +174,7 @@ config USB_OMAP
167 tristate 174 tristate
168 depends on USB_GADGET_OMAP 175 depends on USB_GADGET_OMAP
169 default USB_GADGET 176 default USB_GADGET
177 select USB_GADGET_SELECTED
170 178
171config USB_OTG 179config USB_OTG
172 boolean "OTG Support" 180 boolean "OTG Support"
@@ -207,6 +215,7 @@ config USB_DUMMY_HCD
207 tristate 215 tristate
208 depends on USB_GADGET_DUMMY_HCD 216 depends on USB_GADGET_DUMMY_HCD
209 default USB_GADGET 217 default USB_GADGET
218 select USB_GADGET_SELECTED
210 219
211# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears 220# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
212# first and will be selected by default. 221# first and will be selected by default.
@@ -226,7 +235,7 @@ config USB_GADGET_DUALSPEED
226# 235#
227choice 236choice
228 tristate "USB Gadget Drivers" 237 tristate "USB Gadget Drivers"
229 depends on USB_GADGET 238 depends on USB_GADGET && USB_GADGET_SELECTED
230 default USB_ETH 239 default USB_ETH
231 help 240 help
232 A Linux "Gadget Driver" talks to the USB Peripheral Controller 241 A Linux "Gadget Driver" talks to the USB Peripheral Controller
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index c039d2fbe7ab..583db7c38cf1 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -65,7 +65,7 @@
65 65
66 66
67#define DRIVER_DESC "USB Host+Gadget Emulator" 67#define DRIVER_DESC "USB Host+Gadget Emulator"
68#define DRIVER_VERSION "17 Dec 2004" 68#define DRIVER_VERSION "02 May 2005"
69 69
70static const char driver_name [] = "dummy_hcd"; 70static const char driver_name [] = "dummy_hcd";
71static const char driver_desc [] = "USB Host+Gadget Emulator"; 71static const char driver_desc [] = "USB Host+Gadget Emulator";
@@ -141,6 +141,8 @@ static const char *const ep_name [] = {
141}; 141};
142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) 142#define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *))
143 143
144/*-------------------------------------------------------------------------*/
145
144#define FIFO_SIZE 64 146#define FIFO_SIZE 64
145 147
146struct urbp { 148struct urbp {
@@ -148,6 +150,13 @@ struct urbp {
148 struct list_head urbp_list; 150 struct list_head urbp_list;
149}; 151};
150 152
153
154enum dummy_rh_state {
155 DUMMY_RH_RESET,
156 DUMMY_RH_SUSPENDED,
157 DUMMY_RH_RUNNING
158};
159
151struct dummy { 160struct dummy {
152 spinlock_t lock; 161 spinlock_t lock;
153 162
@@ -161,12 +170,18 @@ struct dummy {
161 struct dummy_request fifo_req; 170 struct dummy_request fifo_req;
162 u8 fifo_buf [FIFO_SIZE]; 171 u8 fifo_buf [FIFO_SIZE];
163 u16 devstatus; 172 u16 devstatus;
173 unsigned udc_suspended:1;
174 unsigned pullup:1;
175 unsigned active:1;
176 unsigned old_active:1;
164 177
165 /* 178 /*
166 * MASTER/HOST side support 179 * MASTER/HOST side support
167 */ 180 */
181 enum dummy_rh_state rh_state;
168 struct timer_list timer; 182 struct timer_list timer;
169 u32 port_status; 183 u32 port_status;
184 u32 old_status;
170 unsigned resuming:1; 185 unsigned resuming:1;
171 unsigned long re_timeout; 186 unsigned long re_timeout;
172 187
@@ -189,6 +204,11 @@ static inline struct device *dummy_dev (struct dummy *dum)
189 return dummy_to_hcd(dum)->self.controller; 204 return dummy_to_hcd(dum)->self.controller;
190} 205}
191 206
207static inline struct device *udc_dev (struct dummy *dum)
208{
209 return dum->gadget.dev.parent;
210}
211
192static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 212static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
193{ 213{
194 return container_of (ep->gadget, struct dummy, gadget); 214 return container_of (ep->gadget, struct dummy, gadget);
@@ -208,16 +228,98 @@ static struct dummy *the_controller;
208 228
209/*-------------------------------------------------------------------------*/ 229/*-------------------------------------------------------------------------*/
210 230
211/* 231/* SLAVE/GADGET SIDE UTILITY ROUTINES */
212 * This "hardware" may look a bit odd in diagnostics since it's got both
213 * host and device sides; and it binds different drivers to each side.
214 */
215static struct platform_device the_pdev;
216 232
217static struct device_driver dummy_driver = { 233/* called with spinlock held */
218 .name = (char *) driver_name, 234static void nuke (struct dummy *dum, struct dummy_ep *ep)
219 .bus = &platform_bus_type, 235{
220}; 236 while (!list_empty (&ep->queue)) {
237 struct dummy_request *req;
238
239 req = list_entry (ep->queue.next, struct dummy_request, queue);
240 list_del_init (&req->queue);
241 req->req.status = -ESHUTDOWN;
242
243 spin_unlock (&dum->lock);
244 req->req.complete (&ep->ep, &req->req);
245 spin_lock (&dum->lock);
246 }
247}
248
249/* caller must hold lock */
250static void
251stop_activity (struct dummy *dum)
252{
253 struct dummy_ep *ep;
254
255 /* prevent any more requests */
256 dum->address = 0;
257
258 /* The timer is left running so that outstanding URBs can fail */
259
260 /* nuke any pending requests first, so driver i/o is quiesced */
261 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
262 nuke (dum, ep);
263
264 /* driver now does any non-usb quiescing necessary */
265}
266
267/* caller must hold lock */
268static void
269set_link_state (struct dummy *dum)
270{
271 dum->active = 0;
272 if ((dum->port_status & USB_PORT_STAT_POWER) == 0)
273 dum->port_status = 0;
274
275 /* UDC suspend must cause a disconnect */
276 else if (!dum->pullup || dum->udc_suspended) {
277 dum->port_status &= ~(USB_PORT_STAT_CONNECTION |
278 USB_PORT_STAT_ENABLE |
279 USB_PORT_STAT_LOW_SPEED |
280 USB_PORT_STAT_HIGH_SPEED |
281 USB_PORT_STAT_SUSPEND);
282 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0)
283 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
284 } else {
285 dum->port_status |= USB_PORT_STAT_CONNECTION;
286 if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0)
287 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
288 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0)
289 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
290 else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
291 dum->rh_state != DUMMY_RH_SUSPENDED)
292 dum->active = 1;
293 }
294
295 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active)
296 dum->resuming = 0;
297
298 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
299 (dum->port_status & USB_PORT_STAT_RESET) != 0) {
300 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
301 (dum->old_status & USB_PORT_STAT_RESET) == 0 &&
302 dum->driver) {
303 stop_activity (dum);
304 spin_unlock (&dum->lock);
305 dum->driver->disconnect (&dum->gadget);
306 spin_lock (&dum->lock);
307 }
308 } else if (dum->active != dum->old_active) {
309 if (dum->old_active && dum->driver->suspend) {
310 spin_unlock (&dum->lock);
311 dum->driver->suspend (&dum->gadget);
312 spin_lock (&dum->lock);
313 } else if (!dum->old_active && dum->driver->resume) {
314 spin_unlock (&dum->lock);
315 dum->driver->resume (&dum->gadget);
316 spin_lock (&dum->lock);
317 }
318 }
319
320 dum->old_status = dum->port_status;
321 dum->old_active = dum->active;
322}
221 323
222/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
223 325
@@ -324,7 +426,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
324 _ep->maxpacket = max; 426 _ep->maxpacket = max;
325 ep->desc = desc; 427 ep->desc = desc;
326 428
327 dev_dbg (dummy_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 429 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n",
328 _ep->name, 430 _ep->name,
329 desc->bEndpointAddress & 0x0f, 431 desc->bEndpointAddress & 0x0f,
330 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 432 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
@@ -345,22 +447,6 @@ done:
345 return retval; 447 return retval;
346} 448}
347 449
348/* called with spinlock held */
349static void nuke (struct dummy *dum, struct dummy_ep *ep)
350{
351 while (!list_empty (&ep->queue)) {
352 struct dummy_request *req;
353
354 req = list_entry (ep->queue.next, struct dummy_request, queue);
355 list_del_init (&req->queue);
356 req->req.status = -ESHUTDOWN;
357
358 spin_unlock (&dum->lock);
359 req->req.complete (&ep->ep, &req->req);
360 spin_lock (&dum->lock);
361 }
362}
363
364static int dummy_disable (struct usb_ep *_ep) 450static int dummy_disable (struct usb_ep *_ep)
365{ 451{
366 struct dummy_ep *ep; 452 struct dummy_ep *ep;
@@ -379,12 +465,12 @@ static int dummy_disable (struct usb_ep *_ep)
379 nuke (dum, ep); 465 nuke (dum, ep);
380 spin_unlock_irqrestore (&dum->lock, flags); 466 spin_unlock_irqrestore (&dum->lock, flags);
381 467
382 dev_dbg (dummy_dev(dum), "disabled %s\n", _ep->name); 468 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name);
383 return retval; 469 return retval;
384} 470}
385 471
386static struct usb_request * 472static struct usb_request *
387dummy_alloc_request (struct usb_ep *_ep, int mem_flags) 473dummy_alloc_request (struct usb_ep *_ep, unsigned mem_flags)
388{ 474{
389 struct dummy_ep *ep; 475 struct dummy_ep *ep;
390 struct dummy_request *req; 476 struct dummy_request *req;
@@ -421,7 +507,7 @@ dummy_alloc_buffer (
421 struct usb_ep *_ep, 507 struct usb_ep *_ep,
422 unsigned bytes, 508 unsigned bytes,
423 dma_addr_t *dma, 509 dma_addr_t *dma,
424 int mem_flags 510 unsigned mem_flags
425) { 511) {
426 char *retval; 512 char *retval;
427 struct dummy_ep *ep; 513 struct dummy_ep *ep;
@@ -454,7 +540,8 @@ fifo_complete (struct usb_ep *ep, struct usb_request *req)
454} 540}
455 541
456static int 542static int
457dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags) 543dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
544 unsigned mem_flags)
458{ 545{
459 struct dummy_ep *ep; 546 struct dummy_ep *ep;
460 struct dummy_request *req; 547 struct dummy_request *req;
@@ -474,7 +561,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags)
474 return -ESHUTDOWN; 561 return -ESHUTDOWN;
475 562
476#if 0 563#if 0
477 dev_dbg (dummy_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 564 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
478 ep, _req, _ep->name, _req->length, _req->buf); 565 ep, _req, _ep->name, _req->length, _req->buf);
479#endif 566#endif
480 567
@@ -537,7 +624,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
537 spin_unlock_irqrestore (&dum->lock, flags); 624 spin_unlock_irqrestore (&dum->lock, flags);
538 625
539 if (retval == 0) { 626 if (retval == 0) {
540 dev_dbg (dummy_dev(dum), 627 dev_dbg (udc_dev(dum),
541 "dequeued req %p from %s, len %d buf %p\n", 628 "dequeued req %p from %s, len %d buf %p\n",
542 req, _ep->name, _req->length, _req->buf); 629 req, _ep->name, _req->length, _req->buf);
543 _req->complete (_ep, _req); 630 _req->complete (_ep, _req);
@@ -601,13 +688,21 @@ static int dummy_wakeup (struct usb_gadget *_gadget)
601 struct dummy *dum; 688 struct dummy *dum;
602 689
603 dum = gadget_to_dummy (_gadget); 690 dum = gadget_to_dummy (_gadget);
604 if ((dum->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) == 0 691 if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE)
605 || !(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND))) 692 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
606 return -EINVAL; 693 return -EINVAL;
694 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0)
695 return -ENOLINK;
696 if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
697 dum->rh_state != DUMMY_RH_SUSPENDED)
698 return -EIO;
699
700 /* FIXME: What if the root hub is suspended but the port isn't? */
607 701
608 /* hub notices our request, issues downstream resume, etc */ 702 /* hub notices our request, issues downstream resume, etc */
609 dum->resuming = 1; 703 dum->resuming = 1;
610 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 704 dum->re_timeout = jiffies + msecs_to_jiffies(20);
705 mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout);
611 return 0; 706 return 0;
612} 707}
613 708
@@ -623,10 +718,26 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
623 return 0; 718 return 0;
624} 719}
625 720
721static int dummy_pullup (struct usb_gadget *_gadget, int value)
722{
723 struct dummy *dum;
724 unsigned long flags;
725
726 dum = gadget_to_dummy (_gadget);
727 spin_lock_irqsave (&dum->lock, flags);
728 dum->pullup = (value != 0);
729 set_link_state (dum);
730 spin_unlock_irqrestore (&dum->lock, flags);
731
732 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
733 return 0;
734}
735
626static const struct usb_gadget_ops dummy_ops = { 736static const struct usb_gadget_ops dummy_ops = {
627 .get_frame = dummy_g_get_frame, 737 .get_frame = dummy_g_get_frame,
628 .wakeup = dummy_wakeup, 738 .wakeup = dummy_wakeup,
629 .set_selfpowered = dummy_set_selfpowered, 739 .set_selfpowered = dummy_set_selfpowered,
740 .pullup = dummy_pullup,
630}; 741};
631 742
632/*-------------------------------------------------------------------------*/ 743/*-------------------------------------------------------------------------*/
@@ -641,7 +752,7 @@ show_function (struct device *dev, struct device_attribute *attr, char *buf)
641 return 0; 752 return 0;
642 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 753 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
643} 754}
644DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 755static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
645 756
646/*-------------------------------------------------------------------------*/ 757/*-------------------------------------------------------------------------*/
647 758
@@ -659,38 +770,6 @@ DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
659 * for each driver that registers: just add to a big root hub. 770 * for each driver that registers: just add to a big root hub.
660 */ 771 */
661 772
662static void
663dummy_udc_release (struct device *dev)
664{
665}
666
667static void
668dummy_pdev_release (struct device *dev)
669{
670}
671
672static int
673dummy_register_udc (struct dummy *dum)
674{
675 int rc;
676
677 strcpy (dum->gadget.dev.bus_id, "udc");
678 dum->gadget.dev.parent = dummy_dev(dum);
679 dum->gadget.dev.release = dummy_udc_release;
680
681 rc = device_register (&dum->gadget.dev);
682 if (rc == 0)
683 device_create_file (&dum->gadget.dev, &dev_attr_function);
684 return rc;
685}
686
687static void
688dummy_unregister_udc (struct dummy *dum)
689{
690 device_remove_file (&dum->gadget.dev, &dev_attr_function);
691 device_unregister (&dum->gadget.dev);
692}
693
694int 773int
695usb_gadget_register_driver (struct usb_gadget_driver *driver) 774usb_gadget_register_driver (struct usb_gadget_driver *driver)
696{ 775{
@@ -709,12 +788,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
709 * SLAVE side init ... the layer above hardware, which 788 * SLAVE side init ... the layer above hardware, which
710 * can't enumerate without help from the driver we're binding. 789 * can't enumerate without help from the driver we're binding.
711 */ 790 */
712 dum->gadget.name = gadget_name;
713 dum->gadget.ops = &dummy_ops;
714 dum->gadget.is_dualspeed = 1;
715 791
716 dum->devstatus = 0; 792 dum->devstatus = 0;
717 dum->resuming = 0;
718 793
719 INIT_LIST_HEAD (&dum->gadget.ep_list); 794 INIT_LIST_HEAD (&dum->gadget.ep_list);
720 for (i = 0; i < DUMMY_ENDPOINTS; i++) { 795 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
@@ -740,7 +815,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
740 815
741 dum->driver = driver; 816 dum->driver = driver;
742 dum->gadget.dev.driver = &driver->driver; 817 dum->gadget.dev.driver = &driver->driver;
743 dev_dbg (dummy_dev(dum), "binding gadget driver '%s'\n", 818 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
744 driver->driver.name); 819 driver->driver.name);
745 if ((retval = driver->bind (&dum->gadget)) != 0) { 820 if ((retval = driver->bind (&dum->gadget)) != 0) {
746 dum->driver = NULL; 821 dum->driver = NULL;
@@ -748,42 +823,21 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
748 return retval; 823 return retval;
749 } 824 }
750 825
751 // FIXME: Check these calls for errors and re-order
752 driver->driver.bus = dum->gadget.dev.parent->bus; 826 driver->driver.bus = dum->gadget.dev.parent->bus;
753 driver_register (&driver->driver); 827 driver_register (&driver->driver);
754
755 device_bind_driver (&dum->gadget.dev); 828 device_bind_driver (&dum->gadget.dev);
756 829
757 /* khubd will enumerate this in a while */ 830 /* khubd will enumerate this in a while */
758 dum->port_status |= USB_PORT_STAT_CONNECTION 831 spin_lock_irq (&dum->lock);
759 | (1 << USB_PORT_FEAT_C_CONNECTION); 832 dum->pullup = 1;
833 set_link_state (dum);
834 spin_unlock_irq (&dum->lock);
835
836 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
760 return 0; 837 return 0;
761} 838}
762EXPORT_SYMBOL (usb_gadget_register_driver); 839EXPORT_SYMBOL (usb_gadget_register_driver);
763 840
764/* caller must hold lock */
765static void
766stop_activity (struct dummy *dum, struct usb_gadget_driver *driver)
767{
768 struct dummy_ep *ep;
769
770 /* prevent any more requests */
771 dum->address = 0;
772
773 /* The timer is left running so that outstanding URBs can fail */
774
775 /* nuke any pending requests first, so driver i/o is quiesced */
776 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
777 nuke (dum, ep);
778
779 /* driver now does any non-usb quiescing necessary */
780 if (driver) {
781 spin_unlock (&dum->lock);
782 driver->disconnect (&dum->gadget);
783 spin_lock (&dum->lock);
784 }
785}
786
787int 841int
788usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 842usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
789{ 843{
@@ -795,35 +849,138 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
795 if (!driver || driver != dum->driver) 849 if (!driver || driver != dum->driver)
796 return -EINVAL; 850 return -EINVAL;
797 851
798 dev_dbg (dummy_dev(dum), "unregister gadget driver '%s'\n", 852 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
799 driver->driver.name); 853 driver->driver.name);
800 854
801 spin_lock_irqsave (&dum->lock, flags); 855 spin_lock_irqsave (&dum->lock, flags);
802 stop_activity (dum, driver); 856 dum->pullup = 0;
803 dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | 857 set_link_state (dum);
804 USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
805 dum->port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
806 spin_unlock_irqrestore (&dum->lock, flags); 858 spin_unlock_irqrestore (&dum->lock, flags);
807 859
808 driver->unbind (&dum->gadget); 860 driver->unbind (&dum->gadget);
809 dum->driver = NULL; 861 dum->driver = NULL;
810 862
811 device_release_driver (&dum->gadget.dev); 863 device_release_driver (&dum->gadget.dev);
812
813 driver_unregister (&driver->driver); 864 driver_unregister (&driver->driver);
814 865
866 spin_lock_irqsave (&dum->lock, flags);
867 dum->pullup = 0;
868 set_link_state (dum);
869 spin_unlock_irqrestore (&dum->lock, flags);
870
871 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
815 return 0; 872 return 0;
816} 873}
817EXPORT_SYMBOL (usb_gadget_unregister_driver); 874EXPORT_SYMBOL (usb_gadget_unregister_driver);
818 875
819#undef is_enabled 876#undef is_enabled
820 877
878/* just declare this in any driver that really need it */
879extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
880
821int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) 881int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
822{ 882{
823 return -ENOSYS; 883 return -ENOSYS;
824} 884}
825EXPORT_SYMBOL (net2280_set_fifo_mode); 885EXPORT_SYMBOL (net2280_set_fifo_mode);
826 886
887
888/* The gadget structure is stored inside the hcd structure and will be
889 * released along with it. */
890static void
891dummy_gadget_release (struct device *dev)
892{
893#if 0 /* usb_bus_put isn't EXPORTed! */
894 struct dummy *dum = gadget_dev_to_dummy (dev);
895
896 usb_bus_put (&dummy_to_hcd (dum)->self);
897#endif
898}
899
900static int dummy_udc_probe (struct device *dev)
901{
902 struct dummy *dum = the_controller;
903 int rc;
904
905 dum->gadget.name = gadget_name;
906 dum->gadget.ops = &dummy_ops;
907 dum->gadget.is_dualspeed = 1;
908
909 /* maybe claim OTG support, though we won't complete HNP */
910 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
911
912 strcpy (dum->gadget.dev.bus_id, "gadget");
913 dum->gadget.dev.parent = dev;
914 dum->gadget.dev.release = dummy_gadget_release;
915 rc = device_register (&dum->gadget.dev);
916 if (rc < 0)
917 return rc;
918
919#if 0 /* usb_bus_get isn't EXPORTed! */
920 usb_bus_get (&dummy_to_hcd (dum)->self);
921#endif
922
923 dev_set_drvdata (dev, dum);
924 device_create_file (&dum->gadget.dev, &dev_attr_function);
925 return rc;
926}
927
928static int dummy_udc_remove (struct device *dev)
929{
930 struct dummy *dum = dev_get_drvdata (dev);
931
932 dev_set_drvdata (dev, NULL);
933 device_remove_file (&dum->gadget.dev, &dev_attr_function);
934 device_unregister (&dum->gadget.dev);
935 return 0;
936}
937
938static int dummy_udc_suspend (struct device *dev, pm_message_t state,
939 u32 level)
940{
941 struct dummy *dum = dev_get_drvdata(dev);
942
943 if (level != SUSPEND_DISABLE)
944 return 0;
945
946 dev_dbg (dev, "%s\n", __FUNCTION__);
947 spin_lock_irq (&dum->lock);
948 dum->udc_suspended = 1;
949 set_link_state (dum);
950 spin_unlock_irq (&dum->lock);
951
952 dev->power.power_state = state;
953 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
954 return 0;
955}
956
957static int dummy_udc_resume (struct device *dev, u32 level)
958{
959 struct dummy *dum = dev_get_drvdata(dev);
960
961 if (level != RESUME_ENABLE)
962 return 0;
963
964 dev_dbg (dev, "%s\n", __FUNCTION__);
965 spin_lock_irq (&dum->lock);
966 dum->udc_suspended = 0;
967 set_link_state (dum);
968 spin_unlock_irq (&dum->lock);
969
970 dev->power.power_state = PMSG_ON;
971 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
972 return 0;
973}
974
975static struct device_driver dummy_udc_driver = {
976 .name = (char *) gadget_name,
977 .bus = &platform_bus_type,
978 .probe = dummy_udc_probe,
979 .remove = dummy_udc_remove,
980 .suspend = dummy_udc_suspend,
981 .resume = dummy_udc_resume,
982};
983
827/*-------------------------------------------------------------------------*/ 984/*-------------------------------------------------------------------------*/
828 985
829/* MASTER/HOST SIDE DRIVER 986/* MASTER/HOST SIDE DRIVER
@@ -842,7 +999,7 @@ static int dummy_urb_enqueue (
842 struct usb_hcd *hcd, 999 struct usb_hcd *hcd,
843 struct usb_host_endpoint *ep, 1000 struct usb_host_endpoint *ep,
844 struct urb *urb, 1001 struct urb *urb,
845 int mem_flags 1002 unsigned mem_flags
846) { 1003) {
847 struct dummy *dum; 1004 struct dummy *dum;
848 struct urbp *urbp; 1005 struct urbp *urbp;
@@ -880,7 +1037,16 @@ static int dummy_urb_enqueue (
880 1037
881static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1038static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
882{ 1039{
883 /* giveback happens automatically in timer callback */ 1040 struct dummy *dum;
1041 unsigned long flags;
1042
1043 /* giveback happens automatically in timer callback,
1044 * so make sure the callback happens */
1045 dum = hcd_to_dummy (hcd);
1046 spin_lock_irqsave (&dum->lock, flags);
1047 if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list))
1048 mod_timer (&dum->timer, jiffies);
1049 spin_unlock_irqrestore (&dum->lock, flags);
884 return 0; 1050 return 0;
885} 1051}
886 1052
@@ -1025,7 +1191,6 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1025 1191
1026 /* high bandwidth mode */ 1192 /* high bandwidth mode */
1027 tmp = le16_to_cpu(ep->desc->wMaxPacketSize); 1193 tmp = le16_to_cpu(ep->desc->wMaxPacketSize);
1028 tmp = le16_to_cpu (tmp);
1029 tmp = (tmp >> 11) & 0x03; 1194 tmp = (tmp >> 11) & 0x03;
1030 tmp *= 8 /* applies to entire frame */; 1195 tmp *= 8 /* applies to entire frame */;
1031 limit += limit * tmp; 1196 limit += limit * tmp;
@@ -1123,7 +1288,8 @@ restart:
1123 if (urb->status != -EINPROGRESS) { 1288 if (urb->status != -EINPROGRESS) {
1124 /* likely it was just unlinked */ 1289 /* likely it was just unlinked */
1125 goto return_urb; 1290 goto return_urb;
1126 } 1291 } else if (dum->rh_state != DUMMY_RH_RUNNING)
1292 continue;
1127 type = usb_pipetype (urb->pipe); 1293 type = usb_pipetype (urb->pipe);
1128 1294
1129 /* used up this frame's non-periodic bandwidth? 1295 /* used up this frame's non-periodic bandwidth?
@@ -1168,12 +1334,14 @@ restart:
1168 struct usb_ctrlrequest setup; 1334 struct usb_ctrlrequest setup;
1169 int value = 1; 1335 int value = 1;
1170 struct dummy_ep *ep2; 1336 struct dummy_ep *ep2;
1337 unsigned w_index;
1338 unsigned w_value;
1171 1339
1172 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1340 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1173 le16_to_cpus (&setup.wIndex); 1341 w_index = le16_to_cpu(setup.wIndex);
1174 le16_to_cpus (&setup.wValue); 1342 w_value = le16_to_cpu(setup.wValue);
1175 le16_to_cpus (&setup.wLength); 1343 if (le16_to_cpu(setup.wLength) !=
1176 if (setup.wLength != urb->transfer_buffer_length) { 1344 urb->transfer_buffer_length) {
1177 maybe_set_status (urb, -EOVERFLOW); 1345 maybe_set_status (urb, -EOVERFLOW);
1178 goto return_urb; 1346 goto return_urb;
1179 } 1347 }
@@ -1182,7 +1350,7 @@ restart:
1182 list_for_each_entry (req, &ep->queue, queue) { 1350 list_for_each_entry (req, &ep->queue, queue) {
1183 list_del_init (&req->queue); 1351 list_del_init (&req->queue);
1184 req->req.status = -EOVERFLOW; 1352 req->req.status = -EOVERFLOW;
1185 dev_dbg (dummy_dev(dum), "stale req = %p\n", 1353 dev_dbg (udc_dev(dum), "stale req = %p\n",
1186 req); 1354 req);
1187 1355
1188 spin_unlock (&dum->lock); 1356 spin_unlock (&dum->lock);
@@ -1203,31 +1371,40 @@ restart:
1203 case USB_REQ_SET_ADDRESS: 1371 case USB_REQ_SET_ADDRESS:
1204 if (setup.bRequestType != Dev_Request) 1372 if (setup.bRequestType != Dev_Request)
1205 break; 1373 break;
1206 dum->address = setup.wValue; 1374 dum->address = w_value;
1207 maybe_set_status (urb, 0); 1375 maybe_set_status (urb, 0);
1208 dev_dbg (dummy_dev(dum), "set_address = %d\n", 1376 dev_dbg (udc_dev(dum), "set_address = %d\n",
1209 setup.wValue); 1377 w_value);
1210 value = 0; 1378 value = 0;
1211 break; 1379 break;
1212 case USB_REQ_SET_FEATURE: 1380 case USB_REQ_SET_FEATURE:
1213 if (setup.bRequestType == Dev_Request) { 1381 if (setup.bRequestType == Dev_Request) {
1214 value = 0; 1382 value = 0;
1215 switch (setup.wValue) { 1383 switch (w_value) {
1216 case USB_DEVICE_REMOTE_WAKEUP: 1384 case USB_DEVICE_REMOTE_WAKEUP:
1217 break; 1385 break;
1386 case USB_DEVICE_B_HNP_ENABLE:
1387 dum->gadget.b_hnp_enable = 1;
1388 break;
1389 case USB_DEVICE_A_HNP_SUPPORT:
1390 dum->gadget.a_hnp_support = 1;
1391 break;
1392 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1393 dum->gadget.a_alt_hnp_support
1394 = 1;
1395 break;
1218 default: 1396 default:
1219 value = -EOPNOTSUPP; 1397 value = -EOPNOTSUPP;
1220 } 1398 }
1221 if (value == 0) { 1399 if (value == 0) {
1222 dum->devstatus |= 1400 dum->devstatus |=
1223 (1 << setup.wValue); 1401 (1 << w_value);
1224 maybe_set_status (urb, 0); 1402 maybe_set_status (urb, 0);
1225 } 1403 }
1226 1404
1227 } else if (setup.bRequestType == Ep_Request) { 1405 } else if (setup.bRequestType == Ep_Request) {
1228 // endpoint halt 1406 // endpoint halt
1229 ep2 = find_endpoint (dum, 1407 ep2 = find_endpoint (dum, w_index);
1230 setup.wIndex);
1231 if (!ep2) { 1408 if (!ep2) {
1232 value = -EOPNOTSUPP; 1409 value = -EOPNOTSUPP;
1233 break; 1410 break;
@@ -1239,7 +1416,7 @@ restart:
1239 break; 1416 break;
1240 case USB_REQ_CLEAR_FEATURE: 1417 case USB_REQ_CLEAR_FEATURE:
1241 if (setup.bRequestType == Dev_Request) { 1418 if (setup.bRequestType == Dev_Request) {
1242 switch (setup.wValue) { 1419 switch (w_value) {
1243 case USB_DEVICE_REMOTE_WAKEUP: 1420 case USB_DEVICE_REMOTE_WAKEUP:
1244 dum->devstatus &= ~(1 << 1421 dum->devstatus &= ~(1 <<
1245 USB_DEVICE_REMOTE_WAKEUP); 1422 USB_DEVICE_REMOTE_WAKEUP);
@@ -1252,8 +1429,7 @@ restart:
1252 } 1429 }
1253 } else if (setup.bRequestType == Ep_Request) { 1430 } else if (setup.bRequestType == Ep_Request) {
1254 // endpoint halt 1431 // endpoint halt
1255 ep2 = find_endpoint (dum, 1432 ep2 = find_endpoint (dum, w_index);
1256 setup.wIndex);
1257 if (!ep2) { 1433 if (!ep2) {
1258 value = -EOPNOTSUPP; 1434 value = -EOPNOTSUPP;
1259 break; 1435 break;
@@ -1279,7 +1455,7 @@ restart:
1279 if (urb->transfer_buffer_length > 0) { 1455 if (urb->transfer_buffer_length > 0) {
1280 if (setup.bRequestType == 1456 if (setup.bRequestType ==
1281 Ep_InRequest) { 1457 Ep_InRequest) {
1282 ep2 = find_endpoint (dum, setup.wIndex); 1458 ep2 = find_endpoint (dum, w_index);
1283 if (!ep2) { 1459 if (!ep2) {
1284 value = -EOPNOTSUPP; 1460 value = -EOPNOTSUPP;
1285 break; 1461 break;
@@ -1321,7 +1497,7 @@ restart:
1321 1497
1322 if (value < 0) { 1498 if (value < 0) {
1323 if (value != -EOPNOTSUPP) 1499 if (value != -EOPNOTSUPP)
1324 dev_dbg (dummy_dev(dum), 1500 dev_dbg (udc_dev(dum),
1325 "setup --> %d\n", 1501 "setup --> %d\n",
1326 value); 1502 value);
1327 maybe_set_status (urb, -EPIPE); 1503 maybe_set_status (urb, -EPIPE);
@@ -1377,12 +1553,12 @@ return_urb:
1377 goto restart; 1553 goto restart;
1378 } 1554 }
1379 1555
1380 /* want a 1 msec delay here */ 1556 if (list_empty (&dum->urbp_list)) {
1381 if (!list_empty (&dum->urbp_list))
1382 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1383 else {
1384 usb_put_dev (dum->udev); 1557 usb_put_dev (dum->udev);
1385 dum->udev = NULL; 1558 dum->udev = NULL;
1559 } else if (dum->rh_state == DUMMY_RH_RUNNING) {
1560 /* want a 1 msec delay here */
1561 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1386 } 1562 }
1387 1563
1388 spin_unlock_irqrestore (&dum->lock, flags); 1564 spin_unlock_irqrestore (&dum->lock, flags);
@@ -1391,29 +1567,39 @@ return_urb:
1391/*-------------------------------------------------------------------------*/ 1567/*-------------------------------------------------------------------------*/
1392 1568
1393#define PORT_C_MASK \ 1569#define PORT_C_MASK \
1394 ((1 << USB_PORT_FEAT_C_CONNECTION) \ 1570 ((USB_PORT_STAT_C_CONNECTION \
1395 | (1 << USB_PORT_FEAT_C_ENABLE) \ 1571 | USB_PORT_STAT_C_ENABLE \
1396 | (1 << USB_PORT_FEAT_C_SUSPEND) \ 1572 | USB_PORT_STAT_C_SUSPEND \
1397 | (1 << USB_PORT_FEAT_C_OVER_CURRENT) \ 1573 | USB_PORT_STAT_C_OVERCURRENT \
1398 | (1 << USB_PORT_FEAT_C_RESET)) 1574 | USB_PORT_STAT_C_RESET) << 16)
1399 1575
1400static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1576static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1401{ 1577{
1402 struct dummy *dum; 1578 struct dummy *dum;
1403 unsigned long flags; 1579 unsigned long flags;
1404 int retval; 1580 int retval = 0;
1405 1581
1406 dum = hcd_to_dummy (hcd); 1582 dum = hcd_to_dummy (hcd);
1407 1583
1408 spin_lock_irqsave (&dum->lock, flags); 1584 spin_lock_irqsave (&dum->lock, flags);
1409 if (!(dum->port_status & PORT_C_MASK)) 1585 if (hcd->state != HC_STATE_RUNNING)
1410 retval = 0; 1586 goto done;
1411 else { 1587
1588 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
1589 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1590 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1591 set_link_state (dum);
1592 }
1593
1594 if ((dum->port_status & PORT_C_MASK) != 0) {
1412 *buf = (1 << 1); 1595 *buf = (1 << 1);
1413 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", 1596 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n",
1414 dum->port_status); 1597 dum->port_status);
1415 retval = 1; 1598 retval = 1;
1599 if (dum->rh_state == DUMMY_RH_SUSPENDED)
1600 usb_hcd_resume_root_hub (hcd);
1416 } 1601 }
1602done:
1417 spin_unlock_irqrestore (&dum->lock, flags); 1603 spin_unlock_irqrestore (&dum->lock, flags);
1418 return retval; 1604 return retval;
1419} 1605}
@@ -1424,7 +1610,8 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1424 memset (desc, 0, sizeof *desc); 1610 memset (desc, 0, sizeof *desc);
1425 desc->bDescriptorType = 0x29; 1611 desc->bDescriptorType = 0x29;
1426 desc->bDescLength = 9; 1612 desc->bDescLength = 9;
1427 desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001); 1613 desc->wHubCharacteristics = (__force __u16)
1614 (__constant_cpu_to_le16 (0x0001));
1428 desc->bNbrPorts = 1; 1615 desc->bNbrPorts = 1;
1429 desc->bitmap [0] = 0xff; 1616 desc->bitmap [0] = 0xff;
1430 desc->bitmap [1] = 0xff; 1617 desc->bitmap [1] = 0xff;
@@ -1442,6 +1629,9 @@ static int dummy_hub_control (
1442 int retval = 0; 1629 int retval = 0;
1443 unsigned long flags; 1630 unsigned long flags;
1444 1631
1632 if (hcd->state != HC_STATE_RUNNING)
1633 return -ETIMEDOUT;
1634
1445 dum = hcd_to_dummy (hcd); 1635 dum = hcd_to_dummy (hcd);
1446 spin_lock_irqsave (&dum->lock, flags); 1636 spin_lock_irqsave (&dum->lock, flags);
1447 switch (typeReq) { 1637 switch (typeReq) {
@@ -1450,27 +1640,27 @@ static int dummy_hub_control (
1450 case ClearPortFeature: 1640 case ClearPortFeature:
1451 switch (wValue) { 1641 switch (wValue) {
1452 case USB_PORT_FEAT_SUSPEND: 1642 case USB_PORT_FEAT_SUSPEND:
1453 if (dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) { 1643 if (dum->port_status & USB_PORT_STAT_SUSPEND) {
1454 /* 20msec resume signaling */ 1644 /* 20msec resume signaling */
1455 dum->resuming = 1; 1645 dum->resuming = 1;
1456 dum->re_timeout = jiffies + 1646 dum->re_timeout = jiffies +
1457 msecs_to_jiffies(20); 1647 msecs_to_jiffies(20);
1458 } 1648 }
1459 break; 1649 break;
1460 case USB_PORT_FEAT_POWER: 1650 case USB_PORT_FEAT_POWER:
1461 dum->port_status = 0; 1651 if (dum->port_status & USB_PORT_STAT_POWER)
1462 dum->resuming = 0; 1652 dev_dbg (dummy_dev(dum), "power-off\n");
1463 stop_activity(dum, dum->driver); 1653 /* FALLS THROUGH */
1464 break;
1465 default: 1654 default:
1466 dum->port_status &= ~(1 << wValue); 1655 dum->port_status &= ~(1 << wValue);
1656 set_link_state (dum);
1467 } 1657 }
1468 break; 1658 break;
1469 case GetHubDescriptor: 1659 case GetHubDescriptor:
1470 hub_descriptor ((struct usb_hub_descriptor *) buf); 1660 hub_descriptor ((struct usb_hub_descriptor *) buf);
1471 break; 1661 break;
1472 case GetHubStatus: 1662 case GetHubStatus:
1473 *(u32 *) buf = __constant_cpu_to_le32 (0); 1663 *(__le32 *) buf = __constant_cpu_to_le32 (0);
1474 break; 1664 break;
1475 case GetPortStatus: 1665 case GetPortStatus:
1476 if (wIndex != 1) 1666 if (wIndex != 1)
@@ -1479,23 +1669,16 @@ static int dummy_hub_control (
1479 /* whoever resets or resumes must GetPortStatus to 1669 /* whoever resets or resumes must GetPortStatus to
1480 * complete it!! 1670 * complete it!!
1481 */ 1671 */
1482 if (dum->resuming && time_after (jiffies, dum->re_timeout)) { 1672 if (dum->resuming &&
1483 dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 1673 time_after_eq (jiffies, dum->re_timeout)) {
1484 dum->port_status &= ~(1 << USB_PORT_FEAT_SUSPEND); 1674 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1485 dum->resuming = 0; 1675 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1486 dum->re_timeout = 0;
1487 if (dum->driver && dum->driver->resume) {
1488 spin_unlock (&dum->lock);
1489 dum->driver->resume (&dum->gadget);
1490 spin_lock (&dum->lock);
1491 }
1492 } 1676 }
1493 if ((dum->port_status & (1 << USB_PORT_FEAT_RESET)) != 0 1677 if ((dum->port_status & USB_PORT_STAT_RESET) != 0 &&
1494 && time_after (jiffies, dum->re_timeout)) { 1678 time_after_eq (jiffies, dum->re_timeout)) {
1495 dum->port_status |= (1 << USB_PORT_FEAT_C_RESET); 1679 dum->port_status |= (USB_PORT_STAT_C_RESET << 16);
1496 dum->port_status &= ~(1 << USB_PORT_FEAT_RESET); 1680 dum->port_status &= ~USB_PORT_STAT_RESET;
1497 dum->re_timeout = 0; 1681 if (dum->pullup) {
1498 if (dum->driver) {
1499 dum->port_status |= USB_PORT_STAT_ENABLE; 1682 dum->port_status |= USB_PORT_STAT_ENABLE;
1500 /* give it the best speed we agree on */ 1683 /* give it the best speed we agree on */
1501 dum->gadget.speed = dum->driver->speed; 1684 dum->gadget.speed = dum->driver->speed;
@@ -1516,8 +1699,9 @@ static int dummy_hub_control (
1516 } 1699 }
1517 } 1700 }
1518 } 1701 }
1519 ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1702 set_link_state (dum);
1520 ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1703 ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status);
1704 ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16);
1521 break; 1705 break;
1522 case SetHubFeature: 1706 case SetHubFeature:
1523 retval = -EPIPE; 1707 retval = -EPIPE;
@@ -1525,36 +1709,37 @@ static int dummy_hub_control (
1525 case SetPortFeature: 1709 case SetPortFeature:
1526 switch (wValue) { 1710 switch (wValue) {
1527 case USB_PORT_FEAT_SUSPEND: 1711 case USB_PORT_FEAT_SUSPEND:
1528 if ((dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) 1712 if (dum->active) {
1529 == 0) { 1713 dum->port_status |= USB_PORT_STAT_SUSPEND;
1530 dum->port_status |= 1714
1531 (1 << USB_PORT_FEAT_SUSPEND); 1715 /* HNP would happen here; for now we
1532 if (dum->driver && dum->driver->suspend) { 1716 * assume b_bus_req is always true.
1533 spin_unlock (&dum->lock); 1717 */
1534 dum->driver->suspend (&dum->gadget); 1718 set_link_state (dum);
1535 spin_lock (&dum->lock); 1719 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1536 } 1720 & dum->devstatus) != 0)
1721 dev_dbg (dummy_dev(dum),
1722 "no HNP yet!\n");
1537 } 1723 }
1538 break; 1724 break;
1725 case USB_PORT_FEAT_POWER:
1726 dum->port_status |= USB_PORT_STAT_POWER;
1727 set_link_state (dum);
1728 break;
1539 case USB_PORT_FEAT_RESET: 1729 case USB_PORT_FEAT_RESET:
1540 /* if it's already running, disconnect first */ 1730 /* if it's already enabled, disable */
1541 if (dum->port_status & USB_PORT_STAT_ENABLE) { 1731 dum->port_status &= ~(USB_PORT_STAT_ENABLE
1542 dum->port_status &= ~(USB_PORT_STAT_ENABLE 1732 | USB_PORT_STAT_LOW_SPEED
1543 | USB_PORT_STAT_LOW_SPEED 1733 | USB_PORT_STAT_HIGH_SPEED);
1544 | USB_PORT_STAT_HIGH_SPEED); 1734 dum->devstatus = 0;
1545 if (dum->driver) {
1546 dev_dbg (dummy_dev(dum),
1547 "disconnect\n");
1548 stop_activity (dum, dum->driver);
1549 }
1550
1551 /* FIXME test that code path! */
1552 }
1553 /* 50msec reset signaling */ 1735 /* 50msec reset signaling */
1554 dum->re_timeout = jiffies + msecs_to_jiffies(50); 1736 dum->re_timeout = jiffies + msecs_to_jiffies(50);
1555 /* FALLTHROUGH */ 1737 /* FALLS THROUGH */
1556 default: 1738 default:
1557 dum->port_status |= (1 << wValue); 1739 if ((dum->port_status & USB_PORT_STAT_POWER) != 0) {
1740 dum->port_status |= (1 << wValue);
1741 set_link_state (dum);
1742 }
1558 } 1743 }
1559 break; 1744 break;
1560 1745
@@ -1567,9 +1752,35 @@ static int dummy_hub_control (
1567 retval = -EPIPE; 1752 retval = -EPIPE;
1568 } 1753 }
1569 spin_unlock_irqrestore (&dum->lock, flags); 1754 spin_unlock_irqrestore (&dum->lock, flags);
1755
1756 if ((dum->port_status & PORT_C_MASK) != 0)
1757 usb_hcd_poll_rh_status (hcd);
1570 return retval; 1758 return retval;
1571} 1759}
1572 1760
1761static int dummy_hub_suspend (struct usb_hcd *hcd)
1762{
1763 struct dummy *dum = hcd_to_dummy (hcd);
1764
1765 spin_lock_irq (&dum->lock);
1766 dum->rh_state = DUMMY_RH_SUSPENDED;
1767 set_link_state (dum);
1768 spin_unlock_irq (&dum->lock);
1769 return 0;
1770}
1771
1772static int dummy_hub_resume (struct usb_hcd *hcd)
1773{
1774 struct dummy *dum = hcd_to_dummy (hcd);
1775
1776 spin_lock_irq (&dum->lock);
1777 dum->rh_state = DUMMY_RH_RUNNING;
1778 set_link_state (dum);
1779 if (!list_empty(&dum->urbp_list))
1780 mod_timer (&dum->timer, jiffies);
1781 spin_unlock_irq (&dum->lock);
1782 return 0;
1783}
1573 1784
1574/*-------------------------------------------------------------------------*/ 1785/*-------------------------------------------------------------------------*/
1575 1786
@@ -1625,8 +1836,6 @@ static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
1625static int dummy_start (struct usb_hcd *hcd) 1836static int dummy_start (struct usb_hcd *hcd)
1626{ 1837{
1627 struct dummy *dum; 1838 struct dummy *dum;
1628 struct usb_device *root;
1629 int retval;
1630 1839
1631 dum = hcd_to_dummy (hcd); 1840 dum = hcd_to_dummy (hcd);
1632 1841
@@ -1639,38 +1848,22 @@ static int dummy_start (struct usb_hcd *hcd)
1639 init_timer (&dum->timer); 1848 init_timer (&dum->timer);
1640 dum->timer.function = dummy_timer; 1849 dum->timer.function = dummy_timer;
1641 dum->timer.data = (unsigned long) dum; 1850 dum->timer.data = (unsigned long) dum;
1851 dum->rh_state = DUMMY_RH_RUNNING;
1642 1852
1643 INIT_LIST_HEAD (&dum->urbp_list); 1853 INIT_LIST_HEAD (&dum->urbp_list);
1644 1854
1645 root = usb_alloc_dev (NULL, &hcd->self, 0);
1646 if (!root)
1647 return -ENOMEM;
1648
1649 /* root hub enters addressed state... */
1650 hcd->state = HC_STATE_RUNNING;
1651 root->speed = USB_SPEED_HIGH;
1652
1653 /* ...then configured, so khubd sees us. */
1654 if ((retval = usb_hcd_register_root_hub (root, hcd)) != 0) {
1655 goto err1;
1656 }
1657
1658 /* only show a low-power port: just 8mA */ 1855 /* only show a low-power port: just 8mA */
1659 hub_set_power_budget (root, 8); 1856 hcd->power_budget = 8;
1857 hcd->state = HC_STATE_RUNNING;
1858 hcd->uses_new_polling = 1;
1660 1859
1661 if ((retval = dummy_register_udc (dum)) != 0) 1860#ifdef CONFIG_USB_OTG
1662 goto err2; 1861 hcd->self.otg_port = 1;
1862#endif
1663 1863
1664 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1864 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1665 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1865 device_create_file (dummy_dev(dum), &dev_attr_urbs);
1666 return 0; 1866 return 0;
1667
1668 err2:
1669 usb_disconnect (&hcd->self.root_hub);
1670 err1:
1671 usb_put_dev (root);
1672 hcd->state = HC_STATE_QUIESCING;
1673 return retval;
1674} 1867}
1675 1868
1676static void dummy_stop (struct usb_hcd *hcd) 1869static void dummy_stop (struct usb_hcd *hcd)
@@ -1680,10 +1873,7 @@ static void dummy_stop (struct usb_hcd *hcd)
1680 dum = hcd_to_dummy (hcd); 1873 dum = hcd_to_dummy (hcd);
1681 1874
1682 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 1875 device_remove_file (dummy_dev(dum), &dev_attr_urbs);
1683
1684 usb_gadget_unregister_driver (dum->driver); 1876 usb_gadget_unregister_driver (dum->driver);
1685 dummy_unregister_udc (dum);
1686
1687 dev_info (dummy_dev(dum), "stopped\n"); 1877 dev_info (dummy_dev(dum), "stopped\n");
1688} 1878}
1689 1879
@@ -1711,9 +1901,11 @@ static const struct hc_driver dummy_hcd = {
1711 1901
1712 .hub_status_data = dummy_hub_status, 1902 .hub_status_data = dummy_hub_status,
1713 .hub_control = dummy_hub_control, 1903 .hub_control = dummy_hub_control,
1904 .hub_suspend = dummy_hub_suspend,
1905 .hub_resume = dummy_hub_resume,
1714}; 1906};
1715 1907
1716static int dummy_probe (struct device *dev) 1908static int dummy_hcd_probe (struct device *dev)
1717{ 1909{
1718 struct usb_hcd *hcd; 1910 struct usb_hcd *hcd;
1719 int retval; 1911 int retval;
@@ -1733,7 +1925,7 @@ static int dummy_probe (struct device *dev)
1733 return retval; 1925 return retval;
1734} 1926}
1735 1927
1736static void dummy_remove (struct device *dev) 1928static int dummy_hcd_remove (struct device *dev)
1737{ 1929{
1738 struct usb_hcd *hcd; 1930 struct usb_hcd *hcd;
1739 1931
@@ -1741,53 +1933,127 @@ static void dummy_remove (struct device *dev)
1741 usb_remove_hcd (hcd); 1933 usb_remove_hcd (hcd);
1742 usb_put_hcd (hcd); 1934 usb_put_hcd (hcd);
1743 the_controller = NULL; 1935 the_controller = NULL;
1936 return 0;
1744} 1937}
1745 1938
1746/*-------------------------------------------------------------------------*/ 1939static int dummy_hcd_suspend (struct device *dev, pm_message_t state,
1747 1940 u32 level)
1748static int dummy_pdev_detect (void)
1749{ 1941{
1750 int retval; 1942 struct usb_hcd *hcd;
1751 1943
1752 retval = driver_register (&dummy_driver); 1944 if (level != SUSPEND_DISABLE)
1753 if (retval < 0) 1945 return 0;
1754 return retval; 1946
1947 dev_dbg (dev, "%s\n", __FUNCTION__);
1948 hcd = dev_get_drvdata (dev);
1755 1949
1756 the_pdev.name = "hc"; 1950#ifndef CONFIG_USB_SUSPEND
1757 the_pdev.dev.driver = &dummy_driver; 1951 /* Otherwise this would never happen */
1758 the_pdev.dev.release = dummy_pdev_release; 1952 usb_lock_device (hcd->self.root_hub);
1953 dummy_hub_suspend (hcd);
1954 usb_unlock_device (hcd->self.root_hub);
1955#endif
1759 1956
1760 retval = platform_device_register (&the_pdev); 1957 hcd->state = HC_STATE_SUSPENDED;
1761 if (retval < 0) 1958 return 0;
1762 driver_unregister (&dummy_driver);
1763 return retval;
1764} 1959}
1765 1960
1766static void dummy_pdev_remove (void) 1961static int dummy_hcd_resume (struct device *dev, u32 level)
1767{ 1962{
1768 platform_device_unregister (&the_pdev); 1963 struct usb_hcd *hcd;
1769 driver_unregister (&dummy_driver); 1964
1965 if (level != RESUME_ENABLE)
1966 return 0;
1967
1968 dev_dbg (dev, "%s\n", __FUNCTION__);
1969 hcd = dev_get_drvdata (dev);
1970 hcd->state = HC_STATE_RUNNING;
1971
1972#ifndef CONFIG_USB_SUSPEND
1973 /* Otherwise this would never happen */
1974 usb_lock_device (hcd->self.root_hub);
1975 dummy_hub_resume (hcd);
1976 usb_unlock_device (hcd->self.root_hub);
1977#endif
1978
1979 usb_hcd_poll_rh_status (hcd);
1980 return 0;
1770} 1981}
1771 1982
1983static struct device_driver dummy_hcd_driver = {
1984 .name = (char *) driver_name,
1985 .bus = &platform_bus_type,
1986 .probe = dummy_hcd_probe,
1987 .remove = dummy_hcd_remove,
1988 .suspend = dummy_hcd_suspend,
1989 .resume = dummy_hcd_resume,
1990};
1991
1772/*-------------------------------------------------------------------------*/ 1992/*-------------------------------------------------------------------------*/
1773 1993
1994/* These don't need to do anything because the pdev structures are
1995 * statically allocated. */
1996static void
1997dummy_udc_release (struct device *dev) {}
1998
1999static void
2000dummy_hcd_release (struct device *dev) {}
2001
2002static struct platform_device the_udc_pdev = {
2003 .name = (char *) gadget_name,
2004 .id = -1,
2005 .dev = {
2006 .release = dummy_udc_release,
2007 },
2008};
2009
2010static struct platform_device the_hcd_pdev = {
2011 .name = (char *) driver_name,
2012 .id = -1,
2013 .dev = {
2014 .release = dummy_hcd_release,
2015 },
2016};
2017
1774static int __init init (void) 2018static int __init init (void)
1775{ 2019{
1776 int retval; 2020 int retval;
1777 2021
1778 if (usb_disabled ()) 2022 if (usb_disabled ())
1779 return -ENODEV; 2023 return -ENODEV;
1780 if ((retval = dummy_pdev_detect ()) != 0) 2024
2025 retval = driver_register (&dummy_hcd_driver);
2026 if (retval < 0)
1781 return retval; 2027 return retval;
1782 if ((retval = dummy_probe (&the_pdev.dev)) != 0) 2028
1783 dummy_pdev_remove (); 2029 retval = driver_register (&dummy_udc_driver);
2030 if (retval < 0)
2031 goto err_register_udc_driver;
2032
2033 retval = platform_device_register (&the_hcd_pdev);
2034 if (retval < 0)
2035 goto err_register_hcd;
2036
2037 retval = platform_device_register (&the_udc_pdev);
2038 if (retval < 0)
2039 goto err_register_udc;
2040 return retval;
2041
2042err_register_udc:
2043 platform_device_unregister (&the_hcd_pdev);
2044err_register_hcd:
2045 driver_unregister (&dummy_udc_driver);
2046err_register_udc_driver:
2047 driver_unregister (&dummy_hcd_driver);
1784 return retval; 2048 return retval;
1785} 2049}
1786module_init (init); 2050module_init (init);
1787 2051
1788static void __exit cleanup (void) 2052static void __exit cleanup (void)
1789{ 2053{
1790 dummy_remove (&the_pdev.dev); 2054 platform_device_unregister (&the_udc_pdev);
1791 dummy_pdev_remove (); 2055 platform_device_unregister (&the_hcd_pdev);
2056 driver_unregister (&dummy_udc_driver);
2057 driver_unregister (&dummy_hcd_driver);
1792} 2058}
1793module_exit (cleanup); 2059module_exit (cleanup);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 3f783cbdc7c3..8509e955007d 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -84,18 +84,19 @@
84 */ 84 */
85 85
86#define DRIVER_DESC "Ethernet Gadget" 86#define DRIVER_DESC "Ethernet Gadget"
87#define DRIVER_VERSION "Equinox 2004" 87#define DRIVER_VERSION "May Day 2005"
88 88
89static const char shortname [] = "ether"; 89static const char shortname [] = "ether";
90static const char driver_desc [] = DRIVER_DESC; 90static const char driver_desc [] = DRIVER_DESC;
91 91
92#define RX_EXTRA 20 /* guard against rx overflows */ 92#define RX_EXTRA 20 /* guard against rx overflows */
93 93
94#ifdef CONFIG_USB_ETH_RNDIS
95#include "rndis.h" 94#include "rndis.h"
96#else 95
97#define rndis_init() 0 96#ifndef CONFIG_USB_ETH_RNDIS
98#define rndis_exit() do{}while(0) 97#define rndis_uninit(x) do{}while(0)
98#define rndis_deregister(c) do{}while(0)
99#define rndis_exit() do{}while(0)
99#endif 100#endif
100 101
101/* CDC and RNDIS support the same host-chosen outgoing packet filters. */ 102/* CDC and RNDIS support the same host-chosen outgoing packet filters. */
@@ -140,9 +141,6 @@ struct eth_dev {
140 * It also ASSUMES a self-powered device, without remote wakeup, 141 * It also ASSUMES a self-powered device, without remote wakeup,
141 * although remote wakeup support would make sense. 142 * although remote wakeup support would make sense.
142 */ 143 */
143static const char *EP_IN_NAME;
144static const char *EP_OUT_NAME;
145static const char *EP_STATUS_NAME;
146 144
147/*-------------------------------------------------------------------------*/ 145/*-------------------------------------------------------------------------*/
148 146
@@ -312,6 +310,7 @@ static inline int rndis_active(struct eth_dev *dev)
312#define FS_BPS (19 * 64 * 1 * 1000 * 8) 310#define FS_BPS (19 * 64 * 1 * 1000 * 8)
313 311
314#ifdef CONFIG_USB_GADGET_DUALSPEED 312#ifdef CONFIG_USB_GADGET_DUALSPEED
313#define DEVSPEED USB_SPEED_HIGH
315 314
316static unsigned qmult = 5; 315static unsigned qmult = 5;
317module_param (qmult, uint, S_IRUGO|S_IWUSR); 316module_param (qmult, uint, S_IRUGO|S_IWUSR);
@@ -330,6 +329,8 @@ static inline int BITRATE(struct usb_gadget *g)
330} 329}
331 330
332#else /* full speed (low speed doesn't do bulk) */ 331#else /* full speed (low speed doesn't do bulk) */
332#define DEVSPEED USB_SPEED_FULL
333
333#define qlen(gadget) DEFAULT_QLEN 334#define qlen(gadget) DEFAULT_QLEN
334 335
335static inline int BITRATE(struct usb_gadget *g) 336static inline int BITRATE(struct usb_gadget *g)
@@ -395,7 +396,8 @@ static inline int BITRATE(struct usb_gadget *g)
395#define STRING_SUBSET 8 396#define STRING_SUBSET 8
396#define STRING_RNDIS 9 397#define STRING_RNDIS 9
397 398
398#define USB_BUFSIZ 256 /* holds our biggest descriptor */ 399/* holds our biggest descriptor (or RNDIS response) */
400#define USB_BUFSIZ 256
399 401
400/* 402/*
401 * This device advertises one configuration, eth_config, unless RNDIS 403 * This device advertises one configuration, eth_config, unless RNDIS
@@ -538,7 +540,7 @@ static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
538 .bDataInterface = 0x01, 540 .bDataInterface = 0x01,
539}; 541};
540 542
541static struct usb_cdc_acm_descriptor acm_descriptor = { 543static const struct usb_cdc_acm_descriptor acm_descriptor = {
542 .bLength = sizeof acm_descriptor, 544 .bLength = sizeof acm_descriptor,
543 .bDescriptorType = USB_DT_CS_INTERFACE, 545 .bDescriptorType = USB_DT_CS_INTERFACE,
544 .bDescriptorSubType = USB_CDC_ACM_TYPE, 546 .bDescriptorSubType = USB_CDC_ACM_TYPE,
@@ -846,7 +848,7 @@ static const struct usb_descriptor_header *hs_rndis_function [] = {
846#else 848#else
847 849
848/* if there's no high speed support, maxpacket doesn't change. */ 850/* if there's no high speed support, maxpacket doesn't change. */
849#define ep_desc(g,hs,fs) fs 851#define ep_desc(g,hs,fs) (((void)(g)), (fs))
850 852
851static inline void __init hs_subset_descriptors(void) 853static inline void __init hs_subset_descriptors(void)
852{ 854{
@@ -943,13 +945,36 @@ config_buf (enum usb_device_speed speed,
943 945
944/*-------------------------------------------------------------------------*/ 946/*-------------------------------------------------------------------------*/
945 947
946static void eth_start (struct eth_dev *dev, int gfp_flags); 948static void eth_start (struct eth_dev *dev, unsigned gfp_flags);
947static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); 949static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags);
948 950
949#ifdef DEV_CONFIG_CDC 951static int
950static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) 952set_ether_config (struct eth_dev *dev, unsigned gfp_flags)
951{ 953{
952 const struct usb_endpoint_descriptor *d; 954 int result = 0;
955 struct usb_gadget *gadget = dev->gadget;
956
957#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
958 /* status endpoint used for RNDIS and (optionally) CDC */
959 if (!subset_active(dev) && dev->status_ep) {
960 dev->status = ep_desc (gadget, &hs_status_desc,
961 &fs_status_desc);
962 dev->status_ep->driver_data = dev;
963
964 result = usb_ep_enable (dev->status_ep, dev->status);
965 if (result != 0) {
966 DEBUG (dev, "enable %s --> %d\n",
967 dev->status_ep->name, result);
968 goto done;
969 }
970 }
971#endif
972
973 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
974 dev->in_ep->driver_data = dev;
975
976 dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
977 dev->out_ep->driver_data = dev;
953 978
954 /* With CDC, the host isn't allowed to use these two data 979 /* With CDC, the host isn't allowed to use these two data
955 * endpoints in the default altsetting for the interface. 980 * endpoints in the default altsetting for the interface.
@@ -959,135 +984,33 @@ static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
959 * a side effect of setting a packet filter. Deactivation is 984 * a side effect of setting a packet filter. Deactivation is
960 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. 985 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG.
961 */ 986 */
962 987 if (!cdc_active(dev)) {
963 /* one endpoint writes data back IN to the host */ 988 result = usb_ep_enable (dev->in_ep, dev->in);
964 if (strcmp (ep->name, EP_IN_NAME) == 0) { 989 if (result != 0) {
965 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 990 DEBUG(dev, "enable %s --> %d\n",
966 ep->driver_data = dev; 991 dev->in_ep->name, result);
967 dev->in = d; 992 goto done;
968
969 /* one endpoint just reads OUT packets */
970 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
971 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
972 ep->driver_data = dev;
973 dev->out = d;
974
975 /* optional status/notification endpoint */
976 } else if (EP_STATUS_NAME &&
977 strcmp (ep->name, EP_STATUS_NAME) == 0) {
978 int result;
979
980 d = ep_desc (dev->gadget, &hs_status_desc, &fs_status_desc);
981 result = usb_ep_enable (ep, d);
982 if (result < 0)
983 return result;
984
985 ep->driver_data = dev;
986 dev->status = d;
987 }
988 return 0;
989}
990#endif
991
992#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS)
993static inline int ether_ep_setup (struct eth_dev *dev, struct usb_ep *ep)
994{
995 int result;
996 const struct usb_endpoint_descriptor *d;
997
998 /* CDC subset is simpler: if the device is there,
999 * it's live with rx and tx endpoints.
1000 *
1001 * Do this as a shortcut for RNDIS too.
1002 */
1003
1004 /* one endpoint writes data back IN to the host */
1005 if (strcmp (ep->name, EP_IN_NAME) == 0) {
1006 d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
1007 result = usb_ep_enable (ep, d);
1008 if (result < 0)
1009 return result;
1010
1011 ep->driver_data = dev;
1012 dev->in = d;
1013
1014 /* one endpoint just reads OUT packets */
1015 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
1016 d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc);
1017 result = usb_ep_enable (ep, d);
1018 if (result < 0)
1019 return result;
1020
1021 ep->driver_data = dev;
1022 dev->out = d;
1023 }
1024
1025 return 0;
1026}
1027#endif
1028
1029static int
1030set_ether_config (struct eth_dev *dev, int gfp_flags)
1031{
1032 int result = 0;
1033 struct usb_ep *ep;
1034 struct usb_gadget *gadget = dev->gadget;
1035
1036 gadget_for_each_ep (ep, gadget) {
1037#ifdef DEV_CONFIG_CDC
1038 if (!dev->rndis && dev->cdc) {
1039 result = ether_alt_ep_setup (dev, ep);
1040 if (result == 0)
1041 continue;
1042 } 993 }
1043#endif
1044
1045#ifdef CONFIG_USB_ETH_RNDIS
1046 if (dev->rndis && strcmp (ep->name, EP_STATUS_NAME) == 0) {
1047 const struct usb_endpoint_descriptor *d;
1048 d = ep_desc (gadget, &hs_status_desc, &fs_status_desc);
1049 result = usb_ep_enable (ep, d);
1050 if (result == 0) {
1051 ep->driver_data = dev;
1052 dev->status = d;
1053 continue;
1054 }
1055 } else
1056#endif
1057 994
1058 { 995 result = usb_ep_enable (dev->out_ep, dev->out);
1059#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 996 if (result != 0) {
1060 result = ether_ep_setup (dev, ep); 997 DEBUG (dev, "enable %s --> %d\n",
1061 if (result == 0) 998 dev->in_ep->name, result);
1062 continue; 999 goto done;
1063#endif
1064 } 1000 }
1065
1066 /* stop on error */
1067 ERROR (dev, "can't enable %s, result %d\n", ep->name, result);
1068 break;
1069 } 1001 }
1070 if (!result && (!dev->in_ep || !dev->out_ep))
1071 result = -ENODEV;
1072 1002
1003done:
1073 if (result == 0) 1004 if (result == 0)
1074 result = alloc_requests (dev, qlen (gadget), gfp_flags); 1005 result = alloc_requests (dev, qlen (gadget), gfp_flags);
1075 1006
1076 /* on error, disable any endpoints */ 1007 /* on error, disable any endpoints */
1077 if (result < 0) { 1008 if (result < 0) {
1078#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 1009 if (!subset_active(dev))
1079 if (dev->status)
1080 (void) usb_ep_disable (dev->status_ep); 1010 (void) usb_ep_disable (dev->status_ep);
1081#endif
1082 dev->status = NULL; 1011 dev->status = NULL;
1083#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1012 (void) usb_ep_disable (dev->in_ep);
1084 if (dev->rndis || !dev->cdc) { 1013 (void) usb_ep_disable (dev->out_ep);
1085 if (dev->in)
1086 (void) usb_ep_disable (dev->in_ep);
1087 if (dev->out)
1088 (void) usb_ep_disable (dev->out_ep);
1089 }
1090#endif
1091 dev->in = NULL; 1014 dev->in = NULL;
1092 dev->out = NULL; 1015 dev->out = NULL;
1093 } else 1016 } else
@@ -1095,8 +1018,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1095 /* activate non-CDC configs right away 1018 /* activate non-CDC configs right away
1096 * this isn't strictly according to the RNDIS spec 1019 * this isn't strictly according to the RNDIS spec
1097 */ 1020 */
1098#if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1021 if (!cdc_active (dev)) {
1099 if (dev->rndis || !dev->cdc) {
1100 netif_carrier_on (dev->net); 1022 netif_carrier_on (dev->net);
1101 if (netif_running (dev->net)) { 1023 if (netif_running (dev->net)) {
1102 spin_unlock (&dev->lock); 1024 spin_unlock (&dev->lock);
@@ -1104,7 +1026,6 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
1104 spin_lock (&dev->lock); 1026 spin_lock (&dev->lock);
1105 } 1027 }
1106 } 1028 }
1107#endif
1108 1029
1109 if (result == 0) 1030 if (result == 0)
1110 DEBUG (dev, "qlen %d\n", qlen (gadget)); 1031 DEBUG (dev, "qlen %d\n", qlen (gadget));
@@ -1124,6 +1045,7 @@ static void eth_reset_config (struct eth_dev *dev)
1124 1045
1125 netif_stop_queue (dev->net); 1046 netif_stop_queue (dev->net);
1126 netif_carrier_off (dev->net); 1047 netif_carrier_off (dev->net);
1048 rndis_uninit(dev->rndis_config);
1127 1049
1128 /* disable endpoints, forcing (synchronous) completion of 1050 /* disable endpoints, forcing (synchronous) completion of
1129 * pending i/o. then free the requests. 1051 * pending i/o. then free the requests.
@@ -1150,6 +1072,8 @@ static void eth_reset_config (struct eth_dev *dev)
1150 if (dev->status) { 1072 if (dev->status) {
1151 usb_ep_disable (dev->status_ep); 1073 usb_ep_disable (dev->status_ep);
1152 } 1074 }
1075 dev->rndis = 0;
1076 dev->cdc_filter = 0;
1153 dev->config = 0; 1077 dev->config = 0;
1154} 1078}
1155 1079
@@ -1157,14 +1081,11 @@ static void eth_reset_config (struct eth_dev *dev)
1157 * that returns config descriptors, and altsetting code. 1081 * that returns config descriptors, and altsetting code.
1158 */ 1082 */
1159static int 1083static int
1160eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags) 1084eth_set_config (struct eth_dev *dev, unsigned number, unsigned gfp_flags)
1161{ 1085{
1162 int result = 0; 1086 int result = 0;
1163 struct usb_gadget *gadget = dev->gadget; 1087 struct usb_gadget *gadget = dev->gadget;
1164 1088
1165 if (number == dev->config)
1166 return 0;
1167
1168 if (gadget_is_sa1100 (gadget) 1089 if (gadget_is_sa1100 (gadget)
1169 && dev->config 1090 && dev->config
1170 && atomic_read (&dev->tx_qlen) != 0) { 1091 && atomic_read (&dev->tx_qlen) != 0) {
@@ -1174,12 +1095,8 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1174 } 1095 }
1175 eth_reset_config (dev); 1096 eth_reset_config (dev);
1176 1097
1177 /* default: pass all packets, no multicast filtering */
1178 dev->cdc_filter = DEFAULT_FILTER;
1179
1180 switch (number) { 1098 switch (number) {
1181 case DEV_CONFIG_VALUE: 1099 case DEV_CONFIG_VALUE:
1182 dev->rndis = 0;
1183 result = set_ether_config (dev, gfp_flags); 1100 result = set_ether_config (dev, gfp_flags);
1184 break; 1101 break;
1185#ifdef CONFIG_USB_ETH_RNDIS 1102#ifdef CONFIG_USB_ETH_RNDIS
@@ -1218,9 +1135,9 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1218 dev->config = number; 1135 dev->config = number;
1219 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n", 1136 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n",
1220 speed, number, power, driver_desc, 1137 speed, number, power, driver_desc,
1221 dev->rndis 1138 rndis_active(dev)
1222 ? "RNDIS" 1139 ? "RNDIS"
1223 : (dev->cdc 1140 : (cdc_active(dev)
1224 ? "CDC Ethernet" 1141 ? "CDC Ethernet"
1225 : "CDC Ethernet Subset")); 1142 : "CDC Ethernet Subset"));
1226 } 1143 }
@@ -1231,6 +1148,13 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
1231 1148
1232#ifdef DEV_CONFIG_CDC 1149#ifdef DEV_CONFIG_CDC
1233 1150
1151/* The interrupt endpoint is used in CDC networking models (Ethernet, ATM)
1152 * only to notify the host about link status changes (which we support) or
1153 * report completion of some encapsulated command (as used in RNDIS). Since
1154 * we want this CDC Ethernet code to be vendor-neutral, we don't use that
1155 * command mechanism; and only one status request is ever queued.
1156 */
1157
1234static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) 1158static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1235{ 1159{
1236 struct usb_cdc_notification *event = req->buf; 1160 struct usb_cdc_notification *event = req->buf;
@@ -1259,7 +1183,7 @@ static void eth_status_complete (struct usb_ep *ep, struct usb_request *req)
1259 } else if (value != -ECONNRESET) 1183 } else if (value != -ECONNRESET)
1260 DEBUG (dev, "event %02x --> %d\n", 1184 DEBUG (dev, "event %02x --> %d\n",
1261 event->bNotificationType, value); 1185 event->bNotificationType, value);
1262 event->bmRequestType = 0xff; 1186 req->context = NULL;
1263} 1187}
1264 1188
1265static void issue_start_status (struct eth_dev *dev) 1189static void issue_start_status (struct eth_dev *dev)
@@ -1276,6 +1200,8 @@ static void issue_start_status (struct eth_dev *dev)
1276 * a "cancel the whole queue" primitive since any 1200 * a "cancel the whole queue" primitive since any
1277 * unlink-one primitive has way too many error modes. 1201 * unlink-one primitive has way too many error modes.
1278 * here, we "know" toggle is already clear... 1202 * here, we "know" toggle is already clear...
1203 *
1204 * FIXME iff req->context != null just dequeue it
1279 */ 1205 */
1280 usb_ep_disable (dev->status_ep); 1206 usb_ep_disable (dev->status_ep);
1281 usb_ep_enable (dev->status_ep, dev->status); 1207 usb_ep_enable (dev->status_ep, dev->status);
@@ -1292,6 +1218,8 @@ static void issue_start_status (struct eth_dev *dev)
1292 1218
1293 req->length = sizeof *event; 1219 req->length = sizeof *event;
1294 req->complete = eth_status_complete; 1220 req->complete = eth_status_complete;
1221 req->context = dev;
1222
1295 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); 1223 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC);
1296 if (value < 0) 1224 if (value < 0)
1297 DEBUG (dev, "status buf queue --> %d\n", value); 1225 DEBUG (dev, "status buf queue --> %d\n", value);
@@ -1351,9 +1279,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1351 struct eth_dev *dev = get_gadget_data (gadget); 1279 struct eth_dev *dev = get_gadget_data (gadget);
1352 struct usb_request *req = dev->req; 1280 struct usb_request *req = dev->req;
1353 int value = -EOPNOTSUPP; 1281 int value = -EOPNOTSUPP;
1354 u16 wIndex = (__force u16) ctrl->wIndex; 1282 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1355 u16 wValue = (__force u16) ctrl->wValue; 1283 u16 wValue = le16_to_cpu(ctrl->wValue);
1356 u16 wLength = (__force u16) ctrl->wLength; 1284 u16 wLength = le16_to_cpu(ctrl->wLength);
1357 1285
1358 /* descriptors just go into the pre-allocated ep0 buffer, 1286 /* descriptors just go into the pre-allocated ep0 buffer,
1359 * while config change events may enable network traffic. 1287 * while config change events may enable network traffic.
@@ -1424,7 +1352,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1424 || !dev->config 1352 || !dev->config
1425 || wIndex > 1) 1353 || wIndex > 1)
1426 break; 1354 break;
1427 if (!dev->cdc && wIndex != 0) 1355 if (!cdc_active(dev) && wIndex != 0)
1428 break; 1356 break;
1429 spin_lock (&dev->lock); 1357 spin_lock (&dev->lock);
1430 1358
@@ -1456,9 +1384,11 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1456 1384
1457 /* CDC requires the data transfers not be done from 1385 /* CDC requires the data transfers not be done from
1458 * the default interface setting ... also, setting 1386 * the default interface setting ... also, setting
1459 * the non-default interface clears filters etc. 1387 * the non-default interface resets filters etc.
1460 */ 1388 */
1461 if (wValue == 1) { 1389 if (wValue == 1) {
1390 if (!cdc_active (dev))
1391 break;
1462 usb_ep_enable (dev->in_ep, dev->in); 1392 usb_ep_enable (dev->in_ep, dev->in);
1463 usb_ep_enable (dev->out_ep, dev->out); 1393 usb_ep_enable (dev->out_ep, dev->out);
1464 dev->cdc_filter = DEFAULT_FILTER; 1394 dev->cdc_filter = DEFAULT_FILTER;
@@ -1492,11 +1422,11 @@ done_set_intf:
1492 || !dev->config 1422 || !dev->config
1493 || wIndex > 1) 1423 || wIndex > 1)
1494 break; 1424 break;
1495 if (!(dev->cdc || dev->rndis) && wIndex != 0) 1425 if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
1496 break; 1426 break;
1497 1427
1498 /* for CDC, iff carrier is on, data interface is active. */ 1428 /* for CDC, iff carrier is on, data interface is active. */
1499 if (dev->rndis || wIndex != 1) 1429 if (rndis_active(dev) || wIndex != 1)
1500 *(u8 *)req->buf = 0; 1430 *(u8 *)req->buf = 0;
1501 else 1431 else
1502 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; 1432 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0;
@@ -1509,8 +1439,7 @@ done_set_intf:
1509 * wValue = packet filter bitmap 1439 * wValue = packet filter bitmap
1510 */ 1440 */
1511 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1441 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1512 || !dev->cdc 1442 || !cdc_active(dev)
1513 || dev->rndis
1514 || wLength != 0 1443 || wLength != 0
1515 || wIndex > 1) 1444 || wIndex > 1)
1516 break; 1445 break;
@@ -1534,7 +1463,7 @@ done_set_intf:
1534 */ 1463 */
1535 case USB_CDC_SEND_ENCAPSULATED_COMMAND: 1464 case USB_CDC_SEND_ENCAPSULATED_COMMAND:
1536 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1465 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1537 || !dev->rndis 1466 || !rndis_active(dev)
1538 || wLength > USB_BUFSIZ 1467 || wLength > USB_BUFSIZ
1539 || wValue 1468 || wValue
1540 || rndis_control_intf.bInterfaceNumber 1469 || rndis_control_intf.bInterfaceNumber
@@ -1549,7 +1478,7 @@ done_set_intf:
1549 case USB_CDC_GET_ENCAPSULATED_RESPONSE: 1478 case USB_CDC_GET_ENCAPSULATED_RESPONSE:
1550 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1479 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
1551 == ctrl->bRequestType 1480 == ctrl->bRequestType
1552 && dev->rndis 1481 && rndis_active(dev)
1553 // && wLength >= 0x0400 1482 // && wLength >= 0x0400
1554 && !wValue 1483 && !wValue
1555 && rndis_control_intf.bInterfaceNumber 1484 && rndis_control_intf.bInterfaceNumber
@@ -1669,7 +1598,7 @@ static void defer_kevent (struct eth_dev *dev, int flag)
1669static void rx_complete (struct usb_ep *ep, struct usb_request *req); 1598static void rx_complete (struct usb_ep *ep, struct usb_request *req);
1670 1599
1671static int 1600static int
1672rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags) 1601rx_submit (struct eth_dev *dev, struct usb_request *req, unsigned gfp_flags)
1673{ 1602{
1674 struct sk_buff *skb; 1603 struct sk_buff *skb;
1675 int retval = -ENOMEM; 1604 int retval = -ENOMEM;
@@ -1688,10 +1617,8 @@ rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags)
1688 */ 1617 */
1689 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); 1618 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA);
1690 size += dev->out_ep->maxpacket - 1; 1619 size += dev->out_ep->maxpacket - 1;
1691#ifdef CONFIG_USB_ETH_RNDIS 1620 if (rndis_active(dev))
1692 if (dev->rndis)
1693 size += sizeof (struct rndis_packet_msg_type); 1621 size += sizeof (struct rndis_packet_msg_type);
1694#endif
1695 size -= size % dev->out_ep->maxpacket; 1622 size -= size % dev->out_ep->maxpacket;
1696 1623
1697 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { 1624 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) {
@@ -1735,11 +1662,9 @@ static void rx_complete (struct usb_ep *ep, struct usb_request *req)
1735 /* normal completion */ 1662 /* normal completion */
1736 case 0: 1663 case 0:
1737 skb_put (skb, req->actual); 1664 skb_put (skb, req->actual);
1738#ifdef CONFIG_USB_ETH_RNDIS
1739 /* we know MaxPacketsPerTransfer == 1 here */ 1665 /* we know MaxPacketsPerTransfer == 1 here */
1740 if (dev->rndis) 1666 if (rndis_active(dev))
1741 status = rndis_rm_hdr (skb); 1667 status = rndis_rm_hdr (skb);
1742#endif
1743 if (status < 0 1668 if (status < 0
1744 || ETH_HLEN > skb->len 1669 || ETH_HLEN > skb->len
1745 || skb->len > ETH_FRAME_LEN) { 1670 || skb->len > ETH_FRAME_LEN) {
@@ -1799,7 +1724,7 @@ clean:
1799} 1724}
1800 1725
1801static int prealloc (struct list_head *list, struct usb_ep *ep, 1726static int prealloc (struct list_head *list, struct usb_ep *ep,
1802 unsigned n, int gfp_flags) 1727 unsigned n, unsigned gfp_flags)
1803{ 1728{
1804 unsigned i; 1729 unsigned i;
1805 struct usb_request *req; 1730 struct usb_request *req;
@@ -1838,7 +1763,7 @@ extra:
1838 return 0; 1763 return 0;
1839} 1764}
1840 1765
1841static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags) 1766static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags)
1842{ 1767{
1843 int status; 1768 int status;
1844 1769
@@ -1854,13 +1779,11 @@ fail:
1854 return status; 1779 return status;
1855} 1780}
1856 1781
1857static void rx_fill (struct eth_dev *dev, int gfp_flags) 1782static void rx_fill (struct eth_dev *dev, unsigned gfp_flags)
1858{ 1783{
1859 struct usb_request *req; 1784 struct usb_request *req;
1860 unsigned long flags; 1785 unsigned long flags;
1861 1786
1862 clear_bit (WORK_RX_MEMORY, &dev->todo);
1863
1864 /* fill unused rxq slots with some skb */ 1787 /* fill unused rxq slots with some skb */
1865 spin_lock_irqsave (&dev->lock, flags); 1788 spin_lock_irqsave (&dev->lock, flags);
1866 while (!list_empty (&dev->rx_reqs)) { 1789 while (!list_empty (&dev->rx_reqs)) {
@@ -1883,11 +1806,9 @@ static void eth_work (void *_dev)
1883{ 1806{
1884 struct eth_dev *dev = _dev; 1807 struct eth_dev *dev = _dev;
1885 1808
1886 if (test_bit (WORK_RX_MEMORY, &dev->todo)) { 1809 if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) {
1887 if (netif_running (dev->net)) 1810 if (netif_running (dev->net))
1888 rx_fill (dev, GFP_KERNEL); 1811 rx_fill (dev, GFP_KERNEL);
1889 else
1890 clear_bit (WORK_RX_MEMORY, &dev->todo);
1891 } 1812 }
1892 1813
1893 if (dev->todo) 1814 if (dev->todo)
@@ -1971,8 +1892,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1971 * or the hardware can't use skb buffers. 1892 * or the hardware can't use skb buffers.
1972 * or there's not enough space for any RNDIS headers we need 1893 * or there's not enough space for any RNDIS headers we need
1973 */ 1894 */
1974#ifdef CONFIG_USB_ETH_RNDIS 1895 if (rndis_active(dev)) {
1975 if (dev->rndis) {
1976 struct sk_buff *skb_rndis; 1896 struct sk_buff *skb_rndis;
1977 1897
1978 skb_rndis = skb_realloc_headroom (skb, 1898 skb_rndis = skb_realloc_headroom (skb,
@@ -1985,7 +1905,6 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1985 rndis_add_hdr (skb); 1905 rndis_add_hdr (skb);
1986 length = skb->len; 1906 length = skb->len;
1987 } 1907 }
1988#endif
1989 req->buf = skb->data; 1908 req->buf = skb->data;
1990 req->context = skb; 1909 req->context = skb;
1991 req->complete = tx_complete; 1910 req->complete = tx_complete;
@@ -2018,9 +1937,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
2018 } 1937 }
2019 1938
2020 if (retval) { 1939 if (retval) {
2021#ifdef CONFIG_USB_ETH_RNDIS
2022drop: 1940drop:
2023#endif
2024 dev->stats.tx_dropped++; 1941 dev->stats.tx_dropped++;
2025 dev_kfree_skb_any (skb); 1942 dev_kfree_skb_any (skb);
2026 spin_lock_irqsave (&dev->lock, flags); 1943 spin_lock_irqsave (&dev->lock, flags);
@@ -2036,27 +1953,31 @@ drop:
2036 1953
2037#ifdef CONFIG_USB_ETH_RNDIS 1954#ifdef CONFIG_USB_ETH_RNDIS
2038 1955
2039static void rndis_send_media_state (struct eth_dev *dev, int connect) 1956/* The interrupt endpoint is used in RNDIS to notify the host when messages
2040{ 1957 * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT
2041 if (!dev) 1958 * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even
2042 return; 1959 * REMOTE_NDIS_KEEPALIVE_MSG.
2043 1960 *
2044 if (connect) { 1961 * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and
2045 if (rndis_signal_connect (dev->rndis_config)) 1962 * normally just one notification will be queued.
2046 return; 1963 */
2047 } else { 1964
2048 if (rndis_signal_disconnect (dev->rndis_config)) 1965static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned);
2049 return; 1966static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
2050 }
2051}
2052 1967
2053static void 1968static void
2054rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) 1969rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
2055{ 1970{
1971 struct eth_dev *dev = ep->driver_data;
1972
2056 if (req->status || req->actual != req->length) 1973 if (req->status || req->actual != req->length)
2057 DEBUG ((struct eth_dev *) ep->driver_data, 1974 DEBUG (dev,
2058 "rndis control ack complete --> %d, %d/%d\n", 1975 "rndis control ack complete --> %d, %d/%d\n",
2059 req->status, req->actual, req->length); 1976 req->status, req->actual, req->length);
1977 req->context = NULL;
1978
1979 if (req != dev->stat_req)
1980 eth_req_free(ep, req);
2060} 1981}
2061 1982
2062static int rndis_control_ack (struct net_device *net) 1983static int rndis_control_ack (struct net_device *net)
@@ -2071,11 +1992,19 @@ static int rndis_control_ack (struct net_device *net)
2071 return -ENODEV; 1992 return -ENODEV;
2072 } 1993 }
2073 1994
1995 /* in case queue length > 1 */
1996 if (resp->context) {
1997 resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC);
1998 if (!resp)
1999 return -ENOMEM;
2000 }
2001
2074 /* Send RNDIS RESPONSE_AVAILABLE notification; 2002 /* Send RNDIS RESPONSE_AVAILABLE notification;
2075 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too 2003 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too
2076 */ 2004 */
2077 resp->length = 8; 2005 resp->length = 8;
2078 resp->complete = rndis_control_ack_complete; 2006 resp->complete = rndis_control_ack_complete;
2007 resp->context = dev;
2079 2008
2080 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); 2009 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1);
2081 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); 2010 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0);
@@ -2089,9 +2018,13 @@ static int rndis_control_ack (struct net_device *net)
2089 return 0; 2018 return 0;
2090} 2019}
2091 2020
2021#else
2022
2023#define rndis_control_ack NULL
2024
2092#endif /* RNDIS */ 2025#endif /* RNDIS */
2093 2026
2094static void eth_start (struct eth_dev *dev, int gfp_flags) 2027static void eth_start (struct eth_dev *dev, unsigned gfp_flags)
2095{ 2028{
2096 DEBUG (dev, "%s\n", __FUNCTION__); 2029 DEBUG (dev, "%s\n", __FUNCTION__);
2097 2030
@@ -2101,14 +2034,12 @@ static void eth_start (struct eth_dev *dev, int gfp_flags)
2101 /* and open the tx floodgates */ 2034 /* and open the tx floodgates */
2102 atomic_set (&dev->tx_qlen, 0); 2035 atomic_set (&dev->tx_qlen, 0);
2103 netif_wake_queue (dev->net); 2036 netif_wake_queue (dev->net);
2104#ifdef CONFIG_USB_ETH_RNDIS 2037 if (rndis_active(dev)) {
2105 if (dev->rndis) {
2106 rndis_set_param_medium (dev->rndis_config, 2038 rndis_set_param_medium (dev->rndis_config,
2107 NDIS_MEDIUM_802_3, 2039 NDIS_MEDIUM_802_3,
2108 BITRATE(dev->gadget)/100); 2040 BITRATE(dev->gadget)/100);
2109 rndis_send_media_state (dev, 1); 2041 (void) rndis_signal_connect (dev->rndis_config);
2110 } 2042 }
2111#endif
2112} 2043}
2113 2044
2114static int eth_open (struct net_device *net) 2045static int eth_open (struct net_device *net)
@@ -2149,28 +2080,27 @@ static int eth_stop (struct net_device *net)
2149 } 2080 }
2150 } 2081 }
2151 2082
2152#ifdef CONFIG_USB_ETH_RNDIS 2083 if (rndis_active(dev)) {
2153 if (dev->rndis) {
2154 rndis_set_param_medium (dev->rndis_config, 2084 rndis_set_param_medium (dev->rndis_config,
2155 NDIS_MEDIUM_802_3, 0); 2085 NDIS_MEDIUM_802_3, 0);
2156 rndis_send_media_state (dev, 0); 2086 (void) rndis_signal_disconnect (dev->rndis_config);
2157 } 2087 }
2158#endif
2159 2088
2160 return 0; 2089 return 0;
2161} 2090}
2162 2091
2163/*-------------------------------------------------------------------------*/ 2092/*-------------------------------------------------------------------------*/
2164 2093
2165static struct usb_request *eth_req_alloc (struct usb_ep *ep, unsigned size) 2094static struct usb_request *
2095eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags)
2166{ 2096{
2167 struct usb_request *req; 2097 struct usb_request *req;
2168 2098
2169 req = usb_ep_alloc_request (ep, GFP_KERNEL); 2099 req = usb_ep_alloc_request (ep, gfp_flags);
2170 if (!req) 2100 if (!req)
2171 return NULL; 2101 return NULL;
2172 2102
2173 req->buf = kmalloc (size, GFP_KERNEL); 2103 req->buf = kmalloc (size, gfp_flags);
2174 if (!req->buf) { 2104 if (!req->buf) {
2175 usb_ep_free_request (ep, req); 2105 usb_ep_free_request (ep, req);
2176 req = NULL; 2106 req = NULL;
@@ -2192,10 +2122,8 @@ eth_unbind (struct usb_gadget *gadget)
2192 struct eth_dev *dev = get_gadget_data (gadget); 2122 struct eth_dev *dev = get_gadget_data (gadget);
2193 2123
2194 DEBUG (dev, "unbind\n"); 2124 DEBUG (dev, "unbind\n");
2195#ifdef CONFIG_USB_ETH_RNDIS
2196 rndis_deregister (dev->rndis_config); 2125 rndis_deregister (dev->rndis_config);
2197 rndis_exit (); 2126 rndis_exit ();
2198#endif
2199 2127
2200 /* we've already been disconnected ... no i/o is active */ 2128 /* we've already been disconnected ... no i/o is active */
2201 if (dev->req) { 2129 if (dev->req) {
@@ -2368,13 +2296,11 @@ autoconf_fail:
2368 gadget->name); 2296 gadget->name);
2369 return -ENODEV; 2297 return -ENODEV;
2370 } 2298 }
2371 EP_IN_NAME = in_ep->name;
2372 in_ep->driver_data = in_ep; /* claim */ 2299 in_ep->driver_data = in_ep; /* claim */
2373 2300
2374 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 2301 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
2375 if (!out_ep) 2302 if (!out_ep)
2376 goto autoconf_fail; 2303 goto autoconf_fail;
2377 EP_OUT_NAME = out_ep->name;
2378 out_ep->driver_data = out_ep; /* claim */ 2304 out_ep->driver_data = out_ep; /* claim */
2379 2305
2380#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2306#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
@@ -2384,7 +2310,6 @@ autoconf_fail:
2384 if (cdc || rndis) { 2310 if (cdc || rndis) {
2385 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); 2311 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc);
2386 if (status_ep) { 2312 if (status_ep) {
2387 EP_STATUS_NAME = status_ep->name;
2388 status_ep->driver_data = status_ep; /* claim */ 2313 status_ep->driver_data = status_ep; /* claim */
2389 } else if (rndis) { 2314 } else if (rndis) {
2390 dev_err (&gadget->dev, 2315 dev_err (&gadget->dev,
@@ -2426,7 +2351,7 @@ autoconf_fail:
2426 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 2351 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
2427 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 2352 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
2428#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2353#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2429 if (EP_STATUS_NAME) 2354 if (status_ep)
2430 hs_status_desc.bEndpointAddress = 2355 hs_status_desc.bEndpointAddress =
2431 fs_status_desc.bEndpointAddress; 2356 fs_status_desc.bEndpointAddress;
2432#endif 2357#endif
@@ -2499,20 +2424,23 @@ autoconf_fail:
2499 SET_ETHTOOL_OPS(net, &ops); 2424 SET_ETHTOOL_OPS(net, &ops);
2500 2425
2501 /* preallocate control message data and buffer */ 2426 /* preallocate control message data and buffer */
2502 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ); 2427 dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL);
2503 if (!dev->req) 2428 if (!dev->req)
2504 goto fail; 2429 goto fail;
2505 dev->req->complete = eth_setup_complete; 2430 dev->req->complete = eth_setup_complete;
2506 2431
2507 /* ... and maybe likewise for status transfer */ 2432 /* ... and maybe likewise for status transfer */
2433#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2508 if (dev->status_ep) { 2434 if (dev->status_ep) {
2509 dev->stat_req = eth_req_alloc (dev->status_ep, 2435 dev->stat_req = eth_req_alloc (dev->status_ep,
2510 STATUS_BYTECOUNT); 2436 STATUS_BYTECOUNT, GFP_KERNEL);
2511 if (!dev->stat_req) { 2437 if (!dev->stat_req) {
2512 eth_req_free (gadget->ep0, dev->req); 2438 eth_req_free (gadget->ep0, dev->req);
2513 goto fail; 2439 goto fail;
2514 } 2440 }
2441 dev->stat_req->context = NULL;
2515 } 2442 }
2443#endif
2516 2444
2517 /* finish hookup to lower layer ... */ 2445 /* finish hookup to lower layer ... */
2518 dev->gadget = gadget; 2446 dev->gadget = gadget;
@@ -2526,16 +2454,16 @@ autoconf_fail:
2526 netif_stop_queue (dev->net); 2454 netif_stop_queue (dev->net);
2527 netif_carrier_off (dev->net); 2455 netif_carrier_off (dev->net);
2528 2456
2529 // SET_NETDEV_DEV (dev->net, &gadget->dev); 2457 SET_NETDEV_DEV (dev->net, &gadget->dev);
2530 status = register_netdev (dev->net); 2458 status = register_netdev (dev->net);
2531 if (status < 0) 2459 if (status < 0)
2532 goto fail1; 2460 goto fail1;
2533 2461
2534 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 2462 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
2535 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, 2463 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name,
2536 EP_OUT_NAME, EP_IN_NAME, 2464 out_ep->name, in_ep->name,
2537 EP_STATUS_NAME ? " STATUS " : "", 2465 status_ep ? " STATUS " : "",
2538 EP_STATUS_NAME ? EP_STATUS_NAME : "" 2466 status_ep ? status_ep->name : ""
2539 ); 2467 );
2540 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2468 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2541 net->dev_addr [0], net->dev_addr [1], 2469 net->dev_addr [0], net->dev_addr [1],
@@ -2548,7 +2476,6 @@ autoconf_fail:
2548 dev->host_mac [2], dev->host_mac [3], 2476 dev->host_mac [2], dev->host_mac [3],
2549 dev->host_mac [4], dev->host_mac [5]); 2477 dev->host_mac [4], dev->host_mac [5]);
2550 2478
2551#ifdef CONFIG_USB_ETH_RNDIS
2552 if (rndis) { 2479 if (rndis) {
2553 u32 vendorID = 0; 2480 u32 vendorID = 0;
2554 2481
@@ -2565,7 +2492,7 @@ fail0:
2565 /* these set up a lot of the OIDs that RNDIS needs */ 2492 /* these set up a lot of the OIDs that RNDIS needs */
2566 rndis_set_host_mac (dev->rndis_config, dev->host_mac); 2493 rndis_set_host_mac (dev->rndis_config, dev->host_mac);
2567 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2494 if (rndis_set_param_dev (dev->rndis_config, dev->net,
2568 &dev->stats)) 2495 &dev->stats, &dev->cdc_filter))
2569 goto fail0; 2496 goto fail0;
2570 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2497 if (rndis_set_param_vendor (dev->rndis_config, vendorID,
2571 manufacturer)) 2498 manufacturer))
@@ -2576,7 +2503,6 @@ fail0:
2576 goto fail0; 2503 goto fail0;
2577 INFO (dev, "RNDIS ready\n"); 2504 INFO (dev, "RNDIS ready\n");
2578 } 2505 }
2579#endif
2580 2506
2581 return status; 2507 return status;
2582 2508
@@ -2610,11 +2536,8 @@ eth_resume (struct usb_gadget *gadget)
2610/*-------------------------------------------------------------------------*/ 2536/*-------------------------------------------------------------------------*/
2611 2537
2612static struct usb_gadget_driver eth_driver = { 2538static struct usb_gadget_driver eth_driver = {
2613#ifdef CONFIG_USB_GADGET_DUALSPEED 2539 .speed = DEVSPEED,
2614 .speed = USB_SPEED_HIGH, 2540
2615#else
2616 .speed = USB_SPEED_FULL,
2617#endif
2618 .function = (char *) driver_desc, 2541 .function = (char *) driver_desc,
2619 .bind = eth_bind, 2542 .bind = eth_bind,
2620 .unbind = eth_unbind, 2543 .unbind = eth_unbind,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a9be85103d23..4f57085619b4 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -81,6 +81,10 @@
81 * removable Default false, boolean for removable media 81 * removable Default false, boolean for removable media
82 * luns=N Default N = number of filenames, number of 82 * luns=N Default N = number of filenames, number of
83 * LUNs to support 83 * LUNs to support
84 * stall Default determined according to the type of
85 * USB device controller (usually true),
86 * boolean to permit the driver to halt
87 * bulk endpoints
84 * transport=XXX Default BBB, transport name (CB, CBI, or BBB) 88 * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
85 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or 89 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
86 * ATAPI, QIC, UFI, 8070, or SCSI; 90 * ATAPI, QIC, UFI, 8070, or SCSI;
@@ -91,14 +95,10 @@
91 * buflen=N Default N=16384, buffer size used (will be 95 * buflen=N Default N=16384, buffer size used (will be
92 * rounded down to a multiple of 96 * rounded down to a multiple of
93 * PAGE_CACHE_SIZE) 97 * PAGE_CACHE_SIZE)
94 * stall Default determined according to the type of
95 * USB device controller (usually true),
96 * boolean to permit the driver to halt
97 * bulk endpoints
98 * 98 *
99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 99 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro",
100 * "removable", and "luns" options are available; default values are used 100 * "removable", "luns", and "stall" options are available; default values
101 * for everything else. 101 * are used for everything else.
102 * 102 *
103 * The pathnames of the backing files and the ro settings are available in 103 * The pathnames of the backing files and the ro settings are available in
104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the 104 * the attribute files "file" and "ro" in the lun<n> subdirectory of the
@@ -342,14 +342,15 @@ static struct {
342 int num_ros; 342 int num_ros;
343 unsigned int nluns; 343 unsigned int nluns;
344 344
345 int removable;
346 int can_stall;
347
345 char *transport_parm; 348 char *transport_parm;
346 char *protocol_parm; 349 char *protocol_parm;
347 int removable;
348 unsigned short vendor; 350 unsigned short vendor;
349 unsigned short product; 351 unsigned short product;
350 unsigned short release; 352 unsigned short release;
351 unsigned int buflen; 353 unsigned int buflen;
352 int can_stall;
353 354
354 int transport_type; 355 int transport_type;
355 char *transport_name; 356 char *transport_name;
@@ -360,11 +361,11 @@ static struct {
360 .transport_parm = "BBB", 361 .transport_parm = "BBB",
361 .protocol_parm = "SCSI", 362 .protocol_parm = "SCSI",
362 .removable = 0, 363 .removable = 0,
364 .can_stall = 1,
363 .vendor = DRIVER_VENDOR_ID, 365 .vendor = DRIVER_VENDOR_ID,
364 .product = DRIVER_PRODUCT_ID, 366 .product = DRIVER_PRODUCT_ID,
365 .release = 0xffff, // Use controller chip type 367 .release = 0xffff, // Use controller chip type
366 .buflen = 16384, 368 .buflen = 16384,
367 .can_stall = 1,
368 }; 369 };
369 370
370 371
@@ -380,6 +381,9 @@ MODULE_PARM_DESC(luns, "number of LUNs");
380module_param_named(removable, mod_data.removable, bool, S_IRUGO); 381module_param_named(removable, mod_data.removable, bool, S_IRUGO);
381MODULE_PARM_DESC(removable, "true to simulate removable media"); 382MODULE_PARM_DESC(removable, "true to simulate removable media");
382 383
384module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
385MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
386
383 387
384/* In the non-TEST version, only the module parameters listed above 388/* In the non-TEST version, only the module parameters listed above
385 * are available. */ 389 * are available. */
@@ -404,9 +408,6 @@ MODULE_PARM_DESC(release, "USB release number");
404module_param_named(buflen, mod_data.buflen, uint, S_IRUGO); 408module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
405MODULE_PARM_DESC(buflen, "I/O buffer size"); 409MODULE_PARM_DESC(buflen, "I/O buffer size");
406 410
407module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
408MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
409
410#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 411#endif /* CONFIG_USB_FILE_STORAGE_TEST */
411 412
412 413
@@ -818,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val)
818 buf[0] = val >> 24; 819 buf[0] = val >> 24;
819 buf[1] = val >> 16; 820 buf[1] = val >> 16;
820 buf[2] = val >> 8; 821 buf[2] = val >> 8;
821 buf[3] = val; 822 buf[3] = val & 0xff;
822} 823}
823 824
824 825
@@ -1276,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg,
1276{ 1277{
1277 struct usb_request *req = fsg->ep0req; 1278 struct usb_request *req = fsg->ep0req;
1278 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1279 u16 w_index = ctrl->wIndex; 1280 u16 w_index = le16_to_cpu(ctrl->wIndex);
1280 u16 w_length = ctrl->wLength; 1281 u16 w_length = le16_to_cpu(ctrl->wLength);
1281 1282
1282 if (!fsg->config) 1283 if (!fsg->config)
1283 return value; 1284 return value;
@@ -1312,7 +1313,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1312 } 1313 }
1313 VDBG(fsg, "get max LUN\n"); 1314 VDBG(fsg, "get max LUN\n");
1314 *(u8 *) req->buf = fsg->nluns - 1; 1315 *(u8 *) req->buf = fsg->nluns - 1;
1315 value = min(w_length, (u16) 1); 1316 value = 1;
1316 break; 1317 break;
1317 } 1318 }
1318 } 1319 }
@@ -1344,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1344 "unknown class-specific control req " 1345 "unknown class-specific control req "
1345 "%02x.%02x v%04x i%04x l%u\n", 1346 "%02x.%02x v%04x i%04x l%u\n",
1346 ctrl->bRequestType, ctrl->bRequest, 1347 ctrl->bRequestType, ctrl->bRequest,
1347 ctrl->wValue, w_index, w_length); 1348 le16_to_cpu(ctrl->wValue), w_index, w_length);
1348 return value; 1349 return value;
1349} 1350}
1350 1351
@@ -1358,9 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg,
1358{ 1359{
1359 struct usb_request *req = fsg->ep0req; 1360 struct usb_request *req = fsg->ep0req;
1360 int value = -EOPNOTSUPP; 1361 int value = -EOPNOTSUPP;
1361 u16 w_index = ctrl->wIndex; 1362 u16 w_index = le16_to_cpu(ctrl->wIndex);
1362 u16 w_value = ctrl->wValue; 1363 u16 w_value = le16_to_cpu(ctrl->wValue);
1363 u16 w_length = ctrl->wLength;
1364 1364
1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer,
1366 * but config change events will also reconfigure hardware. */ 1366 * but config change events will also reconfigure hardware. */
@@ -1374,7 +1374,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1374 1374
1375 case USB_DT_DEVICE: 1375 case USB_DT_DEVICE:
1376 VDBG(fsg, "get device descriptor\n"); 1376 VDBG(fsg, "get device descriptor\n");
1377 value = min(w_length, (u16) sizeof device_desc); 1377 value = sizeof device_desc;
1378 memcpy(req->buf, &device_desc, value); 1378 memcpy(req->buf, &device_desc, value);
1379 break; 1379 break;
1380#ifdef CONFIG_USB_GADGET_DUALSPEED 1380#ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1382,7 +1382,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1382 VDBG(fsg, "get device qualifier\n"); 1382 VDBG(fsg, "get device qualifier\n");
1383 if (!fsg->gadget->is_dualspeed) 1383 if (!fsg->gadget->is_dualspeed)
1384 break; 1384 break;
1385 value = min(w_length, (u16) sizeof dev_qualifier); 1385 value = sizeof dev_qualifier;
1386 memcpy(req->buf, &dev_qualifier, value); 1386 memcpy(req->buf, &dev_qualifier, value);
1387 break; 1387 break;
1388 1388
@@ -1401,8 +1401,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1401 req->buf, 1401 req->buf,
1402 w_value >> 8, 1402 w_value >> 8,
1403 w_value & 0xff); 1403 w_value & 0xff);
1404 if (value >= 0)
1405 value = min(w_length, (u16) value);
1406 break; 1404 break;
1407 1405
1408 case USB_DT_STRING: 1406 case USB_DT_STRING:
@@ -1411,8 +1409,6 @@ static int standard_setup_req(struct fsg_dev *fsg,
1411 /* wIndex == language code */ 1409 /* wIndex == language code */
1412 value = usb_gadget_get_string(&stringtab, 1410 value = usb_gadget_get_string(&stringtab,
1413 w_value & 0xff, req->buf); 1411 w_value & 0xff, req->buf);
1414 if (value >= 0)
1415 value = min(w_length, (u16) value);
1416 break; 1412 break;
1417 } 1413 }
1418 break; 1414 break;
@@ -1438,7 +1434,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1438 break; 1434 break;
1439 VDBG(fsg, "get configuration\n"); 1435 VDBG(fsg, "get configuration\n");
1440 *(u8 *) req->buf = fsg->config; 1436 *(u8 *) req->buf = fsg->config;
1441 value = min(w_length, (u16) 1); 1437 value = 1;
1442 break; 1438 break;
1443 1439
1444 case USB_REQ_SET_INTERFACE: 1440 case USB_REQ_SET_INTERFACE:
@@ -1466,14 +1462,14 @@ static int standard_setup_req(struct fsg_dev *fsg,
1466 } 1462 }
1467 VDBG(fsg, "get interface\n"); 1463 VDBG(fsg, "get interface\n");
1468 *(u8 *) req->buf = 0; 1464 *(u8 *) req->buf = 0;
1469 value = min(w_length, (u16) 1); 1465 value = 1;
1470 break; 1466 break;
1471 1467
1472 default: 1468 default:
1473 VDBG(fsg, 1469 VDBG(fsg,
1474 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1470 "unknown control req %02x.%02x v%04x i%04x l%u\n",
1475 ctrl->bRequestType, ctrl->bRequest, 1471 ctrl->bRequestType, ctrl->bRequest,
1476 w_value, w_index, w_length); 1472 w_value, w_index, le16_to_cpu(ctrl->wLength));
1477 } 1473 }
1478 1474
1479 return value; 1475 return value;
@@ -1485,6 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1485{ 1481{
1486 struct fsg_dev *fsg = get_gadget_data(gadget); 1482 struct fsg_dev *fsg = get_gadget_data(gadget);
1487 int rc; 1483 int rc;
1484 int w_length = le16_to_cpu(ctrl->wLength);
1488 1485
1489 ++fsg->ep0_req_tag; // Record arrival of a new request 1486 ++fsg->ep0_req_tag; // Record arrival of a new request
1490 fsg->ep0req->context = NULL; 1487 fsg->ep0req->context = NULL;
@@ -1498,9 +1495,9 @@ static int fsg_setup(struct usb_gadget *gadget,
1498 1495
1499 /* Respond with data/status or defer until later? */ 1496 /* Respond with data/status or defer until later? */
1500 if (rc >= 0 && rc != DELAYED_STATUS) { 1497 if (rc >= 0 && rc != DELAYED_STATUS) {
1498 rc = min(rc, w_length);
1501 fsg->ep0req->length = rc; 1499 fsg->ep0req->length = rc;
1502 fsg->ep0req->zero = (rc < ctrl->wLength && 1500 fsg->ep0req->zero = rc < w_length;
1503 (rc % gadget->ep0->maxpacket) == 0);
1504 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1501 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
1505 "ep0-in" : "ep0-out"); 1502 "ep0-in" : "ep0-out");
1506 rc = ep0_queue(fsg); 1503 rc = ep0_queue(fsg);
@@ -2660,7 +2657,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2660 } 2657 }
2661 } 2658 }
2662 2659
2663 /* Check that the LUN values are oonsistent */ 2660 /* Check that the LUN values are consistent */
2664 if (transport_is_bbb()) { 2661 if (transport_is_bbb()) {
2665 if (fsg->lun != lun) 2662 if (fsg->lun != lun)
2666 DBG(fsg, "using LUN %d from CBW, " 2663 DBG(fsg, "using LUN %d from CBW, "
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 005db7cca292..eaab26f4ed37 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -70,7 +70,7 @@ MODULE_LICENSE("GPL");
70 * seem to behave quite as expected. Used by default. 70 * seem to behave quite as expected. Used by default.
71 * 71 *
72 * OUT dma documents design problems handling the common "short packet" 72 * OUT dma documents design problems handling the common "short packet"
73 * transfer termination policy; it couldn't enabled by default, even 73 * transfer termination policy; it couldn't be enabled by default, even
74 * if the OUT-dma abort problems had a resolution. 74 * if the OUT-dma abort problems had a resolution.
75 */ 75 */
76static unsigned use_dma = 1; 76static unsigned use_dma = 1;
@@ -269,7 +269,7 @@ static int goku_ep_disable(struct usb_ep *_ep)
269/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
270 270
271static struct usb_request * 271static struct usb_request *
272goku_alloc_request(struct usb_ep *_ep, int gfp_flags) 272goku_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
273{ 273{
274 struct goku_request *req; 274 struct goku_request *req;
275 275
@@ -313,7 +313,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
313#if defined(CONFIG_X86) 313#if defined(CONFIG_X86)
314#define USE_KMALLOC 314#define USE_KMALLOC
315 315
316#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 316#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
317#define USE_KMALLOC 317#define USE_KMALLOC
318 318
319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 319#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
@@ -327,7 +327,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
327 */ 327 */
328static void * 328static void *
329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
330 dma_addr_t *dma, int gfp_flags) 330 dma_addr_t *dma, unsigned gfp_flags)
331{ 331{
332 void *retval; 332 void *retval;
333 struct goku_ep *ep; 333 struct goku_ep *ep;
@@ -789,7 +789,7 @@ finished:
789/*-------------------------------------------------------------------------*/ 789/*-------------------------------------------------------------------------*/
790 790
791static int 791static int
792goku_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 792goku_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
793{ 793{
794 struct goku_request *req; 794 struct goku_request *req;
795 struct goku_ep *ep; 795 struct goku_ep *ep;
@@ -1524,9 +1524,12 @@ static void ep0_setup(struct goku_udc *dev)
1524 /* read SETUP packet and enter DATA stage */ 1524 /* read SETUP packet and enter DATA stage */
1525 ctrl.bRequestType = readl(&regs->bRequestType); 1525 ctrl.bRequestType = readl(&regs->bRequestType);
1526 ctrl.bRequest = readl(&regs->bRequest); 1526 ctrl.bRequest = readl(&regs->bRequest);
1527 ctrl.wValue = (readl(&regs->wValueH) << 8) | readl(&regs->wValueL); 1527 ctrl.wValue = cpu_to_le16((readl(&regs->wValueH) << 8)
1528 ctrl.wIndex = (readl(&regs->wIndexH) << 8) | readl(&regs->wIndexL); 1528 | readl(&regs->wValueL));
1529 ctrl.wLength = (readl(&regs->wLengthH) << 8) | readl(&regs->wLengthL); 1529 ctrl.wIndex = cpu_to_le16((readl(&regs->wIndexH) << 8)
1530 | readl(&regs->wIndexL));
1531 ctrl.wLength = cpu_to_le16((readl(&regs->wLengthH) << 8)
1532 | readl(&regs->wLengthL));
1530 writel(0, &regs->SetupRecv); 1533 writel(0, &regs->SetupRecv);
1531 1534
1532 nuke(&dev->ep[0], 0); 1535 nuke(&dev->ep[0], 0);
@@ -1548,18 +1551,20 @@ static void ep0_setup(struct goku_udc *dev)
1548 case USB_REQ_CLEAR_FEATURE: 1551 case USB_REQ_CLEAR_FEATURE:
1549 switch (ctrl.bRequestType) { 1552 switch (ctrl.bRequestType) {
1550 case USB_RECIP_ENDPOINT: 1553 case USB_RECIP_ENDPOINT:
1551 tmp = ctrl.wIndex & 0x0f; 1554 tmp = le16_to_cpu(ctrl.wIndex) & 0x0f;
1552 /* active endpoint */ 1555 /* active endpoint */
1553 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1556 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0))
1554 goto stall; 1557 goto stall;
1555 if (ctrl.wIndex & USB_DIR_IN) { 1558 if (ctrl.wIndex & __constant_cpu_to_le16(
1559 USB_DIR_IN)) {
1556 if (!dev->ep[tmp].is_in) 1560 if (!dev->ep[tmp].is_in)
1557 goto stall; 1561 goto stall;
1558 } else { 1562 } else {
1559 if (dev->ep[tmp].is_in) 1563 if (dev->ep[tmp].is_in)
1560 goto stall; 1564 goto stall;
1561 } 1565 }
1562 if (ctrl.wValue != USB_ENDPOINT_HALT) 1566 if (ctrl.wValue != __constant_cpu_to_le16(
1567 USB_ENDPOINT_HALT))
1563 goto stall; 1568 goto stall;
1564 if (tmp) 1569 if (tmp)
1565 goku_clear_halt(&dev->ep[tmp]); 1570 goku_clear_halt(&dev->ep[tmp]);
@@ -1571,7 +1576,7 @@ succeed:
1571 return; 1576 return;
1572 case USB_RECIP_DEVICE: 1577 case USB_RECIP_DEVICE:
1573 /* device remote wakeup: always clear */ 1578 /* device remote wakeup: always clear */
1574 if (ctrl.wValue != 1) 1579 if (ctrl.wValue != __constant_cpu_to_le16(1))
1575 goto stall; 1580 goto stall;
1576 VDBG(dev, "clear dev remote wakeup\n"); 1581 VDBG(dev, "clear dev remote wakeup\n");
1577 goto succeed; 1582 goto succeed;
@@ -1589,14 +1594,15 @@ succeed:
1589#ifdef USB_TRACE 1594#ifdef USB_TRACE
1590 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 1595 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1591 ctrl.bRequestType, ctrl.bRequest, 1596 ctrl.bRequestType, ctrl.bRequest,
1592 ctrl.wValue, ctrl.wIndex, ctrl.wLength); 1597 le16_to_cpu(ctrl.wValue), le16_to_cpu(ctrl.wIndex),
1598 le16_to_cpu(ctrl.wLength));
1593#endif 1599#endif
1594 1600
1595 /* hw wants to know when we're configured (or not) */ 1601 /* hw wants to know when we're configured (or not) */
1596 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1602 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION
1597 && ctrl.bRequestType == USB_RECIP_DEVICE); 1603 && ctrl.bRequestType == USB_RECIP_DEVICE);
1598 if (unlikely(dev->req_config)) 1604 if (unlikely(dev->req_config))
1599 dev->configured = (ctrl.wValue != 0); 1605 dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0));
1600 1606
1601 /* delegate everything to the gadget driver. 1607 /* delegate everything to the gadget driver.
1602 * it may respond after this irq handler returns. 1608 * it may respond after this irq handler returns.
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 1e5e6ddef787..020815397a49 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
417 goto free1; 417 goto free1;
418 418
419 value = ep_io (data, kbuf, len); 419 value = ep_io (data, kbuf, len);
420 VDEBUG (data->dev, "%s read %d OUT, status %d\n", 420 VDEBUG (data->dev, "%s read %zu OUT, status %d\n",
421 data->name, len, value); 421 data->name, len, (int) value);
422 if (value >= 0 && copy_to_user (buf, kbuf, value)) 422 if (value >= 0 && copy_to_user (buf, kbuf, value))
423 value = -EFAULT; 423 value = -EFAULT;
424 424
@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
465 } 465 }
466 466
467 value = ep_io (data, kbuf, len); 467 value = ep_io (data, kbuf, len);
468 VDEBUG (data->dev, "%s write %d IN, status %d\n", 468 VDEBUG (data->dev, "%s write %zu IN, status %d\n",
469 data->name, len, value); 469 data->name, len, (int) value);
470free1: 470free1:
471 up (&data->lock); 471 up (&data->lock);
472 kfree (kbuf); 472 kfree (kbuf);
@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1318 struct usb_request *req = dev->req; 1318 struct usb_request *req = dev->req;
1319 int value = -EOPNOTSUPP; 1319 int value = -EOPNOTSUPP;
1320 struct usb_gadgetfs_event *event; 1320 struct usb_gadgetfs_event *event;
1321 u16 w_value = ctrl->wValue; 1321 u16 w_value = le16_to_cpu(ctrl->wValue);
1322 u16 w_length = ctrl->wLength; 1322 u16 w_length = le16_to_cpu(ctrl->wLength);
1323 1323
1324 spin_lock (&dev->lock); 1324 spin_lock (&dev->lock);
1325 dev->setup_abort = 0; 1325 dev->setup_abort = 0;
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index df75ab65a5ec..4842577789c9 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -1106,7 +1106,7 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1106} 1106}
1107 1107
1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, 1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1109 int gfp_flags) 1109 unsigned gfp_flags)
1110{ 1110{
1111 struct lh7a40x_request *req; 1111 struct lh7a40x_request *req;
1112 1112
@@ -1134,7 +1134,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1134} 1134}
1135 1135
1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes, 1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes,
1137 dma_addr_t * dma, int gfp_flags) 1137 dma_addr_t * dma, unsigned gfp_flags)
1138{ 1138{
1139 char *retval; 1139 char *retval;
1140 1140
@@ -1158,7 +1158,7 @@ static void lh7a40x_free_buffer(struct usb_ep *ep, void *buf, dma_addr_t dma,
1158 * NOTE: Sets INDEX register 1158 * NOTE: Sets INDEX register
1159 */ 1159 */
1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req, 1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1161 int gfp_flags) 1161 unsigned gfp_flags)
1162{ 1162{
1163 struct lh7a40x_request *req; 1163 struct lh7a40x_request *req;
1164 struct lh7a40x_ep *ep; 1164 struct lh7a40x_ep *ep;
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h
index c553bbf68cab..09e3ee4eeae1 100644
--- a/drivers/usb/gadget/ndis.h
+++ b/drivers/usb/gadget/ndis.h
@@ -47,17 +47,17 @@ struct NDIS_PM_WAKE_UP_CAPABILITIES {
47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 47#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004
48 48
49struct NDIS_PNP_CAPABILITIES { 49struct NDIS_PNP_CAPABILITIES {
50 u32 Flags; 50 __le32 Flags;
51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; 51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities;
52}; 52};
53 53
54struct NDIS_PM_PACKET_PATTERN { 54struct NDIS_PM_PACKET_PATTERN {
55 u32 Priority; 55 __le32 Priority;
56 u32 Reserved; 56 __le32 Reserved;
57 u32 MaskSize; 57 __le32 MaskSize;
58 u32 PatternOffset; 58 __le32 PatternOffset;
59 u32 PatternSize; 59 __le32 PatternSize;
60 u32 PatternFlags; 60 __le32 PatternFlags;
61}; 61};
62 62
63 63
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index e47e398daeb5..477fab2e74d1 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -376,7 +376,7 @@ static int net2280_disable (struct usb_ep *_ep)
376/*-------------------------------------------------------------------------*/ 376/*-------------------------------------------------------------------------*/
377 377
378static struct usb_request * 378static struct usb_request *
379net2280_alloc_request (struct usb_ep *_ep, int gfp_flags) 379net2280_alloc_request (struct usb_ep *_ep, unsigned gfp_flags)
380{ 380{
381 struct net2280_ep *ep; 381 struct net2280_ep *ep;
382 struct net2280_request *req; 382 struct net2280_request *req;
@@ -448,7 +448,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 448#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
449#define USE_KMALLOC 449#define USE_KMALLOC
450 450
451#elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 451#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
452#define USE_KMALLOC 452#define USE_KMALLOC
453 453
454/* FIXME there are other cases, including an x86-64 one ... */ 454/* FIXME there are other cases, including an x86-64 one ... */
@@ -463,7 +463,7 @@ net2280_alloc_buffer (
463 struct usb_ep *_ep, 463 struct usb_ep *_ep,
464 unsigned bytes, 464 unsigned bytes,
465 dma_addr_t *dma, 465 dma_addr_t *dma,
466 int gfp_flags 466 unsigned gfp_flags
467) 467)
468{ 468{
469 void *retval; 469 void *retval;
@@ -897,7 +897,7 @@ done (struct net2280_ep *ep, struct net2280_request *req, int status)
897/*-------------------------------------------------------------------------*/ 897/*-------------------------------------------------------------------------*/
898 898
899static int 899static int
900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
901{ 901{
902 struct net2280_request *req; 902 struct net2280_request *req;
903 struct net2280_ep *ep; 903 struct net2280_ep *ep;
@@ -1113,7 +1113,7 @@ static void restart_dma (struct net2280_ep *ep)
1113 if (ep->in_fifo_validate) 1113 if (ep->in_fifo_validate)
1114 dmactl |= (1 << DMA_FIFO_VALIDATE); 1114 dmactl |= (1 << DMA_FIFO_VALIDATE);
1115 list_for_each_entry (entry, &ep->queue, queue) { 1115 list_for_each_entry (entry, &ep->queue, queue) {
1116 u32 dmacount; 1116 __le32 dmacount;
1117 1117
1118 if (entry == req) 1118 if (entry == req)
1119 continue; 1119 continue;
@@ -1238,7 +1238,7 @@ static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
1238 &ep->dma->dmadesc); 1238 &ep->dma->dmadesc);
1239 if (req->td->dmacount & dma_done_ie) 1239 if (req->td->dmacount & dma_done_ie)
1240 writel (readl (&ep->dma->dmacount) 1240 writel (readl (&ep->dma->dmacount)
1241 | dma_done_ie, 1241 | le32_to_cpu(dma_done_ie),
1242 &ep->dma->dmacount); 1242 &ep->dma->dmacount);
1243 } else { 1243 } else {
1244 struct net2280_request *prev; 1244 struct net2280_request *prev;
@@ -1490,7 +1490,7 @@ show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
1490 unsigned long flags; 1490 unsigned long flags;
1491 int i; 1491 int i;
1492 u32 t1, t2; 1492 u32 t1, t2;
1493 char *s; 1493 const char *s;
1494 1494
1495 dev = dev_get_drvdata (_dev); 1495 dev = dev_get_drvdata (_dev);
1496 next = buf; 1496 next = buf;
@@ -1779,6 +1779,9 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1780} 1780}
1781 1781
1782/* just declare this in any driver that really need it */
1783extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1784
1782/** 1785/**
1783 * net2280_set_fifo_mode - change allocation of fifo buffers 1786 * net2280_set_fifo_mode - change allocation of fifo buffers
1784 * @gadget: access to the net2280 device that will be updated 1787 * @gadget: access to the net2280 device that will be updated
@@ -2382,9 +2385,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2382 cpu_to_le32s (&u.raw [0]); 2385 cpu_to_le32s (&u.raw [0]);
2383 cpu_to_le32s (&u.raw [1]); 2386 cpu_to_le32s (&u.raw [1]);
2384 2387
2385 le16_to_cpus (&u.r.wValue); 2388#define w_value le16_to_cpup (&u.r.wValue)
2386 le16_to_cpus (&u.r.wIndex); 2389#define w_index le16_to_cpup (&u.r.wIndex)
2387 le16_to_cpus (&u.r.wLength); 2390#define w_length le16_to_cpup (&u.r.wLength)
2388 2391
2389 /* ack the irq */ 2392 /* ack the irq */
2390 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0); 2393 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0);
@@ -2413,25 +2416,25 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2413 switch (u.r.bRequest) { 2416 switch (u.r.bRequest) {
2414 case USB_REQ_GET_STATUS: { 2417 case USB_REQ_GET_STATUS: {
2415 struct net2280_ep *e; 2418 struct net2280_ep *e;
2416 u16 status; 2419 __le32 status;
2417 2420
2418 /* hw handles device and interface status */ 2421 /* hw handles device and interface status */
2419 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2422 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2420 goto delegate; 2423 goto delegate;
2421 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0 2424 if ((e = get_ep_by_addr (dev, w_index)) == 0
2422 || u.r.wLength > 2) 2425 || w_length > 2)
2423 goto do_stall; 2426 goto do_stall;
2424 2427
2425 if (readl (&e->regs->ep_rsp) 2428 if (readl (&e->regs->ep_rsp)
2426 & (1 << SET_ENDPOINT_HALT)) 2429 & (1 << SET_ENDPOINT_HALT))
2427 status = __constant_cpu_to_le16 (1); 2430 status = __constant_cpu_to_le32 (1);
2428 else 2431 else
2429 status = __constant_cpu_to_le16 (0); 2432 status = __constant_cpu_to_le32 (0);
2430 2433
2431 /* don't bother with a request object! */ 2434 /* don't bother with a request object! */
2432 writel (0, &dev->epregs [0].ep_irqenb); 2435 writel (0, &dev->epregs [0].ep_irqenb);
2433 set_fifo_bytecount (ep, u.r.wLength); 2436 set_fifo_bytecount (ep, w_length);
2434 writel (status, &dev->epregs [0].ep_data); 2437 writel ((__force u32)status, &dev->epregs [0].ep_data);
2435 allow_status (ep); 2438 allow_status (ep);
2436 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status); 2439 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
2437 goto next_endpoints; 2440 goto next_endpoints;
@@ -2443,10 +2446,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2443 /* hw handles device features */ 2446 /* hw handles device features */
2444 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2447 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2445 goto delegate; 2448 goto delegate;
2446 if (u.r.wValue != USB_ENDPOINT_HALT 2449 if (w_value != USB_ENDPOINT_HALT
2447 || u.r.wLength != 0) 2450 || w_length != 0)
2448 goto do_stall; 2451 goto do_stall;
2449 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2452 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2450 goto do_stall; 2453 goto do_stall;
2451 clear_halt (e); 2454 clear_halt (e);
2452 allow_status (ep); 2455 allow_status (ep);
@@ -2460,10 +2463,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2460 /* hw handles device features */ 2463 /* hw handles device features */
2461 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2464 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2462 goto delegate; 2465 goto delegate;
2463 if (u.r.wValue != USB_ENDPOINT_HALT 2466 if (w_value != USB_ENDPOINT_HALT
2464 || u.r.wLength != 0) 2467 || w_length != 0)
2465 goto do_stall; 2468 goto do_stall;
2466 if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2469 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2467 goto do_stall; 2470 goto do_stall;
2468 set_halt (e); 2471 set_halt (e);
2469 allow_status (ep); 2472 allow_status (ep);
@@ -2473,10 +2476,10 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2473 break; 2476 break;
2474 default: 2477 default:
2475delegate: 2478delegate:
2476 VDEBUG (dev, "setup %02x.%02x v%04x i%04x " 2479 VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x"
2477 "ep_cfg %08x\n", 2480 "ep_cfg %08x\n",
2478 u.r.bRequestType, u.r.bRequest, 2481 u.r.bRequestType, u.r.bRequest,
2479 u.r.wValue, u.r.wIndex, 2482 w_value, w_index, w_length,
2480 readl (&ep->regs->ep_cfg)); 2483 readl (&ep->regs->ep_cfg));
2481 spin_unlock (&dev->lock); 2484 spin_unlock (&dev->lock);
2482 tmp = dev->driver->setup (&dev->gadget, &u.r); 2485 tmp = dev->driver->setup (&dev->gadget, &u.r);
@@ -2497,6 +2500,10 @@ do_stall:
2497 */ 2500 */
2498 } 2501 }
2499 2502
2503#undef w_value
2504#undef w_index
2505#undef w_length
2506
2500next_endpoints: 2507next_endpoints:
2501 /* endpoint data irq ? */ 2508 /* endpoint data irq ? */
2502 scratch = stat & 0x7f; 2509 scratch = stat & 0x7f;
@@ -2653,7 +2660,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2653 restart_dma (ep); 2660 restart_dma (ep);
2654 else if (ep->is_in && use_dma_chaining) { 2661 else if (ep->is_in && use_dma_chaining) {
2655 struct net2280_request *req; 2662 struct net2280_request *req;
2656 u32 dmacount; 2663 __le32 dmacount;
2657 2664
2658 /* the descriptor at the head of the chain 2665 /* the descriptor at the head of the chain
2659 * may still have VALID_BIT clear; that's 2666 * may still have VALID_BIT clear; that's
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 98cbcbc16cc1..ff5533e69560 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -52,7 +52,6 @@
52#include <asm/mach-types.h> 52#include <asm/mach-types.h>
53 53
54#include <asm/arch/dma.h> 54#include <asm/arch/dma.h>
55#include <asm/arch/mux.h>
56#include <asm/arch/usb.h> 55#include <asm/arch/usb.h>
57 56
58#include "omap_udc.h" 57#include "omap_udc.h"
@@ -167,7 +166,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
167 maxp = le16_to_cpu (desc->wMaxPacketSize); 166 maxp = le16_to_cpu (desc->wMaxPacketSize);
168 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 167 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
169 && maxp != ep->maxpacket) 168 && maxp != ep->maxpacket)
170 || desc->wMaxPacketSize > ep->maxpacket 169 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket
171 || !desc->wMaxPacketSize) { 170 || !desc->wMaxPacketSize) {
172 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 171 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
173 return -ERANGE; 172 return -ERANGE;
@@ -214,7 +213,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
214 ep->has_dma = 0; 213 ep->has_dma = 0;
215 ep->lch = -1; 214 ep->lch = -1;
216 use_ep(ep, UDC_EP_SEL); 215 use_ep(ep, UDC_EP_SEL);
217 UDC_CTRL_REG = UDC_RESET_EP; 216 UDC_CTRL_REG = udc->clr_halt;
218 ep->ackwait = 0; 217 ep->ackwait = 0;
219 deselect_ep(); 218 deselect_ep();
220 219
@@ -253,7 +252,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
253 } 252 }
254 253
255 spin_lock_irqsave(&ep->udc->lock, flags); 254 spin_lock_irqsave(&ep->udc->lock, flags);
256 ep->desc = 0; 255 ep->desc = NULL;
257 nuke (ep, -ESHUTDOWN); 256 nuke (ep, -ESHUTDOWN);
258 ep->ep.maxpacket = ep->maxpacket; 257 ep->ep.maxpacket = ep->maxpacket;
259 ep->has_dma = 0; 258 ep->has_dma = 0;
@@ -270,7 +269,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
270/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
271 270
272static struct usb_request * 271static struct usb_request *
273omap_alloc_request(struct usb_ep *ep, int gfp_flags) 272omap_alloc_request(struct usb_ep *ep, unsigned gfp_flags)
274{ 273{
275 struct omap_req *req; 274 struct omap_req *req;
276 275
@@ -299,7 +298,7 @@ omap_alloc_buffer(
299 struct usb_ep *_ep, 298 struct usb_ep *_ep,
300 unsigned bytes, 299 unsigned bytes,
301 dma_addr_t *dma, 300 dma_addr_t *dma,
302 int gfp_flags 301 unsigned gfp_flags
303) 302)
304{ 303{
305 void *retval; 304 void *retval;
@@ -388,8 +387,8 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
388 387
389/*-------------------------------------------------------------------------*/ 388/*-------------------------------------------------------------------------*/
390 389
391#define FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) 390#define UDC_FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL)
392#define FIFO_UNWRITABLE (UDC_EP_HALTED | FIFO_FULL) 391#define UDC_FIFO_UNWRITABLE (UDC_EP_HALTED | UDC_FIFO_FULL)
393 392
394#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) 393#define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY)
395#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) 394#define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY)
@@ -433,7 +432,7 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
433 432
434 /* PIO-IN isn't double buffered except for iso */ 433 /* PIO-IN isn't double buffered except for iso */
435 ep_stat = UDC_STAT_FLG_REG; 434 ep_stat = UDC_STAT_FLG_REG;
436 if (ep_stat & FIFO_UNWRITABLE) 435 if (ep_stat & UDC_FIFO_UNWRITABLE)
437 return 0; 436 return 0;
438 437
439 count = ep->ep.maxpacket; 438 count = ep->ep.maxpacket;
@@ -504,7 +503,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
504 if (ep_stat & UDC_EP_HALTED) 503 if (ep_stat & UDC_EP_HALTED)
505 break; 504 break;
506 505
507 if (ep_stat & FIFO_FULL) 506 if (ep_stat & UDC_FIFO_FULL)
508 avail = ep->ep.maxpacket; 507 avail = ep->ep.maxpacket;
509 else { 508 else {
510 avail = UDC_RXFSTAT_REG; 509 avail = UDC_RXFSTAT_REG;
@@ -538,6 +537,32 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
538 537
539/*-------------------------------------------------------------------------*/ 538/*-------------------------------------------------------------------------*/
540 539
540static inline dma_addr_t dma_csac(unsigned lch)
541{
542 dma_addr_t csac;
543
544 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
545 * read before the DMA controller finished disabling the channel.
546 */
547 csac = omap_readw(OMAP_DMA_CSAC(lch));
548 if (csac == 0)
549 csac = omap_readw(OMAP_DMA_CSAC(lch));
550 return csac;
551}
552
553static inline dma_addr_t dma_cdac(unsigned lch)
554{
555 dma_addr_t cdac;
556
557 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
558 * read before the DMA controller finished disabling the channel.
559 */
560 cdac = omap_readw(OMAP_DMA_CDAC(lch));
561 if (cdac == 0)
562 cdac = omap_readw(OMAP_DMA_CDAC(lch));
563 return cdac;
564}
565
541static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 566static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
542{ 567{
543 dma_addr_t end; 568 dma_addr_t end;
@@ -548,7 +573,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
548 if (cpu_is_omap15xx()) 573 if (cpu_is_omap15xx())
549 return 0; 574 return 0;
550 575
551 end = omap_readw(OMAP_DMA_CSAC(ep->lch)); 576 end = dma_csac(ep->lch);
552 if (end == ep->dma_counter) 577 if (end == ep->dma_counter)
553 return 0; 578 return 0;
554 579
@@ -559,14 +584,14 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
559} 584}
560 585
561#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 586#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
562 ? OMAP_DMA_CSAC(x) /* really: CPC */ \ 587 ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \
563 : OMAP_DMA_CDAC(x)) 588 : dma_cdac(x))
564 589
565static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 590static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
566{ 591{
567 dma_addr_t end; 592 dma_addr_t end;
568 593
569 end = omap_readw(DMA_DEST_LAST(ep->lch)); 594 end = DMA_DEST_LAST(ep->lch);
570 if (end == ep->dma_counter) 595 if (end == ep->dma_counter)
571 return 0; 596 return 0;
572 597
@@ -593,7 +618,7 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
593 : OMAP_DMA_SYNC_ELEMENT; 618 : OMAP_DMA_SYNC_ELEMENT;
594 619
595 /* measure length in either bytes or packets */ 620 /* measure length in either bytes or packets */
596 if ((cpu_is_omap16xx() && length <= (UDC_TXN_TSC + 1)) 621 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
597 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 622 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
598 txdma_ctrl = UDC_TXN_EOT | length; 623 txdma_ctrl = UDC_TXN_EOT | length;
599 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 624 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
@@ -602,15 +627,15 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
602 length = min(length / ep->maxpacket, 627 length = min(length / ep->maxpacket,
603 (unsigned) UDC_TXN_TSC + 1); 628 (unsigned) UDC_TXN_TSC + 1);
604 txdma_ctrl = length; 629 txdma_ctrl = length;
605 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 630 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
606 ep->ep.maxpacket, length, sync_mode); 631 ep->ep.maxpacket >> 1, length, sync_mode);
607 length *= ep->maxpacket; 632 length *= ep->maxpacket;
608 } 633 }
609 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 634 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
610 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 635 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
611 636
612 omap_start_dma(ep->lch); 637 omap_start_dma(ep->lch);
613 ep->dma_counter = omap_readw(OMAP_DMA_CSAC(ep->lch)); 638 ep->dma_counter = dma_csac(ep->lch);
614 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 639 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel);
615 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 640 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl;
616 req->dma_bytes = length; 641 req->dma_bytes = length;
@@ -650,12 +675,12 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
650 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 675 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket;
651 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 676 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
652 req->dma_bytes = packets * ep->ep.maxpacket; 677 req->dma_bytes = packets * ep->ep.maxpacket;
653 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 678 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
654 ep->ep.maxpacket, packets, 679 ep->ep.maxpacket >> 1, packets,
655 OMAP_DMA_SYNC_ELEMENT); 680 OMAP_DMA_SYNC_ELEMENT);
656 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 681 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
657 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 682 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual);
658 ep->dma_counter = omap_readw(DMA_DEST_LAST(ep->lch)); 683 ep->dma_counter = DMA_DEST_LAST(ep->lch);
659 684
660 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 685 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1);
661 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); 686 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel);
@@ -763,7 +788,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
763 reg = UDC_TXDMA_CFG_REG; 788 reg = UDC_TXDMA_CFG_REG;
764 else 789 else
765 reg = UDC_RXDMA_CFG_REG; 790 reg = UDC_RXDMA_CFG_REG;
766 reg |= 1 << 12; /* "pulse" activated */ 791 reg |= UDC_DMA_REQ; /* "pulse" activated */
767 792
768 ep->dma_channel = 0; 793 ep->dma_channel = 0;
769 ep->lch = -1; 794 ep->lch = -1;
@@ -787,6 +812,11 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
787 ep->ep.name, dma_error, ep, &ep->lch); 812 ep->ep.name, dma_error, ep, &ep->lch);
788 if (status == 0) { 813 if (status == 0) {
789 UDC_TXDMA_CFG_REG = reg; 814 UDC_TXDMA_CFG_REG = reg;
815 /* EMIFF */
816 omap_set_dma_src_burst_mode(ep->lch,
817 OMAP_DMA_DATA_BURST_4);
818 omap_set_dma_src_data_pack(ep->lch, 1);
819 /* TIPB */
790 omap_set_dma_dest_params(ep->lch, 820 omap_set_dma_dest_params(ep->lch,
791 OMAP_DMA_PORT_TIPB, 821 OMAP_DMA_PORT_TIPB,
792 OMAP_DMA_AMODE_CONSTANT, 822 OMAP_DMA_AMODE_CONSTANT,
@@ -797,10 +827,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
797 ep->ep.name, dma_error, ep, &ep->lch); 827 ep->ep.name, dma_error, ep, &ep->lch);
798 if (status == 0) { 828 if (status == 0) {
799 UDC_RXDMA_CFG_REG = reg; 829 UDC_RXDMA_CFG_REG = reg;
830 /* TIPB */
800 omap_set_dma_src_params(ep->lch, 831 omap_set_dma_src_params(ep->lch,
801 OMAP_DMA_PORT_TIPB, 832 OMAP_DMA_PORT_TIPB,
802 OMAP_DMA_AMODE_CONSTANT, 833 OMAP_DMA_AMODE_CONSTANT,
803 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 834 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG));
835 /* EMIFF */
836 omap_set_dma_dest_burst_mode(ep->lch,
837 OMAP_DMA_DATA_BURST_4);
838 omap_set_dma_dest_data_pack(ep->lch, 1);
804 } 839 }
805 } 840 }
806 if (status) 841 if (status)
@@ -856,7 +891,7 @@ static void dma_channel_release(struct omap_ep *ep)
856 if (!list_empty(&ep->queue)) 891 if (!list_empty(&ep->queue))
857 req = container_of(ep->queue.next, struct omap_req, queue); 892 req = container_of(ep->queue.next, struct omap_req, queue);
858 else 893 else
859 req = 0; 894 req = NULL;
860 895
861 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; 896 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0;
862 897
@@ -865,9 +900,13 @@ static void dma_channel_release(struct omap_ep *ep)
865 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', 900 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r',
866 ep->dma_channel - 1, req); 901 ep->dma_channel - 1, req);
867 902
903 /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before
904 * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them.
905 */
906
868 /* wait till current packet DMA finishes, and fifo empties */ 907 /* wait till current packet DMA finishes, and fifo empties */
869 if (ep->bEndpointAddress & USB_DIR_IN) { 908 if (ep->bEndpointAddress & USB_DIR_IN) {
870 UDC_TXDMA_CFG_REG &= ~mask; 909 UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
871 910
872 if (req) { 911 if (req) {
873 finish_in_dma(ep, req, -ECONNRESET); 912 finish_in_dma(ep, req, -ECONNRESET);
@@ -880,7 +919,7 @@ static void dma_channel_release(struct omap_ep *ep)
880 while (UDC_TXDMA_CFG_REG & mask) 919 while (UDC_TXDMA_CFG_REG & mask)
881 udelay(10); 920 udelay(10);
882 } else { 921 } else {
883 UDC_RXDMA_CFG_REG &= ~mask; 922 UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
884 923
885 /* dma empties the fifo */ 924 /* dma empties the fifo */
886 while (UDC_RXDMA_CFG_REG & mask) 925 while (UDC_RXDMA_CFG_REG & mask)
@@ -898,7 +937,7 @@ static void dma_channel_release(struct omap_ep *ep)
898/*-------------------------------------------------------------------------*/ 937/*-------------------------------------------------------------------------*/
899 938
900static int 939static int
901omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 940omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
902{ 941{
903 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); 942 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
904 struct omap_req *req = container_of(_req, struct omap_req, req); 943 struct omap_req *req = container_of(_req, struct omap_req, req);
@@ -997,18 +1036,19 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
997 UDC_IRQ_EN_REG = irq_en; 1036 UDC_IRQ_EN_REG = irq_en;
998 } 1037 }
999 1038
1000 /* STATUS is reverse direction */ 1039 /* STATUS for zero length DATA stages is
1001 UDC_EP_NUM_REG = is_in 1040 * always an IN ... even for IN transfers,
1002 ? UDC_EP_SEL 1041 * a wierd case which seem to stall OMAP.
1003 : (UDC_EP_SEL|UDC_EP_DIR); 1042 */
1043 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
1004 UDC_CTRL_REG = UDC_CLR_EP; 1044 UDC_CTRL_REG = UDC_CLR_EP;
1005 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1045 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1006 UDC_EP_NUM_REG = udc->ep0_in ? 0 : UDC_EP_DIR; 1046 UDC_EP_NUM_REG = UDC_EP_DIR;
1007 1047
1008 /* cleanup */ 1048 /* cleanup */
1009 udc->ep0_pending = 0; 1049 udc->ep0_pending = 0;
1010 done(ep, req, 0); 1050 done(ep, req, 0);
1011 req = 0; 1051 req = NULL;
1012 1052
1013 /* non-empty DATA stage */ 1053 /* non-empty DATA stage */
1014 } else if (is_in) { 1054 } else if (is_in) {
@@ -1029,7 +1069,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1029 (is_in ? next_in_dma : next_out_dma)(ep, req); 1069 (is_in ? next_in_dma : next_out_dma)(ep, req);
1030 else if (req) { 1070 else if (req) {
1031 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) 1071 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1)
1032 req = 0; 1072 req = NULL;
1033 deselect_ep(); 1073 deselect_ep();
1034 if (!is_in) { 1074 if (!is_in) {
1035 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1075 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1041,7 +1081,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
1041 1081
1042irq_wait: 1082irq_wait:
1043 /* irq handler advances the queue */ 1083 /* irq handler advances the queue */
1044 if (req != 0) 1084 if (req != NULL)
1045 list_add_tail(&req->queue, &ep->queue); 1085 list_add_tail(&req->queue, &ep->queue);
1046 spin_unlock_irqrestore(&udc->lock, flags); 1086 spin_unlock_irqrestore(&udc->lock, flags);
1047 1087
@@ -1140,7 +1180,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1140 dma_channel_claim(ep, channel); 1180 dma_channel_claim(ep, channel);
1141 } else { 1181 } else {
1142 use_ep(ep, 0); 1182 use_ep(ep, 0);
1143 UDC_CTRL_REG = UDC_RESET_EP; 1183 UDC_CTRL_REG = ep->udc->clr_halt;
1144 ep->ackwait = 0; 1184 ep->ackwait = 0;
1145 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1185 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1146 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1186 UDC_CTRL_REG = UDC_SET_FIFO_EN;
@@ -1238,6 +1278,8 @@ static int can_pullup(struct omap_udc *udc)
1238 1278
1239static void pullup_enable(struct omap_udc *udc) 1279static void pullup_enable(struct omap_udc *udc)
1240{ 1280{
1281 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1282 udc->gadget.dev.power.power_state = PMSG_ON;
1241 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1283 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1242#ifndef CONFIG_USB_OTG 1284#ifndef CONFIG_USB_OTG
1243 if (!cpu_is_omap15xx()) 1285 if (!cpu_is_omap15xx())
@@ -1382,7 +1424,7 @@ static void update_otg(struct omap_udc *udc)
1382static void ep0_irq(struct omap_udc *udc, u16 irq_src) 1424static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1383{ 1425{
1384 struct omap_ep *ep0 = &udc->ep[0]; 1426 struct omap_ep *ep0 = &udc->ep[0];
1385 struct omap_req *req = 0; 1427 struct omap_req *req = NULL;
1386 1428
1387 ep0->irqs++; 1429 ep0->irqs++;
1388 1430
@@ -1438,7 +1480,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1438 if (req) 1480 if (req)
1439 done(ep0, req, 0); 1481 done(ep0, req, 0);
1440 } 1482 }
1441 req = 0; 1483 req = NULL;
1442 } else if (stat & UDC_STALL) { 1484 } else if (stat & UDC_STALL) {
1443 UDC_CTRL_REG = UDC_CLR_HALT; 1485 UDC_CTRL_REG = UDC_CLR_HALT;
1444 UDC_EP_NUM_REG = UDC_EP_DIR; 1486 UDC_EP_NUM_REG = UDC_EP_DIR;
@@ -1511,9 +1553,10 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1511 u.word[3] = UDC_DATA_REG; 1553 u.word[3] = UDC_DATA_REG;
1512 UDC_EP_NUM_REG = 0; 1554 UDC_EP_NUM_REG = 0;
1513 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1555 } while (UDC_IRQ_SRC_REG & UDC_SETUP);
1514 le16_to_cpus (&u.r.wValue); 1556
1515 le16_to_cpus (&u.r.wIndex); 1557#define w_value le16_to_cpup (&u.r.wValue)
1516 le16_to_cpus (&u.r.wLength); 1558#define w_index le16_to_cpup (&u.r.wIndex)
1559#define w_length le16_to_cpup (&u.r.wLength)
1517 1560
1518 /* Delegate almost all control requests to the gadget driver, 1561 /* Delegate almost all control requests to the gadget driver,
1519 * except for a handful of ch9 status/feature requests that 1562 * except for a handful of ch9 status/feature requests that
@@ -1529,11 +1572,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1529 /* udc needs to know when ep != 0 is valid */ 1572 /* udc needs to know when ep != 0 is valid */
1530 if (u.r.bRequestType != USB_RECIP_DEVICE) 1573 if (u.r.bRequestType != USB_RECIP_DEVICE)
1531 goto delegate; 1574 goto delegate;
1532 if (u.r.wLength != 0) 1575 if (w_length != 0)
1533 goto do_stall; 1576 goto do_stall;
1534 udc->ep0_set_config = 1; 1577 udc->ep0_set_config = 1;
1535 udc->ep0_reset_config = (u.r.wValue == 0); 1578 udc->ep0_reset_config = (w_value == 0);
1536 VDBG("set config %d\n", u.r.wValue); 1579 VDBG("set config %d\n", w_value);
1537 1580
1538 /* update udc NOW since gadget driver may start 1581 /* update udc NOW since gadget driver may start
1539 * queueing requests immediately; clear config 1582 * queueing requests immediately; clear config
@@ -1549,23 +1592,28 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1549 /* clear endpoint halt */ 1592 /* clear endpoint halt */
1550 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1593 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1551 goto delegate; 1594 goto delegate;
1552 if (u.r.wValue != USB_ENDPOINT_HALT 1595 if (w_value != USB_ENDPOINT_HALT
1553 || u.r.wLength != 0) 1596 || w_length != 0)
1554 goto do_stall; 1597 goto do_stall;
1555 ep = &udc->ep[u.r.wIndex & 0xf]; 1598 ep = &udc->ep[w_index & 0xf];
1556 if (ep != ep0) { 1599 if (ep != ep0) {
1557 if (u.r.wIndex & USB_DIR_IN) 1600 if (w_index & USB_DIR_IN)
1558 ep += 16; 1601 ep += 16;
1559 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1602 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1560 || !ep->desc) 1603 || !ep->desc)
1561 goto do_stall; 1604 goto do_stall;
1562 use_ep(ep, 0); 1605 use_ep(ep, 0);
1563 UDC_CTRL_REG = UDC_RESET_EP; 1606 UDC_CTRL_REG = udc->clr_halt;
1564 ep->ackwait = 0; 1607 ep->ackwait = 0;
1565 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1608 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1566 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1609 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1567 ep->ackwait = 1 + ep->double_buf; 1610 ep->ackwait = 1 + ep->double_buf;
1568 } 1611 }
1612 /* NOTE: assumes the host behaves sanely,
1613 * only clearing real halts. Else we may
1614 * need to kill pending transfers and then
1615 * restart the queue... very messy for DMA!
1616 */
1569 } 1617 }
1570 VDBG("%s halt cleared by host\n", ep->name); 1618 VDBG("%s halt cleared by host\n", ep->name);
1571 goto ep0out_status_stage; 1619 goto ep0out_status_stage;
@@ -1573,11 +1621,11 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1573 /* set endpoint halt */ 1621 /* set endpoint halt */
1574 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1622 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1575 goto delegate; 1623 goto delegate;
1576 if (u.r.wValue != USB_ENDPOINT_HALT 1624 if (w_value != USB_ENDPOINT_HALT
1577 || u.r.wLength != 0) 1625 || w_length != 0)
1578 goto do_stall; 1626 goto do_stall;
1579 ep = &udc->ep[u.r.wIndex & 0xf]; 1627 ep = &udc->ep[w_index & 0xf];
1580 if (u.r.wIndex & USB_DIR_IN) 1628 if (w_index & USB_DIR_IN)
1581 ep += 16; 1629 ep += 16;
1582 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1630 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1583 || ep == ep0 || !ep->desc) 1631 || ep == ep0 || !ep->desc)
@@ -1615,13 +1663,13 @@ ep0out_status_stage:
1615 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1663 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1616 UDC_EP_NUM_REG = UDC_EP_DIR; 1664 UDC_EP_NUM_REG = UDC_EP_DIR;
1617 status = 0; 1665 status = 0;
1618 VDBG("GET_STATUS, interface %d\n", u.r.wIndex); 1666 VDBG("GET_STATUS, interface %d\n", w_index);
1619 /* next, status stage */ 1667 /* next, status stage */
1620 break; 1668 break;
1621 default: 1669 default:
1622delegate: 1670delegate:
1623 /* activate the ep0out fifo right away */ 1671 /* activate the ep0out fifo right away */
1624 if (!udc->ep0_in && u.r.wLength) { 1672 if (!udc->ep0_in && w_length) {
1625 UDC_EP_NUM_REG = 0; 1673 UDC_EP_NUM_REG = 0;
1626 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1674 UDC_CTRL_REG = UDC_SET_FIFO_EN;
1627 } 1675 }
@@ -1632,7 +1680,11 @@ delegate:
1632 */ 1680 */
1633 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", 1681 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n",
1634 u.r.bRequestType, u.r.bRequest, 1682 u.r.bRequestType, u.r.bRequest,
1635 u.r.wValue, u.r.wIndex, u.r.wLength); 1683 w_value, w_index, w_length);
1684
1685#undef w_value
1686#undef w_index
1687#undef w_length
1636 1688
1637 /* The gadget driver may return an error here, 1689 /* The gadget driver may return an error here,
1638 * causing an immediate protocol stall. 1690 * causing an immediate protocol stall.
@@ -2013,7 +2065,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2013 udc->softconnect = 1; 2065 udc->softconnect = 1;
2014 2066
2015 /* hook up the driver */ 2067 /* hook up the driver */
2016 driver->driver.bus = 0; 2068 driver->driver.bus = NULL;
2017 udc->driver = driver; 2069 udc->driver = driver;
2018 udc->gadget.dev.driver = &driver->driver; 2070 udc->gadget.dev.driver = &driver->driver;
2019 spin_unlock_irqrestore(&udc->lock, flags); 2071 spin_unlock_irqrestore(&udc->lock, flags);
@@ -2021,8 +2073,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2021 status = driver->bind (&udc->gadget); 2073 status = driver->bind (&udc->gadget);
2022 if (status) { 2074 if (status) {
2023 DBG("bind to %s --> %d\n", driver->driver.name, status); 2075 DBG("bind to %s --> %d\n", driver->driver.name, status);
2024 udc->gadget.dev.driver = 0; 2076 udc->gadget.dev.driver = NULL;
2025 udc->driver = 0; 2077 udc->driver = NULL;
2026 goto done; 2078 goto done;
2027 } 2079 }
2028 DBG("bound to driver %s\n", driver->driver.name); 2080 DBG("bound to driver %s\n", driver->driver.name);
@@ -2035,8 +2087,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2035 if (status < 0) { 2087 if (status < 0) {
2036 ERR("can't bind to transceiver\n"); 2088 ERR("can't bind to transceiver\n");
2037 driver->unbind (&udc->gadget); 2089 driver->unbind (&udc->gadget);
2038 udc->gadget.dev.driver = 0; 2090 udc->gadget.dev.driver = NULL;
2039 udc->driver = 0; 2091 udc->driver = NULL;
2040 goto done; 2092 goto done;
2041 } 2093 }
2042 } else { 2094 } else {
@@ -2071,7 +2123,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2071 omap_vbus_session(&udc->gadget, 0); 2123 omap_vbus_session(&udc->gadget, 0);
2072 2124
2073 if (udc->transceiver) 2125 if (udc->transceiver)
2074 (void) otg_set_peripheral(udc->transceiver, 0); 2126 (void) otg_set_peripheral(udc->transceiver, NULL);
2075 else 2127 else
2076 pullup_disable(udc); 2128 pullup_disable(udc);
2077 2129
@@ -2080,9 +2132,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2080 spin_unlock_irqrestore(&udc->lock, flags); 2132 spin_unlock_irqrestore(&udc->lock, flags);
2081 2133
2082 driver->unbind(&udc->gadget); 2134 driver->unbind(&udc->gadget);
2083 udc->gadget.dev.driver = 0; 2135 udc->gadget.dev.driver = NULL;
2084 udc->driver = 0; 2136 udc->driver = NULL;
2085
2086 2137
2087 DBG("unregistered driver '%s'\n", driver->driver.name); 2138 DBG("unregistered driver '%s'\n", driver->driver.name);
2088 return status; 2139 return status;
@@ -2178,14 +2229,14 @@ static int proc_otg_show(struct seq_file *s)
2178 2229
2179 tmp = OTG_REV_REG; 2230 tmp = OTG_REV_REG;
2180 trans = USB_TRANSCEIVER_CTRL_REG; 2231 trans = USB_TRANSCEIVER_CTRL_REG;
2181 seq_printf(s, "OTG rev %d.%d, transceiver_ctrl %03x\n", 2232 seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n",
2182 tmp >> 4, tmp & 0xf, trans); 2233 tmp >> 4, tmp & 0xf, trans);
2183 tmp = OTG_SYSCON_1_REG; 2234 tmp = OTG_SYSCON_1_REG;
2184 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2235 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
2185 FOURBITS "\n", tmp, 2236 FOURBITS "\n", tmp,
2186 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2237 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R),
2187 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), 2238 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R),
2188 (USB0_TRX_MODE(tmp) == 0) 2239 (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710())
2189 ? "internal" 2240 ? "internal"
2190 : trx_mode(USB0_TRX_MODE(tmp), 1), 2241 : trx_mode(USB0_TRX_MODE(tmp), 1),
2191 (tmp & OTG_IDLE_EN) ? " !otg" : "", 2242 (tmp & OTG_IDLE_EN) ? " !otg" : "",
@@ -2235,6 +2286,7 @@ static int proc_otg_show(struct seq_file *s)
2235 seq_printf(s, "otg_outctrl %04x" "\n", tmp); 2286 seq_printf(s, "otg_outctrl %04x" "\n", tmp);
2236 tmp = OTG_TEST_REG; 2287 tmp = OTG_TEST_REG;
2237 seq_printf(s, "otg_test %04x" "\n", tmp); 2288 seq_printf(s, "otg_test %04x" "\n", tmp);
2289 return 0;
2238} 2290}
2239 2291
2240static int proc_udc_show(struct seq_file *s, void *_) 2292static int proc_udc_show(struct seq_file *s, void *_)
@@ -2378,7 +2430,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2378 2430
2379static int proc_udc_open(struct inode *inode, struct file *file) 2431static int proc_udc_open(struct inode *inode, struct file *file)
2380{ 2432{
2381 return single_open(file, proc_udc_show, 0); 2433 return single_open(file, proc_udc_show, NULL);
2382} 2434}
2383 2435
2384static struct file_operations proc_ops = { 2436static struct file_operations proc_ops = {
@@ -2399,7 +2451,7 @@ static void create_proc_file(void)
2399 2451
2400static void remove_proc_file(void) 2452static void remove_proc_file(void)
2401{ 2453{
2402 remove_proc_entry(proc_filename, 0); 2454 remove_proc_entry(proc_filename, NULL);
2403} 2455}
2404 2456
2405#else 2457#else
@@ -2414,6 +2466,10 @@ static inline void remove_proc_file(void) {}
2414/* Before this controller can enumerate, we need to pick an endpoint 2466/* Before this controller can enumerate, we need to pick an endpoint
2415 * configuration, or "fifo_mode" That involves allocating 2KB of packet 2467 * configuration, or "fifo_mode" That involves allocating 2KB of packet
2416 * buffer space among the endpoints we'll be operating. 2468 * buffer space among the endpoints we'll be operating.
2469 *
2470 * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when
2471 * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that
2472 * capability yet though.
2417 */ 2473 */
2418static unsigned __init 2474static unsigned __init
2419omap_ep_setup(char *name, u8 addr, u8 type, 2475omap_ep_setup(char *name, u8 addr, u8 type,
@@ -2505,7 +2561,7 @@ static void omap_udc_release(struct device *dev)
2505{ 2561{
2506 complete(udc->done); 2562 complete(udc->done);
2507 kfree (udc); 2563 kfree (udc);
2508 udc = 0; 2564 udc = NULL;
2509} 2565}
2510 2566
2511static int __init 2567static int __init
@@ -2577,23 +2633,33 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2577 case 1: 2633 case 1:
2578 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); 2634 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1);
2579 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); 2635 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2);
2636 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2637
2580 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3); 2638 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3);
2581 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); 2639 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4);
2640 OMAP_INT_EP("ep10in", USB_DIR_IN | 10, 16);
2582 2641
2583 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5); 2642 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5);
2584 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); 2643 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5);
2644 OMAP_INT_EP("ep11in", USB_DIR_IN | 11, 16);
2645
2585 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); 2646 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6);
2586 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); 2647 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6);
2648 OMAP_INT_EP("ep12in", USB_DIR_IN | 12, 16);
2587 2649
2588 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7); 2650 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7);
2589 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); 2651 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7);
2652 OMAP_INT_EP("ep13in", USB_DIR_IN | 13, 16);
2653 OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16);
2654
2590 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8); 2655 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8);
2591 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); 2656 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8);
2657 OMAP_INT_EP("ep14in", USB_DIR_IN | 14, 16);
2658 OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16);
2659
2660 OMAP_BULK_EP("ep15in", USB_DIR_IN | 15);
2661 OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15);
2592 2662
2593 OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16);
2594 OMAP_INT_EP("ep10out", USB_DIR_IN | 10, 16);
2595 OMAP_INT_EP("ep11in", USB_DIR_IN | 9, 16);
2596 OMAP_INT_EP("ep12out", USB_DIR_IN | 10, 16);
2597 break; 2663 break;
2598 2664
2599#ifdef USE_ISO 2665#ifdef USE_ISO
@@ -2640,8 +2706,8 @@ static int __init omap_udc_probe(struct device *dev)
2640 struct platform_device *odev = to_platform_device(dev); 2706 struct platform_device *odev = to_platform_device(dev);
2641 int status = -ENODEV; 2707 int status = -ENODEV;
2642 int hmc; 2708 int hmc;
2643 struct otg_transceiver *xceiv = 0; 2709 struct otg_transceiver *xceiv = NULL;
2644 const char *type = 0; 2710 const char *type = NULL;
2645 struct omap_usb_config *config = dev->platform_data; 2711 struct omap_usb_config *config = dev->platform_data;
2646 2712
2647 /* NOTE: "knows" the order of the resources! */ 2713 /* NOTE: "knows" the order of the resources! */
@@ -2676,54 +2742,78 @@ static int __init omap_udc_probe(struct device *dev)
2676 FUNC_MUX_CTRL_0_REG = tmp; 2742 FUNC_MUX_CTRL_0_REG = tmp;
2677 } 2743 }
2678 } else { 2744 } else {
2745 /* The transceiver may package some GPIO logic or handle
2746 * loopback and/or transceiverless setup; if we find one,
2747 * use it. Except for OTG, we don't _need_ to talk to one;
2748 * but not having one probably means no VBUS detection.
2749 */
2750 xceiv = otg_get_transceiver();
2751 if (xceiv)
2752 type = xceiv->label;
2753 else if (config->otg) {
2754 DBG("OTG requires external transceiver!\n");
2755 goto cleanup0;
2756 }
2757
2679 hmc = HMC_1610; 2758 hmc = HMC_1610;
2680 switch (hmc) { 2759 switch (hmc) {
2760 case 0: /* POWERUP DEFAULT == 0 */
2761 case 4:
2762 case 12:
2763 case 20:
2764 if (!cpu_is_omap1710()) {
2765 type = "integrated";
2766 break;
2767 }
2768 /* FALL THROUGH */
2681 case 3: 2769 case 3:
2682 case 11: 2770 case 11:
2683 case 16: 2771 case 16:
2684 case 19: 2772 case 19:
2685 case 25: 2773 case 25:
2686 xceiv = otg_get_transceiver();
2687 if (!xceiv) { 2774 if (!xceiv) {
2688 DBG("external transceiver not registered!\n"); 2775 DBG("external transceiver not registered!\n");
2689 if (config->otg) 2776 type = "unknown";
2690 goto cleanup0; 2777 }
2691 type = "(unknown external)";
2692 } else
2693 type = xceiv->label;
2694 break;
2695 case 0: /* POWERUP DEFAULT == 0 */
2696 case 4:
2697 case 12:
2698 case 20:
2699 type = "INTEGRATED";
2700 break; 2778 break;
2701 case 21: /* internal loopback */ 2779 case 21: /* internal loopback */
2702 type = "(loopback)"; 2780 type = "loopback";
2703 break; 2781 break;
2704 case 14: /* transceiverless */ 2782 case 14: /* transceiverless */
2705 type = "(none)"; 2783 if (cpu_is_omap1710())
2784 goto bad_on_1710;
2785 /* FALL THROUGH */
2786 case 13:
2787 case 15:
2788 type = "no";
2706 break; 2789 break;
2707 2790
2708 default: 2791 default:
2792bad_on_1710:
2709 ERR("unrecognized UDC HMC mode %d\n", hmc); 2793 ERR("unrecognized UDC HMC mode %d\n", hmc);
2710 return -ENODEV; 2794 goto cleanup0;
2711 } 2795 }
2712 } 2796 }
2713 INFO("hmc mode %d, transceiver %s\n", hmc, type); 2797 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2714 2798
2715 /* a "gadget" abstracts/virtualizes the controller */ 2799 /* a "gadget" abstracts/virtualizes the controller */
2716 status = omap_udc_setup(odev, xceiv); 2800 status = omap_udc_setup(odev, xceiv);
2717 if (status) { 2801 if (status) {
2718 goto cleanup0; 2802 goto cleanup0;
2719 } 2803 }
2720 xceiv = 0; 2804 xceiv = NULL;
2721 // "udc" is now valid 2805 // "udc" is now valid
2722 pullup_disable(udc); 2806 pullup_disable(udc);
2723#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2807#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
2724 udc->gadget.is_otg = (config->otg != 0); 2808 udc->gadget.is_otg = (config->otg != 0);
2725#endif 2809#endif
2726 2810
2811 /* starting with omap1710 es2.0, clear toggle is a separate bit */
2812 if (UDC_REV_REG >= 0x61)
2813 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE;
2814 else
2815 udc->clr_halt = UDC_RESET_EP;
2816
2727 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2817 /* USB general purpose IRQ: ep0, state changes, dma, etc */
2728 status = request_irq(odev->resource[1].start, omap_udc_irq, 2818 status = request_irq(odev->resource[1].start, omap_udc_irq,
2729 SA_SAMPLE_RANDOM, driver_name, udc); 2819 SA_SAMPLE_RANDOM, driver_name, udc);
@@ -2765,7 +2855,7 @@ cleanup2:
2765 2855
2766cleanup1: 2856cleanup1:
2767 kfree (udc); 2857 kfree (udc);
2768 udc = 0; 2858 udc = NULL;
2769 2859
2770cleanup0: 2860cleanup0:
2771 if (xceiv) 2861 if (xceiv)
@@ -2788,7 +2878,7 @@ static int __exit omap_udc_remove(struct device *dev)
2788 pullup_disable(udc); 2878 pullup_disable(udc);
2789 if (udc->transceiver) { 2879 if (udc->transceiver) {
2790 put_device(udc->transceiver->dev); 2880 put_device(udc->transceiver->dev);
2791 udc->transceiver = 0; 2881 udc->transceiver = NULL;
2792 } 2882 }
2793 UDC_SYSCON1_REG = 0; 2883 UDC_SYSCON1_REG = 0;
2794 2884
@@ -2809,13 +2899,33 @@ static int __exit omap_udc_remove(struct device *dev)
2809 return 0; 2899 return 0;
2810} 2900}
2811 2901
2812static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level) 2902/* suspend/resume/wakeup from sysfs (echo > power/state) or when the
2903 * system is forced into deep sleep
2904 *
2905 * REVISIT we should probably reject suspend requests when there's a host
2906 * session active, rather than disconnecting, at least on boards that can
2907 * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT). And in any case, we need to
2908 * make host resumes and VBUS detection trigger OMAP wakeup events; that
2909 * may involve talking to an external transceiver (e.g. isp1301).
2910 */
2911
2912static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
2813{ 2913{
2814 if (level != 0) 2914 u32 devstat;
2915
2916 if (level != SUSPEND_POWER_DOWN)
2815 return 0; 2917 return 0;
2918 devstat = UDC_DEVSTAT_REG;
2919
2920 /* we're requesting 48 MHz clock if the pullup is enabled
2921 * (== we're attached to the host) and we're not suspended,
2922 * which would prevent entry to deep sleep...
2923 */
2924 if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) {
2925 WARN("session active; suspend requires disconnect\n");
2926 omap_pullup(&udc->gadget, 0);
2927 }
2816 2928
2817 DBG("suspend, state %d\n", state);
2818 omap_pullup(&udc->gadget, 0);
2819 udc->gadget.dev.power.power_state = PMSG_SUSPEND; 2929 udc->gadget.dev.power.power_state = PMSG_SUSPEND;
2820 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND; 2930 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND;
2821 return 0; 2931 return 0;
@@ -2823,12 +2933,10 @@ static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level)
2823 2933
2824static int omap_udc_resume(struct device *dev, u32 level) 2934static int omap_udc_resume(struct device *dev, u32 level)
2825{ 2935{
2826 if (level != 0) 2936 if (level != RESUME_POWER_ON)
2827 return 0; 2937 return 0;
2828 2938
2829 DBG("resume + wakeup/SRP\n"); 2939 DBG("resume + wakeup/SRP\n");
2830 udc->gadget.dev.parent->power.power_state = PMSG_ON;
2831 udc->gadget.dev.power.power_state = PMSG_ON;
2832 omap_pullup(&udc->gadget, 1); 2940 omap_pullup(&udc->gadget, 1);
2833 2941
2834 /* maybe the host would enumerate us if we nudged it */ 2942 /* maybe the host would enumerate us if we nudged it */
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index c9e68541622c..652ee4627344 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -20,6 +20,7 @@
20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */
21# define UDC_CLR_HALT (1 << 7) 21# define UDC_CLR_HALT (1 << 7)
22# define UDC_SET_HALT (1 << 6) 22# define UDC_SET_HALT (1 << 6)
23# define UDC_CLRDATA_TOGGLE (1 << 3)
23# define UDC_SET_FIFO_EN (1 << 2) 24# define UDC_SET_FIFO_EN (1 << 2)
24# define UDC_CLR_EP (1 << 1) 25# define UDC_CLR_EP (1 << 1)
25# define UDC_RESET_EP (1 << 0) 26# define UDC_RESET_EP (1 << 0)
@@ -99,6 +100,7 @@
99 100
100/* DMA configuration registers: up to three channels in each direction. */ 101/* DMA configuration registers: up to three channels in each direction. */
101#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 102#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */
103# define UDC_DMA_REQ (1 << 12)
102#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 104#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */
103#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 105#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */
104 106
@@ -162,6 +164,7 @@ struct omap_udc {
162 spinlock_t lock; 164 spinlock_t lock;
163 struct omap_ep ep[32]; 165 struct omap_ep ep[32];
164 u16 devstat; 166 u16 devstat;
167 u16 clr_halt;
165 struct otg_transceiver *transceiver; 168 struct otg_transceiver *transceiver;
166 struct list_head iso; 169 struct list_head iso;
167 unsigned softconnect:1; 170 unsigned softconnect:1;
@@ -171,7 +174,6 @@ struct omap_udc {
171 unsigned ep0_set_config:1; 174 unsigned ep0_set_config:1;
172 unsigned ep0_reset_config:1; 175 unsigned ep0_reset_config:1;
173 unsigned ep0_setup:1; 176 unsigned ep0_setup:1;
174
175 struct completion *done; 177 struct completion *done;
176}; 178};
177 179
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index b8b4524ed746..1507738337c4 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * linux/drivers/usb/gadget/pxa2xx_udc.c 2 * linux/drivers/usb/gadget/pxa2xx_udc.c
3 * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers 3 * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
4 * 4 *
5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker) 5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
6 * Copyright (C) 2003 Robert Schwebel, Pengutronix 6 * Copyright (C) 2003 Robert Schwebel, Pengutronix
@@ -63,7 +63,7 @@
63 63
64 64
65/* 65/*
66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 2xx 66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
67 * series processors. The UDC for the IXP 4xx series is very similar. 67 * series processors. The UDC for the IXP 4xx series is very similar.
68 * There are fifteen endpoints, in addition to ep0. 68 * There are fifteen endpoints, in addition to ep0.
69 * 69 *
@@ -79,8 +79,8 @@
79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there. 79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
80 */ 80 */
81 81
82#define DRIVER_VERSION "14-Dec-2003" 82#define DRIVER_VERSION "4-May-2005"
83#define DRIVER_DESC "PXA 2xx USB Device Controller driver" 83#define DRIVER_DESC "PXA 25x USB Device Controller driver"
84 84
85 85
86static const char driver_name [] = "pxa2xx_udc"; 86static const char driver_name [] = "pxa2xx_udc";
@@ -290,6 +290,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
290static int pxa2xx_ep_disable (struct usb_ep *_ep) 290static int pxa2xx_ep_disable (struct usb_ep *_ep)
291{ 291{
292 struct pxa2xx_ep *ep; 292 struct pxa2xx_ep *ep;
293 unsigned long flags;
293 294
294 ep = container_of (_ep, struct pxa2xx_ep, ep); 295 ep = container_of (_ep, struct pxa2xx_ep, ep);
295 if (!_ep || !ep->desc) { 296 if (!_ep || !ep->desc) {
@@ -297,6 +298,8 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
297 _ep ? ep->ep.name : NULL); 298 _ep ? ep->ep.name : NULL);
298 return -EINVAL; 299 return -EINVAL;
299 } 300 }
301 local_irq_save(flags);
302
300 nuke (ep, -ESHUTDOWN); 303 nuke (ep, -ESHUTDOWN);
301 304
302#ifdef USE_DMA 305#ifdef USE_DMA
@@ -313,6 +316,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
313 ep->desc = NULL; 316 ep->desc = NULL;
314 ep->stopped = 1; 317 ep->stopped = 1;
315 318
319 local_irq_restore(flags);
316 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name); 320 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
317 return 0; 321 return 0;
318} 322}
@@ -328,7 +332,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
328 * pxa2xx_ep_alloc_request - allocate a request data structure 332 * pxa2xx_ep_alloc_request - allocate a request data structure
329 */ 333 */
330static struct usb_request * 334static struct usb_request *
331pxa2xx_ep_alloc_request (struct usb_ep *_ep, int gfp_flags) 335pxa2xx_ep_alloc_request (struct usb_ep *_ep, unsigned gfp_flags)
332{ 336{
333 struct pxa2xx_request *req; 337 struct pxa2xx_request *req;
334 338
@@ -363,7 +367,7 @@ pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
363 */ 367 */
364static void * 368static void *
365pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 369pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
366 dma_addr_t *dma, int gfp_flags) 370 dma_addr_t *dma, unsigned gfp_flags)
367{ 371{
368 char *retval; 372 char *retval;
369 373
@@ -870,7 +874,7 @@ done:
870/*-------------------------------------------------------------------------*/ 874/*-------------------------------------------------------------------------*/
871 875
872static int 876static int
873pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 877pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
874{ 878{
875 struct pxa2xx_request *req; 879 struct pxa2xx_request *req;
876 struct pxa2xx_ep *ep; 880 struct pxa2xx_ep *ep;
@@ -971,10 +975,10 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
971 kick_dma(ep, req); 975 kick_dma(ep, req);
972#endif 976#endif
973 /* can the FIFO can satisfy the request immediately? */ 977 /* can the FIFO can satisfy the request immediately? */
974 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0 978 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
975 && (*ep->reg_udccs & UDCCS_BI_TFS) != 0 979 if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
976 && write_fifo(ep, req)) { 980 && write_fifo(ep, req))
977 req = NULL; 981 req = NULL;
978 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0 982 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
979 && read_fifo(ep, req)) { 983 && read_fifo(ep, req)) {
980 req = NULL; 984 req = NULL;
@@ -1290,7 +1294,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1290 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1294 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1291 driver_name, DRIVER_VERSION SIZE_STR DMASTR, 1295 driver_name, DRIVER_VERSION SIZE_STR DMASTR,
1292 dev->driver ? dev->driver->driver.name : "(none)", 1296 dev->driver ? dev->driver->driver.name : "(none)",
1293 is_usb_connected() ? "full speed" : "disconnected"); 1297 is_vbus_present() ? "full speed" : "disconnected");
1294 size -= t; 1298 size -= t;
1295 next += t; 1299 next += t;
1296 1300
@@ -1339,7 +1343,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1339 next += t; 1343 next += t;
1340 } 1344 }
1341 1345
1342 if (!is_usb_connected() || !dev->driver) 1346 if (!is_vbus_present() || !dev->driver)
1343 goto done; 1347 goto done;
1344 1348
1345 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1349 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
@@ -1454,7 +1458,7 @@ static void udc_disable(struct pxa2xx_udc *dev)
1454 UFNRH = UFNRH_SIM; 1458 UFNRH = UFNRH_SIM;
1455 1459
1456 /* if hardware supports it, disconnect from usb */ 1460 /* if hardware supports it, disconnect from usb */
1457 make_usb_disappear(); 1461 pullup_off();
1458 1462
1459 udc_clear_mask_UDCCR(UDCCR_UDE); 1463 udc_clear_mask_UDCCR(UDCCR_UDE);
1460 1464
@@ -1567,7 +1571,7 @@ static void udc_enable (struct pxa2xx_udc *dev)
1567 UICR0 &= ~UICR0_IM0; 1571 UICR0 &= ~UICR0_IM0;
1568 1572
1569 /* if hardware supports it, pullup D+ and wait for reset */ 1573 /* if hardware supports it, pullup D+ and wait for reset */
1570 let_usb_appear(); 1574 pullup_on();
1571} 1575}
1572 1576
1573 1577
@@ -2052,10 +2056,10 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2052 if (unlikely(udccr & UDCCR_SUSIR)) { 2056 if (unlikely(udccr & UDCCR_SUSIR)) {
2053 udc_ack_int_UDCCR(UDCCR_SUSIR); 2057 udc_ack_int_UDCCR(UDCCR_SUSIR);
2054 handled = 1; 2058 handled = 1;
2055 DBG(DBG_VERBOSE, "USB suspend%s\n", is_usb_connected() 2059 DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
2056 ? "" : "+disconnect"); 2060 ? "" : "+disconnect");
2057 2061
2058 if (!is_usb_connected()) 2062 if (!is_vbus_present())
2059 stop_activity(dev, dev->driver); 2063 stop_activity(dev, dev->driver);
2060 else if (dev->gadget.speed != USB_SPEED_UNKNOWN 2064 else if (dev->gadget.speed != USB_SPEED_UNKNOWN
2061 && dev->driver 2065 && dev->driver
@@ -2073,7 +2077,7 @@ pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2073 if (dev->gadget.speed != USB_SPEED_UNKNOWN 2077 if (dev->gadget.speed != USB_SPEED_UNKNOWN
2074 && dev->driver 2078 && dev->driver
2075 && dev->driver->resume 2079 && dev->driver->resume
2076 && is_usb_connected()) 2080 && is_vbus_present())
2077 dev->driver->resume(&dev->gadget); 2081 dev->driver->resume(&dev->gadget);
2078 } 2082 }
2079 2083
@@ -2509,7 +2513,7 @@ static int __init pxa2xx_udc_probe(struct device *_dev)
2509 udc_disable(dev); 2513 udc_disable(dev);
2510 udc_reinit(dev); 2514 udc_reinit(dev);
2511 2515
2512 dev->vbus = is_usb_connected(); 2516 dev->vbus = is_vbus_present();
2513 2517
2514 /* irq setup after old hardware state is cleaned up */ 2518 /* irq setup after old hardware state is cleaned up */
2515 retval = request_irq(IRQ_USB, pxa2xx_udc_irq, 2519 retval = request_irq(IRQ_USB, pxa2xx_udc_irq,
@@ -2555,6 +2559,12 @@ lubbock_fail0:
2555 2559
2556 return 0; 2560 return 0;
2557} 2561}
2562
2563static void pxa2xx_udc_shutdown(struct device *_dev)
2564{
2565 pullup_off();
2566}
2567
2558static int __exit pxa2xx_udc_remove(struct device *_dev) 2568static int __exit pxa2xx_udc_remove(struct device *_dev)
2559{ 2569{
2560 struct pxa2xx_udc *dev = dev_get_drvdata(_dev); 2570 struct pxa2xx_udc *dev = dev_get_drvdata(_dev);
@@ -2624,6 +2634,7 @@ static struct device_driver udc_driver = {
2624 .name = "pxa2xx-udc", 2634 .name = "pxa2xx-udc",
2625 .bus = &platform_bus_type, 2635 .bus = &platform_bus_type,
2626 .probe = pxa2xx_udc_probe, 2636 .probe = pxa2xx_udc_probe,
2637 .shutdown = pxa2xx_udc_shutdown,
2627 .remove = __exit_p(pxa2xx_udc_remove), 2638 .remove = __exit_p(pxa2xx_udc_remove),
2628 .suspend = pxa2xx_udc_suspend, 2639 .suspend = pxa2xx_udc_suspend,
2629 .resume = pxa2xx_udc_resume, 2640 .resume = pxa2xx_udc_resume,
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 1f3a7d999da7..d0bc396a85d5 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,23 +177,23 @@ struct pxa2xx_udc {
177 177
178static struct pxa2xx_udc *the_controller; 178static struct pxa2xx_udc *the_controller;
179 179
180/* one GPIO should be used to detect host disconnect */ 180/* one GPIO should be used to detect VBUS from the host */
181static inline int is_usb_connected(void) 181static inline int is_vbus_present(void)
182{ 182{
183 if (!the_controller->mach->udc_is_connected) 183 if (!the_controller->mach->udc_is_connected)
184 return 1; 184 return 1;
185 return the_controller->mach->udc_is_connected(); 185 return the_controller->mach->udc_is_connected();
186} 186}
187 187
188/* one GPIO should force the host to see this device (or not) */ 188/* one GPIO should control a D+ pullup, so host sees this device (or not) */
189static inline void make_usb_disappear(void) 189static inline void pullup_off(void)
190{ 190{
191 if (!the_controller->mach->udc_command) 191 if (!the_controller->mach->udc_command)
192 return; 192 return;
193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
194} 194}
195 195
196static inline void let_usb_appear(void) 196static inline void pullup_on(void)
197{ 197{
198 if (!the_controller->mach->udc_command) 198 if (!the_controller->mach->udc_command)
199 return; 199 return;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 7457268d5f28..06b6eba925b5 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -41,6 +41,7 @@
41 41
42 42
43#undef RNDIS_PM 43#undef RNDIS_PM
44#undef RNDIS_WAKEUP
44#undef VERBOSE 45#undef VERBOSE
45 46
46#include "rndis.h" 47#include "rndis.h"
@@ -60,7 +61,7 @@
60 } while (0) 61 } while (0)
61static int rndis_debug = 0; 62static int rndis_debug = 0;
62 63
63module_param (rndis_debug, bool, 0); 64module_param (rndis_debug, int, 0);
64MODULE_PARM_DESC (rndis_debug, "enable debugging"); 65MODULE_PARM_DESC (rndis_debug, "enable debugging");
65 66
66#else 67#else
@@ -78,22 +79,103 @@ static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
78static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 79static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
79 80
80/* Function Prototypes */ 81/* Function Prototypes */
81static int rndis_init_response (int configNr, rndis_init_msg_type *buf);
82static int rndis_query_response (int configNr, rndis_query_msg_type *buf);
83static int rndis_set_response (int configNr, rndis_set_msg_type *buf);
84static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf);
85static int rndis_keepalive_response (int configNr,
86 rndis_keepalive_msg_type *buf);
87
88static rndis_resp_t *rndis_add_response (int configNr, u32 length); 82static rndis_resp_t *rndis_add_response (int configNr, u32 length);
89 83
90 84
85/* supported OIDs */
86static const u32 oid_supported_list [] =
87{
88 /* the general stuff */
89 OID_GEN_SUPPORTED_LIST,
90 OID_GEN_HARDWARE_STATUS,
91 OID_GEN_MEDIA_SUPPORTED,
92 OID_GEN_MEDIA_IN_USE,
93 OID_GEN_MAXIMUM_FRAME_SIZE,
94 OID_GEN_LINK_SPEED,
95 OID_GEN_TRANSMIT_BLOCK_SIZE,
96 OID_GEN_RECEIVE_BLOCK_SIZE,
97 OID_GEN_VENDOR_ID,
98 OID_GEN_VENDOR_DESCRIPTION,
99 OID_GEN_VENDOR_DRIVER_VERSION,
100 OID_GEN_CURRENT_PACKET_FILTER,
101 OID_GEN_MAXIMUM_TOTAL_SIZE,
102 OID_GEN_MEDIA_CONNECT_STATUS,
103 OID_GEN_PHYSICAL_MEDIUM,
104#if 0
105 OID_GEN_RNDIS_CONFIG_PARAMETER,
106#endif
107
108 /* the statistical stuff */
109 OID_GEN_XMIT_OK,
110 OID_GEN_RCV_OK,
111 OID_GEN_XMIT_ERROR,
112 OID_GEN_RCV_ERROR,
113 OID_GEN_RCV_NO_BUFFER,
114#ifdef RNDIS_OPTIONAL_STATS
115 OID_GEN_DIRECTED_BYTES_XMIT,
116 OID_GEN_DIRECTED_FRAMES_XMIT,
117 OID_GEN_MULTICAST_BYTES_XMIT,
118 OID_GEN_MULTICAST_FRAMES_XMIT,
119 OID_GEN_BROADCAST_BYTES_XMIT,
120 OID_GEN_BROADCAST_FRAMES_XMIT,
121 OID_GEN_DIRECTED_BYTES_RCV,
122 OID_GEN_DIRECTED_FRAMES_RCV,
123 OID_GEN_MULTICAST_BYTES_RCV,
124 OID_GEN_MULTICAST_FRAMES_RCV,
125 OID_GEN_BROADCAST_BYTES_RCV,
126 OID_GEN_BROADCAST_FRAMES_RCV,
127 OID_GEN_RCV_CRC_ERROR,
128 OID_GEN_TRANSMIT_QUEUE_LENGTH,
129#endif /* RNDIS_OPTIONAL_STATS */
130
131 /* mandatory 802.3 */
132 /* the general stuff */
133 OID_802_3_PERMANENT_ADDRESS,
134 OID_802_3_CURRENT_ADDRESS,
135 OID_802_3_MULTICAST_LIST,
136 OID_802_3_MAC_OPTIONS,
137 OID_802_3_MAXIMUM_LIST_SIZE,
138
139 /* the statistical stuff */
140 OID_802_3_RCV_ERROR_ALIGNMENT,
141 OID_802_3_XMIT_ONE_COLLISION,
142 OID_802_3_XMIT_MORE_COLLISIONS,
143#ifdef RNDIS_OPTIONAL_STATS
144 OID_802_3_XMIT_DEFERRED,
145 OID_802_3_XMIT_MAX_COLLISIONS,
146 OID_802_3_RCV_OVERRUN,
147 OID_802_3_XMIT_UNDERRUN,
148 OID_802_3_XMIT_HEARTBEAT_FAILURE,
149 OID_802_3_XMIT_TIMES_CRS_LOST,
150 OID_802_3_XMIT_LATE_COLLISIONS,
151#endif /* RNDIS_OPTIONAL_STATS */
152
153#ifdef RNDIS_PM
154 /* PM and wakeup are mandatory for USB: */
155
156 /* power management */
157 OID_PNP_CAPABILITIES,
158 OID_PNP_QUERY_POWER,
159 OID_PNP_SET_POWER,
160
161#ifdef RNDIS_WAKEUP
162 /* wake up host */
163 OID_PNP_ENABLE_WAKE_UP,
164 OID_PNP_ADD_WAKE_UP_PATTERN,
165 OID_PNP_REMOVE_WAKE_UP_PATTERN,
166#endif /* RNDIS_WAKEUP */
167#endif /* RNDIS_PM */
168};
169
170
91/* NDIS Functions */ 171/* NDIS Functions */
92static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r) 172static int
173gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
174 rndis_resp_t *r)
93{ 175{
94 int retval = -ENOTSUPP; 176 int retval = -ENOTSUPP;
95 u32 length = 0; 177 u32 length = 4; /* usually */
96 __le32 *tmp; 178 __le32 *outbuf;
97 int i, count; 179 int i, count;
98 rndis_query_cmplt_type *resp; 180 rndis_query_cmplt_type *resp;
99 181
@@ -101,7 +183,22 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
101 resp = (rndis_query_cmplt_type *) r->buf; 183 resp = (rndis_query_cmplt_type *) r->buf;
102 184
103 if (!resp) return -ENOMEM; 185 if (!resp) return -ENOMEM;
104 186
187 if (buf_len && rndis_debug > 1) {
188 DEBUG("query OID %08x value, len %d:\n", OID, buf_len);
189 for (i = 0; i < buf_len; i += 16) {
190 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
191 le32_to_cpup((__le32 *)&buf[i]),
192 le32_to_cpup((__le32 *)&buf[i + 4]),
193 le32_to_cpup((__le32 *)&buf[i + 8]),
194 le32_to_cpup((__le32 *)&buf[i + 12]));
195 }
196 }
197
198 /* response goes here, right after the header */
199 outbuf = (__le32 *) &resp[1];
200 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
201
105 switch (OID) { 202 switch (OID) {
106 203
107 /* general oids (table 4-1) */ 204 /* general oids (table 4-1) */
@@ -111,42 +208,36 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
111 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 208 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);
112 length = sizeof (oid_supported_list); 209 length = sizeof (oid_supported_list);
113 count = length / sizeof (u32); 210 count = length / sizeof (u32);
114 tmp = (__le32 *) ((u8 *)resp + 24);
115 for (i = 0; i < count; i++) 211 for (i = 0; i < count; i++)
116 tmp[i] = cpu_to_le32 (oid_supported_list[i]); 212 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
117 retval = 0; 213 retval = 0;
118 break; 214 break;
119 215
120 /* mandatory */ 216 /* mandatory */
121 case OID_GEN_HARDWARE_STATUS: 217 case OID_GEN_HARDWARE_STATUS:
122 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 218 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);
123 length = 4;
124 /* Bogus question! 219 /* Bogus question!
125 * Hardware must be ready to receive high level protocols. 220 * Hardware must be ready to receive high level protocols.
126 * BTW: 221 * BTW:
127 * reddite ergo quae sunt Caesaris Caesari 222 * reddite ergo quae sunt Caesaris Caesari
128 * et quae sunt Dei Deo! 223 * et quae sunt Dei Deo!
129 */ 224 */
130 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 225 *outbuf = __constant_cpu_to_le32 (0);
131 retval = 0; 226 retval = 0;
132 break; 227 break;
133 228
134 /* mandatory */ 229 /* mandatory */
135 case OID_GEN_MEDIA_SUPPORTED: 230 case OID_GEN_MEDIA_SUPPORTED:
136 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 231 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);
137 length = 4; 232 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
138 *((__le32 *) resp + 6) = cpu_to_le32 (
139 rndis_per_dev_params [configNr].medium);
140 retval = 0; 233 retval = 0;
141 break; 234 break;
142 235
143 /* mandatory */ 236 /* mandatory */
144 case OID_GEN_MEDIA_IN_USE: 237 case OID_GEN_MEDIA_IN_USE:
145 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 238 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);
146 length = 4;
147 /* one medium, one transport... (maybe you do it better) */ 239 /* one medium, one transport... (maybe you do it better) */
148 *((__le32 *) resp + 6) = cpu_to_le32 ( 240 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
149 rndis_per_dev_params [configNr].medium);
150 retval = 0; 241 retval = 0;
151 break; 242 break;
152 243
@@ -154,25 +245,21 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
154 case OID_GEN_MAXIMUM_FRAME_SIZE: 245 case OID_GEN_MAXIMUM_FRAME_SIZE:
155 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 246 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);
156 if (rndis_per_dev_params [configNr].dev) { 247 if (rndis_per_dev_params [configNr].dev) {
157 length = 4; 248 *outbuf = cpu_to_le32 (
158 *((__le32 *) resp + 6) = cpu_to_le32 (
159 rndis_per_dev_params [configNr].dev->mtu); 249 rndis_per_dev_params [configNr].dev->mtu);
160 retval = 0; 250 retval = 0;
161 } else {
162 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
163 retval = 0;
164 } 251 }
165 break; 252 break;
166 253
167 /* mandatory */ 254 /* mandatory */
168 case OID_GEN_LINK_SPEED: 255 case OID_GEN_LINK_SPEED:
169// DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 256 if (rndis_debug > 1)
170 length = 4; 257 DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);
171 if (rndis_per_dev_params [configNr].media_state 258 if (rndis_per_dev_params [configNr].media_state
172 == NDIS_MEDIA_STATE_DISCONNECTED) 259 == NDIS_MEDIA_STATE_DISCONNECTED)
173 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 260 *outbuf = __constant_cpu_to_le32 (0);
174 else 261 else
175 *((__le32 *) resp + 6) = cpu_to_le32 ( 262 *outbuf = cpu_to_le32 (
176 rndis_per_dev_params [configNr].speed); 263 rndis_per_dev_params [configNr].speed);
177 retval = 0; 264 retval = 0;
178 break; 265 break;
@@ -181,8 +268,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
181 case OID_GEN_TRANSMIT_BLOCK_SIZE: 268 case OID_GEN_TRANSMIT_BLOCK_SIZE:
182 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 269 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);
183 if (rndis_per_dev_params [configNr].dev) { 270 if (rndis_per_dev_params [configNr].dev) {
184 length = 4; 271 *outbuf = cpu_to_le32 (
185 *((__le32 *) resp + 6) = cpu_to_le32 (
186 rndis_per_dev_params [configNr].dev->mtu); 272 rndis_per_dev_params [configNr].dev->mtu);
187 retval = 0; 273 retval = 0;
188 } 274 }
@@ -192,8 +278,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
192 case OID_GEN_RECEIVE_BLOCK_SIZE: 278 case OID_GEN_RECEIVE_BLOCK_SIZE:
193 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 279 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);
194 if (rndis_per_dev_params [configNr].dev) { 280 if (rndis_per_dev_params [configNr].dev) {
195 length = 4; 281 *outbuf = cpu_to_le32 (
196 *((__le32 *) resp + 6) = cpu_to_le32 (
197 rndis_per_dev_params [configNr].dev->mtu); 282 rndis_per_dev_params [configNr].dev->mtu);
198 retval = 0; 283 retval = 0;
199 } 284 }
@@ -202,8 +287,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
202 /* mandatory */ 287 /* mandatory */
203 case OID_GEN_VENDOR_ID: 288 case OID_GEN_VENDOR_ID:
204 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 289 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);
205 length = 4; 290 *outbuf = cpu_to_le32 (
206 *((__le32 *) resp + 6) = cpu_to_le32 (
207 rndis_per_dev_params [configNr].vendorID); 291 rndis_per_dev_params [configNr].vendorID);
208 retval = 0; 292 retval = 0;
209 break; 293 break;
@@ -212,51 +296,44 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
212 case OID_GEN_VENDOR_DESCRIPTION: 296 case OID_GEN_VENDOR_DESCRIPTION:
213 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 297 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);
214 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 298 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
215 memcpy ((u8 *) resp + 24, 299 memcpy (outbuf,
216 rndis_per_dev_params [configNr].vendorDescr, length); 300 rndis_per_dev_params [configNr].vendorDescr, length);
217 retval = 0; 301 retval = 0;
218 break; 302 break;
219 303
220 case OID_GEN_VENDOR_DRIVER_VERSION: 304 case OID_GEN_VENDOR_DRIVER_VERSION:
221 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 305 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);
222 length = 4;
223 /* Created as LE */ 306 /* Created as LE */
224 *((__le32 *) resp + 6) = rndis_driver_version; 307 *outbuf = rndis_driver_version;
225 retval = 0; 308 retval = 0;
226 break; 309 break;
227 310
228 /* mandatory */ 311 /* mandatory */
229 case OID_GEN_CURRENT_PACKET_FILTER: 312 case OID_GEN_CURRENT_PACKET_FILTER:
230 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 313 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);
231 length = 4; 314 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
232 *((__le32 *) resp + 6) = cpu_to_le32 (
233 rndis_per_dev_params[configNr].filter);
234 retval = 0; 315 retval = 0;
235 break; 316 break;
236 317
237 /* mandatory */ 318 /* mandatory */
238 case OID_GEN_MAXIMUM_TOTAL_SIZE: 319 case OID_GEN_MAXIMUM_TOTAL_SIZE:
239 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 320 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);
240 length = 4; 321 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
241 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
242 RNDIS_MAX_TOTAL_SIZE);
243 retval = 0; 322 retval = 0;
244 break; 323 break;
245 324
246 /* mandatory */ 325 /* mandatory */
247 case OID_GEN_MEDIA_CONNECT_STATUS: 326 case OID_GEN_MEDIA_CONNECT_STATUS:
248 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 327 if (rndis_debug > 1)
249 length = 4; 328 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);
250 *((__le32 *) resp + 6) = cpu_to_le32 ( 329 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
251 rndis_per_dev_params [configNr]
252 .media_state); 330 .media_state);
253 retval = 0; 331 retval = 0;
254 break; 332 break;
255 333
256 case OID_GEN_PHYSICAL_MEDIUM: 334 case OID_GEN_PHYSICAL_MEDIUM:
257 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 335 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);
258 length = 4; 336 *outbuf = __constant_cpu_to_le32 (0);
259 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
260 retval = 0; 337 retval = 0;
261 break; 338 break;
262 339
@@ -266,8 +343,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
266 */ 343 */
267 case OID_GEN_MAC_OPTIONS: /* from WinME */ 344 case OID_GEN_MAC_OPTIONS: /* from WinME */
268 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 345 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);
269 length = 4; 346 *outbuf = __constant_cpu_to_le32(
270 *((__le32 *) resp + 6) = __constant_cpu_to_le32(
271 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 347 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
272 | NDIS_MAC_OPTION_FULL_DUPLEX); 348 | NDIS_MAC_OPTION_FULL_DUPLEX);
273 retval = 0; 349 retval = 0;
@@ -277,62 +353,49 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
277 353
278 /* mandatory */ 354 /* mandatory */
279 case OID_GEN_XMIT_OK: 355 case OID_GEN_XMIT_OK:
280 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 356 if (rndis_debug > 1)
357 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);
281 if (rndis_per_dev_params [configNr].stats) { 358 if (rndis_per_dev_params [configNr].stats) {
282 length = 4; 359 *outbuf = cpu_to_le32 (
283 *((__le32 *) resp + 6) = cpu_to_le32 (
284 rndis_per_dev_params [configNr].stats->tx_packets - 360 rndis_per_dev_params [configNr].stats->tx_packets -
285 rndis_per_dev_params [configNr].stats->tx_errors - 361 rndis_per_dev_params [configNr].stats->tx_errors -
286 rndis_per_dev_params [configNr].stats->tx_dropped); 362 rndis_per_dev_params [configNr].stats->tx_dropped);
287 retval = 0; 363 retval = 0;
288 } else {
289 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
290 retval = 0;
291 } 364 }
292 break; 365 break;
293 366
294 /* mandatory */ 367 /* mandatory */
295 case OID_GEN_RCV_OK: 368 case OID_GEN_RCV_OK:
296 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 369 if (rndis_debug > 1)
370 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);
297 if (rndis_per_dev_params [configNr].stats) { 371 if (rndis_per_dev_params [configNr].stats) {
298 length = 4; 372 *outbuf = cpu_to_le32 (
299 *((__le32 *) resp + 6) = cpu_to_le32 (
300 rndis_per_dev_params [configNr].stats->rx_packets - 373 rndis_per_dev_params [configNr].stats->rx_packets -
301 rndis_per_dev_params [configNr].stats->rx_errors - 374 rndis_per_dev_params [configNr].stats->rx_errors -
302 rndis_per_dev_params [configNr].stats->rx_dropped); 375 rndis_per_dev_params [configNr].stats->rx_dropped);
303 retval = 0; 376 retval = 0;
304 } else {
305 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
306 retval = 0;
307 } 377 }
308 break; 378 break;
309 379
310 /* mandatory */ 380 /* mandatory */
311 case OID_GEN_XMIT_ERROR: 381 case OID_GEN_XMIT_ERROR:
312 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 382 if (rndis_debug > 1)
383 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);
313 if (rndis_per_dev_params [configNr].stats) { 384 if (rndis_per_dev_params [configNr].stats) {
314 length = 4; 385 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
315 *((__le32 *) resp + 6) = cpu_to_le32 (
316 rndis_per_dev_params [configNr]
317 .stats->tx_errors); 386 .stats->tx_errors);
318 retval = 0; 387 retval = 0;
319 } else {
320 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
321 retval = 0;
322 } 388 }
323 break; 389 break;
324 390
325 /* mandatory */ 391 /* mandatory */
326 case OID_GEN_RCV_ERROR: 392 case OID_GEN_RCV_ERROR:
327 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 393 if (rndis_debug > 1)
394 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);
328 if (rndis_per_dev_params [configNr].stats) { 395 if (rndis_per_dev_params [configNr].stats) {
329 *((__le32 *) resp + 6) = cpu_to_le32 ( 396 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
330 rndis_per_dev_params [configNr]
331 .stats->rx_errors); 397 .stats->rx_errors);
332 retval = 0; 398 retval = 0;
333 } else {
334 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
335 retval = 0;
336 } 399 }
337 break; 400 break;
338 401
@@ -340,13 +403,9 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
340 case OID_GEN_RCV_NO_BUFFER: 403 case OID_GEN_RCV_NO_BUFFER:
341 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 404 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);
342 if (rndis_per_dev_params [configNr].stats) { 405 if (rndis_per_dev_params [configNr].stats) {
343 *((__le32 *) resp + 6) = cpu_to_le32 ( 406 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
344 rndis_per_dev_params [configNr]
345 .stats->rx_dropped); 407 .stats->rx_dropped);
346 retval = 0; 408 retval = 0;
347 } else {
348 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
349 retval = 0;
350 } 409 }
351 break; 410 break;
352 411
@@ -359,8 +418,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
359 * divided by weight of Alpha Centauri 418 * divided by weight of Alpha Centauri
360 */ 419 */
361 if (rndis_per_dev_params [configNr].stats) { 420 if (rndis_per_dev_params [configNr].stats) {
362 length = 4; 421 *outbuf = cpu_to_le32 (
363 *((__le32 *) resp + 6) = cpu_to_le32 (
364 (rndis_per_dev_params [configNr] 422 (rndis_per_dev_params [configNr]
365 .stats->tx_packets - 423 .stats->tx_packets -
366 rndis_per_dev_params [configNr] 424 rndis_per_dev_params [configNr]
@@ -369,9 +427,6 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
369 .stats->tx_dropped) 427 .stats->tx_dropped)
370 * 123); 428 * 123);
371 retval = 0; 429 retval = 0;
372 } else {
373 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
374 retval = 0;
375 } 430 }
376 break; 431 break;
377 432
@@ -379,8 +434,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
379 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 434 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);
380 /* dito */ 435 /* dito */
381 if (rndis_per_dev_params [configNr].stats) { 436 if (rndis_per_dev_params [configNr].stats) {
382 length = 4; 437 *outbuf = cpu_to_le32 (
383 *((__le32 *) resp + 6) = cpu_to_le32 (
384 (rndis_per_dev_params [configNr] 438 (rndis_per_dev_params [configNr]
385 .stats->tx_packets - 439 .stats->tx_packets -
386 rndis_per_dev_params [configNr] 440 rndis_per_dev_params [configNr]
@@ -389,144 +443,105 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
389 .stats->tx_dropped) 443 .stats->tx_dropped)
390 / 123); 444 / 123);
391 retval = 0; 445 retval = 0;
392 } else {
393 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
394 retval = 0;
395 } 446 }
396 break; 447 break;
397 448
398 case OID_GEN_MULTICAST_BYTES_XMIT: 449 case OID_GEN_MULTICAST_BYTES_XMIT:
399 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 450 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);
400 if (rndis_per_dev_params [configNr].stats) { 451 if (rndis_per_dev_params [configNr].stats) {
401 *((__le32 *) resp + 6) = cpu_to_le32 ( 452 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
402 rndis_per_dev_params [configNr]
403 .stats->multicast*1234); 453 .stats->multicast*1234);
404 retval = 0; 454 retval = 0;
405 } else {
406 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
407 retval = 0;
408 } 455 }
409 break; 456 break;
410 457
411 case OID_GEN_MULTICAST_FRAMES_XMIT: 458 case OID_GEN_MULTICAST_FRAMES_XMIT:
412 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 459 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);
413 if (rndis_per_dev_params [configNr].stats) { 460 if (rndis_per_dev_params [configNr].stats) {
414 *((__le32 *) resp + 6) = cpu_to_le32 ( 461 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
415 rndis_per_dev_params [configNr]
416 .stats->multicast); 462 .stats->multicast);
417 retval = 0; 463 retval = 0;
418 } else {
419 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
420 retval = 0;
421 } 464 }
422 break; 465 break;
423 466
424 case OID_GEN_BROADCAST_BYTES_XMIT: 467 case OID_GEN_BROADCAST_BYTES_XMIT:
425 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 468 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);
426 if (rndis_per_dev_params [configNr].stats) { 469 if (rndis_per_dev_params [configNr].stats) {
427 *((__le32 *) resp + 6) = cpu_to_le32 ( 470 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
428 rndis_per_dev_params [configNr]
429 .stats->tx_packets/42*255); 471 .stats->tx_packets/42*255);
430 retval = 0; 472 retval = 0;
431 } else {
432 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
433 retval = 0;
434 } 473 }
435 break; 474 break;
436 475
437 case OID_GEN_BROADCAST_FRAMES_XMIT: 476 case OID_GEN_BROADCAST_FRAMES_XMIT:
438 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 477 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);
439 if (rndis_per_dev_params [configNr].stats) { 478 if (rndis_per_dev_params [configNr].stats) {
440 *((__le32 *) resp + 6) = cpu_to_le32 ( 479 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
441 rndis_per_dev_params [configNr]
442 .stats->tx_packets/42); 480 .stats->tx_packets/42);
443 retval = 0; 481 retval = 0;
444 } else {
445 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
446 retval = 0;
447 } 482 }
448 break; 483 break;
449 484
450 case OID_GEN_DIRECTED_BYTES_RCV: 485 case OID_GEN_DIRECTED_BYTES_RCV:
451 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 486 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);
452 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 487 *outbuf = __constant_cpu_to_le32 (0);
453 retval = 0; 488 retval = 0;
454 break; 489 break;
455 490
456 case OID_GEN_DIRECTED_FRAMES_RCV: 491 case OID_GEN_DIRECTED_FRAMES_RCV:
457 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 492 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);
458 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 493 *outbuf = __constant_cpu_to_le32 (0);
459 retval = 0; 494 retval = 0;
460 break; 495 break;
461 496
462 case OID_GEN_MULTICAST_BYTES_RCV: 497 case OID_GEN_MULTICAST_BYTES_RCV:
463 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 498 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);
464 if (rndis_per_dev_params [configNr].stats) { 499 if (rndis_per_dev_params [configNr].stats) {
465 *((__le32 *) resp + 6) = cpu_to_le32 ( 500 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
466 rndis_per_dev_params [configNr]
467 .stats->multicast * 1111); 501 .stats->multicast * 1111);
468 retval = 0; 502 retval = 0;
469 } else {
470 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
471 retval = 0;
472 } 503 }
473 break; 504 break;
474 505
475 case OID_GEN_MULTICAST_FRAMES_RCV: 506 case OID_GEN_MULTICAST_FRAMES_RCV:
476 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 507 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);
477 if (rndis_per_dev_params [configNr].stats) { 508 if (rndis_per_dev_params [configNr].stats) {
478 *((__le32 *) resp + 6) = cpu_to_le32 ( 509 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 rndis_per_dev_params [configNr]
480 .stats->multicast); 510 .stats->multicast);
481 retval = 0; 511 retval = 0;
482 } else {
483 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
484 retval = 0;
485 } 512 }
486 break; 513 break;
487 514
488 case OID_GEN_BROADCAST_BYTES_RCV: 515 case OID_GEN_BROADCAST_BYTES_RCV:
489 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 516 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);
490 if (rndis_per_dev_params [configNr].stats) { 517 if (rndis_per_dev_params [configNr].stats) {
491 *((__le32 *) resp + 6) = cpu_to_le32 ( 518 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
492 rndis_per_dev_params [configNr]
493 .stats->rx_packets/42*255); 519 .stats->rx_packets/42*255);
494 retval = 0; 520 retval = 0;
495 } else {
496 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
497 retval = 0;
498 } 521 }
499 break; 522 break;
500 523
501 case OID_GEN_BROADCAST_FRAMES_RCV: 524 case OID_GEN_BROADCAST_FRAMES_RCV:
502 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 525 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);
503 if (rndis_per_dev_params [configNr].stats) { 526 if (rndis_per_dev_params [configNr].stats) {
504 *((__le32 *) resp + 6) = cpu_to_le32 ( 527 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
505 rndis_per_dev_params [configNr]
506 .stats->rx_packets/42); 528 .stats->rx_packets/42);
507 retval = 0; 529 retval = 0;
508 } else {
509 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
510 retval = 0;
511 } 530 }
512 break; 531 break;
513 532
514 case OID_GEN_RCV_CRC_ERROR: 533 case OID_GEN_RCV_CRC_ERROR:
515 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 534 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);
516 if (rndis_per_dev_params [configNr].stats) { 535 if (rndis_per_dev_params [configNr].stats) {
517 *((__le32 *) resp + 6) = cpu_to_le32 ( 536 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 rndis_per_dev_params [configNr]
519 .stats->rx_crc_errors); 537 .stats->rx_crc_errors);
520 retval = 0; 538 retval = 0;
521 } else {
522 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
523 retval = 0;
524 } 539 }
525 break; 540 break;
526 541
527 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 542 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
528 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 543 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);
529 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 544 *outbuf = __constant_cpu_to_le32 (0);
530 retval = 0; 545 retval = 0;
531 break; 546 break;
532#endif /* RNDIS_OPTIONAL_STATS */ 547#endif /* RNDIS_OPTIONAL_STATS */
@@ -538,13 +553,10 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
538 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 553 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);
539 if (rndis_per_dev_params [configNr].dev) { 554 if (rndis_per_dev_params [configNr].dev) {
540 length = ETH_ALEN; 555 length = ETH_ALEN;
541 memcpy ((u8 *) resp + 24, 556 memcpy (outbuf,
542 rndis_per_dev_params [configNr].host_mac, 557 rndis_per_dev_params [configNr].host_mac,
543 length); 558 length);
544 retval = 0; 559 retval = 0;
545 } else {
546 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
547 retval = 0;
548 } 560 }
549 break; 561 break;
550 562
@@ -553,7 +565,7 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
553 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 565 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);
554 if (rndis_per_dev_params [configNr].dev) { 566 if (rndis_per_dev_params [configNr].dev) {
555 length = ETH_ALEN; 567 length = ETH_ALEN;
556 memcpy ((u8 *) resp + 24, 568 memcpy (outbuf,
557 rndis_per_dev_params [configNr].host_mac, 569 rndis_per_dev_params [configNr].host_mac,
558 length); 570 length);
559 retval = 0; 571 retval = 0;
@@ -563,18 +575,16 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
563 /* mandatory */ 575 /* mandatory */
564 case OID_802_3_MULTICAST_LIST: 576 case OID_802_3_MULTICAST_LIST:
565 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 577 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
566 length = 4;
567 /* Multicast base address only */ 578 /* Multicast base address only */
568 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000); 579 *outbuf = __constant_cpu_to_le32 (0xE0000000);
569 retval = 0; 580 retval = 0;
570 break; 581 break;
571 582
572 /* mandatory */ 583 /* mandatory */
573 case OID_802_3_MAXIMUM_LIST_SIZE: 584 case OID_802_3_MAXIMUM_LIST_SIZE:
574 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 585 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);
575 length = 4;
576 /* Multicast base address only */ 586 /* Multicast base address only */
577 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (1); 587 *outbuf = __constant_cpu_to_le32 (1);
578 retval = 0; 588 retval = 0;
579 break; 589 break;
580 590
@@ -587,11 +597,8 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
587 /* mandatory */ 597 /* mandatory */
588 case OID_802_3_RCV_ERROR_ALIGNMENT: 598 case OID_802_3_RCV_ERROR_ALIGNMENT:
589 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 599 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);
590 if (rndis_per_dev_params [configNr].stats) 600 if (rndis_per_dev_params [configNr].stats) {
591 { 601 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
592 length = 4;
593 *((__le32 *) resp + 6) = cpu_to_le32 (
594 rndis_per_dev_params [configNr]
595 .stats->rx_frame_errors); 602 .stats->rx_frame_errors);
596 retval = 0; 603 retval = 0;
597 } 604 }
@@ -600,16 +607,14 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
600 /* mandatory */ 607 /* mandatory */
601 case OID_802_3_XMIT_ONE_COLLISION: 608 case OID_802_3_XMIT_ONE_COLLISION:
602 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 609 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);
603 length = 4; 610 *outbuf = __constant_cpu_to_le32 (0);
604 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
605 retval = 0; 611 retval = 0;
606 break; 612 break;
607 613
608 /* mandatory */ 614 /* mandatory */
609 case OID_802_3_XMIT_MORE_COLLISIONS: 615 case OID_802_3_XMIT_MORE_COLLISIONS:
610 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 616 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);
611 length = 4; 617 *outbuf = __constant_cpu_to_le32 (0);
612 *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);
613 retval = 0; 618 retval = 0;
614 break; 619 break;
615 620
@@ -655,27 +660,18 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
655 case OID_PNP_CAPABILITIES: 660 case OID_PNP_CAPABILITIES:
656 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 661 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);
657 662
658 /* just PM, and remote wakeup on link status change 663 /* for now, no wakeup capabilities */
659 * (not magic packet or pattern match)
660 */
661 length = sizeof (struct NDIS_PNP_CAPABILITIES); 664 length = sizeof (struct NDIS_PNP_CAPABILITIES);
662 memset (resp, 0, length); 665 memset(outbuf, 0, length);
663 {
664 struct NDIS_PNP_CAPABILITIES *caps = (void *) resp;
665
666 caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE;
667 caps->WakeUpCapabilities.MinLinkChangeWakeUp
668 = NdisDeviceStateD3;
669
670 /* FIXME then use usb_gadget_wakeup(), and
671 * set USB_CONFIG_ATT_WAKEUP in config desc
672 */
673 }
674 retval = 0; 666 retval = 0;
675 break; 667 break;
676 case OID_PNP_QUERY_POWER: 668 case OID_PNP_QUERY_POWER:
677 DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__); 669 DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__,
678 /* sure, handle any power state that maps to USB suspend */ 670 le32_to_cpup((__le32 *) buf) - 1);
671 /* only suspend is a real power state, and
672 * it can't be entered by OID_PNP_SET_POWER...
673 */
674 length = 0;
679 retval = 0; 675 retval = 0;
680 break; 676 break;
681#endif 677#endif
@@ -684,11 +680,12 @@ static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r)
684 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 680 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n",
685 __FUNCTION__, OID); 681 __FUNCTION__, OID);
686 } 682 }
683 if (retval < 0)
684 length = 0;
687 685
688 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
689 resp->InformationBufferLength = cpu_to_le32 (length); 686 resp->InformationBufferLength = cpu_to_le32 (length);
690 resp->MessageLength = cpu_to_le32 (24 + length); 687 r->length = length + sizeof *resp;
691 r->length = 24 + length; 688 resp->MessageLength = cpu_to_le32 (r->length);
692 return retval; 689 return retval;
693} 690}
694 691
@@ -705,45 +702,40 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
705 if (!resp) 702 if (!resp)
706 return -ENOMEM; 703 return -ENOMEM;
707 704
708 DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 705 if (buf_len && rndis_debug > 1) {
709 for (i = 0; i < buf_len; i += 16) { 706 DEBUG("set OID %08x value, len %d:\n", OID, buf_len);
710 DEBUG ("%03d: " 707 for (i = 0; i < buf_len; i += 16) {
711 " %02x %02x %02x %02x" 708 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
712 " %02x %02x %02x %02x" 709 le32_to_cpup((__le32 *)&buf[i]),
713 " %02x %02x %02x %02x" 710 le32_to_cpup((__le32 *)&buf[i + 4]),
714 " %02x %02x %02x %02x" 711 le32_to_cpup((__le32 *)&buf[i + 8]),
715 "\n", 712 le32_to_cpup((__le32 *)&buf[i + 12]));
716 i, 713 }
717 buf[i], buf [i+1],
718 buf[i+2], buf[i+3],
719 buf[i+4], buf [i+5],
720 buf[i+6], buf[i+7],
721 buf[i+8], buf [i+9],
722 buf[i+10], buf[i+11],
723 buf[i+12], buf [i+13],
724 buf[i+14], buf[i+15]);
725 } 714 }
726 715
716 params = &rndis_per_dev_params [configNr];
727 switch (OID) { 717 switch (OID) {
728 case OID_GEN_CURRENT_PACKET_FILTER: 718 case OID_GEN_CURRENT_PACKET_FILTER:
729 params = &rndis_per_dev_params [configNr];
730 retval = 0;
731 719
732 /* FIXME use these NDIS_PACKET_TYPE_* bitflags to 720 /* these NDIS_PACKET_TYPE_* bitflags are shared with
733 * set the cdc_filter; it's not RNDIS-specific 721 * cdc_filter; it's not RNDIS-specific
734 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: 722 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
735 * PROMISCUOUS, DIRECTED, 723 * PROMISCUOUS, DIRECTED,
736 * MULTICAST, ALL_MULTICAST, BROADCAST 724 * MULTICAST, ALL_MULTICAST, BROADCAST
737 */ 725 */
738 params->filter = le32_to_cpup((__le32 *)buf); 726 *params->filter = (u16) le32_to_cpup((__le32 *)buf);
739 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 727 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
740 __FUNCTION__, params->filter); 728 __FUNCTION__, *params->filter);
741 729
742 /* this call has a significant side effect: it's 730 /* this call has a significant side effect: it's
743 * what makes the packet flow start and stop, like 731 * what makes the packet flow start and stop, like
744 * activating the CDC Ethernet altsetting. 732 * activating the CDC Ethernet altsetting.
745 */ 733 */
746 if (params->filter) { 734#ifdef RNDIS_PM
735update_linkstate:
736#endif
737 retval = 0;
738 if (*params->filter) {
747 params->state = RNDIS_DATA_INITIALIZED; 739 params->state = RNDIS_DATA_INITIALIZED;
748 netif_carrier_on(params->dev); 740 netif_carrier_on(params->dev);
749 if (netif_running(params->dev)) 741 if (netif_running(params->dev))
@@ -776,21 +768,34 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
776 768
777#ifdef RNDIS_PM 769#ifdef RNDIS_PM
778 case OID_PNP_SET_POWER: 770 case OID_PNP_SET_POWER:
779 DEBUG ("OID_PNP_SET_POWER\n"); 771 /* The only real power state is USB suspend, and RNDIS requests
780 /* sure, handle any power state that maps to USB suspend */ 772 * can't enter it; this one isn't really about power. After
781 retval = 0; 773 * resuming, Windows forces a reset, and then SET_POWER D0.
782 break; 774 * FIXME ... then things go batty; Windows wedges itself.
783 775 */
784 case OID_PNP_ENABLE_WAKE_UP: 776 i = le32_to_cpup((__force __le32 *)buf);
785 /* always-connected ... */ 777 DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1);
786 DEBUG ("OID_PNP_ENABLE_WAKE_UP\n"); 778 switch (i) {
787 retval = 0; 779 case NdisDeviceStateD0:
780 *params->filter = params->saved_filter;
781 goto update_linkstate;
782 case NdisDeviceStateD3:
783 case NdisDeviceStateD2:
784 case NdisDeviceStateD1:
785 params->saved_filter = *params->filter;
786 retval = 0;
787 break;
788 }
788 break; 789 break;
789 790
790 // no PM resume patterns supported (specified where?) 791#ifdef RNDIS_WAKEUP
791 // so OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN always fails 792 // no wakeup support advertised, so wakeup OIDs always fail:
793 // - OID_PNP_ENABLE_WAKE_UP
794 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
792#endif 795#endif
793 796
797#endif /* RNDIS_PM */
798
794 default: 799 default:
795 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", 800 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n",
796 __FUNCTION__, OID, buf_len); 801 __FUNCTION__, OID, buf_len);
@@ -811,13 +816,10 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 816 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
812 817
813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 818 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
814 819 if (!r)
815 if (!r) return -ENOMEM; 820 return -ENOMEM;
816
817 resp = (rndis_init_cmplt_type *) r->buf; 821 resp = (rndis_init_cmplt_type *) r->buf;
818 822
819 if (!resp) return -ENOMEM;
820
821 resp->MessageType = __constant_cpu_to_le32 ( 823 resp->MessageType = __constant_cpu_to_le32 (
822 REMOTE_NDIS_INITIALIZE_CMPLT); 824 REMOTE_NDIS_INITIALIZE_CMPLT);
823 resp->MessageLength = __constant_cpu_to_le32 (52); 825 resp->MessageLength = __constant_cpu_to_le32 (52);
@@ -857,20 +859,22 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
857 * oid_supported_list is the largest answer 859 * oid_supported_list is the largest answer
858 */ 860 */
859 r = rndis_add_response (configNr, sizeof (oid_supported_list)); 861 r = rndis_add_response (configNr, sizeof (oid_supported_list));
860 862 if (!r)
861 if (!r) return -ENOMEM; 863 return -ENOMEM;
862 resp = (rndis_query_cmplt_type *) r->buf; 864 resp = (rndis_query_cmplt_type *) r->buf;
863 865
864 if (!resp) return -ENOMEM;
865
866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 866 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
867 resp->MessageLength = __constant_cpu_to_le32 (24);
868 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 867 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
869 868
870 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), r)) { 869 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
870 le32_to_cpu(buf->InformationBufferOffset)
871 + 8 + (u8 *) buf,
872 le32_to_cpu(buf->InformationBufferLength),
873 r)) {
871 /* OID not supported */ 874 /* OID not supported */
872 resp->Status = __constant_cpu_to_le32 ( 875 resp->Status = __constant_cpu_to_le32 (
873 RNDIS_STATUS_NOT_SUPPORTED); 876 RNDIS_STATUS_NOT_SUPPORTED);
877 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
874 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 878 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
875 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 879 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
876 } else 880 } else
@@ -889,10 +893,9 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
889 rndis_resp_t *r; 893 rndis_resp_t *r;
890 894
891 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 895 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
892 896 if (!r)
893 if (!r) return -ENOMEM; 897 return -ENOMEM;
894 resp = (rndis_set_cmplt_type *) r->buf; 898 resp = (rndis_set_cmplt_type *) r->buf;
895 if (!resp) return -ENOMEM;
896 899
897 BufLength = le32_to_cpu (buf->InformationBufferLength); 900 BufLength = le32_to_cpu (buf->InformationBufferLength);
898 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 901 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
@@ -930,10 +933,9 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
930 rndis_resp_t *r; 933 rndis_resp_t *r;
931 934
932 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 935 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
933 936 if (!r)
934 if (!r) return -ENOMEM; 937 return -ENOMEM;
935 resp = (rndis_reset_cmplt_type *) r->buf; 938 resp = (rndis_reset_cmplt_type *) r->buf;
936 if (!resp) return -ENOMEM;
937 939
938 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 940 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
939 resp->MessageLength = __constant_cpu_to_le32 (16); 941 resp->MessageLength = __constant_cpu_to_le32 (16);
@@ -957,8 +959,9 @@ static int rndis_keepalive_response (int configNr,
957 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 959 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
958 960
959 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 961 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
962 if (!r)
963 return -ENOMEM;
960 resp = (rndis_keepalive_cmplt_type *) r->buf; 964 resp = (rndis_keepalive_cmplt_type *) r->buf;
961 if (!resp) return -ENOMEM;
962 965
963 resp->MessageType = __constant_cpu_to_le32 ( 966 resp->MessageType = __constant_cpu_to_le32 (
964 REMOTE_NDIS_KEEPALIVE_CMPLT); 967 REMOTE_NDIS_KEEPALIVE_CMPLT);
@@ -987,10 +990,9 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
987 990
988 r = rndis_add_response (configNr, 991 r = rndis_add_response (configNr,
989 sizeof (rndis_indicate_status_msg_type)); 992 sizeof (rndis_indicate_status_msg_type));
990 if (!r) return -ENOMEM; 993 if (!r)
991 994 return -ENOMEM;
992 resp = (rndis_indicate_status_msg_type *) r->buf; 995 resp = (rndis_indicate_status_msg_type *) r->buf;
993 if (!resp) return -ENOMEM;
994 996
995 resp->MessageType = __constant_cpu_to_le32 ( 997 resp->MessageType = __constant_cpu_to_le32 (
996 REMOTE_NDIS_INDICATE_STATUS_MSG); 998 REMOTE_NDIS_INDICATE_STATUS_MSG);
@@ -1021,6 +1023,21 @@ int rndis_signal_disconnect (int configNr)
1021 RNDIS_STATUS_MEDIA_DISCONNECT); 1023 RNDIS_STATUS_MEDIA_DISCONNECT);
1022} 1024}
1023 1025
1026void rndis_uninit (int configNr)
1027{
1028 u8 *buf;
1029 u32 length;
1030
1031 if (configNr >= RNDIS_MAX_CONFIGS)
1032 return;
1033 rndis_per_dev_params [configNr].used = 0;
1034 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
1035
1036 /* drain the response queue */
1037 while ((buf = rndis_get_next_response(configNr, &length)))
1038 rndis_free_response(configNr, buf);
1039}
1040
1024void rndis_set_host_mac (int configNr, const u8 *addr) 1041void rndis_set_host_mac (int configNr, const u8 *addr)
1025{ 1042{
1026 rndis_per_dev_params [configNr].host_mac = addr; 1043 rndis_per_dev_params [configNr].host_mac = addr;
@@ -1046,9 +1063,13 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1046 return -ENOTSUPP; 1063 return -ENOTSUPP;
1047 params = &rndis_per_dev_params [configNr]; 1064 params = &rndis_per_dev_params [configNr];
1048 1065
1066 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1067 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1068 * and normal HC level polling to see if there's any IN traffic.
1069 */
1070
1049 /* For USB: responses may take up to 10 seconds */ 1071 /* For USB: responses may take up to 10 seconds */
1050 switch (MsgType) 1072 switch (MsgType) {
1051 {
1052 case REMOTE_NDIS_INITIALIZE_MSG: 1073 case REMOTE_NDIS_INITIALIZE_MSG:
1053 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1074 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1054 __FUNCTION__ ); 1075 __FUNCTION__ );
@@ -1082,10 +1103,9 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1082 1103
1083 case REMOTE_NDIS_KEEPALIVE_MSG: 1104 case REMOTE_NDIS_KEEPALIVE_MSG:
1084 /* For USB: host does this every 5 seconds */ 1105 /* For USB: host does this every 5 seconds */
1085#ifdef VERBOSE 1106 if (rndis_debug > 1)
1086 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1107 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1087 __FUNCTION__ ); 1108 __FUNCTION__ );
1088#endif
1089 return rndis_keepalive_response (configNr, 1109 return rndis_keepalive_response (configNr,
1090 (rndis_keepalive_msg_type *) 1110 (rndis_keepalive_msg_type *)
1091 buf); 1111 buf);
@@ -1152,7 +1172,8 @@ void rndis_deregister (int configNr)
1152} 1172}
1153 1173
1154int rndis_set_param_dev (u8 configNr, struct net_device *dev, 1174int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1155 struct net_device_stats *stats) 1175 struct net_device_stats *stats,
1176 u16 *cdc_filter)
1156{ 1177{
1157 DEBUG("%s:\n", __FUNCTION__ ); 1178 DEBUG("%s:\n", __FUNCTION__ );
1158 if (!dev || !stats) return -1; 1179 if (!dev || !stats) return -1;
@@ -1160,6 +1181,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1160 1181
1161 rndis_per_dev_params [configNr].dev = dev; 1182 rndis_per_dev_params [configNr].dev = dev;
1162 rndis_per_dev_params [configNr].stats = stats; 1183 rndis_per_dev_params [configNr].stats = stats;
1184 rndis_per_dev_params [configNr].filter = cdc_filter;
1163 1185
1164 return 0; 1186 return 0;
1165} 1187}
@@ -1178,7 +1200,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1178 1200
1179int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1201int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1180{ 1202{
1181 DEBUG("%s:\n", __FUNCTION__ ); 1203 DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed);
1182 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1204 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1183 1205
1184 rndis_per_dev_params [configNr].medium = medium; 1206 rndis_per_dev_params [configNr].medium = medium;
@@ -1242,6 +1264,7 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1242{ 1264{
1243 rndis_resp_t *r; 1265 rndis_resp_t *r;
1244 1266
1267 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1245 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1268 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1246 if (!r) return NULL; 1269 if (!r) return NULL;
1247 1270
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 2b5b55df3cfd..95b4c6326100 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -69,90 +69,6 @@
69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106 69#define OID_PNP_ENABLE_WAKE_UP 0xFD010106
70 70
71 71
72/* supported OIDs */
73static const u32 oid_supported_list [] =
74{
75 /* the general stuff */
76 OID_GEN_SUPPORTED_LIST,
77 OID_GEN_HARDWARE_STATUS,
78 OID_GEN_MEDIA_SUPPORTED,
79 OID_GEN_MEDIA_IN_USE,
80 OID_GEN_MAXIMUM_FRAME_SIZE,
81 OID_GEN_LINK_SPEED,
82 OID_GEN_TRANSMIT_BLOCK_SIZE,
83 OID_GEN_RECEIVE_BLOCK_SIZE,
84 OID_GEN_VENDOR_ID,
85 OID_GEN_VENDOR_DESCRIPTION,
86 OID_GEN_VENDOR_DRIVER_VERSION,
87 OID_GEN_CURRENT_PACKET_FILTER,
88 OID_GEN_MAXIMUM_TOTAL_SIZE,
89 OID_GEN_MEDIA_CONNECT_STATUS,
90 OID_GEN_PHYSICAL_MEDIUM,
91#if 0
92 OID_GEN_RNDIS_CONFIG_PARAMETER,
93#endif
94
95 /* the statistical stuff */
96 OID_GEN_XMIT_OK,
97 OID_GEN_RCV_OK,
98 OID_GEN_XMIT_ERROR,
99 OID_GEN_RCV_ERROR,
100 OID_GEN_RCV_NO_BUFFER,
101#ifdef RNDIS_OPTIONAL_STATS
102 OID_GEN_DIRECTED_BYTES_XMIT,
103 OID_GEN_DIRECTED_FRAMES_XMIT,
104 OID_GEN_MULTICAST_BYTES_XMIT,
105 OID_GEN_MULTICAST_FRAMES_XMIT,
106 OID_GEN_BROADCAST_BYTES_XMIT,
107 OID_GEN_BROADCAST_FRAMES_XMIT,
108 OID_GEN_DIRECTED_BYTES_RCV,
109 OID_GEN_DIRECTED_FRAMES_RCV,
110 OID_GEN_MULTICAST_BYTES_RCV,
111 OID_GEN_MULTICAST_FRAMES_RCV,
112 OID_GEN_BROADCAST_BYTES_RCV,
113 OID_GEN_BROADCAST_FRAMES_RCV,
114 OID_GEN_RCV_CRC_ERROR,
115 OID_GEN_TRANSMIT_QUEUE_LENGTH,
116#endif /* RNDIS_OPTIONAL_STATS */
117
118 /* mandatory 802.3 */
119 /* the general stuff */
120 OID_802_3_PERMANENT_ADDRESS,
121 OID_802_3_CURRENT_ADDRESS,
122 OID_802_3_MULTICAST_LIST,
123 OID_802_3_MAC_OPTIONS,
124 OID_802_3_MAXIMUM_LIST_SIZE,
125
126 /* the statistical stuff */
127 OID_802_3_RCV_ERROR_ALIGNMENT,
128 OID_802_3_XMIT_ONE_COLLISION,
129 OID_802_3_XMIT_MORE_COLLISIONS,
130#ifdef RNDIS_OPTIONAL_STATS
131 OID_802_3_XMIT_DEFERRED,
132 OID_802_3_XMIT_MAX_COLLISIONS,
133 OID_802_3_RCV_OVERRUN,
134 OID_802_3_XMIT_UNDERRUN,
135 OID_802_3_XMIT_HEARTBEAT_FAILURE,
136 OID_802_3_XMIT_TIMES_CRS_LOST,
137 OID_802_3_XMIT_LATE_COLLISIONS,
138#endif /* RNDIS_OPTIONAL_STATS */
139
140#ifdef RNDIS_PM
141 /* PM and wakeup are mandatory for USB: */
142
143 /* power management */
144 OID_PNP_CAPABILITIES,
145 OID_PNP_QUERY_POWER,
146 OID_PNP_SET_POWER,
147
148 /* wake up host */
149 OID_PNP_ENABLE_WAKE_UP,
150 OID_PNP_ADD_WAKE_UP_PATTERN,
151 OID_PNP_REMOVE_WAKE_UP_PATTERN,
152#endif
153};
154
155
156typedef struct rndis_init_msg_type 72typedef struct rndis_init_msg_type
157{ 73{
158 __le32 MessageType; 74 __le32 MessageType;
@@ -309,15 +225,18 @@ typedef struct rndis_resp_t
309typedef struct rndis_params 225typedef struct rndis_params
310{ 226{
311 u8 confignr; 227 u8 confignr;
312 int used; 228 u8 used;
229 u16 saved_filter;
313 enum rndis_state state; 230 enum rndis_state state;
314 u32 filter;
315 u32 medium; 231 u32 medium;
316 u32 speed; 232 u32 speed;
317 u32 media_state; 233 u32 media_state;
234
318 const u8 *host_mac; 235 const u8 *host_mac;
236 u16 *filter;
319 struct net_device *dev; 237 struct net_device *dev;
320 struct net_device_stats *stats; 238 struct net_device_stats *stats;
239
321 u32 vendorID; 240 u32 vendorID;
322 const char *vendorDescr; 241 const char *vendorDescr;
323 int (*ack) (struct net_device *); 242 int (*ack) (struct net_device *);
@@ -329,7 +248,8 @@ int rndis_msg_parser (u8 configNr, u8 *buf);
329int rndis_register (int (*rndis_control_ack) (struct net_device *)); 248int rndis_register (int (*rndis_control_ack) (struct net_device *));
330void rndis_deregister (int configNr); 249void rndis_deregister (int configNr);
331int rndis_set_param_dev (u8 configNr, struct net_device *dev, 250int rndis_set_param_dev (u8 configNr, struct net_device *dev,
332 struct net_device_stats *stats); 251 struct net_device_stats *stats,
252 u16 *cdc_filter);
333int rndis_set_param_vendor (u8 configNr, u32 vendorID, 253int rndis_set_param_vendor (u8 configNr, u32 vendorID,
334 const char *vendorDescr); 254 const char *vendorDescr);
335int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); 255int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed);
@@ -338,6 +258,7 @@ int rndis_rm_hdr (struct sk_buff *skb);
338u8 *rndis_get_next_response (int configNr, u32 *length); 258u8 *rndis_get_next_response (int configNr, u32 *length);
339void rndis_free_response (int configNr, u8 *buf); 259void rndis_free_response (int configNr, u8 *buf);
340 260
261void rndis_uninit (int configNr);
341int rndis_signal_connect (int configNr); 262int rndis_signal_connect (int configNr);
342int rndis_signal_disconnect (int configNr); 263int rndis_signal_disconnect (int configNr);
343int rndis_state (int configNr); 264int rndis_state (int configNr);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 4d591c764e38..9e4f1c6935a5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
300 u8 type, unsigned int index, int is_otg); 300 u8 type, unsigned int index, int is_otg);
301 301
302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
303 int kmalloc_flags); 303 unsigned kmalloc_flags);
304static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 304static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
305 305
306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
307 int kmalloc_flags); 307 unsigned kmalloc_flags);
308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
309 309
310static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); 310static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags);
311static void gs_free_ports(struct gs_dev *dev); 311static void gs_free_ports(struct gs_dev *dev);
312 312
313/* circular buffer */ 313/* circular buffer */
314static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); 314static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags);
315static void gs_buf_free(struct gs_buf *gb); 315static void gs_buf_free(struct gs_buf *gb);
316static void gs_buf_clear(struct gs_buf *gb); 316static void gs_buf_clear(struct gs_buf *gb);
317static unsigned int gs_buf_data_avail(struct gs_buf *gb); 317static unsigned int gs_buf_data_avail(struct gs_buf *gb);
@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget,
1607 int ret = -EOPNOTSUPP; 1607 int ret = -EOPNOTSUPP;
1608 struct gs_dev *dev = get_gadget_data(gadget); 1608 struct gs_dev *dev = get_gadget_data(gadget);
1609 struct usb_request *req = dev->dev_ctrl_req; 1609 struct usb_request *req = dev->dev_ctrl_req;
1610 u16 wIndex = ctrl->wIndex; 1610 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1611 u16 wValue = ctrl->wValue; 1611 u16 wValue = le16_to_cpu(ctrl->wValue);
1612 u16 wLength = ctrl->wLength; 1612 u16 wLength = le16_to_cpu(ctrl->wLength);
1613 1613
1614 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1614 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1615 case USB_TYPE_STANDARD: 1615 case USB_TYPE_STANDARD:
@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1651 int ret = -EOPNOTSUPP; 1651 int ret = -EOPNOTSUPP;
1652 struct gs_dev *dev = get_gadget_data(gadget); 1652 struct gs_dev *dev = get_gadget_data(gadget);
1653 struct usb_request *req = dev->dev_ctrl_req; 1653 struct usb_request *req = dev->dev_ctrl_req;
1654 u16 wIndex = ctrl->wIndex; 1654 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1655 u16 wValue = ctrl->wValue; 1655 u16 wValue = le16_to_cpu(ctrl->wValue);
1656 u16 wLength = ctrl->wLength; 1656 u16 wLength = le16_to_cpu(ctrl->wLength);
1657 1657
1658 switch (ctrl->bRequest) { 1658 switch (ctrl->bRequest) {
1659 case USB_REQ_GET_DESCRIPTOR: 1659 case USB_REQ_GET_DESCRIPTOR:
@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget,
1782 struct gs_dev *dev = get_gadget_data(gadget); 1782 struct gs_dev *dev = get_gadget_data(gadget);
1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1784 struct usb_request *req = dev->dev_ctrl_req; 1784 struct usb_request *req = dev->dev_ctrl_req;
1785 u16 wIndex = ctrl->wIndex; 1785 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1786 u16 wValue = ctrl->wValue; 1786 u16 wValue = le16_to_cpu(ctrl->wValue);
1787 u16 wLength = ctrl->wLength; 1787 u16 wLength = le16_to_cpu(ctrl->wLength);
1788 1788
1789 switch (ctrl->bRequest) { 1789 switch (ctrl->bRequest) {
1790 case USB_CDC_REQ_SET_LINE_CODING: 1790 case USB_CDC_REQ_SET_LINE_CODING:
@@ -2119,7 +2119,8 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
2119 * Allocate a usb_request and its buffer. Returns a pointer to the 2119 * Allocate a usb_request and its buffer. Returns a pointer to the
2120 * usb_request or NULL if there is an error. 2120 * usb_request or NULL if there is an error.
2121 */ 2121 */
2122static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) 2122static struct usb_request *
2123gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags)
2123{ 2124{
2124 struct usb_request *req; 2125 struct usb_request *req;
2125 2126
@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2159 * Allocates a request and its buffer, using the given 2160 * Allocates a request and its buffer, using the given
2160 * endpoint, buffer len, and kmalloc flags. 2161 * endpoint, buffer len, and kmalloc flags.
2161 */ 2162 */
2162static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) 2163static struct gs_req_entry *
2164gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags)
2163{ 2165{
2164 struct gs_req_entry *req; 2166 struct gs_req_entry *req;
2165 2167
@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2200 * 2202 *
2201 * The device lock is normally held when calling this function. 2203 * The device lock is normally held when calling this function.
2202 */ 2204 */
2203static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) 2205static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags)
2204{ 2206{
2205 int i; 2207 int i;
2206 struct gs_port *port; 2208 struct gs_port *port;
@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev)
2282 * 2284 *
2283 * Allocate a circular buffer and all associated memory. 2285 * Allocate a circular buffer and all associated memory.
2284 */ 2286 */
2285static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) 2287static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags)
2286{ 2288{
2287 struct gs_buf *gb; 2289 struct gs_buf *gb;
2288 2290
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6e49432071a1..bb9b2d94eed5 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -612,7 +612,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
612} 612}
613 613
614static struct usb_request * 614static struct usb_request *
615source_sink_start_ep (struct usb_ep *ep, int gfp_flags) 615source_sink_start_ep (struct usb_ep *ep, unsigned gfp_flags)
616{ 616{
617 struct usb_request *req; 617 struct usb_request *req;
618 int status; 618 int status;
@@ -640,7 +640,7 @@ source_sink_start_ep (struct usb_ep *ep, int gfp_flags)
640} 640}
641 641
642static int 642static int
643set_source_sink_config (struct zero_dev *dev, int gfp_flags) 643set_source_sink_config (struct zero_dev *dev, unsigned gfp_flags)
644{ 644{
645 int result = 0; 645 int result = 0;
646 struct usb_ep *ep; 646 struct usb_ep *ep;
@@ -744,7 +744,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
744} 744}
745 745
746static int 746static int
747set_loopback_config (struct zero_dev *dev, int gfp_flags) 747set_loopback_config (struct zero_dev *dev, unsigned gfp_flags)
748{ 748{
749 int result = 0; 749 int result = 0;
750 struct usb_ep *ep; 750 struct usb_ep *ep;
@@ -845,7 +845,7 @@ static void zero_reset_config (struct zero_dev *dev)
845 * by limiting configuration choices (like the pxa2xx). 845 * by limiting configuration choices (like the pxa2xx).
846 */ 846 */
847static int 847static int
848zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags) 848zero_set_config (struct zero_dev *dev, unsigned number, unsigned gfp_flags)
849{ 849{
850 int result = 0; 850 int result = 0;
851 struct usb_gadget *gadget = dev->gadget; 851 struct usb_gadget *gadget = dev->gadget;
@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
919 struct zero_dev *dev = get_gadget_data (gadget); 919 struct zero_dev *dev = get_gadget_data (gadget);
920 struct usb_request *req = dev->req; 920 struct usb_request *req = dev->req;
921 int value = -EOPNOTSUPP; 921 int value = -EOPNOTSUPP;
922 u16 w_index = ctrl->wIndex; 922 u16 w_index = le16_to_cpu(ctrl->wIndex);
923 u16 w_value = ctrl->wValue; 923 u16 w_value = le16_to_cpu(ctrl->wValue);
924 u16 w_length = ctrl->wLength; 924 u16 w_length = le16_to_cpu(ctrl->wLength);
925 925
926 /* usually this stores reply data in the pre-allocated ep0 buffer, 926 /* usually this stores reply data in the pre-allocated ep0 buffer,
927 * but config change events will reconfigure hardware. 927 * but config change events will reconfigure hardware.
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 19e598c9641f..ed1899d307db 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -49,6 +49,19 @@ config USB_EHCI_ROOT_HUB_TT
49 49
50 This supports the EHCI implementation from TransDimension Inc. 50 This supports the EHCI implementation from TransDimension Inc.
51 51
52config USB_ISP116X_HCD
53 tristate "ISP116X HCD support"
54 depends on USB
55 default N
56 ---help---
57 The ISP1160 and ISP1161 chips are USB host controllers. Enable this
58 option if your board has this chip. If unsure, say N.
59
60 This driver does not support isochronous transfers.
61
62 To compile this driver as a module, choose M here: the
63 module will be called isp116x-hcd.
64
52config USB_OHCI_HCD 65config USB_OHCI_HCD
53 tristate "OHCI HCD support" 66 tristate "OHCI HCD support"
54 depends on USB && USB_ARCH_HAS_OHCI 67 depends on USB && USB_ARCH_HAS_OHCI
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 5dbd3e7a27c7..350d14fc1cc9 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -4,6 +4,7 @@
4# 4#
5 5
6obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 6obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
7obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
7obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 8obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
8obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 9obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
9obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o 10obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 2ff11d53567b..50cb01831075 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -254,7 +254,7 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
254 } 254 }
255 255
256 return scnprintf (buf, len, 256 return scnprintf (buf, len,
257 "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s", 257 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s",
258 label, label [0] ? " " : "", port, status, 258 label, label [0] ? " " : "", port, status,
259 (status & PORT_POWER) ? " POWER" : "", 259 (status & PORT_POWER) ? " POWER" : "",
260 (status & PORT_OWNER) ? " OWNER" : "", 260 (status & PORT_OWNER) ? " OWNER" : "",
@@ -644,9 +644,11 @@ show_registers (struct class_device *class_dev, char *buf)
644 if (bus->controller->power.power_state) { 644 if (bus->controller->power.power_state) {
645 size = scnprintf (next, size, 645 size = scnprintf (next, size,
646 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 646 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
647 "%s\n"
647 "SUSPENDED (no register access)\n", 648 "SUSPENDED (no register access)\n",
648 hcd->self.controller->bus->name, 649 hcd->self.controller->bus->name,
649 hcd->self.controller->bus_id); 650 hcd->self.controller->bus_id,
651 hcd->product_desc);
650 goto done; 652 goto done;
651 } 653 }
652 654
@@ -654,13 +656,53 @@ show_registers (struct class_device *class_dev, char *buf)
654 i = HC_VERSION(readl (&ehci->caps->hc_capbase)); 656 i = HC_VERSION(readl (&ehci->caps->hc_capbase));
655 temp = scnprintf (next, size, 657 temp = scnprintf (next, size,
656 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 658 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
659 "%s\n"
657 "EHCI %x.%02x, hcd state %d\n", 660 "EHCI %x.%02x, hcd state %d\n",
658 hcd->self.controller->bus->name, 661 hcd->self.controller->bus->name,
659 hcd->self.controller->bus_id, 662 hcd->self.controller->bus_id,
663 hcd->product_desc,
660 i >> 8, i & 0x0ff, hcd->state); 664 i >> 8, i & 0x0ff, hcd->state);
661 size -= temp; 665 size -= temp;
662 next += temp; 666 next += temp;
663 667
668#ifdef CONFIG_PCI
669 /* EHCI 0.96 and later may have "extended capabilities" */
670 if (hcd->self.controller->bus == &pci_bus_type) {
671 struct pci_dev *pdev;
672 u32 offset, cap, cap2;
673 unsigned count = 256/4;
674
675 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
676 offset = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params));
677 while (offset && count--) {
678 pci_read_config_dword (pdev, offset, &cap);
679 switch (cap & 0xff) {
680 case 1:
681 temp = scnprintf (next, size,
682 "ownership %08x%s%s\n", cap,
683 (cap & (1 << 24)) ? " linux" : "",
684 (cap & (1 << 16)) ? " firmware" : "");
685 size -= temp;
686 next += temp;
687
688 offset += 4;
689 pci_read_config_dword (pdev, offset, &cap2);
690 temp = scnprintf (next, size,
691 "SMI sts/enable 0x%08x\n", cap2);
692 size -= temp;
693 next += temp;
694 break;
695 case 0: /* illegal reserved capability */
696 cap = 0;
697 /* FALLTHROUGH */
698 default: /* unknown */
699 break;
700 }
701 temp = (cap >> 8) & 0xff;
702 }
703 }
704#endif
705
664 // FIXME interpret both types of params 706 // FIXME interpret both types of params
665 i = readl (&ehci->caps->hcs_params); 707 i = readl (&ehci->caps->hcs_params);
666 temp = scnprintf (next, size, "structural params 0x%08x\n", i); 708 temp = scnprintf (next, size, "structural params 0x%08x\n", i);
@@ -696,12 +738,19 @@ show_registers (struct class_device *class_dev, char *buf)
696 size -= temp; 738 size -= temp;
697 next += temp; 739 next += temp;
698 740
699 for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) { 741 for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
700 temp = dbg_port_buf (scratch, sizeof scratch, label, i + 1, 742 temp = dbg_port_buf (scratch, sizeof scratch, label, i,
701 readl (&ehci->regs->port_status [i])); 743 readl (&ehci->regs->port_status [i - 1]));
702 temp = scnprintf (next, size, fmt, temp, scratch); 744 temp = scnprintf (next, size, fmt, temp, scratch);
703 size -= temp; 745 size -= temp;
704 next += temp; 746 next += temp;
747 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
748 temp = scnprintf (next, size,
749 " debug control %08x\n",
750 readl (&ehci->debug->control));
751 size -= temp;
752 next += temp;
753 }
705 } 754 }
706 755
707 if (ehci->reclaim) { 756 if (ehci->reclaim) {
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index bc69bd7acebe..149b13fc0a71 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -304,30 +304,31 @@ static void ehci_watchdog (unsigned long param)
304 */ 304 */
305static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap) 305static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
306{ 306{
307 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
308
309 /* always say Linux will own the hardware */
310 pci_write_config_byte(pdev, where + 3, 1);
311
312 /* maybe wait a while for BIOS to respond */
307 if (cap & (1 << 16)) { 313 if (cap & (1 << 16)) {
308 int msec = 5000; 314 int msec = 5000;
309 struct pci_dev *pdev =
310 to_pci_dev(ehci_to_hcd(ehci)->self.controller);
311 315
312 /* request handoff to OS */
313 cap |= 1 << 24;
314 pci_write_config_dword(pdev, where, cap);
315
316 /* and wait a while for it to happen */
317 do { 316 do {
318 msleep(10); 317 msleep(10);
319 msec -= 10; 318 msec -= 10;
320 pci_read_config_dword(pdev, where, &cap); 319 pci_read_config_dword(pdev, where, &cap);
321 } while ((cap & (1 << 16)) && msec); 320 } while ((cap & (1 << 16)) && msec);
322 if (cap & (1 << 16)) { 321 if (cap & (1 << 16)) {
323 ehci_err (ehci, "BIOS handoff failed (%d, %04x)\n", 322 ehci_err(ehci, "BIOS handoff failed (%d, %08x)\n",
324 where, cap); 323 where, cap);
325 // some BIOS versions seem buggy... 324 // some BIOS versions seem buggy...
326 // return 1; 325 // return 1;
327 ehci_warn (ehci, "continuing after BIOS bug...\n"); 326 ehci_warn (ehci, "continuing after BIOS bug...\n");
328 return 0; 327 /* disable all SMIs, and clear "BIOS owns" flag */
329 } 328 pci_write_config_dword(pdev, where + 4, 0);
330 ehci_dbg (ehci, "BIOS handoff succeeded\n"); 329 pci_write_config_byte(pdev, where + 2, 0);
330 } else
331 ehci_dbg(ehci, "BIOS handoff succeeded\n");
331 } 332 }
332 return 0; 333 return 0;
333} 334}
@@ -492,8 +493,6 @@ static int ehci_start (struct usb_hcd *hcd)
492{ 493{
493 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 494 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
494 u32 temp; 495 u32 temp;
495 struct usb_device *udev;
496 struct usb_bus *bus;
497 int retval; 496 int retval;
498 u32 hcc_params; 497 u32 hcc_params;
499 u8 sbrn = 0; 498 u8 sbrn = 0;
@@ -588,8 +587,8 @@ static int ehci_start (struct usb_hcd *hcd)
588 writel (0, &ehci->regs->segment); 587 writel (0, &ehci->regs->segment);
589#if 0 588#if 0
590// this is deeply broken on almost all architectures 589// this is deeply broken on almost all architectures
591 if (!pci_set_dma_mask (to_pci_dev(hcd->self.controller), 0xffffffffffffffffULL)) 590 if (!dma_set_mask (hcd->self.controller, DMA_64BIT_MASK))
592 ehci_info (ehci, "enabled 64bit PCI DMA\n"); 591 ehci_info (ehci, "enabled 64bit DMA\n");
593#endif 592#endif
594 } 593 }
595 594
@@ -631,17 +630,6 @@ static int ehci_start (struct usb_hcd *hcd)
631 630
632 /* set async sleep time = 10 us ... ? */ 631 /* set async sleep time = 10 us ... ? */
633 632
634 /* wire up the root hub */
635 bus = hcd_to_bus (hcd);
636 udev = first ? usb_alloc_dev (NULL, bus, 0) : bus->root_hub;
637 if (!udev) {
638done2:
639 ehci_mem_cleanup (ehci);
640 return -ENOMEM;
641 }
642 udev->speed = USB_SPEED_HIGH;
643 udev->state = first ? USB_STATE_ATTACHED : USB_STATE_CONFIGURED;
644
645 /* 633 /*
646 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices 634 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices
647 * are explicitly handed to companion controller(s), so no TT is 635 * are explicitly handed to companion controller(s), so no TT is
@@ -664,24 +652,6 @@ done2:
664 first ? "initialized" : "restarted", 652 first ? "initialized" : "restarted",
665 temp >> 8, temp & 0xff, DRIVER_VERSION); 653 temp >> 8, temp & 0xff, DRIVER_VERSION);
666 654
667 /*
668 * From here on, khubd concurrently accesses the root
669 * hub; drivers will be talking to enumerated devices.
670 * (On restart paths, khubd already knows about the root
671 * hub and could find work as soon as we wrote FLAG_CF.)
672 *
673 * Before this point the HC was idle/ready. After, khubd
674 * and device drivers may start it running.
675 */
676 if (first && usb_hcd_register_root_hub (udev, hcd) != 0) {
677 if (hcd->state == HC_STATE_RUNNING)
678 ehci_quiesce (ehci);
679 ehci_reset (ehci);
680 usb_put_dev (udev);
681 retval = -ENODEV;
682 goto done2;
683 }
684
685 writel (INTR_MASK, &ehci->regs->intr_enable); /* Turn On Interrupts */ 655 writel (INTR_MASK, &ehci->regs->intr_enable); /* Turn On Interrupts */
686 656
687 if (first) 657 if (first)
@@ -990,7 +960,7 @@ static int ehci_urb_enqueue (
990 struct usb_hcd *hcd, 960 struct usb_hcd *hcd,
991 struct usb_host_endpoint *ep, 961 struct usb_host_endpoint *ep,
992 struct urb *urb, 962 struct urb *urb,
993 int mem_flags 963 unsigned mem_flags
994) { 964) {
995 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 965 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
996 struct list_head qtd_list; 966 struct list_head qtd_list;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index d7b4f7939ded..36cc1f2218d5 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (C) 2001-2004 by David Brownell
3 * 3 *
4 * 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
5 * under the terms of the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 7df9b9af54f6..d74b2d68a50e 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2001-2002 by David Brownell 2 * Copyright (C) 2001-2004 by David Brownell
3 * 3 *
4 * 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
5 * under the terms of the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
@@ -898,7 +898,7 @@ submit_async (
898 struct usb_host_endpoint *ep, 898 struct usb_host_endpoint *ep,
899 struct urb *urb, 899 struct urb *urb,
900 struct list_head *qtd_list, 900 struct list_head *qtd_list,
901 int mem_flags 901 unsigned mem_flags
902) { 902) {
903 struct ehci_qtd *qtd; 903 struct ehci_qtd *qtd;
904 int epnum; 904 int epnum;
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 2fa1ffee5ff3..9af4f64532a9 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -588,7 +588,7 @@ static int intr_submit (
588 struct usb_host_endpoint *ep, 588 struct usb_host_endpoint *ep,
589 struct urb *urb, 589 struct urb *urb,
590 struct list_head *qtd_list, 590 struct list_head *qtd_list,
591 int mem_flags 591 unsigned mem_flags
592) { 592) {
593 unsigned epnum; 593 unsigned epnum;
594 unsigned long flags; 594 unsigned long flags;
@@ -633,13 +633,12 @@ done:
633/* ehci_iso_stream ops work with both ITD and SITD */ 633/* ehci_iso_stream ops work with both ITD and SITD */
634 634
635static struct ehci_iso_stream * 635static struct ehci_iso_stream *
636iso_stream_alloc (int mem_flags) 636iso_stream_alloc (unsigned mem_flags)
637{ 637{
638 struct ehci_iso_stream *stream; 638 struct ehci_iso_stream *stream;
639 639
640 stream = kmalloc(sizeof *stream, mem_flags); 640 stream = kcalloc(1, sizeof *stream, mem_flags);
641 if (likely (stream != NULL)) { 641 if (likely (stream != NULL)) {
642 memset (stream, 0, sizeof(*stream));
643 INIT_LIST_HEAD(&stream->td_list); 642 INIT_LIST_HEAD(&stream->td_list);
644 INIT_LIST_HEAD(&stream->free_list); 643 INIT_LIST_HEAD(&stream->free_list);
645 stream->next_uframe = -1; 644 stream->next_uframe = -1;
@@ -847,7 +846,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
847/* ehci_iso_sched ops can be ITD-only or SITD-only */ 846/* ehci_iso_sched ops can be ITD-only or SITD-only */
848 847
849static struct ehci_iso_sched * 848static struct ehci_iso_sched *
850iso_sched_alloc (unsigned packets, int mem_flags) 849iso_sched_alloc (unsigned packets, unsigned mem_flags)
851{ 850{
852 struct ehci_iso_sched *iso_sched; 851 struct ehci_iso_sched *iso_sched;
853 int size = sizeof *iso_sched; 852 int size = sizeof *iso_sched;
@@ -894,7 +893,7 @@ itd_sched_init (
894 trans |= length << 16; 893 trans |= length << 16;
895 uframe->transaction = cpu_to_le32 (trans); 894 uframe->transaction = cpu_to_le32 (trans);
896 895
897 /* might need to cross a buffer page within a td */ 896 /* might need to cross a buffer page within a uframe */
898 uframe->bufp = (buf & ~(u64)0x0fff); 897 uframe->bufp = (buf & ~(u64)0x0fff);
899 buf += length; 898 buf += length;
900 if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff)))) 899 if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff))))
@@ -920,7 +919,7 @@ itd_urb_transaction (
920 struct ehci_iso_stream *stream, 919 struct ehci_iso_stream *stream,
921 struct ehci_hcd *ehci, 920 struct ehci_hcd *ehci,
922 struct urb *urb, 921 struct urb *urb,
923 int mem_flags 922 unsigned mem_flags
924) 923)
925{ 924{
926 struct ehci_itd *itd; 925 struct ehci_itd *itd;
@@ -1194,6 +1193,7 @@ itd_init (struct ehci_iso_stream *stream, struct ehci_itd *itd)
1194{ 1193{
1195 int i; 1194 int i;
1196 1195
1196 /* it's been recently zeroed */
1197 itd->hw_next = EHCI_LIST_END; 1197 itd->hw_next = EHCI_LIST_END;
1198 itd->hw_bufp [0] = stream->buf0; 1198 itd->hw_bufp [0] = stream->buf0;
1199 itd->hw_bufp [1] = stream->buf1; 1199 itd->hw_bufp [1] = stream->buf1;
@@ -1210,8 +1210,7 @@ itd_patch (
1210 struct ehci_itd *itd, 1210 struct ehci_itd *itd,
1211 struct ehci_iso_sched *iso_sched, 1211 struct ehci_iso_sched *iso_sched,
1212 unsigned index, 1212 unsigned index,
1213 u16 uframe, 1213 u16 uframe
1214 int first
1215) 1214)
1216{ 1215{
1217 struct ehci_iso_packet *uf = &iso_sched->packet [index]; 1216 struct ehci_iso_packet *uf = &iso_sched->packet [index];
@@ -1228,7 +1227,7 @@ itd_patch (
1228 itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32)); 1227 itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32));
1229 1228
1230 /* iso_frame_desc[].offset must be strictly increasing */ 1229 /* iso_frame_desc[].offset must be strictly increasing */
1231 if (unlikely (!first && uf->cross)) { 1230 if (unlikely (uf->cross)) {
1232 u64 bufp = uf->bufp + 4096; 1231 u64 bufp = uf->bufp + 4096;
1233 itd->pg = ++pg; 1232 itd->pg = ++pg;
1234 itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0); 1233 itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0);
@@ -1257,7 +1256,7 @@ itd_link_urb (
1257 struct ehci_iso_stream *stream 1256 struct ehci_iso_stream *stream
1258) 1257)
1259{ 1258{
1260 int packet, first = 1; 1259 int packet;
1261 unsigned next_uframe, uframe, frame; 1260 unsigned next_uframe, uframe, frame;
1262 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1261 struct ehci_iso_sched *iso_sched = urb->hcpriv;
1263 struct ehci_itd *itd; 1262 struct ehci_itd *itd;
@@ -1290,7 +1289,6 @@ itd_link_urb (
1290 list_move_tail (&itd->itd_list, &stream->td_list); 1289 list_move_tail (&itd->itd_list, &stream->td_list);
1291 itd->stream = iso_stream_get (stream); 1290 itd->stream = iso_stream_get (stream);
1292 itd->urb = usb_get_urb (urb); 1291 itd->urb = usb_get_urb (urb);
1293 first = 1;
1294 itd_init (stream, itd); 1292 itd_init (stream, itd);
1295 } 1293 }
1296 1294
@@ -1298,8 +1296,7 @@ itd_link_urb (
1298 frame = next_uframe >> 3; 1296 frame = next_uframe >> 3;
1299 1297
1300 itd->usecs [uframe] = stream->usecs; 1298 itd->usecs [uframe] = stream->usecs;
1301 itd_patch (itd, iso_sched, packet, uframe, first); 1299 itd_patch (itd, iso_sched, packet, uframe);
1302 first = 0;
1303 1300
1304 next_uframe += stream->interval; 1301 next_uframe += stream->interval;
1305 stream->depth += stream->interval; 1302 stream->depth += stream->interval;
@@ -1415,7 +1412,8 @@ itd_complete (
1415 1412
1416/*-------------------------------------------------------------------------*/ 1413/*-------------------------------------------------------------------------*/
1417 1414
1418static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1415static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1416 unsigned mem_flags)
1419{ 1417{
1420 int status = -EINVAL; 1418 int status = -EINVAL;
1421 unsigned long flags; 1419 unsigned long flags;
@@ -1526,7 +1524,7 @@ sitd_urb_transaction (
1526 struct ehci_iso_stream *stream, 1524 struct ehci_iso_stream *stream,
1527 struct ehci_hcd *ehci, 1525 struct ehci_hcd *ehci,
1528 struct urb *urb, 1526 struct urb *urb,
1529 int mem_flags 1527 unsigned mem_flags
1530) 1528)
1531{ 1529{
1532 struct ehci_sitd *sitd; 1530 struct ehci_sitd *sitd;
@@ -1775,7 +1773,8 @@ sitd_complete (
1775} 1773}
1776 1774
1777 1775
1778static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1776static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
1777 unsigned mem_flags)
1779{ 1778{
1780 int status = -EINVAL; 1779 int status = -EINVAL;
1781 unsigned long flags; 1780 unsigned long flags;
@@ -1825,7 +1824,8 @@ done:
1825#else 1824#else
1826 1825
1827static inline int 1826static inline int
1828sitd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1827sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
1828 unsigned mem_flags)
1829{ 1829{
1830 ehci_dbg (ehci, "split iso support is disabled\n"); 1830 ehci_dbg (ehci, "split iso support is disabled\n");
1831 return -ENOSYS; 1831 return -ENOSYS;
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index d9883d774d3a..81f8f6b7fdce 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -463,7 +463,8 @@ static void etrax_usb_free_epid(int epid);
463 463
464static int etrax_remove_from_sb_list(struct urb *urb); 464static int etrax_remove_from_sb_list(struct urb *urb);
465 465
466static void* etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, int mem_flags, dma_addr_t *dma); 466static void* etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size,
467 unsigned mem_flags, dma_addr_t *dma);
467static void etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma); 468static void etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma);
468 469
469static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid); 470static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid);
@@ -476,7 +477,7 @@ static int etrax_usb_submit_ctrl_urb(struct urb *urb);
476static int etrax_usb_submit_intr_urb(struct urb *urb); 477static int etrax_usb_submit_intr_urb(struct urb *urb);
477static int etrax_usb_submit_isoc_urb(struct urb *urb); 478static int etrax_usb_submit_isoc_urb(struct urb *urb);
478 479
479static int etrax_usb_submit_urb(struct urb *urb, int mem_flags); 480static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags);
480static int etrax_usb_unlink_urb(struct urb *urb, int status); 481static int etrax_usb_unlink_urb(struct urb *urb, int status);
481static int etrax_usb_get_frame_number(struct usb_device *usb_dev); 482static int etrax_usb_get_frame_number(struct usb_device *usb_dev);
482 483
@@ -1262,7 +1263,7 @@ static int etrax_usb_allocate_epid(void)
1262 return -1; 1263 return -1;
1263} 1264}
1264 1265
1265static int etrax_usb_submit_urb(struct urb *urb, int mem_flags) 1266static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags)
1266{ 1267{
1267 etrax_hc_t *hc; 1268 etrax_hc_t *hc;
1268 int ret = -EINVAL; 1269 int ret = -EINVAL;
@@ -4277,7 +4278,8 @@ etrax_usb_bulk_eot_timer_func(unsigned long dummy)
4277} 4278}
4278 4279
4279static void* 4280static void*
4280etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, int mem_flags, dma_addr_t *dma) 4281etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size,
4282 unsigned mem_flags, dma_addr_t *dma)
4281{ 4283{
4282 return kmalloc(size, mem_flags); 4284 return kmalloc(size, mem_flags);
4283} 4285}
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
new file mode 100644
index 000000000000..50b1970fe6b6
--- /dev/null
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -0,0 +1,1871 @@
1/*
2 * ISP116x HCD (Host Controller Driver) for USB.
3 *
4 * Derived from the SL811 HCD, rewritten for ISP116x.
5 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
6 *
7 * Portions:
8 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
9 * Copyright (C) 2004 David Brownell
10 *
11 * Periodic scheduling is based on Roman's OHCI code
12 * Copyright (C) 1999 Roman Weissgaerber
13 *
14 */
15
16/*
17 * The driver basically works. A number of people have used it with a range
18 * of devices.
19 *
20 * The driver passes all usbtests 1-14.
21 *
22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
23 * And suspending/resuming of platform device works too. Suspend/resume
24 * via HCD operations vector is not implemented.
25 *
26 * Iso transfer support is not implemented. Adding this would include
27 * implementing recovery from the failure to service the processed ITL
28 * fifo ram in time, which will involve chip reset.
29 *
30 * TODO:
31 + More testing of suspend/resume.
32*/
33
34/*
35 ISP116x chips require certain delays between accesses to its
36 registers. The following timing options exist.
37
38 1. Configure your memory controller (the best)
39 2. Implement platform-specific delay function possibly
40 combined with configuring the memory controller; see
41 include/linux/usb-isp116x.h for more info. Some broken
42 memory controllers line LH7A400 SMC need this. Also,
43 uncomment for that to work the following
44 USE_PLATFORM_DELAY macro.
45 3. Use ndelay (easiest, poorest). For that, uncomment
46 the following USE_NDELAY macro.
47*/
48#define USE_PLATFORM_DELAY
49//#define USE_NDELAY
50
51//#define DEBUG
52//#define VERBOSE
53/* Transfer descriptors. See dump_ptd() for printout format */
54//#define PTD_TRACE
55/* enqueuing/finishing log of urbs */
56//#define URB_TRACE
57
58#include <linux/config.h>
59#include <linux/module.h>
60#include <linux/moduleparam.h>
61#include <linux/kernel.h>
62#include <linux/delay.h>
63#include <linux/ioport.h>
64#include <linux/sched.h>
65#include <linux/slab.h>
66#include <linux/smp_lock.h>
67#include <linux/errno.h>
68#include <linux/init.h>
69#include <linux/list.h>
70#include <linux/interrupt.h>
71#include <linux/usb.h>
72#include <linux/usb_isp116x.h>
73
74#include <asm/io.h>
75#include <asm/irq.h>
76#include <asm/system.h>
77#include <asm/byteorder.h>
78
79#ifndef DEBUG
80# define STUB_DEBUG_FILE
81#endif
82
83#include "../core/hcd.h"
84#include "isp116x.h"
85
86#define DRIVER_VERSION "08 Apr 2005"
87#define DRIVER_DESC "ISP116x USB Host Controller Driver"
88
89MODULE_DESCRIPTION(DRIVER_DESC);
90MODULE_LICENSE("GPL");
91
92static const char hcd_name[] = "isp116x-hcd";
93
94/*-----------------------------------------------------------------*/
95
96/*
97 Write len bytes to fifo, pad till 32-bit boundary
98 */
99static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
100{
101 u8 *dp = (u8 *) buf;
102 u16 *dp2 = (u16 *) buf;
103 u16 w;
104 int quot = len % 4;
105
106 if ((unsigned long)dp2 & 1) {
107 /* not aligned */
108 for (; len > 1; len -= 2) {
109 w = *dp++;
110 w |= *dp++ << 8;
111 isp116x_raw_write_data16(isp116x, w);
112 }
113 if (len)
114 isp116x_write_data16(isp116x, (u16) * dp);
115 } else {
116 /* aligned */
117 for (; len > 1; len -= 2)
118 isp116x_raw_write_data16(isp116x, *dp2++);
119 if (len)
120 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
121 }
122 if (quot == 1 || quot == 2)
123 isp116x_raw_write_data16(isp116x, 0);
124}
125
126/*
127 Read len bytes from fifo and then read till 32-bit boundary.
128 */
129static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
130{
131 u8 *dp = (u8 *) buf;
132 u16 *dp2 = (u16 *) buf;
133 u16 w;
134 int quot = len % 4;
135
136 if ((unsigned long)dp2 & 1) {
137 /* not aligned */
138 for (; len > 1; len -= 2) {
139 w = isp116x_raw_read_data16(isp116x);
140 *dp++ = w & 0xff;
141 *dp++ = (w >> 8) & 0xff;
142 }
143 if (len)
144 *dp = 0xff & isp116x_read_data16(isp116x);
145 } else {
146 /* aligned */
147 for (; len > 1; len -= 2)
148 *dp2++ = isp116x_raw_read_data16(isp116x);
149 if (len)
150 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
151 }
152 if (quot == 1 || quot == 2)
153 isp116x_raw_read_data16(isp116x);
154}
155
156/*
157 Write ptd's and data for scheduled transfers into
158 the fifo ram. Fifo must be empty and ready.
159*/
160static void pack_fifo(struct isp116x *isp116x)
161{
162 struct isp116x_ep *ep;
163 struct ptd *ptd;
164 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
165 ? isp116x->atl_bufshrt : isp116x->atl_buflen;
166 int ptd_count = 0;
167
168 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
169 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
170 isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
171 for (ep = isp116x->atl_active; ep; ep = ep->active) {
172 ++ptd_count;
173 ptd = &ep->ptd;
174 dump_ptd(ptd);
175 dump_ptd_out_data(ptd, ep->data);
176 isp116x_write_data16(isp116x, ptd->count);
177 isp116x_write_data16(isp116x, ptd->mps);
178 isp116x_write_data16(isp116x, ptd->len);
179 isp116x_write_data16(isp116x, ptd->faddr);
180 buflen -= sizeof(struct ptd);
181 /* Skip writing data for last IN PTD */
182 if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
183 write_ptddata_to_fifo(isp116x, ep->data, ep->length);
184 buflen -= ALIGN(ep->length, 4);
185 }
186 }
187 BUG_ON(buflen);
188}
189
190/*
191 Read the processed ptd's and data from fifo ram back to
192 URBs' buffers. Fifo must be full and done
193*/
194static void unpack_fifo(struct isp116x *isp116x)
195{
196 struct isp116x_ep *ep;
197 struct ptd *ptd;
198 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
199 ? isp116x->atl_buflen : isp116x->atl_bufshrt;
200
201 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
202 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
203 isp116x_write_addr(isp116x, HCATLPORT);
204 for (ep = isp116x->atl_active; ep; ep = ep->active) {
205 ptd = &ep->ptd;
206 ptd->count = isp116x_read_data16(isp116x);
207 ptd->mps = isp116x_read_data16(isp116x);
208 ptd->len = isp116x_read_data16(isp116x);
209 ptd->faddr = isp116x_read_data16(isp116x);
210 buflen -= sizeof(struct ptd);
211 /* Skip reading data for last Setup or Out PTD */
212 if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
213 read_ptddata_from_fifo(isp116x, ep->data, ep->length);
214 buflen -= ALIGN(ep->length, 4);
215 }
216 dump_ptd(ptd);
217 dump_ptd_in_data(ptd, ep->data);
218 }
219 BUG_ON(buflen);
220}
221
222/*---------------------------------------------------------------*/
223
224/*
225 Set up PTD's.
226*/
227static void preproc_atl_queue(struct isp116x *isp116x)
228{
229 struct isp116x_ep *ep;
230 struct urb *urb;
231 struct ptd *ptd;
232 u16 toggle = 0, dir = PTD_DIR_SETUP, len;
233
234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 BUG_ON(list_empty(&ep->hep->urb_list));
236 urb = container_of(ep->hep->urb_list.next,
237 struct urb, urb_list);
238 ptd = &ep->ptd;
239 len = ep->length;
240 spin_lock(&urb->lock);
241 ep->data = (unsigned char *)urb->transfer_buffer
242 + urb->actual_length;
243
244 switch (ep->nextpid) {
245 case USB_PID_IN:
246 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
247 dir = PTD_DIR_IN;
248 break;
249 case USB_PID_OUT:
250 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
251 dir = PTD_DIR_OUT;
252 break;
253 case USB_PID_SETUP:
254 len = sizeof(struct usb_ctrlrequest);
255 ep->data = urb->setup_packet;
256 break;
257 case USB_PID_ACK:
258 toggle = 1;
259 len = 0;
260 dir = (urb->transfer_buffer_length
261 && usb_pipein(urb->pipe))
262 ? PTD_DIR_OUT : PTD_DIR_IN;
263 break;
264 default:
265 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
266 ep->nextpid);
267 BUG();
268 }
269
270 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
271 ptd->mps = PTD_MPS(ep->maxpacket)
272 | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
273 | PTD_EP(ep->epnum);
274 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
275 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
276 spin_unlock(&urb->lock);
277 if (!ep->active) {
278 ptd->mps |= PTD_LAST_MSK;
279 isp116x->atl_last_dir = dir;
280 }
281 isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
282 isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
283 }
284}
285
286/*
287 Analyze transfer results, handle partial transfers and errors
288*/
289static void postproc_atl_queue(struct isp116x *isp116x)
290{
291 struct isp116x_ep *ep;
292 struct urb *urb;
293 struct usb_device *udev;
294 struct ptd *ptd;
295 int short_not_ok;
296 u8 cc;
297
298 for (ep = isp116x->atl_active; ep; ep = ep->active) {
299 BUG_ON(list_empty(&ep->hep->urb_list));
300 urb =
301 container_of(ep->hep->urb_list.next, struct urb, urb_list);
302 udev = urb->dev;
303 ptd = &ep->ptd;
304 cc = PTD_GET_CC(ptd);
305
306 spin_lock(&urb->lock);
307 short_not_ok = 1;
308
309 /* Data underrun is special. For allowed underrun
310 we clear the error and continue as normal. For
311 forbidden underrun we finish the DATA stage
312 immediately while for control transfer,
313 we do a STATUS stage. */
314 if (cc == TD_DATAUNDERRUN) {
315 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
316 DBG("Allowed data underrun\n");
317 cc = TD_CC_NOERROR;
318 short_not_ok = 0;
319 } else {
320 ep->error_count = 1;
321 if (usb_pipecontrol(urb->pipe))
322 ep->nextpid = USB_PID_ACK;
323 else
324 usb_settoggle(udev, ep->epnum,
325 ep->nextpid ==
326 USB_PID_OUT,
327 PTD_GET_TOGGLE(ptd) ^ 1);
328 urb->status = cc_to_error[TD_DATAUNDERRUN];
329 spin_unlock(&urb->lock);
330 continue;
331 }
332 }
333 /* Keep underrun error through the STATUS stage */
334 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
335 cc = TD_DATAUNDERRUN;
336
337 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
338 && (++ep->error_count >= 3 || cc == TD_CC_STALL
339 || cc == TD_DATAOVERRUN)) {
340 if (urb->status == -EINPROGRESS)
341 urb->status = cc_to_error[cc];
342 if (ep->nextpid == USB_PID_ACK)
343 ep->nextpid = 0;
344 spin_unlock(&urb->lock);
345 continue;
346 }
347 /* According to usb spec, zero-length Int transfer signals
348 finishing of the urb. Hey, does this apply only
349 for IN endpoints? */
350 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
351 if (urb->status == -EINPROGRESS)
352 urb->status = 0;
353 spin_unlock(&urb->lock);
354 continue;
355 }
356
357 /* Relax after previously failed, but later succeeded
358 or correctly NAK'ed retransmission attempt */
359 if (ep->error_count
360 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
361 ep->error_count = 0;
362
363 /* Take into account idiosyncracies of the isp116x chip
364 regarding toggle bit for failed transfers */
365 if (ep->nextpid == USB_PID_OUT)
366 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
367 ^ (ep->error_count > 0));
368 else if (ep->nextpid == USB_PID_IN)
369 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
370 ^ (ep->error_count > 0));
371
372 switch (ep->nextpid) {
373 case USB_PID_IN:
374 case USB_PID_OUT:
375 urb->actual_length += PTD_GET_COUNT(ptd);
376 if (PTD_GET_ACTIVE(ptd)
377 || (cc != TD_CC_NOERROR && cc < 0x0E))
378 break;
379 if (urb->transfer_buffer_length != urb->actual_length) {
380 if (short_not_ok)
381 break;
382 } else {
383 if (urb->transfer_flags & URB_ZERO_PACKET
384 && ep->nextpid == USB_PID_OUT
385 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
386 DBG("Zero packet requested\n");
387 break;
388 }
389 }
390 /* All data for this URB is transferred, let's finish */
391 if (usb_pipecontrol(urb->pipe))
392 ep->nextpid = USB_PID_ACK;
393 else if (urb->status == -EINPROGRESS)
394 urb->status = 0;
395 break;
396 case USB_PID_SETUP:
397 if (PTD_GET_ACTIVE(ptd)
398 || (cc != TD_CC_NOERROR && cc < 0x0E))
399 break;
400 if (urb->transfer_buffer_length == urb->actual_length)
401 ep->nextpid = USB_PID_ACK;
402 else if (usb_pipeout(urb->pipe)) {
403 usb_settoggle(udev, 0, 1, 1);
404 ep->nextpid = USB_PID_OUT;
405 } else {
406 usb_settoggle(udev, 0, 0, 1);
407 ep->nextpid = USB_PID_IN;
408 }
409 break;
410 case USB_PID_ACK:
411 if (PTD_GET_ACTIVE(ptd)
412 || (cc != TD_CC_NOERROR && cc < 0x0E))
413 break;
414 if (urb->status == -EINPROGRESS)
415 urb->status = 0;
416 ep->nextpid = 0;
417 break;
418 default:
419 BUG_ON(1);
420 }
421 spin_unlock(&urb->lock);
422 }
423}
424
425/*
426 Take done or failed requests out of schedule. Give back
427 processed urbs.
428*/
429static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
430 struct urb *urb, struct pt_regs *regs)
431__releases(isp116x->lock) __acquires(isp116x->lock)
432{
433 unsigned i;
434
435 urb->hcpriv = NULL;
436 ep->error_count = 0;
437
438 if (usb_pipecontrol(urb->pipe))
439 ep->nextpid = USB_PID_SETUP;
440
441 urb_dbg(urb, "Finish");
442
443 spin_unlock(&isp116x->lock);
444 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
445 spin_lock(&isp116x->lock);
446
447 /* take idle endpoints out of the schedule */
448 if (!list_empty(&ep->hep->urb_list))
449 return;
450
451 /* async deschedule */
452 if (!list_empty(&ep->schedule)) {
453 list_del_init(&ep->schedule);
454 return;
455 }
456
457 /* periodic deschedule */
458 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
459 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
460 struct isp116x_ep *temp;
461 struct isp116x_ep **prev = &isp116x->periodic[i];
462
463 while (*prev && ((temp = *prev) != ep))
464 prev = &temp->next;
465 if (*prev)
466 *prev = ep->next;
467 isp116x->load[i] -= ep->load;
468 }
469 ep->branch = PERIODIC_SIZE;
470 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
471 ep->load / ep->period;
472
473 /* switch irq type? */
474 if (!--isp116x->periodic_count) {
475 isp116x->irqenb &= ~HCuPINT_SOF;
476 isp116x->irqenb |= HCuPINT_ATL;
477 }
478}
479
480/*
481 Scan transfer lists, schedule transfers, send data off
482 to chip.
483 */
484static void start_atl_transfers(struct isp116x *isp116x)
485{
486 struct isp116x_ep *last_ep = NULL, *ep;
487 struct urb *urb;
488 u16 load = 0;
489 int len, index, speed, byte_time;
490
491 if (atomic_read(&isp116x->atl_finishing))
492 return;
493
494 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
495 return;
496
497 /* FIFO not empty? */
498 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
499 return;
500
501 isp116x->atl_active = NULL;
502 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
503
504 /* Schedule int transfers */
505 if (isp116x->periodic_count) {
506 isp116x->fmindex = index =
507 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
508 if ((load = isp116x->load[index])) {
509 /* Bring all int transfers for this frame
510 into the active queue */
511 isp116x->atl_active = last_ep =
512 isp116x->periodic[index];
513 while (last_ep->next)
514 last_ep = (last_ep->active = last_ep->next);
515 last_ep->active = NULL;
516 }
517 }
518
519 /* Schedule control/bulk transfers */
520 list_for_each_entry(ep, &isp116x->async, schedule) {
521 urb = container_of(ep->hep->urb_list.next,
522 struct urb, urb_list);
523 speed = urb->dev->speed;
524 byte_time = speed == USB_SPEED_LOW
525 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
526
527 if (ep->nextpid == USB_PID_SETUP) {
528 len = sizeof(struct usb_ctrlrequest);
529 } else if (ep->nextpid == USB_PID_ACK) {
530 len = 0;
531 } else {
532 /* Find current free length ... */
533 len = (MAX_LOAD_LIMIT - load) / byte_time;
534
535 /* ... then limit it to configured max size ... */
536 len = min(len, speed == USB_SPEED_LOW ?
537 MAX_TRANSFER_SIZE_LOWSPEED :
538 MAX_TRANSFER_SIZE_FULLSPEED);
539
540 /* ... and finally cut to the multiple of MaxPacketSize,
541 or to the real length if there's enough room. */
542 if (len <
543 (urb->transfer_buffer_length -
544 urb->actual_length)) {
545 len -= len % ep->maxpacket;
546 if (!len)
547 continue;
548 } else
549 len = urb->transfer_buffer_length -
550 urb->actual_length;
551 BUG_ON(len < 0);
552 }
553
554 load += len * byte_time;
555 if (load > MAX_LOAD_LIMIT)
556 break;
557
558 ep->active = NULL;
559 ep->length = len;
560 if (last_ep)
561 last_ep->active = ep;
562 else
563 isp116x->atl_active = ep;
564 last_ep = ep;
565 }
566
567 /* Avoid starving of endpoints */
568 if ((&isp116x->async)->next != (&isp116x->async)->prev)
569 list_move(&isp116x->async, (&isp116x->async)->next);
570
571 if (isp116x->atl_active) {
572 preproc_atl_queue(isp116x);
573 pack_fifo(isp116x);
574 }
575}
576
577/*
578 Finish the processed transfers
579*/
580static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
581{
582 struct isp116x_ep *ep;
583 struct urb *urb;
584
585 if (!isp116x->atl_active)
586 return;
587 /* Fifo not ready? */
588 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
589 return;
590
591 atomic_inc(&isp116x->atl_finishing);
592 unpack_fifo(isp116x);
593 postproc_atl_queue(isp116x);
594 for (ep = isp116x->atl_active; ep; ep = ep->active) {
595 urb =
596 container_of(ep->hep->urb_list.next, struct urb, urb_list);
597 /* USB_PID_ACK check here avoids finishing of
598 control transfers, for which TD_DATAUNDERRUN
599 occured, while URB_SHORT_NOT_OK was set */
600 if (urb && urb->status != -EINPROGRESS
601 && ep->nextpid != USB_PID_ACK)
602 finish_request(isp116x, ep, urb, regs);
603 }
604 atomic_dec(&isp116x->atl_finishing);
605}
606
607static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
608{
609 struct isp116x *isp116x = hcd_to_isp116x(hcd);
610 u16 irqstat;
611 irqreturn_t ret = IRQ_NONE;
612
613 spin_lock(&isp116x->lock);
614 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
615 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
616 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
617
618 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
619 ret = IRQ_HANDLED;
620 finish_atl_transfers(isp116x, regs);
621 }
622
623 if (irqstat & HCuPINT_OPR) {
624 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
625 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
626 if (intstat & HCINT_UE) {
627 ERR("Unrecoverable error\n");
628 /* What should we do here? Reset? */
629 }
630 if (intstat & HCINT_RHSC) {
631 isp116x->rhstatus =
632 isp116x_read_reg32(isp116x, HCRHSTATUS);
633 isp116x->rhport[0] =
634 isp116x_read_reg32(isp116x, HCRHPORT1);
635 isp116x->rhport[1] =
636 isp116x_read_reg32(isp116x, HCRHPORT2);
637 }
638 if (intstat & HCINT_RD) {
639 DBG("---- remote wakeup\n");
640 schedule_work(&isp116x->rh_resume);
641 ret = IRQ_HANDLED;
642 }
643 irqstat &= ~HCuPINT_OPR;
644 ret = IRQ_HANDLED;
645 }
646
647 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
648 start_atl_transfers(isp116x);
649 }
650
651 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
652 spin_unlock(&isp116x->lock);
653 return ret;
654}
655
656/*-----------------------------------------------------------------*/
657
658/* usb 1.1 says max 90% of a frame is available for periodic transfers.
659 * this driver doesn't promise that much since it's got to handle an
660 * IRQ per packet; irq handling latencies also use up that time.
661 */
662
663/* out of 1000 us */
664#define MAX_PERIODIC_LOAD 600
665static int balance(struct isp116x *isp116x, u16 period, u16 load)
666{
667 int i, branch = -ENOSPC;
668
669 /* search for the least loaded schedule branch of that period
670 which has enough bandwidth left unreserved. */
671 for (i = 0; i < period; i++) {
672 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
673 int j;
674
675 for (j = i; j < PERIODIC_SIZE; j += period) {
676 if ((isp116x->load[j] + load)
677 > MAX_PERIODIC_LOAD)
678 break;
679 }
680 if (j < PERIODIC_SIZE)
681 continue;
682 branch = i;
683 }
684 }
685 return branch;
686}
687
688/* NB! ALL the code above this point runs with isp116x->lock
689 held, irqs off
690*/
691
692/*-----------------------------------------------------------------*/
693
694static int isp116x_urb_enqueue(struct usb_hcd *hcd,
695 struct usb_host_endpoint *hep, struct urb *urb,
696 unsigned mem_flags)
697{
698 struct isp116x *isp116x = hcd_to_isp116x(hcd);
699 struct usb_device *udev = urb->dev;
700 unsigned int pipe = urb->pipe;
701 int is_out = !usb_pipein(pipe);
702 int type = usb_pipetype(pipe);
703 int epnum = usb_pipeendpoint(pipe);
704 struct isp116x_ep *ep = NULL;
705 unsigned long flags;
706 int i;
707 int ret = 0;
708
709 urb_dbg(urb, "Enqueue");
710
711 if (type == PIPE_ISOCHRONOUS) {
712 ERR("Isochronous transfers not supported\n");
713 urb_dbg(urb, "Refused to enqueue");
714 return -ENXIO;
715 }
716 /* avoid all allocations within spinlocks: request or endpoint */
717 if (!hep->hcpriv) {
718 ep = kcalloc(1, sizeof *ep, mem_flags);
719 if (!ep)
720 return -ENOMEM;
721 }
722
723 spin_lock_irqsave(&isp116x->lock, flags);
724 if (!HC_IS_RUNNING(hcd->state)) {
725 ret = -ENODEV;
726 goto fail;
727 }
728
729 if (hep->hcpriv)
730 ep = hep->hcpriv;
731 else {
732 INIT_LIST_HEAD(&ep->schedule);
733 ep->udev = usb_get_dev(udev);
734 ep->epnum = epnum;
735 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
736 usb_settoggle(udev, epnum, is_out, 0);
737
738 if (type == PIPE_CONTROL) {
739 ep->nextpid = USB_PID_SETUP;
740 } else if (is_out) {
741 ep->nextpid = USB_PID_OUT;
742 } else {
743 ep->nextpid = USB_PID_IN;
744 }
745
746 if (urb->interval) {
747 /*
748 With INT URBs submitted, the driver works with SOF
749 interrupt enabled and ATL interrupt disabled. After
750 the PTDs are written to fifo ram, the chip starts
751 fifo processing and usb transfers after the next
752 SOF and continues until the transfers are finished
753 (succeeded or failed) or the frame ends. Therefore,
754 the transfers occur only in every second frame,
755 while fifo reading/writing and data processing
756 occur in every other second frame. */
757 if (urb->interval < 2)
758 urb->interval = 2;
759 if (urb->interval > 2 * PERIODIC_SIZE)
760 urb->interval = 2 * PERIODIC_SIZE;
761 ep->period = urb->interval >> 1;
762 ep->branch = PERIODIC_SIZE;
763 ep->load = usb_calc_bus_time(udev->speed,
764 !is_out,
765 (type == PIPE_ISOCHRONOUS),
766 usb_maxpacket(udev, pipe,
767 is_out)) /
768 1000;
769 }
770 hep->hcpriv = ep;
771 ep->hep = hep;
772 }
773
774 /* maybe put endpoint into schedule */
775 switch (type) {
776 case PIPE_CONTROL:
777 case PIPE_BULK:
778 if (list_empty(&ep->schedule))
779 list_add_tail(&ep->schedule, &isp116x->async);
780 break;
781 case PIPE_INTERRUPT:
782 urb->interval = ep->period;
783 ep->length = min((int)ep->maxpacket,
784 urb->transfer_buffer_length);
785
786 /* urb submitted for already existing endpoint */
787 if (ep->branch < PERIODIC_SIZE)
788 break;
789
790 ret = ep->branch = balance(isp116x, ep->period, ep->load);
791 if (ret < 0)
792 goto fail;
793 ret = 0;
794
795 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
796 + ep->branch;
797
798 /* sort each schedule branch by period (slow before fast)
799 to share the faster parts of the tree without needing
800 dummy/placeholder nodes */
801 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
802 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
803 struct isp116x_ep **prev = &isp116x->periodic[i];
804 struct isp116x_ep *here = *prev;
805
806 while (here && ep != here) {
807 if (ep->period > here->period)
808 break;
809 prev = &here->next;
810 here = *prev;
811 }
812 if (ep != here) {
813 ep->next = here;
814 *prev = ep;
815 }
816 isp116x->load[i] += ep->load;
817 }
818 hcd->self.bandwidth_allocated += ep->load / ep->period;
819
820 /* switch over to SOFint */
821 if (!isp116x->periodic_count++) {
822 isp116x->irqenb &= ~HCuPINT_ATL;
823 isp116x->irqenb |= HCuPINT_SOF;
824 isp116x_write_reg16(isp116x, HCuPINTENB,
825 isp116x->irqenb);
826 }
827 }
828
829 /* in case of unlink-during-submit */
830 spin_lock(&urb->lock);
831 if (urb->status != -EINPROGRESS) {
832 spin_unlock(&urb->lock);
833 finish_request(isp116x, ep, urb, NULL);
834 ret = 0;
835 goto fail;
836 }
837 urb->hcpriv = hep;
838 spin_unlock(&urb->lock);
839 start_atl_transfers(isp116x);
840
841 fail:
842 spin_unlock_irqrestore(&isp116x->lock, flags);
843 return ret;
844}
845
846/*
847 Dequeue URBs.
848*/
849static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
850{
851 struct isp116x *isp116x = hcd_to_isp116x(hcd);
852 struct usb_host_endpoint *hep;
853 struct isp116x_ep *ep, *ep_act;
854 unsigned long flags;
855
856 spin_lock_irqsave(&isp116x->lock, flags);
857 hep = urb->hcpriv;
858 /* URB already unlinked (or never linked)? */
859 if (!hep) {
860 spin_unlock_irqrestore(&isp116x->lock, flags);
861 return 0;
862 }
863 ep = hep->hcpriv;
864 WARN_ON(hep != ep->hep);
865
866 /* In front of queue? */
867 if (ep->hep->urb_list.next == &urb->urb_list)
868 /* active? */
869 for (ep_act = isp116x->atl_active; ep_act;
870 ep_act = ep_act->active)
871 if (ep_act == ep) {
872 VDBG("dequeue, urb %p active; wait for irq\n",
873 urb);
874 urb = NULL;
875 break;
876 }
877
878 if (urb)
879 finish_request(isp116x, ep, urb, NULL);
880
881 spin_unlock_irqrestore(&isp116x->lock, flags);
882 return 0;
883}
884
885static void isp116x_endpoint_disable(struct usb_hcd *hcd,
886 struct usb_host_endpoint *hep)
887{
888 int i;
889 struct isp116x_ep *ep = hep->hcpriv;;
890
891 if (!ep)
892 return;
893
894 /* assume we'd just wait for the irq */
895 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
896 msleep(3);
897 if (!list_empty(&hep->urb_list))
898 WARN("ep %p not empty?\n", ep);
899
900 usb_put_dev(ep->udev);
901 kfree(ep);
902 hep->hcpriv = NULL;
903}
904
905static int isp116x_get_frame(struct usb_hcd *hcd)
906{
907 struct isp116x *isp116x = hcd_to_isp116x(hcd);
908 u32 fmnum;
909 unsigned long flags;
910
911 spin_lock_irqsave(&isp116x->lock, flags);
912 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
913 spin_unlock_irqrestore(&isp116x->lock, flags);
914 return (int)fmnum;
915}
916
917/*----------------------------------------------------------------*/
918
919/*
920 Adapted from ohci-hub.c. Currently we don't support autosuspend.
921*/
922static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
923{
924 struct isp116x *isp116x = hcd_to_isp116x(hcd);
925 int ports, i, changed = 0;
926
927 if (!HC_IS_RUNNING(hcd->state))
928 return -ESHUTDOWN;
929
930 ports = isp116x->rhdesca & RH_A_NDP;
931
932 /* init status */
933 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
934 buf[0] = changed = 1;
935 else
936 buf[0] = 0;
937
938 for (i = 0; i < ports; i++) {
939 u32 status = isp116x->rhport[i];
940
941 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
942 | RH_PS_OCIC | RH_PS_PRSC)) {
943 changed = 1;
944 buf[0] |= 1 << (i + 1);
945 continue;
946 }
947 }
948 return changed;
949}
950
951static void isp116x_hub_descriptor(struct isp116x *isp116x,
952 struct usb_hub_descriptor *desc)
953{
954 u32 reg = isp116x->rhdesca;
955
956 desc->bDescriptorType = 0x29;
957 desc->bDescLength = 9;
958 desc->bHubContrCurrent = 0;
959 desc->bNbrPorts = (u8) (reg & 0x3);
960 /* Power switching, device type, overcurrent. */
961 desc->wHubCharacteristics =
962 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
963 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
964 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
965 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
966 desc->bitmap[1] = ~0;
967}
968
969/* Perform reset of a given port.
970 It would be great to just start the reset and let the
971 USB core to clear the reset in due time. However,
972 root hub ports should be reset for at least 50 ms, while
973 our chip stays in reset for about 10 ms. I.e., we must
974 repeatedly reset it ourself here.
975*/
976static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
977{
978 u32 tmp;
979 unsigned long flags, t;
980
981 /* Root hub reset should be 50 ms, but some devices
982 want it even longer. */
983 t = jiffies + msecs_to_jiffies(100);
984
985 while (time_before(jiffies, t)) {
986 spin_lock_irqsave(&isp116x->lock, flags);
987 /* spin until any current reset finishes */
988 for (;;) {
989 tmp = isp116x_read_reg32(isp116x, port ?
990 HCRHPORT2 : HCRHPORT1);
991 if (!(tmp & RH_PS_PRS))
992 break;
993 udelay(500);
994 }
995 /* Don't reset a disconnected port */
996 if (!(tmp & RH_PS_CCS)) {
997 spin_unlock_irqrestore(&isp116x->lock, flags);
998 break;
999 }
1000 /* Reset lasts 10ms (claims datasheet) */
1001 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1002 HCRHPORT1, (RH_PS_PRS));
1003 spin_unlock_irqrestore(&isp116x->lock, flags);
1004 msleep(10);
1005 }
1006}
1007
1008/* Adapted from ohci-hub.c */
1009static int isp116x_hub_control(struct usb_hcd *hcd,
1010 u16 typeReq,
1011 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1012{
1013 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1014 int ret = 0;
1015 unsigned long flags;
1016 int ports = isp116x->rhdesca & RH_A_NDP;
1017 u32 tmp = 0;
1018
1019 switch (typeReq) {
1020 case ClearHubFeature:
1021 DBG("ClearHubFeature: ");
1022 switch (wValue) {
1023 case C_HUB_OVER_CURRENT:
1024 DBG("C_HUB_OVER_CURRENT\n");
1025 spin_lock_irqsave(&isp116x->lock, flags);
1026 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1027 spin_unlock_irqrestore(&isp116x->lock, flags);
1028 case C_HUB_LOCAL_POWER:
1029 DBG("C_HUB_LOCAL_POWER\n");
1030 break;
1031 default:
1032 goto error;
1033 }
1034 break;
1035 case SetHubFeature:
1036 DBG("SetHubFeature: ");
1037 switch (wValue) {
1038 case C_HUB_OVER_CURRENT:
1039 case C_HUB_LOCAL_POWER:
1040 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1041 break;
1042 default:
1043 goto error;
1044 }
1045 break;
1046 case GetHubDescriptor:
1047 DBG("GetHubDescriptor\n");
1048 isp116x_hub_descriptor(isp116x,
1049 (struct usb_hub_descriptor *)buf);
1050 break;
1051 case GetHubStatus:
1052 DBG("GetHubStatus\n");
1053 *(__le32 *) buf = 0;
1054 break;
1055 case GetPortStatus:
1056 DBG("GetPortStatus\n");
1057 if (!wIndex || wIndex > ports)
1058 goto error;
1059 tmp = isp116x->rhport[--wIndex];
1060 *(__le32 *) buf = cpu_to_le32(tmp);
1061 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1062 break;
1063 case ClearPortFeature:
1064 DBG("ClearPortFeature: ");
1065 if (!wIndex || wIndex > ports)
1066 goto error;
1067 wIndex--;
1068
1069 switch (wValue) {
1070 case USB_PORT_FEAT_ENABLE:
1071 DBG("USB_PORT_FEAT_ENABLE\n");
1072 tmp = RH_PS_CCS;
1073 break;
1074 case USB_PORT_FEAT_C_ENABLE:
1075 DBG("USB_PORT_FEAT_C_ENABLE\n");
1076 tmp = RH_PS_PESC;
1077 break;
1078 case USB_PORT_FEAT_SUSPEND:
1079 DBG("USB_PORT_FEAT_SUSPEND\n");
1080 tmp = RH_PS_POCI;
1081 break;
1082 case USB_PORT_FEAT_C_SUSPEND:
1083 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1084 tmp = RH_PS_PSSC;
1085 break;
1086 case USB_PORT_FEAT_POWER:
1087 DBG("USB_PORT_FEAT_POWER\n");
1088 tmp = RH_PS_LSDA;
1089 break;
1090 case USB_PORT_FEAT_C_CONNECTION:
1091 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1092 tmp = RH_PS_CSC;
1093 break;
1094 case USB_PORT_FEAT_C_OVER_CURRENT:
1095 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1096 tmp = RH_PS_OCIC;
1097 break;
1098 case USB_PORT_FEAT_C_RESET:
1099 DBG("USB_PORT_FEAT_C_RESET\n");
1100 tmp = RH_PS_PRSC;
1101 break;
1102 default:
1103 goto error;
1104 }
1105 spin_lock_irqsave(&isp116x->lock, flags);
1106 isp116x_write_reg32(isp116x, wIndex
1107 ? HCRHPORT2 : HCRHPORT1, tmp);
1108 isp116x->rhport[wIndex] =
1109 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1110 spin_unlock_irqrestore(&isp116x->lock, flags);
1111 break;
1112 case SetPortFeature:
1113 DBG("SetPortFeature: ");
1114 if (!wIndex || wIndex > ports)
1115 goto error;
1116 wIndex--;
1117 switch (wValue) {
1118 case USB_PORT_FEAT_SUSPEND:
1119 DBG("USB_PORT_FEAT_SUSPEND\n");
1120 spin_lock_irqsave(&isp116x->lock, flags);
1121 isp116x_write_reg32(isp116x, wIndex
1122 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1123 break;
1124 case USB_PORT_FEAT_POWER:
1125 DBG("USB_PORT_FEAT_POWER\n");
1126 spin_lock_irqsave(&isp116x->lock, flags);
1127 isp116x_write_reg32(isp116x, wIndex
1128 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1129 break;
1130 case USB_PORT_FEAT_RESET:
1131 DBG("USB_PORT_FEAT_RESET\n");
1132 root_port_reset(isp116x, wIndex);
1133 spin_lock_irqsave(&isp116x->lock, flags);
1134 break;
1135 default:
1136 goto error;
1137 }
1138 isp116x->rhport[wIndex] =
1139 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1140 spin_unlock_irqrestore(&isp116x->lock, flags);
1141 break;
1142
1143 default:
1144 error:
1145 /* "protocol stall" on error */
1146 DBG("PROTOCOL STALL\n");
1147 ret = -EPIPE;
1148 }
1149 return ret;
1150}
1151
1152#ifdef CONFIG_PM
1153
1154static int isp116x_hub_suspend(struct usb_hcd *hcd)
1155{
1156 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1157 unsigned long flags;
1158 u32 val;
1159 int ret = 0;
1160
1161 spin_lock_irqsave(&isp116x->lock, flags);
1162
1163 val = isp116x_read_reg32(isp116x, HCCONTROL);
1164 switch (val & HCCONTROL_HCFS) {
1165 case HCCONTROL_USB_OPER:
1166 hcd->state = HC_STATE_QUIESCING;
1167 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1168 val |= HCCONTROL_USB_SUSPEND;
1169 if (hcd->remote_wakeup)
1170 val |= HCCONTROL_RWE;
1171 /* Wait for usb transfers to finish */
1172 mdelay(2);
1173 isp116x_write_reg32(isp116x, HCCONTROL, val);
1174 hcd->state = HC_STATE_SUSPENDED;
1175 /* Wait for devices to suspend */
1176 mdelay(5);
1177 case HCCONTROL_USB_SUSPEND:
1178 break;
1179 case HCCONTROL_USB_RESUME:
1180 isp116x_write_reg32(isp116x, HCCONTROL,
1181 (val & ~HCCONTROL_HCFS) |
1182 HCCONTROL_USB_RESET);
1183 case HCCONTROL_USB_RESET:
1184 ret = -EBUSY;
1185 break;
1186 default:
1187 ret = -EINVAL;
1188 }
1189
1190 spin_unlock_irqrestore(&isp116x->lock, flags);
1191 return ret;
1192}
1193
1194static int isp116x_hub_resume(struct usb_hcd *hcd)
1195{
1196 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1197 u32 val;
1198 int ret = -EINPROGRESS;
1199
1200 msleep(5);
1201 spin_lock_irq(&isp116x->lock);
1202
1203 val = isp116x_read_reg32(isp116x, HCCONTROL);
1204 switch (val & HCCONTROL_HCFS) {
1205 case HCCONTROL_USB_SUSPEND:
1206 val &= ~HCCONTROL_HCFS;
1207 val |= HCCONTROL_USB_RESUME;
1208 isp116x_write_reg32(isp116x, HCCONTROL, val);
1209 case HCCONTROL_USB_RESUME:
1210 break;
1211 case HCCONTROL_USB_OPER:
1212 /* Without setting power_state here the
1213 SUSPENDED state won't be removed from
1214 sysfs/usbN/power.state as a response to remote
1215 wakeup. Maybe in the future. */
1216 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1217 ret = 0;
1218 break;
1219 default:
1220 ret = -EBUSY;
1221 }
1222
1223 if (ret != -EINPROGRESS) {
1224 spin_unlock_irq(&isp116x->lock);
1225 return ret;
1226 }
1227
1228 val = isp116x->rhdesca & RH_A_NDP;
1229 while (val--) {
1230 u32 stat =
1231 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1232 /* force global, not selective, resume */
1233 if (!(stat & RH_PS_PSS))
1234 continue;
1235 DBG("%s: Resuming port %d\n", __func__, val);
1236 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1237 ? HCRHPORT2 : HCRHPORT1);
1238 }
1239 spin_unlock_irq(&isp116x->lock);
1240
1241 hcd->state = HC_STATE_RESUMING;
1242 mdelay(20);
1243
1244 /* Go operational */
1245 spin_lock_irq(&isp116x->lock);
1246 val = isp116x_read_reg32(isp116x, HCCONTROL);
1247 isp116x_write_reg32(isp116x, HCCONTROL,
1248 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1249 spin_unlock_irq(&isp116x->lock);
1250 /* see analogous comment above */
1251 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1252 hcd->state = HC_STATE_RUNNING;
1253
1254 return 0;
1255}
1256
1257static void isp116x_rh_resume(void *_hcd)
1258{
1259 struct usb_hcd *hcd = _hcd;
1260
1261 usb_resume_device(hcd->self.root_hub);
1262}
1263
1264#else
1265
1266#define isp116x_hub_suspend NULL
1267#define isp116x_hub_resume NULL
1268
1269static void isp116x_rh_resume(void *_hcd)
1270{
1271}
1272
1273#endif
1274
1275/*-----------------------------------------------------------------*/
1276
1277#ifdef STUB_DEBUG_FILE
1278
1279static inline void create_debug_file(struct isp116x *isp116x)
1280{
1281}
1282
1283static inline void remove_debug_file(struct isp116x *isp116x)
1284{
1285}
1286
1287#else
1288
1289#include <linux/proc_fs.h>
1290#include <linux/seq_file.h>
1291
1292static void dump_irq(struct seq_file *s, char *label, u16 mask)
1293{
1294 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1295 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1296 mask & HCuPINT_SUSP ? " susp" : "",
1297 mask & HCuPINT_OPR ? " opr" : "",
1298 mask & HCuPINT_AIIEOT ? " eot" : "",
1299 mask & HCuPINT_ATL ? " atl" : "",
1300 mask & HCuPINT_SOF ? " sof" : "");
1301}
1302
1303static void dump_int(struct seq_file *s, char *label, u32 mask)
1304{
1305 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1306 mask & HCINT_MIE ? " MIE" : "",
1307 mask & HCINT_RHSC ? " rhsc" : "",
1308 mask & HCINT_FNO ? " fno" : "",
1309 mask & HCINT_UE ? " ue" : "",
1310 mask & HCINT_RD ? " rd" : "",
1311 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1312}
1313
1314static int proc_isp116x_show(struct seq_file *s, void *unused)
1315{
1316 struct isp116x *isp116x = s->private;
1317 struct isp116x_ep *ep;
1318 struct urb *urb;
1319 unsigned i;
1320 char *str;
1321
1322 seq_printf(s, "%s\n%s version %s\n",
1323 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1324 DRIVER_VERSION);
1325
1326 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1327 seq_printf(s, "HCD is suspended\n");
1328 return 0;
1329 }
1330 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1331 seq_printf(s, "HCD not running\n");
1332 return 0;
1333 }
1334
1335 spin_lock_irq(&isp116x->lock);
1336
1337 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1338 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1339 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1340 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1341
1342 list_for_each_entry(ep, &isp116x->async, schedule) {
1343
1344 switch (ep->nextpid) {
1345 case USB_PID_IN:
1346 str = "in";
1347 break;
1348 case USB_PID_OUT:
1349 str = "out";
1350 break;
1351 case USB_PID_SETUP:
1352 str = "setup";
1353 break;
1354 case USB_PID_ACK:
1355 str = "status";
1356 break;
1357 default:
1358 str = "?";
1359 break;
1360 };
1361 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1362 ep->epnum, str, ep->maxpacket);
1363 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1364 seq_printf(s, " urb%p, %d/%d\n", urb,
1365 urb->actual_length,
1366 urb->transfer_buffer_length);
1367 }
1368 }
1369 if (!list_empty(&isp116x->async))
1370 seq_printf(s, "\n");
1371
1372 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1373
1374 for (i = 0; i < PERIODIC_SIZE; i++) {
1375 ep = isp116x->periodic[i];
1376 if (!ep)
1377 continue;
1378 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1379
1380 /* DUMB: prints shared entries multiple times */
1381 do {
1382 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1383 ep->period, ep,
1384 (ep->udev->speed ==
1385 USB_SPEED_FULL) ? "" : "ls ",
1386 ep->udev->devnum, ep->epnum,
1387 (ep->epnum ==
1388 0) ? "" : ((ep->nextpid ==
1389 USB_PID_IN) ? "in" : "out"),
1390 ep->maxpacket);
1391 ep = ep->next;
1392 } while (ep);
1393 }
1394 spin_unlock_irq(&isp116x->lock);
1395 seq_printf(s, "\n");
1396
1397 return 0;
1398}
1399
1400static int proc_isp116x_open(struct inode *inode, struct file *file)
1401{
1402 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1403}
1404
1405static struct file_operations proc_ops = {
1406 .open = proc_isp116x_open,
1407 .read = seq_read,
1408 .llseek = seq_lseek,
1409 .release = single_release,
1410};
1411
1412/* expect just one isp116x per system */
1413static const char proc_filename[] = "driver/isp116x";
1414
1415static void create_debug_file(struct isp116x *isp116x)
1416{
1417 struct proc_dir_entry *pde;
1418
1419 pde = create_proc_entry(proc_filename, 0, NULL);
1420 if (pde == NULL)
1421 return;
1422
1423 pde->proc_fops = &proc_ops;
1424 pde->data = isp116x;
1425 isp116x->pde = pde;
1426}
1427
1428static void remove_debug_file(struct isp116x *isp116x)
1429{
1430 if (isp116x->pde)
1431 remove_proc_entry(proc_filename, NULL);
1432}
1433
1434#endif
1435
1436/*-----------------------------------------------------------------*/
1437
1438/*
1439 Software reset - can be called from any contect.
1440*/
1441static int isp116x_sw_reset(struct isp116x *isp116x)
1442{
1443 int retries = 15;
1444 unsigned long flags;
1445 int ret = 0;
1446
1447 spin_lock_irqsave(&isp116x->lock, flags);
1448 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1449 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1450 while (--retries) {
1451 /* It usually resets within 1 ms */
1452 mdelay(1);
1453 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1454 break;
1455 }
1456 if (!retries) {
1457 ERR("Software reset timeout\n");
1458 ret = -ETIME;
1459 }
1460 spin_unlock_irqrestore(&isp116x->lock, flags);
1461 return ret;
1462}
1463
1464/*
1465 Reset. Tries to perform platform-specific hardware
1466 reset first; falls back to software reset.
1467*/
1468static int isp116x_reset(struct usb_hcd *hcd)
1469{
1470 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1471 unsigned long t;
1472 u16 clkrdy = 0;
1473 int ret = 0, timeout = 15 /* ms */ ;
1474
1475 if (isp116x->board && isp116x->board->reset) {
1476 /* Hardware reset */
1477 isp116x->board->reset(hcd->self.controller, 1);
1478 msleep(10);
1479 if (isp116x->board->clock)
1480 isp116x->board->clock(hcd->self.controller, 1);
1481 msleep(1);
1482 isp116x->board->reset(hcd->self.controller, 0);
1483 } else
1484 ret = isp116x_sw_reset(isp116x);
1485
1486 if (ret)
1487 return ret;
1488
1489 t = jiffies + msecs_to_jiffies(timeout);
1490 while (time_before_eq(jiffies, t)) {
1491 msleep(4);
1492 spin_lock_irq(&isp116x->lock);
1493 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1494 spin_unlock_irq(&isp116x->lock);
1495 if (clkrdy)
1496 break;
1497 }
1498 if (!clkrdy) {
1499 ERR("Clock not ready after 20ms\n");
1500 /* After sw_reset the clock won't report to be ready, if
1501 H_WAKEUP pin is high. */
1502 if (!isp116x->board || !isp116x->board->reset)
1503 ERR("The driver does not support hardware wakeup.\n");
1504 ERR("Please make sure that the H_WAKEUP pin "
1505 "is pulled low!\n");
1506 ret = -ENODEV;
1507 }
1508 return ret;
1509}
1510
1511static void isp116x_stop(struct usb_hcd *hcd)
1512{
1513 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1514 unsigned long flags;
1515 u32 val;
1516
1517 spin_lock_irqsave(&isp116x->lock, flags);
1518 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1519
1520 /* Switch off ports' power, some devices don't come up
1521 after next 'insmod' without this */
1522 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1523 val &= ~(RH_A_NPS | RH_A_PSM);
1524 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1525 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1526 spin_unlock_irqrestore(&isp116x->lock, flags);
1527
1528 /* Put the chip into reset state */
1529 if (isp116x->board && isp116x->board->reset)
1530 isp116x->board->reset(hcd->self.controller, 0);
1531 else
1532 isp116x_sw_reset(isp116x);
1533
1534 /* Stop the clock */
1535 if (isp116x->board && isp116x->board->clock)
1536 isp116x->board->clock(hcd->self.controller, 0);
1537}
1538
1539/*
1540 Configure the chip. The chip must be successfully reset by now.
1541*/
1542static int isp116x_start(struct usb_hcd *hcd)
1543{
1544 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1545 struct isp116x_platform_data *board = isp116x->board;
1546 u32 val;
1547 unsigned long flags;
1548
1549 spin_lock_irqsave(&isp116x->lock, flags);
1550
1551 /* clear interrupt status and disable all interrupt sources */
1552 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1553 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1554
1555 val = isp116x_read_reg16(isp116x, HCCHIPID);
1556 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1557 ERR("Invalid chip ID %04x\n", val);
1558 spin_unlock_irqrestore(&isp116x->lock, flags);
1559 return -ENODEV;
1560 }
1561
1562 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1563 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1564
1565 /* ----- HW conf */
1566 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1567 if (board->sel15Kres)
1568 val |= HCHWCFG_15KRSEL;
1569 /* Remote wakeup won't work without working clock */
1570 if (board->clknotstop || board->remote_wakeup_enable)
1571 val |= HCHWCFG_CLKNOTSTOP;
1572 if (board->oc_enable)
1573 val |= HCHWCFG_ANALOG_OC;
1574 if (board->int_act_high)
1575 val |= HCHWCFG_INT_POL;
1576 if (board->int_edge_triggered)
1577 val |= HCHWCFG_INT_TRIGGER;
1578 isp116x_write_reg16(isp116x, HCHWCFG, val);
1579
1580 /* ----- Root hub conf */
1581 val = 0;
1582 /* AN10003_1.pdf recommends NPS to be always 1 */
1583 if (board->no_power_switching)
1584 val |= RH_A_NPS;
1585 if (board->power_switching_mode)
1586 val |= RH_A_PSM;
1587 if (board->potpg)
1588 val |= (board->potpg << 24) & RH_A_POTPGT;
1589 else
1590 val |= (25 << 24) & RH_A_POTPGT;
1591 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1592 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1593
1594 val = RH_B_PPCM;
1595 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1596 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1597
1598 val = 0;
1599 if (board->remote_wakeup_enable) {
1600 hcd->can_wakeup = 1;
1601 val |= RH_HS_DRWE;
1602 }
1603 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1604 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1605
1606 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1607
1608 hcd->state = HC_STATE_RUNNING;
1609
1610 /* Set up interrupts */
1611 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1612 if (board->remote_wakeup_enable)
1613 isp116x->intenb |= HCINT_RD;
1614 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1615 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1616 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1617
1618 /* Go operational */
1619 val = HCCONTROL_USB_OPER;
1620 /* Remote wakeup connected - NOT SUPPORTED */
1621 /* if (board->remote_wakeup_connected)
1622 val |= HCCONTROL_RWC; */
1623 if (board->remote_wakeup_enable)
1624 val |= HCCONTROL_RWE;
1625 isp116x_write_reg32(isp116x, HCCONTROL, val);
1626
1627 /* Disable ports to avoid race in device enumeration */
1628 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1629 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1630
1631 isp116x_show_regs(isp116x);
1632 spin_unlock_irqrestore(&isp116x->lock, flags);
1633 return 0;
1634}
1635
1636/*-----------------------------------------------------------------*/
1637
1638static struct hc_driver isp116x_hc_driver = {
1639 .description = hcd_name,
1640 .product_desc = "ISP116x Host Controller",
1641 .hcd_priv_size = sizeof(struct isp116x),
1642
1643 .irq = isp116x_irq,
1644 .flags = HCD_USB11,
1645
1646 .reset = isp116x_reset,
1647 .start = isp116x_start,
1648 .stop = isp116x_stop,
1649
1650 .urb_enqueue = isp116x_urb_enqueue,
1651 .urb_dequeue = isp116x_urb_dequeue,
1652 .endpoint_disable = isp116x_endpoint_disable,
1653
1654 .get_frame_number = isp116x_get_frame,
1655
1656 .hub_status_data = isp116x_hub_status_data,
1657 .hub_control = isp116x_hub_control,
1658 .hub_suspend = isp116x_hub_suspend,
1659 .hub_resume = isp116x_hub_resume,
1660};
1661
1662/*----------------------------------------------------------------*/
1663
1664static int __init_or_module isp116x_remove(struct device *dev)
1665{
1666 struct usb_hcd *hcd = dev_get_drvdata(dev);
1667 struct isp116x *isp116x;
1668 struct platform_device *pdev;
1669 struct resource *res;
1670
1671 if(!hcd)
1672 return 0;
1673 isp116x = hcd_to_isp116x(hcd);
1674 pdev = container_of(dev, struct platform_device, dev);
1675 remove_debug_file(isp116x);
1676 usb_remove_hcd(hcd);
1677
1678 iounmap(isp116x->data_reg);
1679 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1680 release_mem_region(res->start, 2);
1681 iounmap(isp116x->addr_reg);
1682 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1683 release_mem_region(res->start, 2);
1684
1685 usb_put_hcd(hcd);
1686 return 0;
1687}
1688
1689#define resource_len(r) (((r)->end - (r)->start) + 1)
1690
1691static int __init isp116x_probe(struct device *dev)
1692{
1693 struct usb_hcd *hcd;
1694 struct isp116x *isp116x;
1695 struct platform_device *pdev;
1696 struct resource *addr, *data;
1697 void __iomem *addr_reg;
1698 void __iomem *data_reg;
1699 int irq;
1700 int ret = 0;
1701
1702 pdev = container_of(dev, struct platform_device, dev);
1703 if (pdev->num_resources < 3) {
1704 ret = -ENODEV;
1705 goto err1;
1706 }
1707
1708 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1709 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1710 irq = platform_get_irq(pdev, 0);
1711 if (!addr || !data || irq < 0) {
1712 ret = -ENODEV;
1713 goto err1;
1714 }
1715
1716 if (dev->dma_mask) {
1717 DBG("DMA not supported\n");
1718 ret = -EINVAL;
1719 goto err1;
1720 }
1721
1722 if (!request_mem_region(addr->start, 2, hcd_name)) {
1723 ret = -EBUSY;
1724 goto err1;
1725 }
1726 addr_reg = ioremap(addr->start, resource_len(addr));
1727 if (addr_reg == NULL) {
1728 ret = -ENOMEM;
1729 goto err2;
1730 }
1731 if (!request_mem_region(data->start, 2, hcd_name)) {
1732 ret = -EBUSY;
1733 goto err3;
1734 }
1735 data_reg = ioremap(data->start, resource_len(data));
1736 if (data_reg == NULL) {
1737 ret = -ENOMEM;
1738 goto err4;
1739 }
1740
1741 /* allocate and initialize hcd */
1742 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1743 if (!hcd) {
1744 ret = -ENOMEM;
1745 goto err5;
1746 }
1747 /* this rsrc_start is bogus */
1748 hcd->rsrc_start = addr->start;
1749 isp116x = hcd_to_isp116x(hcd);
1750 isp116x->data_reg = data_reg;
1751 isp116x->addr_reg = addr_reg;
1752 spin_lock_init(&isp116x->lock);
1753 INIT_LIST_HEAD(&isp116x->async);
1754 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1755 isp116x->board = dev->platform_data;
1756
1757 if (!isp116x->board) {
1758 ERR("Platform data structure not initialized\n");
1759 ret = -ENODEV;
1760 goto err6;
1761 }
1762 if (isp116x_check_platform_delay(isp116x)) {
1763 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1764 "implemented.\n");
1765 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1766 ret = -ENODEV;
1767 goto err6;
1768 }
1769
1770 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1771 if (ret != 0)
1772 goto err6;
1773
1774 create_debug_file(isp116x);
1775 return 0;
1776
1777 err6:
1778 usb_put_hcd(hcd);
1779 err5:
1780 iounmap(data_reg);
1781 err4:
1782 release_mem_region(data->start, 2);
1783 err3:
1784 iounmap(addr_reg);
1785 err2:
1786 release_mem_region(addr->start, 2);
1787 err1:
1788 ERR("init error, %d\n", ret);
1789 return ret;
1790}
1791
1792#ifdef CONFIG_PM
1793/*
1794 Suspend of platform device
1795*/
1796static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1797{
1798 int ret = 0;
1799 struct usb_hcd *hcd = dev_get_drvdata(dev);
1800
1801 VDBG("%s: state %x, phase %x\n", __func__, state, phase);
1802
1803 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
1804 return 0;
1805
1806 ret = usb_suspend_device(hcd->self.root_hub, state);
1807 if (!ret) {
1808 dev->power.power_state = state;
1809 INFO("%s suspended\n", hcd_name);
1810 } else
1811 ERR("%s suspend failed\n", hcd_name);
1812
1813 return ret;
1814}
1815
1816/*
1817 Resume platform device
1818*/
1819static int isp116x_resume(struct device *dev, u32 phase)
1820{
1821 int ret = 0;
1822 struct usb_hcd *hcd = dev_get_drvdata(dev);
1823
1824 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
1825 phase);
1826 if (phase != RESUME_POWER_ON)
1827 return 0;
1828
1829 ret = usb_resume_device(hcd->self.root_hub);
1830 if (!ret) {
1831 dev->power.power_state = PMSG_ON;
1832 VDBG("%s resumed\n", (char *)hcd_name);
1833 }
1834 return ret;
1835}
1836
1837#else
1838
1839#define isp116x_suspend NULL
1840#define isp116x_resume NULL
1841
1842#endif
1843
1844static struct device_driver isp116x_driver = {
1845 .name = (char *)hcd_name,
1846 .bus = &platform_bus_type,
1847 .probe = isp116x_probe,
1848 .remove = isp116x_remove,
1849 .suspend = isp116x_suspend,
1850 .resume = isp116x_resume,
1851};
1852
1853/*-----------------------------------------------------------------*/
1854
1855static int __init isp116x_init(void)
1856{
1857 if (usb_disabled())
1858 return -ENODEV;
1859
1860 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1861 return driver_register(&isp116x_driver);
1862}
1863
1864module_init(isp116x_init);
1865
1866static void __exit isp116x_cleanup(void)
1867{
1868 driver_unregister(&isp116x_driver);
1869}
1870
1871module_exit(isp116x_cleanup);
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
new file mode 100644
index 000000000000..58873470dcf5
--- /dev/null
+++ b/drivers/usb/host/isp116x.h
@@ -0,0 +1,583 @@
1/*
2 * ISP116x register declarations and HCD data structures
3 *
4 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
5 * Portions:
6 * Copyright (C) 2004 Lothar Wassmann
7 * Copyright (C) 2004 Psion Teklogix
8 * Copyright (C) 2004 David Brownell
9 */
10
11/* us of 1ms frame */
12#define MAX_LOAD_LIMIT 850
13
14/* Full speed: max # of bytes to transfer for a single urb
15 at a time must be < 1024 && must be multiple of 64.
16 832 allows transfering 4kiB within 5 frames. */
17#define MAX_TRANSFER_SIZE_FULLSPEED 832
18
19/* Low speed: there is no reason to schedule in very big
20 chunks; often the requested long transfers are for
21 string descriptors containing short strings. */
22#define MAX_TRANSFER_SIZE_LOWSPEED 64
23
24/* Bytetime (us), a rough indication of how much time it
25 would take to transfer a byte of useful data over USB */
26#define BYTE_TIME_FULLSPEED 1
27#define BYTE_TIME_LOWSPEED 20
28
29/* Buffer sizes */
30#define ISP116x_BUF_SIZE 4096
31#define ISP116x_ITL_BUFSIZE 0
32#define ISP116x_ATL_BUFSIZE ((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE))
33
34#define ISP116x_WRITE_OFFSET 0x80
35
36/*------------ ISP116x registers/bits ------------*/
37#define HCREVISION 0x00
38#define HCCONTROL 0x01
39#define HCCONTROL_HCFS (3 << 6) /* host controller
40 functional state */
41#define HCCONTROL_USB_RESET (0 << 6)
42#define HCCONTROL_USB_RESUME (1 << 6)
43#define HCCONTROL_USB_OPER (2 << 6)
44#define HCCONTROL_USB_SUSPEND (3 << 6)
45#define HCCONTROL_RWC (1 << 9) /* remote wakeup connected */
46#define HCCONTROL_RWE (1 << 10) /* remote wakeup enable */
47#define HCCMDSTAT 0x02
48#define HCCMDSTAT_HCR (1 << 0) /* host controller reset */
49#define HCCMDSTAT_SOC (3 << 16) /* scheduling overrun count */
50#define HCINTSTAT 0x03
51#define HCINT_SO (1 << 0) /* scheduling overrun */
52#define HCINT_WDH (1 << 1) /* writeback of done_head */
53#define HCINT_SF (1 << 2) /* start frame */
54#define HCINT_RD (1 << 3) /* resume detect */
55#define HCINT_UE (1 << 4) /* unrecoverable error */
56#define HCINT_FNO (1 << 5) /* frame number overflow */
57#define HCINT_RHSC (1 << 6) /* root hub status change */
58#define HCINT_OC (1 << 30) /* ownership change */
59#define HCINT_MIE (1 << 31) /* master interrupt enable */
60#define HCINTENB 0x04
61#define HCINTDIS 0x05
62#define HCFMINTVL 0x0d
63#define HCFMREM 0x0e
64#define HCFMNUM 0x0f
65#define HCLSTHRESH 0x11
66#define HCRHDESCA 0x12
67#define RH_A_NDP (0x3 << 0) /* # downstream ports */
68#define RH_A_PSM (1 << 8) /* power switching mode */
69#define RH_A_NPS (1 << 9) /* no power switching */
70#define RH_A_DT (1 << 10) /* device type (mbz) */
71#define RH_A_OCPM (1 << 11) /* overcurrent protection
72 mode */
73#define RH_A_NOCP (1 << 12) /* no overcurrent protection */
74#define RH_A_POTPGT (0xff << 24) /* power on -> power good
75 time */
76#define HCRHDESCB 0x13
77#define RH_B_DR (0xffff << 0) /* device removable flags */
78#define RH_B_PPCM (0xffff << 16) /* port power control mask */
79#define HCRHSTATUS 0x14
80#define RH_HS_LPS (1 << 0) /* local power status */
81#define RH_HS_OCI (1 << 1) /* over current indicator */
82#define RH_HS_DRWE (1 << 15) /* device remote wakeup
83 enable */
84#define RH_HS_LPSC (1 << 16) /* local power status change */
85#define RH_HS_OCIC (1 << 17) /* over current indicator
86 change */
87#define RH_HS_CRWE (1 << 31) /* clear remote wakeup
88 enable */
89#define HCRHPORT1 0x15
90#define RH_PS_CCS (1 << 0) /* current connect status */
91#define RH_PS_PES (1 << 1) /* port enable status */
92#define RH_PS_PSS (1 << 2) /* port suspend status */
93#define RH_PS_POCI (1 << 3) /* port over current
94 indicator */
95#define RH_PS_PRS (1 << 4) /* port reset status */
96#define RH_PS_PPS (1 << 8) /* port power status */
97#define RH_PS_LSDA (1 << 9) /* low speed device attached */
98#define RH_PS_CSC (1 << 16) /* connect status change */
99#define RH_PS_PESC (1 << 17) /* port enable status change */
100#define RH_PS_PSSC (1 << 18) /* port suspend status
101 change */
102#define RH_PS_OCIC (1 << 19) /* over current indicator
103 change */
104#define RH_PS_PRSC (1 << 20) /* port reset status change */
105#define HCRHPORT_CLRMASK (0x1f << 16)
106#define HCRHPORT2 0x16
107#define HCHWCFG 0x20
108#define HCHWCFG_15KRSEL (1 << 12)
109#define HCHWCFG_CLKNOTSTOP (1 << 11)
110#define HCHWCFG_ANALOG_OC (1 << 10)
111#define HCHWCFG_DACK_MODE (1 << 8)
112#define HCHWCFG_EOT_POL (1 << 7)
113#define HCHWCFG_DACK_POL (1 << 6)
114#define HCHWCFG_DREQ_POL (1 << 5)
115#define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
116#define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
117#define HCHWCFG_INT_POL (1 << 2)
118#define HCHWCFG_INT_TRIGGER (1 << 1)
119#define HCHWCFG_INT_ENABLE (1 << 0)
120#define HCDMACFG 0x21
121#define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
122#define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
123#define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
124#define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
125#define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
126#define HCDMACFG_DMA_ENABLE (1 << 4)
127#define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
128#define HCDMACFG_CTR_SEL (1 << 2)
129#define HCDMACFG_ITLATL_SEL (1 << 1)
130#define HCDMACFG_DMA_RW_SELECT (1 << 0)
131#define HCXFERCTR 0x22
132#define HCuPINT 0x24
133#define HCuPINT_SOF (1 << 0)
134#define HCuPINT_ATL (1 << 1)
135#define HCuPINT_AIIEOT (1 << 2)
136#define HCuPINT_OPR (1 << 4)
137#define HCuPINT_SUSP (1 << 5)
138#define HCuPINT_CLKRDY (1 << 6)
139#define HCuPINTENB 0x25
140#define HCCHIPID 0x27
141#define HCCHIPID_MASK 0xff00
142#define HCCHIPID_MAGIC 0x6100
143#define HCSCRATCH 0x28
144#define HCSWRES 0x29
145#define HCSWRES_MAGIC 0x00f6
146#define HCITLBUFLEN 0x2a
147#define HCATLBUFLEN 0x2b
148#define HCBUFSTAT 0x2c
149#define HCBUFSTAT_ITL0_FULL (1 << 0)
150#define HCBUFSTAT_ITL1_FULL (1 << 1)
151#define HCBUFSTAT_ATL_FULL (1 << 2)
152#define HCBUFSTAT_ITL0_DONE (1 << 3)
153#define HCBUFSTAT_ITL1_DONE (1 << 4)
154#define HCBUFSTAT_ATL_DONE (1 << 5)
155#define HCRDITL0LEN 0x2d
156#define HCRDITL1LEN 0x2e
157#define HCITLPORT 0x40
158#define HCATLPORT 0x41
159
160/* Philips transfer descriptor */
161struct ptd {
162 u16 count;
163#define PTD_COUNT_MSK (0x3ff << 0)
164#define PTD_TOGGLE_MSK (1 << 10)
165#define PTD_ACTIVE_MSK (1 << 11)
166#define PTD_CC_MSK (0xf << 12)
167 u16 mps;
168#define PTD_MPS_MSK (0x3ff << 0)
169#define PTD_SPD_MSK (1 << 10)
170#define PTD_LAST_MSK (1 << 11)
171#define PTD_EP_MSK (0xf << 12)
172 u16 len;
173#define PTD_LEN_MSK (0x3ff << 0)
174#define PTD_DIR_MSK (3 << 10)
175#define PTD_DIR_SETUP (0)
176#define PTD_DIR_OUT (1)
177#define PTD_DIR_IN (2)
178#define PTD_B5_5_MSK (1 << 13)
179 u16 faddr;
180#define PTD_FA_MSK (0x7f << 0)
181#define PTD_FMT_MSK (1 << 7)
182} __attribute__ ((packed, aligned(2)));
183
184/* PTD accessor macros. */
185#define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
186#define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
187#define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
188#define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
189#define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
190#define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
191#define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
192#define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
193#define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
194#define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
195#define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
196#define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
197#define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
198#define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
199#define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
200#define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
201#define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
202#define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
203#define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
204#define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
205#define PTD_GET_B5_5(p) (((p)->len & PTD_B5_5_MSK) >> 13)
206#define PTD_B5_5(v) (((v) << 13) & PTD_B5_5_MSK)
207#define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
208#define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
209#define PTD_GET_FMT(p) (((p)->faddr & PTD_FMT_MSK) >> 7)
210#define PTD_FMT(v) (((v) << 7) & PTD_FMT_MSK)
211
212/* Hardware transfer status codes -- CC from ptd->count */
213#define TD_CC_NOERROR 0x00
214#define TD_CC_CRC 0x01
215#define TD_CC_BITSTUFFING 0x02
216#define TD_CC_DATATOGGLEM 0x03
217#define TD_CC_STALL 0x04
218#define TD_DEVNOTRESP 0x05
219#define TD_PIDCHECKFAIL 0x06
220#define TD_UNEXPECTEDPID 0x07
221#define TD_DATAOVERRUN 0x08
222#define TD_DATAUNDERRUN 0x09
223 /* 0x0A, 0x0B reserved for hardware */
224#define TD_BUFFEROVERRUN 0x0C
225#define TD_BUFFERUNDERRUN 0x0D
226 /* 0x0E, 0x0F reserved for HCD */
227#define TD_NOTACCESSED 0x0F
228
229/* map PTD status codes (CC) to errno values */
230static const int cc_to_error[16] = {
231 /* No Error */ 0,
232 /* CRC Error */ -EILSEQ,
233 /* Bit Stuff */ -EPROTO,
234 /* Data Togg */ -EILSEQ,
235 /* Stall */ -EPIPE,
236 /* DevNotResp */ -ETIMEDOUT,
237 /* PIDCheck */ -EPROTO,
238 /* UnExpPID */ -EPROTO,
239 /* DataOver */ -EOVERFLOW,
240 /* DataUnder */ -EREMOTEIO,
241 /* (for hw) */ -EIO,
242 /* (for hw) */ -EIO,
243 /* BufferOver */ -ECOMM,
244 /* BuffUnder */ -ENOSR,
245 /* (for HCD) */ -EALREADY,
246 /* (for HCD) */ -EALREADY
247};
248
249/*--------------------------------------------------------------*/
250
251#define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
252#define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
253
254struct isp116x {
255 spinlock_t lock;
256 struct work_struct rh_resume;
257
258 void __iomem *addr_reg;
259 void __iomem *data_reg;
260
261 struct isp116x_platform_data *board;
262
263 struct proc_dir_entry *pde;
264 unsigned long stat1, stat2, stat4, stat8, stat16;
265
266 /* HC registers */
267 u32 intenb; /* "OHCI" interrupts */
268 u16 irqenb; /* uP interrupts */
269
270 /* Root hub registers */
271 u32 rhdesca;
272 u32 rhdescb;
273 u32 rhstatus;
274 u32 rhport[2];
275
276 /* async schedule: control, bulk */
277 struct list_head async;
278
279 /* periodic schedule: int */
280 u16 load[PERIODIC_SIZE];
281 struct isp116x_ep *periodic[PERIODIC_SIZE];
282 unsigned periodic_count;
283 u16 fmindex;
284
285 /* Schedule for the current frame */
286 struct isp116x_ep *atl_active;
287 int atl_buflen;
288 int atl_bufshrt;
289 int atl_last_dir;
290 atomic_t atl_finishing;
291};
292
293static inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd)
294{
295 return (struct isp116x *)(hcd->hcd_priv);
296}
297
298static inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x)
299{
300 return container_of((void *)isp116x, struct usb_hcd, hcd_priv);
301}
302
303struct isp116x_ep {
304 struct usb_host_endpoint *hep;
305 struct usb_device *udev;
306 struct ptd ptd;
307
308 u8 maxpacket;
309 u8 epnum;
310 u8 nextpid;
311 u16 error_count;
312 u16 length; /* of current packet */
313 unsigned char *data; /* to databuf */
314 /* queue of active EP's (the ones scheduled for the
315 current frame) */
316 struct isp116x_ep *active;
317
318 /* periodic schedule */
319 u16 period;
320 u16 branch;
321 u16 load;
322 struct isp116x_ep *next;
323
324 /* async schedule */
325 struct list_head schedule;
326};
327
328/*-------------------------------------------------------------------------*/
329
330#ifdef DEBUG
331#define DBG(stuff...) printk(KERN_DEBUG "116x: " stuff)
332#else
333#define DBG(stuff...) do{}while(0)
334#endif
335
336#ifdef VERBOSE
337# define VDBG DBG
338#else
339# define VDBG(stuff...) do{}while(0)
340#endif
341
342#define ERR(stuff...) printk(KERN_ERR "116x: " stuff)
343#define WARN(stuff...) printk(KERN_WARNING "116x: " stuff)
344#define INFO(stuff...) printk(KERN_INFO "116x: " stuff)
345
346/* ------------------------------------------------- */
347
348#if defined(USE_PLATFORM_DELAY)
349#if defined(USE_NDELAY)
350#error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined.
351#endif
352#define isp116x_delay(h,d) (h)->board->delay( \
353 isp116x_to_hcd(h)->self.controller,d)
354#define isp116x_check_platform_delay(h) ((h)->board->delay == NULL)
355#elif defined(USE_NDELAY)
356#define isp116x_delay(h,d) ndelay(d)
357#define isp116x_check_platform_delay(h) 0
358#else
359#define isp116x_delay(h,d) do{}while(0)
360#define isp116x_check_platform_delay(h) 0
361#endif
362
363#if defined(DEBUG)
364#define IRQ_TEST() BUG_ON(!irqs_disabled())
365#else
366#define IRQ_TEST() do{}while(0)
367#endif
368
369static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg)
370{
371 IRQ_TEST();
372 writew(reg & 0xff, isp116x->addr_reg);
373 isp116x_delay(isp116x, 300);
374}
375
376static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val)
377{
378 writew(val, isp116x->data_reg);
379 isp116x_delay(isp116x, 150);
380}
381
382static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val)
383{
384 __raw_writew(val, isp116x->data_reg);
385 isp116x_delay(isp116x, 150);
386}
387
388static inline u16 isp116x_read_data16(struct isp116x *isp116x)
389{
390 u16 val;
391
392 val = readw(isp116x->data_reg);
393 isp116x_delay(isp116x, 150);
394 return val;
395}
396
397static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x)
398{
399 u16 val;
400
401 val = __raw_readw(isp116x->data_reg);
402 isp116x_delay(isp116x, 150);
403 return val;
404}
405
406static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val)
407{
408 writew(val & 0xffff, isp116x->data_reg);
409 isp116x_delay(isp116x, 150);
410 writew(val >> 16, isp116x->data_reg);
411 isp116x_delay(isp116x, 150);
412}
413
414static inline u32 isp116x_read_data32(struct isp116x *isp116x)
415{
416 u32 val;
417
418 val = (u32) readw(isp116x->data_reg);
419 isp116x_delay(isp116x, 150);
420 val |= ((u32) readw(isp116x->data_reg)) << 16;
421 isp116x_delay(isp116x, 150);
422 return val;
423}
424
425/* Let's keep register access functions out of line. Hint:
426 we wait at least 150 ns at every access.
427*/
428static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg)
429{
430 isp116x_write_addr(isp116x, reg);
431 return isp116x_read_data16(isp116x);
432}
433
434static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg)
435{
436 isp116x_write_addr(isp116x, reg);
437 return isp116x_read_data32(isp116x);
438}
439
440static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg,
441 unsigned val)
442{
443 isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
444 isp116x_write_data16(isp116x, (u16) (val & 0xffff));
445}
446
447static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg,
448 unsigned val)
449{
450 isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET);
451 isp116x_write_data32(isp116x, (u32) val);
452}
453
454#define isp116x_show_reg(d,r) { \
455 if ((r) < 0x20) { \
456 DBG("%-12s[%02x]: %08x\n", #r, \
457 r, isp116x_read_reg32(d, r)); \
458 } else { \
459 DBG("%-12s[%02x]: %04x\n", #r, \
460 r, isp116x_read_reg16(d, r)); \
461 } \
462}
463
464static inline void isp116x_show_regs(struct isp116x *isp116x)
465{
466 isp116x_show_reg(isp116x, HCREVISION);
467 isp116x_show_reg(isp116x, HCCONTROL);
468 isp116x_show_reg(isp116x, HCCMDSTAT);
469 isp116x_show_reg(isp116x, HCINTSTAT);
470 isp116x_show_reg(isp116x, HCINTENB);
471 isp116x_show_reg(isp116x, HCFMINTVL);
472 isp116x_show_reg(isp116x, HCFMREM);
473 isp116x_show_reg(isp116x, HCFMNUM);
474 isp116x_show_reg(isp116x, HCLSTHRESH);
475 isp116x_show_reg(isp116x, HCRHDESCA);
476 isp116x_show_reg(isp116x, HCRHDESCB);
477 isp116x_show_reg(isp116x, HCRHSTATUS);
478 isp116x_show_reg(isp116x, HCRHPORT1);
479 isp116x_show_reg(isp116x, HCRHPORT2);
480 isp116x_show_reg(isp116x, HCHWCFG);
481 isp116x_show_reg(isp116x, HCDMACFG);
482 isp116x_show_reg(isp116x, HCXFERCTR);
483 isp116x_show_reg(isp116x, HCuPINT);
484 isp116x_show_reg(isp116x, HCuPINTENB);
485 isp116x_show_reg(isp116x, HCCHIPID);
486 isp116x_show_reg(isp116x, HCSCRATCH);
487 isp116x_show_reg(isp116x, HCITLBUFLEN);
488 isp116x_show_reg(isp116x, HCATLBUFLEN);
489 isp116x_show_reg(isp116x, HCBUFSTAT);
490 isp116x_show_reg(isp116x, HCRDITL0LEN);
491 isp116x_show_reg(isp116x, HCRDITL1LEN);
492}
493
494#if defined(URB_TRACE)
495
496#define PIPETYPE(pipe) ({ char *__s; \
497 if (usb_pipecontrol(pipe)) __s = "ctrl"; \
498 else if (usb_pipeint(pipe)) __s = "int"; \
499 else if (usb_pipebulk(pipe)) __s = "bulk"; \
500 else __s = "iso"; \
501 __s;})
502#define PIPEDIR(pipe) ({ usb_pipein(pipe) ? "in" : "out"; })
503#define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \
504 "short_not_ok" : ""; })
505
506/* print debug info about the URB */
507static void urb_dbg(struct urb *urb, char *msg)
508{
509 unsigned int pipe;
510
511 if (!urb) {
512 DBG("%s: zero urb\n", msg);
513 return;
514 }
515 pipe = urb->pipe;
516 DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg,
517 usb_pipedevice(pipe), usb_pipeendpoint(pipe),
518 PIPEDIR(pipe), PIPETYPE(pipe),
519 urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb));
520}
521
522#else
523
524#define urb_dbg(urb,msg) do{}while(0)
525
526#endif /* ! defined(URB_TRACE) */
527
528#if defined(PTD_TRACE)
529
530#define PTD_DIR_STR(ptd) ({char __c; \
531 switch(PTD_GET_DIR(ptd)){ \
532 case 0: __c = 's'; break; \
533 case 1: __c = 'o'; break; \
534 default: __c = 'i'; break; \
535 }; __c;})
536
537/*
538 Dump PTD info. The code documents the format
539 perfectly, right :)
540*/
541static inline void dump_ptd(struct ptd *ptd)
542{
543 printk("td: %x %d%c%d %d,%d,%d %x %x%x%x\n",
544 PTD_GET_CC(ptd), PTD_GET_FA(ptd),
545 PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
546 PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
547 PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd),
548 PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
549}
550
551static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
552{
553 int k;
554
555 if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
556 printk("-> ");
557 for (k = 0; k < PTD_GET_LEN(ptd); ++k)
558 printk("%02x ", ((u8 *) buf)[k]);
559 printk("\n");
560 }
561}
562
563static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
564{
565 int k;
566
567 if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
568 printk("<- ");
569 for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
570 printk("%02x ", ((u8 *) buf)[k]);
571 printk("\n");
572 }
573 if (PTD_GET_LAST(ptd))
574 printk("-\n");
575}
576
577#else
578
579#define dump_ptd(ptd) do{}while(0)
580#define dump_ptd_in_data(ptd,buf) do{}while(0)
581#define dump_ptd_out_data(ptd,buf) do{}while(0)
582
583#endif /* ! defined(PTD_TRACE) */
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1e27f10c1592..68decab280dd 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -95,12 +95,11 @@
95#include <linux/init.h> 95#include <linux/init.h>
96#include <linux/timer.h> 96#include <linux/timer.h>
97#include <linux/list.h> 97#include <linux/list.h>
98#include <linux/interrupt.h> /* for in_interrupt () */
99#include <linux/usb.h> 98#include <linux/usb.h>
100#include <linux/usb_otg.h> 99#include <linux/usb_otg.h>
101#include "../core/hcd.h"
102#include <linux/dma-mapping.h> 100#include <linux/dma-mapping.h>
103#include <linux/dmapool.h> /* needed by ohci-mem.c when no PCI */ 101#include <linux/dmapool.h>
102#include <linux/reboot.h>
104 103
105#include <asm/io.h> 104#include <asm/io.h>
106#include <asm/irq.h> 105#include <asm/irq.h>
@@ -108,8 +107,9 @@
108#include <asm/unaligned.h> 107#include <asm/unaligned.h>
109#include <asm/byteorder.h> 108#include <asm/byteorder.h>
110 109
110#include "../core/hcd.h"
111 111
112#define DRIVER_VERSION "2004 Nov 08" 112#define DRIVER_VERSION "2005 April 22"
113#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 113#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
114#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 114#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
115 115
@@ -141,6 +141,7 @@ static const char hcd_name [] = "ohci_hcd";
141static void ohci_dump (struct ohci_hcd *ohci, int verbose); 141static void ohci_dump (struct ohci_hcd *ohci, int verbose);
142static int ohci_init (struct ohci_hcd *ohci); 142static int ohci_init (struct ohci_hcd *ohci);
143static void ohci_stop (struct usb_hcd *hcd); 143static void ohci_stop (struct usb_hcd *hcd);
144static int ohci_reboot (struct notifier_block *, unsigned long , void *);
144 145
145#include "ohci-hub.c" 146#include "ohci-hub.c"
146#include "ohci-dbg.c" 147#include "ohci-dbg.c"
@@ -179,7 +180,7 @@ static int ohci_urb_enqueue (
179 struct usb_hcd *hcd, 180 struct usb_hcd *hcd,
180 struct usb_host_endpoint *ep, 181 struct usb_host_endpoint *ep,
181 struct urb *urb, 182 struct urb *urb,
182 int mem_flags 183 unsigned mem_flags
183) { 184) {
184 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 185 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
185 struct ed *ed; 186 struct ed *ed;
@@ -420,6 +421,23 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
420 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 421 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
421} 422}
422 423
424/* reboot notifier forcibly disables IRQs and DMA, helping kexec and
425 * other cases where the next software may expect clean state from the
426 * "firmware". this is bus-neutral, unlike shutdown() methods.
427 */
428static int
429ohci_reboot (struct notifier_block *block, unsigned long code, void *null)
430{
431 struct ohci_hcd *ohci;
432
433 ohci = container_of (block, struct ohci_hcd, reboot_notifier);
434 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
435 ohci_usb_reset (ohci);
436 /* flush the writes */
437 (void) ohci_readl (ohci, &ohci->regs->control);
438 return 0;
439}
440
423/*-------------------------------------------------------------------------* 441/*-------------------------------------------------------------------------*
424 * HC functions 442 * HC functions
425 *-------------------------------------------------------------------------*/ 443 *-------------------------------------------------------------------------*/
@@ -487,13 +505,10 @@ static int ohci_init (struct ohci_hcd *ohci)
487/* Start an OHCI controller, set the BUS operational 505/* Start an OHCI controller, set the BUS operational
488 * resets USB and controller 506 * resets USB and controller
489 * enable interrupts 507 * enable interrupts
490 * connect the virtual root hub
491 */ 508 */
492static int ohci_run (struct ohci_hcd *ohci) 509static int ohci_run (struct ohci_hcd *ohci)
493{ 510{
494 u32 mask, temp; 511 u32 mask, temp;
495 struct usb_device *udev;
496 struct usb_bus *bus;
497 int first = ohci->fminterval == 0; 512 int first = ohci->fminterval == 0;
498 513
499 disable (ohci); 514 disable (ohci);
@@ -654,37 +669,15 @@ retry:
654 669
655 // POTPGT delay is bits 24-31, in 2 ms units. 670 // POTPGT delay is bits 24-31, in 2 ms units.
656 mdelay ((temp >> 23) & 0x1fe); 671 mdelay ((temp >> 23) & 0x1fe);
657 bus = &ohci_to_hcd(ohci)->self;
658 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING; 672 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING;
659 673
660 ohci_dump (ohci, 1); 674 ohci_dump (ohci, 1);
661 675
662 udev = bus->root_hub; 676 if (ohci_to_hcd(ohci)->self.root_hub == NULL) {
663 if (udev) { 677 register_reboot_notifier (&ohci->reboot_notifier);
664 return 0; 678 create_debug_files (ohci);
665 }
666
667 /* connect the virtual root hub */
668 udev = usb_alloc_dev (NULL, bus, 0);
669 if (!udev) {
670 disable (ohci);
671 ohci->hc_control &= ~OHCI_CTRL_HCFS;
672 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
673 return -ENOMEM;
674 }
675
676 udev->speed = USB_SPEED_FULL;
677 if (usb_hcd_register_root_hub (udev, ohci_to_hcd(ohci)) != 0) {
678 usb_put_dev (udev);
679 disable (ohci);
680 ohci->hc_control &= ~OHCI_CTRL_HCFS;
681 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
682 return -ENODEV;
683 } 679 }
684 if (ohci->power_budget)
685 hub_set_power_budget(udev, ohci->power_budget);
686 680
687 create_debug_files (ohci);
688 return 0; 681 return 0;
689} 682}
690 683
@@ -781,6 +774,7 @@ static void ohci_stop (struct usb_hcd *hcd)
781 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 774 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
782 775
783 remove_debug_files (ohci); 776 remove_debug_files (ohci);
777 unregister_reboot_notifier (&ohci->reboot_notifier);
784 ohci_mem_cleanup (ohci); 778 ohci_mem_cleanup (ohci);
785 if (ohci->hcca) { 779 if (ohci->hcca) {
786 dma_free_coherent (hcd->self.controller, 780 dma_free_coherent (hcd->self.controller,
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index e2fc4129dfc6..83ca4549a50e 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -419,10 +419,11 @@ ohci_hub_descriptor (
419 419
420 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 420 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
421 rh = roothub_b (ohci); 421 rh = roothub_b (ohci);
422 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
422 desc->bitmap [0] = rh & RH_B_DR; 423 desc->bitmap [0] = rh & RH_B_DR;
423 if (ports > 7) { 424 if (ports > 7) {
424 desc->bitmap [1] = (rh & RH_B_DR) >> 8; 425 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
425 desc->bitmap [2] = desc->bitmap [3] = 0xff; 426 desc->bitmap [2] = 0xff;
426 } else 427 } else
427 desc->bitmap [1] = 0xff; 428 desc->bitmap [1] = 0xff;
428} 429}
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index e55682b4919d..fd3c4d3714bd 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -29,6 +29,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci)); 31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci));
32 ohci->reboot_notifier.notifier_call = ohci_reboot;
32} 33}
33 34
34/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
@@ -83,7 +84,7 @@ dma_to_td (struct ohci_hcd *hc, dma_addr_t td_dma)
83 84
84/* TDs ... */ 85/* TDs ... */
85static struct td * 86static struct td *
86td_alloc (struct ohci_hcd *hc, int mem_flags) 87td_alloc (struct ohci_hcd *hc, unsigned mem_flags)
87{ 88{
88 dma_addr_t dma; 89 dma_addr_t dma;
89 struct td *td; 90 struct td *td;
@@ -117,7 +118,7 @@ td_free (struct ohci_hcd *hc, struct td *td)
117 118
118/* EDs ... */ 119/* EDs ... */
119static struct ed * 120static struct ed *
120ed_alloc (struct ohci_hcd *hc, int mem_flags) 121ed_alloc (struct ohci_hcd *hc, unsigned mem_flags)
121{ 122{
122 dma_addr_t dma; 123 dma_addr_t dma;
123 struct ed *ed; 124 struct ed *ed;
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 8aab5907afe9..5cde76faab93 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -181,7 +181,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
181 if (config->otg) { 181 if (config->otg) {
182 ohci_to_hcd(ohci)->self.otg_port = config->otg; 182 ohci_to_hcd(ohci)->self.otg_port = config->otg;
183 /* default/minimum OTG power budget: 8 mA */ 183 /* default/minimum OTG power budget: 8 mA */
184 ohci->power_budget = 8; 184 ohci_to_hcd(ohci)->power_budget = 8;
185 } 185 }
186 186
187 /* boards can use OTG transceivers in non-OTG modes */ 187 /* boards can use OTG transceivers in non-OTG modes */
@@ -230,7 +230,7 @@ static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
230 230
231 /* TPS2045 switch for internal transceiver (port 1) */ 231 /* TPS2045 switch for internal transceiver (port 1) */
232 if (machine_is_omap_osk()) { 232 if (machine_is_omap_osk()) {
233 ohci->power_budget = 250; 233 ohci_to_hcd(ohci)->power_budget = 250;
234 234
235 rh &= ~RH_A_NOCP; 235 rh &= ~RH_A_NOCP;
236 236
@@ -456,34 +456,22 @@ static int ohci_hcd_omap_drv_remove(struct device *dev)
456 456
457#ifdef CONFIG_PM 457#ifdef CONFIG_PM
458 458
459/* states match PCI usage, always suspending the root hub except that 459static int ohci_omap_suspend(struct device *dev, pm_message_t message, u32 level)
460 * 4 ~= D3cold (ACPI D3) with clock off (resume sees reset).
461 *
462 * FIXME: above comment is not right, and code is wrong, too :-(.
463 */
464
465static int ohci_omap_suspend(struct device *dev, pm_message_t state, u32 level)
466{ 460{
467 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev)); 461 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
468 int status = -EINVAL; 462 int status = -EINVAL;
469 463
470 if (level != SUSPEND_POWER_DOWN) 464 if (level != SUSPEND_POWER_DOWN)
471 return 0; 465 return 0;
472 if (state <= dev->power.power_state)
473 return 0;
474 466
475 dev_dbg(dev, "suspend to %d\n", state);
476 down(&ohci_to_hcd(ohci)->self.root_hub->serialize); 467 down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
477 status = ohci_hub_suspend(ohci_to_hcd(ohci)); 468 status = ohci_hub_suspend(ohci_to_hcd(ohci));
478 if (status == 0) { 469 if (status == 0) {
479 if (state >= 4) { 470 omap_ohci_clock_power(0);
480 omap_ohci_clock_power(0); 471 ohci_to_hcd(ohci)->self.root_hub->state =
481 ohci_to_hcd(ohci)->self.root_hub->state = 472 USB_STATE_SUSPENDED;
482 USB_STATE_SUSPENDED;
483 state = 4;
484 }
485 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 473 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
486 dev->power.power_state = state; 474 dev->power.power_state = PMSG_SUSPEND;
487 } 475 }
488 up(&ohci_to_hcd(ohci)->self.root_hub->serialize); 476 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
489 return status; 477 return status;
@@ -497,29 +485,20 @@ static int ohci_omap_resume(struct device *dev, u32 level)
497 if (level != RESUME_POWER_ON) 485 if (level != RESUME_POWER_ON)
498 return 0; 486 return 0;
499 487
500 switch (dev->power.power_state) { 488 if (time_before(jiffies, ohci->next_statechange))
501 case 0: 489 msleep(5);
502 break; 490 ohci->next_statechange = jiffies;
503 case 4: 491 omap_ohci_clock_power(1);
504 if (time_before(jiffies, ohci->next_statechange))
505 msleep(5);
506 ohci->next_statechange = jiffies;
507 omap_ohci_clock_power(1);
508 /* FALLTHROUGH */
509 default:
510 dev_dbg(dev, "resume from %d\n", dev->power.power_state);
511#ifdef CONFIG_USB_SUSPEND 492#ifdef CONFIG_USB_SUSPEND
512 /* get extra cleanup even if remote wakeup isn't in use */ 493 /* get extra cleanup even if remote wakeup isn't in use */
513 status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub); 494 status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub);
514#else 495#else
515 down(&ohci_to_hcd(ohci)->self.root_hub->serialize); 496 down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
516 status = ohci_hub_resume(ohci_to_hcd(ohci)); 497 status = ohci_hub_resume(ohci_to_hcd(ohci));
517 up(&ohci_to_hcd(ohci)->self.root_hub->serialize); 498 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
518#endif 499#endif
519 if (status == 0) 500 if (status == 0)
520 dev->power.power_state = 0; 501 dev->power.power_state = PMSG_ON;
521 break;
522 }
523 return status; 502 return status;
524} 503}
525 504
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 57fd07d00549..eede6be098d2 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -14,14 +14,11 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#ifdef CONFIG_PMAC_PBOOK 17#ifdef CONFIG_PPC_PMAC
18#include <asm/machdep.h> 18#include <asm/machdep.h>
19#include <asm/pmac_feature.h> 19#include <asm/pmac_feature.h>
20#include <asm/pci-bridge.h> 20#include <asm/pci-bridge.h>
21#include <asm/prom.h> 21#include <asm/prom.h>
22#ifndef CONFIG_PM
23# define CONFIG_PM
24#endif
25#endif 22#endif
26 23
27#ifndef CONFIG_PCI 24#ifndef CONFIG_PCI
@@ -132,7 +129,7 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
132 /* let things settle down a bit */ 129 /* let things settle down a bit */
133 msleep (100); 130 msleep (100);
134 131
135#ifdef CONFIG_PMAC_PBOOK 132#ifdef CONFIG_PPC_PMAC
136 if (_machine == _MACH_Pmac) { 133 if (_machine == _MACH_Pmac) {
137 struct device_node *of_node; 134 struct device_node *of_node;
138 135
@@ -141,7 +138,7 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
141 if (of_node) 138 if (of_node)
142 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0); 139 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0);
143 } 140 }
144#endif /* CONFIG_PMAC_PBOOK */ 141#endif /* CONFIG_PPC_PMAC */
145 return 0; 142 return 0;
146} 143}
147 144
@@ -151,7 +148,7 @@ static int ohci_pci_resume (struct usb_hcd *hcd)
151 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 148 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
152 int retval = 0; 149 int retval = 0;
153 150
154#ifdef CONFIG_PMAC_PBOOK 151#ifdef CONFIG_PPC_PMAC
155 if (_machine == _MACH_Pmac) { 152 if (_machine == _MACH_Pmac) {
156 struct device_node *of_node; 153 struct device_node *of_node;
157 154
@@ -160,7 +157,7 @@ static int ohci_pci_resume (struct usb_hcd *hcd)
160 if (of_node) 157 if (of_node)
161 pmac_call_feature (PMAC_FTR_USB_ENABLE, of_node, 0, 1); 158 pmac_call_feature (PMAC_FTR_USB_ENABLE, of_node, 0, 1);
162 } 159 }
163#endif /* CONFIG_PMAC_PBOOK */ 160#endif /* CONFIG_PPC_PMAC */
164 161
165 /* resume root hub */ 162 /* resume root hub */
166 if (time_before (jiffies, ohci->next_statechange)) 163 if (time_before (jiffies, ohci->next_statechange))
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 22e1ac138ac0..71cdd2262860 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -371,7 +371,6 @@ struct ohci_hcd {
371 * other external transceivers should be software-transparent 371 * other external transceivers should be software-transparent
372 */ 372 */
373 struct otg_transceiver *transceiver; 373 struct otg_transceiver *transceiver;
374 unsigned power_budget;
375 374
376 /* 375 /*
377 * memory management for queue data structures 376 * memory management for queue data structures
@@ -390,6 +389,7 @@ struct ohci_hcd {
390 u32 fminterval; /* saved register */ 389 u32 fminterval; /* saved register */
391 390
392 struct work_struct rh_resume; 391 struct work_struct rh_resume;
392 struct notifier_block reboot_notifier;
393 393
394 unsigned long flags; /* for HC bugs */ 394 unsigned long flags; /* for HC bugs */
395#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ 395#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 99d43f758ad0..7a890a65f55d 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -815,7 +815,7 @@ static int sl811h_urb_enqueue(
815 struct usb_hcd *hcd, 815 struct usb_hcd *hcd,
816 struct usb_host_endpoint *hep, 816 struct usb_host_endpoint *hep,
817 struct urb *urb, 817 struct urb *urb,
818 int mem_flags 818 unsigned mem_flags
819) { 819) {
820 struct sl811 *sl811 = hcd_to_sl811(hcd); 820 struct sl811 *sl811 = hcd_to_sl811(hcd);
821 struct usb_device *udev = urb->dev; 821 struct usb_device *udev = urb->dev;
@@ -1563,29 +1563,15 @@ static int
1563sl811h_start(struct usb_hcd *hcd) 1563sl811h_start(struct usb_hcd *hcd)
1564{ 1564{
1565 struct sl811 *sl811 = hcd_to_sl811(hcd); 1565 struct sl811 *sl811 = hcd_to_sl811(hcd);
1566 struct usb_device *udev;
1567 1566
1568 /* chip has been reset, VBUS power is off */ 1567 /* chip has been reset, VBUS power is off */
1569
1570 udev = usb_alloc_dev(NULL, &hcd->self, 0);
1571 if (!udev)
1572 return -ENOMEM;
1573
1574 udev->speed = USB_SPEED_FULL;
1575 hcd->state = HC_STATE_RUNNING; 1568 hcd->state = HC_STATE_RUNNING;
1576 1569
1577 if (sl811->board) 1570 if (sl811->board) {
1578 hcd->can_wakeup = sl811->board->can_wakeup; 1571 hcd->can_wakeup = sl811->board->can_wakeup;
1579 1572 hcd->power_budget = sl811->board->power * 2;
1580 if (usb_hcd_register_root_hub(udev, hcd) != 0) {
1581 usb_put_dev(udev);
1582 sl811h_stop(hcd);
1583 return -ENODEV;
1584 } 1573 }
1585 1574
1586 if (sl811->board && sl811->board->power)
1587 hub_set_power_budget(udev, sl811->board->power * 2);
1588
1589 /* enable power and interupts */ 1575 /* enable power and interupts */
1590 port_power(sl811, 1); 1576 port_power(sl811, 1);
1591 1577
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 6e173265095c..38aebe361ca1 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -20,7 +20,6 @@
20#include <linux/timer.h> 20#include <linux/timer.h>
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22 22
23#include <pcmcia/version.h>
24#include <pcmcia/cs_types.h> 23#include <pcmcia/cs_types.h>
25#include <pcmcia/cs.h> 24#include <pcmcia/cs.h>
26#include <pcmcia/cistpl.h> 25#include <pcmcia/cistpl.h>
@@ -68,13 +67,6 @@ static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
68 67
69static dev_link_t *dev_list = NULL; 68static dev_link_t *dev_list = NULL;
70 69
71static int irq_list[4] = { -1 };
72static int irq_list_count;
73
74module_param_array(irq_list, int, &irq_list_count, 0444);
75
76INT_MODULE_PARM(irq_mask, 0xdeb8);
77
78typedef struct local_info_t { 70typedef struct local_info_t {
79 dev_link_t link; 71 dev_link_t link;
80 dev_node_t node; 72 dev_node_t node;
@@ -373,7 +365,7 @@ static dev_link_t *sl811_cs_attach(void)
373 local_info_t *local; 365 local_info_t *local;
374 dev_link_t *link; 366 dev_link_t *link;
375 client_reg_t client_reg; 367 client_reg_t client_reg;
376 int ret, i; 368 int ret;
377 369
378 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 370 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
379 if (!local) 371 if (!local)
@@ -385,11 +377,6 @@ static dev_link_t *sl811_cs_attach(void)
385 /* Initialize */ 377 /* Initialize */
386 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 378 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
387 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID; 379 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
388 if (irq_list[0] == -1)
389 link->irq.IRQInfo2 = irq_mask;
390 else
391 for (i = 0; i < irq_list_count; i++)
392 link->irq.IRQInfo2 |= 1 << irq_list[i];
393 link->irq.Handler = NULL; 380 link->irq.Handler = NULL;
394 381
395 link->conf.Attributes = 0; 382 link->conf.Attributes = 0;
@@ -401,11 +388,6 @@ static dev_link_t *sl811_cs_attach(void)
401 dev_list = link; 388 dev_list = link;
402 client_reg.dev_info = (dev_info_t *) &driver_name; 389 client_reg.dev_info = (dev_info_t *) &driver_name;
403 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; 390 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
404 client_reg.EventMask =
405 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
406 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
407 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
408 client_reg.event_handler = &sl811_cs_event;
409 client_reg.Version = 0x0210; 391 client_reg.Version = 0x0210;
410 client_reg.event_callback_args.client_data = link; 392 client_reg.event_callback_args.client_data = link;
411 ret = pcmcia_register_client(&link->handle, &client_reg); 393 ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -418,13 +400,21 @@ static dev_link_t *sl811_cs_attach(void)
418 return link; 400 return link;
419} 401}
420 402
403static struct pcmcia_device_id sl811_ids[] = {
404 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
405 PCMCIA_DEVICE_NULL,
406};
407MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
408
421static struct pcmcia_driver sl811_cs_driver = { 409static struct pcmcia_driver sl811_cs_driver = {
422 .owner = THIS_MODULE, 410 .owner = THIS_MODULE,
423 .drv = { 411 .drv = {
424 .name = (char *)driver_name, 412 .name = (char *)driver_name,
425 }, 413 },
426 .attach = sl811_cs_attach, 414 .attach = sl811_cs_attach,
415 .event = sl811_cs_event,
427 .detach = sl811_cs_detach, 416 .detach = sl811_cs_detach,
417 .id_table = sl811_ids,
428}; 418};
429 419
430/*====================================================================*/ 420/*====================================================================*/
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 24c73c5a3435..4538a98b6f9d 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -237,6 +237,37 @@ static int uhci_show_sc(int port, unsigned short status, char *buf, int len)
237 return out - buf; 237 return out - buf;
238} 238}
239 239
240static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len)
241{
242 char *out = buf;
243 char *rh_state;
244
245 /* Try to make sure there's enough memory */
246 if (len < 60)
247 return 0;
248
249 switch (uhci->rh_state) {
250 case UHCI_RH_RESET:
251 rh_state = "reset"; break;
252 case UHCI_RH_SUSPENDED:
253 rh_state = "suspended"; break;
254 case UHCI_RH_AUTO_STOPPED:
255 rh_state = "auto-stopped"; break;
256 case UHCI_RH_RESUMING:
257 rh_state = "resuming"; break;
258 case UHCI_RH_SUSPENDING:
259 rh_state = "suspending"; break;
260 case UHCI_RH_RUNNING:
261 rh_state = "running"; break;
262 case UHCI_RH_RUNNING_NODEVS:
263 rh_state = "running, no devs"; break;
264 default:
265 rh_state = "?"; break;
266 }
267 out += sprintf(out, "Root-hub state: %s\n", rh_state);
268 return out - buf;
269}
270
240static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) 271static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
241{ 272{
242 char *out = buf; 273 char *out = buf;
@@ -408,6 +439,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
408 439
409 spin_lock_irqsave(&uhci->lock, flags); 440 spin_lock_irqsave(&uhci->lock, flags);
410 441
442 out += uhci_show_root_hub_state(uhci, out, len - (out - buf));
411 out += sprintf(out, "HC status\n"); 443 out += sprintf(out, "HC status\n");
412 out += uhci_show_status(uhci, out, len - (out - buf)); 444 out += uhci_show_status(uhci, out, len - (out - buf));
413 445
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 49bd83ee0c75..0d5d2545bf07 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -13,18 +13,13 @@
13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu 16 * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu
17 * 17 *
18 * Intel documents this fairly well, and as far as I know there 18 * Intel documents this fairly well, and as far as I know there
19 * are no royalties or anything like that, but even so there are 19 * are no royalties or anything like that, but even so there are
20 * people who decided that they want to do the same thing in a 20 * people who decided that they want to do the same thing in a
21 * completely different way. 21 * completely different way.
22 * 22 *
23 * WARNING! The USB documentation is downright evil. Most of it
24 * is just crap, written by a committee. You're better off ignoring
25 * most of it, the important stuff is:
26 * - the low-level protocol (fairly simple but lots of small details)
27 * - working around the horridness of the rest
28 */ 23 */
29 24
30#include <linux/config.h> 25#include <linux/config.h>
@@ -64,7 +59,7 @@
64/* 59/*
65 * Version Information 60 * Version Information
66 */ 61 */
67#define DRIVER_VERSION "v2.2" 62#define DRIVER_VERSION "v2.3"
68#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \ 63#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \
69Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \ 64Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \
70Alan Stern" 65Alan Stern"
@@ -89,8 +84,9 @@ static char *errbuf;
89 84
90static kmem_cache_t *uhci_up_cachep; /* urb_priv */ 85static kmem_cache_t *uhci_up_cachep; /* urb_priv */
91 86
87static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state);
88static void wakeup_rh(struct uhci_hcd *uhci);
92static void uhci_get_current_frame_number(struct uhci_hcd *uhci); 89static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
93static void hc_state_transitions(struct uhci_hcd *uhci);
94 90
95/* If a transfer is still active after this much time, turn off FSBR */ 91/* If a transfer is still active after this much time, turn off FSBR */
96#define IDLE_TIMEOUT msecs_to_jiffies(50) 92#define IDLE_TIMEOUT msecs_to_jiffies(50)
@@ -101,308 +97,352 @@ static void hc_state_transitions(struct uhci_hcd *uhci);
101/* to make sure it doesn't hog all of the bandwidth */ 97/* to make sure it doesn't hog all of the bandwidth */
102#define DEPTH_INTERVAL 5 98#define DEPTH_INTERVAL 5
103 99
100static inline void restart_timer(struct uhci_hcd *uhci)
101{
102 mod_timer(&uhci->stall_timer, jiffies + msecs_to_jiffies(100));
103}
104
104#include "uhci-hub.c" 105#include "uhci-hub.c"
105#include "uhci-debug.c" 106#include "uhci-debug.c"
106#include "uhci-q.c" 107#include "uhci-q.c"
107 108
108static int init_stall_timer(struct usb_hcd *hcd); 109/*
109 110 * Make sure the controller is completely inactive, unable to
110static void stall_callback(unsigned long ptr) 111 * generate interrupts or do DMA.
112 */
113static void reset_hc(struct uhci_hcd *uhci)
111{ 114{
112 struct usb_hcd *hcd = (struct usb_hcd *)ptr; 115 int port;
113 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
114 struct urb_priv *up;
115 unsigned long flags;
116 116
117 spin_lock_irqsave(&uhci->lock, flags); 117 /* Turn off PIRQ enable and SMI enable. (This also turns off the
118 uhci_scan_schedule(uhci, NULL); 118 * BIOS's USB Legacy Support.) Turn off all the R/WC bits too.
119 119 */
120 list_for_each_entry(up, &uhci->urb_list, urb_list) { 120 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
121 struct urb *u = up->urb; 121 USBLEGSUP_RWC);
122
123 spin_lock(&u->lock);
124
125 /* Check if the FSBR timed out */
126 if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT))
127 uhci_fsbr_timeout(uhci, u);
128 122
129 spin_unlock(&u->lock); 123 /* Reset the HC - this will force us to get a
130 } 124 * new notification of any already connected
125 * ports due to the virtual disconnect that it
126 * implies.
127 */
128 outw(USBCMD_HCRESET, uhci->io_addr + USBCMD);
129 mb();
130 udelay(5);
131 if (inw(uhci->io_addr + USBCMD) & USBCMD_HCRESET)
132 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
131 133
132 /* Really disable FSBR */ 134 /* Just to be safe, disable interrupt requests and
133 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { 135 * make sure the controller is stopped.
134 uhci->fsbrtimeout = 0; 136 */
135 uhci->skel_term_qh->link = UHCI_PTR_TERM; 137 outw(0, uhci->io_addr + USBINTR);
136 } 138 outw(0, uhci->io_addr + USBCMD);
137 139
138 /* Poll for and perform state transitions */ 140 /* HCRESET doesn't affect the Suspend, Reset, and Resume Detect
139 hc_state_transitions(uhci); 141 * bits in the port status and control registers.
140 if (unlikely(uhci->suspended_ports && uhci->state != UHCI_SUSPENDED)) 142 * We have to clear them by hand.
141 uhci_check_ports(uhci); 143 */
144 for (port = 0; port < uhci->rh_numports; ++port)
145 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2));
142 146
143 init_stall_timer(hcd); 147 uhci->port_c_suspend = uhci->suspended_ports =
144 spin_unlock_irqrestore(&uhci->lock, flags); 148 uhci->resuming_ports = 0;
149 uhci->rh_state = UHCI_RH_RESET;
150 uhci->is_stopped = UHCI_IS_STOPPED;
151 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
152 uhci_to_hcd(uhci)->poll_rh = 0;
145} 153}
146 154
147static int init_stall_timer(struct usb_hcd *hcd) 155/*
156 * Last rites for a defunct/nonfunctional controller
157 * or one we don't want to use any more.
158 */
159static void hc_died(struct uhci_hcd *uhci)
148{ 160{
149 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 161 reset_hc(uhci);
150 162 uhci->hc_inaccessible = 1;
151 init_timer(&uhci->stall_timer); 163 del_timer(&uhci->stall_timer);
152 uhci->stall_timer.function = stall_callback;
153 uhci->stall_timer.data = (unsigned long)hcd;
154 uhci->stall_timer.expires = jiffies + msecs_to_jiffies(100);
155 add_timer(&uhci->stall_timer);
156
157 return 0;
158} 164}
159 165
160static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) 166/*
167 * Initialize a controller that was newly discovered or has just been
168 * resumed. In either case we can't be sure of its previous state.
169 */
170static void check_and_reset_hc(struct uhci_hcd *uhci)
161{ 171{
162 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 172 u16 legsup;
163 unsigned long io_addr = uhci->io_addr; 173 unsigned int cmd, intr;
164 unsigned short status;
165 174
166 /* 175 /*
167 * Read the interrupt status, and write it back to clear the 176 * When restarting a suspended controller, we expect all the
168 * interrupt cause. Contrary to the UHCI specification, the 177 * settings to be the same as we left them:
169 * "HC Halted" status bit is persistent: it is RO, not R/WC. 178 *
179 * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
180 * Controller is stopped and configured with EGSM set;
181 * No interrupts enabled except possibly Resume Detect.
182 *
183 * If any of these conditions are violated we do a complete reset.
170 */ 184 */
171 status = inw(io_addr + USBSTS); 185 pci_read_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, &legsup);
172 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */ 186 if (legsup & ~(USBLEGSUP_RO | USBLEGSUP_RWC)) {
173 return IRQ_NONE; 187 dev_dbg(uhci_dev(uhci), "%s: legsup = 0x%04x\n",
174 outw(status, io_addr + USBSTS); /* Clear it */ 188 __FUNCTION__, legsup);
175 189 goto reset_needed;
176 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
177 if (status & USBSTS_HSE)
178 dev_err(uhci_dev(uhci), "host system error, "
179 "PCI problems?\n");
180 if (status & USBSTS_HCPE)
181 dev_err(uhci_dev(uhci), "host controller process "
182 "error, something bad happened!\n");
183 if ((status & USBSTS_HCH) && uhci->state > 0) {
184 dev_err(uhci_dev(uhci), "host controller halted, "
185 "very bad!\n");
186 /* FIXME: Reset the controller, fix the offending TD */
187 }
188 } 190 }
189 191
190 if (status & USBSTS_RD) 192 cmd = inw(uhci->io_addr + USBCMD);
191 uhci->resume_detect = 1; 193 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
194 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
195 __FUNCTION__, cmd);
196 goto reset_needed;
197 }
192 198
193 spin_lock(&uhci->lock); 199 intr = inw(uhci->io_addr + USBINTR);
194 uhci_scan_schedule(uhci, regs); 200 if (intr & (~USBINTR_RESUME)) {
195 spin_unlock(&uhci->lock); 201 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
202 __FUNCTION__, intr);
203 goto reset_needed;
204 }
205 return;
196 206
197 return IRQ_HANDLED; 207reset_needed:
208 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
209 reset_hc(uhci);
198} 210}
199 211
200static void reset_hc(struct uhci_hcd *uhci) 212/*
213 * Store the basic register settings needed by the controller.
214 */
215static void configure_hc(struct uhci_hcd *uhci)
201{ 216{
202 unsigned long io_addr = uhci->io_addr; 217 /* Set the frame length to the default: 1 ms exactly */
218 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF);
203 219
204 /* Turn off PIRQ, SMI, and all interrupts. This also turns off 220 /* Store the frame list base address */
205 * the BIOS's USB Legacy Support. 221 outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD);
206 */
207 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
208 outw(0, uhci->io_addr + USBINTR);
209 222
210 /* Global reset for 50ms */ 223 /* Set the current frame number */
211 uhci->state = UHCI_RESET; 224 outw(uhci->frame_number, uhci->io_addr + USBFRNUM);
212 outw(USBCMD_GRESET, io_addr + USBCMD);
213 msleep(50);
214 outw(0, io_addr + USBCMD);
215 225
216 /* Another 10ms delay */ 226 /* Mark controller as running before we enable interrupts */
217 msleep(10); 227 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
218 uhci->resume_detect = 0; 228 mb();
219 uhci->is_stopped = UHCI_IS_STOPPED; 229
230 /* Enable PIRQ */
231 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
232 USBLEGSUP_DEFAULT);
220} 233}
221 234
222static void suspend_hc(struct uhci_hcd *uhci) 235
236static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
223{ 237{
224 unsigned long io_addr = uhci->io_addr; 238 int port;
225 239
226 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 240 switch (to_pci_dev(uhci_dev(uhci))->vendor) {
227 uhci->state = UHCI_SUSPENDED; 241 default:
228 uhci->resume_detect = 0; 242 break;
229 outw(USBCMD_EGSM, io_addr + USBCMD);
230 243
231 /* FIXME: Wait for the controller to actually stop */ 244 case PCI_VENDOR_ID_GENESYS:
232 uhci_get_current_frame_number(uhci); 245 /* Genesys Logic's GL880S controllers don't generate
233 uhci->is_stopped = UHCI_IS_STOPPED; 246 * resume-detect interrupts.
247 */
248 return 1;
234 249
235 uhci_scan_schedule(uhci, NULL); 250 case PCI_VENDOR_ID_INTEL:
251 /* Some of Intel's USB controllers have a bug that causes
252 * resume-detect interrupts if any port has an over-current
253 * condition. To make matters worse, some motherboards
254 * hardwire unused USB ports' over-current inputs active!
255 * To prevent problems, we will not enable resume-detect
256 * interrupts if any ports are OC.
257 */
258 for (port = 0; port < uhci->rh_numports; ++port) {
259 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
260 USBPORTSC_OC)
261 return 1;
262 }
263 break;
264 }
265 return 0;
236} 266}
237 267
238static void wakeup_hc(struct uhci_hcd *uhci) 268static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
269__releases(uhci->lock)
270__acquires(uhci->lock)
239{ 271{
240 unsigned long io_addr = uhci->io_addr; 272 int auto_stop;
273 int int_enable;
241 274
242 switch (uhci->state) { 275 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
243 case UHCI_SUSPENDED: /* Start the resume */ 276 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__,
244 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 277 (auto_stop ? " (auto-stop)" : ""));
245
246 /* Global resume for >= 20ms */
247 outw(USBCMD_FGR | USBCMD_EGSM, io_addr + USBCMD);
248 uhci->state = UHCI_RESUMING_1;
249 uhci->state_end = jiffies + msecs_to_jiffies(20);
250 uhci->is_stopped = 0;
251 break;
252 278
253 case UHCI_RESUMING_1: /* End global resume */ 279 /* If we get a suspend request when we're already auto-stopped
254 uhci->state = UHCI_RESUMING_2; 280 * then there's nothing to do.
255 outw(0, io_addr + USBCMD); 281 */
256 /* Falls through */ 282 if (uhci->rh_state == UHCI_RH_AUTO_STOPPED) {
257 283 uhci->rh_state = new_state;
258 case UHCI_RESUMING_2: /* Wait for EOP to be sent */ 284 return;
259 if (inw(io_addr + USBCMD) & USBCMD_FGR) 285 }
260 break;
261
262 /* Run for at least 1 second, and
263 * mark it configured with a 64-byte max packet */
264 uhci->state = UHCI_RUNNING_GRACE;
265 uhci->state_end = jiffies + HZ;
266 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP,
267 io_addr + USBCMD);
268 break;
269 286
270 case UHCI_RUNNING_GRACE: /* Now allowed to suspend */ 287 /* Enable resume-detect interrupts if they work.
271 uhci->state = UHCI_RUNNING; 288 * Then enter Global Suspend mode, still configured.
272 break; 289 */
290 int_enable = (resume_detect_interrupts_are_broken(uhci) ?
291 0 : USBINTR_RESUME);
292 outw(int_enable, uhci->io_addr + USBINTR);
293 outw(USBCMD_EGSM | USBCMD_CF, uhci->io_addr + USBCMD);
294 mb();
295 udelay(5);
273 296
274 default: 297 /* If we're auto-stopping then no devices have been attached
275 break; 298 * for a while, so there shouldn't be any active URBs and the
299 * controller should stop after a few microseconds. Otherwise
300 * we will give the controller one frame to stop.
301 */
302 if (!auto_stop && !(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) {
303 uhci->rh_state = UHCI_RH_SUSPENDING;
304 spin_unlock_irq(&uhci->lock);
305 msleep(1);
306 spin_lock_irq(&uhci->lock);
307 if (uhci->hc_inaccessible) /* Died */
308 return;
276 } 309 }
277} 310 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH))
311 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
278 312
279static int ports_active(struct uhci_hcd *uhci) 313 uhci_get_current_frame_number(uhci);
280{ 314 smp_wmb();
281 unsigned long io_addr = uhci->io_addr;
282 int connection = 0;
283 int i;
284 315
285 for (i = 0; i < uhci->rh_numports; i++) 316 uhci->rh_state = new_state;
286 connection |= (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_CCS); 317 uhci->is_stopped = UHCI_IS_STOPPED;
318 del_timer(&uhci->stall_timer);
319 uhci_to_hcd(uhci)->poll_rh = !int_enable;
287 320
288 return connection; 321 uhci_scan_schedule(uhci, NULL);
289} 322}
290 323
291static int suspend_allowed(struct uhci_hcd *uhci) 324static void start_rh(struct uhci_hcd *uhci)
292{ 325{
293 unsigned long io_addr = uhci->io_addr; 326 uhci->is_stopped = 0;
294 int i; 327 smp_wmb();
295
296 if (to_pci_dev(uhci_dev(uhci))->vendor != PCI_VENDOR_ID_INTEL)
297 return 1;
298 328
299 /* Some of Intel's USB controllers have a bug that causes false 329 /* Mark it configured and running with a 64-byte max packet.
300 * resume indications if any port has an over current condition. 330 * All interrupts are enabled, even though RESUME won't do anything.
301 * To prevent problems, we will not allow a global suspend if
302 * any ports are OC.
303 *
304 * Some motherboards using Intel's chipsets (but not using all
305 * the USB ports) appear to hardwire the over current inputs active
306 * to disable the USB ports.
307 */ 331 */
308 332 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, uhci->io_addr + USBCMD);
309 /* check for over current condition on any port */ 333 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP,
310 for (i = 0; i < uhci->rh_numports; i++) { 334 uhci->io_addr + USBINTR);
311 if (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_OC) 335 mb();
312 return 0; 336 uhci->rh_state = UHCI_RH_RUNNING;
313 } 337 uhci_to_hcd(uhci)->poll_rh = 1;
314 338 restart_timer(uhci);
315 return 1;
316} 339}
317 340
318static void hc_state_transitions(struct uhci_hcd *uhci) 341static void wakeup_rh(struct uhci_hcd *uhci)
342__releases(uhci->lock)
343__acquires(uhci->lock)
319{ 344{
320 switch (uhci->state) { 345 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__,
321 case UHCI_RUNNING: 346 uhci->rh_state == UHCI_RH_AUTO_STOPPED ?
347 " (auto-start)" : "");
322 348
323 /* global suspend if nothing connected for 1 second */ 349 /* If we are auto-stopped then no devices are attached so there's
324 if (!ports_active(uhci) && suspend_allowed(uhci)) { 350 * no need for wakeup signals. Otherwise we send Global Resume
325 uhci->state = UHCI_SUSPENDING_GRACE; 351 * for 20 ms.
326 uhci->state_end = jiffies + HZ; 352 */
327 } 353 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
328 break; 354 uhci->rh_state = UHCI_RH_RESUMING;
329 355 outw(USBCMD_FGR | USBCMD_EGSM | USBCMD_CF,
330 case UHCI_SUSPENDING_GRACE: 356 uhci->io_addr + USBCMD);
331 if (ports_active(uhci)) 357 spin_unlock_irq(&uhci->lock);
332 uhci->state = UHCI_RUNNING; 358 msleep(20);
333 else if (time_after_eq(jiffies, uhci->state_end)) 359 spin_lock_irq(&uhci->lock);
334 suspend_hc(uhci); 360 if (uhci->hc_inaccessible) /* Died */
335 break; 361 return;
336 362
337 case UHCI_SUSPENDED: 363 /* End Global Resume and wait for EOP to be sent */
338 364 outw(USBCMD_CF, uhci->io_addr + USBCMD);
339 /* wakeup if requested by a device */ 365 mb();
340 if (uhci->resume_detect) 366 udelay(4);
341 wakeup_hc(uhci); 367 if (inw(uhci->io_addr + USBCMD) & USBCMD_FGR)
342 break; 368 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n");
369 }
343 370
344 case UHCI_RESUMING_1: 371 start_rh(uhci);
345 case UHCI_RESUMING_2:
346 case UHCI_RUNNING_GRACE:
347 if (time_after_eq(jiffies, uhci->state_end))
348 wakeup_hc(uhci);
349 break;
350 372
351 default: 373 /* Restart root hub polling */
352 break; 374 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
353 }
354} 375}
355 376
356/* 377static void stall_callback(unsigned long _uhci)
357 * Store the current frame number in uhci->frame_number if the controller
358 * is runnning
359 */
360static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
361{ 378{
379 struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci;
380 unsigned long flags;
381
382 spin_lock_irqsave(&uhci->lock, flags);
383 uhci_scan_schedule(uhci, NULL);
384 check_fsbr(uhci);
385
362 if (!uhci->is_stopped) 386 if (!uhci->is_stopped)
363 uhci->frame_number = inw(uhci->io_addr + USBFRNUM); 387 restart_timer(uhci);
388 spin_unlock_irqrestore(&uhci->lock, flags);
364} 389}
365 390
366static int start_hc(struct uhci_hcd *uhci) 391static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
367{ 392{
368 unsigned long io_addr = uhci->io_addr; 393 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
369 int timeout = 10; 394 unsigned short status;
395 unsigned long flags;
370 396
371 /* 397 /*
372 * Reset the HC - this will force us to get a 398 * Read the interrupt status, and write it back to clear the
373 * new notification of any already connected 399 * interrupt cause. Contrary to the UHCI specification, the
374 * ports due to the virtual disconnect that it 400 * "HC Halted" status bit is persistent: it is RO, not R/WC.
375 * implies.
376 */ 401 */
377 outw(USBCMD_HCRESET, io_addr + USBCMD); 402 status = inw(uhci->io_addr + USBSTS);
378 while (inw(io_addr + USBCMD) & USBCMD_HCRESET) { 403 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */
379 if (--timeout < 0) { 404 return IRQ_NONE;
380 dev_err(uhci_dev(uhci), "USBCMD_HCRESET timed out!\n"); 405 outw(status, uhci->io_addr + USBSTS); /* Clear it */
381 return -ETIMEDOUT; 406
407 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
408 if (status & USBSTS_HSE)
409 dev_err(uhci_dev(uhci), "host system error, "
410 "PCI problems?\n");
411 if (status & USBSTS_HCPE)
412 dev_err(uhci_dev(uhci), "host controller process "
413 "error, something bad happened!\n");
414 if (status & USBSTS_HCH) {
415 spin_lock_irqsave(&uhci->lock, flags);
416 if (uhci->rh_state >= UHCI_RH_RUNNING) {
417 dev_err(uhci_dev(uhci),
418 "host controller halted, "
419 "very bad!\n");
420 hc_died(uhci);
421 spin_unlock_irqrestore(&uhci->lock, flags);
422 return IRQ_HANDLED;
423 }
424 spin_unlock_irqrestore(&uhci->lock, flags);
382 } 425 }
383 msleep(1);
384 } 426 }
385 427
386 /* Mark controller as running before we enable interrupts */ 428 if (status & USBSTS_RD)
387 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 429 usb_hcd_poll_rh_status(hcd);
388
389 /* Turn on PIRQ and all interrupts */
390 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
391 USBLEGSUP_DEFAULT);
392 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP,
393 io_addr + USBINTR);
394 430
395 /* Start at frame 0 */ 431 spin_lock_irqsave(&uhci->lock, flags);
396 outw(0, io_addr + USBFRNUM); 432 uhci_scan_schedule(uhci, regs);
397 outl(uhci->fl->dma_handle, io_addr + USBFLBASEADD); 433 spin_unlock_irqrestore(&uhci->lock, flags);
398 434
399 /* Run and mark it configured with a 64-byte max packet */ 435 return IRQ_HANDLED;
400 uhci->state = UHCI_RUNNING_GRACE; 436}
401 uhci->state_end = jiffies + HZ;
402 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, io_addr + USBCMD);
403 uhci->is_stopped = 0;
404 437
405 return 0; 438/*
439 * Store the current frame number in uhci->frame_number if the controller
440 * is runnning
441 */
442static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
443{
444 if (!uhci->is_stopped)
445 uhci->frame_number = inw(uhci->io_addr + USBFRNUM);
406} 446}
407 447
408/* 448/*
@@ -448,16 +488,58 @@ static void release_uhci(struct uhci_hcd *uhci)
448static int uhci_reset(struct usb_hcd *hcd) 488static int uhci_reset(struct usb_hcd *hcd)
449{ 489{
450 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 490 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
491 unsigned io_size = (unsigned) hcd->rsrc_len;
492 int port;
451 493
452 uhci->io_addr = (unsigned long) hcd->rsrc_start; 494 uhci->io_addr = (unsigned long) hcd->rsrc_start;
453 495
454 /* Kick BIOS off this hardware and reset, so we won't get 496 /* The UHCI spec says devices must have 2 ports, and goes on to say
455 * interrupts from any previous setup. 497 * they may have more but gives no way to determine how many there
498 * are. However according to the UHCI spec, Bit 7 of the port
499 * status and control register is always set to 1. So we try to
500 * use this to our advantage. Another common failure mode when
501 * a nonexistent register is addressed is to return all ones, so
502 * we test for that also.
456 */ 503 */
457 reset_hc(uhci); 504 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
505 unsigned int portstatus;
506
507 portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2));
508 if (!(portstatus & 0x0080) || portstatus == 0xffff)
509 break;
510 }
511 if (debug)
512 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
513
514 /* Anything greater than 7 is weird so we'll ignore it. */
515 if (port > UHCI_RH_MAXCHILD) {
516 dev_info(uhci_dev(uhci), "port count misdetected? "
517 "forcing to 2 ports\n");
518 port = 2;
519 }
520 uhci->rh_numports = port;
521
522 /* Kick BIOS off this hardware and reset if the controller
523 * isn't already safely quiescent.
524 */
525 check_and_reset_hc(uhci);
458 return 0; 526 return 0;
459} 527}
460 528
529/* Make sure the controller is quiescent and that we're not using it
530 * any more. This is mainly for the benefit of programs which, like kexec,
531 * expect the hardware to be idle: not doing DMA or generating IRQs.
532 *
533 * This routine may be called in a damaged or failing kernel. Hence we
534 * do not acquire the spinlock before shutting down the controller.
535 */
536static void uhci_shutdown(struct pci_dev *pdev)
537{
538 struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev);
539
540 hc_died(hcd_to_uhci(hcd));
541}
542
461/* 543/*
462 * Allocate a frame list, and then setup the skeleton 544 * Allocate a frame list, and then setup the skeleton
463 * 545 *
@@ -478,17 +560,20 @@ static int uhci_start(struct usb_hcd *hcd)
478{ 560{
479 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 561 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
480 int retval = -EBUSY; 562 int retval = -EBUSY;
481 int i, port; 563 int i;
482 unsigned io_size;
483 dma_addr_t dma_handle; 564 dma_addr_t dma_handle;
484 struct usb_device *udev;
485 struct dentry *dentry; 565 struct dentry *dentry;
486 566
487 io_size = (unsigned) hcd->rsrc_len; 567 hcd->uses_new_polling = 1;
568 if (pci_find_capability(to_pci_dev(uhci_dev(uhci)), PCI_CAP_ID_PM))
569 hcd->can_wakeup = 1; /* Assume it supports PME# */
488 570
489 dentry = debugfs_create_file(hcd->self.bus_name, S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci, &uhci_debug_operations); 571 dentry = debugfs_create_file(hcd->self.bus_name,
572 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci,
573 &uhci_debug_operations);
490 if (!dentry) { 574 if (!dentry) {
491 dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n"); 575 dev_err(uhci_dev(uhci),
576 "couldn't create uhci debugfs entry\n");
492 retval = -ENOMEM; 577 retval = -ENOMEM;
493 goto err_create_debug_entry; 578 goto err_create_debug_entry;
494 } 579 }
@@ -510,6 +595,10 @@ static int uhci_start(struct usb_hcd *hcd)
510 595
511 init_waitqueue_head(&uhci->waitqh); 596 init_waitqueue_head(&uhci->waitqh);
512 597
598 init_timer(&uhci->stall_timer);
599 uhci->stall_timer.function = stall_callback;
600 uhci->stall_timer.data = (unsigned long) uhci;
601
513 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 602 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl),
514 &dma_handle, 0); 603 &dma_handle, 0);
515 if (!uhci->fl) { 604 if (!uhci->fl) {
@@ -536,46 +625,14 @@ static int uhci_start(struct usb_hcd *hcd)
536 goto err_create_qh_pool; 625 goto err_create_qh_pool;
537 } 626 }
538 627
539 /* Initialize the root hub */ 628 uhci->term_td = uhci_alloc_td(uhci);
540
541 /* UHCI specs says devices must have 2 ports, but goes on to say */
542 /* they may have more but give no way to determine how many they */
543 /* have. However, according to the UHCI spec, Bit 7 is always set */
544 /* to 1. So we try to use this to our advantage */
545 for (port = 0; port < (io_size - 0x10) / 2; port++) {
546 unsigned int portstatus;
547
548 portstatus = inw(uhci->io_addr + 0x10 + (port * 2));
549 if (!(portstatus & 0x0080))
550 break;
551 }
552 if (debug)
553 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
554
555 /* This is experimental so anything less than 2 or greater than 8 is */
556 /* something weird and we'll ignore it */
557 if (port < 2 || port > UHCI_RH_MAXCHILD) {
558 dev_info(uhci_dev(uhci), "port count misdetected? "
559 "forcing to 2 ports\n");
560 port = 2;
561 }
562
563 uhci->rh_numports = port;
564
565 udev = usb_alloc_dev(NULL, &hcd->self, 0);
566 if (!udev) {
567 dev_err(uhci_dev(uhci), "unable to allocate root hub\n");
568 goto err_alloc_root_hub;
569 }
570
571 uhci->term_td = uhci_alloc_td(uhci, udev);
572 if (!uhci->term_td) { 629 if (!uhci->term_td) {
573 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n"); 630 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n");
574 goto err_alloc_term_td; 631 goto err_alloc_term_td;
575 } 632 }
576 633
577 for (i = 0; i < UHCI_NUM_SKELQH; i++) { 634 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
578 uhci->skelqh[i] = uhci_alloc_qh(uhci, udev); 635 uhci->skelqh[i] = uhci_alloc_qh(uhci);
579 if (!uhci->skelqh[i]) { 636 if (!uhci->skelqh[i]) {
580 dev_err(uhci_dev(uhci), "unable to allocate QH\n"); 637 dev_err(uhci_dev(uhci), "unable to allocate QH\n");
581 goto err_alloc_skelqh; 638 goto err_alloc_skelqh;
@@ -641,32 +698,17 @@ static int uhci_start(struct usb_hcd *hcd)
641 698
642 /* 699 /*
643 * Some architectures require a full mb() to enforce completion of 700 * Some architectures require a full mb() to enforce completion of
644 * the memory writes above before the I/O transfers in start_hc(). 701 * the memory writes above before the I/O transfers in configure_hc().
645 */ 702 */
646 mb(); 703 mb();
647 if ((retval = start_hc(uhci)) != 0)
648 goto err_alloc_skelqh;
649
650 init_stall_timer(hcd);
651
652 udev->speed = USB_SPEED_FULL;
653
654 if (usb_hcd_register_root_hub(udev, hcd) != 0) {
655 dev_err(uhci_dev(uhci), "unable to start root hub\n");
656 retval = -ENOMEM;
657 goto err_start_root_hub;
658 }
659 704
705 configure_hc(uhci);
706 start_rh(uhci);
660 return 0; 707 return 0;
661 708
662/* 709/*
663 * error exits: 710 * error exits:
664 */ 711 */
665err_start_root_hub:
666 reset_hc(uhci);
667
668 del_timer_sync(&uhci->stall_timer);
669
670err_alloc_skelqh: 712err_alloc_skelqh:
671 for (i = 0; i < UHCI_NUM_SKELQH; i++) 713 for (i = 0; i < UHCI_NUM_SKELQH; i++)
672 if (uhci->skelqh[i]) { 714 if (uhci->skelqh[i]) {
@@ -678,9 +720,6 @@ err_alloc_skelqh:
678 uhci->term_td = NULL; 720 uhci->term_td = NULL;
679 721
680err_alloc_term_td: 722err_alloc_term_td:
681 usb_put_dev(udev);
682
683err_alloc_root_hub:
684 dma_pool_destroy(uhci->qh_pool); 723 dma_pool_destroy(uhci->qh_pool);
685 uhci->qh_pool = NULL; 724 uhci->qh_pool = NULL;
686 725
@@ -705,73 +744,114 @@ static void uhci_stop(struct usb_hcd *hcd)
705{ 744{
706 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 745 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
707 746
708 del_timer_sync(&uhci->stall_timer);
709 reset_hc(uhci);
710
711 spin_lock_irq(&uhci->lock); 747 spin_lock_irq(&uhci->lock);
748 reset_hc(uhci);
712 uhci_scan_schedule(uhci, NULL); 749 uhci_scan_schedule(uhci, NULL);
713 spin_unlock_irq(&uhci->lock); 750 spin_unlock_irq(&uhci->lock);
714 751
752 del_timer_sync(&uhci->stall_timer);
715 release_uhci(uhci); 753 release_uhci(uhci);
716} 754}
717 755
718#ifdef CONFIG_PM 756#ifdef CONFIG_PM
757static int uhci_rh_suspend(struct usb_hcd *hcd)
758{
759 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
760
761 spin_lock_irq(&uhci->lock);
762 if (!uhci->hc_inaccessible) /* Not dead */
763 suspend_rh(uhci, UHCI_RH_SUSPENDED);
764 spin_unlock_irq(&uhci->lock);
765 return 0;
766}
767
768static int uhci_rh_resume(struct usb_hcd *hcd)
769{
770 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
771 int rc = 0;
772
773 spin_lock_irq(&uhci->lock);
774 if (uhci->hc_inaccessible) {
775 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
776 dev_warn(uhci_dev(uhci), "HC isn't running!\n");
777 rc = -ENODEV;
778 }
779 /* Otherwise the HC is dead */
780 } else
781 wakeup_rh(uhci);
782 spin_unlock_irq(&uhci->lock);
783 return rc;
784}
785
719static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) 786static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
720{ 787{
721 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 788 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
789 int rc = 0;
790
791 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
722 792
723 spin_lock_irq(&uhci->lock); 793 spin_lock_irq(&uhci->lock);
794 if (uhci->hc_inaccessible) /* Dead or already suspended */
795 goto done;
724 796
725 /* Don't try to suspend broken motherboards, reset instead */ 797#ifndef CONFIG_USB_SUSPEND
726 if (suspend_allowed(uhci)) 798 /* Otherwise this would never happen */
727 suspend_hc(uhci); 799 suspend_rh(uhci, UHCI_RH_SUSPENDED);
728 else { 800#endif
729 spin_unlock_irq(&uhci->lock); 801
730 reset_hc(uhci); 802 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
731 spin_lock_irq(&uhci->lock); 803 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
732 uhci_scan_schedule(uhci, NULL); 804 hcd->state = HC_STATE_RUNNING;
733 } 805 rc = -EBUSY;
806 goto done;
807 };
734 808
809 /* All PCI host controllers are required to disable IRQ generation
810 * at the source, so we must turn off PIRQ.
811 */
812 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
813 uhci->hc_inaccessible = 1;
814
815 /* FIXME: Enable non-PME# remote wakeup? */
816
817done:
735 spin_unlock_irq(&uhci->lock); 818 spin_unlock_irq(&uhci->lock);
736 return 0; 819 if (rc == 0)
820 del_timer_sync(&hcd->rh_timer);
821 return rc;
737} 822}
738 823
739static int uhci_resume(struct usb_hcd *hcd) 824static int uhci_resume(struct usb_hcd *hcd)
740{ 825{
741 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 826 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
742 int rc;
743 827
744 pci_set_master(to_pci_dev(uhci_dev(uhci))); 828 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
745 829
830 if (uhci->rh_state == UHCI_RH_RESET) /* Dead */
831 return 0;
746 spin_lock_irq(&uhci->lock); 832 spin_lock_irq(&uhci->lock);
747 833
748 if (uhci->state == UHCI_SUSPENDED) { 834 /* FIXME: Disable non-PME# remote wakeup? */
749 835
750 /* 836 uhci->hc_inaccessible = 0;
751 * Some systems don't maintain the UHCI register values 837
752 * during a PM suspend/resume cycle, so reinitialize 838 /* The BIOS may have changed the controller settings during a
753 * the Frame Number, Framelist Base Address, Interrupt 839 * system wakeup. Check it and reconfigure to avoid problems.
754 * Enable, and Legacy Support registers. 840 */
755 */ 841 check_and_reset_hc(uhci);
756 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 842 configure_hc(uhci);
757 0); 843
758 outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 844#ifndef CONFIG_USB_SUSPEND
759 outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD); 845 /* Otherwise this would never happen */
760 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | 846 wakeup_rh(uhci);
761 USBINTR_SP, uhci->io_addr + USBINTR); 847#endif
762 uhci->resume_detect = 1; 848 if (uhci->rh_state == UHCI_RH_RESET)
763 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 849 suspend_rh(uhci, UHCI_RH_SUSPENDED);
764 USBLEGSUP_DEFAULT);
765 } else {
766 spin_unlock_irq(&uhci->lock);
767 reset_hc(uhci);
768 if ((rc = start_hc(uhci)) != 0)
769 return rc;
770 spin_lock_irq(&uhci->lock);
771 }
772 hcd->state = HC_STATE_RUNNING;
773 850
774 spin_unlock_irq(&uhci->lock); 851 spin_unlock_irq(&uhci->lock);
852
853 if (hcd->poll_rh)
854 usb_hcd_poll_rh_status(hcd);
775 return 0; 855 return 0;
776} 856}
777#endif 857#endif
@@ -788,13 +868,15 @@ static void uhci_hcd_endpoint_disable(struct usb_hcd *hcd,
788static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) 868static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
789{ 869{
790 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 870 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
791 int frame_number;
792 unsigned long flags; 871 unsigned long flags;
872 int is_stopped;
873 int frame_number;
793 874
794 /* Minimize latency by avoiding the spinlock */ 875 /* Minimize latency by avoiding the spinlock */
795 local_irq_save(flags); 876 local_irq_save(flags);
796 rmb(); 877 is_stopped = uhci->is_stopped;
797 frame_number = (uhci->is_stopped ? uhci->frame_number : 878 smp_rmb();
879 frame_number = (is_stopped ? uhci->frame_number :
798 inw(uhci->io_addr + USBFRNUM)); 880 inw(uhci->io_addr + USBFRNUM));
799 local_irq_restore(flags); 881 local_irq_restore(flags);
800 return frame_number; 882 return frame_number;
@@ -817,6 +899,8 @@ static const struct hc_driver uhci_driver = {
817#ifdef CONFIG_PM 899#ifdef CONFIG_PM
818 .suspend = uhci_suspend, 900 .suspend = uhci_suspend,
819 .resume = uhci_resume, 901 .resume = uhci_resume,
902 .hub_suspend = uhci_rh_suspend,
903 .hub_resume = uhci_rh_resume,
820#endif 904#endif
821 .stop = uhci_stop, 905 .stop = uhci_stop,
822 906
@@ -845,6 +929,7 @@ static struct pci_driver uhci_pci_driver = {
845 929
846 .probe = usb_hcd_pci_probe, 930 .probe = usb_hcd_pci_probe,
847 .remove = usb_hcd_pci_remove, 931 .remove = usb_hcd_pci_remove,
932 .shutdown = uhci_shutdown,
848 933
849#ifdef CONFIG_PM 934#ifdef CONFIG_PM
850 .suspend = usb_hcd_pci_suspend, 935 .suspend = usb_hcd_pci_suspend,
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 02255d69e1fe..bf9c5f9b508b 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -41,6 +41,7 @@
41#define USBFRNUM 6 41#define USBFRNUM 6
42#define USBFLBASEADD 8 42#define USBFLBASEADD 8
43#define USBSOF 12 43#define USBSOF 12
44#define USBSOF_DEFAULT 64 /* Frame length is exactly 1 ms */
44 45
45/* USB port status and control registers */ 46/* USB port status and control registers */
46#define USBPORTSC1 16 47#define USBPORTSC1 16
@@ -66,6 +67,8 @@
66/* Legacy support register */ 67/* Legacy support register */
67#define USBLEGSUP 0xc0 68#define USBLEGSUP 0xc0
68#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 69#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
70#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
71#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
69 72
70#define UHCI_NULL_DATA_SIZE 0x7FF /* for UHCI controller TD */ 73#define UHCI_NULL_DATA_SIZE 0x7FF /* for UHCI controller TD */
71 74
@@ -111,7 +114,6 @@ struct uhci_qh {
111 /* Software fields */ 114 /* Software fields */
112 dma_addr_t dma_handle; 115 dma_addr_t dma_handle;
113 116
114 struct usb_device *dev;
115 struct urb_priv *urbp; 117 struct urb_priv *urbp;
116 118
117 struct list_head list; /* P: uhci->frame_list_lock */ 119 struct list_head list; /* P: uhci->frame_list_lock */
@@ -203,7 +205,6 @@ struct uhci_td {
203 /* Software fields */ 205 /* Software fields */
204 dma_addr_t dma_handle; 206 dma_addr_t dma_handle;
205 207
206 struct usb_device *dev;
207 struct urb *urb; 208 struct urb *urb;
208 209
209 struct list_head list; /* P: urb->lock */ 210 struct list_head list; /* P: urb->lock */
@@ -314,26 +315,32 @@ static inline int __interval_to_skel(int interval)
314} 315}
315 316
316/* 317/*
317 * Device states for the host controller. 318 * States for the root hub.
318 * 319 *
319 * To prevent "bouncing" in the presence of electrical noise, 320 * To prevent "bouncing" in the presence of electrical noise,
320 * we insist on a 1-second "grace" period, before switching to 321 * when there are no devices attached we delay for 1 second in the
321 * the RUNNING or SUSPENDED states, during which the state is 322 * RUNNING_NODEVS state before switching to the AUTO_STOPPED state.
322 * not allowed to change. 323 *
323 * 324 * (Note that the AUTO_STOPPED state won't be necessary once the hub
324 * The resume process is divided into substates in order to avoid 325 * driver learns to autosuspend.)
325 * potentially length delays during the timer handler.
326 *
327 * States in which the host controller is halted must have values <= 0.
328 */ 326 */
329enum uhci_state { 327enum uhci_rh_state {
330 UHCI_RESET, 328 /* In the following states the HC must be halted.
331 UHCI_RUNNING_GRACE, /* Before RUNNING */ 329 * These two must come first */
332 UHCI_RUNNING, /* The normal state */ 330 UHCI_RH_RESET,
333 UHCI_SUSPENDING_GRACE, /* Before SUSPENDED */ 331 UHCI_RH_SUSPENDED,
334 UHCI_SUSPENDED = -10, /* When no devices are attached */ 332
335 UHCI_RESUMING_1, 333 UHCI_RH_AUTO_STOPPED,
336 UHCI_RESUMING_2 334 UHCI_RH_RESUMING,
335
336 /* In this state the HC changes from running to halted,
337 * so it can legally appear either way. */
338 UHCI_RH_SUSPENDING,
339
340 /* In the following states it's an error if the HC is halted.
341 * These two must come last */
342 UHCI_RH_RUNNING, /* The normal state */
343 UHCI_RH_RUNNING_NODEVS, /* Running with no devices attached */
337}; 344};
338 345
339/* 346/*
@@ -363,15 +370,16 @@ struct uhci_hcd {
363 int fsbr; /* Full-speed bandwidth reclamation */ 370 int fsbr; /* Full-speed bandwidth reclamation */
364 unsigned long fsbrtimeout; /* FSBR delay */ 371 unsigned long fsbrtimeout; /* FSBR delay */
365 372
366 enum uhci_state state; /* FIXME: needs a spinlock */ 373 enum uhci_rh_state rh_state;
367 unsigned long state_end; /* Time of next transition */ 374 unsigned long auto_stop_time; /* When to AUTO_STOP */
375
368 unsigned int frame_number; /* As of last check */ 376 unsigned int frame_number; /* As of last check */
369 unsigned int is_stopped; 377 unsigned int is_stopped;
370#define UHCI_IS_STOPPED 9999 /* Larger than a frame # */ 378#define UHCI_IS_STOPPED 9999 /* Larger than a frame # */
371 379
372 unsigned int scan_in_progress:1; /* Schedule scan is running */ 380 unsigned int scan_in_progress:1; /* Schedule scan is running */
373 unsigned int need_rescan:1; /* Redo the schedule scan */ 381 unsigned int need_rescan:1; /* Redo the schedule scan */
374 unsigned int resume_detect:1; /* Need a Global Resume */ 382 unsigned int hc_inaccessible:1; /* HC is suspended or dead */
375 383
376 /* Support for port suspend/resume/reset */ 384 /* Support for port suspend/resume/reset */
377 unsigned long port_c_suspend; /* Bit-arrays of ports */ 385 unsigned long port_c_suspend; /* Bit-arrays of ports */
@@ -451,4 +459,11 @@ struct urb_priv {
451 * #2 urb->lock 459 * #2 urb->lock
452 */ 460 */
453 461
462
463/* Some special IDs */
464
465#define PCI_VENDOR_ID_GENESYS 0x17a0
466#define PCI_DEVICE_ID_GL880S_UHCI 0x8083
467#define PCI_DEVICE_ID_GL880S_EHCI 0x8084
468
454#endif 469#endif
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 4c45ba8390f8..4eace2b19ddb 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -33,9 +33,24 @@ static __u8 root_hub_hub_des[] =
33/* status change bits: nonzero writes will clear */ 33/* status change bits: nonzero writes will clear */
34#define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC) 34#define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC)
35 35
36static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf) 36/* A port that either is connected or has a changed-bit set will prevent
37 * us from AUTO_STOPPING.
38 */
39static int any_ports_active(struct uhci_hcd *uhci)
40{
41 int port;
42
43 for (port = 0; port < uhci->rh_numports; ++port) {
44 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) &
45 (USBPORTSC_CCS | RWC_BITS)) ||
46 test_bit(port, &uhci->port_c_suspend))
47 return 1;
48 }
49 return 0;
50}
51
52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
37{ 53{
38 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
39 int port; 54 int port;
40 55
41 *buf = 0; 56 *buf = 0;
@@ -44,8 +59,6 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
44 test_bit(port, &uhci->port_c_suspend)) 59 test_bit(port, &uhci->port_c_suspend))
45 *buf |= (1 << (port + 1)); 60 *buf |= (1 << (port + 1));
46 } 61 }
47 if (*buf && uhci->state == UHCI_SUSPENDED)
48 uhci->resume_detect = 1;
49 return !!*buf; 62 return !!*buf;
50} 63}
51 64
@@ -115,6 +128,11 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
115 set_bit(port, &uhci->resuming_ports); 128 set_bit(port, &uhci->resuming_ports);
116 uhci->ports_timeout = jiffies + 129 uhci->ports_timeout = jiffies +
117 msecs_to_jiffies(20); 130 msecs_to_jiffies(20);
131
132 /* Make sure we see the port again
133 * after the resuming period is over. */
134 mod_timer(&uhci_to_hcd(uhci)->rh_timer,
135 uhci->ports_timeout);
118 } else if (time_after_eq(jiffies, 136 } else if (time_after_eq(jiffies,
119 uhci->ports_timeout)) { 137 uhci->ports_timeout)) {
120 uhci_finish_suspend(uhci, port, port_addr); 138 uhci_finish_suspend(uhci, port, port_addr);
@@ -123,6 +141,60 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
123 } 141 }
124} 142}
125 143
144static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
145{
146 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
147 unsigned long flags;
148 int status;
149
150 spin_lock_irqsave(&uhci->lock, flags);
151 if (uhci->hc_inaccessible) {
152 status = 0;
153 goto done;
154 }
155
156 uhci_check_ports(uhci);
157 status = get_hub_status_data(uhci, buf);
158
159 switch (uhci->rh_state) {
160 case UHCI_RH_SUSPENDING:
161 case UHCI_RH_SUSPENDED:
162 /* if port change, ask to be resumed */
163 if (status)
164 usb_hcd_resume_root_hub(hcd);
165 break;
166
167 case UHCI_RH_AUTO_STOPPED:
168 /* if port change, auto start */
169 if (status)
170 wakeup_rh(uhci);
171 break;
172
173 case UHCI_RH_RUNNING:
174 /* are any devices attached? */
175 if (!any_ports_active(uhci)) {
176 uhci->rh_state = UHCI_RH_RUNNING_NODEVS;
177 uhci->auto_stop_time = jiffies + HZ;
178 }
179 break;
180
181 case UHCI_RH_RUNNING_NODEVS:
182 /* auto-stop if nothing connected for 1 second */
183 if (any_ports_active(uhci))
184 uhci->rh_state = UHCI_RH_RUNNING;
185 else if (time_after_eq(jiffies, uhci->auto_stop_time))
186 suspend_rh(uhci, UHCI_RH_AUTO_STOPPED);
187 break;
188
189 default:
190 break;
191 }
192
193done:
194 spin_unlock_irqrestore(&uhci->lock, flags);
195 return status;
196}
197
126/* size of returned buffer is part of USB spec */ 198/* size of returned buffer is part of USB spec */
127static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 199static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
128 u16 wIndex, char *buf, u16 wLength) 200 u16 wIndex, char *buf, u16 wLength)
@@ -134,6 +206,9 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
134 u16 wPortChange, wPortStatus; 206 u16 wPortChange, wPortStatus;
135 unsigned long flags; 207 unsigned long flags;
136 208
209 if (uhci->hc_inaccessible)
210 return -ETIMEDOUT;
211
137 spin_lock_irqsave(&uhci->lock, flags); 212 spin_lock_irqsave(&uhci->lock, flags);
138 switch (typeReq) { 213 switch (typeReq) {
139 214
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 2a7c19501f24..bbb36cd6ed61 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -32,6 +32,8 @@ static void uhci_free_pending_tds(struct uhci_hcd *uhci);
32 */ 32 */
33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci) 33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci)
34{ 34{
35 if (uhci->is_stopped)
36 mod_timer(&uhci->stall_timer, jiffies);
35 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); 37 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC);
36} 38}
37 39
@@ -46,7 +48,7 @@ static inline void uhci_moveto_complete(struct uhci_hcd *uhci,
46 list_move_tail(&urbp->urb_list, &uhci->complete_list); 48 list_move_tail(&urbp->urb_list, &uhci->complete_list);
47} 49}
48 50
49static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci, struct usb_device *dev) 51static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
50{ 52{
51 dma_addr_t dma_handle; 53 dma_addr_t dma_handle;
52 struct uhci_td *td; 54 struct uhci_td *td;
@@ -61,14 +63,11 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci, struct usb_device *d
61 td->buffer = 0; 63 td->buffer = 0;
62 64
63 td->frame = -1; 65 td->frame = -1;
64 td->dev = dev;
65 66
66 INIT_LIST_HEAD(&td->list); 67 INIT_LIST_HEAD(&td->list);
67 INIT_LIST_HEAD(&td->remove_list); 68 INIT_LIST_HEAD(&td->remove_list);
68 INIT_LIST_HEAD(&td->fl_list); 69 INIT_LIST_HEAD(&td->fl_list);
69 70
70 usb_get_dev(dev);
71
72 return td; 71 return td;
73} 72}
74 73
@@ -168,13 +167,10 @@ static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
168 if (!list_empty(&td->fl_list)) 167 if (!list_empty(&td->fl_list))
169 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); 168 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td);
170 169
171 if (td->dev)
172 usb_put_dev(td->dev);
173
174 dma_pool_free(uhci->td_pool, td, td->dma_handle); 170 dma_pool_free(uhci->td_pool, td, td->dma_handle);
175} 171}
176 172
177static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, struct usb_device *dev) 173static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci)
178{ 174{
179 dma_addr_t dma_handle; 175 dma_addr_t dma_handle;
180 struct uhci_qh *qh; 176 struct uhci_qh *qh;
@@ -188,14 +184,11 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, struct usb_device *d
188 qh->element = UHCI_PTR_TERM; 184 qh->element = UHCI_PTR_TERM;
189 qh->link = UHCI_PTR_TERM; 185 qh->link = UHCI_PTR_TERM;
190 186
191 qh->dev = dev;
192 qh->urbp = NULL; 187 qh->urbp = NULL;
193 188
194 INIT_LIST_HEAD(&qh->list); 189 INIT_LIST_HEAD(&qh->list);
195 INIT_LIST_HEAD(&qh->remove_list); 190 INIT_LIST_HEAD(&qh->remove_list);
196 191
197 usb_get_dev(dev);
198
199 return qh; 192 return qh;
200} 193}
201 194
@@ -206,9 +199,6 @@ static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
206 if (!list_empty(&qh->remove_list)) 199 if (!list_empty(&qh->remove_list))
207 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh); 200 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh);
208 201
209 if (qh->dev)
210 usb_put_dev(qh->dev);
211
212 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle); 202 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle);
213} 203}
214 204
@@ -597,7 +587,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
597 /* 587 /*
598 * Build the TD for the control request setup packet 588 * Build the TD for the control request setup packet
599 */ 589 */
600 td = uhci_alloc_td(uhci, urb->dev); 590 td = uhci_alloc_td(uhci);
601 if (!td) 591 if (!td)
602 return -ENOMEM; 592 return -ENOMEM;
603 593
@@ -626,7 +616,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
626 if (pktsze > maxsze) 616 if (pktsze > maxsze)
627 pktsze = maxsze; 617 pktsze = maxsze;
628 618
629 td = uhci_alloc_td(uhci, urb->dev); 619 td = uhci_alloc_td(uhci);
630 if (!td) 620 if (!td)
631 return -ENOMEM; 621 return -ENOMEM;
632 622
@@ -644,7 +634,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
644 /* 634 /*
645 * Build the final TD for control status 635 * Build the final TD for control status
646 */ 636 */
647 td = uhci_alloc_td(uhci, urb->dev); 637 td = uhci_alloc_td(uhci);
648 if (!td) 638 if (!td)
649 return -ENOMEM; 639 return -ENOMEM;
650 640
@@ -666,7 +656,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, struct ur
666 uhci_fill_td(td, status | TD_CTRL_IOC, 656 uhci_fill_td(td, status | TD_CTRL_IOC,
667 destination | uhci_explen(UHCI_NULL_DATA_SIZE), 0); 657 destination | uhci_explen(UHCI_NULL_DATA_SIZE), 0);
668 658
669 qh = uhci_alloc_qh(uhci, urb->dev); 659 qh = uhci_alloc_qh(uhci);
670 if (!qh) 660 if (!qh)
671 return -ENOMEM; 661 return -ENOMEM;
672 662
@@ -865,7 +855,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
865 status &= ~TD_CTRL_SPD; 855 status &= ~TD_CTRL_SPD;
866 } 856 }
867 857
868 td = uhci_alloc_td(uhci, urb->dev); 858 td = uhci_alloc_td(uhci);
869 if (!td) 859 if (!td)
870 return -ENOMEM; 860 return -ENOMEM;
871 861
@@ -891,7 +881,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
891 */ 881 */
892 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) && 882 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) &&
893 !len && urb->transfer_buffer_length) { 883 !len && urb->transfer_buffer_length) {
894 td = uhci_alloc_td(uhci, urb->dev); 884 td = uhci_alloc_td(uhci);
895 if (!td) 885 if (!td)
896 return -ENOMEM; 886 return -ENOMEM;
897 887
@@ -913,7 +903,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, struct urb
913 * flag setting. */ 903 * flag setting. */
914 td->status |= cpu_to_le32(TD_CTRL_IOC); 904 td->status |= cpu_to_le32(TD_CTRL_IOC);
915 905
916 qh = uhci_alloc_qh(uhci, urb->dev); 906 qh = uhci_alloc_qh(uhci);
917 if (!qh) 907 if (!qh)
918 return -ENOMEM; 908 return -ENOMEM;
919 909
@@ -1096,7 +1086,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1096 if (!urb->iso_frame_desc[i].length) 1086 if (!urb->iso_frame_desc[i].length)
1097 continue; 1087 continue;
1098 1088
1099 td = uhci_alloc_td(uhci, urb->dev); 1089 td = uhci_alloc_td(uhci);
1100 if (!td) 1090 if (!td)
1101 return -ENOMEM; 1091 return -ENOMEM;
1102 1092
@@ -1174,7 +1164,7 @@ static struct urb *uhci_find_urb_ep(struct uhci_hcd *uhci, struct urb *urb)
1174 1164
1175static int uhci_urb_enqueue(struct usb_hcd *hcd, 1165static int uhci_urb_enqueue(struct usb_hcd *hcd,
1176 struct usb_host_endpoint *ep, 1166 struct usb_host_endpoint *ep,
1177 struct urb *urb, int mem_flags) 1167 struct urb *urb, unsigned mem_flags)
1178{ 1168{
1179 int ret; 1169 int ret;
1180 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1170 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
@@ -1497,6 +1487,7 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1497 rescan: 1487 rescan:
1498 uhci->need_rescan = 0; 1488 uhci->need_rescan = 0;
1499 1489
1490 uhci_clear_next_interrupt(uhci);
1500 uhci_get_current_frame_number(uhci); 1491 uhci_get_current_frame_number(uhci);
1501 1492
1502 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age) 1493 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age)
@@ -1537,3 +1528,26 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs)
1537 /* Wake up anyone waiting for an URB to complete */ 1528 /* Wake up anyone waiting for an URB to complete */
1538 wake_up_all(&uhci->waitqh); 1529 wake_up_all(&uhci->waitqh);
1539} 1530}
1531
1532static void check_fsbr(struct uhci_hcd *uhci)
1533{
1534 struct urb_priv *up;
1535
1536 list_for_each_entry(up, &uhci->urb_list, urb_list) {
1537 struct urb *u = up->urb;
1538
1539 spin_lock(&u->lock);
1540
1541 /* Check if the FSBR timed out */
1542 if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT))
1543 uhci_fsbr_timeout(uhci, u);
1544
1545 spin_unlock(&u->lock);
1546 }
1547
1548 /* Really disable FSBR */
1549 if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) {
1550 uhci->fsbrtimeout = 0;
1551 uhci->skel_term_qh->link = UHCI_PTR_TERM;
1552 }
1553}
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index d28e7eab6f98..298e4a25e3d3 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -151,6 +151,18 @@ config USB_WACOM
151 To compile this driver as a module, choose M here: the 151 To compile this driver as a module, choose M here: the
152 module will be called wacom. 152 module will be called wacom.
153 153
154config USB_ACECAD
155 tristate "Acecad Flair tablet support"
156 depends on USB && INPUT
157 help
158 Say Y here if you want to use the USB version of the Acecad Flair
159 tablet. Make sure to say Y to "Mouse support"
160 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
161 (CONFIG_INPUT_EVDEV) as well.
162
163 To compile this driver as a module, choose M here: the
164 module will be called acecad.
165
154config USB_KBTAB 166config USB_KBTAB
155 tristate "KB Gear JamStudio tablet support" 167 tristate "KB Gear JamStudio tablet support"
156 depends on USB && INPUT 168 depends on USB && INPUT
@@ -190,6 +202,18 @@ config USB_MTOUCH
190 To compile this driver as a module, choose M here: the 202 To compile this driver as a module, choose M here: the
191 module will be called mtouchusb. 203 module will be called mtouchusb.
192 204
205config USB_ITMTOUCH
206 tristate "ITM Touch USB Touchscreen Driver"
207 depends on USB && INPUT
208 ---help---
209 Say Y here if you want to use a ITM Touch USB
210 Touchscreen controller.
211
212 This touchscreen is used in LG 1510SF monitors.
213
214 To compile this driver as a module, choose M here: the
215 module will be called itmtouch.
216
193config USB_EGALAX 217config USB_EGALAX
194 tristate "eGalax TouchKit USB Touchscreen Driver" 218 tristate "eGalax TouchKit USB Touchscreen Driver"
195 depends on USB && INPUT 219 depends on USB && INPUT
@@ -235,3 +259,16 @@ config USB_ATI_REMOTE
235 To compile this driver as a module, choose M here: the module will be 259 To compile this driver as a module, choose M here: the module will be
236 called ati_remote. 260 called ati_remote.
237 261
262config USB_KEYSPAN_REMOTE
263 tristate "Keyspan DMR USB remote control (EXPERIMENTAL)"
264 depends on USB && INPUT && EXPERIMENTAL
265 ---help---
266 Say Y here if you want to use a Keyspan DMR USB remote control.
267 Currently only the UIA-11 type of receiver has been tested. The tag
268 on the receiver that connects to the USB port should have a P/N that
269 will tell you what type of DMR you have. The UIA-10 type is not
270 supported at this time. This driver maps all buttons to keypress
271 events.
272
273 To compile this driver as a module, choose M here: the module will
274 be called keyspan_remote.
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index 6bcedd16b0a1..f1547be632d4 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -31,9 +31,12 @@ obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o
31obj-$(CONFIG_USB_HID) += usbhid.o 31obj-$(CONFIG_USB_HID) += usbhid.o
32obj-$(CONFIG_USB_KBD) += usbkbd.o 32obj-$(CONFIG_USB_KBD) += usbkbd.o
33obj-$(CONFIG_USB_KBTAB) += kbtab.o 33obj-$(CONFIG_USB_KBTAB) += kbtab.o
34obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o
34obj-$(CONFIG_USB_MOUSE) += usbmouse.o 35obj-$(CONFIG_USB_MOUSE) += usbmouse.o
35obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o 36obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
37obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
36obj-$(CONFIG_USB_EGALAX) += touchkitusb.o 38obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
37obj-$(CONFIG_USB_POWERMATE) += powermate.o 39obj-$(CONFIG_USB_POWERMATE) += powermate.o
38obj-$(CONFIG_USB_WACOM) += wacom.o 40obj-$(CONFIG_USB_WACOM) += wacom.o
41obj-$(CONFIG_USB_ACECAD) += acecad.o
39obj-$(CONFIG_USB_XPAD) += xpad.o 42obj-$(CONFIG_USB_XPAD) += xpad.o
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
new file mode 100644
index 000000000000..ebcf7c955800
--- /dev/null
+++ b/drivers/usb/input/acecad.c
@@ -0,0 +1,285 @@
1/*
2 * Copyright (c) 2001-2005 Edouard TISSERANT <edouard.tisserant@wanadoo.fr>
3 * Copyright (c) 2004-2005 Stephane VOLTZ <svoltz@numericable.fr>
4 *
5 * USB Acecad "Acecad Flair" tablet support
6 *
7 * Changelog:
8 * v3.2 - Added sysfs support
9 */
10
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 as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/input.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/usb.h>
34
35/*
36 * Version Information
37 */
38#define DRIVER_VERSION "v3.2"
39#define DRIVER_DESC "USB Acecad Flair tablet driver"
40#define DRIVER_LICENSE "GPL"
41#define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
42
43MODULE_AUTHOR(DRIVER_AUTHOR);
44MODULE_DESCRIPTION(DRIVER_DESC);
45MODULE_LICENSE(DRIVER_LICENSE);
46
47#define USB_VENDOR_ID_ACECAD 0x0460
48#define USB_DEVICE_ID_FLAIR 0x0004
49#define USB_DEVICE_ID_302 0x0008
50
51struct usb_acecad {
52 char name[128];
53 char phys[64];
54 struct usb_device *usbdev;
55 struct input_dev dev;
56 struct urb *irq;
57
58 signed char *data;
59 dma_addr_t data_dma;
60};
61
62static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
63{
64 struct usb_acecad *acecad = urb->context;
65 unsigned char *data = acecad->data;
66 struct input_dev *dev = &acecad->dev;
67 int prox, status;
68
69 switch (urb->status) {
70 case 0:
71 /* success */
72 break;
73 case -ECONNRESET:
74 case -ENOENT:
75 case -ESHUTDOWN:
76 /* this urb is terminated, clean up */
77 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
78 return;
79 default:
80 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
81 goto resubmit;
82 }
83
84 prox = (data[0] & 0x04) >> 2;
85 input_report_key(dev, BTN_TOOL_PEN, prox);
86
87 if (prox) {
88 int x = data[1] | (data[2] << 8);
89 int y = data[3] | (data[4] << 8);
90 /*Pressure should compute the same way for flair and 302*/
91 int pressure = data[5] | ((int)data[6] << 8);
92 int touch = data[0] & 0x01;
93 int stylus = (data[0] & 0x10) >> 4;
94 int stylus2 = (data[0] & 0x20) >> 5;
95 input_report_abs(dev, ABS_X, x);
96 input_report_abs(dev, ABS_Y, y);
97 input_report_abs(dev, ABS_PRESSURE, pressure);
98 input_report_key(dev, BTN_TOUCH, touch);
99 input_report_key(dev, BTN_STYLUS, stylus);
100 input_report_key(dev, BTN_STYLUS2, stylus2);
101 }
102
103 /* event termination */
104 input_sync(dev);
105
106resubmit:
107 status = usb_submit_urb (urb, GFP_ATOMIC);
108 if (status)
109 err ("can't resubmit intr, %s-%s/input0, status %d",
110 acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
111}
112
113static int usb_acecad_open(struct input_dev *dev)
114{
115 struct usb_acecad *acecad = dev->private;
116
117 acecad->irq->dev = acecad->usbdev;
118 if (usb_submit_urb(acecad->irq, GFP_KERNEL))
119 return -EIO;
120
121 return 0;
122}
123
124static void usb_acecad_close(struct input_dev *dev)
125{
126 struct usb_acecad *acecad = dev->private;
127
128 usb_kill_urb(acecad->irq);
129}
130
131static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
132{
133 struct usb_device *dev = interface_to_usbdev(intf);
134 struct usb_host_interface *interface = intf->cur_altsetting;
135 struct usb_endpoint_descriptor *endpoint;
136 struct usb_acecad *acecad;
137 int pipe, maxp;
138 char path[64];
139
140 if (interface->desc.bNumEndpoints != 1)
141 return -ENODEV;
142
143 endpoint = &interface->endpoint[0].desc;
144
145 if (!(endpoint->bEndpointAddress & 0x80))
146 return -ENODEV;
147
148 if ((endpoint->bmAttributes & 3) != 3)
149 return -ENODEV;
150
151 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
152 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
153
154 acecad = kcalloc(1, sizeof(struct usb_acecad), GFP_KERNEL);
155 if (!acecad)
156 return -ENOMEM;
157
158 acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
159 if (!acecad->data)
160 goto fail1;
161
162 acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
163 if (!acecad->irq)
164 goto fail2;
165
166 if (dev->manufacturer)
167 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
168
169 if (dev->product) {
170 if (dev->manufacturer)
171 strlcat(acecad->name, " ", sizeof(acecad->name));
172 strlcat(acecad->name, dev->product, sizeof(acecad->name));
173 }
174
175 usb_make_path(dev, path, sizeof(path));
176 snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path);
177
178 acecad->usbdev = dev;
179
180 acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
181 acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
182 acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
183 acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
184
185 switch (id->driver_info) {
186 case 0:
187 acecad->dev.absmax[ABS_X] = 5000;
188 acecad->dev.absmax[ABS_Y] = 3750;
189 acecad->dev.absmax[ABS_PRESSURE] = 512;
190 if (!strlen(acecad->name))
191 snprintf(acecad->name, sizeof(acecad->name),
192 "USB Acecad Flair Tablet %04x:%04x",
193 dev->descriptor.idVendor, dev->descriptor.idProduct);
194 break;
195 case 1:
196 acecad->dev.absmax[ABS_X] = 3000;
197 acecad->dev.absmax[ABS_Y] = 2250;
198 acecad->dev.absmax[ABS_PRESSURE] = 1024;
199 if (!strlen(acecad->name))
200 snprintf(acecad->name, sizeof(acecad->name),
201 "USB Acecad 302 Tablet %04x:%04x",
202 dev->descriptor.idVendor, dev->descriptor.idProduct);
203 break;
204 }
205
206 acecad->dev.absfuzz[ABS_X] = 4;
207 acecad->dev.absfuzz[ABS_Y] = 4;
208
209 acecad->dev.private = acecad;
210 acecad->dev.open = usb_acecad_open;
211 acecad->dev.close = usb_acecad_close;
212
213 acecad->dev.name = acecad->name;
214 acecad->dev.phys = acecad->phys;
215 acecad->dev.id.bustype = BUS_USB;
216 acecad->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
217 acecad->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
218 acecad->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
219 acecad->dev.dev = &intf->dev;
220
221 usb_fill_int_urb(acecad->irq, dev, pipe,
222 acecad->data, maxp > 8 ? 8 : maxp,
223 usb_acecad_irq, acecad, endpoint->bInterval);
224 acecad->irq->transfer_dma = acecad->data_dma;
225 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
226
227 input_register_device(&acecad->dev);
228
229 printk(KERN_INFO "input: %s with packet size %d on %s\n",
230 acecad->name, maxp, path);
231
232 usb_set_intfdata(intf, acecad);
233
234 return 0;
235
236 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
237 fail1: kfree(acecad);
238 return -ENOMEM;
239}
240
241static void usb_acecad_disconnect(struct usb_interface *intf)
242{
243 struct usb_acecad *acecad = usb_get_intfdata(intf);
244
245 usb_set_intfdata(intf, NULL);
246 if (acecad) {
247 usb_kill_urb(acecad->irq);
248 input_unregister_device(&acecad->dev);
249 usb_free_urb(acecad->irq);
250 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
251 kfree(acecad);
252 }
253}
254
255static struct usb_device_id usb_acecad_id_table [] = {
256 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
257 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
258 { }
259};
260
261MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
262
263static struct usb_driver usb_acecad_driver = {
264 .owner = THIS_MODULE,
265 .name = "usb_acecad",
266 .probe = usb_acecad_probe,
267 .disconnect = usb_acecad_disconnect,
268 .id_table = usb_acecad_id_table,
269};
270
271static int __init usb_acecad_init(void)
272{
273 int result = usb_register(&usb_acecad_driver);
274 if (result == 0)
275 info(DRIVER_VERSION ":" DRIVER_DESC);
276 return result;
277}
278
279static void __exit usb_acecad_exit(void)
280{
281 usb_deregister(&usb_acecad_driver);
282}
283
284module_init(usb_acecad_init);
285module_exit(usb_acecad_exit);
diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c
index e991f7ed7330..6bb0f25e8e93 100644
--- a/drivers/usb/input/aiptek.c
+++ b/drivers/usb/input/aiptek.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Native support for the Aiptek HyperPen USB Tablets 2 * Native support for the Aiptek HyperPen USB Tablets
3 * (4000U/5000U/6000U/8000U/12000U) 3 * (4000U/5000U/6000U/8000U/12000U)
4 * 4 *
5 * Copyright (c) 2001 Chris Atenasio <chris@crud.net> 5 * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
6 * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net> 6 * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
7 * 7 *
@@ -31,7 +31,7 @@
31 * - Added support for the sysfs interface, deprecating the 31 * - Added support for the sysfs interface, deprecating the
32 * procfs interface for 2.5.x kernel. Also added support for 32 * procfs interface for 2.5.x kernel. Also added support for
33 * Wheel command. Bryan W. Headley July-15-2003. 33 * Wheel command. Bryan W. Headley July-15-2003.
34 * v1.2 - Reworked jitter timer as a kernel thread. 34 * v1.2 - Reworked jitter timer as a kernel thread.
35 * Bryan W. Headley November-28-2003/Jan-10-2004. 35 * Bryan W. Headley November-28-2003/Jan-10-2004.
36 * v1.3 - Repaired issue of kernel thread going nuts on single-processor 36 * v1.3 - Repaired issue of kernel thread going nuts on single-processor
37 * machines, introduced programmableDelay as a command line 37 * machines, introduced programmableDelay as a command line
@@ -49,10 +49,10 @@
49 * NOTE: 49 * NOTE:
50 * This kernel driver is augmented by the "Aiptek" XFree86 input 50 * This kernel driver is augmented by the "Aiptek" XFree86 input
51 * driver for your X server, as well as the Gaiptek GUI Front-end 51 * driver for your X server, as well as the Gaiptek GUI Front-end
52 * "Tablet Manager". 52 * "Tablet Manager".
53 * These three products are highly interactive with one another, 53 * These three products are highly interactive with one another,
54 * so therefore it's easier to document them all as one subsystem. 54 * so therefore it's easier to document them all as one subsystem.
55 * Please visit the project's "home page", located at, 55 * Please visit the project's "home page", located at,
56 * http://aiptektablet.sourceforge.net. 56 * http://aiptektablet.sourceforge.net.
57 * 57 *
58 * This program is free software; you can redistribute it and/or modify 58 * This program is free software; you can redistribute it and/or modify
@@ -156,7 +156,7 @@
156 * Command/Data Description Return Bytes Return Value 156 * Command/Data Description Return Bytes Return Value
157 * 0x10/0x00 SwitchToMouse 0 157 * 0x10/0x00 SwitchToMouse 0
158 * 0x10/0x01 SwitchToTablet 0 158 * 0x10/0x01 SwitchToTablet 0
159 * 0x18/0x04 SetResolution 0 159 * 0x18/0x04 SetResolution 0
160 * 0x12/0xFF AutoGainOn 0 160 * 0x12/0xFF AutoGainOn 0
161 * 0x17/0x00 FilterOn 0 161 * 0x17/0x00 FilterOn 0
162 * 0x01/0x00 GetXExtension 2 MaxX 162 * 0x01/0x00 GetXExtension 2 MaxX
@@ -247,7 +247,7 @@
247#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2 247#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
248#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3 248#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
249 249
250 /* Time to wait (in ms) to help mask hand jittering 250 /* Time to wait (in ms) to help mask hand jittering
251 * when pressing the stylus buttons. 251 * when pressing the stylus buttons.
252 */ 252 */
253#define AIPTEK_JITTER_DELAY_DEFAULT 50 253#define AIPTEK_JITTER_DELAY_DEFAULT 50
@@ -324,7 +324,6 @@ struct aiptek {
324 struct aiptek_settings curSetting; /* tablet's current programmable */ 324 struct aiptek_settings curSetting; /* tablet's current programmable */
325 struct aiptek_settings newSetting; /* ... and new param settings */ 325 struct aiptek_settings newSetting; /* ... and new param settings */
326 unsigned int ifnum; /* interface number for IO */ 326 unsigned int ifnum; /* interface number for IO */
327 int openCount; /* module use counter */
328 int diagnostic; /* tablet diagnostic codes */ 327 int diagnostic; /* tablet diagnostic codes */
329 unsigned long eventCount; /* event count */ 328 unsigned long eventCount; /* event count */
330 int inDelay; /* jitter: in jitter delay? */ 329 int inDelay; /* jitter: in jitter delay? */
@@ -791,7 +790,7 @@ exit:
791 * specific Aiptek model numbers, because there has been overlaps, 790 * specific Aiptek model numbers, because there has been overlaps,
792 * use, and reuse of id's in existing models. Certain models have 791 * use, and reuse of id's in existing models. Certain models have
793 * been known to use more than one ID, indicative perhaps of 792 * been known to use more than one ID, indicative perhaps of
794 * manufacturing revisions. In any event, we consider these 793 * manufacturing revisions. In any event, we consider these
795 * IDs to not be model-specific nor unique. 794 * IDs to not be model-specific nor unique.
796 */ 795 */
797static const struct usb_device_id aiptek_ids[] = { 796static const struct usb_device_id aiptek_ids[] = {
@@ -814,15 +813,9 @@ static int aiptek_open(struct input_dev *inputdev)
814{ 813{
815 struct aiptek *aiptek = inputdev->private; 814 struct aiptek *aiptek = inputdev->private;
816 815
817 if (aiptek->openCount++ > 0) {
818 return 0;
819 }
820
821 aiptek->urb->dev = aiptek->usbdev; 816 aiptek->urb->dev = aiptek->usbdev;
822 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0) { 817 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
823 aiptek->openCount--;
824 return -EIO; 818 return -EIO;
825 }
826 819
827 return 0; 820 return 0;
828} 821}
@@ -834,13 +827,11 @@ static void aiptek_close(struct input_dev *inputdev)
834{ 827{
835 struct aiptek *aiptek = inputdev->private; 828 struct aiptek *aiptek = inputdev->private;
836 829
837 if (--aiptek->openCount == 0) { 830 usb_kill_urb(aiptek->urb);
838 usb_kill_urb(aiptek->urb);
839 }
840} 831}
841 832
842/*********************************************************************** 833/***********************************************************************
843 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x, 834 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
844 * where they were known as usb_set_report and usb_get_report. 835 * where they were known as usb_set_report and usb_get_report.
845 */ 836 */
846static int 837static int
@@ -2252,7 +2243,6 @@ static void aiptek_disconnect(struct usb_interface *intf)
2252 AIPTEK_PACKET_LENGTH, 2243 AIPTEK_PACKET_LENGTH,
2253 aiptek->data, aiptek->data_dma); 2244 aiptek->data, aiptek->data_dma);
2254 kfree(aiptek); 2245 kfree(aiptek);
2255 aiptek = NULL;
2256 } 2246 }
2257} 2247}
2258 2248
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 860df26323b1..654ac454744d 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -1,15 +1,15 @@
1/* 1/*
2 * USB ATI Remote support 2 * USB ATI Remote support
3 * 3 *
4 * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net> 4 * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
5 * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev 5 * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev
6 * 6 *
7 * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including 7 * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including
8 * porting to the 2.6 kernel interfaces, along with other modification 8 * porting to the 2.6 kernel interfaces, along with other modification
9 * to better match the style of the existing usb/input drivers. However, the 9 * to better match the style of the existing usb/input drivers. However, the
10 * protocol and hardware handling is essentially unchanged from 2.1.1. 10 * protocol and hardware handling is essentially unchanged from 2.1.1.
11 * 11 *
12 * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by 12 * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by
13 * Vojtech Pavlik. 13 * Vojtech Pavlik.
14 * 14 *
15 * Changes: 15 * Changes:
@@ -23,64 +23,64 @@
23 * Added support for the "Lola" remote contributed by: 23 * Added support for the "Lola" remote contributed by:
24 * Seth Cohn <sethcohn@yahoo.com> 24 * Seth Cohn <sethcohn@yahoo.com>
25 * 25 *
26 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 26 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27 * 27 *
28 * This program is free software; you can redistribute it and/or modify 28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by 29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or 30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version. 31 * (at your option) any later version.
32 * 32 *
33 * This program is distributed in the hope that it will be useful, 33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of 34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details. 36 * GNU General Public License for more details.
37 * 37 *
38 * You should have received a copy of the GNU General Public License 38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software 39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 * 41 *
42 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 42 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
43 * 43 *
44 * Hardware & software notes 44 * Hardware & software notes
45 * 45 *
46 * These remote controls are distributed by ATI as part of their 46 * These remote controls are distributed by ATI as part of their
47 * "All-In-Wonder" video card packages. The receiver self-identifies as a 47 * "All-In-Wonder" video card packages. The receiver self-identifies as a
48 * "USB Receiver" with manufacturer "X10 Wireless Technology Inc". 48 * "USB Receiver" with manufacturer "X10 Wireless Technology Inc".
49 * 49 *
50 * The "Lola" remote is available from X10. See: 50 * The "Lola" remote is available from X10. See:
51 * http://www.x10.com/products/lola_sg1.htm 51 * http://www.x10.com/products/lola_sg1.htm
52 * The Lola is similar to the ATI remote but has no mouse support, and slightly 52 * The Lola is similar to the ATI remote but has no mouse support, and slightly
53 * different keys. 53 * different keys.
54 * 54 *
55 * It is possible to use multiple receivers and remotes on multiple computers 55 * It is possible to use multiple receivers and remotes on multiple computers
56 * simultaneously by configuring them to use specific channels. 56 * simultaneously by configuring them to use specific channels.
57 * 57 *
58 * The RF protocol used by the remote supports 16 distinct channels, 1 to 16. 58 * The RF protocol used by the remote supports 16 distinct channels, 1 to 16.
59 * Actually, it may even support more, at least in some revisions of the 59 * Actually, it may even support more, at least in some revisions of the
60 * hardware. 60 * hardware.
61 * 61 *
62 * Each remote can be configured to transmit on one channel as follows: 62 * Each remote can be configured to transmit on one channel as follows:
63 * - Press and hold the "hand icon" button. 63 * - Press and hold the "hand icon" button.
64 * - When the red LED starts to blink, let go of the "hand icon" button. 64 * - When the red LED starts to blink, let go of the "hand icon" button.
65 * - When it stops blinking, input the channel code as two digits, from 01 65 * - When it stops blinking, input the channel code as two digits, from 01
66 * to 16, and press the hand icon again. 66 * to 16, and press the hand icon again.
67 * 67 *
68 * The timing can be a little tricky. Try loading the module with debug=1 68 * The timing can be a little tricky. Try loading the module with debug=1
69 * to have the kernel print out messages about the remote control number 69 * to have the kernel print out messages about the remote control number
70 * and mask. Note: debugging prints remote numbers as zero-based hexadecimal. 70 * and mask. Note: debugging prints remote numbers as zero-based hexadecimal.
71 * 71 *
72 * The driver has a "channel_mask" parameter. This bitmask specifies which 72 * The driver has a "channel_mask" parameter. This bitmask specifies which
73 * channels will be ignored by the module. To mask out channels, just add 73 * channels will be ignored by the module. To mask out channels, just add
74 * all the 2^channel_number values together. 74 * all the 2^channel_number values together.
75 * 75 *
76 * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote 76 * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote
77 * ignore signals coming from remote controls transmitting on channel 4, but 77 * ignore signals coming from remote controls transmitting on channel 4, but
78 * accept all other channels. 78 * accept all other channels.
79 * 79 *
80 * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be 80 * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be
81 * ignored. 81 * ignored.
82 * 82 *
83 * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this 83 * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this
84 * parameter are unused. 84 * parameter are unused.
85 * 85 *
86 */ 86 */
@@ -99,13 +99,13 @@
99/* 99/*
100 * Module and Version Information, Module Parameters 100 * Module and Version Information, Module Parameters
101 */ 101 */
102 102
103#define ATI_REMOTE_VENDOR_ID 0x0bc7 103#define ATI_REMOTE_VENDOR_ID 0x0bc7
104#define ATI_REMOTE_PRODUCT_ID 0x004 104#define ATI_REMOTE_PRODUCT_ID 0x004
105#define LOLA_REMOTE_PRODUCT_ID 0x002 105#define LOLA_REMOTE_PRODUCT_ID 0x002
106#define MEDION_REMOTE_PRODUCT_ID 0x006 106#define MEDION_REMOTE_PRODUCT_ID 0x006
107 107
108#define DRIVER_VERSION "2.2.1" 108#define DRIVER_VERSION "2.2.1"
109#define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>" 109#define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>"
110#define DRIVER_DESC "ATI/X10 RF USB Remote Control" 110#define DRIVER_DESC "ATI/X10 RF USB Remote Control"
111 111
@@ -113,18 +113,18 @@
113#define DATA_BUFSIZE 63 /* size of URB data buffers */ 113#define DATA_BUFSIZE 63 /* size of URB data buffers */
114#define ATI_INPUTNUM 1 /* Which input device to register as */ 114#define ATI_INPUTNUM 1 /* Which input device to register as */
115 115
116static unsigned long channel_mask = 0; 116static unsigned long channel_mask;
117module_param(channel_mask, ulong, 0444); 117module_param(channel_mask, ulong, 0444);
118MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); 118MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
119 119
120static int debug = 0; 120static int debug;
121module_param(debug, int, 0444); 121module_param(debug, int, 0444);
122MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); 122MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
123 123
124#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 124#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
125#undef err 125#undef err
126#define err(format, arg...) printk(KERN_ERR format , ## arg) 126#define err(format, arg...) printk(KERN_ERR format , ## arg)
127 127
128static struct usb_device_id ati_remote_table[] = { 128static struct usb_device_id ati_remote_table[] = {
129 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) }, 129 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) },
130 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) }, 130 { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) },
@@ -148,7 +148,7 @@ static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
148/* Acceleration curve for directional control pad */ 148/* Acceleration curve for directional control pad */
149static char accel[] = { 1, 2, 4, 6, 9, 13, 20 }; 149static char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
150 150
151/* Duplicate event filtering time. 151/* Duplicate event filtering time.
152 * Sequential, identical KIND_FILTERED inputs with less than 152 * Sequential, identical KIND_FILTERED inputs with less than
153 * FILTER_TIME jiffies between them are considered as repeat 153 * FILTER_TIME jiffies between them are considered as repeat
154 * events. The hardware generates 5 events for the first keypress 154 * events. The hardware generates 5 events for the first keypress
@@ -161,10 +161,10 @@ static char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
161static DECLARE_MUTEX(disconnect_sem); 161static DECLARE_MUTEX(disconnect_sem);
162 162
163struct ati_remote { 163struct ati_remote {
164 struct input_dev idev; 164 struct input_dev idev;
165 struct usb_device *udev; 165 struct usb_device *udev;
166 struct usb_interface *interface; 166 struct usb_interface *interface;
167 167
168 struct urb *irq_urb; 168 struct urb *irq_urb;
169 struct urb *out_urb; 169 struct urb *out_urb;
170 struct usb_endpoint_descriptor *endpoint_in; 170 struct usb_endpoint_descriptor *endpoint_in;
@@ -174,13 +174,11 @@ struct ati_remote {
174 dma_addr_t inbuf_dma; 174 dma_addr_t inbuf_dma;
175 dma_addr_t outbuf_dma; 175 dma_addr_t outbuf_dma;
176 176
177 int open; /* open counter */
178
179 unsigned char old_data[2]; /* Detect duplicate events */ 177 unsigned char old_data[2]; /* Detect duplicate events */
180 unsigned long old_jiffies; 178 unsigned long old_jiffies;
181 unsigned long acc_jiffies; /* handle acceleration */ 179 unsigned long acc_jiffies; /* handle acceleration */
182 unsigned int repeat_count; 180 unsigned int repeat_count;
183 181
184 char name[NAME_BUFSIZE]; 182 char name[NAME_BUFSIZE];
185 char phys[NAME_BUFSIZE]; 183 char phys[NAME_BUFSIZE];
186 184
@@ -206,14 +204,14 @@ static struct
206 int type; 204 int type;
207 unsigned int code; 205 unsigned int code;
208 int value; 206 int value;
209} ati_remote_tbl[] = 207} ati_remote_tbl[] =
210{ 208{
211 /* Directional control pad axes */ 209 /* Directional control pad axes */
212 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */ 210 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */
213 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */ 211 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */
214 {KIND_ACCEL, 0x37, 0x72, EV_REL, REL_Y, -1}, /* up */ 212 {KIND_ACCEL, 0x37, 0x72, EV_REL, REL_Y, -1}, /* up */
215 {KIND_ACCEL, 0x38, 0x73, EV_REL, REL_Y, 1}, /* down */ 213 {KIND_ACCEL, 0x38, 0x73, EV_REL, REL_Y, 1}, /* down */
216 /* Directional control pad diagonals */ 214 /* Directional control pad diagonals */
217 {KIND_LU, 0x39, 0x74, EV_REL, 0, 0}, /* left up */ 215 {KIND_LU, 0x39, 0x74, EV_REL, 0, 0}, /* left up */
218 {KIND_RU, 0x3a, 0x75, EV_REL, 0, 0}, /* right up */ 216 {KIND_RU, 0x3a, 0x75, EV_REL, 0, 0}, /* right up */
219 {KIND_LD, 0x3c, 0x77, EV_REL, 0, 0}, /* left down */ 217 {KIND_LD, 0x3c, 0x77, EV_REL, 0, 0}, /* left down */
@@ -225,7 +223,7 @@ static struct
225 {KIND_LITERAL, 0x41, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */ 223 {KIND_LITERAL, 0x41, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */
226 {KIND_LITERAL, 0x42, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */ 224 {KIND_LITERAL, 0x42, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */
227 225
228 /* Artificial "doubleclick" events are generated by the hardware. 226 /* Artificial "doubleclick" events are generated by the hardware.
229 * They are mapped to the "side" and "extra" mouse buttons here. */ 227 * They are mapped to the "side" and "extra" mouse buttons here. */
230 {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */ 228 {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */
231 {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */ 229 {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */
@@ -273,15 +271,15 @@ static struct
273 {KIND_FILTERED, 0xea, 0x25, EV_KEY, KEY_PLAY, 1}, /* ( >) */ 271 {KIND_FILTERED, 0xea, 0x25, EV_KEY, KEY_PLAY, 1}, /* ( >) */
274 {KIND_FILTERED, 0xe9, 0x24, EV_KEY, KEY_REWIND, 1}, /* (<<) */ 272 {KIND_FILTERED, 0xe9, 0x24, EV_KEY, KEY_REWIND, 1}, /* (<<) */
275 {KIND_FILTERED, 0xeb, 0x26, EV_KEY, KEY_FORWARD, 1}, /* (>>) */ 273 {KIND_FILTERED, 0xeb, 0x26, EV_KEY, KEY_FORWARD, 1}, /* (>>) */
276 {KIND_FILTERED, 0xed, 0x28, EV_KEY, KEY_STOP, 1}, /* ([]) */ 274 {KIND_FILTERED, 0xed, 0x28, EV_KEY, KEY_STOP, 1}, /* ([]) */
277 {KIND_FILTERED, 0xee, 0x29, EV_KEY, KEY_PAUSE, 1}, /* ('') */ 275 {KIND_FILTERED, 0xee, 0x29, EV_KEY, KEY_PAUSE, 1}, /* ('') */
278 {KIND_FILTERED, 0xf0, 0x2b, EV_KEY, KEY_PREVIOUS, 1}, /* (<-) */ 276 {KIND_FILTERED, 0xf0, 0x2b, EV_KEY, KEY_PREVIOUS, 1}, /* (<-) */
279 {KIND_FILTERED, 0xef, 0x2a, EV_KEY, KEY_NEXT, 1}, /* (>+) */ 277 {KIND_FILTERED, 0xef, 0x2a, EV_KEY, KEY_NEXT, 1}, /* (>+) */
280 {KIND_FILTERED, 0xf2, 0x2D, EV_KEY, KEY_INFO, 1}, /* PLAYING */ 278 {KIND_FILTERED, 0xf2, 0x2D, EV_KEY, KEY_INFO, 1}, /* PLAYING */
281 {KIND_FILTERED, 0xf3, 0x2E, EV_KEY, KEY_HOME, 1}, /* TOP */ 279 {KIND_FILTERED, 0xf3, 0x2E, EV_KEY, KEY_HOME, 1}, /* TOP */
282 {KIND_FILTERED, 0xf4, 0x2F, EV_KEY, KEY_END, 1}, /* END */ 280 {KIND_FILTERED, 0xf4, 0x2F, EV_KEY, KEY_END, 1}, /* END */
283 {KIND_FILTERED, 0xf5, 0x30, EV_KEY, KEY_SELECT, 1}, /* SELECT */ 281 {KIND_FILTERED, 0xf5, 0x30, EV_KEY, KEY_SELECT, 1}, /* SELECT */
284 282
285 {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0} 283 {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0}
286}; 284};
287 285
@@ -315,7 +313,7 @@ static void ati_remote_dump(unsigned char *data, unsigned int len)
315 if ((len == 1) && (data[0] != (unsigned char)0xff) && (data[0] != 0x00)) 313 if ((len == 1) && (data[0] != (unsigned char)0xff) && (data[0] != 0x00))
316 warn("Weird byte 0x%02x", data[0]); 314 warn("Weird byte 0x%02x", data[0]);
317 else if (len == 4) 315 else if (len == 4)
318 warn("Weird key %02x %02x %02x %02x", 316 warn("Weird key %02x %02x %02x %02x",
319 data[0], data[1], data[2], data[3]); 317 data[0], data[1], data[2], data[3]);
320 else 318 else
321 warn("Weird data, len=%d %02x %02x %02x %02x %02x %02x ...", 319 warn("Weird data, len=%d %02x %02x %02x %02x %02x %02x ...",
@@ -328,25 +326,16 @@ static void ati_remote_dump(unsigned char *data, unsigned int len)
328static int ati_remote_open(struct input_dev *inputdev) 326static int ati_remote_open(struct input_dev *inputdev)
329{ 327{
330 struct ati_remote *ati_remote = inputdev->private; 328 struct ati_remote *ati_remote = inputdev->private;
331 int retval = 0;
332
333 down(&disconnect_sem);
334
335 if (ati_remote->open++)
336 goto exit;
337 329
338 /* On first open, submit the read urb which was set up previously. */ 330 /* On first open, submit the read urb which was set up previously. */
339 ati_remote->irq_urb->dev = ati_remote->udev; 331 ati_remote->irq_urb->dev = ati_remote->udev;
340 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) { 332 if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
341 dev_err(&ati_remote->interface->dev, 333 dev_err(&ati_remote->interface->dev,
342 "%s: usb_submit_urb failed!\n", __FUNCTION__); 334 "%s: usb_submit_urb failed!\n", __FUNCTION__);
343 ati_remote->open--; 335 return -EIO;
344 retval = -EIO;
345 } 336 }
346 337
347exit: 338 return 0;
348 up(&disconnect_sem);
349 return retval;
350} 339}
351 340
352/* 341/*
@@ -355,9 +344,8 @@ exit:
355static void ati_remote_close(struct input_dev *inputdev) 344static void ati_remote_close(struct input_dev *inputdev)
356{ 345{
357 struct ati_remote *ati_remote = inputdev->private; 346 struct ati_remote *ati_remote = inputdev->private;
358 347
359 if (!--ati_remote->open) 348 usb_kill_urb(ati_remote->irq_urb);
360 usb_kill_urb(ati_remote->irq_urb);
361} 349}
362 350
363/* 351/*
@@ -366,13 +354,13 @@ static void ati_remote_close(struct input_dev *inputdev)
366static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs) 354static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs)
367{ 355{
368 struct ati_remote *ati_remote = urb->context; 356 struct ati_remote *ati_remote = urb->context;
369 357
370 if (urb->status) { 358 if (urb->status) {
371 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n", 359 dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
372 __FUNCTION__, urb->status); 360 __FUNCTION__, urb->status);
373 return; 361 return;
374 } 362 }
375 363
376 ati_remote->send_flags |= SEND_FLAG_COMPLETE; 364 ati_remote->send_flags |= SEND_FLAG_COMPLETE;
377 wmb(); 365 wmb();
378 wake_up(&ati_remote->wait); 366 wake_up(&ati_remote->wait);
@@ -380,16 +368,16 @@ static void ati_remote_irq_out(struct urb *urb, struct pt_regs *regs)
380 368
381/* 369/*
382 * ati_remote_sendpacket 370 * ati_remote_sendpacket
383 * 371 *
384 * Used to send device initialization strings 372 * Used to send device initialization strings
385 */ 373 */
386static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigned char *data) 374static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigned char *data)
387{ 375{
388 int retval = 0; 376 int retval = 0;
389 377
390 /* Set up out_urb */ 378 /* Set up out_urb */
391 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd)); 379 memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
392 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd); 380 ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
393 381
394 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1; 382 ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
395 ati_remote->out_urb->dev = ati_remote->udev; 383 ati_remote->out_urb->dev = ati_remote->udev;
@@ -397,17 +385,17 @@ static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigne
397 385
398 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC); 386 retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
399 if (retval) { 387 if (retval) {
400 dev_dbg(&ati_remote->interface->dev, 388 dev_dbg(&ati_remote->interface->dev,
401 "sendpacket: usb_submit_urb failed: %d\n", retval); 389 "sendpacket: usb_submit_urb failed: %d\n", retval);
402 return retval; 390 return retval;
403 } 391 }
404 392
405 wait_event_timeout(ati_remote->wait, 393 wait_event_timeout(ati_remote->wait,
406 ((ati_remote->out_urb->status != -EINPROGRESS) || 394 ((ati_remote->out_urb->status != -EINPROGRESS) ||
407 (ati_remote->send_flags & SEND_FLAG_COMPLETE)), 395 (ati_remote->send_flags & SEND_FLAG_COMPLETE)),
408 HZ); 396 HZ);
409 usb_kill_urb(ati_remote->out_urb); 397 usb_kill_urb(ati_remote->out_urb);
410 398
411 return retval; 399 return retval;
412} 400}
413 401
@@ -419,15 +407,15 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
419 int i; 407 int i;
420 408
421 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) { 409 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
422 /* 410 /*
423 * Decide if the table entry matches the remote input. 411 * Decide if the table entry matches the remote input.
424 */ 412 */
425 if ((((ati_remote_tbl[i].data1 & 0x0f) == (d1 & 0x0f))) && 413 if ((((ati_remote_tbl[i].data1 & 0x0f) == (d1 & 0x0f))) &&
426 ((((ati_remote_tbl[i].data1 >> 4) - 414 ((((ati_remote_tbl[i].data1 >> 4) -
427 (d1 >> 4) + rem) & 0x0f) == 0x0f) && 415 (d1 >> 4) + rem) & 0x0f) == 0x0f) &&
428 (ati_remote_tbl[i].data2 == d2)) 416 (ati_remote_tbl[i].data2 == d2))
429 return i; 417 return i;
430 418
431 } 419 }
432 return -1; 420 return -1;
433} 421}
@@ -435,16 +423,16 @@ static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2)
435/* 423/*
436 * ati_remote_report_input 424 * ati_remote_report_input
437 */ 425 */
438static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs) 426static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
439{ 427{
440 struct ati_remote *ati_remote = urb->context; 428 struct ati_remote *ati_remote = urb->context;
441 unsigned char *data= ati_remote->inbuf; 429 unsigned char *data= ati_remote->inbuf;
442 struct input_dev *dev = &ati_remote->idev; 430 struct input_dev *dev = &ati_remote->idev;
443 int index, acc; 431 int index, acc;
444 int remote_num; 432 int remote_num;
445 433
446 /* Deal with strange looking inputs */ 434 /* Deal with strange looking inputs */
447 if ( (urb->actual_length != 4) || (data[0] != 0x14) || 435 if ( (urb->actual_length != 4) || (data[0] != 0x14) ||
448 ((data[3] & 0x0f) != 0x00) ) { 436 ((data[3] & 0x0f) != 0x00) ) {
449 ati_remote_dump(data, urb->actual_length); 437 ati_remote_dump(data, urb->actual_length);
450 return; 438 return;
@@ -453,7 +441,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
453 /* Mask unwanted remote channels. */ 441 /* Mask unwanted remote channels. */
454 /* note: remote_num is 0-based, channel 1 on remote == 0 here */ 442 /* note: remote_num is 0-based, channel 1 on remote == 0 here */
455 remote_num = (data[3] >> 4) & 0x0f; 443 remote_num = (data[3] >> 4) & 0x0f;
456 if (channel_mask & (1 << (remote_num + 1))) { 444 if (channel_mask & (1 << (remote_num + 1))) {
457 dbginfo(&ati_remote->interface->dev, 445 dbginfo(&ati_remote->interface->dev,
458 "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n", 446 "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n",
459 remote_num, data[1], data[2], channel_mask); 447 remote_num, data[1], data[2], channel_mask);
@@ -463,37 +451,36 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
463 /* Look up event code index in translation table */ 451 /* Look up event code index in translation table */
464 index = ati_remote_event_lookup(remote_num, data[1], data[2]); 452 index = ati_remote_event_lookup(remote_num, data[1], data[2]);
465 if (index < 0) { 453 if (index < 0) {
466 dev_warn(&ati_remote->interface->dev, 454 dev_warn(&ati_remote->interface->dev,
467 "Unknown input from channel 0x%02x: data %02x,%02x\n", 455 "Unknown input from channel 0x%02x: data %02x,%02x\n",
468 remote_num, data[1], data[2]); 456 remote_num, data[1], data[2]);
469 return; 457 return;
470 } 458 }
471 dbginfo(&ati_remote->interface->dev, 459 dbginfo(&ati_remote->interface->dev,
472 "channel 0x%02x; data %02x,%02x; index %d; keycode %d\n", 460 "channel 0x%02x; data %02x,%02x; index %d; keycode %d\n",
473 remote_num, data[1], data[2], index, ati_remote_tbl[index].code); 461 remote_num, data[1], data[2], index, ati_remote_tbl[index].code);
474 462
475 if (ati_remote_tbl[index].kind == KIND_LITERAL) { 463 if (ati_remote_tbl[index].kind == KIND_LITERAL) {
476 input_regs(dev, regs); 464 input_regs(dev, regs);
477 input_event(dev, ati_remote_tbl[index].type, 465 input_event(dev, ati_remote_tbl[index].type,
478 ati_remote_tbl[index].code, 466 ati_remote_tbl[index].code,
479 ati_remote_tbl[index].value); 467 ati_remote_tbl[index].value);
480 input_sync(dev); 468 input_sync(dev);
481 469
482 ati_remote->old_jiffies = jiffies; 470 ati_remote->old_jiffies = jiffies;
483 return; 471 return;
484 } 472 }
485 473
486 if (ati_remote_tbl[index].kind == KIND_FILTERED) { 474 if (ati_remote_tbl[index].kind == KIND_FILTERED) {
487 /* Filter duplicate events which happen "too close" together. */ 475 /* Filter duplicate events which happen "too close" together. */
488 if ((ati_remote->old_data[0] == data[1]) && 476 if ((ati_remote->old_data[0] == data[1]) &&
489 (ati_remote->old_data[1] == data[2]) && 477 (ati_remote->old_data[1] == data[2]) &&
490 ((ati_remote->old_jiffies + FILTER_TIME) > jiffies)) { 478 ((ati_remote->old_jiffies + FILTER_TIME) > jiffies)) {
491 ati_remote->repeat_count++; 479 ati_remote->repeat_count++;
492 } 480 } else {
493 else {
494 ati_remote->repeat_count = 0; 481 ati_remote->repeat_count = 0;
495 } 482 }
496 483
497 ati_remote->old_data[0] = data[1]; 484 ati_remote->old_data[0] = data[1];
498 ati_remote->old_data[1] = data[2]; 485 ati_remote->old_data[1] = data[2];
499 ati_remote->old_jiffies = jiffies; 486 ati_remote->old_jiffies = jiffies;
@@ -501,7 +488,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
501 if ((ati_remote->repeat_count > 0) 488 if ((ati_remote->repeat_count > 0)
502 && (ati_remote->repeat_count < 5)) 489 && (ati_remote->repeat_count < 5))
503 return; 490 return;
504 491
505 492
506 input_regs(dev, regs); 493 input_regs(dev, regs);
507 input_event(dev, ati_remote_tbl[index].type, 494 input_event(dev, ati_remote_tbl[index].type,
@@ -511,13 +498,13 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
511 input_sync(dev); 498 input_sync(dev);
512 499
513 return; 500 return;
514 } 501 }
515 502
516 /* 503 /*
517 * Other event kinds are from the directional control pad, and have an 504 * Other event kinds are from the directional control pad, and have an
518 * acceleration factor applied to them. Without this acceleration, the 505 * acceleration factor applied to them. Without this acceleration, the
519 * control pad is mostly unusable. 506 * control pad is mostly unusable.
520 * 507 *
521 * If elapsed time since last event is > 1/4 second, user "stopped", 508 * If elapsed time since last event is > 1/4 second, user "stopped",
522 * so reset acceleration. Otherwise, user is probably holding the control 509 * so reset acceleration. Otherwise, user is probably holding the control
523 * pad down, so we increase acceleration, ramping up over two seconds to 510 * pad down, so we increase acceleration, ramping up over two seconds to
@@ -559,7 +546,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
559 input_report_rel(dev, REL_Y, acc); 546 input_report_rel(dev, REL_Y, acc);
560 break; 547 break;
561 default: 548 default:
562 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", 549 dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
563 ati_remote_tbl[index].kind); 550 ati_remote_tbl[index].kind);
564 } 551 }
565 input_sync(dev); 552 input_sync(dev);
@@ -586,12 +573,12 @@ static void ati_remote_irq_in(struct urb *urb, struct pt_regs *regs)
586 case -ESHUTDOWN: 573 case -ESHUTDOWN:
587 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n", 574 dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n",
588 __FUNCTION__); 575 __FUNCTION__);
589 return; 576 return;
590 default: /* error */ 577 default: /* error */
591 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n", 578 dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n",
592 __FUNCTION__, urb->status); 579 __FUNCTION__, urb->status);
593 } 580 }
594 581
595 retval = usb_submit_urb(urb, SLAB_ATOMIC); 582 retval = usb_submit_urb(urb, SLAB_ATOMIC);
596 if (retval) 583 if (retval)
597 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n", 584 dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n",
@@ -603,8 +590,6 @@ static void ati_remote_irq_in(struct urb *urb, struct pt_regs *regs)
603 */ 590 */
604static void ati_remote_delete(struct ati_remote *ati_remote) 591static void ati_remote_delete(struct ati_remote *ati_remote)
605{ 592{
606 if (!ati_remote) return;
607
608 if (ati_remote->irq_urb) 593 if (ati_remote->irq_urb)
609 usb_kill_urb(ati_remote->irq_urb); 594 usb_kill_urb(ati_remote->irq_urb);
610 595
@@ -614,16 +599,16 @@ static void ati_remote_delete(struct ati_remote *ati_remote)
614 input_unregister_device(&ati_remote->idev); 599 input_unregister_device(&ati_remote->idev);
615 600
616 if (ati_remote->inbuf) 601 if (ati_remote->inbuf)
617 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 602 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
618 ati_remote->inbuf, ati_remote->inbuf_dma); 603 ati_remote->inbuf, ati_remote->inbuf_dma);
619 604
620 if (ati_remote->outbuf) 605 if (ati_remote->outbuf)
621 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 606 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
622 ati_remote->outbuf, ati_remote->outbuf_dma); 607 ati_remote->outbuf, ati_remote->outbuf_dma);
623 608
624 if (ati_remote->irq_urb) 609 if (ati_remote->irq_urb)
625 usb_free_urb(ati_remote->irq_urb); 610 usb_free_urb(ati_remote->irq_urb);
626 611
627 if (ati_remote->out_urb) 612 if (ati_remote->out_urb)
628 usb_free_urb(ati_remote->out_urb); 613 usb_free_urb(ati_remote->out_urb);
629 614
@@ -636,51 +621,52 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
636 int i; 621 int i;
637 622
638 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 623 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
639 idev->keybit[LONG(BTN_MOUSE)] = ( BIT(BTN_LEFT) | BIT(BTN_RIGHT) | 624 idev->keybit[LONG(BTN_MOUSE)] = ( BIT(BTN_LEFT) | BIT(BTN_RIGHT) |
640 BIT(BTN_SIDE) | BIT(BTN_EXTRA) ); 625 BIT(BTN_SIDE) | BIT(BTN_EXTRA) );
641 idev->relbit[0] = BIT(REL_X) | BIT(REL_Y); 626 idev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
642 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) 627 for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
643 if (ati_remote_tbl[i].type == EV_KEY) 628 if (ati_remote_tbl[i].type == EV_KEY)
644 set_bit(ati_remote_tbl[i].code, idev->keybit); 629 set_bit(ati_remote_tbl[i].code, idev->keybit);
645 630
646 idev->private = ati_remote; 631 idev->private = ati_remote;
647 idev->open = ati_remote_open; 632 idev->open = ati_remote_open;
648 idev->close = ati_remote_close; 633 idev->close = ati_remote_close;
649 634
650 idev->name = ati_remote->name; 635 idev->name = ati_remote->name;
651 idev->phys = ati_remote->phys; 636 idev->phys = ati_remote->phys;
652 637
653 idev->id.bustype = BUS_USB; 638 idev->id.bustype = BUS_USB;
654 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor); 639 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor);
655 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct); 640 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct);
656 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice); 641 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice);
642 idev->dev = &(ati_remote->udev->dev);
657} 643}
658 644
659static int ati_remote_initialize(struct ati_remote *ati_remote) 645static int ati_remote_initialize(struct ati_remote *ati_remote)
660{ 646{
661 struct usb_device *udev = ati_remote->udev; 647 struct usb_device *udev = ati_remote->udev;
662 int pipe, maxp; 648 int pipe, maxp;
663 649
664 init_waitqueue_head(&ati_remote->wait); 650 init_waitqueue_head(&ati_remote->wait);
665 651
666 /* Set up irq_urb */ 652 /* Set up irq_urb */
667 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress); 653 pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
668 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 654 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
669 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; 655 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
670 656
671 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf, 657 usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
672 maxp, ati_remote_irq_in, ati_remote, 658 maxp, ati_remote_irq_in, ati_remote,
673 ati_remote->endpoint_in->bInterval); 659 ati_remote->endpoint_in->bInterval);
674 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma; 660 ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
675 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 661 ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
676 662
677 /* Set up out_urb */ 663 /* Set up out_urb */
678 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress); 664 pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
679 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 665 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
680 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; 666 maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
681 667
682 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf, 668 usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
683 maxp, ati_remote_irq_out, ati_remote, 669 maxp, ati_remote_irq_out, ati_remote,
684 ati_remote->endpoint_out->bInterval); 670 ati_remote->endpoint_out->bInterval);
685 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma; 671 ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
686 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 672 ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@@ -688,11 +674,11 @@ static int ati_remote_initialize(struct ati_remote *ati_remote)
688 /* send initialization strings */ 674 /* send initialization strings */
689 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) || 675 if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
690 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) { 676 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
691 dev_err(&ati_remote->interface->dev, 677 dev_err(&ati_remote->interface->dev,
692 "Initializing ati_remote hardware failed.\n"); 678 "Initializing ati_remote hardware failed.\n");
693 return 1; 679 return 1;
694 } 680 }
695 681
696 return 0; 682 return 0;
697} 683}
698 684
@@ -769,7 +755,7 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
769 755
770 if (!strlen(ati_remote->name)) 756 if (!strlen(ati_remote->name))
771 sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)", 757 sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)",
772 le16_to_cpu(ati_remote->udev->descriptor.idVendor), 758 le16_to_cpu(ati_remote->udev->descriptor.idVendor),
773 le16_to_cpu(ati_remote->udev->descriptor.idProduct)); 759 le16_to_cpu(ati_remote->udev->descriptor.idProduct));
774 760
775 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ 761 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
@@ -781,11 +767,11 @@ static int ati_remote_probe(struct usb_interface *interface, const struct usb_de
781 ati_remote_input_init(ati_remote); 767 ati_remote_input_init(ati_remote);
782 input_register_device(&ati_remote->idev); 768 input_register_device(&ati_remote->idev);
783 769
784 dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n", 770 dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n",
785 ati_remote->name, path); 771 ati_remote->name, path);
786 772
787 usb_set_intfdata(interface, ati_remote); 773 usb_set_intfdata(interface, ati_remote);
788 774
789error: 775error:
790 if (retval) 776 if (retval)
791 ati_remote_delete(ati_remote); 777 ati_remote_delete(ati_remote);
@@ -800,18 +786,14 @@ static void ati_remote_disconnect(struct usb_interface *interface)
800{ 786{
801 struct ati_remote *ati_remote; 787 struct ati_remote *ati_remote;
802 788
803 down(&disconnect_sem);
804
805 ati_remote = usb_get_intfdata(interface); 789 ati_remote = usb_get_intfdata(interface);
806 usb_set_intfdata(interface, NULL); 790 usb_set_intfdata(interface, NULL);
807 if (!ati_remote) { 791 if (!ati_remote) {
808 warn("%s - null device?\n", __FUNCTION__); 792 warn("%s - null device?\n", __FUNCTION__);
809 return; 793 return;
810 } 794 }
811
812 ati_remote_delete(ati_remote);
813 795
814 up(&disconnect_sem); 796 ati_remote_delete(ati_remote);
815} 797}
816 798
817/* 799/*
@@ -820,7 +802,7 @@ static void ati_remote_disconnect(struct usb_interface *interface)
820static int __init ati_remote_init(void) 802static int __init ati_remote_init(void)
821{ 803{
822 int result; 804 int result;
823 805
824 result = usb_register(&ati_remote_driver); 806 result = usb_register(&ati_remote_driver);
825 if (result) 807 if (result)
826 err("usb_register error #%d\n", result); 808 err("usb_register error #%d\n", result);
@@ -838,8 +820,8 @@ static void __exit ati_remote_exit(void)
838 usb_deregister(&ati_remote_driver); 820 usb_deregister(&ati_remote_driver);
839} 821}
840 822
841/* 823/*
842 * module specification 824 * module specification
843 */ 825 */
844 826
845module_init(ati_remote_init); 827module_init(ati_remote_init);
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 740dec1f521d..2350e7a5ad70 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -232,7 +232,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
232 report->size += parser->global.report_size * parser->global.report_count; 232 report->size += parser->global.report_size * parser->global.report_count;
233 233
234 if (!parser->local.usage_index) /* Ignore padding fields */ 234 if (!parser->local.usage_index) /* Ignore padding fields */
235 return 0; 235 return 0;
236 236
237 usages = max_t(int, parser->local.usage_index, parser->global.report_count); 237 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
238 238
@@ -765,7 +765,7 @@ static __inline__ __u32 s32ton(__s32 value, unsigned n)
765static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) 765static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
766{ 766{
767 report += (offset >> 5) << 2; offset &= 31; 767 report += (offset >> 5) << 2; offset &= 31;
768 return (le64_to_cpu(get_unaligned((__le64*)report)) >> offset) & ((1 << n) - 1); 768 return (le64_to_cpu(get_unaligned((__le64*)report)) >> offset) & ((1ULL << n) - 1);
769} 769}
770 770
771static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 771static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
@@ -1233,6 +1233,13 @@ int hid_wait_io(struct hid_device *hid)
1233 return 0; 1233 return 0;
1234} 1234}
1235 1235
1236static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
1237{
1238 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1239 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
1240 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1241}
1242
1236static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, 1243static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
1237 unsigned char type, void *buf, int size) 1244 unsigned char type, void *buf, int size)
1238{ 1245{
@@ -1301,10 +1308,6 @@ void hid_init_reports(struct hid_device *hid)
1301 1308
1302 if (err) 1309 if (err)
1303 warn("timeout initializing reports\n"); 1310 warn("timeout initializing reports\n");
1304
1305 usb_control_msg(hid->dev, usb_sndctrlpipe(hid->dev, 0),
1306 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0,
1307 hid->ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1308} 1311}
1309 1312
1310#define USB_VENDOR_ID_WACOM 0x056a 1313#define USB_VENDOR_ID_WACOM 0x056a
@@ -1318,6 +1321,10 @@ void hid_init_reports(struct hid_device *hid)
1318#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0 1321#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0
1319#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F 1322#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F
1320 1323
1324#define USB_VENDOR_ID_ACECAD 0x0460
1325#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
1326#define USB_DEVICE_ID_ACECAD_302 0x0008
1327
1321#define USB_VENDOR_ID_KBGEAR 0x084e 1328#define USB_VENDOR_ID_KBGEAR 0x084e
1322#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 1329#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
1323 1330
@@ -1421,6 +1428,19 @@ void hid_init_reports(struct hid_device *hid)
1421#define USB_DEVICE_ID_VERNIER_SKIP 0x0003 1428#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
1422#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 1429#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1423 1430
1431#define USB_VENDOR_ID_LD 0x0f11
1432#define USB_DEVICE_ID_CASSY 0x1000
1433#define USB_DEVICE_ID_POCKETCASSY 0x1010
1434#define USB_DEVICE_ID_MOBILECASSY 0x1020
1435#define USB_DEVICE_ID_JWM 0x1080
1436#define USB_DEVICE_ID_DMMP 0x1081
1437#define USB_DEVICE_ID_UMIP 0x1090
1438#define USB_DEVICE_ID_VIDEOCOM 0x1200
1439#define USB_DEVICE_ID_COM3LAB 0x2000
1440#define USB_DEVICE_ID_TELEPORT 0x2010
1441#define USB_DEVICE_ID_NETWORKANALYSER 0x2020
1442#define USB_DEVICE_ID_POWERCONTROL 0x2030
1443
1424 1444
1425/* 1445/*
1426 * Alphabetically sorted blacklist by quirk type. 1446 * Alphabetically sorted blacklist by quirk type.
@@ -1456,6 +1476,17 @@ static struct hid_blacklist {
1456 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, 1476 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
1457 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, 1477 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
1458 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 1478 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
1479 { USB_VENDOR_ID_LD, USB_DEVICE_ID_CASSY, HID_QUIRK_IGNORE },
1480 { USB_VENDOR_ID_LD, USB_DEVICE_ID_POCKETCASSY, HID_QUIRK_IGNORE },
1481 { USB_VENDOR_ID_LD, USB_DEVICE_ID_MOBILECASSY, HID_QUIRK_IGNORE },
1482 { USB_VENDOR_ID_LD, USB_DEVICE_ID_JWM, HID_QUIRK_IGNORE },
1483 { USB_VENDOR_ID_LD, USB_DEVICE_ID_DMMP, HID_QUIRK_IGNORE },
1484 { USB_VENDOR_ID_LD, USB_DEVICE_ID_UMIP, HID_QUIRK_IGNORE },
1485 { USB_VENDOR_ID_LD, USB_DEVICE_ID_VIDEOCOM, HID_QUIRK_IGNORE },
1486 { USB_VENDOR_ID_LD, USB_DEVICE_ID_COM3LAB, HID_QUIRK_IGNORE },
1487 { USB_VENDOR_ID_LD, USB_DEVICE_ID_TELEPORT, HID_QUIRK_IGNORE },
1488 { USB_VENDOR_ID_LD, USB_DEVICE_ID_NETWORKANALYSER, HID_QUIRK_IGNORE },
1489 { USB_VENDOR_ID_LD, USB_DEVICE_ID_POWERCONTROL, HID_QUIRK_IGNORE },
1459 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE }, 1490 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
1460 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE }, 1491 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
1461 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, 1492 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
@@ -1502,6 +1533,9 @@ static struct hid_blacklist {
1502 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1533 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1503 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1534 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1504 1535
1536 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
1537 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
1538
1505 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, 1539 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
1506 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, 1540 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
1507 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 1541 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
@@ -1590,6 +1624,8 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1590 return NULL; 1624 return NULL;
1591 } 1625 }
1592 1626
1627 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
1628
1593 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { 1629 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
1594 dbg("reading report descriptor failed"); 1630 dbg("reading report descriptor failed");
1595 kfree(rdesc); 1631 kfree(rdesc);
@@ -1635,7 +1671,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1635 /* Change the polling interval of mice. */ 1671 /* Change the polling interval of mice. */
1636 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 1672 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
1637 interval = hid_mousepoll_interval; 1673 interval = hid_mousepoll_interval;
1638 1674
1639 if (endpoint->bEndpointAddress & USB_DIR_IN) { 1675 if (endpoint->bEndpointAddress & USB_DIR_IN) {
1640 if (hid->urbin) 1676 if (hid->urbin)
1641 continue; 1677 continue;
diff --git a/drivers/usb/input/hid-debug.h b/drivers/usb/input/hid-debug.h
index 2b91705740a7..52437e5e2e78 100644
--- a/drivers/usb/input/hid-debug.h
+++ b/drivers/usb/input/hid-debug.h
@@ -67,7 +67,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
67 {0, 0x44, "Vbry"}, 67 {0, 0x44, "Vbry"},
68 {0, 0x45, "Vbrz"}, 68 {0, 0x45, "Vbrz"},
69 {0, 0x46, "Vno"}, 69 {0, 0x46, "Vno"},
70 {0, 0x80, "SystemControl"}, 70 {0, 0x80, "SystemControl"},
71 {0, 0x81, "SystemPowerDown"}, 71 {0, 0x81, "SystemPowerDown"},
72 {0, 0x82, "SystemSleep"}, 72 {0, 0x82, "SystemSleep"},
73 {0, 0x83, "SystemWakeUp"}, 73 {0, 0x83, "SystemWakeUp"},
@@ -347,7 +347,7 @@ __inline__ static void tab(int n) {
347 347
348static void hid_dump_field(struct hid_field *field, int n) { 348static void hid_dump_field(struct hid_field *field, int n) {
349 int j; 349 int j;
350 350
351 if (field->physical) { 351 if (field->physical) {
352 tab(n); 352 tab(n);
353 printk("Physical("); 353 printk("Physical(");
@@ -408,7 +408,7 @@ static void hid_dump_field(struct hid_field *field, int n) {
408 printk("%s", units[sys][i]); 408 printk("%s", units[sys][i]);
409 if(nibble != 1) { 409 if(nibble != 1) {
410 /* This is a _signed_ nibble(!) */ 410 /* This is a _signed_ nibble(!) */
411 411
412 int val = nibble & 0x7; 412 int val = nibble & 0x7;
413 if(nibble & 0x08) 413 if(nibble & 0x08)
414 val = -((0x7 & ~val) +1); 414 val = -((0x7 & ~val) +1);
@@ -443,7 +443,7 @@ static void __attribute__((unused)) hid_dump_device(struct hid_device *device) {
443 struct list_head *list; 443 struct list_head *list;
444 unsigned i,k; 444 unsigned i,k;
445 static char *table[] = {"INPUT", "OUTPUT", "FEATURE"}; 445 static char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
446 446
447 for (i = 0; i < HID_REPORT_TYPES; i++) { 447 for (i = 0; i < HID_REPORT_TYPES; i++) {
448 report_enum = device->report_enum + i; 448 report_enum = device->report_enum + i;
449 list = report_enum->report_list.next; 449 list = report_enum->report_list.next;
@@ -664,8 +664,8 @@ static char *keys[KEY_MAX + 1] = {
664static char *relatives[REL_MAX + 1] = { 664static char *relatives[REL_MAX + 1] = {
665 [REL_X] = "X", [REL_Y] = "Y", 665 [REL_X] = "X", [REL_Y] = "Y",
666 [REL_Z] = "Z", [REL_HWHEEL] = "HWheel", 666 [REL_Z] = "Z", [REL_HWHEEL] = "HWheel",
667 [REL_DIAL] = "Dial", [REL_WHEEL] = "Wheel", 667 [REL_DIAL] = "Dial", [REL_WHEEL] = "Wheel",
668 [REL_MISC] = "Misc", 668 [REL_MISC] = "Misc",
669}; 669};
670 670
671static char *absolutes[ABS_MAX + 1] = { 671static char *absolutes[ABS_MAX + 1] = {
@@ -690,9 +690,9 @@ static char *misc[MSC_MAX + 1] = {
690}; 690};
691 691
692static char *leds[LED_MAX + 1] = { 692static char *leds[LED_MAX + 1] = {
693 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock", 693 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
694 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose", 694 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
695 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep", 695 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
696 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute", 696 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
697 [LED_MISC] = "Misc", 697 [LED_MISC] = "Misc",
698}; 698};
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 5553c3553e9d..9ac1e9095334 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -164,7 +164,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
164 case HID_GD_X: case HID_GD_Y: case HID_GD_Z: 164 case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
165 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: 165 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
166 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: 166 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL:
167 if (field->flags & HID_MAIN_ITEM_RELATIVE) 167 if (field->flags & HID_MAIN_ITEM_RELATIVE)
168 map_rel(usage->hid & 0xf); 168 map_rel(usage->hid & 0xf);
169 else 169 else
170 map_abs(usage->hid & 0xf); 170 map_abs(usage->hid & 0xf);
@@ -297,7 +297,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
297 case HID_UP_MSVENDOR: 297 case HID_UP_MSVENDOR:
298 298
299 goto ignore; 299 goto ignore;
300 300
301 case HID_UP_PID: 301 case HID_UP_PID:
302 302
303 set_bit(EV_FF, input->evbit); 303 set_bit(EV_FF, input->evbit);
@@ -349,7 +349,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
349 goto ignore; 349 goto ignore;
350 350
351 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) && 351 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) &&
352 (usage->type == EV_REL) && (usage->code == REL_WHEEL)) 352 (usage->type == EV_REL) && (usage->code == REL_WHEEL))
353 set_bit(REL_HWHEEL, bit); 353 set_bit(REL_HWHEEL, bit);
354 354
355 if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005)) 355 if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
@@ -365,11 +365,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
365 a = field->logical_minimum = 0; 365 a = field->logical_minimum = 0;
366 b = field->logical_maximum = 255; 366 b = field->logical_maximum = 255;
367 } 367 }
368 368
369 if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK) 369 if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK)
370 input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4); 370 input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4);
371 else input_set_abs_params(input, usage->code, a, b, 0, 0); 371 else input_set_abs_params(input, usage->code, a, b, 0, 0);
372 372
373 } 373 }
374 374
375 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 375 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
@@ -420,7 +420,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
420 return; 420 return;
421 } 421 }
422 422
423 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 423 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
424 int hat_dir = usage->hat_dir; 424 int hat_dir = usage->hat_dir;
425 if (!hat_dir) 425 if (!hat_dir)
426 hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; 426 hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1;
@@ -551,7 +551,7 @@ int hidinput_connect(struct hid_device *hid)
551 for (i = 0; i < hid->maxcollection; i++) 551 for (i = 0; i < hid->maxcollection; i++)
552 if (hid->collection[i].type == HID_COLLECTION_APPLICATION || 552 if (hid->collection[i].type == HID_COLLECTION_APPLICATION ||
553 hid->collection[i].type == HID_COLLECTION_PHYSICAL) 553 hid->collection[i].type == HID_COLLECTION_PHYSICAL)
554 if (IS_INPUT_APPLICATION(hid->collection[i].usage)) 554 if (IS_INPUT_APPLICATION(hid->collection[i].usage))
555 break; 555 break;
556 556
557 if (i == hid->maxcollection) 557 if (i == hid->maxcollection)
@@ -592,7 +592,7 @@ int hidinput_connect(struct hid_device *hid)
592 for (j = 0; j < report->field[i]->maxusage; j++) 592 for (j = 0; j < report->field[i]->maxusage; j++)
593 hidinput_configure_usage(hidinput, report->field[i], 593 hidinput_configure_usage(hidinput, report->field[i],
594 report->field[i]->usage + j); 594 report->field[i]->usage + j);
595 595
596 if (hid->quirks & HID_QUIRK_MULTI_INPUT) { 596 if (hid->quirks & HID_QUIRK_MULTI_INPUT) {
597 /* This will leave hidinput NULL, so that it 597 /* This will leave hidinput NULL, so that it
598 * allocates another one if we have more inputs on 598 * allocates another one if we have more inputs on
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 0d7404bab92f..0c4c77aa31ea 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -94,7 +94,7 @@ struct lgff_device {
94 isn't really necessary */ 94 isn't really necessary */
95 95
96 unsigned long flags[1]; /* Contains various information about the 96 unsigned long flags[1]; /* Contains various information about the
97 state of the driver for this device */ 97 state of the driver for this device */
98 98
99 struct timer_list timer; 99 struct timer_list timer;
100}; 100};
@@ -234,7 +234,7 @@ static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
234 kfree(ret); 234 kfree(ret);
235 return NULL; 235 return NULL;
236 } 236 }
237 memset(ret->field[0]->value, 0, sizeof(s32[8])); 237 memset(ret->field[0]->value, 0, sizeof(s32[8]));
238 238
239 return ret; 239 return ret;
240} 240}
@@ -295,11 +295,11 @@ static int hid_lgff_event(struct hid_device *hid, struct input_dev* input,
295 unsigned long flags; 295 unsigned long flags;
296 296
297 if (type != EV_FF) return -EINVAL; 297 if (type != EV_FF) return -EINVAL;
298 if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES; 298 if (!LGFF_CHECK_OWNERSHIP(code, lgff)) return -EACCES;
299 if (value < 0) return -EINVAL; 299 if (value < 0) return -EINVAL;
300 300
301 spin_lock_irqsave(&lgff->lock, flags); 301 spin_lock_irqsave(&lgff->lock, flags);
302 302
303 if (value > 0) { 303 if (value > 0) {
304 if (test_bit(EFFECT_STARTED, effect->flags)) { 304 if (test_bit(EFFECT_STARTED, effect->flags)) {
305 spin_unlock_irqrestore(&lgff->lock, flags); 305 spin_unlock_irqrestore(&lgff->lock, flags);
@@ -345,7 +345,7 @@ static int hid_lgff_flush(struct input_dev *dev, struct file *file)
345 and perform ioctls on the same fd all at the same time */ 345 and perform ioctls on the same fd all at the same time */
346 if ( current->pid == lgff->effects[i].owner 346 if ( current->pid == lgff->effects[i].owner
347 && test_bit(EFFECT_USED, lgff->effects[i].flags)) { 347 && test_bit(EFFECT_USED, lgff->effects[i].flags)) {
348 348
349 if (hid_lgff_erase(dev, i)) 349 if (hid_lgff_erase(dev, i))
350 warn("erase effect %d failed", i); 350 warn("erase effect %d failed", i);
351 } 351 }
@@ -378,7 +378,7 @@ static int hid_lgff_upload_effect(struct input_dev* input,
378 struct lgff_effect new; 378 struct lgff_effect new;
379 int id; 379 int id;
380 unsigned long flags; 380 unsigned long flags;
381 381
382 dbg("ioctl rumble"); 382 dbg("ioctl rumble");
383 383
384 if (!test_bit(effect->type, input->ffbit)) return -EINVAL; 384 if (!test_bit(effect->type, input->ffbit)) return -EINVAL;
@@ -441,7 +441,7 @@ static void hid_lgff_timer(unsigned long timer_data)
441 441
442 spin_lock_irqsave(&lgff->lock, flags); 442 spin_lock_irqsave(&lgff->lock, flags);
443 443
444 for (i=0; i<LGFF_EFFECTS; ++i) { 444 for (i=0; i<LGFF_EFFECTS; ++i) {
445 struct lgff_effect* effect = lgff->effects +i; 445 struct lgff_effect* effect = lgff->effects +i;
446 446
447 if (test_bit(EFFECT_PLAYING, effect->flags)) { 447 if (test_bit(EFFECT_PLAYING, effect->flags)) {
@@ -491,7 +491,7 @@ static void hid_lgff_timer(unsigned long timer_data)
491 set_bit(EFFECT_PLAYING, lgff->effects[i].flags); 491 set_bit(EFFECT_PLAYING, lgff->effects[i].flags);
492 } 492 }
493 } 493 }
494 } 494 }
495 495
496#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff 496#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
497 497
@@ -524,5 +524,5 @@ static void hid_lgff_timer(unsigned long timer_data)
524 add_timer(&lgff->timer); 524 add_timer(&lgff->timer);
525 } 525 }
526 526
527 spin_unlock_irqrestore(&lgff->lock, flags); 527 spin_unlock_irqrestore(&lgff->lock, flags);
528} 528}
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 6d9329c698d9..c1b6b69bc4a4 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -118,7 +118,7 @@ struct hid_item {
118#define HID_MAIN_ITEM_CONSTANT 0x001 118#define HID_MAIN_ITEM_CONSTANT 0x001
119#define HID_MAIN_ITEM_VARIABLE 0x002 119#define HID_MAIN_ITEM_VARIABLE 0x002
120#define HID_MAIN_ITEM_RELATIVE 0x004 120#define HID_MAIN_ITEM_RELATIVE 0x004
121#define HID_MAIN_ITEM_WRAP 0x008 121#define HID_MAIN_ITEM_WRAP 0x008
122#define HID_MAIN_ITEM_NONLINEAR 0x010 122#define HID_MAIN_ITEM_NONLINEAR 0x010
123#define HID_MAIN_ITEM_NO_PREFERRED 0x020 123#define HID_MAIN_ITEM_NO_PREFERRED 0x020
124#define HID_MAIN_ITEM_NULL_STATE 0x040 124#define HID_MAIN_ITEM_NULL_STATE 0x040
@@ -172,14 +172,14 @@ struct hid_item {
172#define HID_USAGE_PAGE 0xffff0000 172#define HID_USAGE_PAGE 0xffff0000
173 173
174#define HID_UP_UNDEFINED 0x00000000 174#define HID_UP_UNDEFINED 0x00000000
175#define HID_UP_GENDESK 0x00010000 175#define HID_UP_GENDESK 0x00010000
176#define HID_UP_KEYBOARD 0x00070000 176#define HID_UP_KEYBOARD 0x00070000
177#define HID_UP_LED 0x00080000 177#define HID_UP_LED 0x00080000
178#define HID_UP_BUTTON 0x00090000 178#define HID_UP_BUTTON 0x00090000
179#define HID_UP_ORDINAL 0x000a0000 179#define HID_UP_ORDINAL 0x000a0000
180#define HID_UP_CONSUMER 0x000c0000 180#define HID_UP_CONSUMER 0x000c0000
181#define HID_UP_DIGITIZER 0x000d0000 181#define HID_UP_DIGITIZER 0x000d0000
182#define HID_UP_PID 0x000f0000 182#define HID_UP_PID 0x000f0000
183#define HID_UP_HPVENDOR 0xff7f0000 183#define HID_UP_HPVENDOR 0xff7f0000
184#define HID_UP_MSVENDOR 0xff000000 184#define HID_UP_MSVENDOR 0xff000000
185 185
@@ -406,7 +406,7 @@ struct hid_device { /* device report descriptor */
406 dma_addr_t outbuf_dma; /* Output buffer dma */ 406 dma_addr_t outbuf_dma; /* Output buffer dma */
407 spinlock_t outlock; /* Output fifo spinlock */ 407 spinlock_t outlock; /* Output fifo spinlock */
408 408
409 unsigned claimed; /* Claimed by hidinput, hiddev? */ 409 unsigned claimed; /* Claimed by hidinput, hiddev? */
410 unsigned quirks; /* Various quirks the device can pull on us */ 410 unsigned quirks; /* Various quirks the device can pull on us */
411 411
412 struct list_head inputs; /* The list of inputs */ 412 struct list_head inputs; /* The list of inputs */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 96b7c9067951..4c13331b5f41 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -95,7 +95,7 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
95 return NULL; 95 return NULL;
96 rinfo->report_id = ((struct hid_report *) list)->id; 96 rinfo->report_id = ((struct hid_report *) list)->id;
97 break; 97 break;
98 98
99 case HID_REPORT_ID_NEXT: 99 case HID_REPORT_ID_NEXT:
100 list = (struct list_head *) 100 list = (struct list_head *)
101 report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK]; 101 report_enum->report_id_hash[rinfo->report_id & HID_REPORT_ID_MASK];
@@ -106,7 +106,7 @@ hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo)
106 return NULL; 106 return NULL;
107 rinfo->report_id = ((struct hid_report *) list)->id; 107 rinfo->report_id = ((struct hid_report *) list)->id;
108 break; 108 break;
109 109
110 default: 110 default:
111 return NULL; 111 return NULL;
112 } 112 }
@@ -158,7 +158,7 @@ static void hiddev_send_event(struct hid_device *hid,
158 if (uref->field_index != HID_FIELD_INDEX_NONE || 158 if (uref->field_index != HID_FIELD_INDEX_NONE ||
159 (list->flags & HIDDEV_FLAG_REPORT) != 0) { 159 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
160 list->buffer[list->head] = *uref; 160 list->buffer[list->head] = *uref;
161 list->head = (list->head + 1) & 161 list->head = (list->head + 1) &
162 (HIDDEV_BUFFER_SIZE - 1); 162 (HIDDEV_BUFFER_SIZE - 1);
163 kill_fasync(&list->fasync, SIGIO, POLL_IN); 163 kill_fasync(&list->fasync, SIGIO, POLL_IN);
164 } 164 }
@@ -179,9 +179,9 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
179 unsigned type = field->report_type; 179 unsigned type = field->report_type;
180 struct hiddev_usage_ref uref; 180 struct hiddev_usage_ref uref;
181 181
182 uref.report_type = 182 uref.report_type =
183 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 183 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
184 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 184 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
185 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 185 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0));
186 uref.report_id = field->report->id; 186 uref.report_id = field->report->id;
187 uref.field_index = field->index; 187 uref.field_index = field->index;
@@ -199,9 +199,9 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
199 struct hiddev_usage_ref uref; 199 struct hiddev_usage_ref uref;
200 200
201 memset(&uref, 0, sizeof(uref)); 201 memset(&uref, 0, sizeof(uref));
202 uref.report_type = 202 uref.report_type =
203 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : 203 (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT :
204 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : 204 ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT :
205 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0)); 205 ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE:0));
206 uref.report_id = report->id; 206 uref.report_id = report->id;
207 uref.field_index = HID_FIELD_INDEX_NONE; 207 uref.field_index = HID_FIELD_INDEX_NONE;
@@ -236,7 +236,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
236 *listptr = (*listptr)->next; 236 *listptr = (*listptr)->next;
237 237
238 if (!--list->hiddev->open) { 238 if (!--list->hiddev->open) {
239 if (list->hiddev->exist) 239 if (list->hiddev->exist)
240 hid_close(list->hiddev->hid); 240 hid_close(list->hiddev->hid);
241 else 241 else
242 kfree(list->hiddev); 242 kfree(list->hiddev);
@@ -303,7 +303,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
303 if (list->head == list->tail) { 303 if (list->head == list->tail) {
304 add_wait_queue(&list->hiddev->wait, &wait); 304 add_wait_queue(&list->hiddev->wait, &wait);
305 set_current_state(TASK_INTERRUPTIBLE); 305 set_current_state(TASK_INTERRUPTIBLE);
306 306
307 while (list->head == list->tail) { 307 while (list->head == list->tail) {
308 if (file->f_flags & O_NONBLOCK) { 308 if (file->f_flags & O_NONBLOCK) {
309 retval = -EAGAIN; 309 retval = -EAGAIN;
@@ -317,7 +317,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
317 retval = -EIO; 317 retval = -EIO;
318 break; 318 break;
319 } 319 }
320 320
321 schedule(); 321 schedule();
322 } 322 }
323 323
@@ -329,7 +329,7 @@ static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t coun
329 return retval; 329 return retval;
330 330
331 331
332 while (list->head != list->tail && 332 while (list->head != list->tail &&
333 retval + event_size <= count) { 333 retval + event_size <= count) {
334 if ((list->flags & HIDDEV_FLAG_UREF) == 0) { 334 if ((list->flags & HIDDEV_FLAG_UREF) == 0) {
335 if (list->buffer[list->tail].field_index != 335 if (list->buffer[list->tail].field_index !=
@@ -405,10 +405,10 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
405 return -EINVAL; 405 return -EINVAL;
406 406
407 for (i = 0; i < hid->maxcollection; i++) 407 for (i = 0; i < hid->maxcollection; i++)
408 if (hid->collection[i].type == 408 if (hid->collection[i].type ==
409 HID_COLLECTION_APPLICATION && arg-- == 0) 409 HID_COLLECTION_APPLICATION && arg-- == 0)
410 break; 410 break;
411 411
412 if (i == hid->maxcollection) 412 if (i == hid->maxcollection)
413 return -EINVAL; 413 return -EINVAL;
414 414
@@ -562,7 +562,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
562 if (!uref_multi) 562 if (!uref_multi)
563 return -ENOMEM; 563 return -ENOMEM;
564 uref = &uref_multi->uref; 564 uref = &uref_multi->uref;
565 if (copy_from_user(uref, user_arg, sizeof(*uref))) 565 if (copy_from_user(uref, user_arg, sizeof(*uref)))
566 goto fault; 566 goto fault;
567 567
568 rinfo.report_type = uref->report_type; 568 rinfo.report_type = uref->report_type;
@@ -595,7 +595,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
595 return -ENOMEM; 595 return -ENOMEM;
596 uref = &uref_multi->uref; 596 uref = &uref_multi->uref;
597 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { 597 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
598 if (copy_from_user(uref_multi, user_arg, 598 if (copy_from_user(uref_multi, user_arg,
599 sizeof(*uref_multi))) 599 sizeof(*uref_multi)))
600 goto fault; 600 goto fault;
601 } else { 601 } else {
@@ -603,7 +603,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
603 goto fault; 603 goto fault;
604 } 604 }
605 605
606 if (cmd != HIDIOCGUSAGE && 606 if (cmd != HIDIOCGUSAGE &&
607 cmd != HIDIOCGUSAGES && 607 cmd != HIDIOCGUSAGES &&
608 uref->report_type == HID_REPORT_TYPE_INPUT) 608 uref->report_type == HID_REPORT_TYPE_INPUT)
609 goto inval; 609 goto inval;
@@ -651,16 +651,16 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
651 return field->usage[uref->usage_index].collection_index; 651 return field->usage[uref->usage_index].collection_index;
652 case HIDIOCGUSAGES: 652 case HIDIOCGUSAGES:
653 for (i = 0; i < uref_multi->num_values; i++) 653 for (i = 0; i < uref_multi->num_values; i++)
654 uref_multi->values[i] = 654 uref_multi->values[i] =
655 field->value[uref->usage_index + i]; 655 field->value[uref->usage_index + i];
656 if (copy_to_user(user_arg, uref_multi, 656 if (copy_to_user(user_arg, uref_multi,
657 sizeof(*uref_multi))) 657 sizeof(*uref_multi)))
658 goto fault; 658 goto fault;
659 goto goodreturn; 659 goto goodreturn;
660 case HIDIOCSUSAGES: 660 case HIDIOCSUSAGES:
661 for (i = 0; i < uref_multi->num_values; i++) 661 for (i = 0; i < uref_multi->num_values; i++)
662 field->value[uref->usage_index + i] = 662 field->value[uref->usage_index + i] =
663 uref_multi->values[i]; 663 uref_multi->values[i];
664 goto goodreturn; 664 goto goodreturn;
665 } 665 }
666 666
@@ -670,7 +670,7 @@ goodreturn:
670fault: 670fault:
671 kfree(uref_multi); 671 kfree(uref_multi);
672 return -EFAULT; 672 return -EFAULT;
673inval: 673inval:
674 kfree(uref_multi); 674 kfree(uref_multi);
675 return -EINVAL; 675 return -EINVAL;
676 676
@@ -734,7 +734,7 @@ static struct usb_class_driver hiddev_class = {
734 .name = "usb/hid/hiddev%d", 734 .name = "usb/hid/hiddev%d",
735 .fops = &hiddev_fops, 735 .fops = &hiddev_fops,
736 .mode = S_IFCHR | S_IRUGO | S_IWUSR, 736 .mode = S_IFCHR | S_IRUGO | S_IWUSR,
737 .minor_base = HIDDEV_MINOR_BASE, 737 .minor_base = HIDDEV_MINOR_BASE,
738}; 738};
739 739
740/* 740/*
@@ -747,7 +747,7 @@ int hiddev_connect(struct hid_device *hid)
747 int retval; 747 int retval;
748 748
749 for (i = 0; i < hid->maxcollection; i++) 749 for (i = 0; i < hid->maxcollection; i++)
750 if (hid->collection[i].type == 750 if (hid->collection[i].type ==
751 HID_COLLECTION_APPLICATION && 751 HID_COLLECTION_APPLICATION &&
752 !IS_INPUT_APPLICATION(hid->collection[i].usage)) 752 !IS_INPUT_APPLICATION(hid->collection[i].usage))
753 break; 753 break;
@@ -755,11 +755,11 @@ int hiddev_connect(struct hid_device *hid)
755 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) 755 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0)
756 return -1; 756 return -1;
757 757
758 if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL))) 758 if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL)))
759 return -1; 759 return -1;
760 memset(hiddev, 0, sizeof(struct hiddev)); 760 memset(hiddev, 0, sizeof(struct hiddev));
761 761
762 retval = usb_register_dev(hid->intf, &hiddev_class); 762 retval = usb_register_dev(hid->intf, &hiddev_class);
763 if (retval) { 763 if (retval) {
764 err("Not able to get a minor for this device."); 764 err("Not able to get a minor for this device.");
765 kfree(hiddev); 765 kfree(hiddev);
@@ -768,12 +768,12 @@ int hiddev_connect(struct hid_device *hid)
768 768
769 init_waitqueue_head(&hiddev->wait); 769 init_waitqueue_head(&hiddev->wait);
770 770
771 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; 771 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
772 772
773 hiddev->hid = hid; 773 hiddev->hid = hid;
774 hiddev->exist = 1; 774 hiddev->exist = 1;
775 775
776 hid->minor = hid->intf->minor; 776 hid->minor = hid->intf->minor;
777 hid->hiddev = hiddev; 777 hid->hiddev = hiddev;
778 778
779 return 0; 779 return 0;
@@ -818,7 +818,7 @@ void hiddev_disconnect(struct hid_device *hid)
818/* We never attach in this manner, and rely on HID to connect us. This 818/* We never attach in this manner, and rely on HID to connect us. This
819 * is why there is no disconnect routine defined in the usb_driver either. 819 * is why there is no disconnect routine defined in the usb_driver either.
820 */ 820 */
821static int hiddev_usbd_probe(struct usb_interface *intf, 821static int hiddev_usbd_probe(struct usb_interface *intf,
822 const struct usb_device_id *hiddev_info) 822 const struct usb_device_id *hiddev_info)
823{ 823{
824 return -ENODEV; 824 return -ENODEV;
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
new file mode 100644
index 000000000000..47dec6a1b344
--- /dev/null
+++ b/drivers/usb/input/itmtouch.c
@@ -0,0 +1,268 @@
1/******************************************************************************
2 * itmtouch.c -- Driver for ITM touchscreen panel
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Based upon original work by Chris Collins <xfire-itmtouch@xware.cx>.
19 *
20 * Kudos to ITM for providing me with the datasheet for the panel,
21 * even though it was a day later than I had finished writing this
22 * driver.
23 *
24 * It has meant that I've been able to correct my interpretation of the
25 * protocol packets however.
26 *
27 * CC -- 2003/9/29
28 *
29 * History
30 * 1.0 & 1.1 2003 (CC) vojtech@suse.cz
31 * Original version for 2.4.x kernels
32 *
33 * 1.2 02/03/2005 (HCE) hc@mivu.no
34 * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints.
35 * Unfortunately no calibration support at this time.
36 *
37 * 1.2.1 09/03/2005 (HCE) hc@mivu.no
38 * Code cleanup and adjusting syntax to start matching kernel standards
39 *
40 *****************************************************************************/
41
42#include <linux/config.h>
43
44#ifdef CONFIG_USB_DEBUG
45 #define DEBUG
46#else
47 #undef DEBUG
48#endif
49
50#include <linux/kernel.h>
51#include <linux/slab.h>
52#include <linux/input.h>
53#include <linux/module.h>
54#include <linux/init.h>
55#include <linux/usb.h>
56
57/* only an 8 byte buffer necessary for a single packet */
58#define ITM_BUFSIZE 8
59#define PATH_SIZE 64
60
61#define USB_VENDOR_ID_ITMINC 0x0403
62#define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9
63
64#define DRIVER_AUTHOR "Hans-Christian Egtvedt <hc@mivu.no>"
65#define DRIVER_VERSION "v1.2.1"
66#define DRIVER_DESC "USB ITM Inc Touch Panel Driver"
67#define DRIVER_LICENSE "GPL"
68
69MODULE_AUTHOR( DRIVER_AUTHOR );
70MODULE_DESCRIPTION( DRIVER_DESC );
71MODULE_LICENSE( DRIVER_LICENSE );
72
73struct itmtouch_dev {
74 struct usb_device *usbdev; /* usb device */
75 struct input_dev inputdev; /* input device */
76 struct urb *readurb; /* urb */
77 char rbuf[ITM_BUFSIZE]; /* data */
78 int users;
79 char name[128];
80 char phys[64];
81};
82
83static struct usb_device_id itmtouch_ids [] = {
84 { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) },
85 { }
86};
87
88static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
89{
90 struct itmtouch_dev * itmtouch = urb->context;
91 unsigned char *data = urb->transfer_buffer;
92 struct input_dev *dev = &itmtouch->inputdev;
93 int retval;
94
95 switch (urb->status) {
96 case 0:
97 /* success */
98 break;
99 case -ETIMEDOUT:
100 /* this urb is timing out */
101 dbg("%s - urb timed out - was the device unplugged?",
102 __FUNCTION__);
103 return;
104 case -ECONNRESET:
105 case -ENOENT:
106 case -ESHUTDOWN:
107 /* this urb is terminated, clean up */
108 dbg("%s - urb shutting down with status: %d",
109 __FUNCTION__, urb->status);
110 return;
111 default:
112 dbg("%s - nonzero urb status received: %d",
113 __FUNCTION__, urb->status);
114 goto exit;
115 }
116
117 input_regs(dev, regs);
118
119 /* if pressure has been released, then don't report X/Y */
120 if (data[7] & 0x20) {
121 input_report_abs(dev, ABS_X, (data[0] & 0x1F) << 7 | (data[3] & 0x7F));
122 input_report_abs(dev, ABS_Y, (data[1] & 0x1F) << 7 | (data[4] & 0x7F));
123 }
124
125 input_report_abs(dev, ABS_PRESSURE, (data[2] & 1) << 7 | (data[5] & 0x7F));
126 input_report_key(dev, BTN_TOUCH, ~data[7] & 0x20);
127 input_sync(dev);
128
129exit:
130 retval = usb_submit_urb (urb, GFP_ATOMIC);
131 if (retval)
132 printk(KERN_ERR "%s - usb_submit_urb failed with result: %d",
133 __FUNCTION__, retval);
134}
135
136static int itmtouch_open(struct input_dev *input)
137{
138 struct itmtouch_dev *itmtouch = input->private;
139
140 itmtouch->readurb->dev = itmtouch->usbdev;
141
142 if (usb_submit_urb(itmtouch->readurb, GFP_KERNEL))
143 return -EIO;
144
145 return 0;
146}
147
148static void itmtouch_close(struct input_dev *input)
149{
150 struct itmtouch_dev *itmtouch = input->private;
151
152 usb_kill_urb(itmtouch->readurb);
153}
154
155static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id)
156{
157 struct itmtouch_dev *itmtouch;
158 struct usb_host_interface *interface;
159 struct usb_endpoint_descriptor *endpoint;
160 struct usb_device *udev = interface_to_usbdev(intf);
161 unsigned int pipe;
162 unsigned int maxp;
163 char path[PATH_SIZE];
164
165 interface = intf->cur_altsetting;
166 endpoint = &interface->endpoint[0].desc;
167
168 if (!(itmtouch = kcalloc(1, sizeof(struct itmtouch_dev), GFP_KERNEL))) {
169 err("%s - Out of memory.", __FUNCTION__);
170 return -ENOMEM;
171 }
172
173 itmtouch->usbdev = udev;
174
175 itmtouch->inputdev.private = itmtouch;
176 itmtouch->inputdev.open = itmtouch_open;
177 itmtouch->inputdev.close = itmtouch_close;
178
179 usb_make_path(udev, path, PATH_SIZE);
180
181 itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
182 itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
183 itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
184
185 itmtouch->inputdev.name = itmtouch->name;
186 itmtouch->inputdev.phys = itmtouch->phys;
187 itmtouch->inputdev.id.bustype = BUS_USB;
188 itmtouch->inputdev.id.vendor = udev->descriptor.idVendor;
189 itmtouch->inputdev.id.product = udev->descriptor.idProduct;
190 itmtouch->inputdev.id.version = udev->descriptor.bcdDevice;
191 itmtouch->inputdev.dev = &intf->dev;
192
193 if (!strlen(itmtouch->name))
194 sprintf(itmtouch->name, "USB ITM touchscreen");
195
196 /* device limits */
197 /* as specified by the ITM datasheet, X and Y are 12bit,
198 * Z (pressure) is 8 bit. However, the fields are defined up
199 * to 14 bits for future possible expansion.
200 */
201 input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0);
202 input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0);
203 input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0);
204
205 /* initialise the URB so we can read from the transport stream */
206 pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress);
207 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
208
209 if (maxp > ITM_BUFSIZE)
210 maxp = ITM_BUFSIZE;
211
212 itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL);
213
214 if (!itmtouch->readurb) {
215 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__);
216 kfree(itmtouch);
217 return -ENOMEM;
218 }
219
220 usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf,
221 maxp, itmtouch_irq, itmtouch, endpoint->bInterval);
222
223 input_register_device(&itmtouch->inputdev);
224
225 printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path);
226 usb_set_intfdata(intf, itmtouch);
227
228 return 0;
229}
230
231static void itmtouch_disconnect(struct usb_interface *intf)
232{
233 struct itmtouch_dev *itmtouch = usb_get_intfdata(intf);
234
235 usb_set_intfdata(intf, NULL);
236
237 if (itmtouch) {
238 input_unregister_device(&itmtouch->inputdev);
239 usb_kill_urb(itmtouch->readurb);
240 usb_free_urb(itmtouch->readurb);
241 kfree(itmtouch);
242 }
243}
244
245MODULE_DEVICE_TABLE(usb, itmtouch_ids);
246
247static struct usb_driver itmtouch_driver = {
248 .owner = THIS_MODULE,
249 .name = "itmtouch",
250 .probe = itmtouch_probe,
251 .disconnect = itmtouch_disconnect,
252 .id_table = itmtouch_ids,
253};
254
255static int __init itmtouch_init(void)
256{
257 info(DRIVER_DESC " " DRIVER_VERSION);
258 info(DRIVER_AUTHOR);
259 return usb_register(&itmtouch_driver);
260}
261
262static void __exit itmtouch_exit(void)
263{
264 usb_deregister(&itmtouch_driver);
265}
266
267module_init(itmtouch_init);
268module_exit(itmtouch_exit);
diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c
index a68c5b4e7b37..d2f0f90a9bcd 100644
--- a/drivers/usb/input/kbtab.c
+++ b/drivers/usb/input/kbtab.c
@@ -36,7 +36,6 @@ struct kbtab {
36 struct input_dev dev; 36 struct input_dev dev;
37 struct usb_device *usbdev; 37 struct usb_device *usbdev;
38 struct urb *irq; 38 struct urb *irq;
39 int open;
40 int x, y; 39 int x, y;
41 int button; 40 int button;
42 int pressure; 41 int pressure;
@@ -79,12 +78,12 @@ static void kbtab_irq(struct urb *urb, struct pt_regs *regs)
79 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/ 78 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
80 input_report_key(dev, BTN_RIGHT, data[0] & 0x02); 79 input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
81 80
82 if( -1 == kb_pressure_click){ 81 if (-1 == kb_pressure_click) {
83 input_report_abs(dev, ABS_PRESSURE, kbtab->pressure); 82 input_report_abs(dev, ABS_PRESSURE, kbtab->pressure);
84 } else { 83 } else {
85 input_report_key(dev, BTN_LEFT, (kbtab->pressure > kb_pressure_click) ? 1 : 0); 84 input_report_key(dev, BTN_LEFT, (kbtab->pressure > kb_pressure_click) ? 1 : 0);
86 }; 85 };
87 86
88 input_sync(dev); 87 input_sync(dev);
89 88
90 exit: 89 exit:
@@ -105,14 +104,9 @@ static int kbtab_open(struct input_dev *dev)
105{ 104{
106 struct kbtab *kbtab = dev->private; 105 struct kbtab *kbtab = dev->private;
107 106
108 if (kbtab->open++)
109 return 0;
110
111 kbtab->irq->dev = kbtab->usbdev; 107 kbtab->irq->dev = kbtab->usbdev;
112 if (usb_submit_urb(kbtab->irq, GFP_KERNEL)) { 108 if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
113 kbtab->open--;
114 return -EIO; 109 return -EIO;
115 }
116 110
117 return 0; 111 return 0;
118} 112}
@@ -121,8 +115,7 @@ static void kbtab_close(struct input_dev *dev)
121{ 115{
122 struct kbtab *kbtab = dev->private; 116 struct kbtab *kbtab = dev->private;
123 117
124 if (!--kbtab->open) 118 usb_kill_urb(kbtab->irq);
125 usb_kill_urb(kbtab->irq);
126} 119}
127 120
128static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id) 121static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -161,7 +154,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
161 kbtab->dev.absmax[ABS_X] = 0x2000; 154 kbtab->dev.absmax[ABS_X] = 0x2000;
162 kbtab->dev.absmax[ABS_Y] = 0x1750; 155 kbtab->dev.absmax[ABS_Y] = 0x1750;
163 kbtab->dev.absmax[ABS_PRESSURE] = 0xff; 156 kbtab->dev.absmax[ABS_PRESSURE] = 0xff;
164 157
165 kbtab->dev.absfuzz[ABS_X] = 4; 158 kbtab->dev.absfuzz[ABS_X] = 4;
166 kbtab->dev.absfuzz[ABS_Y] = 4; 159 kbtab->dev.absfuzz[ABS_Y] = 4;
167 160
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
new file mode 100644
index 000000000000..67dc93685203
--- /dev/null
+++ b/drivers/usb/input/keyspan_remote.c
@@ -0,0 +1,633 @@
1/*
2 * keyspan_remote: USB driver for the Keyspan DMR
3 *
4 * Copyright (C) 2005 Zymeta Corporation - Michael Downey (downey@zymeta.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 * This driver has been put together with the support of Innosys, Inc.
11 * and Keyspan, Inc the manufacturers of the Keyspan USB DMR product.
12 */
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/input.h>
22#include <linux/usb.h>
23
24#define DRIVER_VERSION "v0.1"
25#define DRIVER_AUTHOR "Michael Downey <downey@zymeta.com>"
26#define DRIVER_DESC "Driver for the USB Keyspan remote control."
27#define DRIVER_LICENSE "GPL"
28
29/* Parameters that can be passed to the driver. */
30static int debug;
31module_param(debug, int, 0444);
32MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
33
34/* Vendor and product ids */
35#define USB_KEYSPAN_VENDOR_ID 0x06CD
36#define USB_KEYSPAN_PRODUCT_UIA11 0x0202
37
38/* Defines for converting the data from the remote. */
39#define ZERO 0x18
40#define ZERO_MASK 0x1F /* 5 bits for a 0 */
41#define ONE 0x3C
42#define ONE_MASK 0x3F /* 6 bits for a 1 */
43#define SYNC 0x3F80
44#define SYNC_MASK 0x3FFF /* 14 bits for a SYNC sequence */
45#define STOP 0x00
46#define STOP_MASK 0x1F /* 5 bits for the STOP sequence */
47#define GAP 0xFF
48
49#define RECV_SIZE 8 /* The UIA-11 type have a 8 byte limit. */
50
51/* table of devices that work with this driver */
52static struct usb_device_id keyspan_table[] = {
53 { USB_DEVICE(USB_KEYSPAN_VENDOR_ID, USB_KEYSPAN_PRODUCT_UIA11) },
54 { } /* Terminating entry */
55};
56
57/* Structure to store all the real stuff that a remote sends to us. */
58struct keyspan_message {
59 u16 system;
60 u8 button;
61 u8 toggle;
62};
63
64/* Structure used for all the bit testing magic needed to be done. */
65struct bit_tester {
66 u32 tester;
67 int len;
68 int pos;
69 int bits_left;
70 u8 buffer[32];
71};
72
73/* Structure to hold all of our driver specific stuff */
74struct usb_keyspan {
75 char name[128];
76 char phys[64];
77 struct usb_device* udev;
78 struct input_dev input;
79 struct usb_interface* interface;
80 struct usb_endpoint_descriptor* in_endpoint;
81 struct urb* irq_urb;
82 int open;
83 dma_addr_t in_dma;
84 unsigned char* in_buffer;
85
86 /* variables used to parse messages from remote. */
87 struct bit_tester data;
88 int stage;
89 int toggle;
90};
91
92/*
93 * Table that maps the 31 possible keycodes to input keys.
94 * Currently there are 15 and 17 button models so RESERVED codes
95 * are blank areas in the mapping.
96 */
97static int keyspan_key_table[] = {
98 KEY_RESERVED, /* 0 is just a place holder. */
99 KEY_RESERVED,
100 KEY_STOP,
101 KEY_PLAYCD,
102 KEY_RESERVED,
103 KEY_PREVIOUSSONG,
104 KEY_REWIND,
105 KEY_FORWARD,
106 KEY_NEXTSONG,
107 KEY_RESERVED,
108 KEY_RESERVED,
109 KEY_RESERVED,
110 KEY_PAUSE,
111 KEY_VOLUMEUP,
112 KEY_RESERVED,
113 KEY_RESERVED,
114 KEY_RESERVED,
115 KEY_VOLUMEDOWN,
116 KEY_RESERVED,
117 KEY_UP,
118 KEY_RESERVED,
119 KEY_MUTE,
120 KEY_LEFT,
121 KEY_ENTER,
122 KEY_RIGHT,
123 KEY_RESERVED,
124 KEY_RESERVED,
125 KEY_DOWN,
126 KEY_RESERVED,
127 KEY_KPASTERISK,
128 KEY_RESERVED,
129 KEY_MENU
130};
131
132static struct usb_driver keyspan_driver;
133
134/*
135 * Debug routine that prints out what we've received from the remote.
136 */
137static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/
138{
139 char codes[4*RECV_SIZE];
140 int i;
141
142 for (i = 0; i < RECV_SIZE; i++) {
143 snprintf(codes+i*3, 4, "%02x ", dev->in_buffer[i]);
144 }
145
146 dev_info(&dev->udev->dev, "%s\n", codes);
147}
148
149/*
150 * Routine that manages the bit_tester structure. It makes sure that there are
151 * at least bits_needed bits loaded into the tester.
152 */
153static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
154{
155 if (dev->data.bits_left >= bits_needed)
156 return(0);
157
158 /*
159 * Somehow we've missed the last message. The message will be repeated
160 * though so it's not too big a deal
161 */
162 if (dev->data.pos >= dev->data.len) {
163 dev_dbg(&dev->udev, "%s - Error ran out of data. pos: %d, len: %d\n",
164 __FUNCTION__, dev->data.pos, dev->data.len);
165 return(-1);
166 }
167
168 /* Load as much as we can into the tester. */
169 while ((dev->data.bits_left + 7 < (sizeof(dev->data.tester) * 8)) &&
170 (dev->data.pos < dev->data.len)) {
171 dev->data.tester += (dev->data.buffer[dev->data.pos++] << dev->data.bits_left);
172 dev->data.bits_left += 8;
173 }
174
175 return(0);
176}
177
178/*
179 * Routine that handles all the logic needed to parse out the message from the remote.
180 */
181static void keyspan_check_data(struct usb_keyspan *remote, struct pt_regs *regs)
182{
183 int i;
184 int found = 0;
185 struct keyspan_message message;
186
187 switch(remote->stage) {
188 case 0:
189 /*
190 * In stage 0 we want to find the start of a message. The remote sends a 0xFF as filler.
191 * So the first byte that isn't a FF should be the start of a new message.
192 */
193 for (i = 0; i < RECV_SIZE && remote->in_buffer[i] == GAP; ++i);
194
195 if (i < RECV_SIZE) {
196 memcpy(remote->data.buffer, remote->in_buffer, RECV_SIZE);
197 remote->data.len = RECV_SIZE;
198 remote->data.pos = 0;
199 remote->data.tester = 0;
200 remote->data.bits_left = 0;
201 remote->stage = 1;
202 }
203 break;
204
205 case 1:
206 /*
207 * Stage 1 we should have 16 bytes and should be able to detect a
208 * SYNC. The SYNC is 14 bits, 7 0's and then 7 1's.
209 */
210 memcpy(remote->data.buffer + remote->data.len, remote->in_buffer, RECV_SIZE);
211 remote->data.len += RECV_SIZE;
212
213 found = 0;
214 while ((remote->data.bits_left >= 14 || remote->data.pos < remote->data.len) && !found) {
215 for (i = 0; i < 8; ++i) {
216 if (keyspan_load_tester(remote, 14) != 0) {
217 remote->stage = 0;
218 return;
219 }
220
221 if ((remote->data.tester & SYNC_MASK) == SYNC) {
222 remote->data.tester = remote->data.tester >> 14;
223 remote->data.bits_left -= 14;
224 found = 1;
225 break;
226 } else {
227 remote->data.tester = remote->data.tester >> 1;
228 --remote->data.bits_left;
229 }
230 }
231 }
232
233 if (!found) {
234 remote->stage = 0;
235 remote->data.len = 0;
236 } else {
237 remote->stage = 2;
238 }
239 break;
240
241 case 2:
242 /*
243 * Stage 2 we should have 24 bytes which will be enough for a full
244 * message. We need to parse out the system code, button code,
245 * toggle code, and stop.
246 */
247 memcpy(remote->data.buffer + remote->data.len, remote->in_buffer, RECV_SIZE);
248 remote->data.len += RECV_SIZE;
249
250 message.system = 0;
251 for (i = 0; i < 9; i++) {
252 keyspan_load_tester(remote, 6);
253
254 if ((remote->data.tester & ZERO_MASK) == ZERO) {
255 message.system = message.system << 1;
256 remote->data.tester = remote->data.tester >> 5;
257 remote->data.bits_left -= 5;
258 } else if ((remote->data.tester & ONE_MASK) == ONE) {
259 message.system = (message.system << 1) + 1;
260 remote->data.tester = remote->data.tester >> 6;
261 remote->data.bits_left -= 6;
262 } else {
263 err("%s - Unknown sequence found in system data.\n", __FUNCTION__);
264 remote->stage = 0;
265 return;
266 }
267 }
268
269 message.button = 0;
270 for (i = 0; i < 5; i++) {
271 keyspan_load_tester(remote, 6);
272
273 if ((remote->data.tester & ZERO_MASK) == ZERO) {
274 message.button = message.button << 1;
275 remote->data.tester = remote->data.tester >> 5;
276 remote->data.bits_left -= 5;
277 } else if ((remote->data.tester & ONE_MASK) == ONE) {
278 message.button = (message.button << 1) + 1;
279 remote->data.tester = remote->data.tester >> 6;
280 remote->data.bits_left -= 6;
281 } else {
282 err("%s - Unknown sequence found in button data.\n", __FUNCTION__);
283 remote->stage = 0;
284 return;
285 }
286 }
287
288 keyspan_load_tester(remote, 6);
289 if ((remote->data.tester & ZERO_MASK) == ZERO) {
290 message.toggle = 0;
291 remote->data.tester = remote->data.tester >> 5;
292 remote->data.bits_left -= 5;
293 } else if ((remote->data.tester & ONE_MASK) == ONE) {
294 message.toggle = 1;
295 remote->data.tester = remote->data.tester >> 6;
296 remote->data.bits_left -= 6;
297 } else {
298 err("%s - Error in message, invalid toggle.\n", __FUNCTION__);
299 }
300
301 keyspan_load_tester(remote, 5);
302 if ((remote->data.tester & STOP_MASK) == STOP) {
303 remote->data.tester = remote->data.tester >> 5;
304 remote->data.bits_left -= 5;
305 } else {
306 err("Bad message recieved, no stop bit found.\n");
307 }
308
309 dev_dbg(&remote->udev,
310 "%s found valid message: system: %d, button: %d, toggle: %d\n",
311 __FUNCTION__, message.system, message.button, message.toggle);
312
313 if (message.toggle != remote->toggle) {
314 input_regs(&remote->input, regs);
315 input_report_key(&remote->input, keyspan_key_table[message.button], 1);
316 input_report_key(&remote->input, keyspan_key_table[message.button], 0);
317 input_sync(&remote->input);
318 remote->toggle = message.toggle;
319 }
320
321 remote->stage = 0;
322 break;
323 }
324}
325
326/*
327 * Routine for sending all the initialization messages to the remote.
328 */
329static int keyspan_setup(struct usb_device* dev)
330{
331 int retval = 0;
332
333 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
334 0x11, 0x40, 0x5601, 0x0, NULL, 0, 0);
335 if (retval) {
336 dev_dbg(&dev->dev, "%s - failed to set bit rate due to error: %d\n",
337 __FUNCTION__, retval);
338 return(retval);
339 }
340
341 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
342 0x44, 0x40, 0x0, 0x0, NULL, 0, 0);
343 if (retval) {
344 dev_dbg(&dev->dev, "%s - failed to set resume sensitivity due to error: %d\n",
345 __FUNCTION__, retval);
346 return(retval);
347 }
348
349 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
350 0x22, 0x40, 0x0, 0x0, NULL, 0, 0);
351 if (retval) {
352 dev_dbg(&dev->dev, "%s - failed to turn receive on due to error: %d\n",
353 __FUNCTION__, retval);
354 return(retval);
355 }
356
357 dev_dbg(&dev->dev, "%s - Setup complete.\n", __FUNCTION__);
358 return(retval);
359}
360
361/*
362 * Routine used to handle a new message that has come in.
363 */
364static void keyspan_irq_recv(struct urb *urb, struct pt_regs *regs)
365{
366 struct usb_keyspan *dev = urb->context;
367 int retval;
368
369 /* Check our status in case we need to bail out early. */
370 switch (urb->status) {
371 case 0:
372 break;
373
374 /* Device went away so don't keep trying to read from it. */
375 case -ECONNRESET:
376 case -ENOENT:
377 case -ESHUTDOWN:
378 return;
379
380 default:
381 goto resubmit;
382 break;
383 }
384
385 if (debug)
386 keyspan_print(dev);
387
388 keyspan_check_data(dev, regs);
389
390resubmit:
391 retval = usb_submit_urb(urb, GFP_ATOMIC);
392 if (retval)
393 err ("%s - usb_submit_urb failed with result: %d", __FUNCTION__, retval);
394}
395
396static int keyspan_open(struct input_dev *dev)
397{
398 struct usb_keyspan *remote = dev->private;
399
400 if (remote->open++)
401 return 0;
402
403 remote->irq_urb->dev = remote->udev;
404 if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) {
405 remote->open--;
406 return -EIO;
407 }
408
409 return 0;
410}
411
412static void keyspan_close(struct input_dev *dev)
413{
414 struct usb_keyspan *remote = dev->private;
415
416 if (!--remote->open)
417 usb_kill_urb(remote->irq_urb);
418}
419
420/*
421 * Routine that sets up the driver to handle a specific USB device detected on the bus.
422 */
423static int keyspan_probe(struct usb_interface *interface, const struct usb_device_id *id)
424{
425 int i;
426 int retval = -ENOMEM;
427 char path[64];
428 char *buf;
429 struct usb_keyspan *remote = NULL;
430 struct usb_host_interface *iface_desc;
431 struct usb_endpoint_descriptor *endpoint;
432 struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface));
433
434 /* See if the offered device matches what we can accept */
435 if ((udev->descriptor.idVendor != USB_KEYSPAN_VENDOR_ID) ||
436 (udev->descriptor.idProduct != USB_KEYSPAN_PRODUCT_UIA11) )
437 return -ENODEV;
438
439 /* allocate memory for our device state and initialize it */
440 remote = kmalloc(sizeof(*remote), GFP_KERNEL);
441 if (remote == NULL) {
442 err("Out of memory\n");
443 goto error;
444 }
445 memset(remote, 0x00, sizeof(*remote));
446
447 remote->udev = udev;
448 remote->interface = interface;
449 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */
450
451 /* set up the endpoint information */
452 /* use only the first in interrupt endpoint */
453 iface_desc = interface->cur_altsetting;
454 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
455 endpoint = &iface_desc->endpoint[i].desc;
456
457 if (!remote->in_endpoint &&
458 (endpoint->bEndpointAddress & USB_DIR_IN) &&
459 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
460 /* we found our interrupt in endpoint */
461 remote->in_endpoint = endpoint;
462
463 remote->in_buffer = usb_buffer_alloc(remote->udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma);
464 if (!remote->in_buffer) {
465 retval = -ENOMEM;
466 goto error;
467 }
468 }
469 }
470
471 if (!remote->in_endpoint) {
472 err("Could not find interrupt input endpoint.\n");
473 retval = -ENODEV;
474 goto error;
475 }
476
477 remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
478 if (!remote->irq_urb) {
479 err("Failed to allocate urb.\n");
480 retval = -ENOMEM;
481 goto error;
482 }
483
484 retval = keyspan_setup(remote->udev);
485 if (retval) {
486 err("Failed to setup device.\n");
487 retval = -ENODEV;
488 goto error;
489 }
490
491 /*
492 * Setup the input system with the bits we are going to be reporting
493 */
494 remote->input.evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */
495 for (i = 0; i < 32; ++i) {
496 if (keyspan_key_table[i] != KEY_RESERVED) {
497 set_bit(keyspan_key_table[i], remote->input.keybit);
498 }
499 }
500
501 remote->input.private = remote;
502 remote->input.open = keyspan_open;
503 remote->input.close = keyspan_close;
504
505 usb_make_path(remote->udev, path, 64);
506 sprintf(remote->phys, "%s/input0", path);
507
508 remote->input.name = remote->name;
509 remote->input.phys = remote->phys;
510 remote->input.id.bustype = BUS_USB;
511 remote->input.id.vendor = le16_to_cpu(remote->udev->descriptor.idVendor);
512 remote->input.id.product = le16_to_cpu(remote->udev->descriptor.idProduct);
513 remote->input.id.version = le16_to_cpu(remote->udev->descriptor.bcdDevice);
514
515 if (!(buf = kmalloc(63, GFP_KERNEL))) {
516 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
517 kfree(remote);
518 return -ENOMEM;
519 }
520
521 if (remote->udev->descriptor.iManufacturer &&
522 usb_string(remote->udev, remote->udev->descriptor.iManufacturer, buf, 63) > 0)
523 strcat(remote->name, buf);
524
525 if (remote->udev->descriptor.iProduct &&
526 usb_string(remote->udev, remote->udev->descriptor.iProduct, buf, 63) > 0)
527 sprintf(remote->name, "%s %s", remote->name, buf);
528
529 if (!strlen(remote->name))
530 sprintf(remote->name, "USB Keyspan Remote %04x:%04x",
531 remote->input.id.vendor, remote->input.id.product);
532
533 kfree(buf);
534
535 /*
536 * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open()
537 */
538 usb_fill_int_urb(remote->irq_urb,
539 remote->udev, usb_rcvintpipe(remote->udev, remote->in_endpoint->bEndpointAddress),
540 remote->in_buffer, RECV_SIZE, keyspan_irq_recv, remote,
541 remote->in_endpoint->bInterval);
542 remote->irq_urb->transfer_dma = remote->in_dma;
543 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
544
545 /* we can register the device now, as it is ready */
546 input_register_device(&remote->input);
547
548 /* save our data pointer in this interface device */
549 usb_set_intfdata(interface, remote);
550
551 /* let the user know what node this device is now attached to */
552 info("connected: %s on %s", remote->name, path);
553 return 0;
554
555error:
556 /*
557 * In case of error we need to clean up any allocated buffers
558 */
559 if (remote->irq_urb)
560 usb_free_urb(remote->irq_urb);
561
562 if (remote->in_buffer)
563 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
564
565 if (remote)
566 kfree(remote);
567
568 return retval;
569}
570
571/*
572 * Routine called when a device is disconnected from the USB.
573 */
574static void keyspan_disconnect(struct usb_interface *interface)
575{
576 struct usb_keyspan *remote;
577
578 /* prevent keyspan_open() from racing keyspan_disconnect() */
579 lock_kernel();
580
581 remote = usb_get_intfdata(interface);
582 usb_set_intfdata(interface, NULL);
583
584 if (remote) { /* We have a valid driver structure so clean up everything we allocated. */
585 input_unregister_device(&remote->input);
586 usb_kill_urb(remote->irq_urb);
587 usb_free_urb(remote->irq_urb);
588 usb_buffer_free(interface_to_usbdev(interface), RECV_SIZE, remote->in_buffer, remote->in_dma);
589 kfree(remote);
590 }
591
592 unlock_kernel();
593
594 info("USB Keyspan now disconnected");
595}
596
597/*
598 * Standard driver set up sections
599 */
600static struct usb_driver keyspan_driver =
601{
602 .owner = THIS_MODULE,
603 .name = "keyspan_remote",
604 .probe = keyspan_probe,
605 .disconnect = keyspan_disconnect,
606 .id_table = keyspan_table
607};
608
609static int __init usb_keyspan_init(void)
610{
611 int result;
612
613 /* register this driver with the USB subsystem */
614 result = usb_register(&keyspan_driver);
615 if (result)
616 err("usb_register failed. Error number %d\n", result);
617
618 return result;
619}
620
621static void __exit usb_keyspan_exit(void)
622{
623 /* deregister this driver with the USB subsystem */
624 usb_deregister(&keyspan_driver);
625}
626
627module_init(usb_keyspan_init);
628module_exit(usb_keyspan_exit);
629
630MODULE_DEVICE_TABLE(usb, keyspan_table);
631MODULE_AUTHOR(DRIVER_AUTHOR);
632MODULE_DESCRIPTION(DRIVER_DESC);
633MODULE_LICENSE(DRIVER_LICENSE);
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index ab1a2a30ce7c..09b5cc7c66de 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -42,9 +42,9 @@
42#include <linux/config.h> 42#include <linux/config.h>
43 43
44#ifdef CONFIG_USB_DEBUG 44#ifdef CONFIG_USB_DEBUG
45 #define DEBUG 45 #define DEBUG
46#else 46#else
47 #undef DEBUG 47 #undef DEBUG
48#endif 48#endif
49 49
50#include <linux/kernel.h> 50#include <linux/kernel.h>
@@ -93,275 +93,255 @@ module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)"); 93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)");
94 94
95struct mtouch_usb { 95struct mtouch_usb {
96 unsigned char *data; 96 unsigned char *data;
97 dma_addr_t data_dma; 97 dma_addr_t data_dma;
98 struct urb *irq; 98 struct urb *irq;
99 struct usb_device *udev; 99 struct usb_device *udev;
100 struct input_dev input; 100 struct input_dev input;
101 int open; 101 char name[128];
102 char name[128]; 102 char phys[64];
103 char phys[64];
104}; 103};
105 104
106static struct usb_device_id mtouchusb_devices [] = { 105static struct usb_device_id mtouchusb_devices[] = {
107 { USB_DEVICE(0x0596, 0x0001) }, 106 { USB_DEVICE(0x0596, 0x0001) },
108 { } 107 { }
109}; 108};
110 109
111static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs) 110static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
112{ 111{
113 struct mtouch_usb *mtouch = urb->context; 112 struct mtouch_usb *mtouch = urb->context;
114 int retval; 113 int retval;
115 114
116 switch (urb->status) { 115 switch (urb->status) {
117 case 0: 116 case 0:
118 /* success */ 117 /* success */
119 break; 118 break;
120 case -ETIMEDOUT: 119 case -ETIMEDOUT:
121 /* this urb is timing out */ 120 /* this urb is timing out */
122 dbg("%s - urb timed out - was the device unplugged?", 121 dbg("%s - urb timed out - was the device unplugged?",
123 __FUNCTION__); 122 __FUNCTION__);
124 return; 123 return;
125 case -ECONNRESET: 124 case -ECONNRESET:
126 case -ENOENT: 125 case -ENOENT:
127 case -ESHUTDOWN: 126 case -ESHUTDOWN:
128 /* this urb is terminated, clean up */ 127 /* this urb is terminated, clean up */
129 dbg("%s - urb shutting down with status: %d", 128 dbg("%s - urb shutting down with status: %d",
130 __FUNCTION__, urb->status); 129 __FUNCTION__, urb->status);
131 return; 130 return;
132 default: 131 default:
133 dbg("%s - nonzero urb status received: %d", 132 dbg("%s - nonzero urb status received: %d",
134 __FUNCTION__, urb->status); 133 __FUNCTION__, urb->status);
135 goto exit; 134 goto exit;
136 } 135 }
137 136
138 input_regs(&mtouch->input, regs); 137 input_regs(&mtouch->input, regs);
139 input_report_key(&mtouch->input, BTN_TOUCH, 138 input_report_key(&mtouch->input, BTN_TOUCH,
140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 139 MTOUCHUSB_GET_TOUCHED(mtouch->data));
141 input_report_abs(&mtouch->input, ABS_X, 140 input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
142 MTOUCHUSB_GET_XC(mtouch->data)); 141 input_report_abs(&mtouch->input, ABS_Y,
143 input_report_abs(&mtouch->input, ABS_Y,
144 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 142 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
145 - MTOUCHUSB_GET_YC(mtouch->data)); 143 - MTOUCHUSB_GET_YC(mtouch->data));
146 input_sync(&mtouch->input); 144 input_sync(&mtouch->input);
147 145
148exit: 146exit:
149 retval = usb_submit_urb (urb, GFP_ATOMIC); 147 retval = usb_submit_urb(urb, GFP_ATOMIC);
150 if (retval) 148 if (retval)
151 err ("%s - usb_submit_urb failed with result: %d", 149 err("%s - usb_submit_urb failed with result: %d",
152 __FUNCTION__, retval); 150 __FUNCTION__, retval);
153} 151}
154 152
155static int mtouchusb_open (struct input_dev *input) 153static int mtouchusb_open(struct input_dev *input)
156{ 154{
157 struct mtouch_usb *mtouch = input->private; 155 struct mtouch_usb *mtouch = input->private;
158 156
159 if (mtouch->open++) 157 mtouch->irq->dev = mtouch->udev;
160 return 0;
161 158
162 mtouch->irq->dev = mtouch->udev; 159 if (usb_submit_urb(mtouch->irq, GFP_ATOMIC))
160 return -EIO;
163 161
164 if (usb_submit_urb (mtouch->irq, GFP_ATOMIC)) { 162 return 0;
165 mtouch->open--;
166 return -EIO;
167 }
168
169 return 0;
170} 163}
171 164
172static void mtouchusb_close (struct input_dev *input) 165static void mtouchusb_close(struct input_dev *input)
173{ 166{
174 struct mtouch_usb *mtouch = input->private; 167 struct mtouch_usb *mtouch = input->private;
175 168
176 if (!--mtouch->open) 169 usb_kill_urb(mtouch->irq);
177 usb_kill_urb (mtouch->irq);
178} 170}
179 171
180static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 172static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
181{ 173{
182 dbg("%s - called", __FUNCTION__); 174 dbg("%s - called", __FUNCTION__);
183 175
184 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE, 176 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE,
185 SLAB_ATOMIC, &mtouch->data_dma); 177 SLAB_ATOMIC, &mtouch->data_dma);
186 178
187 if (!mtouch->data) 179 if (!mtouch->data)
188 return -1; 180 return -1;
189 181
190 return 0; 182 return 0;
191} 183}
192 184
193static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 185static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
194{ 186{
195 dbg("%s - called", __FUNCTION__); 187 dbg("%s - called", __FUNCTION__);
196 188
197 if (mtouch->data) 189 if (mtouch->data)
198 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE, 190 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE,
199 mtouch->data, mtouch->data_dma); 191 mtouch->data, mtouch->data_dma);
200} 192}
201 193
202static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 194static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
203{ 195{
204 struct mtouch_usb *mtouch; 196 struct mtouch_usb *mtouch;
205 struct usb_host_interface *interface; 197 struct usb_host_interface *interface;
206 struct usb_endpoint_descriptor *endpoint; 198 struct usb_endpoint_descriptor *endpoint;
207 struct usb_device *udev = interface_to_usbdev (intf); 199 struct usb_device *udev = interface_to_usbdev(intf);
208 char path[64]; 200 char path[64];
209 int nRet; 201 int nRet;
210 202
211 dbg("%s - called", __FUNCTION__); 203 dbg("%s - called", __FUNCTION__);
212 204
213 dbg("%s - setting interface", __FUNCTION__); 205 dbg("%s - setting interface", __FUNCTION__);
214 interface = intf->cur_altsetting; 206 interface = intf->cur_altsetting;
215 207
216 dbg("%s - setting endpoint", __FUNCTION__); 208 dbg("%s - setting endpoint", __FUNCTION__);
217 endpoint = &interface->endpoint[0].desc; 209 endpoint = &interface->endpoint[0].desc;
218 210
219 if (!(mtouch = kmalloc (sizeof (struct mtouch_usb), GFP_KERNEL))) { 211 if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) {
220 err("%s - Out of memory.", __FUNCTION__); 212 err("%s - Out of memory.", __FUNCTION__);
221 return -ENOMEM; 213 return -ENOMEM;
222 } 214 }
223 215
224 memset(mtouch, 0, sizeof(struct mtouch_usb)); 216 memset(mtouch, 0, sizeof(struct mtouch_usb));
225 mtouch->udev = udev; 217 mtouch->udev = udev;
226 218
227 dbg("%s - allocating buffers", __FUNCTION__); 219 dbg("%s - allocating buffers", __FUNCTION__);
228 if (mtouchusb_alloc_buffers(udev, mtouch)) { 220 if (mtouchusb_alloc_buffers(udev, mtouch)) {
229 mtouchusb_free_buffers(udev, mtouch); 221 mtouchusb_free_buffers(udev, mtouch);
230 kfree(mtouch); 222 kfree(mtouch);
231 return -ENOMEM; 223 return -ENOMEM;
232 } 224 }
233 225
234 mtouch->input.private = mtouch; 226 mtouch->input.private = mtouch;
235 mtouch->input.open = mtouchusb_open; 227 mtouch->input.open = mtouchusb_open;
236 mtouch->input.close = mtouchusb_close; 228 mtouch->input.close = mtouchusb_close;
237 229
238 usb_make_path(udev, path, 64); 230 usb_make_path(udev, path, 64);
239 sprintf(mtouch->phys, "%s/input0", path); 231 sprintf(mtouch->phys, "%s/input0", path);
240 232
241 mtouch->input.name = mtouch->name; 233 mtouch->input.name = mtouch->name;
242 mtouch->input.phys = mtouch->phys; 234 mtouch->input.phys = mtouch->phys;
243 mtouch->input.id.bustype = BUS_USB; 235 mtouch->input.id.bustype = BUS_USB;
244 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 236 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
245 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct); 237 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
246 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 238 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
247 mtouch->input.dev = &intf->dev; 239 mtouch->input.dev = &intf->dev;
248 240
249 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 241 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
250 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 242 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
251 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 243 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
252 244
253 /* Used to Scale Compensated Data and Flip Y */ 245 /* Used to Scale Compensated Data and Flip Y */
254 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC; 246 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC;
255 mtouch->input.absmax[ABS_X] = raw_coordinates ? \ 247 mtouch->input.absmax[ABS_X] = raw_coordinates ?
256 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC; 248 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC;
257 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ; 249 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ;
258 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT; 250 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT;
259 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC; 251 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC;
260 mtouch->input.absmax[ABS_Y] = raw_coordinates ? \ 252 mtouch->input.absmax[ABS_Y] = raw_coordinates ?
261 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC; 253 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC;
262 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ; 254 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ;
263 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT; 255 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT;
264 256
265 if (udev->manufacturer) 257 if (udev->manufacturer)
266 strcat(mtouch->name, udev->manufacturer); 258 strcat(mtouch->name, udev->manufacturer);
267 if (udev->product) 259 if (udev->product)
268 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 260 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product);
269 261
270 if (!strlen(mtouch->name)) 262 if (!strlen(mtouch->name))
271 sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 263 sprintf(mtouch->name, "USB Touchscreen %04x:%04x",
272 mtouch->input.id.vendor, mtouch->input.id.product); 264 mtouch->input.id.vendor, mtouch->input.id.product);
273 265
274 nRet = usb_control_msg(mtouch->udev, 266 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
275 usb_rcvctrlpipe(udev, 0), 267 MTOUCHUSB_RESET,
276 MTOUCHUSB_RESET, 268 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
277 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 269 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
278 1, 270 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
279 0, 271 __FUNCTION__, nRet);
280 NULL, 272
281 0, 273 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__);
282 USB_CTRL_SET_TIMEOUT); 274 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
283 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", 275 if (!mtouch->irq) {
284 __FUNCTION__, nRet); 276 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
285 277 mtouchusb_free_buffers(udev, mtouch);
286 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__); 278 kfree(mtouch);
287 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 279 return -ENOMEM;
288 if (!mtouch->irq) { 280 }
289 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 281
290 mtouchusb_free_buffers(udev, mtouch); 282 dbg("%s - usb_fill_int_urb", __FUNCTION__);
291 kfree(mtouch); 283 usb_fill_int_urb(mtouch->irq, mtouch->udev,
292 return -ENOMEM; 284 usb_rcvintpipe(mtouch->udev, 0x81),
293 } 285 mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE,
294 286 mtouchusb_irq, mtouch, endpoint->bInterval);
295 dbg("%s - usb_fill_int_urb", __FUNCTION__); 287
296 usb_fill_int_urb(mtouch->irq, 288 dbg("%s - input_register_device", __FUNCTION__);
297 mtouch->udev, 289 input_register_device(&mtouch->input);
298 usb_rcvintpipe(mtouch->udev, 0x81), 290
299 mtouch->data, 291 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
300 MTOUCHUSB_REPORT_DATA_SIZE, 292 MTOUCHUSB_ASYNC_REPORT,
301 mtouchusb_irq, 293 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
302 mtouch, 294 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
303 endpoint->bInterval); 295 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
304 296 __FUNCTION__, nRet);
305 dbg("%s - input_register_device", __FUNCTION__); 297
306 input_register_device(&mtouch->input); 298 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
307 299 usb_set_intfdata(intf, mtouch);
308 nRet = usb_control_msg(mtouch->udev, 300
309 usb_rcvctrlpipe(udev, 0), 301 return 0;
310 MTOUCHUSB_ASYNC_REPORT,
311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
312 1,
313 1,
314 NULL,
315 0,
316 USB_CTRL_SET_TIMEOUT);
317 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
318 __FUNCTION__, nRet);
319
320 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
321 usb_set_intfdata(intf, mtouch);
322
323 return 0;
324} 302}
325 303
326static void mtouchusb_disconnect(struct usb_interface *intf) 304static void mtouchusb_disconnect(struct usb_interface *intf)
327{ 305{
328 struct mtouch_usb *mtouch = usb_get_intfdata (intf); 306 struct mtouch_usb *mtouch = usb_get_intfdata(intf);
329 307
330 dbg("%s - called", __FUNCTION__); 308 dbg("%s - called", __FUNCTION__);
331 usb_set_intfdata(intf, NULL); 309 usb_set_intfdata(intf, NULL);
332 if (mtouch) { 310 if (mtouch) {
333 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 311 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
334 usb_kill_urb(mtouch->irq); 312 usb_kill_urb(mtouch->irq);
335 input_unregister_device(&mtouch->input); 313 input_unregister_device(&mtouch->input);
336 usb_free_urb(mtouch->irq); 314 usb_free_urb(mtouch->irq);
337 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 315 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
338 kfree(mtouch); 316 kfree(mtouch);
339 } 317 }
340} 318}
341 319
342MODULE_DEVICE_TABLE (usb, mtouchusb_devices); 320MODULE_DEVICE_TABLE(usb, mtouchusb_devices);
343 321
344static struct usb_driver mtouchusb_driver = { 322static struct usb_driver mtouchusb_driver = {
345 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
346 .name = "mtouchusb", 324 .name = "mtouchusb",
347 .probe = mtouchusb_probe, 325 .probe = mtouchusb_probe,
348 .disconnect = mtouchusb_disconnect, 326 .disconnect = mtouchusb_disconnect,
349 .id_table = mtouchusb_devices, 327 .id_table = mtouchusb_devices,
350}; 328};
351 329
352static int __init mtouchusb_init(void) { 330static int __init mtouchusb_init(void)
353 dbg("%s - called", __FUNCTION__); 331{
354 return usb_register(&mtouchusb_driver); 332 dbg("%s - called", __FUNCTION__);
333 return usb_register(&mtouchusb_driver);
355} 334}
356 335
357static void __exit mtouchusb_cleanup(void) { 336static void __exit mtouchusb_cleanup(void)
358 dbg("%s - called", __FUNCTION__); 337{
359 usb_deregister(&mtouchusb_driver); 338 dbg("%s - called", __FUNCTION__);
339 usb_deregister(&mtouchusb_driver);
360} 340}
361 341
362module_init(mtouchusb_init); 342module_init(mtouchusb_init);
363module_exit(mtouchusb_cleanup); 343module_exit(mtouchusb_cleanup);
364 344
365MODULE_AUTHOR( DRIVER_AUTHOR ); 345MODULE_AUTHOR(DRIVER_AUTHOR);
366MODULE_DESCRIPTION( DRIVER_DESC ); 346MODULE_DESCRIPTION(DRIVER_DESC);
367MODULE_LICENSE("GPL"); 347MODULE_LICENSE("GPL");
diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c
index 7fa2f9b9fb69..3975b309d55f 100644
--- a/drivers/usb/input/powermate.c
+++ b/drivers/usb/input/powermate.c
@@ -10,7 +10,7 @@
10 * back to the host when polled by the USB controller. 10 * back to the host when polled by the USB controller.
11 * 11 *
12 * Testing with the knob I have has shown that it measures approximately 94 "clicks" 12 * Testing with the knob I have has shown that it measures approximately 94 "clicks"
13 * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was 13 * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was
14 * a variable speed cordless electric drill) has shown that the device can measure 14 * a variable speed cordless electric drill) has shown that the device can measure
15 * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from 15 * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from
16 * the host. If it counts more than 7 clicks before it is polled, it will wrap back 16 * the host. If it counts more than 7 clicks before it is polled, it will wrap back
@@ -120,9 +120,9 @@ exit:
120/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */ 120/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
121static void powermate_sync_state(struct powermate_device *pm) 121static void powermate_sync_state(struct powermate_device *pm)
122{ 122{
123 if (pm->requires_update == 0) 123 if (pm->requires_update == 0)
124 return; /* no updates are required */ 124 return; /* no updates are required */
125 if (pm->config->status == -EINPROGRESS) 125 if (pm->config->status == -EINPROGRESS)
126 return; /* an update is already in progress; it'll issue this update when it completes */ 126 return; /* an update is already in progress; it'll issue this update when it completes */
127 127
128 if (pm->requires_update & UPDATE_PULSE_ASLEEP){ 128 if (pm->requires_update & UPDATE_PULSE_ASLEEP){
@@ -142,7 +142,7 @@ static void powermate_sync_state(struct powermate_device *pm)
142 2: multiply the speed 142 2: multiply the speed
143 the argument only has an effect for operations 0 and 2, and ranges between 143 the argument only has an effect for operations 0 and 2, and ranges between
144 1 (least effect) to 255 (maximum effect). 144 1 (least effect) to 255 (maximum effect).
145 145
146 thus, several states are equivalent and are coalesced into one state. 146 thus, several states are equivalent and are coalesced into one state.
147 147
148 we map this onto a range from 0 to 510, with: 148 we map this onto a range from 0 to 510, with:
@@ -151,7 +151,7 @@ static void powermate_sync_state(struct powermate_device *pm)
151 256 -- 510 -- use multiple (510 = fastest). 151 256 -- 510 -- use multiple (510 = fastest).
152 152
153 Only values of 'arg' quite close to 255 are particularly useful/spectacular. 153 Only values of 'arg' quite close to 255 are particularly useful/spectacular.
154 */ 154 */
155 if (pm->pulse_speed < 255){ 155 if (pm->pulse_speed < 255){
156 op = 0; // divide 156 op = 0; // divide
157 arg = 255 - pm->pulse_speed; 157 arg = 255 - pm->pulse_speed;
@@ -199,14 +199,14 @@ static void powermate_config_complete(struct urb *urb, struct pt_regs *regs)
199 199
200 if (urb->status) 200 if (urb->status)
201 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); 201 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
202 202
203 spin_lock_irqsave(&pm->lock, flags); 203 spin_lock_irqsave(&pm->lock, flags);
204 powermate_sync_state(pm); 204 powermate_sync_state(pm);
205 spin_unlock_irqrestore(&pm->lock, flags); 205 spin_unlock_irqrestore(&pm->lock, flags);
206} 206}
207 207
208/* Set the LED up as described and begin the sync with the hardware if required */ 208/* Set the LED up as described and begin the sync with the hardware if required */
209static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, 209static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
210 int pulse_table, int pulse_asleep, int pulse_awake) 210 int pulse_table, int pulse_asleep, int pulse_awake)
211{ 211{
212 unsigned long flags; 212 unsigned long flags;
@@ -229,7 +229,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
229 /* mark state updates which are required */ 229 /* mark state updates which are required */
230 if (static_brightness != pm->static_brightness){ 230 if (static_brightness != pm->static_brightness){
231 pm->static_brightness = static_brightness; 231 pm->static_brightness = static_brightness;
232 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS; 232 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
233 } 233 }
234 if (pulse_asleep != pm->pulse_asleep){ 234 if (pulse_asleep != pm->pulse_asleep){
235 pm->pulse_asleep = pulse_asleep; 235 pm->pulse_asleep = pulse_asleep;
@@ -246,7 +246,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
246 } 246 }
247 247
248 powermate_sync_state(pm); 248 powermate_sync_state(pm);
249 249
250 spin_unlock_irqrestore(&pm->lock, flags); 250 spin_unlock_irqrestore(&pm->lock, flags);
251} 251}
252 252
@@ -257,19 +257,19 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
257 struct powermate_device *pm = dev->private; 257 struct powermate_device *pm = dev->private;
258 258
259 if (type == EV_MSC && code == MSC_PULSELED){ 259 if (type == EV_MSC && code == MSC_PULSELED){
260 /* 260 /*
261 bits 0- 7: 8 bits: LED brightness 261 bits 0- 7: 8 bits: LED brightness
262 bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster. 262 bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
263 bits 17-18: 2 bits: pulse table (0, 1, 2 valid) 263 bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
264 bit 19: 1 bit : pulse whilst asleep? 264 bit 19: 1 bit : pulse whilst asleep?
265 bit 20: 1 bit : pulse constantly? 265 bit 20: 1 bit : pulse constantly?
266 */ 266 */
267 int static_brightness = command & 0xFF; // bits 0-7 267 int static_brightness = command & 0xFF; // bits 0-7
268 int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16 268 int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
269 int pulse_table = (command >> 17) & 0x3; // bits 17-18 269 int pulse_table = (command >> 17) & 0x3; // bits 17-18
270 int pulse_asleep = (command >> 19) & 0x1; // bit 19 270 int pulse_asleep = (command >> 19) & 0x1; // bit 19
271 int pulse_awake = (command >> 20) & 0x1; // bit 20 271 int pulse_awake = (command >> 20) & 0x1; // bit 20
272 272
273 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake); 273 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
274 } 274 }
275 275
@@ -378,7 +378,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
378 switch (le16_to_cpu(udev->descriptor.idProduct)) { 378 switch (le16_to_cpu(udev->descriptor.idProduct)) {
379 case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break; 379 case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break;
380 case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break; 380 case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break;
381 default: 381 default:
382 pm->input.name = pm_name_soundknob; 382 pm->input.name = pm_name_soundknob;
383 printk(KERN_WARNING "powermate: unknown product id %04x\n", 383 printk(KERN_WARNING "powermate: unknown product id %04x\n",
384 le16_to_cpu(udev->descriptor.idProduct)); 384 le16_to_cpu(udev->descriptor.idProduct));
@@ -402,11 +402,11 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
402 usb_make_path(udev, path, 64); 402 usb_make_path(udev, path, 64);
403 snprintf(pm->phys, 64, "%s/input0", path); 403 snprintf(pm->phys, 64, "%s/input0", path);
404 printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys); 404 printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys);
405 405
406 /* force an update of everything */ 406 /* force an update of everything */
407 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS; 407 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
408 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters 408 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters
409 409
410 usb_set_intfdata(intf, pm); 410 usb_set_intfdata(intf, pm);
411 return 0; 411 return 0;
412} 412}
diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c
index a71f1bbd0a17..386595ee21c0 100644
--- a/drivers/usb/input/touchkitusb.c
+++ b/drivers/usb/input/touchkitusb.c
@@ -69,7 +69,6 @@ struct touchkit_usb {
69 struct urb *irq; 69 struct urb *irq;
70 struct usb_device *udev; 70 struct usb_device *udev;
71 struct input_dev input; 71 struct input_dev input;
72 int open;
73 char name[128]; 72 char name[128];
74 char phys[64]; 73 char phys[64];
75}; 74};
@@ -134,15 +133,10 @@ static int touchkit_open(struct input_dev *input)
134{ 133{
135 struct touchkit_usb *touchkit = input->private; 134 struct touchkit_usb *touchkit = input->private;
136 135
137 if (touchkit->open++)
138 return 0;
139
140 touchkit->irq->dev = touchkit->udev; 136 touchkit->irq->dev = touchkit->udev;
141 137
142 if (usb_submit_urb(touchkit->irq, GFP_ATOMIC)) { 138 if (usb_submit_urb(touchkit->irq, GFP_ATOMIC))
143 touchkit->open--;
144 return -EIO; 139 return -EIO;
145 }
146 140
147 return 0; 141 return 0;
148} 142}
@@ -151,8 +145,7 @@ static void touchkit_close(struct input_dev *input)
151{ 145{
152 struct touchkit_usb *touchkit = input->private; 146 struct touchkit_usb *touchkit = input->private;
153 147
154 if (!--touchkit->open) 148 usb_kill_urb(touchkit->irq);
155 usb_kill_urb(touchkit->irq);
156} 149}
157 150
158static int touchkit_alloc_buffers(struct usb_device *udev, 151static int touchkit_alloc_buffers(struct usb_device *udev,
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
index 7038fb9d1ced..f35db1974c42 100644
--- a/drivers/usb/input/usbkbd.c
+++ b/drivers/usb/input/usbkbd.c
@@ -9,18 +9,18 @@
9/* 9/*
10 * 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
11 * 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
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 * Should you need to contact me, the author, you can do so either by 24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -72,7 +72,6 @@ struct usb_kbd {
72 unsigned char newleds; 72 unsigned char newleds;
73 char name[128]; 73 char name[128];
74 char phys[64]; 74 char phys[64];
75 int open;
76 75
77 unsigned char *new; 76 unsigned char *new;
78 struct usb_ctrlrequest *cr; 77 struct usb_ctrlrequest *cr;
@@ -166,7 +165,7 @@ static void usb_kbd_led(struct urb *urb, struct pt_regs *regs)
166 165
167 if (urb->status) 166 if (urb->status)
168 warn("led urb status %d received", urb->status); 167 warn("led urb status %d received", urb->status);
169 168
170 if (*(kbd->leds) == kbd->newleds) 169 if (*(kbd->leds) == kbd->newleds)
171 return; 170 return;
172 171
@@ -180,14 +179,9 @@ static int usb_kbd_open(struct input_dev *dev)
180{ 179{
181 struct usb_kbd *kbd = dev->private; 180 struct usb_kbd *kbd = dev->private;
182 181
183 if (kbd->open++)
184 return 0;
185
186 kbd->irq->dev = kbd->usbdev; 182 kbd->irq->dev = kbd->usbdev;
187 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) { 183 if (usb_submit_urb(kbd->irq, GFP_KERNEL))
188 kbd->open--;
189 return -EIO; 184 return -EIO;
190 }
191 185
192 return 0; 186 return 0;
193} 187}
@@ -196,8 +190,7 @@ static void usb_kbd_close(struct input_dev *dev)
196{ 190{
197 struct usb_kbd *kbd = dev->private; 191 struct usb_kbd *kbd = dev->private;
198 192
199 if (!--kbd->open) 193 usb_kill_urb(kbd->irq);
200 usb_kill_urb(kbd->irq);
201} 194}
202 195
203static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd) 196static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
@@ -230,7 +223,7 @@ static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
230 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); 223 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
231} 224}
232 225
233static int usb_kbd_probe(struct usb_interface *iface, 226static int usb_kbd_probe(struct usb_interface *iface,
234 const struct usb_device_id *id) 227 const struct usb_device_id *id)
235{ 228{
236 struct usb_device * dev = interface_to_usbdev(iface); 229 struct usb_device * dev = interface_to_usbdev(iface);
@@ -272,7 +265,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
272 for (i = 0; i < 255; i++) 265 for (i = 0; i < 255; i++)
273 set_bit(usb_kbd_keycode[i], kbd->dev.keybit); 266 set_bit(usb_kbd_keycode[i], kbd->dev.keybit);
274 clear_bit(0, kbd->dev.keybit); 267 clear_bit(0, kbd->dev.keybit);
275 268
276 kbd->dev.private = kbd; 269 kbd->dev.private = kbd;
277 kbd->dev.event = usb_kbd_event; 270 kbd->dev.event = usb_kbd_event;
278 kbd->dev.open = usb_kbd_open; 271 kbd->dev.open = usb_kbd_open;
@@ -294,7 +287,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
294 sprintf(kbd->phys, "%s/input0", path); 287 sprintf(kbd->phys, "%s/input0", path);
295 288
296 kbd->dev.name = kbd->name; 289 kbd->dev.name = kbd->name;
297 kbd->dev.phys = kbd->phys; 290 kbd->dev.phys = kbd->phys;
298 kbd->dev.id.bustype = BUS_USB; 291 kbd->dev.id.bustype = BUS_USB;
299 kbd->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor); 292 kbd->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
300 kbd->dev.id.product = le16_to_cpu(dev->descriptor.idProduct); 293 kbd->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
@@ -329,7 +322,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
329static void usb_kbd_disconnect(struct usb_interface *intf) 322static void usb_kbd_disconnect(struct usb_interface *intf)
330{ 323{
331 struct usb_kbd *kbd = usb_get_intfdata (intf); 324 struct usb_kbd *kbd = usb_get_intfdata (intf);
332 325
333 usb_set_intfdata(intf, NULL); 326 usb_set_intfdata(intf, NULL);
334 if (kbd) { 327 if (kbd) {
335 usb_kill_urb(kbd->irq); 328 usb_kill_urb(kbd->irq);
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 01155bbddd43..1ec41b5effe6 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -9,18 +9,18 @@
9/* 9/*
10 * 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
11 * 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
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 * Should you need to contact me, the author, you can do so either by 24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
@@ -51,7 +51,6 @@ struct usb_mouse {
51 struct usb_device *usbdev; 51 struct usb_device *usbdev;
52 struct input_dev dev; 52 struct input_dev dev;
53 struct urb *irq; 53 struct urb *irq;
54 int open;
55 54
56 signed char *data; 55 signed char *data;
57 dma_addr_t data_dma; 56 dma_addr_t data_dma;
@@ -101,14 +100,9 @@ static int usb_mouse_open(struct input_dev *dev)
101{ 100{
102 struct usb_mouse *mouse = dev->private; 101 struct usb_mouse *mouse = dev->private;
103 102
104 if (mouse->open++)
105 return 0;
106
107 mouse->irq->dev = mouse->usbdev; 103 mouse->irq->dev = mouse->usbdev;
108 if (usb_submit_urb(mouse->irq, GFP_KERNEL)) { 104 if (usb_submit_urb(mouse->irq, GFP_KERNEL))
109 mouse->open--;
110 return -EIO; 105 return -EIO;
111 }
112 106
113 return 0; 107 return 0;
114} 108}
@@ -117,8 +111,7 @@ static void usb_mouse_close(struct input_dev *dev)
117{ 111{
118 struct usb_mouse *mouse = dev->private; 112 struct usb_mouse *mouse = dev->private;
119 113
120 if (!--mouse->open) 114 usb_kill_urb(mouse->irq);
121 usb_kill_urb(mouse->irq);
122} 115}
123 116
124static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id) 117static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id)
@@ -132,19 +125,19 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
132 125
133 interface = intf->cur_altsetting; 126 interface = intf->cur_altsetting;
134 127
135 if (interface->desc.bNumEndpoints != 1) 128 if (interface->desc.bNumEndpoints != 1)
136 return -ENODEV; 129 return -ENODEV;
137 130
138 endpoint = &interface->endpoint[0].desc; 131 endpoint = &interface->endpoint[0].desc;
139 if (!(endpoint->bEndpointAddress & 0x80)) 132 if (!(endpoint->bEndpointAddress & 0x80))
140 return -ENODEV; 133 return -ENODEV;
141 if ((endpoint->bmAttributes & 3) != 3) 134 if ((endpoint->bmAttributes & 3) != 3)
142 return -ENODEV; 135 return -ENODEV;
143 136
144 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 137 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
145 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 138 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
146 139
147 if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) 140 if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL)))
148 return -ENOMEM; 141 return -ENOMEM;
149 memset(mouse, 0, sizeof(struct usb_mouse)); 142 memset(mouse, 0, sizeof(struct usb_mouse));
150 143
@@ -209,7 +202,7 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
209static void usb_mouse_disconnect(struct usb_interface *intf) 202static void usb_mouse_disconnect(struct usb_interface *intf)
210{ 203{
211 struct usb_mouse *mouse = usb_get_intfdata (intf); 204 struct usb_mouse *mouse = usb_get_intfdata (intf);
212 205
213 usb_set_intfdata(intf, NULL); 206 usb_set_intfdata(intf, NULL);
214 if (mouse) { 207 if (mouse) {
215 usb_kill_urb(mouse->irq); 208 usb_kill_urb(mouse->irq);
@@ -238,7 +231,7 @@ static struct usb_driver usb_mouse_driver = {
238static int __init usb_mouse_init(void) 231static int __init usb_mouse_init(void)
239{ 232{
240 int retval = usb_register(&usb_mouse_driver); 233 int retval = usb_register(&usb_mouse_driver);
241 if (retval == 0) 234 if (retval == 0)
242 info(DRIVER_VERSION ":" DRIVER_DESC); 235 info(DRIVER_VERSION ":" DRIVER_DESC);
243 return retval; 236 return retval;
244} 237}
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index fec04dda088e..f6b34af66b3d 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -9,7 +9,7 @@
9 * Copyright (c) 2000 Daniel Egger <egger@suse.de> 9 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com> 10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be> 11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
12 * Copyright (c) 2002-2004 Ping Cheng <pingc@wacom.com> 12 * Copyright (c) 2002-2005 Ping Cheng <pingc@wacom.com>
13 * 13 *
14 * ChangeLog: 14 * ChangeLog:
15 * v0.1 (vp) - Initial release 15 * v0.1 (vp) - Initial release
@@ -18,7 +18,7 @@
18 * v0.4 (sm) - Support for more Intuos models, menustrip 18 * v0.4 (sm) - Support for more Intuos models, menustrip
19 * relative mode, proximity. 19 * relative mode, proximity.
20 * v0.5 (vp) - Big cleanup, nifty features removed, 20 * v0.5 (vp) - Big cleanup, nifty features removed,
21 * they belong in userspace 21 * they belong in userspace
22 * v1.8 (vp) - Submit URB only when operating, moved to CVS, 22 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
23 * use input_report_key instead of report_btn and 23 * use input_report_key instead of report_btn and
24 * other cleanups 24 * other cleanups
@@ -51,6 +51,9 @@
51 * - Cleanups here and there 51 * - Cleanups here and there
52 * v1.30.1 (pi) - Added Graphire3 support 52 * v1.30.1 (pi) - Added Graphire3 support
53 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ... 53 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
54 * v1.43 (pc) - Added support for Cintiq 21UX
55 - Fixed a Graphire bug
56 - Merged wacom_intuos3_irq into wacom_intuos_irq
54 */ 57 */
55 58
56/* 59/*
@@ -72,7 +75,7 @@
72/* 75/*
73 * Version Information 76 * Version Information
74 */ 77 */
75#define DRIVER_VERSION "v1.40" 78#define DRIVER_VERSION "v1.43"
76#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 79#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
77#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver" 80#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
78#define DRIVER_LICENSE "GPL" 81#define DRIVER_LICENSE "GPL"
@@ -83,6 +86,16 @@ MODULE_LICENSE(DRIVER_LICENSE);
83 86
84#define USB_VENDOR_ID_WACOM 0x056a 87#define USB_VENDOR_ID_WACOM 0x056a
85 88
89enum {
90 PENPARTNER = 0,
91 GRAPHIRE,
92 PL,
93 INTUOS,
94 INTUOS3,
95 CINTIQ,
96 MAX_TYPE
97};
98
86struct wacom_features { 99struct wacom_features {
87 char *name; 100 char *name;
88 int pktlen; 101 int pktlen;
@@ -102,7 +115,6 @@ struct wacom {
102 struct urb *irq; 115 struct urb *irq;
103 struct wacom_features *features; 116 struct wacom_features *features;
104 int tool[2]; 117 int tool[2];
105 int open;
106 __u32 serial[2]; 118 __u32 serial[2];
107 char phys[32]; 119 char phys[32];
108}; 120};
@@ -149,7 +161,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
149 prox = data[1] & 0x40; 161 prox = data[1] & 0x40;
150 162
151 input_regs(dev, regs); 163 input_regs(dev, regs);
152 164
153 if (prox) { 165 if (prox) {
154 166
155 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); 167 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
@@ -166,8 +178,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
166 if (!wacom->tool[0]) { 178 if (!wacom->tool[0]) {
167 /* Going into proximity select tool */ 179 /* Going into proximity select tool */
168 wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 180 wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
169 } 181 } else {
170 else {
171 /* was entered with stylus2 pressed */ 182 /* was entered with stylus2 pressed */
172 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) { 183 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) {
173 /* report out proximity for previous tool */ 184 /* report out proximity for previous tool */
@@ -182,16 +193,15 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
182 wacom->tool[1] = BTN_TOOL_PEN; 193 wacom->tool[1] = BTN_TOOL_PEN;
183 } 194 }
184 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */ 195 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
185 input_report_abs(dev, ABS_X, data[3] | ((__u32)data[2] << 7) | ((__u32)(data[1] & 0x03) << 14)); 196 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
186 input_report_abs(dev, ABS_Y, data[6] | ((__u32)data[5] << 7) | ((__u32)(data[4] & 0x03) << 14)); 197 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
187 input_report_abs(dev, ABS_PRESSURE, pressure); 198 input_report_abs(dev, ABS_PRESSURE, pressure);
188 199
189 input_report_key(dev, BTN_TOUCH, data[4] & 0x08); 200 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
190 input_report_key(dev, BTN_STYLUS, data[4] & 0x10); 201 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
191 /* Only allow the stylus2 button to be reported for the pen tool. */ 202 /* Only allow the stylus2 button to be reported for the pen tool. */
192 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20)); 203 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
193 } 204 } else {
194 else {
195 /* report proximity-out of a (valid) tool */ 205 /* report proximity-out of a (valid) tool */
196 if (wacom->tool[1] != BTN_TOOL_RUBBER) { 206 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
197 /* Unknown tool selected default to pen tool */ 207 /* Unknown tool selected default to pen tool */
@@ -203,7 +213,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
203 wacom->tool[0] = prox; /* Save proximity state */ 213 wacom->tool[0] = prox; /* Save proximity state */
204 input_sync(dev); 214 input_sync(dev);
205 215
206exit: 216 exit:
207 retval = usb_submit_urb (urb, GFP_ATOMIC); 217 retval = usb_submit_urb (urb, GFP_ATOMIC);
208 if (retval) 218 if (retval)
209 err ("%s - usb_submit_urb failed with result %d", 219 err ("%s - usb_submit_urb failed with result %d",
@@ -232,20 +242,16 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
232 goto exit; 242 goto exit;
233 } 243 }
234 244
235 if (data[0] != 2) 245 if (data[0] != 2) {
236 {
237 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]); 246 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
238 goto exit; 247 goto exit;
239 } 248 }
240 249
241 input_regs(dev, regs); 250 input_regs(dev, regs);
242 if (data[1] & 0x04) 251 if (data[1] & 0x04) {
243 {
244 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20); 252 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
245 input_report_key(dev, BTN_TOUCH, data[1] & 0x08); 253 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
246 } 254 } else {
247 else
248 {
249 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20); 255 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
250 input_report_key(dev, BTN_TOUCH, data[1] & 0x01); 256 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
251 } 257 }
@@ -257,7 +263,7 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
257 263
258 input_sync(dev); 264 input_sync(dev);
259 265
260exit: 266 exit:
261 retval = usb_submit_urb (urb, GFP_ATOMIC); 267 retval = usb_submit_urb (urb, GFP_ATOMIC);
262 if (retval) 268 if (retval)
263 err ("%s - usb_submit_urb failed with result %d", 269 err ("%s - usb_submit_urb failed with result %d",
@@ -300,7 +306,7 @@ static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
300 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40)); 306 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
301 input_sync(dev); 307 input_sync(dev);
302 308
303exit: 309 exit:
304 retval = usb_submit_urb (urb, GFP_ATOMIC); 310 retval = usb_submit_urb (urb, GFP_ATOMIC);
305 if (retval) 311 if (retval)
306 err ("%s - usb_submit_urb failed with result %d", 312 err ("%s - usb_submit_urb failed with result %d",
@@ -340,47 +346,47 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
340 346
341 input_regs(dev, regs); 347 input_regs(dev, regs);
342 348
343 switch ((data[1] >> 5) & 3) { 349 if (data[1] & 0x10) { /* in prox */
344 350
345 case 0: /* Pen */ 351 switch ((data[1] >> 5) & 3) {
346 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x80);
347 break;
348 352
349 case 1: /* Rubber */ 353 case 0: /* Pen */
350 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x80); 354 wacom->tool[0] = BTN_TOOL_PEN;
351 break; 355 break;
352
353 case 2: /* Mouse with wheel */
354 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
355 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
356 /* fall through */
357 356
358 case 3: /* Mouse without wheel */ 357 case 1: /* Rubber */
359 input_report_key(dev, BTN_TOOL_MOUSE, data[7] > 24); 358 wacom->tool[0] = BTN_TOOL_RUBBER;
360 input_report_key(dev, BTN_LEFT, data[1] & 0x01); 359 break;
361 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
362 input_report_abs(dev, ABS_DISTANCE, data[7]);
363 360
364 input_report_abs(dev, ABS_X, x); 361 case 2: /* Mouse with wheel */
365 input_report_abs(dev, ABS_Y, y); 362 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
363 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
364 /* fall through */
366 365
367 input_sync(dev); 366 case 3: /* Mouse without wheel */
368 goto exit; 367 wacom->tool[0] = BTN_TOOL_MOUSE;
368 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
369 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
370 input_report_abs(dev, ABS_DISTANCE, data[7]);
371 break;
372 }
369 } 373 }
370 374
371 if (data[1] & 0x80) { 375 if (data[1] & 0x80) {
372 input_report_abs(dev, ABS_X, x); 376 input_report_abs(dev, ABS_X, x);
373 input_report_abs(dev, ABS_Y, y); 377 input_report_abs(dev, ABS_Y, y);
374 } 378 }
379 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
380 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
381 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
382 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
383 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
384 }
375 385
376 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6])); 386 input_report_key(dev, wacom->tool[0], data[1] & 0x10);
377 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
378 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
379 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
380
381 input_sync(dev); 387 input_sync(dev);
382 388
383exit: 389 exit:
384 retval = usb_submit_urb (urb, GFP_ATOMIC); 390 retval = usb_submit_urb (urb, GFP_ATOMIC);
385 if (retval) 391 if (retval)
386 err ("%s - usb_submit_urb failed with result %d", 392 err ("%s - usb_submit_urb failed with result %d",
@@ -398,14 +404,13 @@ static int wacom_intuos_inout(struct urb *urb)
398 idx = data[1] & 0x01; 404 idx = data[1] & 0x01;
399 405
400 /* Enter report */ 406 /* Enter report */
401 if ((data[1] & 0xfc) == 0xc0) 407 if ((data[1] & 0xfc) == 0xc0) {
402 {
403 /* serial number of the tool */ 408 /* serial number of the tool */
404 wacom->serial[idx] = ((__u32)(data[3] & 0x0f) << 28) + 409 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
405 ((__u32)data[4] << 20) + ((__u32)data[5] << 12) + 410 (data[4] << 20) + (data[5] << 12) +
406 ((__u32)data[6] << 4) + (data[7] >> 4); 411 (data[6] << 4) + (data[7] >> 4);
407 412
408 switch (((__u32)data[2] << 4) | (data[3] >> 4)) { 413 switch ((data[2] << 4) | (data[3] >> 4)) {
409 case 0x812: /* Inking pen */ 414 case 0x812: /* Inking pen */
410 case 0x801: /* Intuos3 Inking pen */ 415 case 0x801: /* Intuos3 Inking pen */
411 case 0x012: 416 case 0x012:
@@ -449,7 +454,7 @@ static int wacom_intuos_inout(struct urb *urb)
449 case 0x112: 454 case 0x112:
450 case 0x913: /* Intuos3 Airbrush */ 455 case 0x913: /* Intuos3 Airbrush */
451 wacom->tool[idx] = BTN_TOOL_AIRBRUSH; 456 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
452 break; /* Airbrush */ 457 break;
453 default: /* Unknown tool */ 458 default: /* Unknown tool */
454 wacom->tool[idx] = BTN_TOOL_PEN; 459 wacom->tool[idx] = BTN_TOOL_PEN;
455 } 460 }
@@ -478,9 +483,8 @@ static void wacom_intuos_general(struct urb *urb)
478 unsigned int t; 483 unsigned int t;
479 484
480 /* general pen packet */ 485 /* general pen packet */
481 if ((data[1] & 0xb8) == 0xa0) 486 if ((data[1] & 0xb8) == 0xa0) {
482 { 487 t = (data[6] << 2) | ((data[7] >> 6) & 3);
483 t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
484 input_report_abs(dev, ABS_PRESSURE, t); 488 input_report_abs(dev, ABS_PRESSURE, t);
485 input_report_abs(dev, ABS_TILT_X, 489 input_report_abs(dev, ABS_TILT_X,
486 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 490 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
@@ -491,10 +495,9 @@ static void wacom_intuos_general(struct urb *urb)
491 } 495 }
492 496
493 /* airbrush second packet */ 497 /* airbrush second packet */
494 if ((data[1] & 0xbc) == 0xb4) 498 if ((data[1] & 0xbc) == 0xb4) {
495 {
496 input_report_abs(dev, ABS_WHEEL, 499 input_report_abs(dev, ABS_WHEEL,
497 ((__u32)data[6] << 2) | ((data[7] >> 6) & 3)); 500 (data[6] << 2) | ((data[7] >> 6) & 3));
498 input_report_abs(dev, ABS_TILT_X, 501 input_report_abs(dev, ABS_TILT_X,
499 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 502 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
500 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f); 503 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
@@ -526,7 +529,7 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
526 goto exit; 529 goto exit;
527 } 530 }
528 531
529 if (data[0] != 2 && data[0] != 5 && data[0] != 6) { 532 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
530 dbg("wacom_intuos_irq: received unknown report #%d", data[0]); 533 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
531 goto exit; 534 goto exit;
532 } 535 }
@@ -536,107 +539,10 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
536 /* tool number */ 539 /* tool number */
537 idx = data[1] & 0x01; 540 idx = data[1] & 0x01;
538 541
539 /* process in/out prox events */
540 if (wacom_intuos_inout(urb)) goto exit;
541
542 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
543 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
544 input_report_abs(dev, ABS_DISTANCE, data[9]);
545
546 /* process general packets */
547 wacom_intuos_general(urb);
548
549 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) { /* 4D mouse or Lens cursor packets */
550
551 if (data[1] & 0x02) { /* Rotation packet */
552
553 t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
554 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ? ((t - 1) / 2) : -t / 2);
555
556 } else {
557
558 if ((data[1] & 0x10) == 0) { /* 4D mouse packets */
559
560 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
561 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
562 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
563
564 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
565 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
566 t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
567 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
568
569 } else {
570 if (wacom->tool[idx] == BTN_TOOL_MOUSE) { /* 2D mouse packets */
571 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
572 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
573 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
574 input_report_rel(dev, REL_WHEEL,
575 (-(__u32)(data[8] & 0x01) + (__u32)((data[8] & 0x02) >> 1)));
576 }
577 else { /* Lens cursor packets */
578 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
579 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
580 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
581 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
582 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
583 }
584 }
585 }
586 }
587
588 input_report_key(dev, wacom->tool[idx], 1);
589 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
590 input_sync(dev);
591
592exit:
593 retval = usb_submit_urb (urb, GFP_ATOMIC);
594 if (retval)
595 err ("%s - usb_submit_urb failed with result %d",
596 __FUNCTION__, retval);
597}
598
599static void wacom_intuos3_irq(struct urb *urb, struct pt_regs *regs)
600{
601 struct wacom *wacom = urb->context;
602 unsigned char *data = wacom->data;
603 struct input_dev *dev = &wacom->dev;
604 unsigned int t;
605 int idx, retval;
606
607 switch (urb->status) {
608 case 0:
609 /* success */
610 break;
611 case -ECONNRESET:
612 case -ENOENT:
613 case -ESHUTDOWN:
614 /* this urb is terminated, clean up */
615 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
616 return;
617 default:
618 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
619 goto exit;
620 }
621
622 /* check for valid report */
623 if (data[0] != 2 && data[0] != 5 && data[0] != 12)
624 {
625 printk(KERN_INFO "wacom_intuos3_irq: received unknown report #%d\n", data[0]);
626 goto exit;
627 }
628
629 input_regs(dev, regs);
630
631 /* tool index is always 0 here since there is no dual input tool */
632 idx = data[1] & 0x01;
633
634 /* pad packets. Works as a second tool and is always in prox */ 542 /* pad packets. Works as a second tool and is always in prox */
635 if (data[0] == 12) 543 if (data[0] == 12) {
636 {
637 /* initiate the pad as a device */ 544 /* initiate the pad as a device */
638 if (wacom->tool[1] != BTN_TOOL_FINGER) 545 if (wacom->tool[1] != BTN_TOOL_FINGER) {
639 {
640 wacom->tool[1] = BTN_TOOL_FINGER; 546 wacom->tool[1] = BTN_TOOL_FINGER;
641 input_report_key(dev, wacom->tool[1], 1); 547 input_report_key(dev, wacom->tool[1], 1);
642 } 548 }
@@ -656,37 +562,78 @@ static void wacom_intuos3_irq(struct urb *urb, struct pt_regs *regs)
656 } 562 }
657 563
658 /* process in/out prox events */ 564 /* process in/out prox events */
659 if (wacom_intuos_inout(urb)) goto exit; 565 if (wacom_intuos_inout(urb))
566 goto exit;
660 567
661 input_report_abs(dev, ABS_X, ((__u32)data[2] << 9) | ((__u32)data[3] << 1) | ((data[9] >> 1) & 1)); 568 /* Cintiq doesn't send data when RDY bit isn't set */
662 input_report_abs(dev, ABS_Y, ((__u32)data[4] << 9) | ((__u32)data[5] << 1) | (data[9] & 1)); 569 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
663 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 570 return;
571
572 if (wacom->features->type >= INTUOS3) {
573 input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
574 input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
575 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
576 } else {
577 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
578 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
579 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
580 }
664 581
665 /* process general packets */ 582 /* process general packets */
666 wacom_intuos_general(urb); 583 wacom_intuos_general(urb);
667 584
668 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) 585 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
669 { 586 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
670 /* Marker pen rotation packet. Reported as wheel due to valuator limitation */ 587
671 if (data[1] & 0x02) 588 if (data[1] & 0x02) {
672 { 589 /* Rotation packet */
673 t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7); 590 if (wacom->features->type >= INTUOS3) {
674 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : 591 /* I3 marker pen rotation reported as wheel
675 ((t-1) / 2 + 450)) : (450 - t / 2) ; 592 * due to valuator limitation
676 input_report_abs(dev, ABS_WHEEL, t); 593 */
677 } 594 t = (data[6] << 3) | ((data[7] >> 5) & 7);
595 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
596 ((t-1) / 2 + 450)) : (450 - t / 2) ;
597 input_report_abs(dev, ABS_WHEEL, t);
598 } else {
599 /* 4D mouse rotation packet */
600 t = (data[6] << 3) | ((data[7] >> 5) & 7);
601 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
602 ((t - 1) / 2) : -t / 2);
603 }
678 604
679 /* 2D mouse packets */ 605 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
680 if (wacom->tool[idx] == BTN_TOOL_MOUSE) 606 /* 4D mouse packet */
681 { 607 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
608 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
609 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
610
611 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
612 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
613 t = (data[6] << 2) | ((data[7] >> 6) & 3);
614 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
615
616 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
617 /* 2D mouse packet */
682 input_report_key(dev, BTN_LEFT, data[8] & 0x04); 618 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
683 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08); 619 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
684 input_report_key(dev, BTN_RIGHT, data[8] & 0x10); 620 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
685 input_report_key(dev, BTN_SIDE, data[8] & 0x40); 621 input_report_rel(dev, REL_WHEEL, ((data[8] & 0x02) >> 1)
686 input_report_key(dev, BTN_EXTRA, data[8] & 0x20); 622 - (data[8] & 0x01));
687 /* mouse wheel is positive when rolled backwards */ 623
688 input_report_rel(dev, REL_WHEEL, ((__u32)((data[8] & 0x02) >> 1) 624 /* I3 2D mouse side buttons */
689 - (__u32)(data[8] & 0x01))); 625 if (wacom->features->type == INTUOS3) {
626 input_report_key(dev, BTN_SIDE, data[8] & 0x40);
627 input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
628 }
629
630 } else if (wacom->features->type < INTUOS3) {
631 /* Lens cursor packets */
632 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
633 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
634 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
635 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
636 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
690 } 637 }
691 } 638 }
692 639
@@ -702,35 +649,36 @@ exit:
702} 649}
703 650
704static struct wacom_features wacom_features[] = { 651static struct wacom_features wacom_features[] = {
705 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, 0, wacom_penpartner_irq }, 652 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
706 { "Wacom Graphire", 8, 10206, 7422, 511, 32, 1, wacom_graphire_irq }, 653 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
707 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, 1, wacom_graphire_irq }, 654 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
708 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, 1, wacom_graphire_irq }, 655 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
709 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, 1, wacom_graphire_irq }, 656 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
710 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, 1, wacom_graphire_irq }, 657 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
711 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, 2, wacom_intuos_irq }, 658 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
712 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 659 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
713 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, 2, wacom_intuos_irq }, 660 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
714 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, 2, wacom_intuos_irq }, 661 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
715 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, 2, wacom_intuos_irq }, 662 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
716 { "Wacom PL400", 8, 5408, 4056, 255, 32, 3, wacom_pl_irq }, 663 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
717 { "Wacom PL500", 8, 6144, 4608, 255, 32, 3, wacom_pl_irq }, 664 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
718 { "Wacom PL600", 8, 6126, 4604, 255, 32, 3, wacom_pl_irq }, 665 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
719 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, 3, wacom_pl_irq }, 666 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
720 { "Wacom PL550", 8, 6144, 4608, 511, 32, 3, wacom_pl_irq }, 667 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
721 { "Wacom PL800", 8, 7220, 5780, 511, 32, 3, wacom_pl_irq }, 668 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
722 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, 2, wacom_intuos_irq }, 669 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
723 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 670 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
724 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, 2, wacom_intuos_irq }, 671 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
725 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, 2, wacom_intuos_irq }, 672 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
726 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, 2, wacom_intuos_irq }, 673 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
727 { "Wacom Volito", 8, 5104, 3712, 511, 32, 1, wacom_graphire_irq }, 674 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
728 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, 3, wacom_ptu_irq }, 675 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
729 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, 4, wacom_intuos3_irq }, 676 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
730 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, 4, wacom_intuos3_irq }, 677 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
731 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, 4, wacom_intuos3_irq }, 678 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
732 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq }, 679 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
733 { } 680 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
681 { }
734}; 682};
735 683
736static struct usb_device_id wacom_ids[] = { 684static struct usb_device_id wacom_ids[] = {
@@ -761,6 +709,7 @@ static struct usb_device_id wacom_ids[] = {
761 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) }, 709 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
762 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) }, 710 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
763 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) }, 711 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
712 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
764 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, 713 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
765 { } 714 { }
766}; 715};
@@ -771,14 +720,9 @@ static int wacom_open(struct input_dev *dev)
771{ 720{
772 struct wacom *wacom = dev->private; 721 struct wacom *wacom = dev->private;
773 722
774 if (wacom->open++)
775 return 0;
776
777 wacom->irq->dev = wacom->usbdev; 723 wacom->irq->dev = wacom->usbdev;
778 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { 724 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
779 wacom->open--;
780 return -EIO; 725 return -EIO;
781 }
782 726
783 return 0; 727 return 0;
784} 728}
@@ -787,8 +731,7 @@ static void wacom_close(struct input_dev *dev)
787{ 731{
788 struct wacom *wacom = dev->private; 732 struct wacom *wacom = dev->private;
789 733
790 if (!--wacom->open) 734 usb_kill_urb(wacom->irq);
791 usb_kill_urb(wacom->irq);
792} 735}
793 736
794static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) 737static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -823,32 +766,33 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
823 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); 766 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
824 767
825 switch (wacom->features->type) { 768 switch (wacom->features->type) {
826 case 1: 769 case GRAPHIRE:
827 wacom->dev.evbit[0] |= BIT(EV_REL); 770 wacom->dev.evbit[0] |= BIT(EV_REL);
828 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 771 wacom->dev.relbit[0] |= BIT(REL_WHEEL);
829 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE); 772 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE);
830 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 773 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
831 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); 774 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
832 break; 775 break;
833 776
834 case 4: /* new functions for Intuos3 */ 777 case INTUOS3:
778 case CINTIQ:
835 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 779 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
836 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 780 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
837 wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY); 781 wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY);
838 /* fall through */ 782 /* fall through */
839 783
840 case 2: 784 case INTUOS:
841 wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); 785 wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
842 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL); 786 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL);
843 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 787 wacom->dev.relbit[0] |= BIT(REL_WHEEL);
844 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); 788 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
845 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) 789 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
846 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2); 790 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
847 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE); 791 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE);
848 break; 792 break;
849 793
850 case 3: 794 case PL:
851 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); 795 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
852 break; 796 break;
853 } 797 }
854 798
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c
index d65edb22e545..a7fa1b17dcfe 100644
--- a/drivers/usb/input/xpad.c
+++ b/drivers/usb/input/xpad.c
@@ -104,13 +104,12 @@ MODULE_DEVICE_TABLE (usb, xpad_table);
104struct usb_xpad { 104struct usb_xpad {
105 struct input_dev dev; /* input device interface */ 105 struct input_dev dev; /* input device interface */
106 struct usb_device *udev; /* usb device */ 106 struct usb_device *udev; /* usb device */
107 107
108 struct urb *irq_in; /* urb for interrupt in report */ 108 struct urb *irq_in; /* urb for interrupt in report */
109 unsigned char *idata; /* input data */ 109 unsigned char *idata; /* input data */
110 dma_addr_t idata_dma; 110 dma_addr_t idata_dma;
111 111
112 char phys[65]; /* physical device path */ 112 char phys[65]; /* physical device path */
113 int open_count; /* reference count */
114}; 113};
115 114
116/* 115/*
@@ -128,35 +127,35 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
128 struct input_dev *dev = &xpad->dev; 127 struct input_dev *dev = &xpad->dev;
129 128
130 input_regs(dev, regs); 129 input_regs(dev, regs);
131 130
132 /* left stick */ 131 /* left stick */
133 input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12])); 132 input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12]));
134 input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14])); 133 input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14]));
135 134
136 /* right stick */ 135 /* right stick */
137 input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16])); 136 input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16]));
138 input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18])); 137 input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18]));
139 138
140 /* triggers left/right */ 139 /* triggers left/right */
141 input_report_abs(dev, ABS_Z, data[10]); 140 input_report_abs(dev, ABS_Z, data[10]);
142 input_report_abs(dev, ABS_RZ, data[11]); 141 input_report_abs(dev, ABS_RZ, data[11]);
143 142
144 /* digital pad */ 143 /* digital pad */
145 input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); 144 input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04));
146 input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); 145 input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01));
147 146
148 /* start/back buttons and stick press left/right */ 147 /* start/back buttons and stick press left/right */
149 input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); 148 input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4);
150 input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5); 149 input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5);
151 input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6); 150 input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6);
152 input_report_key(dev, BTN_THUMBR, data[2] >> 7); 151 input_report_key(dev, BTN_THUMBR, data[2] >> 7);
153 152
154 /* "analog" buttons A, B, X, Y */ 153 /* "analog" buttons A, B, X, Y */
155 input_report_key(dev, BTN_A, data[4]); 154 input_report_key(dev, BTN_A, data[4]);
156 input_report_key(dev, BTN_B, data[5]); 155 input_report_key(dev, BTN_B, data[5]);
157 input_report_key(dev, BTN_X, data[6]); 156 input_report_key(dev, BTN_X, data[6]);
158 input_report_key(dev, BTN_Y, data[7]); 157 input_report_key(dev, BTN_Y, data[7]);
159 158
160 /* "analog" buttons black, white */ 159 /* "analog" buttons black, white */
161 input_report_key(dev, BTN_C, data[8]); 160 input_report_key(dev, BTN_C, data[8]);
162 input_report_key(dev, BTN_Z, data[9]); 161 input_report_key(dev, BTN_Z, data[9]);
@@ -168,7 +167,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs)
168{ 167{
169 struct usb_xpad *xpad = urb->context; 168 struct usb_xpad *xpad = urb->context;
170 int retval; 169 int retval;
171 170
172 switch (urb->status) { 171 switch (urb->status) {
173 case 0: 172 case 0:
174 /* success */ 173 /* success */
@@ -183,7 +182,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs)
183 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 182 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
184 goto exit; 183 goto exit;
185 } 184 }
186 185
187 xpad_process_packet(xpad, 0, xpad->idata, regs); 186 xpad_process_packet(xpad, 0, xpad->idata, regs);
188 187
189exit: 188exit:
@@ -196,25 +195,19 @@ exit:
196static int xpad_open (struct input_dev *dev) 195static int xpad_open (struct input_dev *dev)
197{ 196{
198 struct usb_xpad *xpad = dev->private; 197 struct usb_xpad *xpad = dev->private;
199 198
200 if (xpad->open_count++)
201 return 0;
202
203 xpad->irq_in->dev = xpad->udev; 199 xpad->irq_in->dev = xpad->udev;
204 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) { 200 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
205 xpad->open_count--;
206 return -EIO; 201 return -EIO;
207 } 202
208
209 return 0; 203 return 0;
210} 204}
211 205
212static void xpad_close (struct input_dev *dev) 206static void xpad_close (struct input_dev *dev)
213{ 207{
214 struct usb_xpad *xpad = dev->private; 208 struct usb_xpad *xpad = dev->private;
215 209
216 if (!--xpad->open_count) 210 usb_kill_urb(xpad->irq_in);
217 usb_kill_urb(xpad->irq_in);
218} 211}
219 212
220static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) 213static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -224,19 +217,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
224 struct usb_endpoint_descriptor *ep_irq_in; 217 struct usb_endpoint_descriptor *ep_irq_in;
225 char path[64]; 218 char path[64];
226 int i; 219 int i;
227 220
228 for (i = 0; xpad_device[i].idVendor; i++) { 221 for (i = 0; xpad_device[i].idVendor; i++) {
229 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && 222 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
230 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) 223 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
231 break; 224 break;
232 } 225 }
233 226
234 if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { 227 if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) {
235 err("cannot allocate memory for new pad"); 228 err("cannot allocate memory for new pad");
236 return -ENOMEM; 229 return -ENOMEM;
237 } 230 }
238 memset(xpad, 0, sizeof(struct usb_xpad)); 231 memset(xpad, 0, sizeof(struct usb_xpad));
239 232
240 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 233 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
241 SLAB_ATOMIC, &xpad->idata_dma); 234 SLAB_ATOMIC, &xpad->idata_dma);
242 if (!xpad->idata) { 235 if (!xpad->idata) {
@@ -251,18 +244,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
251 kfree(xpad); 244 kfree(xpad);
252 return -ENOMEM; 245 return -ENOMEM;
253 } 246 }
254 247
255 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; 248 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
256 249
257 usb_fill_int_urb(xpad->irq_in, udev, 250 usb_fill_int_urb(xpad->irq_in, udev,
258 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), 251 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
259 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, 252 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
260 xpad, ep_irq_in->bInterval); 253 xpad, ep_irq_in->bInterval);
261 xpad->irq_in->transfer_dma = xpad->idata_dma; 254 xpad->irq_in->transfer_dma = xpad->idata_dma;
262 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 255 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
263 256
264 xpad->udev = udev; 257 xpad->udev = udev;
265 258
266 xpad->dev.id.bustype = BUS_USB; 259 xpad->dev.id.bustype = BUS_USB;
267 xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 260 xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
268 xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct); 261 xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct);
@@ -273,21 +266,21 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
273 xpad->dev.phys = xpad->phys; 266 xpad->dev.phys = xpad->phys;
274 xpad->dev.open = xpad_open; 267 xpad->dev.open = xpad_open;
275 xpad->dev.close = xpad_close; 268 xpad->dev.close = xpad_close;
276 269
277 usb_make_path(udev, path, 64); 270 usb_make_path(udev, path, 64);
278 snprintf(xpad->phys, 64, "%s/input0", path); 271 snprintf(xpad->phys, 64, "%s/input0", path);
279 272
280 xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 273 xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
281 274
282 for (i = 0; xpad_btn[i] >= 0; i++) 275 for (i = 0; xpad_btn[i] >= 0; i++)
283 set_bit(xpad_btn[i], xpad->dev.keybit); 276 set_bit(xpad_btn[i], xpad->dev.keybit);
284 277
285 for (i = 0; xpad_abs[i] >= 0; i++) { 278 for (i = 0; xpad_abs[i] >= 0; i++) {
286 279
287 signed short t = xpad_abs[i]; 280 signed short t = xpad_abs[i];
288 281
289 set_bit(t, xpad->dev.absbit); 282 set_bit(t, xpad->dev.absbit);
290 283
291 switch (t) { 284 switch (t) {
292 case ABS_X: 285 case ABS_X:
293 case ABS_Y: 286 case ABS_Y:
@@ -310,11 +303,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
310 break; 303 break;
311 } 304 }
312 } 305 }
313 306
314 input_register_device(&xpad->dev); 307 input_register_device(&xpad->dev);
315 308
316 printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); 309 printk(KERN_INFO "input: %s on %s", xpad->dev.name, path);
317 310
318 usb_set_intfdata(intf, xpad); 311 usb_set_intfdata(intf, xpad);
319 return 0; 312 return 0;
320} 313}
@@ -322,7 +315,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
322static void xpad_disconnect(struct usb_interface *intf) 315static void xpad_disconnect(struct usb_interface *intf)
323{ 316{
324 struct usb_xpad *xpad = usb_get_intfdata (intf); 317 struct usb_xpad *xpad = usb_get_intfdata (intf);
325 318
326 usb_set_intfdata(intf, NULL); 319 usb_set_intfdata(intf, NULL);
327 if (xpad) { 320 if (xpad) {
328 usb_kill_urb(xpad->irq_in); 321 usb_kill_urb(xpad->irq_in);
diff --git a/drivers/usb/media/Makefile b/drivers/usb/media/Makefile
index 2b76df7005fe..d83adffa925f 100644
--- a/drivers/usb/media/Makefile
+++ b/drivers/usb/media/Makefile
@@ -2,7 +2,7 @@
2# Makefile for USB Media drivers 2# Makefile for USB Media drivers
3# 3#
4 4
5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o sn9c102_pas106b.o sn9c102_pas202bcb.o sn9c102_tas5110c1b.o sn9c102_tas5130d1b.o 5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bcb.o sn9c102_tas5110c1b.o sn9c102_tas5130d1b.o
6 6
7obj-$(CONFIG_USB_DABUSB) += dabusb.o 7obj-$(CONFIG_USB_DABUSB) += dabusb.o
8obj-$(CONFIG_USB_DSBR) += dsbr100.o 8obj-$(CONFIG_USB_DSBR) += dsbr100.o
diff --git a/drivers/usb/media/sn9c102.h b/drivers/usb/media/sn9c102.h
index 8b8a4c8743f8..e5cea0e2eb57 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/usb/media/sn9c102.h
@@ -56,7 +56,7 @@
56#define SN9C102_MODULE_AUTHOR "(C) 2004-2005 Luca Risolia" 56#define SN9C102_MODULE_AUTHOR "(C) 2004-2005 Luca Risolia"
57#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 57#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
58#define SN9C102_MODULE_LICENSE "GPL" 58#define SN9C102_MODULE_LICENSE "GPL"
59#define SN9C102_MODULE_VERSION "1:1.24" 59#define SN9C102_MODULE_VERSION "1:1.24a"
60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 24) 60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 24)
61 61
62enum sn9c102_bridge { 62enum sn9c102_bridge {
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index 31d57400d5be..cf8cfbabefde 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -429,7 +429,7 @@ sn9c102_i2c_try_read(struct sn9c102_device* cam,
429} 429}
430 430
431 431
432static int 432int
433sn9c102_i2c_try_write(struct sn9c102_device* cam, 433sn9c102_i2c_try_write(struct sn9c102_device* cam,
434 struct sn9c102_sensor* sensor, u8 address, u8 value) 434 struct sn9c102_sensor* sensor, u8 address, u8 value)
435{ 435{
diff --git a/drivers/usb/media/sn9c102_ov7630.c b/drivers/usb/media/sn9c102_ov7630.c
new file mode 100644
index 000000000000..d27c5aedeaf8
--- /dev/null
+++ b/drivers/usb/media/sn9c102_ov7630.c
@@ -0,0 +1,394 @@
1/***************************************************************************
2 * Plug-in for OV7630 image sensor connected to the SN9C10x PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2005 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include "sn9c102_sensor.h"
23
24
25static struct sn9c102_sensor ov7630;
26
27
28static int ov7630_init(struct sn9c102_device* cam)
29{
30 int err = 0;
31
32 err += sn9c102_write_reg(cam, 0x00, 0x14);
33 err += sn9c102_write_reg(cam, 0x60, 0x17);
34 err += sn9c102_write_reg(cam, 0x0f, 0x18);
35 err += sn9c102_write_reg(cam, 0x50, 0x19);
36
37 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
38 err += sn9c102_i2c_write(cam, 0x11, 0x00);
39 err += sn9c102_i2c_write(cam, 0x15, 0x34);
40 err += sn9c102_i2c_write(cam, 0x16, 0x03);
41 err += sn9c102_i2c_write(cam, 0x17, 0x1c);
42 err += sn9c102_i2c_write(cam, 0x18, 0xbd);
43 err += sn9c102_i2c_write(cam, 0x19, 0x06);
44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6);
45 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
46 err += sn9c102_i2c_write(cam, 0x20, 0x44);
47 err += sn9c102_i2c_write(cam, 0x23, 0xee);
48 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
49 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
50 err += sn9c102_i2c_write(cam, 0x28, 0x20);
51 err += sn9c102_i2c_write(cam, 0x29, 0x30);
52 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
53 err += sn9c102_i2c_write(cam, 0x30, 0x24);
54 err += sn9c102_i2c_write(cam, 0x32, 0x86);
55 err += sn9c102_i2c_write(cam, 0x60, 0xa9);
56 err += sn9c102_i2c_write(cam, 0x61, 0x42);
57 err += sn9c102_i2c_write(cam, 0x65, 0x00);
58 err += sn9c102_i2c_write(cam, 0x69, 0x38);
59 err += sn9c102_i2c_write(cam, 0x6f, 0x88);
60 err += sn9c102_i2c_write(cam, 0x70, 0x0b);
61 err += sn9c102_i2c_write(cam, 0x71, 0x00);
62 err += sn9c102_i2c_write(cam, 0x74, 0x21);
63 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
64
65 return err;
66}
67
68
69static int ov7630_set_ctrl(struct sn9c102_device* cam,
70 const struct v4l2_control* ctrl)
71{
72 int err = 0;
73
74 switch (ctrl->id) {
75 case V4L2_CID_EXPOSURE:
76 err += sn9c102_i2c_write(cam, 0x10, ctrl->value >> 2);
77 err += sn9c102_i2c_write(cam, 0x76, ctrl->value & 0x03);
78 break;
79 case V4L2_CID_RED_BALANCE:
80 err += sn9c102_i2c_write(cam, 0x02, ctrl->value);
81 break;
82 case V4L2_CID_BLUE_BALANCE:
83 err += sn9c102_i2c_write(cam, 0x03, ctrl->value);
84 break;
85 case V4L2_CID_GAIN:
86 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
87 break;
88 case V4L2_CID_CONTRAST:
89 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05,
90 (ctrl->value-1) | 0x20)
91 : sn9c102_i2c_write(cam, 0x05, 0x00);
92 break;
93 case V4L2_CID_BRIGHTNESS:
94 err += sn9c102_i2c_write(cam, 0x06, ctrl->value);
95 break;
96 case V4L2_CID_SATURATION:
97 err += sn9c102_i2c_write(cam, 0x03, ctrl->value << 4);
98 break;
99 case V4L2_CID_HUE:
100 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04,
101 (ctrl->value-1) | 0x20)
102 : sn9c102_i2c_write(cam, 0x04, 0x00);
103 break;
104 case V4L2_CID_DO_WHITE_BALANCE:
105 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
106 break;
107 case V4L2_CID_WHITENESS:
108 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value);
109 break;
110 case V4L2_CID_AUTO_WHITE_BALANCE:
111 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x09);
112 break;
113 case V4L2_CID_AUTOGAIN:
114 err += sn9c102_i2c_write(cam, 0x13, ctrl->value);
115 break;
116 case V4L2_CID_VFLIP:
117 err += sn9c102_i2c_write(cam, 0x75, 0x0e | (ctrl->value << 7));
118 break;
119 case V4L2_CID_BLACK_LEVEL:
120 err += sn9c102_i2c_write(cam, 0x25, ctrl->value);
121 break;
122 case SN9C102_V4L2_CID_BRIGHT_LEVEL:
123 err += sn9c102_i2c_write(cam, 0x24, ctrl->value);
124 break;
125 case SN9C102_V4L2_CID_GAMMA:
126 err += sn9c102_i2c_write(cam, 0x14, (ctrl->value << 2) | 0x80);
127 break;
128 case SN9C102_V4L2_CID_BAND_FILTER:
129 err += sn9c102_i2c_write(cam, 0x2d, ctrl->value << 2);
130 break;
131 default:
132 return -EINVAL;
133 }
134
135 return err ? -EIO : 0;
136}
137
138
139static int ov7630_set_crop(struct sn9c102_device* cam,
140 const struct v4l2_rect* rect)
141{
142 struct sn9c102_sensor* s = &ov7630;
143 int err = 0;
144 u8 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
145
146 err += sn9c102_write_reg(cam, v_start, 0x13);
147
148 return err;
149}
150
151
152static int ov7630_set_pix_format(struct sn9c102_device* cam,
153 const struct v4l2_pix_format* pix)
154{
155 int err = 0;
156
157 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
158 err += sn9c102_write_reg(cam, 0x20, 0x19);
159 else
160 err += sn9c102_write_reg(cam, 0x50, 0x19);
161
162 return err;
163}
164
165
166static struct sn9c102_sensor ov7630 = {
167 .name = "OV7630",
168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
169 .sysfs_ops = SN9C102_I2C_WRITE,
170 .frequency = SN9C102_I2C_100KHZ,
171 .interface = SN9C102_I2C_2WIRES,
172 .i2c_slave_id = 0x21,
173 .init = &ov7630_init,
174 .qctrl = {
175 {
176 .id = V4L2_CID_GAIN,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "global gain",
179 .minimum = 0x00,
180 .maximum = 0x3f,
181 .step = 0x01,
182 .default_value = 0x14,
183 .flags = 0,
184 },
185 {
186 .id = V4L2_CID_HUE,
187 .type = V4L2_CTRL_TYPE_INTEGER,
188 .name = "hue",
189 .minimum = 0x00,
190 .maximum = 0x1f+1,
191 .step = 0x01,
192 .default_value = 0x00,
193 .flags = 0,
194 },
195 {
196 .id = V4L2_CID_SATURATION,
197 .type = V4L2_CTRL_TYPE_INTEGER,
198 .name = "saturation",
199 .minimum = 0x00,
200 .maximum = 0x0f,
201 .step = 0x01,
202 .default_value = 0x08,
203 .flags = 0,
204 },
205 {
206 .id = V4L2_CID_CONTRAST,
207 .type = V4L2_CTRL_TYPE_INTEGER,
208 .name = "contrast",
209 .minimum = 0x00,
210 .maximum = 0x1f+1,
211 .step = 0x01,
212 .default_value = 0x00,
213 .flags = 0,
214 },
215 {
216 .id = V4L2_CID_EXPOSURE,
217 .type = V4L2_CTRL_TYPE_INTEGER,
218 .name = "exposure",
219 .minimum = 0x000,
220 .maximum = 0x3ff,
221 .step = 0x001,
222 .default_value = 0x83<<2,
223 .flags = 0,
224 },
225 {
226 .id = V4L2_CID_RED_BALANCE,
227 .type = V4L2_CTRL_TYPE_INTEGER,
228 .name = "red balance",
229 .minimum = 0x00,
230 .maximum = 0xff,
231 .step = 0x01,
232 .default_value = 0x3a,
233 .flags = 0,
234 },
235 {
236 .id = V4L2_CID_BLUE_BALANCE,
237 .type = V4L2_CTRL_TYPE_INTEGER,
238 .name = "blue balance",
239 .minimum = 0x00,
240 .maximum = 0xff,
241 .step = 0x01,
242 .default_value = 0x77,
243 .flags = 0,
244 },
245 {
246 .id = V4L2_CID_BRIGHTNESS,
247 .type = V4L2_CTRL_TYPE_INTEGER,
248 .name = "brightness",
249 .minimum = 0x00,
250 .maximum = 0xff,
251 .step = 0x01,
252 .default_value = 0xa0,
253 .flags = 0,
254 },
255 {
256 .id = V4L2_CID_DO_WHITE_BALANCE,
257 .type = V4L2_CTRL_TYPE_INTEGER,
258 .name = "white balance background: blue",
259 .minimum = 0x00,
260 .maximum = 0x3f,
261 .step = 0x01,
262 .default_value = 0x20,
263 .flags = 0,
264 },
265 {
266 .id = V4L2_CID_WHITENESS,
267 .type = V4L2_CTRL_TYPE_INTEGER,
268 .name = "white balance background: red",
269 .minimum = 0x00,
270 .maximum = 0x3f,
271 .step = 0x01,
272 .default_value = 0x20,
273 .flags = 0,
274 },
275 {
276 .id = V4L2_CID_AUTO_WHITE_BALANCE,
277 .type = V4L2_CTRL_TYPE_BOOLEAN,
278 .name = "auto white balance",
279 .minimum = 0x00,
280 .maximum = 0x01,
281 .step = 0x01,
282 .default_value = 0x01,
283 .flags = 0,
284 },
285 {
286 .id = V4L2_CID_AUTOGAIN,
287 .type = V4L2_CTRL_TYPE_INTEGER,
288 .name = "gain & exposure mode",
289 .minimum = 0x00,
290 .maximum = 0x03,
291 .step = 0x01,
292 .default_value = 0x00,
293 .flags = 0,
294 },
295 {
296 .id = V4L2_CID_VFLIP,
297 .type = V4L2_CTRL_TYPE_BOOLEAN,
298 .name = "vertical flip",
299 .minimum = 0x00,
300 .maximum = 0x01,
301 .step = 0x01,
302 .default_value = 0x01,
303 .flags = 0,
304 },
305 {
306 .id = V4L2_CID_BLACK_LEVEL,
307 .type = V4L2_CTRL_TYPE_INTEGER,
308 .name = "black pixel ratio",
309 .minimum = 0x01,
310 .maximum = 0x9a,
311 .step = 0x01,
312 .default_value = 0x8a,
313 .flags = 0,
314 },
315 {
316 .id = SN9C102_V4L2_CID_BRIGHT_LEVEL,
317 .type = V4L2_CTRL_TYPE_INTEGER,
318 .name = "bright pixel ratio",
319 .minimum = 0x01,
320 .maximum = 0x9a,
321 .step = 0x01,
322 .default_value = 0x10,
323 .flags = 0,
324 },
325 {
326 .id = SN9C102_V4L2_CID_BAND_FILTER,
327 .type = V4L2_CTRL_TYPE_BOOLEAN,
328 .name = "band filter",
329 .minimum = 0x00,
330 .maximum = 0x01,
331 .step = 0x01,
332 .default_value = 0x00,
333 .flags = 0,
334 },
335 {
336 .id = SN9C102_V4L2_CID_GAMMA,
337 .type = V4L2_CTRL_TYPE_BOOLEAN,
338 .name = "rgb gamma",
339 .minimum = 0x00,
340 .maximum = 0x01,
341 .step = 0x01,
342 .default_value = 0x00,
343 .flags = 0,
344 },
345 },
346 .set_ctrl = &ov7630_set_ctrl,
347 .cropcap = {
348 .bounds = {
349 .left = 0,
350 .top = 0,
351 .width = 640,
352 .height = 480,
353 },
354 .defrect = {
355 .left = 0,
356 .top = 0,
357 .width = 640,
358 .height = 480,
359 },
360 },
361 .set_crop = &ov7630_set_crop,
362 .pix_format = {
363 .width = 640,
364 .height = 480,
365 .pixelformat = V4L2_PIX_FMT_SBGGR8,
366 .priv = 8,
367 },
368 .set_pix_format = &ov7630_set_pix_format
369};
370
371
372int sn9c102_probe_ov7630(struct sn9c102_device* cam)
373{
374 int err = 0;
375
376 sn9c102_attach_sensor(cam, &ov7630);
377
378 if (le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x608f &&
379 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x602c)
380 return -ENODEV;
381
382 err += sn9c102_write_reg(cam, 0x01, 0x01);
383 err += sn9c102_write_reg(cam, 0x00, 0x01);
384 err += sn9c102_write_reg(cam, 0x28, 0x17);
385
386 if (err)
387 return -EIO;
388
389 err += sn9c102_i2c_write(cam, 0x0b, 0);
390 if (err)
391 return -ENODEV;
392
393 return 0;
394}
diff --git a/drivers/usb/media/sn9c102_sensor.h b/drivers/usb/media/sn9c102_sensor.h
index 6a7adebcb4bf..a45166c3488c 100644
--- a/drivers/usb/media/sn9c102_sensor.h
+++ b/drivers/usb/media/sn9c102_sensor.h
@@ -64,6 +64,7 @@ struct sn9c102_sensor;
64*/ 64*/
65extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam); 65extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam); 66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
67extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
67extern int sn9c102_probe_pas106b(struct sn9c102_device* cam); 68extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
68extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam); 69extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam);
69extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam); 70extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
@@ -80,6 +81,7 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = { \
80 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \ 81 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \
81 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \ 82 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \
82 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \ 83 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \
84 &sn9c102_probe_ov7630, /* detection mostly based on USB pid/vid */ \
83 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \ 85 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \
84 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \ 86 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \
85 NULL, \ 87 NULL, \
@@ -103,7 +105,8 @@ static const struct usb_device_id sn9c102_id_table[] = { \
103 { USB_DEVICE(0x0c45, 0x6029), }, /* PAS106B */ \ 105 { USB_DEVICE(0x0c45, 0x6029), }, /* PAS106B */ \
104 { USB_DEVICE(0x0c45, 0x602a), }, /* HV7131D */ \ 106 { USB_DEVICE(0x0c45, 0x602a), }, /* HV7131D */ \
105 { USB_DEVICE(0x0c45, 0x602b), }, /* MI-0343 */ \ 107 { USB_DEVICE(0x0c45, 0x602b), }, /* MI-0343 */ \
106 { USB_DEVICE(0x0c45, 0x602c), }, /* OV7620 */ \ 108 { USB_DEVICE(0x0c45, 0x602c), }, /* OV7630 */ \
109 { USB_DEVICE(0x0c45, 0x602d), }, \
107 { USB_DEVICE(0x0c45, 0x6030), }, /* MI03x */ \ 110 { USB_DEVICE(0x0c45, 0x6030), }, /* MI03x */ \
108 { USB_DEVICE(0x0c45, 0x6080), }, \ 111 { USB_DEVICE(0x0c45, 0x6080), }, \
109 { USB_DEVICE(0x0c45, 0x6082), }, /* MI0343 and MI0360 */ \ 112 { USB_DEVICE(0x0c45, 0x6082), }, /* MI0343 and MI0360 */ \
@@ -145,6 +148,8 @@ static const struct usb_device_id sn9c102_id_table[] = { \
145*/ 148*/
146 149
147/* The "try" I2C I/O versions are used when probing the sensor */ 150/* The "try" I2C I/O versions are used when probing the sensor */
151extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*,
152 u8 address, u8 value);
148extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*, 153extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
149 u8 address); 154 u8 address);
150 155
@@ -201,6 +206,8 @@ enum sn9c102_i2c_interface {
201 SN9C102_I2C_3WIRES, 206 SN9C102_I2C_3WIRES,
202}; 207};
203 208
209#define SN9C102_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10
210
204struct sn9c102_sensor { 211struct sn9c102_sensor {
205 char name[32], /* sensor name */ 212 char name[32], /* sensor name */
206 maintainer[64]; /* name of the mantainer <email> */ 213 maintainer[64]; /* name of the mantainer <email> */
@@ -243,7 +250,7 @@ struct sn9c102_sensor {
243 sensor according to the default configuration structures below. 250 sensor according to the default configuration structures below.
244 */ 251 */
245 252
246 struct v4l2_queryctrl qctrl[V4L2_CID_LASTP1-V4L2_CID_BASE]; 253 struct v4l2_queryctrl qctrl[SN9C102_MAX_CTRLS];
247 /* 254 /*
248 Optional list of default controls, defined as indicated in the 255 Optional list of default controls, defined as indicated in the
249 V4L2 API. Menu type controls are not handled by this interface. 256 V4L2 API. Menu type controls are not handled by this interface.
@@ -356,7 +363,7 @@ struct sn9c102_sensor {
356 core module to store successfully updated values of the above 363 core module to store successfully updated values of the above
357 settings, for rollbacks..etc..in case of errors during atomic I/O 364 settings, for rollbacks..etc..in case of errors during atomic I/O
358 */ 365 */
359 struct v4l2_queryctrl _qctrl[V4L2_CID_LASTP1-V4L2_CID_BASE]; 366 struct v4l2_queryctrl _qctrl[SN9C102_MAX_CTRLS];
360 struct v4l2_rect _rect; 367 struct v4l2_rect _rect;
361}; 368};
362 369
@@ -367,5 +374,8 @@ struct sn9c102_sensor {
367#define SN9C102_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1 374#define SN9C102_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1
368#define SN9C102_V4L2_CID_RESET_LEVEL V4L2_CID_PRIVATE_BASE + 2 375#define SN9C102_V4L2_CID_RESET_LEVEL V4L2_CID_PRIVATE_BASE + 2
369#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE V4L2_CID_PRIVATE_BASE + 3 376#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE V4L2_CID_PRIVATE_BASE + 3
377#define SN9C102_V4L2_CID_GAMMA V4L2_CID_PRIVATE_BASE + 4
378#define SN9C102_V4L2_CID_BAND_FILTER V4L2_CID_PRIVATE_BASE + 5
379#define SN9C102_V4L2_CID_BRIGHT_LEVEL V4L2_CID_PRIVATE_BASE + 6
370 380
371#endif /* _SN9C102_SENSOR_H_ */ 381#endif /* _SN9C102_SENSOR_H_ */
diff --git a/drivers/usb/media/sn9c102_tas5110c1b.c b/drivers/usb/media/sn9c102_tas5110c1b.c
index 690d62192273..8775999b5aff 100644
--- a/drivers/usb/media/sn9c102_tas5110c1b.c
+++ b/drivers/usb/media/sn9c102_tas5110c1b.c
@@ -24,8 +24,6 @@
24 24
25static struct sn9c102_sensor tas5110c1b; 25static struct sn9c102_sensor tas5110c1b;
26 26
27static struct v4l2_control tas5110c1b_gain;
28
29 27
30static int tas5110c1b_init(struct sn9c102_device* cam) 28static int tas5110c1b_init(struct sn9c102_device* cam)
31{ 29{
@@ -46,21 +44,6 @@ static int tas5110c1b_init(struct sn9c102_device* cam)
46} 44}
47 45
48 46
49static int tas5110c1b_get_ctrl(struct sn9c102_device* cam,
50 struct v4l2_control* ctrl)
51{
52 switch (ctrl->id) {
53 case V4L2_CID_GAIN:
54 ctrl->value = tas5110c1b_gain.value;
55 break;
56 default:
57 return -EINVAL;
58 }
59
60 return 0;
61}
62
63
64static int tas5110c1b_set_ctrl(struct sn9c102_device* cam, 47static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
65 const struct v4l2_control* ctrl) 48 const struct v4l2_control* ctrl)
66{ 49{
@@ -68,8 +51,7 @@ static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
68 51
69 switch (ctrl->id) { 52 switch (ctrl->id) {
70 case V4L2_CID_GAIN: 53 case V4L2_CID_GAIN:
71 if (!(err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value))) 54 err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value);
72 tas5110c1b_gain.value = ctrl->value;
73 break; 55 break;
74 default: 56 default:
75 return -EINVAL; 57 return -EINVAL;
@@ -147,7 +129,6 @@ static struct sn9c102_sensor tas5110c1b = {
147 .height = 288, 129 .height = 288,
148 }, 130 },
149 }, 131 },
150 .get_ctrl = &tas5110c1b_get_ctrl,
151 .set_crop = &tas5110c1b_set_crop, 132 .set_crop = &tas5110c1b_set_crop,
152 .pix_format = { 133 .pix_format = {
153 .width = 352, 134 .width = 352,
diff --git a/drivers/usb/media/sn9c102_tas5130d1b.c b/drivers/usb/media/sn9c102_tas5130d1b.c
index b378e941bbe8..927eafdd8c73 100644
--- a/drivers/usb/media/sn9c102_tas5130d1b.c
+++ b/drivers/usb/media/sn9c102_tas5130d1b.c
@@ -24,8 +24,6 @@
24 24
25static struct sn9c102_sensor tas5130d1b; 25static struct sn9c102_sensor tas5130d1b;
26 26
27static struct v4l2_control tas5130d1b_gain, tas5130d1b_exposure;
28
29 27
30static int tas5130d1b_init(struct sn9c102_device* cam) 28static int tas5130d1b_init(struct sn9c102_device* cam)
31{ 29{
@@ -44,24 +42,6 @@ static int tas5130d1b_init(struct sn9c102_device* cam)
44} 42}
45 43
46 44
47static int tas5130d1b_get_ctrl(struct sn9c102_device* cam,
48 struct v4l2_control* ctrl)
49{
50 switch (ctrl->id) {
51 case V4L2_CID_GAIN:
52 ctrl->value = tas5130d1b_gain.value;
53 break;
54 case V4L2_CID_EXPOSURE:
55 ctrl->value = tas5130d1b_exposure.value;
56 break;
57 default:
58 return -EINVAL;
59 }
60
61 return 0;
62}
63
64
65static int tas5130d1b_set_ctrl(struct sn9c102_device* cam, 45static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
66 const struct v4l2_control* ctrl) 46 const struct v4l2_control* ctrl)
67{ 47{
@@ -69,12 +49,10 @@ static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
69 49
70 switch (ctrl->id) { 50 switch (ctrl->id) {
71 case V4L2_CID_GAIN: 51 case V4L2_CID_GAIN:
72 if (!(err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value))) 52 err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value);
73 tas5130d1b_gain.value = ctrl->value;
74 break; 53 break;
75 case V4L2_CID_EXPOSURE: 54 case V4L2_CID_EXPOSURE:
76 if (!(err += sn9c102_i2c_write(cam, 0x40, 0x47 - ctrl->value))) 55 err += sn9c102_i2c_write(cam, 0x40, 0x47 - ctrl->value);
77 tas5130d1b_exposure.value = ctrl->value;
78 break; 56 break;
79 default: 57 default:
80 return -EINVAL; 58 return -EINVAL;
@@ -147,7 +125,6 @@ static struct sn9c102_sensor tas5130d1b = {
147 .flags = 0, 125 .flags = 0,
148 }, 126 },
149 }, 127 },
150 .get_ctrl = &tas5130d1b_get_ctrl,
151 .set_ctrl = &tas5130d1b_set_ctrl, 128 .set_ctrl = &tas5130d1b_set_ctrl,
152 .cropcap = { 129 .cropcap = {
153 .bounds = { 130 .bounds = {
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index ae455c8e3702..7398a7f19c1e 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -1375,9 +1375,13 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1375 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) { 1375 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) {
1376 camera_name = "STV0680"; 1376 camera_name = "STV0680";
1377 PDEBUG (0, "STV(i): STV0680 camera found."); 1377 PDEBUG (0, "STV(i): STV0680 camera found.");
1378 } else if ((le16_to_cpu(dev->descriptor.idVendor) == USB_CREATIVEGOMINI_VENDOR_ID) &&
1379 (le16_to_cpu(dev->descriptor.idProduct) == USB_CREATIVEGOMINI_PRODUCT_ID)) {
1380 camera_name = "Creative WebCam Go Mini";
1381 PDEBUG (0, "STV(i): Creative WebCam Go Mini found.");
1378 } else { 1382 } else {
1379 PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 values."); 1383 PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 or Creative WebCam Go Mini values.");
1380 PDEBUG (0, "STV(e): Check that the STV0680 camera is connected to the computer."); 1384 PDEBUG (0, "STV(e): Check that the STV0680 or Creative WebCam Go Mini camera is connected to the computer.");
1381 retval = -ENODEV; 1385 retval = -ENODEV;
1382 goto error; 1386 goto error;
1383 } 1387 }
diff --git a/drivers/usb/media/stv680.h b/drivers/usb/media/stv680.h
index 7e0e314dcf12..445940612603 100644
--- a/drivers/usb/media/stv680.h
+++ b/drivers/usb/media/stv680.h
@@ -41,12 +41,17 @@
41 41
42#define USB_PENCAM_VENDOR_ID 0x0553 42#define USB_PENCAM_VENDOR_ID 0x0553
43#define USB_PENCAM_PRODUCT_ID 0x0202 43#define USB_PENCAM_PRODUCT_ID 0x0202
44
45#define USB_CREATIVEGOMINI_VENDOR_ID 0x041e
46#define USB_CREATIVEGOMINI_PRODUCT_ID 0x4007
47
44#define PENCAM_TIMEOUT 1000 48#define PENCAM_TIMEOUT 1000
45/* fmt 4 */ 49/* fmt 4 */
46#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24 50#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24
47 51
48static struct usb_device_id device_table[] = { 52static struct usb_device_id device_table[] = {
49 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)}, 53 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)},
54 {USB_DEVICE (USB_CREATIVEGOMINI_VENDOR_ID, USB_CREATIVEGOMINI_PRODUCT_ID)},
50 {} 55 {}
51}; 56};
52MODULE_DEVICE_TABLE (usb, device_table); 57MODULE_DEVICE_TABLE (usb, device_table);
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 3a896954b3a9..6649531fa824 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -139,6 +139,16 @@ config USB_IDMOUSE
139 139
140source "drivers/usb/misc/sisusbvga/Kconfig" 140source "drivers/usb/misc/sisusbvga/Kconfig"
141 141
142config USB_LD
143 tristate "USB LD driver"
144 depends on USB && EXPERIMENTAL
145 help
146 This driver is for generic USB devices that use interrupt transfers,
147 like LD Didactic's USB devices.
148
149 To compile this driver as a module, choose M here: the
150 module will be called ldusb.
151
142config USB_TEST 152config USB_TEST
143 tristate "USB testing driver (DEVELOPMENT)" 153 tristate "USB testing driver (DEVELOPMENT)"
144 depends on USB && USB_DEVICEFS && EXPERIMENTAL 154 depends on USB && USB_DEVICEFS && EXPERIMENTAL
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 4a3814cbd48d..862e40a83689 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB_EMI26) += emi26.o
9obj-$(CONFIG_USB_EMI62) += emi62.o 9obj-$(CONFIG_USB_EMI62) += emi62.o
10obj-$(CONFIG_USB_IDMOUSE) += idmouse.o 10obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
11obj-$(CONFIG_USB_LCD) += usblcd.o 11obj-$(CONFIG_USB_LCD) += usblcd.o
12obj-$(CONFIG_USB_LD) += ldusb.o
12obj-$(CONFIG_USB_LED) += usbled.o 13obj-$(CONFIG_USB_LED) += usbled.o
13obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 14obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
14obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o 15obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index ce030d1f1c1f..733acc213726 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -1,4 +1,4 @@
1/* Siemens ID Mouse driver v0.5 1/* Siemens ID Mouse driver v0.6
2 2
3 This program is free software; you can redistribute it and/or 3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as 4 modify it under the terms of the GNU General Public License as
@@ -11,6 +11,9 @@
11 Derived from the USB Skeleton driver 1.1, 11 Derived from the USB Skeleton driver 1.1,
12 Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com) 12 Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com)
13 13
14 Additional information provided by Martin Reising
15 <Martin.Reising@natural-computing.de>
16
14*/ 17*/
15 18
16#include <linux/config.h> 19#include <linux/config.h>
@@ -25,29 +28,44 @@
25#include <asm/uaccess.h> 28#include <asm/uaccess.h>
26#include <linux/usb.h> 29#include <linux/usb.h>
27 30
31/* image constants */
28#define WIDTH 225 32#define WIDTH 225
29#define HEIGHT 288 33#define HEIGHT 289
30#define HEADER "P5 225 288 255 " 34#define HEADER "P5 225 289 255 "
31#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1) 35#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1)
32 36
33/* Version Information */ 37/* version information */
34#define DRIVER_VERSION "0.5" 38#define DRIVER_VERSION "0.6"
35#define DRIVER_SHORT "idmouse" 39#define DRIVER_SHORT "idmouse"
36#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>" 40#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>"
37#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver" 41#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver"
38 42
39/* Siemens ID Mouse */ 43/* minor number for misc USB devices */
40#define USB_IDMOUSE_VENDOR_ID 0x0681
41#define USB_IDMOUSE_PRODUCT_ID 0x0005
42
43/* we still need a minor number */
44#define USB_IDMOUSE_MINOR_BASE 132 44#define USB_IDMOUSE_MINOR_BASE 132
45 45
46/* vendor and device IDs */
47#define ID_SIEMENS 0x0681
48#define ID_IDMOUSE 0x0005
49#define ID_CHERRY 0x0010
50
51/* device ID table */
46static struct usb_device_id idmouse_table[] = { 52static struct usb_device_id idmouse_table[] = {
47 {USB_DEVICE(USB_IDMOUSE_VENDOR_ID, USB_IDMOUSE_PRODUCT_ID)}, 53 {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */
48 {} /* null entry at the end */ 54 {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */
55 {} /* terminating null entry */
49}; 56};
50 57
58/* sensor commands */
59#define FTIP_RESET 0x20
60#define FTIP_ACQUIRE 0x21
61#define FTIP_RELEASE 0x22
62#define FTIP_BLINK 0x23 /* LSB of value = blink pulse width */
63#define FTIP_SCROLL 0x24
64
65#define ftip_command(dev, command, value, index) \
66 usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), command, \
67 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000)
68
51MODULE_DEVICE_TABLE(usb, idmouse_table); 69MODULE_DEVICE_TABLE(usb, idmouse_table);
52 70
53/* structure to hold all of our device specific stuff */ 71/* structure to hold all of our device specific stuff */
@@ -57,7 +75,8 @@ struct usb_idmouse {
57 struct usb_interface *interface; /* the interface for this device */ 75 struct usb_interface *interface; /* the interface for this device */
58 76
59 unsigned char *bulk_in_buffer; /* the buffer to receive data */ 77 unsigned char *bulk_in_buffer; /* the buffer to receive data */
60 size_t bulk_in_size; /* the size of the receive buffer */ 78 size_t bulk_in_size; /* the maximum bulk packet size */
79 size_t orig_bi_size; /* same as above, but reported by the device */
61 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 80 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
62 81
63 int open; /* if the port is open or not */ 82 int open; /* if the port is open or not */
@@ -103,7 +122,7 @@ static struct usb_driver idmouse_driver = {
103 .id_table = idmouse_table, 122 .id_table = idmouse_table,
104}; 123};
105 124
106// prevent races between open() and disconnect() 125/* prevent races between open() and disconnect() */
107static DECLARE_MUTEX(disconnect_sem); 126static DECLARE_MUTEX(disconnect_sem);
108 127
109static int idmouse_create_image(struct usb_idmouse *dev) 128static int idmouse_create_image(struct usb_idmouse *dev)
@@ -112,42 +131,34 @@ static int idmouse_create_image(struct usb_idmouse *dev)
112 int bulk_read = 0; 131 int bulk_read = 0;
113 int result = 0; 132 int result = 0;
114 133
115 if (dev->bulk_in_size < sizeof(HEADER)) 134 memcpy(dev->bulk_in_buffer, HEADER, sizeof(HEADER)-1);
116 return -ENOMEM;
117
118 memcpy(dev->bulk_in_buffer,HEADER,sizeof(HEADER)-1);
119 bytes_read += sizeof(HEADER)-1; 135 bytes_read += sizeof(HEADER)-1;
120 136
121 /* Dump the setup packets. Yes, they are uncommented, simply 137 /* reset the device and set a fast blink rate */
122 because they were sniffed under Windows using SnoopyPro. 138 result = ftip_command(dev, FTIP_RELEASE, 0, 0);
123 I _guess_ that 0x22 is a kind of reset command and 0x21
124 means init..
125 */
126 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
127 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
128 if (result < 0)
129 return result;
130 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0),
131 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
132 if (result < 0) 139 if (result < 0)
133 return result; 140 goto reset;
134 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 141 result = ftip_command(dev, FTIP_BLINK, 1, 0);
135 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000);
136 if (result < 0) 142 if (result < 0)
137 return result; 143 goto reset;
138 144
139 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 145 /* initialize the sensor - sending this command twice */
140 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 146 /* significantly reduces the rate of failed reads */
147 result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
141 if (result < 0) 148 if (result < 0)
142 return result; 149 goto reset;
143 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 150 result = ftip_command(dev, FTIP_ACQUIRE, 0, 0);
144 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000);
145 if (result < 0) 151 if (result < 0)
146 return result; 152 goto reset;
147 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 153
148 0x20, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 154 /* start the readout - sending this command twice */
155 /* presumably enables the high dynamic range mode */
156 result = ftip_command(dev, FTIP_RESET, 0, 0);
149 if (result < 0) 157 if (result < 0)
150 return result; 158 goto reset;
159 result = ftip_command(dev, FTIP_RESET, 0, 0);
160 if (result < 0)
161 goto reset;
151 162
152 /* loop over a blocking bulk read to get data from the device */ 163 /* loop over a blocking bulk read to get data from the device */
153 while (bytes_read < IMGSIZE) { 164 while (bytes_read < IMGSIZE) {
@@ -155,22 +166,40 @@ static int idmouse_create_image(struct usb_idmouse *dev)
155 usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), 166 usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr),
156 dev->bulk_in_buffer + bytes_read, 167 dev->bulk_in_buffer + bytes_read,
157 dev->bulk_in_size, &bulk_read, 5000); 168 dev->bulk_in_size, &bulk_read, 5000);
158 if (result < 0) 169 if (result < 0) {
159 return result; 170 /* Maybe this error was caused by the increased packet size? */
160 if (signal_pending(current)) 171 /* Reset to the original value and tell userspace to retry. */
161 return -EINTR; 172 if (dev->bulk_in_size != dev->orig_bi_size) {
173 dev->bulk_in_size = dev->orig_bi_size;
174 result = -EAGAIN;
175 }
176 break;
177 }
178 if (signal_pending(current)) {
179 result = -EINTR;
180 break;
181 }
162 bytes_read += bulk_read; 182 bytes_read += bulk_read;
163 } 183 }
164 184
165 /* reset the device */ 185 /* reset the device */
166 result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 186reset:
167 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 187 ftip_command(dev, FTIP_RELEASE, 0, 0);
168 if (result < 0) 188
169 return result; 189 /* check for valid image */
190 /* right border should be black (0x00) */
191 for (bytes_read = sizeof(HEADER)-1 + WIDTH-1; bytes_read < IMGSIZE; bytes_read += WIDTH)
192 if (dev->bulk_in_buffer[bytes_read] != 0x00)
193 return -EAGAIN;
170 194
171 /* should be IMGSIZE == 64815 */ 195 /* lower border should be white (0xFF) */
196 for (bytes_read = IMGSIZE-WIDTH; bytes_read < IMGSIZE-1; bytes_read++)
197 if (dev->bulk_in_buffer[bytes_read] != 0xFF)
198 return -EAGAIN;
199
200 /* should be IMGSIZE == 65040 */
172 dbg("read %d bytes fingerprint data", bytes_read); 201 dbg("read %d bytes fingerprint data", bytes_read);
173 return 0; 202 return result;
174} 203}
175 204
176static inline void idmouse_delete(struct usb_idmouse *dev) 205static inline void idmouse_delete(struct usb_idmouse *dev)
@@ -282,10 +311,10 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
282 311
283 dev = (struct usb_idmouse *) file->private_data; 312 dev = (struct usb_idmouse *) file->private_data;
284 313
285 // lock this object 314 /* lock this object */
286 down (&dev->sem); 315 down (&dev->sem);
287 316
288 // verify that the device wasn't unplugged 317 /* verify that the device wasn't unplugged */
289 if (!dev->present) { 318 if (!dev->present) {
290 up (&dev->sem); 319 up (&dev->sem);
291 return -ENODEV; 320 return -ENODEV;
@@ -296,8 +325,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
296 return 0; 325 return 0;
297 } 326 }
298 327
299 if (count > IMGSIZE - *ppos) 328 count = min ((loff_t)count, IMGSIZE - (*ppos));
300 count = IMGSIZE - *ppos;
301 329
302 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) { 330 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) {
303 result = -EFAULT; 331 result = -EFAULT;
@@ -306,7 +334,7 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
306 *ppos += count; 334 *ppos += count;
307 } 335 }
308 336
309 // unlock the device 337 /* unlock the device */
310 up(&dev->sem); 338 up(&dev->sem);
311 return result; 339 return result;
312} 340}
@@ -318,7 +346,6 @@ static int idmouse_probe(struct usb_interface *interface,
318 struct usb_idmouse *dev = NULL; 346 struct usb_idmouse *dev = NULL;
319 struct usb_host_interface *iface_desc; 347 struct usb_host_interface *iface_desc;
320 struct usb_endpoint_descriptor *endpoint; 348 struct usb_endpoint_descriptor *endpoint;
321 size_t buffer_size;
322 int result; 349 int result;
323 350
324 /* check if we have gotten the data or the hid interface */ 351 /* check if we have gotten the data or the hid interface */
@@ -344,11 +371,11 @@ static int idmouse_probe(struct usb_interface *interface,
344 USB_ENDPOINT_XFER_BULK)) { 371 USB_ENDPOINT_XFER_BULK)) {
345 372
346 /* we found a bulk in endpoint */ 373 /* we found a bulk in endpoint */
347 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 374 dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize);
348 dev->bulk_in_size = buffer_size; 375 dev->bulk_in_size = 0x200; /* works _much_ faster */
349 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 376 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
350 dev->bulk_in_buffer = 377 dev->bulk_in_buffer =
351 kmalloc(IMGSIZE + buffer_size, GFP_KERNEL); 378 kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL);
352 379
353 if (!dev->bulk_in_buffer) { 380 if (!dev->bulk_in_buffer) {
354 err("Unable to allocate input buffer."); 381 err("Unable to allocate input buffer.");
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
new file mode 100644
index 000000000000..66ec88354b93
--- /dev/null
+++ b/drivers/usb/misc/ldusb.c
@@ -0,0 +1,794 @@
1/**
2 * Generic USB driver for report based interrupt in/out devices
3 * like LD Didactic's USB devices. LD Didactic's USB devices are
4 * HID devices which do not use HID report definitons (they use
5 * raw interrupt in and our reports only for communication).
6 *
7 * This driver uses a ring buffer for time critical reading of
8 * interrupt in reports and provides read and write methods for
9 * raw interrupt reports (similar to the Windows HID driver).
10 * Devices based on the book USB COMPLETE by Jan Axelson may need
11 * such a compatibility to the Windows HID driver.
12 *
13 * Copyright (C) 2005 Michael Hund <mhund@ld-didactic.de>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * Derived from Lego USB Tower driver
21 * Copyright (C) 2003 David Glance <advidgsf@sourceforge.net>
22 * 2001-2004 Juergen Stuber <starblue@users.sourceforge.net>
23 *
24 * V0.1 (mh) Initial version
25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint)
26 */
27
28#include <linux/config.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/module.h>
34
35#include <asm/uaccess.h>
36#include <linux/input.h>
37#include <linux/usb.h>
38#include <linux/poll.h>
39
40/* Define these values to match your devices */
41#define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
42#define USB_DEVICE_ID_CASSY 0x1000 /* USB Product ID for all CASSY-S modules */
43#define USB_DEVICE_ID_POCKETCASSY 0x1010 /* USB Product ID for Pocket-CASSY */
44#define USB_DEVICE_ID_MOBILECASSY 0x1020 /* USB Product ID for Mobile-CASSY */
45#define USB_DEVICE_ID_JWM 0x1080 /* USB Product ID for Joule and Wattmeter */
46#define USB_DEVICE_ID_DMMP 0x1081 /* USB Product ID for Digital Multimeter P (reserved) */
47#define USB_DEVICE_ID_UMIP 0x1090 /* USB Product ID for UMI P */
48#define USB_DEVICE_ID_VIDEOCOM 0x1200 /* USB Product ID for VideoCom */
49#define USB_DEVICE_ID_COM3LAB 0x2000 /* USB Product ID for COM3LAB */
50#define USB_DEVICE_ID_TELEPORT 0x2010 /* USB Product ID for Terminal Adapter */
51#define USB_DEVICE_ID_NETWORKANALYSER 0x2020 /* USB Product ID for Network Analyser */
52#define USB_DEVICE_ID_POWERCONTROL 0x2030 /* USB Product ID for Controlling device for Power Electronics */
53
54#define USB_VENDOR_ID_VERNIER 0x08f7
55#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
56#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
57#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
58#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
59
60
61#ifdef CONFIG_USB_DYNAMIC_MINORS
62#define USB_LD_MINOR_BASE 0
63#else
64#define USB_LD_MINOR_BASE 176
65#endif
66
67/* table of devices that work with this driver */
68static struct usb_device_id ld_usb_table [] = {
69 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_CASSY) },
70 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POCKETCASSY) },
71 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_MOBILECASSY) },
72 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_JWM) },
73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_DMMP) },
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_UMIP) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_VIDEOCOM) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_COM3LAB) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_TELEPORT) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_NETWORKANALYSER) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POWERCONTROL) },
80 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
81 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
82 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
83 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
84 { } /* Terminating entry */
85};
86MODULE_DEVICE_TABLE(usb, ld_usb_table);
87MODULE_VERSION("V0.11");
88MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
89MODULE_DESCRIPTION("LD USB Driver");
90MODULE_LICENSE("GPL");
91MODULE_SUPPORTED_DEVICE("LD USB Devices");
92
93#ifdef CONFIG_USB_DEBUG
94 static int debug = 1;
95#else
96 static int debug = 0;
97#endif
98
99/* Use our own dbg macro */
100#define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
101
102/* Module parameters */
103module_param(debug, int, S_IRUGO | S_IWUSR);
104MODULE_PARM_DESC(debug, "Debug enabled or not");
105
106/* All interrupt in transfers are collected in a ring buffer to
107 * avoid racing conditions and get better performance of the driver.
108 */
109static int ring_buffer_size = 128;
110module_param(ring_buffer_size, int, 0);
111MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
112
113/* The write_buffer can contain more than one interrupt out transfer.
114 */
115static int write_buffer_size = 10;
116module_param(write_buffer_size, int, 0);
117MODULE_PARM_DESC(write_buffer_size, "Write buffer size in reports");
118
119/* As of kernel version 2.6.4 ehci-hcd uses an
120 * "only one interrupt transfer per frame" shortcut
121 * to simplify the scheduling of periodic transfers.
122 * This conflicts with our standard 1ms intervals for in and out URBs.
123 * We use default intervals of 2ms for in and 2ms for out transfers,
124 * which should be fast enough.
125 * Increase the interval to allow more devices that do interrupt transfers,
126 * or set to 1 to use the standard interval from the endpoint descriptors.
127 */
128static int min_interrupt_in_interval = 2;
129module_param(min_interrupt_in_interval, int, 0);
130MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms");
131
132static int min_interrupt_out_interval = 2;
133module_param(min_interrupt_out_interval, int, 0);
134MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms");
135
136/* Structure to hold all of our device specific stuff */
137struct ld_usb {
138 struct semaphore sem; /* locks this structure */
139 struct usb_interface* intf; /* save off the usb interface pointer */
140
141 int open_count; /* number of times this port has been opened */
142
143 char* ring_buffer;
144 unsigned int ring_head;
145 unsigned int ring_tail;
146
147 wait_queue_head_t read_wait;
148 wait_queue_head_t write_wait;
149
150 char* interrupt_in_buffer;
151 struct usb_endpoint_descriptor* interrupt_in_endpoint;
152 struct urb* interrupt_in_urb;
153 int interrupt_in_interval;
154 size_t interrupt_in_endpoint_size;
155 int interrupt_in_running;
156 int interrupt_in_done;
157
158 char* interrupt_out_buffer;
159 struct usb_endpoint_descriptor* interrupt_out_endpoint;
160 struct urb* interrupt_out_urb;
161 int interrupt_out_interval;
162 size_t interrupt_out_endpoint_size;
163 int interrupt_out_busy;
164};
165
166/* prevent races between open() and disconnect() */
167static DECLARE_MUTEX(disconnect_sem);
168
169static struct usb_driver ld_usb_driver;
170
171/**
172 * ld_usb_abort_transfers
173 * aborts transfers and frees associated data structures
174 */
175static void ld_usb_abort_transfers(struct ld_usb *dev)
176{
177 /* shutdown transfer */
178 if (dev->interrupt_in_running) {
179 dev->interrupt_in_running = 0;
180 if (dev->intf)
181 usb_kill_urb(dev->interrupt_in_urb);
182 }
183 if (dev->interrupt_out_busy)
184 if (dev->intf)
185 usb_kill_urb(dev->interrupt_out_urb);
186}
187
188/**
189 * ld_usb_delete
190 */
191static void ld_usb_delete(struct ld_usb *dev)
192{
193 ld_usb_abort_transfers(dev);
194
195 /* free data structures */
196 usb_free_urb(dev->interrupt_in_urb);
197 usb_free_urb(dev->interrupt_out_urb);
198 kfree(dev->ring_buffer);
199 kfree(dev->interrupt_in_buffer);
200 kfree(dev->interrupt_out_buffer);
201 kfree(dev);
202}
203
204/**
205 * ld_usb_interrupt_in_callback
206 */
207static void ld_usb_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
208{
209 struct ld_usb *dev = urb->context;
210 size_t *actual_buffer;
211 unsigned int next_ring_head;
212 int retval;
213
214 if (urb->status) {
215 if (urb->status == -ENOENT ||
216 urb->status == -ECONNRESET ||
217 urb->status == -ESHUTDOWN) {
218 goto exit;
219 } else {
220 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
221 __FUNCTION__, urb->status);
222 goto resubmit; /* maybe we can recover */
223 }
224 }
225
226 if (urb->actual_length > 0) {
227 next_ring_head = (dev->ring_head+1) % ring_buffer_size;
228 if (next_ring_head != dev->ring_tail) {
229 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_head*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
230 /* actual_buffer gets urb->actual_length + interrupt_in_buffer */
231 *actual_buffer = urb->actual_length;
232 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
233 dev->ring_head = next_ring_head;
234 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
235 __FUNCTION__, urb->actual_length);
236 } else
237 dev_warn(&dev->intf->dev,
238 "Ring buffer overflow, %d bytes dropped\n",
239 urb->actual_length);
240 }
241
242resubmit:
243 /* resubmit if we're still running */
244 if (dev->interrupt_in_running && dev->intf) {
245 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
246 if (retval)
247 dev_err(&dev->intf->dev,
248 "usb_submit_urb failed (%d)\n", retval);
249 }
250
251exit:
252 dev->interrupt_in_done = 1;
253 wake_up_interruptible(&dev->read_wait);
254}
255
256/**
257 * ld_usb_interrupt_out_callback
258 */
259static void ld_usb_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
260{
261 struct ld_usb *dev = urb->context;
262
263 /* sync/async unlink faults aren't errors */
264 if (urb->status && !(urb->status == -ENOENT ||
265 urb->status == -ECONNRESET ||
266 urb->status == -ESHUTDOWN))
267 dbg_info(&dev->intf->dev,
268 "%s - nonzero write interrupt status received: %d\n",
269 __FUNCTION__, urb->status);
270
271 dev->interrupt_out_busy = 0;
272 wake_up_interruptible(&dev->write_wait);
273}
274
275/**
276 * ld_usb_open
277 */
278static int ld_usb_open(struct inode *inode, struct file *file)
279{
280 struct ld_usb *dev;
281 int subminor;
282 int retval = 0;
283 struct usb_interface *interface;
284
285 nonseekable_open(inode, file);
286 subminor = iminor(inode);
287
288 down(&disconnect_sem);
289
290 interface = usb_find_interface(&ld_usb_driver, subminor);
291
292 if (!interface) {
293 err("%s - error, can't find device for minor %d\n",
294 __FUNCTION__, subminor);
295 retval = -ENODEV;
296 goto unlock_disconnect_exit;
297 }
298
299 dev = usb_get_intfdata(interface);
300
301 if (!dev) {
302 retval = -ENODEV;
303 goto unlock_disconnect_exit;
304 }
305
306 /* lock this device */
307 if (down_interruptible(&dev->sem)) {
308 retval = -ERESTARTSYS;
309 goto unlock_disconnect_exit;
310 }
311
312 /* allow opening only once */
313 if (dev->open_count) {
314 retval = -EBUSY;
315 goto unlock_exit;
316 }
317 dev->open_count = 1;
318
319 /* initialize in direction */
320 dev->ring_head = 0;
321 dev->ring_tail = 0;
322 usb_fill_int_urb(dev->interrupt_in_urb,
323 interface_to_usbdev(interface),
324 usb_rcvintpipe(interface_to_usbdev(interface),
325 dev->interrupt_in_endpoint->bEndpointAddress),
326 dev->interrupt_in_buffer,
327 dev->interrupt_in_endpoint_size,
328 ld_usb_interrupt_in_callback,
329 dev,
330 dev->interrupt_in_interval);
331
332 dev->interrupt_in_running = 1;
333 dev->interrupt_in_done = 0;
334
335 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
336 if (retval) {
337 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval);
338 dev->interrupt_in_running = 0;
339 dev->open_count = 0;
340 goto unlock_exit;
341 }
342
343 /* save device in the file's private structure */
344 file->private_data = dev;
345
346unlock_exit:
347 up(&dev->sem);
348
349unlock_disconnect_exit:
350 up(&disconnect_sem);
351
352 return retval;
353}
354
355/**
356 * ld_usb_release
357 */
358static int ld_usb_release(struct inode *inode, struct file *file)
359{
360 struct ld_usb *dev;
361 int retval = 0;
362
363 dev = file->private_data;
364
365 if (dev == NULL) {
366 retval = -ENODEV;
367 goto exit;
368 }
369
370 if (down_interruptible(&dev->sem)) {
371 retval = -ERESTARTSYS;
372 goto exit;
373 }
374
375 if (dev->open_count != 1) {
376 retval = -ENODEV;
377 goto unlock_exit;
378 }
379 if (dev->intf == NULL) {
380 /* the device was unplugged before the file was released */
381 up(&dev->sem);
382 /* unlock here as ld_usb_delete frees dev */
383 ld_usb_delete(dev);
384 goto exit;
385 }
386
387 /* wait until write transfer is finished */
388 if (dev->interrupt_out_busy)
389 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
390 ld_usb_abort_transfers(dev);
391 dev->open_count = 0;
392
393unlock_exit:
394 up(&dev->sem);
395
396exit:
397 return retval;
398}
399
400/**
401 * ld_usb_poll
402 */
403static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
404{
405 struct ld_usb *dev;
406 unsigned int mask = 0;
407
408 dev = file->private_data;
409
410 poll_wait(file, &dev->read_wait, wait);
411 poll_wait(file, &dev->write_wait, wait);
412
413 if (dev->ring_head != dev->ring_tail)
414 mask |= POLLIN | POLLRDNORM;
415 if (!dev->interrupt_out_busy)
416 mask |= POLLOUT | POLLWRNORM;
417
418 return mask;
419}
420
421/**
422 * ld_usb_read
423 */
424static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
425 loff_t *ppos)
426{
427 struct ld_usb *dev;
428 size_t *actual_buffer;
429 size_t bytes_to_read;
430 int retval = 0;
431
432 dev = file->private_data;
433
434 /* verify that we actually have some data to read */
435 if (count == 0)
436 goto exit;
437
438 /* lock this object */
439 if (down_interruptible(&dev->sem)) {
440 retval = -ERESTARTSYS;
441 goto exit;
442 }
443
444 /* verify that the device wasn't unplugged */
445 if (dev->intf == NULL) {
446 retval = -ENODEV;
447 err("No device or device unplugged %d\n", retval);
448 goto unlock_exit;
449 }
450
451 /* wait for data */
452 if (dev->ring_head == dev->ring_tail) {
453 if (file->f_flags & O_NONBLOCK) {
454 retval = -EAGAIN;
455 goto unlock_exit;
456 }
457 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done);
458 if (retval < 0)
459 goto unlock_exit;
460 }
461
462 /* actual_buffer contains actual_length + interrupt_in_buffer */
463 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
464 bytes_to_read = min(count, *actual_buffer);
465 if (bytes_to_read < *actual_buffer)
466 dev_warn(&dev->intf->dev, "Read buffer overflow, %d bytes dropped\n",
467 *actual_buffer-bytes_to_read);
468
469 /* copy one interrupt_in_buffer from ring_buffer into userspace */
470 if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
471 retval = -EFAULT;
472 goto unlock_exit;
473 }
474 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
475
476 retval = bytes_to_read;
477
478unlock_exit:
479 /* unlock the device */
480 up(&dev->sem);
481
482exit:
483 return retval;
484}
485
486/**
487 * ld_usb_write
488 */
489static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
490 size_t count, loff_t *ppos)
491{
492 struct ld_usb *dev;
493 size_t bytes_to_write;
494 int retval = 0;
495
496 dev = file->private_data;
497
498 /* verify that we actually have some data to write */
499 if (count == 0)
500 goto exit;
501
502 /* lock this object */
503 if (down_interruptible(&dev->sem)) {
504 retval = -ERESTARTSYS;
505 goto exit;
506 }
507
508 /* verify that the device wasn't unplugged */
509 if (dev->intf == NULL) {
510 retval = -ENODEV;
511 err("No device or device unplugged %d\n", retval);
512 goto unlock_exit;
513 }
514
515 /* wait until previous transfer is finished */
516 if (dev->interrupt_out_busy) {
517 if (file->f_flags & O_NONBLOCK) {
518 retval = -EAGAIN;
519 goto unlock_exit;
520 }
521 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);
522 if (retval < 0) {
523 goto unlock_exit;
524 }
525 }
526
527 /* write the data into interrupt_out_buffer from userspace */
528 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
529 if (bytes_to_write < count)
530 dev_warn(&dev->intf->dev, "Write buffer overflow, %d bytes dropped\n",count-bytes_to_write);
531 dbg_info(&dev->intf->dev, "%s: count = %d, bytes_to_write = %d\n", __FUNCTION__, count, bytes_to_write);
532
533 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
534 retval = -EFAULT;
535 goto unlock_exit;
536 }
537
538 if (dev->interrupt_out_endpoint == NULL) {
539 /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
540 retval = usb_control_msg(interface_to_usbdev(dev->intf),
541 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
542 9,
543 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
544 1 << 8, 0,
545 dev->interrupt_out_buffer,
546 bytes_to_write,
547 USB_CTRL_SET_TIMEOUT * HZ);
548 if (retval < 0)
549 err("Couldn't submit HID_REQ_SET_REPORT %d\n", retval);
550 goto unlock_exit;
551 }
552
553 /* send off the urb */
554 usb_fill_int_urb(dev->interrupt_out_urb,
555 interface_to_usbdev(dev->intf),
556 usb_sndintpipe(interface_to_usbdev(dev->intf),
557 dev->interrupt_out_endpoint->bEndpointAddress),
558 dev->interrupt_out_buffer,
559 bytes_to_write,
560 ld_usb_interrupt_out_callback,
561 dev,
562 dev->interrupt_out_interval);
563
564 dev->interrupt_out_busy = 1;
565 wmb();
566
567 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
568 if (retval) {
569 dev->interrupt_out_busy = 0;
570 err("Couldn't submit interrupt_out_urb %d\n", retval);
571 goto unlock_exit;
572 }
573 retval = bytes_to_write;
574
575unlock_exit:
576 /* unlock the device */
577 up(&dev->sem);
578
579exit:
580 return retval;
581}
582
583/* file operations needed when we register this driver */
584static struct file_operations ld_usb_fops = {
585 .owner = THIS_MODULE,
586 .read = ld_usb_read,
587 .write = ld_usb_write,
588 .open = ld_usb_open,
589 .release = ld_usb_release,
590 .poll = ld_usb_poll,
591};
592
593/*
594 * usb class driver info in order to get a minor number from the usb core,
595 * and to have the device registered with devfs and the driver core
596 */
597static struct usb_class_driver ld_usb_class = {
598 .name = "ldusb%d",
599 .fops = &ld_usb_fops,
600 .minor_base = USB_LD_MINOR_BASE,
601};
602
603/**
604 * ld_usb_probe
605 *
606 * Called by the usb core when a new device is connected that it thinks
607 * this driver might be interested in.
608 */
609static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
610{
611 struct usb_device *udev = interface_to_usbdev(intf);
612 struct ld_usb *dev = NULL;
613 struct usb_host_interface *iface_desc;
614 struct usb_endpoint_descriptor *endpoint;
615 char *buffer;
616 int i;
617 int retval = -ENOMEM;
618
619 /* allocate memory for our device state and intialize it */
620
621 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
622 if (dev == NULL) {
623 dev_err(&intf->dev, "Out of memory\n");
624 goto exit;
625 }
626 memset(dev, 0x00, sizeof(*dev));
627 init_MUTEX(&dev->sem);
628 dev->intf = intf;
629 init_waitqueue_head(&dev->read_wait);
630 init_waitqueue_head(&dev->write_wait);
631
632 /* workaround for early firmware versions on fast computers */
633 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) &&
634 ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_CASSY) ||
635 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) &&
636 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
637 buffer = kmalloc(256, GFP_KERNEL);
638 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
639 usb_string(udev, 255, buffer, 256);
640 kfree(buffer);
641 }
642
643 iface_desc = intf->cur_altsetting;
644
645 /* set up the endpoint information */
646 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
647 endpoint = &iface_desc->endpoint[i].desc;
648
649 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
650 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
651 dev->interrupt_in_endpoint = endpoint;
652 }
653
654 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
655 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
656 dev->interrupt_out_endpoint = endpoint;
657 }
658 }
659 if (dev->interrupt_in_endpoint == NULL) {
660 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
661 goto error;
662 }
663 if (dev->interrupt_out_endpoint == NULL)
664 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
665
666 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
667 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
668 if (!dev->ring_buffer) {
669 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n");
670 goto error;
671 }
672 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
673 if (!dev->interrupt_in_buffer) {
674 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
675 goto error;
676 }
677 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
678 if (!dev->interrupt_in_urb) {
679 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
680 goto error;
681 }
682 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
683 udev->descriptor.bMaxPacketSize0;
684 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
685 if (!dev->interrupt_out_buffer) {
686 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
687 goto error;
688 }
689 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
690 if (!dev->interrupt_out_urb) {
691 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
692 goto error;
693 }
694 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;
695 if (dev->interrupt_out_endpoint)
696 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
697
698 /* we can register the device now, as it is ready */
699 usb_set_intfdata(intf, dev);
700
701 retval = usb_register_dev(intf, &ld_usb_class);
702 if (retval) {
703 /* something prevented us from registering this driver */
704 dev_err(&intf->dev, "Not able to get a minor for this device.\n");
705 usb_set_intfdata(intf, NULL);
706 goto error;
707 }
708
709 /* let the user know what node this device is now attached to */
710 dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d\n",
711 (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);
712
713exit:
714 return retval;
715
716error:
717 ld_usb_delete(dev);
718
719 return retval;
720}
721
722/**
723 * ld_usb_disconnect
724 *
725 * Called by the usb core when the device is removed from the system.
726 */
727static void ld_usb_disconnect(struct usb_interface *intf)
728{
729 struct ld_usb *dev;
730 int minor;
731
732 down(&disconnect_sem);
733
734 dev = usb_get_intfdata(intf);
735 usb_set_intfdata(intf, NULL);
736
737 down(&dev->sem);
738
739 minor = intf->minor;
740
741 /* give back our minor */
742 usb_deregister_dev(intf, &ld_usb_class);
743
744 /* if the device is not opened, then we clean up right now */
745 if (!dev->open_count) {
746 up(&dev->sem);
747 ld_usb_delete(dev);
748 } else {
749 dev->intf = NULL;
750 up(&dev->sem);
751 }
752
753 up(&disconnect_sem);
754
755 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
756 (minor - USB_LD_MINOR_BASE));
757}
758
759/* usb specific object needed to register this driver with the usb subsystem */
760static struct usb_driver ld_usb_driver = {
761 .owner = THIS_MODULE,
762 .name = "ldusb",
763 .probe = ld_usb_probe,
764 .disconnect = ld_usb_disconnect,
765 .id_table = ld_usb_table,
766};
767
768/**
769 * ld_usb_init
770 */
771static int __init ld_usb_init(void)
772{
773 int retval;
774
775 /* register this driver with the USB subsystem */
776 retval = usb_register(&ld_usb_driver);
777 if (retval)
778 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval);
779
780 return retval;
781}
782
783/**
784 * ld_usb_exit
785 */
786static void __exit ld_usb_exit(void)
787{
788 /* deregister this driver with the USB subsystem */
789 usb_deregister(&ld_usb_driver);
790}
791
792module_init(ld_usb_init);
793module_exit(ld_usb_exit);
794
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 3104f28f6aa8..cda7249a90b2 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -461,7 +461,7 @@ static int perform_sglist (
461 461
462static unsigned realworld = 1; 462static unsigned realworld = 1;
463module_param (realworld, uint, 0); 463module_param (realworld, uint, 0);
464MODULE_PARM_DESC (realworld, "clear to demand stricter ch9 compliance"); 464MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance");
465 465
466static int get_altsetting (struct usbtest_dev *dev) 466static int get_altsetting (struct usbtest_dev *dev)
467{ 467{
@@ -604,9 +604,8 @@ static int ch9_postconfig (struct usbtest_dev *dev)
604 USB_DIR_IN | USB_RECIP_DEVICE, 604 USB_DIR_IN | USB_RECIP_DEVICE,
605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
606 if (retval != 1 || dev->buf [0] != expected) { 606 if (retval != 1 || dev->buf [0] != expected) {
607 dev_dbg (&iface->dev, 607 dev_dbg (&iface->dev, "get config --> %d %d (1 %d)\n",
608 "get config --> %d (%d)\n", retval, 608 retval, dev->buf[0], expected);
609 expected);
610 return (retval < 0) ? retval : -EDOM; 609 return (retval < 0) ? retval : -EDOM;
611 } 610 }
612 } 611 }
@@ -1243,7 +1242,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1243 char *what = "?"; 1242 char *what = "?";
1244 struct usb_device *udev; 1243 struct usb_device *udev;
1245 1244
1246 if (length > 0xffff || vary >= length) 1245 if (length < 1 || length > 0xffff || vary >= length)
1247 return -EINVAL; 1246 return -EINVAL;
1248 1247
1249 buf = kmalloc(length, SLAB_KERNEL); 1248 buf = kmalloc(length, SLAB_KERNEL);
@@ -1266,6 +1265,11 @@ static int ctrl_out (struct usbtest_dev *dev,
1266 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1265 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1267 if (retval != len) { 1266 if (retval != len) {
1268 what = "write"; 1267 what = "write";
1268 if (retval >= 0) {
1269 INFO(dev, "ctrl_out, wlen %d (expected %d)\n",
1270 retval, len);
1271 retval = -EBADMSG;
1272 }
1269 break; 1273 break;
1270 } 1274 }
1271 1275
@@ -1275,6 +1279,11 @@ static int ctrl_out (struct usbtest_dev *dev,
1275 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1279 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1276 if (retval != len) { 1280 if (retval != len) {
1277 what = "read"; 1281 what = "read";
1282 if (retval >= 0) {
1283 INFO(dev, "ctrl_out, rlen %d (expected %d)\n",
1284 retval, len);
1285 retval = -EBADMSG;
1286 }
1278 break; 1287 break;
1279 } 1288 }
1280 1289
@@ -1293,8 +1302,13 @@ static int ctrl_out (struct usbtest_dev *dev,
1293 } 1302 }
1294 1303
1295 len += vary; 1304 len += vary;
1305
1306 /* [real world] the "zero bytes IN" case isn't really used.
1307 * hardware can easily trip up in this wierd case, since its
1308 * status stage is IN, not OUT like other ep0in transfers.
1309 */
1296 if (len > length) 1310 if (len > length)
1297 len = 0; 1311 len = realworld ? 1 : 0;
1298 } 1312 }
1299 1313
1300 if (retval < 0) 1314 if (retval < 0)
@@ -1519,6 +1533,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1519 if (down_interruptible (&dev->sem)) 1533 if (down_interruptible (&dev->sem))
1520 return -ERESTARTSYS; 1534 return -ERESTARTSYS;
1521 1535
1536 if (intf->dev.power.power_state != PMSG_ON) {
1537 up (&dev->sem);
1538 return -EHOSTUNREACH;
1539 }
1540
1522 /* some devices, like ez-usb default devices, need a non-default 1541 /* some devices, like ez-usb default devices, need a non-default
1523 * altsetting to have any active endpoints. some tests change 1542 * altsetting to have any active endpoints. some tests change
1524 * altsettings; force a default so most tests don't need to check. 1543 * altsettings; force a default so most tests don't need to check.
@@ -1762,8 +1781,10 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1762 case 14: 1781 case 14:
1763 if (!dev->info->ctrl_out) 1782 if (!dev->info->ctrl_out)
1764 break; 1783 break;
1765 dev_dbg (&intf->dev, "TEST 14: %d ep0out, 0..%d vary %d\n", 1784 dev_dbg (&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
1766 param->iterations, param->length, param->vary); 1785 param->iterations,
1786 realworld ? 1 : 0, param->length,
1787 param->vary);
1767 retval = ctrl_out (dev, param->iterations, 1788 retval = ctrl_out (dev, param->iterations,
1768 param->length, param->vary); 1789 param->length, param->vary);
1769 break; 1790 break;
@@ -1927,6 +1948,27 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1927 return 0; 1948 return 0;
1928} 1949}
1929 1950
1951static int usbtest_suspend (struct usb_interface *intf, pm_message_t message)
1952{
1953 struct usbtest_dev *dev = usb_get_intfdata (intf);
1954
1955 down (&dev->sem);
1956 intf->dev.power.power_state = PMSG_SUSPEND;
1957 up (&dev->sem);
1958 return 0;
1959}
1960
1961static int usbtest_resume (struct usb_interface *intf)
1962{
1963 struct usbtest_dev *dev = usb_get_intfdata (intf);
1964
1965 down (&dev->sem);
1966 intf->dev.power.power_state = PMSG_ON;
1967 up (&dev->sem);
1968 return 0;
1969}
1970
1971
1930static void usbtest_disconnect (struct usb_interface *intf) 1972static void usbtest_disconnect (struct usb_interface *intf)
1931{ 1973{
1932 struct usbtest_dev *dev = usb_get_intfdata (intf); 1974 struct usbtest_dev *dev = usb_get_intfdata (intf);
@@ -2115,6 +2157,8 @@ static struct usb_driver usbtest_driver = {
2115 .probe = usbtest_probe, 2157 .probe = usbtest_probe,
2116 .ioctl = usbtest_ioctl, 2158 .ioctl = usbtest_ioctl,
2117 .disconnect = usbtest_disconnect, 2159 .disconnect = usbtest_disconnect,
2160 .suspend = usbtest_suspend,
2161 .resume = usbtest_resume,
2118}; 2162};
2119 2163
2120/*-------------------------------------------------------------------------*/ 2164/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 755a4570477f..26266b30028e 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -19,11 +19,16 @@
19#define DATA_MAX 32 19#define DATA_MAX 32
20 20
21/* 21/*
22 * Defined by USB 2.0 clause 9.3, table 9.2.
23 */
24#define SETUP_MAX 8
25
26/*
22 * This limit exists to prevent OOMs when the user process stops reading. 27 * This limit exists to prevent OOMs when the user process stops reading.
23 */ 28 */
24#define EVENT_MAX 25 29#define EVENT_MAX 25
25 30
26#define PRINTF_DFL 120 31#define PRINTF_DFL 130
27 32
28struct mon_event_text { 33struct mon_event_text {
29 struct list_head e_link; 34 struct list_head e_link;
@@ -33,7 +38,9 @@ struct mon_event_text {
33 unsigned int tstamp; 38 unsigned int tstamp;
34 int length; /* Depends on type: xfer length or act length */ 39 int length; /* Depends on type: xfer length or act length */
35 int status; 40 int status;
41 char setup_flag;
36 char data_flag; 42 char data_flag;
43 unsigned char setup[SETUP_MAX];
37 unsigned char data[DATA_MAX]; 44 unsigned char data[DATA_MAX];
38}; 45};
39 46
@@ -64,6 +71,22 @@ static void mon_text_dtor(void *, kmem_cache_t *, unsigned long);
64 * This is called with the whole mon_bus locked, so no additional lock. 71 * This is called with the whole mon_bus locked, so no additional lock.
65 */ 72 */
66 73
74static inline char mon_text_get_setup(struct mon_event_text *ep,
75 struct urb *urb, char ev_type)
76{
77
78 if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
79 return '-';
80
81 if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)
82 return 'D';
83 if (urb->setup_packet == NULL)
84 return 'Z'; /* '0' would be not as pretty. */
85
86 memcpy(ep->setup, urb->setup_packet, SETUP_MAX);
87 return 0;
88}
89
67static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, 90static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
68 int len, char ev_type) 91 int len, char ev_type)
69{ 92{
@@ -90,7 +113,6 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
90 113
91 /* 114 /*
92 * Bulk is easy to shortcut reliably. 115 * Bulk is easy to shortcut reliably.
93 * XXX Control needs setup packet taken.
94 * XXX Other pipe types need consideration. Currently, we overdo it 116 * XXX Other pipe types need consideration. Currently, we overdo it
95 * and collect garbage for them: better more than less. 117 * and collect garbage for them: better more than less.
96 */ 118 */
@@ -144,6 +166,7 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
144 /* Collecting status makes debugging sense for submits, too */ 166 /* Collecting status makes debugging sense for submits, too */
145 ep->status = urb->status; 167 ep->status = urb->status;
146 168
169 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type);
147 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type); 170 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type);
148 171
149 rp->nevents++; 172 rp->nevents++;
@@ -299,10 +322,25 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
299 default: /* PIPE_BULK */ utype = 'B'; 322 default: /* PIPE_BULK */ utype = 'B';
300 } 323 }
301 cnt += snprintf(pbuf + cnt, limit - cnt, 324 cnt += snprintf(pbuf + cnt, limit - cnt,
302 "%lx %u %c %c%c:%03u:%02u %d %d", 325 "%lx %u %c %c%c:%03u:%02u",
303 ep->id, ep->tstamp, ep->type, 326 ep->id, ep->tstamp, ep->type,
304 utype, udir, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe), 327 utype, udir, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe));
305 ep->status, ep->length); 328
329 if (ep->setup_flag == 0) { /* Setup packet is present and captured */
330 cnt += snprintf(pbuf + cnt, limit - cnt,
331 " s %02x %02x %04x %04x %04x",
332 ep->setup[0],
333 ep->setup[1],
334 (ep->setup[3] << 8) | ep->setup[2],
335 (ep->setup[5] << 8) | ep->setup[4],
336 (ep->setup[7] << 8) | ep->setup[6]);
337 } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */
338 cnt += snprintf(pbuf + cnt, limit - cnt,
339 " %c __ __ ____ ____ ____", ep->setup_flag);
340 } else { /* No setup for this kind of URB */
341 cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->status);
342 }
343 cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->length);
306 344
307 if ((data_len = ep->length) > 0) { 345 if ((data_len = ep->length) > 0) {
308 if (ep->data_flag == 0) { 346 if (ep->data_flag == 0) {
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index fd6ff4cb2c62..7ffa99b9760f 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -477,7 +477,7 @@ static int kaweth_reset(struct kaweth_device *kaweth)
477} 477}
478 478
479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs); 479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs);
480static int kaweth_resubmit_rx_urb(struct kaweth_device *, int); 480static int kaweth_resubmit_rx_urb(struct kaweth_device *, unsigned);
481 481
482/**************************************************************** 482/****************************************************************
483 int_callback 483 int_callback
@@ -550,7 +550,7 @@ static void kaweth_resubmit_tl(void *d)
550 * kaweth_resubmit_rx_urb 550 * kaweth_resubmit_rx_urb
551 ****************************************************************/ 551 ****************************************************************/
552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth, 552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
553 int mem_flags) 553 unsigned mem_flags)
554{ 554{
555 int result; 555 int result;
556 556
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index d976790312aa..5f4496d8dbac 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -1166,7 +1166,7 @@ static void pegasus_set_multicast(struct net_device *net)
1166 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS; 1166 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
1167 if (netif_msg_link(pegasus)) 1167 if (netif_msg_link(pegasus))
1168 pr_info("%s: Promiscuous mode enabled.\n", net->name); 1168 pr_info("%s: Promiscuous mode enabled.\n", net->name);
1169 } else if ((net->mc_count > multicast_filter_limit) || 1169 } else if (net->mc_count ||
1170 (net->flags & IFF_ALLMULTI)) { 1170 (net->flags & IFF_ALLMULTI)) {
1171 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST; 1171 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
1172 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS; 1172 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
index 13ccedef5c7e..b98f2a833442 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/usb/net/pegasus.h
@@ -249,6 +249,8 @@ PEGASUS_DEV( "Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
249 DEFAULT_GPIO_RESET) 249 DEFAULT_GPIO_RESET)
250PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002, 250PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002,
251 DEFAULT_GPIO_RESET ) 251 DEFAULT_GPIO_RESET )
252PEGASUS_DEV( "LANEED USB Ethernet LD-USBL/TX", VENDOR_LANEED, 0x4005,
253 DEFAULT_GPIO_RESET | PEGASUS_II)
252PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b, 254PEGASUS_DEV( "LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b,
253 DEFAULT_GPIO_RESET | PEGASUS_II ) 255 DEFAULT_GPIO_RESET | PEGASUS_II )
254PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1, 256PEGASUS_DEV( "LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 8fb223385f2f..626b016addff 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -667,7 +667,7 @@ static void rtl8150_set_multicast(struct net_device *netdev)
667 if (netdev->flags & IFF_PROMISC) { 667 if (netdev->flags & IFF_PROMISC) {
668 dev->rx_creg |= cpu_to_le16(0x0001); 668 dev->rx_creg |= cpu_to_le16(0x0001);
669 info("%s: promiscuous mode", netdev->name); 669 info("%s: promiscuous mode", netdev->name);
670 } else if ((netdev->mc_count > multicast_filter_limit) || 670 } else if (netdev->mc_count ||
671 (netdev->flags & IFF_ALLMULTI)) { 671 (netdev->flags & IFF_ALLMULTI)) {
672 dev->rx_creg &= cpu_to_le16(0xfffe); 672 dev->rx_creg &= cpu_to_le16(0xfffe);
673 dev->rx_creg |= cpu_to_le16(0x0002); 673 dev->rx_creg |= cpu_to_le16(0x0002);
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 4cbb408af727..576f3b852fce 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -1429,7 +1429,7 @@ static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1429 info->ether = (void *) buf; 1429 info->ether = (void *) buf;
1430 if (info->ether->bLength != sizeof *info->ether) { 1430 if (info->ether->bLength != sizeof *info->ether) {
1431 dev_dbg (&intf->dev, "CDC ether len %u\n", 1431 dev_dbg (&intf->dev, "CDC ether len %u\n",
1432 info->u->bLength); 1432 info->ether->bLength);
1433 goto bad_desc; 1433 goto bad_desc;
1434 } 1434 }
1435 dev->net->mtu = le16_to_cpup ( 1435 dev->net->mtu = le16_to_cpup (
@@ -3227,9 +3227,9 @@ static int usbnet_stop (struct net_device *net)
3227 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq); 3227 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
3228 3228
3229 // maybe wait for deletions to finish. 3229 // maybe wait for deletions to finish.
3230 while (skb_queue_len (&dev->rxq) 3230 while (!skb_queue_empty(&dev->rxq) &&
3231 && skb_queue_len (&dev->txq) 3231 !skb_queue_empty(&dev->txq) &&
3232 && skb_queue_len (&dev->done)) { 3232 !skb_queue_empty(&dev->done)) {
3233 msleep(UNLINK_TIMEOUT_MS); 3233 msleep(UNLINK_TIMEOUT_MS);
3234 if (netif_msg_ifdown (dev)) 3234 if (netif_msg_ifdown (dev))
3235 devdbg (dev, "waited for %d urb completions", temp); 3235 devdbg (dev, "waited for %d urb completions", temp);
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index 341ae5f732dd..3b387b005739 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -1884,12 +1884,53 @@ static void zd1201_disconnect(struct usb_interface *interface)
1884 kfree(zd); 1884 kfree(zd);
1885} 1885}
1886 1886
1887#ifdef CONFIG_PM
1888
1889static int zd1201_suspend(struct usb_interface *interface,
1890 pm_message_t message)
1891{
1892 struct zd1201 *zd = usb_get_intfdata(interface);
1893
1894 netif_device_detach(zd->dev);
1895
1896 zd->was_enabled = zd->mac_enabled;
1897
1898 if (zd->was_enabled)
1899 return zd1201_disable(zd);
1900 else
1901 return 0;
1902}
1903
1904static int zd1201_resume(struct usb_interface *interface)
1905{
1906 struct zd1201 *zd = usb_get_intfdata(interface);
1907
1908 if (!zd || !zd->dev)
1909 return -ENODEV;
1910
1911 netif_device_attach(zd->dev);
1912
1913 if (zd->was_enabled)
1914 return zd1201_enable(zd);
1915 else
1916 return 0;
1917}
1918
1919#else
1920
1921#define zd1201_suspend NULL
1922#define zd1201_resume NULL
1923
1924#endif
1925
1887static struct usb_driver zd1201_usb = { 1926static struct usb_driver zd1201_usb = {
1888 .owner = THIS_MODULE, 1927 .owner = THIS_MODULE,
1889 .name = "zd1201", 1928 .name = "zd1201",
1890 .probe = zd1201_probe, 1929 .probe = zd1201_probe,
1891 .disconnect = zd1201_disconnect, 1930 .disconnect = zd1201_disconnect,
1892 .id_table = zd1201_table, 1931 .id_table = zd1201_table,
1932 .suspend = zd1201_suspend,
1933 .resume = zd1201_resume,
1893}; 1934};
1894 1935
1895static int __init zd1201_init(void) 1936static int __init zd1201_init(void)
diff --git a/drivers/usb/net/zd1201.h b/drivers/usb/net/zd1201.h
index 1627c71e8052..235f0ee34b24 100644
--- a/drivers/usb/net/zd1201.h
+++ b/drivers/usb/net/zd1201.h
@@ -46,6 +46,7 @@ struct zd1201 {
46 char essid[IW_ESSID_MAX_SIZE+1]; 46 char essid[IW_ESSID_MAX_SIZE+1];
47 int essidlen; 47 int essidlen;
48 int mac_enabled; 48 int mac_enabled;
49 int was_enabled;
49 int monitor; 50 int monitor;
50 int encode_enabled; 51 int encode_enabled;
51 int encode_restricted; 52 int encode_restricted;
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 46a204cd40e1..b5b431067b08 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -213,10 +213,14 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
213 return (0); 213 return (0);
214 } 214 }
215 215
216 if (port->write_urb->status == -EINPROGRESS) { 216 spin_lock(&port->lock);
217 if (port->write_urb_busy) {
218 spin_unlock(&port->lock);
217 dbg("%s - already writing", __FUNCTION__); 219 dbg("%s - already writing", __FUNCTION__);
218 return (0); 220 return 0;
219 } 221 }
222 port->write_urb_busy = 1;
223 spin_unlock(&port->lock);
220 224
221 spin_lock_irqsave(&priv->lock, flags); 225 spin_lock_irqsave(&priv->lock, flags);
222 226
@@ -224,6 +228,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
224 /* To much data for buffer. Reset buffer. */ 228 /* To much data for buffer. Reset buffer. */
225 priv->wrfilled=0; 229 priv->wrfilled=0;
226 spin_unlock_irqrestore(&priv->lock, flags); 230 spin_unlock_irqrestore(&priv->lock, flags);
231 port->write_urb_busy = 0;
227 return (0); 232 return (0);
228 } 233 }
229 234
@@ -268,6 +273,7 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
268 priv->wrfilled=0; 273 priv->wrfilled=0;
269 priv->wrsent=0; 274 priv->wrsent=0;
270 spin_unlock_irqrestore(&priv->lock, flags); 275 spin_unlock_irqrestore(&priv->lock, flags);
276 port->write_urb_busy = 0;
271 return 0; 277 return 0;
272 } 278 }
273 279
@@ -412,7 +418,8 @@ static void cyberjack_write_bulk_callback (struct urb *urb, struct pt_regs *regs
412 struct cyberjack_private *priv = usb_get_serial_port_data(port); 418 struct cyberjack_private *priv = usb_get_serial_port_data(port);
413 419
414 dbg("%s - port %d", __FUNCTION__, port->number); 420 dbg("%s - port %d", __FUNCTION__, port->number);
415 421
422 port->write_urb_busy = 0;
416 if (urb->status) { 423 if (urb->status) {
417 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 424 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
418 return; 425 return;
@@ -424,12 +431,6 @@ static void cyberjack_write_bulk_callback (struct urb *urb, struct pt_regs *regs
424 if( priv->wrfilled ) { 431 if( priv->wrfilled ) {
425 int length, blksize, result; 432 int length, blksize, result;
426 433
427 if (port->write_urb->status == -EINPROGRESS) {
428 dbg("%s - already writing", __FUNCTION__);
429 spin_unlock(&priv->lock);
430 return;
431 }
432
433 dbg("%s - transmitting data (frame n)", __FUNCTION__); 434 dbg("%s - transmitting data (frame n)", __FUNCTION__);
434 435
435 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 436 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index d882fa3ad19a..0b03ddab53d9 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -264,16 +264,26 @@
264/* 264/*
265 * Version Information 265 * Version Information
266 */ 266 */
267#define DRIVER_VERSION "v1.4.2" 267#define DRIVER_VERSION "v1.4.3"
268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>" 268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
269#define DRIVER_DESC "USB FTDI Serial Converters Driver" 269#define DRIVER_DESC "USB FTDI Serial Converters Driver"
270 270
271static int debug; 271static int debug;
272 272
273static struct usb_device_id id_table_sio [] = { 273/* struct ftdi_sio_quirk is used by devices requiring special attention. */
274 { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) }, 274struct ftdi_sio_quirk {
275 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 275 void (*setup)(struct usb_serial *); /* Special settings during startup. */
276 { } /* Terminating entry */ 276};
277
278static void ftdi_USB_UIRT_setup (struct usb_serial *serial);
279static void ftdi_HE_TIRA1_setup (struct usb_serial *serial);
280
281static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
282 .setup = ftdi_USB_UIRT_setup,
283};
284
285static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
286 .setup = ftdi_HE_TIRA1_setup,
277}; 287};
278 288
279/* 289/*
@@ -288,237 +298,11 @@ static struct usb_device_id id_table_sio [] = {
288 * the bcdDevice value is used to differentiate FT232BM and FT245BM from 298 * the bcdDevice value is used to differentiate FT232BM and FT245BM from
289 * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID 299 * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID
290 * combinations in both tables. 300 * combinations in both tables.
291 * FIXME: perhaps bcdDevice can also identify 12MHz devices, but I don't know 301 * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
292 * if those ever went into mass production. [Ian Abbott] 302 * but I don't know if those ever went into mass production. [Ian Abbott]
293 */ 303 */
294 304
295 305
296static struct usb_device_id id_table_8U232AM [] = {
297 { USB_DEVICE_VER(FTDI_VID, FTDI_IRTRANS_PID, 0, 0x3ff) },
298 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_PID, 0, 0x3ff) },
299 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_ALT_PID, 0, 0x3ff) },
300 { USB_DEVICE_VER(FTDI_VID, FTDI_RELAIS_PID, 0, 0x3ff) },
301 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
302 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
303 { USB_DEVICE_VER(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID, 0, 0x3ff) },
304 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_632_PID, 0, 0x3ff) },
305 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_634_PID, 0, 0x3ff) },
306 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_547_PID, 0, 0x3ff) },
307 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_633_PID, 0, 0x3ff) },
308 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_631_PID, 0, 0x3ff) },
309 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_635_PID, 0, 0x3ff) },
310 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_640_PID, 0, 0x3ff) },
311 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_642_PID, 0, 0x3ff) },
312 { USB_DEVICE_VER(FTDI_VID, FTDI_VNHCPCUSB_D_PID, 0, 0x3ff) },
313 { USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0, 0x3ff) },
314 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2101_PID, 0, 0x3ff) },
315 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2102_PID, 0, 0x3ff) },
316 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2103_PID, 0, 0x3ff) },
317 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2104_PID, 0, 0x3ff) },
318 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_1_PID, 0, 0x3ff) },
319 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_2_PID, 0, 0x3ff) },
320 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_1_PID, 0, 0x3ff) },
321 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_2_PID, 0, 0x3ff) },
322 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_1_PID, 0, 0x3ff) },
323 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_2_PID, 0, 0x3ff) },
324 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_1_PID, 0, 0x3ff) },
325 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_2_PID, 0, 0x3ff) },
326 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_3_PID, 0, 0x3ff) },
327 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_4_PID, 0, 0x3ff) },
328 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_1_PID, 0, 0x3ff) },
329 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_2_PID, 0, 0x3ff) },
330 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_3_PID, 0, 0x3ff) },
331 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_4_PID, 0, 0x3ff) },
332 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_1_PID, 0, 0x3ff) },
333 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_2_PID, 0, 0x3ff) },
334 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_3_PID, 0, 0x3ff) },
335 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_4_PID, 0, 0x3ff) },
336 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_1_PID, 0, 0x3ff) },
337 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_2_PID, 0, 0x3ff) },
338 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_3_PID, 0, 0x3ff) },
339 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_4_PID, 0, 0x3ff) },
340 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_5_PID, 0, 0x3ff) },
341 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_6_PID, 0, 0x3ff) },
342 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_7_PID, 0, 0x3ff) },
343 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_8_PID, 0, 0x3ff) },
344 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_1_PID, 0, 0x3ff) },
345 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_2_PID, 0, 0x3ff) },
346 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_3_PID, 0, 0x3ff) },
347 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_4_PID, 0, 0x3ff) },
348 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_5_PID, 0, 0x3ff) },
349 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_6_PID, 0, 0x3ff) },
350 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_7_PID, 0, 0x3ff) },
351 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_8_PID, 0, 0x3ff) },
352 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_1_PID, 0, 0x3ff) },
353 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_2_PID, 0, 0x3ff) },
354 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_3_PID, 0, 0x3ff) },
355 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_4_PID, 0, 0x3ff) },
356 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_5_PID, 0, 0x3ff) },
357 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_6_PID, 0, 0x3ff) },
358 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_7_PID, 0, 0x3ff) },
359 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_8_PID, 0, 0x3ff) },
360 { USB_DEVICE_VER(IDTECH_VID, IDTECH_IDT1221U_PID, 0, 0x3ff) },
361 { USB_DEVICE_VER(OCT_VID, OCT_US101_PID, 0, 0x3ff) },
362 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_1, 0, 0x3ff) },
363 { USB_DEVICE_VER(FTDI_VID, PROTEGO_R2X0, 0, 0x3ff) },
364 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0, 0x3ff) },
365 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0, 0x3ff) },
366 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0, 0x3ff) },
367 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UM100_PID, 0, 0x3ff) },
368 { USB_DEVICE_VER(FTDI_VID, INSIDE_ACCESSO, 0, 0x3ff) },
369 { USB_DEVICE_VER(INTREPID_VID, INTREPID_VALUECAN_PID, 0, 0x3ff) },
370 { USB_DEVICE_VER(INTREPID_VID, INTREPID_NEOVI_PID, 0, 0x3ff) },
371 { USB_DEVICE_VER(FALCOM_VID, FALCOM_TWIST_PID, 0, 0x3ff) },
372 { USB_DEVICE_VER(FTDI_VID, FTDI_SUUNTO_SPORTS_PID, 0, 0x3ff) },
373 { USB_DEVICE_VER(FTDI_VID, FTDI_RM_CANVIEW_PID, 0, 0x3ff) },
374 { USB_DEVICE_VER(BANDB_VID, BANDB_USOTL4_PID, 0, 0x3ff) },
375 { USB_DEVICE_VER(BANDB_VID, BANDB_USTL4_PID, 0, 0x3ff) },
376 { USB_DEVICE_VER(BANDB_VID, BANDB_USO9ML2_PID, 0, 0x3ff) },
377 { USB_DEVICE_VER(FTDI_VID, EVER_ECO_PRO_CDS, 0, 0x3ff) },
378 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID, 0, 0x3ff) },
379 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID, 0, 0x3ff) },
380 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID, 0, 0x3ff) },
381 { } /* Terminating entry */
382};
383
384
385static struct usb_device_id id_table_FT232BM [] = {
386 { USB_DEVICE_VER(FTDI_VID, FTDI_IRTRANS_PID, 0x400, 0xffff) },
387 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_PID, 0x400, 0xffff) },
388 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_ALT_PID, 0x400, 0xffff) },
389 { USB_DEVICE_VER(FTDI_VID, FTDI_RELAIS_PID, 0x400, 0xffff) },
390 { USB_DEVICE_VER(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID, 0x400, 0xffff) },
391 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_632_PID, 0x400, 0xffff) },
392 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_634_PID, 0x400, 0xffff) },
393 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_547_PID, 0x400, 0xffff) },
394 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_633_PID, 0x400, 0xffff) },
395 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_631_PID, 0x400, 0xffff) },
396 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_635_PID, 0x400, 0xffff) },
397 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_640_PID, 0x400, 0xffff) },
398 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_642_PID, 0x400, 0xffff) },
399 { USB_DEVICE_VER(FTDI_VID, FTDI_VNHCPCUSB_D_PID, 0x400, 0xffff) },
400 { USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0x400, 0xffff) },
401 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_0_PID, 0x400, 0xffff) },
402 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_1_PID, 0x400, 0xffff) },
403 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_2_PID, 0x400, 0xffff) },
404 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_3_PID, 0x400, 0xffff) },
405 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_4_PID, 0x400, 0xffff) },
406 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_5_PID, 0x400, 0xffff) },
407 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_6_PID, 0x400, 0xffff) },
408 { USB_DEVICE_VER(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID, 0x400, 0xffff) },
409 { USB_DEVICE_VER(FTDI_VID, FTDI_PIEGROUP_PID, 0x400, 0xffff) },
410 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2101_PID, 0x400, 0xffff) },
411 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2102_PID, 0x400, 0xffff) },
412 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2103_PID, 0x400, 0xffff) },
413 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2104_PID, 0x400, 0xffff) },
414 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_1_PID, 0x400, 0xffff) },
415 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_2_PID, 0x400, 0xffff) },
416 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_1_PID, 0x400, 0xffff) },
417 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_2_PID, 0x400, 0xffff) },
418 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_1_PID, 0x400, 0xffff) },
419 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_2_PID, 0x400, 0xffff) },
420 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_1_PID, 0x400, 0xffff) },
421 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_2_PID, 0x400, 0xffff) },
422 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_3_PID, 0x400, 0xffff) },
423 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_4_PID, 0x400, 0xffff) },
424 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_1_PID, 0x400, 0xffff) },
425 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_2_PID, 0x400, 0xffff) },
426 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_3_PID, 0x400, 0xffff) },
427 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_4_PID, 0x400, 0xffff) },
428 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_1_PID, 0x400, 0xffff) },
429 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_2_PID, 0x400, 0xffff) },
430 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_3_PID, 0x400, 0xffff) },
431 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_4_PID, 0x400, 0xffff) },
432 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_1_PID, 0x400, 0xffff) },
433 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_2_PID, 0x400, 0xffff) },
434 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_3_PID, 0x400, 0xffff) },
435 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_4_PID, 0x400, 0xffff) },
436 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_5_PID, 0x400, 0xffff) },
437 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_6_PID, 0x400, 0xffff) },
438 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_7_PID, 0x400, 0xffff) },
439 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_8_PID, 0x400, 0xffff) },
440 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_1_PID, 0x400, 0xffff) },
441 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_2_PID, 0x400, 0xffff) },
442 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_3_PID, 0x400, 0xffff) },
443 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_4_PID, 0x400, 0xffff) },
444 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_5_PID, 0x400, 0xffff) },
445 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_6_PID, 0x400, 0xffff) },
446 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_7_PID, 0x400, 0xffff) },
447 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_8_PID, 0x400, 0xffff) },
448 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_1_PID, 0x400, 0xffff) },
449 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_2_PID, 0x400, 0xffff) },
450 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_3_PID, 0x400, 0xffff) },
451 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_4_PID, 0x400, 0xffff) },
452 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_5_PID, 0x400, 0xffff) },
453 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_6_PID, 0x400, 0xffff) },
454 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_7_PID, 0x400, 0xffff) },
455 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_8_PID, 0x400, 0xffff) },
456 { USB_DEVICE_VER(IDTECH_VID, IDTECH_IDT1221U_PID, 0x400, 0xffff) },
457 { USB_DEVICE_VER(OCT_VID, OCT_US101_PID, 0x400, 0xffff) },
458 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_1, 0x400, 0xffff) },
459 { USB_DEVICE_VER(FTDI_VID, PROTEGO_R2X0, 0x400, 0xffff) },
460 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0x400, 0xffff) },
461 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0x400, 0xffff) },
462 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E808_PID, 0x400, 0xffff) },
463 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E809_PID, 0x400, 0xffff) },
464 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80A_PID, 0x400, 0xffff) },
465 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80B_PID, 0x400, 0xffff) },
466 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80C_PID, 0x400, 0xffff) },
467 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80D_PID, 0x400, 0xffff) },
468 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80E_PID, 0x400, 0xffff) },
469 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80F_PID, 0x400, 0xffff) },
470 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E888_PID, 0x400, 0xffff) },
471 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E889_PID, 0x400, 0xffff) },
472 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88A_PID, 0x400, 0xffff) },
473 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88B_PID, 0x400, 0xffff) },
474 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88C_PID, 0x400, 0xffff) },
475 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88D_PID, 0x400, 0xffff) },
476 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88E_PID, 0x400, 0xffff) },
477 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88F_PID, 0x400, 0xffff) },
478 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0x400, 0xffff) },
479 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UM100_PID, 0x400, 0xffff) },
480 { USB_DEVICE_VER(FTDI_VID, LINX_SDMUSBQSS_PID, 0x400, 0xffff) },
481 { USB_DEVICE_VER(FTDI_VID, LINX_MASTERDEVEL2_PID, 0x400, 0xffff) },
482 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_0_PID, 0x400, 0xffff) },
483 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_1_PID, 0x400, 0xffff) },
484 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_2_PID, 0x400, 0xffff) },
485 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
486 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
487 { USB_DEVICE_VER(FTDI_VID, INSIDE_ACCESSO, 0x400, 0xffff) },
488 { USB_DEVICE_VER(INTREPID_VID, INTREPID_VALUECAN_PID, 0x400, 0xffff) },
489 { USB_DEVICE_VER(INTREPID_VID, INTREPID_NEOVI_PID, 0x400, 0xffff) },
490 { USB_DEVICE_VER(FALCOM_VID, FALCOM_TWIST_PID, 0x400, 0xffff) },
491 { USB_DEVICE_VER(FTDI_VID, FTDI_SUUNTO_SPORTS_PID, 0x400, 0xffff) },
492 { USB_DEVICE_VER(FTDI_VID, FTDI_RM_CANVIEW_PID, 0x400, 0xffff) },
493 { USB_DEVICE_VER(BANDB_VID, BANDB_USOTL4_PID, 0x400, 0xffff) },
494 { USB_DEVICE_VER(BANDB_VID, BANDB_USTL4_PID, 0x400, 0xffff) },
495 { USB_DEVICE_VER(BANDB_VID, BANDB_USO9ML2_PID, 0x400, 0xffff) },
496 { USB_DEVICE_VER(FTDI_VID, EVER_ECO_PRO_CDS, 0x400, 0xffff) },
497 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID, 0x400, 0xffff) },
498 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID, 0x400, 0xffff) },
499 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID, 0x400, 0xffff) },
500 { USB_DEVICE_VER(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID, 0x400, 0xffff) },
501 { } /* Terminating entry */
502};
503
504
505static struct usb_device_id id_table_USB_UIRT [] = {
506 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID) },
507 { } /* Terminating entry */
508};
509
510
511static struct usb_device_id id_table_HE_TIRA1 [] = {
512 { USB_DEVICE_VER(FTDI_VID, FTDI_HE_TIRA1_PID, 0x400, 0xffff) },
513 { } /* Terminating entry */
514};
515
516
517static struct usb_device_id id_table_FT2232C[] = {
518 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
519 { } /* Terminating entry */
520};
521
522 306
523static struct usb_device_id id_table_combined [] = { 307static struct usb_device_id id_table_combined [] = {
524 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 308 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
@@ -540,14 +324,14 @@ static struct usb_device_id id_table_combined [] = {
540 { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) }, 324 { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },
541 { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) }, 325 { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
542 { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) }, 326 { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) },
543 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_0_PID, 0x400, 0xffff) }, 327 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) },
544 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_1_PID, 0x400, 0xffff) }, 328 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) },
545 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_2_PID, 0x400, 0xffff) }, 329 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) },
546 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_3_PID, 0x400, 0xffff) }, 330 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) },
547 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_4_PID, 0x400, 0xffff) }, 331 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
548 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_5_PID, 0x400, 0xffff) }, 332 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
549 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_6_PID, 0x400, 0xffff) }, 333 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
550 { USB_DEVICE_VER(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID, 0x400, 0xffff) }, 334 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
551 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 335 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
552 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, 336 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
553 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 337 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
@@ -597,35 +381,37 @@ static struct usb_device_id id_table_combined [] = {
597 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) }, 381 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
598 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) }, 382 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
599 { USB_DEVICE(OCT_VID, OCT_US101_PID) }, 383 { USB_DEVICE(OCT_VID, OCT_US101_PID) },
600 { USB_DEVICE_VER(FTDI_VID, FTDI_HE_TIRA1_PID, 0x400, 0xffff) }, 384 { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
601 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID) }, 385 .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
386 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
387 .driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk },
602 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) }, 388 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) },
603 { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) }, 389 { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) },
604 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) }, 390 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
605 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) }, 391 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
606 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E808_PID, 0x400, 0xffff) }, 392 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) },
607 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E809_PID, 0x400, 0xffff) }, 393 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) },
608 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80A_PID, 0x400, 0xffff) }, 394 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) },
609 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80B_PID, 0x400, 0xffff) }, 395 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) },
610 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80C_PID, 0x400, 0xffff) }, 396 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) },
611 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80D_PID, 0x400, 0xffff) }, 397 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) },
612 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80E_PID, 0x400, 0xffff) }, 398 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) },
613 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80F_PID, 0x400, 0xffff) }, 399 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) },
614 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E888_PID, 0x400, 0xffff) }, 400 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) },
615 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E889_PID, 0x400, 0xffff) }, 401 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) },
616 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88A_PID, 0x400, 0xffff) }, 402 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) },
617 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88B_PID, 0x400, 0xffff) }, 403 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) },
618 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88C_PID, 0x400, 0xffff) }, 404 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) },
619 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88D_PID, 0x400, 0xffff) }, 405 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) },
620 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88E_PID, 0x400, 0xffff) }, 406 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) },
621 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88F_PID, 0x400, 0xffff) }, 407 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
622 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) }, 408 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
623 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) }, 409 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
624 { USB_DEVICE_VER(FTDI_VID, LINX_SDMUSBQSS_PID, 0x400, 0xffff) }, 410 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
625 { USB_DEVICE_VER(FTDI_VID, LINX_MASTERDEVEL2_PID, 0x400, 0xffff) }, 411 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
626 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_0_PID, 0x400, 0xffff) }, 412 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
627 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_1_PID, 0x400, 0xffff) }, 413 { USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) },
628 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_2_PID, 0x400, 0xffff) }, 414 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
629 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) }, 415 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
630 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) }, 416 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
631 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) }, 417 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
@@ -642,7 +428,7 @@ static struct usb_device_id id_table_combined [] = {
642 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 428 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
643 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 429 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
644 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 430 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
645 { USB_DEVICE_VER(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID, 0x400, 0xffff) }, 431 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
646 { } /* Terminating entry */ 432 { } /* Terminating entry */
647}; 433};
648 434
@@ -705,12 +491,8 @@ struct ftdi_private {
705 ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP ) 491 ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP )
706 492
707/* function prototypes for a FTDI serial converter */ 493/* function prototypes for a FTDI serial converter */
708static int ftdi_SIO_startup (struct usb_serial *serial); 494static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id);
709static int ftdi_8U232AM_startup (struct usb_serial *serial); 495static int ftdi_sio_attach (struct usb_serial *serial);
710static int ftdi_FT232BM_startup (struct usb_serial *serial);
711static int ftdi_FT2232C_startup (struct usb_serial *serial);
712static int ftdi_USB_UIRT_startup (struct usb_serial *serial);
713static int ftdi_HE_TIRA1_startup (struct usb_serial *serial);
714static void ftdi_shutdown (struct usb_serial *serial); 496static void ftdi_shutdown (struct usb_serial *serial);
715static int ftdi_open (struct usb_serial_port *port, struct file *filp); 497static int ftdi_open (struct usb_serial_port *port, struct file *filp);
716static void ftdi_close (struct usb_serial_port *port, struct file *filp); 498static void ftdi_close (struct usb_serial_port *port, struct file *filp);
@@ -733,14 +515,16 @@ static unsigned short int ftdi_232am_baud_to_divisor (int baud);
733static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 515static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base);
734static __u32 ftdi_232bm_baud_to_divisor (int baud); 516static __u32 ftdi_232bm_baud_to_divisor (int baud);
735 517
736static struct usb_serial_device_type ftdi_SIO_device = { 518static struct usb_serial_device_type ftdi_sio_device = {
737 .owner = THIS_MODULE, 519 .owner = THIS_MODULE,
738 .name = "FTDI SIO", 520 .name = "FTDI USB Serial Device",
739 .id_table = id_table_sio, 521 .short_name = "ftdi_sio",
522 .id_table = id_table_combined,
740 .num_interrupt_in = 0, 523 .num_interrupt_in = 0,
741 .num_bulk_in = 1, 524 .num_bulk_in = 1,
742 .num_bulk_out = 1, 525 .num_bulk_out = 1,
743 .num_ports = 1, 526 .num_ports = 1,
527 .probe = ftdi_sio_probe,
744 .open = ftdi_open, 528 .open = ftdi_open,
745 .close = ftdi_close, 529 .close = ftdi_close,
746 .throttle = ftdi_throttle, 530 .throttle = ftdi_throttle,
@@ -755,143 +539,10 @@ static struct usb_serial_device_type ftdi_SIO_device = {
755 .ioctl = ftdi_ioctl, 539 .ioctl = ftdi_ioctl,
756 .set_termios = ftdi_set_termios, 540 .set_termios = ftdi_set_termios,
757 .break_ctl = ftdi_break_ctl, 541 .break_ctl = ftdi_break_ctl,
758 .attach = ftdi_SIO_startup, 542 .attach = ftdi_sio_attach,
759 .shutdown = ftdi_shutdown, 543 .shutdown = ftdi_shutdown,
760}; 544};
761 545
762static struct usb_serial_device_type ftdi_8U232AM_device = {
763 .owner = THIS_MODULE,
764 .name = "FTDI 8U232AM Compatible",
765 .id_table = id_table_8U232AM,
766 .num_interrupt_in = 0,
767 .num_bulk_in = 1,
768 .num_bulk_out = 1,
769 .num_ports = 1,
770 .open = ftdi_open,
771 .close = ftdi_close,
772 .throttle = ftdi_throttle,
773 .unthrottle = ftdi_unthrottle,
774 .write = ftdi_write,
775 .write_room = ftdi_write_room,
776 .chars_in_buffer = ftdi_chars_in_buffer,
777 .read_bulk_callback = ftdi_read_bulk_callback,
778 .write_bulk_callback = ftdi_write_bulk_callback,
779 .tiocmget = ftdi_tiocmget,
780 .tiocmset = ftdi_tiocmset,
781 .ioctl = ftdi_ioctl,
782 .set_termios = ftdi_set_termios,
783 .break_ctl = ftdi_break_ctl,
784 .attach = ftdi_8U232AM_startup,
785 .shutdown = ftdi_shutdown,
786};
787
788static struct usb_serial_device_type ftdi_FT232BM_device = {
789 .owner = THIS_MODULE,
790 .name = "FTDI FT232BM Compatible",
791 .id_table = id_table_FT232BM,
792 .num_interrupt_in = 0,
793 .num_bulk_in = 1,
794 .num_bulk_out = 1,
795 .num_ports = 1,
796 .open = ftdi_open,
797 .close = ftdi_close,
798 .throttle = ftdi_throttle,
799 .unthrottle = ftdi_unthrottle,
800 .write = ftdi_write,
801 .write_room = ftdi_write_room,
802 .chars_in_buffer = ftdi_chars_in_buffer,
803 .read_bulk_callback = ftdi_read_bulk_callback,
804 .write_bulk_callback = ftdi_write_bulk_callback,
805 .tiocmget = ftdi_tiocmget,
806 .tiocmset = ftdi_tiocmset,
807 .ioctl = ftdi_ioctl,
808 .set_termios = ftdi_set_termios,
809 .break_ctl = ftdi_break_ctl,
810 .attach = ftdi_FT232BM_startup,
811 .shutdown = ftdi_shutdown,
812};
813
814static struct usb_serial_device_type ftdi_FT2232C_device = {
815 .owner = THIS_MODULE,
816 .name = "FTDI FT2232C Compatible",
817 .id_table = id_table_FT2232C,
818 .num_interrupt_in = 0,
819 .num_bulk_in = 1,
820 .num_bulk_out = 1,
821 .num_ports = 1,
822 .open = ftdi_open,
823 .close = ftdi_close,
824 .throttle = ftdi_throttle,
825 .unthrottle = ftdi_unthrottle,
826 .write = ftdi_write,
827 .write_room = ftdi_write_room,
828 .chars_in_buffer = ftdi_chars_in_buffer,
829 .read_bulk_callback = ftdi_read_bulk_callback,
830 .write_bulk_callback = ftdi_write_bulk_callback,
831 .tiocmget = ftdi_tiocmget,
832 .tiocmset = ftdi_tiocmset,
833 .ioctl = ftdi_ioctl,
834 .set_termios = ftdi_set_termios,
835 .break_ctl = ftdi_break_ctl,
836 .attach = ftdi_FT2232C_startup,
837 .shutdown = ftdi_shutdown,
838};
839
840static struct usb_serial_device_type ftdi_USB_UIRT_device = {
841 .owner = THIS_MODULE,
842 .name = "USB-UIRT Infrared Tranceiver",
843 .id_table = id_table_USB_UIRT,
844 .num_interrupt_in = 0,
845 .num_bulk_in = 1,
846 .num_bulk_out = 1,
847 .num_ports = 1,
848 .open = ftdi_open,
849 .close = ftdi_close,
850 .throttle = ftdi_throttle,
851 .unthrottle = ftdi_unthrottle,
852 .write = ftdi_write,
853 .write_room = ftdi_write_room,
854 .chars_in_buffer = ftdi_chars_in_buffer,
855 .read_bulk_callback = ftdi_read_bulk_callback,
856 .write_bulk_callback = ftdi_write_bulk_callback,
857 .tiocmget = ftdi_tiocmget,
858 .tiocmset = ftdi_tiocmset,
859 .ioctl = ftdi_ioctl,
860 .set_termios = ftdi_set_termios,
861 .break_ctl = ftdi_break_ctl,
862 .attach = ftdi_USB_UIRT_startup,
863 .shutdown = ftdi_shutdown,
864};
865
866/* The TIRA1 is based on a FT232BM which requires a fixed baud rate of 100000
867 * and which requires RTS-CTS to be enabled. */
868static struct usb_serial_device_type ftdi_HE_TIRA1_device = {
869 .owner = THIS_MODULE,
870 .name = "Home-Electronics TIRA-1 IR Transceiver",
871 .id_table = id_table_HE_TIRA1,
872 .num_interrupt_in = 0,
873 .num_bulk_in = 1,
874 .num_bulk_out = 1,
875 .num_ports = 1,
876 .open = ftdi_open,
877 .close = ftdi_close,
878 .throttle = ftdi_throttle,
879 .unthrottle = ftdi_unthrottle,
880 .write = ftdi_write,
881 .write_room = ftdi_write_room,
882 .chars_in_buffer = ftdi_chars_in_buffer,
883 .read_bulk_callback = ftdi_read_bulk_callback,
884 .write_bulk_callback = ftdi_write_bulk_callback,
885 .tiocmget = ftdi_tiocmget,
886 .tiocmset = ftdi_tiocmset,
887 .ioctl = ftdi_ioctl,
888 .set_termios = ftdi_set_termios,
889 .break_ctl = ftdi_break_ctl,
890 .attach = ftdi_HE_TIRA1_startup,
891 .shutdown = ftdi_shutdown,
892};
893
894
895 546
896#define WDR_TIMEOUT 5000 /* default urb timeout */ 547#define WDR_TIMEOUT 5000 /* default urb timeout */
897 548
@@ -1212,6 +863,59 @@ check_and_exit:
1212} /* set_serial_info */ 863} /* set_serial_info */
1213 864
1214 865
866/* Determine type of FTDI chip based on USB config and descriptor. */
867static void ftdi_determine_type(struct usb_serial_port *port)
868{
869 struct ftdi_private *priv = usb_get_serial_port_data(port);
870 struct usb_serial *serial = port->serial;
871 struct usb_device *udev = serial->dev;
872 unsigned version;
873 unsigned interfaces;
874
875 /* Assume it is not the original SIO device for now. */
876 priv->baud_base = 48000000 / 16;
877 priv->write_offset = 0;
878
879 version = le16_to_cpu(udev->descriptor.bcdDevice);
880 interfaces = udev->actconfig->desc.bNumInterfaces;
881 dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __FUNCTION__,
882 version, interfaces);
883 if (interfaces > 1) {
884 int inter;
885
886 /* Multiple interfaces. Assume FT2232C. */
887 priv->chip_type = FT2232C;
888 /* Determine interface code. */
889 inter = serial->interface->altsetting->desc.bInterfaceNumber;
890 if (inter == 0) {
891 priv->interface = PIT_SIOA;
892 } else {
893 priv->interface = PIT_SIOB;
894 }
895 /* BM-type devices have a bug where bcdDevice gets set
896 * to 0x200 when iSerialNumber is 0. */
897 if (version < 0x500) {
898 dbg("%s: something fishy - bcdDevice too low for multi-interface device",
899 __FUNCTION__);
900 }
901 } else if (version < 0x200) {
902 /* Old device. Assume its the original SIO. */
903 priv->chip_type = SIO;
904 priv->baud_base = 12000000 / 16;
905 priv->write_offset = 1;
906 } else if (version < 0x400) {
907 /* Assume its an FT8U232AM (or FT8U245AM) */
908 /* (It might be a BM because of the iSerialNumber bug,
909 * but it will still work as an AM device.) */
910 priv->chip_type = FT8U232AM;
911 } else {
912 /* Assume its an FT232BM (or FT245BM) */
913 priv->chip_type = FT232BM;
914 }
915 info("Detected %s", ftdi_chip_name[priv->chip_type]);
916}
917
918
1215/* 919/*
1216 * *************************************************************************** 920 * ***************************************************************************
1217 * Sysfs Attribute 921 * Sysfs Attribute
@@ -1355,12 +1059,20 @@ static void remove_sysfs_attrs(struct usb_serial *serial)
1355 * *************************************************************************** 1059 * ***************************************************************************
1356 */ 1060 */
1357 1061
1358/* Common startup subroutine */ 1062/* Probe function to check for special devices */
1359/* Called from ftdi_SIO_startup, etc. */ 1063static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id)
1360static int ftdi_common_startup (struct usb_serial *serial) 1064{
1065 usb_set_serial_data(serial, (void *)id->driver_info);
1066
1067 return (0);
1068}
1069
1070/* attach subroutine */
1071static int ftdi_sio_attach (struct usb_serial *serial)
1361{ 1072{
1362 struct usb_serial_port *port = serial->port[0]; 1073 struct usb_serial_port *port = serial->port[0];
1363 struct ftdi_private *priv; 1074 struct ftdi_private *priv;
1075 struct ftdi_sio_quirk *quirk;
1364 1076
1365 dbg("%s",__FUNCTION__); 1077 dbg("%s",__FUNCTION__);
1366 1078
@@ -1400,150 +1112,49 @@ static int ftdi_common_startup (struct usb_serial *serial)
1400 port->bulk_out_buffer = NULL; 1112 port->bulk_out_buffer = NULL;
1401 1113
1402 usb_set_serial_port_data(serial->port[0], priv); 1114 usb_set_serial_port_data(serial->port[0], priv);
1403
1404 return (0);
1405}
1406
1407
1408/* Startup for the SIO chip */
1409/* Called from usbserial:serial_probe */
1410static int ftdi_SIO_startup (struct usb_serial *serial)
1411{
1412 struct ftdi_private *priv;
1413 int err;
1414
1415 dbg("%s",__FUNCTION__);
1416
1417 err = ftdi_common_startup(serial);
1418 if (err){
1419 return (err);
1420 }
1421
1422 priv = usb_get_serial_port_data(serial->port[0]);
1423 priv->chip_type = SIO;
1424 priv->baud_base = 12000000 / 16;
1425 priv->write_offset = 1;
1426
1427 return (0);
1428}
1429
1430/* Startup for the 8U232AM chip */
1431/* Called from usbserial:serial_probe */
1432static int ftdi_8U232AM_startup (struct usb_serial *serial)
1433{ /* ftdi_8U232AM_startup */
1434 struct ftdi_private *priv;
1435 int err;
1436
1437 dbg("%s",__FUNCTION__);
1438 err = ftdi_common_startup(serial);
1439 if (err){
1440 return (err);
1441 }
1442 1115
1443 priv = usb_get_serial_port_data(serial->port[0]); 1116 ftdi_determine_type (serial->port[0]);
1444 priv->chip_type = FT8U232AM;
1445 priv->baud_base = 48000000 / 2; /* Would be / 16, but FTDI supports 0.125, 0.25 and 0.5 divisor fractions! */
1446
1447 create_sysfs_attrs(serial); 1117 create_sysfs_attrs(serial);
1448
1449 return (0);
1450} /* ftdi_8U232AM_startup */
1451 1118
1452/* Startup for the FT232BM chip */ 1119 /* Check for device requiring special set up. */
1453/* Called from usbserial:serial_probe */ 1120 quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial);
1454static int ftdi_FT232BM_startup (struct usb_serial *serial) 1121 if (quirk && quirk->setup) {
1455{ /* ftdi_FT232BM_startup */ 1122 quirk->setup(serial);
1456 struct ftdi_private *priv;
1457 int err;
1458
1459 dbg("%s",__FUNCTION__);
1460 err = ftdi_common_startup(serial);
1461 if (err){
1462 return (err);
1463 } 1123 }
1464
1465 priv = usb_get_serial_port_data(serial->port[0]);
1466 priv->chip_type = FT232BM;
1467 priv->baud_base = 48000000 / 2; /* Would be / 16, but FT232BM supports multiple of 0.125 divisor fractions! */
1468 1124
1469 create_sysfs_attrs(serial);
1470
1471 return (0); 1125 return (0);
1472} /* ftdi_FT232BM_startup */ 1126} /* ftdi_sio_attach */
1473
1474/* Startup for the FT2232C chip */
1475/* Called from usbserial:serial_probe */
1476static int ftdi_FT2232C_startup (struct usb_serial *serial)
1477{ /* ftdi_FT2232C_startup */
1478 struct ftdi_private *priv;
1479 int err;
1480 int inter;
1481
1482 dbg("%s",__FUNCTION__);
1483 err = ftdi_common_startup(serial);
1484 if (err){
1485 return (err);
1486 }
1487 1127
1488 priv = usb_get_serial_port_data(serial->port[0]);
1489 priv->chip_type = FT2232C;
1490 inter = serial->interface->altsetting->desc.bInterfaceNumber;
1491 1128
1492 if (inter) { 1129/* Setup for the USB-UIRT device, which requires hardwired
1493 priv->interface = PIT_SIOB; 1130 * baudrate (38400 gets mapped to 312500) */
1494 }
1495 else {
1496 priv->interface = PIT_SIOA;
1497 }
1498 priv->baud_base = 48000000 / 2; /* Would be / 16, but FT2232C supports multiple of 0.125 divisor fractions! */
1499
1500 create_sysfs_attrs(serial);
1501
1502 return (0);
1503} /* ftdi_FT2232C_startup */
1504
1505/* Startup for the USB-UIRT device, which requires hardwired baudrate (38400 gets mapped to 312500) */
1506/* Called from usbserial:serial_probe */ 1131/* Called from usbserial:serial_probe */
1507static int ftdi_USB_UIRT_startup (struct usb_serial *serial) 1132static void ftdi_USB_UIRT_setup (struct usb_serial *serial)
1508{ /* ftdi_USB_UIRT_startup */ 1133{
1509 struct ftdi_private *priv; 1134 struct ftdi_private *priv;
1510 int err;
1511 1135
1512 dbg("%s",__FUNCTION__); 1136 dbg("%s",__FUNCTION__);
1513 err = ftdi_8U232AM_startup(serial);
1514 if (err){
1515 return (err);
1516 }
1517 1137
1518 priv = usb_get_serial_port_data(serial->port[0]); 1138 priv = usb_get_serial_port_data(serial->port[0]);
1519 priv->flags |= ASYNC_SPD_CUST; 1139 priv->flags |= ASYNC_SPD_CUST;
1520 priv->custom_divisor = 77; 1140 priv->custom_divisor = 77;
1521 priv->force_baud = B38400; 1141 priv->force_baud = B38400;
1522 1142} /* ftdi_USB_UIRT_setup */
1523 return (0);
1524} /* ftdi_USB_UIRT_startup */
1525 1143
1526/* Startup for the HE-TIRA1 device, which requires hardwired 1144/* Setup for the HE-TIRA1 device, which requires hardwired
1527 * baudrate (38400 gets mapped to 100000) */ 1145 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
1528static int ftdi_HE_TIRA1_startup (struct usb_serial *serial) 1146static void ftdi_HE_TIRA1_setup (struct usb_serial *serial)
1529{ /* ftdi_HE_TIRA1_startup */ 1147{
1530 struct ftdi_private *priv; 1148 struct ftdi_private *priv;
1531 int err;
1532 1149
1533 dbg("%s",__FUNCTION__); 1150 dbg("%s",__FUNCTION__);
1534 err = ftdi_FT232BM_startup(serial);
1535 if (err){
1536 return (err);
1537 }
1538 1151
1539 priv = usb_get_serial_port_data(serial->port[0]); 1152 priv = usb_get_serial_port_data(serial->port[0]);
1540 priv->flags |= ASYNC_SPD_CUST; 1153 priv->flags |= ASYNC_SPD_CUST;
1541 priv->custom_divisor = 240; 1154 priv->custom_divisor = 240;
1542 priv->force_baud = B38400; 1155 priv->force_baud = B38400;
1543 priv->force_rtscts = 1; 1156 priv->force_rtscts = 1;
1544 1157} /* ftdi_HE_TIRA1_setup */
1545 return (0);
1546} /* ftdi_HE_TIRA1_startup */
1547 1158
1548 1159
1549/* ftdi_shutdown is called from usbserial:usb_serial_disconnect 1160/* ftdi_shutdown is called from usbserial:usb_serial_disconnect
@@ -2367,60 +1978,11 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2367{ 1978{
2368 struct ftdi_private *priv = usb_get_serial_port_data(port); 1979 struct ftdi_private *priv = usb_get_serial_port_data(port);
2369 1980
2370 int ret, mask;
2371
2372 dbg("%s cmd 0x%04x", __FUNCTION__, cmd); 1981 dbg("%s cmd 0x%04x", __FUNCTION__, cmd);
2373 1982
2374 /* Based on code from acm.c and others */ 1983 /* Based on code from acm.c and others */
2375 switch (cmd) { 1984 switch (cmd) {
2376 1985
2377 case TIOCMBIS: /* turns on (Sets) the lines as specified by the mask */
2378 dbg("%s TIOCMBIS", __FUNCTION__);
2379 if (get_user(mask, (unsigned long __user *) arg))
2380 return -EFAULT;
2381 if (mask & TIOCM_DTR){
2382 if ((ret = set_dtr(port, HIGH)) < 0) {
2383 err("Urb to set DTR failed");
2384 return(ret);
2385 }
2386 }
2387 if (mask & TIOCM_RTS) {
2388 if ((ret = set_rts(port, HIGH)) < 0){
2389 err("Urb to set RTS failed");
2390 return(ret);
2391 }
2392 }
2393 return(0);
2394 break;
2395
2396 case TIOCMBIC: /* turns off (Clears) the lines as specified by the mask */
2397 dbg("%s TIOCMBIC", __FUNCTION__);
2398 if (get_user(mask, (unsigned long __user *) arg))
2399 return -EFAULT;
2400 if (mask & TIOCM_DTR){
2401 if ((ret = set_dtr(port, LOW)) < 0){
2402 err("Urb to unset DTR failed");
2403 return(ret);
2404 }
2405 }
2406 if (mask & TIOCM_RTS) {
2407 if ((ret = set_rts(port, LOW)) < 0){
2408 err("Urb to unset RTS failed");
2409 return(ret);
2410 }
2411 }
2412 return(0);
2413 break;
2414
2415 /*
2416 * I had originally implemented TCSET{A,S}{,F,W} and
2417 * TCGET{A,S} here separately, however when testing I
2418 * found that the higher layers actually do the termios
2419 * conversions themselves and pass the call onto
2420 * ftdi_sio_set_termios.
2421 *
2422 */
2423
2424 case TIOCGSERIAL: /* gets serial port data */ 1986 case TIOCGSERIAL: /* gets serial port data */
2425 return get_serial_info(port, (struct serial_struct __user *) arg); 1987 return get_serial_info(port, (struct serial_struct __user *) arg);
2426 1988
@@ -2516,24 +2078,9 @@ static int __init ftdi_init (void)
2516 int retval; 2078 int retval;
2517 2079
2518 dbg("%s", __FUNCTION__); 2080 dbg("%s", __FUNCTION__);
2519 retval = usb_serial_register(&ftdi_SIO_device); 2081 retval = usb_serial_register(&ftdi_sio_device);
2520 if (retval)
2521 goto failed_SIO_register;
2522 retval = usb_serial_register(&ftdi_8U232AM_device);
2523 if (retval)
2524 goto failed_8U232AM_register;
2525 retval = usb_serial_register(&ftdi_FT232BM_device);
2526 if (retval)
2527 goto failed_FT232BM_register;
2528 retval = usb_serial_register(&ftdi_FT2232C_device);
2529 if (retval)
2530 goto failed_FT2232C_register;
2531 retval = usb_serial_register(&ftdi_USB_UIRT_device);
2532 if (retval)
2533 goto failed_USB_UIRT_register;
2534 retval = usb_serial_register(&ftdi_HE_TIRA1_device);
2535 if (retval) 2082 if (retval)
2536 goto failed_HE_TIRA1_register; 2083 goto failed_sio_register;
2537 retval = usb_register(&ftdi_driver); 2084 retval = usb_register(&ftdi_driver);
2538 if (retval) 2085 if (retval)
2539 goto failed_usb_register; 2086 goto failed_usb_register;
@@ -2541,18 +2088,8 @@ static int __init ftdi_init (void)
2541 info(DRIVER_VERSION ":" DRIVER_DESC); 2088 info(DRIVER_VERSION ":" DRIVER_DESC);
2542 return 0; 2089 return 0;
2543failed_usb_register: 2090failed_usb_register:
2544 usb_serial_deregister(&ftdi_HE_TIRA1_device); 2091 usb_serial_deregister(&ftdi_sio_device);
2545failed_HE_TIRA1_register: 2092failed_sio_register:
2546 usb_serial_deregister(&ftdi_USB_UIRT_device);
2547failed_USB_UIRT_register:
2548 usb_serial_deregister(&ftdi_FT2232C_device);
2549failed_FT2232C_register:
2550 usb_serial_deregister(&ftdi_FT232BM_device);
2551failed_FT232BM_register:
2552 usb_serial_deregister(&ftdi_8U232AM_device);
2553failed_8U232AM_register:
2554 usb_serial_deregister(&ftdi_SIO_device);
2555failed_SIO_register:
2556 return retval; 2093 return retval;
2557} 2094}
2558 2095
@@ -2563,12 +2100,7 @@ static void __exit ftdi_exit (void)
2563 dbg("%s", __FUNCTION__); 2100 dbg("%s", __FUNCTION__);
2564 2101
2565 usb_deregister (&ftdi_driver); 2102 usb_deregister (&ftdi_driver);
2566 usb_serial_deregister (&ftdi_HE_TIRA1_device); 2103 usb_serial_deregister (&ftdi_sio_device);
2567 usb_serial_deregister (&ftdi_USB_UIRT_device);
2568 usb_serial_deregister (&ftdi_FT2232C_device);
2569 usb_serial_deregister (&ftdi_FT232BM_device);
2570 usb_serial_deregister (&ftdi_8U232AM_device);
2571 usb_serial_deregister (&ftdi_SIO_device);
2572 2104
2573} 2105}
2574 2106
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 99214aa3cd19..ddde5fb13f6b 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -174,10 +174,14 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
174 174
175 /* only do something if we have a bulk out endpoint */ 175 /* only do something if we have a bulk out endpoint */
176 if (serial->num_bulk_out) { 176 if (serial->num_bulk_out) {
177 if (port->write_urb->status == -EINPROGRESS) { 177 spin_lock(&port->lock);
178 if (port->write_urb_busy) {
179 spin_unlock(&port->lock);
178 dbg("%s - already writing", __FUNCTION__); 180 dbg("%s - already writing", __FUNCTION__);
179 return (0); 181 return 0;
180 } 182 }
183 port->write_urb_busy = 1;
184 spin_unlock(&port->lock);
181 185
182 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 186 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
183 187
@@ -195,17 +199,20 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
195 usb_serial_generic_write_bulk_callback), port); 199 usb_serial_generic_write_bulk_callback), port);
196 200
197 /* send the data out the bulk port */ 201 /* send the data out the bulk port */
202 port->write_urb_busy = 1;
198 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 203 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
199 if (result) 204 if (result) {
200 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 205 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
201 else 206 /* don't have to grab the lock here, as we will retry if != 0 */
207 port->write_urb_busy = 0;
208 } else
202 result = count; 209 result = count;
203 210
204 return result; 211 return result;
205 } 212 }
206 213
207 /* no bulk out, so return 0 bytes written */ 214 /* no bulk out, so return 0 bytes written */
208 return (0); 215 return 0;
209} 216}
210 217
211int usb_serial_generic_write_room (struct usb_serial_port *port) 218int usb_serial_generic_write_room (struct usb_serial_port *port)
@@ -214,9 +221,9 @@ int usb_serial_generic_write_room (struct usb_serial_port *port)
214 int room = 0; 221 int room = 0;
215 222
216 dbg("%s - port %d", __FUNCTION__, port->number); 223 dbg("%s - port %d", __FUNCTION__, port->number);
217 224
218 if (serial->num_bulk_out) { 225 if (serial->num_bulk_out) {
219 if (port->write_urb->status != -EINPROGRESS) 226 if (port->write_urb_busy)
220 room = port->bulk_out_size; 227 room = port->bulk_out_size;
221 } 228 }
222 229
@@ -232,7 +239,7 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
232 dbg("%s - port %d", __FUNCTION__, port->number); 239 dbg("%s - port %d", __FUNCTION__, port->number);
233 240
234 if (serial->num_bulk_out) { 241 if (serial->num_bulk_out) {
235 if (port->write_urb->status == -EINPROGRESS) 242 if (port->write_urb_busy)
236 chars = port->write_urb->transfer_buffer_length; 243 chars = port->write_urb->transfer_buffer_length;
237 } 244 }
238 245
@@ -291,6 +298,7 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb, struct pt_regs *re
291 298
292 dbg("%s - port %d", __FUNCTION__, port->number); 299 dbg("%s - port %d", __FUNCTION__, port->number);
293 300
301 port->write_urb_busy = 0;
294 if (urb->status) { 302 if (urb->status) {
295 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 303 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
296 return; 304 return;
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 3bd69c4ef24b..c05c2a2a0f31 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -818,11 +818,6 @@ static void ipaq_write_gather(struct usb_serial_port *port)
818 struct ipaq_packet *pkt, *tmp; 818 struct ipaq_packet *pkt, *tmp;
819 struct urb *urb = port->write_urb; 819 struct urb *urb = port->write_urb;
820 820
821 if (urb->status == -EINPROGRESS) {
822 /* Should never happen */
823 err("%s - flushing while urb is active !", __FUNCTION__);
824 return;
825 }
826 room = URBDATA_SIZE; 821 room = URBDATA_SIZE;
827 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) { 822 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
828 count = min(room, (int)(pkt->len - pkt->written)); 823 count = min(room, (int)(pkt->len - pkt->written));
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 11105d74f461..85e242459c27 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -399,16 +399,21 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
399 dbg("%s - write request of 0 bytes", __FUNCTION__); 399 dbg("%s - write request of 0 bytes", __FUNCTION__);
400 return 0; 400 return 0;
401 } 401 }
402 402
403 /* Racy and broken, FIXME properly! */ 403 spin_lock(&port->lock);
404 if (port->write_urb->status == -EINPROGRESS) 404 if (port->write_urb_busy) {
405 spin_unlock(&port->lock);
406 dbg("%s - already writing", __FUNCTION__);
405 return 0; 407 return 0;
408 }
409 port->write_urb_busy = 1;
410 spin_unlock(&port->lock);
406 411
407 count = min(count, port->bulk_out_size); 412 count = min(count, port->bulk_out_size);
408 memcpy(port->bulk_out_buffer, buf, count); 413 memcpy(port->bulk_out_buffer, buf, count);
409 414
410 dbg("%s count now:%d", __FUNCTION__, count); 415 dbg("%s count now:%d", __FUNCTION__, count);
411 416
412 usb_fill_bulk_urb(port->write_urb, dev, 417 usb_fill_bulk_urb(port->write_urb, dev,
413 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), 418 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress),
414 port->write_urb->transfer_buffer, 419 port->write_urb->transfer_buffer,
@@ -418,6 +423,7 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
418 423
419 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 424 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
420 if (ret != 0) { 425 if (ret != 0) {
426 port->write_urb_busy = 0;
421 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret); 427 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret);
422 return ret; 428 return ret;
423 } 429 }
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 59f234df5f89..937b2fdd7171 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -341,10 +341,14 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
341 if (count == 0) 341 if (count == 0)
342 return 0; 342 return 0;
343 343
344 if (port->write_urb->status == -EINPROGRESS) { 344 spin_lock(&port->lock);
345 dbg ("%s - already writing", __FUNCTION__); 345 if (port->write_urb_busy) {
346 spin_unlock(&port->lock);
347 dbg("%s - already writing", __FUNCTION__);
346 return 0; 348 return 0;
347 } 349 }
350 port->write_urb_busy = 1;
351 spin_unlock(&port->lock);
348 352
349 transfer_buffer = port->write_urb->transfer_buffer; 353 transfer_buffer = port->write_urb->transfer_buffer;
350 transfer_size = min(count, port->bulk_out_size - 1); 354 transfer_size = min(count, port->bulk_out_size - 1);
@@ -374,9 +378,10 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
374 port->write_urb->transfer_flags = URB_ZERO_PACKET; 378 port->write_urb->transfer_flags = URB_ZERO_PACKET;
375 379
376 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 380 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
377 if (result) 381 if (result) {
382 port->write_urb_busy = 0;
378 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 383 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
379 else 384 } else
380 result = transfer_size; 385 result = transfer_size;
381 386
382 return result; 387 return result;
@@ -387,7 +392,8 @@ static void ir_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
387 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 392 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
388 393
389 dbg("%s - port %d", __FUNCTION__, port->number); 394 dbg("%s - port %d", __FUNCTION__, port->number);
390 395
396 port->write_urb_busy = 0;
391 if (urb->status) { 397 if (urb->status) {
392 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 398 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
393 return; 399 return;
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 7fd0aa9eccf6..635c384cb15a 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -520,9 +520,13 @@ static int keyspan_pda_write(struct usb_serial_port *port,
520 the TX urb is in-flight (wait until it completes) 520 the TX urb is in-flight (wait until it completes)
521 the device is full (wait until it says there is room) 521 the device is full (wait until it says there is room)
522 */ 522 */
523 if (port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) { 523 spin_lock(&port->lock);
524 return( 0 ); 524 if (port->write_urb_busy || priv->tx_throttled) {
525 spin_unlock(&port->lock);
526 return 0;
525 } 527 }
528 port->write_urb_busy = 1;
529 spin_unlock(&port->lock);
526 530
527 /* At this point the URB is in our control, nobody else can submit it 531 /* At this point the URB is in our control, nobody else can submit it
528 again (the only sudden transition was the one from EINPROGRESS to 532 again (the only sudden transition was the one from EINPROGRESS to
@@ -570,7 +574,7 @@ static int keyspan_pda_write(struct usb_serial_port *port,
570 memcpy (port->write_urb->transfer_buffer, buf, count); 574 memcpy (port->write_urb->transfer_buffer, buf, count);
571 /* send the data out the bulk port */ 575 /* send the data out the bulk port */
572 port->write_urb->transfer_buffer_length = count; 576 port->write_urb->transfer_buffer_length = count;
573 577
574 priv->tx_room -= count; 578 priv->tx_room -= count;
575 579
576 port->write_urb->dev = port->serial->dev; 580 port->write_urb->dev = port->serial->dev;
@@ -593,6 +597,8 @@ static int keyspan_pda_write(struct usb_serial_port *port,
593 597
594 rc = count; 598 rc = count;
595exit: 599exit:
600 if (rc < 0)
601 port->write_urb_busy = 0;
596 return rc; 602 return rc;
597} 603}
598 604
@@ -602,6 +608,7 @@ static void keyspan_pda_write_bulk_callback (struct urb *urb, struct pt_regs *re
602 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 608 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
603 struct keyspan_pda_private *priv; 609 struct keyspan_pda_private *priv;
604 610
611 port->write_urb_busy = 0;
605 priv = usb_get_serial_port_data(port); 612 priv = usb_get_serial_port_data(port);
606 613
607 /* queue up a wakeup at scheduler time */ 614 /* queue up a wakeup at scheduler time */
@@ -626,12 +633,12 @@ static int keyspan_pda_write_room (struct usb_serial_port *port)
626static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 633static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
627{ 634{
628 struct keyspan_pda_private *priv; 635 struct keyspan_pda_private *priv;
629 636
630 priv = usb_get_serial_port_data(port); 637 priv = usb_get_serial_port_data(port);
631 638
632 /* when throttled, return at least WAKEUP_CHARS to tell select() (via 639 /* when throttled, return at least WAKEUP_CHARS to tell select() (via
633 n_tty.c:normal_poll() ) that we're not writeable. */ 640 n_tty.c:normal_poll() ) that we're not writeable. */
634 if( port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) 641 if (port->write_urb_busy || priv->tx_throttled)
635 return 256; 642 return 256;
636 return 0; 643 return 0;
637} 644}
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index b5f2c06d4f3e..6a99ae192df1 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -254,10 +254,15 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
254 dbg("%s - write request of 0 bytes", __FUNCTION__); 254 dbg("%s - write request of 0 bytes", __FUNCTION__);
255 return (0); 255 return (0);
256 } 256 }
257 if (wport->write_urb->status == -EINPROGRESS) { 257
258 spin_lock(&port->lock);
259 if (port->write_urb_busy) {
260 spin_unlock(&port->lock);
258 dbg("%s - already writing", __FUNCTION__); 261 dbg("%s - already writing", __FUNCTION__);
259 return (0); 262 return 0;
260 } 263 }
264 port->write_urb_busy = 1;
265 spin_unlock(&port->lock);
261 266
262 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 267 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
263 268
@@ -275,9 +280,10 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
275 280
276 wport->write_urb->dev = serial->dev; 281 wport->write_urb->dev = serial->dev;
277 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 282 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
278 if (result) 283 if (result) {
284 port->write_urb_busy = 0;
279 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 285 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
280 else 286 } else
281 result = count; 287 result = count;
282 288
283 return result; 289 return result;
@@ -291,7 +297,7 @@ static int omninet_write_room (struct usb_serial_port *port)
291 297
292 int room = 0; // Default: no room 298 int room = 0; // Default: no room
293 299
294 if (wport->write_urb->status != -EINPROGRESS) 300 if (wport->write_urb_busy)
295 room = wport->bulk_out_size - OMNINET_HEADERLEN; 301 room = wport->bulk_out_size - OMNINET_HEADERLEN;
296 302
297// dbg("omninet_write_room returns %d", room); 303// dbg("omninet_write_room returns %d", room);
@@ -306,6 +312,7 @@ static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
306 312
307// dbg("omninet_write_bulk_callback, port %0x\n", port); 313// dbg("omninet_write_bulk_callback, port %0x\n", port);
308 314
315 port->write_urb_busy = 0;
309 if (urb->status) { 316 if (urb->status) {
310 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 317 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
311 return; 318 return;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index b722175f108f..e9256408757f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -12,14 +12,25 @@
12 History: 12 History:
13 13
14 2005-05-19 v0.1 Initial version, based on incomplete docs 14 2005-05-19 v0.1 Initial version, based on incomplete docs
15 and analysis of misbehavior of the standard driver 15 and analysis of misbehavior with the standard driver
16 2005-05-20 v0.2 Extended the input buffer to avoid losing 16 2005-05-20 v0.2 Extended the input buffer to avoid losing
17 random 64-byte chunks of data 17 random 64-byte chunks of data
18 2005-05-21 v0.3 implemented chars_in_buffer() 18 2005-05-21 v0.3 implemented chars_in_buffer()
19 turned on low_latency 19 turned on low_latency
20 simplified the code somewhat 20 simplified the code somewhat
21 2005-05-24 v0.4 option_write() sometimes deadlocked under heavy load
22 removed some dead code
23 added sponsor notice
24 coding style clean-up
25 2005-06-20 v0.4.1 add missing braces :-/
26 killed end-of-line whitespace
27 2005-07-15 v0.4.2 rename WLAN product to FUSION, add FUSION2
28
29 Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
30
21*/ 31*/
22#define DRIVER_VERSION "v0.3" 32
33#define DRIVER_VERSION "v0.4"
23#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>" 34#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
24#define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver" 35#define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver"
25 36
@@ -44,7 +55,6 @@ static int option_write_room (struct usb_serial_port *port);
44 55
45static void option_instat_callback(struct urb *urb, struct pt_regs *regs); 56static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
46 57
47
48static int option_write (struct usb_serial_port *port, 58static int option_write (struct usb_serial_port *port,
49 const unsigned char *buf, int count); 59 const unsigned char *buf, int count);
50 60
@@ -60,14 +70,17 @@ static int option_tiocmset (struct usb_serial_port *port, struct file *file,
60static int option_send_setup (struct usb_serial_port *port); 70static int option_send_setup (struct usb_serial_port *port);
61 71
62/* Vendor and product IDs */ 72/* Vendor and product IDs */
63#define OPTION_VENDOR_ID 0x0AF0 73#define OPTION_VENDOR_ID 0x0AF0
74
75#define OPTION_PRODUCT_OLD 0x5000
76#define OPTION_PRODUCT_FUSION 0x6000
77#define OPTION_PRODUCT_FUSION2 0x6300
64 78
65#define OPTION_PRODUCT_OLD 0x5000
66#define OPTION_PRODUCT_WLAN 0x6000
67 79
68static struct usb_device_id option_ids[] = { 80static struct usb_device_id option_ids[] = {
69 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
70 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_WLAN) }, 82 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
83 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
71 { } /* Terminating entry */ 84 { } /* Terminating entry */
72}; 85};
73 86
@@ -85,58 +98,62 @@ static struct usb_driver option_driver = {
85 * recognizes separately, thus num_port=1. 98 * recognizes separately, thus num_port=1.
86 */ 99 */
87static struct usb_serial_device_type option_3port_device = { 100static struct usb_serial_device_type option_3port_device = {
88 .owner = THIS_MODULE, 101 .owner = THIS_MODULE,
89 .name = "Option 3-port card", 102 .name = "Option 3G data card",
90 .short_name = "option", 103 .short_name = "option",
91 .id_table = option_ids, 104 .id_table = option_ids,
92 .num_interrupt_in = NUM_DONT_CARE, 105 .num_interrupt_in = NUM_DONT_CARE,
93 .num_bulk_in = NUM_DONT_CARE, 106 .num_bulk_in = NUM_DONT_CARE,
94 .num_bulk_out = NUM_DONT_CARE, 107 .num_bulk_out = NUM_DONT_CARE,
95 .num_ports = 1, /* 3 */ 108 .num_ports = 1, /* 3, but the card reports its ports separately */
96 .open = option_open, 109 .open = option_open,
97 .close = option_close, 110 .close = option_close,
98 .write = option_write, 111 .write = option_write,
99 .write_room = option_write_room, 112 .write_room = option_write_room,
100 .chars_in_buffer = option_chars_in_buffer, 113 .chars_in_buffer = option_chars_in_buffer,
101 .throttle = option_rx_throttle, 114 .throttle = option_rx_throttle,
102 .unthrottle = option_rx_unthrottle, 115 .unthrottle = option_rx_unthrottle,
103 .ioctl = option_ioctl, 116 .ioctl = option_ioctl,
104 .set_termios = option_set_termios, 117 .set_termios = option_set_termios,
105 .break_ctl = option_break_ctl, 118 .break_ctl = option_break_ctl,
106 .tiocmget = option_tiocmget, 119 .tiocmget = option_tiocmget,
107 .tiocmset = option_tiocmset, 120 .tiocmset = option_tiocmset,
108 .attach = option_startup, 121 .attach = option_startup,
109 .shutdown = option_shutdown, 122 .shutdown = option_shutdown,
110 .read_int_callback = option_instat_callback, 123 .read_int_callback = option_instat_callback,
111}; 124};
112 125
126#ifdef CONFIG_USB_DEBUG
113static int debug; 127static int debug;
128#else
129#define debug 0
130#endif
131
114 132
115/* per port private data */ 133/* per port private data */
116 134
117#define N_IN_URB 4 135#define N_IN_URB 4
118#define N_OUT_URB 1 136#define N_OUT_URB 1
119#define IN_BUFLEN 1024 137#define IN_BUFLEN 1024
120#define OUT_BUFLEN 1024 138#define OUT_BUFLEN 128
121 139
122struct option_port_private { 140struct option_port_private {
123 /* Input endpoints and buffer for this port */ 141 /* Input endpoints and buffer for this port */
124 struct urb *in_urbs[N_IN_URB]; 142 struct urb *in_urbs[N_IN_URB];
125 char in_buffer[N_IN_URB][IN_BUFLEN]; 143 char in_buffer[N_IN_URB][IN_BUFLEN];
126 /* Output endpoints and buffer for this port */ 144 /* Output endpoints and buffer for this port */
127 struct urb *out_urbs[N_OUT_URB]; 145 struct urb *out_urbs[N_OUT_URB];
128 char out_buffer[N_OUT_URB][OUT_BUFLEN]; 146 char out_buffer[N_OUT_URB][OUT_BUFLEN];
129 147
130 /* Settings for the port */ 148 /* Settings for the port */
131 int rts_state; /* Handshaking pins (outputs) */ 149 int rts_state; /* Handshaking pins (outputs) */
132 int dtr_state; 150 int dtr_state;
133 int cts_state; /* Handshaking pins (inputs) */ 151 int cts_state; /* Handshaking pins (inputs) */
134 int dsr_state; 152 int dsr_state;
135 int dcd_state; 153 int dcd_state;
136 int ri_state; 154 int ri_state;
137 // int break_on; 155
138 156 unsigned long tx_start_time[N_OUT_URB];
139 unsigned long tx_start_time[N_OUT_URB];
140}; 157};
141 158
142 159
@@ -190,13 +207,13 @@ static void
190option_break_ctl (struct usb_serial_port *port, int break_state) 207option_break_ctl (struct usb_serial_port *port, int break_state)
191{ 208{
192 /* Unfortunately, I don't know how to send a break */ 209 /* Unfortunately, I don't know how to send a break */
193 dbg("%s", __FUNCTION__); 210 dbg("%s", __FUNCTION__);
194} 211}
195 212
196 213
197static void 214static void
198option_set_termios (struct usb_serial_port *port, 215option_set_termios (struct usb_serial_port *port,
199 struct termios *old_termios) 216 struct termios *old_termios)
200{ 217{
201 dbg("%s", __FUNCTION__); 218 dbg("%s", __FUNCTION__);
202 219
@@ -204,10 +221,10 @@ option_set_termios (struct usb_serial_port *port,
204} 221}
205 222
206static int 223static int
207option_tiocmget(struct usb_serial_port *port, struct file *file) 224option_tiocmget (struct usb_serial_port *port, struct file *file)
208{ 225{
209 unsigned int value; 226 unsigned int value;
210 struct option_port_private *portdata; 227 struct option_port_private *portdata;
211 228
212 portdata = usb_get_serial_port_data(port); 229 portdata = usb_get_serial_port_data(port);
213 230
@@ -225,7 +242,7 @@ static int
225option_tiocmset (struct usb_serial_port *port, struct file *file, 242option_tiocmset (struct usb_serial_port *port, struct file *file,
226 unsigned int set, unsigned int clear) 243 unsigned int set, unsigned int clear)
227{ 244{
228 struct option_port_private *portdata; 245 struct option_port_private *portdata;
229 246
230 portdata = usb_get_serial_port_data(port); 247 portdata = usb_get_serial_port_data(port);
231 248
@@ -250,71 +267,50 @@ option_ioctl (struct usb_serial_port *port, struct file *file,
250 267
251/* Write */ 268/* Write */
252static int 269static int
253option_write(struct usb_serial_port *port, 270option_write (struct usb_serial_port *port,
254 const unsigned char *buf, int count) 271 const unsigned char *buf, int count)
255{ 272{
256 struct option_port_private *portdata; 273 struct option_port_private *portdata;
257 int i; 274 int i;
258 int left, todo; 275 int left, todo;
259 struct urb *this_urb = NULL; /* spurious */ 276 struct urb *this_urb = NULL; /* spurious */
260 int err; 277 int err;
261 278
262 portdata = usb_get_serial_port_data(port); 279 portdata = usb_get_serial_port_data(port);
263 280
264 dbg("%s: write (%d chars)", __FUNCTION__, count); 281 dbg("%s: write (%d chars)", __FUNCTION__, count);
265 282
266#if 0
267 spin_lock(&port->lock);
268 if (port->write_urb_busy) {
269 spin_unlock(&port->lock);
270 dbg("%s: already writing", __FUNCTION__);
271 return 0;
272 }
273 port->write_urb_busy = 1;
274 spin_unlock(&port->lock);
275#endif
276
277 i = 0; 283 i = 0;
278 left = count; 284 left = count;
279 while (left>0) { 285 for (i=0; left > 0 && i < N_OUT_URB; i++) {
280 todo = left; 286 todo = left;
281 if (todo > OUT_BUFLEN) 287 if (todo > OUT_BUFLEN)
282 todo = OUT_BUFLEN; 288 todo = OUT_BUFLEN;
283 289
284 for (;i < N_OUT_URB; i++) { 290 this_urb = portdata->out_urbs[i];
285 /* Check we have a valid urb/endpoint before we use it... */ 291 if (this_urb->status == -EINPROGRESS) {
286 this_urb = portdata->out_urbs[i];
287 if (this_urb->status != -EINPROGRESS)
288 break;
289 if (this_urb->transfer_flags & URB_ASYNC_UNLINK) 292 if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
290 continue; 293 continue;
291 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ)) 294 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ))
292 continue; 295 continue;
293 this_urb->transfer_flags |= URB_ASYNC_UNLINK; 296 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
294 usb_unlink_urb(this_urb); 297 usb_unlink_urb(this_urb);
298 continue;
295 } 299 }
296 300 if (this_urb->status != 0)
297 if (i == N_OUT_URB) { 301 dbg("usb_write %p failed (err=%d)", this_urb, this_urb->status);
298 /* no bulk out free! */
299 dbg("%s: no output urb -- left %d", __FUNCTION__,count-left);
300#if 0
301 port->write_urb_busy = 0;
302#endif
303 return count-left;
304 }
305 302
306 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i); 303 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i);
307 304
305 /* send the data */
308 memcpy (this_urb->transfer_buffer, buf, todo); 306 memcpy (this_urb->transfer_buffer, buf, todo);
309
310 /* send the data out the bulk port */
311 this_urb->transfer_buffer_length = todo; 307 this_urb->transfer_buffer_length = todo;
312 308
313 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK; 309 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
314 this_urb->dev = port->serial->dev; 310 this_urb->dev = port->serial->dev;
315 err = usb_submit_urb(this_urb, GFP_ATOMIC); 311 err = usb_submit_urb(this_urb, GFP_ATOMIC);
316 if (err) { 312 if (err) {
317 dbg("usb_submit_urb %p (write bulk) failed (%d,, has %d)", this_urb, err, this_urb->status); 313 dbg("usb_submit_urb %p (write bulk) failed (%d, has %d)", this_urb, err, this_urb->status);
318 continue; 314 continue;
319 } 315 }
320 portdata->tx_start_time[i] = jiffies; 316 portdata->tx_start_time[i] = jiffies;
@@ -323,9 +319,6 @@ option_write(struct usb_serial_port *port,
323 } 319 }
324 320
325 count -= left; 321 count -= left;
326#if 0
327 port->write_urb_busy = 0;
328#endif
329 dbg("%s: wrote (did %d)", __FUNCTION__, count); 322 dbg("%s: wrote (did %d)", __FUNCTION__, count);
330 return count; 323 return count;
331} 324}
@@ -333,7 +326,7 @@ option_write(struct usb_serial_port *port,
333static void 326static void
334option_indat_callback (struct urb *urb, struct pt_regs *regs) 327option_indat_callback (struct urb *urb, struct pt_regs *regs)
335{ 328{
336 int i, err; 329 int i, err;
337 int endpoint; 330 int endpoint;
338 struct usb_serial_port *port; 331 struct usb_serial_port *port;
339 struct tty_struct *tty; 332 struct tty_struct *tty;
@@ -444,10 +437,11 @@ option_write_room (struct usb_serial_port *port)
444 437
445 portdata = usb_get_serial_port_data(port); 438 portdata = usb_get_serial_port_data(port);
446 439
447 for (i=0; i < N_OUT_URB; i++) 440 for (i=0; i < N_OUT_URB; i++) {
448 this_urb = portdata->out_urbs[i]; 441 this_urb = portdata->out_urbs[i];
449 if (this_urb && this_urb->status != -EINPROGRESS) 442 if (this_urb && this_urb->status != -EINPROGRESS)
450 data_len += OUT_BUFLEN; 443 data_len += OUT_BUFLEN;
444 }
451 445
452 dbg("%s: %d", __FUNCTION__, data_len); 446 dbg("%s: %d", __FUNCTION__, data_len);
453 return data_len; 447 return data_len;
@@ -464,11 +458,11 @@ option_chars_in_buffer (struct usb_serial_port *port)
464 458
465 portdata = usb_get_serial_port_data(port); 459 portdata = usb_get_serial_port_data(port);
466 460
467 for (i=0; i < N_OUT_URB; i++) 461 for (i=0; i < N_OUT_URB; i++) {
468 this_urb = portdata->out_urbs[i]; 462 this_urb = portdata->out_urbs[i];
469 if (this_urb && this_urb->status == -EINPROGRESS) 463 if (this_urb && this_urb->status == -EINPROGRESS)
470 data_len += this_urb->transfer_buffer_length; 464 data_len += this_urb->transfer_buffer_length;
471 465 }
472 dbg("%s: %d", __FUNCTION__, data_len); 466 dbg("%s: %d", __FUNCTION__, data_len);
473 return data_len; 467 return data_len;
474} 468}
@@ -477,10 +471,10 @@ option_chars_in_buffer (struct usb_serial_port *port)
477static int 471static int
478option_open (struct usb_serial_port *port, struct file *filp) 472option_open (struct usb_serial_port *port, struct file *filp)
479{ 473{
480 struct option_port_private *portdata; 474 struct option_port_private *portdata;
481 struct usb_serial *serial = port->serial; 475 struct usb_serial *serial = port->serial;
482 int i, err; 476 int i, err;
483 struct urb *urb; 477 struct urb *urb;
484 478
485 portdata = usb_get_serial_port_data(port); 479 portdata = usb_get_serial_port_data(port);
486 480
@@ -528,7 +522,7 @@ option_open (struct usb_serial_port *port, struct file *filp)
528} 522}
529 523
530static inline void 524static inline void
531stop_urb(struct urb *urb) 525stop_urb (struct urb *urb)
532{ 526{
533 if (urb && urb->status == -EINPROGRESS) { 527 if (urb && urb->status == -EINPROGRESS) {
534 urb->transfer_flags &= ~URB_ASYNC_UNLINK; 528 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
@@ -537,11 +531,11 @@ stop_urb(struct urb *urb)
537} 531}
538 532
539static void 533static void
540option_close(struct usb_serial_port *port, struct file *filp) 534option_close (struct usb_serial_port *port, struct file *filp)
541{ 535{
542 int i; 536 int i;
543 struct usb_serial *serial = port->serial; 537 struct usb_serial *serial = port->serial;
544 struct option_port_private *portdata; 538 struct option_port_private *portdata;
545 539
546 dbg("%s", __FUNCTION__); 540 dbg("%s", __FUNCTION__);
547 portdata = usb_get_serial_port_data(port); 541 portdata = usb_get_serial_port_data(port);
@@ -589,11 +583,11 @@ option_setup_urb (struct usb_serial *serial, int endpoint,
589 583
590/* Setup urbs */ 584/* Setup urbs */
591static void 585static void
592option_setup_urbs(struct usb_serial *serial) 586option_setup_urbs (struct usb_serial *serial)
593{ 587{
594 int j; 588 int j;
595 struct usb_serial_port *port; 589 struct usb_serial_port *port;
596 struct option_port_private *portdata; 590 struct option_port_private *portdata;
597 591
598 dbg("%s", __FUNCTION__); 592 dbg("%s", __FUNCTION__);
599 593
@@ -617,7 +611,7 @@ option_setup_urbs(struct usb_serial *serial)
617 611
618 612
619static int 613static int
620option_send_setup(struct usb_serial_port *port) 614option_send_setup (struct usb_serial_port *port)
621{ 615{
622 struct usb_serial *serial = port->serial; 616 struct usb_serial *serial = port->serial;
623 struct option_port_private *portdata; 617 struct option_port_private *portdata;
@@ -644,9 +638,9 @@ option_send_setup(struct usb_serial_port *port)
644static int 638static int
645option_startup (struct usb_serial *serial) 639option_startup (struct usb_serial *serial)
646{ 640{
647 int i, err; 641 int i, err;
648 struct usb_serial_port *port; 642 struct usb_serial_port *port;
649 struct option_port_private *portdata; 643 struct option_port_private *portdata;
650 644
651 dbg("%s", __FUNCTION__); 645 dbg("%s", __FUNCTION__);
652 646
@@ -677,9 +671,9 @@ option_startup (struct usb_serial *serial)
677static void 671static void
678option_shutdown (struct usb_serial *serial) 672option_shutdown (struct usb_serial *serial)
679{ 673{
680 int i, j; 674 int i, j;
681 struct usb_serial_port *port; 675 struct usb_serial_port *port;
682 struct option_port_private *portdata; 676 struct option_port_private *portdata;
683 677
684 dbg("%s", __FUNCTION__); 678 dbg("%s", __FUNCTION__);
685 679
@@ -724,6 +718,8 @@ MODULE_DESCRIPTION(DRIVER_DESC);
724MODULE_VERSION(DRIVER_VERSION); 718MODULE_VERSION(DRIVER_VERSION);
725MODULE_LICENSE("GPL"); 719MODULE_LICENSE("GPL");
726 720
721#ifdef CONFIG_USB_DEBUG
727module_param(debug, bool, S_IRUGO | S_IWUSR); 722module_param(debug, bool, S_IRUGO | S_IWUSR);
728MODULE_PARM_DESC(debug, "Debug messages"); 723MODULE_PARM_DESC(debug, "Debug messages");
724#endif
729 725
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 0e85ed6c6c19..96a17568cbf1 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -299,10 +299,14 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
299 dbg ("%s - write request of 0 bytes", __FUNCTION__); 299 dbg ("%s - write request of 0 bytes", __FUNCTION__);
300 return (0); 300 return (0);
301 } 301 }
302 if (port->write_urb->status == -EINPROGRESS) { 302 spin_lock(&port->lock);
303 dbg ("%s - already writing", __FUNCTION__); 303 if (port->write_urb_busy) {
304 return (0); 304 spin_unlock(&port->lock);
305 dbg("%s - already writing", __FUNCTION__);
306 return 0;
305 } 307 }
308 port->write_urb_busy = 1;
309 spin_unlock(&port->lock);
306 310
307 packet_length = port->bulk_out_size; // get max packetsize 311 packet_length = port->bulk_out_size; // get max packetsize
308 312
@@ -354,6 +358,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
354#endif 358#endif
355 port->write_urb->dev = port->serial->dev; 359 port->write_urb->dev = port->serial->dev;
356 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 360 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) {
361 port->write_urb_busy = 0;
357 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); 362 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result);
358 return 0; 363 return 0;
359 } 364 }
@@ -368,7 +373,7 @@ static int safe_write_room (struct usb_serial_port *port)
368 373
369 dbg ("%s", __FUNCTION__); 374 dbg ("%s", __FUNCTION__);
370 375
371 if (port->write_urb->status != -EINPROGRESS) 376 if (port->write_urb_busy)
372 room = port->bulk_out_size - (safe ? 2 : 0); 377 room = port->bulk_out_size - (safe ? 2 : 0);
373 378
374 if (room) { 379 if (room) {
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 5da76dd8fb28..0267b26dde18 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1047,6 +1047,7 @@ int usb_serial_probe(struct usb_interface *interface,
1047 memset(port, 0x00, sizeof(struct usb_serial_port)); 1047 memset(port, 0x00, sizeof(struct usb_serial_port));
1048 port->number = i + serial->minor; 1048 port->number = i + serial->minor;
1049 port->serial = serial; 1049 port->serial = serial;
1050 spin_lock_init(&port->lock);
1050 INIT_WORK(&port->work, usb_serial_port_softint, port); 1051 INIT_WORK(&port->work, usb_serial_port_softint, port);
1051 serial->port[i] = port; 1052 serial->port[i] = port;
1052 } 1053 }
diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
index d1f0c4057fa6..57f92f054c75 100644
--- a/drivers/usb/serial/usb-serial.h
+++ b/drivers/usb/serial/usb-serial.h
@@ -69,6 +69,7 @@
69 * usb_serial_port: structure for the specific ports of a device. 69 * usb_serial_port: structure for the specific ports of a device.
70 * @serial: pointer back to the struct usb_serial owner of this port. 70 * @serial: pointer back to the struct usb_serial owner of this port.
71 * @tty: pointer to the corresponding tty for this port. 71 * @tty: pointer to the corresponding tty for this port.
72 * @lock: spinlock to grab when updating portions of this structure.
72 * @number: the number of the port (the minor number). 73 * @number: the number of the port (the minor number).
73 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port. 74 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port.
74 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port. 75 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port.
@@ -98,6 +99,7 @@
98struct usb_serial_port { 99struct usb_serial_port {
99 struct usb_serial * serial; 100 struct usb_serial * serial;
100 struct tty_struct * tty; 101 struct tty_struct * tty;
102 spinlock_t lock;
101 unsigned char number; 103 unsigned char number;
102 104
103 unsigned char * interrupt_in_buffer; 105 unsigned char * interrupt_in_buffer;
@@ -117,6 +119,7 @@ struct usb_serial_port {
117 unsigned char * bulk_out_buffer; 119 unsigned char * bulk_out_buffer;
118 int bulk_out_size; 120 int bulk_out_size;
119 struct urb * write_urb; 121 struct urb * write_urb;
122 int write_urb_busy;
120 __u8 bulk_out_endpointAddress; 123 __u8 bulk_out_endpointAddress;
121 124
122 wait_queue_head_t write_wait; 125 wait_queue_head_t write_wait;
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index e43eddc3d44b..af294bb68c35 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -155,6 +155,15 @@ static int slave_configure(struct scsi_device *sdev)
155 * If this device makes that mistake, tell the sd driver. */ 155 * If this device makes that mistake, tell the sd driver. */
156 if (us->flags & US_FL_FIX_CAPACITY) 156 if (us->flags & US_FL_FIX_CAPACITY)
157 sdev->fix_capacity = 1; 157 sdev->fix_capacity = 1;
158
159 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
160 * Hardware Error) when any low-level error occurs,
161 * recoverable or not. Setting this flag tells the SCSI
162 * midlayer to retry such commands, which frequently will
163 * succeed and fix the error. The worst this can lead to
164 * is an occasional series of retries that will all fail. */
165 sdev->retry_hwerror = 1;
166
158 } else { 167 } else {
159 168
160 /* Non-disk-type devices don't need to blacklist any pages 169 /* Non-disk-type devices don't need to blacklist any pages
@@ -255,50 +264,23 @@ static int device_reset(struct scsi_cmnd *srb)
255 264
256 /* lock the device pointers and do the reset */ 265 /* lock the device pointers and do the reset */
257 down(&(us->dev_semaphore)); 266 down(&(us->dev_semaphore));
258 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 267 result = us->transport_reset(us);
259 result = FAILED;
260 US_DEBUGP("No reset during disconnect\n");
261 } else
262 result = us->transport_reset(us);
263 up(&(us->dev_semaphore)); 268 up(&(us->dev_semaphore));
264 269
265 return result; 270 return result < 0 ? FAILED : SUCCESS;
266} 271}
267 272
268/* This resets the device's USB port. */ 273/* Simulate a SCSI bus reset by resetting the device's USB port. */
269/* It refuses to work if there's more than one interface in
270 * the device, so that other users are not affected. */
271/* This is always called with scsi_lock(host) held */ 274/* This is always called with scsi_lock(host) held */
272static int bus_reset(struct scsi_cmnd *srb) 275static int bus_reset(struct scsi_cmnd *srb)
273{ 276{
274 struct us_data *us = host_to_us(srb->device->host); 277 struct us_data *us = host_to_us(srb->device->host);
275 int result, rc; 278 int result;
276 279
277 US_DEBUGP("%s called\n", __FUNCTION__); 280 US_DEBUGP("%s called\n", __FUNCTION__);
278 281
279 /* The USB subsystem doesn't handle synchronisation between
280 * a device's several drivers. Therefore we reset only devices
281 * with just one interface, which we of course own. */
282
283 down(&(us->dev_semaphore)); 282 down(&(us->dev_semaphore));
284 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 283 result = usb_stor_port_reset(us);
285 result = -EIO;
286 US_DEBUGP("No reset during disconnect\n");
287 } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
288 result = -EBUSY;
289 US_DEBUGP("Refusing to reset a multi-interface device\n");
290 } else {
291 rc = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
292 if (rc < 0) {
293 US_DEBUGP("unable to lock device for reset: %d\n", rc);
294 result = rc;
295 } else {
296 result = usb_reset_device(us->pusb_dev);
297 if (rc)
298 usb_unlock_device(us->pusb_dev);
299 US_DEBUGP("usb_reset_device returns %d\n", result);
300 }
301 }
302 up(&(us->dev_semaphore)); 284 up(&(us->dev_semaphore));
303 285
304 /* lock the host for the return */ 286 /* lock the host for the return */
@@ -320,6 +302,14 @@ void usb_stor_report_device_reset(struct us_data *us)
320 } 302 }
321} 303}
322 304
305/* Report a driver-initiated bus reset to the SCSI layer.
306 * Calling this for a SCSI-initiated reset is unnecessary but harmless.
307 * The caller must own the SCSI host lock. */
308void usb_stor_report_bus_reset(struct us_data *us)
309{
310 scsi_report_bus_reset(us_to_host(us), 0);
311}
312
323/*********************************************************************** 313/***********************************************************************
324 * /proc/scsi/ functions 314 * /proc/scsi/ functions
325 ***********************************************************************/ 315 ***********************************************************************/
diff --git a/drivers/usb/storage/scsiglue.h b/drivers/usb/storage/scsiglue.h
index d0a49af026c4..737e4fa6045f 100644
--- a/drivers/usb/storage/scsiglue.h
+++ b/drivers/usb/storage/scsiglue.h
@@ -42,6 +42,7 @@
42#define _SCSIGLUE_H_ 42#define _SCSIGLUE_H_
43 43
44extern void usb_stor_report_device_reset(struct us_data *us); 44extern void usb_stor_report_device_reset(struct us_data *us);
45extern void usb_stor_report_bus_reset(struct us_data *us);
45 46
46extern unsigned char usb_stor_sense_invalidCDB[18]; 47extern unsigned char usb_stor_sense_invalidCDB[18];
47extern struct scsi_host_template usb_stor_host_template; 48extern struct scsi_host_template usb_stor_host_template;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 9743e289cd3b..e6b1c6cf07f2 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -266,8 +266,9 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
266 NULL, 0, 3*HZ); 266 NULL, 0, 3*HZ);
267 267
268 /* reset the endpoint toggle */ 268 /* reset the endpoint toggle */
269 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), 269 if (result >= 0)
270 usb_pipeout(pipe), 0); 270 usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe),
271 usb_pipeout(pipe), 0);
271 272
272 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result); 273 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result);
273 return result; 274 return result;
@@ -540,15 +541,15 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
540 */ 541 */
541 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 542 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
542 US_DEBUGP("-- command was aborted\n"); 543 US_DEBUGP("-- command was aborted\n");
543 goto Handle_Abort; 544 srb->result = DID_ABORT << 16;
545 goto Handle_Errors;
544 } 546 }
545 547
546 /* if there is a transport error, reset and don't auto-sense */ 548 /* if there is a transport error, reset and don't auto-sense */
547 if (result == USB_STOR_TRANSPORT_ERROR) { 549 if (result == USB_STOR_TRANSPORT_ERROR) {
548 US_DEBUGP("-- transport indicates error, resetting\n"); 550 US_DEBUGP("-- transport indicates error, resetting\n");
549 us->transport_reset(us);
550 srb->result = DID_ERROR << 16; 551 srb->result = DID_ERROR << 16;
551 return; 552 goto Handle_Errors;
552 } 553 }
553 554
554 /* if the transport provided its own sense data, don't auto-sense */ 555 /* if the transport provided its own sense data, don't auto-sense */
@@ -668,7 +669,8 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
668 669
669 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 670 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
670 US_DEBUGP("-- auto-sense aborted\n"); 671 US_DEBUGP("-- auto-sense aborted\n");
671 goto Handle_Abort; 672 srb->result = DID_ABORT << 16;
673 goto Handle_Errors;
672 } 674 }
673 if (temp_result != USB_STOR_TRANSPORT_GOOD) { 675 if (temp_result != USB_STOR_TRANSPORT_GOOD) {
674 US_DEBUGP("-- auto-sense failure\n"); 676 US_DEBUGP("-- auto-sense failure\n");
@@ -677,9 +679,9 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
677 * multi-target device, since failure of an 679 * multi-target device, since failure of an
678 * auto-sense is perfectly valid 680 * auto-sense is perfectly valid
679 */ 681 */
680 if (!(us->flags & US_FL_SCM_MULT_TARG))
681 us->transport_reset(us);
682 srb->result = DID_ERROR << 16; 682 srb->result = DID_ERROR << 16;
683 if (!(us->flags & US_FL_SCM_MULT_TARG))
684 goto Handle_Errors;
683 return; 685 return;
684 } 686 }
685 687
@@ -720,12 +722,28 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
720 722
721 return; 723 return;
722 724
723 /* abort processing: the bulk-only transport requires a reset 725 /* Error and abort processing: try to resynchronize with the device
724 * following an abort */ 726 * by issuing a port reset. If that fails, try a class-specific
725 Handle_Abort: 727 * device reset. */
726 srb->result = DID_ABORT << 16; 728 Handle_Errors:
727 if (us->protocol == US_PR_BULK) 729
730 /* Let the SCSI layer know we are doing a reset, set the
731 * RESETTING bit, and clear the ABORTING bit so that the reset
732 * may proceed. */
733 scsi_lock(us_to_host(us));
734 usb_stor_report_bus_reset(us);
735 set_bit(US_FLIDX_RESETTING, &us->flags);
736 clear_bit(US_FLIDX_ABORTING, &us->flags);
737 scsi_unlock(us_to_host(us));
738
739 result = usb_stor_port_reset(us);
740 if (result < 0) {
741 scsi_lock(us_to_host(us));
742 usb_stor_report_device_reset(us);
743 scsi_unlock(us_to_host(us));
728 us->transport_reset(us); 744 us->transport_reset(us);
745 }
746 clear_bit(US_FLIDX_RESETTING, &us->flags);
729} 747}
730 748
731/* Stop the current URB transfer */ 749/* Stop the current URB transfer */
@@ -1124,7 +1142,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1124 * It's handy that every transport mechanism uses the control endpoint for 1142 * It's handy that every transport mechanism uses the control endpoint for
1125 * resets. 1143 * resets.
1126 * 1144 *
1127 * Basically, we send a reset with a 20-second timeout, so we don't get 1145 * Basically, we send a reset with a 5-second timeout, so we don't get
1128 * jammed attempting to do the reset. 1146 * jammed attempting to do the reset.
1129 */ 1147 */
1130static int usb_stor_reset_common(struct us_data *us, 1148static int usb_stor_reset_common(struct us_data *us,
@@ -1133,28 +1151,18 @@ static int usb_stor_reset_common(struct us_data *us,
1133{ 1151{
1134 int result; 1152 int result;
1135 int result2; 1153 int result2;
1136 int rc = FAILED;
1137 1154
1138 /* Let the SCSI layer know we are doing a reset, set the 1155 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1139 * RESETTING bit, and clear the ABORTING bit so that the reset 1156 US_DEBUGP("No reset during disconnect\n");
1140 * may proceed. 1157 return -EIO;
1141 */ 1158 }
1142 scsi_lock(us_to_host(us));
1143 usb_stor_report_device_reset(us);
1144 set_bit(US_FLIDX_RESETTING, &us->flags);
1145 clear_bit(US_FLIDX_ABORTING, &us->flags);
1146 scsi_unlock(us_to_host(us));
1147 1159
1148 /* A 20-second timeout may seem rather long, but a LaCie
1149 * StudioDrive USB2 device takes 16+ seconds to get going
1150 * following a powerup or USB attach event.
1151 */
1152 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 1160 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
1153 request, requesttype, value, index, data, size, 1161 request, requesttype, value, index, data, size,
1154 20*HZ); 1162 5*HZ);
1155 if (result < 0) { 1163 if (result < 0) {
1156 US_DEBUGP("Soft reset failed: %d\n", result); 1164 US_DEBUGP("Soft reset failed: %d\n", result);
1157 goto Done; 1165 return result;
1158 } 1166 }
1159 1167
1160 /* Give the device some time to recover from the reset, 1168 /* Give the device some time to recover from the reset,
@@ -1164,7 +1172,7 @@ static int usb_stor_reset_common(struct us_data *us,
1164 HZ*6); 1172 HZ*6);
1165 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1173 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1166 US_DEBUGP("Reset interrupted by disconnect\n"); 1174 US_DEBUGP("Reset interrupted by disconnect\n");
1167 goto Done; 1175 return -EIO;
1168 } 1176 }
1169 1177
1170 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n"); 1178 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n");
@@ -1173,17 +1181,14 @@ static int usb_stor_reset_common(struct us_data *us,
1173 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n"); 1181 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n");
1174 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); 1182 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
1175 1183
1176 /* return a result code based on the result of the control message */ 1184 /* return a result code based on the result of the clear-halts */
1177 if (result < 0 || result2 < 0) { 1185 if (result >= 0)
1186 result = result2;
1187 if (result < 0)
1178 US_DEBUGP("Soft reset failed\n"); 1188 US_DEBUGP("Soft reset failed\n");
1179 goto Done; 1189 else
1180 } 1190 US_DEBUGP("Soft reset done\n");
1181 US_DEBUGP("Soft reset done\n"); 1191 return result;
1182 rc = SUCCESS;
1183
1184 Done:
1185 clear_bit(US_FLIDX_RESETTING, &us->flags);
1186 return rc;
1187} 1192}
1188 1193
1189/* This issues a CB[I] Reset to the device in question 1194/* This issues a CB[I] Reset to the device in question
@@ -1213,3 +1218,32 @@ int usb_stor_Bulk_reset(struct us_data *us)
1213 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1218 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1214 0, us->ifnum, NULL, 0); 1219 0, us->ifnum, NULL, 0);
1215} 1220}
1221
1222/* Issue a USB port reset to the device. But don't do anything if
1223 * there's more than one interface in the device, so that other users
1224 * are not affected. */
1225int usb_stor_port_reset(struct us_data *us)
1226{
1227 int result, rc;
1228
1229 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
1230 result = -EIO;
1231 US_DEBUGP("No reset during disconnect\n");
1232 } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) {
1233 result = -EBUSY;
1234 US_DEBUGP("Refusing to reset a multi-interface device\n");
1235 } else {
1236 result = rc =
1237 usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1238 if (result < 0) {
1239 US_DEBUGP("unable to lock device for reset: %d\n",
1240 result);
1241 } else {
1242 result = usb_reset_device(us->pusb_dev);
1243 if (rc)
1244 usb_unlock_device(us->pusb_dev);
1245 US_DEBUGP("usb_reset_device returns %d\n", result);
1246 }
1247 }
1248 return result;
1249}
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index e25f8d8fc741..8d9e0663f8fe 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -171,4 +171,5 @@ extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
171extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 171extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
172 void *buf, unsigned int length, int use_sg, int *residual); 172 void *buf, unsigned int length, int use_sg, int *residual);
173 173
174extern int usb_stor_port_reset(struct us_data *us);
174#endif 175#endif
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 9fcc7bd1fbe4..bd0ab3039bdd 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -697,7 +697,7 @@ UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133,
697UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100, 697UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100,
698 "Microtech", 698 "Microtech",
699 "USB-SCSI-HD50", 699 "USB-SCSI-HD50",
700 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 700 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init,
701 US_FL_SCM_MULT_TARG ), 701 US_FL_SCM_MULT_TARG ),
702 702
703#ifdef CONFIG_USB_STORAGE_DPCM 703#ifdef CONFIG_USB_STORAGE_DPCM
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 9789115980a5..7bc1d44d8814 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -350,10 +350,8 @@ static int default_vmode __initdata = VMODE_1024_768_60;
350static int default_cmode __initdata = CMODE_8; 350static int default_cmode __initdata = CMODE_8;
351#endif 351#endif
352 352
353#ifdef CONFIG_PMAC_PBOOK
354static int default_crt_on __initdata = 0; 353static int default_crt_on __initdata = 0;
355static int default_lcd_on __initdata = 1; 354static int default_lcd_on __initdata = 1;
356#endif
357 355
358#ifdef CONFIG_MTRR 356#ifdef CONFIG_MTRR
359static int mtrr = 1; 357static int mtrr = 1;
@@ -1249,7 +1247,6 @@ static int aty128_crtc_to_var(const struct aty128_crtc *crtc,
1249 return 0; 1247 return 0;
1250} 1248}
1251 1249
1252#ifdef CONFIG_PMAC_PBOOK
1253static void aty128_set_crt_enable(struct aty128fb_par *par, int on) 1250static void aty128_set_crt_enable(struct aty128fb_par *par, int on)
1254{ 1251{
1255 if (on) { 1252 if (on) {
@@ -1284,7 +1281,6 @@ static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
1284 aty_st_le32(LVDS_GEN_CNTL, reg); 1281 aty_st_le32(LVDS_GEN_CNTL, reg);
1285 } 1282 }
1286} 1283}
1287#endif /* CONFIG_PMAC_PBOOK */
1288 1284
1289static void aty128_set_pll(struct aty128_pll *pll, const struct aty128fb_par *par) 1285static void aty128_set_pll(struct aty128_pll *pll, const struct aty128fb_par *par)
1290{ 1286{
@@ -1491,12 +1487,10 @@ static int aty128fb_set_par(struct fb_info *info)
1491 info->fix.visual = par->crtc.bpp == 8 ? FB_VISUAL_PSEUDOCOLOR 1487 info->fix.visual = par->crtc.bpp == 8 ? FB_VISUAL_PSEUDOCOLOR
1492 : FB_VISUAL_DIRECTCOLOR; 1488 : FB_VISUAL_DIRECTCOLOR;
1493 1489
1494#ifdef CONFIG_PMAC_PBOOK
1495 if (par->chip_gen == rage_M3) { 1490 if (par->chip_gen == rage_M3) {
1496 aty128_set_crt_enable(par, par->crt_on); 1491 aty128_set_crt_enable(par, par->crt_on);
1497 aty128_set_lcd_enable(par, par->lcd_on); 1492 aty128_set_lcd_enable(par, par->lcd_on);
1498 } 1493 }
1499#endif
1500 if (par->accel_flags & FB_ACCELF_TEXT) 1494 if (par->accel_flags & FB_ACCELF_TEXT)
1501 aty128_init_engine(par); 1495 aty128_init_engine(par);
1502 1496
@@ -1652,7 +1646,6 @@ static int __init aty128fb_setup(char *options)
1652 return 0; 1646 return 0;
1653 1647
1654 while ((this_opt = strsep(&options, ",")) != NULL) { 1648 while ((this_opt = strsep(&options, ",")) != NULL) {
1655#ifdef CONFIG_PMAC_PBOOK
1656 if (!strncmp(this_opt, "lcd:", 4)) { 1649 if (!strncmp(this_opt, "lcd:", 4)) {
1657 default_lcd_on = simple_strtoul(this_opt+4, NULL, 0); 1650 default_lcd_on = simple_strtoul(this_opt+4, NULL, 0);
1658 continue; 1651 continue;
@@ -1660,7 +1653,6 @@ static int __init aty128fb_setup(char *options)
1660 default_crt_on = simple_strtoul(this_opt+4, NULL, 0); 1653 default_crt_on = simple_strtoul(this_opt+4, NULL, 0);
1661 continue; 1654 continue;
1662 } 1655 }
1663#endif
1664#ifdef CONFIG_MTRR 1656#ifdef CONFIG_MTRR
1665 if(!strncmp(this_opt, "nomtrr", 6)) { 1657 if(!strncmp(this_opt, "nomtrr", 6)) {
1666 mtrr = 0; 1658 mtrr = 0;
@@ -1752,10 +1744,8 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
1752 info->fbops = &aty128fb_ops; 1744 info->fbops = &aty128fb_ops;
1753 info->flags = FBINFO_FLAG_DEFAULT; 1745 info->flags = FBINFO_FLAG_DEFAULT;
1754 1746
1755#ifdef CONFIG_PMAC_PBOOK
1756 par->lcd_on = default_lcd_on; 1747 par->lcd_on = default_lcd_on;
1757 par->crt_on = default_crt_on; 1748 par->crt_on = default_crt_on;
1758#endif
1759 1749
1760 var = default_var; 1750 var = default_var;
1761#ifdef CONFIG_PPC_PMAC 1751#ifdef CONFIG_PPC_PMAC
@@ -2035,12 +2025,10 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2035 2025
2036 aty_st_8(CRTC_EXT_CNTL+1, state); 2026 aty_st_8(CRTC_EXT_CNTL+1, state);
2037 2027
2038#ifdef CONFIG_PMAC_PBOOK
2039 if (par->chip_gen == rage_M3) { 2028 if (par->chip_gen == rage_M3) {
2040 aty128_set_crt_enable(par, par->crt_on && !blank); 2029 aty128_set_crt_enable(par, par->crt_on && !blank);
2041 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2030 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2042 } 2031 }
2043#endif
2044#ifdef CONFIG_PMAC_BACKLIGHT 2032#ifdef CONFIG_PMAC_BACKLIGHT
2045 if ((_machine == _MACH_Pmac) && !blank) 2033 if ((_machine == _MACH_Pmac) && !blank)
2046 set_backlight_enable(1); 2034 set_backlight_enable(1);
@@ -2124,7 +2112,6 @@ static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2124static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd, 2112static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
2125 u_long arg, struct fb_info *info) 2113 u_long arg, struct fb_info *info)
2126{ 2114{
2127#ifdef CONFIG_PMAC_PBOOK
2128 struct aty128fb_par *par = info->par; 2115 struct aty128fb_par *par = info->par;
2129 u32 value; 2116 u32 value;
2130 int rc; 2117 int rc;
@@ -2149,7 +2136,6 @@ static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
2149 value = (par->crt_on << 1) | par->lcd_on; 2136 value = (par->crt_on << 1) | par->lcd_on;
2150 return put_user(value, (__u32 __user *)arg); 2137 return put_user(value, (__u32 __user *)arg);
2151 } 2138 }
2152#endif
2153 return -EINVAL; 2139 return -EINVAL;
2154} 2140}
2155 2141
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index 95e72550d43f..e75a965ec760 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -28,22 +28,17 @@
28#include <linux/fb.h> 28#include <linux/fb.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/console.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
33#ifdef CONFIG_PMAC_BACKLIGHT 34#ifdef CONFIG_PMAC_BACKLIGHT
34#include <asm/backlight.h> 35#include <asm/backlight.h>
35#endif 36#endif
36#ifdef CONFIG_PMAC_PBOOK
37#include <linux/adb.h>
38#include <linux/pmu.h>
39#endif
40 37
41/* 38/*
42 * Since we access the display with inb/outb to fixed port numbers, 39 * Since we access the display with inb/outb to fixed port numbers,
43 * we can only handle one 6555x chip. -- paulus 40 * we can only handle one 6555x chip. -- paulus
44 */ 41 */
45static struct fb_info chipsfb_info;
46
47#define write_ind(num, val, ap, dp) do { \ 42#define write_ind(num, val, ap, dp) do { \
48 outb((num), (ap)); outb((val), (dp)); \ 43 outb((num), (ap)); outb((val), (dp)); \
49} while (0) 44} while (0)
@@ -74,14 +69,6 @@ static struct fb_info chipsfb_info;
74 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \ 69 inb(0x3da); read_ind(num, var, 0x3c0, 0x3c1); \
75} while (0) 70} while (0)
76 71
77#ifdef CONFIG_PMAC_PBOOK
78static unsigned char *save_framebuffer;
79int chips_sleep_notify(struct pmu_sleep_notifier *self, int when);
80static struct pmu_sleep_notifier chips_sleep_notifier = {
81 chips_sleep_notify, SLEEP_LEVEL_VIDEO,
82};
83#endif
84
85/* 72/*
86 * Exported functions 73 * Exported functions
87 */ 74 */
@@ -356,6 +343,8 @@ static struct fb_var_screeninfo chipsfb_var __initdata = {
356 343
357static void __init init_chips(struct fb_info *p, unsigned long addr) 344static void __init init_chips(struct fb_info *p, unsigned long addr)
358{ 345{
346 memset(p->screen_base, 0, 0x100000);
347
359 p->fix = chipsfb_fix; 348 p->fix = chipsfb_fix;
360 p->fix.smem_start = addr; 349 p->fix.smem_start = addr;
361 350
@@ -366,34 +355,41 @@ static void __init init_chips(struct fb_info *p, unsigned long addr)
366 355
367 fb_alloc_cmap(&p->cmap, 256, 0); 356 fb_alloc_cmap(&p->cmap, 256, 0);
368 357
369 if (register_framebuffer(p) < 0) {
370 printk(KERN_ERR "C&T 65550 framebuffer failed to register\n");
371 return;
372 }
373
374 printk(KERN_INFO "fb%d: Chips 65550 frame buffer (%dK RAM detected)\n",
375 p->node, p->fix.smem_len / 1024);
376
377 chips_hw_init(); 358 chips_hw_init();
378} 359}
379 360
380static int __devinit 361static int __devinit
381chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent) 362chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
382{ 363{
383 struct fb_info *p = &chipsfb_info; 364 struct fb_info *p;
384 unsigned long addr, size; 365 unsigned long addr, size;
385 unsigned short cmd; 366 unsigned short cmd;
367 int rc = -ENODEV;
368
369 if (pci_enable_device(dp) < 0) {
370 dev_err(&dp->dev, "Cannot enable PCI device\n");
371 goto err_out;
372 }
386 373
387 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0) 374 if ((dp->resource[0].flags & IORESOURCE_MEM) == 0)
388 return -ENODEV; 375 goto err_disable;
389 addr = pci_resource_start(dp, 0); 376 addr = pci_resource_start(dp, 0);
390 size = pci_resource_len(dp, 0); 377 size = pci_resource_len(dp, 0);
391 if (addr == 0) 378 if (addr == 0)
392 return -ENODEV; 379 goto err_disable;
393 if (p->screen_base != 0) 380
394 return -EBUSY; 381 p = framebuffer_alloc(0, &dp->dev);
395 if (!request_mem_region(addr, size, "chipsfb")) 382 if (p == NULL) {
396 return -EBUSY; 383 dev_err(&dp->dev, "Cannot allocate framebuffer structure\n");
384 rc = -ENOMEM;
385 goto err_disable;
386 }
387
388 if (pci_request_region(dp, 0, "chipsfb") != 0) {
389 dev_err(&dp->dev, "Cannot request framebuffer\n");
390 rc = -EBUSY;
391 goto err_release_fb;
392 }
397 393
398#ifdef __BIG_ENDIAN 394#ifdef __BIG_ENDIAN
399 addr += 0x800000; // Use big-endian aperture 395 addr += 0x800000; // Use big-endian aperture
@@ -411,37 +407,89 @@ chipsfb_pci_init(struct pci_dev *dp, const struct pci_device_id *ent)
411 set_backlight_enable(1); 407 set_backlight_enable(1);
412#endif /* CONFIG_PMAC_BACKLIGHT */ 408#endif /* CONFIG_PMAC_BACKLIGHT */
413 409
410#ifdef CONFIG_PPC
414 p->screen_base = __ioremap(addr, 0x200000, _PAGE_NO_CACHE); 411 p->screen_base = __ioremap(addr, 0x200000, _PAGE_NO_CACHE);
412#else
413 p->screen_base = ioremap(addr, 0x200000);
414#endif
415 if (p->screen_base == NULL) { 415 if (p->screen_base == NULL) {
416 release_mem_region(addr, size); 416 dev_err(&dp->dev, "Cannot map framebuffer\n");
417 return -ENOMEM; 417 rc = -ENOMEM;
418 goto err_release_pci;
418 } 419 }
420
421 pci_set_drvdata(dp, p);
419 p->device = &dp->dev; 422 p->device = &dp->dev;
423
420 init_chips(p, addr); 424 init_chips(p, addr);
421 425
422#ifdef CONFIG_PMAC_PBOOK 426 if (register_framebuffer(p) < 0) {
423 pmu_register_sleep_notifier(&chips_sleep_notifier); 427 dev_err(&dp->dev,"C&T 65550 framebuffer failed to register\n");
424#endif /* CONFIG_PMAC_PBOOK */ 428 goto err_unmap;
429 }
430
431 dev_info(&dp->dev,"fb%d: Chips 65550 frame buffer"
432 " (%dK RAM detected)\n",
433 p->node, p->fix.smem_len / 1024);
425 434
426 pci_set_drvdata(dp, p);
427 return 0; 435 return 0;
436
437 err_unmap:
438 iounmap(p->screen_base);
439 err_release_pci:
440 pci_release_region(dp, 0);
441 err_release_fb:
442 framebuffer_release(p);
443 err_disable:
444 err_out:
445 return rc;
428} 446}
429 447
430static void __devexit chipsfb_remove(struct pci_dev *dp) 448static void __devexit chipsfb_remove(struct pci_dev *dp)
431{ 449{
432 struct fb_info *p = pci_get_drvdata(dp); 450 struct fb_info *p = pci_get_drvdata(dp);
433 451
434 if (p != &chipsfb_info || p->screen_base == NULL) 452 if (p->screen_base == NULL)
435 return; 453 return;
436 unregister_framebuffer(p); 454 unregister_framebuffer(p);
437 iounmap(p->screen_base); 455 iounmap(p->screen_base);
438 p->screen_base = NULL; 456 p->screen_base = NULL;
439 release_mem_region(pci_resource_start(dp, 0), pci_resource_len(dp, 0)); 457 pci_release_region(dp, 0);
458}
459
460#ifdef CONFIG_PM
461static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
462{
463 struct fb_info *p = pci_get_drvdata(pdev);
464
465 if (state == pdev->dev.power.power_state)
466 return 0;
467 if (state != PM_SUSPEND_MEM)
468 goto done;
469
470 acquire_console_sem();
471 chipsfb_blank(1, p);
472 fb_set_suspend(p, 1);
473 release_console_sem();
474 done:
475 pdev->dev.power.power_state = state;
476 return 0;
477}
478
479static int chipsfb_pci_resume(struct pci_dev *pdev)
480{
481 struct fb_info *p = pci_get_drvdata(pdev);
440 482
441#ifdef CONFIG_PMAC_PBOOK 483 acquire_console_sem();
442 pmu_unregister_sleep_notifier(&chips_sleep_notifier); 484 fb_set_suspend(p, 0);
443#endif /* CONFIG_PMAC_PBOOK */ 485 chipsfb_blank(0, p);
486 release_console_sem();
487
488 pdev->dev.power.power_state = PMSG_ON;
489 return 0;
444} 490}
491#endif /* CONFIG_PM */
492
445 493
446static struct pci_device_id chipsfb_pci_tbl[] = { 494static struct pci_device_id chipsfb_pci_tbl[] = {
447 { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_65550, PCI_ANY_ID, PCI_ANY_ID }, 495 { PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_65550, PCI_ANY_ID, PCI_ANY_ID },
@@ -455,6 +503,10 @@ static struct pci_driver chipsfb_driver = {
455 .id_table = chipsfb_pci_tbl, 503 .id_table = chipsfb_pci_tbl,
456 .probe = chipsfb_pci_init, 504 .probe = chipsfb_pci_init,
457 .remove = __devexit_p(chipsfb_remove), 505 .remove = __devexit_p(chipsfb_remove),
506#ifdef CONFIG_PM
507 .suspend = chipsfb_pci_suspend,
508 .resume = chipsfb_pci_resume,
509#endif
458}; 510};
459 511
460int __init chips_init(void) 512int __init chips_init(void)
@@ -472,48 +524,4 @@ static void __exit chipsfb_exit(void)
472 pci_unregister_driver(&chipsfb_driver); 524 pci_unregister_driver(&chipsfb_driver);
473} 525}
474 526
475#ifdef CONFIG_PMAC_PBOOK
476/*
477 * Save the contents of the frame buffer when we go to sleep,
478 * and restore it when we wake up again.
479 */
480int
481chips_sleep_notify(struct pmu_sleep_notifier *self, int when)
482{
483 struct fb_info *p = &chipsfb_info;
484 int nb = p->var.yres * p->fix.line_length;
485
486 if (p->screen_base == NULL)
487 return PBOOK_SLEEP_OK;
488
489 switch (when) {
490 case PBOOK_SLEEP_REQUEST:
491 save_framebuffer = vmalloc(nb);
492 if (save_framebuffer == NULL)
493 return PBOOK_SLEEP_REFUSE;
494 break;
495 case PBOOK_SLEEP_REJECT:
496 if (save_framebuffer) {
497 vfree(save_framebuffer);
498 save_framebuffer = NULL;
499 }
500 break;
501 case PBOOK_SLEEP_NOW:
502 chipsfb_blank(1, p);
503 if (save_framebuffer)
504 memcpy(save_framebuffer, p->screen_base, nb);
505 break;
506 case PBOOK_WAKE:
507 if (save_framebuffer) {
508 memcpy(p->screen_base, save_framebuffer, nb);
509 vfree(save_framebuffer);
510 save_framebuffer = NULL;
511 }
512 chipsfb_blank(0, p);
513 break;
514 }
515 return PBOOK_SLEEP_OK;
516}
517#endif /* CONFIG_PMAC_PBOOK */
518
519MODULE_LICENSE("GPL"); 527MODULE_LICENSE("GPL");
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index b209adbd508a..9dd0fbccf994 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -142,7 +142,6 @@ static int fbcon_set_origin(struct vc_data *);
142#define CURSOR_DRAW_DELAY (1) 142#define CURSOR_DRAW_DELAY (1)
143 143
144/* # VBL ints between cursor state changes */ 144/* # VBL ints between cursor state changes */
145#define ARM_CURSOR_BLINK_RATE (10)
146#define ATARI_CURSOR_BLINK_RATE (42) 145#define ATARI_CURSOR_BLINK_RATE (42)
147#define MAC_CURSOR_BLINK_RATE (32) 146#define MAC_CURSOR_BLINK_RATE (32)
148#define DEFAULT_CURSOR_BLINK_RATE (20) 147#define DEFAULT_CURSOR_BLINK_RATE (20)
@@ -288,7 +287,7 @@ static void fb_flashcursor(void *private)
288 release_console_sem(); 287 release_console_sem();
289} 288}
290 289
291#if (defined(__arm__) && defined(IRQ_VSYNCPULSE)) || defined(CONFIG_ATARI) || defined(CONFIG_MAC) 290#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
292static int cursor_blink_rate; 291static int cursor_blink_rate;
293static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp) 292static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
294{ 293{
@@ -878,11 +877,6 @@ static const char *fbcon_startup(void)
878 } 877 }
879#endif /* CONFIG_MAC */ 878#endif /* CONFIG_MAC */
880 879
881#if defined(__arm__) && defined(IRQ_VSYNCPULSE)
882 cursor_blink_rate = ARM_CURSOR_BLINK_RATE;
883 irqres = request_irq(IRQ_VSYNCPULSE, fb_vbl_handler, SA_SHIRQ,
884 "framebuffer vbl", info);
885#endif
886 /* Initialize the work queue. If the driver provides its 880 /* Initialize the work queue. If the driver provides its
887 * own work queue this means it will use something besides 881 * own work queue this means it will use something besides
888 * default timer to flash the cursor. */ 882 * default timer to flash the cursor. */
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 7dfbf39b4ed3..ddc9443254d9 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -256,7 +256,7 @@ static ssize_t show_cmap(struct class_device *class_device, char *buf)
256 unsigned int offset = 0, i; 256 unsigned int offset = 0, i;
257 257
258 if (!fb_info->cmap.red || !fb_info->cmap.blue || 258 if (!fb_info->cmap.red || !fb_info->cmap.blue ||
259 fb_info->cmap.green || fb_info->cmap.transp) 259 !fb_info->cmap.green || !fb_info->cmap.transp)
260 return -EINVAL; 260 return -EINVAL;
261 261
262 for (i = 0; i < fb_info->cmap.len; i++) { 262 for (i = 0; i < fb_info->cmap.len; i++) {
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 8fe1c12a17bd..cabd53cec991 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -249,9 +249,6 @@ static void imxfb_enable_controller(struct imxfb_info *fbi)
249 /* disable hardware cursor */ 249 /* disable hardware cursor */
250 LCDC_CPOS &= ~(CPOS_CC0 | CPOS_CC1); 250 LCDC_CPOS &= ~(CPOS_CC0 | CPOS_CC1);
251 251
252 /* fixed burst length (see erratum 11) */
253 LCDC_DMACR = DMACR_BURST | DMACR_HM(8) | DMACR_TM(2);
254
255 LCDC_RMCR = RMCR_LCDC_EN; 252 LCDC_RMCR = RMCR_LCDC_EN;
256 253
257 if(fbi->backlight_power) 254 if(fbi->backlight_power)
@@ -359,6 +356,7 @@ static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *inf
359 LCDC_PCR = fbi->pcr; 356 LCDC_PCR = fbi->pcr;
360 LCDC_PWMR = fbi->pwmr; 357 LCDC_PWMR = fbi->pwmr;
361 LCDC_LSCR1 = fbi->lscr1; 358 LCDC_LSCR1 = fbi->lscr1;
359 LCDC_DMACR = fbi->dmacr;
362 360
363 return 0; 361 return 0;
364} 362}
@@ -509,6 +507,7 @@ static int __init imxfb_init_fbinfo(struct device *dev)
509 fbi->cmap_inverse = inf->cmap_inverse; 507 fbi->cmap_inverse = inf->cmap_inverse;
510 fbi->pcr = inf->pcr; 508 fbi->pcr = inf->pcr;
511 fbi->lscr1 = inf->lscr1; 509 fbi->lscr1 = inf->lscr1;
510 fbi->dmacr = inf->dmacr;
512 fbi->pwmr = inf->pwmr; 511 fbi->pwmr = inf->pwmr;
513 fbi->lcd_power = inf->lcd_power; 512 fbi->lcd_power = inf->lcd_power;
514 fbi->backlight_power = inf->backlight_power; 513 fbi->backlight_power = inf->backlight_power;
@@ -642,12 +641,12 @@ static int imxfb_remove(struct device *dev)
642{ 641{
643 struct platform_device *pdev = to_platform_device(dev); 642 struct platform_device *pdev = to_platform_device(dev);
644 struct fb_info *info = dev_get_drvdata(dev); 643 struct fb_info *info = dev_get_drvdata(dev);
644 struct imxfb_info *fbi = info->par;
645 struct resource *res; 645 struct resource *res;
646 646
647 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 647 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
648 648
649 /* disable LCD controller */ 649 imxfb_disable_controller(fbi);
650 LCDC_RMCR &= ~RMCR_LCDC_EN;
651 650
652 unregister_framebuffer(info); 651 unregister_framebuffer(info);
653 652
@@ -663,8 +662,9 @@ static int imxfb_remove(struct device *dev)
663 662
664void imxfb_shutdown(struct device * dev) 663void imxfb_shutdown(struct device * dev)
665{ 664{
666 /* disable LCD Controller */ 665 struct fb_info *info = dev_get_drvdata(dev);
667 LCDC_RMCR &= ~RMCR_LCDC_EN; 666 struct imxfb_info *fbi = info->par;
667 imxfb_disable_controller(fbi);
668} 668}
669 669
670static struct device_driver imxfb_driver = { 670static struct device_driver imxfb_driver = {
diff --git a/drivers/video/imxfb.h b/drivers/video/imxfb.h
index 128c3ee515c7..e837a8b48eb8 100644
--- a/drivers/video/imxfb.h
+++ b/drivers/video/imxfb.h
@@ -54,6 +54,7 @@ struct imxfb_info {
54 u_int pcr; 54 u_int pcr;
55 u_int pwmr; 55 u_int pwmr;
56 u_int lscr1; 56 u_int lscr1;
57 u_int dmacr;
57 u_int cmap_inverse:1, 58 u_int cmap_inverse:1,
58 cmap_static:1, 59 cmap_static:1,
59 unused:30; 60 unused:30;
diff --git a/drivers/video/logo/Kconfig b/drivers/video/logo/Kconfig
index 6ba10e3aceff..3e9ccf370ab2 100644
--- a/drivers/video/logo/Kconfig
+++ b/drivers/video/logo/Kconfig
@@ -63,5 +63,10 @@ config LOGO_SUPERH_CLUT224
63 depends on LOGO && SUPERH 63 depends on LOGO && SUPERH
64 default y 64 default y
65 65
66config LOGO_M32R_CLUT224
67 bool "224-color M32R Linux logo"
68 depends on LOGO && M32R
69 default y
70
66endmenu 71endmenu
67 72
diff --git a/drivers/video/logo/Makefile b/drivers/video/logo/Makefile
index b0d995020bd1..d0244c04af5a 100644
--- a/drivers/video/logo/Makefile
+++ b/drivers/video/logo/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_LOGO_SUN_CLUT224) += logo_sun_clut224.o
12obj-$(CONFIG_LOGO_SUPERH_MONO) += logo_superh_mono.o 12obj-$(CONFIG_LOGO_SUPERH_MONO) += logo_superh_mono.o
13obj-$(CONFIG_LOGO_SUPERH_VGA16) += logo_superh_vga16.o 13obj-$(CONFIG_LOGO_SUPERH_VGA16) += logo_superh_vga16.o
14obj-$(CONFIG_LOGO_SUPERH_CLUT224) += logo_superh_clut224.o 14obj-$(CONFIG_LOGO_SUPERH_CLUT224) += logo_superh_clut224.o
15obj-$(CONFIG_LOGO_M32R_CLUT224) += logo_m32r_clut224.o
15 16
16# How to generate logo's 17# How to generate logo's
17 18
diff --git a/drivers/video/logo/logo.c b/drivers/video/logo/logo.c
index 77b622075001..788fa812c871 100644
--- a/drivers/video/logo/logo.c
+++ b/drivers/video/logo/logo.c
@@ -33,6 +33,7 @@ extern const struct linux_logo logo_sun_clut224;
33extern const struct linux_logo logo_superh_mono; 33extern const struct linux_logo logo_superh_mono;
34extern const struct linux_logo logo_superh_vga16; 34extern const struct linux_logo logo_superh_vga16;
35extern const struct linux_logo logo_superh_clut224; 35extern const struct linux_logo logo_superh_clut224;
36extern const struct linux_logo logo_m32r_clut224;
36 37
37 38
38const struct linux_logo *fb_find_logo(int depth) 39const struct linux_logo *fb_find_logo(int depth)
@@ -97,6 +98,10 @@ const struct linux_logo *fb_find_logo(int depth)
97 /* SuperH Linux logo */ 98 /* SuperH Linux logo */
98 logo = &logo_superh_clut224; 99 logo = &logo_superh_clut224;
99#endif 100#endif
101#ifdef CONFIG_LOGO_M32R_CLUT224
102 /* M32R Linux logo */
103 logo = &logo_m32r_clut224;
104#endif
100 } 105 }
101 return logo; 106 return logo;
102} 107}
diff --git a/drivers/video/logo/logo_m32r_clut224.ppm b/drivers/video/logo/logo_m32r_clut224.ppm
new file mode 100644
index 000000000000..8b2983c5a0bd
--- /dev/null
+++ b/drivers/video/logo/logo_m32r_clut224.ppm
@@ -0,0 +1,1292 @@
1P3
2# CREATOR: The GIMP's PNM Filter Version 1.0
3#
4# Note: how to convert ppm to pnm(ascii).
5# $ convert -posterize 224 m32r.ppm - | pnm2asc -f5 >logo_m32r_clut224.ppm
6#
7# convert - imagemagick: /usr/bin/convert
8# pnm2asc - pnm to ascii-pnm format converter
9# http://www.is.aist.go.jp/etlcdb/util/p2a.htm#English
10
1180 80
12255
13 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
14 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
15 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
16 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
17 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
18 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
19 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
20 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
21 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
22 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
23 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
24 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
25 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
26 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
27 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
28 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
29 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
30 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
31 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
32 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
33 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
34 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
35 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
36 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
37 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
38 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
39 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
40 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
41 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
42 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
43 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
44 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
45 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
46 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
47 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
48 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
49 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
50 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
51 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
52 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
53 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
54 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
55 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
56 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
57 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
58 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
59 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
60 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
61 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
62 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
63 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
64 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
65 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
66 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
67 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
68 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
69 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
70 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
71 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
72 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
73 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
74 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
75 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
76 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
77 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
78 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
79 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
80 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
81 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
82 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
83 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
84 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
85 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
86 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
87 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
88 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
89 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
90 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
91 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
92 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
93 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
94 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
95 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
96 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
97 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
98 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
99 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
100 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
101 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
102 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
103 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
104 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
105 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
106 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
107 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
108 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
109 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
110 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
111 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
112 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
113 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
114 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
115 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
116 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
117 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
118 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
119 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
120 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
121 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
122 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
123 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
124 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
125 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
126 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
127 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
128 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
129 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
130 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
131 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
132 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
133 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
134 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
135 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
136 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
137 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
138 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
139 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
140 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
141 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
142 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
143 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
144 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
145 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
146 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
147 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
148 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
149 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
150 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
151 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
152 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
153 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
154 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
155 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
156 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
157 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
158 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
159 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
160 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
161 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
162 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
163 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
164 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
165 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
166 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
167 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
168 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
169 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
170 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
171 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
172 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
173 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
174 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
175 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
176 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
177 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
178 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
179 215 150 13 2 2 3 2 2 3 2 2 3 2 2 3
180 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
181 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
182 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
183 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
184 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
185 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
186 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
187 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
188 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
189 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
190 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
191 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
192 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
193 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
194 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
195 215 150 13 2 2 3 2 2 3 2 2 3 2 2 3
196 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
197 2 2 3 43 43 43 75 75 75 27 27 27 2 2 3
198 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
199 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
200 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
201 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
202 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
203 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
204 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
205 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
206 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
207 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
208 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
209 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
210 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
211 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
212 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
213 2 2 3 59 59 59 123 123 123 67 67 67 27 27 27
214 2 2 3 2 2 3 215 150 13 215 150 13 215 150 13
215 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
216 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
217 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
218 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
219 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
220 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
221 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
222 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
223 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
224 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
225 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
226 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
227 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
228 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
229 10 6 3 59 59 59 80 80 80 43 43 43 27 27 27
230 2 2 3 2 2 3 215 150 13 215 150 13 215 150 13
231 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
232 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
233 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
234 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
235 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
236 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
237 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
238 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
239 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
240 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
241 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
242 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
243 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
244 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
245 2 2 3 19 19 19 2 2 3 2 2 3 2 2 3
246 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
247 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
248 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
249 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
250 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
251 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
252 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
253 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
254 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
255 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
256 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
257 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
258 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
259 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
260 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
261 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
262 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
263 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
264 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
265 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
266 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
267 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
268 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
269 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
270 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
271 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
272 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
273 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
274 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
275 2 2 3 2 2 3 10 6 3 10 6 3 2 2 3
276 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
277 10 6 3 11 11 11 11 11 11 2 2 3 2 2 3
278 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
279 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
280 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
281 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
282 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
283 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
284 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
285 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
286 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
287 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
288 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
289 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
290 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
291 2 2 3 2 2 3 2 2 3 27 27 27 10 6 3
292 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
293 19 19 19 2 2 3 2 2 3 51 51 51 2 2 3
294 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
295 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
296 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
297 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
298 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
299 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
300 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
301 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
302 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
303 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
304 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
305 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
306 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
307 2 2 3 123 123 123 196 196 196 115 115 115 2 2 3
308 2 2 3 2 2 3 2 2 3 75 75 75 141 141 140
309 172 172 172 196 196 196 190 189 188 2 2 3 11 11 11
310 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
311 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
312 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
313 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
314 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
315 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
316 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
317 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
318 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
319 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
320 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
321 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
322 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
323 27 27 27 164 164 164 228 228 228 221 221 220 10 6 3
324 2 2 3 2 2 3 2 2 3 172 172 172 245 245 245
325 254 254 252 254 254 252 221 221 220 35 35 35 2 2 3
326 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
327 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
328 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
329 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
330 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
331 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
332 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
333 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
334 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
335 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
336 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
337 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
338 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
339 164 164 164 228 228 228 35 35 35 236 236 236 236 236 236
340 2 2 3 11 11 11 2 2 3 254 254 252 245 245 245
341 2 2 3 75 75 75 245 245 245 245 245 245 2 2 3
342 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
343 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
344 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
345 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
346 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
347 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
348 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
349 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
350 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
351 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
352 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
353 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
354 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
355 212 212 212 2 2 3 51 51 51 11 11 11 245 245 245
356 27 27 27 80 80 80 10 6 3 254 254 252 2 2 3
357 2 2 3 91 91 91 19 19 19 254 254 252 2 2 3
358 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
359 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
360 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
361 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
362 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
363 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
364 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
365 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
366 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
367 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
368 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
369 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
370 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
371 196 196 196 10 6 3 2 2 3 11 11 11 107 107 107
372 49 35 5 57 42 11 31 22 3 236 236 236 2 2 3
373 2 2 3 2 2 3 2 2 3 254 254 252 2 2 3
374 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
375 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
376 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
377 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
378 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
379 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
380 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
381 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
382 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
383 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
384 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
385 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
386 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
387 107 107 107 221 221 220 2 2 3 64 43 7 194 148 10
388 236 188 10 225 180 10 170 126 10 236 188 10 94 86 67
389 2 2 3 2 2 3 204 204 204 236 236 236 2 2 3
390 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
391 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
392 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
393 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
394 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
395 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
396 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
397 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
398 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
399 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
400 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
401 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
402 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
403 2 2 3 228 228 228 182 126 10 218 164 9 236 188 10
404 236 188 10 237 204 14 236 205 40 246 214 48 246 214 48
405 245 189 11 209 156 9 196 196 196 11 11 11 2 2 3
406 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
407 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
408 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
409 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
410 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
411 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
412 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
413 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
414 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
415 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
416 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
417 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
418 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
419 2 2 3 165 114 10 207 148 7 229 172 9 236 180 10
420 236 196 11 237 204 14 242 218 43 246 218 75 246 218 19
421 246 213 13 246 218 19 244 205 11 218 164 9 2 2 3
422 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
423 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
424 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
425 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
426 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
427 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
428 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
429 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
430 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
431 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
432 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
433 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
434 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
435 164 109 5 192 133 7 224 165 9 236 180 10 236 188 10
436 236 196 11 241 212 42 246 218 75 246 218 19 246 218 19
437 246 218 19 236 196 11 150 114 10 229 172 9 2 2 3
438 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
439 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
440 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
441 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
442 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
443 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
444 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
445 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
446 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
447 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
448 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
449 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
450 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
451 165 114 10 201 142 7 229 172 9 242 182 11 236 188 10
452 237 204 14 245 213 67 246 218 19 246 213 13 246 213 13
453 154 119 10 207 148 7 218 164 9 216 156 8 2 2 3
454 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
455 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
456 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
457 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
458 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
459 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
460 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
461 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
462 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
463 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
464 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
465 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
466 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
467 2 2 3 120 78 3 225 180 10 245 189 11 236 205 40
468 241 212 42 241 212 17 237 204 14 148 107 9 182 126 10
469 216 156 8 218 164 9 207 148 7 82 70 43 2 2 3
470 2 2 3 123 123 123 35 35 35 2 2 3 2 2 3
471 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
472 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
473 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
474 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
475 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
476 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
477 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
478 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
479 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
480 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
481 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
482 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
483 10 6 3 180 180 180 156 102 5 135 88 5 142 106 7
484 126 98 11 165 114 10 185 132 9 207 148 7 215 150 13
485 199 140 8 188 148 71 196 196 196 190 189 188 2 2 3
486 2 2 3 11 11 11 132 132 132 75 75 75 2 2 3
487 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
488 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
489 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
490 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
491 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
492 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
493 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
494 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
495 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
496 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
497 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
498 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
499 10 6 3 190 189 188 190 189 188 151 97 5 192 133 7
500 207 148 7 206 142 8 199 140 8 180 121 7 180 132 31
501 190 189 188 190 189 188 212 212 212 212 212 212 107 107 107
502 2 2 3 2 2 3 99 99 99 51 51 51 2 2 3
503 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
504 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
505 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
506 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
507 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
508 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
509 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
510 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
511 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
512 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
513 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
514 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
515 2 2 3 190 189 188 190 189 188 190 189 188 136 95 7
516 151 97 5 151 97 5 151 97 5 183 156 91 190 189 188
517 190 189 188 228 228 228 254 254 252 254 254 252 221 221 220
518 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
519 2 2 3 10 6 3 215 150 13 215 150 13 215 150 13
520 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
521 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
522 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
523 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
524 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
525 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
526 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
527 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
528 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
529 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
530 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
531 75 75 75 245 245 245 196 196 196 190 189 188 190 189 188
532 190 189 188 196 196 196 190 189 188 190 189 188 204 204 204
533 236 236 236 254 254 252 254 254 252 254 254 252 254 254 252
534 35 35 35 2 2 3 2 2 3 2 2 3 2 2 3
535 2 2 3 2 2 3 215 150 13 215 150 13 215 150 13
536 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
537 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
538 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
539 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
540 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
541 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
542 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
543 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
544 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
545 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
546 215 150 13 215 150 13 2 2 3 27 27 27 2 2 3
547 245 245 245 254 254 252 245 245 245 190 189 188 190 189 188
548 190 189 188 190 189 188 190 189 188 212 212 212 245 245 245
549 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
550 254 254 252 10 6 3 2 2 3 2 2 3 2 2 3
551 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
552 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
553 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
554 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
555 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
556 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
557 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
558 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
559 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
560 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
561 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
562 215 150 13 215 150 13 2 2 3 2 2 3 132 132 132
563 254 254 252 254 254 252 254 254 252 236 236 236 196 196 196
564 190 189 188 204 204 204 245 245 245 245 245 245 254 254 252
565 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
566 254 254 252 80 80 80 2 2 3 2 2 3 2 2 3
567 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
568 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
569 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
570 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
571 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
572 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
573 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
574 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
575 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
576 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
577 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
578 215 150 13 2 2 3 2 2 3 2 2 3 254 254 252
579 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
580 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
581 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
582 254 254 252 254 254 252 2 2 3 2 2 3 2 2 3
583 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
584 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
585 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
586 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
587 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
588 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
589 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
590 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
591 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
592 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
593 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
594 2 2 3 2 2 3 2 2 3 212 212 212 245 245 245
595 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
596 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
597 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
598 254 254 252 254 254 252 2 2 3 2 2 3 2 2 3
599 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
600 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
601 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
602 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
603 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
604 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
605 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
606 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
607 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
608 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
609 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
610 2 2 3 2 2 3 2 2 3 204 204 204 245 245 245
611 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
612 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
613 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
614 245 245 245 236 236 236 2 2 3 2 2 3 2 2 3
615 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
616 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
617 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
618 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
619 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
620 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
621 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
622 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
623 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
624 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
625 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
626 2 2 3 2 2 3 11 11 11 164 164 164 212 212 212
627 236 236 236 245 245 245 254 254 252 236 236 236 221 221 220
628 221 221 220 228 228 228 245 245 245 245 245 245 245 245 245
629 236 236 236 221 221 220 212 212 212 204 204 204 204 204 204
630 196 196 196 204 204 204 59 59 59 2 2 3 2 2 3
631 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
632 2 2 3 2 2 3 215 150 13 215 150 13 215 150 13
633 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
634 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
635 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
636 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
637 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
638 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
639 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
640 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
641 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
642 2 2 3 2 2 3 27 27 27 172 172 172 212 212 212
643 236 236 236 254 254 252 254 254 252 254 254 252 228 228 228
644 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
645 254 254 252 245 245 245 221 221 220 204 204 204 196 196 196
646 196 196 196 196 196 196 228 228 228 19 19 19 2 2 3
647 80 80 80 2 2 3 2 2 3 2 2 3 2 2 3
648 2 2 3 2 2 3 215 150 13 215 150 13 215 150 13
649 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
650 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
651 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
652 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
653 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
654 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
655 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
656 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
657 215 150 13 215 150 13 2 2 3 2 2 3 2 2 3
658 11 11 11 2 2 3 164 164 164 236 236 236 254 254 252
659 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
660 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
661 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
662 236 236 236 212 212 212 196 196 196 245 245 245 2 2 3
663 2 2 3 11 11 11 51 51 51 2 2 3 2 2 3
664 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
665 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
666 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
667 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
668 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
669 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
670 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
671 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
672 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
673 215 150 13 215 150 13 2 2 3 2 2 3 86 86 83
674 2 2 3 27 27 27 236 236 236 254 254 252 254 254 252
675 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
676 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
677 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
678 254 254 252 254 254 252 212 212 212 196 196 196 91 91 91
679 2 2 3 2 2 3 2 2 3 11 11 11 2 2 3
680 2 2 3 2 2 3 2 2 3 215 150 13 215 150 13
681 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
682 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
683 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
684 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
685 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
686 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
687 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
688 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
689 215 150 13 215 150 13 2 2 3 2 2 3 2 2 3
690 2 2 3 245 245 245 254 254 252 254 254 252 254 254 252
691 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
692 254 254 252 245 245 245 254 254 252 254 254 252 254 254 252
693 254 254 252 245 245 245 254 254 252 254 254 252 254 254 252
694 254 254 252 254 254 252 254 254 252 221 221 220 245 245 245
695 2 2 3 11 11 11 43 43 43 19 19 19 10 6 3
696 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
697 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
698 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
699 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
700 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
701 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
702 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
703 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
704 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
705 215 150 13 215 150 13 2 2 3 80 80 80 2 2 3
706 2 2 3 254 254 252 254 254 252 254 254 252 254 254 252
707 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
708 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
709 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
710 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
711 43 43 43 27 27 27 80 80 80 19 19 19 80 80 80
712 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
713 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
714 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
715 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
716 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
717 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
718 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
719 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
720 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
721 215 150 13 2 2 3 2 2 3 2 2 3 2 2 3
722 245 245 245 254 254 252 254 254 252 17 11 233 254 254 252
723 254 254 252 254 254 252 254 254 252 236 236 236 17 11 233
724 17 11 233 254 254 252 254 254 252 254 254 252 254 254 252
725 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
726 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
727 254 254 252 11 11 11 11 11 11 2 2 3 2 2 3
728 2 2 3 2 2 3 2 2 3 2 2 3 215 150 13
729 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
730 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
731 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
732 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
733 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
734 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
735 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
736 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
737 215 150 13 2 2 3 67 67 67 2 2 3 19 19 19
738 254 254 252 254 254 252 245 245 245 17 11 233 245 245 245
739 254 254 252 254 254 252 17 11 233 228 228 228 17 11 233
740 17 11 233 17 11 233 17 11 233 254 254 252 17 11 233
741 17 11 233 254 254 252 254 254 252 17 11 233 17 11 233
742 17 11 233 254 254 252 254 254 252 254 254 252 254 254 252
743 254 254 252 2 2 3 2 2 3 2 2 3 2 2 3
744 11 11 11 2 2 3 2 2 3 2 2 3 2 2 3
745 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
746 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
747 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
748 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
749 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
750 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
751 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
752 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
753 2 2 3 10 6 3 11 11 11 2 2 3 228 228 228
754 254 254 252 254 254 252 254 254 252 17 11 233 254 254 252
755 254 254 252 17 11 233 17 11 233 17 11 233 245 245 245
756 254 254 252 254 254 252 17 11 233 17 11 233 17 11 233
757 17 11 233 17 11 233 254 254 252 17 11 233 17 11 233
758 17 11 233 17 11 233 254 254 252 254 254 252 254 254 252
759 254 254 252 2 2 3 2 2 3 2 2 3 2 2 3
760 27 27 27 2 2 3 2 2 3 2 2 3 2 2 3
761 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
762 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
763 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
764 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
765 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
766 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
767 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
768 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
769 2 2 3 2 2 3 2 2 3 2 2 3 254 254 252
770 254 254 252 254 254 252 254 254 252 17 11 233 17 11 233
771 17 11 233 17 11 233 17 11 233 17 11 233 254 254 252
772 17 11 233 17 11 233 17 11 233 254 254 252 254 254 252
773 17 11 233 17 11 233 254 254 252 17 11 233 17 11 233
774 254 254 252 17 11 233 254 254 252 254 254 252 254 254 252
775 254 254 252 2 2 3 2 2 3 2 2 3 2 2 3
776 11 11 11 2 2 3 2 2 3 2 2 3 2 2 3
777 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
778 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
779 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
780 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
781 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
782 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
783 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
784 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
785 2 2 3 19 19 19 2 2 3 2 2 3 254 254 252
786 254 254 252 254 254 252 17 11 233 245 245 245 17 11 233
787 17 11 233 245 245 245 254 254 252 17 11 233 254 254 252
788 17 11 233 17 11 233 17 11 233 254 254 252 254 254 252
789 17 11 233 17 11 233 254 254 252 17 11 233 17 11 233
790 17 11 233 17 11 233 254 254 252 254 254 252 254 254 252
791 254 254 252 2 2 3 2 2 3 2 2 3 2 2 3
792 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
793 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
794 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
795 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
796 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
797 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
798 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
799 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
800 215 150 13 215 150 13 215 150 13 215 150 13 2 2 3
801 2 2 3 19 19 19 2 2 3 19 19 19 254 254 252
802 254 254 252 245 245 245 17 11 233 254 254 252 17 11 233
803 17 11 233 254 254 252 254 254 252 17 11 233 254 254 252
804 254 254 252 254 254 252 17 11 233 17 11 233 254 254 252
805 17 11 233 17 11 233 254 254 252 17 11 233 17 11 233
806 17 11 233 17 11 233 17 11 233 254 254 252 254 254 252
807 254 254 252 2 2 3 2 2 3 2 2 3 2 2 3
808 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
809 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
810 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
811 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
812 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
813 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
814 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
815 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
816 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
817 2 2 3 43 43 43 2 2 3 43 43 43 254 254 252
818 245 245 245 254 254 252 17 11 233 254 254 252 17 11 233
819 254 254 252 254 254 252 254 254 252 17 11 233 17 11 233
820 17 11 233 17 11 233 17 11 233 254 254 252 17 11 233
821 17 11 233 17 11 233 17 11 233 17 11 233 17 11 233
822 245 245 245 254 254 252 17 11 233 254 254 252 254 254 252
823 245 245 245 2 2 3 2 2 3 2 2 3 11 11 11
824 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
825 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
826 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
827 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
828 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
829 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
830 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
831 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
832 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
833 2 2 3 75 75 75 2 2 3 99 99 99 254 254 252
834 254 254 252 254 254 252 17 11 233 254 254 252 254 254 252
835 254 254 252 254 254 252 245 245 245 228 228 228 254 254 252
836 254 254 252 17 11 233 245 245 245 254 254 252 254 254 252
837 254 254 252 254 254 252 254 254 252 17 11 233 17 11 233
838 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
839 254 254 252 2 2 3 2 2 3 2 2 3 75 75 75
840 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
841 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
842 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
843 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
844 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
845 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
846 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
847 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
848 215 150 13 215 150 13 215 150 13 2 2 3 2 2 3
849 2 2 3 2 2 3 11 11 11 107 107 107 254 254 252
850 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
851 245 245 245 254 254 252 245 245 245 236 236 236 254 254 252
852 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
853 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
854 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
855 254 254 252 2 2 3 2 2 3 11 11 11 19 19 19
856 11 11 11 2 2 3 2 2 3 2 2 3 2 2 3
857 2 2 3 215 150 13 215 150 13 215 150 13 215 150 13
858 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
859 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
860 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
861 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
862 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
863 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
864 215 150 13 215 150 13 215 150 13 2 2 3 11 11 11
865 140 102 3 11 11 11 10 6 3 67 67 67 254 254 252
866 245 245 245 245 245 245 254 254 252 254 254 252 245 245 245
867 254 254 252 254 254 252 245 245 245 228 228 228 254 254 252
868 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
869 254 254 252 245 245 245 254 254 252 254 254 252 245 245 245
870 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
871 254 254 252 2 2 3 43 43 43 2 2 3 2 2 3
872 2 2 3 11 11 11 67 67 67 11 11 11 2 2 3
873 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
874 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
875 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
876 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
877 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
878 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
879 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
880 215 150 13 215 150 13 215 150 13 185 132 9 242 182 11
881 245 189 11 245 189 11 49 35 5 2 2 3 228 228 228
882 254 254 252 254 254 252 254 254 252 245 245 245 254 254 252
883 254 254 252 254 254 252 254 254 252 228 228 228 245 245 245
884 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
885 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
886 254 254 252 254 254 252 254 254 252 245 238 222 232 189 94
887 226 186 99 43 43 43 2 2 3 2 2 3 2 2 3
888 2 2 3 2 2 3 2 2 3 59 59 59 2 2 3
889 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
890 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
891 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
892 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
893 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
894 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
895 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
896 215 150 13 215 150 13 215 150 13 216 156 8 236 180 22
897 245 189 11 245 189 11 245 189 11 49 35 5 11 11 11
898 212 212 212 245 245 245 254 254 252 254 254 252 254 254 252
899 254 254 252 254 254 252 245 245 245 228 228 228 254 254 252
900 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
901 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
902 245 245 245 254 254 252 254 254 252 229 172 9 246 218 19
903 246 218 19 41 27 3 2 2 3 2 2 3 2 2 3
904 2 2 3 2 2 3 19 19 19 27 27 27 196 154 14
905 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
906 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
907 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
908 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
909 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
910 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
911 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
912 215 150 13 215 150 13 199 140 8 229 172 9 242 182 11
913 245 189 11 245 189 11 245 189 11 244 196 10 2 2 3
914 2 2 3 115 115 115 254 254 252 254 254 252 254 254 252
915 254 254 252 254 254 252 245 245 245 228 228 228 254 254 252
916 254 254 252 245 245 245 254 254 252 254 254 252 254 254 252
917 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
918 254 254 252 254 254 252 254 254 252 224 165 9 245 189 11
919 236 196 11 19 19 19 2 2 3 2 2 3 2 2 3
920 2 2 3 2 2 3 2 2 3 11 11 11 236 196 11
921 244 205 11 215 150 13 215 150 13 215 150 13 215 150 13
922 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
923 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
924 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
925 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
926 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
927 215 150 13 215 150 13 182 126 10 209 156 9 215 150 13
928 193 140 10 207 148 24 216 156 8 242 182 11 245 189 11
929 245 189 11 245 189 11 245 189 11 245 189 11 209 156 9
930 2 2 3 2 2 3 43 43 43 254 254 252 254 254 252
931 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
932 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
933 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
934 254 254 252 254 254 252 236 236 236 216 156 8 245 189 11
935 229 172 9 64 43 7 2 2 3 2 2 3 2 2 3
936 2 2 3 2 2 3 2 2 3 207 148 7 236 188 10
937 245 189 11 215 150 13 215 150 13 215 150 13 215 150 13
938 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
939 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
940 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
941 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
942 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
943 215 150 13 180 121 7 216 156 8 242 182 11 236 180 10
944 229 172 9 242 182 11 242 182 11 245 189 11 245 189 11
945 245 189 11 245 189 11 245 189 11 245 189 11 237 204 14
946 170 126 10 2 2 3 2 2 3 11 11 11 236 236 236
947 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
948 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
949 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
950 254 254 252 204 204 204 196 196 196 216 156 8 236 180 10
951 224 165 9 182 126 10 73 48 6 2 2 3 2 2 3
952 2 2 3 41 27 3 199 140 8 229 172 9 236 180 10
953 245 189 11 215 150 13 215 150 13 215 150 13 215 150 13
954 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
955 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
956 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
957 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
958 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
959 215 150 13 185 132 9 229 172 9 245 189 11 245 189 11
960 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
961 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
962 226 188 11 2 2 3 2 2 3 2 2 3 11 11 11
963 245 245 245 254 254 252 254 254 252 254 254 252 254 254 252
964 254 254 252 245 245 245 254 254 252 254 254 252 254 254 252
965 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
966 254 254 252 196 196 196 196 196 196 215 150 13 236 180 10
967 229 172 9 201 142 7 185 132 9 180 121 7 173 120 10
968 180 121 7 192 133 7 229 172 9 242 182 11 245 189 11
969 245 189 11 215 150 13 215 150 13 215 150 13 215 150 13
970 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
971 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
972 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
973 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
974 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
975 215 150 13 180 126 47 224 165 9 245 189 11 245 189 11
976 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
977 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
978 236 188 10 193 140 10 2 2 3 2 2 3 2 2 3
979 2 2 3 212 212 212 254 254 252 245 245 245 245 245 245
980 254 254 252 254 254 252 254 254 252 245 245 245 254 254 252
981 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
982 254 254 252 204 204 204 196 196 196 199 140 8 229 172 9
983 236 180 10 218 164 9 215 150 13 207 148 7 207 148 7
984 216 156 8 229 172 9 245 189 11 245 189 11 245 189 11
985 245 189 11 242 182 11 215 150 13 215 150 13 215 150 13
986 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
987 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
988 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
989 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
990 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
991 215 150 13 185 132 9 216 156 8 242 182 11 245 189 11
992 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
993 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
994 245 189 11 236 196 11 19 19 19 2 2 3 2 2 3
995 2 2 3 11 11 11 254 254 252 254 254 252 254 254 252
996 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
997 254 254 252 254 254 252 245 245 245 254 254 252 254 254 252
998 245 245 245 221 221 220 196 196 196 185 132 9 229 172 9
999 242 182 11 229 172 9 224 165 9 218 164 9 224 165 9
1000 229 172 9 236 180 10 245 189 11 245 189 11 245 189 11
1001 245 189 11 236 180 22 242 182 11 215 150 13 215 150 13
1002 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1003 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1004 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1005 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1006 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1007 215 150 13 215 150 13 215 150 13 236 180 22 245 189 11
1008 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1009 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1010 245 189 11 236 188 10 225 180 10 2 2 3 2 2 3
1011 2 2 3 11 11 11 254 254 252 254 254 252 254 254 252
1012 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1013 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1014 254 254 252 221 221 220 19 19 19 185 132 9 224 165 9
1015 245 189 11 245 189 11 242 182 11 236 180 10 236 180 10
1016 242 182 11 242 182 11 245 189 11 245 189 11 245 189 11
1017 245 189 11 245 189 11 245 189 11 245 189 11 196 154 14
1018 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1019 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1020 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1021 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1022 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1023 215 150 13 215 150 13 207 148 7 236 180 22 245 189 11
1024 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1025 245 189 11 245 189 11 245 189 11 245 189 11 242 182 11
1026 245 189 11 245 189 11 237 204 14 135 88 5 2 2 3
1027 27 27 27 254 254 252 254 254 252 254 254 252 254 254 252
1028 254 254 252 245 245 245 254 254 252 254 254 252 245 245 245
1029 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1030 254 254 252 67 67 67 19 13 3 185 132 9 229 172 9
1031 242 182 11 245 189 11 245 189 11 245 189 11 245 189 11
1032 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1033 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1034 236 180 22 215 150 13 215 150 13 215 150 13 215 150 13
1035 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1036 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1037 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1038 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1039 215 150 13 215 150 13 215 150 13 245 189 11 242 182 11
1040 242 182 11 245 189 11 245 189 11 245 189 11 245 189 11
1041 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1042 245 189 11 245 189 11 236 188 10 226 188 11 104 83 48
1043 254 254 252 254 254 252 254 254 252 254 254 252 245 245 245
1044 254 254 252 254 254 252 245 245 245 254 254 252 245 245 245
1045 254 254 252 245 245 245 254 254 252 254 254 252 254 254 252
1046 2 2 3 2 2 3 56 38 5 185 132 9 229 172 9
1047 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1048 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1049 245 189 11 245 189 11 245 189 11 245 189 11 242 182 11
1050 229 172 9 215 150 13 215 150 13 215 150 13 215 150 13
1051 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1052 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1053 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1054 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1055 215 150 13 182 126 10 215 150 13 242 182 11 245 189 11
1056 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1057 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1058 245 189 11 242 182 11 245 189 11 236 196 11 216 156 8
1059 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1060 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1061 254 254 252 254 254 252 254 254 252 245 245 245 2 2 3
1062 2 2 3 2 2 3 75 54 3 182 126 10 229 172 9
1063 242 182 11 245 189 11 245 189 11 245 189 11 245 189 11
1064 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1065 245 189 11 245 189 11 245 189 11 245 189 11 229 172 9
1066 207 148 24 215 150 13 215 150 13 215 150 13 215 150 13
1067 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1068 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1069 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1070 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1071 215 150 13 192 133 7 229 172 9 242 182 11 245 189 11
1072 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1073 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1074 245 189 11 245 189 11 242 182 11 225 180 10 224 165 9
1075 107 69 5 245 245 245 254 254 252 254 254 252 254 254 252
1076 254 254 252 254 254 252 254 254 252 254 254 252 254 254 252
1077 254 254 252 236 236 236 2 2 3 2 2 3 2 2 3
1078 2 2 3 2 2 3 91 67 9 182 126 10 229 172 9
1079 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1080 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1081 245 189 11 242 182 11 242 182 11 216 156 8 180 126 47
1082 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1083 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1084 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1085 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1086 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1087 215 150 13 206 142 8 224 165 9 245 189 11 242 182 11
1088 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1089 245 189 11 245 189 11 245 189 11 245 189 11 242 182 11
1090 245 189 11 245 189 11 242 182 11 242 182 11 216 156 8
1091 156 102 5 19 13 3 43 43 43 196 196 196 254 254 252
1092 245 245 245 254 254 252 254 254 252 204 204 204 51 51 51
1093 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1094 2 2 3 2 2 3 95 62 5 185 132 9 229 172 9
1095 242 182 11 245 189 11 245 189 11 245 189 11 245 189 11
1096 245 189 11 245 189 11 242 182 11 245 189 11 245 189 11
1097 236 180 22 216 156 8 206 142 8 215 150 13 215 150 13
1098 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1099 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1100 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1101 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1102 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1103 215 150 13 192 133 7 215 150 13 229 172 9 229 172 9
1104 236 180 10 236 180 22 242 182 11 242 182 11 245 189 11
1105 245 189 11 245 189 11 245 189 11 245 189 11 245 189 11
1106 245 189 11 245 189 11 245 189 11 229 172 9 216 156 8
1107 156 102 5 83 54 6 2 2 3 2 2 3 2 2 3
1108 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1109 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1110 2 2 3 2 2 3 115 73 3 185 132 9 229 172 9
1111 242 182 11 245 189 11 245 189 11 245 189 11 245 189 11
1112 245 189 11 242 182 11 229 172 9 229 172 9 216 156 8
1113 180 121 7 215 150 13 215 150 13 215 150 13 215 150 13
1114 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1115 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1116 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1117 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1118 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1119 215 150 13 180 121 7 182 126 10 192 133 7 199 140 8
1120 207 148 7 215 150 13 216 156 8 224 165 9 229 172 9
1121 236 180 22 245 189 11 242 182 11 245 189 11 242 182 11
1122 245 189 11 245 189 11 242 182 11 229 172 9 199 140 8
1123 151 97 5 101 67 7 2 2 3 2 2 3 2 2 3
1124 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1125 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1126 2 2 3 2 2 3 115 73 3 180 121 7 216 156 8
1127 236 180 22 242 182 11 245 189 11 245 189 11 242 182 11
1128 236 180 10 224 165 9 215 150 13 206 142 8 215 150 13
1129 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1130 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1131 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1132 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1133 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1134 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1135 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1136 156 102 5 164 109 5 172 114 5 180 121 7 180 121 7
1137 192 133 7 201 142 7 216 156 8 224 165 9 236 180 22
1138 245 189 11 242 182 11 229 172 9 201 142 7 172 114 5
1139 125 83 5 83 54 6 2 2 3 2 2 3 2 2 3
1140 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1141 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3
1142 2 2 3 2 2 3 91 58 5 156 102 5 192 133 7
1143 216 156 8 229 172 9 236 180 10 236 180 10 229 172 9
1144 215 150 13 199 140 8 164 109 5 215 150 13 215 150 13
1145 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1146 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1147 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1148 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1149 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1150 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1151 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1152 215 150 13 215 150 13 215 150 13 120 78 3 132 82 3
1153 151 97 5 157 106 7 180 121 7 185 132 9 193 140 10
1154 207 148 7 207 148 7 192 133 7 172 114 5 132 82 3
1155 101 67 7 41 27 3 215 150 13 215 150 13 215 150 13
1156 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1157 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1158 215 150 13 215 150 13 73 48 6 143 90 3 180 121 7
1159 192 133 7 207 148 7 207 148 7 201 142 7 185 132 9
1160 173 120 10 136 95 7 215 150 13 215 150 13 215 150 13
1161 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1162 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1163 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1164 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1165 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1166 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1167 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1168 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1169 215 150 13 215 150 13 91 58 5 125 83 5 135 88 5
1170 144 95 7 151 97 5 132 82 3 115 73 3 95 62 5
1171 64 43 7 215 150 13 215 150 13 215 150 13 215 150 13
1172 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1173 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1174 215 150 13 215 150 13 64 43 7 91 58 5 151 97 5
1175 157 106 7 172 114 5 172 114 5 164 109 5 151 97 5
1176 85 59 6 215 150 13 215 150 13 215 150 13 215 150 13
1177 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1178 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1179 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1180 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1181 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1182 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1183 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1184 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1185 215 150 13 215 150 13 215 150 13 215 150 13 73 48 6
1186 91 58 5 95 62 5 95 62 5 91 58 5 56 38 5
1187 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1188 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1189 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1190 215 150 13 215 150 13 215 150 13 215 150 13 83 54 6
1191 107 69 5 132 82 3 125 83 5 101 67 7 71 47 31
1192 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1193 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1194 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1195 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1196 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1197 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1198 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1199 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1200 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1201 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1202 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1203 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1204 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1205 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1206 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1207 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1208 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1209 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1210 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1211 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1212 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1213 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1214 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1215 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1216 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1217 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1218 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1219 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1220 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1221 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1222 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1223 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1224 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1225 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1226 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1227 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1228 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1229 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1230 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1231 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1232 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1233 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1234 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1235 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1236 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1237 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1238 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1239 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1240 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1241 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1242 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1243 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1244 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1245 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1246 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1247 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1248 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1249 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1250 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1251 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1252 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1253 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1254 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1255 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1256 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1257 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1258 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1259 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1260 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1261 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1262 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1263 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1264 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1265 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1266 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1267 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1268 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1269 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1270 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1271 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1272 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1273 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1274 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1275 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1276 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1277 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1278 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1279 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1280 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1281 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1282 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1283 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1284 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1285 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1286 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1287 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1288 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1289 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1290 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1291 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
1292 215 150 13 215 150 13 215 150 13 215 150 13 215 150 13
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 3dd1de1539d2..b00887e9851c 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -523,7 +523,7 @@ int __init platinumfb_setup(char *options)
523#define invalidate_cache(addr) 523#define invalidate_cache(addr)
524#endif 524#endif
525 525
526static int __devinit platinumfb_probe(struct of_device* odev, const struct of_match *match) 526static int __devinit platinumfb_probe(struct of_device* odev, const struct of_device_id *match)
527{ 527{
528 struct device_node *dp = odev->node; 528 struct device_node *dp = odev->node;
529 struct fb_info *info; 529 struct fb_info *info;
@@ -647,12 +647,10 @@ static int __devexit platinumfb_remove(struct of_device* odev)
647 return 0; 647 return 0;
648} 648}
649 649
650static struct of_match platinumfb_match[] = 650static struct of_device_id platinumfb_match[] =
651{ 651{
652 { 652 {
653 .name = "platinum", 653 .name = "platinum",
654 .type = OF_ANY_MATCH,
655 .compatible = OF_ANY_MATCH,
656 }, 654 },
657 {}, 655 {},
658}; 656};
diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
index 789de13f461f..3848be2b9d2d 100644
--- a/drivers/video/s1d13xxxfb.c
+++ b/drivers/video/s1d13xxxfb.c
@@ -67,12 +67,18 @@ static struct fb_fix_screeninfo __devinitdata s1d13xxxfb_fix = {
67static inline u8 67static inline u8
68s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno) 68s1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno)
69{ 69{
70#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
71 regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
72#endif
70 return readb(par->regs + regno); 73 return readb(par->regs + regno);
71} 74}
72 75
73static inline void 76static inline void
74s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value) 77s1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value)
75{ 78{
79#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI3)
80 regno=((regno & 1) ? (regno & ~1L) : (regno + 1));
81#endif
76 writeb(value, par->regs + regno); 82 writeb(value, par->regs + regno);
77} 83}
78 84
@@ -259,7 +265,11 @@ s1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
259 dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n", 265 dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n",
260 regno, pseudo_val); 266 regno, pseudo_val);
261 267
268#if defined(CONFIG_PLAT_MAPPI)
269 ((u32 *)info->pseudo_palette)[regno] = cpu_to_le16(pseudo_val);
270#else
262 ((u32 *)info->pseudo_palette)[regno] = pseudo_val; 271 ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
272#endif
263 273
264 break; 274 break;
265 case FB_VISUAL_PSEUDOCOLOR: 275 case FB_VISUAL_PSEUDOCOLOR:
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 8fadcdae6f42..f4633d1891f1 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -2113,7 +2113,7 @@ static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
2113 printk(KERN_DEBUG "state: %u\n", state); 2113 printk(KERN_DEBUG "state: %u\n", state);
2114 2114
2115 acquire_console_sem(); 2115 acquire_console_sem();
2116 fb_set_suspend(info, state); 2116 fb_set_suspend(info, pci_choose_state(dev, state));
2117 savage_disable_mmio(par); 2117 savage_disable_mmio(par);
2118 release_console_sem(); 2118 release_console_sem();
2119 2119
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 312cf3220f12..8a9c42822502 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -516,6 +516,7 @@ static void w1_slave_found(unsigned long data, u64 rn)
516 struct w1_reg_num *tmp; 516 struct w1_reg_num *tmp;
517 int family_found = 0; 517 int family_found = 0;
518 struct w1_master *dev; 518 struct w1_master *dev;
519 u64 rn_le = cpu_to_le64(rn);
519 520
520 dev = w1_search_master(data); 521 dev = w1_search_master(data);
521 if (!dev) { 522 if (!dev) {
@@ -544,10 +545,8 @@ static void w1_slave_found(unsigned long data, u64 rn)
544 slave_count++; 545 slave_count++;
545 } 546 }
546 547
547 rn = cpu_to_le64(rn);
548
549 if (slave_count == dev->slave_count && 548 if (slave_count == dev->slave_count &&
550 rn && ((le64_to_cpu(rn) >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { 549 rn && ((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn_le, 7)) {
551 w1_attach_slave_device(dev, tmp); 550 w1_attach_slave_device(dev, tmp);
552 } 551 }
553 552
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 35e85d961702..b5a5e04b6d37 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -88,7 +88,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
88 88
89 dev->groups = 23; 89 dev->groups = 23;
90 dev->seq = 1; 90 dev->seq = 1;
91 dev->nls = netlink_kernel_create(NETLINK_NFLOG, NULL); 91 dev->nls = netlink_kernel_create(NETLINK_W1, NULL);
92 if (!dev->nls) { 92 if (!dev->nls) {
93 printk(KERN_ERR "Failed to create new netlink socket(%u) for w1 master %s.\n", 93 printk(KERN_ERR "Failed to create new netlink socket(%u) for w1 master %s.\n",
94 NETLINK_NFLOG, dev->dev.bus_id); 94 NETLINK_NFLOG, dev->dev.bus_id);